4 * $Id: hfc_usb.c,v 4.34 2005/01/26 17:25:53 martinb1 Exp $
6 * modular HiSax ISDN driver for Colognechip HFC-S USB chip
8 * Authors : Peter Sprenger (sprenger@moving-bytes.de)
9 * Martin Bachem (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/config.h>
36 #include <linux/init.h>
37 #include <linux/module.h>
38 #include <linux/kernel_stat.h>
39 #include <linux/usb.h>
40 #include <linux/kernel.h>
41 #include <linux/smp_lock.h>
42 #include <linux/sched.h>
49 * (do not modify the CVS Makros $Revision: 4.34 $ and $Date: 2005/01/26 17:25:53 $ !)
51 static const char *hfcusb_revision =
52 "Revision: 4.34 $ Date: 2005/01/26 17:25:53 $ ";
54 /* Hisax debug support
55 * use "modprobe debug=x" where x is bitfield of USB_DBG & ISDN_DBG
57 #ifdef CONFIG_HISAX_DEBUG
58 #include <linux/moduleparam.h>
59 #define __debug_variable hfc_debug
60 #include "hisax_debug.h"
62 module_param(debug, uint, 0);
67 /****************************************/
68 /* data defining the devices to be used */
69 /****************************************/
70 static struct usb_device_id hfc_usb_idtab[] = {
71 {USB_DEVICE(0x0959, 0x2bd0)}, /* Colognechip USB eval TA */
72 {USB_DEVICE(0x0675, 0x1688)}, /* DrayTek miniVigor 128 USB ISDN TA */
73 {USB_DEVICE(0x07b0, 0x0007)}, /* Billion USB TA 2 */
74 {USB_DEVICE(0x0742, 0x2008)}, /* Stollmann USB TA */
75 {USB_DEVICE(0x0742, 0x2009)}, /* Aceex USB ISDN TA */
76 {USB_DEVICE(0x0742, 0x200A)}, /* OEM USB ISDN TA */
77 {USB_DEVICE(0x08e3, 0x0301)}, /* OliTec ISDN USB */
78 {USB_DEVICE(0x07fa, 0x0846)}, /* Bewan ISDN USB TA */
79 {USB_DEVICE(0x07fa, 0x0847)}, /* Djinn Numeris USB */
80 {USB_DEVICE(0x07b0, 0x0006)}, /* Twister ISDN USB TA */
81 {} /* end with an all-zeroes entry */
84 /* driver internal device specific data:
85 * VendorID, ProductID, Devicename, LED_SCHEME,
86 * LED's BitMask in HFCUSB_P_DATA Register : LED_USB, LED_S0, LED_B1, LED_B2
88 static vendor_data vdata[] = {
89 /* CologneChip Eval TA */
90 {0x0959, 0x2bd0, "ISDN USB TA (Cologne Chip HFC-S USB based)",
94 /* DrayTek miniVigor 128 USB ISDN TA */
95 {0x0675, 0x1688, "DrayTek miniVigor 128 USB ISDN TA",
96 LED_SCHEME1, {1, 2, 0, 0}
100 {0x07b0, 0x0007, "Billion tiny USB ISDN TA 128",
101 LED_SCHEME1, {0x80, -64, -32, -16}
105 {0x0742, 0x2008, "Stollmann USB TA",
106 LED_SCHEME1, {4, 0, 2, 1}
109 /* Aceex USB ISDN TA */
110 {0x0742, 0x2009, "Aceex USB ISDN TA",
111 LED_SCHEME1, {4, 0, 2, 1}
114 /* OEM USB ISDN TA */
115 {0x0742, 0x200A, "OEM USB ISDN TA",
116 LED_SCHEME1, {4, 0, 2, 1}
120 {0x08e3, 0x0301, "Olitec USB RNIS",
121 LED_SCHEME1, {2, 0, 1, 4}
125 {0x07fa, 0x0846, "Bewan Modem RNIS USB",
126 LED_SCHEME1, {0x80, -64, -32, -16}
130 {0x07fa, 0x0847, "Djinn Numeris USB",
131 LED_SCHEME1, {0x80, -64, -32, -16}
134 /* Twister ISDN TA */
135 {0x07b0, 0x0006, "Twister ISDN TA",
136 LED_SCHEME1, {0x80, -64, -32, -16}
139 {0, 0, 0} /* EOL element */
142 /***************************************************************/
143 /* structure defining input+output fifos (interrupt/bulk mode) */
144 /***************************************************************/
145 struct usb_fifo; /* forward definition */
146 typedef struct iso_urb_struct {
148 __u8 buffer[ISO_BUFFER_SIZE]; /* buffer incoming/outgoing data */
149 struct usb_fifo *owner_fifo; /* pointer to owner fifo */
153 struct hfcusb_data; /* forward definition */
154 typedef struct usb_fifo {
155 int fifonum; /* fifo index attached to this structure */
156 int active; /* fifo is currently active */
157 struct hfcusb_data *hfc; /* pointer to main structure */
158 int pipe; /* address of endpoint */
159 __u8 usb_packet_maxlen; /* maximum length for usb transfer */
160 unsigned int max_size; /* maximum size of receive/send packet */
161 __u8 intervall; /* interrupt interval */
162 struct sk_buff *skbuff; /* actual used buffer */
163 struct urb *urb; /* transfer structure for usb routines */
164 __u8 buffer[128]; /* buffer incoming/outgoing data */
165 int bit_line; /* how much bits are in the fifo? */
167 volatile __u8 usb_transfer_mode; /* switched between ISO and INT */
168 iso_urb_struct iso[2]; /* need two urbs to have one always for pending */
169 struct hisax_if *hif; /* hisax interface */
170 int delete_flg; /* only delete skbuff once */
171 int last_urblen; /* remember length of last packet */
175 /*********************************************/
176 /* structure holding all data for one device */
177 /*********************************************/
178 typedef struct hfcusb_data {
179 /* HiSax Interface for loadable Layer1 drivers */
180 struct hisax_d_if d_if; /* see hisax_if.h */
181 struct hisax_b_if b_if[2]; /* see hisax_if.h */
184 struct usb_device *dev; /* our device */
185 int if_used; /* used interface number */
186 int alt_used; /* used alternate config */
187 int ctrl_paksize; /* control pipe packet size */
188 int ctrl_in_pipe, ctrl_out_pipe; /* handles for control pipe */
189 int cfg_used; /* configuration index used */
190 int vend_idx; /* vendor found */
191 int b_mode[2]; /* B-channel mode */
192 int l1_activated; /* layer 1 activated */
193 int disc_flag; /* TRUE if device was disonnected to avoid some USB actions */
194 int packet_size, iso_packet_size;
196 /* control pipe background handling */
197 ctrl_buft ctrl_buff[HFC_CTRL_BUFSIZE]; /* buffer holding queued data */
198 volatile int ctrl_in_idx, ctrl_out_idx, ctrl_cnt; /* input/output pointer + count */
199 struct urb *ctrl_urb; /* transfer structure for control channel */
201 struct usb_ctrlrequest ctrl_write; /* buffer for control write request */
202 struct usb_ctrlrequest ctrl_read; /* same for read request */
204 __u8 old_led_state, led_state, led_new_data, led_b_active;
206 volatile __u8 threshold_mask; /* threshold actually reported */
207 volatile __u8 bch_enables; /* or mask for sctrl_r and sctrl register values */
209 usb_fifo fifos[HFCUSB_NUM_FIFOS]; /* structure holding all fifo data */
211 volatile __u8 l1_state; /* actual l1 state */
212 struct timer_list t3_timer; /* timer 3 for activation/deactivation */
213 struct timer_list t4_timer; /* timer 4 for activation/deactivation */
214 struct timer_list led_timer; /* timer flashing leds */
219 static void collect_rx_frame(usb_fifo * fifo, __u8 * data, int len,
223 static inline const char *
224 symbolic(struct hfcusb_symbolic_list list[], const int num)
227 for (i = 0; list[i].name != NULL; i++)
228 if (list[i].num == num)
229 return (list[i].name);
234 /******************************************************/
235 /* start next background transfer for control channel */
236 /******************************************************/
238 ctrl_start_transfer(hfcusb_data * hfc)
241 hfc->ctrl_urb->pipe = hfc->ctrl_out_pipe;
242 hfc->ctrl_urb->setup_packet = (u_char *) & hfc->ctrl_write;
243 hfc->ctrl_urb->transfer_buffer = NULL;
244 hfc->ctrl_urb->transfer_buffer_length = 0;
245 hfc->ctrl_write.wIndex =
246 hfc->ctrl_buff[hfc->ctrl_out_idx].hfc_reg;
247 hfc->ctrl_write.wValue =
248 hfc->ctrl_buff[hfc->ctrl_out_idx].reg_val;
250 usb_submit_urb(hfc->ctrl_urb, GFP_ATOMIC); /* start transfer */
252 } /* ctrl_start_transfer */
254 /************************************/
255 /* queue a control transfer request */
256 /* return 0 on success. */
257 /************************************/
259 queue_control_request(hfcusb_data * hfc, __u8 reg, __u8 val, int action)
263 if (hfc->ctrl_cnt >= HFC_CTRL_BUFSIZE)
264 return (1); /* no space left */
265 buf = &hfc->ctrl_buff[hfc->ctrl_in_idx]; /* pointer to new index */
268 buf->action = action;
269 if (++hfc->ctrl_in_idx >= HFC_CTRL_BUFSIZE)
270 hfc->ctrl_in_idx = 0; /* pointer wrap */
271 if (++hfc->ctrl_cnt == 1)
272 ctrl_start_transfer(hfc);
274 } /* queue_control_request */
277 control_action_handler(hfcusb_data * hfc, int reg, int val, int action)
280 return (1); /* no action defined */
284 /***************************************************************/
285 /* control completion routine handling background control cmds */
286 /***************************************************************/
288 ctrl_complete(struct urb *urb, struct pt_regs *regs)
290 hfcusb_data *hfc = (hfcusb_data *) urb->context;
295 buf = &hfc->ctrl_buff[hfc->ctrl_out_idx];
296 control_action_handler(hfc, buf->hfc_reg, buf->reg_val,
299 hfc->ctrl_cnt--; /* decrement actual count */
300 if (++hfc->ctrl_out_idx >= HFC_CTRL_BUFSIZE)
301 hfc->ctrl_out_idx = 0; /* pointer wrap */
303 ctrl_start_transfer(hfc); /* start next transfer */
305 } /* ctrl_complete */
307 /***************************************************/
308 /* write led data to auxport & invert if necessary */
309 /***************************************************/
311 write_led(hfcusb_data * hfc, __u8 led_state)
313 if (led_state != hfc->old_led_state) {
314 hfc->old_led_state = led_state;
315 queue_control_request(hfc, HFCUSB_P_DATA, led_state, 1);
319 /**************************/
320 /* handle LED bits */
321 /**************************/
323 set_led_bit(hfcusb_data * hfc, signed short led_bits, int unset)
327 hfc->led_state |= abs(led_bits);
329 hfc->led_state &= ~led_bits;
332 hfc->led_state &= ~abs(led_bits);
334 hfc->led_state |= led_bits;
338 /******************************************/
339 /* invert B-channel LEDs if data is sent */
340 /******************************************/
342 led_timer(hfcusb_data * hfc)
347 if (hfc->led_b_active & 1)
348 set_led_bit(hfc, vdata[hfc->vend_idx].led_bits[2],
350 if (hfc->led_b_active & 2)
351 set_led_bit(hfc, vdata[hfc->vend_idx].led_bits[3],
354 if (!(hfc->led_b_active & 1) || hfc->led_new_data & 1)
355 set_led_bit(hfc, vdata[hfc->vend_idx].led_bits[2],
357 if (!(hfc->led_b_active & 2) || hfc->led_new_data & 2)
358 set_led_bit(hfc, vdata[hfc->vend_idx].led_bits[3],
362 write_led(hfc, hfc->led_state);
363 hfc->led_new_data = 0;
367 /* restart 4 hz timer */
368 if (!timer_pending(&hfc->led_timer)) {
369 add_timer(&hfc->led_timer);
370 hfc->led_timer.expires = jiffies + (LED_TIME * HZ) / 1000;
374 /**************************/
375 /* handle LED requests */
376 /**************************/
378 handle_led(hfcusb_data * hfc, int event)
380 /* if no scheme -> no LED action */
381 if (vdata[hfc->vend_idx].led_scheme == LED_OFF)
386 set_led_bit(hfc, vdata[hfc->vend_idx].led_bits[0],
388 set_led_bit(hfc, vdata[hfc->vend_idx].led_bits[1],
390 set_led_bit(hfc, vdata[hfc->vend_idx].led_bits[2],
392 set_led_bit(hfc, vdata[hfc->vend_idx].led_bits[3],
395 case LED_POWER_OFF: /* no Power off handling */
398 set_led_bit(hfc, vdata[hfc->vend_idx].led_bits[1],
402 set_led_bit(hfc, vdata[hfc->vend_idx].led_bits[1],
406 hfc->led_b_active |= 1;
409 hfc->led_b_active &= ~1;
412 hfc->led_new_data |= 1;
415 hfc->led_b_active |= 2;
418 hfc->led_b_active &= ~2;
421 hfc->led_new_data |= 2;
425 write_led(hfc, hfc->led_state);
428 /********************************/
429 /* called when timer t3 expires */
430 /********************************/
432 l1_timer_expire_t3(hfcusb_data * hfc)
434 hfc->d_if.ifc.l1l2(&hfc->d_if.ifc, PH_DEACTIVATE | INDICATION,
436 #ifdef CONFIG_HISAX_DEBUG
438 "HFC-S USB: PH_DEACTIVATE | INDICATION sent (T3 expire)");
440 hfc->l1_activated = FALSE;
441 handle_led(hfc, LED_S0_OFF);
443 queue_control_request(hfc, HFCUSB_STATES, 0x10, 1);
444 queue_control_request(hfc, HFCUSB_STATES, 3, 1);
447 /********************************/
448 /* called when timer t4 expires */
449 /********************************/
451 l1_timer_expire_t4(hfcusb_data * hfc)
453 hfc->d_if.ifc.l1l2(&hfc->d_if.ifc, PH_DEACTIVATE | INDICATION,
455 #ifdef CONFIG_HISAX_DEBUG
457 "HFC-S USB: PH_DEACTIVATE | INDICATION sent (T4 expire)");
459 hfc->l1_activated = FALSE;
460 handle_led(hfc, LED_S0_OFF);
463 /*****************************/
464 /* handle S0 state changes */
465 /*****************************/
467 state_handler(hfcusb_data * hfc, __u8 state)
471 old_state = hfc->l1_state;
472 if (state == old_state || state < 1 || state > 8)
475 #ifdef CONFIG_HISAX_DEBUG
476 DBG(ISDN_DBG, "HFC-S USB: new S0 state:%d old_state:%d", state,
479 if (state < 4 || state == 7 || state == 8) {
480 if (timer_pending(&hfc->t3_timer))
481 del_timer(&hfc->t3_timer);
482 #ifdef CONFIG_HISAX_DEBUG
483 DBG(ISDN_DBG, "HFC-S USB: T3 deactivated");
487 if (timer_pending(&hfc->t4_timer))
488 del_timer(&hfc->t4_timer);
489 #ifdef CONFIG_HISAX_DEBUG
490 DBG(ISDN_DBG, "HFC-S USB: T4 deactivated");
494 if (state == 7 && !hfc->l1_activated) {
495 hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,
496 PH_ACTIVATE | INDICATION, NULL);
497 #ifdef CONFIG_HISAX_DEBUG
498 DBG(ISDN_DBG, "HFC-S USB: PH_ACTIVATE | INDICATION sent");
500 hfc->l1_activated = TRUE;
501 handle_led(hfc, LED_S0_ON);
502 } else if (state <= 3 /* && activated */ ) {
503 if (old_state == 7 || old_state == 8) {
504 #ifdef CONFIG_HISAX_DEBUG
505 DBG(ISDN_DBG, "HFC-S USB: T4 activated");
507 if (!timer_pending(&hfc->t4_timer)) {
508 hfc->t4_timer.expires =
509 jiffies + (HFC_TIMER_T4 * HZ) / 1000;
510 add_timer(&hfc->t4_timer);
513 hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,
514 PH_DEACTIVATE | INDICATION,
516 #ifdef CONFIG_HISAX_DEBUG
518 "HFC-S USB: PH_DEACTIVATE | INDICATION sent");
520 hfc->l1_activated = FALSE;
521 handle_led(hfc, LED_S0_OFF);
524 hfc->l1_state = state;
527 /* prepare iso urb */
529 fill_isoc_urb(struct urb *urb, struct usb_device *dev, unsigned int pipe,
530 void *buf, int num_packets, int packet_size, int interval,
531 usb_complete_t complete, void *context)
535 spin_lock_init(&urb->lock);
538 urb->complete = complete;
539 urb->number_of_packets = num_packets;
540 urb->transfer_buffer_length = packet_size * num_packets;
541 urb->context = context;
542 urb->transfer_buffer = buf;
543 urb->transfer_flags = URB_ISO_ASAP;
544 urb->actual_length = 0;
545 urb->interval = interval;
546 for (k = 0; k < num_packets; k++) {
547 urb->iso_frame_desc[k].offset = packet_size * k;
548 urb->iso_frame_desc[k].length = packet_size;
549 urb->iso_frame_desc[k].actual_length = 0;
553 /* allocs urbs and start isoc transfer with two pending urbs to avoid
554 gaps in the transfer chain */
556 start_isoc_chain(usb_fifo * fifo, int num_packets_per_urb,
557 usb_complete_t complete, int packet_size)
561 printk(KERN_INFO "HFC-S USB: starting ISO-chain for Fifo %i\n",
564 /* allocate Memory for Iso out Urbs */
565 for (i = 0; i < 2; i++) {
566 if (!(fifo->iso[i].purb)) {
568 usb_alloc_urb(num_packets_per_urb, GFP_KERNEL);
569 if (!(fifo->iso[i].purb)) {
571 "alloc urb for fifo %i failed!!!",
574 fifo->iso[i].owner_fifo = (struct usb_fifo *) fifo;
576 /* Init the first iso */
577 if (ISO_BUFFER_SIZE >=
578 (fifo->usb_packet_maxlen *
579 num_packets_per_urb)) {
580 fill_isoc_urb(fifo->iso[i].purb,
581 fifo->hfc->dev, fifo->pipe,
584 fifo->usb_packet_maxlen,
585 fifo->intervall, complete,
587 memset(fifo->iso[i].buffer, 0,
588 sizeof(fifo->iso[i].buffer));
589 /* defining packet delimeters in fifo->buffer */
590 for (k = 0; k < num_packets_per_urb; k++) {
592 iso_frame_desc[k].offset =
595 iso_frame_desc[k].length =
600 "HFC-S USB: ISO Buffer size to small!\n");
603 fifo->bit_line = BITLINE_INF;
605 errcode = usb_submit_urb(fifo->iso[i].purb, GFP_KERNEL);
606 fifo->active = (errcode >= 0) ? 1 : 0;
608 printk(KERN_INFO "HFC-S USB: %s URB nr:%d\n",
609 symbolic(urb_errlist, errcode), i);
612 return (fifo->active);
615 /* stops running iso chain and frees their pending urbs */
617 stop_isoc_chain(usb_fifo * fifo)
621 for (i = 0; i < 2; i++) {
622 if (fifo->iso[i].purb) {
623 #ifdef CONFIG_HISAX_DEBUG
625 "HFC-S USB: Stopping iso chain for fifo %i.%i",
628 usb_unlink_urb(fifo->iso[i].purb);
629 usb_free_urb(fifo->iso[i].purb);
630 fifo->iso[i].purb = NULL;
634 usb_unlink_urb(fifo->urb);
635 usb_free_urb(fifo->urb);
641 /* defines how much ISO packets are handled in one URB */
642 static int iso_packets[8] =
643 { ISOC_PACKETS_B, ISOC_PACKETS_B, ISOC_PACKETS_B, ISOC_PACKETS_B,
644 ISOC_PACKETS_D, ISOC_PACKETS_D, ISOC_PACKETS_D, ISOC_PACKETS_D
647 /*****************************************************/
648 /* transmit completion routine for all ISO tx fifos */
649 /*****************************************************/
651 tx_iso_complete(struct urb *urb, struct pt_regs *regs)
653 iso_urb_struct *context_iso_urb = (iso_urb_struct *) urb->context;
654 usb_fifo *fifo = context_iso_urb->owner_fifo;
655 hfcusb_data *hfc = fifo->hfc;
656 int k, tx_offset, num_isoc_packets, sink, len, current_len,
658 int frame_complete, transp_mode, fifon, status;
660 __u8 threshtable[8] = { 1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80 };
662 fifon = fifo->fifonum;
663 status = urb->status;
667 if (fifo->active && !status) {
669 if (fifon < 4 && hfc->b_mode[fifon / 2] == L1_MODE_TRANS)
672 /* is FifoFull-threshold set for our channel? */
673 threshbit = threshtable[fifon] & hfc->threshold_mask;
674 num_isoc_packets = iso_packets[fifon];
676 /* predict dataflow to avoid fifo overflow */
677 if (fifon >= HFCUSB_D_TX) {
678 sink = (threshbit) ? SINK_DMIN : SINK_DMAX;
680 sink = (threshbit) ? SINK_MIN : SINK_MAX;
682 fill_isoc_urb(urb, fifo->hfc->dev, fifo->pipe,
683 context_iso_urb->buffer, num_isoc_packets,
684 fifo->usb_packet_maxlen, fifo->intervall,
685 tx_iso_complete, urb->context);
686 memset(context_iso_urb->buffer, 0,
687 sizeof(context_iso_urb->buffer));
688 frame_complete = FALSE;
689 /* Generate next Iso Packets */
690 for (k = 0; k < num_isoc_packets; ++k) {
692 len = fifo->skbuff->len;
693 /* we lower data margin every msec */
694 fifo->bit_line -= sink;
695 current_len = (0 - fifo->bit_line) / 8;
696 /* maximum 15 byte for every ISO packet makes our life easier */
697 if (current_len > 14)
701 current_len) ? len : current_len;
702 /* how much bit do we put on the line? */
703 fifo->bit_line += current_len * 8;
705 context_iso_urb->buffer[tx_offset] = 0;
706 if (current_len == len) {
708 /* here frame completion */
710 buffer[tx_offset] = 1;
711 /* add 2 byte flags and 16bit CRC at end of ISDN frame */
712 fifo->bit_line += 32;
714 frame_complete = TRUE;
717 memcpy(context_iso_urb->buffer +
718 tx_offset + 1, fifo->skbuff->data,
720 skb_pull(fifo->skbuff, current_len);
722 /* define packet delimeters within the URB buffer */
723 urb->iso_frame_desc[k].offset = tx_offset;
724 urb->iso_frame_desc[k].length =
727 tx_offset += (current_len + 1);
729 if (fifon == HFCUSB_B1_TX)
732 if (fifon == HFCUSB_B2_TX)
737 urb->iso_frame_desc[k].offset =
740 urb->iso_frame_desc[k].length = 1;
741 fifo->bit_line -= sink; /* we lower data margin every msec */
743 if (fifo->bit_line < BITLINE_INF) {
744 fifo->bit_line = BITLINE_INF;
748 if (frame_complete) {
749 fifo->delete_flg = TRUE;
750 fifo->hif->l1l2(fifo->hif,
752 (void *) fifo->skbuff->
754 if (fifo->skbuff && fifo->delete_flg) {
755 dev_kfree_skb_any(fifo->skbuff);
757 fifo->delete_flg = FALSE;
759 frame_complete = FALSE;
762 errcode = usb_submit_urb(urb, GFP_ATOMIC);
765 "HFC-S USB: error submitting ISO URB: %d \n",
769 if (status && !hfc->disc_flag) {
771 "HFC-S USB: tx_iso_complete : urb->status %s (%i), fifonum=%d\n",
772 symbolic(urb_errlist, status), status,
776 } /* tx_iso_complete */
778 /*****************************************************/
779 /* receive completion routine for all ISO tx fifos */
780 /*****************************************************/
782 rx_iso_complete(struct urb *urb, struct pt_regs *regs)
784 iso_urb_struct *context_iso_urb = (iso_urb_struct *) urb->context;
785 usb_fifo *fifo = context_iso_urb->owner_fifo;
786 hfcusb_data *hfc = fifo->hfc;
787 int k, len, errcode, offset, num_isoc_packets, fifon, maxlen,
789 unsigned int iso_status;
792 #ifdef CONFIG_HISAX_DEBUG
796 fifon = fifo->fifonum;
797 status = urb->status;
799 if (urb->status == -EOVERFLOW) {
800 #ifdef CONFIG_HISAX_DEBUG
802 "HFC-USB: ignoring USB DATAOVERRUN for fifo %i \n",
807 if (fifo->active && !status) {
808 num_isoc_packets = iso_packets[fifon];
809 maxlen = fifo->usb_packet_maxlen;
810 for (k = 0; k < num_isoc_packets; ++k) {
811 len = urb->iso_frame_desc[k].actual_length;
812 offset = urb->iso_frame_desc[k].offset;
813 buf = context_iso_urb->buffer + offset;
814 iso_status = urb->iso_frame_desc[k].status;
815 #ifdef CONFIG_HISAX_DEBUG
816 if (iso_status && !hfc->disc_flag)
818 "HFC-S USB: ISO packet failure - status:%x",
821 if ((fifon == 5) && (debug > 1)) {
823 "HFC-S USB: ISO-D-RX lst_urblen:%2d "
824 "act_urblen:%2d max-urblen:%2d "
826 fifo->last_urblen, len, maxlen,
828 for (i = 0; i < len; i++)
829 printk("%.2x ", buf[i]);
833 if (fifo->last_urblen != maxlen) {
834 /* the threshold mask is in the 2nd status byte */
835 hfc->threshold_mask = buf[1];
836 /* care for L1 state only for D-Channel
837 to avoid overlapped iso completions */
839 /* the S0 state is in the upper half
840 of the 1st status byte */
841 state_handler(hfc, buf[0] >> 4);
843 eof[fifon] = buf[0] & 1;
845 collect_rx_frame(fifo, buf + 2,
851 collect_rx_frame(fifo, buf, len,
853 maxlen) ? eof[fifon] :
856 fifo->last_urblen = len;
859 fill_isoc_urb(urb, fifo->hfc->dev, fifo->pipe,
860 context_iso_urb->buffer, num_isoc_packets,
861 fifo->usb_packet_maxlen, fifo->intervall,
862 rx_iso_complete, urb->context);
863 errcode = usb_submit_urb(urb, GFP_ATOMIC);
866 "HFC-S USB: error submitting ISO URB: %d \n",
870 if (status && !hfc->disc_flag) {
872 "HFC-S USB: rx_iso_complete : "
873 "urb->status %d, fifonum %d\n",
877 } /* rx_iso_complete */
879 /*****************************************************/
880 /* collect data from interrupt or isochron in */
881 /*****************************************************/
883 collect_rx_frame(usb_fifo * fifo, __u8 * data, int len, int finish)
885 hfcusb_data *hfc = fifo->hfc;
886 int transp_mode, fifon;
887 #ifdef CONFIG_HISAX_DEBUG
890 fifon = fifo->fifonum;
892 if (fifon < 4 && hfc->b_mode[fifon / 2] == L1_MODE_TRANS)
896 fifo->skbuff = dev_alloc_skb(fifo->max_size + 3);
899 "HFC-S USB: cannot allocate buffer (dev_alloc_skb) fifo:%d\n",
905 if (fifo->skbuff->len + len < fifo->max_size) {
906 memcpy(skb_put(fifo->skbuff, len), data, len);
908 #ifdef CONFIG_HISAX_DEBUG
909 printk(KERN_INFO "HFC-S USB: ");
910 for (i = 0; i < 15; i++)
912 fifo->skbuff->data[fifo->skbuff->
917 "HCF-USB: got frame exceeded fifo->max_size:%d on fifo:%d\n",
918 fifo->max_size, fifon);
921 if (transp_mode && fifo->skbuff->len >= 128) {
922 fifo->hif->l1l2(fifo->hif, PH_DATA | INDICATION,
927 /* we have a complete hdlc packet */
929 if ((!fifo->skbuff->data[fifo->skbuff->len - 1])
930 && (fifo->skbuff->len > 3)) {
931 /* remove CRC & status */
932 skb_trim(fifo->skbuff, fifo->skbuff->len - 3);
933 if (fifon == HFCUSB_PCM_RX) {
934 fifo->hif->l1l2(fifo->hif,
935 PH_DATA_E | INDICATION,
938 fifo->hif->l1l2(fifo->hif,
939 PH_DATA | INDICATION,
941 fifo->skbuff = NULL; /* buffer was freed from upper layer */
943 if (fifo->skbuff->len > 3) {
945 "HFC-S USB: got frame %d bytes but CRC ERROR on fifo:%d!!!\n",
946 fifo->skbuff->len, fifon);
947 #ifdef CONFIG_HISAX_DEBUG
949 printk(KERN_INFO "HFC-S USB: ");
950 for (i = 0; i < 15; i++)
959 #ifdef CONFIG_HISAX_DEBUG
962 "HFC-S USB: frame to small (%d bytes)!!!\n",
966 skb_trim(fifo->skbuff, 0);
970 /* LED flashing only in HDLC mode */
972 if (fifon == HFCUSB_B1_RX)
973 handle_led(hfc, LED_B1_DATA);
974 if (fifon == HFCUSB_B2_RX)
975 handle_led(hfc, LED_B2_DATA);
979 /***********************************************/
980 /* receive completion routine for all rx fifos */
981 /***********************************************/
983 rx_complete(struct urb *urb, struct pt_regs *regs)
987 __u8 *buf, maxlen, fifon;
988 usb_fifo *fifo = (usb_fifo *) urb->context;
989 hfcusb_data *hfc = fifo->hfc;
991 #ifdef CONFIG_HISAX_DEBUG
995 urb->dev = hfc->dev; /* security init */
997 fifon = fifo->fifonum;
998 if ((!fifo->active) || (urb->status)) {
999 #ifdef CONFIG_HISAX_DEBUG
1000 DBG(USB_DBG, "HFC-S USB: RX-Fifo %i is going down (%i)",
1001 fifon, urb->status);
1003 fifo->urb->interval = 0; /* cancel automatic rescheduling */
1005 dev_kfree_skb_any(fifo->skbuff);
1006 fifo->skbuff = NULL;
1010 len = urb->actual_length;
1012 maxlen = fifo->usb_packet_maxlen;
1014 #ifdef CONFIG_HISAX_DEBUG
1015 if ((fifon == 5) && (debug > 1)) {
1017 "HFC-S USB: INT-D-RX lst_urblen:%2d act_urblen:%2d max-urblen:%2d EOF:0x%0x DATA: ",
1018 fifo->last_urblen, len, maxlen, eof[5]);
1019 for (i = 0; i < len; i++)
1020 printk("%.2x ", buf[i]);
1025 if (fifo->last_urblen != fifo->usb_packet_maxlen) {
1026 /* the threshold mask is in the 2nd status byte */
1027 hfc->threshold_mask = buf[1];
1028 /* the S0 state is in the upper half of the 1st status byte */
1029 state_handler(hfc, buf[0] >> 4);
1030 eof[fifon] = buf[0] & 1;
1031 /* if we have more than the 2 status bytes -> collect data */
1033 collect_rx_frame(fifo, buf + 2,
1034 urb->actual_length - 2,
1035 (len < maxlen) ? eof[fifon] : 0);
1037 collect_rx_frame(fifo, buf, urb->actual_length,
1038 (len < maxlen) ? eof[fifon] : 0);
1040 fifo->last_urblen = urb->actual_length;
1041 status = usb_submit_urb(urb, GFP_ATOMIC);
1044 "HFC-S USB: error resubmitting URN at rx_complete...\n");
1048 /***************************************************/
1049 /* start the interrupt transfer for the given fifo */
1050 /***************************************************/
1052 start_int_fifo(usb_fifo * fifo)
1056 printk(KERN_INFO "HFC-S USB: starting intr IN fifo:%d\n",
1060 fifo->urb = usb_alloc_urb(0, GFP_KERNEL);
1064 usb_fill_int_urb(fifo->urb, fifo->hfc->dev, fifo->pipe,
1065 fifo->buffer, fifo->usb_packet_maxlen,
1066 rx_complete, fifo, fifo->intervall);
1067 fifo->active = 1; /* must be marked active */
1068 errcode = usb_submit_urb(fifo->urb, GFP_KERNEL);
1071 "HFC-S USB: submit URB error(start_int_info): status:%i\n",
1074 fifo->skbuff = NULL;
1076 } /* start_int_fifo */
1078 /*****************************/
1079 /* set the B-channel mode */
1080 /*****************************/
1082 set_hfcmode(hfcusb_data * hfc, int channel, int mode)
1084 __u8 val, idx_table[2] = { 0, 2 };
1086 if (hfc->disc_flag) {
1089 #ifdef CONFIG_HISAX_DEBUG
1090 DBG(ISDN_DBG, "HFC-S USB: setting channel %d to mode %d", channel,
1093 hfc->b_mode[channel] = mode;
1095 /* setup CON_HDLC */
1097 if (mode != L1_MODE_NULL)
1098 val = 8; /* enable fifo? */
1099 if (mode == L1_MODE_TRANS)
1100 val |= 2; /* set transparent bit */
1102 /* set FIFO to transmit register */
1103 queue_control_request(hfc, HFCUSB_FIFO, idx_table[channel], 1);
1104 queue_control_request(hfc, HFCUSB_CON_HDLC, val, 1);
1106 queue_control_request(hfc, HFCUSB_INC_RES_F, 2, 1);
1107 /* set FIFO to receive register */
1108 queue_control_request(hfc, HFCUSB_FIFO, idx_table[channel] + 1, 1);
1109 queue_control_request(hfc, HFCUSB_CON_HDLC, val, 1);
1111 queue_control_request(hfc, HFCUSB_INC_RES_F, 2, 1);
1118 queue_control_request(hfc, HFCUSB_SCTRL, val, 1);
1125 queue_control_request(hfc, HFCUSB_SCTRL_R, val, 1);
1127 if (mode == L1_MODE_NULL) {
1129 handle_led(hfc, LED_B2_OFF);
1131 handle_led(hfc, LED_B1_OFF);
1134 handle_led(hfc, LED_B2_ON);
1136 handle_led(hfc, LED_B1_ON);
1141 hfc_usb_l2l1(struct hisax_if *my_hisax_if, int pr, void *arg)
1143 usb_fifo *fifo = my_hisax_if->priv;
1144 hfcusb_data *hfc = fifo->hfc;
1147 case PH_ACTIVATE | REQUEST:
1148 if (fifo->fifonum == HFCUSB_D_TX) {
1149 #ifdef CONFIG_HISAX_DEBUG
1151 "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_ACTIVATE | REQUEST");
1153 if (hfc->l1_state != 3
1154 && hfc->l1_state != 7) {
1155 hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,
1159 #ifdef CONFIG_HISAX_DEBUG
1161 "HFC-S USB: PH_DEACTIVATE | INDICATION sent (not state 3 or 7)");
1164 if (hfc->l1_state == 7) { /* l1 already active */
1165 hfc->d_if.ifc.l1l2(&hfc->
1172 #ifdef CONFIG_HISAX_DEBUG
1174 "HFC-S USB: PH_ACTIVATE | INDICATION sent again ;)");
1177 /* force sending sending INFO1 */
1178 queue_control_request(hfc,
1183 /* start l1 activation */
1184 queue_control_request(hfc,
1201 #ifdef CONFIG_HISAX_DEBUG
1203 "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_ACTIVATE | REQUEST");
1207 HFCUSB_B1_TX) ? 0 : 1,
1209 fifo->hif->l1l2(fifo->hif,
1210 PH_ACTIVATE | INDICATION,
1214 case PH_DEACTIVATE | REQUEST:
1215 if (fifo->fifonum == HFCUSB_D_TX) {
1216 #ifdef CONFIG_HISAX_DEBUG
1218 "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_DEACTIVATE | REQUEST");
1221 "HFC-S USB: ISDN TE device should not deativate...\n");
1223 #ifdef CONFIG_HISAX_DEBUG
1225 "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_DEACTIVATE | REQUEST");
1229 HFCUSB_B1_TX) ? 0 : 1,
1230 (int) L1_MODE_NULL);
1231 fifo->hif->l1l2(fifo->hif,
1232 PH_DEACTIVATE | INDICATION,
1236 case PH_DATA | REQUEST:
1237 if (fifo->skbuff && fifo->delete_flg) {
1238 dev_kfree_skb_any(fifo->skbuff);
1239 fifo->skbuff = NULL;
1240 fifo->delete_flg = FALSE;
1242 fifo->skbuff = arg; /* we have a new buffer */
1246 "HFC_USB: hfc_usb_d_l2l1: unkown state : %#x\n",
1252 /***************************************************************************/
1253 /* usb_init is called once when a new matching device is detected to setup */
1254 /* main parameters. It registers the driver at the main hisax module. */
1255 /* on success 0 is returned. */
1256 /***************************************************************************/
1258 usb_init(hfcusb_data * hfc)
1263 struct hisax_b_if *p_b_if[2];
1265 /* check the chip id */
1266 if (read_usb(hfc, HFCUSB_CHIP_ID, &b) != 1) {
1267 printk(KERN_INFO "HFC-USB: cannot read chip id\n");
1270 if (b != HFCUSB_CHIPID) {
1271 printk(KERN_INFO "HFC-S USB: Invalid chip id 0x%02x\n", b);
1275 /* first set the needed config, interface and alternate */
1276 err = usb_set_interface(hfc->dev, hfc->if_used, hfc->alt_used);
1279 write_usb(hfc, HFCUSB_CIRM, 8);
1280 /* aux = output, reset off */
1281 write_usb(hfc, HFCUSB_CIRM, 0x10);
1283 /* set USB_SIZE to match the the wMaxPacketSize for INT or BULK transfers */
1284 write_usb(hfc, HFCUSB_USB_SIZE,
1285 (hfc->packet_size / 8) | ((hfc->packet_size / 8) << 4));
1287 /* set USB_SIZE_I to match the the wMaxPacketSize for ISO transfers */
1288 write_usb(hfc, HFCUSB_USB_SIZE_I, hfc->iso_packet_size);
1290 /* enable PCM/GCI master mode */
1291 write_usb(hfc, HFCUSB_MST_MODE1, 0); /* set default values */
1292 write_usb(hfc, HFCUSB_MST_MODE0, 1); /* enable master mode */
1294 /* init the fifos */
1295 write_usb(hfc, HFCUSB_F_THRES,
1296 (HFCUSB_TX_THRESHOLD /
1297 8) | ((HFCUSB_RX_THRESHOLD / 8) << 4));
1300 for (i = 0; i < HFCUSB_NUM_FIFOS; i++) {
1301 write_usb(hfc, HFCUSB_FIFO, i); /* select the desired fifo */
1302 fifo[i].skbuff = NULL; /* init buffer pointer */
1304 (i <= HFCUSB_B2_RX) ? MAX_BCH_SIZE : MAX_DFRAME_LEN;
1305 fifo[i].last_urblen = 0;
1306 /* set 2 bit for D- & E-channel */
1307 write_usb(hfc, HFCUSB_HDLC_PAR,
1308 ((i <= HFCUSB_B2_RX) ? 0 : 2));
1309 /* rx hdlc, enable IFF for D-channel */
1310 write_usb(hfc, HFCUSB_CON_HDLC,
1311 ((i == HFCUSB_D_TX) ? 0x09 : 0x08));
1312 write_usb(hfc, HFCUSB_INC_RES_F, 2); /* reset the fifo */
1315 write_usb(hfc, HFCUSB_CLKDEL, 0x0f); /* clock delay value */
1316 write_usb(hfc, HFCUSB_STATES, 3 | 0x10); /* set deactivated mode */
1317 write_usb(hfc, HFCUSB_STATES, 3); /* enable state machine */
1319 write_usb(hfc, HFCUSB_SCTRL_R, 0); /* disable both B receivers */
1320 write_usb(hfc, HFCUSB_SCTRL, 0x40); /* disable B transmitters + capacitive mode */
1322 /* set both B-channel to not connected */
1323 hfc->b_mode[0] = L1_MODE_NULL;
1324 hfc->b_mode[1] = L1_MODE_NULL;
1326 hfc->l1_activated = FALSE;
1327 hfc->disc_flag = FALSE;
1329 hfc->led_new_data = 0;
1330 hfc->old_led_state = 0;
1332 /* init the t3 timer */
1333 init_timer(&hfc->t3_timer);
1334 hfc->t3_timer.data = (long) hfc;
1335 hfc->t3_timer.function = (void *) l1_timer_expire_t3;
1337 /* init the t4 timer */
1338 init_timer(&hfc->t4_timer);
1339 hfc->t4_timer.data = (long) hfc;
1340 hfc->t4_timer.function = (void *) l1_timer_expire_t4;
1342 /* init the led timer */
1343 init_timer(&hfc->led_timer);
1344 hfc->led_timer.data = (long) hfc;
1345 hfc->led_timer.function = (void *) led_timer;
1347 /* trigger 4 hz led timer */
1348 if (!timer_pending(&hfc->led_timer)) {
1349 hfc->led_timer.expires = jiffies + (LED_TIME * HZ) / 1000;
1350 add_timer(&hfc->led_timer);
1353 /* init the background machinery for control requests */
1354 hfc->ctrl_read.bRequestType = 0xc0;
1355 hfc->ctrl_read.bRequest = 1;
1356 hfc->ctrl_read.wLength = 1;
1357 hfc->ctrl_write.bRequestType = 0x40;
1358 hfc->ctrl_write.bRequest = 0;
1359 hfc->ctrl_write.wLength = 0;
1360 usb_fill_control_urb(hfc->ctrl_urb,
1363 (u_char *) & hfc->ctrl_write,
1364 NULL, 0, ctrl_complete, hfc);
1365 /* Init All Fifos */
1366 for (i = 0; i < HFCUSB_NUM_FIFOS; i++) {
1367 hfc->fifos[i].iso[0].purb = NULL;
1368 hfc->fifos[i].iso[1].purb = NULL;
1369 hfc->fifos[i].active = 0;
1371 /* register Modul to upper Hisax Layers */
1372 hfc->d_if.owner = THIS_MODULE;
1373 hfc->d_if.ifc.priv = &hfc->fifos[HFCUSB_D_TX];
1374 hfc->d_if.ifc.l2l1 = hfc_usb_l2l1;
1375 for (i = 0; i < 2; i++) {
1376 hfc->b_if[i].ifc.priv = &hfc->fifos[HFCUSB_B1_TX + i * 2];
1377 hfc->b_if[i].ifc.l2l1 = hfc_usb_l2l1;
1378 p_b_if[i] = &hfc->b_if[i];
1380 /* default Prot: EURO ISDN, should be a module_param */
1382 hisax_register(&hfc->d_if, p_b_if, "hfc_usb", hfc->protocol);
1384 #ifdef CONFIG_HISAX_DEBUG
1388 for (i = 0; i < 4; i++)
1389 hfc->fifos[i].hif = &p_b_if[i / 2]->ifc;
1390 for (i = 4; i < 8; i++)
1391 hfc->fifos[i].hif = &hfc->d_if.ifc;
1393 /* 3 (+1) INT IN + 3 ISO OUT */
1394 if (hfc->cfg_used == CNF_3INT3ISO || hfc->cfg_used == CNF_4INT3ISO) {
1395 start_int_fifo(hfc->fifos + HFCUSB_D_RX);
1396 if (hfc->fifos[HFCUSB_PCM_RX].pipe)
1397 start_int_fifo(hfc->fifos + HFCUSB_PCM_RX);
1398 start_int_fifo(hfc->fifos + HFCUSB_B1_RX);
1399 start_int_fifo(hfc->fifos + HFCUSB_B2_RX);
1401 /* 3 (+1) ISO IN + 3 ISO OUT */
1402 if (hfc->cfg_used == CNF_3ISO3ISO || hfc->cfg_used == CNF_4ISO3ISO) {
1403 start_isoc_chain(hfc->fifos + HFCUSB_D_RX, ISOC_PACKETS_D,
1404 rx_iso_complete, 16);
1405 if (hfc->fifos[HFCUSB_PCM_RX].pipe)
1406 start_isoc_chain(hfc->fifos + HFCUSB_PCM_RX,
1407 ISOC_PACKETS_D, rx_iso_complete,
1409 start_isoc_chain(hfc->fifos + HFCUSB_B1_RX, ISOC_PACKETS_B,
1410 rx_iso_complete, 16);
1411 start_isoc_chain(hfc->fifos + HFCUSB_B2_RX, ISOC_PACKETS_B,
1412 rx_iso_complete, 16);
1415 start_isoc_chain(hfc->fifos + HFCUSB_D_TX, ISOC_PACKETS_D,
1416 tx_iso_complete, 1);
1417 start_isoc_chain(hfc->fifos + HFCUSB_B1_TX, ISOC_PACKETS_B,
1418 tx_iso_complete, 1);
1419 start_isoc_chain(hfc->fifos + HFCUSB_B2_TX, ISOC_PACKETS_B,
1420 tx_iso_complete, 1);
1422 handle_led(hfc, LED_POWER_ON);
1427 /*************************************************/
1428 /* function called to probe a new plugged device */
1429 /*************************************************/
1431 hfc_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
1433 struct usb_device *dev = interface_to_usbdev(intf);
1434 hfcusb_data *context;
1435 struct usb_host_interface *iface = intf->cur_altsetting;
1436 struct usb_host_interface *iface_used = NULL;
1437 struct usb_host_endpoint *ep;
1438 int ifnum = iface->desc.bInterfaceNumber;
1439 int i, idx, alt_idx, probe_alt_setting, vend_idx, cfg_used, *vcf,
1440 attr, cfg_found, cidx, ep_addr;
1441 int cmptbl[16], small_match, iso_packet_size, packet_size,
1445 for (i = 0; vdata[i].vendor; i++) {
1446 if (dev->descriptor.idVendor == vdata[i].vendor
1447 && dev->descriptor.idProduct == vdata[i].prod_id)
1450 #ifdef CONFIG_HISAX_DEBUG
1452 "HFC-USB: probing interface(%d) actalt(%d) minor(%d)\n", ifnum,
1453 iface->desc.bAlternateSetting, intf->minor);
1456 "HFC-S USB: probing interface(%d) actalt(%d) minor(%d)\n",
1457 ifnum, iface->desc.bAlternateSetting, intf->minor);
1459 if (vend_idx != 0xffff) {
1460 #ifdef CONFIG_HISAX_DEBUG
1461 DBG(USB_DBG, "HFC-S USB: found vendor idx:%d name:%s",
1462 vend_idx, vdata[vend_idx].vend_name);
1464 /* if vendor and product ID is OK, start probing alternate settings */
1466 small_match = 0xffff;
1468 /* default settings */
1469 iso_packet_size = 16;
1472 while (alt_idx < intf->num_altsetting) {
1473 iface = intf->altsetting + alt_idx;
1474 probe_alt_setting = iface->desc.bAlternateSetting;
1477 /* check for config EOL element */
1478 while (validconf[cfg_used][0]) {
1480 vcf = validconf[cfg_used];
1481 /* first endpoint descriptor */
1482 ep = iface->endpoint;
1483 #ifdef CONFIG_HISAX_DEBUG
1485 "HFC-S USB: (if=%d alt=%d cfg_used=%d)\n",
1486 ifnum, probe_alt_setting, cfg_used);
1488 memcpy(cmptbl, vcf, 16 * sizeof(int));
1490 /* check for all endpoints in this alternate setting */
1491 for (i = 0; i < iface->desc.bNumEndpoints;
1494 ep->desc.bEndpointAddress;
1495 /* get endpoint base */
1496 idx = ((ep_addr & 0x7f) - 1) * 2;
1499 attr = ep->desc.bmAttributes;
1500 if (cmptbl[idx] == EP_NUL) {
1503 if (attr == USB_ENDPOINT_XFER_INT
1504 && cmptbl[idx] == EP_INT)
1505 cmptbl[idx] = EP_NUL;
1506 if (attr == USB_ENDPOINT_XFER_BULK
1507 && cmptbl[idx] == EP_BLK)
1508 cmptbl[idx] = EP_NUL;
1509 if (attr == USB_ENDPOINT_XFER_ISOC
1510 && cmptbl[idx] == EP_ISO)
1511 cmptbl[idx] = EP_NUL;
1513 /* check if all INT endpoints match minimum interval */
1514 if (attr == USB_ENDPOINT_XFER_INT
1515 && ep->desc.bInterval <
1517 #ifdef CONFIG_HISAX_DEBUG
1520 "HFC-S USB: Interrupt Endpoint interval < %d found - skipping config",
1527 for (i = 0; i < 16; i++) {
1528 /* all entries must be EP_NOP or EP_NUL for a valid config */
1529 if (cmptbl[i] != EP_NOP
1530 && cmptbl[i] != EP_NUL)
1534 if (cfg_used < small_match) {
1535 small_match = cfg_used;
1540 #ifdef CONFIG_HISAX_DEBUG
1542 "HFC-USB: small_match=%x %x\n",
1543 small_match, alt_used);
1549 } /* (alt_idx < intf->num_altsetting) */
1551 /* found a valid USB Ta Endpint config */
1552 if (small_match != 0xffff) {
1556 kmalloc(sizeof(hfcusb_data), GFP_KERNEL)))
1557 return (-ENOMEM); /* got no mem */
1558 memset(context, 0, sizeof(hfcusb_data));
1560 ep = iface->endpoint;
1561 vcf = validconf[small_match];
1563 for (i = 0; i < iface->desc.bNumEndpoints; i++) {
1564 ep_addr = ep->desc.bEndpointAddress;
1565 /* get endpoint base */
1566 idx = ((ep_addr & 0x7f) - 1) * 2;
1570 attr = ep->desc.bmAttributes;
1572 /* init Endpoints */
1573 if (vcf[idx] != EP_NOP
1574 && vcf[idx] != EP_NUL) {
1576 case USB_ENDPOINT_XFER_INT:
1592 case USB_ENDPOINT_XFER_BULK:
1621 case USB_ENDPOINT_XFER_ISOC:
1654 } /* switch attribute */
1656 if (context->fifos[cidx].pipe) {
1657 context->fifos[cidx].
1659 context->fifos[cidx].hfc =
1661 context->fifos[cidx].
1665 context->fifos[cidx].
1668 context->fifos[cidx].
1674 context->dev = dev; /* save device */
1675 context->if_used = ifnum; /* save used interface */
1676 context->alt_used = alt_used; /* and alternate config */
1677 context->ctrl_paksize = dev->descriptor.bMaxPacketSize0; /* control size */
1678 context->cfg_used = vcf[16]; /* store used config */
1679 context->vend_idx = vend_idx; /* store found vendor */
1680 context->packet_size = packet_size;
1681 context->iso_packet_size = iso_packet_size;
1683 /* create the control pipes needed for register access */
1684 context->ctrl_in_pipe =
1685 usb_rcvctrlpipe(context->dev, 0);
1686 context->ctrl_out_pipe =
1687 usb_sndctrlpipe(context->dev, 0);
1688 context->ctrl_urb = usb_alloc_urb(0, GFP_KERNEL);
1691 "HFC-S USB: detected \"%s\"\n",
1692 vdata[vend_idx].vend_name);
1693 #ifdef CONFIG_HISAX_DEBUG
1695 "HFC-S USB: Endpoint-Config: %s (if=%d alt=%d)\n",
1696 conf_str[small_match], context->if_used,
1699 "HFC-S USB: E-channel (\"ECHO:\") logging ");
1700 if (validconf[small_match][18])
1701 printk(" possible\n");
1703 printk("NOT possible\n");
1705 /* init the chip and register the driver */
1706 if (usb_init(context)) {
1707 if (context->ctrl_urb) {
1708 usb_unlink_urb(context->ctrl_urb);
1709 usb_free_urb(context->ctrl_urb);
1710 context->ctrl_urb = NULL;
1715 usb_set_intfdata(intf, context);
1720 "HFC-S USB: no valid vendor found in USB descriptor\n");
1725 /****************************************************/
1726 /* function called when an active device is removed */
1727 /****************************************************/
1729 hfc_usb_disconnect(struct usb_interface
1732 hfcusb_data *context = usb_get_intfdata(intf);
1734 printk(KERN_INFO "HFC-S USB: device disconnect\n");
1735 context->disc_flag = TRUE;
1736 usb_set_intfdata(intf, NULL);
1739 if (timer_pending(&context->t3_timer))
1740 del_timer(&context->t3_timer);
1741 if (timer_pending(&context->t4_timer))
1742 del_timer(&context->t4_timer);
1743 if (timer_pending(&context->led_timer))
1744 del_timer(&context->led_timer);
1745 /* tell all fifos to terminate */
1746 for (i = 0; i < HFCUSB_NUM_FIFOS; i++) {
1747 if (context->fifos[i].usb_transfer_mode == USB_ISOC) {
1748 if (context->fifos[i].active > 0) {
1749 stop_isoc_chain(&context->fifos[i]);
1750 #ifdef CONFIG_HISAX_DEBUG
1752 "HFC-S USB: hfc_usb_disconnect: stopping ISOC chain Fifo no %i",
1757 if (context->fifos[i].active > 0) {
1758 context->fifos[i].active = 0;
1759 #ifdef CONFIG_HISAX_DEBUG
1761 "HFC-S USB: hfc_usb_disconnect: unlinking URB for Fifo no %i",
1765 if (context->fifos[i].urb) {
1766 usb_unlink_urb(context->fifos[i].urb);
1767 usb_free_urb(context->fifos[i].urb);
1768 context->fifos[i].urb = NULL;
1771 context->fifos[i].active = 0;
1773 /* wait for all URBS to terminate */
1775 if (context->ctrl_urb) {
1776 usb_unlink_urb(context->ctrl_urb);
1777 usb_free_urb(context->ctrl_urb);
1778 context->ctrl_urb = NULL;
1780 hisax_unregister(&context->d_if);
1781 kfree(context); /* free our structure again */
1782 } /* hfc_usb_disconnect */
1784 /************************************/
1785 /* our driver information structure */
1786 /************************************/
1787 static struct usb_driver hfc_drv = {
1788 .owner = THIS_MODULE,.name =
1789 "hfc_usb",.id_table = hfc_usb_idtab,.probe =
1790 hfc_usb_probe,.disconnect = hfc_usb_disconnect,
1795 #ifdef CONFIG_HISAX_DEBUG
1796 DBG(USB_DBG, "HFC-S USB: calling \"hfc_usb_exit\" ...");
1798 usb_deregister(&hfc_drv); /* release our driver */
1799 printk(KERN_INFO "HFC-S USB: module removed\n");
1805 #ifndef CONFIG_HISAX_DEBUG
1806 unsigned int debug = -1;
1808 char revstr[30], datestr[30], dummy[30];
1809 sscanf(hfcusb_revision,
1810 "%s %s $ %s %s %s $ ", dummy, revstr,
1811 dummy, datestr, dummy);
1813 "HFC-S USB: driver module revision %s date %s loaded, (debug=%i)\n",
1814 revstr, datestr, debug);
1815 if (usb_register(&hfc_drv)) {
1817 "HFC-S USB: Unable to register HFC-S USB module at usb stack\n");
1818 return (-1); /* unable to register */
1823 module_init(hfc_usb_init);
1824 module_exit(hfc_usb_exit);
1825 MODULE_AUTHOR(DRIVER_AUTHOR);
1826 MODULE_DESCRIPTION(DRIVER_DESC);
1827 MODULE_LICENSE("GPL");
1828 MODULE_DEVICE_TABLE(usb, hfc_usb_idtab);