Lines Matching refs:kaweth

4  *     kaweth.c - driver for KL5KUSB101 based USB->Ethernet
94 MODULE_FIRMWARE("kaweth/new_code.bin");
95 MODULE_FIRMWARE("kaweth/new_code_fix.bin");
96 MODULE_FIRMWARE("kaweth/trigger_code.bin");
97 MODULE_FIRMWARE("kaweth/trigger_code_fix.bin");
99 static const char driver_name[] = "kaweth";
237 static int kaweth_read_configuration(struct kaweth_device *kaweth)
239 return usb_control_msg(kaweth->dev, usb_rcvctrlpipe(kaweth->dev, 0),
243 &kaweth->configuration,
244 sizeof(kaweth->configuration),
251 static int kaweth_set_urb_size(struct kaweth_device *kaweth, __u16 urb_size)
253 netdev_dbg(kaweth->net, "Setting URB size to %d\n", (unsigned)urb_size);
255 return usb_control_msg(kaweth->dev, usb_sndctrlpipe(kaweth->dev, 0),
259 &kaweth->scratch, 0,
266 static int kaweth_set_sofs_wait(struct kaweth_device *kaweth, __u16 sofs_wait)
268 netdev_dbg(kaweth->net, "Set SOFS wait to %d\n", (unsigned)sofs_wait);
270 return usb_control_msg(kaweth->dev, usb_sndctrlpipe(kaweth->dev, 0),
274 &kaweth->scratch, 0,
281 static int kaweth_set_receive_filter(struct kaweth_device *kaweth,
284 netdev_dbg(kaweth->net, "Set receive filter to %d\n",
287 return usb_control_msg(kaweth->dev, usb_sndctrlpipe(kaweth->dev, 0),
291 &kaweth->scratch, 0,
298 static int kaweth_download_firmware(struct kaweth_device *kaweth,
307 ret = request_firmware(&fw, fwname, &kaweth->dev->dev);
309 dev_err(&kaweth->intf->dev, "Firmware request failed\n");
314 dev_err(&kaweth->intf->dev, "Firmware too big: %zu\n",
320 memcpy(kaweth->firmware_buf, fw->data, fw->size);
324 kaweth->firmware_buf[2] = (data_len & 0xFF) - 7;
325 kaweth->firmware_buf[3] = data_len >> 8;
326 kaweth->firmware_buf[4] = type;
327 kaweth->firmware_buf[5] = interrupt;
329 netdev_dbg(kaweth->net, "High: %i, Low:%i\n", kaweth->firmware_buf[3],
330 kaweth->firmware_buf[2]);
332 netdev_dbg(kaweth->net,
333 "Downloading firmware at %p to kaweth device at %p\n",
334 kaweth->firmware_buf, kaweth);
335 netdev_dbg(kaweth->net, "Firmware length: %d\n", data_len);
337 return usb_control_msg(kaweth->dev, usb_sndctrlpipe(kaweth->dev, 0),
341 kaweth->firmware_buf, data_len,
348 static int kaweth_trigger_firmware(struct kaweth_device *kaweth,
351 kaweth->firmware_buf[0] = 0xB6;
352 kaweth->firmware_buf[1] = 0xC3;
353 kaweth->firmware_buf[2] = 0x01;
354 kaweth->firmware_buf[3] = 0x00;
355 kaweth->firmware_buf[4] = 0x06;
356 kaweth->firmware_buf[5] = interrupt;
357 kaweth->firmware_buf[6] = 0x00;
358 kaweth->firmware_buf[7] = 0x00;
360 return usb_control_msg(kaweth->dev, usb_sndctrlpipe(kaweth->dev, 0),
364 (void *)kaweth->firmware_buf, 8,
371 static int kaweth_reset(struct kaweth_device *kaweth)
375 result = usb_reset_configuration(kaweth->dev);
378 netdev_dbg(kaweth->net, "kaweth_reset() returns %d.\n", result);
390 static void kaweth_resubmit_int_urb(struct kaweth_device *kaweth, gfp_t mf)
394 status = usb_submit_urb (kaweth->irq_urb, mf);
396 kaweth->suspend_lowmem_ctrl = 1;
397 schedule_delayed_work(&kaweth->lowmem_work, HZ/4);
399 kaweth->suspend_lowmem_ctrl = 0;
403 dev_err(&kaweth->intf->dev,
405 kaweth->dev->bus->bus_name,
406 kaweth->dev->devpath, status);
411 struct kaweth_device *kaweth = u->context;
428 if (kaweth->linkstate != (act_state = ( kaweth->intbuffer[STATE_OFFSET] | STATE_MASK) >> STATE_SHIFT)) {
430 netif_carrier_on(kaweth->net);
432 netif_carrier_off(kaweth->net);
434 kaweth->linkstate = act_state;
437 kaweth_resubmit_int_urb(kaweth, GFP_ATOMIC);
442 struct kaweth_device *kaweth =
445 if (IS_BLOCKED(kaweth->status))
448 if (kaweth->suspend_lowmem_rx)
449 kaweth_resubmit_rx_urb(kaweth, GFP_NOIO);
451 if (kaweth->suspend_lowmem_ctrl)
452 kaweth_resubmit_int_urb(kaweth, GFP_NOIO);
459 static int kaweth_resubmit_rx_urb(struct kaweth_device *kaweth,
464 usb_fill_bulk_urb(kaweth->rx_urb,
465 kaweth->dev,
466 usb_rcvbulkpipe(kaweth->dev, 1),
467 kaweth->rx_buf,
470 kaweth);
471 kaweth->rx_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
472 kaweth->rx_urb->transfer_dma = kaweth->rxbufferhandle;
474 if((result = usb_submit_urb(kaweth->rx_urb, mem_flags))) {
476 kaweth->suspend_lowmem_rx = 1;
477 schedule_delayed_work(&kaweth->lowmem_work, HZ/4);
479 dev_err(&kaweth->intf->dev, "resubmitting rx_urb %d failed\n",
482 kaweth->suspend_lowmem_rx = 0;
488 static void kaweth_async_set_rx_mode(struct kaweth_device *kaweth,
497 struct kaweth_device *kaweth = urb->context;
498 struct net_device *net = kaweth->net;
504 __u16 pkt_len = le16_to_cpup((__le16 *)kaweth->rx_buf);
510 kaweth->end = 1;
511 wake_up(&kaweth->term_wait);
517 kaweth->end = 1;
518 wake_up(&kaweth->term_wait);
532 spin_lock_irqsave(&kaweth->device_lock, flags);
533 if (IS_BLOCKED(kaweth->status)) {
534 spin_unlock_irqrestore(&kaweth->device_lock, flags);
537 spin_unlock_irqrestore(&kaweth->device_lock, flags);
540 dev_err(&kaweth->intf->dev,
543 kaweth_resubmit_rx_urb(kaweth, GFP_ATOMIC);
547 if(kaweth->net && (count > 2)) {
549 dev_err(&kaweth->intf->dev,
552 dev_err(&kaweth->intf->dev, "Packet len & 2047: %x\n",
554 dev_err(&kaweth->intf->dev, "Count 2: %x\n", count2);
555 kaweth_resubmit_rx_urb(kaweth, GFP_ATOMIC);
560 kaweth_resubmit_rx_urb(kaweth, GFP_ATOMIC);
566 skb_copy_to_linear_data(skb, kaweth->rx_buf + 2, pkt_len);
578 kaweth_resubmit_rx_urb(kaweth, GFP_ATOMIC);
586 struct kaweth_device *kaweth = netdev_priv(net);
589 res = usb_autopm_get_interface(kaweth->intf);
591 dev_err(&kaweth->intf->dev, "Interface cannot be resumed.\n");
594 res = kaweth_resubmit_rx_urb(kaweth, GFP_KERNEL);
599 kaweth->irq_urb,
600 kaweth->dev,
601 usb_rcvintpipe(kaweth->dev, 3),
602 kaweth->intbuffer,
605 kaweth,
607 kaweth->irq_urb->transfer_dma = kaweth->intbufferhandle;
608 kaweth->irq_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
610 res = usb_submit_urb(kaweth->irq_urb, GFP_KERNEL);
612 usb_kill_urb(kaweth->rx_urb);
615 kaweth->opened = 1;
619 kaweth_async_set_rx_mode(kaweth, true);
623 usb_autopm_put_interface(kaweth->intf);
630 static void kaweth_kill_urbs(struct kaweth_device *kaweth)
632 usb_kill_urb(kaweth->irq_urb);
633 usb_kill_urb(kaweth->rx_urb);
634 usb_kill_urb(kaweth->tx_urb);
636 cancel_delayed_work_sync(&kaweth->lowmem_work);
640 usb_kill_urb(kaweth->irq_urb);
641 usb_kill_urb(kaweth->rx_urb);
649 struct kaweth_device *kaweth = netdev_priv(net);
652 kaweth->opened = 0;
654 kaweth->status |= KAWETH_STATUS_CLOSING;
656 kaweth_kill_urbs(kaweth);
658 kaweth->status &= ~KAWETH_STATUS_CLOSING;
660 usb_autopm_put_interface(kaweth->intf);
667 struct kaweth_device *kaweth = netdev_priv(dev);
669 return kaweth->linkstate;
681 struct kaweth_device *kaweth = urb->context;
682 struct sk_buff *skb = kaweth->tx_skb;
688 kaweth->net->name, status);
690 netif_wake_queue(kaweth->net);
700 struct kaweth_device *kaweth = netdev_priv(net);
705 spin_lock_irq(&kaweth->device_lock);
707 kaweth_async_set_rx_mode(kaweth, false);
709 if (IS_BLOCKED(kaweth->status)) {
717 spin_unlock_irq(&kaweth->device_lock);
724 kaweth->tx_skb = skb;
726 usb_fill_bulk_urb(kaweth->tx_urb,
727 kaweth->dev,
728 usb_sndbulkpipe(kaweth->dev, 2),
732 kaweth);
733 kaweth->end = 0;
735 if((res = usb_submit_urb(kaweth->tx_urb, GFP_ATOMIC)))
737 dev_warn(&net->dev, "kaweth failed tx_urb %d\n", res);
750 spin_unlock_irq(&kaweth->device_lock);
760 struct kaweth_device *kaweth = netdev_priv(net);
777 kaweth->packet_filter_bitmap = packet_filter_bitmap;
784 static void kaweth_async_set_rx_mode(struct kaweth_device *kaweth,
788 __u16 packet_filter_bitmap = kaweth->packet_filter_bitmap;
790 kaweth->packet_filter_bitmap = 0;
797 ret = usb_control_msg(kaweth->dev, usb_sndctrlpipe(kaweth->dev, 0),
801 &kaweth->scratch, 0,
804 dev_err(&kaweth->intf->dev, "Failed to set Rx mode: %d\n",
807 netdev_dbg(kaweth->net, "Set Rx mode to %d\n",
816 struct kaweth_device *kaweth = netdev_priv(net);
822 usb_unlink_urb(kaweth->tx_urb);
830 struct kaweth_device *kaweth = usb_get_intfdata(intf);
833 spin_lock_irqsave(&kaweth->device_lock, flags);
834 kaweth->status |= KAWETH_STATUS_SUSPENDING;
835 spin_unlock_irqrestore(&kaweth->device_lock, flags);
837 kaweth_kill_urbs(kaweth);
846 struct kaweth_device *kaweth = usb_get_intfdata(intf);
849 spin_lock_irqsave(&kaweth->device_lock, flags);
850 kaweth->status &= ~KAWETH_STATUS_SUSPENDING;
851 spin_unlock_irqrestore(&kaweth->device_lock, flags);
853 if (!kaweth->opened)
855 kaweth_resubmit_rx_urb(kaweth, GFP_NOIO);
856 kaweth_resubmit_int_urb(kaweth, GFP_NOIO);
883 struct kaweth_device *kaweth;
901 netdev = alloc_etherdev(sizeof(*kaweth));
905 kaweth = netdev_priv(netdev);
906 kaweth->dev = udev;
907 kaweth->net = netdev;
908 kaweth->intf = intf;
910 spin_lock_init(&kaweth->device_lock);
911 init_waitqueue_head(&kaweth->term_wait);
915 kaweth_reset(kaweth);
927 kaweth->firmware_buf = (__u8 *)__get_free_page(GFP_KERNEL);
928 if (!kaweth->firmware_buf) {
932 if ((result = kaweth_download_firmware(kaweth,
933 "kaweth/new_code.bin",
941 if ((result = kaweth_download_firmware(kaweth,
942 "kaweth/new_code_fix.bin",
950 if ((result = kaweth_download_firmware(kaweth,
951 "kaweth/trigger_code.bin",
960 if ((result = kaweth_download_firmware(kaweth,
961 "kaweth/trigger_code_fix.bin",
969 if ((result = kaweth_trigger_firmware(kaweth, 126)) < 0) {
977 free_page((unsigned long)kaweth->firmware_buf);
982 result = kaweth_read_configuration(kaweth);
989 dev_info(dev, "Statistics collection: %x\n", kaweth->configuration.statistics_mask);
990 dev_info(dev, "Multicast filter limit: %x\n", kaweth->configuration.max_multicast_filters & ((1 << 15) - 1));
991 dev_info(dev, "MTU: %d\n", le16_to_cpu(kaweth->configuration.segment_size));
992 dev_info(dev, "Read MAC address %pM\n", kaweth->configuration.hw_addr);
994 if(!memcmp(&kaweth->configuration.hw_addr,
1001 if(kaweth_set_urb_size(kaweth, KAWETH_BUF_SIZE) < 0) {
1006 if(kaweth_set_sofs_wait(kaweth, KAWETH_SOFS_TO_WAIT) < 0) {
1011 result = kaweth_set_receive_filter(kaweth,
1023 kaweth->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
1024 if (!kaweth->tx_urb)
1026 kaweth->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
1027 if (!kaweth->rx_urb)
1029 kaweth->irq_urb = usb_alloc_urb(0, GFP_KERNEL);
1030 if (!kaweth->irq_urb)
1033 kaweth->intbuffer = usb_alloc_coherent( kaweth->dev,
1036 &kaweth->intbufferhandle);
1037 if (!kaweth->intbuffer)
1039 kaweth->rx_buf = usb_alloc_coherent( kaweth->dev,
1042 &kaweth->rxbufferhandle);
1043 if (!kaweth->rx_buf)
1047 memcpy(netdev->dev_addr, &kaweth->configuration.hw_addr,
1048 sizeof(kaweth->configuration.hw_addr));
1052 netdev->mtu = le16_to_cpu(kaweth->configuration.segment_size);
1055 /* kaweth is zeroed as part of alloc_netdev */
1056 INIT_DELAYED_WORK(&kaweth->lowmem_work, kaweth_resubmit_tl);
1057 usb_set_intfdata(intf, kaweth);
1065 dev_info(dev, "kaweth interface created at %s\n",
1066 kaweth->net->name);
1072 usb_free_coherent(kaweth->dev, KAWETH_BUF_SIZE, (void *)kaweth->rx_buf, kaweth->rxbufferhandle);
1074 usb_free_coherent(kaweth->dev, INTBUFFERSIZE, (void *)kaweth->intbuffer, kaweth->intbufferhandle);
1076 usb_free_urb(kaweth->irq_urb);
1078 usb_free_urb(kaweth->rx_urb);
1080 usb_free_urb(kaweth->tx_urb);
1092 struct kaweth_device *kaweth = usb_get_intfdata(intf);
1096 if (!kaweth) {
1100 netdev = kaweth->net;
1102 netdev_dbg(kaweth->net, "Unregistering net device\n");
1105 usb_free_urb(kaweth->rx_urb);
1106 usb_free_urb(kaweth->tx_urb);
1107 usb_free_urb(kaweth->irq_urb);
1109 usb_free_coherent(kaweth->dev, KAWETH_BUF_SIZE, (void *)kaweth->rx_buf, kaweth->rxbufferhandle);
1110 usb_free_coherent(kaweth->dev, INTBUFFERSIZE, (void *)kaweth->intbuffer, kaweth->intbufferhandle);