Lines Matching +full:ld +full:- +full:pulse +full:- +full:delay +full:- +full:us

1 // SPDX-License-Identifier: GPL-2.0-only
30 /* Information for net-next */
487 #define LPM_TIMER_500US 0x0c /* 500 us */
669 #define RTL8153_MAX_MTU (RTL8153_MAX_PACKET - VLAN_ETH_HLEN - \
873 * struct fw_block - block type and total length
884 * struct fw_header - header of the firmware file
898 * struct fw_mac - a firmware block used by RTL_FW_PLA and RTL_FW_USB.
937 * struct fw_phy_patch_key - a firmware block used by RTL_FW_PHY_START.
950 * struct fw_phy_nc - a firmware block used by RTL_FW_PHY_NC.
1024 /* Maximum number of multicast addresses to filter (vs. Rx-all-multicast).
1030 #define RTL_LIMITED_TSO_SIZE (agg_buf_sz - sizeof(struct tx_desc) - \
1031 VLAN_ETH_HLEN - ETH_FCS_LEN)
1041 return -ENOMEM; in get_registers()
1043 ret = usb_control_msg(tp->udev, usb_rcvctrlpipe(tp->udev, 0), in get_registers()
1064 return -ENOMEM; in set_registers()
1066 ret = usb_control_msg(tp->udev, usb_sndctrlpipe(tp->udev, 0), in set_registers()
1077 if (tp->udev->state == USB_STATE_NOTATTACHED) { in rtl_set_unplug()
1078 set_bit(RTL8152_UNPLUG, &tp->flags); in rtl_set_unplug()
1089 if (test_bit(RTL8152_UNPLUG, &tp->flags)) in generic_ocp_read()
1090 return -ENODEV; in generic_ocp_read()
1094 return -EPERM; in generic_ocp_read()
1097 return -EPERM; in generic_ocp_read()
1107 size -= limit; in generic_ocp_read()
1120 if (ret == -ENODEV) in generic_ocp_read()
1133 if (test_bit(RTL8152_UNPLUG, &tp->flags)) in generic_ocp_write()
1134 return -ENODEV; in generic_ocp_write()
1138 return -EPERM; in generic_ocp_write()
1141 return -EPERM; in generic_ocp_write()
1153 size -= 4; in generic_ocp_write()
1156 size -= 4; in generic_ocp_write()
1168 size -= limit; in generic_ocp_write()
1190 if (ret == -ENODEV) in generic_ocp_write()
1313 if (ocp_base != tp->ocp_base) { in ocp_reg_read()
1315 tp->ocp_base = ocp_base; in ocp_reg_read()
1327 if (ocp_base != tp->ocp_base) { in ocp_reg_write()
1329 tp->ocp_base = ocp_base; in ocp_reg_write()
1363 if (test_bit(RTL8152_UNPLUG, &tp->flags)) in read_mii_word()
1364 return -ENODEV; in read_mii_word()
1367 return -EINVAL; in read_mii_word()
1379 if (test_bit(RTL8152_UNPLUG, &tp->flags)) in write_mii_word()
1395 int ret = -EADDRNOTAVAIL; in rtl8152_set_mac_address()
1397 if (!is_valid_ether_addr(addr->sa_data)) in rtl8152_set_mac_address()
1400 ret = usb_autopm_get_interface(tp->intf); in rtl8152_set_mac_address()
1404 mutex_lock(&tp->control); in rtl8152_set_mac_address()
1406 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); in rtl8152_set_mac_address()
1409 pla_ocp_write(tp, PLA_IDR, BYTE_EN_SIX_BYTES, 8, addr->sa_data); in rtl8152_set_mac_address()
1412 mutex_unlock(&tp->control); in rtl8152_set_mac_address()
1414 usb_autopm_put_interface(tp->intf); in rtl8152_set_mac_address()
1428 int ret = -EINVAL; in vendor_mac_passthru_addr_read()
1435 if (test_bit(LENOVO_MACPASSTHRU, &tp->flags)) { in vendor_mac_passthru_addr_read()
1440 /* test for -AD variant of RTL8153 */ in vendor_mac_passthru_addr_read()
1443 /* test for MAC address pass-through bit */ in vendor_mac_passthru_addr_read()
1446 netif_dbg(tp, probe, tp->netdev, in vendor_mac_passthru_addr_read()
1447 "No efuse for RTL8153-AD MAC pass through\n"); in vendor_mac_passthru_addr_read()
1448 return -ENODEV; in vendor_mac_passthru_addr_read()
1451 /* test for RTL8153-BND and RTL8153-BD */ in vendor_mac_passthru_addr_read()
1454 netif_dbg(tp, probe, tp->netdev, in vendor_mac_passthru_addr_read()
1456 return -ENODEV; in vendor_mac_passthru_addr_read()
1469 return -ENODEV; in vendor_mac_passthru_addr_read()
1470 if (obj->type != mac_obj_type || obj->string.length != mac_strlen) { in vendor_mac_passthru_addr_read()
1471 netif_warn(tp, probe, tp->netdev, in vendor_mac_passthru_addr_read()
1472 "Invalid buffer for pass-thru MAC addr: (%d, %d)\n", in vendor_mac_passthru_addr_read()
1473 obj->type, obj->string.length); in vendor_mac_passthru_addr_read()
1477 if (strncmp(obj->string.pointer, "_AUXMAC_#", 9) != 0 || in vendor_mac_passthru_addr_read()
1478 strncmp(obj->string.pointer + 0x15, "#", 1) != 0) { in vendor_mac_passthru_addr_read()
1479 netif_warn(tp, probe, tp->netdev, in vendor_mac_passthru_addr_read()
1480 "Invalid header when reading pass-thru MAC addr\n"); in vendor_mac_passthru_addr_read()
1483 ret = hex2bin(buf, obj->string.pointer + 9, 6); in vendor_mac_passthru_addr_read()
1485 netif_warn(tp, probe, tp->netdev, in vendor_mac_passthru_addr_read()
1486 "Invalid MAC for pass-thru MAC addr: %d, %pM\n", in vendor_mac_passthru_addr_read()
1488 ret = -EINVAL; in vendor_mac_passthru_addr_read()
1491 memcpy(sa->sa_data, buf, 6); in vendor_mac_passthru_addr_read()
1492 netif_info(tp, probe, tp->netdev, in vendor_mac_passthru_addr_read()
1493 "Using pass-thru MAC addr %pM\n", sa->sa_data); in vendor_mac_passthru_addr_read()
1502 struct net_device *dev = tp->netdev; in determine_ethernet_addr()
1505 sa->sa_family = dev->type; in determine_ethernet_addr()
1507 ret = eth_platform_get_mac_address(&tp->udev->dev, sa->sa_data); in determine_ethernet_addr()
1509 if (tp->version == RTL_VER_01) { in determine_ethernet_addr()
1510 ret = pla_ocp_read(tp, PLA_IDR, 8, sa->sa_data); in determine_ethernet_addr()
1513 * be expected to be non-zero in determine_ethernet_addr()
1518 sa->sa_data); in determine_ethernet_addr()
1524 } else if (!is_valid_ether_addr(sa->sa_data)) { in determine_ethernet_addr()
1526 sa->sa_data); in determine_ethernet_addr()
1528 ether_addr_copy(sa->sa_data, dev->dev_addr); in determine_ethernet_addr()
1530 sa->sa_data); in determine_ethernet_addr()
1539 struct net_device *dev = tp->netdev; in set_ethernet_addr()
1547 if (tp->version == RTL_VER_01) in set_ethernet_addr()
1548 ether_addr_copy(dev->dev_addr, sa.sa_data); in set_ethernet_addr()
1558 int status = urb->status; in read_bulk_callback()
1563 agg = urb->context; in read_bulk_callback()
1567 tp = agg->context; in read_bulk_callback()
1571 if (test_bit(RTL8152_UNPLUG, &tp->flags)) in read_bulk_callback()
1574 if (!test_bit(WORK_ENABLE, &tp->flags)) in read_bulk_callback()
1577 netdev = tp->netdev; in read_bulk_callback()
1580 /* This avoid the re-submitting bulk */ in read_bulk_callback()
1584 usb_mark_last_busy(tp->udev); in read_bulk_callback()
1588 if (urb->actual_length < ETH_ZLEN) in read_bulk_callback()
1591 spin_lock_irqsave(&tp->rx_lock, flags); in read_bulk_callback()
1592 list_add_tail(&agg->list, &tp->rx_done); in read_bulk_callback()
1593 spin_unlock_irqrestore(&tp->rx_lock, flags); in read_bulk_callback()
1594 napi_schedule(&tp->napi); in read_bulk_callback()
1596 case -ESHUTDOWN: in read_bulk_callback()
1598 netif_device_detach(tp->netdev); in read_bulk_callback()
1600 case -ENOENT: in read_bulk_callback()
1602 case -ETIME: in read_bulk_callback()
1622 int status = urb->status; in write_bulk_callback()
1624 agg = urb->context; in write_bulk_callback()
1628 tp = agg->context; in write_bulk_callback()
1632 netdev = tp->netdev; in write_bulk_callback()
1633 stats = &netdev->stats; in write_bulk_callback()
1637 stats->tx_errors += agg->skb_num; in write_bulk_callback()
1639 stats->tx_packets += agg->skb_num; in write_bulk_callback()
1640 stats->tx_bytes += agg->skb_len; in write_bulk_callback()
1643 spin_lock_irqsave(&tp->tx_lock, flags); in write_bulk_callback()
1644 list_add_tail(&agg->list, &tp->tx_free); in write_bulk_callback()
1645 spin_unlock_irqrestore(&tp->tx_lock, flags); in write_bulk_callback()
1647 usb_autopm_put_interface_async(tp->intf); in write_bulk_callback()
1652 if (!test_bit(WORK_ENABLE, &tp->flags)) in write_bulk_callback()
1655 if (test_bit(RTL8152_UNPLUG, &tp->flags)) in write_bulk_callback()
1658 if (!skb_queue_empty(&tp->tx_queue)) in write_bulk_callback()
1659 tasklet_schedule(&tp->tx_tl); in write_bulk_callback()
1666 int status = urb->status; in intr_callback()
1669 tp = urb->context; in intr_callback()
1673 if (!test_bit(WORK_ENABLE, &tp->flags)) in intr_callback()
1676 if (test_bit(RTL8152_UNPLUG, &tp->flags)) in intr_callback()
1682 case -ECONNRESET: /* unlink */ in intr_callback()
1683 case -ESHUTDOWN: in intr_callback()
1684 netif_device_detach(tp->netdev); in intr_callback()
1686 case -ENOENT: in intr_callback()
1687 case -EPROTO: in intr_callback()
1688 netif_info(tp, intr, tp->netdev, in intr_callback()
1691 case -EOVERFLOW: in intr_callback()
1692 netif_info(tp, intr, tp->netdev, "intr status -EOVERFLOW\n"); in intr_callback()
1694 /* -EPIPE: should clear the halt */ in intr_callback()
1696 netif_info(tp, intr, tp->netdev, "intr status %d\n", status); in intr_callback()
1700 d = urb->transfer_buffer; in intr_callback()
1702 if (!netif_carrier_ok(tp->netdev)) { in intr_callback()
1703 set_bit(RTL8152_LINK_CHG, &tp->flags); in intr_callback()
1704 schedule_delayed_work(&tp->schedule, 0); in intr_callback()
1707 if (netif_carrier_ok(tp->netdev)) { in intr_callback()
1708 netif_stop_queue(tp->netdev); in intr_callback()
1709 set_bit(RTL8152_LINK_CHG, &tp->flags); in intr_callback()
1710 schedule_delayed_work(&tp->schedule, 0); in intr_callback()
1716 if (res == -ENODEV) { in intr_callback()
1718 netif_device_detach(tp->netdev); in intr_callback()
1720 netif_err(tp, intr, tp->netdev, in intr_callback()
1737 list_del(&agg->info_list); in free_rx_agg()
1739 usb_free_urb(agg->urb); in free_rx_agg()
1740 put_page(agg->page); in free_rx_agg()
1743 atomic_dec(&tp->rx_count); in free_rx_agg()
1748 struct net_device *netdev = tp->netdev; in alloc_rx_agg()
1749 int node = netdev->dev.parent ? dev_to_node(netdev->dev.parent) : -1; in alloc_rx_agg()
1750 unsigned int order = get_order(tp->rx_buf_sz); in alloc_rx_agg()
1758 rx_agg->page = alloc_pages(mflags | __GFP_COMP, order); in alloc_rx_agg()
1759 if (!rx_agg->page) in alloc_rx_agg()
1762 rx_agg->buffer = page_address(rx_agg->page); in alloc_rx_agg()
1764 rx_agg->urb = usb_alloc_urb(0, mflags); in alloc_rx_agg()
1765 if (!rx_agg->urb) in alloc_rx_agg()
1768 rx_agg->context = tp; in alloc_rx_agg()
1770 INIT_LIST_HEAD(&rx_agg->list); in alloc_rx_agg()
1771 INIT_LIST_HEAD(&rx_agg->info_list); in alloc_rx_agg()
1772 spin_lock_irqsave(&tp->rx_lock, flags); in alloc_rx_agg()
1773 list_add_tail(&rx_agg->info_list, &tp->rx_info); in alloc_rx_agg()
1774 spin_unlock_irqrestore(&tp->rx_lock, flags); in alloc_rx_agg()
1776 atomic_inc(&tp->rx_count); in alloc_rx_agg()
1781 __free_pages(rx_agg->page, order); in alloc_rx_agg()
1793 spin_lock_irqsave(&tp->rx_lock, flags); in free_all_mem()
1795 list_for_each_entry_safe(agg, agg_next, &tp->rx_info, info_list) in free_all_mem()
1798 spin_unlock_irqrestore(&tp->rx_lock, flags); in free_all_mem()
1800 WARN_ON(atomic_read(&tp->rx_count)); in free_all_mem()
1803 usb_free_urb(tp->tx_info[i].urb); in free_all_mem()
1804 tp->tx_info[i].urb = NULL; in free_all_mem()
1806 kfree(tp->tx_info[i].buffer); in free_all_mem()
1807 tp->tx_info[i].buffer = NULL; in free_all_mem()
1808 tp->tx_info[i].head = NULL; in free_all_mem()
1811 usb_free_urb(tp->intr_urb); in free_all_mem()
1812 tp->intr_urb = NULL; in free_all_mem()
1814 kfree(tp->intr_buff); in free_all_mem()
1815 tp->intr_buff = NULL; in free_all_mem()
1820 struct net_device *netdev = tp->netdev; in alloc_all_mem()
1821 struct usb_interface *intf = tp->intf; in alloc_all_mem()
1822 struct usb_host_interface *alt = intf->cur_altsetting; in alloc_all_mem()
1823 struct usb_host_endpoint *ep_intr = alt->endpoint + 2; in alloc_all_mem()
1826 node = netdev->dev.parent ? dev_to_node(netdev->dev.parent) : -1; in alloc_all_mem()
1828 spin_lock_init(&tp->rx_lock); in alloc_all_mem()
1829 spin_lock_init(&tp->tx_lock); in alloc_all_mem()
1830 INIT_LIST_HEAD(&tp->rx_info); in alloc_all_mem()
1831 INIT_LIST_HEAD(&tp->tx_free); in alloc_all_mem()
1832 INIT_LIST_HEAD(&tp->rx_done); in alloc_all_mem()
1833 skb_queue_head_init(&tp->tx_queue); in alloc_all_mem()
1834 skb_queue_head_init(&tp->rx_queue); in alloc_all_mem()
1835 atomic_set(&tp->rx_count, 0); in alloc_all_mem()
1864 INIT_LIST_HEAD(&tp->tx_info[i].list); in alloc_all_mem()
1865 tp->tx_info[i].context = tp; in alloc_all_mem()
1866 tp->tx_info[i].urb = urb; in alloc_all_mem()
1867 tp->tx_info[i].buffer = buf; in alloc_all_mem()
1868 tp->tx_info[i].head = tx_agg_align(buf); in alloc_all_mem()
1870 list_add_tail(&tp->tx_info[i].list, &tp->tx_free); in alloc_all_mem()
1873 tp->intr_urb = usb_alloc_urb(0, GFP_KERNEL); in alloc_all_mem()
1874 if (!tp->intr_urb) in alloc_all_mem()
1877 tp->intr_buff = kmalloc(INTBUFSIZE, GFP_KERNEL); in alloc_all_mem()
1878 if (!tp->intr_buff) in alloc_all_mem()
1881 tp->intr_interval = (int)ep_intr->desc.bInterval; in alloc_all_mem()
1882 usb_fill_int_urb(tp->intr_urb, tp->udev, usb_rcvintpipe(tp->udev, 3), in alloc_all_mem()
1883 tp->intr_buff, INTBUFSIZE, intr_callback, in alloc_all_mem()
1884 tp, tp->intr_interval); in alloc_all_mem()
1890 return -ENOMEM; in alloc_all_mem()
1898 if (list_empty(&tp->tx_free)) in r8152_get_tx_agg()
1901 spin_lock_irqsave(&tp->tx_lock, flags); in r8152_get_tx_agg()
1902 if (!list_empty(&tp->tx_free)) { in r8152_get_tx_agg()
1905 cursor = tp->tx_free.next; in r8152_get_tx_agg()
1909 spin_unlock_irqrestore(&tp->tx_lock, flags); in r8152_get_tx_agg()
1921 if (skb_shinfo(skb)->gso_size) { in r8152_csum_workaround()
1922 netdev_features_t features = tp->netdev->features; in r8152_csum_workaround()
1940 } else if (skb->ip_summed == CHECKSUM_PARTIAL) { in r8152_csum_workaround()
1949 stats = &tp->netdev->stats; in r8152_csum_workaround()
1950 stats->tx_dropped++; in r8152_csum_workaround()
1961 desc->opts2 |= cpu_to_le32(opts2); in rtl_tx_vlan_tag()
1967 u32 opts2 = le32_to_cpu(desc->opts2); in rtl_rx_vlan_tag()
1977 u32 mss = skb_shinfo(skb)->gso_size; in r8152_tx_csum()
1987 netif_warn(tp, tx_err, tp->netdev, in r8152_tx_csum()
2015 } else if (skb->ip_summed == CHECKSUM_PARTIAL) { in r8152_tx_csum()
2019 netif_warn(tp, tx_err, tp->netdev, in r8152_tx_csum()
2029 ip_protocol = ip_hdr(skb)->protocol; in r8152_tx_csum()
2034 ip_protocol = ipv6_hdr(skb)->nexthdr; in r8152_tx_csum()
2052 desc->opts2 = cpu_to_le32(opts2); in r8152_tx_csum()
2053 desc->opts1 = cpu_to_le32(opts1); in r8152_tx_csum()
2061 struct sk_buff_head skb_head, *tx_queue = &tp->tx_queue; in r8152_tx_agg_fill()
2066 spin_lock(&tx_queue->lock); in r8152_tx_agg_fill()
2068 spin_unlock(&tx_queue->lock); in r8152_tx_agg_fill()
2070 tx_data = agg->head; in r8152_tx_agg_fill()
2071 agg->skb_num = 0; in r8152_tx_agg_fill()
2072 agg->skb_len = 0; in r8152_tx_agg_fill()
2085 len = skb->len + sizeof(*tx_desc); in r8152_tx_agg_fill()
2097 if (r8152_tx_csum(tp, tx_desc, skb, skb->len, offset)) { in r8152_tx_agg_fill()
2106 len = skb->len; in r8152_tx_agg_fill()
2108 struct net_device_stats *stats = &tp->netdev->stats; in r8152_tx_agg_fill()
2110 stats->tx_dropped++; in r8152_tx_agg_fill()
2112 tx_data -= sizeof(*tx_desc); in r8152_tx_agg_fill()
2117 agg->skb_len += len; in r8152_tx_agg_fill()
2118 agg->skb_num += skb_shinfo(skb)->gso_segs ?: 1; in r8152_tx_agg_fill()
2122 remain = agg_buf_sz - (int)(tx_agg_align(tx_data) - agg->head); in r8152_tx_agg_fill()
2124 if (test_bit(DELL_TB_RX_AGG_BUG, &tp->flags)) in r8152_tx_agg_fill()
2129 spin_lock(&tx_queue->lock); in r8152_tx_agg_fill()
2131 spin_unlock(&tx_queue->lock); in r8152_tx_agg_fill()
2134 netif_tx_lock(tp->netdev); in r8152_tx_agg_fill()
2136 if (netif_queue_stopped(tp->netdev) && in r8152_tx_agg_fill()
2137 skb_queue_len(&tp->tx_queue) < tp->tx_qlen) in r8152_tx_agg_fill()
2138 netif_wake_queue(tp->netdev); in r8152_tx_agg_fill()
2140 netif_tx_unlock(tp->netdev); in r8152_tx_agg_fill()
2142 ret = usb_autopm_get_interface_async(tp->intf); in r8152_tx_agg_fill()
2146 usb_fill_bulk_urb(agg->urb, tp->udev, usb_sndbulkpipe(tp->udev, 2), in r8152_tx_agg_fill()
2147 agg->head, (int)(tx_data - (u8 *)agg->head), in r8152_tx_agg_fill()
2150 ret = usb_submit_urb(agg->urb, GFP_ATOMIC); in r8152_tx_agg_fill()
2152 usb_autopm_put_interface_async(tp->intf); in r8152_tx_agg_fill()
2163 if (!(tp->netdev->features & NETIF_F_RXCSUM)) in r8152_rx_csum()
2166 opts2 = le32_to_cpu(rx_desc->opts2); in r8152_rx_csum()
2167 opts3 = le32_to_cpu(rx_desc->opts3); in r8152_rx_csum()
2189 return atomic_read(&tp->rx_count) > RTL8152_MAX_RX; in rx_count_exceed()
2194 return (int)(addr - agg->buffer); in agg_offset()
2202 spin_lock_irqsave(&tp->rx_lock, flags); in rtl_get_free_rx()
2204 list_for_each_entry_safe(agg, agg_next, &tp->rx_used, list) { in rtl_get_free_rx()
2205 if (page_count(agg->page) == 1) { in rtl_get_free_rx()
2207 list_del_init(&agg->list); in rtl_get_free_rx()
2212 list_del_init(&agg->list); in rtl_get_free_rx()
2219 spin_unlock_irqrestore(&tp->rx_lock, flags); in rtl_get_free_rx()
2221 if (!agg_free && atomic_read(&tp->rx_count) < tp->rx_pending) in rtl_get_free_rx()
2232 struct napi_struct *napi = &tp->napi; in rx_bottom()
2234 if (!skb_queue_empty(&tp->rx_queue)) { in rx_bottom()
2236 struct sk_buff *skb = __skb_dequeue(&tp->rx_queue); in rx_bottom()
2237 struct net_device *netdev = tp->netdev; in rx_bottom()
2238 struct net_device_stats *stats = &netdev->stats; in rx_bottom()
2244 pkt_len = skb->len; in rx_bottom()
2247 stats->rx_packets++; in rx_bottom()
2248 stats->rx_bytes += pkt_len; in rx_bottom()
2252 if (list_empty(&tp->rx_done)) in rx_bottom()
2256 spin_lock_irqsave(&tp->rx_lock, flags); in rx_bottom()
2257 list_splice_init(&tp->rx_done, &rx_queue); in rx_bottom()
2258 spin_unlock_irqrestore(&tp->rx_lock, flags); in rx_bottom()
2270 urb = agg->urb; in rx_bottom()
2271 if (urb->actual_length < ETH_ZLEN) in rx_bottom()
2276 rx_desc = agg->buffer; in rx_bottom()
2277 rx_data = agg->buffer; in rx_bottom()
2280 while (urb->actual_length > len_used) { in rx_bottom()
2281 struct net_device *netdev = tp->netdev; in rx_bottom()
2282 struct net_device_stats *stats = &netdev->stats; in rx_bottom()
2287 if (unlikely(skb_queue_len(&tp->rx_queue) >= 1000)) in rx_bottom()
2290 pkt_len = le32_to_cpu(rx_desc->opts1) & RX_LEN_MASK; in rx_bottom()
2295 if (urb->actual_length < len_used) in rx_bottom()
2298 pkt_len -= ETH_FCS_LEN; in rx_bottom()
2301 if (!agg_free || tp->rx_copybreak > pkt_len) in rx_bottom()
2304 rx_frag_head_sz = tp->rx_copybreak; in rx_bottom()
2308 stats->rx_dropped++; in rx_bottom()
2312 skb->ip_summed = r8152_rx_csum(tp, rx_desc); in rx_bottom()
2313 memcpy(skb->data, rx_data, rx_frag_head_sz); in rx_bottom()
2315 pkt_len -= rx_frag_head_sz; in rx_bottom()
2318 skb_add_rx_frag(skb, 0, agg->page, in rx_bottom()
2322 get_page(agg->page); in rx_bottom()
2325 skb->protocol = eth_type_trans(skb, netdev); in rx_bottom()
2329 stats->rx_packets++; in rx_bottom()
2330 stats->rx_bytes += skb->len; in rx_bottom()
2333 __skb_queue_tail(&tp->rx_queue, skb); in rx_bottom()
2343 WARN_ON(!agg_free && page_count(agg->page) > 1); in rx_bottom()
2346 spin_lock_irqsave(&tp->rx_lock, flags); in rx_bottom()
2347 if (page_count(agg->page) == 1) { in rx_bottom()
2348 list_add(&agg_free->list, &tp->rx_used); in rx_bottom()
2350 list_add_tail(&agg->list, &tp->rx_used); in rx_bottom()
2352 urb = agg->urb; in rx_bottom()
2354 spin_unlock_irqrestore(&tp->rx_lock, flags); in rx_bottom()
2361 urb->actual_length = 0; in rx_bottom()
2362 list_add_tail(&agg->list, next); in rx_bottom()
2367 spin_lock_irqsave(&tp->rx_lock, flags); in rx_bottom()
2368 list_splice_tail(&rx_queue, &tp->rx_done); in rx_bottom()
2369 spin_unlock_irqrestore(&tp->rx_lock, flags); in rx_bottom()
2381 struct net_device *netdev = tp->netdev; in tx_bottom()
2384 if (skb_queue_empty(&tp->tx_queue)) in tx_bottom()
2395 if (res == -ENODEV) { in tx_bottom()
2399 struct net_device_stats *stats = &netdev->stats; in tx_bottom()
2404 stats->tx_dropped += agg->skb_num; in tx_bottom()
2406 spin_lock_irqsave(&tp->tx_lock, flags); in tx_bottom()
2407 list_add_tail(&agg->list, &tp->tx_free); in tx_bottom()
2408 spin_unlock_irqrestore(&tp->tx_lock, flags); in tx_bottom()
2419 if (test_bit(RTL8152_UNPLUG, &tp->flags)) in bottom_half()
2422 if (!test_bit(WORK_ENABLE, &tp->flags)) in bottom_half()
2426 /* This avoid the re-submitting bulk */ in bottom_half()
2427 if (!netif_carrier_ok(tp->netdev)) in bottom_half()
2430 clear_bit(SCHEDULE_TASKLET, &tp->flags); in bottom_half()
2445 if (!list_empty(&tp->rx_done)) in r8152_poll()
2459 if (test_bit(RTL8152_UNPLUG, &tp->flags) || in r8152_submit_rx()
2460 !test_bit(WORK_ENABLE, &tp->flags) || !netif_carrier_ok(tp->netdev)) in r8152_submit_rx()
2463 usb_fill_bulk_urb(agg->urb, tp->udev, usb_rcvbulkpipe(tp->udev, 1), in r8152_submit_rx()
2464 agg->buffer, tp->rx_buf_sz, in r8152_submit_rx()
2467 ret = usb_submit_urb(agg->urb, mem_flags); in r8152_submit_rx()
2468 if (ret == -ENODEV) { in r8152_submit_rx()
2470 netif_device_detach(tp->netdev); in r8152_submit_rx()
2472 struct urb *urb = agg->urb; in r8152_submit_rx()
2475 urb->actual_length = 0; in r8152_submit_rx()
2476 spin_lock_irqsave(&tp->rx_lock, flags); in r8152_submit_rx()
2477 list_add_tail(&agg->list, &tp->rx_done); in r8152_submit_rx()
2478 spin_unlock_irqrestore(&tp->rx_lock, flags); in r8152_submit_rx()
2480 netif_err(tp, rx_err, tp->netdev, in r8152_submit_rx()
2483 napi_schedule(&tp->napi); in r8152_submit_rx()
2491 struct net_device_stats *stats = &tp->netdev->stats; in rtl_drop_queued_tx()
2492 struct sk_buff_head skb_head, *tx_queue = &tp->tx_queue; in rtl_drop_queued_tx()
2499 spin_lock_bh(&tx_queue->lock); in rtl_drop_queued_tx()
2501 spin_unlock_bh(&tx_queue->lock); in rtl_drop_queued_tx()
2505 stats->tx_dropped++; in rtl_drop_queued_tx()
2515 usb_queue_reset_device(tp->intf); in rtl8152_tx_timeout()
2523 set_bit(RTL8152_SET_RX_MODE, &tp->flags); in rtl8152_set_rx_mode()
2524 schedule_delayed_work(&tp->schedule, 0); in rtl8152_set_rx_mode()
2540 if (netdev->flags & IFF_PROMISC) { in _rtl8152_set_rx_mode()
2547 (netdev->flags & IFF_ALLMULTI)) { in _rtl8152_set_rx_mode()
2548 /* Too many to filter perfectly -- accept all multicasts. */ in _rtl8152_set_rx_mode()
2558 int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26; in _rtl8152_set_rx_mode()
2577 u32 mss = skb_shinfo(skb)->gso_size; in rtl8152_features_check()
2581 if ((mss || skb->ip_summed == CHECKSUM_PARTIAL) && offset > max_offset) in rtl8152_features_check()
2583 else if ((skb->len + sizeof(struct tx_desc)) > agg_buf_sz) in rtl8152_features_check()
2596 skb_queue_tail(&tp->tx_queue, skb); in rtl8152_start_xmit()
2598 if (!list_empty(&tp->tx_free)) { in rtl8152_start_xmit()
2599 if (test_bit(SELECTIVE_SUSPEND, &tp->flags)) { in rtl8152_start_xmit()
2600 set_bit(SCHEDULE_TASKLET, &tp->flags); in rtl8152_start_xmit()
2601 schedule_delayed_work(&tp->schedule, 0); in rtl8152_start_xmit()
2603 usb_mark_last_busy(tp->udev); in rtl8152_start_xmit()
2604 tasklet_schedule(&tp->tx_tl); in rtl8152_start_xmit()
2606 } else if (skb_queue_len(&tp->tx_queue) > tp->tx_qlen) { in rtl8152_start_xmit()
2639 struct net_device *netdev = tp->netdev; in set_tx_qlen()
2641 tp->tx_qlen = agg_buf_sz / (netdev->mtu + VLAN_ETH_HLEN + ETH_FCS_LEN + in set_tx_qlen()
2688 spin_lock_irqsave(&tp->rx_lock, flags); in rtl_start_rx()
2690 INIT_LIST_HEAD(&tp->rx_done); in rtl_start_rx()
2691 INIT_LIST_HEAD(&tp->rx_used); in rtl_start_rx()
2693 list_splice_init(&tp->rx_info, &tmp_list); in rtl_start_rx()
2695 spin_unlock_irqrestore(&tp->rx_lock, flags); in rtl_start_rx()
2698 INIT_LIST_HEAD(&agg->list); in rtl_start_rx()
2702 spin_lock_irqsave(&tp->rx_lock, flags); in rtl_start_rx()
2703 list_add_tail(&agg->list, &tp->rx_used); in rtl_start_rx()
2704 spin_unlock_irqrestore(&tp->rx_lock, flags); in rtl_start_rx()
2706 spin_lock_irqsave(&tp->rx_lock, flags); in rtl_start_rx()
2707 list_add_tail(&agg->list, &tp->rx_done); in rtl_start_rx()
2708 spin_unlock_irqrestore(&tp->rx_lock, flags); in rtl_start_rx()
2714 spin_lock_irqsave(&tp->rx_lock, flags); in rtl_start_rx()
2715 WARN_ON(!list_empty(&tp->rx_info)); in rtl_start_rx()
2716 list_splice(&tmp_list, &tp->rx_info); in rtl_start_rx()
2717 spin_unlock_irqrestore(&tp->rx_lock, flags); in rtl_start_rx()
2736 spin_lock_irqsave(&tp->rx_lock, flags); in rtl_stop_rx()
2737 list_splice_init(&tp->rx_info, &tmp_list); in rtl_stop_rx()
2738 spin_unlock_irqrestore(&tp->rx_lock, flags); in rtl_stop_rx()
2744 if (page_count(agg->page) > 1) in rtl_stop_rx()
2747 usb_kill_urb(agg->urb); in rtl_stop_rx()
2751 spin_lock_irqsave(&tp->rx_lock, flags); in rtl_stop_rx()
2752 WARN_ON(!list_empty(&tp->rx_info)); in rtl_stop_rx()
2753 list_splice(&tmp_list, &tp->rx_info); in rtl_stop_rx()
2754 spin_unlock_irqrestore(&tp->rx_lock, flags); in rtl_stop_rx()
2756 while (!skb_queue_empty(&tp->rx_queue)) in rtl_stop_rx()
2757 dev_kfree_skb(__skb_dequeue(&tp->rx_queue)); in rtl_stop_rx()
2778 switch (tp->version) { in rtl_enable()
2794 if (test_bit(RTL8152_UNPLUG, &tp->flags)) in rtl8152_enable()
2795 return -ENODEV; in rtl8152_enable()
2805 u32 ocp_data = tp->coalesce / 8; in r8153_set_rx_early_timeout()
2807 switch (tp->version) { in r8153_set_rx_early_timeout()
2834 u32 ocp_data = tp->rx_buf_sz - rx_reserved_size(tp->netdev->mtu); in r8153_set_rx_early_size()
2836 switch (tp->version) { in r8153_set_rx_early_size()
2857 if (test_bit(RTL8152_UNPLUG, &tp->flags)) in rtl8153_enable()
2858 return -ENODEV; in rtl8153_enable()
2865 if (tp->version == RTL_VER_09) { in rtl8153_enable()
2884 if (test_bit(RTL8152_UNPLUG, &tp->flags)) { in rtl_disable()
2896 usb_kill_urb(tp->tx_info[i].urb); in rtl_disable()
2949 netdev_features_t changed = features ^ dev->features; in rtl8152_set_features()
2953 ret = usb_autopm_get_interface(tp->intf); in rtl8152_set_features()
2957 mutex_lock(&tp->control); in rtl8152_set_features()
2966 mutex_unlock(&tp->control); in rtl8152_set_features()
2968 usb_autopm_put_interface(tp->intf); in rtl8152_set_features()
3031 device_set_wakeup_enable(&tp->udev->dev, true); in __rtl_set_wol()
3033 device_set_wakeup_enable(&tp->udev->dev, false); in __rtl_set_wol()
3100 if (tp->ups_info.green) in r8153b_ups_flags()
3103 if (tp->ups_info.aldps) in r8153b_ups_flags()
3106 if (tp->ups_info.eee) in r8153b_ups_flags()
3109 if (tp->ups_info.flow_control) in r8153b_ups_flags()
3112 if (tp->ups_info.eee_ckdiv) in r8153b_ups_flags()
3115 if (tp->ups_info.eee_cmod_lv) in r8153b_ups_flags()
3118 if (tp->ups_info._10m_ckdiv) in r8153b_ups_flags()
3121 if (tp->ups_info.eee_plloff_100) in r8153b_ups_flags()
3124 if (tp->ups_info.eee_plloff_giga) in r8153b_ups_flags()
3127 if (tp->ups_info._250m_ckdiv) in r8153b_ups_flags()
3130 if (tp->ups_info.ctap_short_off) in r8153b_ups_flags()
3133 switch (tp->ups_info.speed_duplex) { in r8153b_ups_flags()
3186 tp->ups_info.green = enable; in r8153b_green_en()
3206 if (test_bit(RTL8152_UNPLUG, &tp->flags)) in r8153_phy_status()
3246 test_bit(GREEN_ETHERNET, &tp->flags)); in r8153b_ups_en()
3258 netif_warn(tp, link, tp->netdev, in r8153b_ups_en()
3319 struct usb_device *udev = tp->udev; in rtl_can_wakeup()
3321 return (udev->actconfig->desc.bmAttributes & USB_CONFIG_ATT_WAKEUP); in rtl_can_wakeup()
3341 __rtl_set_wol(tp, tp->saved_wolopts); in rtl_runtime_suspend_enable()
3364 switch (tp->version) { in rtl8153_runtime_enable()
3391 if (tp->udev->speed != USB_SPEED_HIGH) in rtl8153b_runtime_enable()
3400 switch (tp->version) { in r8153_teredo_off()
3445 switch (tp->version) { in rtl_clear_bp()
3509 netif_err(tp, drv, tp->netdev, "patch request fail\n"); in r8153_patch_request()
3511 return -ETIME; in r8153_patch_request()
3520 dev_err(&tp->intf->dev, "patch request fail\n"); in r8153_pre_ram_code()
3521 return -ETIME; in r8153_pre_ram_code()
3544 ocp_write_word(tp, MCU_TYPE_PLA, PLA_OCP_GPHY_BASE, tp->ocp_base); in r8153_post_ram_code()
3555 switch (tp->version) { in rtl8152_is_fw_phy_nc_ok()
3569 fw_offset = __le16_to_cpu(phy->fw_offset); in rtl8152_is_fw_phy_nc_ok()
3571 dev_err(&tp->intf->dev, "fw_offset too small\n"); in rtl8152_is_fw_phy_nc_ok()
3575 length = __le32_to_cpu(phy->blk_hdr.length); in rtl8152_is_fw_phy_nc_ok()
3577 dev_err(&tp->intf->dev, "invalid fw_offset\n"); in rtl8152_is_fw_phy_nc_ok()
3581 length -= __le16_to_cpu(phy->fw_offset); in rtl8152_is_fw_phy_nc_ok()
3583 dev_err(&tp->intf->dev, "invalid block length\n"); in rtl8152_is_fw_phy_nc_ok()
3587 if (__le16_to_cpu(phy->fw_reg) != fw_reg) { in rtl8152_is_fw_phy_nc_ok()
3588 dev_err(&tp->intf->dev, "invalid register to load firmware\n"); in rtl8152_is_fw_phy_nc_ok()
3592 if (__le16_to_cpu(phy->ba_reg) != ba_reg) { in rtl8152_is_fw_phy_nc_ok()
3593 dev_err(&tp->intf->dev, "invalid base address register\n"); in rtl8152_is_fw_phy_nc_ok()
3597 if (__le16_to_cpu(phy->patch_en_addr) != patch_en_addr) { in rtl8152_is_fw_phy_nc_ok()
3598 dev_err(&tp->intf->dev, in rtl8152_is_fw_phy_nc_ok()
3603 if (__le16_to_cpu(phy->mode_reg) != mode_reg) { in rtl8152_is_fw_phy_nc_ok()
3604 dev_err(&tp->intf->dev, in rtl8152_is_fw_phy_nc_ok()
3609 if (__le16_to_cpu(phy->bp_start) != bp_start) { in rtl8152_is_fw_phy_nc_ok()
3610 dev_err(&tp->intf->dev, in rtl8152_is_fw_phy_nc_ok()
3615 if (__le16_to_cpu(phy->bp_num) > 4) { in rtl8152_is_fw_phy_nc_ok()
3616 dev_err(&tp->intf->dev, "invalid break point number\n"); in rtl8152_is_fw_phy_nc_ok()
3632 type = __le32_to_cpu(mac->blk_hdr.type); in rtl8152_is_fw_mac_ok()
3634 switch (tp->version) { in rtl8152_is_fw_mac_ok()
3660 switch (tp->version) { in rtl8152_is_fw_mac_ok()
3689 fw_offset = __le16_to_cpu(mac->fw_offset); in rtl8152_is_fw_mac_ok()
3691 dev_err(&tp->intf->dev, "fw_offset too small\n"); in rtl8152_is_fw_mac_ok()
3695 length = __le32_to_cpu(mac->blk_hdr.length); in rtl8152_is_fw_mac_ok()
3697 dev_err(&tp->intf->dev, "invalid fw_offset\n"); in rtl8152_is_fw_mac_ok()
3701 length -= fw_offset; in rtl8152_is_fw_mac_ok()
3703 dev_err(&tp->intf->dev, "invalid block length\n"); in rtl8152_is_fw_mac_ok()
3707 if (__le16_to_cpu(mac->fw_reg) != fw_reg) { in rtl8152_is_fw_mac_ok()
3708 dev_err(&tp->intf->dev, "invalid register to load firmware\n"); in rtl8152_is_fw_mac_ok()
3712 if (__le16_to_cpu(mac->bp_ba_addr) != bp_ba_addr) { in rtl8152_is_fw_mac_ok()
3713 dev_err(&tp->intf->dev, "invalid base address register\n"); in rtl8152_is_fw_mac_ok()
3717 if (__le16_to_cpu(mac->bp_en_addr) != bp_en_addr) { in rtl8152_is_fw_mac_ok()
3718 dev_err(&tp->intf->dev, "invalid enabled mask register\n"); in rtl8152_is_fw_mac_ok()
3722 if (__le16_to_cpu(mac->bp_start) != bp_start) { in rtl8152_is_fw_mac_ok()
3723 dev_err(&tp->intf->dev, in rtl8152_is_fw_mac_ok()
3728 if (__le16_to_cpu(mac->bp_num) > max_bp) { in rtl8152_is_fw_mac_ok()
3729 dev_err(&tp->intf->dev, "invalid break point number\n"); in rtl8152_is_fw_mac_ok()
3733 for (i = __le16_to_cpu(mac->bp_num); i < max_bp; i++) { in rtl8152_is_fw_mac_ok()
3734 if (mac->bp[i]) { in rtl8152_is_fw_mac_ok()
3735 dev_err(&tp->intf->dev, "unused bp%u is not zero\n", i); in rtl8152_is_fw_mac_ok()
3752 unsigned char checksum[sizeof(fw_hdr->checksum)]; in rtl8152_fw_verify_checksum()
3764 if (crypto_shash_digestsize(alg) != sizeof(fw_hdr->checksum)) { in rtl8152_fw_verify_checksum()
3765 rc = -EFAULT; in rtl8152_fw_verify_checksum()
3766 dev_err(&tp->intf->dev, "digestsize incorrect (%u)\n", in rtl8152_fw_verify_checksum()
3774 rc = -ENOMEM; in rtl8152_fw_verify_checksum()
3777 sdesc->tfm = alg; in rtl8152_fw_verify_checksum()
3779 len = size - sizeof(fw_hdr->checksum); in rtl8152_fw_verify_checksum()
3780 rc = crypto_shash_digest(sdesc, fw_hdr->version, len, checksum); in rtl8152_fw_verify_checksum()
3785 if (memcmp(fw_hdr->checksum, checksum, sizeof(fw_hdr->checksum))) { in rtl8152_fw_verify_checksum()
3786 dev_err(&tp->intf->dev, "checksum fail\n"); in rtl8152_fw_verify_checksum()
3787 rc = -EFAULT; in rtl8152_fw_verify_checksum()
3798 const struct firmware *fw = rtl_fw->fw; in rtl8152_check_firmware()
3799 struct fw_header *fw_hdr = (struct fw_header *)fw->data; in rtl8152_check_firmware()
3804 long ret = -EFAULT; in rtl8152_check_firmware()
3807 if (fw->size < sizeof(*fw_hdr)) { in rtl8152_check_firmware()
3808 dev_err(&tp->intf->dev, "file too small\n"); in rtl8152_check_firmware()
3812 ret = rtl8152_fw_verify_checksum(tp, fw_hdr, fw->size); in rtl8152_check_firmware()
3816 ret = -EFAULT; in rtl8152_check_firmware()
3818 for (i = sizeof(*fw_hdr); i < fw->size;) { in rtl8152_check_firmware()
3819 struct fw_block *block = (struct fw_block *)&fw->data[i]; in rtl8152_check_firmware()
3822 if ((i + sizeof(*block)) > fw->size) in rtl8152_check_firmware()
3825 type = __le32_to_cpu(block->type); in rtl8152_check_firmware()
3828 if (__le32_to_cpu(block->length) != sizeof(*block)) in rtl8152_check_firmware()
3833 dev_err(&tp->intf->dev, in rtl8152_check_firmware()
3840 dev_err(&tp->intf->dev, in rtl8152_check_firmware()
3847 dev_err(&tp->intf->dev, in rtl8152_check_firmware()
3854 dev_err(&tp->intf->dev, in rtl8152_check_firmware()
3861 dev_err(&tp->intf->dev, in rtl8152_check_firmware()
3866 if (__le32_to_cpu(block->length) != sizeof(*start)) { in rtl8152_check_firmware()
3867 dev_err(&tp->intf->dev, in rtl8152_check_firmware()
3876 dev_err(&tp->intf->dev, in rtl8152_check_firmware()
3881 if (__le32_to_cpu(block->length) != sizeof(*block)) { in rtl8152_check_firmware()
3882 dev_err(&tp->intf->dev, in rtl8152_check_firmware()
3891 dev_err(&tp->intf->dev, in rtl8152_check_firmware()
3897 dev_err(&tp->intf->dev, in rtl8152_check_firmware()
3904 dev_err(&tp->intf->dev, in rtl8152_check_firmware()
3911 dev_warn(&tp->intf->dev, "Unknown type %u is found\n", in rtl8152_check_firmware()
3917 i += ALIGN(__le32_to_cpu(block->length), 8); in rtl8152_check_firmware()
3922 dev_err(&tp->intf->dev, "without PHY_STOP\n"); in rtl8152_check_firmware()
3937 mode_reg = __le16_to_cpu(phy->mode_reg); in rtl8152_fw_phy_nc_apply()
3938 sram_write(tp, mode_reg, __le16_to_cpu(phy->mode_pre)); in rtl8152_fw_phy_nc_apply()
3939 sram_write(tp, __le16_to_cpu(phy->ba_reg), in rtl8152_fw_phy_nc_apply()
3940 __le16_to_cpu(phy->ba_data)); in rtl8152_fw_phy_nc_apply()
3942 length = __le32_to_cpu(phy->blk_hdr.length); in rtl8152_fw_phy_nc_apply()
3943 length -= __le16_to_cpu(phy->fw_offset); in rtl8152_fw_phy_nc_apply()
3945 data = (__le16 *)((u8 *)phy + __le16_to_cpu(phy->fw_offset)); in rtl8152_fw_phy_nc_apply()
3947 ocp_reg_write(tp, OCP_SRAM_ADDR, __le16_to_cpu(phy->fw_reg)); in rtl8152_fw_phy_nc_apply()
3951 sram_write(tp, __le16_to_cpu(phy->patch_en_addr), in rtl8152_fw_phy_nc_apply()
3952 __le16_to_cpu(phy->patch_en_value)); in rtl8152_fw_phy_nc_apply()
3954 bp_index = __le16_to_cpu(phy->bp_start); in rtl8152_fw_phy_nc_apply()
3955 num = __le16_to_cpu(phy->bp_num); in rtl8152_fw_phy_nc_apply()
3957 sram_write(tp, bp_index, __le16_to_cpu(phy->bp[i])); in rtl8152_fw_phy_nc_apply()
3961 sram_write(tp, mode_reg, __le16_to_cpu(phy->mode_post)); in rtl8152_fw_phy_nc_apply()
3963 dev_dbg(&tp->intf->dev, "successfully applied %s\n", phy->info); in rtl8152_fw_phy_nc_apply()
3973 switch (__le32_to_cpu(mac->blk_hdr.type)) { in rtl8152_fw_mac_apply()
3989 if (tp->version == RTL_VER_04 && type == MCU_TYPE_PLA && in rtl8152_fw_mac_apply()
3995 length = __le32_to_cpu(mac->blk_hdr.length); in rtl8152_fw_mac_apply()
3996 length -= __le16_to_cpu(mac->fw_offset); in rtl8152_fw_mac_apply()
3999 data += __le16_to_cpu(mac->fw_offset); in rtl8152_fw_mac_apply()
4001 generic_ocp_write(tp, __le16_to_cpu(mac->fw_reg), 0xff, length, data, in rtl8152_fw_mac_apply()
4004 ocp_write_word(tp, type, __le16_to_cpu(mac->bp_ba_addr), in rtl8152_fw_mac_apply()
4005 __le16_to_cpu(mac->bp_ba_value)); in rtl8152_fw_mac_apply()
4007 bp_index = __le16_to_cpu(mac->bp_start); in rtl8152_fw_mac_apply()
4008 bp_num = __le16_to_cpu(mac->bp_num); in rtl8152_fw_mac_apply()
4010 ocp_write_word(tp, type, bp_index, __le16_to_cpu(mac->bp[i])); in rtl8152_fw_mac_apply()
4014 bp_en_addr = __le16_to_cpu(mac->bp_en_addr); in rtl8152_fw_mac_apply()
4017 __le16_to_cpu(mac->bp_en_value)); in rtl8152_fw_mac_apply()
4019 fw_ver_reg = __le16_to_cpu(mac->fw_ver_reg); in rtl8152_fw_mac_apply()
4022 mac->fw_ver_data); in rtl8152_fw_mac_apply()
4024 dev_dbg(&tp->intf->dev, "successfully applied %s\n", mac->info); in rtl8152_fw_mac_apply()
4029 struct rtl_fw *rtl_fw = &tp->rtl_fw; in rtl8152_apply_firmware()
4036 if (IS_ERR_OR_NULL(rtl_fw->fw)) in rtl8152_apply_firmware()
4039 fw = rtl_fw->fw; in rtl8152_apply_firmware()
4040 fw_hdr = (struct fw_header *)fw->data; in rtl8152_apply_firmware()
4042 if (rtl_fw->pre_fw) in rtl8152_apply_firmware()
4043 rtl_fw->pre_fw(tp); in rtl8152_apply_firmware()
4045 for (i = offsetof(struct fw_header, blocks); i < fw->size;) { in rtl8152_apply_firmware()
4046 struct fw_block *block = (struct fw_block *)&fw->data[i]; in rtl8152_apply_firmware()
4048 switch (__le32_to_cpu(block->type)) { in rtl8152_apply_firmware()
4057 key_addr = __le16_to_cpu(key->key_reg); in rtl8152_apply_firmware()
4059 __le16_to_cpu(key->key_data)); in rtl8152_apply_firmware()
4072 i += ALIGN(__le32_to_cpu(block->length), 8); in rtl8152_apply_firmware()
4076 if (rtl_fw->post_fw) in rtl8152_apply_firmware()
4077 rtl_fw->post_fw(tp); in rtl8152_apply_firmware()
4079 strscpy(rtl_fw->version, fw_hdr->version, RTL_VER_SIZE); in rtl8152_apply_firmware()
4080 dev_info(&tp->intf->dev, "load %s successfully\n", rtl_fw->version); in rtl8152_apply_firmware()
4085 struct rtl_fw *rtl_fw = &tp->rtl_fw; in rtl8152_release_firmware()
4087 if (!IS_ERR_OR_NULL(rtl_fw->fw)) { in rtl8152_release_firmware()
4088 release_firmware(rtl_fw->fw); in rtl8152_release_firmware()
4089 rtl_fw->fw = NULL; in rtl8152_release_firmware()
4095 struct rtl_fw *rtl_fw = &tp->rtl_fw; in rtl8152_request_firmware()
4098 if (rtl_fw->fw || !rtl_fw->fw_name) { in rtl8152_request_firmware()
4099 dev_info(&tp->intf->dev, "skip request firmware\n"); in rtl8152_request_firmware()
4104 rc = request_firmware(&rtl_fw->fw, rtl_fw->fw_name, &tp->intf->dev); in rtl8152_request_firmware()
4110 release_firmware(rtl_fw->fw); in rtl8152_request_firmware()
4114 rtl_fw->fw = ERR_PTR(rc); in rtl8152_request_firmware()
4116 dev_warn(&tp->intf->dev, in rtl8152_request_firmware()
4117 "unable to load firmware patch %s (%ld)\n", in rtl8152_request_firmware()
4118 rtl_fw->fw_name, rc); in rtl8152_request_firmware()
4211 tp->ups_info.eee = enable; in r8153_eee_en()
4216 switch (tp->version) { in rtl_eee_enable()
4223 tp->eee_adv); in rtl_eee_enable()
4237 ocp_reg_write(tp, OCP_EEE_ADV, tp->eee_adv); in rtl_eee_enable()
4256 tp->ups_info.flow_control = true; in r8152b_enable_fc()
4269 rtl_eee_enable(tp, tp->eee_en); in r8152b_hw_phy_cfg()
4273 set_bit(PHY_RESET, &tp->flags); in r8152b_hw_phy_cfg()
4323 if (tp->udev->speed == USB_SPEED_FULL || in r8152b_exit_oob()
4324 tp->udev->speed == USB_SPEED_LOW) { in r8152b_exit_oob()
4346 rtl_rx_vlan_en(tp, tp->netdev->features & NETIF_F_HW_VLAN_CTAG_RX); in r8152b_exit_oob()
4493 /* enable bp0 for RTL8153-BND */ in r8153b_post_firmware_1()
4536 tp->ups_info.aldps = enable; in r8153_aldps_en()
4552 if (tp->version == RTL_VER_03) { in r8153_hw_phy_cfg()
4581 if (tp->eee_en) in r8153_hw_phy_cfg()
4587 switch (tp->version) { in r8153_hw_phy_cfg()
4598 set_bit(PHY_RESET, &tp->flags); in r8153_hw_phy_cfg()
4626 r8153b_green_en(tp, test_bit(GREEN_ETHERNET, &tp->flags)); in r8153b_hw_phy_cfg()
4636 * read efuse offset 0x7d to get a 17-bit data. Remove the dummy/fake in r8153b_hw_phy_cfg()
4637 * bit (bit3) to rebuild the real 16-bit data. Write the data to the in r8153b_hw_phy_cfg()
4645 /* ups mode tx-link-pulse timing adjustment: in r8153b_hw_phy_cfg()
4669 tp->ups_info.eee_ckdiv = true; in r8153b_hw_phy_cfg()
4674 tp->ups_info.eee_cmod_lv = true; in r8153b_hw_phy_cfg()
4675 tp->ups_info._10m_ckdiv = true; in r8153b_hw_phy_cfg()
4676 tp->ups_info.eee_plloff_giga = true; in r8153b_hw_phy_cfg()
4680 tp->ups_info._250m_ckdiv = true; in r8153b_hw_phy_cfg()
4685 if (tp->eee_en) in r8153b_hw_phy_cfg()
4691 set_bit(PHY_RESET, &tp->flags); in r8153b_hw_phy_cfg()
4725 rtl_rx_vlan_en(tp, tp->netdev->features & NETIF_F_HW_VLAN_CTAG_RX); in r8153_first_init()
4727 ocp_data = tp->netdev->mtu + VLAN_ETH_HLEN + ETH_FCS_LEN; in r8153_first_init()
4766 ocp_data = tp->netdev->mtu + VLAN_ETH_HLEN + ETH_FCS_LEN; in r8153_enter_oob()
4769 switch (tp->version) { in r8153_enter_oob()
4825 return -EINVAL; in rtl8152_set_speed()
4832 tp->ups_info.speed_duplex = FORCE_10M_FULL; in rtl8152_set_speed()
4834 tp->ups_info.speed_duplex = FORCE_10M_HALF; in rtl8152_set_speed()
4841 tp->ups_info.speed_duplex = FORCE_100M_FULL; in rtl8152_set_speed()
4843 tp->ups_info.speed_duplex = FORCE_100M_HALF; in rtl8152_set_speed()
4847 if (tp->mii.supports_gmii) { in rtl8152_set_speed()
4849 tp->ups_info.speed_duplex = NWAY_1000M_FULL; in rtl8152_set_speed()
4854 ret = -EINVAL; in rtl8152_set_speed()
4859 tp->mii.full_duplex = 1; in rtl8152_set_speed()
4861 tp->mii.full_duplex = 0; in rtl8152_set_speed()
4863 tp->mii.force_media = 1; in rtl8152_set_speed()
4871 if (tp->mii.supports_gmii) in rtl8152_set_speed()
4875 return -EINVAL; in rtl8152_set_speed()
4882 tp->ups_info.speed_duplex = NWAY_10M_HALF; in rtl8152_set_speed()
4886 tp->ups_info.speed_duplex = NWAY_10M_FULL; in rtl8152_set_speed()
4891 tp->ups_info.speed_duplex = NWAY_100M_HALF; in rtl8152_set_speed()
4895 tp->ups_info.speed_duplex = NWAY_100M_FULL; in rtl8152_set_speed()
4900 tp->mii.advertising = tmp1; in rtl8152_set_speed()
4903 if (tp->mii.supports_gmii) { in rtl8152_set_speed()
4912 tp->ups_info.speed_duplex = NWAY_1000M_FULL; in rtl8152_set_speed()
4921 tp->mii.force_media = 0; in rtl8152_set_speed()
4924 if (test_and_clear_bit(PHY_RESET, &tp->flags)) in rtl8152_set_speed()
4945 if (test_bit(RTL8152_UNPLUG, &tp->flags)) in rtl8152_up()
4955 if (test_bit(RTL8152_UNPLUG, &tp->flags)) { in rtl8152_down()
4970 if (test_bit(RTL8152_UNPLUG, &tp->flags)) in rtl8153_up()
4992 switch (tp->version) { in rtl8153_up()
5010 if (test_bit(RTL8152_UNPLUG, &tp->flags)) { in rtl8153_down()
5031 if (test_bit(RTL8152_UNPLUG, &tp->flags)) in rtl8153b_up()
5047 if (tp->udev->speed != USB_SPEED_HIGH) in rtl8153b_up()
5055 if (test_bit(RTL8152_UNPLUG, &tp->flags)) { in rtl8153b_down()
5077 tp->ocp_base = 0x2000; in rtl8152_in_nway()
5100 struct net_device *netdev = tp->netdev; in set_carrier()
5101 struct napi_struct *napi = &tp->napi; in set_carrier()
5108 tp->rtl_ops.enable(tp); in set_carrier()
5113 clear_bit(RTL8152_SET_RX_MODE, &tp->flags); in set_carrier()
5115 napi_enable(&tp->napi); in set_carrier()
5119 skb_queue_len(&tp->tx_queue) < tp->tx_qlen) { in set_carrier()
5125 tasklet_disable(&tp->tx_tl); in set_carrier()
5127 tp->rtl_ops.disable(tp); in set_carrier()
5129 tasklet_enable(&tp->tx_tl); in set_carrier()
5142 if (test_bit(RTL8152_UNPLUG, &tp->flags) || !netif_running(tp->netdev)) in rtl_work_func_t()
5145 if (usb_autopm_get_interface(tp->intf) < 0) in rtl_work_func_t()
5148 if (!test_bit(WORK_ENABLE, &tp->flags)) in rtl_work_func_t()
5151 if (!mutex_trylock(&tp->control)) { in rtl_work_func_t()
5152 schedule_delayed_work(&tp->schedule, 0); in rtl_work_func_t()
5156 if (test_and_clear_bit(RTL8152_LINK_CHG, &tp->flags)) in rtl_work_func_t()
5159 if (test_and_clear_bit(RTL8152_SET_RX_MODE, &tp->flags)) in rtl_work_func_t()
5160 _rtl8152_set_rx_mode(tp->netdev); in rtl_work_func_t()
5163 if (test_and_clear_bit(SCHEDULE_TASKLET, &tp->flags) && in rtl_work_func_t()
5164 netif_carrier_ok(tp->netdev)) in rtl_work_func_t()
5165 tasklet_schedule(&tp->tx_tl); in rtl_work_func_t()
5167 mutex_unlock(&tp->control); in rtl_work_func_t()
5170 usb_autopm_put_interface(tp->intf); in rtl_work_func_t()
5177 if (test_bit(RTL8152_UNPLUG, &tp->flags)) in rtl_hw_phy_work_func_t()
5180 if (usb_autopm_get_interface(tp->intf) < 0) in rtl_hw_phy_work_func_t()
5183 mutex_lock(&tp->control); in rtl_hw_phy_work_func_t()
5185 if (rtl8152_request_firmware(tp) == -ENODEV && tp->rtl_fw.retry) { in rtl_hw_phy_work_func_t()
5186 tp->rtl_fw.retry = false; in rtl_hw_phy_work_func_t()
5187 tp->rtl_fw.fw = NULL; in rtl_hw_phy_work_func_t()
5189 /* Delay execution in case request_firmware() is not ready yet. in rtl_hw_phy_work_func_t()
5191 queue_delayed_work(system_long_wq, &tp->hw_phy_work, HZ * 10); in rtl_hw_phy_work_func_t()
5195 tp->rtl_ops.hw_phy_cfg(tp); in rtl_hw_phy_work_func_t()
5197 rtl8152_set_speed(tp, tp->autoneg, tp->speed, tp->duplex, in rtl_hw_phy_work_func_t()
5198 tp->advertising); in rtl_hw_phy_work_func_t()
5201 mutex_unlock(&tp->control); in rtl_hw_phy_work_func_t()
5203 usb_autopm_put_interface(tp->intf); in rtl_hw_phy_work_func_t()
5215 usb_autopm_get_interface(tp->intf); in rtl_notifier()
5220 usb_autopm_put_interface(tp->intf); in rtl_notifier()
5238 if (work_busy(&tp->hw_phy_work.work) & WORK_BUSY_PENDING) { in rtl8152_open()
5239 cancel_delayed_work_sync(&tp->hw_phy_work); in rtl8152_open()
5240 rtl_hw_phy_work_func_t(&tp->hw_phy_work.work); in rtl8152_open()
5247 res = usb_autopm_get_interface(tp->intf); in rtl8152_open()
5251 mutex_lock(&tp->control); in rtl8152_open()
5253 tp->rtl_ops.up(tp); in rtl8152_open()
5257 set_bit(WORK_ENABLE, &tp->flags); in rtl8152_open()
5259 res = usb_submit_urb(tp->intr_urb, GFP_KERNEL); in rtl8152_open()
5261 if (res == -ENODEV) in rtl8152_open()
5262 netif_device_detach(tp->netdev); in rtl8152_open()
5267 napi_enable(&tp->napi); in rtl8152_open()
5268 tasklet_enable(&tp->tx_tl); in rtl8152_open()
5270 mutex_unlock(&tp->control); in rtl8152_open()
5272 usb_autopm_put_interface(tp->intf); in rtl8152_open()
5274 tp->pm_notifier.notifier_call = rtl_notifier; in rtl8152_open()
5275 register_pm_notifier(&tp->pm_notifier); in rtl8152_open()
5280 mutex_unlock(&tp->control); in rtl8152_open()
5281 usb_autopm_put_interface(tp->intf); in rtl8152_open()
5294 unregister_pm_notifier(&tp->pm_notifier); in rtl8152_close()
5296 tasklet_disable(&tp->tx_tl); in rtl8152_close()
5297 clear_bit(WORK_ENABLE, &tp->flags); in rtl8152_close()
5298 usb_kill_urb(tp->intr_urb); in rtl8152_close()
5299 cancel_delayed_work_sync(&tp->schedule); in rtl8152_close()
5300 napi_disable(&tp->napi); in rtl8152_close()
5303 res = usb_autopm_get_interface(tp->intf); in rtl8152_close()
5304 if (res < 0 || test_bit(RTL8152_UNPLUG, &tp->flags)) { in rtl8152_close()
5308 mutex_lock(&tp->control); in rtl8152_close()
5310 tp->rtl_ops.down(tp); in rtl8152_close()
5312 mutex_unlock(&tp->control); in rtl8152_close()
5314 usb_autopm_put_interface(tp->intf); in rtl8152_close()
5336 if (test_bit(RTL8152_UNPLUG, &tp->flags)) in r8152b_init()
5347 if (tp->version == RTL_VER_01) { in r8152b_init()
5380 if (test_bit(RTL8152_UNPLUG, &tp->flags)) in r8153_init()
5391 if (test_bit(RTL8152_UNPLUG, &tp->flags)) in r8153_init()
5397 if (tp->version == RTL_VER_03 || tp->version == RTL_VER_04 || in r8153_init()
5398 tp->version == RTL_VER_05) in r8153_init()
5411 if (tp->version == RTL_VER_04) { in r8153_init()
5420 } else if (tp->version == RTL_VER_05) { in r8153_init()
5431 } else if (tp->version == RTL_VER_06) { in r8153_init()
5463 if (tp->version == RTL_VER_04 && tp->udev->speed < USB_SPEED_SUPER) in r8153_init()
5480 usb_enable_lpm(tp->udev); in r8153_init()
5493 if (test_bit(DELL_TB_RX_AGG_BUG, &tp->flags)) in r8153_init()
5500 switch (tp->udev->speed) { in r8153_init()
5503 tp->coalesce = COALESCE_SUPER; in r8153_init()
5506 tp->coalesce = COALESCE_HIGH; in r8153_init()
5509 tp->coalesce = COALESCE_SLOW; in r8153_init()
5520 if (test_bit(RTL8152_UNPLUG, &tp->flags)) in r8153b_init()
5531 if (test_bit(RTL8152_UNPLUG, &tp->flags)) in r8153b_init()
5550 /* U1/U2/L1 idle timer. 500 us */ in r8153b_init()
5566 if (tp->udev->speed != USB_SPEED_HIGH) in r8153b_init()
5568 usb_enable_lpm(tp->udev); in r8153b_init()
5579 if (tp->version == RTL_VER_09) { in r8153b_init()
5588 set_bit(GREEN_ETHERNET, &tp->flags); in r8153b_init()
5597 tp->coalesce = 15000; /* 15 us */ in r8153b_init()
5608 netdev = tp->netdev; in rtl8152_pre_reset()
5613 tasklet_disable(&tp->tx_tl); in rtl8152_pre_reset()
5614 clear_bit(WORK_ENABLE, &tp->flags); in rtl8152_pre_reset()
5615 usb_kill_urb(tp->intr_urb); in rtl8152_pre_reset()
5616 cancel_delayed_work_sync(&tp->schedule); in rtl8152_pre_reset()
5617 napi_disable(&tp->napi); in rtl8152_pre_reset()
5619 mutex_lock(&tp->control); in rtl8152_pre_reset()
5620 tp->rtl_ops.disable(tp); in rtl8152_pre_reset()
5621 mutex_unlock(&tp->control); in rtl8152_pre_reset()
5639 dev_set_mac_address (tp->netdev, &sa, NULL); in rtl8152_post_reset()
5643 netdev = tp->netdev; in rtl8152_post_reset()
5647 set_bit(WORK_ENABLE, &tp->flags); in rtl8152_post_reset()
5649 mutex_lock(&tp->control); in rtl8152_post_reset()
5650 tp->rtl_ops.enable(tp); in rtl8152_post_reset()
5653 mutex_unlock(&tp->control); in rtl8152_post_reset()
5656 napi_enable(&tp->napi); in rtl8152_post_reset()
5657 tasklet_enable(&tp->tx_tl); in rtl8152_post_reset()
5659 usb_submit_urb(tp->intr_urb, GFP_KERNEL); in rtl8152_post_reset()
5661 if (!list_empty(&tp->rx_done)) in rtl8152_post_reset()
5662 napi_schedule(&tp->napi); in rtl8152_post_reset()
5669 bool sw_linking = !!netif_carrier_ok(tp->netdev); in delay_autosuspend()
5676 if (work_busy(&tp->schedule.work) || sw_linking != hw_linking) in delay_autosuspend()
5682 if (!sw_linking && tp->rtl_ops.in_nway(tp)) in delay_autosuspend()
5684 else if (!skb_queue_empty(&tp->tx_queue)) in delay_autosuspend()
5692 struct net_device *netdev = tp->netdev; in rtl8152_runtime_resume()
5694 if (netif_running(netdev) && netdev->flags & IFF_UP) { in rtl8152_runtime_resume()
5695 struct napi_struct *napi = &tp->napi; in rtl8152_runtime_resume()
5697 tp->rtl_ops.autosuspend_en(tp, false); in rtl8152_runtime_resume()
5699 set_bit(WORK_ENABLE, &tp->flags); in rtl8152_runtime_resume()
5706 tp->rtl_ops.disable(tp); in rtl8152_runtime_resume()
5712 clear_bit(SELECTIVE_SUSPEND, &tp->flags); in rtl8152_runtime_resume()
5715 if (!list_empty(&tp->rx_done)) in rtl8152_runtime_resume()
5716 napi_schedule(&tp->napi); in rtl8152_runtime_resume()
5718 usb_submit_urb(tp->intr_urb, GFP_NOIO); in rtl8152_runtime_resume()
5720 if (netdev->flags & IFF_UP) in rtl8152_runtime_resume()
5721 tp->rtl_ops.autosuspend_en(tp, false); in rtl8152_runtime_resume()
5723 clear_bit(SELECTIVE_SUSPEND, &tp->flags); in rtl8152_runtime_resume()
5731 struct net_device *netdev = tp->netdev; in rtl8152_system_resume()
5735 if (netif_running(netdev) && (netdev->flags & IFF_UP)) { in rtl8152_system_resume()
5736 tp->rtl_ops.up(tp); in rtl8152_system_resume()
5738 set_bit(WORK_ENABLE, &tp->flags); in rtl8152_system_resume()
5739 usb_submit_urb(tp->intr_urb, GFP_NOIO); in rtl8152_system_resume()
5747 struct net_device *netdev = tp->netdev; in rtl8152_runtime_suspend()
5750 set_bit(SELECTIVE_SUSPEND, &tp->flags); in rtl8152_runtime_suspend()
5753 if (netif_running(netdev) && test_bit(WORK_ENABLE, &tp->flags)) { in rtl8152_runtime_suspend()
5768 clear_bit(SELECTIVE_SUSPEND, &tp->flags); in rtl8152_runtime_suspend()
5770 ret = -EBUSY; in rtl8152_runtime_suspend()
5775 clear_bit(WORK_ENABLE, &tp->flags); in rtl8152_runtime_suspend()
5776 usb_kill_urb(tp->intr_urb); in rtl8152_runtime_suspend()
5778 tp->rtl_ops.autosuspend_en(tp, true); in rtl8152_runtime_suspend()
5781 struct napi_struct *napi = &tp->napi; in rtl8152_runtime_suspend()
5792 ret = -EBUSY; in rtl8152_runtime_suspend()
5802 struct net_device *netdev = tp->netdev; in rtl8152_system_suspend()
5806 if (netif_running(netdev) && test_bit(WORK_ENABLE, &tp->flags)) { in rtl8152_system_suspend()
5807 struct napi_struct *napi = &tp->napi; in rtl8152_system_suspend()
5809 clear_bit(WORK_ENABLE, &tp->flags); in rtl8152_system_suspend()
5810 usb_kill_urb(tp->intr_urb); in rtl8152_system_suspend()
5811 tasklet_disable(&tp->tx_tl); in rtl8152_system_suspend()
5813 cancel_delayed_work_sync(&tp->schedule); in rtl8152_system_suspend()
5814 tp->rtl_ops.down(tp); in rtl8152_system_suspend()
5816 tasklet_enable(&tp->tx_tl); in rtl8152_system_suspend()
5827 mutex_lock(&tp->control); in rtl8152_suspend()
5834 mutex_unlock(&tp->control); in rtl8152_suspend()
5844 mutex_lock(&tp->control); in rtl8152_resume()
5846 if (test_bit(SELECTIVE_SUSPEND, &tp->flags)) in rtl8152_resume()
5851 mutex_unlock(&tp->control); in rtl8152_resume()
5860 clear_bit(SELECTIVE_SUSPEND, &tp->flags); in rtl8152_reset_resume()
5861 tp->rtl_ops.init(tp); in rtl8152_reset_resume()
5862 queue_delayed_work(system_long_wq, &tp->hw_phy_work, 0); in rtl8152_reset_resume()
5871 if (usb_autopm_get_interface(tp->intf) < 0) in rtl8152_get_wol()
5875 wol->supported = 0; in rtl8152_get_wol()
5876 wol->wolopts = 0; in rtl8152_get_wol()
5878 mutex_lock(&tp->control); in rtl8152_get_wol()
5879 wol->supported = WAKE_ANY; in rtl8152_get_wol()
5880 wol->wolopts = __rtl_get_wol(tp); in rtl8152_get_wol()
5881 mutex_unlock(&tp->control); in rtl8152_get_wol()
5884 usb_autopm_put_interface(tp->intf); in rtl8152_get_wol()
5893 return -EOPNOTSUPP; in rtl8152_set_wol()
5895 if (wol->wolopts & ~WAKE_ANY) in rtl8152_set_wol()
5896 return -EINVAL; in rtl8152_set_wol()
5898 ret = usb_autopm_get_interface(tp->intf); in rtl8152_set_wol()
5902 mutex_lock(&tp->control); in rtl8152_set_wol()
5904 __rtl_set_wol(tp, wol->wolopts); in rtl8152_set_wol()
5905 tp->saved_wolopts = wol->wolopts & WAKE_ANY; in rtl8152_set_wol()
5907 mutex_unlock(&tp->control); in rtl8152_set_wol()
5909 usb_autopm_put_interface(tp->intf); in rtl8152_set_wol()
5919 return tp->msg_enable; in rtl8152_get_msglevel()
5926 tp->msg_enable = value; in rtl8152_set_msglevel()
5934 strlcpy(info->driver, MODULENAME, sizeof(info->driver)); in rtl8152_get_drvinfo()
5935 strlcpy(info->version, DRIVER_VERSION, sizeof(info->version)); in rtl8152_get_drvinfo()
5936 usb_make_path(tp->udev, info->bus_info, sizeof(info->bus_info)); in rtl8152_get_drvinfo()
5937 if (!IS_ERR_OR_NULL(tp->rtl_fw.fw)) in rtl8152_get_drvinfo()
5938 strlcpy(info->fw_version, tp->rtl_fw.version, in rtl8152_get_drvinfo()
5939 sizeof(info->fw_version)); in rtl8152_get_drvinfo()
5949 if (!tp->mii.mdio_read) in rtl8152_get_link_ksettings()
5950 return -EOPNOTSUPP; in rtl8152_get_link_ksettings()
5952 ret = usb_autopm_get_interface(tp->intf); in rtl8152_get_link_ksettings()
5956 mutex_lock(&tp->control); in rtl8152_get_link_ksettings()
5958 mii_ethtool_get_link_ksettings(&tp->mii, cmd); in rtl8152_get_link_ksettings()
5960 mutex_unlock(&tp->control); in rtl8152_get_link_ksettings()
5962 usb_autopm_put_interface(tp->intf); in rtl8152_get_link_ksettings()
5975 ret = usb_autopm_get_interface(tp->intf); in rtl8152_set_link_ksettings()
5980 cmd->link_modes.advertising)) in rtl8152_set_link_ksettings()
5984 cmd->link_modes.advertising)) in rtl8152_set_link_ksettings()
5988 cmd->link_modes.advertising)) in rtl8152_set_link_ksettings()
5992 cmd->link_modes.advertising)) in rtl8152_set_link_ksettings()
5996 cmd->link_modes.advertising)) in rtl8152_set_link_ksettings()
6000 cmd->link_modes.advertising)) in rtl8152_set_link_ksettings()
6003 mutex_lock(&tp->control); in rtl8152_set_link_ksettings()
6005 ret = rtl8152_set_speed(tp, cmd->base.autoneg, cmd->base.speed, in rtl8152_set_link_ksettings()
6006 cmd->base.duplex, advertising); in rtl8152_set_link_ksettings()
6008 tp->autoneg = cmd->base.autoneg; in rtl8152_set_link_ksettings()
6009 tp->speed = cmd->base.speed; in rtl8152_set_link_ksettings()
6010 tp->duplex = cmd->base.duplex; in rtl8152_set_link_ksettings()
6011 tp->advertising = advertising; in rtl8152_set_link_ksettings()
6014 mutex_unlock(&tp->control); in rtl8152_set_link_ksettings()
6016 usb_autopm_put_interface(tp->intf); in rtl8152_set_link_ksettings()
6044 return -EOPNOTSUPP; in rtl8152_get_sset_count()
6054 if (usb_autopm_get_interface(tp->intf) < 0) in rtl8152_get_ethtool_stats()
6059 usb_autopm_put_interface(tp->intf); in rtl8152_get_ethtool_stats()
6099 eee->eee_enabled = tp->eee_en; in r8152_get_eee()
6100 eee->eee_active = !!(supported & adv & lp); in r8152_get_eee()
6101 eee->supported = supported; in r8152_get_eee()
6102 eee->advertised = tp->eee_adv; in r8152_get_eee()
6103 eee->lp_advertised = lp; in r8152_get_eee()
6110 u16 val = ethtool_adv_to_mmd_eee_adv_t(eee->advertised); in r8152_set_eee()
6112 tp->eee_en = eee->eee_enabled; in r8152_set_eee()
6113 tp->eee_adv = val; in r8152_set_eee()
6115 rtl_eee_enable(tp, tp->eee_en); in r8152_set_eee()
6134 eee->eee_enabled = tp->eee_en; in r8153_get_eee()
6135 eee->eee_active = !!(supported & adv & lp); in r8153_get_eee()
6136 eee->supported = supported; in r8153_get_eee()
6137 eee->advertised = tp->eee_adv; in r8153_get_eee()
6138 eee->lp_advertised = lp; in r8153_get_eee()
6149 ret = usb_autopm_get_interface(tp->intf); in rtl_ethtool_get_eee()
6153 mutex_lock(&tp->control); in rtl_ethtool_get_eee()
6155 ret = tp->rtl_ops.eee_get(tp, edata); in rtl_ethtool_get_eee()
6157 mutex_unlock(&tp->control); in rtl_ethtool_get_eee()
6159 usb_autopm_put_interface(tp->intf); in rtl_ethtool_get_eee()
6171 ret = usb_autopm_get_interface(tp->intf); in rtl_ethtool_set_eee()
6175 mutex_lock(&tp->control); in rtl_ethtool_set_eee()
6177 ret = tp->rtl_ops.eee_set(tp, edata); in rtl_ethtool_set_eee()
6179 ret = mii_nway_restart(&tp->mii); in rtl_ethtool_set_eee()
6181 mutex_unlock(&tp->control); in rtl_ethtool_set_eee()
6183 usb_autopm_put_interface(tp->intf); in rtl_ethtool_set_eee()
6194 ret = usb_autopm_get_interface(tp->intf); in rtl8152_nway_reset()
6198 mutex_lock(&tp->control); in rtl8152_nway_reset()
6200 ret = mii_nway_restart(&tp->mii); in rtl8152_nway_reset()
6202 mutex_unlock(&tp->control); in rtl8152_nway_reset()
6204 usb_autopm_put_interface(tp->intf); in rtl8152_nway_reset()
6215 switch (tp->version) { in rtl8152_get_coalesce()
6219 return -EOPNOTSUPP; in rtl8152_get_coalesce()
6224 coalesce->rx_coalesce_usecs = tp->coalesce; in rtl8152_get_coalesce()
6235 switch (tp->version) { in rtl8152_set_coalesce()
6239 return -EOPNOTSUPP; in rtl8152_set_coalesce()
6244 if (coalesce->rx_coalesce_usecs > COALESCE_SLOW) in rtl8152_set_coalesce()
6245 return -EINVAL; in rtl8152_set_coalesce()
6247 ret = usb_autopm_get_interface(tp->intf); in rtl8152_set_coalesce()
6251 mutex_lock(&tp->control); in rtl8152_set_coalesce()
6253 if (tp->coalesce != coalesce->rx_coalesce_usecs) { in rtl8152_set_coalesce()
6254 tp->coalesce = coalesce->rx_coalesce_usecs; in rtl8152_set_coalesce()
6258 napi_disable(&tp->napi); in rtl8152_set_coalesce()
6259 tp->rtl_ops.disable(tp); in rtl8152_set_coalesce()
6260 tp->rtl_ops.enable(tp); in rtl8152_set_coalesce()
6262 clear_bit(RTL8152_SET_RX_MODE, &tp->flags); in rtl8152_set_coalesce()
6264 napi_enable(&tp->napi); in rtl8152_set_coalesce()
6269 mutex_unlock(&tp->control); in rtl8152_set_coalesce()
6271 usb_autopm_put_interface(tp->intf); in rtl8152_set_coalesce()
6281 switch (tunable->id) { in rtl8152_get_tunable()
6283 *(u32 *)d = tp->rx_copybreak; in rtl8152_get_tunable()
6286 return -EOPNOTSUPP; in rtl8152_get_tunable()
6299 switch (tunable->id) { in rtl8152_set_tunable()
6305 return -EINVAL; in rtl8152_set_tunable()
6308 if (tp->rx_copybreak != val) { in rtl8152_set_tunable()
6309 if (netdev->flags & IFF_UP) { in rtl8152_set_tunable()
6310 mutex_lock(&tp->control); in rtl8152_set_tunable()
6311 napi_disable(&tp->napi); in rtl8152_set_tunable()
6312 tp->rx_copybreak = val; in rtl8152_set_tunable()
6313 napi_enable(&tp->napi); in rtl8152_set_tunable()
6314 mutex_unlock(&tp->control); in rtl8152_set_tunable()
6316 tp->rx_copybreak = val; in rtl8152_set_tunable()
6321 return -EOPNOTSUPP; in rtl8152_set_tunable()
6332 ring->rx_max_pending = RTL8152_RX_MAX_PENDING; in rtl8152_get_ringparam()
6333 ring->rx_pending = tp->rx_pending; in rtl8152_get_ringparam()
6341 if (ring->rx_pending < (RTL8152_MAX_RX * 2)) in rtl8152_set_ringparam()
6342 return -EINVAL; in rtl8152_set_ringparam()
6344 if (tp->rx_pending != ring->rx_pending) { in rtl8152_set_ringparam()
6345 if (netdev->flags & IFF_UP) { in rtl8152_set_ringparam()
6346 mutex_lock(&tp->control); in rtl8152_set_ringparam()
6347 napi_disable(&tp->napi); in rtl8152_set_ringparam()
6348 tp->rx_pending = ring->rx_pending; in rtl8152_set_ringparam()
6349 napi_enable(&tp->napi); in rtl8152_set_ringparam()
6350 mutex_unlock(&tp->control); in rtl8152_set_ringparam()
6352 tp->rx_pending = ring->rx_pending; in rtl8152_set_ringparam()
6389 if (test_bit(RTL8152_UNPLUG, &tp->flags)) in rtl8152_ioctl()
6390 return -ENODEV; in rtl8152_ioctl()
6392 res = usb_autopm_get_interface(tp->intf); in rtl8152_ioctl()
6398 data->phy_id = R8152_PHY_ID; /* Internal PHY */ in rtl8152_ioctl()
6402 mutex_lock(&tp->control); in rtl8152_ioctl()
6403 data->val_out = r8152_mdio_read(tp, data->reg_num); in rtl8152_ioctl()
6404 mutex_unlock(&tp->control); in rtl8152_ioctl()
6409 res = -EPERM; in rtl8152_ioctl()
6412 mutex_lock(&tp->control); in rtl8152_ioctl()
6413 r8152_mdio_write(tp, data->reg_num, data->val_in); in rtl8152_ioctl()
6414 mutex_unlock(&tp->control); in rtl8152_ioctl()
6418 res = -EOPNOTSUPP; in rtl8152_ioctl()
6421 usb_autopm_put_interface(tp->intf); in rtl8152_ioctl()
6432 switch (tp->version) { in rtl8152_change_mtu()
6436 dev->mtu = new_mtu; in rtl8152_change_mtu()
6442 ret = usb_autopm_get_interface(tp->intf); in rtl8152_change_mtu()
6446 mutex_lock(&tp->control); in rtl8152_change_mtu()
6448 dev->mtu = new_mtu; in rtl8152_change_mtu()
6459 mutex_unlock(&tp->control); in rtl8152_change_mtu()
6461 usb_autopm_put_interface(tp->intf); in rtl8152_change_mtu()
6482 if (test_bit(RTL8152_UNPLUG, &tp->flags)) in rtl8152_unload()
6485 if (tp->version != RTL_VER_01) in rtl8152_unload()
6491 if (test_bit(RTL8152_UNPLUG, &tp->flags)) in rtl8153_unload()
6499 if (test_bit(RTL8152_UNPLUG, &tp->flags)) in rtl8153b_unload()
6507 struct rtl_ops *ops = &tp->rtl_ops; in rtl_ops_init()
6510 switch (tp->version) { in rtl_ops_init()
6514 ops->init = r8152b_init; in rtl_ops_init()
6515 ops->enable = rtl8152_enable; in rtl_ops_init()
6516 ops->disable = rtl8152_disable; in rtl_ops_init()
6517 ops->up = rtl8152_up; in rtl_ops_init()
6518 ops->down = rtl8152_down; in rtl_ops_init()
6519 ops->unload = rtl8152_unload; in rtl_ops_init()
6520 ops->eee_get = r8152_get_eee; in rtl_ops_init()
6521 ops->eee_set = r8152_set_eee; in rtl_ops_init()
6522 ops->in_nway = rtl8152_in_nway; in rtl_ops_init()
6523 ops->hw_phy_cfg = r8152b_hw_phy_cfg; in rtl_ops_init()
6524 ops->autosuspend_en = rtl_runtime_suspend_enable; in rtl_ops_init()
6525 tp->rx_buf_sz = 16 * 1024; in rtl_ops_init()
6526 tp->eee_en = true; in rtl_ops_init()
6527 tp->eee_adv = MDIO_EEE_100TX; in rtl_ops_init()
6534 ops->init = r8153_init; in rtl_ops_init()
6535 ops->enable = rtl8153_enable; in rtl_ops_init()
6536 ops->disable = rtl8153_disable; in rtl_ops_init()
6537 ops->up = rtl8153_up; in rtl_ops_init()
6538 ops->down = rtl8153_down; in rtl_ops_init()
6539 ops->unload = rtl8153_unload; in rtl_ops_init()
6540 ops->eee_get = r8153_get_eee; in rtl_ops_init()
6541 ops->eee_set = r8152_set_eee; in rtl_ops_init()
6542 ops->in_nway = rtl8153_in_nway; in rtl_ops_init()
6543 ops->hw_phy_cfg = r8153_hw_phy_cfg; in rtl_ops_init()
6544 ops->autosuspend_en = rtl8153_runtime_enable; in rtl_ops_init()
6545 tp->rx_buf_sz = 32 * 1024; in rtl_ops_init()
6546 tp->eee_en = true; in rtl_ops_init()
6547 tp->eee_adv = MDIO_EEE_1000T | MDIO_EEE_100TX; in rtl_ops_init()
6552 ops->init = r8153b_init; in rtl_ops_init()
6553 ops->enable = rtl8153_enable; in rtl_ops_init()
6554 ops->disable = rtl8153_disable; in rtl_ops_init()
6555 ops->up = rtl8153b_up; in rtl_ops_init()
6556 ops->down = rtl8153b_down; in rtl_ops_init()
6557 ops->unload = rtl8153b_unload; in rtl_ops_init()
6558 ops->eee_get = r8153_get_eee; in rtl_ops_init()
6559 ops->eee_set = r8152_set_eee; in rtl_ops_init()
6560 ops->in_nway = rtl8153_in_nway; in rtl_ops_init()
6561 ops->hw_phy_cfg = r8153b_hw_phy_cfg; in rtl_ops_init()
6562 ops->autosuspend_en = rtl8153b_runtime_enable; in rtl_ops_init()
6563 tp->rx_buf_sz = 32 * 1024; in rtl_ops_init()
6564 tp->eee_en = true; in rtl_ops_init()
6565 tp->eee_adv = MDIO_EEE_1000T | MDIO_EEE_100TX; in rtl_ops_init()
6569 ret = -ENODEV; in rtl_ops_init()
6570 netif_err(tp, probe, tp->netdev, "Unknown Device\n"); in rtl_ops_init()
6577 #define FIRMWARE_8153A_2 "rtl_nic/rtl8153a-2.fw"
6578 #define FIRMWARE_8153A_3 "rtl_nic/rtl8153a-3.fw"
6579 #define FIRMWARE_8153A_4 "rtl_nic/rtl8153a-4.fw"
6580 #define FIRMWARE_8153B_2 "rtl_nic/rtl8153b-2.fw"
6589 struct rtl_fw *rtl_fw = &tp->rtl_fw; in rtl_fw_init()
6591 switch (tp->version) { in rtl_fw_init()
6593 rtl_fw->fw_name = FIRMWARE_8153A_2; in rtl_fw_init()
6594 rtl_fw->pre_fw = r8153_pre_firmware_1; in rtl_fw_init()
6595 rtl_fw->post_fw = r8153_post_firmware_1; in rtl_fw_init()
6598 rtl_fw->fw_name = FIRMWARE_8153A_3; in rtl_fw_init()
6599 rtl_fw->pre_fw = r8153_pre_firmware_2; in rtl_fw_init()
6600 rtl_fw->post_fw = r8153_post_firmware_2; in rtl_fw_init()
6603 rtl_fw->fw_name = FIRMWARE_8153A_4; in rtl_fw_init()
6604 rtl_fw->post_fw = r8153_post_firmware_3; in rtl_fw_init()
6607 rtl_fw->fw_name = FIRMWARE_8153B_2; in rtl_fw_init()
6608 rtl_fw->pre_fw = r8153b_pre_firmware_1; in rtl_fw_init()
6609 rtl_fw->post_fw = r8153b_post_firmware_1; in rtl_fw_init()
6668 dev_info(&intf->dev, "Unknown version 0x%04x\n", ocp_data); in rtl_get_version()
6672 dev_dbg(&intf->dev, "Detected version 0x%04x\n", version); in rtl_get_version()
6687 return -ENODEV; in rtl8152_probe()
6689 if (udev->actconfig->desc.bConfigurationValue != 1) { in rtl8152_probe()
6691 return -ENODEV; in rtl8152_probe()
6694 if (intf->cur_altsetting->desc.bNumEndpoints < 3) in rtl8152_probe()
6695 return -ENODEV; in rtl8152_probe()
6700 dev_err(&intf->dev, "Out of memory\n"); in rtl8152_probe()
6701 return -ENOMEM; in rtl8152_probe()
6704 SET_NETDEV_DEV(netdev, &intf->dev); in rtl8152_probe()
6706 tp->msg_enable = 0x7FFF; in rtl8152_probe()
6708 tp->udev = udev; in rtl8152_probe()
6709 tp->netdev = netdev; in rtl8152_probe()
6710 tp->intf = intf; in rtl8152_probe()
6711 tp->version = version; in rtl8152_probe()
6717 tp->mii.supports_gmii = 0; in rtl8152_probe()
6720 tp->mii.supports_gmii = 1; in rtl8152_probe()
6730 mutex_init(&tp->control); in rtl8152_probe()
6731 INIT_DELAYED_WORK(&tp->schedule, rtl_work_func_t); in rtl8152_probe()
6732 INIT_DELAYED_WORK(&tp->hw_phy_work, rtl_hw_phy_work_func_t); in rtl8152_probe()
6733 tasklet_init(&tp->tx_tl, bottom_half, (unsigned long)tp); in rtl8152_probe()
6734 tasklet_disable(&tp->tx_tl); in rtl8152_probe()
6736 netdev->netdev_ops = &rtl8152_netdev_ops; in rtl8152_probe()
6737 netdev->watchdog_timeo = RTL8152_TX_TIMEOUT; in rtl8152_probe()
6739 netdev->features |= NETIF_F_RXCSUM | NETIF_F_IP_CSUM | NETIF_F_SG | in rtl8152_probe()
6743 netdev->hw_features = NETIF_F_RXCSUM | NETIF_F_IP_CSUM | NETIF_F_SG | in rtl8152_probe()
6747 netdev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO | in rtl8152_probe()
6751 if (tp->version == RTL_VER_01) { in rtl8152_probe()
6752 netdev->features &= ~NETIF_F_RXCSUM; in rtl8152_probe()
6753 netdev->hw_features &= ~NETIF_F_RXCSUM; in rtl8152_probe()
6756 if (le16_to_cpu(udev->descriptor.idVendor) == VENDOR_ID_LENOVO) { in rtl8152_probe()
6757 switch (le16_to_cpu(udev->descriptor.idProduct)) { in rtl8152_probe()
6760 set_bit(LENOVO_MACPASSTHRU, &tp->flags); in rtl8152_probe()
6764 if (le16_to_cpu(udev->descriptor.bcdDevice) == 0x3011 && udev->serial && in rtl8152_probe()
6765 (!strcmp(udev->serial, "000001000000") || in rtl8152_probe()
6766 !strcmp(udev->serial, "000002000000"))) { in rtl8152_probe()
6767 dev_info(&udev->dev, "Dell TB16 Dock, disable RX aggregation"); in rtl8152_probe()
6768 set_bit(DELL_TB_RX_AGG_BUG, &tp->flags); in rtl8152_probe()
6771 netdev->ethtool_ops = &ops; in rtl8152_probe()
6774 /* MTU range: 68 - 1500 or 9194 */ in rtl8152_probe()
6775 netdev->min_mtu = ETH_MIN_MTU; in rtl8152_probe()
6776 switch (tp->version) { in rtl8152_probe()
6779 netdev->max_mtu = ETH_DATA_LEN; in rtl8152_probe()
6782 netdev->max_mtu = RTL8153_MAX_MTU; in rtl8152_probe()
6786 tp->mii.dev = netdev; in rtl8152_probe()
6787 tp->mii.mdio_read = read_mii_word; in rtl8152_probe()
6788 tp->mii.mdio_write = write_mii_word; in rtl8152_probe()
6789 tp->mii.phy_id_mask = 0x3f; in rtl8152_probe()
6790 tp->mii.reg_num_mask = 0x1f; in rtl8152_probe()
6791 tp->mii.phy_id = R8152_PHY_ID; in rtl8152_probe()
6793 tp->autoneg = AUTONEG_ENABLE; in rtl8152_probe()
6794 tp->speed = SPEED_100; in rtl8152_probe()
6795 tp->advertising = RTL_ADVERTISED_10_HALF | RTL_ADVERTISED_10_FULL | in rtl8152_probe()
6797 if (tp->mii.supports_gmii) { in rtl8152_probe()
6798 tp->speed = SPEED_1000; in rtl8152_probe()
6799 tp->advertising |= RTL_ADVERTISED_1000_FULL; in rtl8152_probe()
6801 tp->duplex = DUPLEX_FULL; in rtl8152_probe()
6803 tp->rx_copybreak = RTL8152_RXFG_HEADSZ; in rtl8152_probe()
6804 tp->rx_pending = 10 * RTL8152_MAX_RX; in rtl8152_probe()
6806 intf->needs_remote_wakeup = 1; in rtl8152_probe()
6811 tp->saved_wolopts = __rtl_get_wol(tp); in rtl8152_probe()
6813 tp->rtl_ops.init(tp); in rtl8152_probe()
6816 tp->rtl_fw.retry = true; in rtl8152_probe()
6818 queue_delayed_work(system_long_wq, &tp->hw_phy_work, 0); in rtl8152_probe()
6822 netif_napi_add(netdev, &tp->napi, r8152_poll, RTL8152_NAPI_WEIGHT); in rtl8152_probe()
6830 if (tp->saved_wolopts) in rtl8152_probe()
6831 device_set_wakeup_enable(&udev->dev, true); in rtl8152_probe()
6833 device_set_wakeup_enable(&udev->dev, false); in rtl8152_probe()
6840 tasklet_kill(&tp->tx_tl); in rtl8152_probe()
6855 unregister_netdev(tp->netdev); in rtl8152_disconnect()
6856 tasklet_kill(&tp->tx_tl); in rtl8152_disconnect()
6857 cancel_delayed_work_sync(&tp->hw_phy_work); in rtl8152_disconnect()
6858 tp->rtl_ops.unload(tp); in rtl8152_disconnect()
6860 free_netdev(tp->netdev); in rtl8152_disconnect()