32 #include <linux/types.h>
33 #include <linux/stddef.h>
36 #include <linux/module.h>
39 #include <linux/kernel.h>
40 #include <linux/sched.h>
42 #include <linux/slab.h>
47 static const char *hfcusb_revision =
48 "$Revision: 2.3.2.24 $ $Date: 2007/10/14 08:40:29 $ ";
53 #define __debug_variable hfc_debug
70 USB_DEVICE(0x0959, 0x2bd0),
73 "ISDN USB TA (Cologne Chip HFC-S USB based)"}),
76 USB_DEVICE(0x0675, 0x1688),
79 "DrayTek miniVigor 128 USB ISDN TA"}),
82 USB_DEVICE(0x07b0, 0x0007),
85 "Billion tiny USB ISDN TA 128"}),
88 USB_DEVICE(0x0742, 0x2008),
94 USB_DEVICE(0x0742, 0x2009),
97 "Aceex USB ISDN TA"}),
100 USB_DEVICE(0x0742, 0x200A),
106 USB_DEVICE(0x08e3, 0x0301),
112 USB_DEVICE(0x07fa, 0x0846),
115 "Bewan Modem RNIS USB"}),
118 USB_DEVICE(0x07fa, 0x0847),
121 "Djinn Numeris USB"}),
124 USB_DEVICE(0x07b0, 0x0006),
130 USB_DEVICE(0x071d, 0x1005),
133 "Eicon DIVA USB 4.0"}),
212 static inline const char *
217 if (list[i].num == num)
218 return (list[i].
name);
219 return "<unknown ERROR>";
229 hfc->
ctrl_urb->transfer_buffer_length = 0;
253 ctrl_start_transfer(hfc);
258 ctrl_complete(
struct urb *
urb)
268 ctrl_start_transfer(hfc);
311 set_led_bit(hfc, driver_info->
led_bits[0], 1);
312 set_led_bit(hfc, driver_info->
led_bits[1], 0);
313 set_led_bit(hfc, driver_info->
led_bits[2], 0);
314 set_led_bit(hfc, driver_info->
led_bits[3], 0);
317 set_led_bit(hfc, driver_info->
led_bits[0], 0);
318 set_led_bit(hfc, driver_info->
led_bits[1], 0);
319 set_led_bit(hfc, driver_info->
led_bits[2], 0);
320 set_led_bit(hfc, driver_info->
led_bits[3], 0);
323 set_led_bit(hfc, driver_info->
led_bits[1], 1);
326 set_led_bit(hfc, driver_info->
led_bits[1], 0);
329 set_led_bit(hfc, driver_info->
led_bits[2], 1);
332 set_led_bit(hfc, driver_info->
led_bits[2], 0);
335 set_led_bit(hfc, driver_info->
led_bits[3], 1);
338 set_led_bit(hfc, driver_info->
led_bits[3], 0);
352 "HFC-S USB: PH_DEACTIVATE | INDICATION sent (T3 expire)");
369 "HFC-S USB: PH_DEACTIVATE | INDICATION sent (T4 expire)");
388 if (state < 4 || state == 7 || state == 8) {
405 }
else if (state <= 3 ) {
406 if (old_state == 7 || old_state == 8) {
408 if (!timer_pending(&hfc->
t4_timer)) {
418 "HFC-S USB: PH_DEACTIVATE | INDICATION sent");
427 fill_isoc_urb(
struct urb *urb,
struct usb_device *
dev,
unsigned int pipe,
428 void *buf,
int num_packets,
int packet_size,
int interval,
436 urb->number_of_packets = num_packets;
437 urb->transfer_buffer_length = packet_size * num_packets;
439 urb->transfer_buffer =
buf;
440 urb->transfer_flags = URB_ISO_ASAP;
441 urb->actual_length = 0;
443 for (k = 0; k < num_packets; k++) {
444 urb->iso_frame_desc[
k].offset = packet_size *
k;
445 urb->iso_frame_desc[
k].length = packet_size;
446 urb->iso_frame_desc[
k].actual_length = 0;
454 start_isoc_chain(
usb_fifo *
fifo,
int num_packets_per_urb,
455 usb_complete_t complete,
int packet_size)
463 for (i = 0; i < 2; i++) {
464 if (!(fifo->
iso[i].purb)) {
467 if (!(fifo->
iso[i].purb)) {
469 "alloc urb for fifo %i failed!!!",
477 num_packets_per_urb)) {
478 fill_isoc_urb(fifo->
iso[i].purb,
486 sizeof(fifo->
iso[i].buffer));
488 for (k = 0; k < num_packets_per_urb; k++) {
490 iso_frame_desc[
k].offset =
493 iso_frame_desc[
k].length =
498 "HFC-S USB: ISO Buffer size to small!\n");
504 fifo->
active = (errcode >= 0) ? 1 : 0;
506 printk(
KERN_INFO "HFC-S USB: usb_submit_urb URB nr:%d, error(%i): '%s'\n",
507 i, errcode, symbolic(urb_errlist, errcode));
518 for (i = 0; i < 2; i++) {
519 if (fifo->
iso[i].purb) {
521 "HFC-S USB: Stopping iso chain for fifo %i.%i",
536 static int iso_packets[8] =
542 tx_iso_complete(
struct urb *urb)
547 int k, tx_offset, num_isoc_packets,
sink, len, current_len,
549 int frame_complete, transp_mode, fifon,
status;
561 ", urb->status %d, fifonum %d\n",
564 for (k = 0; k < iso_packets[fifon]; ++
k) {
565 errcode = urb->iso_frame_desc[
k].status;
568 "packet %i, status: %i\n",
583 num_isoc_packets = iso_packets[fifon];
591 fill_isoc_urb(urb, fifo->
hfc->dev, fifo->
pipe,
592 context_iso_urb->
buffer, num_isoc_packets,
594 tx_iso_complete, urb->context);
596 sizeof(context_iso_urb->
buffer));
600 for (k = 0; k < num_isoc_packets; ++
k) {
605 current_len = (0 - fifo->
bit_line) / 8;
607 if (current_len > 14)
611 current_len) ? len : current_len;
615 context_iso_urb->
buffer[tx_offset] = 0;
616 if (current_len == len) {
628 tx_offset + 1, fifo->
skbuff->data,
633 urb->iso_frame_desc[
k].offset = tx_offset;
634 urb->iso_frame_desc[
k].length =
637 tx_offset += (current_len + 1);
639 urb->iso_frame_desc[
k].offset =
642 urb->iso_frame_desc[
k].length = 1;
650 if (frame_complete) {
652 fifo->
hif->l1l2(fifo->
hif,
654 (
void *) (
unsigned long) fifo->
skbuff->
667 "HFC-S USB: error submitting ISO URB: %d\n",
673 "HFC-S USB: tx_iso_complete: error(%i): '%s', fifonum=%d\n",
680 rx_iso_complete(
struct urb *urb)
685 int k, len, errcode,
offset, num_isoc_packets, fifon, maxlen,
687 unsigned int iso_status;
696 "HFC-USB: ignoring USB DATAOVERRUN fifo(%i)", fifon);
704 "urb->status %d, fifonum %d\n",
710 num_isoc_packets = iso_packets[fifon];
712 for (k = 0; k < num_isoc_packets; ++
k) {
713 len = urb->iso_frame_desc[
k].actual_length;
716 iso_status = urb->iso_frame_desc[
k].status;
720 "HFC-S USB: rx_iso_complete "
721 "ISO packet %i, status: %i\n",
726 "HFC-S USB: ISO-D-RX lst_urblen:%2d "
727 "act_urblen:%2d max-urblen:%2d EOF:0x%0x",
742 s0_state_handler(hfc, buf[0] >> 4);
744 eof[fifon] = buf[0] & 1;
746 collect_rx_frame(fifo, buf + 2,
751 collect_rx_frame(fifo, buf, len,
753 maxlen) ? eof[fifon] :
759 fill_isoc_urb(urb, fifo->
hfc->dev, fifo->
pipe,
760 context_iso_urb->
buffer, num_isoc_packets,
762 rx_iso_complete, urb->context);
766 "HFC-S USB: error submitting ISO URB: %d\n",
772 "HFC-S USB: rx_iso_complete : "
773 "urb->status %d, fifonum %d\n",
784 int transp_mode, fifon;
795 "HFC-S USB: cannot allocate buffer for fifo(%d)\n",
805 "HCF-USB: got frame exceeded fifo->max_size(%d) fifo(%d)",
811 if (transp_mode && fifo->
skbuff->len >= 128) {
819 if (fifo->
skbuff->len > 3 &&
824 "HFC-S USB: D-RX len(%d)", fifo->
skbuff->len);
831 fifo->
hif->l1l2(fifo->
hif,
835 fifo->
hif->l1l2(fifo->
hif,
841 "HFC-S USB: ERROR frame len(%d) fifo(%d)",
842 fifo->
skbuff->len, fifon);
850 rx_int_complete(
struct urb *urb)
862 if ((!fifo->
active) || (urb->status)) {
866 fifo->
urb->interval = 0;
873 len = urb->actual_length;
879 "HFC-S USB: INT-D-RX lst_urblen:%2d "
880 "act_urblen:%2d max-urblen:%2d EOF:0x%0x",
890 s0_state_handler(hfc, buf[0] >> 4);
891 eof[fifon] = buf[0] & 1;
894 collect_rx_frame(fifo, buf + 2,
895 urb->actual_length - 2,
896 (len < maxlen) ? eof[fifon] : 0);
898 collect_rx_frame(fifo, buf, urb->actual_length,
899 (len < maxlen) ? eof[fifon] : 0);
905 "HFC-S USB: %s error resubmitting URB fifo(%d)\n",
924 usb_fill_int_urb(fifo->
urb, fifo->
hfc->dev, fifo->
pipe,
931 "HFC-S USB: submit URB error(start_int_info): status:%i\n",
941 __u8 val, idx_table[2] = { 0, 2 };
958 queue_control_request(hfc,
HFCUSB_FIFO, idx_table[channel], 1);
963 queue_control_request(hfc,
HFCUSB_FIFO, idx_table[channel] + 1, 1);
996 hfc_usb_l2l1(
struct hisax_if *my_hisax_if,
int pr,
void *
arg)
1005 "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_ACTIVATE | REQUEST");
1014 "HFC-S USB: PH_DEACTIVATE | INDICATION sent (not state 3 or 7)");
1017 hfc->
d_if.ifc.l1l2(&hfc->
1025 "HFC-S USB: PH_ACTIVATE | INDICATION sent again ;)");
1028 queue_control_request(hfc,
1034 queue_control_request(hfc,
1052 "HFC_USB: hfc_usb_d_l2l1 B-chan: PH_ACTIVATE | REQUEST");
1057 fifo->
hif->l1l2(fifo->
hif,
1065 "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_DEACTIVATE | REQUEST");
1068 "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_DEACTIVATE | REQUEST");
1073 fifo->
hif->l1l2(fifo->
hif,
1088 "HFC_USB: hfc_usb_d_l2l1: unknown state : %#x", pr);
1171 hfc->
t3_timer.function = (
void *) l1_timer_expire_t3;
1176 hfc->
t4_timer.function = (
void *) l1_timer_expire_t4;
1185 usb_fill_control_urb(hfc->
ctrl_urb,
1189 NULL, 0, ctrl_complete, hfc);
1199 hfc->
d_if.ifc.l2l1 = hfc_usb_l2l1;
1200 for (i = 0; i < 2; i++) {
1202 hfc->
b_if[
i].ifc.l2l1 = hfc_usb_l2l1;
1203 p_b_if[
i] = &hfc->
b_if[
i];
1213 #ifdef CONFIG_HISAX_DEBUG
1217 for (i = 0; i < 4; i++)
1219 for (i = 4; i < 8; i++)
1233 rx_iso_complete, 16);
1239 rx_iso_complete, 16);
1241 rx_iso_complete, 16);
1245 tx_iso_complete, 1);
1247 tx_iso_complete, 1);
1249 tx_iso_complete, 1);
1260 struct usb_device *dev = interface_to_usbdev(intf);
1262 struct usb_host_interface *iface = intf->cur_altsetting;
1263 struct usb_host_interface *iface_used =
NULL;
1264 struct usb_host_endpoint *ep;
1265 int ifnum = iface->desc.bInterfaceNumber;
1266 int i,
idx, alt_idx, probe_alt_setting, vend_idx, cfg_used, *vcf,
1267 attr, cfg_found, cidx, ep_addr;
1268 int cmptbl[16], small_match, iso_packet_size, packet_size,
1273 for (i = 0; hfcusb_idtab[
i].
idVendor; i++) {
1282 "HFC-S USB: probing interface(%d) actalt(%d) minor(%d)\n",
1283 ifnum, iface->desc.bAlternateSetting, intf->minor);
1285 if (vend_idx != 0xffff) {
1288 small_match = 0xffff;
1291 iso_packet_size = 16;
1294 while (alt_idx < intf->num_altsetting) {
1295 iface = intf->altsetting + alt_idx;
1296 probe_alt_setting = iface->desc.bAlternateSetting;
1300 while (validconf[cfg_used][0]) {
1302 vcf = validconf[cfg_used];
1304 ep = iface->endpoint;
1306 memcpy(cmptbl, vcf, 16 *
sizeof(
int));
1309 for (i = 0; i < iface->desc.bNumEndpoints;
1312 ep->desc.bEndpointAddress;
1314 idx = ((ep_addr & 0x7f) - 1) * 2;
1317 attr = ep->desc.bmAttributes;
1318 if (cmptbl[idx] ==
EP_NUL) {
1322 && cmptbl[idx] ==
EP_INT)
1325 && cmptbl[idx] ==
EP_BLK)
1328 && cmptbl[idx] ==
EP_ISO)
1333 && (ep->desc.bInterval < vcf[17])) {
1338 for (i = 0; i < 16; i++) {
1345 if (cfg_used < small_match) {
1346 small_match = cfg_used;
1358 if (small_match != 0xffff) {
1363 ep = iface->endpoint;
1364 vcf = validconf[small_match];
1366 for (i = 0; i < iface->desc.bNumEndpoints; i++) {
1367 ep_addr = ep->desc.bEndpointAddress;
1369 idx = ((ep_addr & 0x7f) - 1) * 2;
1373 attr = ep->desc.bmAttributes;
1457 context->
fifos[cidx].
1463 context->
fifos[cidx].
1466 context->
fifos[cidx].
1475 context->
ctrl_paksize = dev->descriptor.bMaxPacketSize0;
1483 usb_rcvctrlpipe(context->
dev, 0);
1485 usb_sndctrlpipe(context->
dev, 0);
1488 hfcusb_idtab[vend_idx].driver_info;
1493 pr_warn(
"%s: No memory for control urb\n",
1499 pr_info(
"HFC-S USB: detected \"%s\"\n",
1503 "HFC-S USB: Endpoint-Config: %s (if=%d alt=%d), E-Channel(%d)",
1504 conf_str[small_match], context->
if_used,
1506 validconf[small_match][18]);
1509 if (hfc_usb_init(context)) {
1516 usb_set_intfdata(intf, context);
1521 "HFC-S USB: no valid vendor found in USB descriptor\n");
1538 usb_set_intfdata(intf,
NULL);
1540 if (timer_pending(&context->
t3_timer))
1542 if (timer_pending(&context->
t4_timer))
1549 stop_isoc_chain(&context->
fifos[i]);
1551 "HFC-S USB: %s stopping ISOC chain Fifo(%i)",
1558 "HFC-S USB: %s unlinking URB for Fifo(%i)",
1574 static struct usb_driver hfc_drv = {
1576 .id_table = hfcusb_idtab,
1577 .probe = hfc_usb_probe,
1578 .disconnect = hfc_usb_disconnect,
1579 .disable_hub_initiated_lpm = 1,
1583 hfc_usb_mod_exit(
void)
1590 hfc_usb_mod_init(
void)
1592 char revstr[30], datestr[30],
dummy[30];
1593 #ifndef CONFIG_HISAX_DEBUG
1597 "%s %s $ %s %s %s $ ", dummy, revstr,
1598 dummy, datestr, dummy);
1600 "HFC-S USB: driver module revision %s date %s loaded, (debug=%i)\n",
1601 revstr, datestr,
debug);
1602 if (usb_register(&hfc_drv)) {
1604 "HFC-S USB: Unable to register HFC-S USB module at usb stack\n");