Lines Matching +full:report +full:- +full:speed +full:- +full:hz
1 // SPDX-License-Identifier: GPL-2.0-only
19 #define DRIVER_DESC "rtl8150 based usb-ethernet driver"
86 #define RTL8150_TX_TIMEOUT (HZ)
155 return usb_control_msg_recv(dev->udev, 0, RTL8150_REQ_GET_REGS, in get_registers()
162 return usb_control_msg_send(dev->udev, 0, RTL8150_REQ_SET_REGS, in set_registers()
169 struct async_req *req = (struct async_req *)urb->context; in async_set_reg_cb()
170 int status = urb->status; in async_set_reg_cb()
173 dev_dbg(&urb->dev->dev, "%s failed with %d", __func__, status); in async_set_reg_cb()
180 int res = -ENOMEM; in async_set_registers()
192 req->rx_creg = cpu_to_le16(reg); in async_set_registers()
193 req->dr.bRequestType = RTL8150_REQT_WRITE; in async_set_registers()
194 req->dr.bRequest = RTL8150_REQ_SET_REGS; in async_set_registers()
195 req->dr.wIndex = 0; in async_set_registers()
196 req->dr.wValue = cpu_to_le16(indx); in async_set_registers()
197 req->dr.wLength = cpu_to_le16(size); in async_set_registers()
198 usb_fill_control_urb(async_urb, dev->udev, in async_set_registers()
199 usb_sndctrlpipe(dev->udev, 0), (void *)&req->dr, in async_set_registers()
200 &req->rx_creg, size, async_set_reg_cb, req); in async_set_registers()
203 if (res == -ENODEV) in async_set_registers()
204 netif_device_detach(dev->netdev); in async_set_registers()
205 dev_err(&dev->udev->dev, "%s failed with %d\n", __func__, res); in async_set_registers()
265 eth_hw_addr_set(dev->netdev, node_id); in set_ethernet_addr()
267 eth_hw_addr_random(dev->netdev); in set_ethernet_addr()
268 netdev_notice(dev->netdev, "Assigned a random MAC address: %pM\n", in set_ethernet_addr()
269 dev->netdev->dev_addr); in set_ethernet_addr()
279 return -EBUSY; in rtl8150_set_mac_address()
281 eth_hw_addr_set(netdev, addr->sa_data); in rtl8150_set_mac_address()
282 netdev_dbg(netdev, "Setting MAC address to %pM\n", netdev->dev_addr); in rtl8150_set_mac_address()
284 set_registers(dev, IDR, netdev->addr_len, netdev->dev_addr); in rtl8150_set_mac_address()
294 /* Write the MAC address into eeprom. Eeprom writes must be word-sized, in rtl8150_set_mac_address()
296 for (i = 0; i * 2 < netdev->addr_len; i++) { in rtl8150_set_mac_address()
298 netdev->dev_addr + (i * 2)); in rtl8150_set_mac_address()
311 int i = HZ; in rtl8150_reset()
316 } while ((data & 0x10) && --i); in rtl8150_reset()
323 dev->rx_urb = usb_alloc_urb(0, GFP_KERNEL); in alloc_all_urbs()
324 if (!dev->rx_urb) in alloc_all_urbs()
326 dev->tx_urb = usb_alloc_urb(0, GFP_KERNEL); in alloc_all_urbs()
327 if (!dev->tx_urb) { in alloc_all_urbs()
328 usb_free_urb(dev->rx_urb); in alloc_all_urbs()
331 dev->intr_urb = usb_alloc_urb(0, GFP_KERNEL); in alloc_all_urbs()
332 if (!dev->intr_urb) { in alloc_all_urbs()
333 usb_free_urb(dev->rx_urb); in alloc_all_urbs()
334 usb_free_urb(dev->tx_urb); in alloc_all_urbs()
343 usb_free_urb(dev->rx_urb); in free_all_urbs()
344 usb_free_urb(dev->tx_urb); in free_all_urbs()
345 usb_free_urb(dev->intr_urb); in free_all_urbs()
350 usb_kill_urb(dev->rx_urb); in unlink_all_urbs()
351 usb_kill_urb(dev->tx_urb); in unlink_all_urbs()
352 usb_kill_urb(dev->intr_urb); in unlink_all_urbs()
361 if (dev->rx_skb_pool[i]) { in pull_skb()
362 skb = dev->rx_skb_pool[i]; in pull_skb()
363 dev->rx_skb_pool[i] = NULL; in pull_skb()
376 int status = urb->status; in read_bulk_callback()
380 dev = urb->context; in read_bulk_callback()
383 if (test_bit(RTL8150_UNPLUG, &dev->flags)) in read_bulk_callback()
385 netdev = dev->netdev; in read_bulk_callback()
392 case -ENOENT: in read_bulk_callback()
394 case -ETIME: in read_bulk_callback()
396 dev_warn(&urb->dev->dev, "may be reset is needed?..\n"); in read_bulk_callback()
400 dev_warn(&urb->dev->dev, "Rx status %d\n", status); in read_bulk_callback()
404 if (!dev->rx_skb) in read_bulk_callback()
407 if (urb->actual_length < 4) in read_bulk_callback()
410 res = urb->actual_length; in read_bulk_callback()
411 pkt_len = res - 4; in read_bulk_callback()
413 skb_put(dev->rx_skb, pkt_len); in read_bulk_callback()
414 dev->rx_skb->protocol = eth_type_trans(dev->rx_skb, netdev); in read_bulk_callback()
415 netif_rx(dev->rx_skb); in read_bulk_callback()
416 netdev->stats.rx_packets++; in read_bulk_callback()
417 netdev->stats.rx_bytes += pkt_len; in read_bulk_callback()
419 spin_lock_irqsave(&dev->rx_pool_lock, flags); in read_bulk_callback()
421 spin_unlock_irqrestore(&dev->rx_pool_lock, flags); in read_bulk_callback()
425 dev->rx_skb = skb; in read_bulk_callback()
427 usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1), in read_bulk_callback()
428 dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev); in read_bulk_callback()
429 result = usb_submit_urb(dev->rx_urb, GFP_ATOMIC); in read_bulk_callback()
430 if (result == -ENODEV) in read_bulk_callback()
431 netif_device_detach(dev->netdev); in read_bulk_callback()
433 set_bit(RX_URB_FAIL, &dev->flags); in read_bulk_callback()
436 clear_bit(RX_URB_FAIL, &dev->flags); in read_bulk_callback()
441 tasklet_schedule(&dev->tl); in read_bulk_callback()
447 int status = urb->status; in write_bulk_callback()
449 dev = urb->context; in write_bulk_callback()
452 dev_kfree_skb_irq(dev->tx_skb); in write_bulk_callback()
453 if (!netif_device_present(dev->netdev)) in write_bulk_callback()
456 dev_info(&urb->dev->dev, "%s: Tx status %d\n", in write_bulk_callback()
457 dev->netdev->name, status); in write_bulk_callback()
458 netif_trans_update(dev->netdev); in write_bulk_callback()
459 netif_wake_queue(dev->netdev); in write_bulk_callback()
466 int status = urb->status; in intr_callback()
469 dev = urb->context; in intr_callback()
475 case -ECONNRESET: /* unlink */ in intr_callback()
476 case -ENOENT: in intr_callback()
477 case -ESHUTDOWN: in intr_callback()
479 /* -EPIPE: should clear the halt */ in intr_callback()
481 dev_info(&urb->dev->dev, "%s: intr status %d\n", in intr_callback()
482 dev->netdev->name, status); in intr_callback()
486 d = urb->transfer_buffer; in intr_callback()
488 dev->netdev->stats.tx_errors++; in intr_callback()
490 dev->netdev->stats.tx_aborted_errors++; in intr_callback()
492 dev->netdev->stats.tx_window_errors++; in intr_callback()
494 dev->netdev->stats.tx_carrier_errors++; in intr_callback()
496 /* Report link status changes to the network stack */ in intr_callback()
498 if (netif_carrier_ok(dev->netdev)) { in intr_callback()
499 netif_carrier_off(dev->netdev); in intr_callback()
500 netdev_dbg(dev->netdev, "%s: LINK LOST\n", __func__); in intr_callback()
503 if (!netif_carrier_ok(dev->netdev)) { in intr_callback()
504 netif_carrier_on(dev->netdev); in intr_callback()
505 netdev_dbg(dev->netdev, "%s: LINK CAME BACK\n", __func__); in intr_callback()
511 if (res == -ENODEV) in intr_callback()
512 netif_device_detach(dev->netdev); in intr_callback()
514 dev_err(&dev->udev->dev, in intr_callback()
515 "can't resubmit intr, %s-%s/input0, status %d\n", in intr_callback()
516 dev->udev->bus->bus_name, dev->udev->devpath, res); in intr_callback()
523 netif_device_detach(dev->netdev); in rtl8150_suspend()
525 if (netif_running(dev->netdev)) { in rtl8150_suspend()
526 usb_kill_urb(dev->rx_urb); in rtl8150_suspend()
527 usb_kill_urb(dev->intr_urb); in rtl8150_suspend()
536 netif_device_attach(dev->netdev); in rtl8150_resume()
537 if (netif_running(dev->netdev)) { in rtl8150_resume()
538 dev->rx_urb->status = 0; in rtl8150_resume()
539 dev->rx_urb->actual_length = 0; in rtl8150_resume()
540 read_bulk_callback(dev->rx_urb); in rtl8150_resume()
542 dev->intr_urb->status = 0; in rtl8150_resume()
543 dev->intr_urb->actual_length = 0; in rtl8150_resume()
544 intr_callback(dev->intr_urb); in rtl8150_resume()
561 if (dev->rx_skb_pool[i]) in fill_skb_pool()
568 dev->rx_skb_pool[i] = skb; in fill_skb_pool()
577 dev_kfree_skb(dev->rx_skb_pool[i]); in free_skb_pool()
586 spin_lock_irq(&dev->rx_pool_lock); in rx_fixup()
588 spin_unlock_irq(&dev->rx_pool_lock); in rx_fixup()
589 if (test_bit(RX_URB_FAIL, &dev->flags)) in rx_fixup()
590 if (dev->rx_skb) in rx_fixup()
592 spin_lock_irq(&dev->rx_pool_lock); in rx_fixup()
594 spin_unlock_irq(&dev->rx_pool_lock); in rx_fixup()
597 dev->rx_skb = skb; in rx_fixup()
598 usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1), in rx_fixup()
599 dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev); in rx_fixup()
601 status = usb_submit_urb(dev->rx_urb, GFP_ATOMIC); in rx_fixup()
602 if (status == -ENODEV) { in rx_fixup()
603 netif_device_detach(dev->netdev); in rx_fixup()
605 set_bit(RX_URB_FAIL, &dev->flags); in rx_fixup()
608 clear_bit(RX_URB_FAIL, &dev->flags); in rx_fixup()
613 tasklet_schedule(&dev->tl); in rx_fixup()
621 dev_warn(&dev->udev->dev, "device reset failed\n"); in enable_net_traffic()
628 set_bit(RTL8150_HW_CRC, &dev->flags); in enable_net_traffic()
649 dev_warn(&netdev->dev, "Tx timeout.\n"); in rtl8150_tx_timeout()
650 usb_unlink_urb(dev->tx_urb); in rtl8150_tx_timeout()
651 netdev->stats.tx_errors++; in rtl8150_tx_timeout()
660 if (netdev->flags & IFF_PROMISC) { in rtl8150_set_multicast()
662 dev_info(&netdev->dev, "%s: promiscuous mode\n", netdev->name); in rtl8150_set_multicast()
664 (netdev->flags & IFF_ALLMULTI)) { in rtl8150_set_multicast()
667 dev_dbg(&netdev->dev, "%s: allmulti set\n", netdev->name); in rtl8150_set_multicast()
683 count = (skb->len < 60) ? 60 : skb->len; in rtl8150_start_xmit()
685 dev->tx_skb = skb; in rtl8150_start_xmit()
686 usb_fill_bulk_urb(dev->tx_urb, dev->udev, usb_sndbulkpipe(dev->udev, 2), in rtl8150_start_xmit()
687 skb->data, count, write_bulk_callback, dev); in rtl8150_start_xmit()
688 if ((res = usb_submit_urb(dev->tx_urb, GFP_ATOMIC))) { in rtl8150_start_xmit()
690 if (res == -ENODEV) in rtl8150_start_xmit()
691 netif_device_detach(dev->netdev); in rtl8150_start_xmit()
693 dev_warn(&netdev->dev, "failed tx_urb %d\n", res); in rtl8150_start_xmit()
694 netdev->stats.tx_errors++; in rtl8150_start_xmit()
698 netdev->stats.tx_packets++; in rtl8150_start_xmit()
699 netdev->stats.tx_bytes += skb->len; in rtl8150_start_xmit()
724 if (dev->rx_skb == NULL) in rtl8150_open()
725 dev->rx_skb = pull_skb(dev); in rtl8150_open()
726 if (!dev->rx_skb) in rtl8150_open()
727 return -ENOMEM; in rtl8150_open()
729 set_registers(dev, IDR, 6, netdev->dev_addr); in rtl8150_open()
731 usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1), in rtl8150_open()
732 dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev); in rtl8150_open()
733 if ((res = usb_submit_urb(dev->rx_urb, GFP_KERNEL))) { in rtl8150_open()
734 if (res == -ENODEV) in rtl8150_open()
735 netif_device_detach(dev->netdev); in rtl8150_open()
736 dev_warn(&netdev->dev, "rx_urb submit failed: %d\n", res); in rtl8150_open()
739 usb_fill_int_urb(dev->intr_urb, dev->udev, usb_rcvintpipe(dev->udev, 3), in rtl8150_open()
740 dev->intr_buff, INTBUFSIZE, intr_callback, in rtl8150_open()
741 dev, dev->intr_interval); in rtl8150_open()
742 if ((res = usb_submit_urb(dev->intr_urb, GFP_KERNEL))) { in rtl8150_open()
743 if (res == -ENODEV) in rtl8150_open()
744 netif_device_detach(dev->netdev); in rtl8150_open()
745 dev_warn(&netdev->dev, "intr_urb submit failed: %d\n", res); in rtl8150_open()
746 usb_kill_urb(dev->rx_urb); in rtl8150_open()
761 if (!test_bit(RTL8150_UNPLUG, &dev->flags)) in rtl8150_close()
772 strscpy(info->driver, driver_name, sizeof(info->driver)); in rtl8150_get_drvinfo()
773 strscpy(info->version, DRIVER_VERSION, sizeof(info->version)); in rtl8150_get_drvinfo()
774 usb_make_path(dev->udev, info->bus_info, sizeof(info->bus_info)); in rtl8150_get_drvinfo()
791 ecmd->base.port = PORT_TP; in rtl8150_get_link_ksettings()
792 ecmd->base.phy_address = dev->phy; in rtl8150_get_link_ksettings()
796 u32 speed = ((lpa & (LPA_100HALF | LPA_100FULL)) ? in rtl8150_get_link_ksettings() local
798 ecmd->base.speed = speed; in rtl8150_get_link_ksettings()
799 ecmd->base.autoneg = AUTONEG_ENABLE; in rtl8150_get_link_ksettings()
800 if (speed == SPEED_100) in rtl8150_get_link_ksettings()
801 ecmd->base.duplex = (lpa & LPA_100FULL) ? in rtl8150_get_link_ksettings()
804 ecmd->base.duplex = (lpa & LPA_10FULL) ? in rtl8150_get_link_ksettings()
807 ecmd->base.autoneg = AUTONEG_DISABLE; in rtl8150_get_link_ksettings()
808 ecmd->base.speed = ((bmcr & BMCR_SPEED100) ? in rtl8150_get_link_ksettings()
810 ecmd->base.duplex = (bmcr & BMCR_FULLDPLX) ? in rtl8150_get_link_ksettings()
814 ethtool_convert_legacy_u32_to_link_mode(ecmd->link_modes.supported, in rtl8150_get_link_ksettings()
830 u16 *data = (u16 *) & rq->ifr_ifru; in rtl8150_siocdevprivate()
835 data[0] = dev->phy; in rtl8150_siocdevprivate()
838 read_mii_word(dev, dev->phy, (data[1] & 0x1f), &data[3]); in rtl8150_siocdevprivate()
842 return -EPERM; in rtl8150_siocdevprivate()
843 write_mii_word(dev, dev->phy, (data[1] & 0x1f), data[2]); in rtl8150_siocdevprivate()
846 res = -EOPNOTSUPP; in rtl8150_siocdevprivate()
873 return -ENOMEM; in rtl8150_probe()
877 dev->intr_buff = kmalloc(INTBUFSIZE, GFP_KERNEL); in rtl8150_probe()
878 if (!dev->intr_buff) { in rtl8150_probe()
880 return -ENOMEM; in rtl8150_probe()
883 tasklet_setup(&dev->tl, rx_fixup); in rtl8150_probe()
884 spin_lock_init(&dev->rx_pool_lock); in rtl8150_probe()
886 dev->udev = udev; in rtl8150_probe()
887 dev->netdev = netdev; in rtl8150_probe()
888 netdev->netdev_ops = &rtl8150_netdev_ops; in rtl8150_probe()
889 netdev->watchdog_timeo = RTL8150_TX_TIMEOUT; in rtl8150_probe()
890 netdev->ethtool_ops = &ops; in rtl8150_probe()
891 dev->intr_interval = 100; /* 100ms */ in rtl8150_probe()
894 dev_err(&intf->dev, "out of memory\n"); in rtl8150_probe()
898 dev_err(&intf->dev, "couldn't reset the device\n"); in rtl8150_probe()
905 SET_NETDEV_DEV(netdev, &intf->dev); in rtl8150_probe()
907 dev_err(&intf->dev, "couldn't register the device\n"); in rtl8150_probe()
911 dev_info(&intf->dev, "%s: rtl8150 is detected\n", netdev->name); in rtl8150_probe()
921 kfree(dev->intr_buff); in rtl8150_probe()
923 return -EIO; in rtl8150_probe()
932 set_bit(RTL8150_UNPLUG, &dev->flags); in rtl8150_disconnect()
933 tasklet_kill(&dev->tl); in rtl8150_disconnect()
934 unregister_netdev(dev->netdev); in rtl8150_disconnect()
938 dev_kfree_skb(dev->rx_skb); in rtl8150_disconnect()
939 kfree(dev->intr_buff); in rtl8150_disconnect()
940 free_netdev(dev->netdev); in rtl8150_disconnect()