2 * mISDN driver for Colognechip HFC-S USB chip
4 * Copyright 2001 by Peter Sprenger (sprenger@moving-bytes.de)
5 * Copyright 2008 by Martin Bachem (info@bachem-it.com)
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * debug=<n>, default=0, with n=0xHHHHGGGG
24 * H - l1 driver flags described in hfcsusb.h
25 * G - common mISDN debug flags described at mISDNhw.h
27 * poll=<n>, default 128
28 * n : burst size of PH_DATA_IND at transparent rx data
32 #include <linux/module.h>
33 #include <linux/delay.h>
34 #include <linux/usb.h>
35 #include <linux/mISDNhw.h>
36 #include <linux/slab.h>
39 static const char *hfcsusb_rev
= "Revision: 0.3.3 (socket), 2008-11-05";
41 static unsigned int debug
;
42 static int poll
= DEFAULT_TRANSP_BURST_SZ
;
44 static LIST_HEAD(HFClist
);
45 static DEFINE_RWLOCK(HFClock
);
48 MODULE_AUTHOR("Martin Bachem");
49 MODULE_LICENSE("GPL");
50 module_param(debug
, uint
, S_IRUGO
| S_IWUSR
);
51 module_param(poll
, int, 0);
53 static int hfcsusb_cnt
;
55 /* some function prototypes */
56 static void hfcsusb_ph_command(struct hfcsusb
*hw
, u_char command
);
57 static void release_hw(struct hfcsusb
*hw
);
58 static void reset_hfcsusb(struct hfcsusb
*hw
);
59 static void setPortMode(struct hfcsusb
*hw
);
60 static void hfcsusb_start_endpoint(struct hfcsusb
*hw
, int channel
);
61 static void hfcsusb_stop_endpoint(struct hfcsusb
*hw
, int channel
);
62 static int hfcsusb_setup_bch(struct bchannel
*bch
, int protocol
);
63 static void deactivate_bchannel(struct bchannel
*bch
);
64 static void hfcsusb_ph_info(struct hfcsusb
*hw
);
66 /* start next background transfer for control channel */
68 ctrl_start_transfer(struct hfcsusb
*hw
)
70 if (debug
& DBG_HFC_CALL_TRACE
)
71 printk(KERN_DEBUG
"%s: %s\n", hw
->name
, __func__
);
74 hw
->ctrl_urb
->pipe
= hw
->ctrl_out_pipe
;
75 hw
->ctrl_urb
->setup_packet
= (u_char
*)&hw
->ctrl_write
;
76 hw
->ctrl_urb
->transfer_buffer
= NULL
;
77 hw
->ctrl_urb
->transfer_buffer_length
= 0;
78 hw
->ctrl_write
.wIndex
=
79 cpu_to_le16(hw
->ctrl_buff
[hw
->ctrl_out_idx
].hfcs_reg
);
80 hw
->ctrl_write
.wValue
=
81 cpu_to_le16(hw
->ctrl_buff
[hw
->ctrl_out_idx
].reg_val
);
83 usb_submit_urb(hw
->ctrl_urb
, GFP_ATOMIC
);
88 * queue a control transfer request to write HFC-S USB
89 * chip register using CTRL resuest queue
91 static int write_reg(struct hfcsusb
*hw
, __u8 reg
, __u8 val
)
95 if (debug
& DBG_HFC_CALL_TRACE
)
96 printk(KERN_DEBUG
"%s: %s reg(0x%02x) val(0x%02x)\n",
97 hw
->name
, __func__
, reg
, val
);
99 spin_lock(&hw
->ctrl_lock
);
100 if (hw
->ctrl_cnt
>= HFC_CTRL_BUFSIZE
) {
101 spin_unlock(&hw
->ctrl_lock
);
104 buf
= &hw
->ctrl_buff
[hw
->ctrl_in_idx
];
107 if (++hw
->ctrl_in_idx
>= HFC_CTRL_BUFSIZE
)
109 if (++hw
->ctrl_cnt
== 1)
110 ctrl_start_transfer(hw
);
111 spin_unlock(&hw
->ctrl_lock
);
116 /* control completion routine handling background control cmds */
118 ctrl_complete(struct urb
*urb
)
120 struct hfcsusb
*hw
= (struct hfcsusb
*) urb
->context
;
122 if (debug
& DBG_HFC_CALL_TRACE
)
123 printk(KERN_DEBUG
"%s: %s\n", hw
->name
, __func__
);
127 hw
->ctrl_cnt
--; /* decrement actual count */
128 if (++hw
->ctrl_out_idx
>= HFC_CTRL_BUFSIZE
)
129 hw
->ctrl_out_idx
= 0; /* pointer wrap */
131 ctrl_start_transfer(hw
); /* start next transfer */
135 /* handle LED bits */
137 set_led_bit(struct hfcsusb
*hw
, signed short led_bits
, int set_on
)
141 hw
->led_state
&= ~abs(led_bits
);
143 hw
->led_state
|= led_bits
;
146 hw
->led_state
|= abs(led_bits
);
148 hw
->led_state
&= ~led_bits
;
152 /* handle LED requests */
154 handle_led(struct hfcsusb
*hw
, int event
)
156 struct hfcsusb_vdata
*driver_info
= (struct hfcsusb_vdata
*)
157 hfcsusb_idtab
[hw
->vend_idx
].driver_info
;
160 if (driver_info
->led_scheme
== LED_OFF
)
162 tmpled
= hw
->led_state
;
166 set_led_bit(hw
, driver_info
->led_bits
[0], 1);
167 set_led_bit(hw
, driver_info
->led_bits
[1], 0);
168 set_led_bit(hw
, driver_info
->led_bits
[2], 0);
169 set_led_bit(hw
, driver_info
->led_bits
[3], 0);
172 set_led_bit(hw
, driver_info
->led_bits
[0], 0);
173 set_led_bit(hw
, driver_info
->led_bits
[1], 0);
174 set_led_bit(hw
, driver_info
->led_bits
[2], 0);
175 set_led_bit(hw
, driver_info
->led_bits
[3], 0);
178 set_led_bit(hw
, driver_info
->led_bits
[1], 1);
181 set_led_bit(hw
, driver_info
->led_bits
[1], 0);
184 set_led_bit(hw
, driver_info
->led_bits
[2], 1);
187 set_led_bit(hw
, driver_info
->led_bits
[2], 0);
190 set_led_bit(hw
, driver_info
->led_bits
[3], 1);
193 set_led_bit(hw
, driver_info
->led_bits
[3], 0);
197 if (hw
->led_state
!= tmpled
) {
198 if (debug
& DBG_HFC_CALL_TRACE
)
199 printk(KERN_DEBUG
"%s: %s reg(0x%02x) val(x%02x)\n",
201 HFCUSB_P_DATA
, hw
->led_state
);
203 write_reg(hw
, HFCUSB_P_DATA
, hw
->led_state
);
208 * Layer2 -> Layer 1 Bchannel data
211 hfcusb_l2l1B(struct mISDNchannel
*ch
, struct sk_buff
*skb
)
213 struct bchannel
*bch
= container_of(ch
, struct bchannel
, ch
);
214 struct hfcsusb
*hw
= bch
->hw
;
216 struct mISDNhead
*hh
= mISDN_HEAD_P(skb
);
219 if (debug
& DBG_HFC_CALL_TRACE
)
220 printk(KERN_DEBUG
"%s: %s\n", hw
->name
, __func__
);
224 spin_lock_irqsave(&hw
->lock
, flags
);
225 ret
= bchannel_senddata(bch
, skb
);
226 spin_unlock_irqrestore(&hw
->lock
, flags
);
227 if (debug
& DBG_HFC_CALL_TRACE
)
228 printk(KERN_DEBUG
"%s: %s PH_DATA_REQ ret(%i)\n",
229 hw
->name
, __func__
, ret
);
232 * other l1 drivers don't send early confirms on
233 * transp data, but hfcsusb does because tx_next
234 * skb is needed in tx_iso_complete()
236 queue_ch_frame(ch
, PH_DATA_CNF
, hh
->id
, NULL
);
240 case PH_ACTIVATE_REQ
:
241 if (!test_and_set_bit(FLG_ACTIVE
, &bch
->Flags
)) {
242 hfcsusb_start_endpoint(hw
, bch
->nr
);
243 ret
= hfcsusb_setup_bch(bch
, ch
->protocol
);
247 _queue_data(ch
, PH_ACTIVATE_IND
, MISDN_ID_ANY
,
248 0, NULL
, GFP_KERNEL
);
250 case PH_DEACTIVATE_REQ
:
251 deactivate_bchannel(bch
);
252 _queue_data(ch
, PH_DEACTIVATE_IND
, MISDN_ID_ANY
,
253 0, NULL
, GFP_KERNEL
);
263 * send full D/B channel status information
264 * as MPH_INFORMATION_IND
267 hfcsusb_ph_info(struct hfcsusb
*hw
)
270 struct dchannel
*dch
= &hw
->dch
;
273 phi
= kzalloc(sizeof(struct ph_info
) +
274 dch
->dev
.nrbchan
* sizeof(struct ph_info_ch
), GFP_ATOMIC
);
275 phi
->dch
.ch
.protocol
= hw
->protocol
;
276 phi
->dch
.ch
.Flags
= dch
->Flags
;
277 phi
->dch
.state
= dch
->state
;
278 phi
->dch
.num_bch
= dch
->dev
.nrbchan
;
279 for (i
= 0; i
< dch
->dev
.nrbchan
; i
++) {
280 phi
->bch
[i
].protocol
= hw
->bch
[i
].ch
.protocol
;
281 phi
->bch
[i
].Flags
= hw
->bch
[i
].Flags
;
283 _queue_data(&dch
->dev
.D
, MPH_INFORMATION_IND
, MISDN_ID_ANY
,
284 sizeof(struct ph_info_dch
) + dch
->dev
.nrbchan
*
285 sizeof(struct ph_info_ch
), phi
, GFP_ATOMIC
);
290 * Layer2 -> Layer 1 Dchannel data
293 hfcusb_l2l1D(struct mISDNchannel
*ch
, struct sk_buff
*skb
)
295 struct mISDNdevice
*dev
= container_of(ch
, struct mISDNdevice
, D
);
296 struct dchannel
*dch
= container_of(dev
, struct dchannel
, dev
);
297 struct mISDNhead
*hh
= mISDN_HEAD_P(skb
);
298 struct hfcsusb
*hw
= dch
->hw
;
304 if (debug
& DBG_HFC_CALL_TRACE
)
305 printk(KERN_DEBUG
"%s: %s: PH_DATA_REQ\n",
308 spin_lock_irqsave(&hw
->lock
, flags
);
309 ret
= dchannel_senddata(dch
, skb
);
310 spin_unlock_irqrestore(&hw
->lock
, flags
);
313 queue_ch_frame(ch
, PH_DATA_CNF
, hh
->id
, NULL
);
317 case PH_ACTIVATE_REQ
:
318 if (debug
& DBG_HFC_CALL_TRACE
)
319 printk(KERN_DEBUG
"%s: %s: PH_ACTIVATE_REQ %s\n",
321 (hw
->protocol
== ISDN_P_NT_S0
) ? "NT" : "TE");
323 if (hw
->protocol
== ISDN_P_NT_S0
) {
325 if (test_bit(FLG_ACTIVE
, &dch
->Flags
)) {
326 _queue_data(&dch
->dev
.D
,
327 PH_ACTIVATE_IND
, MISDN_ID_ANY
, 0,
330 hfcsusb_ph_command(hw
,
332 test_and_set_bit(FLG_L2_ACTIVATED
,
336 hfcsusb_ph_command(hw
, HFC_L1_ACTIVATE_TE
);
337 ret
= l1_event(dch
->l1
, hh
->prim
);
341 case PH_DEACTIVATE_REQ
:
342 if (debug
& DBG_HFC_CALL_TRACE
)
343 printk(KERN_DEBUG
"%s: %s: PH_DEACTIVATE_REQ\n",
345 test_and_clear_bit(FLG_L2_ACTIVATED
, &dch
->Flags
);
347 if (hw
->protocol
== ISDN_P_NT_S0
) {
348 hfcsusb_ph_command(hw
, HFC_L1_DEACTIVATE_NT
);
349 spin_lock_irqsave(&hw
->lock
, flags
);
350 skb_queue_purge(&dch
->squeue
);
352 dev_kfree_skb(dch
->tx_skb
);
357 dev_kfree_skb(dch
->rx_skb
);
360 test_and_clear_bit(FLG_TX_BUSY
, &dch
->Flags
);
361 spin_unlock_irqrestore(&hw
->lock
, flags
);
363 if (test_and_clear_bit(FLG_L1_BUSY
, &dch
->Flags
))
364 dchannel_sched_event(&hc
->dch
, D_CLEARBUSY
);
368 ret
= l1_event(dch
->l1
, hh
->prim
);
370 case MPH_INFORMATION_REQ
:
380 * Layer 1 callback function
383 hfc_l1callback(struct dchannel
*dch
, u_int cmd
)
385 struct hfcsusb
*hw
= dch
->hw
;
387 if (debug
& DBG_HFC_CALL_TRACE
)
388 printk(KERN_DEBUG
"%s: %s cmd 0x%x\n",
389 hw
->name
, __func__
, cmd
);
399 skb_queue_purge(&dch
->squeue
);
401 dev_kfree_skb(dch
->tx_skb
);
406 dev_kfree_skb(dch
->rx_skb
);
409 test_and_clear_bit(FLG_TX_BUSY
, &dch
->Flags
);
411 case PH_ACTIVATE_IND
:
412 test_and_set_bit(FLG_ACTIVE
, &dch
->Flags
);
413 _queue_data(&dch
->dev
.D
, cmd
, MISDN_ID_ANY
, 0, NULL
,
416 case PH_DEACTIVATE_IND
:
417 test_and_clear_bit(FLG_ACTIVE
, &dch
->Flags
);
418 _queue_data(&dch
->dev
.D
, cmd
, MISDN_ID_ANY
, 0, NULL
,
422 if (dch
->debug
& DEBUG_HW
)
423 printk(KERN_DEBUG
"%s: %s: unknown cmd %x\n",
424 hw
->name
, __func__
, cmd
);
432 open_dchannel(struct hfcsusb
*hw
, struct mISDNchannel
*ch
,
433 struct channel_req
*rq
)
437 if (debug
& DEBUG_HW_OPEN
)
438 printk(KERN_DEBUG
"%s: %s: dev(%d) open addr(%i) from %p\n",
439 hw
->name
, __func__
, hw
->dch
.dev
.id
, rq
->adr
.channel
,
440 __builtin_return_address(0));
441 if (rq
->protocol
== ISDN_P_NONE
)
444 test_and_clear_bit(FLG_ACTIVE
, &hw
->dch
.Flags
);
445 test_and_clear_bit(FLG_ACTIVE
, &hw
->ech
.Flags
);
446 hfcsusb_start_endpoint(hw
, HFC_CHAN_D
);
448 /* E-Channel logging */
449 if (rq
->adr
.channel
== 1) {
450 if (hw
->fifos
[HFCUSB_PCM_RX
].pipe
) {
451 hfcsusb_start_endpoint(hw
, HFC_CHAN_E
);
452 set_bit(FLG_ACTIVE
, &hw
->ech
.Flags
);
453 _queue_data(&hw
->ech
.dev
.D
, PH_ACTIVATE_IND
,
454 MISDN_ID_ANY
, 0, NULL
, GFP_ATOMIC
);
460 hw
->protocol
= rq
->protocol
;
461 if (rq
->protocol
== ISDN_P_TE_S0
) {
462 err
= create_l1(&hw
->dch
, hfc_l1callback
);
467 ch
->protocol
= rq
->protocol
;
470 if (rq
->protocol
!= ch
->protocol
)
471 return -EPROTONOSUPPORT
;
474 if (((ch
->protocol
== ISDN_P_NT_S0
) && (hw
->dch
.state
== 3)) ||
475 ((ch
->protocol
== ISDN_P_TE_S0
) && (hw
->dch
.state
== 7)))
476 _queue_data(ch
, PH_ACTIVATE_IND
, MISDN_ID_ANY
,
477 0, NULL
, GFP_KERNEL
);
479 if (!try_module_get(THIS_MODULE
))
480 printk(KERN_WARNING
"%s: %s: cannot get module\n",
486 open_bchannel(struct hfcsusb
*hw
, struct channel_req
*rq
)
488 struct bchannel
*bch
;
490 if (rq
->adr
.channel
> 2)
492 if (rq
->protocol
== ISDN_P_NONE
)
495 if (debug
& DBG_HFC_CALL_TRACE
)
496 printk(KERN_DEBUG
"%s: %s B%i\n",
497 hw
->name
, __func__
, rq
->adr
.channel
);
499 bch
= &hw
->bch
[rq
->adr
.channel
- 1];
500 if (test_and_set_bit(FLG_OPEN
, &bch
->Flags
))
501 return -EBUSY
; /* b-channel can be only open once */
502 test_and_clear_bit(FLG_FILLEMPTY
, &bch
->Flags
);
503 bch
->ch
.protocol
= rq
->protocol
;
506 /* start USB endpoint for bchannel */
507 if (rq
->adr
.channel
== 1)
508 hfcsusb_start_endpoint(hw
, HFC_CHAN_B1
);
510 hfcsusb_start_endpoint(hw
, HFC_CHAN_B2
);
512 if (!try_module_get(THIS_MODULE
))
513 printk(KERN_WARNING
"%s: %s:cannot get module\n",
519 channel_ctrl(struct hfcsusb
*hw
, struct mISDN_ctrl_req
*cq
)
523 if (debug
& DBG_HFC_CALL_TRACE
)
524 printk(KERN_DEBUG
"%s: %s op(0x%x) channel(0x%x)\n",
525 hw
->name
, __func__
, (cq
->op
), (cq
->channel
));
528 case MISDN_CTRL_GETOP
:
529 cq
->op
= MISDN_CTRL_LOOP
| MISDN_CTRL_CONNECT
|
530 MISDN_CTRL_DISCONNECT
;
533 printk(KERN_WARNING
"%s: %s: unknown Op %x\n",
534 hw
->name
, __func__
, cq
->op
);
542 * device control function
545 hfc_dctrl(struct mISDNchannel
*ch
, u_int cmd
, void *arg
)
547 struct mISDNdevice
*dev
= container_of(ch
, struct mISDNdevice
, D
);
548 struct dchannel
*dch
= container_of(dev
, struct dchannel
, dev
);
549 struct hfcsusb
*hw
= dch
->hw
;
550 struct channel_req
*rq
;
553 if (dch
->debug
& DEBUG_HW
)
554 printk(KERN_DEBUG
"%s: %s: cmd:%x %p\n",
555 hw
->name
, __func__
, cmd
, arg
);
559 if ((rq
->protocol
== ISDN_P_TE_S0
) ||
560 (rq
->protocol
== ISDN_P_NT_S0
))
561 err
= open_dchannel(hw
, ch
, rq
);
563 err
= open_bchannel(hw
, rq
);
569 if (debug
& DEBUG_HW_OPEN
)
571 "%s: %s: dev(%d) close from %p (open %d)\n",
572 hw
->name
, __func__
, hw
->dch
.dev
.id
,
573 __builtin_return_address(0), hw
->open
);
575 hfcsusb_stop_endpoint(hw
, HFC_CHAN_D
);
576 if (hw
->fifos
[HFCUSB_PCM_RX
].pipe
)
577 hfcsusb_stop_endpoint(hw
, HFC_CHAN_E
);
578 handle_led(hw
, LED_POWER_ON
);
580 module_put(THIS_MODULE
);
582 case CONTROL_CHANNEL
:
583 err
= channel_ctrl(hw
, arg
);
586 if (dch
->debug
& DEBUG_HW
)
587 printk(KERN_DEBUG
"%s: %s: unknown command %x\n",
588 hw
->name
, __func__
, cmd
);
595 * S0 TE state change event handler
598 ph_state_te(struct dchannel
*dch
)
600 struct hfcsusb
*hw
= dch
->hw
;
602 if (debug
& DEBUG_HW
) {
603 if (dch
->state
<= HFC_MAX_TE_LAYER1_STATE
)
604 printk(KERN_DEBUG
"%s: %s: %s\n", hw
->name
, __func__
,
605 HFC_TE_LAYER1_STATES
[dch
->state
]);
607 printk(KERN_DEBUG
"%s: %s: TE F%d\n",
608 hw
->name
, __func__
, dch
->state
);
611 switch (dch
->state
) {
613 l1_event(dch
->l1
, HW_RESET_IND
);
616 l1_event(dch
->l1
, HW_DEACT_IND
);
620 l1_event(dch
->l1
, ANYSIGNAL
);
623 l1_event(dch
->l1
, INFO2
);
626 l1_event(dch
->l1
, INFO4_P8
);
630 handle_led(hw
, LED_S0_ON
);
632 handle_led(hw
, LED_S0_OFF
);
636 * S0 NT state change event handler
639 ph_state_nt(struct dchannel
*dch
)
641 struct hfcsusb
*hw
= dch
->hw
;
643 if (debug
& DEBUG_HW
) {
644 if (dch
->state
<= HFC_MAX_NT_LAYER1_STATE
)
645 printk(KERN_DEBUG
"%s: %s: %s\n",
647 HFC_NT_LAYER1_STATES
[dch
->state
]);
650 printk(KERN_INFO DRIVER_NAME
"%s: %s: NT G%d\n",
651 hw
->name
, __func__
, dch
->state
);
654 switch (dch
->state
) {
656 test_and_clear_bit(FLG_ACTIVE
, &dch
->Flags
);
657 test_and_clear_bit(FLG_L2_ACTIVATED
, &dch
->Flags
);
659 hw
->timers
&= ~NT_ACTIVATION_TIMER
;
660 handle_led(hw
, LED_S0_OFF
);
664 if (hw
->nt_timer
< 0) {
666 hw
->timers
&= ~NT_ACTIVATION_TIMER
;
667 hfcsusb_ph_command(dch
->hw
, HFC_L1_DEACTIVATE_NT
);
669 hw
->timers
|= NT_ACTIVATION_TIMER
;
670 hw
->nt_timer
= NT_T1_COUNT
;
671 /* allow G2 -> G3 transition */
672 write_reg(hw
, HFCUSB_STATES
, 2 | HFCUSB_NT_G2_G3
);
677 hw
->timers
&= ~NT_ACTIVATION_TIMER
;
678 test_and_set_bit(FLG_ACTIVE
, &dch
->Flags
);
679 _queue_data(&dch
->dev
.D
, PH_ACTIVATE_IND
,
680 MISDN_ID_ANY
, 0, NULL
, GFP_ATOMIC
);
681 handle_led(hw
, LED_S0_ON
);
685 hw
->timers
&= ~NT_ACTIVATION_TIMER
;
694 ph_state(struct dchannel
*dch
)
696 struct hfcsusb
*hw
= dch
->hw
;
698 if (hw
->protocol
== ISDN_P_NT_S0
)
700 else if (hw
->protocol
== ISDN_P_TE_S0
)
705 * disable/enable BChannel for desired protocoll
708 hfcsusb_setup_bch(struct bchannel
*bch
, int protocol
)
710 struct hfcsusb
*hw
= bch
->hw
;
711 __u8 conhdlc
, sctrl
, sctrl_r
;
713 if (debug
& DEBUG_HW
)
714 printk(KERN_DEBUG
"%s: %s: protocol %x-->%x B%d\n",
715 hw
->name
, __func__
, bch
->state
, protocol
,
718 /* setup val for CON_HDLC */
720 if (protocol
> ISDN_P_NONE
)
721 conhdlc
= 8; /* enable FIFO */
724 case (-1): /* used for init */
728 if (bch
->state
== ISDN_P_NONE
)
729 return 0; /* already in idle state */
730 bch
->state
= ISDN_P_NONE
;
731 clear_bit(FLG_HDLC
, &bch
->Flags
);
732 clear_bit(FLG_TRANSPARENT
, &bch
->Flags
);
736 bch
->state
= protocol
;
737 set_bit(FLG_TRANSPARENT
, &bch
->Flags
);
739 case (ISDN_P_B_HDLC
):
740 bch
->state
= protocol
;
741 set_bit(FLG_HDLC
, &bch
->Flags
);
744 if (debug
& DEBUG_HW
)
745 printk(KERN_DEBUG
"%s: %s: prot not known %x\n",
746 hw
->name
, __func__
, protocol
);
750 if (protocol
>= ISDN_P_NONE
) {
751 write_reg(hw
, HFCUSB_FIFO
, (bch
->nr
== 1) ? 0 : 2);
752 write_reg(hw
, HFCUSB_CON_HDLC
, conhdlc
);
753 write_reg(hw
, HFCUSB_INC_RES_F
, 2);
754 write_reg(hw
, HFCUSB_FIFO
, (bch
->nr
== 1) ? 1 : 3);
755 write_reg(hw
, HFCUSB_CON_HDLC
, conhdlc
);
756 write_reg(hw
, HFCUSB_INC_RES_F
, 2);
758 sctrl
= 0x40 + ((hw
->protocol
== ISDN_P_TE_S0
) ? 0x00 : 0x04);
760 if (test_bit(FLG_ACTIVE
, &hw
->bch
[0].Flags
)) {
764 if (test_bit(FLG_ACTIVE
, &hw
->bch
[1].Flags
)) {
768 write_reg(hw
, HFCUSB_SCTRL
, sctrl
);
769 write_reg(hw
, HFCUSB_SCTRL_R
, sctrl_r
);
771 if (protocol
> ISDN_P_NONE
)
772 handle_led(hw
, (bch
->nr
== 1) ? LED_B1_ON
: LED_B2_ON
);
774 handle_led(hw
, (bch
->nr
== 1) ? LED_B1_OFF
:
782 hfcsusb_ph_command(struct hfcsusb
*hw
, u_char command
)
784 if (debug
& DEBUG_HW
)
785 printk(KERN_DEBUG
"%s: %s: %x\n",
786 hw
->name
, __func__
, command
);
789 case HFC_L1_ACTIVATE_TE
:
790 /* force sending sending INFO1 */
791 write_reg(hw
, HFCUSB_STATES
, 0x14);
792 /* start l1 activation */
793 write_reg(hw
, HFCUSB_STATES
, 0x04);
796 case HFC_L1_FORCE_DEACTIVATE_TE
:
797 write_reg(hw
, HFCUSB_STATES
, 0x10);
798 write_reg(hw
, HFCUSB_STATES
, 0x03);
801 case HFC_L1_ACTIVATE_NT
:
802 if (hw
->dch
.state
== 3)
803 _queue_data(&hw
->dch
.dev
.D
, PH_ACTIVATE_IND
,
804 MISDN_ID_ANY
, 0, NULL
, GFP_ATOMIC
);
806 write_reg(hw
, HFCUSB_STATES
, HFCUSB_ACTIVATE
|
807 HFCUSB_DO_ACTION
| HFCUSB_NT_G2_G3
);
810 case HFC_L1_DEACTIVATE_NT
:
811 write_reg(hw
, HFCUSB_STATES
,
818 * Layer 1 B-channel hardware access
821 channel_bctrl(struct bchannel
*bch
, struct mISDN_ctrl_req
*cq
)
826 case MISDN_CTRL_GETOP
:
827 cq
->op
= MISDN_CTRL_FILL_EMPTY
;
829 case MISDN_CTRL_FILL_EMPTY
: /* fill fifo, if empty */
830 test_and_set_bit(FLG_FILLEMPTY
, &bch
->Flags
);
831 if (debug
& DEBUG_HW_OPEN
)
832 printk(KERN_DEBUG
"%s: FILL_EMPTY request (nr=%d "
833 "off=%d)\n", __func__
, bch
->nr
, !!cq
->p1
);
836 printk(KERN_WARNING
"%s: unknown Op %x\n", __func__
, cq
->op
);
843 /* collect data from incoming interrupt or isochron USB data */
845 hfcsusb_rx_frame(struct usb_fifo
*fifo
, __u8
*data
, unsigned int len
,
848 struct hfcsusb
*hw
= fifo
->hw
;
849 struct sk_buff
*rx_skb
= NULL
;
851 int fifon
= fifo
->fifonum
;
855 if (debug
& DBG_HFC_CALL_TRACE
)
856 printk(KERN_DEBUG
"%s: %s: fifo(%i) len(%i) "
857 "dch(%p) bch(%p) ech(%p)\n",
858 hw
->name
, __func__
, fifon
, len
,
859 fifo
->dch
, fifo
->bch
, fifo
->ech
);
864 if ((!!fifo
->dch
+ !!fifo
->bch
+ !!fifo
->ech
) != 1) {
865 printk(KERN_DEBUG
"%s: %s: undefined channel\n",
870 spin_lock(&hw
->lock
);
872 rx_skb
= fifo
->dch
->rx_skb
;
873 maxlen
= fifo
->dch
->maxlen
;
877 rx_skb
= fifo
->bch
->rx_skb
;
878 maxlen
= fifo
->bch
->maxlen
;
879 hdlc
= test_bit(FLG_HDLC
, &fifo
->bch
->Flags
);
882 rx_skb
= fifo
->ech
->rx_skb
;
883 maxlen
= fifo
->ech
->maxlen
;
888 rx_skb
= mI_alloc_skb(maxlen
, GFP_ATOMIC
);
891 fifo
->dch
->rx_skb
= rx_skb
;
893 fifo
->bch
->rx_skb
= rx_skb
;
895 fifo
->ech
->rx_skb
= rx_skb
;
898 printk(KERN_DEBUG
"%s: %s: No mem for rx_skb\n",
900 spin_unlock(&hw
->lock
);
905 if (fifo
->dch
|| fifo
->ech
) {
906 /* D/E-Channel SKB range check */
907 if ((rx_skb
->len
+ len
) >= MAX_DFRAME_LEN_L1
) {
908 printk(KERN_DEBUG
"%s: %s: sbk mem exceeded "
909 "for fifo(%d) HFCUSB_D_RX\n",
910 hw
->name
, __func__
, fifon
);
912 spin_unlock(&hw
->lock
);
915 } else if (fifo
->bch
) {
916 /* B-Channel SKB range check */
917 if ((rx_skb
->len
+ len
) >= (MAX_BCH_SIZE
+ 3)) {
918 printk(KERN_DEBUG
"%s: %s: sbk mem exceeded "
919 "for fifo(%d) HFCUSB_B_RX\n",
920 hw
->name
, __func__
, fifon
);
922 spin_unlock(&hw
->lock
);
927 memcpy(skb_put(rx_skb
, len
), data
, len
);
930 /* we have a complete hdlc packet */
932 if ((rx_skb
->len
> 3) &&
933 (!(rx_skb
->data
[rx_skb
->len
- 1]))) {
934 if (debug
& DBG_HFC_FIFO_VERBOSE
) {
935 printk(KERN_DEBUG
"%s: %s: fifon(%i)"
937 hw
->name
, __func__
, fifon
,
940 while (i
< rx_skb
->len
)
946 /* remove CRC & status */
947 skb_trim(rx_skb
, rx_skb
->len
- 3);
950 recv_Dchannel(fifo
->dch
);
952 recv_Bchannel(fifo
->bch
, MISDN_ID_ANY
);
954 recv_Echannel(fifo
->ech
,
957 if (debug
& DBG_HFC_FIFO_VERBOSE
) {
959 "%s: CRC or minlen ERROR fifon(%i) "
961 hw
->name
, fifon
, rx_skb
->len
);
963 while (i
< rx_skb
->len
)
972 /* deliver transparent data to layer2 */
973 if (rx_skb
->len
>= poll
)
974 recv_Bchannel(fifo
->bch
, MISDN_ID_ANY
);
976 spin_unlock(&hw
->lock
);
980 fill_isoc_urb(struct urb
*urb
, struct usb_device
*dev
, unsigned int pipe
,
981 void *buf
, int num_packets
, int packet_size
, int interval
,
982 usb_complete_t complete
, void *context
)
986 usb_fill_bulk_urb(urb
, dev
, pipe
, buf
, packet_size
* num_packets
,
989 urb
->number_of_packets
= num_packets
;
990 urb
->transfer_flags
= URB_ISO_ASAP
;
991 urb
->actual_length
= 0;
992 urb
->interval
= interval
;
994 for (k
= 0; k
< num_packets
; k
++) {
995 urb
->iso_frame_desc
[k
].offset
= packet_size
* k
;
996 urb
->iso_frame_desc
[k
].length
= packet_size
;
997 urb
->iso_frame_desc
[k
].actual_length
= 0;
1001 /* receive completion routine for all ISO tx fifos */
1003 rx_iso_complete(struct urb
*urb
)
1005 struct iso_urb
*context_iso_urb
= (struct iso_urb
*) urb
->context
;
1006 struct usb_fifo
*fifo
= context_iso_urb
->owner_fifo
;
1007 struct hfcsusb
*hw
= fifo
->hw
;
1008 int k
, len
, errcode
, offset
, num_isoc_packets
, fifon
, maxlen
,
1009 status
, iso_status
, i
;
1014 fifon
= fifo
->fifonum
;
1015 status
= urb
->status
;
1017 spin_lock(&hw
->lock
);
1018 if (fifo
->stop_gracefull
) {
1019 fifo
->stop_gracefull
= 0;
1021 spin_unlock(&hw
->lock
);
1024 spin_unlock(&hw
->lock
);
1027 * ISO transfer only partially completed,
1028 * look at individual frame status for details
1030 if (status
== -EXDEV
) {
1031 if (debug
& DEBUG_HW
)
1032 printk(KERN_DEBUG
"%s: %s: with -EXDEV "
1033 "urb->status %d, fifonum %d\n",
1034 hw
->name
, __func__
, status
, fifon
);
1036 /* clear status, so go on with ISO transfers */
1041 if (fifo
->active
&& !status
) {
1042 num_isoc_packets
= iso_packets
[fifon
];
1043 maxlen
= fifo
->usb_packet_maxlen
;
1045 for (k
= 0; k
< num_isoc_packets
; ++k
) {
1046 len
= urb
->iso_frame_desc
[k
].actual_length
;
1047 offset
= urb
->iso_frame_desc
[k
].offset
;
1048 buf
= context_iso_urb
->buffer
+ offset
;
1049 iso_status
= urb
->iso_frame_desc
[k
].status
;
1051 if (iso_status
&& (debug
& DBG_HFC_FIFO_VERBOSE
)) {
1052 printk(KERN_DEBUG
"%s: %s: "
1053 "ISO packet %i, status: %i\n",
1054 hw
->name
, __func__
, k
, iso_status
);
1057 /* USB data log for every D ISO in */
1058 if ((fifon
== HFCUSB_D_RX
) &&
1059 (debug
& DBG_HFC_USB_VERBOSE
)) {
1061 "%s: %s: %d (%d/%d) len(%d) ",
1062 hw
->name
, __func__
, urb
->start_frame
,
1063 k
, num_isoc_packets
-1,
1065 for (i
= 0; i
< len
; i
++)
1066 printk("%x ", buf
[i
]);
1071 if (fifo
->last_urblen
!= maxlen
) {
1073 * save fifo fill-level threshold bits
1074 * to use them later in TX ISO URB
1077 hw
->threshold_mask
= buf
[1];
1079 if (fifon
== HFCUSB_D_RX
)
1080 s0_state
= (buf
[0] >> 4);
1082 eof
[fifon
] = buf
[0] & 1;
1084 hfcsusb_rx_frame(fifo
, buf
+ 2,
1085 len
- 2, (len
< maxlen
)
1088 hfcsusb_rx_frame(fifo
, buf
, len
,
1091 fifo
->last_urblen
= len
;
1095 /* signal S0 layer1 state change */
1096 if ((s0_state
) && (hw
->initdone
) &&
1097 (s0_state
!= hw
->dch
.state
)) {
1098 hw
->dch
.state
= s0_state
;
1099 schedule_event(&hw
->dch
, FLG_PHCHANGE
);
1102 fill_isoc_urb(urb
, fifo
->hw
->dev
, fifo
->pipe
,
1103 context_iso_urb
->buffer
, num_isoc_packets
,
1104 fifo
->usb_packet_maxlen
, fifo
->intervall
,
1105 (usb_complete_t
)rx_iso_complete
, urb
->context
);
1106 errcode
= usb_submit_urb(urb
, GFP_ATOMIC
);
1108 if (debug
& DEBUG_HW
)
1109 printk(KERN_DEBUG
"%s: %s: error submitting "
1111 hw
->name
, __func__
, errcode
);
1114 if (status
&& (debug
& DBG_HFC_URB_INFO
))
1115 printk(KERN_DEBUG
"%s: %s: rx_iso_complete : "
1116 "urb->status %d, fifonum %d\n",
1117 hw
->name
, __func__
, status
, fifon
);
1121 /* receive completion routine for all interrupt rx fifos */
1123 rx_int_complete(struct urb
*urb
)
1126 __u8
*buf
, maxlen
, fifon
;
1127 struct usb_fifo
*fifo
= (struct usb_fifo
*) urb
->context
;
1128 struct hfcsusb
*hw
= fifo
->hw
;
1131 spin_lock(&hw
->lock
);
1132 if (fifo
->stop_gracefull
) {
1133 fifo
->stop_gracefull
= 0;
1135 spin_unlock(&hw
->lock
);
1138 spin_unlock(&hw
->lock
);
1140 fifon
= fifo
->fifonum
;
1141 if ((!fifo
->active
) || (urb
->status
)) {
1142 if (debug
& DBG_HFC_URB_ERROR
)
1144 "%s: %s: RX-Fifo %i is going down (%i)\n",
1145 hw
->name
, __func__
, fifon
, urb
->status
);
1147 fifo
->urb
->interval
= 0; /* cancel automatic rescheduling */
1150 len
= urb
->actual_length
;
1152 maxlen
= fifo
->usb_packet_maxlen
;
1154 /* USB data log for every D INT in */
1155 if ((fifon
== HFCUSB_D_RX
) && (debug
& DBG_HFC_USB_VERBOSE
)) {
1156 printk(KERN_DEBUG
"%s: %s: D RX INT len(%d) ",
1157 hw
->name
, __func__
, len
);
1158 for (i
= 0; i
< len
; i
++)
1159 printk("%02x ", buf
[i
]);
1163 if (fifo
->last_urblen
!= fifo
->usb_packet_maxlen
) {
1164 /* the threshold mask is in the 2nd status byte */
1165 hw
->threshold_mask
= buf
[1];
1167 /* signal S0 layer1 state change */
1168 if (hw
->initdone
&& ((buf
[0] >> 4) != hw
->dch
.state
)) {
1169 hw
->dch
.state
= (buf
[0] >> 4);
1170 schedule_event(&hw
->dch
, FLG_PHCHANGE
);
1173 eof
[fifon
] = buf
[0] & 1;
1174 /* if we have more than the 2 status bytes -> collect data */
1176 hfcsusb_rx_frame(fifo
, buf
+ 2,
1177 urb
->actual_length
- 2,
1178 (len
< maxlen
) ? eof
[fifon
] : 0);
1180 hfcsusb_rx_frame(fifo
, buf
, urb
->actual_length
,
1181 (len
< maxlen
) ? eof
[fifon
] : 0);
1183 fifo
->last_urblen
= urb
->actual_length
;
1185 status
= usb_submit_urb(urb
, GFP_ATOMIC
);
1187 if (debug
& DEBUG_HW
)
1188 printk(KERN_DEBUG
"%s: %s: error resubmitting USB\n",
1189 hw
->name
, __func__
);
1193 /* transmit completion routine for all ISO tx fifos */
1195 tx_iso_complete(struct urb
*urb
)
1197 struct iso_urb
*context_iso_urb
= (struct iso_urb
*) urb
->context
;
1198 struct usb_fifo
*fifo
= context_iso_urb
->owner_fifo
;
1199 struct hfcsusb
*hw
= fifo
->hw
;
1200 struct sk_buff
*tx_skb
;
1201 int k
, tx_offset
, num_isoc_packets
, sink
, remain
, current_len
,
1204 int frame_complete
, fifon
, status
;
1207 spin_lock(&hw
->lock
);
1208 if (fifo
->stop_gracefull
) {
1209 fifo
->stop_gracefull
= 0;
1211 spin_unlock(&hw
->lock
);
1216 tx_skb
= fifo
->dch
->tx_skb
;
1217 tx_idx
= &fifo
->dch
->tx_idx
;
1219 } else if (fifo
->bch
) {
1220 tx_skb
= fifo
->bch
->tx_skb
;
1221 tx_idx
= &fifo
->bch
->tx_idx
;
1222 hdlc
= test_bit(FLG_HDLC
, &fifo
->bch
->Flags
);
1224 printk(KERN_DEBUG
"%s: %s: neither BCH nor DCH\n",
1225 hw
->name
, __func__
);
1226 spin_unlock(&hw
->lock
);
1230 fifon
= fifo
->fifonum
;
1231 status
= urb
->status
;
1236 * ISO transfer only partially completed,
1237 * look at individual frame status for details
1239 if (status
== -EXDEV
) {
1240 if (debug
& DBG_HFC_URB_ERROR
)
1241 printk(KERN_DEBUG
"%s: %s: "
1242 "-EXDEV (%i) fifon (%d)\n",
1243 hw
->name
, __func__
, status
, fifon
);
1245 /* clear status, so go on with ISO transfers */
1249 if (fifo
->active
&& !status
) {
1250 /* is FifoFull-threshold set for our channel? */
1251 threshbit
= (hw
->threshold_mask
& (1 << fifon
));
1252 num_isoc_packets
= iso_packets
[fifon
];
1254 /* predict dataflow to avoid fifo overflow */
1255 if (fifon
>= HFCUSB_D_TX
)
1256 sink
= (threshbit
) ? SINK_DMIN
: SINK_DMAX
;
1258 sink
= (threshbit
) ? SINK_MIN
: SINK_MAX
;
1259 fill_isoc_urb(urb
, fifo
->hw
->dev
, fifo
->pipe
,
1260 context_iso_urb
->buffer
, num_isoc_packets
,
1261 fifo
->usb_packet_maxlen
, fifo
->intervall
,
1262 (usb_complete_t
)tx_iso_complete
, urb
->context
);
1263 memset(context_iso_urb
->buffer
, 0,
1264 sizeof(context_iso_urb
->buffer
));
1267 for (k
= 0; k
< num_isoc_packets
; ++k
) {
1268 /* analyze tx success of previous ISO packets */
1269 if (debug
& DBG_HFC_URB_ERROR
) {
1270 errcode
= urb
->iso_frame_desc
[k
].status
;
1272 printk(KERN_DEBUG
"%s: %s: "
1273 "ISO packet %i, status: %i\n",
1274 hw
->name
, __func__
, k
, errcode
);
1278 /* Generate next ISO Packets */
1280 remain
= tx_skb
->len
- *tx_idx
;
1285 fifo
->bit_line
-= sink
;
1286 current_len
= (0 - fifo
->bit_line
) / 8;
1287 if (current_len
> 14)
1289 if (current_len
< 0)
1291 if (remain
< current_len
)
1292 current_len
= remain
;
1294 /* how much bit do we put on the line? */
1295 fifo
->bit_line
+= current_len
* 8;
1297 context_iso_urb
->buffer
[tx_offset
] = 0;
1298 if (current_len
== remain
) {
1300 /* signal frame completion */
1302 buffer
[tx_offset
] = 1;
1303 /* add 2 byte flags and 16bit
1304 * CRC at end of ISDN frame */
1305 fifo
->bit_line
+= 32;
1310 /* copy tx data to iso-urb buffer */
1311 memcpy(context_iso_urb
->buffer
+ tx_offset
+ 1,
1312 (tx_skb
->data
+ *tx_idx
), current_len
);
1313 *tx_idx
+= current_len
;
1315 urb
->iso_frame_desc
[k
].offset
= tx_offset
;
1316 urb
->iso_frame_desc
[k
].length
= current_len
+ 1;
1318 /* USB data log for every D ISO out */
1319 if ((fifon
== HFCUSB_D_RX
) &&
1320 (debug
& DBG_HFC_USB_VERBOSE
)) {
1322 "%s: %s (%d/%d) offs(%d) len(%d) ",
1324 k
, num_isoc_packets
-1,
1325 urb
->iso_frame_desc
[k
].offset
,
1326 urb
->iso_frame_desc
[k
].length
);
1328 for (i
= urb
->iso_frame_desc
[k
].offset
;
1329 i
< (urb
->iso_frame_desc
[k
].offset
1330 + urb
->iso_frame_desc
[k
].length
);
1333 context_iso_urb
->buffer
[i
]);
1335 printk(" skb->len(%i) tx-idx(%d)\n",
1336 tx_skb
->len
, *tx_idx
);
1339 tx_offset
+= (current_len
+ 1);
1341 urb
->iso_frame_desc
[k
].offset
= tx_offset
++;
1342 urb
->iso_frame_desc
[k
].length
= 1;
1343 /* we lower data margin every msec */
1344 fifo
->bit_line
-= sink
;
1345 if (fifo
->bit_line
< BITLINE_INF
)
1346 fifo
->bit_line
= BITLINE_INF
;
1349 if (frame_complete
) {
1352 if (debug
& DBG_HFC_FIFO_VERBOSE
) {
1353 printk(KERN_DEBUG
"%s: %s: "
1354 "fifon(%i) new TX len(%i): ",
1356 fifon
, tx_skb
->len
);
1358 while (i
< tx_skb
->len
)
1364 dev_kfree_skb(tx_skb
);
1366 if (fifo
->dch
&& get_next_dframe(fifo
->dch
))
1367 tx_skb
= fifo
->dch
->tx_skb
;
1368 else if (fifo
->bch
&&
1369 get_next_bframe(fifo
->bch
)) {
1370 if (test_bit(FLG_TRANSPARENT
,
1372 confirm_Bsend(fifo
->bch
);
1373 tx_skb
= fifo
->bch
->tx_skb
;
1377 errcode
= usb_submit_urb(urb
, GFP_ATOMIC
);
1379 if (debug
& DEBUG_HW
)
1381 "%s: %s: error submitting ISO URB: %d \n",
1382 hw
->name
, __func__
, errcode
);
1386 * abuse DChannel tx iso completion to trigger NT mode state
1387 * changes tx_iso_complete is assumed to be called every
1388 * fifo->intervall (ms)
1390 if ((fifon
== HFCUSB_D_TX
) && (hw
->protocol
== ISDN_P_NT_S0
)
1391 && (hw
->timers
& NT_ACTIVATION_TIMER
)) {
1392 if ((--hw
->nt_timer
) < 0)
1393 schedule_event(&hw
->dch
, FLG_PHCHANGE
);
1397 if (status
&& (debug
& DBG_HFC_URB_ERROR
))
1398 printk(KERN_DEBUG
"%s: %s: urb->status %s (%i)"
1401 symbolic(urb_errlist
, status
), status
, fifon
);
1403 spin_unlock(&hw
->lock
);
1407 * allocs urbs and start isoc transfer with two pending urbs to avoid
1408 * gaps in the transfer chain
1411 start_isoc_chain(struct usb_fifo
*fifo
, int num_packets_per_urb
,
1412 usb_complete_t complete
, int packet_size
)
1414 struct hfcsusb
*hw
= fifo
->hw
;
1418 printk(KERN_DEBUG
"%s: %s: fifo %i\n",
1419 hw
->name
, __func__
, fifo
->fifonum
);
1421 /* allocate Memory for Iso out Urbs */
1422 for (i
= 0; i
< 2; i
++) {
1423 if (!(fifo
->iso
[i
].urb
)) {
1425 usb_alloc_urb(num_packets_per_urb
, GFP_KERNEL
);
1426 if (!(fifo
->iso
[i
].urb
)) {
1428 "%s: %s: alloc urb for fifo %i failed",
1429 hw
->name
, __func__
, fifo
->fifonum
);
1431 fifo
->iso
[i
].owner_fifo
= (struct usb_fifo
*) fifo
;
1432 fifo
->iso
[i
].indx
= i
;
1434 /* Init the first iso */
1435 if (ISO_BUFFER_SIZE
>=
1436 (fifo
->usb_packet_maxlen
*
1437 num_packets_per_urb
)) {
1438 fill_isoc_urb(fifo
->iso
[i
].urb
,
1439 fifo
->hw
->dev
, fifo
->pipe
,
1440 fifo
->iso
[i
].buffer
,
1441 num_packets_per_urb
,
1442 fifo
->usb_packet_maxlen
,
1443 fifo
->intervall
, complete
,
1445 memset(fifo
->iso
[i
].buffer
, 0,
1446 sizeof(fifo
->iso
[i
].buffer
));
1448 for (k
= 0; k
< num_packets_per_urb
; k
++) {
1450 iso_frame_desc
[k
].offset
=
1453 iso_frame_desc
[k
].length
=
1458 "%s: %s: ISO Buffer size to small!\n",
1459 hw
->name
, __func__
);
1462 fifo
->bit_line
= BITLINE_INF
;
1464 errcode
= usb_submit_urb(fifo
->iso
[i
].urb
, GFP_KERNEL
);
1465 fifo
->active
= (errcode
>= 0) ? 1 : 0;
1466 fifo
->stop_gracefull
= 0;
1468 printk(KERN_DEBUG
"%s: %s: %s URB nr:%d\n",
1470 symbolic(urb_errlist
, errcode
), i
);
1473 return fifo
->active
;
1477 stop_iso_gracefull(struct usb_fifo
*fifo
)
1479 struct hfcsusb
*hw
= fifo
->hw
;
1483 for (i
= 0; i
< 2; i
++) {
1484 spin_lock_irqsave(&hw
->lock
, flags
);
1486 printk(KERN_DEBUG
"%s: %s for fifo %i.%i\n",
1487 hw
->name
, __func__
, fifo
->fifonum
, i
);
1488 fifo
->stop_gracefull
= 1;
1489 spin_unlock_irqrestore(&hw
->lock
, flags
);
1492 for (i
= 0; i
< 2; i
++) {
1494 while (fifo
->stop_gracefull
&& timeout
--)
1495 schedule_timeout_interruptible((HZ
/1000)*16);
1496 if (debug
&& fifo
->stop_gracefull
)
1497 printk(KERN_DEBUG
"%s: ERROR %s for fifo %i.%i\n",
1498 hw
->name
, __func__
, fifo
->fifonum
, i
);
1503 stop_int_gracefull(struct usb_fifo
*fifo
)
1505 struct hfcsusb
*hw
= fifo
->hw
;
1509 spin_lock_irqsave(&hw
->lock
, flags
);
1511 printk(KERN_DEBUG
"%s: %s for fifo %i\n",
1512 hw
->name
, __func__
, fifo
->fifonum
);
1513 fifo
->stop_gracefull
= 1;
1514 spin_unlock_irqrestore(&hw
->lock
, flags
);
1517 while (fifo
->stop_gracefull
&& timeout
--)
1518 schedule_timeout_interruptible((HZ
/1000)*3);
1519 if (debug
&& fifo
->stop_gracefull
)
1520 printk(KERN_DEBUG
"%s: ERROR %s for fifo %i\n",
1521 hw
->name
, __func__
, fifo
->fifonum
);
1524 /* start the interrupt transfer for the given fifo */
1526 start_int_fifo(struct usb_fifo
*fifo
)
1528 struct hfcsusb
*hw
= fifo
->hw
;
1532 printk(KERN_DEBUG
"%s: %s: INT IN fifo:%d\n",
1533 hw
->name
, __func__
, fifo
->fifonum
);
1536 fifo
->urb
= usb_alloc_urb(0, GFP_KERNEL
);
1540 usb_fill_int_urb(fifo
->urb
, fifo
->hw
->dev
, fifo
->pipe
,
1541 fifo
->buffer
, fifo
->usb_packet_maxlen
,
1542 (usb_complete_t
)rx_int_complete
, fifo
, fifo
->intervall
);
1544 fifo
->stop_gracefull
= 0;
1545 errcode
= usb_submit_urb(fifo
->urb
, GFP_KERNEL
);
1547 printk(KERN_DEBUG
"%s: %s: submit URB: status:%i\n",
1548 hw
->name
, __func__
, errcode
);
1554 setPortMode(struct hfcsusb
*hw
)
1556 if (debug
& DEBUG_HW
)
1557 printk(KERN_DEBUG
"%s: %s %s\n", hw
->name
, __func__
,
1558 (hw
->protocol
== ISDN_P_TE_S0
) ? "TE" : "NT");
1560 if (hw
->protocol
== ISDN_P_TE_S0
) {
1561 write_reg(hw
, HFCUSB_SCTRL
, 0x40);
1562 write_reg(hw
, HFCUSB_SCTRL_E
, 0x00);
1563 write_reg(hw
, HFCUSB_CLKDEL
, CLKDEL_TE
);
1564 write_reg(hw
, HFCUSB_STATES
, 3 | 0x10);
1565 write_reg(hw
, HFCUSB_STATES
, 3);
1567 write_reg(hw
, HFCUSB_SCTRL
, 0x44);
1568 write_reg(hw
, HFCUSB_SCTRL_E
, 0x09);
1569 write_reg(hw
, HFCUSB_CLKDEL
, CLKDEL_NT
);
1570 write_reg(hw
, HFCUSB_STATES
, 1 | 0x10);
1571 write_reg(hw
, HFCUSB_STATES
, 1);
1576 reset_hfcsusb(struct hfcsusb
*hw
)
1578 struct usb_fifo
*fifo
;
1581 if (debug
& DEBUG_HW
)
1582 printk(KERN_DEBUG
"%s: %s\n", hw
->name
, __func__
);
1585 write_reg(hw
, HFCUSB_CIRM
, 8);
1587 /* aux = output, reset off */
1588 write_reg(hw
, HFCUSB_CIRM
, 0x10);
1590 /* set USB_SIZE to match the wMaxPacketSize for INT or BULK transfers */
1591 write_reg(hw
, HFCUSB_USB_SIZE
, (hw
->packet_size
/ 8) |
1592 ((hw
->packet_size
/ 8) << 4));
1594 /* set USB_SIZE_I to match the the wMaxPacketSize for ISO transfers */
1595 write_reg(hw
, HFCUSB_USB_SIZE_I
, hw
->iso_packet_size
);
1597 /* enable PCM/GCI master mode */
1598 write_reg(hw
, HFCUSB_MST_MODE1
, 0); /* set default values */
1599 write_reg(hw
, HFCUSB_MST_MODE0
, 1); /* enable master mode */
1601 /* init the fifos */
1602 write_reg(hw
, HFCUSB_F_THRES
,
1603 (HFCUSB_TX_THRESHOLD
/ 8) | ((HFCUSB_RX_THRESHOLD
/ 8) << 4));
1606 for (i
= 0; i
< HFCUSB_NUM_FIFOS
; i
++) {
1607 write_reg(hw
, HFCUSB_FIFO
, i
); /* select the desired fifo */
1609 (i
<= HFCUSB_B2_RX
) ? MAX_BCH_SIZE
: MAX_DFRAME_LEN
;
1610 fifo
[i
].last_urblen
= 0;
1612 /* set 2 bit for D- & E-channel */
1613 write_reg(hw
, HFCUSB_HDLC_PAR
, ((i
<= HFCUSB_B2_RX
) ? 0 : 2));
1615 /* enable all fifos */
1616 if (i
== HFCUSB_D_TX
)
1617 write_reg(hw
, HFCUSB_CON_HDLC
,
1618 (hw
->protocol
== ISDN_P_NT_S0
) ? 0x08 : 0x09);
1620 write_reg(hw
, HFCUSB_CON_HDLC
, 0x08);
1621 write_reg(hw
, HFCUSB_INC_RES_F
, 2); /* reset the fifo */
1624 write_reg(hw
, HFCUSB_SCTRL_R
, 0); /* disable both B receivers */
1625 handle_led(hw
, LED_POWER_ON
);
1628 /* start USB data pipes dependand on device's endpoint configuration */
1630 hfcsusb_start_endpoint(struct hfcsusb
*hw
, int channel
)
1632 /* quick check if endpoint already running */
1633 if ((channel
== HFC_CHAN_D
) && (hw
->fifos
[HFCUSB_D_RX
].active
))
1635 if ((channel
== HFC_CHAN_B1
) && (hw
->fifos
[HFCUSB_B1_RX
].active
))
1637 if ((channel
== HFC_CHAN_B2
) && (hw
->fifos
[HFCUSB_B2_RX
].active
))
1639 if ((channel
== HFC_CHAN_E
) && (hw
->fifos
[HFCUSB_PCM_RX
].active
))
1642 /* start rx endpoints using USB INT IN method */
1643 if (hw
->cfg_used
== CNF_3INT3ISO
|| hw
->cfg_used
== CNF_4INT3ISO
)
1644 start_int_fifo(hw
->fifos
+ channel
*2 + 1);
1646 /* start rx endpoints using USB ISO IN method */
1647 if (hw
->cfg_used
== CNF_3ISO3ISO
|| hw
->cfg_used
== CNF_4ISO3ISO
) {
1650 start_isoc_chain(hw
->fifos
+ HFCUSB_D_RX
,
1652 (usb_complete_t
)rx_iso_complete
,
1656 start_isoc_chain(hw
->fifos
+ HFCUSB_PCM_RX
,
1658 (usb_complete_t
)rx_iso_complete
,
1662 start_isoc_chain(hw
->fifos
+ HFCUSB_B1_RX
,
1664 (usb_complete_t
)rx_iso_complete
,
1668 start_isoc_chain(hw
->fifos
+ HFCUSB_B2_RX
,
1670 (usb_complete_t
)rx_iso_complete
,
1676 /* start tx endpoints using USB ISO OUT method */
1679 start_isoc_chain(hw
->fifos
+ HFCUSB_D_TX
,
1681 (usb_complete_t
)tx_iso_complete
, 1);
1684 start_isoc_chain(hw
->fifos
+ HFCUSB_B1_TX
,
1686 (usb_complete_t
)tx_iso_complete
, 1);
1689 start_isoc_chain(hw
->fifos
+ HFCUSB_B2_TX
,
1691 (usb_complete_t
)tx_iso_complete
, 1);
1696 /* stop USB data pipes dependand on device's endpoint configuration */
1698 hfcsusb_stop_endpoint(struct hfcsusb
*hw
, int channel
)
1700 /* quick check if endpoint currently running */
1701 if ((channel
== HFC_CHAN_D
) && (!hw
->fifos
[HFCUSB_D_RX
].active
))
1703 if ((channel
== HFC_CHAN_B1
) && (!hw
->fifos
[HFCUSB_B1_RX
].active
))
1705 if ((channel
== HFC_CHAN_B2
) && (!hw
->fifos
[HFCUSB_B2_RX
].active
))
1707 if ((channel
== HFC_CHAN_E
) && (!hw
->fifos
[HFCUSB_PCM_RX
].active
))
1710 /* rx endpoints using USB INT IN method */
1711 if (hw
->cfg_used
== CNF_3INT3ISO
|| hw
->cfg_used
== CNF_4INT3ISO
)
1712 stop_int_gracefull(hw
->fifos
+ channel
*2 + 1);
1714 /* rx endpoints using USB ISO IN method */
1715 if (hw
->cfg_used
== CNF_3ISO3ISO
|| hw
->cfg_used
== CNF_4ISO3ISO
)
1716 stop_iso_gracefull(hw
->fifos
+ channel
*2 + 1);
1718 /* tx endpoints using USB ISO OUT method */
1719 if (channel
!= HFC_CHAN_E
)
1720 stop_iso_gracefull(hw
->fifos
+ channel
*2);
1724 /* Hardware Initialization */
1726 setup_hfcsusb(struct hfcsusb
*hw
)
1730 if (debug
& DBG_HFC_CALL_TRACE
)
1731 printk(KERN_DEBUG
"%s: %s\n", hw
->name
, __func__
);
1733 /* check the chip id */
1734 if (read_reg_atomic(hw
, HFCUSB_CHIP_ID
, &b
) != 1) {
1735 printk(KERN_DEBUG
"%s: %s: cannot read chip id\n",
1736 hw
->name
, __func__
);
1739 if (b
!= HFCUSB_CHIPID
) {
1740 printk(KERN_DEBUG
"%s: %s: Invalid chip id 0x%02x\n",
1741 hw
->name
, __func__
, b
);
1745 /* first set the needed config, interface and alternate */
1746 (void) usb_set_interface(hw
->dev
, hw
->if_used
, hw
->alt_used
);
1750 /* init the background machinery for control requests */
1751 hw
->ctrl_read
.bRequestType
= 0xc0;
1752 hw
->ctrl_read
.bRequest
= 1;
1753 hw
->ctrl_read
.wLength
= cpu_to_le16(1);
1754 hw
->ctrl_write
.bRequestType
= 0x40;
1755 hw
->ctrl_write
.bRequest
= 0;
1756 hw
->ctrl_write
.wLength
= 0;
1757 usb_fill_control_urb(hw
->ctrl_urb
, hw
->dev
, hw
->ctrl_out_pipe
,
1758 (u_char
*)&hw
->ctrl_write
, NULL
, 0,
1759 (usb_complete_t
)ctrl_complete
, hw
);
1766 release_hw(struct hfcsusb
*hw
)
1768 if (debug
& DBG_HFC_CALL_TRACE
)
1769 printk(KERN_DEBUG
"%s: %s\n", hw
->name
, __func__
);
1772 * stop all endpoints gracefully
1773 * TODO: mISDN_core should generate CLOSE_CHANNEL
1774 * signals after calling mISDN_unregister_device()
1776 hfcsusb_stop_endpoint(hw
, HFC_CHAN_D
);
1777 hfcsusb_stop_endpoint(hw
, HFC_CHAN_B1
);
1778 hfcsusb_stop_endpoint(hw
, HFC_CHAN_B2
);
1779 if (hw
->fifos
[HFCUSB_PCM_RX
].pipe
)
1780 hfcsusb_stop_endpoint(hw
, HFC_CHAN_E
);
1781 if (hw
->protocol
== ISDN_P_TE_S0
)
1782 l1_event(hw
->dch
.l1
, CLOSE_CHANNEL
);
1784 mISDN_unregister_device(&hw
->dch
.dev
);
1785 mISDN_freebchannel(&hw
->bch
[1]);
1786 mISDN_freebchannel(&hw
->bch
[0]);
1787 mISDN_freedchannel(&hw
->dch
);
1790 usb_kill_urb(hw
->ctrl_urb
);
1791 usb_free_urb(hw
->ctrl_urb
);
1792 hw
->ctrl_urb
= NULL
;
1796 usb_set_intfdata(hw
->intf
, NULL
);
1797 list_del(&hw
->list
);
1803 deactivate_bchannel(struct bchannel
*bch
)
1805 struct hfcsusb
*hw
= bch
->hw
;
1808 if (bch
->debug
& DEBUG_HW
)
1809 printk(KERN_DEBUG
"%s: %s: bch->nr(%i)\n",
1810 hw
->name
, __func__
, bch
->nr
);
1812 spin_lock_irqsave(&hw
->lock
, flags
);
1813 mISDN_clear_bchannel(bch
);
1814 spin_unlock_irqrestore(&hw
->lock
, flags
);
1815 hfcsusb_setup_bch(bch
, ISDN_P_NONE
);
1816 hfcsusb_stop_endpoint(hw
, bch
->nr
);
1820 * Layer 1 B-channel hardware access
1823 hfc_bctrl(struct mISDNchannel
*ch
, u_int cmd
, void *arg
)
1825 struct bchannel
*bch
= container_of(ch
, struct bchannel
, ch
);
1828 if (bch
->debug
& DEBUG_HW
)
1829 printk(KERN_DEBUG
"%s: cmd:%x %p\n", __func__
, cmd
, arg
);
1833 case HW_TESTRX_HDLC
:
1839 test_and_clear_bit(FLG_OPEN
, &bch
->Flags
);
1840 if (test_bit(FLG_ACTIVE
, &bch
->Flags
))
1841 deactivate_bchannel(bch
);
1842 ch
->protocol
= ISDN_P_NONE
;
1844 module_put(THIS_MODULE
);
1847 case CONTROL_CHANNEL
:
1848 ret
= channel_bctrl(bch
, arg
);
1851 printk(KERN_WARNING
"%s: unknown prim(%x)\n",
1858 setup_instance(struct hfcsusb
*hw
, struct device
*parent
)
1863 if (debug
& DBG_HFC_CALL_TRACE
)
1864 printk(KERN_DEBUG
"%s: %s\n", hw
->name
, __func__
);
1866 spin_lock_init(&hw
->ctrl_lock
);
1867 spin_lock_init(&hw
->lock
);
1869 mISDN_initdchannel(&hw
->dch
, MAX_DFRAME_LEN_L1
, ph_state
);
1870 hw
->dch
.debug
= debug
& 0xFFFF;
1872 hw
->dch
.dev
.Dprotocols
= (1 << ISDN_P_TE_S0
) | (1 << ISDN_P_NT_S0
);
1873 hw
->dch
.dev
.D
.send
= hfcusb_l2l1D
;
1874 hw
->dch
.dev
.D
.ctrl
= hfc_dctrl
;
1876 /* enable E-Channel logging */
1877 if (hw
->fifos
[HFCUSB_PCM_RX
].pipe
)
1878 mISDN_initdchannel(&hw
->ech
, MAX_DFRAME_LEN_L1
, NULL
);
1880 hw
->dch
.dev
.Bprotocols
= (1 << (ISDN_P_B_RAW
& ISDN_P_B_MASK
)) |
1881 (1 << (ISDN_P_B_HDLC
& ISDN_P_B_MASK
));
1882 hw
->dch
.dev
.nrbchan
= 2;
1883 for (i
= 0; i
< 2; i
++) {
1884 hw
->bch
[i
].nr
= i
+ 1;
1885 set_channelmap(i
+ 1, hw
->dch
.dev
.channelmap
);
1886 hw
->bch
[i
].debug
= debug
;
1887 mISDN_initbchannel(&hw
->bch
[i
], MAX_DATA_MEM
);
1889 hw
->bch
[i
].ch
.send
= hfcusb_l2l1B
;
1890 hw
->bch
[i
].ch
.ctrl
= hfc_bctrl
;
1891 hw
->bch
[i
].ch
.nr
= i
+ 1;
1892 list_add(&hw
->bch
[i
].ch
.list
, &hw
->dch
.dev
.bchannels
);
1895 hw
->fifos
[HFCUSB_B1_TX
].bch
= &hw
->bch
[0];
1896 hw
->fifos
[HFCUSB_B1_RX
].bch
= &hw
->bch
[0];
1897 hw
->fifos
[HFCUSB_B2_TX
].bch
= &hw
->bch
[1];
1898 hw
->fifos
[HFCUSB_B2_RX
].bch
= &hw
->bch
[1];
1899 hw
->fifos
[HFCUSB_D_TX
].dch
= &hw
->dch
;
1900 hw
->fifos
[HFCUSB_D_RX
].dch
= &hw
->dch
;
1901 hw
->fifos
[HFCUSB_PCM_RX
].ech
= &hw
->ech
;
1902 hw
->fifos
[HFCUSB_PCM_TX
].ech
= &hw
->ech
;
1904 err
= setup_hfcsusb(hw
);
1908 snprintf(hw
->name
, MISDN_MAX_IDLEN
- 1, "%s.%d", DRIVER_NAME
,
1910 printk(KERN_INFO
"%s: registered as '%s'\n",
1911 DRIVER_NAME
, hw
->name
);
1913 err
= mISDN_register_device(&hw
->dch
.dev
, parent
, hw
->name
);
1918 write_lock_irqsave(&HFClock
, flags
);
1919 list_add_tail(&hw
->list
, &HFClist
);
1920 write_unlock_irqrestore(&HFClock
, flags
);
1924 mISDN_freebchannel(&hw
->bch
[1]);
1925 mISDN_freebchannel(&hw
->bch
[0]);
1926 mISDN_freedchannel(&hw
->dch
);
1932 hfcsusb_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
)
1935 struct usb_device
*dev
= interface_to_usbdev(intf
);
1936 struct usb_host_interface
*iface
= intf
->cur_altsetting
;
1937 struct usb_host_interface
*iface_used
= NULL
;
1938 struct usb_host_endpoint
*ep
;
1939 struct hfcsusb_vdata
*driver_info
;
1940 int ifnum
= iface
->desc
.bInterfaceNumber
, i
, idx
, alt_idx
,
1941 probe_alt_setting
, vend_idx
, cfg_used
, *vcf
, attr
, cfg_found
,
1942 ep_addr
, cmptbl
[16], small_match
, iso_packet_size
, packet_size
,
1946 for (i
= 0; hfcsusb_idtab
[i
].idVendor
; i
++) {
1947 if ((le16_to_cpu(dev
->descriptor
.idVendor
)
1948 == hfcsusb_idtab
[i
].idVendor
) &&
1949 (le16_to_cpu(dev
->descriptor
.idProduct
)
1950 == hfcsusb_idtab
[i
].idProduct
)) {
1957 "%s: interface(%d) actalt(%d) minor(%d) vend_idx(%d)\n",
1958 __func__
, ifnum
, iface
->desc
.bAlternateSetting
,
1959 intf
->minor
, vend_idx
);
1961 if (vend_idx
== 0xffff) {
1963 "%s: no valid vendor found in USB descriptor\n",
1967 /* if vendor and product ID is OK, start probing alternate settings */
1971 /* default settings */
1972 iso_packet_size
= 16;
1975 while (alt_idx
< intf
->num_altsetting
) {
1976 iface
= intf
->altsetting
+ alt_idx
;
1977 probe_alt_setting
= iface
->desc
.bAlternateSetting
;
1980 while (validconf
[cfg_used
][0]) {
1982 vcf
= validconf
[cfg_used
];
1983 ep
= iface
->endpoint
;
1984 memcpy(cmptbl
, vcf
, 16 * sizeof(int));
1986 /* check for all endpoints in this alternate setting */
1987 for (i
= 0; i
< iface
->desc
.bNumEndpoints
; i
++) {
1988 ep_addr
= ep
->desc
.bEndpointAddress
;
1990 /* get endpoint base */
1991 idx
= ((ep_addr
& 0x7f) - 1) * 2;
1994 attr
= ep
->desc
.bmAttributes
;
1996 if (cmptbl
[idx
] != EP_NOP
) {
1997 if (cmptbl
[idx
] == EP_NUL
)
1999 if (attr
== USB_ENDPOINT_XFER_INT
2000 && cmptbl
[idx
] == EP_INT
)
2001 cmptbl
[idx
] = EP_NUL
;
2002 if (attr
== USB_ENDPOINT_XFER_BULK
2003 && cmptbl
[idx
] == EP_BLK
)
2004 cmptbl
[idx
] = EP_NUL
;
2005 if (attr
== USB_ENDPOINT_XFER_ISOC
2006 && cmptbl
[idx
] == EP_ISO
)
2007 cmptbl
[idx
] = EP_NUL
;
2009 if (attr
== USB_ENDPOINT_XFER_INT
&&
2010 ep
->desc
.bInterval
< vcf
[17]) {
2017 for (i
= 0; i
< 16; i
++)
2018 if (cmptbl
[i
] != EP_NOP
&& cmptbl
[i
] != EP_NUL
)
2022 if (small_match
< cfg_used
) {
2023 small_match
= cfg_used
;
2024 alt_used
= probe_alt_setting
;
2031 } /* (alt_idx < intf->num_altsetting) */
2033 /* not found a valid USB Ta Endpoint config */
2034 if (small_match
== -1)
2038 hw
= kzalloc(sizeof(struct hfcsusb
), GFP_KERNEL
);
2040 return -ENOMEM
; /* got no mem */
2041 snprintf(hw
->name
, MISDN_MAX_IDLEN
- 1, "%s", DRIVER_NAME
);
2043 ep
= iface
->endpoint
;
2044 vcf
= validconf
[small_match
];
2046 for (i
= 0; i
< iface
->desc
.bNumEndpoints
; i
++) {
2049 ep_addr
= ep
->desc
.bEndpointAddress
;
2050 /* get endpoint base */
2051 idx
= ((ep_addr
& 0x7f) - 1) * 2;
2054 f
= &hw
->fifos
[idx
& 7];
2056 /* init Endpoints */
2057 if (vcf
[idx
] == EP_NOP
|| vcf
[idx
] == EP_NUL
) {
2061 switch (ep
->desc
.bmAttributes
) {
2062 case USB_ENDPOINT_XFER_INT
:
2063 f
->pipe
= usb_rcvintpipe(dev
,
2064 ep
->desc
.bEndpointAddress
);
2065 f
->usb_transfer_mode
= USB_INT
;
2066 packet_size
= le16_to_cpu(ep
->desc
.wMaxPacketSize
);
2068 case USB_ENDPOINT_XFER_BULK
:
2070 f
->pipe
= usb_rcvbulkpipe(dev
,
2071 ep
->desc
.bEndpointAddress
);
2073 f
->pipe
= usb_sndbulkpipe(dev
,
2074 ep
->desc
.bEndpointAddress
);
2075 f
->usb_transfer_mode
= USB_BULK
;
2076 packet_size
= le16_to_cpu(ep
->desc
.wMaxPacketSize
);
2078 case USB_ENDPOINT_XFER_ISOC
:
2080 f
->pipe
= usb_rcvisocpipe(dev
,
2081 ep
->desc
.bEndpointAddress
);
2083 f
->pipe
= usb_sndisocpipe(dev
,
2084 ep
->desc
.bEndpointAddress
);
2085 f
->usb_transfer_mode
= USB_ISOC
;
2086 iso_packet_size
= le16_to_cpu(ep
->desc
.wMaxPacketSize
);
2093 f
->fifonum
= idx
& 7;
2095 f
->usb_packet_maxlen
=
2096 le16_to_cpu(ep
->desc
.wMaxPacketSize
);
2097 f
->intervall
= ep
->desc
.bInterval
;
2101 hw
->dev
= dev
; /* save device */
2102 hw
->if_used
= ifnum
; /* save used interface */
2103 hw
->alt_used
= alt_used
; /* and alternate config */
2104 hw
->ctrl_paksize
= dev
->descriptor
.bMaxPacketSize0
; /* control size */
2105 hw
->cfg_used
= vcf
[16]; /* store used config */
2106 hw
->vend_idx
= vend_idx
; /* store found vendor */
2107 hw
->packet_size
= packet_size
;
2108 hw
->iso_packet_size
= iso_packet_size
;
2110 /* create the control pipes needed for register access */
2111 hw
->ctrl_in_pipe
= usb_rcvctrlpipe(hw
->dev
, 0);
2112 hw
->ctrl_out_pipe
= usb_sndctrlpipe(hw
->dev
, 0);
2113 hw
->ctrl_urb
= usb_alloc_urb(0, GFP_KERNEL
);
2116 (struct hfcsusb_vdata
*)hfcsusb_idtab
[vend_idx
].driver_info
;
2117 printk(KERN_DEBUG
"%s: %s: detected \"%s\" (%s, if=%d alt=%d)\n",
2118 hw
->name
, __func__
, driver_info
->vend_name
,
2119 conf_str
[small_match
], ifnum
, alt_used
);
2121 if (setup_instance(hw
, dev
->dev
.parent
))
2125 usb_set_intfdata(hw
->intf
, hw
);
2129 /* function called when an active device is removed */
2131 hfcsusb_disconnect(struct usb_interface
*intf
)
2133 struct hfcsusb
*hw
= usb_get_intfdata(intf
);
2134 struct hfcsusb
*next
;
2137 printk(KERN_INFO
"%s: device disconnected\n", hw
->name
);
2139 handle_led(hw
, LED_POWER_OFF
);
2142 list_for_each_entry_safe(hw
, next
, &HFClist
, list
)
2147 usb_set_intfdata(intf
, NULL
);
2150 static struct usb_driver hfcsusb_drv
= {
2151 .name
= DRIVER_NAME
,
2152 .id_table
= hfcsusb_idtab
,
2153 .probe
= hfcsusb_probe
,
2154 .disconnect
= hfcsusb_disconnect
,
2157 module_usb_driver(hfcsusb_drv
);