4 * $Id: hfc_usb.c,v 2.3.2.24 2007/10/14 08:40:29 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.24 $ $Date: 2007/10/14 08:40:29 $ ";
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},
130 USB_DEVICE(0x071d, 0x1005),
131 .driver_info
= (unsigned long) &((hfcsusb_vdata
)
132 {LED_SCHEME1
, {0x02, 0, 0x01, 0x04},
133 "Eicon DIVA USB 4.0"}),
138 /* structure defining input+output fifos (interrupt/bulk mode) */
139 struct usb_fifo
; /* forward definition */
140 typedef struct iso_urb_struct
{
142 __u8 buffer
[ISO_BUFFER_SIZE
]; /* buffer incoming/outgoing data */
143 struct usb_fifo
*owner_fifo
; /* pointer to owner fifo */
146 struct hfcusb_data
; /* forward definition */
148 typedef struct usb_fifo
{
149 int fifonum
; /* fifo index attached to this structure */
150 int active
; /* fifo is currently active */
151 struct hfcusb_data
*hfc
; /* pointer to main structure */
152 int pipe
; /* address of endpoint */
153 __u8 usb_packet_maxlen
; /* maximum length for usb transfer */
154 unsigned int max_size
; /* maximum size of receive/send packet */
155 __u8 intervall
; /* interrupt interval */
156 struct sk_buff
*skbuff
; /* actual used buffer */
157 struct urb
*urb
; /* transfer structure for usb routines */
158 __u8 buffer
[128]; /* buffer incoming/outgoing data */
159 int bit_line
; /* how much bits are in the fifo? */
161 volatile __u8 usb_transfer_mode
; /* switched between ISO and INT */
162 iso_urb_struct iso
[2]; /* need two urbs to have one always for pending */
163 struct hisax_if
*hif
; /* hisax interface */
164 int delete_flg
; /* only delete skbuff once */
165 int last_urblen
; /* remember length of last packet */
168 /* structure holding all data for one device */
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
, /* handles for control pipe */
181 int cfg_used
; /* configuration index used */
182 int vend_idx
; /* vendor found */
183 int b_mode
[2]; /* B-channel mode */
184 int l1_activated
; /* layer 1 activated */
185 int disc_flag
; /* TRUE if device was disonnected to avoid some USB actions */
186 int packet_size
, iso_packet_size
;
188 /* control pipe background handling */
189 ctrl_buft ctrl_buff
[HFC_CTRL_BUFSIZE
]; /* buffer holding queued data */
190 volatile int ctrl_in_idx
, ctrl_out_idx
, ctrl_cnt
; /* input/output pointer + count */
191 struct urb
*ctrl_urb
; /* transfer structure for control channel */
193 struct usb_ctrlrequest ctrl_write
; /* buffer for control write request */
194 struct usb_ctrlrequest ctrl_read
; /* same for read request */
196 __u8 old_led_state
, led_state
;
198 volatile __u8 threshold_mask
; /* threshold actually reported */
199 volatile __u8 bch_enables
; /* or mask for sctrl_r and sctrl register values */
201 usb_fifo fifos
[HFCUSB_NUM_FIFOS
]; /* structure holding all fifo data */
203 volatile __u8 l1_state
; /* actual l1 state */
204 struct timer_list t3_timer
; /* timer 3 for activation/deactivation */
205 struct timer_list t4_timer
; /* timer 4 for activation/deactivation */
209 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 ctrl_start_transfer(hfcusb_data
* hfc
)
226 hfc
->ctrl_urb
->pipe
= hfc
->ctrl_out_pipe
;
227 hfc
->ctrl_urb
->setup_packet
= (u_char
*) & hfc
->ctrl_write
;
228 hfc
->ctrl_urb
->transfer_buffer
= NULL
;
229 hfc
->ctrl_urb
->transfer_buffer_length
= 0;
230 hfc
->ctrl_write
.wIndex
=
231 cpu_to_le16(hfc
->ctrl_buff
[hfc
->ctrl_out_idx
].hfc_reg
);
232 hfc
->ctrl_write
.wValue
=
233 cpu_to_le16(hfc
->ctrl_buff
[hfc
->ctrl_out_idx
].reg_val
);
235 usb_submit_urb(hfc
->ctrl_urb
, GFP_ATOMIC
); /* start transfer */
237 } /* ctrl_start_transfer */
240 queue_control_request(hfcusb_data
* hfc
, __u8 reg
, __u8 val
, int action
)
244 if (hfc
->ctrl_cnt
>= HFC_CTRL_BUFSIZE
)
245 return (1); /* no space left */
246 buf
= &hfc
->ctrl_buff
[hfc
->ctrl_in_idx
]; /* pointer to new index */
249 buf
->action
= action
;
250 if (++hfc
->ctrl_in_idx
>= HFC_CTRL_BUFSIZE
)
251 hfc
->ctrl_in_idx
= 0; /* pointer wrap */
252 if (++hfc
->ctrl_cnt
== 1)
253 ctrl_start_transfer(hfc
);
258 ctrl_complete(struct urb
*urb
)
260 hfcusb_data
*hfc
= (hfcusb_data
*) urb
->context
;
265 buf
= &hfc
->ctrl_buff
[hfc
->ctrl_out_idx
];
266 hfc
->ctrl_cnt
--; /* decrement actual count */
267 if (++hfc
->ctrl_out_idx
>= HFC_CTRL_BUFSIZE
)
268 hfc
->ctrl_out_idx
= 0; /* pointer wrap */
270 ctrl_start_transfer(hfc
); /* start next transfer */
274 /* write led data to auxport & invert if necessary */
276 write_led(hfcusb_data
* hfc
, __u8 led_state
)
278 if (led_state
!= hfc
->old_led_state
) {
279 hfc
->old_led_state
= led_state
;
280 queue_control_request(hfc
, HFCUSB_P_DATA
, led_state
, 1);
285 set_led_bit(hfcusb_data
* hfc
, signed short led_bits
, int on
)
289 hfc
->led_state
&= ~abs(led_bits
);
291 hfc
->led_state
|= led_bits
;
294 hfc
->led_state
|= abs(led_bits
);
296 hfc
->led_state
&= ~led_bits
;
300 /* handle LED requests */
302 handle_led(hfcusb_data
* hfc
, int event
)
304 hfcsusb_vdata
*driver_info
=
305 (hfcsusb_vdata
*) hfcusb_idtab
[hfc
->vend_idx
].driver_info
;
307 /* if no scheme -> no LED action */
308 if (driver_info
->led_scheme
== LED_OFF
)
313 set_led_bit(hfc
, driver_info
->led_bits
[0], 1);
314 set_led_bit(hfc
, driver_info
->led_bits
[1], 0);
315 set_led_bit(hfc
, driver_info
->led_bits
[2], 0);
316 set_led_bit(hfc
, driver_info
->led_bits
[3], 0);
319 set_led_bit(hfc
, driver_info
->led_bits
[0], 0);
320 set_led_bit(hfc
, driver_info
->led_bits
[1], 0);
321 set_led_bit(hfc
, driver_info
->led_bits
[2], 0);
322 set_led_bit(hfc
, driver_info
->led_bits
[3], 0);
325 set_led_bit(hfc
, driver_info
->led_bits
[1], 1);
328 set_led_bit(hfc
, driver_info
->led_bits
[1], 0);
331 set_led_bit(hfc
, driver_info
->led_bits
[2], 1);
334 set_led_bit(hfc
, driver_info
->led_bits
[2], 0);
337 set_led_bit(hfc
, driver_info
->led_bits
[3], 1);
340 set_led_bit(hfc
, driver_info
->led_bits
[3], 0);
343 write_led(hfc
, hfc
->led_state
);
346 /* ISDN l1 timer T3 expires */
348 l1_timer_expire_t3(hfcusb_data
* hfc
)
350 hfc
->d_if
.ifc
.l1l2(&hfc
->d_if
.ifc
, PH_DEACTIVATE
| INDICATION
,
353 DBG(HFCUSB_DBG_STATES
,
354 "HFC-S USB: PH_DEACTIVATE | INDICATION sent (T3 expire)");
356 hfc
->l1_activated
= 0;
357 handle_led(hfc
, LED_S0_OFF
);
359 queue_control_request(hfc
, HFCUSB_STATES
, 0x10, 1);
360 queue_control_request(hfc
, HFCUSB_STATES
, 3, 1);
363 /* ISDN l1 timer T4 expires */
365 l1_timer_expire_t4(hfcusb_data
* hfc
)
367 hfc
->d_if
.ifc
.l1l2(&hfc
->d_if
.ifc
, PH_DEACTIVATE
| INDICATION
,
370 DBG(HFCUSB_DBG_STATES
,
371 "HFC-S USB: PH_DEACTIVATE | INDICATION sent (T4 expire)");
373 hfc
->l1_activated
= 0;
374 handle_led(hfc
, LED_S0_OFF
);
377 /* S0 state changed */
379 s0_state_handler(hfcusb_data
* hfc
, __u8 state
)
383 old_state
= hfc
->l1_state
;
384 if (state
== old_state
|| state
< 1 || state
> 8)
387 DBG(HFCUSB_DBG_STATES
, "HFC-S USB: S0 statechange(%d -> %d)",
390 if (state
< 4 || state
== 7 || state
== 8) {
391 if (timer_pending(&hfc
->t3_timer
))
392 del_timer(&hfc
->t3_timer
);
393 DBG(HFCUSB_DBG_STATES
, "HFC-S USB: T3 deactivated");
396 if (timer_pending(&hfc
->t4_timer
))
397 del_timer(&hfc
->t4_timer
);
398 DBG(HFCUSB_DBG_STATES
, "HFC-S USB: T4 deactivated");
401 if (state
== 7 && !hfc
->l1_activated
) {
402 hfc
->d_if
.ifc
.l1l2(&hfc
->d_if
.ifc
,
403 PH_ACTIVATE
| INDICATION
, NULL
);
404 DBG(HFCUSB_DBG_STATES
, "HFC-S USB: PH_ACTIVATE | INDICATION sent");
405 hfc
->l1_activated
= 1;
406 handle_led(hfc
, LED_S0_ON
);
407 } else if (state
<= 3 /* && activated */ ) {
408 if (old_state
== 7 || old_state
== 8) {
409 DBG(HFCUSB_DBG_STATES
, "HFC-S USB: T4 activated");
410 if (!timer_pending(&hfc
->t4_timer
)) {
411 hfc
->t4_timer
.expires
=
412 jiffies
+ (HFC_TIMER_T4
* HZ
) / 1000;
413 add_timer(&hfc
->t4_timer
);
416 hfc
->d_if
.ifc
.l1l2(&hfc
->d_if
.ifc
,
417 PH_DEACTIVATE
| INDICATION
,
419 DBG(HFCUSB_DBG_STATES
,
420 "HFC-S USB: PH_DEACTIVATE | INDICATION sent");
421 hfc
->l1_activated
= 0;
422 handle_led(hfc
, LED_S0_OFF
);
425 hfc
->l1_state
= state
;
429 fill_isoc_urb(struct urb
*urb
, struct usb_device
*dev
, unsigned int pipe
,
430 void *buf
, int num_packets
, int packet_size
, int interval
,
431 usb_complete_t complete
, void *context
)
437 urb
->complete
= complete
;
438 urb
->number_of_packets
= num_packets
;
439 urb
->transfer_buffer_length
= packet_size
* num_packets
;
440 urb
->context
= context
;
441 urb
->transfer_buffer
= buf
;
442 urb
->transfer_flags
= URB_ISO_ASAP
;
443 urb
->actual_length
= 0;
444 urb
->interval
= interval
;
445 for (k
= 0; k
< num_packets
; k
++) {
446 urb
->iso_frame_desc
[k
].offset
= packet_size
* k
;
447 urb
->iso_frame_desc
[k
].length
= packet_size
;
448 urb
->iso_frame_desc
[k
].actual_length
= 0;
452 /* allocs urbs and start isoc transfer with two pending urbs to avoid
453 * gaps in the transfer chain
456 start_isoc_chain(usb_fifo
* fifo
, int num_packets_per_urb
,
457 usb_complete_t complete
, int packet_size
)
461 DBG(HFCUSB_DBG_INIT
, "HFC-S USB: starting ISO-URBs for fifo:%d\n",
464 /* allocate Memory for Iso out Urbs */
465 for (i
= 0; i
< 2; i
++) {
466 if (!(fifo
->iso
[i
].purb
)) {
468 usb_alloc_urb(num_packets_per_urb
, GFP_KERNEL
);
469 if (!(fifo
->iso
[i
].purb
)) {
471 "alloc urb for fifo %i failed!!!",
474 fifo
->iso
[i
].owner_fifo
= (struct usb_fifo
*) fifo
;
476 /* Init the first iso */
477 if (ISO_BUFFER_SIZE
>=
478 (fifo
->usb_packet_maxlen
*
479 num_packets_per_urb
)) {
480 fill_isoc_urb(fifo
->iso
[i
].purb
,
481 fifo
->hfc
->dev
, fifo
->pipe
,
484 fifo
->usb_packet_maxlen
,
485 fifo
->intervall
, complete
,
487 memset(fifo
->iso
[i
].buffer
, 0,
488 sizeof(fifo
->iso
[i
].buffer
));
489 /* defining packet delimeters in fifo->buffer */
490 for (k
= 0; k
< num_packets_per_urb
; k
++) {
492 iso_frame_desc
[k
].offset
=
495 iso_frame_desc
[k
].length
=
500 "HFC-S USB: ISO Buffer size to small!\n");
503 fifo
->bit_line
= BITLINE_INF
;
505 errcode
= usb_submit_urb(fifo
->iso
[i
].purb
, GFP_KERNEL
);
506 fifo
->active
= (errcode
>= 0) ? 1 : 0;
508 printk(KERN_INFO
"HFC-S USB: usb_submit_urb URB nr:%d, error(%i): '%s'\n",
509 i
, errcode
, symbolic(urb_errlist
, errcode
));
511 return (fifo
->active
);
514 /* stops running iso chain and frees their pending urbs */
516 stop_isoc_chain(usb_fifo
* fifo
)
520 for (i
= 0; i
< 2; i
++) {
521 if (fifo
->iso
[i
].purb
) {
523 "HFC-S USB: Stopping iso chain for fifo %i.%i",
525 usb_kill_urb(fifo
->iso
[i
].purb
);
526 usb_free_urb(fifo
->iso
[i
].purb
);
527 fifo
->iso
[i
].purb
= NULL
;
531 usb_kill_urb(fifo
->urb
);
532 usb_free_urb(fifo
->urb
);
537 /* defines how much ISO packets are handled in one URB */
538 static int iso_packets
[8] =
539 { ISOC_PACKETS_B
, ISOC_PACKETS_B
, ISOC_PACKETS_B
, ISOC_PACKETS_B
,
540 ISOC_PACKETS_D
, ISOC_PACKETS_D
, ISOC_PACKETS_D
, ISOC_PACKETS_D
544 tx_iso_complete(struct urb
*urb
)
546 iso_urb_struct
*context_iso_urb
= (iso_urb_struct
*) urb
->context
;
547 usb_fifo
*fifo
= context_iso_urb
->owner_fifo
;
548 hfcusb_data
*hfc
= fifo
->hfc
;
549 int k
, tx_offset
, num_isoc_packets
, sink
, len
, current_len
,
551 int frame_complete
, transp_mode
, fifon
, status
;
554 fifon
= fifo
->fifonum
;
555 status
= urb
->status
;
559 /* ISO transfer only partially completed,
560 look at individual frame status for details */
561 if (status
== -EXDEV
) {
562 DBG(HFCUSB_DBG_VERBOSE_USB
, "HFC-S USB: tx_iso_complete with -EXDEV"
563 ", urb->status %d, fifonum %d\n",
566 for (k
= 0; k
< iso_packets
[fifon
]; ++k
) {
567 errcode
= urb
->iso_frame_desc
[k
].status
;
569 DBG(HFCUSB_DBG_VERBOSE_USB
, "HFC-S USB: tx_iso_complete "
570 "packet %i, status: %i\n",
574 // clear status, so go on with ISO transfers
578 if (fifo
->active
&& !status
) {
580 if (fifon
< 4 && hfc
->b_mode
[fifon
/ 2] == L1_MODE_TRANS
)
583 /* is FifoFull-threshold set for our channel? */
584 threshbit
= (hfc
->threshold_mask
& (1 << fifon
));
585 num_isoc_packets
= iso_packets
[fifon
];
587 /* predict dataflow to avoid fifo overflow */
588 if (fifon
>= HFCUSB_D_TX
) {
589 sink
= (threshbit
) ? SINK_DMIN
: SINK_DMAX
;
591 sink
= (threshbit
) ? SINK_MIN
: SINK_MAX
;
593 fill_isoc_urb(urb
, fifo
->hfc
->dev
, fifo
->pipe
,
594 context_iso_urb
->buffer
, num_isoc_packets
,
595 fifo
->usb_packet_maxlen
, fifo
->intervall
,
596 tx_iso_complete
, urb
->context
);
597 memset(context_iso_urb
->buffer
, 0,
598 sizeof(context_iso_urb
->buffer
));
601 /* Generate next ISO Packets */
602 for (k
= 0; k
< num_isoc_packets
; ++k
) {
604 len
= fifo
->skbuff
->len
;
605 /* we lower data margin every msec */
606 fifo
->bit_line
-= sink
;
607 current_len
= (0 - fifo
->bit_line
) / 8;
608 /* maximum 15 byte for every ISO packet makes our life easier */
609 if (current_len
> 14)
613 current_len
) ? len
: current_len
;
614 /* how much bit do we put on the line? */
615 fifo
->bit_line
+= current_len
* 8;
617 context_iso_urb
->buffer
[tx_offset
] = 0;
618 if (current_len
== len
) {
620 /* here frame completion */
622 buffer
[tx_offset
] = 1;
623 /* add 2 byte flags and 16bit CRC at end of ISDN frame */
624 fifo
->bit_line
+= 32;
629 memcpy(context_iso_urb
->buffer
+
630 tx_offset
+ 1, fifo
->skbuff
->data
,
632 skb_pull(fifo
->skbuff
, current_len
);
634 /* define packet delimeters within the URB buffer */
635 urb
->iso_frame_desc
[k
].offset
= tx_offset
;
636 urb
->iso_frame_desc
[k
].length
=
639 tx_offset
+= (current_len
+ 1);
641 urb
->iso_frame_desc
[k
].offset
=
644 urb
->iso_frame_desc
[k
].length
= 1;
645 fifo
->bit_line
-= sink
; /* we lower data margin every msec */
647 if (fifo
->bit_line
< BITLINE_INF
) {
648 fifo
->bit_line
= BITLINE_INF
;
652 if (frame_complete
) {
653 fifo
->delete_flg
= 1;
654 fifo
->hif
->l1l2(fifo
->hif
,
656 (void *) (unsigned long) fifo
->skbuff
->
658 if (fifo
->skbuff
&& fifo
->delete_flg
) {
659 dev_kfree_skb_any(fifo
->skbuff
);
661 fifo
->delete_flg
= 0;
666 errcode
= usb_submit_urb(urb
, GFP_ATOMIC
);
669 "HFC-S USB: error submitting ISO URB: %d\n",
673 if (status
&& !hfc
->disc_flag
) {
675 "HFC-S USB: tx_iso_complete: error(%i): '%s', fifonum=%d\n",
676 status
, symbolic(urb_errlist
, status
), fifon
);
682 rx_iso_complete(struct urb
*urb
)
684 iso_urb_struct
*context_iso_urb
= (iso_urb_struct
*) urb
->context
;
685 usb_fifo
*fifo
= context_iso_urb
->owner_fifo
;
686 hfcusb_data
*hfc
= fifo
->hfc
;
687 int k
, len
, errcode
, offset
, num_isoc_packets
, fifon
, maxlen
,
689 unsigned int iso_status
;
693 fifon
= fifo
->fifonum
;
694 status
= urb
->status
;
696 if (urb
->status
== -EOVERFLOW
) {
697 DBG(HFCUSB_DBG_VERBOSE_USB
,
698 "HFC-USB: ignoring USB DATAOVERRUN fifo(%i)", fifon
);
702 /* ISO transfer only partially completed,
703 look at individual frame status for details */
704 if (status
== -EXDEV
) {
705 DBG(HFCUSB_DBG_VERBOSE_USB
, "HFC-S USB: rx_iso_complete with -EXDEV "
706 "urb->status %d, fifonum %d\n",
711 if (fifo
->active
&& !status
) {
712 num_isoc_packets
= iso_packets
[fifon
];
713 maxlen
= fifo
->usb_packet_maxlen
;
714 for (k
= 0; k
< num_isoc_packets
; ++k
) {
715 len
= urb
->iso_frame_desc
[k
].actual_length
;
716 offset
= urb
->iso_frame_desc
[k
].offset
;
717 buf
= context_iso_urb
->buffer
+ offset
;
718 iso_status
= urb
->iso_frame_desc
[k
].status
;
720 if (iso_status
&& !hfc
->disc_flag
)
721 DBG(HFCUSB_DBG_VERBOSE_USB
,
722 "HFC-S USB: rx_iso_complete "
723 "ISO packet %i, status: %i\n",
726 if (fifon
== HFCUSB_D_RX
) {
727 DBG(HFCUSB_DBG_VERBOSE_USB
,
728 "HFC-S USB: ISO-D-RX lst_urblen:%2d "
729 "act_urblen:%2d max-urblen:%2d EOF:0x%0x",
730 fifo
->last_urblen
, len
, maxlen
,
733 DBG_PACKET(HFCUSB_DBG_VERBOSE_USB
, buf
, len
);
736 if (fifo
->last_urblen
!= maxlen
) {
737 /* the threshold mask is in the 2nd status byte */
738 hfc
->threshold_mask
= buf
[1];
739 /* care for L1 state only for D-Channel
740 to avoid overlapped iso completions */
741 if (fifon
== HFCUSB_D_RX
) {
742 /* the S0 state is in the upper half
743 of the 1st status byte */
744 s0_state_handler(hfc
, buf
[0] >> 4);
746 eof
[fifon
] = buf
[0] & 1;
748 collect_rx_frame(fifo
, buf
+ 2,
753 collect_rx_frame(fifo
, buf
, len
,
755 maxlen
) ? eof
[fifon
] :
758 fifo
->last_urblen
= len
;
761 fill_isoc_urb(urb
, fifo
->hfc
->dev
, fifo
->pipe
,
762 context_iso_urb
->buffer
, num_isoc_packets
,
763 fifo
->usb_packet_maxlen
, fifo
->intervall
,
764 rx_iso_complete
, urb
->context
);
765 errcode
= usb_submit_urb(urb
, GFP_ATOMIC
);
768 "HFC-S USB: error submitting ISO URB: %d\n",
772 if (status
&& !hfc
->disc_flag
) {
774 "HFC-S USB: rx_iso_complete : "
775 "urb->status %d, fifonum %d\n",
781 /* collect rx data from INT- and ISO-URBs */
783 collect_rx_frame(usb_fifo
* fifo
, __u8
* data
, int len
, int finish
)
785 hfcusb_data
*hfc
= fifo
->hfc
;
786 int transp_mode
, fifon
;
788 fifon
= fifo
->fifonum
;
790 if (fifon
< 4 && hfc
->b_mode
[fifon
/ 2] == L1_MODE_TRANS
)
794 fifo
->skbuff
= dev_alloc_skb(fifo
->max_size
+ 3);
797 "HFC-S USB: cannot allocate buffer for fifo(%d)\n",
803 if (fifo
->skbuff
->len
+ len
< fifo
->max_size
) {
804 memcpy(skb_put(fifo
->skbuff
, len
), data
, len
);
806 DBG(HFCUSB_DBG_FIFO_ERR
,
807 "HCF-USB: got frame exceeded fifo->max_size(%d) fifo(%d)",
808 fifo
->max_size
, fifon
);
809 DBG_SKB(HFCUSB_DBG_VERBOSE_USB
, fifo
->skbuff
);
810 skb_trim(fifo
->skbuff
, 0);
813 if (transp_mode
&& fifo
->skbuff
->len
>= 128) {
814 fifo
->hif
->l1l2(fifo
->hif
, PH_DATA
| INDICATION
,
819 /* we have a complete hdlc packet */
821 if ((!fifo
->skbuff
->data
[fifo
->skbuff
->len
- 1])
822 && (fifo
->skbuff
->len
> 3)) {
824 if (fifon
== HFCUSB_D_RX
) {
825 DBG(HFCUSB_DBG_DCHANNEL
,
826 "HFC-S USB: D-RX len(%d)", fifo
->skbuff
->len
);
827 DBG_SKB(HFCUSB_DBG_DCHANNEL
, fifo
->skbuff
);
830 /* remove CRC & status */
831 skb_trim(fifo
->skbuff
, fifo
->skbuff
->len
- 3);
832 if (fifon
== HFCUSB_PCM_RX
) {
833 fifo
->hif
->l1l2(fifo
->hif
,
834 PH_DATA_E
| INDICATION
,
837 fifo
->hif
->l1l2(fifo
->hif
,
838 PH_DATA
| INDICATION
,
840 fifo
->skbuff
= NULL
; /* buffer was freed from upper layer */
842 DBG(HFCUSB_DBG_FIFO_ERR
,
843 "HFC-S USB: ERROR frame len(%d) fifo(%d)",
844 fifo
->skbuff
->len
, fifon
);
845 DBG_SKB(HFCUSB_DBG_VERBOSE_USB
, fifo
->skbuff
);
846 skb_trim(fifo
->skbuff
, 0);
852 rx_int_complete(struct urb
*urb
)
856 __u8
*buf
, maxlen
, fifon
;
857 usb_fifo
*fifo
= (usb_fifo
*) urb
->context
;
858 hfcusb_data
*hfc
= fifo
->hfc
;
861 urb
->dev
= hfc
->dev
; /* security init */
863 fifon
= fifo
->fifonum
;
864 if ((!fifo
->active
) || (urb
->status
)) {
865 DBG(HFCUSB_DBG_INIT
, "HFC-S USB: RX-Fifo %i is going down (%i)",
868 fifo
->urb
->interval
= 0; /* cancel automatic rescheduling */
870 dev_kfree_skb_any(fifo
->skbuff
);
875 len
= urb
->actual_length
;
877 maxlen
= fifo
->usb_packet_maxlen
;
879 if (fifon
== HFCUSB_D_RX
) {
880 DBG(HFCUSB_DBG_VERBOSE_USB
,
881 "HFC-S USB: INT-D-RX lst_urblen:%2d "
882 "act_urblen:%2d max-urblen:%2d EOF:0x%0x",
883 fifo
->last_urblen
, len
, maxlen
,
885 DBG_PACKET(HFCUSB_DBG_VERBOSE_USB
, buf
, len
);
888 if (fifo
->last_urblen
!= fifo
->usb_packet_maxlen
) {
889 /* the threshold mask is in the 2nd status byte */
890 hfc
->threshold_mask
= buf
[1];
891 /* the S0 state is in the upper half of the 1st status byte */
892 s0_state_handler(hfc
, buf
[0] >> 4);
893 eof
[fifon
] = buf
[0] & 1;
894 /* if we have more than the 2 status bytes -> collect data */
896 collect_rx_frame(fifo
, buf
+ 2,
897 urb
->actual_length
- 2,
898 (len
< maxlen
) ? eof
[fifon
] : 0);
900 collect_rx_frame(fifo
, buf
, urb
->actual_length
,
901 (len
< maxlen
) ? eof
[fifon
] : 0);
903 fifo
->last_urblen
= urb
->actual_length
;
904 status
= usb_submit_urb(urb
, GFP_ATOMIC
);
907 "HFC-S USB: %s error resubmitting URB fifo(%d)\n",
908 __FUNCTION__
, fifon
);
912 /* start initial INT-URB for certain fifo */
914 start_int_fifo(usb_fifo
* fifo
)
918 DBG(HFCUSB_DBG_INIT
, "HFC-S USB: starting RX INT-URB for fifo:%d\n",
922 fifo
->urb
= usb_alloc_urb(0, GFP_KERNEL
);
926 usb_fill_int_urb(fifo
->urb
, fifo
->hfc
->dev
, fifo
->pipe
,
927 fifo
->buffer
, fifo
->usb_packet_maxlen
,
928 rx_int_complete
, fifo
, fifo
->intervall
);
929 fifo
->active
= 1; /* must be marked active */
930 errcode
= usb_submit_urb(fifo
->urb
, GFP_KERNEL
);
933 "HFC-S USB: submit URB error(start_int_info): status:%i\n",
941 setup_bchannel(hfcusb_data
* hfc
, int channel
, int mode
)
943 __u8 val
, idx_table
[2] = { 0, 2 };
945 if (hfc
->disc_flag
) {
948 DBG(HFCUSB_DBG_STATES
, "HFC-S USB: setting channel %d to mode %d",
950 hfc
->b_mode
[channel
] = mode
;
954 if (mode
!= L1_MODE_NULL
)
955 val
= 8; /* enable fifo? */
956 if (mode
== L1_MODE_TRANS
)
957 val
|= 2; /* set transparent bit */
959 /* set FIFO to transmit register */
960 queue_control_request(hfc
, HFCUSB_FIFO
, idx_table
[channel
], 1);
961 queue_control_request(hfc
, HFCUSB_CON_HDLC
, val
, 1);
963 queue_control_request(hfc
, HFCUSB_INC_RES_F
, 2, 1);
964 /* set FIFO to receive register */
965 queue_control_request(hfc
, HFCUSB_FIFO
, idx_table
[channel
] + 1, 1);
966 queue_control_request(hfc
, HFCUSB_CON_HDLC
, val
, 1);
968 queue_control_request(hfc
, HFCUSB_INC_RES_F
, 2, 1);
975 queue_control_request(hfc
, HFCUSB_SCTRL
, val
, 1);
982 queue_control_request(hfc
, HFCUSB_SCTRL_R
, val
, 1);
984 if (mode
== L1_MODE_NULL
) {
986 handle_led(hfc
, LED_B2_OFF
);
988 handle_led(hfc
, LED_B1_OFF
);
991 handle_led(hfc
, LED_B2_ON
);
993 handle_led(hfc
, LED_B1_ON
);
998 hfc_usb_l2l1(struct hisax_if
*my_hisax_if
, int pr
, void *arg
)
1000 usb_fifo
*fifo
= my_hisax_if
->priv
;
1001 hfcusb_data
*hfc
= fifo
->hfc
;
1004 case PH_ACTIVATE
| REQUEST
:
1005 if (fifo
->fifonum
== HFCUSB_D_TX
) {
1006 DBG(HFCUSB_DBG_STATES
,
1007 "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_ACTIVATE | REQUEST");
1009 if (hfc
->l1_state
!= 3
1010 && hfc
->l1_state
!= 7) {
1011 hfc
->d_if
.ifc
.l1l2(&hfc
->d_if
.ifc
,
1015 DBG(HFCUSB_DBG_STATES
,
1016 "HFC-S USB: PH_DEACTIVATE | INDICATION sent (not state 3 or 7)");
1018 if (hfc
->l1_state
== 7) { /* l1 already active */
1019 hfc
->d_if
.ifc
.l1l2(&hfc
->
1026 DBG(HFCUSB_DBG_STATES
,
1027 "HFC-S USB: PH_ACTIVATE | INDICATION sent again ;)");
1029 /* force sending sending INFO1 */
1030 queue_control_request(hfc
,
1035 /* start l1 activation */
1036 queue_control_request(hfc
,
1053 DBG(HFCUSB_DBG_STATES
,
1054 "HFC_USB: hfc_usb_d_l2l1 B-chan: PH_ACTIVATE | REQUEST");
1057 HFCUSB_B1_TX
) ? 0 : 1,
1059 fifo
->hif
->l1l2(fifo
->hif
,
1060 PH_ACTIVATE
| INDICATION
,
1064 case PH_DEACTIVATE
| REQUEST
:
1065 if (fifo
->fifonum
== HFCUSB_D_TX
) {
1066 DBG(HFCUSB_DBG_STATES
,
1067 "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_DEACTIVATE | REQUEST");
1069 DBG(HFCUSB_DBG_STATES
,
1070 "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_DEACTIVATE | REQUEST");
1073 HFCUSB_B1_TX
) ? 0 : 1,
1074 (int) L1_MODE_NULL
);
1075 fifo
->hif
->l1l2(fifo
->hif
,
1076 PH_DEACTIVATE
| INDICATION
,
1080 case PH_DATA
| REQUEST
:
1081 if (fifo
->skbuff
&& fifo
->delete_flg
) {
1082 dev_kfree_skb_any(fifo
->skbuff
);
1083 fifo
->skbuff
= NULL
;
1084 fifo
->delete_flg
= 0;
1086 fifo
->skbuff
= arg
; /* we have a new buffer */
1089 DBG(HFCUSB_DBG_STATES
,
1090 "HFC_USB: hfc_usb_d_l2l1: unkown state : %#x", pr
);
1095 /* initial init HFC-S USB chip registers, HiSax interface, USB URBs */
1097 hfc_usb_init(hfcusb_data
* hfc
)
1102 struct hisax_b_if
*p_b_if
[2];
1104 /* check the chip id */
1105 if (read_usb(hfc
, HFCUSB_CHIP_ID
, &b
) != 1) {
1106 printk(KERN_INFO
"HFC-USB: cannot read chip id\n");
1109 if (b
!= HFCUSB_CHIPID
) {
1110 printk(KERN_INFO
"HFC-S USB: Invalid chip id 0x%02x\n", b
);
1114 /* first set the needed config, interface and alternate */
1115 err
= usb_set_interface(hfc
->dev
, hfc
->if_used
, hfc
->alt_used
);
1118 write_usb(hfc
, HFCUSB_CIRM
, 8);
1119 /* aux = output, reset off */
1120 write_usb(hfc
, HFCUSB_CIRM
, 0x10);
1122 /* set USB_SIZE to match wMaxPacketSize for INT or BULK transfers */
1123 write_usb(hfc
, HFCUSB_USB_SIZE
,
1124 (hfc
->packet_size
/ 8) | ((hfc
->packet_size
/ 8) << 4));
1126 /* set USB_SIZE_I to match wMaxPacketSize for ISO transfers */
1127 write_usb(hfc
, HFCUSB_USB_SIZE_I
, hfc
->iso_packet_size
);
1129 /* enable PCM/GCI master mode */
1130 write_usb(hfc
, HFCUSB_MST_MODE1
, 0); /* set default values */
1131 write_usb(hfc
, HFCUSB_MST_MODE0
, 1); /* enable master mode */
1133 /* init the fifos */
1134 write_usb(hfc
, HFCUSB_F_THRES
,
1135 (HFCUSB_TX_THRESHOLD
/
1136 8) | ((HFCUSB_RX_THRESHOLD
/ 8) << 4));
1139 for (i
= 0; i
< HFCUSB_NUM_FIFOS
; i
++) {
1140 write_usb(hfc
, HFCUSB_FIFO
, i
); /* select the desired fifo */
1141 fifo
[i
].skbuff
= NULL
; /* init buffer pointer */
1143 (i
<= HFCUSB_B2_RX
) ? MAX_BCH_SIZE
: MAX_DFRAME_LEN
;
1144 fifo
[i
].last_urblen
= 0;
1145 /* set 2 bit for D- & E-channel */
1146 write_usb(hfc
, HFCUSB_HDLC_PAR
,
1147 ((i
<= HFCUSB_B2_RX
) ? 0 : 2));
1148 /* rx hdlc, enable IFF for D-channel */
1149 write_usb(hfc
, HFCUSB_CON_HDLC
,
1150 ((i
== HFCUSB_D_TX
) ? 0x09 : 0x08));
1151 write_usb(hfc
, HFCUSB_INC_RES_F
, 2); /* reset the fifo */
1154 write_usb(hfc
, HFCUSB_CLKDEL
, 0x0f); /* clock delay value */
1155 write_usb(hfc
, HFCUSB_STATES
, 3 | 0x10); /* set deactivated mode */
1156 write_usb(hfc
, HFCUSB_STATES
, 3); /* enable state machine */
1158 write_usb(hfc
, HFCUSB_SCTRL_R
, 0); /* disable both B receivers */
1159 write_usb(hfc
, HFCUSB_SCTRL
, 0x40); /* disable B transmitters + capacitive mode */
1161 /* set both B-channel to not connected */
1162 hfc
->b_mode
[0] = L1_MODE_NULL
;
1163 hfc
->b_mode
[1] = L1_MODE_NULL
;
1165 hfc
->l1_activated
= 0;
1168 hfc
->old_led_state
= 0;
1170 /* init the t3 timer */
1171 init_timer(&hfc
->t3_timer
);
1172 hfc
->t3_timer
.data
= (long) hfc
;
1173 hfc
->t3_timer
.function
= (void *) l1_timer_expire_t3
;
1175 /* init the t4 timer */
1176 init_timer(&hfc
->t4_timer
);
1177 hfc
->t4_timer
.data
= (long) hfc
;
1178 hfc
->t4_timer
.function
= (void *) l1_timer_expire_t4
;
1180 /* init the background machinery for control requests */
1181 hfc
->ctrl_read
.bRequestType
= 0xc0;
1182 hfc
->ctrl_read
.bRequest
= 1;
1183 hfc
->ctrl_read
.wLength
= cpu_to_le16(1);
1184 hfc
->ctrl_write
.bRequestType
= 0x40;
1185 hfc
->ctrl_write
.bRequest
= 0;
1186 hfc
->ctrl_write
.wLength
= 0;
1187 usb_fill_control_urb(hfc
->ctrl_urb
,
1190 (u_char
*) & hfc
->ctrl_write
,
1191 NULL
, 0, ctrl_complete
, hfc
);
1192 /* Init All Fifos */
1193 for (i
= 0; i
< HFCUSB_NUM_FIFOS
; i
++) {
1194 hfc
->fifos
[i
].iso
[0].purb
= NULL
;
1195 hfc
->fifos
[i
].iso
[1].purb
= NULL
;
1196 hfc
->fifos
[i
].active
= 0;
1198 /* register Modul to upper Hisax Layers */
1199 hfc
->d_if
.owner
= THIS_MODULE
;
1200 hfc
->d_if
.ifc
.priv
= &hfc
->fifos
[HFCUSB_D_TX
];
1201 hfc
->d_if
.ifc
.l2l1
= hfc_usb_l2l1
;
1202 for (i
= 0; i
< 2; i
++) {
1203 hfc
->b_if
[i
].ifc
.priv
= &hfc
->fifos
[HFCUSB_B1_TX
+ i
* 2];
1204 hfc
->b_if
[i
].ifc
.l2l1
= hfc_usb_l2l1
;
1205 p_b_if
[i
] = &hfc
->b_if
[i
];
1207 /* default Prot: EURO ISDN, should be a module_param */
1209 i
= hisax_register(&hfc
->d_if
, p_b_if
, "hfc_usb", hfc
->protocol
);
1211 printk(KERN_INFO
"HFC-S USB: hisax_register -> %d\n", i
);
1215 #ifdef CONFIG_HISAX_DEBUG
1219 for (i
= 0; i
< 4; i
++)
1220 hfc
->fifos
[i
].hif
= &p_b_if
[i
/ 2]->ifc
;
1221 for (i
= 4; i
< 8; i
++)
1222 hfc
->fifos
[i
].hif
= &hfc
->d_if
.ifc
;
1224 /* 3 (+1) INT IN + 3 ISO OUT */
1225 if (hfc
->cfg_used
== CNF_3INT3ISO
|| hfc
->cfg_used
== CNF_4INT3ISO
) {
1226 start_int_fifo(hfc
->fifos
+ HFCUSB_D_RX
);
1227 if (hfc
->fifos
[HFCUSB_PCM_RX
].pipe
)
1228 start_int_fifo(hfc
->fifos
+ HFCUSB_PCM_RX
);
1229 start_int_fifo(hfc
->fifos
+ HFCUSB_B1_RX
);
1230 start_int_fifo(hfc
->fifos
+ HFCUSB_B2_RX
);
1232 /* 3 (+1) ISO IN + 3 ISO OUT */
1233 if (hfc
->cfg_used
== CNF_3ISO3ISO
|| hfc
->cfg_used
== CNF_4ISO3ISO
) {
1234 start_isoc_chain(hfc
->fifos
+ HFCUSB_D_RX
, ISOC_PACKETS_D
,
1235 rx_iso_complete
, 16);
1236 if (hfc
->fifos
[HFCUSB_PCM_RX
].pipe
)
1237 start_isoc_chain(hfc
->fifos
+ HFCUSB_PCM_RX
,
1238 ISOC_PACKETS_D
, rx_iso_complete
,
1240 start_isoc_chain(hfc
->fifos
+ HFCUSB_B1_RX
, ISOC_PACKETS_B
,
1241 rx_iso_complete
, 16);
1242 start_isoc_chain(hfc
->fifos
+ HFCUSB_B2_RX
, ISOC_PACKETS_B
,
1243 rx_iso_complete
, 16);
1246 start_isoc_chain(hfc
->fifos
+ HFCUSB_D_TX
, ISOC_PACKETS_D
,
1247 tx_iso_complete
, 1);
1248 start_isoc_chain(hfc
->fifos
+ HFCUSB_B1_TX
, ISOC_PACKETS_B
,
1249 tx_iso_complete
, 1);
1250 start_isoc_chain(hfc
->fifos
+ HFCUSB_B2_TX
, ISOC_PACKETS_B
,
1251 tx_iso_complete
, 1);
1253 handle_led(hfc
, LED_POWER_ON
);
1258 /* initial callback for each plugged USB device */
1260 hfc_usb_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
)
1262 struct usb_device
*dev
= interface_to_usbdev(intf
);
1263 hfcusb_data
*context
;
1264 struct usb_host_interface
*iface
= intf
->cur_altsetting
;
1265 struct usb_host_interface
*iface_used
= NULL
;
1266 struct usb_host_endpoint
*ep
;
1267 int ifnum
= iface
->desc
.bInterfaceNumber
;
1268 int i
, idx
, alt_idx
, probe_alt_setting
, vend_idx
, cfg_used
, *vcf
,
1269 attr
, cfg_found
, cidx
, ep_addr
;
1270 int cmptbl
[16], small_match
, iso_packet_size
, packet_size
,
1272 hfcsusb_vdata
*driver_info
;
1275 for (i
= 0; hfcusb_idtab
[i
].idVendor
; i
++) {
1276 if ((le16_to_cpu(dev
->descriptor
.idVendor
) == hfcusb_idtab
[i
].idVendor
)
1277 && (le16_to_cpu(dev
->descriptor
.idProduct
) == hfcusb_idtab
[i
].idProduct
)) {
1284 "HFC-S USB: probing interface(%d) actalt(%d) minor(%d)\n",
1285 ifnum
, iface
->desc
.bAlternateSetting
, intf
->minor
);
1287 if (vend_idx
!= 0xffff) {
1288 /* if vendor and product ID is OK, start probing alternate settings */
1290 small_match
= 0xffff;
1292 /* default settings */
1293 iso_packet_size
= 16;
1296 while (alt_idx
< intf
->num_altsetting
) {
1297 iface
= intf
->altsetting
+ alt_idx
;
1298 probe_alt_setting
= iface
->desc
.bAlternateSetting
;
1301 /* check for config EOL element */
1302 while (validconf
[cfg_used
][0]) {
1304 vcf
= validconf
[cfg_used
];
1305 /* first endpoint descriptor */
1306 ep
= iface
->endpoint
;
1308 memcpy(cmptbl
, vcf
, 16 * sizeof(int));
1310 /* check for all endpoints in this alternate setting */
1311 for (i
= 0; i
< iface
->desc
.bNumEndpoints
;
1314 ep
->desc
.bEndpointAddress
;
1315 /* get endpoint base */
1316 idx
= ((ep_addr
& 0x7f) - 1) * 2;
1319 attr
= ep
->desc
.bmAttributes
;
1320 if (cmptbl
[idx
] == EP_NUL
) {
1323 if (attr
== USB_ENDPOINT_XFER_INT
1324 && cmptbl
[idx
] == EP_INT
)
1325 cmptbl
[idx
] = EP_NUL
;
1326 if (attr
== USB_ENDPOINT_XFER_BULK
1327 && cmptbl
[idx
] == EP_BLK
)
1328 cmptbl
[idx
] = EP_NUL
;
1329 if (attr
== USB_ENDPOINT_XFER_ISOC
1330 && cmptbl
[idx
] == EP_ISO
)
1331 cmptbl
[idx
] = EP_NUL
;
1333 /* check if all INT endpoints match minimum interval */
1334 if ((attr
== USB_ENDPOINT_XFER_INT
)
1335 && (ep
->desc
.bInterval
< vcf
[17])) {
1340 for (i
= 0; i
< 16; i
++) {
1341 /* all entries must be EP_NOP or EP_NUL for a valid config */
1342 if (cmptbl
[i
] != EP_NOP
1343 && cmptbl
[i
] != EP_NUL
)
1347 if (cfg_used
< small_match
) {
1348 small_match
= cfg_used
;
1357 } /* (alt_idx < intf->num_altsetting) */
1359 /* found a valid USB Ta Endpint config */
1360 if (small_match
!= 0xffff) {
1362 if (!(context
= kzalloc(sizeof(hfcusb_data
), GFP_KERNEL
)))
1363 return (-ENOMEM
); /* got no mem */
1365 ep
= iface
->endpoint
;
1366 vcf
= validconf
[small_match
];
1368 for (i
= 0; i
< iface
->desc
.bNumEndpoints
; i
++) {
1369 ep_addr
= ep
->desc
.bEndpointAddress
;
1370 /* get endpoint base */
1371 idx
= ((ep_addr
& 0x7f) - 1) * 2;
1375 attr
= ep
->desc
.bmAttributes
;
1377 /* init Endpoints */
1378 if (vcf
[idx
] != EP_NOP
1379 && vcf
[idx
] != EP_NUL
) {
1381 case USB_ENDPOINT_XFER_INT
:
1394 le16_to_cpu(ep
->desc
.wMaxPacketSize
);
1396 case USB_ENDPOINT_XFER_BULK
:
1422 le16_to_cpu(ep
->desc
.wMaxPacketSize
);
1424 case USB_ENDPOINT_XFER_ISOC
:
1450 le16_to_cpu(ep
->desc
.wMaxPacketSize
);
1456 } /* switch attribute */
1458 if (context
->fifos
[cidx
].pipe
) {
1459 context
->fifos
[cidx
].
1461 context
->fifos
[cidx
].hfc
=
1463 context
->fifos
[cidx
].usb_packet_maxlen
=
1464 le16_to_cpu(ep
->desc
.wMaxPacketSize
);
1465 context
->fifos
[cidx
].
1468 context
->fifos
[cidx
].
1474 context
->dev
= dev
; /* save device */
1475 context
->if_used
= ifnum
; /* save used interface */
1476 context
->alt_used
= alt_used
; /* and alternate config */
1477 context
->ctrl_paksize
= dev
->descriptor
.bMaxPacketSize0
; /* control size */
1478 context
->cfg_used
= vcf
[16]; /* store used config */
1479 context
->vend_idx
= vend_idx
; /* store found vendor */
1480 context
->packet_size
= packet_size
;
1481 context
->iso_packet_size
= iso_packet_size
;
1483 /* create the control pipes needed for register access */
1484 context
->ctrl_in_pipe
=
1485 usb_rcvctrlpipe(context
->dev
, 0);
1486 context
->ctrl_out_pipe
=
1487 usb_sndctrlpipe(context
->dev
, 0);
1488 context
->ctrl_urb
= usb_alloc_urb(0, GFP_KERNEL
);
1491 (hfcsusb_vdata
*) hfcusb_idtab
[vend_idx
].
1493 printk(KERN_INFO
"HFC-S USB: detected \"%s\"\n",
1494 driver_info
->vend_name
);
1496 DBG(HFCUSB_DBG_INIT
,
1497 "HFC-S USB: Endpoint-Config: %s (if=%d alt=%d), E-Channel(%d)",
1498 conf_str
[small_match
], context
->if_used
,
1500 validconf
[small_match
][18]);
1502 /* init the chip and register the driver */
1503 if (hfc_usb_init(context
)) {
1504 usb_kill_urb(context
->ctrl_urb
);
1505 usb_free_urb(context
->ctrl_urb
);
1506 context
->ctrl_urb
= NULL
;
1510 usb_set_intfdata(intf
, context
);
1515 "HFC-S USB: no valid vendor found in USB descriptor\n");
1520 /* callback for unplugged USB device */
1522 hfc_usb_disconnect(struct usb_interface
*intf
)
1524 hfcusb_data
*context
= usb_get_intfdata(intf
);
1527 handle_led(context
, LED_POWER_OFF
);
1528 schedule_timeout(HZ
/ 100);
1530 printk(KERN_INFO
"HFC-S USB: device disconnect\n");
1531 context
->disc_flag
= 1;
1532 usb_set_intfdata(intf
, NULL
);
1534 if (timer_pending(&context
->t3_timer
))
1535 del_timer(&context
->t3_timer
);
1536 if (timer_pending(&context
->t4_timer
))
1537 del_timer(&context
->t4_timer
);
1539 /* tell all fifos to terminate */
1540 for (i
= 0; i
< HFCUSB_NUM_FIFOS
; i
++) {
1541 if (context
->fifos
[i
].usb_transfer_mode
== USB_ISOC
) {
1542 if (context
->fifos
[i
].active
> 0) {
1543 stop_isoc_chain(&context
->fifos
[i
]);
1544 DBG(HFCUSB_DBG_INIT
,
1545 "HFC-S USB: %s stopping ISOC chain Fifo(%i)",
1549 if (context
->fifos
[i
].active
> 0) {
1550 context
->fifos
[i
].active
= 0;
1551 DBG(HFCUSB_DBG_INIT
,
1552 "HFC-S USB: %s unlinking URB for Fifo(%i)",
1555 usb_kill_urb(context
->fifos
[i
].urb
);
1556 usb_free_urb(context
->fifos
[i
].urb
);
1557 context
->fifos
[i
].urb
= NULL
;
1559 context
->fifos
[i
].active
= 0;
1561 usb_kill_urb(context
->ctrl_urb
);
1562 usb_free_urb(context
->ctrl_urb
);
1563 context
->ctrl_urb
= NULL
;
1564 hisax_unregister(&context
->d_if
);
1565 kfree(context
); /* free our structure again */
1568 static struct usb_driver hfc_drv
= {
1570 .id_table
= hfcusb_idtab
,
1571 .probe
= hfc_usb_probe
,
1572 .disconnect
= hfc_usb_disconnect
,
1576 hfc_usb_mod_exit(void)
1578 usb_deregister(&hfc_drv
); /* release our driver */
1579 printk(KERN_INFO
"HFC-S USB: module removed\n");
1583 hfc_usb_mod_init(void)
1585 char revstr
[30], datestr
[30], dummy
[30];
1586 #ifndef CONFIG_HISAX_DEBUG
1589 sscanf(hfcusb_revision
,
1590 "%s %s $ %s %s %s $ ", dummy
, revstr
,
1591 dummy
, datestr
, dummy
);
1593 "HFC-S USB: driver module revision %s date %s loaded, (debug=%i)\n",
1594 revstr
, datestr
, debug
);
1595 if (usb_register(&hfc_drv
)) {
1597 "HFC-S USB: Unable to register HFC-S USB module at usb stack\n");
1598 return (-1); /* unable to register */
1603 module_init(hfc_usb_mod_init
);
1604 module_exit(hfc_usb_mod_exit
);
1605 MODULE_AUTHOR(DRIVER_AUTHOR
);
1606 MODULE_DESCRIPTION(DRIVER_DESC
);
1607 MODULE_LICENSE("GPL");
1608 MODULE_DEVICE_TABLE(usb
, hfcusb_idtab
);