33 #include <linux/module.h>
37 #include <linux/slab.h>
40 static unsigned int debug;
52 static int hfcsusb_cnt;
56 static void release_hw(
struct hfcsusb *
hw);
57 static void reset_hfcsusb(
struct hfcsusb *
hw);
58 static void setPortMode(
struct hfcsusb *
hw);
62 static void deactivate_bchannel(
struct bchannel *bch);
63 static void hfcsusb_ph_info(
struct hfcsusb *
hw);
76 hw->
ctrl_urb->transfer_buffer_length = 0;
94 if (
debug & DBG_HFC_CALL_TRACE)
96 hw->
name, __func__, reg, val);
109 ctrl_start_transfer(hw);
117 ctrl_complete(
struct urb *
urb)
121 if (
debug & DBG_HFC_CALL_TRACE)
130 ctrl_start_transfer(hw);
156 hfcsusb_idtab[hw->
vend_idx].driver_info;
165 set_led_bit(hw, driver_info->
led_bits[0], 1);
166 set_led_bit(hw, driver_info->
led_bits[1], 0);
167 set_led_bit(hw, driver_info->
led_bits[2], 0);
168 set_led_bit(hw, driver_info->
led_bits[3], 0);
171 set_led_bit(hw, driver_info->
led_bits[0], 0);
172 set_led_bit(hw, driver_info->
led_bits[1], 0);
173 set_led_bit(hw, driver_info->
led_bits[2], 0);
174 set_led_bit(hw, driver_info->
led_bits[3], 0);
177 set_led_bit(hw, driver_info->
led_bits[1], 1);
180 set_led_bit(hw, driver_info->
led_bits[1], 0);
183 set_led_bit(hw, driver_info->
led_bits[2], 1);
186 set_led_bit(hw, driver_info->
led_bits[2], 0);
189 set_led_bit(hw, driver_info->
led_bits[3], 1);
192 set_led_bit(hw, driver_info->
led_bits[3], 0);
197 if (
debug & DBG_HFC_CALL_TRACE)
210 hfcusb_l2l1B(
struct mISDNchannel *ch,
struct sk_buff *
skb)
218 if (
debug & DBG_HFC_CALL_TRACE)
225 spin_unlock_irqrestore(&hw->
lock, flags);
226 if (
debug & DBG_HFC_CALL_TRACE)
228 hw->
name, __func__, ret);
234 hfcsusb_start_endpoint(hw, bch->
nr - 1);
235 ret = hfcsusb_setup_bch(bch, ch->protocol);
243 deactivate_bchannel(bch);
259 hfcsusb_ph_info(
struct hfcsusb *hw)
265 phi = kzalloc(
sizeof(
struct ph_info) +
270 phi->
dch.num_bch = dch->
dev.nrbchan;
271 for (i = 0; i < dch->
dev.nrbchan; i++) {
272 phi->
bch[
i].protocol = hw->
bch[
i].ch.protocol;
273 phi->
bch[
i].Flags = hw->
bch[
i].Flags;
285 hfcusb_l2l1D(
struct mISDNchannel *ch,
struct sk_buff *skb)
289 struct mISDNhead *hh = mISDN_HEAD_P(skb);
296 if (
debug & DBG_HFC_CALL_TRACE)
302 spin_unlock_irqrestore(&hw->
lock, flags);
310 if (
debug & DBG_HFC_CALL_TRACE)
318 _queue_data(&dch->
dev.D,
322 hfcsusb_ph_command(hw,
334 if (
debug & DBG_HFC_CALL_TRACE)
344 dev_kfree_skb(dch->
tx_skb);
349 dev_kfree_skb(dch->
rx_skb);
353 spin_unlock_irqrestore(&hw->
lock, flags);
379 if (
debug & DBG_HFC_CALL_TRACE)
381 hw->
name, __func__, cmd);
393 dev_kfree_skb(dch->
tx_skb);
398 dev_kfree_skb(dch->
rx_skb);
416 hw->
name, __func__, cmd);
424 open_dchannel(
struct hfcsusb *hw,
struct mISDNchannel *ch,
425 struct channel_req *
rq)
431 hw->
name, __func__, hw->
dch.dev.id, rq->adr.channel,
432 __builtin_return_address(0));
441 if (rq->adr.channel == 1) {
459 ch->protocol = rq->protocol;
462 if (rq->protocol != ch->protocol)
478 open_bchannel(
struct hfcsusb *hw,
struct channel_req *rq)
482 if (rq->adr.channel == 0 || rq->adr.channel > 2)
487 if (
debug & DBG_HFC_CALL_TRACE)
489 hw->
name, __func__, rq->adr.channel);
491 bch = &hw->
bch[rq->adr.channel - 1];
494 bch->
ch.protocol = rq->protocol;
508 if (
debug & DBG_HFC_CALL_TRACE)
519 hw->
name, __func__, cq->
op);
530 hfc_dctrl(
struct mISDNchannel *ch,
u_int cmd,
void *
arg)
532 struct mISDNdevice *dev =
container_of(ch,
struct mISDNdevice,
D);
535 struct channel_req *
rq;
540 hw->
name, __func__, cmd, arg);
546 err = open_dchannel(hw, ch, rq);
548 err = open_bchannel(hw, rq);
554 if (
debug & DEBUG_HW_OPEN)
556 "%s: %s: dev(%d) close from %p (open %d)\n",
557 hw->
name, __func__, hw->
dch.dev.id,
558 __builtin_return_address(0), hw->
open);
568 err = channel_ctrl(hw, arg);
573 hw->
name, __func__, cmd);
590 HFC_TE_LAYER1_STATES[dch->
state]);
596 switch (dch->
state) {
628 if (
debug & DEBUG_HW) {
632 HFC_NT_LAYER1_STATES[dch->
state]);
639 switch (dch->
state) {
696 __u8 conhdlc, sctrl, sctrl_r;
698 if (
debug & DEBUG_HW)
700 hw->
name, __func__, bch->
state, protocol,
729 if (
debug & DEBUG_HW)
731 hw->
name, __func__, protocol);
769 if (
debug & DEBUG_HW)
771 hw->
name, __func__, command);
787 if (hw->
dch.state == 3)
823 if (
debug & DBG_HFC_CALL_TRACE)
825 "dch(%p) bch(%p) ech(%p)\n",
826 hw->
name, __func__, fifon, len,
832 if ((!!fifo->
dch + !!fifo->
bch + !!fifo->
ech) != 1) {
838 spin_lock(&hw->
lock);
840 rx_skb = fifo->
dch->rx_skb;
841 maxlen = fifo->
dch->maxlen;
846 fifo->
bch->dropcnt +=
len;
847 spin_unlock(&hw->
lock);
851 rx_skb = fifo->
bch->rx_skb;
855 pr_warning(
"%s.B%d: No bufferspace for %d bytes\n",
857 spin_unlock(&hw->
lock);
860 maxlen = fifo->
bch->maxlen;
864 rx_skb = fifo->
ech->rx_skb;
865 maxlen = fifo->
ech->maxlen;
869 if (fifo->
dch || fifo->
ech) {
874 fifo->
dch->rx_skb = rx_skb;
876 fifo->
ech->rx_skb = rx_skb;
881 spin_unlock(&hw->
lock);
888 "for fifo(%d) HFCUSB_D_RX\n",
889 hw->
name, __func__, fifon);
891 spin_unlock(&hw->
lock);
901 if ((rx_skb->
len > 3) &&
902 (!(rx_skb->
data[rx_skb->
len - 1]))) {
906 hw->
name, __func__, fifon,
909 while (i < rx_skb->len)
927 if (
debug & DBG_HFC_FIFO_VERBOSE) {
929 "%s: CRC or minlen ERROR fifon(%i) "
933 while (i < rx_skb->len)
945 spin_unlock(&hw->
lock);
949 fill_isoc_urb(
struct urb *urb,
struct usb_device *dev,
unsigned int pipe,
950 void *buf,
int num_packets,
int packet_size,
int interval,
955 usb_fill_bulk_urb(urb, dev, pipe, buf, packet_size * num_packets,
958 urb->number_of_packets = num_packets;
959 urb->transfer_flags = URB_ISO_ASAP;
960 urb->actual_length = 0;
963 for (k = 0; k < num_packets; k++) {
964 urb->iso_frame_desc[
k].offset = packet_size *
k;
965 urb->iso_frame_desc[
k].length = packet_size;
966 urb->iso_frame_desc[
k].actual_length = 0;
972 rx_iso_complete(
struct urb *urb)
974 struct iso_urb *context_iso_urb = (
struct iso_urb *) urb->context;
977 int k, len,
errcode,
offset, num_isoc_packets, fifon, maxlen,
986 spin_lock(&hw->
lock);
990 spin_unlock(&hw->
lock);
993 spin_unlock(&hw->
lock);
1000 if (
debug & DEBUG_HW)
1002 "urb->status %d, fifonum %d\n",
1011 num_isoc_packets = iso_packets[fifon];
1014 for (k = 0; k < num_isoc_packets; ++
k) {
1015 len = urb->iso_frame_desc[
k].actual_length;
1018 iso_status = urb->iso_frame_desc[
k].status;
1020 if (iso_status && (
debug & DBG_HFC_FIFO_VERBOSE)) {
1022 "ISO packet %i, status: %i\n",
1023 hw->
name, __func__, k, iso_status);
1030 "%s: %s: %d (%d/%d) len(%d) ",
1031 hw->
name, __func__, urb->start_frame,
1032 k, num_isoc_packets - 1,
1034 for (i = 0; i < len; i++)
1049 s0_state = (buf[0] >> 4);
1051 eof[fifon] = buf[0] & 1;
1053 hfcsusb_rx_frame(fifo, buf + 2,
1054 len - 2, (len < maxlen)
1057 hfcsusb_rx_frame(fifo, buf, len,
1065 if ((s0_state) && (hw->
initdone) &&
1066 (s0_state != hw->
dch.state)) {
1067 hw->
dch.state = s0_state;
1071 fill_isoc_urb(urb, fifo->
hw->dev, fifo->
pipe,
1072 context_iso_urb->
buffer, num_isoc_packets,
1074 (usb_complete_t)rx_iso_complete, urb->context);
1077 if (
debug & DEBUG_HW)
1085 "urb->status %d, fifonum %d\n",
1092 rx_int_complete(
struct urb *urb)
1100 spin_lock(&hw->
lock);
1104 spin_unlock(&hw->
lock);
1107 spin_unlock(&hw->
lock);
1110 if ((!fifo->
active) || (urb->status)) {
1113 "%s: %s: RX-Fifo %i is going down (%i)\n",
1114 hw->
name, __func__, fifon, urb->status);
1116 fifo->
urb->interval = 0;
1119 len = urb->actual_length;
1126 hw->
name, __func__, len);
1127 for (i = 0; i < len; i++)
1137 if (hw->
initdone && ((buf[0] >> 4) != hw->
dch.state)) {
1138 hw->
dch.state = (buf[0] >> 4);
1142 eof[fifon] = buf[0] & 1;
1145 hfcsusb_rx_frame(fifo, buf + 2,
1146 urb->actual_length - 2,
1147 (len < maxlen) ? eof[fifon] : 0);
1149 hfcsusb_rx_frame(fifo, buf, urb->actual_length,
1150 (len < maxlen) ? eof[fifon] : 0);
1156 if (
debug & DEBUG_HW)
1158 hw->
name, __func__);
1164 tx_iso_complete(
struct urb *urb)
1166 struct iso_urb *context_iso_urb = (
struct iso_urb *) urb->context;
1170 int k, tx_offset, num_isoc_packets,
sink, remain, current_len,
1173 int frame_complete, fifon, status, fillempty = 0;
1176 spin_lock(&hw->
lock);
1180 spin_unlock(&hw->
lock);
1185 tx_skb = fifo->
dch->tx_skb;
1186 tx_idx = &fifo->
dch->tx_idx;
1188 }
else if (fifo->
bch) {
1189 tx_skb = fifo->
bch->tx_skb;
1190 tx_idx = &fifo->
bch->tx_idx;
1192 if (!tx_skb && !hdlc &&
1197 hw->
name, __func__);
1198 spin_unlock(&hw->
lock);
1203 status = urb->status;
1211 if (status == -
EXDEV) {
1214 "-EXDEV (%i) fifon (%d)\n",
1215 hw->
name, __func__, status, fifon);
1221 if (fifo->
active && !status) {
1224 num_isoc_packets = iso_packets[fifon];
1231 fill_isoc_urb(urb, fifo->
hw->dev, fifo->
pipe,
1232 context_iso_urb->
buffer, num_isoc_packets,
1234 (usb_complete_t)tx_iso_complete, urb->context);
1236 sizeof(context_iso_urb->
buffer));
1239 for (k = 0; k < num_isoc_packets; ++
k) {
1242 errcode = urb->iso_frame_desc[
k].status;
1245 "ISO packet %i, status: %i\n",
1252 remain = tx_skb->len - *tx_idx;
1260 current_len = (0 - fifo->
bit_line) / 8;
1261 if (current_len > 14)
1263 if (current_len < 0)
1265 if (remain < current_len)
1266 current_len = remain;
1271 context_iso_urb->
buffer[tx_offset] = 0;
1272 if (current_len == remain) {
1285 p = context_iso_urb->
buffer + tx_offset + 1;
1290 memcpy(
p, (tx_skb->data + *tx_idx),
1292 *tx_idx += current_len;
1294 urb->iso_frame_desc[
k].offset = tx_offset;
1295 urb->iso_frame_desc[
k].length = current_len + 1;
1299 (
debug & DBG_HFC_USB_VERBOSE)) {
1301 "%s: %s (%d/%d) offs(%d) len(%d) ",
1303 k, num_isoc_packets - 1,
1304 urb->iso_frame_desc[k].offset,
1305 urb->iso_frame_desc[k].length);
1307 for (i = urb->iso_frame_desc[k].offset;
1308 i < (urb->iso_frame_desc[k].offset
1309 + urb->iso_frame_desc[k].length);
1312 context_iso_urb->
buffer[i]);
1314 printk(
" skb->len(%i) tx-idx(%d)\n",
1315 tx_skb->len, *tx_idx);
1318 tx_offset += (current_len + 1);
1320 urb->iso_frame_desc[
k].offset = tx_offset++;
1321 urb->iso_frame_desc[
k].length = 1;
1328 if (frame_complete) {
1331 if (
debug & DBG_HFC_FIFO_VERBOSE) {
1333 "fifon(%i) new TX len(%i): ",
1335 fifon, tx_skb->len);
1337 while (i < tx_skb->len)
1343 dev_kfree_skb(tx_skb);
1346 tx_skb = fifo->
dch->tx_skb;
1347 else if (fifo->
bch &&
1349 tx_skb = fifo->
bch->tx_skb;
1354 if (
debug & DEBUG_HW)
1356 "%s: %s: error submitting ISO URB: %d \n",
1372 if (status && (
debug & DBG_HFC_URB_ERROR))
1376 symbolic(urb_errlist, status), status, fifon);
1378 spin_unlock(&hw->
lock);
1386 start_isoc_chain(
struct usb_fifo *fifo,
int num_packets_per_urb,
1387 usb_complete_t complete,
int packet_size)
1397 for (i = 0; i < 2; i++) {
1398 if (!(fifo->
iso[i].urb)) {
1401 if (!(fifo->
iso[i].urb)) {
1403 "%s: %s: alloc urb for fifo %i failed",
1407 fifo->
iso[
i].indx =
i;
1412 num_packets_per_urb)) {
1413 fill_isoc_urb(fifo->
iso[i].urb,
1414 fifo->
hw->dev, fifo->
pipe,
1415 fifo->
iso[i].buffer,
1416 num_packets_per_urb,
1421 sizeof(fifo->
iso[i].buffer));
1423 for (k = 0; k < num_packets_per_urb; k++) {
1425 iso_frame_desc[
k].offset =
1428 iso_frame_desc[
k].length =
1433 "%s: %s: ISO Buffer size to small!\n",
1434 hw->
name, __func__);
1440 fifo->
active = (errcode >= 0) ? 1 : 0;
1445 symbolic(urb_errlist, errcode), i);
1452 stop_iso_gracefull(
struct usb_fifo *fifo)
1458 for (i = 0; i < 2; i++) {
1464 spin_unlock_irqrestore(&hw->
lock, flags);
1467 for (i = 0; i < 2; i++) {
1478 stop_int_gracefull(
struct usb_fifo *fifo)
1489 spin_unlock_irqrestore(&hw->
lock, flags);
1501 start_int_fifo(
struct usb_fifo *fifo)
1515 usb_fill_int_urb(fifo->
urb, fifo->
hw->dev, fifo->
pipe,
1517 (usb_complete_t)rx_int_complete, fifo, fifo->
intervall);
1523 hw->
name, __func__, errcode);
1529 setPortMode(
struct hfcsusb *hw)
1531 if (
debug & DEBUG_HW)
1551 reset_hfcsusb(
struct hfcsusb *hw)
1556 if (
debug & DEBUG_HW)
1619 start_int_fifo(hw->
fifos + channel * 2 + 1);
1627 (usb_complete_t)rx_iso_complete,
1633 (usb_complete_t)rx_iso_complete,
1639 (usb_complete_t)rx_iso_complete,
1645 (usb_complete_t)rx_iso_complete,
1656 (usb_complete_t)tx_iso_complete, 1);
1661 (usb_complete_t)tx_iso_complete, 1);
1666 (usb_complete_t)tx_iso_complete, 1);
1673 hfcsusb_stop_endpoint(
struct hfcsusb *hw,
int channel)
1687 stop_int_gracefull(hw->
fifos + channel * 2 + 1);
1691 stop_iso_gracefull(hw->
fifos + channel * 2 + 1);
1695 stop_iso_gracefull(hw->
fifos + channel * 2);
1701 setup_hfcsusb(
struct hfcsusb *hw)
1705 if (
debug & DBG_HFC_CALL_TRACE)
1711 hw->
name, __func__);
1716 hw->
name, __func__, b);
1734 (usb_complete_t)ctrl_complete, hw);
1741 release_hw(
struct hfcsusb *hw)
1743 if (
debug & DBG_HFC_CALL_TRACE)
1778 deactivate_bchannel(
struct bchannel *bch)
1783 if (bch->
debug & DEBUG_HW)
1785 hw->
name, __func__, bch->
nr);
1789 spin_unlock_irqrestore(&hw->
lock, flags);
1791 hfcsusb_stop_endpoint(hw, bch->
nr - 1);
1798 hfc_bctrl(
struct mISDNchannel *ch,
u_int cmd,
void *arg)
1803 if (bch->
debug & DEBUG_HW)
1815 deactivate_bchannel(bch);
1822 ret = channel_bctrl(bch, arg);
1837 if (
debug & DBG_HFC_CALL_TRACE)
1847 hw->
dch.dev.D.send = hfcusb_l2l1D;
1848 hw->
dch.dev.D.ctrl = hfc_dctrl;
1856 hw->
dch.dev.nrbchan = 2;
1857 for (i = 0; i < 2; i++) {
1858 hw->
bch[
i].nr = i + 1;
1859 set_channelmap(i + 1, hw->
dch.dev.channelmap);
1863 hw->
bch[
i].ch.send = hfcusb_l2l1B;
1864 hw->
bch[
i].ch.ctrl = hfc_bctrl;
1865 hw->
bch[
i].ch.nr = i + 1;
1866 list_add(&hw->
bch[i].ch.list, &hw->
dch.dev.bchannels);
1878 err = setup_hfcsusb(hw);
1909 struct usb_device *dev = interface_to_usbdev(intf);
1910 struct usb_host_interface *iface = intf->cur_altsetting;
1911 struct usb_host_interface *iface_used =
NULL;
1912 struct usb_host_endpoint *ep;
1914 int ifnum = iface->desc.bInterfaceNumber,
i,
idx, alt_idx,
1915 probe_alt_setting, vend_idx, cfg_used, *vcf,
attr, cfg_found,
1916 ep_addr, cmptbl[16], small_match, iso_packet_size, packet_size,
1920 for (i = 0; hfcsusb_idtab[
i].idVendor; i++) {
1922 == hfcsusb_idtab[i].idVendor) &&
1924 == hfcsusb_idtab[i].idProduct)) {
1931 "%s: interface(%d) actalt(%d) minor(%d) vend_idx(%d)\n",
1932 __func__, ifnum, iface->desc.bAlternateSetting,
1933 intf->minor, vend_idx);
1935 if (vend_idx == 0xffff) {
1937 "%s: no valid vendor found in USB descriptor\n",
1946 iso_packet_size = 16;
1949 while (alt_idx < intf->num_altsetting) {
1950 iface = intf->altsetting + alt_idx;
1951 probe_alt_setting = iface->desc.bAlternateSetting;
1954 while (validconf[cfg_used][0]) {
1956 vcf = validconf[cfg_used];
1957 ep = iface->endpoint;
1958 memcpy(cmptbl, vcf, 16 *
sizeof(
int));
1961 for (i = 0; i < iface->desc.bNumEndpoints; i++) {
1962 ep_addr = ep->desc.bEndpointAddress;
1965 idx = ((ep_addr & 0x7f) - 1) * 2;
1968 attr = ep->desc.bmAttributes;
1970 if (cmptbl[idx] !=
EP_NOP) {
1971 if (cmptbl[idx] ==
EP_NUL)
1974 && cmptbl[idx] ==
EP_INT)
1977 && cmptbl[idx] ==
EP_BLK)
1980 && cmptbl[idx] ==
EP_ISO)
1984 ep->desc.bInterval < vcf[17]) {
1991 for (i = 0; i < 16; i++)
1996 if (small_match < cfg_used) {
1997 small_match = cfg_used;
1998 alt_used = probe_alt_setting;
2008 if (small_match == -1)
2017 ep = iface->endpoint;
2018 vcf = validconf[small_match];
2020 for (i = 0; i < iface->desc.bNumEndpoints; i++) {
2023 ep_addr = ep->desc.bEndpointAddress;
2025 idx = ((ep_addr & 0x7f) - 1) * 2;
2028 f = &hw->
fifos[idx & 7];
2035 switch (ep->desc.bmAttributes) {
2037 f->
pipe = usb_rcvintpipe(dev,
2038 ep->desc.bEndpointAddress);
2040 packet_size =
le16_to_cpu(ep->desc.wMaxPacketSize);
2044 f->
pipe = usb_rcvbulkpipe(dev,
2045 ep->desc.bEndpointAddress);
2047 f->
pipe = usb_sndbulkpipe(dev,
2048 ep->desc.bEndpointAddress);
2050 packet_size =
le16_to_cpu(ep->desc.wMaxPacketSize);
2054 f->
pipe = usb_rcvisocpipe(dev,
2055 ep->desc.bEndpointAddress);
2057 f->
pipe = usb_sndisocpipe(dev,
2058 ep->desc.bEndpointAddress);
2060 iso_packet_size =
le16_to_cpu(ep->desc.wMaxPacketSize);
2089 hfcsusb_idtab[vend_idx].driver_info;
2093 pr_warn(
"%s: No memory for control urb\n",
2099 pr_info(
"%s: %s: detected \"%s\" (%s, if=%d alt=%d)\n",
2101 conf_str[small_match], ifnum, alt_used);
2103 if (setup_instance(hw, dev->
dev.parent))
2107 usb_set_intfdata(hw->
intf, hw);
2115 struct hfcsusb *hw = usb_get_intfdata(intf);
2129 usb_set_intfdata(intf,
NULL);
2132 static
struct usb_driver hfcsusb_drv = {
2134 .id_table = hfcsusb_idtab,
2135 .probe = hfcsusb_probe,
2136 .disconnect = hfcsusb_disconnect,
2137 .disable_hub_initiated_lpm = 1,