Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'r8152'

Hayes Wang says:

====================
r8152: improvement and new features

Change some flows or behavior to improve the efficiency or make the
code readable. Besides, support WOL and runtime suspend.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>

+527 -186
+527 -186
drivers/net/usb/r8152.c
··· 23 23 #include <linux/ipv6.h> 24 24 25 25 /* Version Information */ 26 - #define DRIVER_VERSION "v1.04.0 (2014/01/15)" 26 + #define DRIVER_VERSION "v1.05.0 (2014/02/18)" 27 27 #define DRIVER_AUTHOR "Realtek linux nic maintainers <nic_swsd@realtek.com>" 28 28 #define DRIVER_DESC "Realtek RTL8152/RTL8153 Based USB Ethernet Adapters" 29 29 #define MODULENAME "r8152" ··· 62 62 #define PLA_RSTTELLY 0xe800 63 63 #define PLA_CR 0xe813 64 64 #define PLA_CRWECR 0xe81c 65 + #define PLA_CONFIG12 0xe81e /* CONFIG1, CONFIG2 */ 66 + #define PLA_CONFIG34 0xe820 /* CONFIG3, CONFIG4 */ 65 67 #define PLA_CONFIG5 0xe822 66 68 #define PLA_PHY_PWR 0xe84c 67 69 #define PLA_OOB_CTRL 0xe84f ··· 218 216 /* PAL_BDC_CR */ 219 217 #define ALDPS_PROXY_MODE 0x0001 220 218 219 + /* PLA_CONFIG34 */ 220 + #define LINK_ON_WAKE_EN 0x0010 221 + #define LINK_OFF_WAKE_EN 0x0008 222 + 221 223 /* PLA_CONFIG5 */ 224 + #define BWF_EN 0x0040 225 + #define MWF_EN 0x0020 226 + #define UWF_EN 0x0010 222 227 #define LAN_WAKE_EN 0x0002 223 228 224 229 /* PLA_LED_FEATURE */ ··· 445 436 RTL8152_SET_RX_MODE, 446 437 WORK_ENABLE, 447 438 RTL8152_LINK_CHG, 439 + SELECTIVE_SUSPEND, 440 + PHY_RESET, 448 441 }; 449 442 450 443 /* Define these values to match your device */ ··· 525 514 void (*init)(struct r8152 *); 526 515 int (*enable)(struct r8152 *); 527 516 void (*disable)(struct r8152 *); 517 + void (*up)(struct r8152 *); 528 518 void (*down)(struct r8152 *); 529 519 void (*unload)(struct r8152 *); 530 520 } rtl_ops; 531 521 532 522 int intr_interval; 523 + u32 saved_wolopts; 533 524 u32 msg_enable; 534 525 u32 tx_qlen; 535 526 u16 ocp_base; ··· 878 865 static int read_mii_word(struct net_device *netdev, int phy_id, int reg) 879 866 { 880 867 struct r8152 *tp = netdev_priv(netdev); 868 + int ret; 881 869 882 870 if (phy_id != R8152_PHY_ID) 883 871 return -EINVAL; 884 872 885 - return r8152_mdio_read(tp, reg); 873 + ret = usb_autopm_get_interface(tp->intf); 874 + if (ret < 0) 875 + goto out; 876 + 877 + ret = r8152_mdio_read(tp, reg); 878 + 879 + usb_autopm_put_interface(tp->intf); 880 + 881 + out: 882 + return ret; 886 883 } 887 884 888 885 static ··· 903 880 if (phy_id != R8152_PHY_ID) 904 881 return; 905 882 883 + if (usb_autopm_get_interface(tp->intf) < 0) 884 + return; 885 + 906 886 r8152_mdio_write(tp, reg, val); 887 + 888 + usb_autopm_put_interface(tp->intf); 907 889 } 908 890 909 891 static ··· 917 889 static inline void set_ethernet_addr(struct r8152 *tp) 918 890 { 919 891 struct net_device *dev = tp->netdev; 892 + int ret; 920 893 u8 node_id[8] = {0}; 921 894 922 - if (pla_ocp_read(tp, PLA_IDR, sizeof(node_id), node_id) < 0) 895 + if (tp->version == RTL_VER_01) 896 + ret = pla_ocp_read(tp, PLA_IDR, sizeof(node_id), node_id); 897 + else 898 + ret = pla_ocp_read(tp, PLA_BACKUP, sizeof(node_id), node_id); 899 + 900 + if (ret < 0) { 923 901 netif_notice(tp, probe, dev, "inet addr fail\n"); 924 - else { 902 + } else { 903 + if (tp->version != RTL_VER_01) { 904 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, 905 + CRWECR_CONFIG); 906 + pla_ocp_write(tp, PLA_IDR, BYTE_EN_SIX_BYTES, 907 + sizeof(node_id), node_id); 908 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, 909 + CRWECR_NORAML); 910 + } 911 + 925 912 memcpy(dev->dev_addr, node_id, dev->addr_len); 926 913 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); 927 914 } ··· 993 950 /* This avoid the re-submitting bulk */ 994 951 if (!netif_carrier_ok(netdev)) 995 952 return; 953 + 954 + usb_mark_last_busy(tp->udev); 996 955 997 956 switch (status) { 998 957 case 0: ··· 1063 1018 list_add_tail(&agg->list, &tp->tx_free); 1064 1019 spin_unlock_irqrestore(&tp->tx_lock, flags); 1065 1020 1021 + usb_autopm_put_interface_async(tp->intf); 1022 + 1066 1023 if (!netif_carrier_ok(tp->netdev)) 1067 1024 return; 1068 1025 ··· 1075 1028 return; 1076 1029 1077 1030 if (!skb_queue_empty(&tp->tx_queue)) 1078 - tasklet_schedule(&tp->tl); 1031 + schedule_delayed_work(&tp->schedule, 0); 1079 1032 } 1080 1033 1081 1034 static void intr_callback(struct urb *urb) ··· 1331 1284 1332 1285 static int r8152_tx_agg_fill(struct r8152 *tp, struct tx_agg *agg) 1333 1286 { 1334 - int remain; 1287 + struct sk_buff_head skb_head, *tx_queue = &tp->tx_queue; 1288 + unsigned long flags; 1289 + int remain, ret; 1335 1290 u8 *tx_data; 1291 + 1292 + __skb_queue_head_init(&skb_head); 1293 + spin_lock_irqsave(&tx_queue->lock, flags); 1294 + skb_queue_splice_init(tx_queue, &skb_head); 1295 + spin_unlock_irqrestore(&tx_queue->lock, flags); 1336 1296 1337 1297 tx_data = agg->head; 1338 1298 agg->skb_num = agg->skb_len = 0; ··· 1350 1296 struct sk_buff *skb; 1351 1297 unsigned int len; 1352 1298 1353 - skb = skb_dequeue(&tp->tx_queue); 1299 + skb = __skb_dequeue(&skb_head); 1354 1300 if (!skb) 1355 1301 break; 1356 1302 1357 1303 remain -= sizeof(*tx_desc); 1358 1304 len = skb->len; 1359 1305 if (remain < len) { 1360 - skb_queue_head(&tp->tx_queue, skb); 1306 + __skb_queue_head(&skb_head, skb); 1361 1307 break; 1362 1308 } 1363 1309 ··· 1375 1321 remain = rx_buf_sz - (int)(tx_agg_align(tx_data) - agg->head); 1376 1322 } 1377 1323 1378 - netif_tx_lock(tp->netdev); 1324 + if (!skb_queue_empty(&skb_head)) { 1325 + spin_lock_irqsave(&tx_queue->lock, flags); 1326 + skb_queue_splice(&skb_head, tx_queue); 1327 + spin_unlock_irqrestore(&tx_queue->lock, flags); 1328 + } 1329 + 1330 + netif_tx_lock_bh(tp->netdev); 1379 1331 1380 1332 if (netif_queue_stopped(tp->netdev) && 1381 1333 skb_queue_len(&tp->tx_queue) < tp->tx_qlen) 1382 1334 netif_wake_queue(tp->netdev); 1383 1335 1384 - netif_tx_unlock(tp->netdev); 1336 + netif_tx_unlock_bh(tp->netdev); 1337 + 1338 + ret = usb_autopm_get_interface(tp->intf); 1339 + if (ret < 0) 1340 + goto out_tx_fill; 1385 1341 1386 1342 usb_fill_bulk_urb(agg->urb, tp->udev, usb_sndbulkpipe(tp->udev, 2), 1387 1343 agg->head, (int)(tx_data - (u8 *)agg->head), 1388 1344 (usb_complete_t)write_bulk_callback, agg); 1389 1345 1390 - return usb_submit_urb(agg->urb, GFP_ATOMIC); 1346 + ret = usb_submit_urb(agg->urb, GFP_KERNEL); 1347 + if (ret < 0) 1348 + usb_autopm_put_interface(tp->intf); 1349 + 1350 + out_tx_fill: 1351 + return ret; 1391 1352 } 1392 1353 1393 1354 static void rx_bottom(struct r8152 *tp) 1394 1355 { 1395 1356 unsigned long flags; 1396 - struct list_head *cursor, *next; 1357 + struct list_head *cursor, *next, rx_queue; 1397 1358 1359 + if (list_empty(&tp->rx_done)) 1360 + return; 1361 + 1362 + INIT_LIST_HEAD(&rx_queue); 1398 1363 spin_lock_irqsave(&tp->rx_lock, flags); 1399 - list_for_each_safe(cursor, next, &tp->rx_done) { 1364 + list_splice_init(&tp->rx_done, &rx_queue); 1365 + spin_unlock_irqrestore(&tp->rx_lock, flags); 1366 + 1367 + list_for_each_safe(cursor, next, &rx_queue) { 1400 1368 struct rx_desc *rx_desc; 1401 1369 struct rx_agg *agg; 1402 1370 int len_used = 0; ··· 1427 1351 int ret; 1428 1352 1429 1353 list_del_init(cursor); 1430 - spin_unlock_irqrestore(&tp->rx_lock, flags); 1431 1354 1432 1355 agg = list_entry(cursor, struct rx_agg, list); 1433 1356 urb = agg->urb; ··· 1464 1389 memcpy(skb->data, rx_data, pkt_len); 1465 1390 skb_put(skb, pkt_len); 1466 1391 skb->protocol = eth_type_trans(skb, netdev); 1467 - netif_rx(skb); 1392 + netif_receive_skb(skb); 1468 1393 stats->rx_packets++; 1469 1394 stats->rx_bytes += pkt_len; 1470 1395 ··· 1476 1401 1477 1402 submit: 1478 1403 ret = r8152_submit_rx(tp, agg, GFP_ATOMIC); 1479 - spin_lock_irqsave(&tp->rx_lock, flags); 1480 1404 if (ret && ret != -ENODEV) { 1481 - list_add_tail(&agg->list, next); 1405 + spin_lock_irqsave(&tp->rx_lock, flags); 1406 + list_add_tail(&agg->list, &tp->rx_done); 1407 + spin_unlock_irqrestore(&tp->rx_lock, flags); 1482 1408 tasklet_schedule(&tp->tl); 1483 1409 } 1484 1410 } 1485 - spin_unlock_irqrestore(&tp->rx_lock, flags); 1486 1411 } 1487 1412 1488 1413 static void tx_bottom(struct r8152 *tp) ··· 1540 1465 return; 1541 1466 1542 1467 rx_bottom(tp); 1543 - tx_bottom(tp); 1544 1468 } 1545 1469 1546 1470 static ··· 1550 1476 (usb_complete_t)read_bulk_callback, agg); 1551 1477 1552 1478 return usb_submit_urb(agg->urb, mem_flags); 1479 + } 1480 + 1481 + static void rtl_drop_queued_tx(struct r8152 *tp) 1482 + { 1483 + struct net_device_stats *stats = &tp->netdev->stats; 1484 + struct sk_buff_head skb_head, *tx_queue = &tp->tx_queue; 1485 + unsigned long flags; 1486 + struct sk_buff *skb; 1487 + 1488 + if (skb_queue_empty(tx_queue)) 1489 + return; 1490 + 1491 + __skb_queue_head_init(&skb_head); 1492 + spin_lock_irqsave(&tx_queue->lock, flags); 1493 + skb_queue_splice_init(tx_queue, &skb_head); 1494 + spin_unlock_irqrestore(&tx_queue->lock, flags); 1495 + 1496 + while ((skb = __skb_dequeue(&skb_head))) { 1497 + dev_kfree_skb(skb); 1498 + stats->tx_dropped++; 1499 + } 1553 1500 } 1554 1501 1555 1502 static void rtl8152_tx_timeout(struct net_device *netdev) ··· 1649 1554 netif_stop_queue(netdev); 1650 1555 1651 1556 if (!list_empty(&tp->tx_free)) 1652 - tasklet_schedule(&tp->tl); 1557 + schedule_delayed_work(&tp->schedule, 0); 1653 1558 1654 1559 return NETDEV_TX_OK; 1655 1560 } ··· 1708 1613 } 1709 1614 } 1710 1615 1616 + static void rxdy_gated_en(struct r8152 *tp, bool enable) 1617 + { 1618 + u32 ocp_data; 1619 + 1620 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MISC_1); 1621 + if (enable) 1622 + ocp_data |= RXDY_GATED_EN; 1623 + else 1624 + ocp_data &= ~RXDY_GATED_EN; 1625 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_MISC_1, ocp_data); 1626 + } 1627 + 1711 1628 static int rtl_enable(struct r8152 *tp) 1712 1629 { 1713 1630 u32 ocp_data; ··· 1731 1624 ocp_data |= CR_RE | CR_TE; 1732 1625 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CR, ocp_data); 1733 1626 1734 - ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MISC_1); 1735 - ocp_data &= ~RXDY_GATED_EN; 1736 - ocp_write_word(tp, MCU_TYPE_PLA, PLA_MISC_1, ocp_data); 1627 + rxdy_gated_en(tp, false); 1737 1628 1738 1629 INIT_LIST_HEAD(&tp->rx_done); 1739 1630 ret = 0; ··· 1786 1681 1787 1682 static void rtl8152_disable(struct r8152 *tp) 1788 1683 { 1789 - struct net_device_stats *stats = rtl8152_get_stats(tp->netdev); 1790 - struct sk_buff *skb; 1791 1684 u32 ocp_data; 1792 1685 int i; 1793 1686 ··· 1793 1690 ocp_data &= ~RCR_ACPT_ALL; 1794 1691 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); 1795 1692 1796 - while ((skb = skb_dequeue(&tp->tx_queue))) { 1797 - dev_kfree_skb(skb); 1798 - stats->tx_dropped++; 1799 - } 1693 + rtl_drop_queued_tx(tp); 1800 1694 1801 1695 for (i = 0; i < RTL8152_MAX_TX; i++) 1802 1696 usb_kill_urb(tp->tx_info[i].urb); 1803 1697 1804 - ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MISC_1); 1805 - ocp_data |= RXDY_GATED_EN; 1806 - ocp_write_word(tp, MCU_TYPE_PLA, PLA_MISC_1, ocp_data); 1698 + rxdy_gated_en(tp, true); 1807 1699 1808 1700 for (i = 0; i < 1000; i++) { 1809 1701 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); ··· 1819 1721 rtl8152_nic_reset(tp); 1820 1722 } 1821 1723 1724 + static void r8152_power_cut_en(struct r8152 *tp, bool enable) 1725 + { 1726 + u32 ocp_data; 1727 + 1728 + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_UPS_CTRL); 1729 + if (enable) 1730 + ocp_data |= POWER_CUT; 1731 + else 1732 + ocp_data &= ~POWER_CUT; 1733 + ocp_write_word(tp, MCU_TYPE_USB, USB_UPS_CTRL, ocp_data); 1734 + 1735 + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_PM_CTRL_STATUS); 1736 + ocp_data &= ~RESUME_INDICATE; 1737 + ocp_write_word(tp, MCU_TYPE_USB, USB_PM_CTRL_STATUS, ocp_data); 1738 + 1739 + } 1740 + 1741 + #define WAKE_ANY (WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_BCAST | WAKE_MCAST) 1742 + 1743 + static u32 __rtl_get_wol(struct r8152 *tp) 1744 + { 1745 + u32 ocp_data; 1746 + u32 wolopts = 0; 1747 + 1748 + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CONFIG5); 1749 + if (!(ocp_data & LAN_WAKE_EN)) 1750 + return 0; 1751 + 1752 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CONFIG34); 1753 + if (ocp_data & LINK_ON_WAKE_EN) 1754 + wolopts |= WAKE_PHY; 1755 + 1756 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CONFIG5); 1757 + if (ocp_data & UWF_EN) 1758 + wolopts |= WAKE_UCAST; 1759 + if (ocp_data & BWF_EN) 1760 + wolopts |= WAKE_BCAST; 1761 + if (ocp_data & MWF_EN) 1762 + wolopts |= WAKE_MCAST; 1763 + 1764 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CFG_WOL); 1765 + if (ocp_data & MAGIC_EN) 1766 + wolopts |= WAKE_MAGIC; 1767 + 1768 + return wolopts; 1769 + } 1770 + 1771 + static void __rtl_set_wol(struct r8152 *tp, u32 wolopts) 1772 + { 1773 + u32 ocp_data; 1774 + 1775 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_CONFIG); 1776 + 1777 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CONFIG34); 1778 + ocp_data &= ~LINK_ON_WAKE_EN; 1779 + if (wolopts & WAKE_PHY) 1780 + ocp_data |= LINK_ON_WAKE_EN; 1781 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_CONFIG34, ocp_data); 1782 + 1783 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CONFIG5); 1784 + ocp_data &= ~(UWF_EN | BWF_EN | MWF_EN | LAN_WAKE_EN); 1785 + if (wolopts & WAKE_UCAST) 1786 + ocp_data |= UWF_EN; 1787 + if (wolopts & WAKE_BCAST) 1788 + ocp_data |= BWF_EN; 1789 + if (wolopts & WAKE_MCAST) 1790 + ocp_data |= MWF_EN; 1791 + if (wolopts & WAKE_ANY) 1792 + ocp_data |= LAN_WAKE_EN; 1793 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_CONFIG5, ocp_data); 1794 + 1795 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML); 1796 + 1797 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CFG_WOL); 1798 + ocp_data &= ~MAGIC_EN; 1799 + if (wolopts & WAKE_MAGIC) 1800 + ocp_data |= MAGIC_EN; 1801 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_CFG_WOL, ocp_data); 1802 + 1803 + if (wolopts & WAKE_ANY) 1804 + device_set_wakeup_enable(&tp->udev->dev, true); 1805 + else 1806 + device_set_wakeup_enable(&tp->udev->dev, false); 1807 + } 1808 + 1809 + static void rtl_runtime_suspend_enable(struct r8152 *tp, bool enable) 1810 + { 1811 + if (enable) { 1812 + u32 ocp_data; 1813 + 1814 + __rtl_set_wol(tp, WAKE_ANY); 1815 + 1816 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_CONFIG); 1817 + 1818 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CONFIG34); 1819 + ocp_data |= LINK_OFF_WAKE_EN; 1820 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_CONFIG34, ocp_data); 1821 + 1822 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML); 1823 + } else { 1824 + __rtl_set_wol(tp, tp->saved_wolopts); 1825 + } 1826 + } 1827 + 1828 + static void rtl_phy_reset(struct r8152 *tp) 1829 + { 1830 + u16 data; 1831 + int i; 1832 + 1833 + clear_bit(PHY_RESET, &tp->flags); 1834 + 1835 + data = r8152_mdio_read(tp, MII_BMCR); 1836 + 1837 + /* don't reset again before the previous one complete */ 1838 + if (data & BMCR_RESET) 1839 + return; 1840 + 1841 + data |= BMCR_RESET; 1842 + r8152_mdio_write(tp, MII_BMCR, data); 1843 + 1844 + for (i = 0; i < 50; i++) { 1845 + msleep(20); 1846 + if ((r8152_mdio_read(tp, MII_BMCR) & BMCR_RESET) == 0) 1847 + break; 1848 + } 1849 + } 1850 + 1851 + static void rtl_clear_bp(struct r8152 *tp) 1852 + { 1853 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_0, 0); 1854 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_2, 0); 1855 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_4, 0); 1856 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_6, 0); 1857 + ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_0, 0); 1858 + ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_2, 0); 1859 + ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_4, 0); 1860 + ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_6, 0); 1861 + mdelay(3); 1862 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_BP_BA, 0); 1863 + ocp_write_word(tp, MCU_TYPE_USB, USB_BP_BA, 0); 1864 + } 1865 + 1866 + static void r8153_clear_bp(struct r8152 *tp) 1867 + { 1868 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_BP_EN, 0); 1869 + ocp_write_byte(tp, MCU_TYPE_USB, USB_BP_EN, 0); 1870 + rtl_clear_bp(tp); 1871 + } 1872 + 1873 + static void r8153_teredo_off(struct r8152 *tp) 1874 + { 1875 + u32 ocp_data; 1876 + 1877 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG); 1878 + ocp_data &= ~(TEREDO_SEL | TEREDO_RS_EVENT_MASK | OOB_TEREDO_EN); 1879 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG, ocp_data); 1880 + 1881 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_WDT6_CTRL, WDT6_SET_MODE); 1882 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_REALWOW_TIMER, 0); 1883 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_TEREDO_TIMER, 0); 1884 + } 1885 + 1886 + static void r8152b_disable_aldps(struct r8152 *tp) 1887 + { 1888 + ocp_reg_write(tp, OCP_ALDPS_CONFIG, ENPDNPS | LINKENA | DIS_SDSAVE); 1889 + msleep(20); 1890 + } 1891 + 1892 + static inline void r8152b_enable_aldps(struct r8152 *tp) 1893 + { 1894 + ocp_reg_write(tp, OCP_ALDPS_CONFIG, ENPWRSAVE | ENPDNPS | 1895 + LINKENA | DIS_SDSAVE); 1896 + } 1897 + 1898 + static void r8152b_hw_phy_cfg(struct r8152 *tp) 1899 + { 1900 + u16 data; 1901 + 1902 + data = r8152_mdio_read(tp, MII_BMCR); 1903 + if (data & BMCR_PDOWN) { 1904 + data &= ~BMCR_PDOWN; 1905 + r8152_mdio_write(tp, MII_BMCR, data); 1906 + } 1907 + 1908 + r8152b_disable_aldps(tp); 1909 + 1910 + rtl_clear_bp(tp); 1911 + 1912 + r8152b_enable_aldps(tp); 1913 + set_bit(PHY_RESET, &tp->flags); 1914 + } 1915 + 1822 1916 static void r8152b_exit_oob(struct r8152 *tp) 1823 1917 { 1824 1918 u32 ocp_data; ··· 2020 1730 ocp_data &= ~RCR_ACPT_ALL; 2021 1731 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); 2022 1732 2023 - ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MISC_1); 2024 - ocp_data |= RXDY_GATED_EN; 2025 - ocp_write_word(tp, MCU_TYPE_PLA, PLA_MISC_1, ocp_data); 1733 + rxdy_gated_en(tp, true); 1734 + r8153_teredo_off(tp); 1735 + r8152b_hw_phy_cfg(tp); 2026 1736 2027 1737 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML); 2028 1738 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CR, 0x00); ··· 2128 1838 2129 1839 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, RTL8152_RMS); 2130 1840 2131 - ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CFG_WOL); 2132 - ocp_data |= MAGIC_EN; 2133 - ocp_write_word(tp, MCU_TYPE_PLA, PLA_CFG_WOL, ocp_data); 2134 - 2135 1841 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CPCR); 2136 1842 ocp_data |= CPCR_RX_VLAN; 2137 1843 ocp_write_word(tp, MCU_TYPE_PLA, PLA_CPCR, ocp_data); ··· 2140 1854 ocp_data |= NOW_IS_OOB | DIS_MCU_CLROOB; 2141 1855 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data); 2142 1856 2143 - ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CONFIG5, LAN_WAKE_EN); 2144 - 2145 - ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MISC_1); 2146 - ocp_data &= ~RXDY_GATED_EN; 2147 - ocp_write_word(tp, MCU_TYPE_PLA, PLA_MISC_1, ocp_data); 1857 + rxdy_gated_en(tp, false); 2148 1858 2149 1859 ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); 2150 1860 ocp_data |= RCR_APM | RCR_AM | RCR_AB; 2151 1861 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); 2152 - } 2153 - 2154 - static void r8152b_disable_aldps(struct r8152 *tp) 2155 - { 2156 - ocp_reg_write(tp, OCP_ALDPS_CONFIG, ENPDNPS | LINKENA | DIS_SDSAVE); 2157 - msleep(20); 2158 - } 2159 - 2160 - static inline void r8152b_enable_aldps(struct r8152 *tp) 2161 - { 2162 - ocp_reg_write(tp, OCP_ALDPS_CONFIG, ENPWRSAVE | ENPDNPS | 2163 - LINKENA | DIS_SDSAVE); 2164 1862 } 2165 1863 2166 1864 static void r8153_hw_phy_cfg(struct r8152 *tp) ··· 2153 1883 u16 data; 2154 1884 2155 1885 ocp_reg_write(tp, OCP_ADC_CFG, CKADSEL_L | ADC_EN | EN_EMI_L); 2156 - r8152_mdio_write(tp, MII_BMCR, BMCR_ANENABLE); 1886 + data = r8152_mdio_read(tp, MII_BMCR); 1887 + if (data & BMCR_PDOWN) { 1888 + data &= ~BMCR_PDOWN; 1889 + r8152_mdio_write(tp, MII_BMCR, data); 1890 + } 1891 + 1892 + r8153_clear_bp(tp); 2157 1893 2158 1894 if (tp->version == RTL_VER_03) { 2159 1895 data = ocp_reg_read(tp, OCP_EEE_CFG); ··· 2195 1919 data = sram_read(tp, SRAM_10M_AMP2); 2196 1920 data |= AMP_DN; 2197 1921 sram_write(tp, SRAM_10M_AMP2, data); 1922 + 1923 + set_bit(PHY_RESET, &tp->flags); 2198 1924 } 2199 1925 2200 - static void r8153_u1u2en(struct r8152 *tp, int enable) 1926 + static void r8153_u1u2en(struct r8152 *tp, bool enable) 2201 1927 { 2202 1928 u8 u1u2[8]; 2203 1929 ··· 2211 1933 usb_ocp_write(tp, USB_TOLERANCE, BYTE_EN_SIX_BYTES, sizeof(u1u2), u1u2); 2212 1934 } 2213 1935 2214 - static void r8153_u2p3en(struct r8152 *tp, int enable) 1936 + static void r8153_u2p3en(struct r8152 *tp, bool enable) 2215 1937 { 2216 1938 u32 ocp_data; 2217 1939 ··· 2223 1945 ocp_write_word(tp, MCU_TYPE_USB, USB_U2P3_CTRL, ocp_data); 2224 1946 } 2225 1947 2226 - static void r8153_power_cut_en(struct r8152 *tp, int enable) 1948 + static void r8153_power_cut_en(struct r8152 *tp, bool enable) 2227 1949 { 2228 1950 u32 ocp_data; 2229 1951 ··· 2239 1961 ocp_write_word(tp, MCU_TYPE_USB, USB_MISC_0, ocp_data); 2240 1962 } 2241 1963 2242 - static void r8153_teredo_off(struct r8152 *tp) 2243 - { 2244 - u32 ocp_data; 2245 - 2246 - ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG); 2247 - ocp_data &= ~(TEREDO_SEL | TEREDO_RS_EVENT_MASK | OOB_TEREDO_EN); 2248 - ocp_write_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG, ocp_data); 2249 - 2250 - ocp_write_word(tp, MCU_TYPE_PLA, PLA_WDT6_CTRL, WDT6_SET_MODE); 2251 - ocp_write_word(tp, MCU_TYPE_PLA, PLA_REALWOW_TIMER, 0); 2252 - ocp_write_dword(tp, MCU_TYPE_PLA, PLA_TEREDO_TIMER, 0); 2253 - } 2254 - 2255 1964 static void r8153_first_init(struct r8152 *tp) 2256 1965 { 2257 1966 u32 ocp_data; 2258 1967 int i; 2259 1968 2260 - ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MISC_1); 2261 - ocp_data |= RXDY_GATED_EN; 2262 - ocp_write_word(tp, MCU_TYPE_PLA, PLA_MISC_1, ocp_data); 2263 - 1969 + rxdy_gated_en(tp, true); 2264 1970 r8153_teredo_off(tp); 2265 1971 2266 1972 ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); ··· 2337 2075 2338 2076 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, RTL8152_RMS); 2339 2077 2340 - ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CFG_WOL); 2341 - ocp_data |= MAGIC_EN; 2342 - ocp_write_word(tp, MCU_TYPE_PLA, PLA_CFG_WOL, ocp_data); 2343 - 2344 2078 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG); 2345 2079 ocp_data &= ~TEREDO_WAKE_MASK; 2346 2080 ocp_write_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG, ocp_data); ··· 2353 2095 ocp_data |= NOW_IS_OOB | DIS_MCU_CLROOB; 2354 2096 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data); 2355 2097 2356 - ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CONFIG5, LAN_WAKE_EN); 2357 - 2358 - ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MISC_1); 2359 - ocp_data &= ~RXDY_GATED_EN; 2360 - ocp_write_word(tp, MCU_TYPE_PLA, PLA_MISC_1, ocp_data); 2098 + rxdy_gated_en(tp, false); 2361 2099 2362 2100 ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); 2363 2101 ocp_data |= RCR_APM | RCR_AM | RCR_AB; ··· 2444 2190 bmcr = BMCR_ANENABLE | BMCR_ANRESTART; 2445 2191 } 2446 2192 2193 + if (test_bit(PHY_RESET, &tp->flags)) 2194 + bmcr |= BMCR_RESET; 2195 + 2447 2196 if (tp->mii.supports_gmii) 2448 2197 r8152_mdio_write(tp, MII_CTRL1000, gbcr); 2449 2198 2450 2199 r8152_mdio_write(tp, MII_ADVERTISE, anar); 2451 2200 r8152_mdio_write(tp, MII_BMCR, bmcr); 2201 + 2202 + if (test_bit(PHY_RESET, &tp->flags)) { 2203 + int i; 2204 + 2205 + clear_bit(PHY_RESET, &tp->flags); 2206 + for (i = 0; i < 50; i++) { 2207 + msleep(20); 2208 + if ((r8152_mdio_read(tp, MII_BMCR) & BMCR_RESET) == 0) 2209 + break; 2210 + } 2211 + } 2452 2212 2453 2213 out: 2454 2214 ··· 2471 2203 2472 2204 static void rtl8152_down(struct r8152 *tp) 2473 2205 { 2474 - u32 ocp_data; 2475 - 2476 - ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_UPS_CTRL); 2477 - ocp_data &= ~POWER_CUT; 2478 - ocp_write_word(tp, MCU_TYPE_USB, USB_UPS_CTRL, ocp_data); 2479 - 2206 + r8152_power_cut_en(tp, false); 2480 2207 r8152b_disable_aldps(tp); 2481 2208 r8152b_enter_oob(tp); 2482 2209 r8152b_enable_aldps(tp); ··· 2479 2216 2480 2217 static void rtl8153_down(struct r8152 *tp) 2481 2218 { 2482 - r8153_u1u2en(tp, 0); 2483 - r8153_power_cut_en(tp, 0); 2219 + r8153_u1u2en(tp, false); 2220 + r8153_power_cut_en(tp, false); 2484 2221 r8153_disable_aldps(tp); 2485 2222 r8153_enter_oob(tp); 2486 2223 r8153_enable_aldps(tp); ··· 2515 2252 { 2516 2253 struct r8152 *tp = container_of(work, struct r8152, schedule.work); 2517 2254 2255 + if (usb_autopm_get_interface(tp->intf) < 0) 2256 + return; 2257 + 2518 2258 if (!test_bit(WORK_ENABLE, &tp->flags)) 2519 2259 goto out1; 2520 2260 ··· 2530 2264 if (test_bit(RTL8152_SET_RX_MODE, &tp->flags)) 2531 2265 _rtl8152_set_rx_mode(tp->netdev); 2532 2266 2267 + if (tp->speed & LINK_STATUS) 2268 + tx_bottom(tp); 2269 + 2270 + if (test_bit(PHY_RESET, &tp->flags)) 2271 + rtl_phy_reset(tp); 2272 + 2533 2273 out1: 2534 - return; 2274 + usb_autopm_put_interface(tp->intf); 2535 2275 } 2536 2276 2537 2277 static int rtl8152_open(struct net_device *netdev) 2538 2278 { 2539 2279 struct r8152 *tp = netdev_priv(netdev); 2540 2280 int res = 0; 2281 + 2282 + res = alloc_all_mem(tp); 2283 + if (res) 2284 + goto out; 2285 + 2286 + res = usb_autopm_get_interface(tp->intf); 2287 + if (res < 0) { 2288 + free_all_mem(tp); 2289 + goto out; 2290 + } 2291 + 2292 + /* The WORK_ENABLE may be set when autoresume occurs */ 2293 + if (test_bit(WORK_ENABLE, &tp->flags)) { 2294 + clear_bit(WORK_ENABLE, &tp->flags); 2295 + usb_kill_urb(tp->intr_urb); 2296 + cancel_delayed_work_sync(&tp->schedule); 2297 + if (tp->speed & LINK_STATUS) 2298 + tp->rtl_ops.disable(tp); 2299 + } 2300 + 2301 + tp->rtl_ops.up(tp); 2541 2302 2542 2303 rtl8152_set_speed(tp, AUTONEG_ENABLE, 2543 2304 tp->mii.supports_gmii ? SPEED_1000 : SPEED_100, ··· 2579 2286 netif_device_detach(tp->netdev); 2580 2287 netif_warn(tp, ifup, netdev, "intr_urb submit failed: %d\n", 2581 2288 res); 2289 + free_all_mem(tp); 2582 2290 } 2583 2291 2292 + usb_autopm_put_interface(tp->intf); 2584 2293 2294 + out: 2585 2295 return res; 2586 2296 } 2587 2297 ··· 2597 2301 usb_kill_urb(tp->intr_urb); 2598 2302 cancel_delayed_work_sync(&tp->schedule); 2599 2303 netif_stop_queue(netdev); 2600 - tasklet_disable(&tp->tl); 2601 - tp->rtl_ops.disable(tp); 2602 - tasklet_enable(&tp->tl); 2304 + 2305 + res = usb_autopm_get_interface(tp->intf); 2306 + if (res < 0) { 2307 + rtl_drop_queued_tx(tp); 2308 + } else { 2309 + /* 2310 + * The autosuspend may have been enabled and wouldn't 2311 + * be disable when autoresume occurs, because the 2312 + * netif_running() would be false. 2313 + */ 2314 + if (test_bit(SELECTIVE_SUSPEND, &tp->flags)) { 2315 + rtl_runtime_suspend_enable(tp, false); 2316 + clear_bit(SELECTIVE_SUSPEND, &tp->flags); 2317 + } 2318 + 2319 + tasklet_disable(&tp->tl); 2320 + tp->rtl_ops.down(tp); 2321 + tasklet_enable(&tp->tl); 2322 + usb_autopm_put_interface(tp->intf); 2323 + } 2324 + 2325 + free_all_mem(tp); 2603 2326 2604 2327 return res; 2605 - } 2606 - 2607 - static void rtl_clear_bp(struct r8152 *tp) 2608 - { 2609 - ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_0, 0); 2610 - ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_2, 0); 2611 - ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_4, 0); 2612 - ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_6, 0); 2613 - ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_0, 0); 2614 - ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_2, 0); 2615 - ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_4, 0); 2616 - ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_6, 0); 2617 - mdelay(3); 2618 - ocp_write_word(tp, MCU_TYPE_PLA, PLA_BP_BA, 0); 2619 - ocp_write_word(tp, MCU_TYPE_USB, USB_BP_BA, 0); 2620 - } 2621 - 2622 - static void r8153_clear_bp(struct r8152 *tp) 2623 - { 2624 - ocp_write_byte(tp, MCU_TYPE_PLA, PLA_BP_EN, 0); 2625 - ocp_write_byte(tp, MCU_TYPE_USB, USB_BP_EN, 0); 2626 - rtl_clear_bp(tp); 2627 2328 } 2628 2329 2629 2330 static void r8152b_enable_eee(struct r8152 *tp) ··· 2671 2378 r8152_mdio_write(tp, MII_ADVERTISE, anar); 2672 2379 } 2673 2380 2674 - static void r8152b_hw_phy_cfg(struct r8152 *tp) 2675 - { 2676 - r8152_mdio_write(tp, MII_BMCR, BMCR_ANENABLE); 2677 - r8152b_disable_aldps(tp); 2678 - } 2679 - 2680 2381 static void r8152b_init(struct r8152 *tp) 2681 2382 { 2682 2383 u32 ocp_data; 2683 - int i; 2684 - 2685 - rtl_clear_bp(tp); 2686 2384 2687 2385 if (tp->version == RTL_VER_01) { 2688 2386 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE); ··· 2681 2397 ocp_write_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE, ocp_data); 2682 2398 } 2683 2399 2684 - r8152b_hw_phy_cfg(tp); 2685 - 2686 - ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_UPS_CTRL); 2687 - ocp_data &= ~POWER_CUT; 2688 - ocp_write_word(tp, MCU_TYPE_USB, USB_UPS_CTRL, ocp_data); 2689 - 2690 - ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_PM_CTRL_STATUS); 2691 - ocp_data &= ~RESUME_INDICATE; 2692 - ocp_write_word(tp, MCU_TYPE_USB, USB_PM_CTRL_STATUS, ocp_data); 2693 - 2694 - r8152b_exit_oob(tp); 2400 + r8152_power_cut_en(tp, false); 2695 2401 2696 2402 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR); 2697 2403 ocp_data |= TX_10M_IDLE_EN | PFM_PWM_SWITCH; ··· 2698 2424 r8152b_enable_aldps(tp); 2699 2425 r8152b_enable_fc(tp); 2700 2426 2701 - r8152_mdio_write(tp, MII_BMCR, BMCR_RESET | BMCR_ANENABLE | 2702 - BMCR_ANRESTART); 2703 - for (i = 0; i < 100; i++) { 2704 - udelay(100); 2705 - if (!(r8152_mdio_read(tp, MII_BMCR) & BMCR_RESET)) 2706 - break; 2707 - } 2708 - 2709 2427 /* enable rx aggregation */ 2710 2428 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL); 2711 2429 ocp_data &= ~RX_AGG_DISABLE; ··· 2709 2443 u32 ocp_data; 2710 2444 int i; 2711 2445 2712 - r8153_u1u2en(tp, 0); 2446 + r8153_u1u2en(tp, false); 2713 2447 2714 2448 for (i = 0; i < 500; i++) { 2715 2449 if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) & ··· 2725 2459 msleep(20); 2726 2460 } 2727 2461 2728 - r8153_u2p3en(tp, 0); 2462 + r8153_u2p3en(tp, false); 2729 2463 2730 2464 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_WDT11_CTRL); 2731 2465 ocp_data &= ~TIMER11_EN; 2732 2466 ocp_write_word(tp, MCU_TYPE_USB, USB_WDT11_CTRL, ocp_data); 2733 - 2734 - r8153_clear_bp(tp); 2735 2467 2736 2468 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE); 2737 2469 ocp_data &= ~LED_MODE_MASK; ··· 2748 2484 ocp_data |= SEN_VAL_NORMAL | SEL_RXIDLE; 2749 2485 ocp_write_word(tp, MCU_TYPE_USB, USB_AFE_CTRL2, ocp_data); 2750 2486 2751 - r8153_power_cut_en(tp, 0); 2752 - r8153_u1u2en(tp, 1); 2753 - 2754 - r8153_first_init(tp); 2487 + r8153_power_cut_en(tp, false); 2488 + r8153_u1u2en(tp, true); 2755 2489 2756 2490 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL, ALDPS_SPDWN_RATIO); 2757 2491 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL2, EEE_SPDWN_RATIO); ··· 2764 2502 r8153_enable_eee(tp); 2765 2503 r8153_enable_aldps(tp); 2766 2504 r8152b_enable_fc(tp); 2767 - 2768 - r8152_mdio_write(tp, MII_BMCR, BMCR_RESET | BMCR_ANENABLE | 2769 - BMCR_ANRESTART); 2770 2505 } 2771 2506 2772 2507 static int rtl8152_suspend(struct usb_interface *intf, pm_message_t message) 2773 2508 { 2774 2509 struct r8152 *tp = usb_get_intfdata(intf); 2775 2510 2776 - netif_device_detach(tp->netdev); 2511 + if (PMSG_IS_AUTO(message)) 2512 + set_bit(SELECTIVE_SUSPEND, &tp->flags); 2513 + else 2514 + netif_device_detach(tp->netdev); 2777 2515 2778 2516 if (netif_running(tp->netdev)) { 2779 2517 clear_bit(WORK_ENABLE, &tp->flags); 2780 2518 usb_kill_urb(tp->intr_urb); 2781 2519 cancel_delayed_work_sync(&tp->schedule); 2782 - tasklet_disable(&tp->tl); 2520 + if (test_bit(SELECTIVE_SUSPEND, &tp->flags)) { 2521 + rtl_runtime_suspend_enable(tp, true); 2522 + } else { 2523 + tasklet_disable(&tp->tl); 2524 + tp->rtl_ops.down(tp); 2525 + tasklet_enable(&tp->tl); 2526 + } 2783 2527 } 2784 - 2785 - tp->rtl_ops.down(tp); 2786 2528 2787 2529 return 0; 2788 2530 } ··· 2795 2529 { 2796 2530 struct r8152 *tp = usb_get_intfdata(intf); 2797 2531 2798 - tp->rtl_ops.init(tp); 2799 - netif_device_attach(tp->netdev); 2532 + if (!test_bit(SELECTIVE_SUSPEND, &tp->flags)) { 2533 + tp->rtl_ops.init(tp); 2534 + netif_device_attach(tp->netdev); 2535 + } 2536 + 2800 2537 if (netif_running(tp->netdev)) { 2801 - rtl8152_set_speed(tp, AUTONEG_ENABLE, 2538 + if (test_bit(SELECTIVE_SUSPEND, &tp->flags)) { 2539 + rtl_runtime_suspend_enable(tp, false); 2540 + clear_bit(SELECTIVE_SUSPEND, &tp->flags); 2541 + if (tp->speed & LINK_STATUS) 2542 + tp->rtl_ops.disable(tp); 2543 + } else { 2544 + tp->rtl_ops.up(tp); 2545 + rtl8152_set_speed(tp, AUTONEG_ENABLE, 2802 2546 tp->mii.supports_gmii ? SPEED_1000 : SPEED_100, 2803 2547 DUPLEX_FULL); 2548 + } 2804 2549 tp->speed = 0; 2805 2550 netif_carrier_off(tp->netdev); 2806 2551 set_bit(WORK_ENABLE, &tp->flags); 2807 2552 usb_submit_urb(tp->intr_urb, GFP_KERNEL); 2808 - tasklet_enable(&tp->tl); 2809 2553 } 2810 2554 2811 2555 return 0; 2556 + } 2557 + 2558 + static void rtl8152_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) 2559 + { 2560 + struct r8152 *tp = netdev_priv(dev); 2561 + 2562 + if (usb_autopm_get_interface(tp->intf) < 0) 2563 + return; 2564 + 2565 + wol->supported = WAKE_ANY; 2566 + wol->wolopts = __rtl_get_wol(tp); 2567 + 2568 + usb_autopm_put_interface(tp->intf); 2569 + } 2570 + 2571 + static int rtl8152_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) 2572 + { 2573 + struct r8152 *tp = netdev_priv(dev); 2574 + int ret; 2575 + 2576 + ret = usb_autopm_get_interface(tp->intf); 2577 + if (ret < 0) 2578 + goto out_set_wol; 2579 + 2580 + __rtl_set_wol(tp, wol->wolopts); 2581 + tp->saved_wolopts = wol->wolopts & WAKE_ANY; 2582 + 2583 + usb_autopm_put_interface(tp->intf); 2584 + 2585 + out_set_wol: 2586 + return ret; 2587 + } 2588 + 2589 + static u32 rtl8152_get_msglevel(struct net_device *dev) 2590 + { 2591 + struct r8152 *tp = netdev_priv(dev); 2592 + 2593 + return tp->msg_enable; 2594 + } 2595 + 2596 + static void rtl8152_set_msglevel(struct net_device *dev, u32 value) 2597 + { 2598 + struct r8152 *tp = netdev_priv(dev); 2599 + 2600 + tp->msg_enable = value; 2812 2601 } 2813 2602 2814 2603 static void rtl8152_get_drvinfo(struct net_device *netdev, ··· 2890 2569 static int rtl8152_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) 2891 2570 { 2892 2571 struct r8152 *tp = netdev_priv(dev); 2572 + int ret; 2893 2573 2894 - return rtl8152_set_speed(tp, cmd->autoneg, cmd->speed, cmd->duplex); 2574 + ret = usb_autopm_get_interface(tp->intf); 2575 + if (ret < 0) 2576 + goto out; 2577 + 2578 + ret = rtl8152_set_speed(tp, cmd->autoneg, cmd->speed, cmd->duplex); 2579 + 2580 + usb_autopm_put_interface(tp->intf); 2581 + 2582 + out: 2583 + return ret; 2895 2584 } 2896 2585 2897 2586 static struct ethtool_ops ops = { ··· 2909 2578 .get_settings = rtl8152_get_settings, 2910 2579 .set_settings = rtl8152_set_settings, 2911 2580 .get_link = ethtool_op_get_link, 2581 + .get_msglevel = rtl8152_get_msglevel, 2582 + .set_msglevel = rtl8152_set_msglevel, 2583 + .get_wol = rtl8152_get_wol, 2584 + .set_wol = rtl8152_set_wol, 2912 2585 }; 2913 2586 2914 2587 static int rtl8152_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd) 2915 2588 { 2916 2589 struct r8152 *tp = netdev_priv(netdev); 2917 2590 struct mii_ioctl_data *data = if_mii(rq); 2918 - int res = 0; 2591 + int res; 2592 + 2593 + res = usb_autopm_get_interface(tp->intf); 2594 + if (res < 0) 2595 + goto out; 2919 2596 2920 2597 switch (cmd) { 2921 2598 case SIOCGMIIPHY: ··· 2946 2607 res = -EOPNOTSUPP; 2947 2608 } 2948 2609 2610 + usb_autopm_put_interface(tp->intf); 2611 + 2612 + out: 2949 2613 return res; 2950 2614 } 2951 2615 ··· 3001 2659 3002 2660 static void rtl8152_unload(struct r8152 *tp) 3003 2661 { 3004 - u32 ocp_data; 3005 - 3006 - if (tp->version != RTL_VER_01) { 3007 - ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_UPS_CTRL); 3008 - ocp_data |= POWER_CUT; 3009 - ocp_write_word(tp, MCU_TYPE_USB, USB_UPS_CTRL, ocp_data); 3010 - } 3011 - 3012 - ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_PM_CTRL_STATUS); 3013 - ocp_data &= ~RESUME_INDICATE; 3014 - ocp_write_word(tp, MCU_TYPE_USB, USB_PM_CTRL_STATUS, ocp_data); 2662 + if (tp->version != RTL_VER_01) 2663 + r8152_power_cut_en(tp, true); 3015 2664 } 3016 2665 3017 2666 static void rtl8153_unload(struct r8152 *tp) 3018 2667 { 3019 - r8153_power_cut_en(tp, 1); 2668 + r8153_power_cut_en(tp, true); 3020 2669 } 3021 2670 3022 2671 static int rtl_ops_init(struct r8152 *tp, const struct usb_device_id *id) ··· 3022 2689 ops->init = r8152b_init; 3023 2690 ops->enable = rtl8152_enable; 3024 2691 ops->disable = rtl8152_disable; 2692 + ops->up = r8152b_exit_oob; 3025 2693 ops->down = rtl8152_down; 3026 2694 ops->unload = rtl8152_unload; 3027 2695 ret = 0; ··· 3031 2697 ops->init = r8153_init; 3032 2698 ops->enable = rtl8153_enable; 3033 2699 ops->disable = rtl8152_disable; 2700 + ops->up = r8153_first_init; 3034 2701 ops->down = rtl8153_down; 3035 2702 ops->unload = rtl8153_unload; 3036 2703 ret = 0; ··· 3047 2712 ops->init = r8153_init; 3048 2713 ops->enable = rtl8153_enable; 3049 2714 ops->disable = rtl8152_disable; 2715 + ops->up = r8153_first_init; 3050 2716 ops->down = rtl8153_down; 3051 2717 ops->unload = rtl8153_unload; 3052 2718 ret = 0; ··· 3111 2775 tp->mii.phy_id = R8152_PHY_ID; 3112 2776 tp->mii.supports_gmii = 0; 3113 2777 2778 + intf->needs_remote_wakeup = 1; 2779 + 3114 2780 r8152b_get_version(tp); 3115 2781 tp->rtl_ops.init(tp); 3116 2782 set_ethernet_addr(tp); 3117 - 3118 - ret = alloc_all_mem(tp); 3119 - if (ret) 3120 - goto out; 3121 2783 3122 2784 usb_set_intfdata(intf, tp); 3123 2785 ··· 3124 2790 netif_err(tp, probe, netdev, "couldn't register the device\n"); 3125 2791 goto out1; 3126 2792 } 2793 + 2794 + tp->saved_wolopts = __rtl_get_wol(tp); 2795 + if (tp->saved_wolopts) 2796 + device_set_wakeup_enable(&udev->dev, true); 2797 + else 2798 + device_set_wakeup_enable(&udev->dev, false); 3127 2799 3128 2800 netif_info(tp, probe, netdev, "%s\n", DRIVER_VERSION); 3129 2801 ··· 3152 2812 tasklet_kill(&tp->tl); 3153 2813 unregister_netdev(tp->netdev); 3154 2814 tp->rtl_ops.unload(tp); 3155 - free_all_mem(tp); 3156 2815 free_netdev(tp->netdev); 3157 2816 } 3158 2817 } ··· 3174 2835 .suspend = rtl8152_suspend, 3175 2836 .resume = rtl8152_resume, 3176 2837 .reset_resume = rtl8152_resume, 2838 + .supports_autosuspend = 1, 2839 + .disable_hub_initiated_lpm = 1, 3177 2840 }; 3178 2841 3179 2842 module_usb_driver(rtl8152_driver);