4 * $Id: hfc_usb.c,v 2.3.2.20 2007/08/20 14:07:54 mbachem Exp $
6 * modular HiSax ISDN driver for Colognechip HFC-S USB chip
8 * Authors : Peter Sprenger (sprenger@moving-bytes.de)
9 * Martin Bachem (m.bachem@gmx.de, info@colognechip.com)
11 * based on the first hfc_usb driver of
12 * Werner Cornelius (werner@isdn-development.de)
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 * See Version Histroy at the bottom of this file
32 #include <linux/types.h>
33 #include <linux/stddef.h>
34 #include <linux/timer.h>
35 #include <linux/init.h>
36 #include <linux/module.h>
37 #include <linux/kernel_stat.h>
38 #include <linux/usb.h>
39 #include <linux/kernel.h>
40 #include <linux/smp_lock.h>
41 #include <linux/sched.h>
42 #include <linux/moduleparam.h>
47 static const char *hfcusb_revision =
48 "$Revision: 2.3.2.20 $ $Date: 2007/08/20 14:07:54 $ ";
50 /* Hisax debug support
51 * debug flags defined in hfc_usb.h as HFCUSB_DBG_[*]
53 #define __debug_variable hfc_debug
54 #include "hisax_debug.h"
56 module_param(debug, uint, 0);
60 /* private vendor specific data */
62 __u8 led_scheme; // led display scheme
63 signed short led_bits[8]; // array of 8 possible LED bitmask settings
64 char *vend_name; // device name
67 /* VID/PID device list */
68 static struct usb_device_id hfcusb_idtab[] = {
70 USB_DEVICE(0x0959, 0x2bd0),
71 .driver_info = (unsigned long) &((hfcsusb_vdata)
72 {LED_OFF, {4, 0, 2, 1},
73 "ISDN USB TA (Cologne Chip HFC-S USB based)"}),
76 USB_DEVICE(0x0675, 0x1688),
77 .driver_info = (unsigned long) &((hfcsusb_vdata)
78 {LED_SCHEME1, {1, 2, 0, 0},
79 "DrayTek miniVigor 128 USB ISDN TA"}),
82 USB_DEVICE(0x07b0, 0x0007),
83 .driver_info = (unsigned long) &((hfcsusb_vdata)
84 {LED_SCHEME1, {0x80, -64, -32, -16},
85 "Billion tiny USB ISDN TA 128"}),
88 USB_DEVICE(0x0742, 0x2008),
89 .driver_info = (unsigned long) &((hfcsusb_vdata)
90 {LED_SCHEME1, {4, 0, 2, 1},
94 USB_DEVICE(0x0742, 0x2009),
95 .driver_info = (unsigned long) &((hfcsusb_vdata)
96 {LED_SCHEME1, {4, 0, 2, 1},
97 "Aceex USB ISDN TA"}),
100 USB_DEVICE(0x0742, 0x200A),
101 .driver_info = (unsigned long) &((hfcsusb_vdata)
102 {LED_SCHEME1, {4, 0, 2, 1},
106 USB_DEVICE(0x08e3, 0x0301),
107 .driver_info = (unsigned long) &((hfcsusb_vdata)
108 {LED_SCHEME1, {2, 0, 1, 4},
112 USB_DEVICE(0x07fa, 0x0846),
113 .driver_info = (unsigned long) &((hfcsusb_vdata)
114 {LED_SCHEME1, {0x80, -64, -32, -16},
115 "Bewan Modem RNIS USB"}),
118 USB_DEVICE(0x07fa, 0x0847),
119 .driver_info = (unsigned long) &((hfcsusb_vdata)
120 {LED_SCHEME1, {0x80, -64, -32, -16},
121 "Djinn Numeris USB"}),
124 USB_DEVICE(0x07b0, 0x0006),
125 .driver_info = (unsigned long) &((hfcsusb_vdata)
126 {LED_SCHEME1, {0x80, -64, -32, -16},
132 /* structure defining input+output fifos (interrupt/bulk mode) */
133 struct usb_fifo; /* forward definition */
134 typedef struct iso_urb_struct {
136 __u8 buffer[ISO_BUFFER_SIZE]; /* buffer incoming/outgoing data */
137 struct usb_fifo *owner_fifo; /* pointer to owner fifo */
140 struct hfcusb_data; /* forward definition */
142 typedef struct usb_fifo {
143 int fifonum; /* fifo index attached to this structure */
144 int active; /* fifo is currently active */
145 struct hfcusb_data *hfc; /* pointer to main structure */
146 int pipe; /* address of endpoint */
147 __u8 usb_packet_maxlen; /* maximum length for usb transfer */
148 unsigned int max_size; /* maximum size of receive/send packet */
149 __u8 intervall; /* interrupt interval */
150 struct sk_buff *skbuff; /* actual used buffer */
151 struct urb *urb; /* transfer structure for usb routines */
152 __u8 buffer[128]; /* buffer incoming/outgoing data */
153 int bit_line; /* how much bits are in the fifo? */
155 volatile __u8 usb_transfer_mode; /* switched between ISO and INT */
156 iso_urb_struct iso[2]; /* need two urbs to have one always for pending */
157 struct hisax_if *hif; /* hisax interface */
158 int delete_flg; /* only delete skbuff once */
159 int last_urblen; /* remember length of last packet */
162 /* structure holding all data for one device */
163 typedef struct hfcusb_data {
164 /* HiSax Interface for loadable Layer1 drivers */
165 struct hisax_d_if d_if; /* see hisax_if.h */
166 struct hisax_b_if b_if[2]; /* see hisax_if.h */
169 struct usb_device *dev; /* our device */
170 int if_used; /* used interface number */
171 int alt_used; /* used alternate config */
172 int ctrl_paksize; /* control pipe packet size */
173 int ctrl_in_pipe, /* handles for control pipe */
175 int cfg_used; /* configuration index used */
176 int vend_idx; /* vendor found */
177 int b_mode[2]; /* B-channel mode */
178 int l1_activated; /* layer 1 activated */
179 int disc_flag; /* TRUE if device was disonnected to avoid some USB actions */
180 int packet_size, iso_packet_size;
182 /* control pipe background handling */
183 ctrl_buft ctrl_buff[HFC_CTRL_BUFSIZE]; /* buffer holding queued data */
184 volatile int ctrl_in_idx, ctrl_out_idx, ctrl_cnt; /* input/output pointer + count */
185 struct urb *ctrl_urb; /* transfer structure for control channel */
187 struct usb_ctrlrequest ctrl_write; /* buffer for control write request */
188 struct usb_ctrlrequest ctrl_read; /* same for read request */
190 __u8 old_led_state, led_state, led_new_data, led_b_active;
192 volatile __u8 threshold_mask; /* threshold actually reported */
193 volatile __u8 bch_enables; /* or mask for sctrl_r and sctrl register values */
195 usb_fifo fifos[HFCUSB_NUM_FIFOS]; /* structure holding all fifo data */
197 volatile __u8 l1_state; /* actual l1 state */
198 struct timer_list t3_timer; /* timer 3 for activation/deactivation */
199 struct timer_list t4_timer; /* timer 4 for activation/deactivation */
203 static void collect_rx_frame(usb_fifo * fifo, __u8 * data, int len,
206 static inline const char *
207 symbolic(struct hfcusb_symbolic_list list[], const int num)
210 for (i = 0; list[i].name != NULL; i++)
211 if (list[i].num == num)
212 return (list[i].name);
213 return "<unknown ERROR>";
217 ctrl_start_transfer(hfcusb_data * hfc)
220 hfc->ctrl_urb->pipe = hfc->ctrl_out_pipe;
221 hfc->ctrl_urb->setup_packet = (u_char *) & hfc->ctrl_write;
222 hfc->ctrl_urb->transfer_buffer = NULL;
223 hfc->ctrl_urb->transfer_buffer_length = 0;
224 hfc->ctrl_write.wIndex =
225 cpu_to_le16(hfc->ctrl_buff[hfc->ctrl_out_idx].hfc_reg);
226 hfc->ctrl_write.wValue =
227 cpu_to_le16(hfc->ctrl_buff[hfc->ctrl_out_idx].reg_val);
229 usb_submit_urb(hfc->ctrl_urb, GFP_ATOMIC); /* start transfer */
231 } /* ctrl_start_transfer */
234 queue_control_request(hfcusb_data * hfc, __u8 reg, __u8 val, int action)
238 if (hfc->ctrl_cnt >= HFC_CTRL_BUFSIZE)
239 return (1); /* no space left */
240 buf = &hfc->ctrl_buff[hfc->ctrl_in_idx]; /* pointer to new index */
243 buf->action = action;
244 if (++hfc->ctrl_in_idx >= HFC_CTRL_BUFSIZE)
245 hfc->ctrl_in_idx = 0; /* pointer wrap */
246 if (++hfc->ctrl_cnt == 1)
247 ctrl_start_transfer(hfc);
252 ctrl_complete(struct urb *urb)
254 hfcusb_data *hfc = (hfcusb_data *) urb->context;
259 buf = &hfc->ctrl_buff[hfc->ctrl_out_idx];
260 hfc->ctrl_cnt--; /* decrement actual count */
261 if (++hfc->ctrl_out_idx >= HFC_CTRL_BUFSIZE)
262 hfc->ctrl_out_idx = 0; /* pointer wrap */
264 ctrl_start_transfer(hfc); /* start next transfer */
266 } /* ctrl_complete */
268 /* write led data to auxport & invert if necessary */
270 write_led(hfcusb_data * hfc, __u8 led_state)
272 if (led_state != hfc->old_led_state) {
273 hfc->old_led_state = led_state;
274 queue_control_request(hfc, HFCUSB_P_DATA, led_state, 1);
279 set_led_bit(hfcusb_data * hfc, signed short led_bits, int unset)
283 hfc->led_state |= abs(led_bits);
285 hfc->led_state &= ~led_bits;
288 hfc->led_state &= ~abs(led_bits);
290 hfc->led_state |= led_bits;
294 /* handle LED requests */
296 handle_led(hfcusb_data * hfc, int event)
298 hfcsusb_vdata *driver_info =
299 (hfcsusb_vdata *) hfcusb_idtab[hfc->vend_idx].driver_info;
301 /* if no scheme -> no LED action */
302 if (driver_info->led_scheme == LED_OFF)
307 set_led_bit(hfc, driver_info->led_bits[0], 0);
308 set_led_bit(hfc, driver_info->led_bits[1], 1);
309 set_led_bit(hfc, driver_info->led_bits[2], 1);
310 set_led_bit(hfc, driver_info->led_bits[3], 1);
313 set_led_bit(hfc, driver_info->led_bits[0], 1);
314 set_led_bit(hfc, driver_info->led_bits[1], 1);
315 set_led_bit(hfc, driver_info->led_bits[2], 1);
316 set_led_bit(hfc, driver_info->led_bits[3], 1);
319 set_led_bit(hfc, driver_info->led_bits[1], 0);
322 set_led_bit(hfc, driver_info->led_bits[1], 1);
325 set_led_bit(hfc, driver_info->led_bits[2], 0);
328 set_led_bit(hfc, driver_info->led_bits[2], 1);
331 set_led_bit(hfc, driver_info->led_bits[3], 0);
334 set_led_bit(hfc, driver_info->led_bits[3], 1);
337 write_led(hfc, hfc->led_state);
340 /* ISDN l1 timer T3 expires */
342 l1_timer_expire_t3(hfcusb_data * hfc)
344 hfc->d_if.ifc.l1l2(&hfc->d_if.ifc, PH_DEACTIVATE | INDICATION,
347 DBG(HFCUSB_DBG_STATES,
348 "HFC-S USB: PH_DEACTIVATE | INDICATION sent (T3 expire)");
350 hfc->l1_activated = 0;
351 handle_led(hfc, LED_S0_OFF);
353 queue_control_request(hfc, HFCUSB_STATES, 0x10, 1);
354 queue_control_request(hfc, HFCUSB_STATES, 3, 1);
357 /* ISDN l1 timer T4 expires */
359 l1_timer_expire_t4(hfcusb_data * hfc)
361 hfc->d_if.ifc.l1l2(&hfc->d_if.ifc, PH_DEACTIVATE | INDICATION,
364 DBG(HFCUSB_DBG_STATES,
365 "HFC-S USB: PH_DEACTIVATE | INDICATION sent (T4 expire)");
367 hfc->l1_activated = 0;
368 handle_led(hfc, LED_S0_OFF);
371 /* S0 state changed */
373 s0_state_handler(hfcusb_data * hfc, __u8 state)
377 old_state = hfc->l1_state;
378 if (state == old_state || state < 1 || state > 8)
381 DBG(HFCUSB_DBG_STATES, "HFC-S USB: S0 statechange(%d -> %d)",
384 if (state < 4 || state == 7 || state == 8) {
385 if (timer_pending(&hfc->t3_timer))
386 del_timer(&hfc->t3_timer);
387 DBG(HFCUSB_DBG_STATES, "HFC-S USB: T3 deactivated");
390 if (timer_pending(&hfc->t4_timer))
391 del_timer(&hfc->t4_timer);
392 DBG(HFCUSB_DBG_STATES, "HFC-S USB: T4 deactivated");
395 if (state == 7 && !hfc->l1_activated) {
396 hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,
397 PH_ACTIVATE | INDICATION, NULL);
398 DBG(HFCUSB_DBG_STATES, "HFC-S USB: PH_ACTIVATE | INDICATION sent");
399 hfc->l1_activated = 1;
400 handle_led(hfc, LED_S0_ON);
401 } else if (state <= 3 /* && activated */ ) {
402 if (old_state == 7 || old_state == 8) {
403 DBG(HFCUSB_DBG_STATES, "HFC-S USB: T4 activated");
404 if (!timer_pending(&hfc->t4_timer)) {
405 hfc->t4_timer.expires =
406 jiffies + (HFC_TIMER_T4 * HZ) / 1000;
407 add_timer(&hfc->t4_timer);
410 hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,
411 PH_DEACTIVATE | INDICATION,
413 DBG(HFCUSB_DBG_STATES,
414 "HFC-S USB: PH_DEACTIVATE | INDICATION sent");
415 hfc->l1_activated = 0;
416 handle_led(hfc, LED_S0_OFF);
419 hfc->l1_state = state;
423 fill_isoc_urb(struct urb *urb, struct usb_device *dev, unsigned int pipe,
424 void *buf, int num_packets, int packet_size, int interval,
425 usb_complete_t complete, void *context)
431 urb->complete = complete;
432 urb->number_of_packets = num_packets;
433 urb->transfer_buffer_length = packet_size * num_packets;
434 urb->context = context;
435 urb->transfer_buffer = buf;
436 urb->transfer_flags = URB_ISO_ASAP;
437 urb->actual_length = 0;
438 urb->interval = interval;
439 for (k = 0; k < num_packets; k++) {
440 urb->iso_frame_desc[k].offset = packet_size * k;
441 urb->iso_frame_desc[k].length = packet_size;
442 urb->iso_frame_desc[k].actual_length = 0;
446 /* allocs urbs and start isoc transfer with two pending urbs to avoid
447 * gaps in the transfer chain
450 start_isoc_chain(usb_fifo * fifo, int num_packets_per_urb,
451 usb_complete_t complete, int packet_size)
455 DBG(HFCUSB_DBG_INIT, "HFC-S USB: starting ISO-URBs for fifo:%d\n",
458 /* allocate Memory for Iso out Urbs */
459 for (i = 0; i < 2; i++) {
460 if (!(fifo->iso[i].purb)) {
462 usb_alloc_urb(num_packets_per_urb, GFP_KERNEL);
463 if (!(fifo->iso[i].purb)) {
465 "alloc urb for fifo %i failed!!!",
468 fifo->iso[i].owner_fifo = (struct usb_fifo *) fifo;
470 /* Init the first iso */
471 if (ISO_BUFFER_SIZE >=
472 (fifo->usb_packet_maxlen *
473 num_packets_per_urb)) {
474 fill_isoc_urb(fifo->iso[i].purb,
475 fifo->hfc->dev, fifo->pipe,
478 fifo->usb_packet_maxlen,
479 fifo->intervall, complete,
481 memset(fifo->iso[i].buffer, 0,
482 sizeof(fifo->iso[i].buffer));
483 /* defining packet delimeters in fifo->buffer */
484 for (k = 0; k < num_packets_per_urb; k++) {
486 iso_frame_desc[k].offset =
489 iso_frame_desc[k].length =
494 "HFC-S USB: ISO Buffer size to small!\n");
497 fifo->bit_line = BITLINE_INF;
499 errcode = usb_submit_urb(fifo->iso[i].purb, GFP_KERNEL);
500 fifo->active = (errcode >= 0) ? 1 : 0;
502 printk(KERN_INFO "HFC-S USB: usb_submit_urb URB nr:%d, error(%i): '%s'\n",
503 i, errcode, symbolic(urb_errlist, errcode));
505 return (fifo->active);
508 /* stops running iso chain and frees their pending urbs */
510 stop_isoc_chain(usb_fifo * fifo)
514 for (i = 0; i < 2; i++) {
515 if (fifo->iso[i].purb) {
517 "HFC-S USB: Stopping iso chain for fifo %i.%i",
519 usb_kill_urb(fifo->iso[i].purb);
520 usb_free_urb(fifo->iso[i].purb);
521 fifo->iso[i].purb = NULL;
525 usb_kill_urb(fifo->urb);
526 usb_free_urb(fifo->urb);
531 /* defines how much ISO packets are handled in one URB */
532 static int iso_packets[8] =
533 { ISOC_PACKETS_B, ISOC_PACKETS_B, ISOC_PACKETS_B, ISOC_PACKETS_B,
534 ISOC_PACKETS_D, ISOC_PACKETS_D, ISOC_PACKETS_D, ISOC_PACKETS_D
538 tx_iso_complete(struct urb *urb)
540 iso_urb_struct *context_iso_urb = (iso_urb_struct *) urb->context;
541 usb_fifo *fifo = context_iso_urb->owner_fifo;
542 hfcusb_data *hfc = fifo->hfc;
543 int k, tx_offset, num_isoc_packets, sink, len, current_len,
545 int frame_complete, transp_mode, fifon, status;
548 fifon = fifo->fifonum;
549 status = urb->status;
553 /* ISO transfer only partially completed,
554 look at individual frame status for details */
555 if (status == -EXDEV) {
556 DBG(HFCUSB_DBG_VERBOSE_USB, "HFC-S USB: tx_iso_complete with -EXDEV"
557 ", urb->status %d, fifonum %d\n",
560 for (k = 0; k < iso_packets[fifon]; ++k) {
561 errcode = urb->iso_frame_desc[k].status;
563 DBG(HFCUSB_DBG_VERBOSE_USB, "HFC-S USB: tx_iso_complete "
564 "packet %i, status: %i\n",
568 // clear status, so go on with ISO transfers
572 if (fifo->active && !status) {
574 if (fifon < 4 && hfc->b_mode[fifon / 2] == L1_MODE_TRANS)
577 /* is FifoFull-threshold set for our channel? */
578 threshbit = (hfc->threshold_mask & (1 << fifon));
579 num_isoc_packets = iso_packets[fifon];
581 /* predict dataflow to avoid fifo overflow */
582 if (fifon >= HFCUSB_D_TX) {
583 sink = (threshbit) ? SINK_DMIN : SINK_DMAX;
585 sink = (threshbit) ? SINK_MIN : SINK_MAX;
587 fill_isoc_urb(urb, fifo->hfc->dev, fifo->pipe,
588 context_iso_urb->buffer, num_isoc_packets,
589 fifo->usb_packet_maxlen, fifo->intervall,
590 tx_iso_complete, urb->context);
591 memset(context_iso_urb->buffer, 0,
592 sizeof(context_iso_urb->buffer));
595 /* Generate next ISO Packets */
596 for (k = 0; k < num_isoc_packets; ++k) {
598 len = fifo->skbuff->len;
599 /* we lower data margin every msec */
600 fifo->bit_line -= sink;
601 current_len = (0 - fifo->bit_line) / 8;
602 /* maximum 15 byte for every ISO packet makes our life easier */
603 if (current_len > 14)
607 current_len) ? len : current_len;
608 /* how much bit do we put on the line? */
609 fifo->bit_line += current_len * 8;
611 context_iso_urb->buffer[tx_offset] = 0;
612 if (current_len == len) {
614 /* here frame completion */
616 buffer[tx_offset] = 1;
617 /* add 2 byte flags and 16bit CRC at end of ISDN frame */
618 fifo->bit_line += 32;
623 memcpy(context_iso_urb->buffer +
624 tx_offset + 1, fifo->skbuff->data,
626 skb_pull(fifo->skbuff, current_len);
628 /* define packet delimeters within the URB buffer */
629 urb->iso_frame_desc[k].offset = tx_offset;
630 urb->iso_frame_desc[k].length =
633 tx_offset += (current_len + 1);
635 urb->iso_frame_desc[k].offset =
638 urb->iso_frame_desc[k].length = 1;
639 fifo->bit_line -= sink; /* we lower data margin every msec */
641 if (fifo->bit_line < BITLINE_INF) {
642 fifo->bit_line = BITLINE_INF;
646 if (frame_complete) {
647 fifo->delete_flg = 1;
648 fifo->hif->l1l2(fifo->hif,
650 (void *) (unsigned long) fifo->skbuff->
652 if (fifo->skbuff && fifo->delete_flg) {
653 dev_kfree_skb_any(fifo->skbuff);
655 fifo->delete_flg = 0;
660 errcode = usb_submit_urb(urb, GFP_ATOMIC);
663 "HFC-S USB: error submitting ISO URB: %d\n",
667 if (status && !hfc->disc_flag) {
669 "HFC-S USB: tx_iso_complete: error(%i): '%s', fifonum=%d\n",
670 status, symbolic(urb_errlist, status), fifon);
676 rx_iso_complete(struct urb *urb)
678 iso_urb_struct *context_iso_urb = (iso_urb_struct *) urb->context;
679 usb_fifo *fifo = context_iso_urb->owner_fifo;
680 hfcusb_data *hfc = fifo->hfc;
681 int k, len, errcode, offset, num_isoc_packets, fifon, maxlen,
683 unsigned int iso_status;
687 fifon = fifo->fifonum;
688 status = urb->status;
690 if (urb->status == -EOVERFLOW) {
691 DBG(HFCUSB_DBG_VERBOSE_USB,
692 "HFC-USB: ignoring USB DATAOVERRUN fifo(%i)", fifon);
696 /* ISO transfer only partially completed,
697 look at individual frame status for details */
698 if (status == -EXDEV) {
699 DBG(HFCUSB_DBG_VERBOSE_USB, "HFC-S USB: rx_iso_complete with -EXDEV "
700 "urb->status %d, fifonum %d\n",
705 if (fifo->active && !status) {
706 num_isoc_packets = iso_packets[fifon];
707 maxlen = fifo->usb_packet_maxlen;
708 for (k = 0; k < num_isoc_packets; ++k) {
709 len = urb->iso_frame_desc[k].actual_length;
710 offset = urb->iso_frame_desc[k].offset;
711 buf = context_iso_urb->buffer + offset;
712 iso_status = urb->iso_frame_desc[k].status;
714 if (iso_status && !hfc->disc_flag)
715 DBG(HFCUSB_DBG_VERBOSE_USB,
716 "HFC-S USB: rx_iso_complete "
717 "ISO packet %i, status: %i\n",
720 if (fifon == HFCUSB_D_RX) {
721 DBG(HFCUSB_DBG_VERBOSE_USB,
722 "HFC-S USB: ISO-D-RX lst_urblen:%2d "
723 "act_urblen:%2d max-urblen:%2d EOF:0x%0x",
724 fifo->last_urblen, len, maxlen,
727 DBG_PACKET(HFCUSB_DBG_VERBOSE_USB, buf, len);
730 if (fifo->last_urblen != maxlen) {
731 /* the threshold mask is in the 2nd status byte */
732 hfc->threshold_mask = buf[1];
733 /* care for L1 state only for D-Channel
734 to avoid overlapped iso completions */
735 if (fifon == HFCUSB_D_RX) {
736 /* the S0 state is in the upper half
737 of the 1st status byte */
738 s0_state_handler(hfc, buf[0] >> 4);
740 eof[fifon] = buf[0] & 1;
742 collect_rx_frame(fifo, buf + 2,
747 collect_rx_frame(fifo, buf, len,
749 maxlen) ? eof[fifon] :
752 fifo->last_urblen = len;
755 fill_isoc_urb(urb, fifo->hfc->dev, fifo->pipe,
756 context_iso_urb->buffer, num_isoc_packets,
757 fifo->usb_packet_maxlen, fifo->intervall,
758 rx_iso_complete, urb->context);
759 errcode = usb_submit_urb(urb, GFP_ATOMIC);
762 "HFC-S USB: error submitting ISO URB: %d\n",
766 if (status && !hfc->disc_flag) {
768 "HFC-S USB: rx_iso_complete : "
769 "urb->status %d, fifonum %d\n",
775 /* collect rx data from INT- and ISO-URBs */
777 collect_rx_frame(usb_fifo * fifo, __u8 * data, int len, int finish)
779 hfcusb_data *hfc = fifo->hfc;
780 int transp_mode, fifon;
782 fifon = fifo->fifonum;
784 if (fifon < 4 && hfc->b_mode[fifon / 2] == L1_MODE_TRANS)
788 fifo->skbuff = dev_alloc_skb(fifo->max_size + 3);
791 "HFC-S USB: cannot allocate buffer for fifo(%d)\n",
797 if (fifo->skbuff->len + len < fifo->max_size) {
798 memcpy(skb_put(fifo->skbuff, len), data, len);
800 DBG(HFCUSB_DBG_FIFO_ERR,
801 "HCF-USB: got frame exceeded fifo->max_size(%d) fifo(%d)",
802 fifo->max_size, fifon);
803 DBG_SKB(HFCUSB_DBG_VERBOSE_USB, fifo->skbuff);
804 skb_trim(fifo->skbuff, 0);
807 if (transp_mode && fifo->skbuff->len >= 128) {
808 fifo->hif->l1l2(fifo->hif, PH_DATA | INDICATION,
813 /* we have a complete hdlc packet */
815 if ((!fifo->skbuff->data[fifo->skbuff->len - 1])
816 && (fifo->skbuff->len > 3)) {
818 if (fifon == HFCUSB_D_RX) {
819 DBG(HFCUSB_DBG_DCHANNEL,
820 "HFC-S USB: D-RX len(%d)", fifo->skbuff->len);
821 DBG_SKB(HFCUSB_DBG_DCHANNEL, fifo->skbuff);
824 /* remove CRC & status */
825 skb_trim(fifo->skbuff, fifo->skbuff->len - 3);
826 if (fifon == HFCUSB_PCM_RX) {
827 fifo->hif->l1l2(fifo->hif,
828 PH_DATA_E | INDICATION,
831 fifo->hif->l1l2(fifo->hif,
832 PH_DATA | INDICATION,
834 fifo->skbuff = NULL; /* buffer was freed from upper layer */
836 DBG(HFCUSB_DBG_FIFO_ERR,
837 "HFC-S USB: ERROR frame len(%d) fifo(%d)",
838 fifo->skbuff->len, fifon);
839 DBG_SKB(HFCUSB_DBG_VERBOSE_USB, fifo->skbuff);
840 skb_trim(fifo->skbuff, 0);
846 rx_int_complete(struct urb *urb)
850 __u8 *buf, maxlen, fifon;
851 usb_fifo *fifo = (usb_fifo *) urb->context;
852 hfcusb_data *hfc = fifo->hfc;
855 urb->dev = hfc->dev; /* security init */
857 fifon = fifo->fifonum;
858 if ((!fifo->active) || (urb->status)) {
859 DBG(HFCUSB_DBG_INIT, "HFC-S USB: RX-Fifo %i is going down (%i)",
862 fifo->urb->interval = 0; /* cancel automatic rescheduling */
864 dev_kfree_skb_any(fifo->skbuff);
869 len = urb->actual_length;
871 maxlen = fifo->usb_packet_maxlen;
873 if (fifon == HFCUSB_D_RX) {
874 DBG(HFCUSB_DBG_VERBOSE_USB,
875 "HFC-S USB: INT-D-RX lst_urblen:%2d "
876 "act_urblen:%2d max-urblen:%2d EOF:0x%0x",
877 fifo->last_urblen, len, maxlen,
879 DBG_PACKET(HFCUSB_DBG_VERBOSE_USB, buf, len);
882 if (fifo->last_urblen != fifo->usb_packet_maxlen) {
883 /* the threshold mask is in the 2nd status byte */
884 hfc->threshold_mask = buf[1];
885 /* the S0 state is in the upper half of the 1st status byte */
886 s0_state_handler(hfc, buf[0] >> 4);
887 eof[fifon] = buf[0] & 1;
888 /* if we have more than the 2 status bytes -> collect data */
890 collect_rx_frame(fifo, buf + 2,
891 urb->actual_length - 2,
892 (len < maxlen) ? eof[fifon] : 0);
894 collect_rx_frame(fifo, buf, urb->actual_length,
895 (len < maxlen) ? eof[fifon] : 0);
897 fifo->last_urblen = urb->actual_length;
898 status = usb_submit_urb(urb, GFP_ATOMIC);
901 "HFC-S USB: %s error resubmitting URB fifo(%d)\n",
902 __FUNCTION__, fifon);
906 /* start initial INT-URB for certain fifo */
908 start_int_fifo(usb_fifo * fifo)
912 DBG(HFCUSB_DBG_INIT, "HFC-S USB: starting RX INT-URB for fifo:%d\n",
916 fifo->urb = usb_alloc_urb(0, GFP_KERNEL);
920 usb_fill_int_urb(fifo->urb, fifo->hfc->dev, fifo->pipe,
921 fifo->buffer, fifo->usb_packet_maxlen,
922 rx_int_complete, fifo, fifo->intervall);
923 fifo->active = 1; /* must be marked active */
924 errcode = usb_submit_urb(fifo->urb, GFP_KERNEL);
927 "HFC-S USB: submit URB error(start_int_info): status:%i\n",
935 setup_bchannel(hfcusb_data * hfc, int channel, int mode)
937 __u8 val, idx_table[2] = { 0, 2 };
939 if (hfc->disc_flag) {
942 DBG(HFCUSB_DBG_STATES, "HFC-S USB: setting channel %d to mode %d",
944 hfc->b_mode[channel] = mode;
948 if (mode != L1_MODE_NULL)
949 val = 8; /* enable fifo? */
950 if (mode == L1_MODE_TRANS)
951 val |= 2; /* set transparent bit */
953 /* set FIFO to transmit register */
954 queue_control_request(hfc, HFCUSB_FIFO, idx_table[channel], 1);
955 queue_control_request(hfc, HFCUSB_CON_HDLC, val, 1);
957 queue_control_request(hfc, HFCUSB_INC_RES_F, 2, 1);
958 /* set FIFO to receive register */
959 queue_control_request(hfc, HFCUSB_FIFO, idx_table[channel] + 1, 1);
960 queue_control_request(hfc, HFCUSB_CON_HDLC, val, 1);
962 queue_control_request(hfc, HFCUSB_INC_RES_F, 2, 1);
969 queue_control_request(hfc, HFCUSB_SCTRL, val, 1);
976 queue_control_request(hfc, HFCUSB_SCTRL_R, val, 1);
978 if (mode == L1_MODE_NULL) {
980 handle_led(hfc, LED_B2_OFF);
982 handle_led(hfc, LED_B1_OFF);
985 handle_led(hfc, LED_B2_ON);
987 handle_led(hfc, LED_B1_ON);
992 hfc_usb_l2l1(struct hisax_if *my_hisax_if, int pr, void *arg)
994 usb_fifo *fifo = my_hisax_if->priv;
995 hfcusb_data *hfc = fifo->hfc;
998 case PH_ACTIVATE | REQUEST:
999 if (fifo->fifonum == HFCUSB_D_TX) {
1000 DBG(HFCUSB_DBG_STATES,
1001 "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_ACTIVATE | REQUEST");
1003 if (hfc->l1_state != 3
1004 && hfc->l1_state != 7) {
1005 hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,
1009 DBG(HFCUSB_DBG_STATES,
1010 "HFC-S USB: PH_DEACTIVATE | INDICATION sent (not state 3 or 7)");
1012 if (hfc->l1_state == 7) { /* l1 already active */
1013 hfc->d_if.ifc.l1l2(&hfc->
1020 DBG(HFCUSB_DBG_STATES,
1021 "HFC-S USB: PH_ACTIVATE | INDICATION sent again ;)");
1023 /* force sending sending INFO1 */
1024 queue_control_request(hfc,
1029 /* start l1 activation */
1030 queue_control_request(hfc,
1047 DBG(HFCUSB_DBG_STATES,
1048 "HFC_USB: hfc_usb_d_l2l1 B-chan: PH_ACTIVATE | REQUEST");
1051 HFCUSB_B1_TX) ? 0 : 1,
1053 fifo->hif->l1l2(fifo->hif,
1054 PH_ACTIVATE | INDICATION,
1058 case PH_DEACTIVATE | REQUEST:
1059 if (fifo->fifonum == HFCUSB_D_TX) {
1060 DBG(HFCUSB_DBG_STATES,
1061 "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_DEACTIVATE | REQUEST");
1063 DBG(HFCUSB_DBG_STATES,
1064 "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_DEACTIVATE | REQUEST");
1067 HFCUSB_B1_TX) ? 0 : 1,
1068 (int) L1_MODE_NULL);
1069 fifo->hif->l1l2(fifo->hif,
1070 PH_DEACTIVATE | INDICATION,
1074 case PH_DATA | REQUEST:
1075 if (fifo->skbuff && fifo->delete_flg) {
1076 dev_kfree_skb_any(fifo->skbuff);
1077 fifo->skbuff = NULL;
1078 fifo->delete_flg = 0;
1080 fifo->skbuff = arg; /* we have a new buffer */
1083 DBG(HFCUSB_DBG_STATES,
1084 "HFC_USB: hfc_usb_d_l2l1: unkown state : %#x", pr);
1089 /* initial init HFC-S USB chip registers, HiSax interface, USB URBs */
1091 hfc_usb_init(hfcusb_data * hfc)
1096 struct hisax_b_if *p_b_if[2];
1098 /* check the chip id */
1099 if (read_usb(hfc, HFCUSB_CHIP_ID, &b) != 1) {
1100 printk(KERN_INFO "HFC-USB: cannot read chip id\n");
1103 if (b != HFCUSB_CHIPID) {
1104 printk(KERN_INFO "HFC-S USB: Invalid chip id 0x%02x\n", b);
1108 /* first set the needed config, interface and alternate */
1109 err = usb_set_interface(hfc->dev, hfc->if_used, hfc->alt_used);
1112 write_usb(hfc, HFCUSB_CIRM, 8);
1113 /* aux = output, reset off */
1114 write_usb(hfc, HFCUSB_CIRM, 0x10);
1116 /* set USB_SIZE to match wMaxPacketSize for INT or BULK transfers */
1117 write_usb(hfc, HFCUSB_USB_SIZE,
1118 (hfc->packet_size / 8) | ((hfc->packet_size / 8) << 4));
1120 /* set USB_SIZE_I to match wMaxPacketSize for ISO transfers */
1121 write_usb(hfc, HFCUSB_USB_SIZE_I, hfc->iso_packet_size);
1123 /* enable PCM/GCI master mode */
1124 write_usb(hfc, HFCUSB_MST_MODE1, 0); /* set default values */
1125 write_usb(hfc, HFCUSB_MST_MODE0, 1); /* enable master mode */
1127 /* init the fifos */
1128 write_usb(hfc, HFCUSB_F_THRES,
1129 (HFCUSB_TX_THRESHOLD /
1130 8) | ((HFCUSB_RX_THRESHOLD / 8) << 4));
1133 for (i = 0; i < HFCUSB_NUM_FIFOS; i++) {
1134 write_usb(hfc, HFCUSB_FIFO, i); /* select the desired fifo */
1135 fifo[i].skbuff = NULL; /* init buffer pointer */
1137 (i <= HFCUSB_B2_RX) ? MAX_BCH_SIZE : MAX_DFRAME_LEN;
1138 fifo[i].last_urblen = 0;
1139 /* set 2 bit for D- & E-channel */
1140 write_usb(hfc, HFCUSB_HDLC_PAR,
1141 ((i <= HFCUSB_B2_RX) ? 0 : 2));
1142 /* rx hdlc, enable IFF for D-channel */
1143 write_usb(hfc, HFCUSB_CON_HDLC,
1144 ((i == HFCUSB_D_TX) ? 0x09 : 0x08));
1145 write_usb(hfc, HFCUSB_INC_RES_F, 2); /* reset the fifo */
1148 write_usb(hfc, HFCUSB_CLKDEL, 0x0f); /* clock delay value */
1149 write_usb(hfc, HFCUSB_STATES, 3 | 0x10); /* set deactivated mode */
1150 write_usb(hfc, HFCUSB_STATES, 3); /* enable state machine */
1152 write_usb(hfc, HFCUSB_SCTRL_R, 0); /* disable both B receivers */
1153 write_usb(hfc, HFCUSB_SCTRL, 0x40); /* disable B transmitters + capacitive mode */
1155 /* set both B-channel to not connected */
1156 hfc->b_mode[0] = L1_MODE_NULL;
1157 hfc->b_mode[1] = L1_MODE_NULL;
1159 hfc->l1_activated = 0;
1162 hfc->led_new_data = 0;
1163 hfc->old_led_state = 0;
1165 /* init the t3 timer */
1166 init_timer(&hfc->t3_timer);
1167 hfc->t3_timer.data = (long) hfc;
1168 hfc->t3_timer.function = (void *) l1_timer_expire_t3;
1170 /* init the t4 timer */
1171 init_timer(&hfc->t4_timer);
1172 hfc->t4_timer.data = (long) hfc;
1173 hfc->t4_timer.function = (void *) l1_timer_expire_t4;
1175 /* init the background machinery for control requests */
1176 hfc->ctrl_read.bRequestType = 0xc0;
1177 hfc->ctrl_read.bRequest = 1;
1178 hfc->ctrl_read.wLength = cpu_to_le16(1);
1179 hfc->ctrl_write.bRequestType = 0x40;
1180 hfc->ctrl_write.bRequest = 0;
1181 hfc->ctrl_write.wLength = 0;
1182 usb_fill_control_urb(hfc->ctrl_urb,
1185 (u_char *) & hfc->ctrl_write,
1186 NULL, 0, ctrl_complete, hfc);
1187 /* Init All Fifos */
1188 for (i = 0; i < HFCUSB_NUM_FIFOS; i++) {
1189 hfc->fifos[i].iso[0].purb = NULL;
1190 hfc->fifos[i].iso[1].purb = NULL;
1191 hfc->fifos[i].active = 0;
1193 /* register Modul to upper Hisax Layers */
1194 hfc->d_if.owner = THIS_MODULE;
1195 hfc->d_if.ifc.priv = &hfc->fifos[HFCUSB_D_TX];
1196 hfc->d_if.ifc.l2l1 = hfc_usb_l2l1;
1197 for (i = 0; i < 2; i++) {
1198 hfc->b_if[i].ifc.priv = &hfc->fifos[HFCUSB_B1_TX + i * 2];
1199 hfc->b_if[i].ifc.l2l1 = hfc_usb_l2l1;
1200 p_b_if[i] = &hfc->b_if[i];
1202 /* default Prot: EURO ISDN, should be a module_param */
1204 i = hisax_register(&hfc->d_if, p_b_if, "hfc_usb", hfc->protocol);
1206 printk(KERN_INFO "HFC-S USB: hisax_register -> %d\n", i);
1210 #ifdef CONFIG_HISAX_DEBUG
1214 for (i = 0; i < 4; i++)
1215 hfc->fifos[i].hif = &p_b_if[i / 2]->ifc;
1216 for (i = 4; i < 8; i++)
1217 hfc->fifos[i].hif = &hfc->d_if.ifc;
1219 /* 3 (+1) INT IN + 3 ISO OUT */
1220 if (hfc->cfg_used == CNF_3INT3ISO || hfc->cfg_used == CNF_4INT3ISO) {
1221 start_int_fifo(hfc->fifos + HFCUSB_D_RX);
1222 if (hfc->fifos[HFCUSB_PCM_RX].pipe)
1223 start_int_fifo(hfc->fifos + HFCUSB_PCM_RX);
1224 start_int_fifo(hfc->fifos + HFCUSB_B1_RX);
1225 start_int_fifo(hfc->fifos + HFCUSB_B2_RX);
1227 /* 3 (+1) ISO IN + 3 ISO OUT */
1228 if (hfc->cfg_used == CNF_3ISO3ISO || hfc->cfg_used == CNF_4ISO3ISO) {
1229 start_isoc_chain(hfc->fifos + HFCUSB_D_RX, ISOC_PACKETS_D,
1230 rx_iso_complete, 16);
1231 if (hfc->fifos[HFCUSB_PCM_RX].pipe)
1232 start_isoc_chain(hfc->fifos + HFCUSB_PCM_RX,
1233 ISOC_PACKETS_D, rx_iso_complete,
1235 start_isoc_chain(hfc->fifos + HFCUSB_B1_RX, ISOC_PACKETS_B,
1236 rx_iso_complete, 16);
1237 start_isoc_chain(hfc->fifos + HFCUSB_B2_RX, ISOC_PACKETS_B,
1238 rx_iso_complete, 16);
1241 start_isoc_chain(hfc->fifos + HFCUSB_D_TX, ISOC_PACKETS_D,
1242 tx_iso_complete, 1);
1243 start_isoc_chain(hfc->fifos + HFCUSB_B1_TX, ISOC_PACKETS_B,
1244 tx_iso_complete, 1);
1245 start_isoc_chain(hfc->fifos + HFCUSB_B2_TX, ISOC_PACKETS_B,
1246 tx_iso_complete, 1);
1248 handle_led(hfc, LED_POWER_ON);
1253 /* initial callback for each plugged USB device */
1255 hfc_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
1257 struct usb_device *dev = interface_to_usbdev(intf);
1258 hfcusb_data *context;
1259 struct usb_host_interface *iface = intf->cur_altsetting;
1260 struct usb_host_interface *iface_used = NULL;
1261 struct usb_host_endpoint *ep;
1262 int ifnum = iface->desc.bInterfaceNumber;
1263 int i, idx, alt_idx, probe_alt_setting, vend_idx, cfg_used, *vcf,
1264 attr, cfg_found, cidx, ep_addr;
1265 int cmptbl[16], small_match, iso_packet_size, packet_size,
1267 hfcsusb_vdata *driver_info;
1270 for (i = 0; hfcusb_idtab[i].idVendor; i++) {
1271 if ((le16_to_cpu(dev->descriptor.idVendor) == hfcusb_idtab[i].idVendor)
1272 && (le16_to_cpu(dev->descriptor.idProduct) == hfcusb_idtab[i].idProduct)) {
1279 "HFC-S USB: probing interface(%d) actalt(%d) minor(%d)\n",
1280 ifnum, iface->desc.bAlternateSetting, intf->minor);
1282 if (vend_idx != 0xffff) {
1283 /* if vendor and product ID is OK, start probing alternate settings */
1285 small_match = 0xffff;
1287 /* default settings */
1288 iso_packet_size = 16;
1291 while (alt_idx < intf->num_altsetting) {
1292 iface = intf->altsetting + alt_idx;
1293 probe_alt_setting = iface->desc.bAlternateSetting;
1296 /* check for config EOL element */
1297 while (validconf[cfg_used][0]) {
1299 vcf = validconf[cfg_used];
1300 /* first endpoint descriptor */
1301 ep = iface->endpoint;
1303 memcpy(cmptbl, vcf, 16 * sizeof(int));
1305 /* check for all endpoints in this alternate setting */
1306 for (i = 0; i < iface->desc.bNumEndpoints;
1309 ep->desc.bEndpointAddress;
1310 /* get endpoint base */
1311 idx = ((ep_addr & 0x7f) - 1) * 2;
1314 attr = ep->desc.bmAttributes;
1315 if (cmptbl[idx] == EP_NUL) {
1318 if (attr == USB_ENDPOINT_XFER_INT
1319 && cmptbl[idx] == EP_INT)
1320 cmptbl[idx] = EP_NUL;
1321 if (attr == USB_ENDPOINT_XFER_BULK
1322 && cmptbl[idx] == EP_BLK)
1323 cmptbl[idx] = EP_NUL;
1324 if (attr == USB_ENDPOINT_XFER_ISOC
1325 && cmptbl[idx] == EP_ISO)
1326 cmptbl[idx] = EP_NUL;
1328 /* check if all INT endpoints match minimum interval */
1329 if ((attr == USB_ENDPOINT_XFER_INT)
1330 && (ep->desc.bInterval < vcf[17])) {
1335 for (i = 0; i < 16; i++) {
1336 /* all entries must be EP_NOP or EP_NUL for a valid config */
1337 if (cmptbl[i] != EP_NOP
1338 && cmptbl[i] != EP_NUL)
1342 if (cfg_used < small_match) {
1343 small_match = cfg_used;
1352 } /* (alt_idx < intf->num_altsetting) */
1354 /* found a valid USB Ta Endpint config */
1355 if (small_match != 0xffff) {
1357 if (!(context = kzalloc(sizeof(hfcusb_data), GFP_KERNEL)))
1358 return (-ENOMEM); /* got no mem */
1360 ep = iface->endpoint;
1361 vcf = validconf[small_match];
1363 for (i = 0; i < iface->desc.bNumEndpoints; i++) {
1364 ep_addr = ep->desc.bEndpointAddress;
1365 /* get endpoint base */
1366 idx = ((ep_addr & 0x7f) - 1) * 2;
1370 attr = ep->desc.bmAttributes;
1372 /* init Endpoints */
1373 if (vcf[idx] != EP_NOP
1374 && vcf[idx] != EP_NUL) {
1376 case USB_ENDPOINT_XFER_INT:
1389 le16_to_cpu(ep->desc.wMaxPacketSize);
1391 case USB_ENDPOINT_XFER_BULK:
1417 le16_to_cpu(ep->desc.wMaxPacketSize);
1419 case USB_ENDPOINT_XFER_ISOC:
1445 le16_to_cpu(ep->desc.wMaxPacketSize);
1451 } /* switch attribute */
1453 if (context->fifos[cidx].pipe) {
1454 context->fifos[cidx].
1456 context->fifos[cidx].hfc =
1458 context->fifos[cidx].usb_packet_maxlen =
1459 le16_to_cpu(ep->desc.wMaxPacketSize);
1460 context->fifos[cidx].
1463 context->fifos[cidx].
1469 context->dev = dev; /* save device */
1470 context->if_used = ifnum; /* save used interface */
1471 context->alt_used = alt_used; /* and alternate config */
1472 context->ctrl_paksize = dev->descriptor.bMaxPacketSize0; /* control size */
1473 context->cfg_used = vcf[16]; /* store used config */
1474 context->vend_idx = vend_idx; /* store found vendor */
1475 context->packet_size = packet_size;
1476 context->iso_packet_size = iso_packet_size;
1478 /* create the control pipes needed for register access */
1479 context->ctrl_in_pipe =
1480 usb_rcvctrlpipe(context->dev, 0);
1481 context->ctrl_out_pipe =
1482 usb_sndctrlpipe(context->dev, 0);
1483 context->ctrl_urb = usb_alloc_urb(0, GFP_KERNEL);
1486 (hfcsusb_vdata *) hfcusb_idtab[vend_idx].
1488 printk(KERN_INFO "HFC-S USB: detected \"%s\"\n",
1489 driver_info->vend_name);
1491 DBG(HFCUSB_DBG_INIT,
1492 "HFC-S USB: Endpoint-Config: %s (if=%d alt=%d), E-Channel(%d)",
1493 conf_str[small_match], context->if_used,
1495 validconf[small_match][18]);
1497 /* init the chip and register the driver */
1498 if (hfc_usb_init(context)) {
1499 usb_kill_urb(context->ctrl_urb);
1500 usb_free_urb(context->ctrl_urb);
1501 context->ctrl_urb = NULL;
1505 usb_set_intfdata(intf, context);
1510 "HFC-S USB: no valid vendor found in USB descriptor\n");
1515 /* callback for unplugged USB device */
1517 hfc_usb_disconnect(struct usb_interface
1520 hfcusb_data *context = usb_get_intfdata(intf);
1523 handle_led(context, LED_POWER_OFF);
1524 schedule_timeout((10 * HZ) / 1000);
1526 printk(KERN_INFO "HFC-S USB: device disconnect\n");
1527 context->disc_flag = 1;
1528 usb_set_intfdata(intf, NULL);
1531 if (timer_pending(&context->t3_timer))
1532 del_timer(&context->t3_timer);
1533 if (timer_pending(&context->t4_timer))
1534 del_timer(&context->t4_timer);
1536 /* tell all fifos to terminate */
1537 for (i = 0; i < HFCUSB_NUM_FIFOS; i++) {
1538 if (context->fifos[i].usb_transfer_mode == USB_ISOC) {
1539 if (context->fifos[i].active > 0) {
1540 stop_isoc_chain(&context->fifos[i]);
1541 DBG(HFCUSB_DBG_INIT,
1542 "HFC-S USB: %s stopping ISOC chain Fifo(%i)",
1546 if (context->fifos[i].active > 0) {
1547 context->fifos[i].active = 0;
1548 DBG(HFCUSB_DBG_INIT,
1549 "HFC-S USB: %s unlinking URB for Fifo(%i)",
1552 usb_kill_urb(context->fifos[i].urb);
1553 usb_free_urb(context->fifos[i].urb);
1554 context->fifos[i].urb = NULL;
1556 context->fifos[i].active = 0;
1558 usb_kill_urb(context->ctrl_urb);
1559 usb_free_urb(context->ctrl_urb);
1560 context->ctrl_urb = NULL;
1561 hisax_unregister(&context->d_if);
1562 kfree(context); /* free our structure again */
1565 static struct usb_driver hfc_drv = {
1567 .id_table = hfcusb_idtab,
1568 .probe = hfc_usb_probe,
1569 .disconnect = hfc_usb_disconnect,
1573 hfc_usb_mod_exit(void)
1575 usb_deregister(&hfc_drv); /* release our driver */
1576 printk(KERN_INFO "HFC-S USB: module removed\n");
1580 hfc_usb_mod_init(void)
1582 char revstr[30], datestr[30], dummy[30];
1583 #ifndef CONFIG_HISAX_DEBUG
1586 sscanf(hfcusb_revision,
1587 "%s %s $ %s %s %s $ ", dummy, revstr,
1588 dummy, datestr, dummy);
1590 "HFC-S USB: driver module revision %s date %s loaded, (debug=%i)\n",
1591 revstr, datestr, debug);
1592 if (usb_register(&hfc_drv)) {
1594 "HFC-S USB: Unable to register HFC-S USB module at usb stack\n");
1595 return (-1); /* unable to register */
1600 module_init(hfc_usb_mod_init);
1601 module_exit(hfc_usb_mod_exit);
1602 MODULE_AUTHOR(DRIVER_AUTHOR);
1603 MODULE_DESCRIPTION(DRIVER_DESC);
1604 MODULE_LICENSE("GPL");
1605 MODULE_DEVICE_TABLE(usb, hfcusb_idtab);