1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * mISDN driver for Colognechip HFC-S USB chip
5 * Copyright 2001 by Peter Sprenger (sprenger@moving-bytes.de)
6 * Copyright 2008 by Martin Bachem (info@bachem-it.com)
9 * debug=<n>, default=0, with n=0xHHHHGGGG
10 * H - l1 driver flags described in hfcsusb.h
11 * G - common mISDN debug flags described at mISDNhw.h
13 * poll=<n>, default 128
14 * n : burst size of PH_DATA_IND at transparent rx data
16 * Revision: 0.3.3 (socket), 2008-11-05
19 #include <linux/module.h>
20 #include <linux/delay.h>
21 #include <linux/usb.h>
22 #include <linux/mISDNhw.h>
23 #include <linux/slab.h>
26 static unsigned int debug
;
27 static int poll
= DEFAULT_TRANSP_BURST_SZ
;
29 static LIST_HEAD(HFClist
);
30 static DEFINE_RWLOCK(HFClock
);
33 MODULE_AUTHOR("Martin Bachem");
34 MODULE_DESCRIPTION("mISDN driver for Colognechip HFC-S USB chip");
35 MODULE_LICENSE("GPL");
36 module_param(debug
, uint
, S_IRUGO
| S_IWUSR
);
37 module_param(poll
, int, 0);
39 static int hfcsusb_cnt
;
41 /* some function prototypes */
42 static void hfcsusb_ph_command(struct hfcsusb
*hw
, u_char command
);
43 static void release_hw(struct hfcsusb
*hw
);
44 static void reset_hfcsusb(struct hfcsusb
*hw
);
45 static void setPortMode(struct hfcsusb
*hw
);
46 static void hfcsusb_start_endpoint(struct hfcsusb
*hw
, int channel
);
47 static void hfcsusb_stop_endpoint(struct hfcsusb
*hw
, int channel
);
48 static int hfcsusb_setup_bch(struct bchannel
*bch
, int protocol
);
49 static void deactivate_bchannel(struct bchannel
*bch
);
50 static int hfcsusb_ph_info(struct hfcsusb
*hw
);
52 /* start next background transfer for control channel */
54 ctrl_start_transfer(struct hfcsusb
*hw
)
56 if (debug
& DBG_HFC_CALL_TRACE
)
57 printk(KERN_DEBUG
"%s: %s\n", hw
->name
, __func__
);
60 hw
->ctrl_urb
->pipe
= hw
->ctrl_out_pipe
;
61 hw
->ctrl_urb
->setup_packet
= (u_char
*)&hw
->ctrl_write
;
62 hw
->ctrl_urb
->transfer_buffer
= NULL
;
63 hw
->ctrl_urb
->transfer_buffer_length
= 0;
64 hw
->ctrl_write
.wIndex
=
65 cpu_to_le16(hw
->ctrl_buff
[hw
->ctrl_out_idx
].hfcs_reg
);
66 hw
->ctrl_write
.wValue
=
67 cpu_to_le16(hw
->ctrl_buff
[hw
->ctrl_out_idx
].reg_val
);
69 usb_submit_urb(hw
->ctrl_urb
, GFP_ATOMIC
);
74 * queue a control transfer request to write HFC-S USB
75 * chip register using CTRL resuest queue
77 static int write_reg(struct hfcsusb
*hw
, __u8 reg
, __u8 val
)
81 if (debug
& DBG_HFC_CALL_TRACE
)
82 printk(KERN_DEBUG
"%s: %s reg(0x%02x) val(0x%02x)\n",
83 hw
->name
, __func__
, reg
, val
);
85 spin_lock(&hw
->ctrl_lock
);
86 if (hw
->ctrl_cnt
>= HFC_CTRL_BUFSIZE
) {
87 spin_unlock(&hw
->ctrl_lock
);
90 buf
= &hw
->ctrl_buff
[hw
->ctrl_in_idx
];
93 if (++hw
->ctrl_in_idx
>= HFC_CTRL_BUFSIZE
)
95 if (++hw
->ctrl_cnt
== 1)
96 ctrl_start_transfer(hw
);
97 spin_unlock(&hw
->ctrl_lock
);
102 /* control completion routine handling background control cmds */
104 ctrl_complete(struct urb
*urb
)
106 struct hfcsusb
*hw
= (struct hfcsusb
*) urb
->context
;
108 if (debug
& DBG_HFC_CALL_TRACE
)
109 printk(KERN_DEBUG
"%s: %s\n", hw
->name
, __func__
);
113 hw
->ctrl_cnt
--; /* decrement actual count */
114 if (++hw
->ctrl_out_idx
>= HFC_CTRL_BUFSIZE
)
115 hw
->ctrl_out_idx
= 0; /* pointer wrap */
117 ctrl_start_transfer(hw
); /* start next transfer */
121 /* handle LED bits */
123 set_led_bit(struct hfcsusb
*hw
, signed short led_bits
, int set_on
)
127 hw
->led_state
&= ~abs(led_bits
);
129 hw
->led_state
|= led_bits
;
132 hw
->led_state
|= abs(led_bits
);
134 hw
->led_state
&= ~led_bits
;
138 /* handle LED requests */
140 handle_led(struct hfcsusb
*hw
, int event
)
142 struct hfcsusb_vdata
*driver_info
= (struct hfcsusb_vdata
*)
143 hfcsusb_idtab
[hw
->vend_idx
].driver_info
;
146 if (driver_info
->led_scheme
== LED_OFF
)
148 tmpled
= hw
->led_state
;
152 set_led_bit(hw
, driver_info
->led_bits
[0], 1);
153 set_led_bit(hw
, driver_info
->led_bits
[1], 0);
154 set_led_bit(hw
, driver_info
->led_bits
[2], 0);
155 set_led_bit(hw
, driver_info
->led_bits
[3], 0);
158 set_led_bit(hw
, driver_info
->led_bits
[0], 0);
159 set_led_bit(hw
, driver_info
->led_bits
[1], 0);
160 set_led_bit(hw
, driver_info
->led_bits
[2], 0);
161 set_led_bit(hw
, driver_info
->led_bits
[3], 0);
164 set_led_bit(hw
, driver_info
->led_bits
[1], 1);
167 set_led_bit(hw
, driver_info
->led_bits
[1], 0);
170 set_led_bit(hw
, driver_info
->led_bits
[2], 1);
173 set_led_bit(hw
, driver_info
->led_bits
[2], 0);
176 set_led_bit(hw
, driver_info
->led_bits
[3], 1);
179 set_led_bit(hw
, driver_info
->led_bits
[3], 0);
183 if (hw
->led_state
!= tmpled
) {
184 if (debug
& DBG_HFC_CALL_TRACE
)
185 printk(KERN_DEBUG
"%s: %s reg(0x%02x) val(x%02x)\n",
187 HFCUSB_P_DATA
, hw
->led_state
);
189 write_reg(hw
, HFCUSB_P_DATA
, hw
->led_state
);
194 * Layer2 -> Layer 1 Bchannel data
197 hfcusb_l2l1B(struct mISDNchannel
*ch
, struct sk_buff
*skb
)
199 struct bchannel
*bch
= container_of(ch
, struct bchannel
, ch
);
200 struct hfcsusb
*hw
= bch
->hw
;
202 struct mISDNhead
*hh
= mISDN_HEAD_P(skb
);
205 if (debug
& DBG_HFC_CALL_TRACE
)
206 printk(KERN_DEBUG
"%s: %s\n", hw
->name
, __func__
);
210 spin_lock_irqsave(&hw
->lock
, flags
);
211 ret
= bchannel_senddata(bch
, skb
);
212 spin_unlock_irqrestore(&hw
->lock
, flags
);
213 if (debug
& DBG_HFC_CALL_TRACE
)
214 printk(KERN_DEBUG
"%s: %s PH_DATA_REQ ret(%i)\n",
215 hw
->name
, __func__
, ret
);
219 case PH_ACTIVATE_REQ
:
220 if (!test_and_set_bit(FLG_ACTIVE
, &bch
->Flags
)) {
221 hfcsusb_start_endpoint(hw
, bch
->nr
- 1);
222 ret
= hfcsusb_setup_bch(bch
, ch
->protocol
);
226 _queue_data(ch
, PH_ACTIVATE_IND
, MISDN_ID_ANY
,
227 0, NULL
, GFP_KERNEL
);
229 case PH_DEACTIVATE_REQ
:
230 deactivate_bchannel(bch
);
231 _queue_data(ch
, PH_DEACTIVATE_IND
, MISDN_ID_ANY
,
232 0, NULL
, GFP_KERNEL
);
242 * send full D/B channel status information
243 * as MPH_INFORMATION_IND
246 hfcsusb_ph_info(struct hfcsusb
*hw
)
249 struct dchannel
*dch
= &hw
->dch
;
252 phi
= kzalloc(struct_size(phi
, bch
, dch
->dev
.nrbchan
), GFP_ATOMIC
);
256 phi
->dch
.ch
.protocol
= hw
->protocol
;
257 phi
->dch
.ch
.Flags
= dch
->Flags
;
258 phi
->dch
.state
= dch
->state
;
259 phi
->dch
.num_bch
= dch
->dev
.nrbchan
;
260 for (i
= 0; i
< dch
->dev
.nrbchan
; i
++) {
261 phi
->bch
[i
].protocol
= hw
->bch
[i
].ch
.protocol
;
262 phi
->bch
[i
].Flags
= hw
->bch
[i
].Flags
;
264 _queue_data(&dch
->dev
.D
, MPH_INFORMATION_IND
, MISDN_ID_ANY
,
265 struct_size(phi
, bch
, dch
->dev
.nrbchan
), phi
, GFP_ATOMIC
);
272 * Layer2 -> Layer 1 Dchannel data
275 hfcusb_l2l1D(struct mISDNchannel
*ch
, struct sk_buff
*skb
)
277 struct mISDNdevice
*dev
= container_of(ch
, struct mISDNdevice
, D
);
278 struct dchannel
*dch
= container_of(dev
, struct dchannel
, dev
);
279 struct mISDNhead
*hh
= mISDN_HEAD_P(skb
);
280 struct hfcsusb
*hw
= dch
->hw
;
286 if (debug
& DBG_HFC_CALL_TRACE
)
287 printk(KERN_DEBUG
"%s: %s: PH_DATA_REQ\n",
290 spin_lock_irqsave(&hw
->lock
, flags
);
291 ret
= dchannel_senddata(dch
, skb
);
292 spin_unlock_irqrestore(&hw
->lock
, flags
);
295 queue_ch_frame(ch
, PH_DATA_CNF
, hh
->id
, NULL
);
299 case PH_ACTIVATE_REQ
:
300 if (debug
& DBG_HFC_CALL_TRACE
)
301 printk(KERN_DEBUG
"%s: %s: PH_ACTIVATE_REQ %s\n",
303 (hw
->protocol
== ISDN_P_NT_S0
) ? "NT" : "TE");
305 if (hw
->protocol
== ISDN_P_NT_S0
) {
307 if (test_bit(FLG_ACTIVE
, &dch
->Flags
)) {
308 _queue_data(&dch
->dev
.D
,
309 PH_ACTIVATE_IND
, MISDN_ID_ANY
, 0,
312 hfcsusb_ph_command(hw
,
314 test_and_set_bit(FLG_L2_ACTIVATED
,
318 hfcsusb_ph_command(hw
, HFC_L1_ACTIVATE_TE
);
319 ret
= l1_event(dch
->l1
, hh
->prim
);
323 case PH_DEACTIVATE_REQ
:
324 if (debug
& DBG_HFC_CALL_TRACE
)
325 printk(KERN_DEBUG
"%s: %s: PH_DEACTIVATE_REQ\n",
327 test_and_clear_bit(FLG_L2_ACTIVATED
, &dch
->Flags
);
329 if (hw
->protocol
== ISDN_P_NT_S0
) {
330 struct sk_buff_head free_queue
;
332 __skb_queue_head_init(&free_queue
);
333 hfcsusb_ph_command(hw
, HFC_L1_DEACTIVATE_NT
);
334 spin_lock_irqsave(&hw
->lock
, flags
);
335 skb_queue_splice_init(&dch
->squeue
, &free_queue
);
337 __skb_queue_tail(&free_queue
, dch
->tx_skb
);
342 __skb_queue_tail(&free_queue
, dch
->rx_skb
);
345 test_and_clear_bit(FLG_TX_BUSY
, &dch
->Flags
);
346 spin_unlock_irqrestore(&hw
->lock
, flags
);
347 __skb_queue_purge(&free_queue
);
349 if (test_and_clear_bit(FLG_L1_BUSY
, &dch
->Flags
))
350 dchannel_sched_event(&hc
->dch
, D_CLEARBUSY
);
354 ret
= l1_event(dch
->l1
, hh
->prim
);
356 case MPH_INFORMATION_REQ
:
357 ret
= hfcsusb_ph_info(hw
);
365 * Layer 1 callback function
368 hfc_l1callback(struct dchannel
*dch
, u_int cmd
)
370 struct hfcsusb
*hw
= dch
->hw
;
372 if (debug
& DBG_HFC_CALL_TRACE
)
373 printk(KERN_DEBUG
"%s: %s cmd 0x%x\n",
374 hw
->name
, __func__
, cmd
);
384 skb_queue_purge(&dch
->squeue
);
386 dev_kfree_skb(dch
->tx_skb
);
391 dev_kfree_skb(dch
->rx_skb
);
394 test_and_clear_bit(FLG_TX_BUSY
, &dch
->Flags
);
396 case PH_ACTIVATE_IND
:
397 test_and_set_bit(FLG_ACTIVE
, &dch
->Flags
);
398 _queue_data(&dch
->dev
.D
, cmd
, MISDN_ID_ANY
, 0, NULL
,
401 case PH_DEACTIVATE_IND
:
402 test_and_clear_bit(FLG_ACTIVE
, &dch
->Flags
);
403 _queue_data(&dch
->dev
.D
, cmd
, MISDN_ID_ANY
, 0, NULL
,
407 if (dch
->debug
& DEBUG_HW
)
408 printk(KERN_DEBUG
"%s: %s: unknown cmd %x\n",
409 hw
->name
, __func__
, cmd
);
412 return hfcsusb_ph_info(hw
);
416 open_dchannel(struct hfcsusb
*hw
, struct mISDNchannel
*ch
,
417 struct channel_req
*rq
)
421 if (debug
& DEBUG_HW_OPEN
)
422 printk(KERN_DEBUG
"%s: %s: dev(%d) open addr(%i) from %p\n",
423 hw
->name
, __func__
, hw
->dch
.dev
.id
, rq
->adr
.channel
,
424 __builtin_return_address(0));
425 if (rq
->protocol
== ISDN_P_NONE
)
428 test_and_clear_bit(FLG_ACTIVE
, &hw
->dch
.Flags
);
429 test_and_clear_bit(FLG_ACTIVE
, &hw
->ech
.Flags
);
430 hfcsusb_start_endpoint(hw
, HFC_CHAN_D
);
432 /* E-Channel logging */
433 if (rq
->adr
.channel
== 1) {
434 if (hw
->fifos
[HFCUSB_PCM_RX
].pipe
) {
435 hfcsusb_start_endpoint(hw
, HFC_CHAN_E
);
436 set_bit(FLG_ACTIVE
, &hw
->ech
.Flags
);
437 _queue_data(&hw
->ech
.dev
.D
, PH_ACTIVATE_IND
,
438 MISDN_ID_ANY
, 0, NULL
, GFP_ATOMIC
);
444 hw
->protocol
= rq
->protocol
;
445 if (rq
->protocol
== ISDN_P_TE_S0
) {
446 err
= create_l1(&hw
->dch
, hfc_l1callback
);
451 ch
->protocol
= rq
->protocol
;
454 if (rq
->protocol
!= ch
->protocol
)
455 return -EPROTONOSUPPORT
;
458 if (((ch
->protocol
== ISDN_P_NT_S0
) && (hw
->dch
.state
== 3)) ||
459 ((ch
->protocol
== ISDN_P_TE_S0
) && (hw
->dch
.state
== 7)))
460 _queue_data(ch
, PH_ACTIVATE_IND
, MISDN_ID_ANY
,
461 0, NULL
, GFP_KERNEL
);
463 if (!try_module_get(THIS_MODULE
))
464 printk(KERN_WARNING
"%s: %s: cannot get module\n",
470 open_bchannel(struct hfcsusb
*hw
, struct channel_req
*rq
)
472 struct bchannel
*bch
;
474 if (rq
->adr
.channel
== 0 || rq
->adr
.channel
> 2)
476 if (rq
->protocol
== ISDN_P_NONE
)
479 if (debug
& DBG_HFC_CALL_TRACE
)
480 printk(KERN_DEBUG
"%s: %s B%i\n",
481 hw
->name
, __func__
, rq
->adr
.channel
);
483 bch
= &hw
->bch
[rq
->adr
.channel
- 1];
484 if (test_and_set_bit(FLG_OPEN
, &bch
->Flags
))
485 return -EBUSY
; /* b-channel can be only open once */
486 bch
->ch
.protocol
= rq
->protocol
;
489 if (!try_module_get(THIS_MODULE
))
490 printk(KERN_WARNING
"%s: %s:cannot get module\n",
496 channel_ctrl(struct hfcsusb
*hw
, struct mISDN_ctrl_req
*cq
)
500 if (debug
& DBG_HFC_CALL_TRACE
)
501 printk(KERN_DEBUG
"%s: %s op(0x%x) channel(0x%x)\n",
502 hw
->name
, __func__
, (cq
->op
), (cq
->channel
));
505 case MISDN_CTRL_GETOP
:
506 cq
->op
= MISDN_CTRL_LOOP
| MISDN_CTRL_CONNECT
|
507 MISDN_CTRL_DISCONNECT
;
510 printk(KERN_WARNING
"%s: %s: unknown Op %x\n",
511 hw
->name
, __func__
, cq
->op
);
519 * device control function
522 hfc_dctrl(struct mISDNchannel
*ch
, u_int cmd
, void *arg
)
524 struct mISDNdevice
*dev
= container_of(ch
, struct mISDNdevice
, D
);
525 struct dchannel
*dch
= container_of(dev
, struct dchannel
, dev
);
526 struct hfcsusb
*hw
= dch
->hw
;
527 struct channel_req
*rq
;
530 if (dch
->debug
& DEBUG_HW
)
531 printk(KERN_DEBUG
"%s: %s: cmd:%x %p\n",
532 hw
->name
, __func__
, cmd
, arg
);
536 if ((rq
->protocol
== ISDN_P_TE_S0
) ||
537 (rq
->protocol
== ISDN_P_NT_S0
))
538 err
= open_dchannel(hw
, ch
, rq
);
540 err
= open_bchannel(hw
, rq
);
546 if (debug
& DEBUG_HW_OPEN
)
548 "%s: %s: dev(%d) close from %p (open %d)\n",
549 hw
->name
, __func__
, hw
->dch
.dev
.id
,
550 __builtin_return_address(0), hw
->open
);
552 hfcsusb_stop_endpoint(hw
, HFC_CHAN_D
);
553 if (hw
->fifos
[HFCUSB_PCM_RX
].pipe
)
554 hfcsusb_stop_endpoint(hw
, HFC_CHAN_E
);
555 handle_led(hw
, LED_POWER_ON
);
557 module_put(THIS_MODULE
);
559 case CONTROL_CHANNEL
:
560 err
= channel_ctrl(hw
, arg
);
563 if (dch
->debug
& DEBUG_HW
)
564 printk(KERN_DEBUG
"%s: %s: unknown command %x\n",
565 hw
->name
, __func__
, cmd
);
572 * S0 TE state change event handler
575 ph_state_te(struct dchannel
*dch
)
577 struct hfcsusb
*hw
= dch
->hw
;
579 if (debug
& DEBUG_HW
) {
580 if (dch
->state
<= HFC_MAX_TE_LAYER1_STATE
)
581 printk(KERN_DEBUG
"%s: %s: %s\n", hw
->name
, __func__
,
582 HFC_TE_LAYER1_STATES
[dch
->state
]);
584 printk(KERN_DEBUG
"%s: %s: TE F%d\n",
585 hw
->name
, __func__
, dch
->state
);
588 switch (dch
->state
) {
590 l1_event(dch
->l1
, HW_RESET_IND
);
593 l1_event(dch
->l1
, HW_DEACT_IND
);
597 l1_event(dch
->l1
, ANYSIGNAL
);
600 l1_event(dch
->l1
, INFO2
);
603 l1_event(dch
->l1
, INFO4_P8
);
607 handle_led(hw
, LED_S0_ON
);
609 handle_led(hw
, LED_S0_OFF
);
613 * S0 NT state change event handler
616 ph_state_nt(struct dchannel
*dch
)
618 struct hfcsusb
*hw
= dch
->hw
;
620 if (debug
& DEBUG_HW
) {
621 if (dch
->state
<= HFC_MAX_NT_LAYER1_STATE
)
622 printk(KERN_DEBUG
"%s: %s: %s\n",
624 HFC_NT_LAYER1_STATES
[dch
->state
]);
627 printk(KERN_INFO DRIVER_NAME
"%s: %s: NT G%d\n",
628 hw
->name
, __func__
, dch
->state
);
631 switch (dch
->state
) {
633 test_and_clear_bit(FLG_ACTIVE
, &dch
->Flags
);
634 test_and_clear_bit(FLG_L2_ACTIVATED
, &dch
->Flags
);
636 hw
->timers
&= ~NT_ACTIVATION_TIMER
;
637 handle_led(hw
, LED_S0_OFF
);
641 if (hw
->nt_timer
< 0) {
643 hw
->timers
&= ~NT_ACTIVATION_TIMER
;
644 hfcsusb_ph_command(dch
->hw
, HFC_L1_DEACTIVATE_NT
);
646 hw
->timers
|= NT_ACTIVATION_TIMER
;
647 hw
->nt_timer
= NT_T1_COUNT
;
648 /* allow G2 -> G3 transition */
649 write_reg(hw
, HFCUSB_STATES
, 2 | HFCUSB_NT_G2_G3
);
654 hw
->timers
&= ~NT_ACTIVATION_TIMER
;
655 test_and_set_bit(FLG_ACTIVE
, &dch
->Flags
);
656 _queue_data(&dch
->dev
.D
, PH_ACTIVATE_IND
,
657 MISDN_ID_ANY
, 0, NULL
, GFP_ATOMIC
);
658 handle_led(hw
, LED_S0_ON
);
662 hw
->timers
&= ~NT_ACTIVATION_TIMER
;
671 ph_state(struct dchannel
*dch
)
673 struct hfcsusb
*hw
= dch
->hw
;
675 if (hw
->protocol
== ISDN_P_NT_S0
)
677 else if (hw
->protocol
== ISDN_P_TE_S0
)
682 * disable/enable BChannel for desired protocol
685 hfcsusb_setup_bch(struct bchannel
*bch
, int protocol
)
687 struct hfcsusb
*hw
= bch
->hw
;
688 __u8 conhdlc
, sctrl
, sctrl_r
;
690 if (debug
& DEBUG_HW
)
691 printk(KERN_DEBUG
"%s: %s: protocol %x-->%x B%d\n",
692 hw
->name
, __func__
, bch
->state
, protocol
,
695 /* setup val for CON_HDLC */
697 if (protocol
> ISDN_P_NONE
)
698 conhdlc
= 8; /* enable FIFO */
701 case (-1): /* used for init */
705 if (bch
->state
== ISDN_P_NONE
)
706 return 0; /* already in idle state */
707 bch
->state
= ISDN_P_NONE
;
708 clear_bit(FLG_HDLC
, &bch
->Flags
);
709 clear_bit(FLG_TRANSPARENT
, &bch
->Flags
);
713 bch
->state
= protocol
;
714 set_bit(FLG_TRANSPARENT
, &bch
->Flags
);
716 case (ISDN_P_B_HDLC
):
717 bch
->state
= protocol
;
718 set_bit(FLG_HDLC
, &bch
->Flags
);
721 if (debug
& DEBUG_HW
)
722 printk(KERN_DEBUG
"%s: %s: prot not known %x\n",
723 hw
->name
, __func__
, protocol
);
727 if (protocol
>= ISDN_P_NONE
) {
728 write_reg(hw
, HFCUSB_FIFO
, (bch
->nr
== 1) ? 0 : 2);
729 write_reg(hw
, HFCUSB_CON_HDLC
, conhdlc
);
730 write_reg(hw
, HFCUSB_INC_RES_F
, 2);
731 write_reg(hw
, HFCUSB_FIFO
, (bch
->nr
== 1) ? 1 : 3);
732 write_reg(hw
, HFCUSB_CON_HDLC
, conhdlc
);
733 write_reg(hw
, HFCUSB_INC_RES_F
, 2);
735 sctrl
= 0x40 + ((hw
->protocol
== ISDN_P_TE_S0
) ? 0x00 : 0x04);
737 if (test_bit(FLG_ACTIVE
, &hw
->bch
[0].Flags
)) {
741 if (test_bit(FLG_ACTIVE
, &hw
->bch
[1].Flags
)) {
745 write_reg(hw
, HFCUSB_SCTRL
, sctrl
);
746 write_reg(hw
, HFCUSB_SCTRL_R
, sctrl_r
);
748 if (protocol
> ISDN_P_NONE
)
749 handle_led(hw
, (bch
->nr
== 1) ? LED_B1_ON
: LED_B2_ON
);
751 handle_led(hw
, (bch
->nr
== 1) ? LED_B1_OFF
:
754 return hfcsusb_ph_info(hw
);
758 hfcsusb_ph_command(struct hfcsusb
*hw
, u_char command
)
760 if (debug
& DEBUG_HW
)
761 printk(KERN_DEBUG
"%s: %s: %x\n",
762 hw
->name
, __func__
, command
);
765 case HFC_L1_ACTIVATE_TE
:
766 /* force sending sending INFO1 */
767 write_reg(hw
, HFCUSB_STATES
, 0x14);
768 /* start l1 activation */
769 write_reg(hw
, HFCUSB_STATES
, 0x04);
772 case HFC_L1_FORCE_DEACTIVATE_TE
:
773 write_reg(hw
, HFCUSB_STATES
, 0x10);
774 write_reg(hw
, HFCUSB_STATES
, 0x03);
777 case HFC_L1_ACTIVATE_NT
:
778 if (hw
->dch
.state
== 3)
779 _queue_data(&hw
->dch
.dev
.D
, PH_ACTIVATE_IND
,
780 MISDN_ID_ANY
, 0, NULL
, GFP_ATOMIC
);
782 write_reg(hw
, HFCUSB_STATES
, HFCUSB_ACTIVATE
|
783 HFCUSB_DO_ACTION
| HFCUSB_NT_G2_G3
);
786 case HFC_L1_DEACTIVATE_NT
:
787 write_reg(hw
, HFCUSB_STATES
,
794 * Layer 1 B-channel hardware access
797 channel_bctrl(struct bchannel
*bch
, struct mISDN_ctrl_req
*cq
)
799 return mISDN_ctrl_bchannel(bch
, cq
);
802 /* collect data from incoming interrupt or isochron USB data */
804 hfcsusb_rx_frame(struct usb_fifo
*fifo
, __u8
*data
, unsigned int len
,
807 struct hfcsusb
*hw
= fifo
->hw
;
808 struct sk_buff
*rx_skb
= NULL
;
810 int fifon
= fifo
->fifonum
;
815 if (debug
& DBG_HFC_CALL_TRACE
)
816 printk(KERN_DEBUG
"%s: %s: fifo(%i) len(%i) "
817 "dch(%p) bch(%p) ech(%p)\n",
818 hw
->name
, __func__
, fifon
, len
,
819 fifo
->dch
, fifo
->bch
, fifo
->ech
);
824 if ((!!fifo
->dch
+ !!fifo
->bch
+ !!fifo
->ech
) != 1) {
825 printk(KERN_DEBUG
"%s: %s: undefined channel\n",
830 spin_lock_irqsave(&hw
->lock
, flags
);
832 rx_skb
= fifo
->dch
->rx_skb
;
833 maxlen
= fifo
->dch
->maxlen
;
837 if (test_bit(FLG_RX_OFF
, &fifo
->bch
->Flags
)) {
838 fifo
->bch
->dropcnt
+= len
;
839 spin_unlock_irqrestore(&hw
->lock
, flags
);
842 maxlen
= bchannel_get_rxbuf(fifo
->bch
, len
);
843 rx_skb
= fifo
->bch
->rx_skb
;
847 pr_warn("%s.B%d: No bufferspace for %d bytes\n",
848 hw
->name
, fifo
->bch
->nr
, len
);
849 spin_unlock_irqrestore(&hw
->lock
, flags
);
852 maxlen
= fifo
->bch
->maxlen
;
853 hdlc
= test_bit(FLG_HDLC
, &fifo
->bch
->Flags
);
856 rx_skb
= fifo
->ech
->rx_skb
;
857 maxlen
= fifo
->ech
->maxlen
;
861 if (fifo
->dch
|| fifo
->ech
) {
863 rx_skb
= mI_alloc_skb(maxlen
, GFP_ATOMIC
);
866 fifo
->dch
->rx_skb
= rx_skb
;
868 fifo
->ech
->rx_skb
= rx_skb
;
871 printk(KERN_DEBUG
"%s: %s: No mem for rx_skb\n",
873 spin_unlock_irqrestore(&hw
->lock
, flags
);
877 /* D/E-Channel SKB range check */
878 if ((rx_skb
->len
+ len
) >= MAX_DFRAME_LEN_L1
) {
879 printk(KERN_DEBUG
"%s: %s: sbk mem exceeded "
880 "for fifo(%d) HFCUSB_D_RX\n",
881 hw
->name
, __func__
, fifon
);
883 spin_unlock_irqrestore(&hw
->lock
, flags
);
888 skb_put_data(rx_skb
, data
, len
);
891 /* we have a complete hdlc packet */
893 if ((rx_skb
->len
> 3) &&
894 (!(rx_skb
->data
[rx_skb
->len
- 1]))) {
895 if (debug
& DBG_HFC_FIFO_VERBOSE
) {
896 printk(KERN_DEBUG
"%s: %s: fifon(%i)"
898 hw
->name
, __func__
, fifon
,
901 while (i
< rx_skb
->len
)
907 /* remove CRC & status */
908 skb_trim(rx_skb
, rx_skb
->len
- 3);
911 recv_Dchannel(fifo
->dch
);
913 recv_Bchannel(fifo
->bch
, MISDN_ID_ANY
,
916 recv_Echannel(fifo
->ech
,
919 if (debug
& DBG_HFC_FIFO_VERBOSE
) {
921 "%s: CRC or minlen ERROR fifon(%i) "
923 hw
->name
, fifon
, rx_skb
->len
);
925 while (i
< rx_skb
->len
)
934 /* deliver transparent data to layer2 */
935 recv_Bchannel(fifo
->bch
, MISDN_ID_ANY
, false);
937 spin_unlock_irqrestore(&hw
->lock
, flags
);
941 fill_isoc_urb(struct urb
*urb
, struct usb_device
*dev
, unsigned int pipe
,
942 void *buf
, int num_packets
, int packet_size
, int interval
,
943 usb_complete_t complete
, void *context
)
947 usb_fill_bulk_urb(urb
, dev
, pipe
, buf
, packet_size
* num_packets
,
950 urb
->number_of_packets
= num_packets
;
951 urb
->transfer_flags
= URB_ISO_ASAP
;
952 urb
->actual_length
= 0;
953 urb
->interval
= interval
;
955 for (k
= 0; k
< num_packets
; k
++) {
956 urb
->iso_frame_desc
[k
].offset
= packet_size
* k
;
957 urb
->iso_frame_desc
[k
].length
= packet_size
;
958 urb
->iso_frame_desc
[k
].actual_length
= 0;
962 /* receive completion routine for all ISO tx fifos */
964 rx_iso_complete(struct urb
*urb
)
966 struct iso_urb
*context_iso_urb
= (struct iso_urb
*) urb
->context
;
967 struct usb_fifo
*fifo
= context_iso_urb
->owner_fifo
;
968 struct hfcsusb
*hw
= fifo
->hw
;
969 int k
, len
, errcode
, offset
, num_isoc_packets
, fifon
, maxlen
,
970 status
, iso_status
, i
;
976 fifon
= fifo
->fifonum
;
977 status
= urb
->status
;
979 spin_lock_irqsave(&hw
->lock
, flags
);
980 if (fifo
->stop_gracefull
) {
981 fifo
->stop_gracefull
= 0;
983 spin_unlock_irqrestore(&hw
->lock
, flags
);
986 spin_unlock_irqrestore(&hw
->lock
, flags
);
989 * ISO transfer only partially completed,
990 * look at individual frame status for details
992 if (status
== -EXDEV
) {
993 if (debug
& DEBUG_HW
)
994 printk(KERN_DEBUG
"%s: %s: with -EXDEV "
995 "urb->status %d, fifonum %d\n",
996 hw
->name
, __func__
, status
, fifon
);
998 /* clear status, so go on with ISO transfers */
1003 if (fifo
->active
&& !status
) {
1004 num_isoc_packets
= iso_packets
[fifon
];
1005 maxlen
= fifo
->usb_packet_maxlen
;
1007 for (k
= 0; k
< num_isoc_packets
; ++k
) {
1008 len
= urb
->iso_frame_desc
[k
].actual_length
;
1009 offset
= urb
->iso_frame_desc
[k
].offset
;
1010 buf
= context_iso_urb
->buffer
+ offset
;
1011 iso_status
= urb
->iso_frame_desc
[k
].status
;
1013 if (iso_status
&& (debug
& DBG_HFC_FIFO_VERBOSE
)) {
1014 printk(KERN_DEBUG
"%s: %s: "
1015 "ISO packet %i, status: %i\n",
1016 hw
->name
, __func__
, k
, iso_status
);
1019 /* USB data log for every D ISO in */
1020 if ((fifon
== HFCUSB_D_RX
) &&
1021 (debug
& DBG_HFC_USB_VERBOSE
)) {
1023 "%s: %s: %d (%d/%d) len(%d) ",
1024 hw
->name
, __func__
, urb
->start_frame
,
1025 k
, num_isoc_packets
- 1,
1027 for (i
= 0; i
< len
; i
++)
1028 printk("%x ", buf
[i
]);
1033 if (fifo
->last_urblen
!= maxlen
) {
1035 * save fifo fill-level threshold bits
1036 * to use them later in TX ISO URB
1039 hw
->threshold_mask
= buf
[1];
1041 if (fifon
== HFCUSB_D_RX
)
1042 s0_state
= (buf
[0] >> 4);
1044 eof
[fifon
] = buf
[0] & 1;
1046 hfcsusb_rx_frame(fifo
, buf
+ 2,
1047 len
- 2, (len
< maxlen
)
1050 hfcsusb_rx_frame(fifo
, buf
, len
,
1053 fifo
->last_urblen
= len
;
1057 /* signal S0 layer1 state change */
1058 if ((s0_state
) && (hw
->initdone
) &&
1059 (s0_state
!= hw
->dch
.state
)) {
1060 hw
->dch
.state
= s0_state
;
1061 schedule_event(&hw
->dch
, FLG_PHCHANGE
);
1064 fill_isoc_urb(urb
, fifo
->hw
->dev
, fifo
->pipe
,
1065 context_iso_urb
->buffer
, num_isoc_packets
,
1066 fifo
->usb_packet_maxlen
, fifo
->intervall
,
1067 (usb_complete_t
)rx_iso_complete
, urb
->context
);
1068 errcode
= usb_submit_urb(urb
, GFP_ATOMIC
);
1070 if (debug
& DEBUG_HW
)
1071 printk(KERN_DEBUG
"%s: %s: error submitting "
1073 hw
->name
, __func__
, errcode
);
1076 if (status
&& (debug
& DBG_HFC_URB_INFO
))
1077 printk(KERN_DEBUG
"%s: %s: rx_iso_complete : "
1078 "urb->status %d, fifonum %d\n",
1079 hw
->name
, __func__
, status
, fifon
);
1083 /* receive completion routine for all interrupt rx fifos */
1085 rx_int_complete(struct urb
*urb
)
1088 __u8
*buf
, maxlen
, fifon
;
1089 struct usb_fifo
*fifo
= (struct usb_fifo
*) urb
->context
;
1090 struct hfcsusb
*hw
= fifo
->hw
;
1092 unsigned long flags
;
1094 spin_lock_irqsave(&hw
->lock
, flags
);
1095 if (fifo
->stop_gracefull
) {
1096 fifo
->stop_gracefull
= 0;
1098 spin_unlock_irqrestore(&hw
->lock
, flags
);
1101 spin_unlock_irqrestore(&hw
->lock
, flags
);
1103 fifon
= fifo
->fifonum
;
1104 if ((!fifo
->active
) || (urb
->status
)) {
1105 if (debug
& DBG_HFC_URB_ERROR
)
1107 "%s: %s: RX-Fifo %i is going down (%i)\n",
1108 hw
->name
, __func__
, fifon
, urb
->status
);
1110 fifo
->urb
->interval
= 0; /* cancel automatic rescheduling */
1113 len
= urb
->actual_length
;
1115 maxlen
= fifo
->usb_packet_maxlen
;
1117 /* USB data log for every D INT in */
1118 if ((fifon
== HFCUSB_D_RX
) && (debug
& DBG_HFC_USB_VERBOSE
)) {
1119 printk(KERN_DEBUG
"%s: %s: D RX INT len(%d) ",
1120 hw
->name
, __func__
, len
);
1121 for (i
= 0; i
< len
; i
++)
1122 printk("%02x ", buf
[i
]);
1126 if (fifo
->last_urblen
!= fifo
->usb_packet_maxlen
) {
1127 /* the threshold mask is in the 2nd status byte */
1128 hw
->threshold_mask
= buf
[1];
1130 /* signal S0 layer1 state change */
1131 if (hw
->initdone
&& ((buf
[0] >> 4) != hw
->dch
.state
)) {
1132 hw
->dch
.state
= (buf
[0] >> 4);
1133 schedule_event(&hw
->dch
, FLG_PHCHANGE
);
1136 eof
[fifon
] = buf
[0] & 1;
1137 /* if we have more than the 2 status bytes -> collect data */
1139 hfcsusb_rx_frame(fifo
, buf
+ 2,
1140 urb
->actual_length
- 2,
1141 (len
< maxlen
) ? eof
[fifon
] : 0);
1143 hfcsusb_rx_frame(fifo
, buf
, urb
->actual_length
,
1144 (len
< maxlen
) ? eof
[fifon
] : 0);
1146 fifo
->last_urblen
= urb
->actual_length
;
1148 status
= usb_submit_urb(urb
, GFP_ATOMIC
);
1150 if (debug
& DEBUG_HW
)
1151 printk(KERN_DEBUG
"%s: %s: error resubmitting USB\n",
1152 hw
->name
, __func__
);
1156 /* transmit completion routine for all ISO tx fifos */
1158 tx_iso_complete(struct urb
*urb
)
1160 struct iso_urb
*context_iso_urb
= (struct iso_urb
*) urb
->context
;
1161 struct usb_fifo
*fifo
= context_iso_urb
->owner_fifo
;
1162 struct hfcsusb
*hw
= fifo
->hw
;
1163 struct sk_buff
*tx_skb
;
1164 int k
, tx_offset
, num_isoc_packets
, sink
, remain
, current_len
,
1167 int frame_complete
, fifon
, status
, fillempty
= 0;
1169 unsigned long flags
;
1171 spin_lock_irqsave(&hw
->lock
, flags
);
1172 if (fifo
->stop_gracefull
) {
1173 fifo
->stop_gracefull
= 0;
1175 spin_unlock_irqrestore(&hw
->lock
, flags
);
1180 tx_skb
= fifo
->dch
->tx_skb
;
1181 tx_idx
= &fifo
->dch
->tx_idx
;
1183 } else if (fifo
->bch
) {
1184 tx_skb
= fifo
->bch
->tx_skb
;
1185 tx_idx
= &fifo
->bch
->tx_idx
;
1186 hdlc
= test_bit(FLG_HDLC
, &fifo
->bch
->Flags
);
1187 if (!tx_skb
&& !hdlc
&&
1188 test_bit(FLG_FILLEMPTY
, &fifo
->bch
->Flags
))
1191 printk(KERN_DEBUG
"%s: %s: neither BCH nor DCH\n",
1192 hw
->name
, __func__
);
1193 spin_unlock_irqrestore(&hw
->lock
, flags
);
1197 fifon
= fifo
->fifonum
;
1198 status
= urb
->status
;
1203 * ISO transfer only partially completed,
1204 * look at individual frame status for details
1206 if (status
== -EXDEV
) {
1207 if (debug
& DBG_HFC_URB_ERROR
)
1208 printk(KERN_DEBUG
"%s: %s: "
1209 "-EXDEV (%i) fifon (%d)\n",
1210 hw
->name
, __func__
, status
, fifon
);
1212 /* clear status, so go on with ISO transfers */
1216 if (fifo
->active
&& !status
) {
1217 /* is FifoFull-threshold set for our channel? */
1218 threshbit
= (hw
->threshold_mask
& (1 << fifon
));
1219 num_isoc_packets
= iso_packets
[fifon
];
1221 /* predict dataflow to avoid fifo overflow */
1222 if (fifon
>= HFCUSB_D_TX
)
1223 sink
= (threshbit
) ? SINK_DMIN
: SINK_DMAX
;
1225 sink
= (threshbit
) ? SINK_MIN
: SINK_MAX
;
1226 fill_isoc_urb(urb
, fifo
->hw
->dev
, fifo
->pipe
,
1227 context_iso_urb
->buffer
, num_isoc_packets
,
1228 fifo
->usb_packet_maxlen
, fifo
->intervall
,
1229 (usb_complete_t
)tx_iso_complete
, urb
->context
);
1230 memset(context_iso_urb
->buffer
, 0,
1231 sizeof(context_iso_urb
->buffer
));
1234 for (k
= 0; k
< num_isoc_packets
; ++k
) {
1235 /* analyze tx success of previous ISO packets */
1236 if (debug
& DBG_HFC_URB_ERROR
) {
1237 errcode
= urb
->iso_frame_desc
[k
].status
;
1239 printk(KERN_DEBUG
"%s: %s: "
1240 "ISO packet %i, status: %i\n",
1241 hw
->name
, __func__
, k
, errcode
);
1245 /* Generate next ISO Packets */
1247 remain
= tx_skb
->len
- *tx_idx
;
1249 remain
= 15; /* > not complete */
1254 fifo
->bit_line
-= sink
;
1255 current_len
= (0 - fifo
->bit_line
) / 8;
1256 if (current_len
> 14)
1258 if (current_len
< 0)
1260 if (remain
< current_len
)
1261 current_len
= remain
;
1263 /* how much bit do we put on the line? */
1264 fifo
->bit_line
+= current_len
* 8;
1266 context_iso_urb
->buffer
[tx_offset
] = 0;
1267 if (current_len
== remain
) {
1269 /* signal frame completion */
1271 buffer
[tx_offset
] = 1;
1272 /* add 2 byte flags and 16bit
1273 * CRC at end of ISDN frame */
1274 fifo
->bit_line
+= 32;
1279 /* copy tx data to iso-urb buffer */
1280 p
= context_iso_urb
->buffer
+ tx_offset
+ 1;
1282 memset(p
, fifo
->bch
->fill
[0],
1285 memcpy(p
, (tx_skb
->data
+ *tx_idx
),
1287 *tx_idx
+= current_len
;
1289 urb
->iso_frame_desc
[k
].offset
= tx_offset
;
1290 urb
->iso_frame_desc
[k
].length
= current_len
+ 1;
1292 /* USB data log for every D ISO out */
1293 if ((fifon
== HFCUSB_D_RX
) && !fillempty
&&
1294 (debug
& DBG_HFC_USB_VERBOSE
)) {
1296 "%s: %s (%d/%d) offs(%d) len(%d) ",
1298 k
, num_isoc_packets
- 1,
1299 urb
->iso_frame_desc
[k
].offset
,
1300 urb
->iso_frame_desc
[k
].length
);
1302 for (i
= urb
->iso_frame_desc
[k
].offset
;
1303 i
< (urb
->iso_frame_desc
[k
].offset
1304 + urb
->iso_frame_desc
[k
].length
);
1307 context_iso_urb
->buffer
[i
]);
1309 printk(" skb->len(%i) tx-idx(%d)\n",
1310 tx_skb
->len
, *tx_idx
);
1313 tx_offset
+= (current_len
+ 1);
1315 urb
->iso_frame_desc
[k
].offset
= tx_offset
++;
1316 urb
->iso_frame_desc
[k
].length
= 1;
1317 /* we lower data margin every msec */
1318 fifo
->bit_line
-= sink
;
1319 if (fifo
->bit_line
< BITLINE_INF
)
1320 fifo
->bit_line
= BITLINE_INF
;
1323 if (frame_complete
) {
1326 if (debug
& DBG_HFC_FIFO_VERBOSE
) {
1327 printk(KERN_DEBUG
"%s: %s: "
1328 "fifon(%i) new TX len(%i): ",
1330 fifon
, tx_skb
->len
);
1332 while (i
< tx_skb
->len
)
1338 dev_consume_skb_irq(tx_skb
);
1340 if (fifo
->dch
&& get_next_dframe(fifo
->dch
))
1341 tx_skb
= fifo
->dch
->tx_skb
;
1342 else if (fifo
->bch
&&
1343 get_next_bframe(fifo
->bch
))
1344 tx_skb
= fifo
->bch
->tx_skb
;
1347 errcode
= usb_submit_urb(urb
, GFP_ATOMIC
);
1349 if (debug
& DEBUG_HW
)
1351 "%s: %s: error submitting ISO URB: %d \n",
1352 hw
->name
, __func__
, errcode
);
1356 * abuse DChannel tx iso completion to trigger NT mode state
1357 * changes tx_iso_complete is assumed to be called every
1358 * fifo->intervall (ms)
1360 if ((fifon
== HFCUSB_D_TX
) && (hw
->protocol
== ISDN_P_NT_S0
)
1361 && (hw
->timers
& NT_ACTIVATION_TIMER
)) {
1362 if ((--hw
->nt_timer
) < 0)
1363 schedule_event(&hw
->dch
, FLG_PHCHANGE
);
1367 if (status
&& (debug
& DBG_HFC_URB_ERROR
))
1368 printk(KERN_DEBUG
"%s: %s: urb->status %s (%i)"
1371 symbolic(urb_errlist
, status
), status
, fifon
);
1373 spin_unlock_irqrestore(&hw
->lock
, flags
);
1377 * allocs urbs and start isoc transfer with two pending urbs to avoid
1378 * gaps in the transfer chain
1381 start_isoc_chain(struct usb_fifo
*fifo
, int num_packets_per_urb
,
1382 usb_complete_t complete
, int packet_size
)
1384 struct hfcsusb
*hw
= fifo
->hw
;
1388 printk(KERN_DEBUG
"%s: %s: fifo %i\n",
1389 hw
->name
, __func__
, fifo
->fifonum
);
1391 /* allocate Memory for Iso out Urbs */
1392 for (i
= 0; i
< 2; i
++) {
1393 if (!(fifo
->iso
[i
].urb
)) {
1395 usb_alloc_urb(num_packets_per_urb
, GFP_KERNEL
);
1396 if (!(fifo
->iso
[i
].urb
)) {
1398 "%s: %s: alloc urb for fifo %i failed",
1399 hw
->name
, __func__
, fifo
->fifonum
);
1402 fifo
->iso
[i
].owner_fifo
= (struct usb_fifo
*) fifo
;
1403 fifo
->iso
[i
].indx
= i
;
1405 /* Init the first iso */
1406 if (ISO_BUFFER_SIZE
>=
1407 (fifo
->usb_packet_maxlen
*
1408 num_packets_per_urb
)) {
1409 fill_isoc_urb(fifo
->iso
[i
].urb
,
1410 fifo
->hw
->dev
, fifo
->pipe
,
1411 fifo
->iso
[i
].buffer
,
1412 num_packets_per_urb
,
1413 fifo
->usb_packet_maxlen
,
1414 fifo
->intervall
, complete
,
1416 memset(fifo
->iso
[i
].buffer
, 0,
1417 sizeof(fifo
->iso
[i
].buffer
));
1419 for (k
= 0; k
< num_packets_per_urb
; k
++) {
1421 iso_frame_desc
[k
].offset
=
1424 iso_frame_desc
[k
].length
=
1429 "%s: %s: ISO Buffer size to small!\n",
1430 hw
->name
, __func__
);
1433 fifo
->bit_line
= BITLINE_INF
;
1435 errcode
= usb_submit_urb(fifo
->iso
[i
].urb
, GFP_KERNEL
);
1436 fifo
->active
= (errcode
>= 0) ? 1 : 0;
1437 fifo
->stop_gracefull
= 0;
1439 printk(KERN_DEBUG
"%s: %s: %s URB nr:%d\n",
1441 symbolic(urb_errlist
, errcode
), i
);
1444 return fifo
->active
;
1448 stop_iso_gracefull(struct usb_fifo
*fifo
)
1450 struct hfcsusb
*hw
= fifo
->hw
;
1454 for (i
= 0; i
< 2; i
++) {
1455 spin_lock_irqsave(&hw
->lock
, flags
);
1457 printk(KERN_DEBUG
"%s: %s for fifo %i.%i\n",
1458 hw
->name
, __func__
, fifo
->fifonum
, i
);
1459 fifo
->stop_gracefull
= 1;
1460 spin_unlock_irqrestore(&hw
->lock
, flags
);
1463 for (i
= 0; i
< 2; i
++) {
1465 while (fifo
->stop_gracefull
&& timeout
--)
1466 schedule_timeout_interruptible((HZ
/ 1000) * 16);
1467 if (debug
&& fifo
->stop_gracefull
)
1468 printk(KERN_DEBUG
"%s: ERROR %s for fifo %i.%i\n",
1469 hw
->name
, __func__
, fifo
->fifonum
, i
);
1474 stop_int_gracefull(struct usb_fifo
*fifo
)
1476 struct hfcsusb
*hw
= fifo
->hw
;
1480 spin_lock_irqsave(&hw
->lock
, flags
);
1482 printk(KERN_DEBUG
"%s: %s for fifo %i\n",
1483 hw
->name
, __func__
, fifo
->fifonum
);
1484 fifo
->stop_gracefull
= 1;
1485 spin_unlock_irqrestore(&hw
->lock
, flags
);
1488 while (fifo
->stop_gracefull
&& timeout
--)
1489 schedule_timeout_interruptible((HZ
/ 1000) * 3);
1490 if (debug
&& fifo
->stop_gracefull
)
1491 printk(KERN_DEBUG
"%s: ERROR %s for fifo %i\n",
1492 hw
->name
, __func__
, fifo
->fifonum
);
1495 /* start the interrupt transfer for the given fifo */
1497 start_int_fifo(struct usb_fifo
*fifo
)
1499 struct hfcsusb
*hw
= fifo
->hw
;
1503 printk(KERN_DEBUG
"%s: %s: INT IN fifo:%d\n",
1504 hw
->name
, __func__
, fifo
->fifonum
);
1507 fifo
->urb
= usb_alloc_urb(0, GFP_KERNEL
);
1511 usb_fill_int_urb(fifo
->urb
, fifo
->hw
->dev
, fifo
->pipe
,
1512 fifo
->buffer
, fifo
->usb_packet_maxlen
,
1513 (usb_complete_t
)rx_int_complete
, fifo
, fifo
->intervall
);
1515 fifo
->stop_gracefull
= 0;
1516 errcode
= usb_submit_urb(fifo
->urb
, GFP_KERNEL
);
1518 printk(KERN_DEBUG
"%s: %s: submit URB: status:%i\n",
1519 hw
->name
, __func__
, errcode
);
1525 setPortMode(struct hfcsusb
*hw
)
1527 if (debug
& DEBUG_HW
)
1528 printk(KERN_DEBUG
"%s: %s %s\n", hw
->name
, __func__
,
1529 (hw
->protocol
== ISDN_P_TE_S0
) ? "TE" : "NT");
1531 if (hw
->protocol
== ISDN_P_TE_S0
) {
1532 write_reg(hw
, HFCUSB_SCTRL
, 0x40);
1533 write_reg(hw
, HFCUSB_SCTRL_E
, 0x00);
1534 write_reg(hw
, HFCUSB_CLKDEL
, CLKDEL_TE
);
1535 write_reg(hw
, HFCUSB_STATES
, 3 | 0x10);
1536 write_reg(hw
, HFCUSB_STATES
, 3);
1538 write_reg(hw
, HFCUSB_SCTRL
, 0x44);
1539 write_reg(hw
, HFCUSB_SCTRL_E
, 0x09);
1540 write_reg(hw
, HFCUSB_CLKDEL
, CLKDEL_NT
);
1541 write_reg(hw
, HFCUSB_STATES
, 1 | 0x10);
1542 write_reg(hw
, HFCUSB_STATES
, 1);
1547 reset_hfcsusb(struct hfcsusb
*hw
)
1549 struct usb_fifo
*fifo
;
1552 if (debug
& DEBUG_HW
)
1553 printk(KERN_DEBUG
"%s: %s\n", hw
->name
, __func__
);
1556 write_reg(hw
, HFCUSB_CIRM
, 8);
1558 /* aux = output, reset off */
1559 write_reg(hw
, HFCUSB_CIRM
, 0x10);
1561 /* set USB_SIZE to match the wMaxPacketSize for INT or BULK transfers */
1562 write_reg(hw
, HFCUSB_USB_SIZE
, (hw
->packet_size
/ 8) |
1563 ((hw
->packet_size
/ 8) << 4));
1565 /* set USB_SIZE_I to match the wMaxPacketSize for ISO transfers */
1566 write_reg(hw
, HFCUSB_USB_SIZE_I
, hw
->iso_packet_size
);
1568 /* enable PCM/GCI master mode */
1569 write_reg(hw
, HFCUSB_MST_MODE1
, 0); /* set default values */
1570 write_reg(hw
, HFCUSB_MST_MODE0
, 1); /* enable master mode */
1572 /* init the fifos */
1573 write_reg(hw
, HFCUSB_F_THRES
,
1574 (HFCUSB_TX_THRESHOLD
/ 8) | ((HFCUSB_RX_THRESHOLD
/ 8) << 4));
1577 for (i
= 0; i
< HFCUSB_NUM_FIFOS
; i
++) {
1578 write_reg(hw
, HFCUSB_FIFO
, i
); /* select the desired fifo */
1580 (i
<= HFCUSB_B2_RX
) ? MAX_BCH_SIZE
: MAX_DFRAME_LEN
;
1581 fifo
[i
].last_urblen
= 0;
1583 /* set 2 bit for D- & E-channel */
1584 write_reg(hw
, HFCUSB_HDLC_PAR
, ((i
<= HFCUSB_B2_RX
) ? 0 : 2));
1586 /* enable all fifos */
1587 if (i
== HFCUSB_D_TX
)
1588 write_reg(hw
, HFCUSB_CON_HDLC
,
1589 (hw
->protocol
== ISDN_P_NT_S0
) ? 0x08 : 0x09);
1591 write_reg(hw
, HFCUSB_CON_HDLC
, 0x08);
1592 write_reg(hw
, HFCUSB_INC_RES_F
, 2); /* reset the fifo */
1595 write_reg(hw
, HFCUSB_SCTRL_R
, 0); /* disable both B receivers */
1596 handle_led(hw
, LED_POWER_ON
);
1599 /* start USB data pipes dependand on device's endpoint configuration */
1601 hfcsusb_start_endpoint(struct hfcsusb
*hw
, int channel
)
1603 /* quick check if endpoint already running */
1604 if ((channel
== HFC_CHAN_D
) && (hw
->fifos
[HFCUSB_D_RX
].active
))
1606 if ((channel
== HFC_CHAN_B1
) && (hw
->fifos
[HFCUSB_B1_RX
].active
))
1608 if ((channel
== HFC_CHAN_B2
) && (hw
->fifos
[HFCUSB_B2_RX
].active
))
1610 if ((channel
== HFC_CHAN_E
) && (hw
->fifos
[HFCUSB_PCM_RX
].active
))
1613 /* start rx endpoints using USB INT IN method */
1614 if (hw
->cfg_used
== CNF_3INT3ISO
|| hw
->cfg_used
== CNF_4INT3ISO
)
1615 start_int_fifo(hw
->fifos
+ channel
* 2 + 1);
1617 /* start rx endpoints using USB ISO IN method */
1618 if (hw
->cfg_used
== CNF_3ISO3ISO
|| hw
->cfg_used
== CNF_4ISO3ISO
) {
1621 start_isoc_chain(hw
->fifos
+ HFCUSB_D_RX
,
1623 (usb_complete_t
)rx_iso_complete
,
1627 start_isoc_chain(hw
->fifos
+ HFCUSB_PCM_RX
,
1629 (usb_complete_t
)rx_iso_complete
,
1633 start_isoc_chain(hw
->fifos
+ HFCUSB_B1_RX
,
1635 (usb_complete_t
)rx_iso_complete
,
1639 start_isoc_chain(hw
->fifos
+ HFCUSB_B2_RX
,
1641 (usb_complete_t
)rx_iso_complete
,
1647 /* start tx endpoints using USB ISO OUT method */
1650 start_isoc_chain(hw
->fifos
+ HFCUSB_D_TX
,
1652 (usb_complete_t
)tx_iso_complete
, 1);
1655 start_isoc_chain(hw
->fifos
+ HFCUSB_B1_TX
,
1657 (usb_complete_t
)tx_iso_complete
, 1);
1660 start_isoc_chain(hw
->fifos
+ HFCUSB_B2_TX
,
1662 (usb_complete_t
)tx_iso_complete
, 1);
1667 /* stop USB data pipes dependand on device's endpoint configuration */
1669 hfcsusb_stop_endpoint(struct hfcsusb
*hw
, int channel
)
1671 /* quick check if endpoint currently running */
1672 if ((channel
== HFC_CHAN_D
) && (!hw
->fifos
[HFCUSB_D_RX
].active
))
1674 if ((channel
== HFC_CHAN_B1
) && (!hw
->fifos
[HFCUSB_B1_RX
].active
))
1676 if ((channel
== HFC_CHAN_B2
) && (!hw
->fifos
[HFCUSB_B2_RX
].active
))
1678 if ((channel
== HFC_CHAN_E
) && (!hw
->fifos
[HFCUSB_PCM_RX
].active
))
1681 /* rx endpoints using USB INT IN method */
1682 if (hw
->cfg_used
== CNF_3INT3ISO
|| hw
->cfg_used
== CNF_4INT3ISO
)
1683 stop_int_gracefull(hw
->fifos
+ channel
* 2 + 1);
1685 /* rx endpoints using USB ISO IN method */
1686 if (hw
->cfg_used
== CNF_3ISO3ISO
|| hw
->cfg_used
== CNF_4ISO3ISO
)
1687 stop_iso_gracefull(hw
->fifos
+ channel
* 2 + 1);
1689 /* tx endpoints using USB ISO OUT method */
1690 if (channel
!= HFC_CHAN_E
)
1691 stop_iso_gracefull(hw
->fifos
+ channel
* 2);
1695 /* Hardware Initialization */
1697 setup_hfcsusb(struct hfcsusb
*hw
)
1699 void *dmabuf
= kmalloc(sizeof(u_char
), GFP_KERNEL
);
1703 if (debug
& DBG_HFC_CALL_TRACE
)
1704 printk(KERN_DEBUG
"%s: %s\n", hw
->name
, __func__
);
1709 ret
= read_reg_atomic(hw
, HFCUSB_CHIP_ID
, dmabuf
);
1711 memcpy(&b
, dmabuf
, sizeof(u_char
));
1714 /* check the chip id */
1716 printk(KERN_DEBUG
"%s: %s: cannot read chip id\n",
1717 hw
->name
, __func__
);
1720 if (b
!= HFCUSB_CHIPID
) {
1721 printk(KERN_DEBUG
"%s: %s: Invalid chip id 0x%02x\n",
1722 hw
->name
, __func__
, b
);
1726 /* first set the needed config, interface and alternate */
1727 (void) usb_set_interface(hw
->dev
, hw
->if_used
, hw
->alt_used
);
1731 /* init the background machinery for control requests */
1732 hw
->ctrl_read
.bRequestType
= 0xc0;
1733 hw
->ctrl_read
.bRequest
= 1;
1734 hw
->ctrl_read
.wLength
= cpu_to_le16(1);
1735 hw
->ctrl_write
.bRequestType
= 0x40;
1736 hw
->ctrl_write
.bRequest
= 0;
1737 hw
->ctrl_write
.wLength
= 0;
1738 usb_fill_control_urb(hw
->ctrl_urb
, hw
->dev
, hw
->ctrl_out_pipe
,
1739 (u_char
*)&hw
->ctrl_write
, NULL
, 0,
1740 (usb_complete_t
)ctrl_complete
, hw
);
1747 release_hw(struct hfcsusb
*hw
)
1749 if (debug
& DBG_HFC_CALL_TRACE
)
1750 printk(KERN_DEBUG
"%s: %s\n", hw
->name
, __func__
);
1753 * stop all endpoints gracefully
1754 * TODO: mISDN_core should generate CLOSE_CHANNEL
1755 * signals after calling mISDN_unregister_device()
1757 hfcsusb_stop_endpoint(hw
, HFC_CHAN_D
);
1758 hfcsusb_stop_endpoint(hw
, HFC_CHAN_B1
);
1759 hfcsusb_stop_endpoint(hw
, HFC_CHAN_B2
);
1760 if (hw
->fifos
[HFCUSB_PCM_RX
].pipe
)
1761 hfcsusb_stop_endpoint(hw
, HFC_CHAN_E
);
1762 if (hw
->protocol
== ISDN_P_TE_S0
)
1763 l1_event(hw
->dch
.l1
, CLOSE_CHANNEL
);
1765 mISDN_unregister_device(&hw
->dch
.dev
);
1766 mISDN_freebchannel(&hw
->bch
[1]);
1767 mISDN_freebchannel(&hw
->bch
[0]);
1768 mISDN_freedchannel(&hw
->dch
);
1771 usb_kill_urb(hw
->ctrl_urb
);
1772 usb_free_urb(hw
->ctrl_urb
);
1773 hw
->ctrl_urb
= NULL
;
1777 usb_set_intfdata(hw
->intf
, NULL
);
1778 list_del(&hw
->list
);
1784 deactivate_bchannel(struct bchannel
*bch
)
1786 struct hfcsusb
*hw
= bch
->hw
;
1789 if (bch
->debug
& DEBUG_HW
)
1790 printk(KERN_DEBUG
"%s: %s: bch->nr(%i)\n",
1791 hw
->name
, __func__
, bch
->nr
);
1793 spin_lock_irqsave(&hw
->lock
, flags
);
1794 mISDN_clear_bchannel(bch
);
1795 spin_unlock_irqrestore(&hw
->lock
, flags
);
1796 hfcsusb_setup_bch(bch
, ISDN_P_NONE
);
1797 hfcsusb_stop_endpoint(hw
, bch
->nr
- 1);
1801 * Layer 1 B-channel hardware access
1804 hfc_bctrl(struct mISDNchannel
*ch
, u_int cmd
, void *arg
)
1806 struct bchannel
*bch
= container_of(ch
, struct bchannel
, ch
);
1809 if (bch
->debug
& DEBUG_HW
)
1810 printk(KERN_DEBUG
"%s: cmd:%x %p\n", __func__
, cmd
, arg
);
1814 case HW_TESTRX_HDLC
:
1820 test_and_clear_bit(FLG_OPEN
, &bch
->Flags
);
1821 deactivate_bchannel(bch
);
1822 ch
->protocol
= ISDN_P_NONE
;
1824 module_put(THIS_MODULE
);
1827 case CONTROL_CHANNEL
:
1828 ret
= channel_bctrl(bch
, arg
);
1831 printk(KERN_WARNING
"%s: unknown prim(%x)\n",
1838 setup_instance(struct hfcsusb
*hw
, struct device
*parent
)
1843 if (debug
& DBG_HFC_CALL_TRACE
)
1844 printk(KERN_DEBUG
"%s: %s\n", hw
->name
, __func__
);
1846 spin_lock_init(&hw
->ctrl_lock
);
1847 spin_lock_init(&hw
->lock
);
1849 mISDN_initdchannel(&hw
->dch
, MAX_DFRAME_LEN_L1
, ph_state
);
1850 hw
->dch
.debug
= debug
& 0xFFFF;
1852 hw
->dch
.dev
.Dprotocols
= (1 << ISDN_P_TE_S0
) | (1 << ISDN_P_NT_S0
);
1853 hw
->dch
.dev
.D
.send
= hfcusb_l2l1D
;
1854 hw
->dch
.dev
.D
.ctrl
= hfc_dctrl
;
1856 /* enable E-Channel logging */
1857 if (hw
->fifos
[HFCUSB_PCM_RX
].pipe
)
1858 mISDN_initdchannel(&hw
->ech
, MAX_DFRAME_LEN_L1
, NULL
);
1860 hw
->dch
.dev
.Bprotocols
= (1 << (ISDN_P_B_RAW
& ISDN_P_B_MASK
)) |
1861 (1 << (ISDN_P_B_HDLC
& ISDN_P_B_MASK
));
1862 hw
->dch
.dev
.nrbchan
= 2;
1863 for (i
= 0; i
< 2; i
++) {
1864 hw
->bch
[i
].nr
= i
+ 1;
1865 set_channelmap(i
+ 1, hw
->dch
.dev
.channelmap
);
1866 hw
->bch
[i
].debug
= debug
;
1867 mISDN_initbchannel(&hw
->bch
[i
], MAX_DATA_MEM
, poll
>> 1);
1869 hw
->bch
[i
].ch
.send
= hfcusb_l2l1B
;
1870 hw
->bch
[i
].ch
.ctrl
= hfc_bctrl
;
1871 hw
->bch
[i
].ch
.nr
= i
+ 1;
1872 list_add(&hw
->bch
[i
].ch
.list
, &hw
->dch
.dev
.bchannels
);
1875 hw
->fifos
[HFCUSB_B1_TX
].bch
= &hw
->bch
[0];
1876 hw
->fifos
[HFCUSB_B1_RX
].bch
= &hw
->bch
[0];
1877 hw
->fifos
[HFCUSB_B2_TX
].bch
= &hw
->bch
[1];
1878 hw
->fifos
[HFCUSB_B2_RX
].bch
= &hw
->bch
[1];
1879 hw
->fifos
[HFCUSB_D_TX
].dch
= &hw
->dch
;
1880 hw
->fifos
[HFCUSB_D_RX
].dch
= &hw
->dch
;
1881 hw
->fifos
[HFCUSB_PCM_RX
].ech
= &hw
->ech
;
1882 hw
->fifos
[HFCUSB_PCM_TX
].ech
= &hw
->ech
;
1884 err
= setup_hfcsusb(hw
);
1888 snprintf(hw
->name
, MISDN_MAX_IDLEN
- 1, "%s.%d", DRIVER_NAME
,
1890 printk(KERN_INFO
"%s: registered as '%s'\n",
1891 DRIVER_NAME
, hw
->name
);
1893 err
= mISDN_register_device(&hw
->dch
.dev
, parent
, hw
->name
);
1898 write_lock_irqsave(&HFClock
, flags
);
1899 list_add_tail(&hw
->list
, &HFClist
);
1900 write_unlock_irqrestore(&HFClock
, flags
);
1904 mISDN_freebchannel(&hw
->bch
[1]);
1905 mISDN_freebchannel(&hw
->bch
[0]);
1906 mISDN_freedchannel(&hw
->dch
);
1912 hfcsusb_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
)
1915 struct usb_device
*dev
= interface_to_usbdev(intf
);
1916 struct usb_host_interface
*iface
= intf
->cur_altsetting
;
1917 struct usb_host_interface
*iface_used
= NULL
;
1918 struct usb_host_endpoint
*ep
;
1919 struct hfcsusb_vdata
*driver_info
;
1920 int ifnum
= iface
->desc
.bInterfaceNumber
, i
, idx
, alt_idx
,
1921 probe_alt_setting
, vend_idx
, cfg_used
, *vcf
, attr
, cfg_found
,
1922 ep_addr
, cmptbl
[16], small_match
, iso_packet_size
, packet_size
,
1926 for (i
= 0; hfcsusb_idtab
[i
].idVendor
; i
++) {
1927 if ((le16_to_cpu(dev
->descriptor
.idVendor
)
1928 == hfcsusb_idtab
[i
].idVendor
) &&
1929 (le16_to_cpu(dev
->descriptor
.idProduct
)
1930 == hfcsusb_idtab
[i
].idProduct
)) {
1937 "%s: interface(%d) actalt(%d) minor(%d) vend_idx(%d)\n",
1938 __func__
, ifnum
, iface
->desc
.bAlternateSetting
,
1939 intf
->minor
, vend_idx
);
1941 if (vend_idx
== 0xffff) {
1943 "%s: no valid vendor found in USB descriptor\n",
1947 /* if vendor and product ID is OK, start probing alternate settings */
1951 /* default settings */
1952 iso_packet_size
= 16;
1955 while (alt_idx
< intf
->num_altsetting
) {
1956 iface
= intf
->altsetting
+ alt_idx
;
1957 probe_alt_setting
= iface
->desc
.bAlternateSetting
;
1960 while (validconf
[cfg_used
][0]) {
1962 vcf
= validconf
[cfg_used
];
1963 ep
= iface
->endpoint
;
1964 memcpy(cmptbl
, vcf
, 16 * sizeof(int));
1966 /* check for all endpoints in this alternate setting */
1967 for (i
= 0; i
< iface
->desc
.bNumEndpoints
; i
++) {
1968 ep_addr
= ep
->desc
.bEndpointAddress
;
1970 /* get endpoint base */
1971 idx
= ((ep_addr
& 0x7f) - 1) * 2;
1977 attr
= ep
->desc
.bmAttributes
;
1979 if (cmptbl
[idx
] != EP_NOP
) {
1980 if (cmptbl
[idx
] == EP_NUL
)
1982 if (attr
== USB_ENDPOINT_XFER_INT
1983 && cmptbl
[idx
] == EP_INT
)
1984 cmptbl
[idx
] = EP_NUL
;
1985 if (attr
== USB_ENDPOINT_XFER_BULK
1986 && cmptbl
[idx
] == EP_BLK
)
1987 cmptbl
[idx
] = EP_NUL
;
1988 if (attr
== USB_ENDPOINT_XFER_ISOC
1989 && cmptbl
[idx
] == EP_ISO
)
1990 cmptbl
[idx
] = EP_NUL
;
1992 if (attr
== USB_ENDPOINT_XFER_INT
&&
1993 ep
->desc
.bInterval
< vcf
[17]) {
2000 for (i
= 0; i
< 16; i
++)
2001 if (cmptbl
[i
] != EP_NOP
&& cmptbl
[i
] != EP_NUL
)
2005 if (small_match
< cfg_used
) {
2006 small_match
= cfg_used
;
2007 alt_used
= probe_alt_setting
;
2014 } /* (alt_idx < intf->num_altsetting) */
2016 /* not found a valid USB Ta Endpoint config */
2017 if (small_match
== -1)
2021 hw
= kzalloc(sizeof(struct hfcsusb
), GFP_KERNEL
);
2023 return -ENOMEM
; /* got no mem */
2024 snprintf(hw
->name
, MISDN_MAX_IDLEN
- 1, "%s", DRIVER_NAME
);
2026 ep
= iface
->endpoint
;
2027 vcf
= validconf
[small_match
];
2029 for (i
= 0; i
< iface
->desc
.bNumEndpoints
; i
++) {
2032 ep_addr
= ep
->desc
.bEndpointAddress
;
2033 /* get endpoint base */
2034 idx
= ((ep_addr
& 0x7f) - 1) * 2;
2037 f
= &hw
->fifos
[idx
& 7];
2039 /* init Endpoints */
2040 if (vcf
[idx
] == EP_NOP
|| vcf
[idx
] == EP_NUL
) {
2044 switch (ep
->desc
.bmAttributes
) {
2045 case USB_ENDPOINT_XFER_INT
:
2046 f
->pipe
= usb_rcvintpipe(dev
,
2047 ep
->desc
.bEndpointAddress
);
2048 f
->usb_transfer_mode
= USB_INT
;
2049 packet_size
= le16_to_cpu(ep
->desc
.wMaxPacketSize
);
2051 case USB_ENDPOINT_XFER_BULK
:
2053 f
->pipe
= usb_rcvbulkpipe(dev
,
2054 ep
->desc
.bEndpointAddress
);
2056 f
->pipe
= usb_sndbulkpipe(dev
,
2057 ep
->desc
.bEndpointAddress
);
2058 f
->usb_transfer_mode
= USB_BULK
;
2059 packet_size
= le16_to_cpu(ep
->desc
.wMaxPacketSize
);
2061 case USB_ENDPOINT_XFER_ISOC
:
2063 f
->pipe
= usb_rcvisocpipe(dev
,
2064 ep
->desc
.bEndpointAddress
);
2066 f
->pipe
= usb_sndisocpipe(dev
,
2067 ep
->desc
.bEndpointAddress
);
2068 f
->usb_transfer_mode
= USB_ISOC
;
2069 iso_packet_size
= le16_to_cpu(ep
->desc
.wMaxPacketSize
);
2076 f
->fifonum
= idx
& 7;
2078 f
->usb_packet_maxlen
=
2079 le16_to_cpu(ep
->desc
.wMaxPacketSize
);
2080 f
->intervall
= ep
->desc
.bInterval
;
2084 hw
->dev
= dev
; /* save device */
2085 hw
->if_used
= ifnum
; /* save used interface */
2086 hw
->alt_used
= alt_used
; /* and alternate config */
2087 hw
->ctrl_paksize
= dev
->descriptor
.bMaxPacketSize0
; /* control size */
2088 hw
->cfg_used
= vcf
[16]; /* store used config */
2089 hw
->vend_idx
= vend_idx
; /* store found vendor */
2090 hw
->packet_size
= packet_size
;
2091 hw
->iso_packet_size
= iso_packet_size
;
2093 /* create the control pipes needed for register access */
2094 hw
->ctrl_in_pipe
= usb_rcvctrlpipe(hw
->dev
, 0);
2095 hw
->ctrl_out_pipe
= usb_sndctrlpipe(hw
->dev
, 0);
2097 driver_info
= (struct hfcsusb_vdata
*)
2098 hfcsusb_idtab
[vend_idx
].driver_info
;
2100 hw
->ctrl_urb
= usb_alloc_urb(0, GFP_KERNEL
);
2101 if (!hw
->ctrl_urb
) {
2102 pr_warn("%s: No memory for control urb\n",
2103 driver_info
->vend_name
);
2108 pr_info("%s: %s: detected \"%s\" (%s, if=%d alt=%d)\n",
2109 hw
->name
, __func__
, driver_info
->vend_name
,
2110 conf_str
[small_match
], ifnum
, alt_used
);
2112 if (setup_instance(hw
, dev
->dev
.parent
))
2116 usb_set_intfdata(hw
->intf
, hw
);
2120 /* function called when an active device is removed */
2122 hfcsusb_disconnect(struct usb_interface
*intf
)
2124 struct hfcsusb
*hw
= usb_get_intfdata(intf
);
2125 struct hfcsusb
*next
;
2128 printk(KERN_INFO
"%s: device disconnected\n", hw
->name
);
2130 handle_led(hw
, LED_POWER_OFF
);
2133 list_for_each_entry_safe(hw
, next
, &HFClist
, list
)
2138 usb_set_intfdata(intf
, NULL
);
2141 static struct usb_driver hfcsusb_drv
= {
2142 .name
= DRIVER_NAME
,
2143 .id_table
= hfcsusb_idtab
,
2144 .probe
= hfcsusb_probe
,
2145 .disconnect
= hfcsusb_disconnect
,
2146 .disable_hub_initiated_lpm
= 1,
2149 module_usb_driver(hfcsusb_drv
);