4 * $Id: hfc_usb.c,v 2.3.2.13 2006/02/17 17:17:22 mbachem 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/init.h>
36 #include <linux/module.h>
37 #include <linux/kernel_stat.h>
38 #include <linux/usb.h>
39 #include <linux/kernel.h>
44 static const char *hfcusb_revision
=
45 "$Revision: 2.3.2.13 $ $Date: 2006/02/17 17:17:22 $ ";
47 /* Hisax debug support
48 * use "modprobe debug=x" where x is bitfield of USB_DBG & ISDN_DBG
50 #ifdef CONFIG_HISAX_DEBUG
51 #include <linux/moduleparam.h>
52 #define __debug_variable hfc_debug
53 #include "hisax_debug.h"
55 module_param(debug
, uint
, 0);
59 /* private vendor specific data */
61 __u8 led_scheme
; // led display scheme
62 signed short led_bits
[8]; // array of 8 possible LED bitmask settings
63 char *vend_name
; // device name
66 /****************************************/
67 /* data defining the devices to be used */
68 /****************************************/
69 static struct usb_device_id hfcusb_idtab
[] = {
71 USB_DEVICE(0x0959, 0x2bd0),
72 .driver_info
= (unsigned long) &((hfcsusb_vdata
)
73 {LED_OFF
, {4, 0, 2, 1},
74 "ISDN USB TA (Cologne Chip HFC-S USB based)"}),
77 USB_DEVICE(0x0675, 0x1688),
78 .driver_info
= (unsigned long) &((hfcsusb_vdata
)
79 {LED_SCHEME1
, {1, 2, 0, 0},
80 "DrayTek miniVigor 128 USB ISDN TA"}),
83 USB_DEVICE(0x07b0, 0x0007),
84 .driver_info
= (unsigned long) &((hfcsusb_vdata
)
85 {LED_SCHEME1
, {0x80, -64, -32, -16},
86 "Billion tiny USB ISDN TA 128"}),
89 USB_DEVICE(0x0742, 0x2008),
90 .driver_info
= (unsigned long) &((hfcsusb_vdata
)
91 {LED_SCHEME1
, {4, 0, 2, 1},
95 USB_DEVICE(0x0742, 0x2009),
96 .driver_info
= (unsigned long) &((hfcsusb_vdata
)
97 {LED_SCHEME1
, {4, 0, 2, 1},
98 "Aceex USB ISDN TA"}),
101 USB_DEVICE(0x0742, 0x200A),
102 .driver_info
= (unsigned long) &((hfcsusb_vdata
)
103 {LED_SCHEME1
, {4, 0, 2, 1},
107 USB_DEVICE(0x08e3, 0x0301),
108 .driver_info
= (unsigned long) &((hfcsusb_vdata
)
109 {LED_SCHEME1
, {2, 0, 1, 4},
113 USB_DEVICE(0x07fa, 0x0846),
114 .driver_info
= (unsigned long) &((hfcsusb_vdata
)
115 {LED_SCHEME1
, {0x80, -64, -32, -16},
116 "Bewan Modem RNIS USB"}),
119 USB_DEVICE(0x07fa, 0x0847),
120 .driver_info
= (unsigned long) &((hfcsusb_vdata
)
121 {LED_SCHEME1
, {0x80, -64, -32, -16},
122 "Djinn Numeris USB"}),
125 USB_DEVICE(0x07b0, 0x0006),
126 .driver_info
= (unsigned long) &((hfcsusb_vdata
)
127 {LED_SCHEME1
, {0x80, -64, -32, -16},
133 /***************************************************************/
134 /* structure defining input+output fifos (interrupt/bulk mode) */
135 /***************************************************************/
136 struct usb_fifo
; /* forward definition */
137 typedef struct iso_urb_struct
{
139 __u8 buffer
[ISO_BUFFER_SIZE
]; /* buffer incoming/outgoing data */
140 struct usb_fifo
*owner_fifo
; /* pointer to owner fifo */
144 struct hfcusb_data
; /* forward definition */
145 typedef struct usb_fifo
{
146 int fifonum
; /* fifo index attached to this structure */
147 int active
; /* fifo is currently active */
148 struct hfcusb_data
*hfc
; /* pointer to main structure */
149 int pipe
; /* address of endpoint */
150 __u8 usb_packet_maxlen
; /* maximum length for usb transfer */
151 unsigned int max_size
; /* maximum size of receive/send packet */
152 __u8 intervall
; /* interrupt interval */
153 struct sk_buff
*skbuff
; /* actual used buffer */
154 struct urb
*urb
; /* transfer structure for usb routines */
155 __u8 buffer
[128]; /* buffer incoming/outgoing data */
156 int bit_line
; /* how much bits are in the fifo? */
158 volatile __u8 usb_transfer_mode
; /* switched between ISO and INT */
159 iso_urb_struct iso
[2]; /* need two urbs to have one always for pending */
160 struct hisax_if
*hif
; /* hisax interface */
161 int delete_flg
; /* only delete skbuff once */
162 int last_urblen
; /* remember length of last packet */
166 /*********************************************/
167 /* structure holding all data for one device */
168 /*********************************************/
169 typedef struct hfcusb_data
{
170 /* HiSax Interface for loadable Layer1 drivers */
171 struct hisax_d_if d_if
; /* see hisax_if.h */
172 struct hisax_b_if b_if
[2]; /* see hisax_if.h */
175 struct usb_device
*dev
; /* our device */
176 int if_used
; /* used interface number */
177 int alt_used
; /* used alternate config */
178 int ctrl_paksize
; /* control pipe packet size */
179 int ctrl_in_pipe
, ctrl_out_pipe
; /* handles for control pipe */
180 int cfg_used
; /* configuration index used */
181 int vend_idx
; /* vendor found */
182 int b_mode
[2]; /* B-channel mode */
183 int l1_activated
; /* layer 1 activated */
184 int disc_flag
; /* 'true' if device was disonnected to avoid some USB actions */
185 int packet_size
, iso_packet_size
;
187 /* control pipe background handling */
188 ctrl_buft ctrl_buff
[HFC_CTRL_BUFSIZE
]; /* buffer holding queued data */
189 volatile int ctrl_in_idx
, ctrl_out_idx
, ctrl_cnt
; /* input/output pointer + count */
190 struct urb
*ctrl_urb
; /* transfer structure for control channel */
192 struct usb_ctrlrequest ctrl_write
; /* buffer for control write request */
193 struct usb_ctrlrequest ctrl_read
; /* same for read request */
195 __u8 old_led_state
, led_state
, led_new_data
, led_b_active
;
197 volatile __u8 threshold_mask
; /* threshold actually reported */
198 volatile __u8 bch_enables
; /* or mask for sctrl_r and sctrl register values */
200 usb_fifo fifos
[HFCUSB_NUM_FIFOS
]; /* structure holding all fifo data */
202 volatile __u8 l1_state
; /* actual l1 state */
203 struct timer_list t3_timer
; /* timer 3 for activation/deactivation */
204 struct timer_list t4_timer
; /* timer 4 for activation/deactivation */
208 static void collect_rx_frame(usb_fifo
* fifo
, __u8
* data
, int len
,
212 static inline const char *
213 symbolic(struct hfcusb_symbolic_list list
[], const int num
)
216 for (i
= 0; list
[i
].name
!= NULL
; i
++)
217 if (list
[i
].num
== num
)
218 return (list
[i
].name
);
219 return "<unknown ERROR>";
223 /******************************************************/
224 /* start next background transfer for control channel */
225 /******************************************************/
227 ctrl_start_transfer(hfcusb_data
* hfc
)
230 hfc
->ctrl_urb
->pipe
= hfc
->ctrl_out_pipe
;
231 hfc
->ctrl_urb
->setup_packet
= (u_char
*) & hfc
->ctrl_write
;
232 hfc
->ctrl_urb
->transfer_buffer
= NULL
;
233 hfc
->ctrl_urb
->transfer_buffer_length
= 0;
234 hfc
->ctrl_write
.wIndex
=
235 cpu_to_le16(hfc
->ctrl_buff
[hfc
->ctrl_out_idx
].hfc_reg
);
236 hfc
->ctrl_write
.wValue
=
237 cpu_to_le16(hfc
->ctrl_buff
[hfc
->ctrl_out_idx
].reg_val
);
239 usb_submit_urb(hfc
->ctrl_urb
, GFP_ATOMIC
); /* start transfer */
241 } /* ctrl_start_transfer */
243 /************************************/
244 /* queue a control transfer request */
245 /* return 0 on success. */
246 /************************************/
248 queue_control_request(hfcusb_data
* hfc
, __u8 reg
, __u8 val
, int action
)
252 if (hfc
->ctrl_cnt
>= HFC_CTRL_BUFSIZE
)
253 return (1); /* no space left */
254 buf
= &hfc
->ctrl_buff
[hfc
->ctrl_in_idx
]; /* pointer to new index */
257 buf
->action
= action
;
258 if (++hfc
->ctrl_in_idx
>= HFC_CTRL_BUFSIZE
)
259 hfc
->ctrl_in_idx
= 0; /* pointer wrap */
260 if (++hfc
->ctrl_cnt
== 1)
261 ctrl_start_transfer(hfc
);
263 } /* queue_control_request */
266 control_action_handler(hfcusb_data
* hfc
, int reg
, int val
, int action
)
269 return (1); /* no action defined */
273 /***************************************************************/
274 /* control completion routine handling background control cmds */
275 /***************************************************************/
277 ctrl_complete(struct urb
*urb
)
279 hfcusb_data
*hfc
= (hfcusb_data
*) urb
->context
;
284 buf
= &hfc
->ctrl_buff
[hfc
->ctrl_out_idx
];
285 control_action_handler(hfc
, buf
->hfc_reg
, buf
->reg_val
,
288 hfc
->ctrl_cnt
--; /* decrement actual count */
289 if (++hfc
->ctrl_out_idx
>= HFC_CTRL_BUFSIZE
)
290 hfc
->ctrl_out_idx
= 0; /* pointer wrap */
292 ctrl_start_transfer(hfc
); /* start next transfer */
294 } /* ctrl_complete */
296 /***************************************************/
297 /* write led data to auxport & invert if necessary */
298 /***************************************************/
300 write_led(hfcusb_data
* hfc
, __u8 led_state
)
302 if (led_state
!= hfc
->old_led_state
) {
303 hfc
->old_led_state
= led_state
;
304 queue_control_request(hfc
, HFCUSB_P_DATA
, led_state
, 1);
308 /**************************/
309 /* handle LED bits */
310 /**************************/
312 set_led_bit(hfcusb_data
* hfc
, signed short led_bits
, int unset
)
316 hfc
->led_state
|= abs(led_bits
);
318 hfc
->led_state
&= ~led_bits
;
321 hfc
->led_state
&= ~abs(led_bits
);
323 hfc
->led_state
|= led_bits
;
327 /**************************/
328 /* handle LED requests */
329 /**************************/
331 handle_led(hfcusb_data
* hfc
, int event
)
333 hfcsusb_vdata
*driver_info
=
334 (hfcsusb_vdata
*) hfcusb_idtab
[hfc
->vend_idx
].driver_info
;
336 /* if no scheme -> no LED action */
337 if (driver_info
->led_scheme
== LED_OFF
)
342 set_led_bit(hfc
, driver_info
->led_bits
[0],
344 set_led_bit(hfc
, driver_info
->led_bits
[1],
346 set_led_bit(hfc
, driver_info
->led_bits
[2],
348 set_led_bit(hfc
, driver_info
->led_bits
[3],
351 case LED_POWER_OFF
: /* no Power off handling */
354 set_led_bit(hfc
, driver_info
->led_bits
[1],
358 set_led_bit(hfc
, driver_info
->led_bits
[1],
362 set_led_bit(hfc
, driver_info
->led_bits
[2],
366 set_led_bit(hfc
, driver_info
->led_bits
[2],
370 set_led_bit(hfc
, driver_info
->led_bits
[3],
374 set_led_bit(hfc
, driver_info
->led_bits
[3],
378 write_led(hfc
, hfc
->led_state
);
381 /********************************/
382 /* called when timer t3 expires */
383 /********************************/
385 l1_timer_expire_t3(hfcusb_data
* hfc
)
387 hfc
->d_if
.ifc
.l1l2(&hfc
->d_if
.ifc
, PH_DEACTIVATE
| INDICATION
,
389 #ifdef CONFIG_HISAX_DEBUG
391 "HFC-S USB: PH_DEACTIVATE | INDICATION sent (T3 expire)");
393 hfc
->l1_activated
= false;
394 handle_led(hfc
, LED_S0_OFF
);
396 queue_control_request(hfc
, HFCUSB_STATES
, 0x10, 1);
397 queue_control_request(hfc
, HFCUSB_STATES
, 3, 1);
400 /********************************/
401 /* called when timer t4 expires */
402 /********************************/
404 l1_timer_expire_t4(hfcusb_data
* hfc
)
406 hfc
->d_if
.ifc
.l1l2(&hfc
->d_if
.ifc
, PH_DEACTIVATE
| INDICATION
,
408 #ifdef CONFIG_HISAX_DEBUG
410 "HFC-S USB: PH_DEACTIVATE | INDICATION sent (T4 expire)");
412 hfc
->l1_activated
= false;
413 handle_led(hfc
, LED_S0_OFF
);
416 /*****************************/
417 /* handle S0 state changes */
418 /*****************************/
420 state_handler(hfcusb_data
* hfc
, __u8 state
)
424 old_state
= hfc
->l1_state
;
425 if (state
== old_state
|| state
< 1 || state
> 8)
428 #ifdef CONFIG_HISAX_DEBUG
429 DBG(ISDN_DBG
, "HFC-S USB: new S0 state:%d old_state:%d", state
,
432 if (state
< 4 || state
== 7 || state
== 8) {
433 if (timer_pending(&hfc
->t3_timer
))
434 del_timer(&hfc
->t3_timer
);
435 #ifdef CONFIG_HISAX_DEBUG
436 DBG(ISDN_DBG
, "HFC-S USB: T3 deactivated");
440 if (timer_pending(&hfc
->t4_timer
))
441 del_timer(&hfc
->t4_timer
);
442 #ifdef CONFIG_HISAX_DEBUG
443 DBG(ISDN_DBG
, "HFC-S USB: T4 deactivated");
447 if (state
== 7 && !hfc
->l1_activated
) {
448 hfc
->d_if
.ifc
.l1l2(&hfc
->d_if
.ifc
,
449 PH_ACTIVATE
| INDICATION
, NULL
);
450 #ifdef CONFIG_HISAX_DEBUG
451 DBG(ISDN_DBG
, "HFC-S USB: PH_ACTIVATE | INDICATION sent");
453 hfc
->l1_activated
= true;
454 handle_led(hfc
, LED_S0_ON
);
455 } else if (state
<= 3 /* && activated */ ) {
456 if (old_state
== 7 || old_state
== 8) {
457 #ifdef CONFIG_HISAX_DEBUG
458 DBG(ISDN_DBG
, "HFC-S USB: T4 activated");
460 if (!timer_pending(&hfc
->t4_timer
)) {
461 hfc
->t4_timer
.expires
=
462 jiffies
+ (HFC_TIMER_T4
* HZ
) / 1000;
463 add_timer(&hfc
->t4_timer
);
466 hfc
->d_if
.ifc
.l1l2(&hfc
->d_if
.ifc
,
467 PH_DEACTIVATE
| INDICATION
,
469 #ifdef CONFIG_HISAX_DEBUG
471 "HFC-S USB: PH_DEACTIVATE | INDICATION sent");
473 hfc
->l1_activated
= false;
474 handle_led(hfc
, LED_S0_OFF
);
477 hfc
->l1_state
= state
;
480 /* prepare iso urb */
482 fill_isoc_urb(struct urb
*urb
, struct usb_device
*dev
, unsigned int pipe
,
483 void *buf
, int num_packets
, int packet_size
, int interval
,
484 usb_complete_t complete
, void *context
)
488 spin_lock_init(&urb
->lock
);
491 urb
->complete
= complete
;
492 urb
->number_of_packets
= num_packets
;
493 urb
->transfer_buffer_length
= packet_size
* num_packets
;
494 urb
->context
= context
;
495 urb
->transfer_buffer
= buf
;
496 urb
->transfer_flags
= URB_ISO_ASAP
;
497 urb
->actual_length
= 0;
498 urb
->interval
= interval
;
499 for (k
= 0; k
< num_packets
; k
++) {
500 urb
->iso_frame_desc
[k
].offset
= packet_size
* k
;
501 urb
->iso_frame_desc
[k
].length
= packet_size
;
502 urb
->iso_frame_desc
[k
].actual_length
= 0;
506 /* allocs urbs and start isoc transfer with two pending urbs to avoid
507 gaps in the transfer chain */
509 start_isoc_chain(usb_fifo
* fifo
, int num_packets_per_urb
,
510 usb_complete_t complete
, int packet_size
)
514 printk(KERN_INFO
"HFC-S USB: starting ISO-chain for Fifo %i\n",
517 /* allocate Memory for Iso out Urbs */
518 for (i
= 0; i
< 2; i
++) {
519 if (!(fifo
->iso
[i
].purb
)) {
521 usb_alloc_urb(num_packets_per_urb
, GFP_KERNEL
);
522 if (!(fifo
->iso
[i
].purb
)) {
524 "alloc urb for fifo %i failed!!!",
527 fifo
->iso
[i
].owner_fifo
= (struct usb_fifo
*) fifo
;
529 /* Init the first iso */
530 if (ISO_BUFFER_SIZE
>=
531 (fifo
->usb_packet_maxlen
*
532 num_packets_per_urb
)) {
533 fill_isoc_urb(fifo
->iso
[i
].purb
,
534 fifo
->hfc
->dev
, fifo
->pipe
,
537 fifo
->usb_packet_maxlen
,
538 fifo
->intervall
, complete
,
540 memset(fifo
->iso
[i
].buffer
, 0,
541 sizeof(fifo
->iso
[i
].buffer
));
542 /* defining packet delimeters in fifo->buffer */
543 for (k
= 0; k
< num_packets_per_urb
; k
++) {
545 iso_frame_desc
[k
].offset
=
548 iso_frame_desc
[k
].length
=
553 "HFC-S USB: ISO Buffer size to small!\n");
556 fifo
->bit_line
= BITLINE_INF
;
558 errcode
= usb_submit_urb(fifo
->iso
[i
].purb
, GFP_KERNEL
);
559 fifo
->active
= (errcode
>= 0) ? 1 : 0;
561 printk(KERN_INFO
"HFC-S USB: %s URB nr:%d\n",
562 symbolic(urb_errlist
, errcode
), i
);
565 return (fifo
->active
);
568 /* stops running iso chain and frees their pending urbs */
570 stop_isoc_chain(usb_fifo
* fifo
)
574 for (i
= 0; i
< 2; i
++) {
575 if (fifo
->iso
[i
].purb
) {
576 #ifdef CONFIG_HISAX_DEBUG
578 "HFC-S USB: Stopping iso chain for fifo %i.%i",
581 usb_unlink_urb(fifo
->iso
[i
].purb
);
582 usb_free_urb(fifo
->iso
[i
].purb
);
583 fifo
->iso
[i
].purb
= NULL
;
587 usb_unlink_urb(fifo
->urb
);
588 usb_free_urb(fifo
->urb
);
594 /* defines how much ISO packets are handled in one URB */
595 static int iso_packets
[8] =
596 { ISOC_PACKETS_B
, ISOC_PACKETS_B
, ISOC_PACKETS_B
, ISOC_PACKETS_B
,
597 ISOC_PACKETS_D
, ISOC_PACKETS_D
, ISOC_PACKETS_D
, ISOC_PACKETS_D
600 /*****************************************************/
601 /* transmit completion routine for all ISO tx fifos */
602 /*****************************************************/
604 tx_iso_complete(struct urb
*urb
)
606 iso_urb_struct
*context_iso_urb
= (iso_urb_struct
*) urb
->context
;
607 usb_fifo
*fifo
= context_iso_urb
->owner_fifo
;
608 hfcusb_data
*hfc
= fifo
->hfc
;
609 int k
, tx_offset
, num_isoc_packets
, sink
, len
, current_len
,
611 int frame_complete
, transp_mode
, fifon
, status
;
613 __u8 threshtable
[8] = { 1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80 };
615 fifon
= fifo
->fifonum
;
616 status
= urb
->status
;
620 if (fifo
->active
&& !status
) {
622 if (fifon
< 4 && hfc
->b_mode
[fifon
/ 2] == L1_MODE_TRANS
)
625 /* is FifoFull-threshold set for our channel? */
626 threshbit
= threshtable
[fifon
] & hfc
->threshold_mask
;
627 num_isoc_packets
= iso_packets
[fifon
];
629 /* predict dataflow to avoid fifo overflow */
630 if (fifon
>= HFCUSB_D_TX
) {
631 sink
= (threshbit
) ? SINK_DMIN
: SINK_DMAX
;
633 sink
= (threshbit
) ? SINK_MIN
: SINK_MAX
;
635 fill_isoc_urb(urb
, fifo
->hfc
->dev
, fifo
->pipe
,
636 context_iso_urb
->buffer
, num_isoc_packets
,
637 fifo
->usb_packet_maxlen
, fifo
->intervall
,
638 tx_iso_complete
, urb
->context
);
639 memset(context_iso_urb
->buffer
, 0,
640 sizeof(context_iso_urb
->buffer
));
641 frame_complete
= false;
642 /* Generate next Iso Packets */
643 for (k
= 0; k
< num_isoc_packets
; ++k
) {
645 len
= fifo
->skbuff
->len
;
646 /* we lower data margin every msec */
647 fifo
->bit_line
-= sink
;
648 current_len
= (0 - fifo
->bit_line
) / 8;
649 /* maximum 15 byte for every ISO packet makes our life easier */
650 if (current_len
> 14)
654 current_len
) ? len
: current_len
;
655 /* how much bit do we put on the line? */
656 fifo
->bit_line
+= current_len
* 8;
658 context_iso_urb
->buffer
[tx_offset
] = 0;
659 if (current_len
== len
) {
661 /* here frame completion */
663 buffer
[tx_offset
] = 1;
664 /* add 2 byte flags and 16bit CRC at end of ISDN frame */
665 fifo
->bit_line
+= 32;
667 frame_complete
= true;
670 memcpy(context_iso_urb
->buffer
+
671 tx_offset
+ 1, fifo
->skbuff
->data
,
673 skb_pull(fifo
->skbuff
, current_len
);
675 /* define packet delimeters within the URB buffer */
676 urb
->iso_frame_desc
[k
].offset
= tx_offset
;
677 urb
->iso_frame_desc
[k
].length
=
680 tx_offset
+= (current_len
+ 1);
682 urb
->iso_frame_desc
[k
].offset
=
685 urb
->iso_frame_desc
[k
].length
= 1;
686 fifo
->bit_line
-= sink
; /* we lower data margin every msec */
688 if (fifo
->bit_line
< BITLINE_INF
) {
689 fifo
->bit_line
= BITLINE_INF
;
693 if (frame_complete
) {
694 fifo
->delete_flg
= true;
695 fifo
->hif
->l1l2(fifo
->hif
,
697 (void *) (unsigned long) fifo
->skbuff
->
699 if (fifo
->skbuff
&& fifo
->delete_flg
) {
700 dev_kfree_skb_any(fifo
->skbuff
);
702 fifo
->delete_flg
= false;
704 frame_complete
= false;
707 errcode
= usb_submit_urb(urb
, GFP_ATOMIC
);
710 "HFC-S USB: error submitting ISO URB: %d \n",
714 if (status
&& !hfc
->disc_flag
) {
716 "HFC-S USB: tx_iso_complete : urb->status %s (%i), fifonum=%d\n",
717 symbolic(urb_errlist
, status
), status
,
721 } /* tx_iso_complete */
723 /*****************************************************/
724 /* receive completion routine for all ISO tx fifos */
725 /*****************************************************/
727 rx_iso_complete(struct urb
*urb
)
729 iso_urb_struct
*context_iso_urb
= (iso_urb_struct
*) urb
->context
;
730 usb_fifo
*fifo
= context_iso_urb
->owner_fifo
;
731 hfcusb_data
*hfc
= fifo
->hfc
;
732 int k
, len
, errcode
, offset
, num_isoc_packets
, fifon
, maxlen
,
734 unsigned int iso_status
;
737 #ifdef CONFIG_HISAX_DEBUG
741 fifon
= fifo
->fifonum
;
742 status
= urb
->status
;
744 if (urb
->status
== -EOVERFLOW
) {
745 #ifdef CONFIG_HISAX_DEBUG
747 "HFC-USB: ignoring USB DATAOVERRUN for fifo %i \n",
752 if (fifo
->active
&& !status
) {
753 num_isoc_packets
= iso_packets
[fifon
];
754 maxlen
= fifo
->usb_packet_maxlen
;
755 for (k
= 0; k
< num_isoc_packets
; ++k
) {
756 len
= urb
->iso_frame_desc
[k
].actual_length
;
757 offset
= urb
->iso_frame_desc
[k
].offset
;
758 buf
= context_iso_urb
->buffer
+ offset
;
759 iso_status
= urb
->iso_frame_desc
[k
].status
;
760 #ifdef CONFIG_HISAX_DEBUG
761 if (iso_status
&& !hfc
->disc_flag
)
763 "HFC-S USB: ISO packet failure - status:%x",
766 if ((fifon
== 5) && (debug
> 1)) {
768 "HFC-S USB: ISO-D-RX lst_urblen:%2d "
769 "act_urblen:%2d max-urblen:%2d "
771 fifo
->last_urblen
, len
, maxlen
,
773 for (i
= 0; i
< len
; i
++)
774 printk("%.2x ", buf
[i
]);
778 if (fifo
->last_urblen
!= maxlen
) {
779 /* the threshold mask is in the 2nd status byte */
780 hfc
->threshold_mask
= buf
[1];
781 /* care for L1 state only for D-Channel
782 to avoid overlapped iso completions */
784 /* the S0 state is in the upper half
785 of the 1st status byte */
786 state_handler(hfc
, buf
[0] >> 4);
788 eof
[fifon
] = buf
[0] & 1;
790 collect_rx_frame(fifo
, buf
+ 2,
796 collect_rx_frame(fifo
, buf
, len
,
798 maxlen
) ? eof
[fifon
] :
801 fifo
->last_urblen
= len
;
804 fill_isoc_urb(urb
, fifo
->hfc
->dev
, fifo
->pipe
,
805 context_iso_urb
->buffer
, num_isoc_packets
,
806 fifo
->usb_packet_maxlen
, fifo
->intervall
,
807 rx_iso_complete
, urb
->context
);
808 errcode
= usb_submit_urb(urb
, GFP_ATOMIC
);
811 "HFC-S USB: error submitting ISO URB: %d \n",
815 if (status
&& !hfc
->disc_flag
) {
817 "HFC-S USB: rx_iso_complete : "
818 "urb->status %d, fifonum %d\n",
822 } /* rx_iso_complete */
824 /*****************************************************/
825 /* collect data from interrupt or isochron in */
826 /*****************************************************/
828 collect_rx_frame(usb_fifo
* fifo
, __u8
* data
, int len
, int finish
)
830 hfcusb_data
*hfc
= fifo
->hfc
;
831 int transp_mode
, fifon
;
832 #ifdef CONFIG_HISAX_DEBUG
835 fifon
= fifo
->fifonum
;
837 if (fifon
< 4 && hfc
->b_mode
[fifon
/ 2] == L1_MODE_TRANS
)
841 fifo
->skbuff
= dev_alloc_skb(fifo
->max_size
+ 3);
844 "HFC-S USB: cannot allocate buffer (dev_alloc_skb) fifo:%d\n",
850 if (fifo
->skbuff
->len
+ len
< fifo
->max_size
) {
851 memcpy(skb_put(fifo
->skbuff
, len
), data
, len
);
853 #ifdef CONFIG_HISAX_DEBUG
854 printk(KERN_INFO
"HFC-S USB: ");
855 for (i
= 0; i
< 15; i
++)
857 fifo
->skbuff
->data
[fifo
->skbuff
->
862 "HCF-USB: got frame exceeded fifo->max_size:%d on fifo:%d\n",
863 fifo
->max_size
, fifon
);
866 if (transp_mode
&& fifo
->skbuff
->len
>= 128) {
867 fifo
->hif
->l1l2(fifo
->hif
, PH_DATA
| INDICATION
,
872 /* we have a complete hdlc packet */
874 if ((!fifo
->skbuff
->data
[fifo
->skbuff
->len
- 1])
875 && (fifo
->skbuff
->len
> 3)) {
876 /* remove CRC & status */
877 skb_trim(fifo
->skbuff
, fifo
->skbuff
->len
- 3);
878 if (fifon
== HFCUSB_PCM_RX
) {
879 fifo
->hif
->l1l2(fifo
->hif
,
880 PH_DATA_E
| INDICATION
,
883 fifo
->hif
->l1l2(fifo
->hif
,
884 PH_DATA
| INDICATION
,
886 fifo
->skbuff
= NULL
; /* buffer was freed from upper layer */
888 if (fifo
->skbuff
->len
> 3) {
890 "HFC-S USB: got frame %d bytes but CRC ERROR on fifo:%d!!!\n",
891 fifo
->skbuff
->len
, fifon
);
892 #ifdef CONFIG_HISAX_DEBUG
894 printk(KERN_INFO
"HFC-S USB: ");
895 for (i
= 0; i
< 15; i
++)
904 #ifdef CONFIG_HISAX_DEBUG
907 "HFC-S USB: frame to small (%d bytes)!!!\n",
911 skb_trim(fifo
->skbuff
, 0);
916 /***********************************************/
917 /* receive completion routine for all rx fifos */
918 /***********************************************/
920 rx_complete(struct urb
*urb
)
924 __u8
*buf
, maxlen
, fifon
;
925 usb_fifo
*fifo
= (usb_fifo
*) urb
->context
;
926 hfcusb_data
*hfc
= fifo
->hfc
;
928 #ifdef CONFIG_HISAX_DEBUG
932 urb
->dev
= hfc
->dev
; /* security init */
934 fifon
= fifo
->fifonum
;
935 if ((!fifo
->active
) || (urb
->status
)) {
936 #ifdef CONFIG_HISAX_DEBUG
937 DBG(USB_DBG
, "HFC-S USB: RX-Fifo %i is going down (%i)",
940 fifo
->urb
->interval
= 0; /* cancel automatic rescheduling */
942 dev_kfree_skb_any(fifo
->skbuff
);
947 len
= urb
->actual_length
;
949 maxlen
= fifo
->usb_packet_maxlen
;
951 #ifdef CONFIG_HISAX_DEBUG
952 if ((fifon
== 5) && (debug
> 1)) {
954 "HFC-S USB: INT-D-RX lst_urblen:%2d act_urblen:%2d max-urblen:%2d EOF:0x%0x DATA: ",
955 fifo
->last_urblen
, len
, maxlen
, eof
[5]);
956 for (i
= 0; i
< len
; i
++)
957 printk("%.2x ", buf
[i
]);
962 if (fifo
->last_urblen
!= fifo
->usb_packet_maxlen
) {
963 /* the threshold mask is in the 2nd status byte */
964 hfc
->threshold_mask
= buf
[1];
965 /* the S0 state is in the upper half of the 1st status byte */
966 state_handler(hfc
, buf
[0] >> 4);
967 eof
[fifon
] = buf
[0] & 1;
968 /* if we have more than the 2 status bytes -> collect data */
970 collect_rx_frame(fifo
, buf
+ 2,
971 urb
->actual_length
- 2,
972 (len
< maxlen
) ? eof
[fifon
] : 0);
974 collect_rx_frame(fifo
, buf
, urb
->actual_length
,
975 (len
< maxlen
) ? eof
[fifon
] : 0);
977 fifo
->last_urblen
= urb
->actual_length
;
978 status
= usb_submit_urb(urb
, GFP_ATOMIC
);
981 "HFC-S USB: error resubmitting URN at rx_complete...\n");
985 /***************************************************/
986 /* start the interrupt transfer for the given fifo */
987 /***************************************************/
989 start_int_fifo(usb_fifo
* fifo
)
993 printk(KERN_INFO
"HFC-S USB: starting intr IN fifo:%d\n",
997 fifo
->urb
= usb_alloc_urb(0, GFP_KERNEL
);
1001 usb_fill_int_urb(fifo
->urb
, fifo
->hfc
->dev
, fifo
->pipe
,
1002 fifo
->buffer
, fifo
->usb_packet_maxlen
,
1003 rx_complete
, fifo
, fifo
->intervall
);
1004 fifo
->active
= 1; /* must be marked active */
1005 errcode
= usb_submit_urb(fifo
->urb
, GFP_KERNEL
);
1008 "HFC-S USB: submit URB error(start_int_info): status:%i\n",
1011 fifo
->skbuff
= NULL
;
1013 } /* start_int_fifo */
1015 /*****************************/
1016 /* set the B-channel mode */
1017 /*****************************/
1019 set_hfcmode(hfcusb_data
* hfc
, int channel
, int mode
)
1021 __u8 val
, idx_table
[2] = { 0, 2 };
1023 if (hfc
->disc_flag
) {
1026 #ifdef CONFIG_HISAX_DEBUG
1027 DBG(ISDN_DBG
, "HFC-S USB: setting channel %d to mode %d", channel
,
1030 hfc
->b_mode
[channel
] = mode
;
1032 /* setup CON_HDLC */
1034 if (mode
!= L1_MODE_NULL
)
1035 val
= 8; /* enable fifo? */
1036 if (mode
== L1_MODE_TRANS
)
1037 val
|= 2; /* set transparent bit */
1039 /* set FIFO to transmit register */
1040 queue_control_request(hfc
, HFCUSB_FIFO
, idx_table
[channel
], 1);
1041 queue_control_request(hfc
, HFCUSB_CON_HDLC
, val
, 1);
1043 queue_control_request(hfc
, HFCUSB_INC_RES_F
, 2, 1);
1044 /* set FIFO to receive register */
1045 queue_control_request(hfc
, HFCUSB_FIFO
, idx_table
[channel
] + 1, 1);
1046 queue_control_request(hfc
, HFCUSB_CON_HDLC
, val
, 1);
1048 queue_control_request(hfc
, HFCUSB_INC_RES_F
, 2, 1);
1055 queue_control_request(hfc
, HFCUSB_SCTRL
, val
, 1);
1062 queue_control_request(hfc
, HFCUSB_SCTRL_R
, val
, 1);
1064 if (mode
== L1_MODE_NULL
) {
1066 handle_led(hfc
, LED_B2_OFF
);
1068 handle_led(hfc
, LED_B1_OFF
);
1071 handle_led(hfc
, LED_B2_ON
);
1073 handle_led(hfc
, LED_B1_ON
);
1078 hfc_usb_l2l1(struct hisax_if
*my_hisax_if
, int pr
, void *arg
)
1080 usb_fifo
*fifo
= my_hisax_if
->priv
;
1081 hfcusb_data
*hfc
= fifo
->hfc
;
1084 case PH_ACTIVATE
| REQUEST
:
1085 if (fifo
->fifonum
== HFCUSB_D_TX
) {
1086 #ifdef CONFIG_HISAX_DEBUG
1088 "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_ACTIVATE | REQUEST");
1090 if (hfc
->l1_state
!= 3
1091 && hfc
->l1_state
!= 7) {
1092 hfc
->d_if
.ifc
.l1l2(&hfc
->d_if
.ifc
,
1096 #ifdef CONFIG_HISAX_DEBUG
1098 "HFC-S USB: PH_DEACTIVATE | INDICATION sent (not state 3 or 7)");
1101 if (hfc
->l1_state
== 7) { /* l1 already active */
1102 hfc
->d_if
.ifc
.l1l2(&hfc
->
1109 #ifdef CONFIG_HISAX_DEBUG
1111 "HFC-S USB: PH_ACTIVATE | INDICATION sent again ;)");
1114 /* force sending sending INFO1 */
1115 queue_control_request(hfc
,
1120 /* start l1 activation */
1121 queue_control_request(hfc
,
1138 #ifdef CONFIG_HISAX_DEBUG
1140 "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_ACTIVATE | REQUEST");
1144 HFCUSB_B1_TX
) ? 0 : 1,
1146 fifo
->hif
->l1l2(fifo
->hif
,
1147 PH_ACTIVATE
| INDICATION
,
1151 case PH_DEACTIVATE
| REQUEST
:
1152 if (fifo
->fifonum
== HFCUSB_D_TX
) {
1153 #ifdef CONFIG_HISAX_DEBUG
1155 "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_DEACTIVATE | REQUEST");
1158 "HFC-S USB: ISDN TE device should not deativate...\n");
1160 #ifdef CONFIG_HISAX_DEBUG
1162 "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_DEACTIVATE | REQUEST");
1166 HFCUSB_B1_TX
) ? 0 : 1,
1167 (int) L1_MODE_NULL
);
1168 fifo
->hif
->l1l2(fifo
->hif
,
1169 PH_DEACTIVATE
| INDICATION
,
1173 case PH_DATA
| REQUEST
:
1174 if (fifo
->skbuff
&& fifo
->delete_flg
) {
1175 dev_kfree_skb_any(fifo
->skbuff
);
1176 fifo
->skbuff
= NULL
;
1177 fifo
->delete_flg
= false;
1179 fifo
->skbuff
= arg
; /* we have a new buffer */
1183 "HFC_USB: hfc_usb_d_l2l1: unkown state : %#x\n",
1189 /***************************************************************************/
1190 /* usb_init is called once when a new matching device is detected to setup */
1191 /* main parameters. It registers the driver at the main hisax module. */
1192 /* on success 0 is returned. */
1193 /***************************************************************************/
1195 usb_init(hfcusb_data
* hfc
)
1200 struct hisax_b_if
*p_b_if
[2];
1202 /* check the chip id */
1203 if (read_usb(hfc
, HFCUSB_CHIP_ID
, &b
) != 1) {
1204 printk(KERN_INFO
"HFC-USB: cannot read chip id\n");
1207 if (b
!= HFCUSB_CHIPID
) {
1208 printk(KERN_INFO
"HFC-S USB: Invalid chip id 0x%02x\n", b
);
1212 /* first set the needed config, interface and alternate */
1213 err
= usb_set_interface(hfc
->dev
, hfc
->if_used
, hfc
->alt_used
);
1216 write_usb(hfc
, HFCUSB_CIRM
, 8);
1217 /* aux = output, reset off */
1218 write_usb(hfc
, HFCUSB_CIRM
, 0x10);
1220 /* set USB_SIZE to match the wMaxPacketSize for INT or BULK transfers */
1221 write_usb(hfc
, HFCUSB_USB_SIZE
,
1222 (hfc
->packet_size
/ 8) | ((hfc
->packet_size
/ 8) << 4));
1224 /* set USB_SIZE_I to match the wMaxPacketSize for ISO transfers */
1225 write_usb(hfc
, HFCUSB_USB_SIZE_I
, hfc
->iso_packet_size
);
1227 /* enable PCM/GCI master mode */
1228 write_usb(hfc
, HFCUSB_MST_MODE1
, 0); /* set default values */
1229 write_usb(hfc
, HFCUSB_MST_MODE0
, 1); /* enable master mode */
1231 /* init the fifos */
1232 write_usb(hfc
, HFCUSB_F_THRES
,
1233 (HFCUSB_TX_THRESHOLD
/
1234 8) | ((HFCUSB_RX_THRESHOLD
/ 8) << 4));
1237 for (i
= 0; i
< HFCUSB_NUM_FIFOS
; i
++) {
1238 write_usb(hfc
, HFCUSB_FIFO
, i
); /* select the desired fifo */
1239 fifo
[i
].skbuff
= NULL
; /* init buffer pointer */
1241 (i
<= HFCUSB_B2_RX
) ? MAX_BCH_SIZE
: MAX_DFRAME_LEN
;
1242 fifo
[i
].last_urblen
= 0;
1243 /* set 2 bit for D- & E-channel */
1244 write_usb(hfc
, HFCUSB_HDLC_PAR
,
1245 ((i
<= HFCUSB_B2_RX
) ? 0 : 2));
1246 /* rx hdlc, enable IFF for D-channel */
1247 write_usb(hfc
, HFCUSB_CON_HDLC
,
1248 ((i
== HFCUSB_D_TX
) ? 0x09 : 0x08));
1249 write_usb(hfc
, HFCUSB_INC_RES_F
, 2); /* reset the fifo */
1252 write_usb(hfc
, HFCUSB_CLKDEL
, 0x0f); /* clock delay value */
1253 write_usb(hfc
, HFCUSB_STATES
, 3 | 0x10); /* set deactivated mode */
1254 write_usb(hfc
, HFCUSB_STATES
, 3); /* enable state machine */
1256 write_usb(hfc
, HFCUSB_SCTRL_R
, 0); /* disable both B receivers */
1257 write_usb(hfc
, HFCUSB_SCTRL
, 0x40); /* disable B transmitters + capacitive mode */
1259 /* set both B-channel to not connected */
1260 hfc
->b_mode
[0] = L1_MODE_NULL
;
1261 hfc
->b_mode
[1] = L1_MODE_NULL
;
1263 hfc
->l1_activated
= false;
1264 hfc
->disc_flag
= false;
1266 hfc
->led_new_data
= 0;
1267 hfc
->old_led_state
= 0;
1269 /* init the t3 timer */
1270 init_timer(&hfc
->t3_timer
);
1271 hfc
->t3_timer
.data
= (long) hfc
;
1272 hfc
->t3_timer
.function
= (void *) l1_timer_expire_t3
;
1274 /* init the t4 timer */
1275 init_timer(&hfc
->t4_timer
);
1276 hfc
->t4_timer
.data
= (long) hfc
;
1277 hfc
->t4_timer
.function
= (void *) l1_timer_expire_t4
;
1279 /* init the background machinery for control requests */
1280 hfc
->ctrl_read
.bRequestType
= 0xc0;
1281 hfc
->ctrl_read
.bRequest
= 1;
1282 hfc
->ctrl_read
.wLength
= cpu_to_le16(1);
1283 hfc
->ctrl_write
.bRequestType
= 0x40;
1284 hfc
->ctrl_write
.bRequest
= 0;
1285 hfc
->ctrl_write
.wLength
= 0;
1286 usb_fill_control_urb(hfc
->ctrl_urb
,
1289 (u_char
*) & hfc
->ctrl_write
,
1290 NULL
, 0, ctrl_complete
, hfc
);
1291 /* Init All Fifos */
1292 for (i
= 0; i
< HFCUSB_NUM_FIFOS
; i
++) {
1293 hfc
->fifos
[i
].iso
[0].purb
= NULL
;
1294 hfc
->fifos
[i
].iso
[1].purb
= NULL
;
1295 hfc
->fifos
[i
].active
= 0;
1297 /* register Modul to upper Hisax Layers */
1298 hfc
->d_if
.owner
= THIS_MODULE
;
1299 hfc
->d_if
.ifc
.priv
= &hfc
->fifos
[HFCUSB_D_TX
];
1300 hfc
->d_if
.ifc
.l2l1
= hfc_usb_l2l1
;
1301 for (i
= 0; i
< 2; i
++) {
1302 hfc
->b_if
[i
].ifc
.priv
= &hfc
->fifos
[HFCUSB_B1_TX
+ i
* 2];
1303 hfc
->b_if
[i
].ifc
.l2l1
= hfc_usb_l2l1
;
1304 p_b_if
[i
] = &hfc
->b_if
[i
];
1306 /* default Prot: EURO ISDN, should be a module_param */
1308 hisax_register(&hfc
->d_if
, p_b_if
, "hfc_usb", hfc
->protocol
);
1310 #ifdef CONFIG_HISAX_DEBUG
1314 for (i
= 0; i
< 4; i
++)
1315 hfc
->fifos
[i
].hif
= &p_b_if
[i
/ 2]->ifc
;
1316 for (i
= 4; i
< 8; i
++)
1317 hfc
->fifos
[i
].hif
= &hfc
->d_if
.ifc
;
1319 /* 3 (+1) INT IN + 3 ISO OUT */
1320 if (hfc
->cfg_used
== CNF_3INT3ISO
|| hfc
->cfg_used
== CNF_4INT3ISO
) {
1321 start_int_fifo(hfc
->fifos
+ HFCUSB_D_RX
);
1322 if (hfc
->fifos
[HFCUSB_PCM_RX
].pipe
)
1323 start_int_fifo(hfc
->fifos
+ HFCUSB_PCM_RX
);
1324 start_int_fifo(hfc
->fifos
+ HFCUSB_B1_RX
);
1325 start_int_fifo(hfc
->fifos
+ HFCUSB_B2_RX
);
1327 /* 3 (+1) ISO IN + 3 ISO OUT */
1328 if (hfc
->cfg_used
== CNF_3ISO3ISO
|| hfc
->cfg_used
== CNF_4ISO3ISO
) {
1329 start_isoc_chain(hfc
->fifos
+ HFCUSB_D_RX
, ISOC_PACKETS_D
,
1330 rx_iso_complete
, 16);
1331 if (hfc
->fifos
[HFCUSB_PCM_RX
].pipe
)
1332 start_isoc_chain(hfc
->fifos
+ HFCUSB_PCM_RX
,
1333 ISOC_PACKETS_D
, rx_iso_complete
,
1335 start_isoc_chain(hfc
->fifos
+ HFCUSB_B1_RX
, ISOC_PACKETS_B
,
1336 rx_iso_complete
, 16);
1337 start_isoc_chain(hfc
->fifos
+ HFCUSB_B2_RX
, ISOC_PACKETS_B
,
1338 rx_iso_complete
, 16);
1341 start_isoc_chain(hfc
->fifos
+ HFCUSB_D_TX
, ISOC_PACKETS_D
,
1342 tx_iso_complete
, 1);
1343 start_isoc_chain(hfc
->fifos
+ HFCUSB_B1_TX
, ISOC_PACKETS_B
,
1344 tx_iso_complete
, 1);
1345 start_isoc_chain(hfc
->fifos
+ HFCUSB_B2_TX
, ISOC_PACKETS_B
,
1346 tx_iso_complete
, 1);
1348 handle_led(hfc
, LED_POWER_ON
);
1353 /*************************************************/
1354 /* function called to probe a new plugged device */
1355 /*************************************************/
1357 hfc_usb_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
)
1359 struct usb_device
*dev
= interface_to_usbdev(intf
);
1360 hfcusb_data
*context
;
1361 struct usb_host_interface
*iface
= intf
->cur_altsetting
;
1362 struct usb_host_interface
*iface_used
= NULL
;
1363 struct usb_host_endpoint
*ep
;
1364 int ifnum
= iface
->desc
.bInterfaceNumber
;
1365 int i
, idx
, alt_idx
, probe_alt_setting
, vend_idx
, cfg_used
, *vcf
,
1366 attr
, cfg_found
, cidx
, ep_addr
;
1367 int cmptbl
[16], small_match
, iso_packet_size
, packet_size
,
1369 hfcsusb_vdata
*driver_info
;
1372 for (i
= 0; hfcusb_idtab
[i
].idVendor
; i
++) {
1373 if ((le16_to_cpu(dev
->descriptor
.idVendor
) == hfcusb_idtab
[i
].idVendor
)
1374 && (le16_to_cpu(dev
->descriptor
.idProduct
) == hfcusb_idtab
[i
].idProduct
)) {
1380 #ifdef CONFIG_HISAX_DEBUG
1382 "HFC-USB: probing interface(%d) actalt(%d) minor(%d)\n", ifnum
,
1383 iface
->desc
.bAlternateSetting
, intf
->minor
);
1386 "HFC-S USB: probing interface(%d) actalt(%d) minor(%d)\n",
1387 ifnum
, iface
->desc
.bAlternateSetting
, intf
->minor
);
1389 if (vend_idx
!= 0xffff) {
1390 /* if vendor and product ID is OK, start probing alternate settings */
1392 small_match
= 0xffff;
1394 /* default settings */
1395 iso_packet_size
= 16;
1398 while (alt_idx
< intf
->num_altsetting
) {
1399 iface
= intf
->altsetting
+ alt_idx
;
1400 probe_alt_setting
= iface
->desc
.bAlternateSetting
;
1403 /* check for config EOL element */
1404 while (validconf
[cfg_used
][0]) {
1406 vcf
= validconf
[cfg_used
];
1407 /* first endpoint descriptor */
1408 ep
= iface
->endpoint
;
1409 #ifdef CONFIG_HISAX_DEBUG
1411 "HFC-S USB: (if=%d alt=%d cfg_used=%d)\n",
1412 ifnum
, probe_alt_setting
, cfg_used
);
1414 memcpy(cmptbl
, vcf
, 16 * sizeof(int));
1416 /* check for all endpoints in this alternate setting */
1417 for (i
= 0; i
< iface
->desc
.bNumEndpoints
;
1420 ep
->desc
.bEndpointAddress
;
1421 /* get endpoint base */
1422 idx
= ((ep_addr
& 0x7f) - 1) * 2;
1425 attr
= ep
->desc
.bmAttributes
;
1426 if (cmptbl
[idx
] == EP_NUL
) {
1429 if (attr
== USB_ENDPOINT_XFER_INT
1430 && cmptbl
[idx
] == EP_INT
)
1431 cmptbl
[idx
] = EP_NUL
;
1432 if (attr
== USB_ENDPOINT_XFER_BULK
1433 && cmptbl
[idx
] == EP_BLK
)
1434 cmptbl
[idx
] = EP_NUL
;
1435 if (attr
== USB_ENDPOINT_XFER_ISOC
1436 && cmptbl
[idx
] == EP_ISO
)
1437 cmptbl
[idx
] = EP_NUL
;
1439 /* check if all INT endpoints match minimum interval */
1440 if (attr
== USB_ENDPOINT_XFER_INT
1441 && ep
->desc
.bInterval
<
1443 #ifdef CONFIG_HISAX_DEBUG
1446 "HFC-S USB: Interrupt Endpoint interval < %d found - skipping config",
1453 for (i
= 0; i
< 16; i
++) {
1454 /* all entries must be EP_NOP or EP_NUL for a valid config */
1455 if (cmptbl
[i
] != EP_NOP
1456 && cmptbl
[i
] != EP_NUL
)
1460 if (cfg_used
< small_match
) {
1461 small_match
= cfg_used
;
1466 #ifdef CONFIG_HISAX_DEBUG
1468 "HFC-USB: small_match=%x %x\n",
1469 small_match
, alt_used
);
1475 } /* (alt_idx < intf->num_altsetting) */
1477 /* found a valid USB Ta Endpint config */
1478 if (small_match
!= 0xffff) {
1482 kzalloc(sizeof(hfcusb_data
), GFP_KERNEL
)))
1483 return (-ENOMEM
); /* got no mem */
1485 ep
= iface
->endpoint
;
1486 vcf
= validconf
[small_match
];
1488 for (i
= 0; i
< iface
->desc
.bNumEndpoints
; i
++) {
1489 ep_addr
= ep
->desc
.bEndpointAddress
;
1490 /* get endpoint base */
1491 idx
= ((ep_addr
& 0x7f) - 1) * 2;
1495 attr
= ep
->desc
.bmAttributes
;
1497 /* init Endpoints */
1498 if (vcf
[idx
] != EP_NOP
1499 && vcf
[idx
] != EP_NUL
) {
1501 case USB_ENDPOINT_XFER_INT
:
1514 le16_to_cpu(ep
->desc
.wMaxPacketSize
);
1516 case USB_ENDPOINT_XFER_BULK
:
1542 le16_to_cpu(ep
->desc
.wMaxPacketSize
);
1544 case USB_ENDPOINT_XFER_ISOC
:
1570 le16_to_cpu(ep
->desc
.wMaxPacketSize
);
1576 } /* switch attribute */
1578 if (context
->fifos
[cidx
].pipe
) {
1579 context
->fifos
[cidx
].
1581 context
->fifos
[cidx
].hfc
=
1583 context
->fifos
[cidx
].usb_packet_maxlen
=
1584 le16_to_cpu(ep
->desc
.wMaxPacketSize
);
1585 context
->fifos
[cidx
].
1588 context
->fifos
[cidx
].
1594 context
->dev
= dev
; /* save device */
1595 context
->if_used
= ifnum
; /* save used interface */
1596 context
->alt_used
= alt_used
; /* and alternate config */
1597 context
->ctrl_paksize
= dev
->descriptor
.bMaxPacketSize0
; /* control size */
1598 context
->cfg_used
= vcf
[16]; /* store used config */
1599 context
->vend_idx
= vend_idx
; /* store found vendor */
1600 context
->packet_size
= packet_size
;
1601 context
->iso_packet_size
= iso_packet_size
;
1603 /* create the control pipes needed for register access */
1604 context
->ctrl_in_pipe
=
1605 usb_rcvctrlpipe(context
->dev
, 0);
1606 context
->ctrl_out_pipe
=
1607 usb_sndctrlpipe(context
->dev
, 0);
1608 context
->ctrl_urb
= usb_alloc_urb(0, GFP_KERNEL
);
1611 (hfcsusb_vdata
*) hfcusb_idtab
[vend_idx
].
1613 printk(KERN_INFO
"HFC-S USB: detected \"%s\"\n",
1614 driver_info
->vend_name
);
1615 #ifdef CONFIG_HISAX_DEBUG
1617 "HFC-S USB: Endpoint-Config: %s (if=%d alt=%d)\n",
1618 conf_str
[small_match
], context
->if_used
,
1621 "HFC-S USB: E-channel (\"ECHO:\") logging ");
1622 if (validconf
[small_match
][18])
1623 printk(" possible\n");
1625 printk("NOT possible\n");
1627 /* init the chip and register the driver */
1628 if (usb_init(context
)) {
1629 if (context
->ctrl_urb
) {
1630 usb_unlink_urb(context
->ctrl_urb
);
1631 usb_free_urb(context
->ctrl_urb
);
1632 context
->ctrl_urb
= NULL
;
1637 usb_set_intfdata(intf
, context
);
1642 "HFC-S USB: no valid vendor found in USB descriptor\n");
1647 /****************************************************/
1648 /* function called when an active device is removed */
1649 /****************************************************/
1651 hfc_usb_disconnect(struct usb_interface
1654 hfcusb_data
*context
= usb_get_intfdata(intf
);
1656 printk(KERN_INFO
"HFC-S USB: device disconnect\n");
1657 context
->disc_flag
= true;
1658 usb_set_intfdata(intf
, NULL
);
1661 if (timer_pending(&context
->t3_timer
))
1662 del_timer(&context
->t3_timer
);
1663 if (timer_pending(&context
->t4_timer
))
1664 del_timer(&context
->t4_timer
);
1665 /* tell all fifos to terminate */
1666 for (i
= 0; i
< HFCUSB_NUM_FIFOS
; i
++) {
1667 if (context
->fifos
[i
].usb_transfer_mode
== USB_ISOC
) {
1668 if (context
->fifos
[i
].active
> 0) {
1669 stop_isoc_chain(&context
->fifos
[i
]);
1670 #ifdef CONFIG_HISAX_DEBUG
1672 "HFC-S USB: hfc_usb_disconnect: stopping ISOC chain Fifo no %i",
1677 if (context
->fifos
[i
].active
> 0) {
1678 context
->fifos
[i
].active
= 0;
1679 #ifdef CONFIG_HISAX_DEBUG
1681 "HFC-S USB: hfc_usb_disconnect: unlinking URB for Fifo no %i",
1685 if (context
->fifos
[i
].urb
) {
1686 usb_unlink_urb(context
->fifos
[i
].urb
);
1687 usb_free_urb(context
->fifos
[i
].urb
);
1688 context
->fifos
[i
].urb
= NULL
;
1691 context
->fifos
[i
].active
= 0;
1693 /* wait for all URBS to terminate */
1695 if (context
->ctrl_urb
) {
1696 usb_unlink_urb(context
->ctrl_urb
);
1697 usb_free_urb(context
->ctrl_urb
);
1698 context
->ctrl_urb
= NULL
;
1700 hisax_unregister(&context
->d_if
);
1701 kfree(context
); /* free our structure again */
1702 } /* hfc_usb_disconnect */
1704 /************************************/
1705 /* our driver information structure */
1706 /************************************/
1707 static struct usb_driver hfc_drv
= {
1709 .id_table
= hfcusb_idtab
,
1710 .probe
= hfc_usb_probe
,
1711 .disconnect
= hfc_usb_disconnect
,
1716 #ifdef CONFIG_HISAX_DEBUG
1717 DBG(USB_DBG
, "HFC-S USB: calling \"hfc_usb_exit\" ...");
1719 usb_deregister(&hfc_drv
); /* release our driver */
1720 printk(KERN_INFO
"HFC-S USB: module removed\n");
1726 #ifndef CONFIG_HISAX_DEBUG
1727 unsigned int debug
= -1;
1729 char revstr
[30], datestr
[30], dummy
[30];
1730 sscanf(hfcusb_revision
,
1731 "%s %s $ %s %s %s $ ", dummy
, revstr
,
1732 dummy
, datestr
, dummy
);
1734 "HFC-S USB: driver module revision %s date %s loaded, (debug=%i)\n",
1735 revstr
, datestr
, debug
);
1736 if (usb_register(&hfc_drv
)) {
1738 "HFC-S USB: Unable to register HFC-S USB module at usb stack\n");
1739 return (-1); /* unable to register */
1744 module_init(hfc_usb_init
);
1745 module_exit(hfc_usb_exit
);
1746 MODULE_AUTHOR(DRIVER_AUTHOR
);
1747 MODULE_DESCRIPTION(DRIVER_DESC
);
1748 MODULE_LICENSE("GPL");
1749 MODULE_DEVICE_TABLE(usb
, hfcusb_idtab
);