Lines Matching +full:enable +full:- +full:lpa
1 // SPDX-License-Identifier: GPL-2.0-only
19 #define DRIVER_DESC "rtl8150 based usb-ethernet driver"
163 return usb_control_msg_recv(dev->udev, 0, RTL8150_REQ_GET_REGS, in get_registers()
170 return usb_control_msg_send(dev->udev, 0, RTL8150_REQ_SET_REGS, in set_registers()
177 struct async_req *req = (struct async_req *)urb->context; in async_set_reg_cb()
178 int status = urb->status; in async_set_reg_cb()
181 dev_dbg(&urb->dev->dev, "%s failed with %d", __func__, status); in async_set_reg_cb()
188 int res = -ENOMEM; in async_set_registers()
200 req->rx_creg = cpu_to_le16(reg); in async_set_registers()
201 req->dr.bRequestType = RTL8150_REQT_WRITE; in async_set_registers()
202 req->dr.bRequest = RTL8150_REQ_SET_REGS; in async_set_registers()
203 req->dr.wIndex = 0; in async_set_registers()
204 req->dr.wValue = cpu_to_le16(indx); in async_set_registers()
205 req->dr.wLength = cpu_to_le16(size); in async_set_registers()
206 usb_fill_control_urb(async_urb, dev->udev, in async_set_registers()
207 usb_sndctrlpipe(dev->udev, 0), (void *)&req->dr, in async_set_registers()
208 &req->rx_creg, size, async_set_reg_cb, req); in async_set_registers()
211 if (res == -ENODEV) in async_set_registers()
212 netif_device_detach(dev->netdev); in async_set_registers()
213 dev_err(&dev->udev->dev, "%s failed with %d\n", __func__, res); in async_set_registers()
273 eth_hw_addr_set(dev->netdev, node_id); in set_ethernet_addr()
275 eth_hw_addr_random(dev->netdev); in set_ethernet_addr()
276 netdev_notice(dev->netdev, "Assigned a random MAC address: %pM\n", in set_ethernet_addr()
277 dev->netdev->dev_addr); in set_ethernet_addr()
287 return -EBUSY; in rtl8150_set_mac_address()
289 eth_hw_addr_set(netdev, addr->sa_data); in rtl8150_set_mac_address()
290 netdev_dbg(netdev, "Setting MAC address to %pM\n", netdev->dev_addr); in rtl8150_set_mac_address()
292 set_registers(dev, IDR, netdev->addr_len, netdev->dev_addr); in rtl8150_set_mac_address()
299 /* Set the WEPROM bit (eeprom write enable). */ in rtl8150_set_mac_address()
302 /* Write the MAC address into eeprom. Eeprom writes must be word-sized, in rtl8150_set_mac_address()
304 for (i = 0; i * 2 < netdev->addr_len; i++) { in rtl8150_set_mac_address()
306 netdev->dev_addr + (i * 2)); in rtl8150_set_mac_address()
324 } while ((data & 0x10) && --i); in rtl8150_reset()
331 dev->rx_urb = usb_alloc_urb(0, GFP_KERNEL); in alloc_all_urbs()
332 if (!dev->rx_urb) in alloc_all_urbs()
334 dev->tx_urb = usb_alloc_urb(0, GFP_KERNEL); in alloc_all_urbs()
335 if (!dev->tx_urb) { in alloc_all_urbs()
336 usb_free_urb(dev->rx_urb); in alloc_all_urbs()
339 dev->intr_urb = usb_alloc_urb(0, GFP_KERNEL); in alloc_all_urbs()
340 if (!dev->intr_urb) { in alloc_all_urbs()
341 usb_free_urb(dev->rx_urb); in alloc_all_urbs()
342 usb_free_urb(dev->tx_urb); in alloc_all_urbs()
351 usb_free_urb(dev->rx_urb); in free_all_urbs()
352 usb_free_urb(dev->tx_urb); in free_all_urbs()
353 usb_free_urb(dev->intr_urb); in free_all_urbs()
358 usb_kill_urb(dev->rx_urb); in unlink_all_urbs()
359 usb_kill_urb(dev->tx_urb); in unlink_all_urbs()
360 usb_kill_urb(dev->intr_urb); in unlink_all_urbs()
369 if (dev->rx_skb_pool[i]) { in pull_skb()
370 skb = dev->rx_skb_pool[i]; in pull_skb()
371 dev->rx_skb_pool[i] = NULL; in pull_skb()
384 int status = urb->status; in read_bulk_callback()
388 dev = urb->context; in read_bulk_callback()
391 if (test_bit(RTL8150_UNPLUG, &dev->flags)) in read_bulk_callback()
393 netdev = dev->netdev; in read_bulk_callback()
400 case -ENOENT: in read_bulk_callback()
402 case -ETIME: in read_bulk_callback()
404 dev_warn(&urb->dev->dev, "may be reset is needed?..\n"); in read_bulk_callback()
408 dev_warn(&urb->dev->dev, "Rx status %d\n", status); in read_bulk_callback()
412 if (!dev->rx_skb) in read_bulk_callback()
415 if (urb->actual_length < 4) in read_bulk_callback()
418 res = urb->actual_length; in read_bulk_callback()
419 pkt_len = res - 4; in read_bulk_callback()
421 skb_put(dev->rx_skb, pkt_len); in read_bulk_callback()
422 dev->rx_skb->protocol = eth_type_trans(dev->rx_skb, netdev); in read_bulk_callback()
423 netif_rx(dev->rx_skb); in read_bulk_callback()
424 netdev->stats.rx_packets++; in read_bulk_callback()
425 netdev->stats.rx_bytes += pkt_len; in read_bulk_callback()
427 spin_lock_irqsave(&dev->rx_pool_lock, flags); in read_bulk_callback()
429 spin_unlock_irqrestore(&dev->rx_pool_lock, flags); in read_bulk_callback()
433 dev->rx_skb = skb; in read_bulk_callback()
435 usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1), in read_bulk_callback()
436 dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev); in read_bulk_callback()
437 result = usb_submit_urb(dev->rx_urb, GFP_ATOMIC); in read_bulk_callback()
438 if (result == -ENODEV) in read_bulk_callback()
439 netif_device_detach(dev->netdev); in read_bulk_callback()
441 set_bit(RX_URB_FAIL, &dev->flags); in read_bulk_callback()
444 clear_bit(RX_URB_FAIL, &dev->flags); in read_bulk_callback()
449 tasklet_schedule(&dev->tl); in read_bulk_callback()
455 int status = urb->status; in write_bulk_callback()
457 dev = urb->context; in write_bulk_callback()
460 dev_kfree_skb_irq(dev->tx_skb); in write_bulk_callback()
461 if (!netif_device_present(dev->netdev)) in write_bulk_callback()
464 dev_info(&urb->dev->dev, "%s: Tx status %d\n", in write_bulk_callback()
465 dev->netdev->name, status); in write_bulk_callback()
466 netif_trans_update(dev->netdev); in write_bulk_callback()
467 netif_wake_queue(dev->netdev); in write_bulk_callback()
474 int status = urb->status; in intr_callback()
477 dev = urb->context; in intr_callback()
483 case -ECONNRESET: /* unlink */ in intr_callback()
484 case -ENOENT: in intr_callback()
485 case -ESHUTDOWN: in intr_callback()
487 /* -EPIPE: should clear the halt */ in intr_callback()
489 dev_info(&urb->dev->dev, "%s: intr status %d\n", in intr_callback()
490 dev->netdev->name, status); in intr_callback()
494 d = urb->transfer_buffer; in intr_callback()
496 dev->netdev->stats.tx_errors++; in intr_callback()
498 dev->netdev->stats.tx_aborted_errors++; in intr_callback()
500 dev->netdev->stats.tx_window_errors++; in intr_callback()
502 dev->netdev->stats.tx_carrier_errors++; in intr_callback()
506 if (netif_carrier_ok(dev->netdev)) { in intr_callback()
507 netif_carrier_off(dev->netdev); in intr_callback()
508 netdev_dbg(dev->netdev, "%s: LINK LOST\n", __func__); in intr_callback()
511 if (!netif_carrier_ok(dev->netdev)) { in intr_callback()
512 netif_carrier_on(dev->netdev); in intr_callback()
513 netdev_dbg(dev->netdev, "%s: LINK CAME BACK\n", __func__); in intr_callback()
519 if (res == -ENODEV) in intr_callback()
520 netif_device_detach(dev->netdev); in intr_callback()
522 dev_err(&dev->udev->dev, in intr_callback()
523 "can't resubmit intr, %s-%s/input0, status %d\n", in intr_callback()
524 dev->udev->bus->bus_name, dev->udev->devpath, res); in intr_callback()
531 netif_device_detach(dev->netdev); in rtl8150_suspend()
533 if (netif_running(dev->netdev)) { in rtl8150_suspend()
534 usb_kill_urb(dev->rx_urb); in rtl8150_suspend()
535 usb_kill_urb(dev->intr_urb); in rtl8150_suspend()
544 netif_device_attach(dev->netdev); in rtl8150_resume()
545 if (netif_running(dev->netdev)) { in rtl8150_resume()
546 dev->rx_urb->status = 0; in rtl8150_resume()
547 dev->rx_urb->actual_length = 0; in rtl8150_resume()
548 read_bulk_callback(dev->rx_urb); in rtl8150_resume()
550 dev->intr_urb->status = 0; in rtl8150_resume()
551 dev->intr_urb->actual_length = 0; in rtl8150_resume()
552 intr_callback(dev->intr_urb); in rtl8150_resume()
569 if (dev->rx_skb_pool[i]) in fill_skb_pool()
576 dev->rx_skb_pool[i] = skb; in fill_skb_pool()
585 dev_kfree_skb(dev->rx_skb_pool[i]); in free_skb_pool()
594 spin_lock_irq(&dev->rx_pool_lock); in rx_fixup()
596 spin_unlock_irq(&dev->rx_pool_lock); in rx_fixup()
597 if (test_bit(RX_URB_FAIL, &dev->flags)) in rx_fixup()
598 if (dev->rx_skb) in rx_fixup()
600 spin_lock_irq(&dev->rx_pool_lock); in rx_fixup()
602 spin_unlock_irq(&dev->rx_pool_lock); in rx_fixup()
605 dev->rx_skb = skb; in rx_fixup()
606 usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1), in rx_fixup()
607 dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev); in rx_fixup()
609 status = usb_submit_urb(dev->rx_urb, GFP_ATOMIC); in rx_fixup()
610 if (status == -ENODEV) { in rx_fixup()
611 netif_device_detach(dev->netdev); in rx_fixup()
613 set_bit(RX_URB_FAIL, &dev->flags); in rx_fixup()
616 clear_bit(RX_URB_FAIL, &dev->flags); in rx_fixup()
621 tasklet_schedule(&dev->tl); in rx_fixup()
629 dev_warn(&dev->udev->dev, "device reset failed\n"); in enable_net_traffic()
636 set_bit(RTL8150_HW_CRC, &dev->flags); in enable_net_traffic()
657 dev_warn(&netdev->dev, "Tx timeout.\n"); in rtl8150_tx_timeout()
658 usb_unlink_urb(dev->tx_urb); in rtl8150_tx_timeout()
659 netdev->stats.tx_errors++; in rtl8150_tx_timeout()
668 if (netdev->flags & IFF_PROMISC) { in rtl8150_set_multicast()
670 dev_info(&netdev->dev, "%s: promiscuous mode\n", netdev->name); in rtl8150_set_multicast()
672 (netdev->flags & IFF_ALLMULTI)) { in rtl8150_set_multicast()
675 dev_dbg(&netdev->dev, "%s: allmulti set\n", netdev->name); in rtl8150_set_multicast()
691 count = (skb->len < 60) ? 60 : skb->len; in rtl8150_start_xmit()
693 dev->tx_skb = skb; in rtl8150_start_xmit()
694 usb_fill_bulk_urb(dev->tx_urb, dev->udev, usb_sndbulkpipe(dev->udev, 2), in rtl8150_start_xmit()
695 skb->data, count, write_bulk_callback, dev); in rtl8150_start_xmit()
696 if ((res = usb_submit_urb(dev->tx_urb, GFP_ATOMIC))) { in rtl8150_start_xmit()
698 if (res == -ENODEV) in rtl8150_start_xmit()
699 netif_device_detach(dev->netdev); in rtl8150_start_xmit()
701 dev_warn(&netdev->dev, "failed tx_urb %d\n", res); in rtl8150_start_xmit()
702 netdev->stats.tx_errors++; in rtl8150_start_xmit()
706 netdev->stats.tx_packets++; in rtl8150_start_xmit()
707 netdev->stats.tx_bytes += skb->len; in rtl8150_start_xmit()
732 if (dev->rx_skb == NULL) in rtl8150_open()
733 dev->rx_skb = pull_skb(dev); in rtl8150_open()
734 if (!dev->rx_skb) in rtl8150_open()
735 return -ENOMEM; in rtl8150_open()
737 set_registers(dev, IDR, 6, netdev->dev_addr); in rtl8150_open()
739 usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1), in rtl8150_open()
740 dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev); in rtl8150_open()
741 if ((res = usb_submit_urb(dev->rx_urb, GFP_KERNEL))) { in rtl8150_open()
742 if (res == -ENODEV) in rtl8150_open()
743 netif_device_detach(dev->netdev); in rtl8150_open()
744 dev_warn(&netdev->dev, "rx_urb submit failed: %d\n", res); in rtl8150_open()
747 usb_fill_int_urb(dev->intr_urb, dev->udev, usb_rcvintpipe(dev->udev, 3), in rtl8150_open()
748 dev->intr_buff, INTBUFSIZE, intr_callback, in rtl8150_open()
749 dev, dev->intr_interval); in rtl8150_open()
750 if ((res = usb_submit_urb(dev->intr_urb, GFP_KERNEL))) { in rtl8150_open()
751 if (res == -ENODEV) in rtl8150_open()
752 netif_device_detach(dev->netdev); in rtl8150_open()
753 dev_warn(&netdev->dev, "intr_urb submit failed: %d\n", res); in rtl8150_open()
754 usb_kill_urb(dev->rx_urb); in rtl8150_open()
769 if (!test_bit(RTL8150_UNPLUG, &dev->flags)) in rtl8150_close()
780 strscpy(info->driver, driver_name, sizeof(info->driver)); in rtl8150_get_drvinfo()
781 strscpy(info->version, DRIVER_VERSION, sizeof(info->version)); in rtl8150_get_drvinfo()
782 usb_make_path(dev->udev, info->bus_info, sizeof(info->bus_info)); in rtl8150_get_drvinfo()
789 short lpa = 0; in rtl8150_get_link_ksettings() local
799 ecmd->base.port = PORT_TP; in rtl8150_get_link_ksettings()
800 ecmd->base.phy_address = dev->phy; in rtl8150_get_link_ksettings()
802 get_registers(dev, ANLP, 2, &lpa); in rtl8150_get_link_ksettings()
804 u32 speed = ((lpa & (LPA_100HALF | LPA_100FULL)) ? in rtl8150_get_link_ksettings()
806 ecmd->base.speed = speed; in rtl8150_get_link_ksettings()
807 ecmd->base.autoneg = AUTONEG_ENABLE; in rtl8150_get_link_ksettings()
809 ecmd->base.duplex = (lpa & LPA_100FULL) ? in rtl8150_get_link_ksettings()
812 ecmd->base.duplex = (lpa & LPA_10FULL) ? in rtl8150_get_link_ksettings()
815 ecmd->base.autoneg = AUTONEG_DISABLE; in rtl8150_get_link_ksettings()
816 ecmd->base.speed = ((bmcr & BMCR_SPEED100) ? in rtl8150_get_link_ksettings()
818 ecmd->base.duplex = (bmcr & BMCR_FULLDPLX) ? in rtl8150_get_link_ksettings()
822 ethtool_convert_legacy_u32_to_link_mode(ecmd->link_modes.supported, in rtl8150_get_link_ksettings()
838 u16 *data = (u16 *) & rq->ifr_ifru; in rtl8150_siocdevprivate()
843 data[0] = dev->phy; in rtl8150_siocdevprivate()
846 read_mii_word(dev, dev->phy, (data[1] & 0x1f), &data[3]); in rtl8150_siocdevprivate()
850 return -EPERM; in rtl8150_siocdevprivate()
851 write_mii_word(dev, dev->phy, (data[1] & 0x1f), data[2]); in rtl8150_siocdevprivate()
854 res = -EOPNOTSUPP; in rtl8150_siocdevprivate()
888 return -ENOMEM; in rtl8150_probe()
892 dev->intr_buff = kmalloc(INTBUFSIZE, GFP_KERNEL); in rtl8150_probe()
893 if (!dev->intr_buff) { in rtl8150_probe()
895 return -ENOMEM; in rtl8150_probe()
901 dev_err(&intf->dev, "couldn't find required endpoints\n"); in rtl8150_probe()
905 tasklet_setup(&dev->tl, rx_fixup); in rtl8150_probe()
906 spin_lock_init(&dev->rx_pool_lock); in rtl8150_probe()
908 dev->udev = udev; in rtl8150_probe()
909 dev->netdev = netdev; in rtl8150_probe()
910 netdev->netdev_ops = &rtl8150_netdev_ops; in rtl8150_probe()
911 netdev->watchdog_timeo = RTL8150_TX_TIMEOUT; in rtl8150_probe()
912 netdev->ethtool_ops = &ops; in rtl8150_probe()
913 dev->intr_interval = 100; /* 100ms */ in rtl8150_probe()
916 dev_err(&intf->dev, "out of memory\n"); in rtl8150_probe()
920 dev_err(&intf->dev, "couldn't reset the device\n"); in rtl8150_probe()
927 SET_NETDEV_DEV(netdev, &intf->dev); in rtl8150_probe()
929 dev_err(&intf->dev, "couldn't register the device\n"); in rtl8150_probe()
933 dev_info(&intf->dev, "%s: rtl8150 is detected\n", netdev->name); in rtl8150_probe()
943 kfree(dev->intr_buff); in rtl8150_probe()
945 return -EIO; in rtl8150_probe()
954 set_bit(RTL8150_UNPLUG, &dev->flags); in rtl8150_disconnect()
955 tasklet_kill(&dev->tl); in rtl8150_disconnect()
956 unregister_netdev(dev->netdev); in rtl8150_disconnect()
960 dev_kfree_skb(dev->rx_skb); in rtl8150_disconnect()
961 kfree(dev->intr_buff); in rtl8150_disconnect()
962 free_netdev(dev->netdev); in rtl8150_disconnect()