1 diff -rNu linux-2.4.29.old/drivers/Makefile linux-2.4.29/drivers/Makefile
2 --- linux-2.4.29.old/drivers/Makefile 2005-03-22 14:47:41.000000000 +0100
3 +++ linux-2.4.29/drivers/Makefile 2005-03-22 15:15:20.012957872 +0100
5 subdir-$(CONFIG_MD) += md
6 subdir-$(CONFIG_IEEE1394) += ieee1394
7 subdir-$(CONFIG_PNP) += pnp
8 -subdir-$(CONFIG_ISDN_BOOL) += isdn
9 +subdir-$(CONFIG_ISDN) += isdn
10 subdir-$(CONFIG_ATM) += atm
11 subdir-$(CONFIG_FC4) += fc4
13 diff -rNu linux-2.4.29.old/drivers/isdn/hisax/hfc_usb.c linux-2.4.29/drivers/isdn/hisax/hfc_usb.c
14 --- linux-2.4.29.old/drivers/isdn/hisax/hfc_usb.c 2005-03-22 15:13:58.233390256 +0100
15 +++ linux-2.4.29/drivers/isdn/hisax/hfc_usb.c 2005-03-22 15:14:57.475384104 +0100
17 -/* $Id: hfc_usb.c,v 2.3 2001/07/06 21:30:11 werner Exp $
21 + * modular HiSax ISDN driver for Colognechip HFC-USB chip
24 - * Author (C) 2001 Werner Cornelius (werner@isdn-development.de)
25 - * modular driver for Colognechip HFC-USB chip
26 - * as plugin for HiSax isdn driver
27 - * type approval valid for HFC-S USB based TAs
29 - * Copyright 2001 by Werner Cornelius (werner@isdn-development.de)
30 + * Authors : Peter Sprenger (sprenger@moving-byters.de)
31 + * Martin Bachem (info@colognechip.com)
32 + * based on the first hfc_usb driver of Werner Cornelius (werner@isdn-development.de)
34 * This program is free software; you can redistribute it and/or modify
35 * it under the terms of the GNU General Public License as published by
37 * along with this program; if not, write to the Free Software
38 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
42 + * ported 2.6.8 hfc_usb.c to 2.4.20 format
43 + * Gregor Schaffrath <gschaff@ran-dom.org>
47 #include <linux/types.h>
48 #include <linux/stddef.h>
49 #include <linux/timer.h>
50 #include <linux/config.h>
51 -#include <linux/isdn_compat.h>
52 #include <linux/init.h>
54 #include <linux/module.h>
55 #include <linux/kernel_stat.h>
56 -#include <linux/tqueue.h>
57 #include <linux/usb.h>
58 #include <linux/kernel.h>
59 #include <linux/smp_lock.h>
60 #include <linux/sched.h>
61 +#include "hisax_if.h"
62 #include "hisax_loadable.h"
64 +static const char *hfcusb_revision = "4.0";
67 + to enable much mire debug messages in this driver, define
68 + VERBOSE_USB_DEBUG and VERBOSE_ISDN_DEBUG
72 +#define VERBOSE_USB_DEBUG
73 +#define VERBOSE_ISDN_DEBUG
75 #define INCLUDE_INLINE_FUNCS
84 -#define HFC_CTRL_TIMEOUT 5 /* 5ms timeout writing/reading regs */
85 -#define HFC_TIMER_T3 7000 /* timeout for l1 activation timer */
87 -#define HFCUSB_L1_STATECHANGE 0 /* L1 state changed */
88 -#define HFCUSB_L1_DRX 1 /* D-frame received */
89 -#define HFCUSB_L1_ERX 2 /* E-frame received */
90 -#define HFCUSB_L1_DTX 4 /* D-frames completed */
92 -#define MAX_BCH_SIZE 2048 /* allowed B-channel packet size */
94 -#define HFCUSB_RX_THRESHOLD 64 /* threshold for fifo report bit rx */
95 -#define HFCUSB_TX_THRESHOLD 64 /* threshold for fifo report bit tx */
97 -#define HFCUSB_CHIP_ID 0x16 /* Chip ID register index */
98 -#define HFCUSB_CIRM 0x00 /* cirm register index */
99 -#define HFCUSB_USB_SIZE 0x07 /* int length register */
100 -#define HFCUSB_USB_SIZE_I 0x06 /* iso length register */
101 -#define HFCUSB_F_CROSS 0x0b /* bit order register */
102 -#define HFCUSB_CLKDEL 0x37 /* bit delay register */
103 -#define HFCUSB_CON_HDLC 0xfa /* channel connect register */
104 +#define HFC_CTRL_TIMEOUT 20 //(HZ * USB_CTRL_GET_TIMEOUT)
105 +/* 5ms timeout writing/reading regs */
106 +#define HFC_TIMER_T3 8000 /* timeout for l1 activation timer */
107 +#define HFC_TIMER_T4 500 /* time for state change interval */
109 +#define HFCUSB_L1_STATECHANGE 0 /* L1 state changed */
110 +#define HFCUSB_L1_DRX 1 /* D-frame received */
111 +#define HFCUSB_L1_ERX 2 /* E-frame received */
112 +#define HFCUSB_L1_DTX 4 /* D-frames completed */
114 +#define MAX_BCH_SIZE 2048 /* allowed B-channel packet size */
116 +#define HFCUSB_RX_THRESHOLD 64 /* threshold for fifo report bit rx */
117 +#define HFCUSB_TX_THRESHOLD 64 /* threshold for fifo report bit tx */
119 +#define HFCUSB_CHIP_ID 0x16 /* Chip ID register index */
120 +#define HFCUSB_CIRM 0x00 /* cirm register index */
121 +#define HFCUSB_USB_SIZE 0x07 /* int length register */
122 +#define HFCUSB_USB_SIZE_I 0x06 /* iso length register */
123 +#define HFCUSB_F_CROSS 0x0b /* bit order register */
124 +#define HFCUSB_CLKDEL 0x37 /* bit delay register */
125 +#define HFCUSB_CON_HDLC 0xfa /* channel connect register */
126 #define HFCUSB_HDLC_PAR 0xfb
127 -#define HFCUSB_SCTRL 0x31 /* S-bus control register (tx) */
128 -#define HFCUSB_SCTRL_E 0x32 /* same for E and special funcs */
129 -#define HFCUSB_SCTRL_R 0x33 /* S-bus control register (rx) */
130 -#define HFCUSB_F_THRES 0x0c /* threshold register */
131 -#define HFCUSB_FIFO 0x0f /* fifo select register */
132 -#define HFCUSB_F_USAGE 0x1a /* fifo usage register */
133 +#define HFCUSB_SCTRL 0x31 /* S-bus control register (tx) */
134 +#define HFCUSB_SCTRL_E 0x32 /* same for E and special funcs */
135 +#define HFCUSB_SCTRL_R 0x33 /* S-bus control register (rx) */
136 +#define HFCUSB_F_THRES 0x0c /* threshold register */
137 +#define HFCUSB_FIFO 0x0f /* fifo select register */
138 +#define HFCUSB_F_USAGE 0x1a /* fifo usage register */
139 #define HFCUSB_MST_MODE0 0x14
140 #define HFCUSB_MST_MODE1 0x15
141 #define HFCUSB_P_DATA 0x1f
142 #define HFCUSB_INC_RES_F 0x0e
143 #define HFCUSB_STATES 0x30
145 -#define HFCUSB_CHIPID 0x40 /* ID value of HFC-USB */
146 +#define HFCUSB_CHIPID 0x40 /* ID value of HFC-USB */
151 -#define HFCUSB_NUM_FIFOS 8 /* maximum number of fifos */
152 -#define HFCUSB_B1_TX 0 /* index for B1 transmit bulk/int */
153 -#define HFCUSB_B1_RX 1 /* index for B1 receive bulk/int */
154 +#define HFCUSB_NUM_FIFOS 8 /* maximum number of fifos */
155 +#define HFCUSB_B1_TX 0 /* index for B1 transmit bulk/int */
156 +#define HFCUSB_B1_RX 1 /* index for B1 receive bulk/int */
157 #define HFCUSB_B2_TX 2
158 #define HFCUSB_B2_RX 3
159 #define HFCUSB_D_TX 4
160 @@ -94,198 +112,162 @@
161 #define HFCUSB_PCM_TX 6
162 #define HFCUSB_PCM_RX 7
167 -#define LED_DRIVER 0x1
171 +* used to switch snd_transfer_mode for different TA modes e.g. the Billion USB TA just
172 +* supports ISO out, while the Cologne Chip EVAL TA just supports BULK out
178 +#define ISOC_PACKETS_D 8
179 +#define ISOC_PACKETS_B 8
180 +#define ISO_BUFFER_SIZE 128
182 +// ISO send definitions
185 +#define SINK_DMIN 12
186 +#define SINK_DMAX 18
187 +#define BITLINE_INF (-64*8)
195 -#define Write_hfc(a,b,c) usb_control_msg((a)->dev,(a)->ctrl_out_pipe,0,0x40,(c),(b),0,0,HFC_CTRL_TIMEOUT)
196 -#define Read_hfc(a,b,c) usb_control_msg((a)->dev,(a)->ctrl_in_pipe,1,0xC0,0,(b),(c),1,HFC_CTRL_TIMEOUT)
198 -#ifdef COMPAT_HAS_USB_IDTAB
199 -/****************************************/
200 -/* data defining the devices to be used */
201 -/****************************************/
202 -static __devinitdata const struct usb_device_id hfc_usb_idtab[3] = {
203 - {USB_DEVICE(0x959, 0x2bd0)}, /* Colognechip ROM */
204 - {USB_DEVICE(0x7b0, 0x0006)}, /* USB TA 128 */
205 - {} /* end with an all-zeroes entry */
208 +#define write_usb(a,b,c) usb_control_msg((a)->dev,(a)->ctrl_out_pipe,0,0x40,(c),(b),NULL,0,HFC_CTRL_TIMEOUT)
209 +#define read_usb(a,b,c) usb_control_msg((a)->dev,(a)->ctrl_in_pipe,1,0xC0,0,(b),(c),1,HFC_CTRL_TIMEOUT)
211 /*************************************************/
212 /* entry and size of output/input control buffer */
213 /*************************************************/
214 #define HFC_CTRL_BUFSIZE 32
218 __u8 hfc_reg; /* register number */
219 __u8 reg_val; /* value to be written (or read) */
220 + int action; /* data for action handler */
226 + int vendor; // vendor id
227 + int prod_id; // product id
228 + char *vend_name; // vendor string
229 + __u8 led_scheme; // led display scheme
230 + __u8 led_invert; // invert led aux port settings
231 + __u8 led_bits[8]; // array of 8 possible LED bitmask settings
235 /***************************************************************/
236 /* structure defining input+output fifos (interrupt/bulk mode) */
237 /***************************************************************/
238 -struct hfcusb_data; /* forward definition */
240 - int fifonum; /* fifo index attached to this structure */
241 - __u8 fifo_mask; /* mask for this fifo */
242 - int active; /* fifo is currently active */
244 +struct usb_fifo; /* forward definition */
245 +typedef struct iso_urb_struct
248 + __u8 buffer[ISO_BUFFER_SIZE]; /* buffer incoming/outgoing data */
249 + struct usb_fifo *owner_fifo; // pointer to owner fifo
253 +struct hfcusb_data; /* forward definition */
254 +typedef struct usb_fifo
256 + int fifonum; /* fifo index attached to this structure */
257 + int active; /* fifo is currently active */
258 struct hfcusb_data *hfc; /* pointer to main structure */
259 - int pipe; /* address of endpoint */
260 - __u8 usb_maxlen; /* maximum length for usb transfer */
261 - int max_size; /* maximum size of receive/send packet */
262 - int transmode; /* transparent mode selected */
263 - int framenum; /* number of frame when last tx completed */
264 - int rx_offset; /* offset inside rx buffer */
265 - int next_complete; /* complete marker */
266 - __u8 *act_ptr; /* pointer to next data */
267 - __u8 intervall; /* interrupt interval */
268 - struct sk_buff *buff; /* actual used buffer */
269 - urb_t urb; /* transfer structure for usb routines */
270 - __u8 buffer[128]; /* buffer incoming/outgoing data */
271 + int pipe; /* address of endpoint */
272 + __u8 usb_packet_maxlen; /* maximum length for usb transfer */
273 + unsigned int max_size; /* maximum size of receive/send packet */
274 + __u8 intervall; /* interrupt interval */
275 + struct sk_buff *skbuff; /* actual used buffer */
276 + struct urb *urb; /* transfer structure for usb routines */
277 + __u8 buffer[128]; /* buffer incoming/outgoing data */
278 + int bit_line; /* how much bits are in the fifo? */
280 + volatile __u8 usb_transfer_mode;/* switched between ISO and INT */
281 + iso_urb_struct iso[2]; /* need two urbs to have one always for pending */
282 + struct hisax_if *hif; /* hisax interface */
283 + int delete_flg; /* only delete skbuff once */
284 + int last_urblen; /* remember length of last packet */
289 /*********************************************/
290 /* structure holding all data for one device */
291 /*********************************************/
292 -typedef struct hfcusb_data {
293 - struct hisax_drvreg regd; /* register data and callbacks */
294 - struct usb_device *dev; /* our device */
295 - int if_used; /* used interface number */
296 - int alt_used; /* used alternate config */
297 - int ctrl_paksize; /* control pipe packet size */
298 +typedef struct hfcusb_data
300 + // HiSax Interface for loadable Layer1 drivers
301 + struct hisax_d_if d_if; /* see hisax_if.h */
302 + struct hisax_b_if b_if[2]; /* see hisax_if.h */
305 + struct usb_device *dev; /* our device */
306 + int if_used; /* used interface number */
307 + int alt_used; /* used alternate config */
308 + int ctrl_paksize; /* control pipe packet size */
309 int ctrl_in_pipe, ctrl_out_pipe; /* handles for control pipe */
310 + int cfg_used; /* configuration index used */
311 + int vend_idx; // vendor found
313 + int b_mode[2]; // B-channel mode
315 + int l1_activated; // layer 1 activated
317 + int packet_size,iso_packet_size;
319 /* control pipe background handling */
320 ctrl_buft ctrl_buff[HFC_CTRL_BUFSIZE]; /* buffer holding queued data */
321 - volatile int ctrl_in_idx, ctrl_out_idx, ctrl_cnt; /* input/output pointer + count */
322 - urb_t ctrl_urb; /* transfer structure for control channel */
323 - devrequest ctrl_write; /* buffer for control write request */
324 - devrequest ctrl_read; /* same for read request */
326 - volatile __u8 dfifo_fill; /* value read from tx d-fifo */
327 - volatile __u8 active_fifos; /* fifos currently active as bit mask */
328 - volatile __u8 threshold_mask; /* threshold actually reported */
329 - volatile __u8 service_request; /* fifo needs service from task */
330 - volatile __u8 ctrl_fifo; /* last selected fifo */
331 - volatile __u8 bch_enables; /* or mask for sctrl_r and sctrl register values */
332 - volatile __u8 led_req; /* request status of adapters leds */
333 - volatile __u8 led_act; /* active status of adapters leds */
334 + volatile int ctrl_in_idx, ctrl_out_idx,
335 + ctrl_cnt; /* input/output pointer + count */
336 + struct urb *ctrl_urb; /* transfer structure for control channel */
338 + struct usb_ctrlrequest ctrl_write; /* buffer for control write request */
339 + struct usb_ctrlrequest ctrl_read; /* same for read request */
341 + __u8 led_state,led_new_data,led_b_active;
343 + volatile __u8 threshold_mask; /* threshold actually reported */
344 + volatile __u8 bch_enables; /* or mask for sctrl_r and sctrl register values */
346 usb_fifo fifos[HFCUSB_NUM_FIFOS]; /* structure holding all fifo data */
348 - /* layer 1 activation/deactivation handling */
349 - volatile __u8 l1_state; /* actual l1 state */
350 - volatile ulong l1_event; /* event mask */
351 - struct tq_struct l1_tq; /* l1 bh structure */
352 - struct timer_list t3_timer; /* timer for activation/deactivation */
353 - struct timer_list t4_timer; /* timer for activation/deactivation */
354 + volatile __u8 l1_state; /* actual l1 state */
355 + struct timer_list t3_timer; /* timer 3 for activation/deactivation */
356 + struct timer_list t4_timer; /* timer 4 for activation/deactivation */
357 + struct timer_list led_timer; /* timer flashing leds */
363 -usb_dump_urb(purb_t purb)
365 - printk("urb :%p\n", purb);
366 - printk("next :%p\n", purb->next);
367 - printk("dev :%p\n", purb->dev);
368 - printk("pipe :%08X\n", purb->pipe);
369 - printk("status :%d\n", purb->status);
370 - printk("transfer_flags :%08X\n", purb->transfer_flags);
371 - printk("transfer_buffer :%p\n", purb->transfer_buffer);
372 - printk("transfer_buffer_length:%d\n",
373 - purb->transfer_buffer_length);
374 - printk("actual_length :%d\n", purb->actual_length);
375 - printk("setup_packet :%p\n", purb->setup_packet);
376 - printk("start_frame :%d\n", purb->start_frame);
377 - printk("number_of_packets :%d\n", purb->number_of_packets);
378 - printk("interval :%d\n", purb->interval);
379 - printk("error_count :%d\n", purb->error_count);
380 - printk("context :%p\n", purb->context);
381 - printk("complete :%p\n", purb->complete);
385 -/*************************************************************************/
386 -/* bottom half handler for L1 activation/deactiavtaion + D-chan + E-chan */
387 -/*************************************************************************/
389 -usb_l1d_bh(hfcusb_data * hfc)
391 +static void collect_rx_frame(usb_fifo *fifo,__u8 *data,int len,int finish);
394 - while (hfc->l1_event) {
395 - if (test_and_clear_bit
396 - (HFCUSB_L1_STATECHANGE, &hfc->l1_event)) {
397 - if (hfc->l1_state == 7)
398 - hfc->led_req |= LED_L1;
400 - hfc->led_req &= ~LED_L1;
401 - if ((hfc->l1_state == 7) ||
402 - (hfc->l1_state == 3))
403 - hfc->regd.dch_l1l2(hfc->regd.arg_hisax,
405 - 7) ? (PH_ACTIVATE |
407 - : (PH_DEACTIVATE | INDICATION),
410 - if (test_and_clear_bit(HFCUSB_L1_DRX, &hfc->l1_event)) {
411 - hfc->regd.dch_l1l2(hfc->regd.arg_hisax,
412 - PH_DATA | INDICATION,
415 - if (test_and_clear_bit(HFCUSB_L1_ERX, &hfc->l1_event)) {
416 - hfc->regd.dch_l1l2(hfc->regd.arg_hisax,
417 - PH_DATA | INDICATION,
420 - if (test_and_clear_bit(HFCUSB_L1_DTX, &hfc->l1_event)) {
421 - hfc->regd.dch_l1l2(hfc->regd.arg_hisax,
422 - PH_DATA | CONFIRM, NULL);
427 /******************************************************/
428 /* start next background transfer for control channel */
429 /******************************************************/
431 -ctrl_start_transfer(hfcusb_data * hfc)
432 +static void ctrl_start_transfer(hfcusb_data * hfc)
435 - if (hfc->ctrl_cnt) {
436 - switch (hfc->ctrl_buff[hfc->ctrl_out_idx].hfc_reg) {
437 - case HFCUSB_F_USAGE:
438 - hfc->ctrl_urb.pipe = hfc->ctrl_in_pipe;
439 - hfc->ctrl_urb.setup_packet =
440 - (u_char *) & hfc->ctrl_read;
441 - hfc->ctrl_urb.transfer_buffer_length = 1;
442 - hfc->ctrl_read.index =
443 - hfc->ctrl_buff[hfc->ctrl_out_idx].
445 - hfc->ctrl_urb.transfer_buffer =
446 - (char *) &hfc->dfifo_fill;
449 - default: /* write register */
450 - hfc->ctrl_urb.pipe = hfc->ctrl_out_pipe;
451 - hfc->ctrl_urb.setup_packet =
452 - (u_char *) & hfc->ctrl_write;
453 - hfc->ctrl_urb.transfer_buffer = NULL;
454 - hfc->ctrl_urb.transfer_buffer_length = 0;
455 - hfc->ctrl_write.index =
456 - hfc->ctrl_buff[hfc->ctrl_out_idx].
458 - hfc->ctrl_write.value =
459 - hfc->ctrl_buff[hfc->ctrl_out_idx].
463 - usb_submit_urb(&hfc->ctrl_urb); /* start transfer */
467 + hfc->ctrl_urb->pipe = hfc->ctrl_out_pipe;
468 + hfc->ctrl_urb->setup_packet = (u_char *) & hfc->ctrl_write;
469 + hfc->ctrl_urb->transfer_buffer = NULL;
470 + hfc->ctrl_urb->transfer_buffer_length = 0;
471 + hfc->ctrl_write.wIndex = hfc->ctrl_buff[hfc->ctrl_out_idx].hfc_reg;
472 + hfc->ctrl_write.wValue = hfc->ctrl_buff[hfc->ctrl_out_idx].reg_val;
473 + err = usb_submit_urb(hfc->ctrl_urb); /* start transfer */
474 + printk(KERN_DEBUG "ctrl_start_transfer: submit %d\n", err);
476 } /* ctrl_start_transfer */
478 @@ -293,897 +275,1418 @@
479 /* queue a control transfer request */
480 /* return 0 on success. */
481 /************************************/
483 -queue_control_request(hfcusb_data * hfc, __u8 reg, __u8 val)
484 +static int queue_control_request(hfcusb_data * hfc, __u8 reg, __u8 val,int action)
488 - if (hfc->ctrl_cnt >= HFC_CTRL_BUFSIZE)
489 - return (1); /* no space left */
490 - buf = hfc->ctrl_buff + hfc->ctrl_in_idx; /* pointer to new index */
491 +#ifdef VERBOSE_USB_DEBUG
492 + printk ("HFC_USB: queue_control_request reg: %x, val: %x\n", reg, val);
495 + if(hfc->ctrl_cnt >= HFC_CTRL_BUFSIZE) return(1); /* no space left */
496 + buf = &hfc->ctrl_buff[hfc->ctrl_in_idx]; /* pointer to new index */
499 + buf->action=action;
500 if (++hfc->ctrl_in_idx >= HFC_CTRL_BUFSIZE)
501 hfc->ctrl_in_idx = 0; /* pointer wrap */
502 if (++hfc->ctrl_cnt == 1)
503 ctrl_start_transfer(hfc);
505 -} /* queue_control_request */
507 +} /* queue_control_request */
509 -/**************************************/
510 -/* called when timer t3 or t4 expires */
511 -/**************************************/
513 -l1_timer_expire(hfcusb_data * hfc)
515 - if (timer_pending(&hfc->t4_timer))
516 - del_timer(&hfc->t4_timer);
517 - queue_control_request(hfc, HFCUSB_STATES, 0x40);
518 - test_and_set_bit(HFCUSB_L1_STATECHANGE,
520 - queue_task(&hfc->l1_tq, &tq_immediate);
521 - mark_bh(IMMEDIATE_BH);
522 -} /* l1_timer_expire */
524 -/**************************************************/
525 -/* (re)fills a tx-fifo urb. Queuing is done later */
526 -/**************************************************/
528 -fill_tx_urb(usb_fifo * fifo)
530 - struct sk_buff *skb;
534 - fifo->urb.dev = fifo->hfc->dev;
536 - && (fifo->urb.transfer_buffer_length < fifo->usb_maxlen)) {
537 - switch (fifo->fifonum) {
542 - fifo->hfc->regd.bch_l1l2(fifo->hfc->regd.
550 - fifo->hfc->service_request |=
554 - dev_kfree_skb_any(fifo->buff);
558 - fifo->hfc->dfifo_fill = 0xff; /* currently invalid data */
559 - queue_control_request(fifo->hfc,
562 - queue_control_request(fifo->hfc,
563 - HFCUSB_F_USAGE, 0);
564 - restore_flags(flags);
567 - return; /* error, invalid fifo */
570 +static int control_action_handler(hfcusb_data *hfc,int reg,int val,int action)
572 + if(!action) return(1); // no action defined
578 +/***************************************************************/
579 +/* control completion routine handling background control cmds */
580 +/***************************************************************/
581 +static void ctrl_complete(struct urb *urb)
583 + hfcusb_data *hfc = (hfcusb_data *) urb->context;
586 + printk(KERN_DEBUG "ctrl_complete cnt %d\n", hfc->ctrl_cnt);
587 + urb->dev = hfc->dev;
590 + buf=&hfc->ctrl_buff[hfc->ctrl_out_idx];
591 + control_action_handler(hfc,buf->hfc_reg,buf->reg_val,buf->action);
593 + hfc->ctrl_cnt--; /* decrement actual count */
594 + if(++hfc->ctrl_out_idx >= HFC_CTRL_BUFSIZE) hfc->ctrl_out_idx = 0; /* pointer wrap */
596 + ctrl_start_transfer(hfc); /* start next transfer */
598 +} /* ctrl_complete */
602 +#define LED_OFF 0 // no LED support
603 +#define LED_SCHEME1 1 // LED standard scheme
604 +#define LED_SCHEME2 2 // not used yet...
606 +#define LED_POWER_ON 1
607 +#define LED_POWER_OFF 2
609 +#define LED_S0_OFF 4
611 +#define LED_B1_OFF 6
612 +#define LED_B1_DATA 7
614 +#define LED_B2_OFF 9
615 +#define LED_B2_DATA 10
617 +#define LED_NORMAL 0 // LEDs are normal
618 +#define LED_INVERTED 1 // LEDs are inverted
620 +// time for LED flashing
621 +#define LED_TIME 250
623 +vendor_data vdata[]=
625 + {0x959, 0x2bd0, "ISDN USB TA (Cologne Chip HFC-S USB based)", LED_OFF,LED_NORMAL,{4,0,2,1}}, /* CologneChip Eval TA */
626 + {0x7b0, 0x0007, "Billion tiny USB ISDN TA 128", LED_SCHEME1, LED_INVERTED, {8,0x40,0x20,0x10}}, /* Billion TA */
627 + {0x742, 0x2008, "Stollmann USB TA", LED_SCHEME1, LED_NORMAL, {4,0,2,1}}, /* Stollmann TA */
628 + {0x8e3, 0x0301, "Olitec USB RNIS", LED_SCHEME1, LED_NORMAL, {2,0,1,4}}, /* Olitec TA */
629 + {0x675, 0x1688, "DrayTec USB ISDN TA", LED_SCHEME1, LED_NORMAL, {4,0,2,1}}, /* Draytec TA */
630 + {0x7fa, 0x0846, "Bewan Modem RNIS USB", LED_SCHEME1, LED_INVERTED, {8,0x40,0x20,0x10}}, /* Bewan TA */
634 +/***************************************************/
635 +/* write led data to auxport & invert if necessary */
636 +/***************************************************/
637 +static void write_led(hfcusb_data * hfc,__u8 led_state)
639 + if(led_state!=hfc->led_state)
641 + hfc->led_state=led_state;
642 + queue_control_request(hfc, HFCUSB_P_DATA,(vdata[hfc->vend_idx].led_invert) ? ~led_state : led_state,1);
646 +/******************************************/
647 +/* invert B-channel LEDs if data is sent */
648 +/******************************************/
649 +static void led_timer(hfcusb_data * hfc)
652 + __u8 led_state=hfc->led_state;
656 + if(hfc->led_b_active&1) led_state|=vdata[hfc->vend_idx].led_bits[2];
657 + if(hfc->led_b_active&2) led_state|=vdata[hfc->vend_idx].led_bits[3];
661 + if(!(hfc->led_b_active&1) || hfc->led_new_data&1) led_state&=~vdata[hfc->vend_idx].led_bits[2];
662 + if(!(hfc->led_b_active&2) || hfc->led_new_data&2) led_state&=~vdata[hfc->vend_idx].led_bits[3];
665 - /* check if new buffer needed */
667 - switch (fifo->fifonum) {
669 - if (fifo->hfc->regd.bsk[0])
670 - fifo->buff = *fifo->hfc->regd.bsk[0]; /* B1-channel tx buffer */
671 + write_led(hfc,led_state);
672 + hfc->led_new_data=0;
675 + // restart 4 hz timer
676 + hfc->led_timer.expires = jiffies + (LED_TIME * HZ) / 1000;
677 + if(!timer_pending(&hfc->led_timer)) add_timer(&hfc->led_timer);
680 +/**************************/
681 +/* handle LED requests */
682 +/**************************/
683 +static void handle_led(hfcusb_data * hfc,int event)
685 + __u8 led_state=hfc->led_state;
687 + // if no scheme -> no LED action
688 + if(vdata[hfc->vend_idx].led_scheme==LED_OFF) return;
693 + led_state|=vdata[hfc->vend_idx].led_bits[0];
695 + case LED_POWER_OFF: // no Power off handling
698 + led_state|=vdata[hfc->vend_idx].led_bits[1];
701 + led_state&=~vdata[hfc->vend_idx].led_bits[1];
704 - if (fifo->hfc->regd.bsk[1])
705 - fifo->buff = *fifo->hfc->regd.bsk[1]; /* B2-channel tx buffer */
707 + hfc->led_b_active|=1;
710 - if (fifo->hfc->regd.dsq)
711 - fifo->buff = skb_dequeue(fifo->hfc->regd.dsq); /* D-channel tx queue */
713 + hfc->led_b_active&=~1;
716 - return; /* error, invalid fifo */
718 + hfc->led_new_data|=1;
721 + hfc->led_b_active|=2;
724 + hfc->led_b_active&=~2;
727 + hfc->led_new_data|=2;
731 + write_led(hfc,led_state);
734 +/********************************/
735 +/* called when timer t3 expires */
736 +/********************************/
737 +static void l1_timer_expire_t3(hfcusb_data * hfc)
739 + //printk (KERN_INFO "HFC-USB: l1_timer_expire_t3\n");
741 + hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,PH_DEACTIVATE | INDICATION,NULL);
742 +#ifdef VERBOSE_USB_DEBUG
743 + printk(KERN_INFO "PH_DEACTIVATE | INDICATION sent\n");
745 + hfc->l1_activated=FALSE;
746 + handle_led(hfc,LED_S0_OFF);
749 +/********************************/
750 +/* called when timer t4 expires */
751 +/********************************/
752 +static void l1_timer_expire_t4(hfcusb_data * hfc)
754 + //printk (KERN_INFO "HFC-USB: l1_timer_expire_t4\n");
756 + hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,PH_DEACTIVATE | INDICATION,NULL);
757 +#ifdef VERBOSE_USB_DEBUG
758 + printk(KERN_INFO "PH_DEACTIVATE | INDICATION sent\n");
760 + hfc->l1_activated=FALSE;
761 + handle_led(hfc,LED_S0_OFF);
764 +/*****************************/
765 +/* handle S0 state changes */
766 +/*****************************/
767 +static void state_handler(hfcusb_data * hfc,__u8 state)
771 + old_state=hfc->l1_state;
774 + if(state==old_state || state<1 || state>8) return;
776 +#ifdef VERBOSE_ISDN_DEBUG
777 + printk(KERN_INFO "HFC-USB: new S0 state:%d old_state:%d\n",state,old_state);
780 + if(state<4 || state==7 || state==8)
782 + if(timer_pending(&hfc->t3_timer)) del_timer(&hfc->t3_timer);
783 + //printk(KERN_INFO "HFC-USB: T3 deactivated\n");
788 + if(timer_pending(&hfc->t4_timer)) del_timer(&hfc->t4_timer);
789 + //printk(KERN_INFO "HFC-USB: T4 deactivated\n");
792 + if(state==7 && !hfc->l1_activated)
794 + hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,PH_ACTIVATE | INDICATION,NULL);
795 + //printk(KERN_INFO "HFC-USB: PH_ACTIVATE | INDICATION sent\n");
796 + hfc->l1_activated=TRUE;
797 + handle_led(hfc,LED_S0_ON);
800 + if(state<=3 /* && activated*/)
802 + if(old_state==7 || old_state==8)
804 + //printk(KERN_INFO "HFC-USB: T4 activated\n");
805 + hfc->t4_timer.expires = jiffies + (HFC_TIMER_T4 * HZ) / 1000;
806 + if(!timer_pending(&hfc->t4_timer)) add_timer(&hfc->t4_timer);
809 - fifo->active = 0; /* we are inactive now */
810 - fifo->hfc->active_fifos &= ~fifo->fifo_mask;
811 - if (fifo->fifonum == HFCUSB_D_TX) {
812 - test_and_set_bit(HFCUSB_L1_DTX,
813 - &fifo->hfc->l1_event);
814 - queue_task(&fifo->hfc->l1_tq,
816 - mark_bh(IMMEDIATE_BH);
821 + hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,PH_DEACTIVATE | INDICATION,NULL);
822 + //printk(KERN_INFO "HFC-USB: PH_DEACTIVATE | INDICATION sent\n");
823 + hfc->l1_activated=FALSE;
824 + handle_led(hfc,LED_S0_OFF);
826 - fifo->act_ptr = fifo->buff->data; /* start of data */
829 - fifo->hfc->active_fifos |= fifo->fifo_mask;
830 - fifo->hfc->service_request &= ~fifo->fifo_mask;
832 - /* fillup the send buffer */
833 - i = fifo->buff->len - (fifo->act_ptr - fifo->buff->data); /* remaining length */
834 - fifo->buffer[0] = !fifo->transmode; /* not eof */
835 - if (i > (fifo->usb_maxlen - ii)) {
836 - i = fifo->usb_maxlen - ii;
839 - memcpy(fifo->buffer + ii, fifo->act_ptr, i);
840 - fifo->urb.transfer_buffer_length = i + ii;
841 - fifo->rx_offset = ii;
844 -/************************************************/
845 -/* transmit completion routine for all tx fifos */
846 -/************************************************/
848 -tx_complete(purb_t urb)
851 + hfc->l1_state=state;
855 +/* prepare iso urb */
856 +static void fill_isoc_urb(struct urb *urb, struct usb_device *dev, unsigned int pipe, void *buf,
857 + int num_packets, int packet_size, int interval, usb_complete_t complete, void *context)
859 - usb_fifo *fifo = (usb_fifo *) urb->context; /* pointer to our fifo */
862 - fifo->hfc->service_request &= ~fifo->fifo_mask; /* no further handling */
863 - fifo->framenum = usb_get_current_frame_number(fifo->hfc->dev);
864 + spin_lock_init(&urb->lock); // do we really need spin_lock_init ?
867 + urb->complete = complete;
868 + urb->number_of_packets = num_packets;
869 + urb->transfer_buffer_length = packet_size * num_packets;
870 + urb->context = context;
871 + urb->transfer_buffer = buf;
872 + urb->transfer_flags = 0;
873 + urb->transfer_flags = USB_ISO_ASAP;
874 + urb->actual_length = 0;
875 + urb->interval = interval;
876 + for (k = 0; k < num_packets; k++) {
877 + urb->iso_frame_desc[k].offset = packet_size * k;
878 + urb->iso_frame_desc[k].length = packet_size;
879 + urb->iso_frame_desc[k].actual_length = 0;
883 - /* check for deactivation or error */
884 - if ((!fifo->active) || (urb->status)) {
885 - fifo->hfc->active_fifos &= ~fifo->fifo_mask; /* we are inactive */
887 - if ((fifo->buff) && (fifo->fifonum == HFCUSB_D_TX)) {
888 - dev_kfree_skb_any(fifo->buff);
889 +/* allocs urbs and start isoc transfer with two pending urbs to avoid gaps in the transfer chain */
890 +static int start_isoc_chain(usb_fifo * fifo, int num_packets_per_urb,usb_complete_t complete,int packet_size)
894 +#ifdef VERBOSE_USB_DEBUG
895 + printk(KERN_INFO "HFC-USB: starting ISO-chain for Fifo %i\n", fifo->fifonum);
899 + // allocate Memory for Iso out Urbs
900 + for (i = 0; i < 2; i++) {
901 + if (!(fifo->iso[i].purb)) {
902 + fifo->iso[i].purb = usb_alloc_urb(num_packets_per_urb);
903 + fifo->iso[i].owner_fifo = (struct usb_fifo *) fifo;
905 + // Init the first iso
906 + if (ISO_BUFFER_SIZE >= (fifo->usb_packet_maxlen * num_packets_per_urb))
909 + fill_isoc_urb(fifo->iso[i].purb, fifo->hfc->dev, fifo->pipe, fifo->iso[i].buffer,
910 + num_packets_per_urb, fifo->usb_packet_maxlen, fifo->intervall,
911 + complete, &fifo->iso[i]);
913 + memset(fifo->iso[i].buffer, 0, sizeof(fifo->iso[i].buffer));
915 + // defining packet delimeters in fifo->buffer
916 + for(k = 0; k < num_packets_per_urb; k++)
918 + fifo->iso[i].purb->iso_frame_desc[k].offset = k*packet_size;
919 + fifo->iso[i].purb->iso_frame_desc[k].length = packet_size;
926 + fifo->bit_line = BITLINE_INF;
928 + errcode = usb_submit_urb(fifo->iso[i].purb);
929 + fifo->active = (errcode >= 0) ? 1 : 0;
932 + printk(KERN_INFO "HFC-USB: error submitting ISO URB: %i.%i \n", errcode, i);
936 - fifo->act_ptr += (urb->transfer_buffer_length - fifo->rx_offset); /* adjust pointer */
937 - fill_tx_urb(fifo); /* refill the urb */
938 - fifo->hfc->threshold_mask |= fifo->fifo_mask; /* assume threshold reached */
940 - fifo->hfc->service_request |= fifo->fifo_mask; /* need to restart */
943 -/***********************************************/
944 -/* receive completion routine for all rx fifos */
945 -/***********************************************/
947 -rx_complete(purb_t urb)
948 + // errcode = (usb_submit_urb(fifo->iso[0].purb, GFP_KERNEL));
949 + return(fifo->active);
952 +/* stops running iso chain and frees their pending urbs */
953 +static void stop_isoc_chain(usb_fifo * fifo)
955 - usb_fifo *fifo = (usb_fifo *) urb->context; /* pointer to our fifo */
956 - hfcusb_data *hfc = fifo->hfc;
959 - int i, ii, currcnt, hdlci;
960 - struct sk_buff *skb;
962 - urb->dev = hfc->dev; /* security init */
963 - if ((!fifo->active) || (urb->status)) {
964 - hfc->service_request &= ~fifo->fifo_mask; /* no further handling */
965 - hfc->active_fifos &= ~fifo->fifo_mask; /* we are inactive */
966 - fifo->urb.interval = 0; /* cancel automatic rescheduling */
968 - dev_kfree_skb_any(fifo->buff);
972 + for(i = 0; i < 2; i++)
974 + if(fifo->iso[i].purb)
976 +#ifdef VERBOSE_USB_DEBUG
977 + printk(KERN_INFO "HFC-USB: Stopping iso chain for fifo %i.%i\n", fifo->fifonum, i);
979 + usb_unlink_urb(fifo->iso[i].purb);
980 + usb_free_urb(fifo->iso[i].purb);
981 + fifo->iso[i].purb = NULL;
986 + usb_unlink_urb(fifo->urb);
987 + usb_free_urb(fifo->urb);
993 - /* first check for any status changes */
994 - if ((urb->actual_length < fifo->rx_offset)
995 - || (urb->actual_length > fifo->usb_maxlen))
996 - return; /* error condition */
998 - if (fifo->rx_offset) {
999 - hfc->threshold_mask = fifo->buffer[1]; /* update threshold status */
1000 - fifo->next_complete = fifo->buffer[0] & 1;
1001 - if ((fifo->fifonum == HFCUSB_D_RX) &&
1002 - (hfc->led_req != hfc->led_act))
1003 - queue_control_request(hfc, HFCUSB_P_DATA, hfc->led_req);
1005 - /* check if rescheduling needed */
1007 - hfc->service_request & hfc->active_fifos & ~hfc->
1008 - threshold_mask)) {
1010 - usb_get_current_frame_number(hfc->dev);
1011 - txfifo = hfc->fifos + HFCUSB_B1_TX;
1014 - if ((i & txfifo->fifo_mask)
1015 - && (currcnt != txfifo->framenum)) {
1016 - hfc->service_request &=
1017 - ~txfifo->fifo_mask;
1018 - if (!txfifo->buff)
1019 - fill_tx_urb(txfifo);
1021 - usb_submit_urb(&txfifo->
1023 +// defines how much ISO packets are handled in one URB
1024 +static int iso_packets[8]={ISOC_PACKETS_B,ISOC_PACKETS_B,ISOC_PACKETS_B,ISOC_PACKETS_B,
1025 + ISOC_PACKETS_D,ISOC_PACKETS_D,ISOC_PACKETS_D,ISOC_PACKETS_D};
1027 +/*****************************************************/
1028 +/* transmit completion routine for all ISO tx fifos */
1029 +/*****************************************************/
1030 +static void tx_iso_complete(struct urb *urb)
1032 + iso_urb_struct *context_iso_urb = (iso_urb_struct *) urb->context;
1033 + usb_fifo *fifo = context_iso_urb->owner_fifo;
1034 + hfcusb_data *hfc = fifo->hfc;
1035 + int k, tx_offset, num_isoc_packets, sink, len, current_len,errcode,frame_complete,transp_mode,fifon;
1037 + __u8 threshtable[8] = { 1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1039 + fifon=fifo->fifonum;
1041 + // very weird error code when using ohci drivers, for now : ignore this error ... (MB)
1042 + if(urb->status == -EOVERFLOW)
1045 +#ifdef VERBOSE_USB_DEBUG
1046 + printk(KERN_INFO "HFC-USB: ignoring USB DATAOVERRUN for fifo %i \n",fifon);
1050 + if(fifo->active && !urb->status)
1053 + if(fifon<4 && hfc->b_mode[fifon/2]==L1_MODE_TRANS) transp_mode=TRUE;
1055 + threshbit = threshtable[fifon] & hfc->threshold_mask; // is threshold set for our channel?
1056 + num_isoc_packets=iso_packets[fifon];
1058 + if(fifon >= HFCUSB_D_TX)
1060 + sink = (threshbit) ? SINK_DMIN : SINK_DMAX; // how much bit go to the sink for D-channel?
1064 + sink = (threshbit) ? SINK_MIN : SINK_MAX; // how much bit go to the sink for B-channel?
1067 + // prepare ISO Urb
1068 + fill_isoc_urb(urb, fifo->hfc->dev, fifo->pipe,context_iso_urb->buffer, num_isoc_packets,
1069 + fifo->usb_packet_maxlen, fifo->intervall, tx_iso_complete, urb->context);
1070 + memset(context_iso_urb->buffer, 0, sizeof(context_iso_urb->buffer));
1072 + frame_complete=FALSE;
1074 + // Generate Iso Packets
1075 + for(k = 0; k < num_isoc_packets; ++k)
1079 + len = fifo->skbuff->len; // remaining length
1081 + fifo->bit_line -= sink; // we lower data margin every msec
1082 + current_len = (0 - fifo->bit_line) / 8;
1083 + if(current_len > 14) current_len = 14; // maximum 15 byte for every ISO packet makes our life easier
1084 + current_len = (len <= current_len) ? len : current_len;
1085 + fifo->bit_line += current_len * 8; // how much bit do we put on the line?
1087 + context_iso_urb->buffer[tx_offset] = 0;
1088 + if(current_len == len)
1092 + context_iso_urb->buffer[tx_offset] = 1; // here frame completion
1093 + fifo->bit_line += 32; // add 2 byte flags and 16bit CRC at end of ISDN frame
1095 + frame_complete = TRUE;
1098 + // copy bytes from buffer into ISO_URB
1099 + memcpy(context_iso_urb->buffer+tx_offset+1,fifo->skbuff->data,current_len);
1100 + skb_pull(fifo->skbuff,current_len);
1102 + // define packet delimeters within the URB buffer
1103 + urb->iso_frame_desc[k].offset = tx_offset;
1104 + urb->iso_frame_desc[k].length = current_len + 1;
1106 + tx_offset += (current_len + 1);
1107 + // printk(KERN_INFO "HFC-USB: fifonum:%d,%d bytes to send, %d bytes ISO packet,bitline:%d,sink:%d,threshbit:%d,threshmask:%x\n",fifon,len,current_len,fifo->bit_line,sink,threshbit,hfc->threshold_mask);
1110 + if(fifon==HFCUSB_B1_TX) handle_led(hfc,LED_B1_DATA);
1111 + if(fifon==HFCUSB_B2_TX) handle_led(hfc,LED_B2_DATA);
1116 + // we have no more data - generate 1 byte ISO packets
1117 + urb->iso_frame_desc[k].offset = tx_offset++;
1119 + urb->iso_frame_desc[k].length = 1;
1120 + fifo->bit_line -= sink; // we lower data margin every msec
1122 + if(fifo->bit_line < BITLINE_INF)
1124 + fifo->bit_line = BITLINE_INF;
1125 + //printk (KERN_INFO "HFC-USB: BITLINE_INF underrun\n");
1131 - /* handle l1 events */
1132 - if ((fifo->buffer[0] >> 4) != hfc->l1_state) {
1133 - last_state = hfc->l1_state;
1134 - hfc->l1_state = fifo->buffer[0] >> 4; /* update status */
1135 - if (timer_pending(&hfc->t4_timer))
1136 - del_timer(&hfc->t4_timer);
1137 - if (((hfc->l1_state == 3) &&
1138 - ((last_state == 7) ||
1139 - (last_state == 8))) ||
1140 - ((timer_pending(&hfc->t3_timer) &&
1141 - (hfc->l1_state == 8)))) {
1142 - hfc->t4_timer.expires = jiffies + 2;
1143 - add_timer(&hfc->t4_timer);
1145 - if (timer_pending(&hfc->t3_timer)
1146 - && (hfc->l1_state == 7))
1147 - del_timer(&hfc->t3_timer); /* no longer needed */
1148 - test_and_set_bit(HFCUSB_L1_STATECHANGE,
1150 - queue_task(&hfc->l1_tq, &tq_immediate);
1151 - mark_bh(IMMEDIATE_BH);
1152 + if(frame_complete)
1154 + // delete the buffer only once, here or in hfc_usb_l2l1() in a PH_DATA|REQUEST
1155 + fifo->delete_flg=TRUE;
1157 + fifo->hif->l1l2(fifo->hif,PH_DATA|CONFIRM,(void*)fifo->skbuff->truesize);
1159 + if(fifo->skbuff && fifo->delete_flg)
1161 + dev_kfree_skb_any(fifo->skbuff);
1162 + //printk(KERN_INFO "HFC-USB: skbuff=NULL on fifo:%d\n",fifo->fifonum);
1163 + fifo->skbuff = NULL;
1164 + fifo->delete_flg=FALSE;
1167 + frame_complete=FALSE;
1171 + errcode = usb_submit_urb(urb);
1174 + printk(KERN_INFO "HFC-USB: error submitting ISO URB: %i \n", errcode);
1181 + printk(KERN_INFO "HFC-USB: tx_iso_complete : urb->status %i, fifonum %i\n", urb->status,fifon);
1185 - /* check the length for data and move if present */
1186 - if (fifo->next_complete || (urb->actual_length > fifo->rx_offset)) {
1187 - i = fifo->buff->len + urb->actual_length - fifo->rx_offset; /* new total length */
1188 - hdlci = (fifo->transmode) ? 0 : 3;
1189 - if (i <= (fifo->max_size + hdlci)) {
1190 - memcpy(fifo->act_ptr,
1191 - fifo->buffer + fifo->rx_offset,
1192 - urb->actual_length - fifo->rx_offset);
1194 - (urb->actual_length - fifo->rx_offset);
1195 - fifo->buff->len +=
1196 - (urb->actual_length - fifo->rx_offset);
1198 - fifo->buff->len = fifo->max_size + 4; /* mark frame as to long */
1199 - if (fifo->next_complete && (urb->actual_length < fifo->usb_maxlen)) {
1200 - /* the frame is complete */
1201 - fifo->next_complete = 0;
1202 - if (((!*(fifo->act_ptr - 1)) || fifo->transmode) &&
1203 - (fifo->buff->len >= (hdlci + 1))
1204 - && (fifo->buff->len <=
1205 - (fifo->max_size + hdlci)) &&
1206 - ((skb = dev_alloc_skb(fifo->max_size + hdlci)) != NULL)) {
1207 - fifo->buff->len -= hdlci; /* adjust size */
1208 - switch (fifo->fifonum) {
1210 - skb_queue_tail(hfc->regd.
1216 - queue_task(&hfc->l1_tq,
1218 - mark_bh(IMMEDIATE_BH);
1220 +} /* tx_iso_complete */
1222 - case HFCUSB_B1_RX:
1223 - if (hfc->regd.brq[0]) {
1244 - case HFCUSB_B2_RX:
1245 - if (hfc->regd.brq[1]) {
1266 +/*****************************************************/
1267 +/* receive completion routine for all ISO tx fifos */
1268 +/*****************************************************/
1269 +static void rx_iso_complete(struct urb *urb)
1271 + iso_urb_struct *context_iso_urb = (iso_urb_struct *) urb->context;
1272 + usb_fifo *fifo = context_iso_urb->owner_fifo;
1273 + hfcusb_data *hfc = fifo->hfc;
1274 + int k, len, errcode, offset, num_isoc_packets,fifon;
1277 - case HFCUSB_PCM_RX:
1278 - skb_queue_tail(&hfc->regd.
1284 - queue_task(&hfc->l1_tq,
1286 - mark_bh(IMMEDIATE_BH);
1288 + fifon=fifo->fifonum;
1289 + // very weird error code when using ohci drivers, for now : ignore this error ... (MB)
1290 + if(urb->status == -EOVERFLOW)
1293 +#ifdef VERBOSE_USB_DEBUG
1294 + printk(KERN_INFO "HFC-USB: ignoring USB DATAOVERRUN for fifo %i \n",fifon);
1299 - dev_kfree_skb_any(fifo->
1302 + if(fifo->active && !urb->status)
1304 + num_isoc_packets=iso_packets[fifon];
1306 + // Generate D-Channel Iso Packets
1307 + for(k = 0; k < num_isoc_packets; ++k)
1309 + len=urb->iso_frame_desc[k].actual_length;
1310 + offset=urb->iso_frame_desc[k].offset;
1311 + buf=context_iso_urb->buffer+offset;
1313 + if(fifo->last_urblen!=fifo->usb_packet_maxlen)
1315 + // the threshold mask is in the 2nd status byte
1316 + hfc->threshold_mask=buf[1];
1317 + // the S0 state is in the upper half of the 1st status byte
1318 + state_handler(hfc,buf[0] >> 4);
1319 + // if we have more than the 2 status bytes -> collect data
1320 + if(len>2) collect_rx_frame(fifo,buf+2,len-2,buf[0]&1);
1324 - fifo->buff->len = 0; /* reset counter */
1325 - fifo->act_ptr = fifo->buff->data; /* and pointer */
1326 + else collect_rx_frame(fifo,buf,len,0);
1328 + fifo->last_urblen=len;
1332 + // prepare ISO Urb
1333 + fill_isoc_urb(urb, fifo->hfc->dev, fifo->pipe,context_iso_urb->buffer, num_isoc_packets,
1334 + fifo->usb_packet_maxlen, fifo->intervall, rx_iso_complete, urb->context);
1336 + errcode = usb_submit_urb(urb);
1339 + printk(KERN_INFO "HFC-USB: error submitting ISO URB: %i \n", errcode);
1346 + printk(KERN_INFO "HFC-USB: rx_iso_complete : urb->status %i, fifonum %i\n", urb->status,fifon);
1349 +} /* rx_iso_complete */
1352 +/*****************************************************/
1353 +/* collect data from interrupt or isochron in */
1354 +/*****************************************************/
1355 +static void collect_rx_frame(usb_fifo *fifo,__u8 *data,int len,int finish)
1357 + hfcusb_data *hfc = fifo->hfc;
1358 + int transp_mode,fifon;
1360 + fifon=fifo->fifonum;
1362 + if(fifon<4 && hfc->b_mode[fifon/2]==L1_MODE_TRANS) transp_mode=TRUE;
1364 + //printk(KERN_INFO "HFC-USB: got %d bytes finish:%d max_size:%d fifo:%d\n",len,finish,fifo->max_size,fifon);
1367 + // allocate sk buffer
1368 + fifo->skbuff=dev_alloc_skb(fifo->max_size + 3);
1371 + printk(KERN_INFO "HFC-USB: cannot allocate buffer (dev_alloc_skb) fifo:%d\n",fifon);
1377 + if(len && fifo->skbuff->len+len<fifo->max_size)
1379 + memcpy(skb_put(fifo->skbuff,len),data,len);
1381 + else printk(KERN_INFO "HCF-USB: got frame exceeded fifo->max_size:%d\n",fifo->max_size);
1383 + // give transparent data up, when 128 byte are available
1384 + if(transp_mode && fifo->skbuff->len>=128)
1386 + fifo->hif->l1l2(fifo->hif,PH_DATA | INDICATION,fifo->skbuff);
1387 + fifo->skbuff = NULL; // buffer was freed from upper layer
1391 + // we have a complete hdlc packet
1394 + if(!fifo->skbuff->data[fifo->skbuff->len-1])
1396 + skb_trim(fifo->skbuff,fifo->skbuff->len-3); // remove CRC & status
1398 + //printk(KERN_INFO "HFC-USB: got frame %d bytes on fifo:%d\n",fifo->skbuff->len,fifon);
1400 + if(fifon==HFCUSB_PCM_RX) fifo->hif->l1l2(fifo->hif,PH_DATA_E | INDICATION,fifo->skbuff);
1401 + else fifo->hif->l1l2(fifo->hif,PH_DATA | INDICATION,fifo->skbuff);
1403 + fifo->skbuff = NULL; // buffer was freed from upper layer
1407 + printk(KERN_INFO "HFC-USB: got frame %d bytes but CRC ERROR!!!\n",fifo->skbuff->len);
1409 + skb_trim(fifo->skbuff,0); // clear whole buffer
1413 + // LED flashing only in HDLC mode
1416 + if(fifon==HFCUSB_B1_RX) handle_led(hfc,LED_B1_DATA);
1417 + if(fifon==HFCUSB_B2_RX) handle_led(hfc,LED_B2_DATA);
1421 +/***********************************************/
1422 +/* receive completion routine for all rx fifos */
1423 +/***********************************************/
1424 +static void rx_complete(struct urb *urb)
1428 + usb_fifo *fifo = (usb_fifo *) urb->context; /* pointer to our fifo */
1429 + hfcusb_data *hfc = fifo->hfc;
1431 + urb->dev = hfc->dev; /* security init */
1433 + if((!fifo->active) || (urb->status)) {
1434 +#ifdef VERBOSE_USB_DEBUG
1435 + printk(KERN_INFO "HFC-USB: RX-Fifo %i is going down (%i)\n", fifo->fifonum, urb->status);
1437 + fifo->urb->interval = 0; /* cancel automatic rescheduling */
1438 + if(fifo->skbuff) {
1439 + dev_kfree_skb_any(fifo->skbuff);
1440 + fifo->skbuff = NULL;
1444 - fifo->rx_offset = (urb->actual_length < fifo->usb_maxlen) ? 2 : 0;
1445 -} /* rx_complete */
1447 + len=urb->actual_length;
1450 + if(fifo->last_urblen!=fifo->usb_packet_maxlen) {
1451 + // the threshold mask is in the 2nd status byte
1452 + hfc->threshold_mask=buf[1];
1453 + // the S0 state is in the upper half of the 1st status byte
1454 + state_handler(hfc,buf[0] >> 4);
1455 + // if we have more than the 2 status bytes -> collect data
1456 + if(len>2) collect_rx_frame(fifo,buf+2,urb->actual_length-2,buf[0]&1);
1458 + collect_rx_frame(fifo,buf,urb->actual_length,0);
1460 + fifo->last_urblen=urb->actual_length;
1463 +} /* rx_complete */
1467 /***************************************************/
1468 /* start the interrupt transfer for the given fifo */
1469 /***************************************************/
1471 -start_rx_fifo(usb_fifo * fifo)
1472 +static void start_int_fifo(usb_fifo * fifo)
1475 - return; /* still active */
1478 - dev_alloc_skb(fifo->max_size + (fifo->transmode ? 0 : 3))))
1480 - fifo->act_ptr = fifo->buff->data;
1481 - FILL_INT_URB(&fifo->urb, fifo->hfc->dev, fifo->pipe, fifo->buffer,
1482 - fifo->usb_maxlen, rx_complete, fifo, fifo->intervall);
1483 - fifo->next_complete = 0;
1484 - fifo->rx_offset = 2;
1485 - fifo->active = 1; /* must be marked active */
1486 - fifo->hfc->active_fifos |= fifo->fifo_mask;
1487 - if (usb_submit_urb(&fifo->urb)) {
1490 +#ifdef VERBOSE_USB_DEBUG
1491 + printk(KERN_INFO "HFC-USB: starting intr IN fifo:%d\n", fifo->fifonum);
1494 + fifo->urb = usb_alloc_urb(0);
1498 + usb_fill_int_urb(fifo->urb, fifo->hfc->dev, fifo->pipe, fifo->buffer,
1499 + fifo->usb_packet_maxlen, rx_complete, fifo, fifo->intervall);
1500 + fifo->active = 1; /* must be marked active */
1501 + errcode = usb_submit_urb(fifo->urb);
1505 + printk(KERN_INFO "HFC-USB: submit URB error(start_int_info): status:%i\n", errcode);
1507 - fifo->hfc->active_fifos &= ~fifo->fifo_mask;
1508 - dev_kfree_skb_any(fifo->buff);
1509 - fifo->buff = NULL;
1510 + fifo->skbuff = NULL;
1512 -} /* start_rx_fifo */
1513 +} /* start_int_fifo */
1515 -/***************************************************************/
1516 -/* control completion routine handling background control cmds */
1517 -/***************************************************************/
1519 -ctrl_complete(purb_t urb)
1520 +/*****************************/
1521 +/* set the B-channel mode */
1522 +/*****************************/
1523 +static void set_hfcmode(hfcusb_data *hfc,int channel,int mode)
1525 - hfcusb_data *hfc = (hfcusb_data *) urb->context;
1526 + __u8 val,idx_table[2]={0,2};
1528 - urb->dev = hfc->dev;
1529 - if (hfc->ctrl_cnt) {
1530 - switch (hfc->ctrl_buff[hfc->ctrl_out_idx].hfc_reg) {
1533 - hfc->ctrl_buff[hfc->ctrl_out_idx].
1536 - case HFCUSB_F_USAGE:
1537 - if (!hfc->dfifo_fill) {
1538 - fill_tx_urb(hfc->fifos +
1540 - if (hfc->fifos[HFCUSB_D_TX].buff)
1541 - usb_submit_urb(&hfc->
1546 - queue_control_request(hfc,
1549 - queue_control_request(hfc,
1554 - case HFCUSB_SCTRL_R:
1555 - switch (hfc->ctrl_fifo) {
1556 - case HFCUSB_B1_RX:
1557 - if (hfc->bch_enables & 1)
1558 - start_rx_fifo(hfc->
1563 - case HFCUSB_B2_RX:
1564 - if (hfc->bch_enables & 2)
1565 - start_rx_fifo(hfc->
1571 - if (hfc->bch_enables & 3)
1572 - hfc->led_req |= LED_BCH;
1574 - hfc->led_req &= ~LED_BCH;
1576 - case HFCUSB_P_DATA:
1578 - hfc->ctrl_buff[hfc->ctrl_out_idx].
1582 - hfc->ctrl_cnt--; /* decrement actual count */
1583 - if (++hfc->ctrl_out_idx >= HFC_CTRL_BUFSIZE)
1584 - hfc->ctrl_out_idx = 0; /* pointer wrap */
1585 - ctrl_start_transfer(hfc); /* start next transfer */
1586 +#ifdef VERBOSE_ISDN_DEBUG
1587 + printk (KERN_INFO "HFC-USB: setting channel %d to mode %d\n",channel,mode);
1590 + hfc->b_mode[channel]=mode;
1594 + if(mode!=L1_MODE_NULL) val=8; // enable fifo?
1595 + if(mode==L1_MODE_TRANS) val|=2; // set transparent bit
1597 + queue_control_request(hfc,HFCUSB_FIFO,idx_table[channel],1); // set FIFO to transmit register
1598 + queue_control_request(hfc,HFCUSB_CON_HDLC,val,1);
1599 + queue_control_request(hfc,HFCUSB_INC_RES_F,2,1); // reset fifo
1601 + queue_control_request(hfc,HFCUSB_FIFO,idx_table[channel]+1,1); // set FIFO to receive register
1602 + queue_control_request(hfc,HFCUSB_CON_HDLC,val,1);
1603 + queue_control_request(hfc,HFCUSB_INC_RES_F,2,1); // reset fifo
1606 + if(hfc->b_mode[0]) val|=1;
1607 + if(hfc->b_mode[1]) val|=2;
1608 + queue_control_request(hfc,HFCUSB_SCTRL,val,1);
1611 + if(hfc->b_mode[0]) val|=1;
1612 + if(hfc->b_mode[1]) val|=2;
1613 + queue_control_request(hfc,HFCUSB_SCTRL_R,val,1);
1615 + if(mode==L1_MODE_NULL)
1617 + if(channel) handle_led(hfc,LED_B2_OFF);
1618 + else handle_led(hfc,LED_B1_OFF);
1620 -} /* ctrl_complete */
1623 + if(channel) handle_led(hfc,LED_B2_ON);
1624 + else handle_led(hfc,LED_B1_ON);
1628 -/*****************************************/
1629 -/* Layer 1 + D channel access from HiSax */
1630 -/*****************************************/
1632 -hfcusb_l1_access(void *drvarg, int pr, void *arg)
1634 - hfcusb_data *hfc = (hfcusb_data *) drvarg;
1637 - case (PH_DATA | REQUEST):
1638 - case (PH_PULL | INDICATION):
1639 - skb_queue_tail(hfc->regd.dsq,
1640 - (struct sk_buff *) arg);
1641 - if (!hfc->fifos[HFCUSB_D_TX].active
1642 - && !hfc->dfifo_fill) {
1643 - fill_tx_urb(hfc->fifos + HFCUSB_D_TX);
1644 - hfc->active_fifos |=
1645 - hfc->fifos[HFCUSB_D_TX].fifo_mask;
1646 - usb_submit_urb(&hfc->fifos[HFCUSB_D_TX].
1650 - case (PH_ACTIVATE | REQUEST):
1651 - switch (hfc->l1_state) {
1654 - hfc->regd.dch_l1l2(hfc->regd.arg_hisax,
1656 - INDICATION), NULL);
1658 + --------------------------------------------------------------------------------------
1659 + from here : hisax_if callback routines :
1660 + - void hfc_usb_d_l2l1(struct hisax_if *hisax_d_if, int pr, void *arg) {
1664 - hfc->regd.dch_l1l2(hfc->regd.arg_hisax,
1666 - INDICATION), NULL);
1667 + l1 to l2 routines :
1668 + - static void hfc_usb_l1l2(hfcusb_data * hfc)
1672 - queue_control_request(hfc, HFCUSB_STATES, 0x60); /* start activation */
1673 - hfc->t3_timer.expires =
1674 - jiffies + (HFC_TIMER_T3 * HZ) / 1000;
1675 - if (!timer_pending(&hfc->t3_timer))
1676 - add_timer(&hfc->t3_timer);
1682 - case (PH_DEACTIVATE | REQUEST):
1683 - queue_control_request(hfc, HFCUSB_STATES, 0x40); /* start deactivation */
1686 - printk(KERN_INFO "unknown hfcusb l1_access 0x%x\n",
1690 -} /* hfcusb_l1_access */
1692 -/*******************************/
1693 -/* B channel access from HiSax */
1694 -/*******************************/
1696 -hfcusb_bch_access(void *drvarg, int chan, int pr, void *arg)
1698 - hfcusb_data *hfc = (hfcusb_data *) drvarg;
1699 - usb_fifo *fifo = hfc->fifos + (chan ? HFCUSB_B2_TX : HFCUSB_B1_TX);
1703 - case (PH_DATA | REQUEST):
1704 - case (PH_PULL | INDICATION):
1705 - save_flags(flags);
1707 - if (!fifo->active) {
1708 - fill_tx_urb(fifo);
1709 - hfc->active_fifos |= fifo->fifo_mask;
1710 - usb_submit_urb(&fifo->urb);
1712 - restore_flags(flags);
1714 - case (PH_ACTIVATE | REQUEST):
1715 - if (!((int) arg)) {
1716 - hfc->bch_enables &= ~(1 << chan);
1717 - if (fifo->active) {
1719 - usb_unlink_urb(&fifo->urb);
1720 +void hfc_usb_l2l1(struct hisax_if *my_hisax_if, int pr, void *arg)
1722 + usb_fifo *fifo = my_hisax_if->priv;
1723 + hfcusb_data *hfc = fifo->hfc;
1726 + case PH_ACTIVATE | REQUEST:
1727 + if(fifo->fifonum==HFCUSB_D_TX)
1729 +#ifdef VERBOSE_ISDN_DEBUG
1730 + printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_ACTIVATE | REQUEST\n");
1732 + queue_control_request(hfc, HFCUSB_STATES,0x60,1); /* make activation */
1733 + hfc->t3_timer.expires = jiffies + (HFC_TIMER_T3 * HZ) / 1000;
1734 + if(!timer_pending(&hfc->t3_timer)) add_timer(&hfc->t3_timer);
1736 - save_flags(flags);
1738 - queue_control_request(hfc, HFCUSB_FIFO,
1740 - queue_control_request(hfc,
1741 - HFCUSB_INC_RES_F, 2);
1742 - queue_control_request(hfc, HFCUSB_CON_HDLC,
1744 - queue_control_request(hfc, HFCUSB_SCTRL,
1746 - hfc->bch_enables);
1747 - queue_control_request(hfc, HFCUSB_SCTRL_R,
1748 - hfc->bch_enables);
1749 - restore_flags(flags);
1751 - if (fifo->active) {
1753 - usb_unlink_urb(&fifo->urb);
1756 +#ifdef VERBOSE_ISDN_DEBUG
1757 + printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_ACTIVATE | REQUEST\n");
1759 + set_hfcmode(hfc,(fifo->fifonum==HFCUSB_B1_TX) ? 0 : 1 ,(int)arg);
1760 + fifo->hif->l1l2(fifo->hif,PH_ACTIVATE | INDICATION, NULL);
1762 - return; /* fifo deactivated */
1764 - fifo->transmode = ((int) arg == L1_MODE_TRANS);
1766 - ((fifo->transmode) ? fifo->
1767 - usb_maxlen : MAX_BCH_SIZE);
1768 - (fifo + 1)->transmode = fifo->transmode;
1769 - (fifo + 1)->max_size = fifo->max_size;
1770 - hfc->bch_enables |= (1 << chan);
1771 - save_flags(flags);
1773 - queue_control_request(hfc, HFCUSB_FIFO,
1775 - queue_control_request(hfc, HFCUSB_CON_HDLC,
1777 - transmode) ? 9 : 11));
1778 - queue_control_request(hfc, HFCUSB_INC_RES_F, 2);
1779 - queue_control_request(hfc, HFCUSB_SCTRL,
1780 - 0x40 + hfc->bch_enables);
1781 - if ((int) arg == L1_MODE_HDLC)
1782 - queue_control_request(hfc, HFCUSB_CON_HDLC,
1784 - queue_control_request(hfc, HFCUSB_FIFO,
1785 - fifo->fifonum + 1);
1786 - queue_control_request(hfc, HFCUSB_CON_HDLC,
1788 - transmode) ? 8 : 10));
1789 - queue_control_request(hfc, HFCUSB_INC_RES_F, 2);
1790 - queue_control_request(hfc, HFCUSB_SCTRL_R,
1791 - hfc->bch_enables);
1792 - restore_flags(flags);
1798 - "unknown hfcusb bch_access chan %d 0x%x\n",
1802 -} /* hfcusb_bch_access */
1804 + case PH_DEACTIVATE | REQUEST:
1805 + if(fifo->fifonum==HFCUSB_D_TX)
1807 +#ifdef VERBOSE_ISDN_DEBUG
1808 + printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_DEACTIVATE | REQUEST\n");
1810 + printk (KERN_INFO "HFC-USB: ISDN TE device should not deativate...\n");
1814 +#ifdef VERBOSE_ISDN_DEBUG
1815 + printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_DEACTIVATE | REQUEST\n");
1817 + set_hfcmode(hfc,(fifo->fifonum==HFCUSB_B1_TX) ? 0 : 1 ,(int)L1_MODE_NULL);
1818 + fifo->hif->l1l2(fifo->hif,PH_DEACTIVATE | INDICATION, NULL);
1821 + case PH_DATA | REQUEST:
1822 + if(fifo->skbuff && fifo->delete_flg)
1824 + dev_kfree_skb_any(fifo->skbuff);
1825 + //printk(KERN_INFO "skbuff=NULL on fifo:%d\n",fifo->fifonum);
1826 + fifo->skbuff = NULL;
1827 + fifo->delete_flg=FALSE;
1830 + fifo->skbuff=arg; // we have a new buffer
1832 + //if(fifo->fifonum==HFCUSB_D_TX) printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_DATA | REQUEST\n");
1833 + //else printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_DATA | REQUEST\n");
1836 + printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1: unkown state : %#x\n", pr);
1841 +// valid configurations
1842 +#define CNF_4INT3ISO 1 // 4 INT IN, 3 ISO OUT
1843 +#define CNF_3INT3ISO 2 // 3 INT IN, 3 ISO OUT
1844 +#define CNF_4ISO3ISO 3 // 4 ISO IN, 3 ISO OUT
1845 +#define CNF_3ISO3ISO 4 // 3 ISO IN, 3 ISO OUT
1849 + --------------------------------------------------------------------------------------
1850 + From here on USB initialization and deactivation related routines are implemented :
1853 + is the main Entry Point for the USB Subsystem when the device get plugged
1854 + in. This function calls usb_register with usb_driver as parameter.
1855 + Here, further entry points for probing (hfc_usb_probe) and disconnecting
1856 + the device (hfc_usb_disconnect) are published, as the id_table
1859 + this function is called by the usb subsystem, and steps through the alternate
1860 + settings of the currently plugged in device to detect all Endpoints needed to
1862 + Needed EndPoints are
1863 + 3 (+1) IntIn EndPoints (D-in, E-in, B1-in, B2-in, (E-in)) or
1864 + 3 (+1) Isochron In Endpoints (D-out, B1-out, B2-out) and 3 IsoOut Endpoints
1865 + The currently used transfer mode of on the Out-Endpoints will be stored in
1866 + hfc->usb_transfer_mode and is either USB_INT or USB_ISO
1867 + When a valid alternate setting could be found, the usb_init (see blow)
1868 + function is called
1871 + Here, the HFC_USB Chip itself gets initialized and the USB framework to send/receive
1872 + Data to/from the several EndPoints are initialized:
1873 + The E- and D-Channel Int-In chain gets started
1874 + The IsoChain for the Iso-Out traffic get started
1876 + - hfc_usb_disconnect
1877 + this function is called by the usb subsystem and has to free all resources
1878 + and stop all usb traffic to allow a proper hotplugging disconnect.
1882 /***************************************************************************/
1883 /* usb_init is called once when a new matching device is detected to setup */
1884 -/* main parmeters. It registers the driver at the main hisax module. */
1885 +/* main parameters. It registers the driver at the main hisax module. */
1886 /* on success 0 is returned. */
1887 /***************************************************************************/
1889 -usb_init(hfcusb_data * hfc)
1890 +static int usb_init(hfcusb_data * hfc)
1897 + struct hisax_b_if *p_b_if[2];
1899 /* check the chip id */
1900 - if ((Read_hfc(hfc, HFCUSB_CHIP_ID, &b) != 1) ||
1901 - (b != HFCUSB_CHIPID)) {
1902 + printk(KERN_INFO "HFCUSB_CHIP_ID begin\n");
1903 + if (read_usb(hfc, HFCUSB_CHIP_ID, &b) != 1) {
1904 + printk(KERN_INFO "HFC-USB: cannot read chip id\n");
1907 + printk(KERN_INFO "HFCUSB_CHIP_ID %x\n", b);
1908 + if (b != HFCUSB_CHIPID) {
1909 printk(KERN_INFO "HFC-USB: Invalid chip id 0x%02x\n", b);
1914 /* first set the needed config, interface and alternate */
1915 - usb_set_configuration(hfc->dev, 1);
1916 - usb_set_interface(hfc->dev, hfc->if_used, hfc->alt_used);
1917 + printk(KERN_INFO "usb_init 1\n");
1918 +// usb_set_configuration(hfc->dev, 1);
1919 + printk(KERN_INFO "usb_init 2\n");
1920 + err = usb_set_interface(hfc->dev, hfc->if_used, hfc->alt_used);
1921 + printk(KERN_INFO "usb_init usb_set_interface return %d\n", err);
1922 + /* now we initialize the chip */
1923 + write_usb(hfc, HFCUSB_CIRM, 8); // do reset
1924 + write_usb(hfc, HFCUSB_CIRM, 0x10); // aux = output, reset off
1926 - /* init the led state request */
1927 - hfc->led_req = LED_DRIVER;
1928 + // set USB_SIZE to match the the wMaxPacketSize for INT or BULK transfers
1929 + write_usb(hfc, HFCUSB_USB_SIZE,(hfc->packet_size/8) | ((hfc->packet_size/8) << 4));
1931 - /* now we initialise the chip */
1932 - Write_hfc(hfc, HFCUSB_CIRM, 0x10); /* aux = output, reset off */
1933 - Write_hfc(hfc, HFCUSB_P_DATA, 0); /* leds = off */
1934 - Write_hfc(hfc, HFCUSB_USB_SIZE,
1935 - (hfc->fifos[HFCUSB_B1_TX].usb_maxlen >> 3) |
1936 - ((hfc->fifos[HFCUSB_B1_RX].usb_maxlen >> 3) << 4));
1937 + // set USB_SIZE_I to match the the wMaxPacketSize for ISO transfers
1938 + write_usb(hfc, HFCUSB_USB_SIZE_I, hfc->iso_packet_size);
1940 /* enable PCM/GCI master mode */
1941 - Write_hfc(hfc, HFCUSB_MST_MODE1, 0); /* set default values */
1942 - Write_hfc(hfc, HFCUSB_MST_MODE0, 1); /* enable master mode */
1943 + write_usb(hfc, HFCUSB_MST_MODE1, 0); /* set default values */
1944 + write_usb(hfc, HFCUSB_MST_MODE0, 1); /* enable master mode */
1946 /* init the fifos */
1947 - Write_hfc(hfc, HFCUSB_F_THRES, (HFCUSB_TX_THRESHOLD >> 3) |
1948 - ((HFCUSB_RX_THRESHOLD >> 3) << 4));
1949 + write_usb(hfc, HFCUSB_F_THRES, (HFCUSB_TX_THRESHOLD/8) |((HFCUSB_RX_THRESHOLD/8) << 4));
1951 - for (i = 0, fifo = hfc->fifos + i; i < HFCUSB_NUM_FIFOS;
1953 - Write_hfc(hfc, HFCUSB_FIFO, i); /* select the desired fifo */
1955 - fifo->transmode = 0; /* hdlc mode selected */
1956 - fifo->buff = NULL; /* init buffer pointer */
1958 - (i <= HFCUSB_B2_RX) ? MAX_BCH_SIZE : MAX_DFRAME_LEN;
1959 - Write_hfc(hfc, HFCUSB_HDLC_PAR, ((i <= HFCUSB_B2_RX) ? 0 : 2)); /* data length */
1960 - Write_hfc(hfc, HFCUSB_CON_HDLC, ((i & 1) ? 0x08 : 0x09)); /* rx hdlc, tx fill 1 */
1961 - Write_hfc(hfc, HFCUSB_INC_RES_F, 2); /* reset the fifo */
1964 - Write_hfc(hfc, HFCUSB_CLKDEL, 0x0f); /* clock delay value */
1965 - Write_hfc(hfc, HFCUSB_STATES, 3 | 0x10); /* set deactivated mode */
1966 - Write_hfc(hfc, HFCUSB_STATES, 3); /* enable state machine */
1967 + fifo = hfc->fifos;
1968 + for(i = 0; i < HFCUSB_NUM_FIFOS; i++)
1970 + write_usb(hfc, HFCUSB_FIFO, i); /* select the desired fifo */
1971 + fifo[i].skbuff = NULL; /* init buffer pointer */
1972 + fifo[i].max_size = (i <= HFCUSB_B2_RX) ? MAX_BCH_SIZE : MAX_DFRAME_LEN;
1973 + fifo[i].last_urblen=0;
1974 + write_usb(hfc, HFCUSB_HDLC_PAR, ((i <= HFCUSB_B2_RX) ? 0 : 2)); // set 2 bit for D- & E-channel
1975 + write_usb(hfc, HFCUSB_CON_HDLC, ((i==HFCUSB_D_TX) ? 0x09 : 0x08)); // rx hdlc, enable IFF for D-channel
1976 + write_usb(hfc, HFCUSB_INC_RES_F, 2); /* reset the fifo */
1979 - Write_hfc(hfc, HFCUSB_SCTRL_R, 0); /* disable both B receivers */
1980 - Write_hfc(hfc, HFCUSB_SCTRL, 0x40); /* disable B transmitters + cap mode */
1981 + write_usb(hfc, HFCUSB_CLKDEL, 0x0f); /* clock delay value */
1982 + write_usb(hfc, HFCUSB_STATES, 3 | 0x10); /* set deactivated mode */
1983 + write_usb(hfc, HFCUSB_STATES, 3); /* enable state machine */
1985 + write_usb(hfc, HFCUSB_SCTRL_R, 0); /* disable both B receivers */
1986 + write_usb(hfc, HFCUSB_SCTRL, 0x40); /* disable B transmitters + capacitive mode */
1988 + // set both B-channel to not connected
1989 + hfc->b_mode[0]=L1_MODE_NULL;
1990 + hfc->b_mode[1]=L1_MODE_NULL;
1992 + hfc->l1_activated=FALSE;
1994 + hfc->led_new_data=0;
1996 - /* init the l1 timer */
1997 + /* init the t3 timer */
1998 init_timer(&hfc->t3_timer);
1999 hfc->t3_timer.data = (long) hfc;
2000 - hfc->t3_timer.function = (void *) l1_timer_expire;
2001 + hfc->t3_timer.function = (void *) l1_timer_expire_t3;
2002 + /* init the t4 timer */
2003 + init_timer(&hfc->t4_timer);
2004 hfc->t4_timer.data = (long) hfc;
2005 - hfc->t4_timer.function = (void *) l1_timer_expire;
2006 - hfc->l1_tq.routine = (void *) (void *) usb_l1d_bh;
2007 - hfc->l1_tq.sync = 0;
2008 - hfc->l1_tq.data = hfc;
2010 - /* init the background control machinery */
2011 - hfc->ctrl_read.requesttype = 0xc0;
2012 - hfc->ctrl_read.request = 1;
2013 - hfc->ctrl_read.length = 1;
2014 - hfc->ctrl_write.requesttype = 0x40;
2015 - hfc->ctrl_write.request = 0;
2016 - hfc->ctrl_write.length = 0;
2017 - FILL_CONTROL_URB(&hfc->ctrl_urb, hfc->dev, hfc->ctrl_out_pipe,
2018 - (u_char *) & hfc->ctrl_write, NULL, 0,
2019 - ctrl_complete, hfc);
2021 - /* init the TX-urbs */
2022 - fifo = hfc->fifos + HFCUSB_D_TX;
2023 - FILL_BULK_URB(&fifo->urb, hfc->dev, fifo->pipe,
2024 - (u_char *) fifo->buffer, 0, tx_complete, fifo);
2025 - fifo = hfc->fifos + HFCUSB_B1_TX;
2026 - FILL_BULK_URB(&fifo->urb, hfc->dev, fifo->pipe,
2027 - (u_char *) fifo->buffer, 0, tx_complete, fifo);
2028 - fifo = hfc->fifos + HFCUSB_B2_TX;
2029 - FILL_BULK_URB(&fifo->urb, hfc->dev, fifo->pipe,
2030 - (u_char *) fifo->buffer, 0, tx_complete, fifo);
2032 - /* init the E-buffer */
2033 - skb_queue_head_init(&hfc->regd.erq);
2035 - /* now register ourself at hisax */
2036 - hfc->regd.version = HISAX_LOAD_VERSION; /* set our version */
2037 - hfc->regd.cmd = HISAX_LOAD_REGISTER; /* register command */
2038 - hfc->regd.argl1 = (void *) hfc; /* argument for our local routine */
2039 - hfc->regd.dch_l2l1 = hfcusb_l1_access;
2040 - hfc->regd.bch_l2l1 = hfcusb_bch_access;
2041 - hfc->regd.drvname = "hfc_usb";
2042 - if (hisax_register_hfcusb(&hfc->regd)) {
2043 - printk(KERN_INFO "HFC-USB failed to register at hisax\n");
2044 - Write_hfc(hfc, HFCUSB_CIRM, 0x08); /* aux = input, reset on */
2048 - /* startup the D- and E-channel fifos */
2049 - start_rx_fifo(hfc->fifos + HFCUSB_D_RX); /* D-fifo */
2050 - if (hfc->fifos[HFCUSB_PCM_RX].pipe)
2051 - start_rx_fifo(hfc->fifos + HFCUSB_PCM_RX); /* E-fifo */
2052 + hfc->t4_timer.function = (void *) l1_timer_expire_t4;
2053 + /* init the led timer */
2054 + init_timer(&hfc->led_timer);
2055 + hfc->led_timer.data = (long) hfc;
2056 + hfc->led_timer.function = (void *) led_timer;
2057 + // trigger 4 hz led timer
2058 + hfc->led_timer.expires = jiffies + (LED_TIME * HZ) / 1000;
2059 + if(!timer_pending(&hfc->led_timer)) add_timer(&hfc->led_timer);
2061 + // init the background machinery for control requests
2062 + hfc->ctrl_read.bRequestType = 0xc0;
2063 + hfc->ctrl_read.bRequest = 1;
2064 + hfc->ctrl_read.wLength = 1;
2065 + hfc->ctrl_write.bRequestType = 0x40;
2066 + hfc->ctrl_write.bRequest = 0;
2067 + hfc->ctrl_write.wLength = 0;
2068 + usb_fill_control_urb(hfc->ctrl_urb, hfc->dev, hfc->ctrl_out_pipe,(u_char *) & hfc->ctrl_write, NULL, 0, ctrl_complete, hfc);
2070 + /* Init All Fifos */
2071 + for(i = 0; i < HFCUSB_NUM_FIFOS; i++)
2073 + hfc->fifos[i].iso[0].purb = NULL;
2074 + hfc->fifos[i].iso[1].purb = NULL;
2075 + hfc->fifos[i].active = 0;
2078 + // register like Germaschewski :
2079 + hfc->d_if.owner = THIS_MODULE;
2080 + hfc->d_if.ifc.priv = &hfc->fifos[HFCUSB_D_TX];
2081 + hfc->d_if.ifc.l2l1 = hfc_usb_l2l1;
2083 + for (i=0; i<2; i++)
2085 + hfc->b_if[i].ifc.priv = &hfc->fifos[HFCUSB_B1_TX+i*2];
2086 + hfc->b_if[i].ifc.l2l1 = hfc_usb_l2l1;
2087 + p_b_if[i] = &hfc->b_if[i];
2090 + hfc->protocol = 2; /* default EURO ISDN, should be a module_param */
2091 + hisax_register(&hfc->d_if, p_b_if, "hfc_usb", hfc->protocol);
2093 + for (i=0; i<4; i++)
2094 + hfc->fifos[i].hif=&p_b_if[i/2]->ifc;
2095 + for (i=4; i<8; i++)
2096 + hfc->fifos[i].hif=&hfc->d_if.ifc;
2098 + // 3 (+1) INT IN + 3 ISO OUT
2099 + if(hfc->cfg_used == CNF_3INT3ISO || hfc->cfg_used == CNF_4INT3ISO)
2101 + start_int_fifo(hfc->fifos + HFCUSB_D_RX); // Int IN D-fifo
2102 + if(hfc->fifos[HFCUSB_PCM_RX].pipe) start_int_fifo(hfc->fifos + HFCUSB_PCM_RX); // E-fifo
2103 + start_int_fifo(hfc->fifos + HFCUSB_B1_RX); // Int IN B1-fifo
2104 + start_int_fifo(hfc->fifos + HFCUSB_B2_RX); // Int IN B2-fifo
2107 + // 3 (+1) ISO IN + 3 ISO OUT
2108 + if(hfc->cfg_used==CNF_3ISO3ISO || hfc->cfg_used==CNF_4ISO3ISO)
2110 + start_isoc_chain(hfc->fifos + HFCUSB_D_RX, ISOC_PACKETS_D, rx_iso_complete,16);
2111 + if(hfc->fifos[HFCUSB_PCM_RX].pipe) start_isoc_chain(hfc->fifos + HFCUSB_PCM_RX, ISOC_PACKETS_D, rx_iso_complete,16);
2112 + start_isoc_chain(hfc->fifos + HFCUSB_B1_RX, ISOC_PACKETS_B, rx_iso_complete,16);
2113 + start_isoc_chain(hfc->fifos + HFCUSB_B2_RX, ISOC_PACKETS_B, rx_iso_complete,16);
2116 + start_isoc_chain(hfc->fifos + HFCUSB_D_TX, ISOC_PACKETS_D, tx_iso_complete,1);
2117 + start_isoc_chain(hfc->fifos + HFCUSB_B1_TX, ISOC_PACKETS_B, tx_iso_complete,1);
2118 + start_isoc_chain(hfc->fifos + HFCUSB_B2_TX, ISOC_PACKETS_B, tx_iso_complete,1);
2120 + handle_led(hfc,LED_POWER_ON);
2126 +/****************************************/
2127 +/* data defining the devices to be used */
2128 +/****************************************/
2129 +// static __devinitdata const struct usb_device_id hfc_usb_idtab[3] = {
2130 +static struct usb_device_id hfc_usb_idtab[] = {
2131 + {USB_DEVICE(0x7b0, 0x0007)}, /* Billion USB TA 2 */
2132 + {USB_DEVICE(0x742, 0x2008)}, /* Stollmann USB TA */
2133 + {USB_DEVICE(0x959, 0x2bd0)}, /* Colognechip USB eval TA */
2134 + {USB_DEVICE(0x8e3, 0x0301)}, /* OliTec ISDN USB */
2135 + {USB_DEVICE(0x675, 0x1688)}, /* DrayTec ISDN USB */
2136 + {USB_DEVICE(0x7fa, 0x0846)}, /* Bewan ISDN USB TA */
2137 + {} /* end with an all-zeroes entry */
2140 +MODULE_AUTHOR("Peter Sprenger (sprenger@moving-byters.de)/Martin Bachem (info@colognechip.com)");
2141 +MODULE_DESCRIPTION("HFC I4L USB driver");
2142 +MODULE_DEVICE_TABLE(usb, hfc_usb_idtab);
2143 +MODULE_LICENSE("GPL");
2145 +#define EP_NUL 1 // Endpoint at this position not allowed
2146 +#define EP_NOP 2 // all type of endpoints allowed at this position
2147 +#define EP_ISO 3 // Isochron endpoint mandatory at this position
2148 +#define EP_BLK 4 // Bulk endpoint mandatory at this position
2149 +#define EP_INT 5 // Interrupt endpoint mandatory at this position
2151 +// this array represents all endpoints possible in the HCF-USB
2152 +// the last 2 entries are the configuration number and the minimum interval for Interrupt endpoints
2153 +int validconf[][18]=
2155 + // INT in, ISO out config
2156 + {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},
2157 + {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},
2158 + // ISO in, ISO out config
2159 + {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},
2160 + {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},
2161 + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} // EOL element
2164 +// string description of chosen config
2167 + "4 Interrupt IN + 3 Isochron OUT",
2168 + "3 Interrupt IN + 3 Isochron OUT",
2169 + "4 Isochron IN + 3 Isochron OUT",
2170 + "3 Isochron IN + 3 Isochron OUT"
2176 /*************************************************/
2177 /* function called to probe a new plugged device */
2178 /*************************************************/
2180 -hfc_usb_probe(struct usb_device *dev, unsigned int interface
2181 -#ifdef COMPAT_HAS_USB_IDTAB
2182 - , const struct usb_device_id *id_table)
2186 +//static int hfc_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
2187 +static void* hfc_usb_probe(struct usb_device *dev, unsigned int ifnum, const struct usb_device_id *id)
2189 + //struct usb_device *dev= interface_to_usbdev(intf);
2190 + struct usb_interface* intf = dev->actconfig->interface + ifnum;
2191 hfcusb_data *context;
2192 - struct usb_interface *ifp = dev->actconfig->interface + interface;
2193 - struct usb_interface_descriptor *ifdp =
2194 - ifp->altsetting + ifp->act_altsetting;
2195 - struct usb_endpoint_descriptor *epd;
2196 - int i, idx, ep_msk;
2198 -#ifdef COMPAT_HAS_USB_IDTAB
2199 - if (id_table && (dev->descriptor.idVendor == id_table->idVendor) &&
2200 - (dev->descriptor.idProduct == id_table->idProduct) &&
2202 - if ((((dev->descriptor.idVendor == 0x959) &&
2203 - (dev->descriptor.idProduct == 0x2bd0)) ||
2204 - ((dev->descriptor.idVendor == 0x7b0) &&
2205 - (dev->descriptor.idProduct == 0x0006))) &&
2207 - (ifdp->bNumEndpoints >= 6) && (ifdp->bNumEndpoints <= 16)) {
2208 - if (!(context = kmalloc(sizeof(hfcusb_data), GFP_KERNEL))) {
2209 - return (NULL); /* got no mem */
2211 - memset(context, 0, sizeof(hfcusb_data)); /* clear the structure */
2212 - i = ifdp->bNumEndpoints; /* get number of endpoints */
2213 - ep_msk = 0; /* none found */
2214 - epd = ifdp->endpoint; /* first endpoint descriptor */
2215 - while (i-- && ((ep_msk & 0xcf) != 0xcf)) {
2217 - idx = (((epd->bEndpointAddress & 0x7f) - 1) << 1); /* get endpoint base */
2219 - switch (epd->bmAttributes) {
2220 - case USB_ENDPOINT_XFER_INT:
2223 - bEndpointAddress &
2225 - break; /* only interrupt in allowed */
2226 - idx++; /* input index is odd */
2227 - context->fifos[idx].pipe =
2228 - usb_rcvintpipe(dev,
2230 - bEndpointAddress);
2233 - case USB_ENDPOINT_XFER_BULK:
2235 - bEndpointAddress &
2237 - break; /* only bulk out allowed */
2238 - context->fifos[idx].pipe =
2239 - usb_sndbulkpipe(dev,
2241 - bEndpointAddress);
2244 - context->fifos[idx].pipe = 0; /* reset data */
2245 - } /* switch attribute */
2247 - if (context->fifos[idx].pipe) {
2248 - context->fifos[idx].fifonum = idx;
2249 - context->fifos[idx].fifo_mask =
2251 - context->fifos[idx].hfc = context;
2252 - context->fifos[idx].usb_maxlen =
2253 - epd->wMaxPacketSize;
2254 - context->fifos[idx].intervall =
2256 - ep_msk |= (1 << idx);
2258 - ep_msk &= ~(1 << idx);
2262 + //struct usb_host_interface *iface = intf->cur_altsetting;
2263 + //struct usb_host_interface *iface_used = NULL;
2264 + //struct usb_host_endpoint *ep;
2265 + struct usb_endpoint_descriptor* ep;
2266 + //int ifnum = iface->desc.bInterfaceNumber;
2267 + struct usb_interface_descriptor* intfdesc = intf->altsetting + intf->act_altsetting;
2268 + struct usb_interface_descriptor* intfdesc_used = NULL;
2269 + int i, idx, alt_idx, probe_alt_setting, vend_idx, cfg_used, *vcf, attr, cfg_found, cidx, ep_addr;
2270 + int cmptbl[16],small_match,iso_packet_size,packet_size,alt_used=0;
2272 +// usb_show_device(dev);
2273 +// usb_show_device_descriptor(&dev->descriptor);
2274 +// usb_show_interface_descriptor(&iface->desc);
2276 + for(i=0;vdata[i].vendor;i++)
2278 + if(dev->descriptor.idVendor==vdata[i].vendor && dev->descriptor.idProduct==vdata[i].prod_id) vend_idx=i;
2282 - if ((ep_msk & 0x3f) != 0x3f) {
2286 - MOD_INC_USE_COUNT; /* lock our module */
2287 - context->dev = dev; /* save device */
2288 - context->if_used = interface; /* save used interface */
2289 - context->alt_used = ifp->act_altsetting; /* and alternate config */
2290 - context->ctrl_paksize = dev->descriptor.bMaxPacketSize0; /* control size */
2292 - /* create the control pipes needed for register access */
2293 - context->ctrl_in_pipe = usb_rcvctrlpipe(context->dev, 0);
2294 - context->ctrl_out_pipe = usb_sndctrlpipe(context->dev, 0);
2296 - /* init the chip and register the driver */
2297 - if (usb_init(context)) {
2299 - MOD_DEC_USE_COUNT;
2302 +#ifdef VERBOSE_USB_DEBUG
2303 + printk(KERN_INFO "HFC-USB: probing interface(%d) actalt(%d)\n",
2304 + ifnum, intfdesc->bAlternateSetting);
2305 + /* printk(KERN_INFO "HFC-USB: probing interface(%d) actalt(%d) minor(%d)\n",
2306 + ifnum, intfdesc->bAlternateSetting, intf->driver->minor); */
2310 - "HFC-USB: New device if=%d alt=%d registered\n",
2311 - context->if_used, context->alt_used);
2314 + if (vend_idx != 0xffff) {
2315 +#ifdef VERBOSE_USB_DEBUG
2316 + printk(KERN_INFO "HFC-USB: found vendor idx:%d name:%s\n",vend_idx,vdata[vend_idx].vend_name);
2318 + /* if vendor and product ID is OK, start probing a matching alternate setting ... */
2320 + small_match=0xffff;
2321 + // default settings
2322 + iso_packet_size=16;
2325 + while (alt_idx < intf->num_altsetting) {
2326 + //iface = intf->altsetting + alt_idx;
2327 + intfdesc = intf->altsetting + alt_idx;
2328 + probe_alt_setting = intfdesc->bAlternateSetting;
2331 - return (NULL); /* no matching entry */
2332 -} /* hfc_usb_probe */
2333 +#ifdef VERBOSE_USB_DEBUG
2334 + printk(KERN_INFO "HFC-USB: test alt_setting %d\n", probe_alt_setting);
2336 + // check for config EOL element
2337 + while (validconf[cfg_used][0]) {
2339 + vcf=validconf[cfg_used];
2340 + ep = intfdesc->endpoint; /* first endpoint descriptor */
2342 +#ifdef VERBOSE_USB_DEBUG
2343 + printk(KERN_INFO "HFC-USB: (if=%d alt=%d cfg_used=%d)\n",
2344 + ifnum, probe_alt_setting, cfg_used);
2347 + memcpy(cmptbl,vcf,16*sizeof(int));
2349 + // check for all endpoints in this alternate setting
2350 + for (i=0; i < intfdesc->bNumEndpoints; i++) {
2351 + ep_addr = ep->bEndpointAddress;
2352 + idx = ((ep_addr & 0x7f)-1)*2; /* get endpoint base */
2353 + if (ep_addr & 0x80)
2355 + attr = ep->bmAttributes;
2357 + if (cmptbl[idx] == EP_NUL) {
2358 + printk(KERN_INFO "HFC-USB: cfg_found=FALSE in idx:%d attr:%d cmptbl[%d]:%d\n",
2359 + idx, attr, idx, cmptbl[idx]);
2360 + cfg_found = FALSE;
2363 + if (attr == USB_ENDPOINT_XFER_INT && cmptbl[idx] == EP_INT)
2364 + cmptbl[idx] = EP_NUL;
2365 + if (attr == USB_ENDPOINT_XFER_BULK && cmptbl[idx] == EP_BLK)
2366 + cmptbl[idx] = EP_NUL;
2367 + if (attr == USB_ENDPOINT_XFER_ISOC && cmptbl[idx] == EP_ISO)
2368 + cmptbl[idx] = EP_NUL;
2370 + // check if all INT endpoints match minimum interval
2371 + if (attr == USB_ENDPOINT_XFER_INT && ep->bInterval < vcf[17]) {
2372 +#ifdef VERBOSE_USB_DEBUG
2374 + printk(KERN_INFO "HFC-USB: Interrupt Endpoint interval < %d found - skipping config\n",
2377 + cfg_found = FALSE;
2383 + for (i = 0; i < 16; i++) {
2384 + // printk(KERN_INFO "HFC-USB: cmptbl[%d]:%d\n", i, cmptbl[i]);
2386 + // all entries must be EP_NOP or EP_NUL for a valid config
2387 + if (cmptbl[i] != EP_NOP && cmptbl[i] != EP_NUL)
2388 + cfg_found = FALSE;
2391 + // we check for smallest match, to provide configuration priority
2392 + // configurations with smaller index have higher priority
2394 + if (cfg_used < small_match) {
2395 + small_match = cfg_used;
2396 + alt_used = probe_alt_setting;
2397 + //iface_used = iface;
2398 + intfdesc_used = intfdesc;
2400 +#ifdef VERBOSE_USB_DEBUG
2401 + printk(KERN_INFO "HFC-USB: small_match=%x %x\n", small_match, alt_used);
2409 + } /* (alt_idx < intf->num_altsetting) */
2410 +#ifdef VERBOSE_USB_DEBUG
2411 + printk(KERN_INFO "HFC-USB: final small_match=%x alt_used=%x\n",small_match, alt_used);
2413 + // yiipiee, we found a valid config
2414 + if (small_match != 0xffff) {
2415 + //iface = iface_used;
2416 + intfdesc = intfdesc_used;
2418 + if (!(context = kmalloc(sizeof(hfcusb_data), GFP_KERNEL)))
2419 + return(NULL); /* got no mem */
2420 + memset(context, 0, sizeof(hfcusb_data)); /* clear the structure */
2422 + ep = intfdesc->endpoint; /* first endpoint descriptor */
2423 + vcf = validconf[small_match];
2425 + for (i = 0; i < intfdesc->bNumEndpoints; i++) {
2426 + ep_addr = ep->bEndpointAddress;
2427 + idx = ((ep_addr & 0x7f)-1)*2; /* get endpoint base */
2428 + if (ep_addr & 0x80)
2431 + attr = ep->bmAttributes;
2433 + // only initialize used endpoints
2434 + if (vcf[idx] != EP_NOP && vcf[idx] != EP_NUL) {
2436 + case USB_ENDPOINT_XFER_INT:
2437 + context->fifos[cidx].pipe = usb_rcvintpipe(dev, ep->bEndpointAddress);
2438 + context->fifos[cidx].usb_transfer_mode = USB_INT;
2439 + packet_size = ep->wMaxPacketSize; // remember max packet size
2440 +#ifdef VERBOSE_USB_DEBUG
2441 + printk (KERN_INFO "HFC-USB: Interrupt-In Endpoint found %d ms(idx:%d cidx:%d)!\n",
2442 + ep->bInterval, idx, cidx);
2445 + case USB_ENDPOINT_XFER_BULK:
2446 + if (ep_addr & 0x80)
2447 + context->fifos[cidx].pipe = usb_rcvbulkpipe(dev, ep->bEndpointAddress);
2449 + context->fifos[cidx].pipe = usb_sndbulkpipe(dev, ep->bEndpointAddress);
2450 + context->fifos[cidx].usb_transfer_mode = USB_BULK;
2451 + packet_size = ep->wMaxPacketSize; // remember max packet size
2452 +#ifdef VERBOSE_USB_DEBUG
2453 + printk (KERN_INFO "HFC-USB: Bulk Endpoint found (idx:%d cidx:%d)!\n",
2457 + case USB_ENDPOINT_XFER_ISOC:
2458 + if (ep_addr & 0x80)
2459 + context->fifos[cidx].pipe = usb_rcvisocpipe(dev, ep->bEndpointAddress);
2461 + context->fifos[cidx].pipe = usb_sndisocpipe(dev, ep->bEndpointAddress);
2462 + context->fifos[cidx].usb_transfer_mode = USB_ISOC;
2463 + iso_packet_size = ep->wMaxPacketSize; // remember max packet size
2464 +#ifdef VERBOSE_USB_DEBUG
2465 + printk (KERN_INFO "HFC-USB: ISO Endpoint found (idx:%d cidx:%d)!\n",
2470 + context->fifos[cidx].pipe = 0; /* reset data */
2471 + } /* switch attribute */
2473 + if (context->fifos[cidx].pipe) {
2474 + context->fifos[cidx].fifonum = cidx;
2475 + context->fifos[cidx].hfc = context;
2476 + context->fifos[cidx].usb_packet_maxlen = ep->wMaxPacketSize;
2477 + context->fifos[cidx].intervall = ep->bInterval;
2478 + context->fifos[cidx].skbuff = NULL;
2479 +#ifdef VERBOSE_USB_DEBUG
2480 + printk (KERN_INFO "HFC-USB: fifo%d pktlen %d interval %d\n",
2481 + context->fifos[cidx].fifonum,
2482 + context->fifos[cidx].usb_packet_maxlen,
2483 + context->fifos[cidx].intervall);
2491 + // now share our luck
2492 + context->dev = dev; /* save device */
2493 + context->if_used = ifnum; /* save used interface */
2494 + context->alt_used = alt_used; /* and alternate config */
2495 + context->ctrl_paksize = dev->descriptor.bMaxPacketSize0; /* control size */
2496 + context->cfg_used=vcf[16]; // store used config
2497 + context->vend_idx=vend_idx; // store found vendor
2498 + context->packet_size=packet_size;
2499 + context->iso_packet_size=iso_packet_size;
2501 + /* create the control pipes needed for register access */
2502 + context->ctrl_in_pipe = usb_rcvctrlpipe(context->dev, 0);
2503 + context->ctrl_out_pipe = usb_sndctrlpipe(context->dev, 0);
2504 + context->ctrl_urb = usb_alloc_urb(0);
2506 + printk(KERN_INFO "HFC-USB: detected \"%s\" configuration: %s (if=%d alt=%d)\n",
2507 + vdata[vend_idx].vend_name, conf_str[small_match], context->if_used, context->alt_used);
2509 + /* init the chip and register the driver */
2510 + if (usb_init(context))
2512 + if (context->ctrl_urb) {
2513 + usb_unlink_urb(context->ctrl_urb);
2514 + usb_free_urb(context->ctrl_urb);
2515 + context->ctrl_urb = NULL;
2520 + //usb_set_intfdata(intf, context);
2521 + //intf->private_data = context;
2528 /****************************************************/
2529 /* function called when an active device is removed */
2530 /****************************************************/
2532 -hfc_usb_disconnect(struct usb_device *usbdev, void *drv_context)
2533 +//static void hfc_usb_disconnect(struct usb_interface *intf)
2534 +static void hfc_usb_disconnect(struct usb_device *usbdev, void* drv_context)
2536 - hfcusb_data *context = drv_context;
2537 + //hfcusb_data *context = intf->private_data;
2538 + hfcusb_data* context = drv_context;
2540 - struct sk_buff *skb;
2542 - /* tell all fifos to terminate */
2543 - for (i = 0; i < HFCUSB_NUM_FIFOS; i++)
2544 - if (context->fifos[i].active) {
2545 - context->fifos[i].active = 0;
2546 - usb_unlink_urb(&context->fifos[i].urb);
2548 - while (context->active_fifos) {
2549 - set_current_state(TASK_INTERRUPTIBLE);
2550 - /* Timeout 10ms */
2551 - schedule_timeout((10 * HZ) / 1000);
2553 + printk(KERN_INFO "HFC-USB: device disconnect\n");
2555 + //intf->private_data = NULL;
2558 if (timer_pending(&context->t3_timer))
2559 del_timer(&context->t3_timer);
2560 - context->regd.release_driver(context->regd.arg_hisax);
2561 - while ((skb = skb_dequeue(&context->regd.erq)) != NULL)
2562 - dev_kfree_skb_any(skb);
2563 + if (timer_pending(&context->t4_timer))
2564 + del_timer(&context->t4_timer);
2565 + if (timer_pending(&context->led_timer))
2566 + del_timer(&context->led_timer);
2568 + hisax_unregister(&context->d_if);
2570 + /* tell all fifos to terminate */
2571 + for(i = 0; i < HFCUSB_NUM_FIFOS; i++) {
2572 + if(context->fifos[i].usb_transfer_mode == USB_ISOC) {
2573 + if(context->fifos[i].active > 0) {
2574 + stop_isoc_chain(&context->fifos[i]);
2575 +#ifdef VERBOSE_USB_DEBUG
2576 + printk (KERN_INFO "HFC-USB: hfc_usb_disconnect: stopping ISOC chain Fifo no %i\n", i);
2580 + if(context->fifos[i].active > 0) {
2581 + context->fifos[i].active = 0;
2582 +#ifdef VERBOSE_USB_DEBUG
2583 + printk (KERN_INFO "HFC-USB: hfc_usb_disconnect: unlinking URB for Fifo no %i\n", i);
2586 + if (context->fifos[i].urb) {
2587 + usb_unlink_urb(context->fifos[i].urb);
2588 + usb_free_urb(context->fifos[i].urb);
2589 + context->fifos[i].urb = NULL;
2592 + context->fifos[i].active = 0;
2594 + if (context->ctrl_urb) {
2595 + usb_unlink_urb(context->ctrl_urb);
2596 + usb_free_urb(context->ctrl_urb);
2597 + context->ctrl_urb = NULL;
2599 kfree(context); /* free our structure again */
2600 - MOD_DEC_USE_COUNT; /* and decrement the usage counter */
2601 } /* hfc_usb_disconnect */
2604 /************************************/
2605 /* our driver information structure */
2606 /************************************/
2607 static struct usb_driver hfc_drv = {
2609 -#ifdef COMPAT_HAS_USB_IDTAB
2610 id_table:hfc_usb_idtab,
2612 probe:hfc_usb_probe,
2613 disconnect:hfc_usb_disconnect,
2620 +static void __exit hfc_usb_exit(void)
2622 +#ifdef VERBOSE_USB_DEBUG
2623 + printk ("HFC-USB: calling \"hfc_usb_exit\" ...\n");
2625 usb_deregister(&hfc_drv); /* release our driver */
2626 printk(KERN_INFO "HFC-USB module removed\n");
2631 +static int __init hfc_usb_init(void)
2633 - struct hisax_drvreg drv;
2634 + printk ("HFC-USB: driver module revision %s loaded\n", hfcusb_revision);
2636 - drv.version = HISAX_LOAD_VERSION; /* set our version */
2637 - drv.cmd = HISAX_LOAD_CHKVER; /* check command only */
2638 - if (hisax_register_hfcusb(&drv)) {
2639 - printk(KERN_INFO "HFC-USB <-> hisax version conflict\n");
2640 - return (-1); /* unable to register */
2642 - if (usb_register(&hfc_drv)) {
2644 - "Unable to register HFC-USB module at usb stack\n");
2645 - return (-1); /* unable to register */
2646 + if(usb_register(&hfc_drv))
2648 + printk(KERN_INFO "HFC-USB: Unable to register HFC-USB module at usb stack\n");
2649 + return(-1); /* unable to register */
2652 - printk(KERN_INFO "HFC-USB module loaded\n");
2661 module_init(hfc_usb_init);
2662 module_exit(hfc_usb_exit);