3 @@ -38,7 +38,7 @@ subdir-$(CONFIG_FUSION) += message/fusi
4 subdir-$(CONFIG_MD) += md
5 subdir-$(CONFIG_IEEE1394) += ieee1394
6 subdir-$(CONFIG_PNP) += pnp
7 -subdir-$(CONFIG_ISDN_BOOL) += isdn
8 +subdir-$(CONFIG_ISDN) += isdn
9 subdir-$(CONFIG_ATM) += atm
10 subdir-$(CONFIG_FC4) += fc4
12 --- a/drivers/isdn/hisax/hfc_usb.c
13 +++ b/drivers/isdn/hisax/hfc_usb.c
15 -/* $Id: hfc_usb.c,v 2.3 2001/07/06 21:30:11 werner Exp $
19 + * modular HiSax ISDN driver for Colognechip HFC-USB chip
22 - * Author (C) 2001 Werner Cornelius (werner@isdn-development.de)
23 - * modular driver for Colognechip HFC-USB chip
24 - * as plugin for HiSax isdn driver
25 - * type approval valid for HFC-S USB based TAs
27 - * Copyright 2001 by Werner Cornelius (werner@isdn-development.de)
28 + * Authors : Peter Sprenger (sprenger@moving-byters.de)
29 + * Martin Bachem (info@colognechip.com)
30 + * based on the first hfc_usb driver of Werner Cornelius (werner@isdn-development.de)
32 * This program is free software; you can redistribute it and/or modify
33 * it under the terms of the GNU General Public License as published by
35 * along with this program; if not, write to the Free Software
36 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
40 + * ported 2.6.8 hfc_usb.c to 2.4.20 format
41 + * Gregor Schaffrath <gschaff@ran-dom.org>
45 #include <linux/types.h>
46 #include <linux/stddef.h>
47 #include <linux/timer.h>
48 #include <linux/config.h>
49 -#include <linux/isdn_compat.h>
50 #include <linux/init.h>
52 #include <linux/module.h>
53 #include <linux/kernel_stat.h>
54 -#include <linux/tqueue.h>
55 #include <linux/usb.h>
56 #include <linux/kernel.h>
57 #include <linux/smp_lock.h>
58 #include <linux/sched.h>
59 +#include "hisax_if.h"
60 #include "hisax_loadable.h"
62 +static const char *hfcusb_revision = "4.0";
65 + to enable much mire debug messages in this driver, define
66 + VERBOSE_USB_DEBUG and VERBOSE_ISDN_DEBUG
70 +#define VERBOSE_USB_DEBUG
71 +#define VERBOSE_ISDN_DEBUG
73 #define INCLUDE_INLINE_FUNCS
82 -#define HFC_CTRL_TIMEOUT 5 /* 5ms timeout writing/reading regs */
83 -#define HFC_TIMER_T3 7000 /* timeout for l1 activation timer */
85 -#define HFCUSB_L1_STATECHANGE 0 /* L1 state changed */
86 -#define HFCUSB_L1_DRX 1 /* D-frame received */
87 -#define HFCUSB_L1_ERX 2 /* E-frame received */
88 -#define HFCUSB_L1_DTX 4 /* D-frames completed */
90 -#define MAX_BCH_SIZE 2048 /* allowed B-channel packet size */
92 -#define HFCUSB_RX_THRESHOLD 64 /* threshold for fifo report bit rx */
93 -#define HFCUSB_TX_THRESHOLD 64 /* threshold for fifo report bit tx */
95 -#define HFCUSB_CHIP_ID 0x16 /* Chip ID register index */
96 -#define HFCUSB_CIRM 0x00 /* cirm register index */
97 -#define HFCUSB_USB_SIZE 0x07 /* int length register */
98 -#define HFCUSB_USB_SIZE_I 0x06 /* iso length register */
99 -#define HFCUSB_F_CROSS 0x0b /* bit order register */
100 -#define HFCUSB_CLKDEL 0x37 /* bit delay register */
101 -#define HFCUSB_CON_HDLC 0xfa /* channel connect register */
102 +#define HFC_CTRL_TIMEOUT 20 //(HZ * USB_CTRL_GET_TIMEOUT)
103 +/* 5ms timeout writing/reading regs */
104 +#define HFC_TIMER_T3 8000 /* timeout for l1 activation timer */
105 +#define HFC_TIMER_T4 500 /* time for state change interval */
107 +#define HFCUSB_L1_STATECHANGE 0 /* L1 state changed */
108 +#define HFCUSB_L1_DRX 1 /* D-frame received */
109 +#define HFCUSB_L1_ERX 2 /* E-frame received */
110 +#define HFCUSB_L1_DTX 4 /* D-frames completed */
112 +#define MAX_BCH_SIZE 2048 /* allowed B-channel packet size */
114 +#define HFCUSB_RX_THRESHOLD 64 /* threshold for fifo report bit rx */
115 +#define HFCUSB_TX_THRESHOLD 64 /* threshold for fifo report bit tx */
117 +#define HFCUSB_CHIP_ID 0x16 /* Chip ID register index */
118 +#define HFCUSB_CIRM 0x00 /* cirm register index */
119 +#define HFCUSB_USB_SIZE 0x07 /* int length register */
120 +#define HFCUSB_USB_SIZE_I 0x06 /* iso length register */
121 +#define HFCUSB_F_CROSS 0x0b /* bit order register */
122 +#define HFCUSB_CLKDEL 0x37 /* bit delay register */
123 +#define HFCUSB_CON_HDLC 0xfa /* channel connect register */
124 #define HFCUSB_HDLC_PAR 0xfb
125 -#define HFCUSB_SCTRL 0x31 /* S-bus control register (tx) */
126 -#define HFCUSB_SCTRL_E 0x32 /* same for E and special funcs */
127 -#define HFCUSB_SCTRL_R 0x33 /* S-bus control register (rx) */
128 -#define HFCUSB_F_THRES 0x0c /* threshold register */
129 -#define HFCUSB_FIFO 0x0f /* fifo select register */
130 -#define HFCUSB_F_USAGE 0x1a /* fifo usage register */
131 +#define HFCUSB_SCTRL 0x31 /* S-bus control register (tx) */
132 +#define HFCUSB_SCTRL_E 0x32 /* same for E and special funcs */
133 +#define HFCUSB_SCTRL_R 0x33 /* S-bus control register (rx) */
134 +#define HFCUSB_F_THRES 0x0c /* threshold register */
135 +#define HFCUSB_FIFO 0x0f /* fifo select register */
136 +#define HFCUSB_F_USAGE 0x1a /* fifo usage register */
137 #define HFCUSB_MST_MODE0 0x14
138 #define HFCUSB_MST_MODE1 0x15
139 #define HFCUSB_P_DATA 0x1f
140 #define HFCUSB_INC_RES_F 0x0e
141 #define HFCUSB_STATES 0x30
143 -#define HFCUSB_CHIPID 0x40 /* ID value of HFC-USB */
144 +#define HFCUSB_CHIPID 0x40 /* ID value of HFC-USB */
149 -#define HFCUSB_NUM_FIFOS 8 /* maximum number of fifos */
150 -#define HFCUSB_B1_TX 0 /* index for B1 transmit bulk/int */
151 -#define HFCUSB_B1_RX 1 /* index for B1 receive bulk/int */
152 +#define HFCUSB_NUM_FIFOS 8 /* maximum number of fifos */
153 +#define HFCUSB_B1_TX 0 /* index for B1 transmit bulk/int */
154 +#define HFCUSB_B1_RX 1 /* index for B1 receive bulk/int */
155 #define HFCUSB_B2_TX 2
156 #define HFCUSB_B2_RX 3
157 #define HFCUSB_D_TX 4
158 @@ -94,198 +112,162 @@
159 #define HFCUSB_PCM_TX 6
160 #define HFCUSB_PCM_RX 7
165 -#define LED_DRIVER 0x1
169 +* used to switch snd_transfer_mode for different TA modes e.g. the Billion USB TA just
170 +* supports ISO out, while the Cologne Chip EVAL TA just supports BULK out
176 +#define ISOC_PACKETS_D 8
177 +#define ISOC_PACKETS_B 8
178 +#define ISO_BUFFER_SIZE 128
180 +// ISO send definitions
183 +#define SINK_DMIN 12
184 +#define SINK_DMAX 18
185 +#define BITLINE_INF (-64*8)
193 -#define Write_hfc(a,b,c) usb_control_msg((a)->dev,(a)->ctrl_out_pipe,0,0x40,(c),(b),0,0,HFC_CTRL_TIMEOUT)
194 -#define Read_hfc(a,b,c) usb_control_msg((a)->dev,(a)->ctrl_in_pipe,1,0xC0,0,(b),(c),1,HFC_CTRL_TIMEOUT)
196 -#ifdef COMPAT_HAS_USB_IDTAB
197 -/****************************************/
198 -/* data defining the devices to be used */
199 -/****************************************/
200 -static __devinitdata const struct usb_device_id hfc_usb_idtab[3] = {
201 - {USB_DEVICE(0x959, 0x2bd0)}, /* Colognechip ROM */
202 - {USB_DEVICE(0x7b0, 0x0006)}, /* USB TA 128 */
203 - {} /* end with an all-zeroes entry */
206 +#define write_usb(a,b,c) usb_control_msg((a)->dev,(a)->ctrl_out_pipe,0,0x40,(c),(b),NULL,0,HFC_CTRL_TIMEOUT)
207 +#define read_usb(a,b,c) usb_control_msg((a)->dev,(a)->ctrl_in_pipe,1,0xC0,0,(b),(c),1,HFC_CTRL_TIMEOUT)
209 /*************************************************/
210 /* entry and size of output/input control buffer */
211 /*************************************************/
212 #define HFC_CTRL_BUFSIZE 32
216 __u8 hfc_reg; /* register number */
217 __u8 reg_val; /* value to be written (or read) */
218 + int action; /* data for action handler */
224 + int vendor; // vendor id
225 + int prod_id; // product id
226 + char *vend_name; // vendor string
227 + __u8 led_scheme; // led display scheme
228 + __u8 led_invert; // invert led aux port settings
229 + __u8 led_bits[8]; // array of 8 possible LED bitmask settings
233 /***************************************************************/
234 /* structure defining input+output fifos (interrupt/bulk mode) */
235 /***************************************************************/
236 -struct hfcusb_data; /* forward definition */
238 - int fifonum; /* fifo index attached to this structure */
239 - __u8 fifo_mask; /* mask for this fifo */
240 - int active; /* fifo is currently active */
242 +struct usb_fifo; /* forward definition */
243 +typedef struct iso_urb_struct
246 + __u8 buffer[ISO_BUFFER_SIZE]; /* buffer incoming/outgoing data */
247 + struct usb_fifo *owner_fifo; // pointer to owner fifo
251 +struct hfcusb_data; /* forward definition */
252 +typedef struct usb_fifo
254 + int fifonum; /* fifo index attached to this structure */
255 + int active; /* fifo is currently active */
256 struct hfcusb_data *hfc; /* pointer to main structure */
257 - int pipe; /* address of endpoint */
258 - __u8 usb_maxlen; /* maximum length for usb transfer */
259 - int max_size; /* maximum size of receive/send packet */
260 - int transmode; /* transparent mode selected */
261 - int framenum; /* number of frame when last tx completed */
262 - int rx_offset; /* offset inside rx buffer */
263 - int next_complete; /* complete marker */
264 - __u8 *act_ptr; /* pointer to next data */
265 - __u8 intervall; /* interrupt interval */
266 - struct sk_buff *buff; /* actual used buffer */
267 - urb_t urb; /* transfer structure for usb routines */
268 - __u8 buffer[128]; /* buffer incoming/outgoing data */
269 + int pipe; /* address of endpoint */
270 + __u8 usb_packet_maxlen; /* maximum length for usb transfer */
271 + unsigned int max_size; /* maximum size of receive/send packet */
272 + __u8 intervall; /* interrupt interval */
273 + struct sk_buff *skbuff; /* actual used buffer */
274 + struct urb *urb; /* transfer structure for usb routines */
275 + __u8 buffer[128]; /* buffer incoming/outgoing data */
276 + int bit_line; /* how much bits are in the fifo? */
278 + volatile __u8 usb_transfer_mode;/* switched between ISO and INT */
279 + iso_urb_struct iso[2]; /* need two urbs to have one always for pending */
280 + struct hisax_if *hif; /* hisax interface */
281 + int delete_flg; /* only delete skbuff once */
282 + int last_urblen; /* remember length of last packet */
287 /*********************************************/
288 /* structure holding all data for one device */
289 /*********************************************/
290 -typedef struct hfcusb_data {
291 - struct hisax_drvreg regd; /* register data and callbacks */
292 - struct usb_device *dev; /* our device */
293 - int if_used; /* used interface number */
294 - int alt_used; /* used alternate config */
295 - int ctrl_paksize; /* control pipe packet size */
296 +typedef struct hfcusb_data
298 + // HiSax Interface for loadable Layer1 drivers
299 + struct hisax_d_if d_if; /* see hisax_if.h */
300 + struct hisax_b_if b_if[2]; /* see hisax_if.h */
303 + struct usb_device *dev; /* our device */
304 + int if_used; /* used interface number */
305 + int alt_used; /* used alternate config */
306 + int ctrl_paksize; /* control pipe packet size */
307 int ctrl_in_pipe, ctrl_out_pipe; /* handles for control pipe */
308 + int cfg_used; /* configuration index used */
309 + int vend_idx; // vendor found
311 + int b_mode[2]; // B-channel mode
313 + int l1_activated; // layer 1 activated
315 + int packet_size,iso_packet_size;
317 /* control pipe background handling */
318 ctrl_buft ctrl_buff[HFC_CTRL_BUFSIZE]; /* buffer holding queued data */
319 - volatile int ctrl_in_idx, ctrl_out_idx, ctrl_cnt; /* input/output pointer + count */
320 - urb_t ctrl_urb; /* transfer structure for control channel */
321 - devrequest ctrl_write; /* buffer for control write request */
322 - devrequest ctrl_read; /* same for read request */
324 - volatile __u8 dfifo_fill; /* value read from tx d-fifo */
325 - volatile __u8 active_fifos; /* fifos currently active as bit mask */
326 - volatile __u8 threshold_mask; /* threshold actually reported */
327 - volatile __u8 service_request; /* fifo needs service from task */
328 - volatile __u8 ctrl_fifo; /* last selected fifo */
329 - volatile __u8 bch_enables; /* or mask for sctrl_r and sctrl register values */
330 - volatile __u8 led_req; /* request status of adapters leds */
331 - volatile __u8 led_act; /* active status of adapters leds */
332 + volatile int ctrl_in_idx, ctrl_out_idx,
333 + ctrl_cnt; /* input/output pointer + count */
334 + struct urb *ctrl_urb; /* transfer structure for control channel */
336 + struct usb_ctrlrequest ctrl_write; /* buffer for control write request */
337 + struct usb_ctrlrequest ctrl_read; /* same for read request */
339 + __u8 led_state,led_new_data,led_b_active;
341 + volatile __u8 threshold_mask; /* threshold actually reported */
342 + volatile __u8 bch_enables; /* or mask for sctrl_r and sctrl register values */
344 usb_fifo fifos[HFCUSB_NUM_FIFOS]; /* structure holding all fifo data */
346 - /* layer 1 activation/deactivation handling */
347 - volatile __u8 l1_state; /* actual l1 state */
348 - volatile ulong l1_event; /* event mask */
349 - struct tq_struct l1_tq; /* l1 bh structure */
350 - struct timer_list t3_timer; /* timer for activation/deactivation */
351 - struct timer_list t4_timer; /* timer for activation/deactivation */
352 + volatile __u8 l1_state; /* actual l1 state */
353 + struct timer_list t3_timer; /* timer 3 for activation/deactivation */
354 + struct timer_list t4_timer; /* timer 4 for activation/deactivation */
355 + struct timer_list led_timer; /* timer flashing leds */
361 -usb_dump_urb(purb_t purb)
363 - printk("urb :%p\n", purb);
364 - printk("next :%p\n", purb->next);
365 - printk("dev :%p\n", purb->dev);
366 - printk("pipe :%08X\n", purb->pipe);
367 - printk("status :%d\n", purb->status);
368 - printk("transfer_flags :%08X\n", purb->transfer_flags);
369 - printk("transfer_buffer :%p\n", purb->transfer_buffer);
370 - printk("transfer_buffer_length:%d\n",
371 - purb->transfer_buffer_length);
372 - printk("actual_length :%d\n", purb->actual_length);
373 - printk("setup_packet :%p\n", purb->setup_packet);
374 - printk("start_frame :%d\n", purb->start_frame);
375 - printk("number_of_packets :%d\n", purb->number_of_packets);
376 - printk("interval :%d\n", purb->interval);
377 - printk("error_count :%d\n", purb->error_count);
378 - printk("context :%p\n", purb->context);
379 - printk("complete :%p\n", purb->complete);
383 -/*************************************************************************/
384 -/* bottom half handler for L1 activation/deactiavtaion + D-chan + E-chan */
385 -/*************************************************************************/
387 -usb_l1d_bh(hfcusb_data * hfc)
389 +static void collect_rx_frame(usb_fifo *fifo,__u8 *data,int len,int finish);
392 - while (hfc->l1_event) {
393 - if (test_and_clear_bit
394 - (HFCUSB_L1_STATECHANGE, &hfc->l1_event)) {
395 - if (hfc->l1_state == 7)
396 - hfc->led_req |= LED_L1;
398 - hfc->led_req &= ~LED_L1;
399 - if ((hfc->l1_state == 7) ||
400 - (hfc->l1_state == 3))
401 - hfc->regd.dch_l1l2(hfc->regd.arg_hisax,
403 - 7) ? (PH_ACTIVATE |
405 - : (PH_DEACTIVATE | INDICATION),
408 - if (test_and_clear_bit(HFCUSB_L1_DRX, &hfc->l1_event)) {
409 - hfc->regd.dch_l1l2(hfc->regd.arg_hisax,
410 - PH_DATA | INDICATION,
413 - if (test_and_clear_bit(HFCUSB_L1_ERX, &hfc->l1_event)) {
414 - hfc->regd.dch_l1l2(hfc->regd.arg_hisax,
415 - PH_DATA | INDICATION,
418 - if (test_and_clear_bit(HFCUSB_L1_DTX, &hfc->l1_event)) {
419 - hfc->regd.dch_l1l2(hfc->regd.arg_hisax,
420 - PH_DATA | CONFIRM, NULL);
425 /******************************************************/
426 /* start next background transfer for control channel */
427 /******************************************************/
429 -ctrl_start_transfer(hfcusb_data * hfc)
430 +static void ctrl_start_transfer(hfcusb_data * hfc)
433 - if (hfc->ctrl_cnt) {
434 - switch (hfc->ctrl_buff[hfc->ctrl_out_idx].hfc_reg) {
435 - case HFCUSB_F_USAGE:
436 - hfc->ctrl_urb.pipe = hfc->ctrl_in_pipe;
437 - hfc->ctrl_urb.setup_packet =
438 - (u_char *) & hfc->ctrl_read;
439 - hfc->ctrl_urb.transfer_buffer_length = 1;
440 - hfc->ctrl_read.index =
441 - hfc->ctrl_buff[hfc->ctrl_out_idx].
443 - hfc->ctrl_urb.transfer_buffer =
444 - (char *) &hfc->dfifo_fill;
447 - default: /* write register */
448 - hfc->ctrl_urb.pipe = hfc->ctrl_out_pipe;
449 - hfc->ctrl_urb.setup_packet =
450 - (u_char *) & hfc->ctrl_write;
451 - hfc->ctrl_urb.transfer_buffer = NULL;
452 - hfc->ctrl_urb.transfer_buffer_length = 0;
453 - hfc->ctrl_write.index =
454 - hfc->ctrl_buff[hfc->ctrl_out_idx].
456 - hfc->ctrl_write.value =
457 - hfc->ctrl_buff[hfc->ctrl_out_idx].
461 - usb_submit_urb(&hfc->ctrl_urb); /* start transfer */
465 + hfc->ctrl_urb->pipe = hfc->ctrl_out_pipe;
466 + hfc->ctrl_urb->setup_packet = (u_char *) & hfc->ctrl_write;
467 + hfc->ctrl_urb->transfer_buffer = NULL;
468 + hfc->ctrl_urb->transfer_buffer_length = 0;
469 + hfc->ctrl_write.wIndex = hfc->ctrl_buff[hfc->ctrl_out_idx].hfc_reg;
470 + hfc->ctrl_write.wValue = hfc->ctrl_buff[hfc->ctrl_out_idx].reg_val;
471 + err = usb_submit_urb(hfc->ctrl_urb); /* start transfer */
472 + printk(KERN_DEBUG "ctrl_start_transfer: submit %d\n", err);
474 } /* ctrl_start_transfer */
476 @@ -293,897 +275,1418 @@ ctrl_start_transfer(hfcusb_data * hfc)
477 /* queue a control transfer request */
478 /* return 0 on success. */
479 /************************************/
481 -queue_control_request(hfcusb_data * hfc, __u8 reg, __u8 val)
482 +static int queue_control_request(hfcusb_data * hfc, __u8 reg, __u8 val,int action)
486 - if (hfc->ctrl_cnt >= HFC_CTRL_BUFSIZE)
487 - return (1); /* no space left */
488 - buf = hfc->ctrl_buff + hfc->ctrl_in_idx; /* pointer to new index */
489 +#ifdef VERBOSE_USB_DEBUG
490 + printk ("HFC_USB: queue_control_request reg: %x, val: %x\n", reg, val);
493 + if(hfc->ctrl_cnt >= HFC_CTRL_BUFSIZE) return(1); /* no space left */
494 + buf = &hfc->ctrl_buff[hfc->ctrl_in_idx]; /* pointer to new index */
497 + buf->action=action;
498 if (++hfc->ctrl_in_idx >= HFC_CTRL_BUFSIZE)
499 hfc->ctrl_in_idx = 0; /* pointer wrap */
500 if (++hfc->ctrl_cnt == 1)
501 ctrl_start_transfer(hfc);
503 -} /* queue_control_request */
505 +} /* queue_control_request */
507 -/**************************************/
508 -/* called when timer t3 or t4 expires */
509 -/**************************************/
511 -l1_timer_expire(hfcusb_data * hfc)
513 - if (timer_pending(&hfc->t4_timer))
514 - del_timer(&hfc->t4_timer);
515 - queue_control_request(hfc, HFCUSB_STATES, 0x40);
516 - test_and_set_bit(HFCUSB_L1_STATECHANGE,
518 - queue_task(&hfc->l1_tq, &tq_immediate);
519 - mark_bh(IMMEDIATE_BH);
520 -} /* l1_timer_expire */
522 -/**************************************************/
523 -/* (re)fills a tx-fifo urb. Queuing is done later */
524 -/**************************************************/
526 -fill_tx_urb(usb_fifo * fifo)
528 - struct sk_buff *skb;
532 - fifo->urb.dev = fifo->hfc->dev;
534 - && (fifo->urb.transfer_buffer_length < fifo->usb_maxlen)) {
535 - switch (fifo->fifonum) {
540 - fifo->hfc->regd.bch_l1l2(fifo->hfc->regd.
548 - fifo->hfc->service_request |=
552 - dev_kfree_skb_any(fifo->buff);
556 - fifo->hfc->dfifo_fill = 0xff; /* currently invalid data */
557 - queue_control_request(fifo->hfc,
560 - queue_control_request(fifo->hfc,
561 - HFCUSB_F_USAGE, 0);
562 - restore_flags(flags);
565 - return; /* error, invalid fifo */
568 +static int control_action_handler(hfcusb_data *hfc,int reg,int val,int action)
570 + if(!action) return(1); // no action defined
576 +/***************************************************************/
577 +/* control completion routine handling background control cmds */
578 +/***************************************************************/
579 +static void ctrl_complete(struct urb *urb)
581 + hfcusb_data *hfc = (hfcusb_data *) urb->context;
584 + printk(KERN_DEBUG "ctrl_complete cnt %d\n", hfc->ctrl_cnt);
585 + urb->dev = hfc->dev;
588 + buf=&hfc->ctrl_buff[hfc->ctrl_out_idx];
589 + control_action_handler(hfc,buf->hfc_reg,buf->reg_val,buf->action);
591 + hfc->ctrl_cnt--; /* decrement actual count */
592 + if(++hfc->ctrl_out_idx >= HFC_CTRL_BUFSIZE) hfc->ctrl_out_idx = 0; /* pointer wrap */
594 + ctrl_start_transfer(hfc); /* start next transfer */
596 +} /* ctrl_complete */
600 +#define LED_OFF 0 // no LED support
601 +#define LED_SCHEME1 1 // LED standard scheme
602 +#define LED_SCHEME2 2 // not used yet...
604 +#define LED_POWER_ON 1
605 +#define LED_POWER_OFF 2
607 +#define LED_S0_OFF 4
609 +#define LED_B1_OFF 6
610 +#define LED_B1_DATA 7
612 +#define LED_B2_OFF 9
613 +#define LED_B2_DATA 10
615 +#define LED_NORMAL 0 // LEDs are normal
616 +#define LED_INVERTED 1 // LEDs are inverted
618 +// time for LED flashing
619 +#define LED_TIME 250
621 +vendor_data vdata[]=
623 + {0x959, 0x2bd0, "ISDN USB TA (Cologne Chip HFC-S USB based)", LED_OFF,LED_NORMAL,{4,0,2,1}}, /* CologneChip Eval TA */
624 + {0x7b0, 0x0007, "Billion tiny USB ISDN TA 128", LED_SCHEME1, LED_INVERTED, {8,0x40,0x20,0x10}}, /* Billion TA */
625 + {0x742, 0x2008, "Stollmann USB TA", LED_SCHEME1, LED_NORMAL, {4,0,2,1}}, /* Stollmann TA */
626 + {0x8e3, 0x0301, "Olitec USB RNIS", LED_SCHEME1, LED_NORMAL, {2,0,1,4}}, /* Olitec TA */
627 + {0x675, 0x1688, "DrayTec USB ISDN TA", LED_SCHEME1, LED_NORMAL, {4,0,2,1}}, /* Draytec TA */
628 + {0x7fa, 0x0846, "Bewan Modem RNIS USB", LED_SCHEME1, LED_INVERTED, {8,0x40,0x20,0x10}}, /* Bewan TA */
632 +/***************************************************/
633 +/* write led data to auxport & invert if necessary */
634 +/***************************************************/
635 +static void write_led(hfcusb_data * hfc,__u8 led_state)
637 + if(led_state!=hfc->led_state)
639 + hfc->led_state=led_state;
640 + queue_control_request(hfc, HFCUSB_P_DATA,(vdata[hfc->vend_idx].led_invert) ? ~led_state : led_state,1);
644 +/******************************************/
645 +/* invert B-channel LEDs if data is sent */
646 +/******************************************/
647 +static void led_timer(hfcusb_data * hfc)
650 + __u8 led_state=hfc->led_state;
654 + if(hfc->led_b_active&1) led_state|=vdata[hfc->vend_idx].led_bits[2];
655 + if(hfc->led_b_active&2) led_state|=vdata[hfc->vend_idx].led_bits[3];
659 + if(!(hfc->led_b_active&1) || hfc->led_new_data&1) led_state&=~vdata[hfc->vend_idx].led_bits[2];
660 + if(!(hfc->led_b_active&2) || hfc->led_new_data&2) led_state&=~vdata[hfc->vend_idx].led_bits[3];
663 - /* check if new buffer needed */
665 - switch (fifo->fifonum) {
667 - if (fifo->hfc->regd.bsk[0])
668 - fifo->buff = *fifo->hfc->regd.bsk[0]; /* B1-channel tx buffer */
669 + write_led(hfc,led_state);
670 + hfc->led_new_data=0;
673 + // restart 4 hz timer
674 + hfc->led_timer.expires = jiffies + (LED_TIME * HZ) / 1000;
675 + if(!timer_pending(&hfc->led_timer)) add_timer(&hfc->led_timer);
678 +/**************************/
679 +/* handle LED requests */
680 +/**************************/
681 +static void handle_led(hfcusb_data * hfc,int event)
683 + __u8 led_state=hfc->led_state;
685 + // if no scheme -> no LED action
686 + if(vdata[hfc->vend_idx].led_scheme==LED_OFF) return;
691 + led_state|=vdata[hfc->vend_idx].led_bits[0];
693 + case LED_POWER_OFF: // no Power off handling
696 + led_state|=vdata[hfc->vend_idx].led_bits[1];
699 + led_state&=~vdata[hfc->vend_idx].led_bits[1];
702 - if (fifo->hfc->regd.bsk[1])
703 - fifo->buff = *fifo->hfc->regd.bsk[1]; /* B2-channel tx buffer */
705 + hfc->led_b_active|=1;
708 - if (fifo->hfc->regd.dsq)
709 - fifo->buff = skb_dequeue(fifo->hfc->regd.dsq); /* D-channel tx queue */
711 + hfc->led_b_active&=~1;
714 - return; /* error, invalid fifo */
716 + hfc->led_new_data|=1;
719 + hfc->led_b_active|=2;
722 + hfc->led_b_active&=~2;
725 + hfc->led_new_data|=2;
729 + write_led(hfc,led_state);
732 +/********************************/
733 +/* called when timer t3 expires */
734 +/********************************/
735 +static void l1_timer_expire_t3(hfcusb_data * hfc)
737 + //printk (KERN_INFO "HFC-USB: l1_timer_expire_t3\n");
739 + hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,PH_DEACTIVATE | INDICATION,NULL);
740 +#ifdef VERBOSE_USB_DEBUG
741 + printk(KERN_INFO "PH_DEACTIVATE | INDICATION sent\n");
743 + hfc->l1_activated=FALSE;
744 + handle_led(hfc,LED_S0_OFF);
747 +/********************************/
748 +/* called when timer t4 expires */
749 +/********************************/
750 +static void l1_timer_expire_t4(hfcusb_data * hfc)
752 + //printk (KERN_INFO "HFC-USB: l1_timer_expire_t4\n");
754 + hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,PH_DEACTIVATE | INDICATION,NULL);
755 +#ifdef VERBOSE_USB_DEBUG
756 + printk(KERN_INFO "PH_DEACTIVATE | INDICATION sent\n");
758 + hfc->l1_activated=FALSE;
759 + handle_led(hfc,LED_S0_OFF);
762 +/*****************************/
763 +/* handle S0 state changes */
764 +/*****************************/
765 +static void state_handler(hfcusb_data * hfc,__u8 state)
769 + old_state=hfc->l1_state;
772 + if(state==old_state || state<1 || state>8) return;
774 +#ifdef VERBOSE_ISDN_DEBUG
775 + printk(KERN_INFO "HFC-USB: new S0 state:%d old_state:%d\n",state,old_state);
778 + if(state<4 || state==7 || state==8)
780 + if(timer_pending(&hfc->t3_timer)) del_timer(&hfc->t3_timer);
781 + //printk(KERN_INFO "HFC-USB: T3 deactivated\n");
786 + if(timer_pending(&hfc->t4_timer)) del_timer(&hfc->t4_timer);
787 + //printk(KERN_INFO "HFC-USB: T4 deactivated\n");
790 + if(state==7 && !hfc->l1_activated)
792 + hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,PH_ACTIVATE | INDICATION,NULL);
793 + //printk(KERN_INFO "HFC-USB: PH_ACTIVATE | INDICATION sent\n");
794 + hfc->l1_activated=TRUE;
795 + handle_led(hfc,LED_S0_ON);
798 + if(state<=3 /* && activated*/)
800 + if(old_state==7 || old_state==8)
802 + //printk(KERN_INFO "HFC-USB: T4 activated\n");
803 + hfc->t4_timer.expires = jiffies + (HFC_TIMER_T4 * HZ) / 1000;
804 + if(!timer_pending(&hfc->t4_timer)) add_timer(&hfc->t4_timer);
807 - fifo->active = 0; /* we are inactive now */
808 - fifo->hfc->active_fifos &= ~fifo->fifo_mask;
809 - if (fifo->fifonum == HFCUSB_D_TX) {
810 - test_and_set_bit(HFCUSB_L1_DTX,
811 - &fifo->hfc->l1_event);
812 - queue_task(&fifo->hfc->l1_tq,
814 - mark_bh(IMMEDIATE_BH);
819 + hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,PH_DEACTIVATE | INDICATION,NULL);
820 + //printk(KERN_INFO "HFC-USB: PH_DEACTIVATE | INDICATION sent\n");
821 + hfc->l1_activated=FALSE;
822 + handle_led(hfc,LED_S0_OFF);
824 - fifo->act_ptr = fifo->buff->data; /* start of data */
827 - fifo->hfc->active_fifos |= fifo->fifo_mask;
828 - fifo->hfc->service_request &= ~fifo->fifo_mask;
830 - /* fillup the send buffer */
831 - i = fifo->buff->len - (fifo->act_ptr - fifo->buff->data); /* remaining length */
832 - fifo->buffer[0] = !fifo->transmode; /* not eof */
833 - if (i > (fifo->usb_maxlen - ii)) {
834 - i = fifo->usb_maxlen - ii;
837 - memcpy(fifo->buffer + ii, fifo->act_ptr, i);
838 - fifo->urb.transfer_buffer_length = i + ii;
839 - fifo->rx_offset = ii;
842 -/************************************************/
843 -/* transmit completion routine for all tx fifos */
844 -/************************************************/
846 -tx_complete(purb_t urb)
849 + hfc->l1_state=state;
853 +/* prepare iso urb */
854 +static void fill_isoc_urb(struct urb *urb, struct usb_device *dev, unsigned int pipe, void *buf,
855 + int num_packets, int packet_size, int interval, usb_complete_t complete, void *context)
857 - usb_fifo *fifo = (usb_fifo *) urb->context; /* pointer to our fifo */
860 - fifo->hfc->service_request &= ~fifo->fifo_mask; /* no further handling */
861 - fifo->framenum = usb_get_current_frame_number(fifo->hfc->dev);
862 + spin_lock_init(&urb->lock); // do we really need spin_lock_init ?
865 + urb->complete = complete;
866 + urb->number_of_packets = num_packets;
867 + urb->transfer_buffer_length = packet_size * num_packets;
868 + urb->context = context;
869 + urb->transfer_buffer = buf;
870 + urb->transfer_flags = 0;
871 + urb->transfer_flags = USB_ISO_ASAP;
872 + urb->actual_length = 0;
873 + urb->interval = interval;
874 + for (k = 0; k < num_packets; k++) {
875 + urb->iso_frame_desc[k].offset = packet_size * k;
876 + urb->iso_frame_desc[k].length = packet_size;
877 + urb->iso_frame_desc[k].actual_length = 0;
881 - /* check for deactivation or error */
882 - if ((!fifo->active) || (urb->status)) {
883 - fifo->hfc->active_fifos &= ~fifo->fifo_mask; /* we are inactive */
885 - if ((fifo->buff) && (fifo->fifonum == HFCUSB_D_TX)) {
886 - dev_kfree_skb_any(fifo->buff);
887 +/* allocs urbs and start isoc transfer with two pending urbs to avoid gaps in the transfer chain */
888 +static int start_isoc_chain(usb_fifo * fifo, int num_packets_per_urb,usb_complete_t complete,int packet_size)
892 +#ifdef VERBOSE_USB_DEBUG
893 + printk(KERN_INFO "HFC-USB: starting ISO-chain for Fifo %i\n", fifo->fifonum);
897 + // allocate Memory for Iso out Urbs
898 + for (i = 0; i < 2; i++) {
899 + if (!(fifo->iso[i].purb)) {
900 + fifo->iso[i].purb = usb_alloc_urb(num_packets_per_urb);
901 + fifo->iso[i].owner_fifo = (struct usb_fifo *) fifo;
903 + // Init the first iso
904 + if (ISO_BUFFER_SIZE >= (fifo->usb_packet_maxlen * num_packets_per_urb))
907 + fill_isoc_urb(fifo->iso[i].purb, fifo->hfc->dev, fifo->pipe, fifo->iso[i].buffer,
908 + num_packets_per_urb, fifo->usb_packet_maxlen, fifo->intervall,
909 + complete, &fifo->iso[i]);
911 + memset(fifo->iso[i].buffer, 0, sizeof(fifo->iso[i].buffer));
913 + // defining packet delimeters in fifo->buffer
914 + for(k = 0; k < num_packets_per_urb; k++)
916 + fifo->iso[i].purb->iso_frame_desc[k].offset = k*packet_size;
917 + fifo->iso[i].purb->iso_frame_desc[k].length = packet_size;
924 + fifo->bit_line = BITLINE_INF;
926 + errcode = usb_submit_urb(fifo->iso[i].purb);
927 + fifo->active = (errcode >= 0) ? 1 : 0;
930 + printk(KERN_INFO "HFC-USB: error submitting ISO URB: %i.%i \n", errcode, i);
934 - fifo->act_ptr += (urb->transfer_buffer_length - fifo->rx_offset); /* adjust pointer */
935 - fill_tx_urb(fifo); /* refill the urb */
936 - fifo->hfc->threshold_mask |= fifo->fifo_mask; /* assume threshold reached */
938 - fifo->hfc->service_request |= fifo->fifo_mask; /* need to restart */
941 -/***********************************************/
942 -/* receive completion routine for all rx fifos */
943 -/***********************************************/
945 -rx_complete(purb_t urb)
946 + // errcode = (usb_submit_urb(fifo->iso[0].purb, GFP_KERNEL));
947 + return(fifo->active);
950 +/* stops running iso chain and frees their pending urbs */
951 +static void stop_isoc_chain(usb_fifo * fifo)
953 - usb_fifo *fifo = (usb_fifo *) urb->context; /* pointer to our fifo */
954 - hfcusb_data *hfc = fifo->hfc;
957 - int i, ii, currcnt, hdlci;
958 - struct sk_buff *skb;
960 - urb->dev = hfc->dev; /* security init */
961 - if ((!fifo->active) || (urb->status)) {
962 - hfc->service_request &= ~fifo->fifo_mask; /* no further handling */
963 - hfc->active_fifos &= ~fifo->fifo_mask; /* we are inactive */
964 - fifo->urb.interval = 0; /* cancel automatic rescheduling */
966 - dev_kfree_skb_any(fifo->buff);
970 + for(i = 0; i < 2; i++)
972 + if(fifo->iso[i].purb)
974 +#ifdef VERBOSE_USB_DEBUG
975 + printk(KERN_INFO "HFC-USB: Stopping iso chain for fifo %i.%i\n", fifo->fifonum, i);
977 + usb_unlink_urb(fifo->iso[i].purb);
978 + usb_free_urb(fifo->iso[i].purb);
979 + fifo->iso[i].purb = NULL;
984 + usb_unlink_urb(fifo->urb);
985 + usb_free_urb(fifo->urb);
991 - /* first check for any status changes */
992 - if ((urb->actual_length < fifo->rx_offset)
993 - || (urb->actual_length > fifo->usb_maxlen))
994 - return; /* error condition */
996 - if (fifo->rx_offset) {
997 - hfc->threshold_mask = fifo->buffer[1]; /* update threshold status */
998 - fifo->next_complete = fifo->buffer[0] & 1;
999 - if ((fifo->fifonum == HFCUSB_D_RX) &&
1000 - (hfc->led_req != hfc->led_act))
1001 - queue_control_request(hfc, HFCUSB_P_DATA, hfc->led_req);
1003 - /* check if rescheduling needed */
1005 - hfc->service_request & hfc->active_fifos & ~hfc->
1006 - threshold_mask)) {
1008 - usb_get_current_frame_number(hfc->dev);
1009 - txfifo = hfc->fifos + HFCUSB_B1_TX;
1012 - if ((i & txfifo->fifo_mask)
1013 - && (currcnt != txfifo->framenum)) {
1014 - hfc->service_request &=
1015 - ~txfifo->fifo_mask;
1016 - if (!txfifo->buff)
1017 - fill_tx_urb(txfifo);
1019 - usb_submit_urb(&txfifo->
1021 +// defines how much ISO packets are handled in one URB
1022 +static int iso_packets[8]={ISOC_PACKETS_B,ISOC_PACKETS_B,ISOC_PACKETS_B,ISOC_PACKETS_B,
1023 + ISOC_PACKETS_D,ISOC_PACKETS_D,ISOC_PACKETS_D,ISOC_PACKETS_D};
1025 +/*****************************************************/
1026 +/* transmit completion routine for all ISO tx fifos */
1027 +/*****************************************************/
1028 +static void tx_iso_complete(struct urb *urb)
1030 + iso_urb_struct *context_iso_urb = (iso_urb_struct *) urb->context;
1031 + usb_fifo *fifo = context_iso_urb->owner_fifo;
1032 + hfcusb_data *hfc = fifo->hfc;
1033 + int k, tx_offset, num_isoc_packets, sink, len, current_len,errcode,frame_complete,transp_mode,fifon;
1035 + __u8 threshtable[8] = { 1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1037 + fifon=fifo->fifonum;
1039 + // very weird error code when using ohci drivers, for now : ignore this error ... (MB)
1040 + if(urb->status == -EOVERFLOW)
1043 +#ifdef VERBOSE_USB_DEBUG
1044 + printk(KERN_INFO "HFC-USB: ignoring USB DATAOVERRUN for fifo %i \n",fifon);
1048 + if(fifo->active && !urb->status)
1051 + if(fifon<4 && hfc->b_mode[fifon/2]==L1_MODE_TRANS) transp_mode=TRUE;
1053 + threshbit = threshtable[fifon] & hfc->threshold_mask; // is threshold set for our channel?
1054 + num_isoc_packets=iso_packets[fifon];
1056 + if(fifon >= HFCUSB_D_TX)
1058 + sink = (threshbit) ? SINK_DMIN : SINK_DMAX; // how much bit go to the sink for D-channel?
1062 + sink = (threshbit) ? SINK_MIN : SINK_MAX; // how much bit go to the sink for B-channel?
1065 + // prepare ISO Urb
1066 + fill_isoc_urb(urb, fifo->hfc->dev, fifo->pipe,context_iso_urb->buffer, num_isoc_packets,
1067 + fifo->usb_packet_maxlen, fifo->intervall, tx_iso_complete, urb->context);
1068 + memset(context_iso_urb->buffer, 0, sizeof(context_iso_urb->buffer));
1070 + frame_complete=FALSE;
1072 + // Generate Iso Packets
1073 + for(k = 0; k < num_isoc_packets; ++k)
1077 + len = fifo->skbuff->len; // remaining length
1079 + fifo->bit_line -= sink; // we lower data margin every msec
1080 + current_len = (0 - fifo->bit_line) / 8;
1081 + if(current_len > 14) current_len = 14; // maximum 15 byte for every ISO packet makes our life easier
1082 + current_len = (len <= current_len) ? len : current_len;
1083 + fifo->bit_line += current_len * 8; // how much bit do we put on the line?
1085 + context_iso_urb->buffer[tx_offset] = 0;
1086 + if(current_len == len)
1090 + context_iso_urb->buffer[tx_offset] = 1; // here frame completion
1091 + fifo->bit_line += 32; // add 2 byte flags and 16bit CRC at end of ISDN frame
1093 + frame_complete = TRUE;
1096 + // copy bytes from buffer into ISO_URB
1097 + memcpy(context_iso_urb->buffer+tx_offset+1,fifo->skbuff->data,current_len);
1098 + skb_pull(fifo->skbuff,current_len);
1100 + // define packet delimeters within the URB buffer
1101 + urb->iso_frame_desc[k].offset = tx_offset;
1102 + urb->iso_frame_desc[k].length = current_len + 1;
1104 + tx_offset += (current_len + 1);
1105 + // 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);
1108 + if(fifon==HFCUSB_B1_TX) handle_led(hfc,LED_B1_DATA);
1109 + if(fifon==HFCUSB_B2_TX) handle_led(hfc,LED_B2_DATA);
1114 + // we have no more data - generate 1 byte ISO packets
1115 + urb->iso_frame_desc[k].offset = tx_offset++;
1117 + urb->iso_frame_desc[k].length = 1;
1118 + fifo->bit_line -= sink; // we lower data margin every msec
1120 + if(fifo->bit_line < BITLINE_INF)
1122 + fifo->bit_line = BITLINE_INF;
1123 + //printk (KERN_INFO "HFC-USB: BITLINE_INF underrun\n");
1129 - /* handle l1 events */
1130 - if ((fifo->buffer[0] >> 4) != hfc->l1_state) {
1131 - last_state = hfc->l1_state;
1132 - hfc->l1_state = fifo->buffer[0] >> 4; /* update status */
1133 - if (timer_pending(&hfc->t4_timer))
1134 - del_timer(&hfc->t4_timer);
1135 - if (((hfc->l1_state == 3) &&
1136 - ((last_state == 7) ||
1137 - (last_state == 8))) ||
1138 - ((timer_pending(&hfc->t3_timer) &&
1139 - (hfc->l1_state == 8)))) {
1140 - hfc->t4_timer.expires = jiffies + 2;
1141 - add_timer(&hfc->t4_timer);
1143 - if (timer_pending(&hfc->t3_timer)
1144 - && (hfc->l1_state == 7))
1145 - del_timer(&hfc->t3_timer); /* no longer needed */
1146 - test_and_set_bit(HFCUSB_L1_STATECHANGE,
1148 - queue_task(&hfc->l1_tq, &tq_immediate);
1149 - mark_bh(IMMEDIATE_BH);
1150 + if(frame_complete)
1152 + // delete the buffer only once, here or in hfc_usb_l2l1() in a PH_DATA|REQUEST
1153 + fifo->delete_flg=TRUE;
1155 + fifo->hif->l1l2(fifo->hif,PH_DATA|CONFIRM,(void*)fifo->skbuff->truesize);
1157 + if(fifo->skbuff && fifo->delete_flg)
1159 + dev_kfree_skb_any(fifo->skbuff);
1160 + //printk(KERN_INFO "HFC-USB: skbuff=NULL on fifo:%d\n",fifo->fifonum);
1161 + fifo->skbuff = NULL;
1162 + fifo->delete_flg=FALSE;
1165 + frame_complete=FALSE;
1169 + errcode = usb_submit_urb(urb);
1172 + printk(KERN_INFO "HFC-USB: error submitting ISO URB: %i \n", errcode);
1179 + printk(KERN_INFO "HFC-USB: tx_iso_complete : urb->status %i, fifonum %i\n", urb->status,fifon);
1183 - /* check the length for data and move if present */
1184 - if (fifo->next_complete || (urb->actual_length > fifo->rx_offset)) {
1185 - i = fifo->buff->len + urb->actual_length - fifo->rx_offset; /* new total length */
1186 - hdlci = (fifo->transmode) ? 0 : 3;
1187 - if (i <= (fifo->max_size + hdlci)) {
1188 - memcpy(fifo->act_ptr,
1189 - fifo->buffer + fifo->rx_offset,
1190 - urb->actual_length - fifo->rx_offset);
1192 - (urb->actual_length - fifo->rx_offset);
1193 - fifo->buff->len +=
1194 - (urb->actual_length - fifo->rx_offset);
1196 - fifo->buff->len = fifo->max_size + 4; /* mark frame as to long */
1197 - if (fifo->next_complete && (urb->actual_length < fifo->usb_maxlen)) {
1198 - /* the frame is complete */
1199 - fifo->next_complete = 0;
1200 - if (((!*(fifo->act_ptr - 1)) || fifo->transmode) &&
1201 - (fifo->buff->len >= (hdlci + 1))
1202 - && (fifo->buff->len <=
1203 - (fifo->max_size + hdlci)) &&
1204 - ((skb = dev_alloc_skb(fifo->max_size + hdlci)) != NULL)) {
1205 - fifo->buff->len -= hdlci; /* adjust size */
1206 - switch (fifo->fifonum) {
1208 - skb_queue_tail(hfc->regd.
1214 - queue_task(&hfc->l1_tq,
1216 - mark_bh(IMMEDIATE_BH);
1218 +} /* tx_iso_complete */
1220 - case HFCUSB_B1_RX:
1221 - if (hfc->regd.brq[0]) {
1242 - case HFCUSB_B2_RX:
1243 - if (hfc->regd.brq[1]) {
1264 +/*****************************************************/
1265 +/* receive completion routine for all ISO tx fifos */
1266 +/*****************************************************/
1267 +static void rx_iso_complete(struct urb *urb)
1269 + iso_urb_struct *context_iso_urb = (iso_urb_struct *) urb->context;
1270 + usb_fifo *fifo = context_iso_urb->owner_fifo;
1271 + hfcusb_data *hfc = fifo->hfc;
1272 + int k, len, errcode, offset, num_isoc_packets,fifon;
1275 - case HFCUSB_PCM_RX:
1276 - skb_queue_tail(&hfc->regd.
1282 - queue_task(&hfc->l1_tq,
1284 - mark_bh(IMMEDIATE_BH);
1286 + fifon=fifo->fifonum;
1287 + // very weird error code when using ohci drivers, for now : ignore this error ... (MB)
1288 + if(urb->status == -EOVERFLOW)
1291 +#ifdef VERBOSE_USB_DEBUG
1292 + printk(KERN_INFO "HFC-USB: ignoring USB DATAOVERRUN for fifo %i \n",fifon);
1297 - dev_kfree_skb_any(fifo->
1300 + if(fifo->active && !urb->status)
1302 + num_isoc_packets=iso_packets[fifon];
1304 + // Generate D-Channel Iso Packets
1305 + for(k = 0; k < num_isoc_packets; ++k)
1307 + len=urb->iso_frame_desc[k].actual_length;
1308 + offset=urb->iso_frame_desc[k].offset;
1309 + buf=context_iso_urb->buffer+offset;
1311 + if(fifo->last_urblen!=fifo->usb_packet_maxlen)
1313 + // the threshold mask is in the 2nd status byte
1314 + hfc->threshold_mask=buf[1];
1315 + // the S0 state is in the upper half of the 1st status byte
1316 + state_handler(hfc,buf[0] >> 4);
1317 + // if we have more than the 2 status bytes -> collect data
1318 + if(len>2) collect_rx_frame(fifo,buf+2,len-2,buf[0]&1);
1322 - fifo->buff->len = 0; /* reset counter */
1323 - fifo->act_ptr = fifo->buff->data; /* and pointer */
1324 + else collect_rx_frame(fifo,buf,len,0);
1326 + fifo->last_urblen=len;
1330 + // prepare ISO Urb
1331 + fill_isoc_urb(urb, fifo->hfc->dev, fifo->pipe,context_iso_urb->buffer, num_isoc_packets,
1332 + fifo->usb_packet_maxlen, fifo->intervall, rx_iso_complete, urb->context);
1334 + errcode = usb_submit_urb(urb);
1337 + printk(KERN_INFO "HFC-USB: error submitting ISO URB: %i \n", errcode);
1344 + printk(KERN_INFO "HFC-USB: rx_iso_complete : urb->status %i, fifonum %i\n", urb->status,fifon);
1347 +} /* rx_iso_complete */
1350 +/*****************************************************/
1351 +/* collect data from interrupt or isochron in */
1352 +/*****************************************************/
1353 +static void collect_rx_frame(usb_fifo *fifo,__u8 *data,int len,int finish)
1355 + hfcusb_data *hfc = fifo->hfc;
1356 + int transp_mode,fifon;
1358 + fifon=fifo->fifonum;
1360 + if(fifon<4 && hfc->b_mode[fifon/2]==L1_MODE_TRANS) transp_mode=TRUE;
1362 + //printk(KERN_INFO "HFC-USB: got %d bytes finish:%d max_size:%d fifo:%d\n",len,finish,fifo->max_size,fifon);
1365 + // allocate sk buffer
1366 + fifo->skbuff=dev_alloc_skb(fifo->max_size + 3);
1369 + printk(KERN_INFO "HFC-USB: cannot allocate buffer (dev_alloc_skb) fifo:%d\n",fifon);
1375 + if(len && fifo->skbuff->len+len<fifo->max_size)
1377 + memcpy(skb_put(fifo->skbuff,len),data,len);
1379 + else printk(KERN_INFO "HCF-USB: got frame exceeded fifo->max_size:%d\n",fifo->max_size);
1381 + // give transparent data up, when 128 byte are available
1382 + if(transp_mode && fifo->skbuff->len>=128)
1384 + fifo->hif->l1l2(fifo->hif,PH_DATA | INDICATION,fifo->skbuff);
1385 + fifo->skbuff = NULL; // buffer was freed from upper layer
1389 + // we have a complete hdlc packet
1392 + if(!fifo->skbuff->data[fifo->skbuff->len-1])
1394 + skb_trim(fifo->skbuff,fifo->skbuff->len-3); // remove CRC & status
1396 + //printk(KERN_INFO "HFC-USB: got frame %d bytes on fifo:%d\n",fifo->skbuff->len,fifon);
1398 + if(fifon==HFCUSB_PCM_RX) fifo->hif->l1l2(fifo->hif,PH_DATA_E | INDICATION,fifo->skbuff);
1399 + else fifo->hif->l1l2(fifo->hif,PH_DATA | INDICATION,fifo->skbuff);
1401 + fifo->skbuff = NULL; // buffer was freed from upper layer
1405 + printk(KERN_INFO "HFC-USB: got frame %d bytes but CRC ERROR!!!\n",fifo->skbuff->len);
1407 + skb_trim(fifo->skbuff,0); // clear whole buffer
1411 + // LED flashing only in HDLC mode
1414 + if(fifon==HFCUSB_B1_RX) handle_led(hfc,LED_B1_DATA);
1415 + if(fifon==HFCUSB_B2_RX) handle_led(hfc,LED_B2_DATA);
1419 +/***********************************************/
1420 +/* receive completion routine for all rx fifos */
1421 +/***********************************************/
1422 +static void rx_complete(struct urb *urb)
1426 + usb_fifo *fifo = (usb_fifo *) urb->context; /* pointer to our fifo */
1427 + hfcusb_data *hfc = fifo->hfc;
1429 + urb->dev = hfc->dev; /* security init */
1431 + if((!fifo->active) || (urb->status)) {
1432 +#ifdef VERBOSE_USB_DEBUG
1433 + printk(KERN_INFO "HFC-USB: RX-Fifo %i is going down (%i)\n", fifo->fifonum, urb->status);
1435 + fifo->urb->interval = 0; /* cancel automatic rescheduling */
1436 + if(fifo->skbuff) {
1437 + dev_kfree_skb_any(fifo->skbuff);
1438 + fifo->skbuff = NULL;
1442 - fifo->rx_offset = (urb->actual_length < fifo->usb_maxlen) ? 2 : 0;
1443 -} /* rx_complete */
1445 + len=urb->actual_length;
1448 + if(fifo->last_urblen!=fifo->usb_packet_maxlen) {
1449 + // the threshold mask is in the 2nd status byte
1450 + hfc->threshold_mask=buf[1];
1451 + // the S0 state is in the upper half of the 1st status byte
1452 + state_handler(hfc,buf[0] >> 4);
1453 + // if we have more than the 2 status bytes -> collect data
1454 + if(len>2) collect_rx_frame(fifo,buf+2,urb->actual_length-2,buf[0]&1);
1456 + collect_rx_frame(fifo,buf,urb->actual_length,0);
1458 + fifo->last_urblen=urb->actual_length;
1461 +} /* rx_complete */
1465 /***************************************************/
1466 /* start the interrupt transfer for the given fifo */
1467 /***************************************************/
1469 -start_rx_fifo(usb_fifo * fifo)
1470 +static void start_int_fifo(usb_fifo * fifo)
1473 - return; /* still active */
1476 - dev_alloc_skb(fifo->max_size + (fifo->transmode ? 0 : 3))))
1478 - fifo->act_ptr = fifo->buff->data;
1479 - FILL_INT_URB(&fifo->urb, fifo->hfc->dev, fifo->pipe, fifo->buffer,
1480 - fifo->usb_maxlen, rx_complete, fifo, fifo->intervall);
1481 - fifo->next_complete = 0;
1482 - fifo->rx_offset = 2;
1483 - fifo->active = 1; /* must be marked active */
1484 - fifo->hfc->active_fifos |= fifo->fifo_mask;
1485 - if (usb_submit_urb(&fifo->urb)) {
1488 +#ifdef VERBOSE_USB_DEBUG
1489 + printk(KERN_INFO "HFC-USB: starting intr IN fifo:%d\n", fifo->fifonum);
1492 + fifo->urb = usb_alloc_urb(0);
1496 + usb_fill_int_urb(fifo->urb, fifo->hfc->dev, fifo->pipe, fifo->buffer,
1497 + fifo->usb_packet_maxlen, rx_complete, fifo, fifo->intervall);
1498 + fifo->active = 1; /* must be marked active */
1499 + errcode = usb_submit_urb(fifo->urb);
1503 + printk(KERN_INFO "HFC-USB: submit URB error(start_int_info): status:%i\n", errcode);
1505 - fifo->hfc->active_fifos &= ~fifo->fifo_mask;
1506 - dev_kfree_skb_any(fifo->buff);
1507 - fifo->buff = NULL;
1508 + fifo->skbuff = NULL;
1510 -} /* start_rx_fifo */
1511 +} /* start_int_fifo */
1513 -/***************************************************************/
1514 -/* control completion routine handling background control cmds */
1515 -/***************************************************************/
1517 -ctrl_complete(purb_t urb)
1518 +/*****************************/
1519 +/* set the B-channel mode */
1520 +/*****************************/
1521 +static void set_hfcmode(hfcusb_data *hfc,int channel,int mode)
1523 - hfcusb_data *hfc = (hfcusb_data *) urb->context;
1524 + __u8 val,idx_table[2]={0,2};
1526 - urb->dev = hfc->dev;
1527 - if (hfc->ctrl_cnt) {
1528 - switch (hfc->ctrl_buff[hfc->ctrl_out_idx].hfc_reg) {
1531 - hfc->ctrl_buff[hfc->ctrl_out_idx].
1534 - case HFCUSB_F_USAGE:
1535 - if (!hfc->dfifo_fill) {
1536 - fill_tx_urb(hfc->fifos +
1538 - if (hfc->fifos[HFCUSB_D_TX].buff)
1539 - usb_submit_urb(&hfc->
1544 - queue_control_request(hfc,
1547 - queue_control_request(hfc,
1552 - case HFCUSB_SCTRL_R:
1553 - switch (hfc->ctrl_fifo) {
1554 - case HFCUSB_B1_RX:
1555 - if (hfc->bch_enables & 1)
1556 - start_rx_fifo(hfc->
1561 - case HFCUSB_B2_RX:
1562 - if (hfc->bch_enables & 2)
1563 - start_rx_fifo(hfc->
1569 - if (hfc->bch_enables & 3)
1570 - hfc->led_req |= LED_BCH;
1572 - hfc->led_req &= ~LED_BCH;
1574 - case HFCUSB_P_DATA:
1576 - hfc->ctrl_buff[hfc->ctrl_out_idx].
1580 - hfc->ctrl_cnt--; /* decrement actual count */
1581 - if (++hfc->ctrl_out_idx >= HFC_CTRL_BUFSIZE)
1582 - hfc->ctrl_out_idx = 0; /* pointer wrap */
1583 - ctrl_start_transfer(hfc); /* start next transfer */
1584 +#ifdef VERBOSE_ISDN_DEBUG
1585 + printk (KERN_INFO "HFC-USB: setting channel %d to mode %d\n",channel,mode);
1588 + hfc->b_mode[channel]=mode;
1592 + if(mode!=L1_MODE_NULL) val=8; // enable fifo?
1593 + if(mode==L1_MODE_TRANS) val|=2; // set transparent bit
1595 + queue_control_request(hfc,HFCUSB_FIFO,idx_table[channel],1); // set FIFO to transmit register
1596 + queue_control_request(hfc,HFCUSB_CON_HDLC,val,1);
1597 + queue_control_request(hfc,HFCUSB_INC_RES_F,2,1); // reset fifo
1599 + queue_control_request(hfc,HFCUSB_FIFO,idx_table[channel]+1,1); // set FIFO to receive register
1600 + queue_control_request(hfc,HFCUSB_CON_HDLC,val,1);
1601 + queue_control_request(hfc,HFCUSB_INC_RES_F,2,1); // reset fifo
1604 + if(hfc->b_mode[0]) val|=1;
1605 + if(hfc->b_mode[1]) val|=2;
1606 + queue_control_request(hfc,HFCUSB_SCTRL,val,1);
1609 + if(hfc->b_mode[0]) val|=1;
1610 + if(hfc->b_mode[1]) val|=2;
1611 + queue_control_request(hfc,HFCUSB_SCTRL_R,val,1);
1613 + if(mode==L1_MODE_NULL)
1615 + if(channel) handle_led(hfc,LED_B2_OFF);
1616 + else handle_led(hfc,LED_B1_OFF);
1618 -} /* ctrl_complete */
1621 + if(channel) handle_led(hfc,LED_B2_ON);
1622 + else handle_led(hfc,LED_B1_ON);
1626 -/*****************************************/
1627 -/* Layer 1 + D channel access from HiSax */
1628 -/*****************************************/
1630 -hfcusb_l1_access(void *drvarg, int pr, void *arg)
1632 - hfcusb_data *hfc = (hfcusb_data *) drvarg;
1635 - case (PH_DATA | REQUEST):
1636 - case (PH_PULL | INDICATION):
1637 - skb_queue_tail(hfc->regd.dsq,
1638 - (struct sk_buff *) arg);
1639 - if (!hfc->fifos[HFCUSB_D_TX].active
1640 - && !hfc->dfifo_fill) {
1641 - fill_tx_urb(hfc->fifos + HFCUSB_D_TX);
1642 - hfc->active_fifos |=
1643 - hfc->fifos[HFCUSB_D_TX].fifo_mask;
1644 - usb_submit_urb(&hfc->fifos[HFCUSB_D_TX].
1648 - case (PH_ACTIVATE | REQUEST):
1649 - switch (hfc->l1_state) {
1652 - hfc->regd.dch_l1l2(hfc->regd.arg_hisax,
1654 - INDICATION), NULL);
1656 + --------------------------------------------------------------------------------------
1657 + from here : hisax_if callback routines :
1658 + - void hfc_usb_d_l2l1(struct hisax_if *hisax_d_if, int pr, void *arg) {
1662 - hfc->regd.dch_l1l2(hfc->regd.arg_hisax,
1664 - INDICATION), NULL);
1665 + l1 to l2 routines :
1666 + - static void hfc_usb_l1l2(hfcusb_data * hfc)
1670 - queue_control_request(hfc, HFCUSB_STATES, 0x60); /* start activation */
1671 - hfc->t3_timer.expires =
1672 - jiffies + (HFC_TIMER_T3 * HZ) / 1000;
1673 - if (!timer_pending(&hfc->t3_timer))
1674 - add_timer(&hfc->t3_timer);
1680 - case (PH_DEACTIVATE | REQUEST):
1681 - queue_control_request(hfc, HFCUSB_STATES, 0x40); /* start deactivation */
1684 - printk(KERN_INFO "unknown hfcusb l1_access 0x%x\n",
1688 -} /* hfcusb_l1_access */
1690 -/*******************************/
1691 -/* B channel access from HiSax */
1692 -/*******************************/
1694 -hfcusb_bch_access(void *drvarg, int chan, int pr, void *arg)
1696 - hfcusb_data *hfc = (hfcusb_data *) drvarg;
1697 - usb_fifo *fifo = hfc->fifos + (chan ? HFCUSB_B2_TX : HFCUSB_B1_TX);
1701 - case (PH_DATA | REQUEST):
1702 - case (PH_PULL | INDICATION):
1703 - save_flags(flags);
1705 - if (!fifo->active) {
1706 - fill_tx_urb(fifo);
1707 - hfc->active_fifos |= fifo->fifo_mask;
1708 - usb_submit_urb(&fifo->urb);
1710 - restore_flags(flags);
1712 - case (PH_ACTIVATE | REQUEST):
1713 - if (!((int) arg)) {
1714 - hfc->bch_enables &= ~(1 << chan);
1715 - if (fifo->active) {
1717 - usb_unlink_urb(&fifo->urb);
1718 +void hfc_usb_l2l1(struct hisax_if *my_hisax_if, int pr, void *arg)
1720 + usb_fifo *fifo = my_hisax_if->priv;
1721 + hfcusb_data *hfc = fifo->hfc;
1724 + case PH_ACTIVATE | REQUEST:
1725 + if(fifo->fifonum==HFCUSB_D_TX)
1727 +#ifdef VERBOSE_ISDN_DEBUG
1728 + printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_ACTIVATE | REQUEST\n");
1730 + queue_control_request(hfc, HFCUSB_STATES,0x60,1); /* make activation */
1731 + hfc->t3_timer.expires = jiffies + (HFC_TIMER_T3 * HZ) / 1000;
1732 + if(!timer_pending(&hfc->t3_timer)) add_timer(&hfc->t3_timer);
1734 - save_flags(flags);
1736 - queue_control_request(hfc, HFCUSB_FIFO,
1738 - queue_control_request(hfc,
1739 - HFCUSB_INC_RES_F, 2);
1740 - queue_control_request(hfc, HFCUSB_CON_HDLC,
1742 - queue_control_request(hfc, HFCUSB_SCTRL,
1744 - hfc->bch_enables);
1745 - queue_control_request(hfc, HFCUSB_SCTRL_R,
1746 - hfc->bch_enables);
1747 - restore_flags(flags);
1749 - if (fifo->active) {
1751 - usb_unlink_urb(&fifo->urb);
1754 +#ifdef VERBOSE_ISDN_DEBUG
1755 + printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_ACTIVATE | REQUEST\n");
1757 + set_hfcmode(hfc,(fifo->fifonum==HFCUSB_B1_TX) ? 0 : 1 ,(int)arg);
1758 + fifo->hif->l1l2(fifo->hif,PH_ACTIVATE | INDICATION, NULL);
1760 - return; /* fifo deactivated */
1762 - fifo->transmode = ((int) arg == L1_MODE_TRANS);
1764 - ((fifo->transmode) ? fifo->
1765 - usb_maxlen : MAX_BCH_SIZE);
1766 - (fifo + 1)->transmode = fifo->transmode;
1767 - (fifo + 1)->max_size = fifo->max_size;
1768 - hfc->bch_enables |= (1 << chan);
1769 - save_flags(flags);
1771 - queue_control_request(hfc, HFCUSB_FIFO,
1773 - queue_control_request(hfc, HFCUSB_CON_HDLC,
1775 - transmode) ? 9 : 11));
1776 - queue_control_request(hfc, HFCUSB_INC_RES_F, 2);
1777 - queue_control_request(hfc, HFCUSB_SCTRL,
1778 - 0x40 + hfc->bch_enables);
1779 - if ((int) arg == L1_MODE_HDLC)
1780 - queue_control_request(hfc, HFCUSB_CON_HDLC,
1782 - queue_control_request(hfc, HFCUSB_FIFO,
1783 - fifo->fifonum + 1);
1784 - queue_control_request(hfc, HFCUSB_CON_HDLC,
1786 - transmode) ? 8 : 10));
1787 - queue_control_request(hfc, HFCUSB_INC_RES_F, 2);
1788 - queue_control_request(hfc, HFCUSB_SCTRL_R,
1789 - hfc->bch_enables);
1790 - restore_flags(flags);
1796 - "unknown hfcusb bch_access chan %d 0x%x\n",
1800 -} /* hfcusb_bch_access */
1802 + case PH_DEACTIVATE | REQUEST:
1803 + if(fifo->fifonum==HFCUSB_D_TX)
1805 +#ifdef VERBOSE_ISDN_DEBUG
1806 + printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_DEACTIVATE | REQUEST\n");
1808 + printk (KERN_INFO "HFC-USB: ISDN TE device should not deativate...\n");
1812 +#ifdef VERBOSE_ISDN_DEBUG
1813 + printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_DEACTIVATE | REQUEST\n");
1815 + set_hfcmode(hfc,(fifo->fifonum==HFCUSB_B1_TX) ? 0 : 1 ,(int)L1_MODE_NULL);
1816 + fifo->hif->l1l2(fifo->hif,PH_DEACTIVATE | INDICATION, NULL);
1819 + case PH_DATA | REQUEST:
1820 + if(fifo->skbuff && fifo->delete_flg)
1822 + dev_kfree_skb_any(fifo->skbuff);
1823 + //printk(KERN_INFO "skbuff=NULL on fifo:%d\n",fifo->fifonum);
1824 + fifo->skbuff = NULL;
1825 + fifo->delete_flg=FALSE;
1828 + fifo->skbuff=arg; // we have a new buffer
1830 + //if(fifo->fifonum==HFCUSB_D_TX) printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_DATA | REQUEST\n");
1831 + //else printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_DATA | REQUEST\n");
1834 + printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1: unkown state : %#x\n", pr);
1839 +// valid configurations
1840 +#define CNF_4INT3ISO 1 // 4 INT IN, 3 ISO OUT
1841 +#define CNF_3INT3ISO 2 // 3 INT IN, 3 ISO OUT
1842 +#define CNF_4ISO3ISO 3 // 4 ISO IN, 3 ISO OUT
1843 +#define CNF_3ISO3ISO 4 // 3 ISO IN, 3 ISO OUT
1847 + --------------------------------------------------------------------------------------
1848 + From here on USB initialization and deactivation related routines are implemented :
1851 + is the main Entry Point for the USB Subsystem when the device get plugged
1852 + in. This function calls usb_register with usb_driver as parameter.
1853 + Here, further entry points for probing (hfc_usb_probe) and disconnecting
1854 + the device (hfc_usb_disconnect) are published, as the id_table
1857 + this function is called by the usb subsystem, and steps through the alternate
1858 + settings of the currently plugged in device to detect all Endpoints needed to
1860 + Needed EndPoints are
1861 + 3 (+1) IntIn EndPoints (D-in, E-in, B1-in, B2-in, (E-in)) or
1862 + 3 (+1) Isochron In Endpoints (D-out, B1-out, B2-out) and 3 IsoOut Endpoints
1863 + The currently used transfer mode of on the Out-Endpoints will be stored in
1864 + hfc->usb_transfer_mode and is either USB_INT or USB_ISO
1865 + When a valid alternate setting could be found, the usb_init (see blow)
1866 + function is called
1869 + Here, the HFC_USB Chip itself gets initialized and the USB framework to send/receive
1870 + Data to/from the several EndPoints are initialized:
1871 + The E- and D-Channel Int-In chain gets started
1872 + The IsoChain for the Iso-Out traffic get started
1874 + - hfc_usb_disconnect
1875 + this function is called by the usb subsystem and has to free all resources
1876 + and stop all usb traffic to allow a proper hotplugging disconnect.
1880 /***************************************************************************/
1881 /* usb_init is called once when a new matching device is detected to setup */
1882 -/* main parmeters. It registers the driver at the main hisax module. */
1883 +/* main parameters. It registers the driver at the main hisax module. */
1884 /* on success 0 is returned. */
1885 /***************************************************************************/
1887 -usb_init(hfcusb_data * hfc)
1888 +static int usb_init(hfcusb_data * hfc)
1895 + struct hisax_b_if *p_b_if[2];
1897 /* check the chip id */
1898 - if ((Read_hfc(hfc, HFCUSB_CHIP_ID, &b) != 1) ||
1899 - (b != HFCUSB_CHIPID)) {
1900 + printk(KERN_INFO "HFCUSB_CHIP_ID begin\n");
1901 + if (read_usb(hfc, HFCUSB_CHIP_ID, &b) != 1) {
1902 + printk(KERN_INFO "HFC-USB: cannot read chip id\n");
1905 + printk(KERN_INFO "HFCUSB_CHIP_ID %x\n", b);
1906 + if (b != HFCUSB_CHIPID) {
1907 printk(KERN_INFO "HFC-USB: Invalid chip id 0x%02x\n", b);
1912 /* first set the needed config, interface and alternate */
1913 - usb_set_configuration(hfc->dev, 1);
1914 - usb_set_interface(hfc->dev, hfc->if_used, hfc->alt_used);
1915 + printk(KERN_INFO "usb_init 1\n");
1916 +// usb_set_configuration(hfc->dev, 1);
1917 + printk(KERN_INFO "usb_init 2\n");
1918 + err = usb_set_interface(hfc->dev, hfc->if_used, hfc->alt_used);
1919 + printk(KERN_INFO "usb_init usb_set_interface return %d\n", err);
1920 + /* now we initialize the chip */
1921 + write_usb(hfc, HFCUSB_CIRM, 8); // do reset
1922 + write_usb(hfc, HFCUSB_CIRM, 0x10); // aux = output, reset off
1924 - /* init the led state request */
1925 - hfc->led_req = LED_DRIVER;
1926 + // set USB_SIZE to match the the wMaxPacketSize for INT or BULK transfers
1927 + write_usb(hfc, HFCUSB_USB_SIZE,(hfc->packet_size/8) | ((hfc->packet_size/8) << 4));
1929 - /* now we initialise the chip */
1930 - Write_hfc(hfc, HFCUSB_CIRM, 0x10); /* aux = output, reset off */
1931 - Write_hfc(hfc, HFCUSB_P_DATA, 0); /* leds = off */
1932 - Write_hfc(hfc, HFCUSB_USB_SIZE,
1933 - (hfc->fifos[HFCUSB_B1_TX].usb_maxlen >> 3) |
1934 - ((hfc->fifos[HFCUSB_B1_RX].usb_maxlen >> 3) << 4));
1935 + // set USB_SIZE_I to match the the wMaxPacketSize for ISO transfers
1936 + write_usb(hfc, HFCUSB_USB_SIZE_I, hfc->iso_packet_size);
1938 /* enable PCM/GCI master mode */
1939 - Write_hfc(hfc, HFCUSB_MST_MODE1, 0); /* set default values */
1940 - Write_hfc(hfc, HFCUSB_MST_MODE0, 1); /* enable master mode */
1941 + write_usb(hfc, HFCUSB_MST_MODE1, 0); /* set default values */
1942 + write_usb(hfc, HFCUSB_MST_MODE0, 1); /* enable master mode */
1944 /* init the fifos */
1945 - Write_hfc(hfc, HFCUSB_F_THRES, (HFCUSB_TX_THRESHOLD >> 3) |
1946 - ((HFCUSB_RX_THRESHOLD >> 3) << 4));
1947 + write_usb(hfc, HFCUSB_F_THRES, (HFCUSB_TX_THRESHOLD/8) |((HFCUSB_RX_THRESHOLD/8) << 4));
1949 - for (i = 0, fifo = hfc->fifos + i; i < HFCUSB_NUM_FIFOS;
1951 - Write_hfc(hfc, HFCUSB_FIFO, i); /* select the desired fifo */
1953 - fifo->transmode = 0; /* hdlc mode selected */
1954 - fifo->buff = NULL; /* init buffer pointer */
1956 - (i <= HFCUSB_B2_RX) ? MAX_BCH_SIZE : MAX_DFRAME_LEN;
1957 - Write_hfc(hfc, HFCUSB_HDLC_PAR, ((i <= HFCUSB_B2_RX) ? 0 : 2)); /* data length */
1958 - Write_hfc(hfc, HFCUSB_CON_HDLC, ((i & 1) ? 0x08 : 0x09)); /* rx hdlc, tx fill 1 */
1959 - Write_hfc(hfc, HFCUSB_INC_RES_F, 2); /* reset the fifo */
1962 - Write_hfc(hfc, HFCUSB_CLKDEL, 0x0f); /* clock delay value */
1963 - Write_hfc(hfc, HFCUSB_STATES, 3 | 0x10); /* set deactivated mode */
1964 - Write_hfc(hfc, HFCUSB_STATES, 3); /* enable state machine */
1965 + fifo = hfc->fifos;
1966 + for(i = 0; i < HFCUSB_NUM_FIFOS; i++)
1968 + write_usb(hfc, HFCUSB_FIFO, i); /* select the desired fifo */
1969 + fifo[i].skbuff = NULL; /* init buffer pointer */
1970 + fifo[i].max_size = (i <= HFCUSB_B2_RX) ? MAX_BCH_SIZE : MAX_DFRAME_LEN;
1971 + fifo[i].last_urblen=0;
1972 + write_usb(hfc, HFCUSB_HDLC_PAR, ((i <= HFCUSB_B2_RX) ? 0 : 2)); // set 2 bit for D- & E-channel
1973 + write_usb(hfc, HFCUSB_CON_HDLC, ((i==HFCUSB_D_TX) ? 0x09 : 0x08)); // rx hdlc, enable IFF for D-channel
1974 + write_usb(hfc, HFCUSB_INC_RES_F, 2); /* reset the fifo */
1977 - Write_hfc(hfc, HFCUSB_SCTRL_R, 0); /* disable both B receivers */
1978 - Write_hfc(hfc, HFCUSB_SCTRL, 0x40); /* disable B transmitters + cap mode */
1979 + write_usb(hfc, HFCUSB_CLKDEL, 0x0f); /* clock delay value */
1980 + write_usb(hfc, HFCUSB_STATES, 3 | 0x10); /* set deactivated mode */
1981 + write_usb(hfc, HFCUSB_STATES, 3); /* enable state machine */
1983 + write_usb(hfc, HFCUSB_SCTRL_R, 0); /* disable both B receivers */
1984 + write_usb(hfc, HFCUSB_SCTRL, 0x40); /* disable B transmitters + capacitive mode */
1986 + // set both B-channel to not connected
1987 + hfc->b_mode[0]=L1_MODE_NULL;
1988 + hfc->b_mode[1]=L1_MODE_NULL;
1990 + hfc->l1_activated=FALSE;
1992 + hfc->led_new_data=0;
1994 - /* init the l1 timer */
1995 + /* init the t3 timer */
1996 init_timer(&hfc->t3_timer);
1997 hfc->t3_timer.data = (long) hfc;
1998 - hfc->t3_timer.function = (void *) l1_timer_expire;
1999 + hfc->t3_timer.function = (void *) l1_timer_expire_t3;
2000 + /* init the t4 timer */
2001 + init_timer(&hfc->t4_timer);
2002 hfc->t4_timer.data = (long) hfc;
2003 - hfc->t4_timer.function = (void *) l1_timer_expire;
2004 - hfc->l1_tq.routine = (void *) (void *) usb_l1d_bh;
2005 - hfc->l1_tq.sync = 0;
2006 - hfc->l1_tq.data = hfc;
2008 - /* init the background control machinery */
2009 - hfc->ctrl_read.requesttype = 0xc0;
2010 - hfc->ctrl_read.request = 1;
2011 - hfc->ctrl_read.length = 1;
2012 - hfc->ctrl_write.requesttype = 0x40;
2013 - hfc->ctrl_write.request = 0;
2014 - hfc->ctrl_write.length = 0;
2015 - FILL_CONTROL_URB(&hfc->ctrl_urb, hfc->dev, hfc->ctrl_out_pipe,
2016 - (u_char *) & hfc->ctrl_write, NULL, 0,
2017 - ctrl_complete, hfc);
2019 - /* init the TX-urbs */
2020 - fifo = hfc->fifos + HFCUSB_D_TX;
2021 - FILL_BULK_URB(&fifo->urb, hfc->dev, fifo->pipe,
2022 - (u_char *) fifo->buffer, 0, tx_complete, fifo);
2023 - fifo = hfc->fifos + HFCUSB_B1_TX;
2024 - FILL_BULK_URB(&fifo->urb, hfc->dev, fifo->pipe,
2025 - (u_char *) fifo->buffer, 0, tx_complete, fifo);
2026 - fifo = hfc->fifos + HFCUSB_B2_TX;
2027 - FILL_BULK_URB(&fifo->urb, hfc->dev, fifo->pipe,
2028 - (u_char *) fifo->buffer, 0, tx_complete, fifo);
2030 - /* init the E-buffer */
2031 - skb_queue_head_init(&hfc->regd.erq);
2033 - /* now register ourself at hisax */
2034 - hfc->regd.version = HISAX_LOAD_VERSION; /* set our version */
2035 - hfc->regd.cmd = HISAX_LOAD_REGISTER; /* register command */
2036 - hfc->regd.argl1 = (void *) hfc; /* argument for our local routine */
2037 - hfc->regd.dch_l2l1 = hfcusb_l1_access;
2038 - hfc->regd.bch_l2l1 = hfcusb_bch_access;
2039 - hfc->regd.drvname = "hfc_usb";
2040 - if (hisax_register_hfcusb(&hfc->regd)) {
2041 - printk(KERN_INFO "HFC-USB failed to register at hisax\n");
2042 - Write_hfc(hfc, HFCUSB_CIRM, 0x08); /* aux = input, reset on */
2046 - /* startup the D- and E-channel fifos */
2047 - start_rx_fifo(hfc->fifos + HFCUSB_D_RX); /* D-fifo */
2048 - if (hfc->fifos[HFCUSB_PCM_RX].pipe)
2049 - start_rx_fifo(hfc->fifos + HFCUSB_PCM_RX); /* E-fifo */
2050 + hfc->t4_timer.function = (void *) l1_timer_expire_t4;
2051 + /* init the led timer */
2052 + init_timer(&hfc->led_timer);
2053 + hfc->led_timer.data = (long) hfc;
2054 + hfc->led_timer.function = (void *) led_timer;
2055 + // trigger 4 hz led timer
2056 + hfc->led_timer.expires = jiffies + (LED_TIME * HZ) / 1000;
2057 + if(!timer_pending(&hfc->led_timer)) add_timer(&hfc->led_timer);
2059 + // init the background machinery for control requests
2060 + hfc->ctrl_read.bRequestType = 0xc0;
2061 + hfc->ctrl_read.bRequest = 1;
2062 + hfc->ctrl_read.wLength = 1;
2063 + hfc->ctrl_write.bRequestType = 0x40;
2064 + hfc->ctrl_write.bRequest = 0;
2065 + hfc->ctrl_write.wLength = 0;
2066 + usb_fill_control_urb(hfc->ctrl_urb, hfc->dev, hfc->ctrl_out_pipe,(u_char *) & hfc->ctrl_write, NULL, 0, ctrl_complete, hfc);
2068 + /* Init All Fifos */
2069 + for(i = 0; i < HFCUSB_NUM_FIFOS; i++)
2071 + hfc->fifos[i].iso[0].purb = NULL;
2072 + hfc->fifos[i].iso[1].purb = NULL;
2073 + hfc->fifos[i].active = 0;
2076 + // register like Germaschewski :
2077 + hfc->d_if.owner = THIS_MODULE;
2078 + hfc->d_if.ifc.priv = &hfc->fifos[HFCUSB_D_TX];
2079 + hfc->d_if.ifc.l2l1 = hfc_usb_l2l1;
2081 + for (i=0; i<2; i++)
2083 + hfc->b_if[i].ifc.priv = &hfc->fifos[HFCUSB_B1_TX+i*2];
2084 + hfc->b_if[i].ifc.l2l1 = hfc_usb_l2l1;
2085 + p_b_if[i] = &hfc->b_if[i];
2088 + hfc->protocol = 2; /* default EURO ISDN, should be a module_param */
2089 + hisax_register(&hfc->d_if, p_b_if, "hfc_usb", hfc->protocol);
2091 + for (i=0; i<4; i++)
2092 + hfc->fifos[i].hif=&p_b_if[i/2]->ifc;
2093 + for (i=4; i<8; i++)
2094 + hfc->fifos[i].hif=&hfc->d_if.ifc;
2096 + // 3 (+1) INT IN + 3 ISO OUT
2097 + if(hfc->cfg_used == CNF_3INT3ISO || hfc->cfg_used == CNF_4INT3ISO)
2099 + start_int_fifo(hfc->fifos + HFCUSB_D_RX); // Int IN D-fifo
2100 + if(hfc->fifos[HFCUSB_PCM_RX].pipe) start_int_fifo(hfc->fifos + HFCUSB_PCM_RX); // E-fifo
2101 + start_int_fifo(hfc->fifos + HFCUSB_B1_RX); // Int IN B1-fifo
2102 + start_int_fifo(hfc->fifos + HFCUSB_B2_RX); // Int IN B2-fifo
2105 + // 3 (+1) ISO IN + 3 ISO OUT
2106 + if(hfc->cfg_used==CNF_3ISO3ISO || hfc->cfg_used==CNF_4ISO3ISO)
2108 + start_isoc_chain(hfc->fifos + HFCUSB_D_RX, ISOC_PACKETS_D, rx_iso_complete,16);
2109 + if(hfc->fifos[HFCUSB_PCM_RX].pipe) start_isoc_chain(hfc->fifos + HFCUSB_PCM_RX, ISOC_PACKETS_D, rx_iso_complete,16);
2110 + start_isoc_chain(hfc->fifos + HFCUSB_B1_RX, ISOC_PACKETS_B, rx_iso_complete,16);
2111 + start_isoc_chain(hfc->fifos + HFCUSB_B2_RX, ISOC_PACKETS_B, rx_iso_complete,16);
2114 + start_isoc_chain(hfc->fifos + HFCUSB_D_TX, ISOC_PACKETS_D, tx_iso_complete,1);
2115 + start_isoc_chain(hfc->fifos + HFCUSB_B1_TX, ISOC_PACKETS_B, tx_iso_complete,1);
2116 + start_isoc_chain(hfc->fifos + HFCUSB_B2_TX, ISOC_PACKETS_B, tx_iso_complete,1);
2118 + handle_led(hfc,LED_POWER_ON);
2124 +/****************************************/
2125 +/* data defining the devices to be used */
2126 +/****************************************/
2127 +// static __devinitdata const struct usb_device_id hfc_usb_idtab[3] = {
2128 +static struct usb_device_id hfc_usb_idtab[] = {
2129 + {USB_DEVICE(0x7b0, 0x0007)}, /* Billion USB TA 2 */
2130 + {USB_DEVICE(0x742, 0x2008)}, /* Stollmann USB TA */
2131 + {USB_DEVICE(0x959, 0x2bd0)}, /* Colognechip USB eval TA */
2132 + {USB_DEVICE(0x8e3, 0x0301)}, /* OliTec ISDN USB */
2133 + {USB_DEVICE(0x675, 0x1688)}, /* DrayTec ISDN USB */
2134 + {USB_DEVICE(0x7fa, 0x0846)}, /* Bewan ISDN USB TA */
2135 + {} /* end with an all-zeroes entry */
2138 +MODULE_AUTHOR("Peter Sprenger (sprenger@moving-byters.de)/Martin Bachem (info@colognechip.com)");
2139 +MODULE_DESCRIPTION("HFC I4L USB driver");
2140 +MODULE_DEVICE_TABLE(usb, hfc_usb_idtab);
2141 +MODULE_LICENSE("GPL");
2143 +#define EP_NUL 1 // Endpoint at this position not allowed
2144 +#define EP_NOP 2 // all type of endpoints allowed at this position
2145 +#define EP_ISO 3 // Isochron endpoint mandatory at this position
2146 +#define EP_BLK 4 // Bulk endpoint mandatory at this position
2147 +#define EP_INT 5 // Interrupt endpoint mandatory at this position
2149 +// this array represents all endpoints possible in the HCF-USB
2150 +// the last 2 entries are the configuration number and the minimum interval for Interrupt endpoints
2151 +int validconf[][18]=
2153 + // INT in, ISO out config
2154 + {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},
2155 + {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},
2156 + // ISO in, ISO out config
2157 + {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},
2158 + {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},
2159 + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} // EOL element
2162 +// string description of chosen config
2165 + "4 Interrupt IN + 3 Isochron OUT",
2166 + "3 Interrupt IN + 3 Isochron OUT",
2167 + "4 Isochron IN + 3 Isochron OUT",
2168 + "3 Isochron IN + 3 Isochron OUT"
2174 /*************************************************/
2175 /* function called to probe a new plugged device */
2176 /*************************************************/
2178 -hfc_usb_probe(struct usb_device *dev, unsigned int interface
2179 -#ifdef COMPAT_HAS_USB_IDTAB
2180 - , const struct usb_device_id *id_table)
2184 +//static int hfc_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
2185 +static void* hfc_usb_probe(struct usb_device *dev, unsigned int ifnum, const struct usb_device_id *id)
2187 + //struct usb_device *dev= interface_to_usbdev(intf);
2188 + struct usb_interface* intf = dev->actconfig->interface + ifnum;
2189 hfcusb_data *context;
2190 - struct usb_interface *ifp = dev->actconfig->interface + interface;
2191 - struct usb_interface_descriptor *ifdp =
2192 - ifp->altsetting + ifp->act_altsetting;
2193 - struct usb_endpoint_descriptor *epd;
2194 - int i, idx, ep_msk;
2196 -#ifdef COMPAT_HAS_USB_IDTAB
2197 - if (id_table && (dev->descriptor.idVendor == id_table->idVendor) &&
2198 - (dev->descriptor.idProduct == id_table->idProduct) &&
2200 - if ((((dev->descriptor.idVendor == 0x959) &&
2201 - (dev->descriptor.idProduct == 0x2bd0)) ||
2202 - ((dev->descriptor.idVendor == 0x7b0) &&
2203 - (dev->descriptor.idProduct == 0x0006))) &&
2205 - (ifdp->bNumEndpoints >= 6) && (ifdp->bNumEndpoints <= 16)) {
2206 - if (!(context = kmalloc(sizeof(hfcusb_data), GFP_KERNEL))) {
2207 - return (NULL); /* got no mem */
2209 - memset(context, 0, sizeof(hfcusb_data)); /* clear the structure */
2210 - i = ifdp->bNumEndpoints; /* get number of endpoints */
2211 - ep_msk = 0; /* none found */
2212 - epd = ifdp->endpoint; /* first endpoint descriptor */
2213 - while (i-- && ((ep_msk & 0xcf) != 0xcf)) {
2215 - idx = (((epd->bEndpointAddress & 0x7f) - 1) << 1); /* get endpoint base */
2217 - switch (epd->bmAttributes) {
2218 - case USB_ENDPOINT_XFER_INT:
2221 - bEndpointAddress &
2223 - break; /* only interrupt in allowed */
2224 - idx++; /* input index is odd */
2225 - context->fifos[idx].pipe =
2226 - usb_rcvintpipe(dev,
2228 - bEndpointAddress);
2231 - case USB_ENDPOINT_XFER_BULK:
2233 - bEndpointAddress &
2235 - break; /* only bulk out allowed */
2236 - context->fifos[idx].pipe =
2237 - usb_sndbulkpipe(dev,
2239 - bEndpointAddress);
2242 - context->fifos[idx].pipe = 0; /* reset data */
2243 - } /* switch attribute */
2245 - if (context->fifos[idx].pipe) {
2246 - context->fifos[idx].fifonum = idx;
2247 - context->fifos[idx].fifo_mask =
2249 - context->fifos[idx].hfc = context;
2250 - context->fifos[idx].usb_maxlen =
2251 - epd->wMaxPacketSize;
2252 - context->fifos[idx].intervall =
2254 - ep_msk |= (1 << idx);
2256 - ep_msk &= ~(1 << idx);
2260 + //struct usb_host_interface *iface = intf->cur_altsetting;
2261 + //struct usb_host_interface *iface_used = NULL;
2262 + //struct usb_host_endpoint *ep;
2263 + struct usb_endpoint_descriptor* ep;
2264 + //int ifnum = iface->desc.bInterfaceNumber;
2265 + struct usb_interface_descriptor* intfdesc = intf->altsetting + intf->act_altsetting;
2266 + struct usb_interface_descriptor* intfdesc_used = NULL;
2267 + int i, idx, alt_idx, probe_alt_setting, vend_idx, cfg_used, *vcf, attr, cfg_found, cidx, ep_addr;
2268 + int cmptbl[16],small_match,iso_packet_size,packet_size,alt_used=0;
2270 +// usb_show_device(dev);
2271 +// usb_show_device_descriptor(&dev->descriptor);
2272 +// usb_show_interface_descriptor(&iface->desc);
2274 + for(i=0;vdata[i].vendor;i++)
2276 + if(dev->descriptor.idVendor==vdata[i].vendor && dev->descriptor.idProduct==vdata[i].prod_id) vend_idx=i;
2280 - if ((ep_msk & 0x3f) != 0x3f) {
2284 - MOD_INC_USE_COUNT; /* lock our module */
2285 - context->dev = dev; /* save device */
2286 - context->if_used = interface; /* save used interface */
2287 - context->alt_used = ifp->act_altsetting; /* and alternate config */
2288 - context->ctrl_paksize = dev->descriptor.bMaxPacketSize0; /* control size */
2290 - /* create the control pipes needed for register access */
2291 - context->ctrl_in_pipe = usb_rcvctrlpipe(context->dev, 0);
2292 - context->ctrl_out_pipe = usb_sndctrlpipe(context->dev, 0);
2294 - /* init the chip and register the driver */
2295 - if (usb_init(context)) {
2297 - MOD_DEC_USE_COUNT;
2300 +#ifdef VERBOSE_USB_DEBUG
2301 + printk(KERN_INFO "HFC-USB: probing interface(%d) actalt(%d)\n",
2302 + ifnum, intfdesc->bAlternateSetting);
2303 + /* printk(KERN_INFO "HFC-USB: probing interface(%d) actalt(%d) minor(%d)\n",
2304 + ifnum, intfdesc->bAlternateSetting, intf->driver->minor); */
2308 - "HFC-USB: New device if=%d alt=%d registered\n",
2309 - context->if_used, context->alt_used);
2312 + if (vend_idx != 0xffff) {
2313 +#ifdef VERBOSE_USB_DEBUG
2314 + printk(KERN_INFO "HFC-USB: found vendor idx:%d name:%s\n",vend_idx,vdata[vend_idx].vend_name);
2316 + /* if vendor and product ID is OK, start probing a matching alternate setting ... */
2318 + small_match=0xffff;
2319 + // default settings
2320 + iso_packet_size=16;
2323 + while (alt_idx < intf->num_altsetting) {
2324 + //iface = intf->altsetting + alt_idx;
2325 + intfdesc = intf->altsetting + alt_idx;
2326 + probe_alt_setting = intfdesc->bAlternateSetting;
2329 - return (NULL); /* no matching entry */
2330 -} /* hfc_usb_probe */
2331 +#ifdef VERBOSE_USB_DEBUG
2332 + printk(KERN_INFO "HFC-USB: test alt_setting %d\n", probe_alt_setting);
2334 + // check for config EOL element
2335 + while (validconf[cfg_used][0]) {
2337 + vcf=validconf[cfg_used];
2338 + ep = intfdesc->endpoint; /* first endpoint descriptor */
2340 +#ifdef VERBOSE_USB_DEBUG
2341 + printk(KERN_INFO "HFC-USB: (if=%d alt=%d cfg_used=%d)\n",
2342 + ifnum, probe_alt_setting, cfg_used);
2345 + memcpy(cmptbl,vcf,16*sizeof(int));
2347 + // check for all endpoints in this alternate setting
2348 + for (i=0; i < intfdesc->bNumEndpoints; i++) {
2349 + ep_addr = ep->bEndpointAddress;
2350 + idx = ((ep_addr & 0x7f)-1)*2; /* get endpoint base */
2351 + if (ep_addr & 0x80)
2353 + attr = ep->bmAttributes;
2355 + if (cmptbl[idx] == EP_NUL) {
2356 + printk(KERN_INFO "HFC-USB: cfg_found=FALSE in idx:%d attr:%d cmptbl[%d]:%d\n",
2357 + idx, attr, idx, cmptbl[idx]);
2358 + cfg_found = FALSE;
2361 + if (attr == USB_ENDPOINT_XFER_INT && cmptbl[idx] == EP_INT)
2362 + cmptbl[idx] = EP_NUL;
2363 + if (attr == USB_ENDPOINT_XFER_BULK && cmptbl[idx] == EP_BLK)
2364 + cmptbl[idx] = EP_NUL;
2365 + if (attr == USB_ENDPOINT_XFER_ISOC && cmptbl[idx] == EP_ISO)
2366 + cmptbl[idx] = EP_NUL;
2368 + // check if all INT endpoints match minimum interval
2369 + if (attr == USB_ENDPOINT_XFER_INT && ep->bInterval < vcf[17]) {
2370 +#ifdef VERBOSE_USB_DEBUG
2372 + printk(KERN_INFO "HFC-USB: Interrupt Endpoint interval < %d found - skipping config\n",
2375 + cfg_found = FALSE;
2381 + for (i = 0; i < 16; i++) {
2382 + // printk(KERN_INFO "HFC-USB: cmptbl[%d]:%d\n", i, cmptbl[i]);
2384 + // all entries must be EP_NOP or EP_NUL for a valid config
2385 + if (cmptbl[i] != EP_NOP && cmptbl[i] != EP_NUL)
2386 + cfg_found = FALSE;
2389 + // we check for smallest match, to provide configuration priority
2390 + // configurations with smaller index have higher priority
2392 + if (cfg_used < small_match) {
2393 + small_match = cfg_used;
2394 + alt_used = probe_alt_setting;
2395 + //iface_used = iface;
2396 + intfdesc_used = intfdesc;
2398 +#ifdef VERBOSE_USB_DEBUG
2399 + printk(KERN_INFO "HFC-USB: small_match=%x %x\n", small_match, alt_used);
2407 + } /* (alt_idx < intf->num_altsetting) */
2408 +#ifdef VERBOSE_USB_DEBUG
2409 + printk(KERN_INFO "HFC-USB: final small_match=%x alt_used=%x\n",small_match, alt_used);
2411 + // yiipiee, we found a valid config
2412 + if (small_match != 0xffff) {
2413 + //iface = iface_used;
2414 + intfdesc = intfdesc_used;
2416 + if (!(context = kmalloc(sizeof(hfcusb_data), GFP_KERNEL)))
2417 + return(NULL); /* got no mem */
2418 + memset(context, 0, sizeof(hfcusb_data)); /* clear the structure */
2420 + ep = intfdesc->endpoint; /* first endpoint descriptor */
2421 + vcf = validconf[small_match];
2423 + for (i = 0; i < intfdesc->bNumEndpoints; i++) {
2424 + ep_addr = ep->bEndpointAddress;
2425 + idx = ((ep_addr & 0x7f)-1)*2; /* get endpoint base */
2426 + if (ep_addr & 0x80)
2429 + attr = ep->bmAttributes;
2431 + // only initialize used endpoints
2432 + if (vcf[idx] != EP_NOP && vcf[idx] != EP_NUL) {
2434 + case USB_ENDPOINT_XFER_INT:
2435 + context->fifos[cidx].pipe = usb_rcvintpipe(dev, ep->bEndpointAddress);
2436 + context->fifos[cidx].usb_transfer_mode = USB_INT;
2437 + packet_size = ep->wMaxPacketSize; // remember max packet size
2438 +#ifdef VERBOSE_USB_DEBUG
2439 + printk (KERN_INFO "HFC-USB: Interrupt-In Endpoint found %d ms(idx:%d cidx:%d)!\n",
2440 + ep->bInterval, idx, cidx);
2443 + case USB_ENDPOINT_XFER_BULK:
2444 + if (ep_addr & 0x80)
2445 + context->fifos[cidx].pipe = usb_rcvbulkpipe(dev, ep->bEndpointAddress);
2447 + context->fifos[cidx].pipe = usb_sndbulkpipe(dev, ep->bEndpointAddress);
2448 + context->fifos[cidx].usb_transfer_mode = USB_BULK;
2449 + packet_size = ep->wMaxPacketSize; // remember max packet size
2450 +#ifdef VERBOSE_USB_DEBUG
2451 + printk (KERN_INFO "HFC-USB: Bulk Endpoint found (idx:%d cidx:%d)!\n",
2455 + case USB_ENDPOINT_XFER_ISOC:
2456 + if (ep_addr & 0x80)
2457 + context->fifos[cidx].pipe = usb_rcvisocpipe(dev, ep->bEndpointAddress);
2459 + context->fifos[cidx].pipe = usb_sndisocpipe(dev, ep->bEndpointAddress);
2460 + context->fifos[cidx].usb_transfer_mode = USB_ISOC;
2461 + iso_packet_size = ep->wMaxPacketSize; // remember max packet size
2462 +#ifdef VERBOSE_USB_DEBUG
2463 + printk (KERN_INFO "HFC-USB: ISO Endpoint found (idx:%d cidx:%d)!\n",
2468 + context->fifos[cidx].pipe = 0; /* reset data */
2469 + } /* switch attribute */
2471 + if (context->fifos[cidx].pipe) {
2472 + context->fifos[cidx].fifonum = cidx;
2473 + context->fifos[cidx].hfc = context;
2474 + context->fifos[cidx].usb_packet_maxlen = ep->wMaxPacketSize;
2475 + context->fifos[cidx].intervall = ep->bInterval;
2476 + context->fifos[cidx].skbuff = NULL;
2477 +#ifdef VERBOSE_USB_DEBUG
2478 + printk (KERN_INFO "HFC-USB: fifo%d pktlen %d interval %d\n",
2479 + context->fifos[cidx].fifonum,
2480 + context->fifos[cidx].usb_packet_maxlen,
2481 + context->fifos[cidx].intervall);
2489 + // now share our luck
2490 + context->dev = dev; /* save device */
2491 + context->if_used = ifnum; /* save used interface */
2492 + context->alt_used = alt_used; /* and alternate config */
2493 + context->ctrl_paksize = dev->descriptor.bMaxPacketSize0; /* control size */
2494 + context->cfg_used=vcf[16]; // store used config
2495 + context->vend_idx=vend_idx; // store found vendor
2496 + context->packet_size=packet_size;
2497 + context->iso_packet_size=iso_packet_size;
2499 + /* create the control pipes needed for register access */
2500 + context->ctrl_in_pipe = usb_rcvctrlpipe(context->dev, 0);
2501 + context->ctrl_out_pipe = usb_sndctrlpipe(context->dev, 0);
2502 + context->ctrl_urb = usb_alloc_urb(0);
2504 + printk(KERN_INFO "HFC-USB: detected \"%s\" configuration: %s (if=%d alt=%d)\n",
2505 + vdata[vend_idx].vend_name, conf_str[small_match], context->if_used, context->alt_used);
2507 + /* init the chip and register the driver */
2508 + if (usb_init(context))
2510 + if (context->ctrl_urb) {
2511 + usb_unlink_urb(context->ctrl_urb);
2512 + usb_free_urb(context->ctrl_urb);
2513 + context->ctrl_urb = NULL;
2518 + //usb_set_intfdata(intf, context);
2519 + //intf->private_data = context;
2526 /****************************************************/
2527 /* function called when an active device is removed */
2528 /****************************************************/
2530 -hfc_usb_disconnect(struct usb_device *usbdev, void *drv_context)
2531 +//static void hfc_usb_disconnect(struct usb_interface *intf)
2532 +static void hfc_usb_disconnect(struct usb_device *usbdev, void* drv_context)
2534 - hfcusb_data *context = drv_context;
2535 + //hfcusb_data *context = intf->private_data;
2536 + hfcusb_data* context = drv_context;
2538 - struct sk_buff *skb;
2540 - /* tell all fifos to terminate */
2541 - for (i = 0; i < HFCUSB_NUM_FIFOS; i++)
2542 - if (context->fifos[i].active) {
2543 - context->fifos[i].active = 0;
2544 - usb_unlink_urb(&context->fifos[i].urb);
2546 - while (context->active_fifos) {
2547 - set_current_state(TASK_INTERRUPTIBLE);
2548 - /* Timeout 10ms */
2549 - schedule_timeout((10 * HZ) / 1000);
2551 + printk(KERN_INFO "HFC-USB: device disconnect\n");
2553 + //intf->private_data = NULL;
2556 if (timer_pending(&context->t3_timer))
2557 del_timer(&context->t3_timer);
2558 - context->regd.release_driver(context->regd.arg_hisax);
2559 - while ((skb = skb_dequeue(&context->regd.erq)) != NULL)
2560 - dev_kfree_skb_any(skb);
2561 + if (timer_pending(&context->t4_timer))
2562 + del_timer(&context->t4_timer);
2563 + if (timer_pending(&context->led_timer))
2564 + del_timer(&context->led_timer);
2566 + hisax_unregister(&context->d_if);
2568 + /* tell all fifos to terminate */
2569 + for(i = 0; i < HFCUSB_NUM_FIFOS; i++) {
2570 + if(context->fifos[i].usb_transfer_mode == USB_ISOC) {
2571 + if(context->fifos[i].active > 0) {
2572 + stop_isoc_chain(&context->fifos[i]);
2573 +#ifdef VERBOSE_USB_DEBUG
2574 + printk (KERN_INFO "HFC-USB: hfc_usb_disconnect: stopping ISOC chain Fifo no %i\n", i);
2578 + if(context->fifos[i].active > 0) {
2579 + context->fifos[i].active = 0;
2580 +#ifdef VERBOSE_USB_DEBUG
2581 + printk (KERN_INFO "HFC-USB: hfc_usb_disconnect: unlinking URB for Fifo no %i\n", i);
2584 + if (context->fifos[i].urb) {
2585 + usb_unlink_urb(context->fifos[i].urb);
2586 + usb_free_urb(context->fifos[i].urb);
2587 + context->fifos[i].urb = NULL;
2590 + context->fifos[i].active = 0;
2592 + if (context->ctrl_urb) {
2593 + usb_unlink_urb(context->ctrl_urb);
2594 + usb_free_urb(context->ctrl_urb);
2595 + context->ctrl_urb = NULL;
2597 kfree(context); /* free our structure again */
2598 - MOD_DEC_USE_COUNT; /* and decrement the usage counter */
2599 } /* hfc_usb_disconnect */
2602 /************************************/
2603 /* our driver information structure */
2604 /************************************/
2605 static struct usb_driver hfc_drv = {
2607 -#ifdef COMPAT_HAS_USB_IDTAB
2608 id_table:hfc_usb_idtab,
2610 probe:hfc_usb_probe,
2611 disconnect:hfc_usb_disconnect,
2618 +static void __exit hfc_usb_exit(void)
2620 +#ifdef VERBOSE_USB_DEBUG
2621 + printk ("HFC-USB: calling \"hfc_usb_exit\" ...\n");
2623 usb_deregister(&hfc_drv); /* release our driver */
2624 printk(KERN_INFO "HFC-USB module removed\n");
2629 +static int __init hfc_usb_init(void)
2631 - struct hisax_drvreg drv;
2632 + printk ("HFC-USB: driver module revision %s loaded\n", hfcusb_revision);
2634 - drv.version = HISAX_LOAD_VERSION; /* set our version */
2635 - drv.cmd = HISAX_LOAD_CHKVER; /* check command only */
2636 - if (hisax_register_hfcusb(&drv)) {
2637 - printk(KERN_INFO "HFC-USB <-> hisax version conflict\n");
2638 - return (-1); /* unable to register */
2640 - if (usb_register(&hfc_drv)) {
2642 - "Unable to register HFC-USB module at usb stack\n");
2643 - return (-1); /* unable to register */
2644 + if(usb_register(&hfc_drv))
2646 + printk(KERN_INFO "HFC-USB: Unable to register HFC-USB module at usb stack\n");
2647 + return(-1); /* unable to register */
2650 - printk(KERN_INFO "HFC-USB module loaded\n");
2659 module_init(hfc_usb_init);
2660 module_exit(hfc_usb_exit);