Lines Matching +full:channel +full:- +full:fifo +full:- +full:len
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)
10 * H - l1 driver flags described in hfcsusb.h
11 * G - common mISDN debug flags described at mISDNhw.h
16 * Revision: 0.3.3 (socket), 2008-11-05
34 MODULE_DESCRIPTION("mISDN driver for Colognechip HFC-S USB chip");
46 static void hfcsusb_start_endpoint(struct hfcsusb *hw, int channel);
47 static void hfcsusb_stop_endpoint(struct hfcsusb *hw, int channel);
52 /* start next background transfer for control channel */
57 printk(KERN_DEBUG "%s: %s\n", hw->name, __func__); in ctrl_start_transfer()
59 if (hw->ctrl_cnt) { in ctrl_start_transfer()
60 hw->ctrl_urb->pipe = hw->ctrl_out_pipe; in ctrl_start_transfer()
61 hw->ctrl_urb->setup_packet = (u_char *)&hw->ctrl_write; in ctrl_start_transfer()
62 hw->ctrl_urb->transfer_buffer = NULL; in ctrl_start_transfer()
63 hw->ctrl_urb->transfer_buffer_length = 0; in ctrl_start_transfer()
64 hw->ctrl_write.wIndex = in ctrl_start_transfer()
65 cpu_to_le16(hw->ctrl_buff[hw->ctrl_out_idx].hfcs_reg); in ctrl_start_transfer()
66 hw->ctrl_write.wValue = in ctrl_start_transfer()
67 cpu_to_le16(hw->ctrl_buff[hw->ctrl_out_idx].reg_val); in ctrl_start_transfer()
69 usb_submit_urb(hw->ctrl_urb, GFP_ATOMIC); in ctrl_start_transfer()
74 * queue a control transfer request to write HFC-S USB
83 hw->name, __func__, reg, val); in write_reg()
85 spin_lock(&hw->ctrl_lock); in write_reg()
86 if (hw->ctrl_cnt >= HFC_CTRL_BUFSIZE) { in write_reg()
87 spin_unlock(&hw->ctrl_lock); in write_reg()
90 buf = &hw->ctrl_buff[hw->ctrl_in_idx]; in write_reg()
91 buf->hfcs_reg = reg; in write_reg()
92 buf->reg_val = val; in write_reg()
93 if (++hw->ctrl_in_idx >= HFC_CTRL_BUFSIZE) in write_reg()
94 hw->ctrl_in_idx = 0; in write_reg()
95 if (++hw->ctrl_cnt == 1) in write_reg()
97 spin_unlock(&hw->ctrl_lock); in write_reg()
106 struct hfcsusb *hw = (struct hfcsusb *) urb->context; in ctrl_complete()
109 printk(KERN_DEBUG "%s: %s\n", hw->name, __func__); in ctrl_complete()
111 urb->dev = hw->dev; in ctrl_complete()
112 if (hw->ctrl_cnt) { in ctrl_complete()
113 hw->ctrl_cnt--; /* decrement actual count */ in ctrl_complete()
114 if (++hw->ctrl_out_idx >= HFC_CTRL_BUFSIZE) in ctrl_complete()
115 hw->ctrl_out_idx = 0; /* pointer wrap */ in ctrl_complete()
127 hw->led_state &= ~abs(led_bits); in set_led_bit()
129 hw->led_state |= led_bits; in set_led_bit()
132 hw->led_state |= abs(led_bits); in set_led_bit()
134 hw->led_state &= ~led_bits; in set_led_bit()
143 hfcsusb_idtab[hw->vend_idx].driver_info; in handle_led()
146 if (driver_info->led_scheme == LED_OFF) in handle_led()
148 tmpled = hw->led_state; in handle_led()
152 set_led_bit(hw, driver_info->led_bits[0], 1); in handle_led()
153 set_led_bit(hw, driver_info->led_bits[1], 0); in handle_led()
154 set_led_bit(hw, driver_info->led_bits[2], 0); in handle_led()
155 set_led_bit(hw, driver_info->led_bits[3], 0); in handle_led()
158 set_led_bit(hw, driver_info->led_bits[0], 0); in handle_led()
159 set_led_bit(hw, driver_info->led_bits[1], 0); in handle_led()
160 set_led_bit(hw, driver_info->led_bits[2], 0); in handle_led()
161 set_led_bit(hw, driver_info->led_bits[3], 0); in handle_led()
164 set_led_bit(hw, driver_info->led_bits[1], 1); in handle_led()
167 set_led_bit(hw, driver_info->led_bits[1], 0); in handle_led()
170 set_led_bit(hw, driver_info->led_bits[2], 1); in handle_led()
173 set_led_bit(hw, driver_info->led_bits[2], 0); in handle_led()
176 set_led_bit(hw, driver_info->led_bits[3], 1); in handle_led()
179 set_led_bit(hw, driver_info->led_bits[3], 0); in handle_led()
183 if (hw->led_state != tmpled) { in handle_led()
186 hw->name, __func__, in handle_led()
187 HFCUSB_P_DATA, hw->led_state); in handle_led()
189 write_reg(hw, HFCUSB_P_DATA, hw->led_state); in handle_led()
194 * Layer2 -> Layer 1 Bchannel data
200 struct hfcsusb *hw = bch->hw; in hfcusb_l2l1B()
201 int ret = -EINVAL; in hfcusb_l2l1B()
206 printk(KERN_DEBUG "%s: %s\n", hw->name, __func__); in hfcusb_l2l1B()
208 switch (hh->prim) { in hfcusb_l2l1B()
210 spin_lock_irqsave(&hw->lock, flags); in hfcusb_l2l1B()
212 spin_unlock_irqrestore(&hw->lock, flags); in hfcusb_l2l1B()
215 hw->name, __func__, ret); in hfcusb_l2l1B()
220 if (!test_and_set_bit(FLG_ACTIVE, &bch->Flags)) { in hfcusb_l2l1B()
221 hfcsusb_start_endpoint(hw, bch->nr - 1); in hfcusb_l2l1B()
222 ret = hfcsusb_setup_bch(bch, ch->protocol); in hfcusb_l2l1B()
242 * send full D/B channel status information
249 struct dchannel *dch = &hw->dch; in hfcsusb_ph_info()
252 phi = kzalloc(struct_size(phi, bch, dch->dev.nrbchan), GFP_ATOMIC); in hfcsusb_ph_info()
254 return -ENOMEM; in hfcsusb_ph_info()
256 phi->dch.ch.protocol = hw->protocol; in hfcsusb_ph_info()
257 phi->dch.ch.Flags = dch->Flags; in hfcsusb_ph_info()
258 phi->dch.state = dch->state; in hfcsusb_ph_info()
259 phi->dch.num_bch = dch->dev.nrbchan; in hfcsusb_ph_info()
260 for (i = 0; i < dch->dev.nrbchan; i++) { in hfcsusb_ph_info()
261 phi->bch[i].protocol = hw->bch[i].ch.protocol; in hfcsusb_ph_info()
262 phi->bch[i].Flags = hw->bch[i].Flags; in hfcsusb_ph_info()
264 _queue_data(&dch->dev.D, MPH_INFORMATION_IND, MISDN_ID_ANY, in hfcsusb_ph_info()
265 struct_size(phi, bch, dch->dev.nrbchan), phi, GFP_ATOMIC); in hfcsusb_ph_info()
272 * Layer2 -> Layer 1 Dchannel data
280 struct hfcsusb *hw = dch->hw; in hfcusb_l2l1D()
281 int ret = -EINVAL; in hfcusb_l2l1D()
284 switch (hh->prim) { in hfcusb_l2l1D()
288 hw->name, __func__); in hfcusb_l2l1D()
290 spin_lock_irqsave(&hw->lock, flags); in hfcusb_l2l1D()
292 spin_unlock_irqrestore(&hw->lock, flags); in hfcusb_l2l1D()
295 queue_ch_frame(ch, PH_DATA_CNF, hh->id, NULL); in hfcusb_l2l1D()
302 hw->name, __func__, in hfcusb_l2l1D()
303 (hw->protocol == ISDN_P_NT_S0) ? "NT" : "TE"); in hfcusb_l2l1D()
305 if (hw->protocol == ISDN_P_NT_S0) { in hfcusb_l2l1D()
307 if (test_bit(FLG_ACTIVE, &dch->Flags)) { in hfcusb_l2l1D()
308 _queue_data(&dch->dev.D, in hfcusb_l2l1D()
315 &dch->Flags); in hfcusb_l2l1D()
319 ret = l1_event(dch->l1, hh->prim); in hfcusb_l2l1D()
326 hw->name, __func__); in hfcusb_l2l1D()
327 test_and_clear_bit(FLG_L2_ACTIVATED, &dch->Flags); in hfcusb_l2l1D()
329 if (hw->protocol == ISDN_P_NT_S0) { in hfcusb_l2l1D()
334 spin_lock_irqsave(&hw->lock, flags); in hfcusb_l2l1D()
335 skb_queue_splice_init(&dch->squeue, &free_queue); in hfcusb_l2l1D()
336 if (dch->tx_skb) { in hfcusb_l2l1D()
337 __skb_queue_tail(&free_queue, dch->tx_skb); in hfcusb_l2l1D()
338 dch->tx_skb = NULL; in hfcusb_l2l1D()
340 dch->tx_idx = 0; in hfcusb_l2l1D()
341 if (dch->rx_skb) { in hfcusb_l2l1D()
342 __skb_queue_tail(&free_queue, dch->rx_skb); in hfcusb_l2l1D()
343 dch->rx_skb = NULL; in hfcusb_l2l1D()
345 test_and_clear_bit(FLG_TX_BUSY, &dch->Flags); in hfcusb_l2l1D()
346 spin_unlock_irqrestore(&hw->lock, flags); in hfcusb_l2l1D()
349 if (test_and_clear_bit(FLG_L1_BUSY, &dch->Flags)) in hfcusb_l2l1D()
350 dchannel_sched_event(&hc->dch, D_CLEARBUSY); in hfcusb_l2l1D()
354 ret = l1_event(dch->l1, hh->prim); in hfcusb_l2l1D()
370 struct hfcsusb *hw = dch->hw; in hfc_l1callback()
374 hw->name, __func__, cmd); in hfc_l1callback()
384 skb_queue_purge(&dch->squeue); in hfc_l1callback()
385 if (dch->tx_skb) { in hfc_l1callback()
386 dev_kfree_skb(dch->tx_skb); in hfc_l1callback()
387 dch->tx_skb = NULL; in hfc_l1callback()
389 dch->tx_idx = 0; in hfc_l1callback()
390 if (dch->rx_skb) { in hfc_l1callback()
391 dev_kfree_skb(dch->rx_skb); in hfc_l1callback()
392 dch->rx_skb = NULL; in hfc_l1callback()
394 test_and_clear_bit(FLG_TX_BUSY, &dch->Flags); in hfc_l1callback()
397 test_and_set_bit(FLG_ACTIVE, &dch->Flags); in hfc_l1callback()
398 _queue_data(&dch->dev.D, cmd, MISDN_ID_ANY, 0, NULL, in hfc_l1callback()
402 test_and_clear_bit(FLG_ACTIVE, &dch->Flags); in hfc_l1callback()
403 _queue_data(&dch->dev.D, cmd, MISDN_ID_ANY, 0, NULL, in hfc_l1callback()
407 if (dch->debug & DEBUG_HW) in hfc_l1callback()
409 hw->name, __func__, cmd); in hfc_l1callback()
410 return -1; in hfc_l1callback()
423 hw->name, __func__, hw->dch.dev.id, rq->adr.channel, in open_dchannel()
425 if (rq->protocol == ISDN_P_NONE) in open_dchannel()
426 return -EINVAL; in open_dchannel()
428 test_and_clear_bit(FLG_ACTIVE, &hw->dch.Flags); in open_dchannel()
429 test_and_clear_bit(FLG_ACTIVE, &hw->ech.Flags); in open_dchannel()
432 /* E-Channel logging */ in open_dchannel()
433 if (rq->adr.channel == 1) { in open_dchannel()
434 if (hw->fifos[HFCUSB_PCM_RX].pipe) { in open_dchannel()
436 set_bit(FLG_ACTIVE, &hw->ech.Flags); in open_dchannel()
437 _queue_data(&hw->ech.dev.D, PH_ACTIVATE_IND, in open_dchannel()
440 return -EINVAL; in open_dchannel()
443 if (!hw->initdone) { in open_dchannel()
444 hw->protocol = rq->protocol; in open_dchannel()
445 if (rq->protocol == ISDN_P_TE_S0) { in open_dchannel()
446 err = create_l1(&hw->dch, hfc_l1callback); in open_dchannel()
451 ch->protocol = rq->protocol; in open_dchannel()
452 hw->initdone = 1; in open_dchannel()
454 if (rq->protocol != ch->protocol) in open_dchannel()
455 return -EPROTONOSUPPORT; in open_dchannel()
458 if (((ch->protocol == ISDN_P_NT_S0) && (hw->dch.state == 3)) || in open_dchannel()
459 ((ch->protocol == ISDN_P_TE_S0) && (hw->dch.state == 7))) in open_dchannel()
462 rq->ch = ch; in open_dchannel()
465 hw->name, __func__); in open_dchannel()
474 if (rq->adr.channel == 0 || rq->adr.channel > 2) in open_bchannel()
475 return -EINVAL; in open_bchannel()
476 if (rq->protocol == ISDN_P_NONE) in open_bchannel()
477 return -EINVAL; in open_bchannel()
481 hw->name, __func__, rq->adr.channel); in open_bchannel()
483 bch = &hw->bch[rq->adr.channel - 1]; in open_bchannel()
484 if (test_and_set_bit(FLG_OPEN, &bch->Flags)) in open_bchannel()
485 return -EBUSY; /* b-channel can be only open once */ in open_bchannel()
486 bch->ch.protocol = rq->protocol; in open_bchannel()
487 rq->ch = &bch->ch; in open_bchannel()
491 hw->name, __func__); in open_bchannel()
501 printk(KERN_DEBUG "%s: %s op(0x%x) channel(0x%x)\n", in channel_ctrl()
502 hw->name, __func__, (cq->op), (cq->channel)); in channel_ctrl()
504 switch (cq->op) { in channel_ctrl()
506 cq->op = MISDN_CTRL_LOOP | MISDN_CTRL_CONNECT | in channel_ctrl()
511 hw->name, __func__, cq->op); in channel_ctrl()
512 ret = -EINVAL; in channel_ctrl()
526 struct hfcsusb *hw = dch->hw; in hfc_dctrl()
530 if (dch->debug & DEBUG_HW) in hfc_dctrl()
532 hw->name, __func__, cmd, arg); in hfc_dctrl()
536 if ((rq->protocol == ISDN_P_TE_S0) || in hfc_dctrl()
537 (rq->protocol == ISDN_P_NT_S0)) in hfc_dctrl()
542 hw->open++; in hfc_dctrl()
545 hw->open--; in hfc_dctrl()
549 hw->name, __func__, hw->dch.dev.id, in hfc_dctrl()
550 __builtin_return_address(0), hw->open); in hfc_dctrl()
551 if (!hw->open) { in hfc_dctrl()
553 if (hw->fifos[HFCUSB_PCM_RX].pipe) in hfc_dctrl()
563 if (dch->debug & DEBUG_HW) in hfc_dctrl()
565 hw->name, __func__, cmd); in hfc_dctrl()
566 return -EINVAL; in hfc_dctrl()
577 struct hfcsusb *hw = dch->hw; in ph_state_te()
580 if (dch->state <= HFC_MAX_TE_LAYER1_STATE) in ph_state_te()
581 printk(KERN_DEBUG "%s: %s: %s\n", hw->name, __func__, in ph_state_te()
582 HFC_TE_LAYER1_STATES[dch->state]); in ph_state_te()
585 hw->name, __func__, dch->state); in ph_state_te()
588 switch (dch->state) { in ph_state_te()
590 l1_event(dch->l1, HW_RESET_IND); in ph_state_te()
593 l1_event(dch->l1, HW_DEACT_IND); in ph_state_te()
597 l1_event(dch->l1, ANYSIGNAL); in ph_state_te()
600 l1_event(dch->l1, INFO2); in ph_state_te()
603 l1_event(dch->l1, INFO4_P8); in ph_state_te()
606 if (dch->state == 7) in ph_state_te()
618 struct hfcsusb *hw = dch->hw; in ph_state_nt()
621 if (dch->state <= HFC_MAX_NT_LAYER1_STATE) in ph_state_nt()
623 hw->name, __func__, in ph_state_nt()
624 HFC_NT_LAYER1_STATES[dch->state]); in ph_state_nt()
628 hw->name, __func__, dch->state); in ph_state_nt()
631 switch (dch->state) { in ph_state_nt()
633 test_and_clear_bit(FLG_ACTIVE, &dch->Flags); in ph_state_nt()
634 test_and_clear_bit(FLG_L2_ACTIVATED, &dch->Flags); in ph_state_nt()
635 hw->nt_timer = 0; in ph_state_nt()
636 hw->timers &= ~NT_ACTIVATION_TIMER; in ph_state_nt()
641 if (hw->nt_timer < 0) { in ph_state_nt()
642 hw->nt_timer = 0; in ph_state_nt()
643 hw->timers &= ~NT_ACTIVATION_TIMER; in ph_state_nt()
644 hfcsusb_ph_command(dch->hw, HFC_L1_DEACTIVATE_NT); in ph_state_nt()
646 hw->timers |= NT_ACTIVATION_TIMER; in ph_state_nt()
647 hw->nt_timer = NT_T1_COUNT; in ph_state_nt()
648 /* allow G2 -> G3 transition */ in ph_state_nt()
653 hw->nt_timer = 0; in ph_state_nt()
654 hw->timers &= ~NT_ACTIVATION_TIMER; in ph_state_nt()
655 test_and_set_bit(FLG_ACTIVE, &dch->Flags); in ph_state_nt()
656 _queue_data(&dch->dev.D, PH_ACTIVATE_IND, in ph_state_nt()
661 hw->nt_timer = 0; in ph_state_nt()
662 hw->timers &= ~NT_ACTIVATION_TIMER; in ph_state_nt()
673 struct hfcsusb *hw = dch->hw; in ph_state()
675 if (hw->protocol == ISDN_P_NT_S0) in ph_state()
677 else if (hw->protocol == ISDN_P_TE_S0) in ph_state()
687 struct hfcsusb *hw = bch->hw; in hfcsusb_setup_bch()
691 printk(KERN_DEBUG "%s: %s: protocol %x-->%x B%d\n", in hfcsusb_setup_bch()
692 hw->name, __func__, bch->state, protocol, in hfcsusb_setup_bch()
693 bch->nr); in hfcsusb_setup_bch()
698 conhdlc = 8; /* enable FIFO */ in hfcsusb_setup_bch()
701 case (-1): /* used for init */ in hfcsusb_setup_bch()
702 bch->state = -1; in hfcsusb_setup_bch()
705 if (bch->state == ISDN_P_NONE) in hfcsusb_setup_bch()
707 bch->state = ISDN_P_NONE; in hfcsusb_setup_bch()
708 clear_bit(FLG_HDLC, &bch->Flags); in hfcsusb_setup_bch()
709 clear_bit(FLG_TRANSPARENT, &bch->Flags); in hfcsusb_setup_bch()
713 bch->state = protocol; in hfcsusb_setup_bch()
714 set_bit(FLG_TRANSPARENT, &bch->Flags); in hfcsusb_setup_bch()
717 bch->state = protocol; in hfcsusb_setup_bch()
718 set_bit(FLG_HDLC, &bch->Flags); in hfcsusb_setup_bch()
723 hw->name, __func__, protocol); in hfcsusb_setup_bch()
724 return -ENOPROTOOPT; in hfcsusb_setup_bch()
728 write_reg(hw, HFCUSB_FIFO, (bch->nr == 1) ? 0 : 2); in hfcsusb_setup_bch()
731 write_reg(hw, HFCUSB_FIFO, (bch->nr == 1) ? 1 : 3); in hfcsusb_setup_bch()
735 sctrl = 0x40 + ((hw->protocol == ISDN_P_TE_S0) ? 0x00 : 0x04); in hfcsusb_setup_bch()
737 if (test_bit(FLG_ACTIVE, &hw->bch[0].Flags)) { in hfcsusb_setup_bch()
741 if (test_bit(FLG_ACTIVE, &hw->bch[1].Flags)) { in hfcsusb_setup_bch()
749 handle_led(hw, (bch->nr == 1) ? LED_B1_ON : LED_B2_ON); in hfcsusb_setup_bch()
751 handle_led(hw, (bch->nr == 1) ? LED_B1_OFF : in hfcsusb_setup_bch()
762 hw->name, __func__, command); in hfcsusb_ph_command()
778 if (hw->dch.state == 3) in hfcsusb_ph_command()
779 _queue_data(&hw->dch.dev.D, PH_ACTIVATE_IND, in hfcsusb_ph_command()
794 * Layer 1 B-channel hardware access
804 hfcsusb_rx_frame(struct usb_fifo *fifo, __u8 *data, unsigned int len, in hfcsusb_rx_frame() argument
807 struct hfcsusb *hw = fifo->hw; in hfcsusb_rx_frame()
810 int fifon = fifo->fifonum; in hfcsusb_rx_frame()
816 printk(KERN_DEBUG "%s: %s: fifo(%i) len(%i) " in hfcsusb_rx_frame()
818 hw->name, __func__, fifon, len, in hfcsusb_rx_frame()
819 fifo->dch, fifo->bch, fifo->ech); in hfcsusb_rx_frame()
821 if (!len) in hfcsusb_rx_frame()
824 if ((!!fifo->dch + !!fifo->bch + !!fifo->ech) != 1) { in hfcsusb_rx_frame()
825 printk(KERN_DEBUG "%s: %s: undefined channel\n", in hfcsusb_rx_frame()
826 hw->name, __func__); in hfcsusb_rx_frame()
830 spin_lock_irqsave(&hw->lock, flags); in hfcsusb_rx_frame()
831 if (fifo->dch) { in hfcsusb_rx_frame()
832 rx_skb = fifo->dch->rx_skb; in hfcsusb_rx_frame()
833 maxlen = fifo->dch->maxlen; in hfcsusb_rx_frame()
836 if (fifo->bch) { in hfcsusb_rx_frame()
837 if (test_bit(FLG_RX_OFF, &fifo->bch->Flags)) { in hfcsusb_rx_frame()
838 fifo->bch->dropcnt += len; in hfcsusb_rx_frame()
839 spin_unlock_irqrestore(&hw->lock, flags); in hfcsusb_rx_frame()
842 maxlen = bchannel_get_rxbuf(fifo->bch, len); in hfcsusb_rx_frame()
843 rx_skb = fifo->bch->rx_skb; in hfcsusb_rx_frame()
848 hw->name, fifo->bch->nr, len); in hfcsusb_rx_frame()
849 spin_unlock_irqrestore(&hw->lock, flags); in hfcsusb_rx_frame()
852 maxlen = fifo->bch->maxlen; in hfcsusb_rx_frame()
853 hdlc = test_bit(FLG_HDLC, &fifo->bch->Flags); in hfcsusb_rx_frame()
855 if (fifo->ech) { in hfcsusb_rx_frame()
856 rx_skb = fifo->ech->rx_skb; in hfcsusb_rx_frame()
857 maxlen = fifo->ech->maxlen; in hfcsusb_rx_frame()
861 if (fifo->dch || fifo->ech) { in hfcsusb_rx_frame()
865 if (fifo->dch) in hfcsusb_rx_frame()
866 fifo->dch->rx_skb = rx_skb; in hfcsusb_rx_frame()
867 if (fifo->ech) in hfcsusb_rx_frame()
868 fifo->ech->rx_skb = rx_skb; in hfcsusb_rx_frame()
872 hw->name, __func__); in hfcsusb_rx_frame()
873 spin_unlock_irqrestore(&hw->lock, flags); in hfcsusb_rx_frame()
877 /* D/E-Channel SKB range check */ in hfcsusb_rx_frame()
878 if ((rx_skb->len + len) >= MAX_DFRAME_LEN_L1) { in hfcsusb_rx_frame()
880 "for fifo(%d) HFCUSB_D_RX\n", in hfcsusb_rx_frame()
881 hw->name, __func__, fifon); in hfcsusb_rx_frame()
883 spin_unlock_irqrestore(&hw->lock, flags); in hfcsusb_rx_frame()
888 skb_put_data(rx_skb, data, len); in hfcsusb_rx_frame()
893 if ((rx_skb->len > 3) && in hfcsusb_rx_frame()
894 (!(rx_skb->data[rx_skb->len - 1]))) { in hfcsusb_rx_frame()
897 " new RX len(%i): ", in hfcsusb_rx_frame()
898 hw->name, __func__, fifon, in hfcsusb_rx_frame()
899 rx_skb->len); in hfcsusb_rx_frame()
901 while (i < rx_skb->len) in hfcsusb_rx_frame()
903 rx_skb->data[i++]); in hfcsusb_rx_frame()
908 skb_trim(rx_skb, rx_skb->len - 3); in hfcsusb_rx_frame()
910 if (fifo->dch) in hfcsusb_rx_frame()
911 recv_Dchannel(fifo->dch); in hfcsusb_rx_frame()
912 if (fifo->bch) in hfcsusb_rx_frame()
913 recv_Bchannel(fifo->bch, MISDN_ID_ANY, in hfcsusb_rx_frame()
915 if (fifo->ech) in hfcsusb_rx_frame()
916 recv_Echannel(fifo->ech, in hfcsusb_rx_frame()
917 &hw->dch); in hfcsusb_rx_frame()
922 "RX len(%i): ", in hfcsusb_rx_frame()
923 hw->name, fifon, rx_skb->len); in hfcsusb_rx_frame()
925 while (i < rx_skb->len) in hfcsusb_rx_frame()
927 rx_skb->data[i++]); in hfcsusb_rx_frame()
935 recv_Bchannel(fifo->bch, MISDN_ID_ANY, false); in hfcsusb_rx_frame()
937 spin_unlock_irqrestore(&hw->lock, flags); in hfcsusb_rx_frame()
950 urb->number_of_packets = num_packets; in fill_isoc_urb()
951 urb->transfer_flags = URB_ISO_ASAP; in fill_isoc_urb()
952 urb->actual_length = 0; in fill_isoc_urb()
953 urb->interval = interval; in fill_isoc_urb()
956 urb->iso_frame_desc[k].offset = packet_size * k; in fill_isoc_urb()
957 urb->iso_frame_desc[k].length = packet_size; in fill_isoc_urb()
958 urb->iso_frame_desc[k].actual_length = 0; in fill_isoc_urb()
966 struct iso_urb *context_iso_urb = (struct iso_urb *) urb->context; in rx_iso_complete()
967 struct usb_fifo *fifo = context_iso_urb->owner_fifo; in rx_iso_complete() local
968 struct hfcsusb *hw = fifo->hw; in rx_iso_complete()
969 int k, len, errcode, offset, num_isoc_packets, fifon, maxlen, in rx_iso_complete() local
976 fifon = fifo->fifonum; in rx_iso_complete()
977 status = urb->status; in rx_iso_complete()
979 spin_lock_irqsave(&hw->lock, flags); in rx_iso_complete()
980 if (fifo->stop_gracefull) { in rx_iso_complete()
981 fifo->stop_gracefull = 0; in rx_iso_complete()
982 fifo->active = 0; in rx_iso_complete()
983 spin_unlock_irqrestore(&hw->lock, flags); in rx_iso_complete()
986 spin_unlock_irqrestore(&hw->lock, flags); in rx_iso_complete()
992 if (status == -EXDEV) { in rx_iso_complete()
994 printk(KERN_DEBUG "%s: %s: with -EXDEV " in rx_iso_complete()
995 "urb->status %d, fifonum %d\n", in rx_iso_complete()
996 hw->name, __func__, status, fifon); in rx_iso_complete()
1003 if (fifo->active && !status) { in rx_iso_complete()
1005 maxlen = fifo->usb_packet_maxlen; in rx_iso_complete()
1008 len = urb->iso_frame_desc[k].actual_length; in rx_iso_complete()
1009 offset = urb->iso_frame_desc[k].offset; in rx_iso_complete()
1010 buf = context_iso_urb->buffer + offset; in rx_iso_complete()
1011 iso_status = urb->iso_frame_desc[k].status; in rx_iso_complete()
1016 hw->name, __func__, k, iso_status); in rx_iso_complete()
1023 "%s: %s: %d (%d/%d) len(%d) ", in rx_iso_complete()
1024 hw->name, __func__, urb->start_frame, in rx_iso_complete()
1025 k, num_isoc_packets - 1, in rx_iso_complete()
1026 len); in rx_iso_complete()
1027 for (i = 0; i < len; i++) in rx_iso_complete()
1033 if (fifo->last_urblen != maxlen) { in rx_iso_complete()
1035 * save fifo fill-level threshold bits in rx_iso_complete()
1039 hw->threshold_mask = buf[1]; in rx_iso_complete()
1045 if (len > 2) in rx_iso_complete()
1046 hfcsusb_rx_frame(fifo, buf + 2, in rx_iso_complete()
1047 len - 2, (len < maxlen) in rx_iso_complete()
1050 hfcsusb_rx_frame(fifo, buf, len, in rx_iso_complete()
1051 (len < maxlen) ? in rx_iso_complete()
1053 fifo->last_urblen = len; in rx_iso_complete()
1058 if ((s0_state) && (hw->initdone) && in rx_iso_complete()
1059 (s0_state != hw->dch.state)) { in rx_iso_complete()
1060 hw->dch.state = s0_state; in rx_iso_complete()
1061 schedule_event(&hw->dch, FLG_PHCHANGE); in rx_iso_complete()
1064 fill_isoc_urb(urb, fifo->hw->dev, fifo->pipe, in rx_iso_complete()
1065 context_iso_urb->buffer, num_isoc_packets, in rx_iso_complete()
1066 fifo->usb_packet_maxlen, fifo->intervall, in rx_iso_complete()
1067 (usb_complete_t)rx_iso_complete, urb->context); in rx_iso_complete()
1073 hw->name, __func__, errcode); in rx_iso_complete()
1078 "urb->status %d, fifonum %d\n", in rx_iso_complete()
1079 hw->name, __func__, status, fifon); in rx_iso_complete()
1087 int len, status, i; in rx_int_complete() local
1089 struct usb_fifo *fifo = (struct usb_fifo *) urb->context; in rx_int_complete() local
1090 struct hfcsusb *hw = fifo->hw; in rx_int_complete()
1094 spin_lock_irqsave(&hw->lock, flags); in rx_int_complete()
1095 if (fifo->stop_gracefull) { in rx_int_complete()
1096 fifo->stop_gracefull = 0; in rx_int_complete()
1097 fifo->active = 0; in rx_int_complete()
1098 spin_unlock_irqrestore(&hw->lock, flags); in rx_int_complete()
1101 spin_unlock_irqrestore(&hw->lock, flags); in rx_int_complete()
1103 fifon = fifo->fifonum; in rx_int_complete()
1104 if ((!fifo->active) || (urb->status)) { in rx_int_complete()
1107 "%s: %s: RX-Fifo %i is going down (%i)\n", in rx_int_complete()
1108 hw->name, __func__, fifon, urb->status); in rx_int_complete()
1110 fifo->urb->interval = 0; /* cancel automatic rescheduling */ in rx_int_complete()
1113 len = urb->actual_length; in rx_int_complete()
1114 buf = fifo->buffer; in rx_int_complete()
1115 maxlen = fifo->usb_packet_maxlen; in rx_int_complete()
1119 printk(KERN_DEBUG "%s: %s: D RX INT len(%d) ", in rx_int_complete()
1120 hw->name, __func__, len); in rx_int_complete()
1121 for (i = 0; i < len; i++) in rx_int_complete()
1126 if (fifo->last_urblen != fifo->usb_packet_maxlen) { in rx_int_complete()
1128 hw->threshold_mask = buf[1]; in rx_int_complete()
1131 if (hw->initdone && ((buf[0] >> 4) != hw->dch.state)) { in rx_int_complete()
1132 hw->dch.state = (buf[0] >> 4); in rx_int_complete()
1133 schedule_event(&hw->dch, FLG_PHCHANGE); in rx_int_complete()
1137 /* if we have more than the 2 status bytes -> collect data */ in rx_int_complete()
1138 if (len > 2) in rx_int_complete()
1139 hfcsusb_rx_frame(fifo, buf + 2, in rx_int_complete()
1140 urb->actual_length - 2, in rx_int_complete()
1141 (len < maxlen) ? eof[fifon] : 0); in rx_int_complete()
1143 hfcsusb_rx_frame(fifo, buf, urb->actual_length, in rx_int_complete()
1144 (len < maxlen) ? eof[fifon] : 0); in rx_int_complete()
1146 fifo->last_urblen = urb->actual_length; in rx_int_complete()
1152 hw->name, __func__); in rx_int_complete()
1160 struct iso_urb *context_iso_urb = (struct iso_urb *) urb->context; in tx_iso_complete()
1161 struct usb_fifo *fifo = context_iso_urb->owner_fifo; in tx_iso_complete() local
1162 struct hfcsusb *hw = fifo->hw; in tx_iso_complete()
1171 spin_lock_irqsave(&hw->lock, flags); in tx_iso_complete()
1172 if (fifo->stop_gracefull) { in tx_iso_complete()
1173 fifo->stop_gracefull = 0; in tx_iso_complete()
1174 fifo->active = 0; in tx_iso_complete()
1175 spin_unlock_irqrestore(&hw->lock, flags); in tx_iso_complete()
1179 if (fifo->dch) { in tx_iso_complete()
1180 tx_skb = fifo->dch->tx_skb; in tx_iso_complete()
1181 tx_idx = &fifo->dch->tx_idx; in tx_iso_complete()
1183 } else if (fifo->bch) { in tx_iso_complete()
1184 tx_skb = fifo->bch->tx_skb; in tx_iso_complete()
1185 tx_idx = &fifo->bch->tx_idx; in tx_iso_complete()
1186 hdlc = test_bit(FLG_HDLC, &fifo->bch->Flags); in tx_iso_complete()
1188 test_bit(FLG_FILLEMPTY, &fifo->bch->Flags)) in tx_iso_complete()
1192 hw->name, __func__); in tx_iso_complete()
1193 spin_unlock_irqrestore(&hw->lock, flags); in tx_iso_complete()
1197 fifon = fifo->fifonum; in tx_iso_complete()
1198 status = urb->status; in tx_iso_complete()
1206 if (status == -EXDEV) { in tx_iso_complete()
1209 "-EXDEV (%i) fifon (%d)\n", in tx_iso_complete()
1210 hw->name, __func__, status, fifon); in tx_iso_complete()
1216 if (fifo->active && !status) { in tx_iso_complete()
1217 /* is FifoFull-threshold set for our channel? */ in tx_iso_complete()
1218 threshbit = (hw->threshold_mask & (1 << fifon)); in tx_iso_complete()
1221 /* predict dataflow to avoid fifo overflow */ in tx_iso_complete()
1226 fill_isoc_urb(urb, fifo->hw->dev, fifo->pipe, in tx_iso_complete()
1227 context_iso_urb->buffer, num_isoc_packets, in tx_iso_complete()
1228 fifo->usb_packet_maxlen, fifo->intervall, in tx_iso_complete()
1229 (usb_complete_t)tx_iso_complete, urb->context); in tx_iso_complete()
1230 memset(context_iso_urb->buffer, 0, in tx_iso_complete()
1231 sizeof(context_iso_urb->buffer)); in tx_iso_complete()
1237 errcode = urb->iso_frame_desc[k].status; in tx_iso_complete()
1241 hw->name, __func__, k, errcode); in tx_iso_complete()
1247 remain = tx_skb->len - *tx_idx; in tx_iso_complete()
1254 fifo->bit_line -= sink; in tx_iso_complete()
1255 current_len = (0 - fifo->bit_line) / 8; in tx_iso_complete()
1264 fifo->bit_line += current_len * 8; in tx_iso_complete()
1266 context_iso_urb->buffer[tx_offset] = 0; in tx_iso_complete()
1270 context_iso_urb-> in tx_iso_complete()
1274 fifo->bit_line += 32; in tx_iso_complete()
1279 /* copy tx data to iso-urb buffer */ in tx_iso_complete()
1280 p = context_iso_urb->buffer + tx_offset + 1; in tx_iso_complete()
1282 memset(p, fifo->bch->fill[0], in tx_iso_complete()
1285 memcpy(p, (tx_skb->data + *tx_idx), in tx_iso_complete()
1289 urb->iso_frame_desc[k].offset = tx_offset; in tx_iso_complete()
1290 urb->iso_frame_desc[k].length = current_len + 1; in tx_iso_complete()
1296 "%s: %s (%d/%d) offs(%d) len(%d) ", in tx_iso_complete()
1297 hw->name, __func__, in tx_iso_complete()
1298 k, num_isoc_packets - 1, in tx_iso_complete()
1299 urb->iso_frame_desc[k].offset, in tx_iso_complete()
1300 urb->iso_frame_desc[k].length); in tx_iso_complete()
1302 for (i = urb->iso_frame_desc[k].offset; in tx_iso_complete()
1303 i < (urb->iso_frame_desc[k].offset in tx_iso_complete()
1304 + urb->iso_frame_desc[k].length); in tx_iso_complete()
1307 context_iso_urb->buffer[i]); in tx_iso_complete()
1309 printk(" skb->len(%i) tx-idx(%d)\n", in tx_iso_complete()
1310 tx_skb->len, *tx_idx); in tx_iso_complete()
1315 urb->iso_frame_desc[k].offset = tx_offset++; in tx_iso_complete()
1316 urb->iso_frame_desc[k].length = 1; in tx_iso_complete()
1318 fifo->bit_line -= sink; in tx_iso_complete()
1319 if (fifo->bit_line < BITLINE_INF) in tx_iso_complete()
1320 fifo->bit_line = BITLINE_INF; in tx_iso_complete()
1328 "fifon(%i) new TX len(%i): ", in tx_iso_complete()
1329 hw->name, __func__, in tx_iso_complete()
1330 fifon, tx_skb->len); in tx_iso_complete()
1332 while (i < tx_skb->len) in tx_iso_complete()
1334 tx_skb->data[i++]); in tx_iso_complete()
1340 if (fifo->dch && get_next_dframe(fifo->dch)) in tx_iso_complete()
1341 tx_skb = fifo->dch->tx_skb; in tx_iso_complete()
1342 else if (fifo->bch && in tx_iso_complete()
1343 get_next_bframe(fifo->bch)) in tx_iso_complete()
1344 tx_skb = fifo->bch->tx_skb; in tx_iso_complete()
1352 hw->name, __func__, errcode); in tx_iso_complete()
1358 * fifo->intervall (ms) in tx_iso_complete()
1360 if ((fifon == HFCUSB_D_TX) && (hw->protocol == ISDN_P_NT_S0) in tx_iso_complete()
1361 && (hw->timers & NT_ACTIVATION_TIMER)) { in tx_iso_complete()
1362 if ((--hw->nt_timer) < 0) in tx_iso_complete()
1363 schedule_event(&hw->dch, FLG_PHCHANGE); in tx_iso_complete()
1368 printk(KERN_DEBUG "%s: %s: urb->status %s (%i)" in tx_iso_complete()
1370 hw->name, __func__, in tx_iso_complete()
1373 spin_unlock_irqrestore(&hw->lock, flags); in tx_iso_complete()
1381 start_isoc_chain(struct usb_fifo *fifo, int num_packets_per_urb, in start_isoc_chain() argument
1384 struct hfcsusb *hw = fifo->hw; in start_isoc_chain()
1388 printk(KERN_DEBUG "%s: %s: fifo %i\n", in start_isoc_chain()
1389 hw->name, __func__, fifo->fifonum); in start_isoc_chain()
1393 if (!(fifo->iso[i].urb)) { in start_isoc_chain()
1394 fifo->iso[i].urb = in start_isoc_chain()
1396 if (!(fifo->iso[i].urb)) { in start_isoc_chain()
1398 "%s: %s: alloc urb for fifo %i failed", in start_isoc_chain()
1399 hw->name, __func__, fifo->fifonum); in start_isoc_chain()
1402 fifo->iso[i].owner_fifo = (struct usb_fifo *) fifo; in start_isoc_chain()
1403 fifo->iso[i].indx = i; in start_isoc_chain()
1407 (fifo->usb_packet_maxlen * in start_isoc_chain()
1409 fill_isoc_urb(fifo->iso[i].urb, in start_isoc_chain()
1410 fifo->hw->dev, fifo->pipe, in start_isoc_chain()
1411 fifo->iso[i].buffer, in start_isoc_chain()
1413 fifo->usb_packet_maxlen, in start_isoc_chain()
1414 fifo->intervall, complete, in start_isoc_chain()
1415 &fifo->iso[i]); in start_isoc_chain()
1416 memset(fifo->iso[i].buffer, 0, in start_isoc_chain()
1417 sizeof(fifo->iso[i].buffer)); in start_isoc_chain()
1420 fifo->iso[i].urb-> in start_isoc_chain()
1423 fifo->iso[i].urb-> in start_isoc_chain()
1430 hw->name, __func__); in start_isoc_chain()
1433 fifo->bit_line = BITLINE_INF; in start_isoc_chain()
1435 errcode = usb_submit_urb(fifo->iso[i].urb, GFP_KERNEL); in start_isoc_chain()
1436 fifo->active = (errcode >= 0) ? 1 : 0; in start_isoc_chain()
1437 fifo->stop_gracefull = 0; in start_isoc_chain()
1440 hw->name, __func__, in start_isoc_chain()
1444 return fifo->active; in start_isoc_chain()
1448 stop_iso_gracefull(struct usb_fifo *fifo) in stop_iso_gracefull() argument
1450 struct hfcsusb *hw = fifo->hw; in stop_iso_gracefull()
1455 spin_lock_irqsave(&hw->lock, flags); in stop_iso_gracefull()
1457 printk(KERN_DEBUG "%s: %s for fifo %i.%i\n", in stop_iso_gracefull()
1458 hw->name, __func__, fifo->fifonum, i); in stop_iso_gracefull()
1459 fifo->stop_gracefull = 1; in stop_iso_gracefull()
1460 spin_unlock_irqrestore(&hw->lock, flags); in stop_iso_gracefull()
1465 while (fifo->stop_gracefull && timeout--) in stop_iso_gracefull()
1467 if (debug && fifo->stop_gracefull) in stop_iso_gracefull()
1468 printk(KERN_DEBUG "%s: ERROR %s for fifo %i.%i\n", in stop_iso_gracefull()
1469 hw->name, __func__, fifo->fifonum, i); in stop_iso_gracefull()
1474 stop_int_gracefull(struct usb_fifo *fifo) in stop_int_gracefull() argument
1476 struct hfcsusb *hw = fifo->hw; in stop_int_gracefull()
1480 spin_lock_irqsave(&hw->lock, flags); in stop_int_gracefull()
1482 printk(KERN_DEBUG "%s: %s for fifo %i\n", in stop_int_gracefull()
1483 hw->name, __func__, fifo->fifonum); in stop_int_gracefull()
1484 fifo->stop_gracefull = 1; in stop_int_gracefull()
1485 spin_unlock_irqrestore(&hw->lock, flags); in stop_int_gracefull()
1488 while (fifo->stop_gracefull && timeout--) in stop_int_gracefull()
1490 if (debug && fifo->stop_gracefull) in stop_int_gracefull()
1491 printk(KERN_DEBUG "%s: ERROR %s for fifo %i\n", in stop_int_gracefull()
1492 hw->name, __func__, fifo->fifonum); in stop_int_gracefull()
1495 /* start the interrupt transfer for the given fifo */
1497 start_int_fifo(struct usb_fifo *fifo) in start_int_fifo() argument
1499 struct hfcsusb *hw = fifo->hw; in start_int_fifo()
1503 printk(KERN_DEBUG "%s: %s: INT IN fifo:%d\n", in start_int_fifo()
1504 hw->name, __func__, fifo->fifonum); in start_int_fifo()
1506 if (!fifo->urb) { in start_int_fifo()
1507 fifo->urb = usb_alloc_urb(0, GFP_KERNEL); in start_int_fifo()
1508 if (!fifo->urb) in start_int_fifo()
1511 usb_fill_int_urb(fifo->urb, fifo->hw->dev, fifo->pipe, in start_int_fifo()
1512 fifo->buffer, fifo->usb_packet_maxlen, in start_int_fifo()
1513 (usb_complete_t)rx_int_complete, fifo, fifo->intervall); in start_int_fifo()
1514 fifo->active = 1; in start_int_fifo()
1515 fifo->stop_gracefull = 0; in start_int_fifo()
1516 errcode = usb_submit_urb(fifo->urb, GFP_KERNEL); in start_int_fifo()
1519 hw->name, __func__, errcode); in start_int_fifo()
1520 fifo->active = 0; in start_int_fifo()
1528 printk(KERN_DEBUG "%s: %s %s\n", hw->name, __func__, in setPortMode()
1529 (hw->protocol == ISDN_P_TE_S0) ? "TE" : "NT"); in setPortMode()
1531 if (hw->protocol == ISDN_P_TE_S0) { in setPortMode()
1549 struct usb_fifo *fifo; in reset_hfcsusb() local
1553 printk(KERN_DEBUG "%s: %s\n", hw->name, __func__); in reset_hfcsusb()
1562 write_reg(hw, HFCUSB_USB_SIZE, (hw->packet_size / 8) | in reset_hfcsusb()
1563 ((hw->packet_size / 8) << 4)); in reset_hfcsusb()
1566 write_reg(hw, HFCUSB_USB_SIZE_I, hw->iso_packet_size); in reset_hfcsusb()
1576 fifo = hw->fifos; in reset_hfcsusb()
1578 write_reg(hw, HFCUSB_FIFO, i); /* select the desired fifo */ in reset_hfcsusb()
1579 fifo[i].max_size = in reset_hfcsusb()
1581 fifo[i].last_urblen = 0; in reset_hfcsusb()
1583 /* set 2 bit for D- & E-channel */ in reset_hfcsusb()
1589 (hw->protocol == ISDN_P_NT_S0) ? 0x08 : 0x09); in reset_hfcsusb()
1592 write_reg(hw, HFCUSB_INC_RES_F, 2); /* reset the fifo */ in reset_hfcsusb()
1601 hfcsusb_start_endpoint(struct hfcsusb *hw, int channel) in hfcsusb_start_endpoint() argument
1604 if ((channel == HFC_CHAN_D) && (hw->fifos[HFCUSB_D_RX].active)) in hfcsusb_start_endpoint()
1606 if ((channel == HFC_CHAN_B1) && (hw->fifos[HFCUSB_B1_RX].active)) in hfcsusb_start_endpoint()
1608 if ((channel == HFC_CHAN_B2) && (hw->fifos[HFCUSB_B2_RX].active)) in hfcsusb_start_endpoint()
1610 if ((channel == HFC_CHAN_E) && (hw->fifos[HFCUSB_PCM_RX].active)) in hfcsusb_start_endpoint()
1614 if (hw->cfg_used == CNF_3INT3ISO || hw->cfg_used == CNF_4INT3ISO) in hfcsusb_start_endpoint()
1615 start_int_fifo(hw->fifos + channel * 2 + 1); in hfcsusb_start_endpoint()
1618 if (hw->cfg_used == CNF_3ISO3ISO || hw->cfg_used == CNF_4ISO3ISO) { in hfcsusb_start_endpoint()
1619 switch (channel) { in hfcsusb_start_endpoint()
1621 start_isoc_chain(hw->fifos + HFCUSB_D_RX, in hfcsusb_start_endpoint()
1627 start_isoc_chain(hw->fifos + HFCUSB_PCM_RX, in hfcsusb_start_endpoint()
1633 start_isoc_chain(hw->fifos + HFCUSB_B1_RX, in hfcsusb_start_endpoint()
1639 start_isoc_chain(hw->fifos + HFCUSB_B2_RX, in hfcsusb_start_endpoint()
1648 switch (channel) { in hfcsusb_start_endpoint()
1650 start_isoc_chain(hw->fifos + HFCUSB_D_TX, in hfcsusb_start_endpoint()
1655 start_isoc_chain(hw->fifos + HFCUSB_B1_TX, in hfcsusb_start_endpoint()
1660 start_isoc_chain(hw->fifos + HFCUSB_B2_TX, in hfcsusb_start_endpoint()
1669 hfcsusb_stop_endpoint(struct hfcsusb *hw, int channel) in hfcsusb_stop_endpoint() argument
1672 if ((channel == HFC_CHAN_D) && (!hw->fifos[HFCUSB_D_RX].active)) in hfcsusb_stop_endpoint()
1674 if ((channel == HFC_CHAN_B1) && (!hw->fifos[HFCUSB_B1_RX].active)) in hfcsusb_stop_endpoint()
1676 if ((channel == HFC_CHAN_B2) && (!hw->fifos[HFCUSB_B2_RX].active)) in hfcsusb_stop_endpoint()
1678 if ((channel == HFC_CHAN_E) && (!hw->fifos[HFCUSB_PCM_RX].active)) in hfcsusb_stop_endpoint()
1682 if (hw->cfg_used == CNF_3INT3ISO || hw->cfg_used == CNF_4INT3ISO) in hfcsusb_stop_endpoint()
1683 stop_int_gracefull(hw->fifos + channel * 2 + 1); in hfcsusb_stop_endpoint()
1686 if (hw->cfg_used == CNF_3ISO3ISO || hw->cfg_used == CNF_4ISO3ISO) in hfcsusb_stop_endpoint()
1687 stop_iso_gracefull(hw->fifos + channel * 2 + 1); in hfcsusb_stop_endpoint()
1690 if (channel != HFC_CHAN_E) in hfcsusb_stop_endpoint()
1691 stop_iso_gracefull(hw->fifos + channel * 2); in hfcsusb_stop_endpoint()
1704 printk(KERN_DEBUG "%s: %s\n", hw->name, __func__); in setup_hfcsusb()
1707 return -ENOMEM; in setup_hfcsusb()
1717 hw->name, __func__); in setup_hfcsusb()
1722 hw->name, __func__, b); in setup_hfcsusb()
1727 (void) usb_set_interface(hw->dev, hw->if_used, hw->alt_used); in setup_hfcsusb()
1729 hw->led_state = 0; in setup_hfcsusb()
1732 hw->ctrl_read.bRequestType = 0xc0; in setup_hfcsusb()
1733 hw->ctrl_read.bRequest = 1; in setup_hfcsusb()
1734 hw->ctrl_read.wLength = cpu_to_le16(1); in setup_hfcsusb()
1735 hw->ctrl_write.bRequestType = 0x40; in setup_hfcsusb()
1736 hw->ctrl_write.bRequest = 0; in setup_hfcsusb()
1737 hw->ctrl_write.wLength = 0; in setup_hfcsusb()
1738 usb_fill_control_urb(hw->ctrl_urb, hw->dev, hw->ctrl_out_pipe, in setup_hfcsusb()
1739 (u_char *)&hw->ctrl_write, NULL, 0, in setup_hfcsusb()
1750 printk(KERN_DEBUG "%s: %s\n", hw->name, __func__); in release_hw()
1760 if (hw->fifos[HFCUSB_PCM_RX].pipe) in release_hw()
1762 if (hw->protocol == ISDN_P_TE_S0) in release_hw()
1763 l1_event(hw->dch.l1, CLOSE_CHANNEL); in release_hw()
1765 mISDN_unregister_device(&hw->dch.dev); in release_hw()
1766 mISDN_freebchannel(&hw->bch[1]); in release_hw()
1767 mISDN_freebchannel(&hw->bch[0]); in release_hw()
1768 mISDN_freedchannel(&hw->dch); in release_hw()
1770 if (hw->ctrl_urb) { in release_hw()
1771 usb_kill_urb(hw->ctrl_urb); in release_hw()
1772 usb_free_urb(hw->ctrl_urb); in release_hw()
1773 hw->ctrl_urb = NULL; in release_hw()
1776 if (hw->intf) in release_hw()
1777 usb_set_intfdata(hw->intf, NULL); in release_hw()
1778 list_del(&hw->list); in release_hw()
1786 struct hfcsusb *hw = bch->hw; in deactivate_bchannel()
1789 if (bch->debug & DEBUG_HW) in deactivate_bchannel()
1790 printk(KERN_DEBUG "%s: %s: bch->nr(%i)\n", in deactivate_bchannel()
1791 hw->name, __func__, bch->nr); in deactivate_bchannel()
1793 spin_lock_irqsave(&hw->lock, flags); in deactivate_bchannel()
1795 spin_unlock_irqrestore(&hw->lock, flags); in deactivate_bchannel()
1797 hfcsusb_stop_endpoint(hw, bch->nr - 1); in deactivate_bchannel()
1801 * Layer 1 B-channel hardware access
1807 int ret = -EINVAL; in hfc_bctrl()
1809 if (bch->debug & DEBUG_HW) in hfc_bctrl()
1816 ret = -EINVAL; in hfc_bctrl()
1820 test_and_clear_bit(FLG_OPEN, &bch->Flags); in hfc_bctrl()
1822 ch->protocol = ISDN_P_NONE; in hfc_bctrl()
1823 ch->peer = NULL; in hfc_bctrl()
1844 printk(KERN_DEBUG "%s: %s\n", hw->name, __func__); in setup_instance()
1846 spin_lock_init(&hw->ctrl_lock); in setup_instance()
1847 spin_lock_init(&hw->lock); in setup_instance()
1849 mISDN_initdchannel(&hw->dch, MAX_DFRAME_LEN_L1, ph_state); in setup_instance()
1850 hw->dch.debug = debug & 0xFFFF; in setup_instance()
1851 hw->dch.hw = hw; in setup_instance()
1852 hw->dch.dev.Dprotocols = (1 << ISDN_P_TE_S0) | (1 << ISDN_P_NT_S0); in setup_instance()
1853 hw->dch.dev.D.send = hfcusb_l2l1D; in setup_instance()
1854 hw->dch.dev.D.ctrl = hfc_dctrl; in setup_instance()
1856 /* enable E-Channel logging */ in setup_instance()
1857 if (hw->fifos[HFCUSB_PCM_RX].pipe) in setup_instance()
1858 mISDN_initdchannel(&hw->ech, MAX_DFRAME_LEN_L1, NULL); in setup_instance()
1860 hw->dch.dev.Bprotocols = (1 << (ISDN_P_B_RAW & ISDN_P_B_MASK)) | in setup_instance()
1862 hw->dch.dev.nrbchan = 2; in setup_instance()
1864 hw->bch[i].nr = i + 1; in setup_instance()
1865 set_channelmap(i + 1, hw->dch.dev.channelmap); in setup_instance()
1866 hw->bch[i].debug = debug; in setup_instance()
1867 mISDN_initbchannel(&hw->bch[i], MAX_DATA_MEM, poll >> 1); in setup_instance()
1868 hw->bch[i].hw = hw; in setup_instance()
1869 hw->bch[i].ch.send = hfcusb_l2l1B; in setup_instance()
1870 hw->bch[i].ch.ctrl = hfc_bctrl; in setup_instance()
1871 hw->bch[i].ch.nr = i + 1; in setup_instance()
1872 list_add(&hw->bch[i].ch.list, &hw->dch.dev.bchannels); in setup_instance()
1875 hw->fifos[HFCUSB_B1_TX].bch = &hw->bch[0]; in setup_instance()
1876 hw->fifos[HFCUSB_B1_RX].bch = &hw->bch[0]; in setup_instance()
1877 hw->fifos[HFCUSB_B2_TX].bch = &hw->bch[1]; in setup_instance()
1878 hw->fifos[HFCUSB_B2_RX].bch = &hw->bch[1]; in setup_instance()
1879 hw->fifos[HFCUSB_D_TX].dch = &hw->dch; in setup_instance()
1880 hw->fifos[HFCUSB_D_RX].dch = &hw->dch; in setup_instance()
1881 hw->fifos[HFCUSB_PCM_RX].ech = &hw->ech; in setup_instance()
1882 hw->fifos[HFCUSB_PCM_TX].ech = &hw->ech; in setup_instance()
1888 snprintf(hw->name, MISDN_MAX_IDLEN - 1, "%s.%d", DRIVER_NAME, in setup_instance()
1891 DRIVER_NAME, hw->name); in setup_instance()
1893 err = mISDN_register_device(&hw->dch.dev, parent, hw->name); in setup_instance()
1899 list_add_tail(&hw->list, &HFClist); in setup_instance()
1904 mISDN_freebchannel(&hw->bch[1]); in setup_instance()
1905 mISDN_freebchannel(&hw->bch[0]); in setup_instance()
1906 mISDN_freedchannel(&hw->dch); in setup_instance()
1916 struct usb_host_interface *iface = intf->cur_altsetting; in hfcsusb_probe()
1920 int ifnum = iface->desc.bInterfaceNumber, i, idx, alt_idx, in hfcsusb_probe()
1927 if ((le16_to_cpu(dev->descriptor.idVendor) in hfcsusb_probe()
1929 (le16_to_cpu(dev->descriptor.idProduct) in hfcsusb_probe()
1938 __func__, ifnum, iface->desc.bAlternateSetting, in hfcsusb_probe()
1939 intf->minor, vend_idx); in hfcsusb_probe()
1945 return -EIO; in hfcsusb_probe()
1949 small_match = -1; in hfcsusb_probe()
1955 while (alt_idx < intf->num_altsetting) { in hfcsusb_probe()
1956 iface = intf->altsetting + alt_idx; in hfcsusb_probe()
1957 probe_alt_setting = iface->desc.bAlternateSetting; in hfcsusb_probe()
1963 ep = iface->endpoint; in hfcsusb_probe()
1967 for (i = 0; i < iface->desc.bNumEndpoints; i++) { in hfcsusb_probe()
1968 ep_addr = ep->desc.bEndpointAddress; in hfcsusb_probe()
1971 idx = ((ep_addr & 0x7f) - 1) * 2; in hfcsusb_probe()
1973 return -EIO; in hfcsusb_probe()
1977 attr = ep->desc.bmAttributes; in hfcsusb_probe()
1993 ep->desc.bInterval < vcf[17]) { in hfcsusb_probe()
2014 } /* (alt_idx < intf->num_altsetting) */ in hfcsusb_probe()
2017 if (small_match == -1) in hfcsusb_probe()
2018 return -EIO; in hfcsusb_probe()
2023 return -ENOMEM; /* got no mem */ in hfcsusb_probe()
2024 snprintf(hw->name, MISDN_MAX_IDLEN - 1, "%s", DRIVER_NAME); in hfcsusb_probe()
2026 ep = iface->endpoint; in hfcsusb_probe()
2029 for (i = 0; i < iface->desc.bNumEndpoints; i++) { in hfcsusb_probe()
2032 ep_addr = ep->desc.bEndpointAddress; in hfcsusb_probe()
2034 idx = ((ep_addr & 0x7f) - 1) * 2; in hfcsusb_probe()
2037 f = &hw->fifos[idx & 7]; in hfcsusb_probe()
2044 switch (ep->desc.bmAttributes) { in hfcsusb_probe()
2046 f->pipe = usb_rcvintpipe(dev, in hfcsusb_probe()
2047 ep->desc.bEndpointAddress); in hfcsusb_probe()
2048 f->usb_transfer_mode = USB_INT; in hfcsusb_probe()
2049 packet_size = le16_to_cpu(ep->desc.wMaxPacketSize); in hfcsusb_probe()
2053 f->pipe = usb_rcvbulkpipe(dev, in hfcsusb_probe()
2054 ep->desc.bEndpointAddress); in hfcsusb_probe()
2056 f->pipe = usb_sndbulkpipe(dev, in hfcsusb_probe()
2057 ep->desc.bEndpointAddress); in hfcsusb_probe()
2058 f->usb_transfer_mode = USB_BULK; in hfcsusb_probe()
2059 packet_size = le16_to_cpu(ep->desc.wMaxPacketSize); in hfcsusb_probe()
2063 f->pipe = usb_rcvisocpipe(dev, in hfcsusb_probe()
2064 ep->desc.bEndpointAddress); in hfcsusb_probe()
2066 f->pipe = usb_sndisocpipe(dev, in hfcsusb_probe()
2067 ep->desc.bEndpointAddress); in hfcsusb_probe()
2068 f->usb_transfer_mode = USB_ISOC; in hfcsusb_probe()
2069 iso_packet_size = le16_to_cpu(ep->desc.wMaxPacketSize); in hfcsusb_probe()
2072 f->pipe = 0; in hfcsusb_probe()
2075 if (f->pipe) { in hfcsusb_probe()
2076 f->fifonum = idx & 7; in hfcsusb_probe()
2077 f->hw = hw; in hfcsusb_probe()
2078 f->usb_packet_maxlen = in hfcsusb_probe()
2079 le16_to_cpu(ep->desc.wMaxPacketSize); in hfcsusb_probe()
2080 f->intervall = ep->desc.bInterval; in hfcsusb_probe()
2084 hw->dev = dev; /* save device */ in hfcsusb_probe()
2085 hw->if_used = ifnum; /* save used interface */ in hfcsusb_probe()
2086 hw->alt_used = alt_used; /* and alternate config */ in hfcsusb_probe()
2087 hw->ctrl_paksize = dev->descriptor.bMaxPacketSize0; /* control size */ in hfcsusb_probe()
2088 hw->cfg_used = vcf[16]; /* store used config */ in hfcsusb_probe()
2089 hw->vend_idx = vend_idx; /* store found vendor */ in hfcsusb_probe()
2090 hw->packet_size = packet_size; in hfcsusb_probe()
2091 hw->iso_packet_size = iso_packet_size; in hfcsusb_probe()
2094 hw->ctrl_in_pipe = usb_rcvctrlpipe(hw->dev, 0); in hfcsusb_probe()
2095 hw->ctrl_out_pipe = usb_sndctrlpipe(hw->dev, 0); in hfcsusb_probe()
2100 hw->ctrl_urb = usb_alloc_urb(0, GFP_KERNEL); in hfcsusb_probe()
2101 if (!hw->ctrl_urb) { in hfcsusb_probe()
2103 driver_info->vend_name); in hfcsusb_probe()
2105 return -ENOMEM; in hfcsusb_probe()
2109 hw->name, __func__, driver_info->vend_name, in hfcsusb_probe()
2112 if (setup_instance(hw, dev->dev.parent)) in hfcsusb_probe()
2113 return -EIO; in hfcsusb_probe()
2115 hw->intf = intf; in hfcsusb_probe()
2116 usb_set_intfdata(hw->intf, hw); in hfcsusb_probe()
2128 printk(KERN_INFO "%s: device disconnected\n", hw->name); in hfcsusb_disconnect()