Lines Matching refs:tp
888 void (*init)(struct r8152 *tp);
889 int (*enable)(struct r8152 *tp);
890 void (*disable)(struct r8152 *tp);
891 void (*up)(struct r8152 *tp);
892 void (*down)(struct r8152 *tp);
893 void (*unload)(struct r8152 *tp);
894 int (*eee_get)(struct r8152 *tp, struct ethtool_eee *eee);
895 int (*eee_set)(struct r8152 *tp, struct ethtool_eee *eee);
896 bool (*in_nway)(struct r8152 *tp);
897 void (*hw_phy_cfg)(struct r8152 *tp);
898 void (*autosuspend_en)(struct r8152 *tp, bool enable);
899 void (*change_mtu)(struct r8152 *tp);
927 int (*pre_fw)(struct r8152 *tp);
928 int (*post_fw)(struct r8152 *tp);
1214 static void rtl_set_inaccessible(struct r8152 *tp) in rtl_set_inaccessible() argument
1216 set_bit(RTL8152_INACCESSIBLE, &tp->flags); in rtl_set_inaccessible()
1220 static void rtl_set_accessible(struct r8152 *tp) in rtl_set_accessible() argument
1222 clear_bit(RTL8152_INACCESSIBLE, &tp->flags); in rtl_set_accessible()
1227 int r8152_control_msg(struct r8152 *tp, unsigned int pipe, __u8 request, in r8152_control_msg() argument
1231 struct usb_device *udev = tp->udev; in r8152_control_msg()
1234 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8152_control_msg()
1249 tp->reg_access_reset_count = 0; in r8152_control_msg()
1263 rtl_set_inaccessible(tp); in r8152_control_msg()
1270 if (!test_bit(PROBED_WITH_NO_ERRORS, &tp->flags)) { in r8152_control_msg()
1271 set_bit(PROBE_SHOULD_RETRY, &tp->flags); in r8152_control_msg()
1283 if (test_bit(IN_PRE_RESET, &tp->flags)) in r8152_control_msg()
1286 if (tp->reg_access_reset_count < REGISTER_ACCESS_MAX_RESETS) { in r8152_control_msg()
1287 usb_queue_reset_device(tp->intf); in r8152_control_msg()
1288 tp->reg_access_reset_count++; in r8152_control_msg()
1289 } else if (tp->reg_access_reset_count == REGISTER_ACCESS_MAX_RESETS) { in r8152_control_msg()
1299 int get_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data) in get_registers() argument
1308 ret = r8152_control_msg(tp, tp->pipe_ctrl_in, in get_registers()
1323 int set_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data) in set_registers() argument
1332 ret = r8152_control_msg(tp, tp->pipe_ctrl_out, in set_registers()
1341 static void rtl_set_unplug(struct r8152 *tp) in rtl_set_unplug() argument
1343 if (tp->udev->state == USB_STATE_NOTATTACHED) in rtl_set_unplug()
1344 rtl_set_inaccessible(tp); in rtl_set_unplug()
1347 static int generic_ocp_read(struct r8152 *tp, u16 index, u16 size, in generic_ocp_read() argument
1353 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in generic_ocp_read()
1365 ret = get_registers(tp, index, type, limit, data); in generic_ocp_read()
1373 ret = get_registers(tp, index, type, size, data); in generic_ocp_read()
1385 rtl_set_unplug(tp); in generic_ocp_read()
1390 static int generic_ocp_write(struct r8152 *tp, u16 index, u16 byteen, in generic_ocp_write() argument
1397 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in generic_ocp_write()
1414 ret = set_registers(tp, index, type | byen, 4, data); in generic_ocp_write()
1432 ret = set_registers(tp, index, in generic_ocp_write()
1442 ret = set_registers(tp, index, in generic_ocp_write()
1457 ret = set_registers(tp, index, type | byen, 4, data); in generic_ocp_write()
1462 rtl_set_unplug(tp); in generic_ocp_write()
1468 int pla_ocp_read(struct r8152 *tp, u16 index, u16 size, void *data) in pla_ocp_read() argument
1470 return generic_ocp_read(tp, index, size, data, MCU_TYPE_PLA); in pla_ocp_read()
1474 int pla_ocp_write(struct r8152 *tp, u16 index, u16 byteen, u16 size, void *data) in pla_ocp_write() argument
1476 return generic_ocp_write(tp, index, byteen, size, data, MCU_TYPE_PLA); in pla_ocp_write()
1480 int usb_ocp_write(struct r8152 *tp, u16 index, u16 byteen, u16 size, void *data) in usb_ocp_write() argument
1482 return generic_ocp_write(tp, index, byteen, size, data, MCU_TYPE_USB); in usb_ocp_write()
1485 static u32 ocp_read_dword(struct r8152 *tp, u16 type, u16 index) in ocp_read_dword() argument
1489 generic_ocp_read(tp, index, sizeof(data), &data, type); in ocp_read_dword()
1494 static void ocp_write_dword(struct r8152 *tp, u16 type, u16 index, u32 data) in ocp_write_dword() argument
1498 generic_ocp_write(tp, index, BYTE_EN_DWORD, sizeof(tmp), &tmp, type); in ocp_write_dword()
1501 static u16 ocp_read_word(struct r8152 *tp, u16 type, u16 index) in ocp_read_word() argument
1511 generic_ocp_read(tp, index, sizeof(tmp), &tmp, type | byen); in ocp_read_word()
1520 static void ocp_write_word(struct r8152 *tp, u16 type, u16 index, u32 data) in ocp_write_word() argument
1538 generic_ocp_write(tp, index, byen, sizeof(tmp), &tmp, type); in ocp_write_word()
1541 static u8 ocp_read_byte(struct r8152 *tp, u16 type, u16 index) in ocp_read_byte() argument
1549 generic_ocp_read(tp, index, sizeof(tmp), &tmp, type); in ocp_read_byte()
1558 static void ocp_write_byte(struct r8152 *tp, u16 type, u16 index, u32 data) in ocp_write_byte() argument
1576 generic_ocp_write(tp, index, byen, sizeof(tmp), &tmp, type); in ocp_write_byte()
1579 static u16 ocp_reg_read(struct r8152 *tp, u16 addr) in ocp_reg_read() argument
1584 if (ocp_base != tp->ocp_base) { in ocp_reg_read()
1585 ocp_write_word(tp, MCU_TYPE_PLA, PLA_OCP_GPHY_BASE, ocp_base); in ocp_reg_read()
1586 tp->ocp_base = ocp_base; in ocp_reg_read()
1590 return ocp_read_word(tp, MCU_TYPE_PLA, ocp_index); in ocp_reg_read()
1593 static void ocp_reg_write(struct r8152 *tp, u16 addr, u16 data) in ocp_reg_write() argument
1598 if (ocp_base != tp->ocp_base) { in ocp_reg_write()
1599 ocp_write_word(tp, MCU_TYPE_PLA, PLA_OCP_GPHY_BASE, ocp_base); in ocp_reg_write()
1600 tp->ocp_base = ocp_base; in ocp_reg_write()
1604 ocp_write_word(tp, MCU_TYPE_PLA, ocp_index, data); in ocp_reg_write()
1607 static inline void r8152_mdio_write(struct r8152 *tp, u32 reg_addr, u32 value) in r8152_mdio_write() argument
1609 ocp_reg_write(tp, OCP_BASE_MII + reg_addr * 2, value); in r8152_mdio_write()
1612 static inline int r8152_mdio_read(struct r8152 *tp, u32 reg_addr) in r8152_mdio_read() argument
1614 return ocp_reg_read(tp, OCP_BASE_MII + reg_addr * 2); in r8152_mdio_read()
1617 static void sram_write(struct r8152 *tp, u16 addr, u16 data) in sram_write() argument
1619 ocp_reg_write(tp, OCP_SRAM_ADDR, addr); in sram_write()
1620 ocp_reg_write(tp, OCP_SRAM_DATA, data); in sram_write()
1623 static u16 sram_read(struct r8152 *tp, u16 addr) in sram_read() argument
1625 ocp_reg_write(tp, OCP_SRAM_ADDR, addr); in sram_read()
1626 return ocp_reg_read(tp, OCP_SRAM_DATA); in sram_read()
1631 struct r8152 *tp = netdev_priv(netdev); in read_mii_word() local
1634 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in read_mii_word()
1640 ret = r8152_mdio_read(tp, reg); in read_mii_word()
1648 struct r8152 *tp = netdev_priv(netdev); in write_mii_word() local
1650 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in write_mii_word()
1656 r8152_mdio_write(tp, reg, val); in write_mii_word()
1660 r8152_submit_rx(struct r8152 *tp, struct rx_agg *agg, gfp_t mem_flags);
1663 rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u32 speed, u8 duplex,
1669 struct r8152 *tp = netdev_priv(netdev); in __rtl8152_set_mac_address() local
1677 ret = usb_autopm_get_interface(tp->intf); in __rtl8152_set_mac_address()
1682 mutex_lock(&tp->control); in __rtl8152_set_mac_address()
1686 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_CONFIG); in __rtl8152_set_mac_address()
1687 pla_ocp_write(tp, PLA_IDR, BYTE_EN_SIX_BYTES, 8, addr->sa_data); in __rtl8152_set_mac_address()
1688 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML); in __rtl8152_set_mac_address()
1690 mutex_unlock(&tp->control); in __rtl8152_set_mac_address()
1693 usb_autopm_put_interface(tp->intf); in __rtl8152_set_mac_address()
1707 static int vendor_mac_passthru_addr_read(struct r8152 *tp, struct sockaddr *sa) in vendor_mac_passthru_addr_read() argument
1719 if (tp->lenovo_macpassthru) { in vendor_mac_passthru_addr_read()
1725 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0); in vendor_mac_passthru_addr_read()
1728 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, EFUSE); in vendor_mac_passthru_addr_read()
1730 netif_dbg(tp, probe, tp->netdev, in vendor_mac_passthru_addr_read()
1736 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_MISC_1); in vendor_mac_passthru_addr_read()
1738 netif_dbg(tp, probe, tp->netdev, in vendor_mac_passthru_addr_read()
1755 netif_warn(tp, probe, tp->netdev, in vendor_mac_passthru_addr_read()
1763 netif_warn(tp, probe, tp->netdev, in vendor_mac_passthru_addr_read()
1769 netif_warn(tp, probe, tp->netdev, in vendor_mac_passthru_addr_read()
1776 netif_info(tp, probe, tp->netdev, in vendor_mac_passthru_addr_read()
1784 static int determine_ethernet_addr(struct r8152 *tp, struct sockaddr *sa) in determine_ethernet_addr() argument
1786 struct net_device *dev = tp->netdev; in determine_ethernet_addr()
1791 ret = eth_platform_get_mac_address(&tp->udev->dev, sa->sa_data); in determine_ethernet_addr()
1793 if (tp->version == RTL_VER_01) { in determine_ethernet_addr()
1794 ret = pla_ocp_read(tp, PLA_IDR, 8, sa->sa_data); in determine_ethernet_addr()
1799 ret = vendor_mac_passthru_addr_read(tp, sa); in determine_ethernet_addr()
1801 ret = pla_ocp_read(tp, PLA_BACKUP, 8, in determine_ethernet_addr()
1807 netif_err(tp, probe, dev, "Get ether addr fail\n"); in determine_ethernet_addr()
1809 netif_err(tp, probe, dev, "Invalid ether addr %pM\n", in determine_ethernet_addr()
1813 netif_info(tp, probe, dev, "Random ether addr %pM\n", in determine_ethernet_addr()
1821 static int set_ethernet_addr(struct r8152 *tp, bool in_resume) in set_ethernet_addr() argument
1823 struct net_device *dev = tp->netdev; in set_ethernet_addr()
1827 ret = determine_ethernet_addr(tp, &sa); in set_ethernet_addr()
1831 if (tp->version == RTL_VER_01) in set_ethernet_addr()
1844 struct r8152 *tp; in read_bulk_callback() local
1851 tp = agg->context; in read_bulk_callback()
1852 if (!tp) in read_bulk_callback()
1855 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in read_bulk_callback()
1858 if (!test_bit(WORK_ENABLE, &tp->flags)) in read_bulk_callback()
1861 netdev = tp->netdev; in read_bulk_callback()
1868 usb_mark_last_busy(tp->udev); in read_bulk_callback()
1875 spin_lock_irqsave(&tp->rx_lock, flags); in read_bulk_callback()
1876 list_add_tail(&agg->list, &tp->rx_done); in read_bulk_callback()
1877 spin_unlock_irqrestore(&tp->rx_lock, flags); in read_bulk_callback()
1878 napi_schedule(&tp->napi); in read_bulk_callback()
1881 rtl_set_unplug(tp); in read_bulk_callback()
1882 netif_device_detach(tp->netdev); in read_bulk_callback()
1886 spin_lock_irqsave(&tp->rx_lock, flags); in read_bulk_callback()
1887 list_add_tail(&agg->list, &tp->rx_done); in read_bulk_callback()
1888 spin_unlock_irqrestore(&tp->rx_lock, flags); in read_bulk_callback()
1889 set_bit(RX_EPROTO, &tp->flags); in read_bulk_callback()
1890 schedule_delayed_work(&tp->schedule, 1); in read_bulk_callback()
1904 r8152_submit_rx(tp, agg, GFP_ATOMIC); in read_bulk_callback()
1912 struct r8152 *tp; in write_bulk_callback() local
1920 tp = agg->context; in write_bulk_callback()
1921 if (!tp) in write_bulk_callback()
1924 netdev = tp->netdev; in write_bulk_callback()
1935 spin_lock_irqsave(&tp->tx_lock, flags); in write_bulk_callback()
1936 list_add_tail(&agg->list, &tp->tx_free); in write_bulk_callback()
1937 spin_unlock_irqrestore(&tp->tx_lock, flags); in write_bulk_callback()
1939 usb_autopm_put_interface_async(tp->intf); in write_bulk_callback()
1944 if (!test_bit(WORK_ENABLE, &tp->flags)) in write_bulk_callback()
1947 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in write_bulk_callback()
1950 if (!skb_queue_empty(&tp->tx_queue)) in write_bulk_callback()
1951 tasklet_schedule(&tp->tx_tl); in write_bulk_callback()
1956 struct r8152 *tp; in intr_callback() local
1961 tp = urb->context; in intr_callback()
1962 if (!tp) in intr_callback()
1965 if (!test_bit(WORK_ENABLE, &tp->flags)) in intr_callback()
1968 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in intr_callback()
1976 netif_device_detach(tp->netdev); in intr_callback()
1980 netif_info(tp, intr, tp->netdev, in intr_callback()
1985 netif_info(tp, intr, tp->netdev, in intr_callback()
1990 netif_info(tp, intr, tp->netdev, "intr status %d\n", status); in intr_callback()
1996 if (!netif_carrier_ok(tp->netdev)) { in intr_callback()
1997 set_bit(RTL8152_LINK_CHG, &tp->flags); in intr_callback()
1998 schedule_delayed_work(&tp->schedule, 0); in intr_callback()
2001 if (netif_carrier_ok(tp->netdev)) { in intr_callback()
2002 netif_stop_queue(tp->netdev); in intr_callback()
2003 set_bit(RTL8152_LINK_CHG, &tp->flags); in intr_callback()
2004 schedule_delayed_work(&tp->schedule, 0); in intr_callback()
2011 rtl_set_unplug(tp); in intr_callback()
2012 netif_device_detach(tp->netdev); in intr_callback()
2014 netif_err(tp, intr, tp->netdev, in intr_callback()
2029 static void free_rx_agg(struct r8152 *tp, struct rx_agg *agg) in free_rx_agg() argument
2037 atomic_dec(&tp->rx_count); in free_rx_agg()
2040 static struct rx_agg *alloc_rx_agg(struct r8152 *tp, gfp_t mflags) in alloc_rx_agg() argument
2042 struct net_device *netdev = tp->netdev; in alloc_rx_agg()
2044 unsigned int order = get_order(tp->rx_buf_sz); in alloc_rx_agg()
2062 rx_agg->context = tp; in alloc_rx_agg()
2066 spin_lock_irqsave(&tp->rx_lock, flags); in alloc_rx_agg()
2067 list_add_tail(&rx_agg->info_list, &tp->rx_info); in alloc_rx_agg()
2068 spin_unlock_irqrestore(&tp->rx_lock, flags); in alloc_rx_agg()
2070 atomic_inc(&tp->rx_count); in alloc_rx_agg()
2081 static void free_all_mem(struct r8152 *tp) in free_all_mem() argument
2087 spin_lock_irqsave(&tp->rx_lock, flags); in free_all_mem()
2089 list_for_each_entry_safe(agg, agg_next, &tp->rx_info, info_list) in free_all_mem()
2090 free_rx_agg(tp, agg); in free_all_mem()
2092 spin_unlock_irqrestore(&tp->rx_lock, flags); in free_all_mem()
2094 WARN_ON(atomic_read(&tp->rx_count)); in free_all_mem()
2097 usb_free_urb(tp->tx_info[i].urb); in free_all_mem()
2098 tp->tx_info[i].urb = NULL; in free_all_mem()
2100 kfree(tp->tx_info[i].buffer); in free_all_mem()
2101 tp->tx_info[i].buffer = NULL; in free_all_mem()
2102 tp->tx_info[i].head = NULL; in free_all_mem()
2105 usb_free_urb(tp->intr_urb); in free_all_mem()
2106 tp->intr_urb = NULL; in free_all_mem()
2108 kfree(tp->intr_buff); in free_all_mem()
2109 tp->intr_buff = NULL; in free_all_mem()
2112 static int alloc_all_mem(struct r8152 *tp) in alloc_all_mem() argument
2114 struct net_device *netdev = tp->netdev; in alloc_all_mem()
2115 struct usb_interface *intf = tp->intf; in alloc_all_mem()
2122 spin_lock_init(&tp->rx_lock); in alloc_all_mem()
2123 spin_lock_init(&tp->tx_lock); in alloc_all_mem()
2124 INIT_LIST_HEAD(&tp->rx_info); in alloc_all_mem()
2125 INIT_LIST_HEAD(&tp->tx_free); in alloc_all_mem()
2126 INIT_LIST_HEAD(&tp->rx_done); in alloc_all_mem()
2127 skb_queue_head_init(&tp->tx_queue); in alloc_all_mem()
2128 skb_queue_head_init(&tp->rx_queue); in alloc_all_mem()
2129 atomic_set(&tp->rx_count, 0); in alloc_all_mem()
2132 if (!alloc_rx_agg(tp, GFP_KERNEL)) in alloc_all_mem()
2158 INIT_LIST_HEAD(&tp->tx_info[i].list); in alloc_all_mem()
2159 tp->tx_info[i].context = tp; in alloc_all_mem()
2160 tp->tx_info[i].urb = urb; in alloc_all_mem()
2161 tp->tx_info[i].buffer = buf; in alloc_all_mem()
2162 tp->tx_info[i].head = tx_agg_align(buf); in alloc_all_mem()
2164 list_add_tail(&tp->tx_info[i].list, &tp->tx_free); in alloc_all_mem()
2167 tp->intr_urb = usb_alloc_urb(0, GFP_KERNEL); in alloc_all_mem()
2168 if (!tp->intr_urb) in alloc_all_mem()
2171 tp->intr_buff = kmalloc(INTBUFSIZE, GFP_KERNEL); in alloc_all_mem()
2172 if (!tp->intr_buff) in alloc_all_mem()
2175 tp->intr_interval = (int)ep_intr->desc.bInterval; in alloc_all_mem()
2176 usb_fill_int_urb(tp->intr_urb, tp->udev, tp->pipe_intr, in alloc_all_mem()
2177 tp->intr_buff, INTBUFSIZE, intr_callback, in alloc_all_mem()
2178 tp, tp->intr_interval); in alloc_all_mem()
2183 free_all_mem(tp); in alloc_all_mem()
2187 static struct tx_agg *r8152_get_tx_agg(struct r8152 *tp) in r8152_get_tx_agg() argument
2192 if (list_empty(&tp->tx_free)) in r8152_get_tx_agg()
2195 spin_lock_irqsave(&tp->tx_lock, flags); in r8152_get_tx_agg()
2196 if (!list_empty(&tp->tx_free)) { in r8152_get_tx_agg()
2199 cursor = tp->tx_free.next; in r8152_get_tx_agg()
2203 spin_unlock_irqrestore(&tp->tx_lock, flags); in r8152_get_tx_agg()
2212 static void r8152_csum_workaround(struct r8152 *tp, struct sk_buff *skb, in r8152_csum_workaround() argument
2216 netdev_features_t features = tp->netdev->features; in r8152_csum_workaround()
2243 stats = &tp->netdev->stats; in r8152_csum_workaround()
2268 static int r8152_tx_csum(struct r8152 *tp, struct tx_desc *desc, in r8152_tx_csum() argument
2283 netif_warn(tp, tx_err, tp->netdev, in r8152_tx_csum()
2316 netif_warn(tp, tx_err, tp->netdev, in r8152_tx_csum()
2356 static int r8152_tx_agg_fill(struct r8152 *tp, struct tx_agg *agg) in r8152_tx_agg_fill() argument
2358 struct sk_buff_head skb_head, *tx_queue = &tp->tx_queue; in r8152_tx_agg_fill()
2391 if (r8152_tx_csum(tp, tx_desc, skb, skb->len)) { in r8152_tx_agg_fill()
2392 r8152_csum_workaround(tp, skb, &skb_head); in r8152_tx_agg_fill()
2402 struct net_device_stats *stats = &tp->netdev->stats; in r8152_tx_agg_fill()
2418 if (tp->dell_tb_rx_agg_bug) in r8152_tx_agg_fill()
2428 netif_tx_lock(tp->netdev); in r8152_tx_agg_fill()
2430 if (netif_queue_stopped(tp->netdev) && in r8152_tx_agg_fill()
2431 skb_queue_len(&tp->tx_queue) < tp->tx_qlen) in r8152_tx_agg_fill()
2432 netif_wake_queue(tp->netdev); in r8152_tx_agg_fill()
2434 netif_tx_unlock(tp->netdev); in r8152_tx_agg_fill()
2436 ret = usb_autopm_get_interface_async(tp->intf); in r8152_tx_agg_fill()
2440 usb_fill_bulk_urb(agg->urb, tp->udev, tp->pipe_out, in r8152_tx_agg_fill()
2446 usb_autopm_put_interface_async(tp->intf); in r8152_tx_agg_fill()
2452 static u8 r8152_rx_csum(struct r8152 *tp, struct rx_desc *rx_desc) in r8152_rx_csum() argument
2457 if (!(tp->netdev->features & NETIF_F_RXCSUM)) in r8152_rx_csum()
2481 static inline bool rx_count_exceed(struct r8152 *tp) in rx_count_exceed() argument
2483 return atomic_read(&tp->rx_count) > RTL8152_MAX_RX; in rx_count_exceed()
2491 static struct rx_agg *rtl_get_free_rx(struct r8152 *tp, gfp_t mflags) in rtl_get_free_rx() argument
2496 spin_lock_irqsave(&tp->rx_lock, flags); in rtl_get_free_rx()
2498 list_for_each_entry_safe(agg, agg_next, &tp->rx_used, list) { in rtl_get_free_rx()
2505 if (rx_count_exceed(tp)) { in rtl_get_free_rx()
2507 free_rx_agg(tp, agg); in rtl_get_free_rx()
2513 spin_unlock_irqrestore(&tp->rx_lock, flags); in rtl_get_free_rx()
2515 if (!agg_free && atomic_read(&tp->rx_count) < tp->rx_pending) in rtl_get_free_rx()
2516 agg_free = alloc_rx_agg(tp, mflags); in rtl_get_free_rx()
2521 static int rx_bottom(struct r8152 *tp, int budget) in rx_bottom() argument
2526 struct napi_struct *napi = &tp->napi; in rx_bottom()
2528 if (!skb_queue_empty(&tp->rx_queue)) { in rx_bottom()
2530 struct sk_buff *skb = __skb_dequeue(&tp->rx_queue); in rx_bottom()
2531 struct net_device *netdev = tp->netdev; in rx_bottom()
2546 if (list_empty(&tp->rx_done) || work_done >= budget) in rx_bottom()
2549 clear_bit(RX_EPROTO, &tp->flags); in rx_bottom()
2551 spin_lock_irqsave(&tp->rx_lock, flags); in rx_bottom()
2552 list_splice_init(&tp->rx_done, &rx_queue); in rx_bottom()
2553 spin_unlock_irqrestore(&tp->rx_lock, flags); in rx_bottom()
2578 agg_free = rtl_get_free_rx(tp, GFP_ATOMIC); in rx_bottom()
2585 struct net_device *netdev = tp->netdev; in rx_bottom()
2590 WARN_ON_ONCE(skb_queue_len(&tp->rx_queue) >= 1000); in rx_bottom()
2603 if (!agg_free || tp->rx_copybreak > pkt_len) in rx_bottom()
2606 rx_frag_head_sz = tp->rx_copybreak; in rx_bottom()
2614 skb->ip_summed = r8152_rx_csum(tp, rx_desc); in rx_bottom()
2635 __skb_queue_tail(&tp->rx_queue, skb); in rx_bottom()
2648 spin_lock_irqsave(&tp->rx_lock, flags); in rx_bottom()
2650 list_add(&agg_free->list, &tp->rx_used); in rx_bottom()
2652 list_add_tail(&agg->list, &tp->rx_used); in rx_bottom()
2656 spin_unlock_irqrestore(&tp->rx_lock, flags); in rx_bottom()
2661 ret = r8152_submit_rx(tp, agg, GFP_ATOMIC); in rx_bottom()
2670 spin_lock_irqsave(&tp->rx_lock, flags); in rx_bottom()
2671 list_splice(&rx_queue, &tp->rx_done); in rx_bottom()
2672 spin_unlock_irqrestore(&tp->rx_lock, flags); in rx_bottom()
2679 static void tx_bottom(struct r8152 *tp) in tx_bottom() argument
2684 struct net_device *netdev = tp->netdev; in tx_bottom()
2687 if (skb_queue_empty(&tp->tx_queue)) in tx_bottom()
2690 agg = r8152_get_tx_agg(tp); in tx_bottom()
2694 res = r8152_tx_agg_fill(tp, agg); in tx_bottom()
2699 rtl_set_unplug(tp); in tx_bottom()
2705 netif_warn(tp, tx_err, netdev, in tx_bottom()
2709 spin_lock_irqsave(&tp->tx_lock, flags); in tx_bottom()
2710 list_add_tail(&agg->list, &tp->tx_free); in tx_bottom()
2711 spin_unlock_irqrestore(&tp->tx_lock, flags); in tx_bottom()
2718 struct r8152 *tp = from_tasklet(tp, t, tx_tl); in bottom_half() local
2720 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in bottom_half()
2723 if (!test_bit(WORK_ENABLE, &tp->flags)) in bottom_half()
2728 if (!netif_carrier_ok(tp->netdev)) in bottom_half()
2731 clear_bit(SCHEDULE_TASKLET, &tp->flags); in bottom_half()
2733 tx_bottom(tp); in bottom_half()
2738 struct r8152 *tp = container_of(napi, struct r8152, napi); in r8152_poll() local
2744 work_done = rx_bottom(tp, budget); in r8152_poll()
2749 if (!list_empty(&tp->rx_done)) in r8152_poll()
2758 int r8152_submit_rx(struct r8152 *tp, struct rx_agg *agg, gfp_t mem_flags) in r8152_submit_rx() argument
2763 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags) || in r8152_submit_rx()
2764 !test_bit(WORK_ENABLE, &tp->flags) || !netif_carrier_ok(tp->netdev)) in r8152_submit_rx()
2767 usb_fill_bulk_urb(agg->urb, tp->udev, tp->pipe_in, in r8152_submit_rx()
2768 agg->buffer, tp->rx_buf_sz, in r8152_submit_rx()
2773 rtl_set_unplug(tp); in r8152_submit_rx()
2774 netif_device_detach(tp->netdev); in r8152_submit_rx()
2780 spin_lock_irqsave(&tp->rx_lock, flags); in r8152_submit_rx()
2781 list_add_tail(&agg->list, &tp->rx_done); in r8152_submit_rx()
2782 spin_unlock_irqrestore(&tp->rx_lock, flags); in r8152_submit_rx()
2784 netif_err(tp, rx_err, tp->netdev, in r8152_submit_rx()
2787 napi_schedule(&tp->napi); in r8152_submit_rx()
2793 static void rtl_drop_queued_tx(struct r8152 *tp) in rtl_drop_queued_tx() argument
2795 struct net_device_stats *stats = &tp->netdev->stats; in rtl_drop_queued_tx()
2796 struct sk_buff_head skb_head, *tx_queue = &tp->tx_queue; in rtl_drop_queued_tx()
2815 struct r8152 *tp = netdev_priv(netdev); in rtl8152_tx_timeout() local
2817 netif_warn(tp, tx_err, netdev, "Tx timeout\n"); in rtl8152_tx_timeout()
2819 usb_queue_reset_device(tp->intf); in rtl8152_tx_timeout()
2824 struct r8152 *tp = netdev_priv(netdev); in rtl8152_set_rx_mode() local
2827 set_bit(RTL8152_SET_RX_MODE, &tp->flags); in rtl8152_set_rx_mode()
2828 schedule_delayed_work(&tp->schedule, 0); in rtl8152_set_rx_mode()
2834 struct r8152 *tp = netdev_priv(netdev); in _rtl8152_set_rx_mode() local
2840 ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); in _rtl8152_set_rx_mode()
2846 netif_notice(tp, link, netdev, "Promiscuous mode enabled\n"); in _rtl8152_set_rx_mode()
2876 pla_ocp_write(tp, PLA_MAR, BYTE_EN_DWORD, sizeof(tmp), tmp); in _rtl8152_set_rx_mode()
2877 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); in _rtl8152_set_rx_mode()
2900 struct r8152 *tp = netdev_priv(netdev); in rtl8152_start_xmit() local
2904 skb_queue_tail(&tp->tx_queue, skb); in rtl8152_start_xmit()
2906 if (!list_empty(&tp->tx_free)) { in rtl8152_start_xmit()
2907 if (test_bit(SELECTIVE_SUSPEND, &tp->flags)) { in rtl8152_start_xmit()
2908 set_bit(SCHEDULE_TASKLET, &tp->flags); in rtl8152_start_xmit()
2909 schedule_delayed_work(&tp->schedule, 0); in rtl8152_start_xmit()
2911 usb_mark_last_busy(tp->udev); in rtl8152_start_xmit()
2912 tasklet_schedule(&tp->tx_tl); in rtl8152_start_xmit()
2914 } else if (skb_queue_len(&tp->tx_queue) > tp->tx_qlen) { in rtl8152_start_xmit()
2921 static void r8152b_reset_packet_filter(struct r8152 *tp) in r8152b_reset_packet_filter() argument
2925 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_FMC); in r8152b_reset_packet_filter()
2927 ocp_write_word(tp, MCU_TYPE_PLA, PLA_FMC, ocp_data); in r8152b_reset_packet_filter()
2929 ocp_write_word(tp, MCU_TYPE_PLA, PLA_FMC, ocp_data); in r8152b_reset_packet_filter()
2932 static void rtl8152_nic_reset(struct r8152 *tp) in rtl8152_nic_reset() argument
2937 switch (tp->version) { in rtl8152_nic_reset()
2941 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CR); in rtl8152_nic_reset()
2943 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CR, ocp_data); in rtl8152_nic_reset()
2945 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_BMU_RESET); in rtl8152_nic_reset()
2947 ocp_write_word(tp, MCU_TYPE_USB, USB_BMU_RESET, ocp_data); in rtl8152_nic_reset()
2949 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL); in rtl8152_nic_reset()
2951 ocp_write_word(tp, MCU_TYPE_USB, USB_USB_CTRL, ocp_data); in rtl8152_nic_reset()
2953 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CR); in rtl8152_nic_reset()
2955 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CR, ocp_data); in rtl8152_nic_reset()
2957 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_BMU_RESET); in rtl8152_nic_reset()
2959 ocp_write_word(tp, MCU_TYPE_USB, USB_BMU_RESET, ocp_data); in rtl8152_nic_reset()
2961 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL); in rtl8152_nic_reset()
2963 ocp_write_word(tp, MCU_TYPE_USB, USB_USB_CTRL, ocp_data); in rtl8152_nic_reset()
2967 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CR, CR_RST); in rtl8152_nic_reset()
2970 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl8152_nic_reset()
2972 if (!(ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CR) & CR_RST)) in rtl8152_nic_reset()
2980 static void set_tx_qlen(struct r8152 *tp) in set_tx_qlen() argument
2982 tp->tx_qlen = agg_buf_sz / (mtu_to_size(tp->netdev->mtu) + sizeof(struct tx_desc)); in set_tx_qlen()
2985 static inline u16 rtl8152_get_speed(struct r8152 *tp) in rtl8152_get_speed() argument
2987 return ocp_read_word(tp, MCU_TYPE_PLA, PLA_PHYSTATUS); in rtl8152_get_speed()
2990 static void rtl_eee_plus_en(struct r8152 *tp, bool enable) in rtl_eee_plus_en() argument
2994 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EEEP_CR); in rtl_eee_plus_en()
2999 ocp_write_word(tp, MCU_TYPE_PLA, PLA_EEEP_CR, ocp_data); in rtl_eee_plus_en()
3002 static void rtl_set_eee_plus(struct r8152 *tp) in rtl_set_eee_plus() argument
3004 if (rtl8152_get_speed(tp) & _10bps) in rtl_set_eee_plus()
3005 rtl_eee_plus_en(tp, true); in rtl_set_eee_plus()
3007 rtl_eee_plus_en(tp, false); in rtl_set_eee_plus()
3010 static void rxdy_gated_en(struct r8152 *tp, bool enable) in rxdy_gated_en() argument
3014 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MISC_1); in rxdy_gated_en()
3019 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MISC_1, ocp_data); in rxdy_gated_en()
3022 static int rtl_start_rx(struct r8152 *tp) in rtl_start_rx() argument
3031 spin_lock_irqsave(&tp->rx_lock, flags); in rtl_start_rx()
3033 INIT_LIST_HEAD(&tp->rx_done); in rtl_start_rx()
3034 INIT_LIST_HEAD(&tp->rx_used); in rtl_start_rx()
3036 list_splice_init(&tp->rx_info, &tmp_list); in rtl_start_rx()
3038 spin_unlock_irqrestore(&tp->rx_lock, flags); in rtl_start_rx()
3045 spin_lock_irqsave(&tp->rx_lock, flags); in rtl_start_rx()
3046 list_add_tail(&agg->list, &tp->rx_used); in rtl_start_rx()
3047 spin_unlock_irqrestore(&tp->rx_lock, flags); in rtl_start_rx()
3049 spin_lock_irqsave(&tp->rx_lock, flags); in rtl_start_rx()
3050 list_add_tail(&agg->list, &tp->rx_done); in rtl_start_rx()
3051 spin_unlock_irqrestore(&tp->rx_lock, flags); in rtl_start_rx()
3053 ret = r8152_submit_rx(tp, agg, GFP_KERNEL); in rtl_start_rx()
3057 spin_lock_irqsave(&tp->rx_lock, flags); in rtl_start_rx()
3058 WARN_ON(!list_empty(&tp->rx_info)); in rtl_start_rx()
3059 list_splice(&tmp_list, &tp->rx_info); in rtl_start_rx()
3060 spin_unlock_irqrestore(&tp->rx_lock, flags); in rtl_start_rx()
3065 static int rtl_stop_rx(struct r8152 *tp) in rtl_stop_rx() argument
3079 spin_lock_irqsave(&tp->rx_lock, flags); in rtl_stop_rx()
3080 list_splice_init(&tp->rx_info, &tmp_list); in rtl_stop_rx()
3081 spin_unlock_irqrestore(&tp->rx_lock, flags); in rtl_stop_rx()
3088 free_rx_agg(tp, agg); in rtl_stop_rx()
3094 spin_lock_irqsave(&tp->rx_lock, flags); in rtl_stop_rx()
3095 WARN_ON(!list_empty(&tp->rx_info)); in rtl_stop_rx()
3096 list_splice(&tmp_list, &tp->rx_info); in rtl_stop_rx()
3097 spin_unlock_irqrestore(&tp->rx_lock, flags); in rtl_stop_rx()
3099 while (!skb_queue_empty(&tp->rx_queue)) in rtl_stop_rx()
3100 dev_kfree_skb(__skb_dequeue(&tp->rx_queue)); in rtl_stop_rx()
3105 static void rtl_set_ifg(struct r8152 *tp, u16 speed) in rtl_set_ifg() argument
3109 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TCR1); in rtl_set_ifg()
3113 ocp_write_word(tp, MCU_TYPE_PLA, PLA_TCR1, ocp_data); in rtl_set_ifg()
3115 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4); in rtl_set_ifg()
3117 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4, ocp_data); in rtl_set_ifg()
3120 ocp_write_word(tp, MCU_TYPE_PLA, PLA_TCR1, ocp_data); in rtl_set_ifg()
3122 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4); in rtl_set_ifg()
3124 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4, ocp_data); in rtl_set_ifg()
3128 static inline void r8153b_rx_agg_chg_indicate(struct r8152 *tp) in r8153b_rx_agg_chg_indicate() argument
3130 ocp_write_byte(tp, MCU_TYPE_USB, USB_UPT_RXDMA_OWN, in r8153b_rx_agg_chg_indicate()
3134 static int rtl_enable(struct r8152 *tp) in rtl_enable() argument
3138 r8152b_reset_packet_filter(tp); in rtl_enable()
3140 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CR); in rtl_enable()
3142 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CR, ocp_data); in rtl_enable()
3144 switch (tp->version) { in rtl_enable()
3154 r8153b_rx_agg_chg_indicate(tp); in rtl_enable()
3158 rxdy_gated_en(tp, false); in rtl_enable()
3163 static int rtl8152_enable(struct r8152 *tp) in rtl8152_enable() argument
3165 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl8152_enable()
3168 set_tx_qlen(tp); in rtl8152_enable()
3169 rtl_set_eee_plus(tp); in rtl8152_enable()
3171 return rtl_enable(tp); in rtl8152_enable()
3174 static void r8153_set_rx_early_timeout(struct r8152 *tp) in r8153_set_rx_early_timeout() argument
3176 u32 ocp_data = tp->coalesce / 8; in r8153_set_rx_early_timeout()
3178 switch (tp->version) { in r8153_set_rx_early_timeout()
3183 ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_TIMEOUT, in r8153_set_rx_early_timeout()
3193 ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_TIMEOUT, in r8153_set_rx_early_timeout()
3195 ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EXTRA_AGGR_TMR, in r8153_set_rx_early_timeout()
3204 ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_TIMEOUT, in r8153_set_rx_early_timeout()
3206 ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EXTRA_AGGR_TMR, in r8153_set_rx_early_timeout()
3215 static void r8153_set_rx_early_size(struct r8152 *tp) in r8153_set_rx_early_size() argument
3217 u32 ocp_data = tp->rx_buf_sz - rx_reserved_size(tp->netdev->mtu); in r8153_set_rx_early_size()
3219 switch (tp->version) { in r8153_set_rx_early_size()
3224 ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_SIZE, in r8153_set_rx_early_size()
3230 ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_SIZE, in r8153_set_rx_early_size()
3239 ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_SIZE, in r8153_set_rx_early_size()
3248 static int rtl8153_enable(struct r8152 *tp) in rtl8153_enable() argument
3252 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl8153_enable()
3255 set_tx_qlen(tp); in rtl8153_enable()
3256 rtl_set_eee_plus(tp); in rtl8153_enable()
3257 r8153_set_rx_early_timeout(tp); in rtl8153_enable()
3258 r8153_set_rx_early_size(tp); in rtl8153_enable()
3260 rtl_set_ifg(tp, rtl8152_get_speed(tp)); in rtl8153_enable()
3262 switch (tp->version) { in rtl8153_enable()
3265 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_TASK); in rtl8153_enable()
3267 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_TASK, ocp_data); in rtl8153_enable()
3270 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_TASK, ocp_data); in rtl8153_enable()
3276 return rtl_enable(tp); in rtl8153_enable()
3279 static void rtl_disable(struct r8152 *tp) in rtl_disable() argument
3284 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) { in rtl_disable()
3285 rtl_drop_queued_tx(tp); in rtl_disable()
3289 ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); in rtl_disable()
3291 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); in rtl_disable()
3293 rtl_drop_queued_tx(tp); in rtl_disable()
3296 usb_kill_urb(tp->tx_info[i].urb); in rtl_disable()
3298 rxdy_gated_en(tp, true); in rtl_disable()
3301 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl_disable()
3303 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); in rtl_disable()
3310 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl_disable()
3312 if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_TCR0) & TCR0_TX_EMPTY) in rtl_disable()
3317 rtl_stop_rx(tp); in rtl_disable()
3319 rtl8152_nic_reset(tp); in rtl_disable()
3322 static void r8152_power_cut_en(struct r8152 *tp, bool enable) in r8152_power_cut_en() argument
3326 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_UPS_CTRL); in r8152_power_cut_en()
3331 ocp_write_word(tp, MCU_TYPE_USB, USB_UPS_CTRL, ocp_data); in r8152_power_cut_en()
3333 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_PM_CTRL_STATUS); in r8152_power_cut_en()
3335 ocp_write_word(tp, MCU_TYPE_USB, USB_PM_CTRL_STATUS, ocp_data); in r8152_power_cut_en()
3338 static void rtl_rx_vlan_en(struct r8152 *tp, bool enable) in rtl_rx_vlan_en() argument
3342 switch (tp->version) { in rtl_rx_vlan_en()
3353 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CPCR); in rtl_rx_vlan_en()
3358 ocp_write_word(tp, MCU_TYPE_PLA, PLA_CPCR, ocp_data); in rtl_rx_vlan_en()
3368 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_RCR1); in rtl_rx_vlan_en()
3373 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RCR1, ocp_data); in rtl_rx_vlan_en()
3382 struct r8152 *tp = netdev_priv(dev); in rtl8152_set_features() local
3385 ret = usb_autopm_get_interface(tp->intf); in rtl8152_set_features()
3389 mutex_lock(&tp->control); in rtl8152_set_features()
3393 rtl_rx_vlan_en(tp, true); in rtl8152_set_features()
3395 rtl_rx_vlan_en(tp, false); in rtl8152_set_features()
3398 mutex_unlock(&tp->control); in rtl8152_set_features()
3400 usb_autopm_put_interface(tp->intf); in rtl8152_set_features()
3408 static u32 __rtl_get_wol(struct r8152 *tp) in __rtl_get_wol() argument
3413 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CONFIG34); in __rtl_get_wol()
3417 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CONFIG5); in __rtl_get_wol()
3425 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CFG_WOL); in __rtl_get_wol()
3432 static void __rtl_set_wol(struct r8152 *tp, u32 wolopts) in __rtl_set_wol() argument
3436 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_CONFIG); in __rtl_set_wol()
3438 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CONFIG34); in __rtl_set_wol()
3442 ocp_write_word(tp, MCU_TYPE_PLA, PLA_CONFIG34, ocp_data); in __rtl_set_wol()
3444 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CONFIG5); in __rtl_set_wol()
3452 ocp_write_word(tp, MCU_TYPE_PLA, PLA_CONFIG5, ocp_data); in __rtl_set_wol()
3454 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML); in __rtl_set_wol()
3456 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CFG_WOL); in __rtl_set_wol()
3460 ocp_write_word(tp, MCU_TYPE_PLA, PLA_CFG_WOL, ocp_data); in __rtl_set_wol()
3463 device_set_wakeup_enable(&tp->udev->dev, true); in __rtl_set_wol()
3465 device_set_wakeup_enable(&tp->udev->dev, false); in __rtl_set_wol()
3468 static void r8153_mac_clk_speed_down(struct r8152 *tp, bool enable) in r8153_mac_clk_speed_down() argument
3470 u32 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL2); in r8153_mac_clk_speed_down()
3478 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL2, ocp_data); in r8153_mac_clk_speed_down()
3481 static void r8156_mac_clk_spd(struct r8152 *tp, bool enable) in r8156_mac_clk_spd() argument
3488 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL, in r8156_mac_clk_spd()
3491 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL2); in r8156_mac_clk_spd()
3494 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL2, ocp_data); in r8156_mac_clk_spd()
3496 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL2); in r8156_mac_clk_spd()
3498 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL2, ocp_data); in r8156_mac_clk_spd()
3502 static void r8153_u1u2en(struct r8152 *tp, bool enable) in r8153_u1u2en() argument
3511 usb_ocp_write(tp, USB_TOLERANCE, BYTE_EN_SIX_BYTES, sizeof(u1u2), u1u2); in r8153_u1u2en()
3514 static void r8153b_u1u2en(struct r8152 *tp, bool enable) in r8153b_u1u2en() argument
3518 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_LPM_CONFIG); in r8153b_u1u2en()
3524 ocp_write_word(tp, MCU_TYPE_USB, USB_LPM_CONFIG, ocp_data); in r8153b_u1u2en()
3527 static void r8153_u2p3en(struct r8152 *tp, bool enable) in r8153_u2p3en() argument
3531 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_U2P3_CTRL); in r8153_u2p3en()
3536 ocp_write_word(tp, MCU_TYPE_USB, USB_U2P3_CTRL, ocp_data); in r8153_u2p3en()
3539 static void r8153b_ups_flags(struct r8152 *tp) in r8153b_ups_flags() argument
3543 if (tp->ups_info.green) in r8153b_ups_flags()
3546 if (tp->ups_info.aldps) in r8153b_ups_flags()
3549 if (tp->ups_info.eee) in r8153b_ups_flags()
3552 if (tp->ups_info.flow_control) in r8153b_ups_flags()
3555 if (tp->ups_info.eee_ckdiv) in r8153b_ups_flags()
3558 if (tp->ups_info.eee_cmod_lv) in r8153b_ups_flags()
3561 if (tp->ups_info.r_tune) in r8153b_ups_flags()
3564 if (tp->ups_info._10m_ckdiv) in r8153b_ups_flags()
3567 if (tp->ups_info.eee_plloff_100) in r8153b_ups_flags()
3570 if (tp->ups_info.eee_plloff_giga) in r8153b_ups_flags()
3573 if (tp->ups_info._250m_ckdiv) in r8153b_ups_flags()
3576 if (tp->ups_info.ctap_short_off) in r8153b_ups_flags()
3579 switch (tp->ups_info.speed_duplex) { in r8153b_ups_flags()
3611 ocp_write_dword(tp, MCU_TYPE_USB, USB_UPS_FLAGS, ups_flags); in r8153b_ups_flags()
3614 static void r8156_ups_flags(struct r8152 *tp) in r8156_ups_flags() argument
3618 if (tp->ups_info.green) in r8156_ups_flags()
3621 if (tp->ups_info.aldps) in r8156_ups_flags()
3624 if (tp->ups_info.eee) in r8156_ups_flags()
3627 if (tp->ups_info.flow_control) in r8156_ups_flags()
3630 if (tp->ups_info.eee_ckdiv) in r8156_ups_flags()
3633 if (tp->ups_info._10m_ckdiv) in r8156_ups_flags()
3636 if (tp->ups_info.eee_plloff_100) in r8156_ups_flags()
3639 if (tp->ups_info.eee_plloff_giga) in r8156_ups_flags()
3642 if (tp->ups_info._250m_ckdiv) in r8156_ups_flags()
3645 switch (tp->ups_info.speed_duplex) { in r8156_ups_flags()
3680 switch (tp->ups_info.lite_mode) { in r8156_ups_flags()
3693 ocp_write_dword(tp, MCU_TYPE_USB, USB_UPS_FLAGS, ups_flags); in r8156_ups_flags()
3696 static void rtl_green_en(struct r8152 *tp, bool enable) in rtl_green_en() argument
3700 data = sram_read(tp, SRAM_GREEN_CFG); in rtl_green_en()
3705 sram_write(tp, SRAM_GREEN_CFG, data); in rtl_green_en()
3707 tp->ups_info.green = enable; in rtl_green_en()
3710 static void r8153b_green_en(struct r8152 *tp, bool enable) in r8153b_green_en() argument
3713 sram_write(tp, 0x8045, 0); /* 10M abiq&ldvbias */ in r8153b_green_en()
3714 sram_write(tp, 0x804d, 0x1222); /* 100M short abiq&ldvbias */ in r8153b_green_en()
3715 sram_write(tp, 0x805d, 0x0022); /* 1000M short abiq&ldvbias */ in r8153b_green_en()
3717 sram_write(tp, 0x8045, 0x2444); /* 10M abiq&ldvbias */ in r8153b_green_en()
3718 sram_write(tp, 0x804d, 0x2444); /* 100M short abiq&ldvbias */ in r8153b_green_en()
3719 sram_write(tp, 0x805d, 0x2444); /* 1000M short abiq&ldvbias */ in r8153b_green_en()
3722 rtl_green_en(tp, true); in r8153b_green_en()
3725 static u16 r8153_phy_status(struct r8152 *tp, u16 desired) in r8153_phy_status() argument
3731 data = ocp_reg_read(tp, OCP_PHY_STATUS); in r8153_phy_status()
3742 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8153_phy_status()
3749 static void r8153b_ups_en(struct r8152 *tp, bool enable) in r8153b_ups_en() argument
3751 u32 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_POWER_CUT); in r8153b_ups_en()
3754 r8153b_ups_flags(tp); in r8153b_ups_en()
3757 ocp_write_byte(tp, MCU_TYPE_USB, USB_POWER_CUT, ocp_data); in r8153b_ups_en()
3759 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_MISC_2); in r8153b_ups_en()
3761 ocp_write_byte(tp, MCU_TYPE_USB, USB_MISC_2, ocp_data); in r8153b_ups_en()
3764 ocp_write_byte(tp, MCU_TYPE_USB, USB_POWER_CUT, ocp_data); in r8153b_ups_en()
3766 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_MISC_2); in r8153b_ups_en()
3768 ocp_write_byte(tp, MCU_TYPE_USB, USB_MISC_2, ocp_data); in r8153b_ups_en()
3770 if (ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0) & PCUT_STATUS) { in r8153b_ups_en()
3774 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8153b_ups_en()
3776 if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) & in r8153b_ups_en()
3782 tp->rtl_ops.hw_phy_cfg(tp); in r8153b_ups_en()
3784 rtl8152_set_speed(tp, tp->autoneg, tp->speed, in r8153b_ups_en()
3785 tp->duplex, tp->advertising); in r8153b_ups_en()
3790 static void r8153c_ups_en(struct r8152 *tp, bool enable) in r8153c_ups_en() argument
3792 u32 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_POWER_CUT); in r8153c_ups_en()
3795 r8153b_ups_flags(tp); in r8153c_ups_en()
3798 ocp_write_byte(tp, MCU_TYPE_USB, USB_POWER_CUT, ocp_data); in r8153c_ups_en()
3800 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_MISC_2); in r8153c_ups_en()
3803 ocp_write_byte(tp, MCU_TYPE_USB, USB_MISC_2, ocp_data); in r8153c_ups_en()
3806 ocp_write_byte(tp, MCU_TYPE_USB, USB_POWER_CUT, ocp_data); in r8153c_ups_en()
3808 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_MISC_2); in r8153c_ups_en()
3810 ocp_write_byte(tp, MCU_TYPE_USB, USB_MISC_2, ocp_data); in r8153c_ups_en()
3812 if (ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0) & PCUT_STATUS) { in r8153c_ups_en()
3816 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8153c_ups_en()
3818 if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) & in r8153c_ups_en()
3824 tp->rtl_ops.hw_phy_cfg(tp); in r8153c_ups_en()
3826 rtl8152_set_speed(tp, tp->autoneg, tp->speed, in r8153c_ups_en()
3827 tp->duplex, tp->advertising); in r8153c_ups_en()
3830 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_CONFIG); in r8153c_ups_en()
3832 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CONFIG34); in r8153c_ups_en()
3834 ocp_write_word(tp, MCU_TYPE_PLA, PLA_CONFIG34, ocp_data); in r8153c_ups_en()
3836 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML); in r8153c_ups_en()
3840 static void r8156_ups_en(struct r8152 *tp, bool enable) in r8156_ups_en() argument
3842 u32 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_POWER_CUT); in r8156_ups_en()
3845 r8156_ups_flags(tp); in r8156_ups_en()
3848 ocp_write_byte(tp, MCU_TYPE_USB, USB_POWER_CUT, ocp_data); in r8156_ups_en()
3850 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_MISC_2); in r8156_ups_en()
3852 ocp_write_byte(tp, MCU_TYPE_USB, USB_MISC_2, ocp_data); in r8156_ups_en()
3854 switch (tp->version) { in r8156_ups_en()
3857 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_UPHY_XTAL); in r8156_ups_en()
3859 ocp_write_byte(tp, MCU_TYPE_USB, USB_UPHY_XTAL, ocp_data); in r8156_ups_en()
3866 ocp_write_byte(tp, MCU_TYPE_USB, USB_POWER_CUT, ocp_data); in r8156_ups_en()
3868 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_MISC_2); in r8156_ups_en()
3870 ocp_write_byte(tp, MCU_TYPE_USB, USB_MISC_2, ocp_data); in r8156_ups_en()
3872 if (ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0) & PCUT_STATUS) { in r8156_ups_en()
3873 tp->rtl_ops.hw_phy_cfg(tp); in r8156_ups_en()
3875 rtl8152_set_speed(tp, tp->autoneg, tp->speed, in r8156_ups_en()
3876 tp->duplex, tp->advertising); in r8156_ups_en()
3881 static void r8153_power_cut_en(struct r8152 *tp, bool enable) in r8153_power_cut_en() argument
3885 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_POWER_CUT); in r8153_power_cut_en()
3890 ocp_write_word(tp, MCU_TYPE_USB, USB_POWER_CUT, ocp_data); in r8153_power_cut_en()
3892 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0); in r8153_power_cut_en()
3894 ocp_write_word(tp, MCU_TYPE_USB, USB_MISC_0, ocp_data); in r8153_power_cut_en()
3897 static void r8153b_power_cut_en(struct r8152 *tp, bool enable) in r8153b_power_cut_en() argument
3901 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_POWER_CUT); in r8153b_power_cut_en()
3906 ocp_write_word(tp, MCU_TYPE_USB, USB_POWER_CUT, ocp_data); in r8153b_power_cut_en()
3908 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0); in r8153b_power_cut_en()
3910 ocp_write_word(tp, MCU_TYPE_USB, USB_MISC_0, ocp_data); in r8153b_power_cut_en()
3913 static void r8153_queue_wake(struct r8152 *tp, bool enable) in r8153_queue_wake() argument
3917 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_INDICATE_FALG); in r8153_queue_wake()
3922 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_INDICATE_FALG, ocp_data); in r8153_queue_wake()
3924 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_SUSPEND_FLAG); in r8153_queue_wake()
3926 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_SUSPEND_FLAG, ocp_data); in r8153_queue_wake()
3928 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS); in r8153_queue_wake()
3930 ocp_write_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS, ocp_data); in r8153_queue_wake()
3933 static bool rtl_can_wakeup(struct r8152 *tp) in rtl_can_wakeup() argument
3935 struct usb_device *udev = tp->udev; in rtl_can_wakeup()
3940 static void rtl_runtime_suspend_enable(struct r8152 *tp, bool enable) in rtl_runtime_suspend_enable() argument
3945 __rtl_set_wol(tp, WAKE_ANY); in rtl_runtime_suspend_enable()
3947 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_CONFIG); in rtl_runtime_suspend_enable()
3949 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CONFIG34); in rtl_runtime_suspend_enable()
3951 ocp_write_word(tp, MCU_TYPE_PLA, PLA_CONFIG34, ocp_data); in rtl_runtime_suspend_enable()
3953 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML); in rtl_runtime_suspend_enable()
3957 __rtl_set_wol(tp, tp->saved_wolopts); in rtl_runtime_suspend_enable()
3959 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_CONFIG); in rtl_runtime_suspend_enable()
3961 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CONFIG34); in rtl_runtime_suspend_enable()
3963 ocp_write_word(tp, MCU_TYPE_PLA, PLA_CONFIG34, ocp_data); in rtl_runtime_suspend_enable()
3965 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML); in rtl_runtime_suspend_enable()
3969 static void rtl8153_runtime_enable(struct r8152 *tp, bool enable) in rtl8153_runtime_enable() argument
3972 r8153_u1u2en(tp, false); in rtl8153_runtime_enable()
3973 r8153_u2p3en(tp, false); in rtl8153_runtime_enable()
3974 rtl_runtime_suspend_enable(tp, true); in rtl8153_runtime_enable()
3976 rtl_runtime_suspend_enable(tp, false); in rtl8153_runtime_enable()
3978 switch (tp->version) { in rtl8153_runtime_enable()
3985 r8153_u2p3en(tp, true); in rtl8153_runtime_enable()
3989 r8153_u1u2en(tp, true); in rtl8153_runtime_enable()
3993 static void rtl8153b_runtime_enable(struct r8152 *tp, bool enable) in rtl8153b_runtime_enable() argument
3996 r8153_queue_wake(tp, true); in rtl8153b_runtime_enable()
3997 r8153b_u1u2en(tp, false); in rtl8153b_runtime_enable()
3998 r8153_u2p3en(tp, false); in rtl8153b_runtime_enable()
3999 rtl_runtime_suspend_enable(tp, true); in rtl8153b_runtime_enable()
4000 r8153b_ups_en(tp, true); in rtl8153b_runtime_enable()
4002 r8153b_ups_en(tp, false); in rtl8153b_runtime_enable()
4003 r8153_queue_wake(tp, false); in rtl8153b_runtime_enable()
4004 rtl_runtime_suspend_enable(tp, false); in rtl8153b_runtime_enable()
4005 if (tp->udev->speed >= USB_SPEED_SUPER) in rtl8153b_runtime_enable()
4006 r8153b_u1u2en(tp, true); in rtl8153b_runtime_enable()
4010 static void rtl8153c_runtime_enable(struct r8152 *tp, bool enable) in rtl8153c_runtime_enable() argument
4013 r8153_queue_wake(tp, true); in rtl8153c_runtime_enable()
4014 r8153b_u1u2en(tp, false); in rtl8153c_runtime_enable()
4015 r8153_u2p3en(tp, false); in rtl8153c_runtime_enable()
4016 rtl_runtime_suspend_enable(tp, true); in rtl8153c_runtime_enable()
4017 r8153c_ups_en(tp, true); in rtl8153c_runtime_enable()
4019 r8153c_ups_en(tp, false); in rtl8153c_runtime_enable()
4020 r8153_queue_wake(tp, false); in rtl8153c_runtime_enable()
4021 rtl_runtime_suspend_enable(tp, false); in rtl8153c_runtime_enable()
4022 r8153b_u1u2en(tp, true); in rtl8153c_runtime_enable()
4026 static void rtl8156_runtime_enable(struct r8152 *tp, bool enable) in rtl8156_runtime_enable() argument
4029 r8153_queue_wake(tp, true); in rtl8156_runtime_enable()
4030 r8153b_u1u2en(tp, false); in rtl8156_runtime_enable()
4031 r8153_u2p3en(tp, false); in rtl8156_runtime_enable()
4032 rtl_runtime_suspend_enable(tp, true); in rtl8156_runtime_enable()
4034 r8153_queue_wake(tp, false); in rtl8156_runtime_enable()
4035 rtl_runtime_suspend_enable(tp, false); in rtl8156_runtime_enable()
4036 r8153_u2p3en(tp, true); in rtl8156_runtime_enable()
4037 if (tp->udev->speed >= USB_SPEED_SUPER) in rtl8156_runtime_enable()
4038 r8153b_u1u2en(tp, true); in rtl8156_runtime_enable()
4042 static void r8153_teredo_off(struct r8152 *tp) in r8153_teredo_off() argument
4046 switch (tp->version) { in r8153_teredo_off()
4054 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG); in r8153_teredo_off()
4057 ocp_write_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG, ocp_data); in r8153_teredo_off()
4073 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG, 0xff); in r8153_teredo_off()
4077 ocp_write_word(tp, MCU_TYPE_PLA, PLA_WDT6_CTRL, WDT6_SET_MODE); in r8153_teredo_off()
4078 ocp_write_word(tp, MCU_TYPE_PLA, PLA_REALWOW_TIMER, 0); in r8153_teredo_off()
4079 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_TEREDO_TIMER, 0); in r8153_teredo_off()
4082 static void rtl_reset_bmu(struct r8152 *tp) in rtl_reset_bmu() argument
4086 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_BMU_RESET); in rtl_reset_bmu()
4088 ocp_write_byte(tp, MCU_TYPE_USB, USB_BMU_RESET, ocp_data); in rtl_reset_bmu()
4090 ocp_write_byte(tp, MCU_TYPE_USB, USB_BMU_RESET, ocp_data); in rtl_reset_bmu()
4094 static void rtl_clear_bp(struct r8152 *tp, u16 type) in rtl_clear_bp() argument
4099 switch (tp->version) { in rtl_clear_bp()
4108 ocp_write_word(tp, MCU_TYPE_USB, USB_BP2_EN, 0); in rtl_clear_bp()
4117 ocp_write_byte(tp, type, PLA_BP_EN, 0); in rtl_clear_bp()
4126 ocp_write_word(tp, type, USB_BP2_EN, 0); in rtl_clear_bp()
4131 generic_ocp_write(tp, PLA_BP_0, BYTE_EN_DWORD, bp_num << 1, bp, type); in rtl_clear_bp()
4135 ocp_write_word(tp, type, PLA_BP_BA, 0); in rtl_clear_bp()
4138 static inline void rtl_reset_ocp_base(struct r8152 *tp) in rtl_reset_ocp_base() argument
4140 tp->ocp_base = -1; in rtl_reset_ocp_base()
4143 static int rtl_phy_patch_request(struct r8152 *tp, bool request, bool wait) in rtl_phy_patch_request() argument
4148 data = ocp_reg_read(tp, OCP_PHY_PATCH_CMD); in rtl_phy_patch_request()
4156 ocp_reg_write(tp, OCP_PHY_PATCH_CMD, data); in rtl_phy_patch_request()
4161 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl_phy_patch_request()
4165 ocp_data = ocp_reg_read(tp, OCP_PHY_PATCH_STAT); in rtl_phy_patch_request()
4171 !(ocp_reg_read(tp, OCP_PHY_PATCH_STAT) & PATCH_READY)) { in rtl_phy_patch_request()
4172 dev_err(&tp->intf->dev, "PHY patch request fail\n"); in rtl_phy_patch_request()
4173 rtl_phy_patch_request(tp, false, false); in rtl_phy_patch_request()
4180 static void rtl_patch_key_set(struct r8152 *tp, u16 key_addr, u16 patch_key) in rtl_patch_key_set() argument
4183 sram_write(tp, key_addr, patch_key); in rtl_patch_key_set()
4184 sram_write(tp, SRAM_PHY_LOCK, PHY_PATCH_LOCK); in rtl_patch_key_set()
4188 sram_write(tp, 0x0000, 0x0000); in rtl_patch_key_set()
4190 data = ocp_reg_read(tp, OCP_PHY_LOCK); in rtl_patch_key_set()
4192 ocp_reg_write(tp, OCP_PHY_LOCK, data); in rtl_patch_key_set()
4194 sram_write(tp, key_addr, 0x0000); in rtl_patch_key_set()
4201 rtl_pre_ram_code(struct r8152 *tp, u16 key_addr, u16 patch_key, bool wait) in rtl_pre_ram_code() argument
4203 if (rtl_phy_patch_request(tp, true, wait)) in rtl_pre_ram_code()
4206 rtl_patch_key_set(tp, key_addr, patch_key); in rtl_pre_ram_code()
4211 static int rtl_post_ram_code(struct r8152 *tp, u16 key_addr, bool wait) in rtl_post_ram_code() argument
4213 rtl_patch_key_set(tp, key_addr, 0); in rtl_post_ram_code()
4215 rtl_phy_patch_request(tp, false, wait); in rtl_post_ram_code()
4220 static bool rtl8152_is_fw_phy_speed_up_ok(struct r8152 *tp, struct fw_phy_speed_up *phy) in rtl8152_is_fw_phy_speed_up_ok() argument
4226 switch (tp->version) { in rtl8152_is_fw_phy_speed_up_ok()
4250 dev_err(&tp->intf->dev, "invalid fw_offset\n"); in rtl8152_is_fw_phy_speed_up_ok()
4256 dev_err(&tp->intf->dev, "invalid block length\n"); in rtl8152_is_fw_phy_speed_up_ok()
4261 dev_err(&tp->intf->dev, "invalid register to load firmware\n"); in rtl8152_is_fw_phy_speed_up_ok()
4270 static bool rtl8152_is_fw_phy_ver_ok(struct r8152 *tp, struct fw_phy_ver *ver) in rtl8152_is_fw_phy_ver_ok() argument
4274 switch (tp->version) { in rtl8152_is_fw_phy_ver_ok()
4286 dev_err(&tp->intf->dev, "invalid block length\n"); in rtl8152_is_fw_phy_ver_ok()
4291 dev_err(&tp->intf->dev, "invalid phy ver addr\n"); in rtl8152_is_fw_phy_ver_ok()
4300 static bool rtl8152_is_fw_phy_fixup_ok(struct r8152 *tp, struct fw_phy_fixup *fix) in rtl8152_is_fw_phy_fixup_ok() argument
4304 switch (tp->version) { in rtl8152_is_fw_phy_fixup_ok()
4316 dev_err(&tp->intf->dev, "invalid block length\n"); in rtl8152_is_fw_phy_fixup_ok()
4322 dev_err(&tp->intf->dev, "invalid phy fixup\n"); in rtl8152_is_fw_phy_fixup_ok()
4331 static bool rtl8152_is_fw_phy_union_ok(struct r8152 *tp, struct fw_phy_union *phy) in rtl8152_is_fw_phy_union_ok() argument
4337 switch (tp->version) { in rtl8152_is_fw_phy_union_ok()
4351 dev_err(&tp->intf->dev, "invalid fw_offset\n"); in rtl8152_is_fw_phy_union_ok()
4357 dev_err(&tp->intf->dev, "invalid block length\n"); in rtl8152_is_fw_phy_union_ok()
4362 dev_err(&tp->intf->dev, "invalid pre_num %d\n", phy->pre_num); in rtl8152_is_fw_phy_union_ok()
4367 dev_err(&tp->intf->dev, "invalid bp_num %d\n", phy->bp_num); in rtl8152_is_fw_phy_union_ok()
4376 static bool rtl8152_is_fw_phy_nc_ok(struct r8152 *tp, struct fw_phy_nc *phy) in rtl8152_is_fw_phy_nc_ok() argument
4382 switch (tp->version) { in rtl8152_is_fw_phy_nc_ok()
4398 dev_err(&tp->intf->dev, "fw_offset too small\n"); in rtl8152_is_fw_phy_nc_ok()
4404 dev_err(&tp->intf->dev, "invalid fw_offset\n"); in rtl8152_is_fw_phy_nc_ok()
4410 dev_err(&tp->intf->dev, "invalid block length\n"); in rtl8152_is_fw_phy_nc_ok()
4415 dev_err(&tp->intf->dev, "invalid register to load firmware\n"); in rtl8152_is_fw_phy_nc_ok()
4420 dev_err(&tp->intf->dev, "invalid base address register\n"); in rtl8152_is_fw_phy_nc_ok()
4425 dev_err(&tp->intf->dev, in rtl8152_is_fw_phy_nc_ok()
4431 dev_err(&tp->intf->dev, in rtl8152_is_fw_phy_nc_ok()
4437 dev_err(&tp->intf->dev, in rtl8152_is_fw_phy_nc_ok()
4443 dev_err(&tp->intf->dev, "invalid break point number\n"); in rtl8152_is_fw_phy_nc_ok()
4452 static bool rtl8152_is_fw_mac_ok(struct r8152 *tp, struct fw_mac *mac) in rtl8152_is_fw_mac_ok() argument
4461 switch (tp->version) { in rtl8152_is_fw_mac_ok()
4498 switch (tp->version) { in rtl8152_is_fw_mac_ok()
4534 dev_err(&tp->intf->dev, "fw_offset too small\n"); in rtl8152_is_fw_mac_ok()
4540 dev_err(&tp->intf->dev, "invalid fw_offset\n"); in rtl8152_is_fw_mac_ok()
4546 dev_err(&tp->intf->dev, "invalid block length\n"); in rtl8152_is_fw_mac_ok()
4551 dev_err(&tp->intf->dev, "invalid register to load firmware\n"); in rtl8152_is_fw_mac_ok()
4556 dev_err(&tp->intf->dev, "invalid base address register\n"); in rtl8152_is_fw_mac_ok()
4561 dev_err(&tp->intf->dev, "invalid enabled mask register\n"); in rtl8152_is_fw_mac_ok()
4566 dev_err(&tp->intf->dev, in rtl8152_is_fw_mac_ok()
4572 dev_err(&tp->intf->dev, "invalid break point number\n"); in rtl8152_is_fw_mac_ok()
4578 dev_err(&tp->intf->dev, "unused bp%u is not zero\n", i); in rtl8152_is_fw_mac_ok()
4592 static long rtl8152_fw_verify_checksum(struct r8152 *tp, in rtl8152_fw_verify_checksum() argument
4609 dev_err(&tp->intf->dev, "digestsize incorrect (%u)\n", in rtl8152_fw_verify_checksum()
4629 dev_err(&tp->intf->dev, "checksum fail\n"); in rtl8152_fw_verify_checksum()
4639 static long rtl8152_check_firmware(struct r8152 *tp, struct rtl_fw *rtl_fw) in rtl8152_check_firmware() argument
4648 dev_err(&tp->intf->dev, "file too small\n"); in rtl8152_check_firmware()
4652 ret = rtl8152_fw_verify_checksum(tp, fw_hdr, fw->size); in rtl8152_check_firmware()
4673 dev_err(&tp->intf->dev, in rtl8152_check_firmware()
4678 if (!rtl8152_is_fw_mac_ok(tp, (struct fw_mac *)block)) { in rtl8152_check_firmware()
4679 dev_err(&tp->intf->dev, in rtl8152_check_firmware()
4687 dev_err(&tp->intf->dev, in rtl8152_check_firmware()
4692 if (!rtl8152_is_fw_mac_ok(tp, (struct fw_mac *)block)) { in rtl8152_check_firmware()
4693 dev_err(&tp->intf->dev, in rtl8152_check_firmware()
4707 dev_err(&tp->intf->dev, in rtl8152_check_firmware()
4713 dev_err(&tp->intf->dev, in rtl8152_check_firmware()
4722 dev_err(&tp->intf->dev, in rtl8152_check_firmware()
4728 dev_err(&tp->intf->dev, in rtl8152_check_firmware()
4737 dev_err(&tp->intf->dev, in rtl8152_check_firmware()
4743 dev_err(&tp->intf->dev, in rtl8152_check_firmware()
4748 if (!rtl8152_is_fw_phy_nc_ok(tp, (struct fw_phy_nc *)block)) { in rtl8152_check_firmware()
4749 dev_err(&tp->intf->dev, in rtl8152_check_firmware()
4762 dev_err(&tp->intf->dev, "PHY_UNION_NC out of order\n"); in rtl8152_check_firmware()
4767 dev_err(&tp->intf->dev, "multiple PHY_UNION_NC encountered\n"); in rtl8152_check_firmware()
4771 if (!rtl8152_is_fw_phy_union_ok(tp, (struct fw_phy_union *)block)) { in rtl8152_check_firmware()
4772 dev_err(&tp->intf->dev, "check PHY_UNION_NC failed\n"); in rtl8152_check_firmware()
4783 dev_err(&tp->intf->dev, "PHY_UNION_NC1 out of order\n"); in rtl8152_check_firmware()
4788 dev_err(&tp->intf->dev, "multiple PHY NC1 encountered\n"); in rtl8152_check_firmware()
4792 if (!rtl8152_is_fw_phy_union_ok(tp, (struct fw_phy_union *)block)) { in rtl8152_check_firmware()
4793 dev_err(&tp->intf->dev, "check PHY_UNION_NC1 failed\n"); in rtl8152_check_firmware()
4803 dev_err(&tp->intf->dev, "PHY_UNION_NC2 out of order\n"); in rtl8152_check_firmware()
4808 dev_err(&tp->intf->dev, "multiple PHY NC2 encountered\n"); in rtl8152_check_firmware()
4812 if (!rtl8152_is_fw_phy_union_ok(tp, (struct fw_phy_union *)block)) { in rtl8152_check_firmware()
4813 dev_err(&tp->intf->dev, "check PHY_UNION_NC2 failed\n"); in rtl8152_check_firmware()
4822 dev_err(&tp->intf->dev, "PHY_UNION_UC2 out of order\n"); in rtl8152_check_firmware()
4827 dev_err(&tp->intf->dev, "multiple PHY UC2 encountered\n"); in rtl8152_check_firmware()
4831 if (!rtl8152_is_fw_phy_union_ok(tp, (struct fw_phy_union *)block)) { in rtl8152_check_firmware()
4832 dev_err(&tp->intf->dev, "check PHY_UNION_UC2 failed\n"); in rtl8152_check_firmware()
4840 dev_err(&tp->intf->dev, "PHY_UNION_UC out of order\n"); in rtl8152_check_firmware()
4845 dev_err(&tp->intf->dev, "multiple PHY UC encountered\n"); in rtl8152_check_firmware()
4849 if (!rtl8152_is_fw_phy_union_ok(tp, (struct fw_phy_union *)block)) { in rtl8152_check_firmware()
4850 dev_err(&tp->intf->dev, "check PHY_UNION_UC failed\n"); in rtl8152_check_firmware()
4856 if (!rtl8152_is_fw_phy_union_ok(tp, (struct fw_phy_union *)block)) { in rtl8152_check_firmware()
4857 dev_err(&tp->intf->dev, "check RTL_FW_PHY_UNION_MISC failed\n"); in rtl8152_check_firmware()
4862 if (!rtl8152_is_fw_phy_fixup_ok(tp, (struct fw_phy_fixup *)block)) { in rtl8152_check_firmware()
4863 dev_err(&tp->intf->dev, "check PHY fixup failed\n"); in rtl8152_check_firmware()
4869 dev_err(&tp->intf->dev, "multiple PHY firmware encountered"); in rtl8152_check_firmware()
4873 if (!rtl8152_is_fw_phy_speed_up_ok(tp, (struct fw_phy_speed_up *)block)) { in rtl8152_check_firmware()
4874 dev_err(&tp->intf->dev, "check PHY speed up failed\n"); in rtl8152_check_firmware()
4887 dev_err(&tp->intf->dev, "Invalid order to set PHY version\n"); in rtl8152_check_firmware()
4892 dev_err(&tp->intf->dev, "multiple PHY version encountered"); in rtl8152_check_firmware()
4896 if (!rtl8152_is_fw_phy_ver_ok(tp, (struct fw_phy_ver *)block)) { in rtl8152_check_firmware()
4897 dev_err(&tp->intf->dev, "check PHY version failed\n"); in rtl8152_check_firmware()
4903 dev_warn(&tp->intf->dev, "Unknown type %u is found\n", in rtl8152_check_firmware()
4914 dev_err(&tp->intf->dev, "without PHY_STOP\n"); in rtl8152_check_firmware()
4923 static void rtl_ram_code_speed_up(struct r8152 *tp, struct fw_phy_speed_up *phy, bool wait) in rtl_ram_code_speed_up() argument
4928 rtl_reset_ocp_base(tp); in rtl_ram_code_speed_up()
4930 if (sram_read(tp, SRAM_GPHY_FW_VER) >= __le16_to_cpu(phy->version)) { in rtl_ram_code_speed_up()
4931 dev_dbg(&tp->intf->dev, "PHY firmware has been the newest\n"); in rtl_ram_code_speed_up()
4939 if (rtl_phy_patch_request(tp, true, wait)) in rtl_ram_code_speed_up()
4951 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_GPHY_CTRL); in rtl_ram_code_speed_up()
4953 ocp_write_word(tp, MCU_TYPE_USB, USB_GPHY_CTRL, ocp_data); in rtl_ram_code_speed_up()
4955 generic_ocp_write(tp, __le16_to_cpu(phy->fw_reg), 0xff, size, data, MCU_TYPE_USB); in rtl_ram_code_speed_up()
4960 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_POL_GPIO_CTRL); in rtl_ram_code_speed_up()
4962 ocp_write_word(tp, MCU_TYPE_PLA, PLA_POL_GPIO_CTRL, ocp_data); in rtl_ram_code_speed_up()
4965 if (!(ocp_read_word(tp, MCU_TYPE_PLA, PLA_POL_GPIO_CTRL) & POL_GPHY_PATCH)) in rtl_ram_code_speed_up()
4970 dev_err(&tp->intf->dev, "ram code speedup mode timeout\n"); in rtl_ram_code_speed_up()
4975 rtl_reset_ocp_base(tp); in rtl_ram_code_speed_up()
4977 rtl_phy_patch_request(tp, false, wait); in rtl_ram_code_speed_up()
4979 if (sram_read(tp, SRAM_GPHY_FW_VER) == __le16_to_cpu(phy->version)) in rtl_ram_code_speed_up()
4980 dev_dbg(&tp->intf->dev, "successfully applied %s\n", phy->info); in rtl_ram_code_speed_up()
4982 dev_err(&tp->intf->dev, "ram code speedup mode fail\n"); in rtl_ram_code_speed_up()
4985 static int rtl8152_fw_phy_ver(struct r8152 *tp, struct fw_phy_ver *phy_ver) in rtl8152_fw_phy_ver() argument
4992 rtl_reset_ocp_base(tp); in rtl8152_fw_phy_ver()
4994 if (sram_read(tp, ver_addr) >= ver) { in rtl8152_fw_phy_ver()
4995 dev_dbg(&tp->intf->dev, "PHY firmware has been the newest\n"); in rtl8152_fw_phy_ver()
4999 sram_write(tp, ver_addr, ver); in rtl8152_fw_phy_ver()
5001 dev_dbg(&tp->intf->dev, "PHY firmware version %x\n", ver); in rtl8152_fw_phy_ver()
5006 static void rtl8152_fw_phy_fixup(struct r8152 *tp, struct fw_phy_fixup *fix) in rtl8152_fw_phy_fixup() argument
5010 rtl_reset_ocp_base(tp); in rtl8152_fw_phy_fixup()
5013 data = ocp_reg_read(tp, addr); in rtl8152_fw_phy_fixup()
5032 ocp_reg_write(tp, addr, data); in rtl8152_fw_phy_fixup()
5034 dev_dbg(&tp->intf->dev, "applied ocp %x %x\n", addr, data); in rtl8152_fw_phy_fixup()
5037 static void rtl8152_fw_phy_union_apply(struct r8152 *tp, struct fw_phy_union *phy) in rtl8152_fw_phy_union_apply() argument
5043 rtl_reset_ocp_base(tp); in rtl8152_fw_phy_union_apply()
5047 sram_write(tp, __le16_to_cpu(phy->pre_set[i].addr), in rtl8152_fw_phy_union_apply()
5055 ocp_reg_write(tp, OCP_SRAM_ADDR, __le16_to_cpu(phy->fw_reg)); in rtl8152_fw_phy_union_apply()
5057 ocp_reg_write(tp, OCP_SRAM_DATA, __le16_to_cpu(data[i])); in rtl8152_fw_phy_union_apply()
5061 sram_write(tp, __le16_to_cpu(phy->bp[i].addr), __le16_to_cpu(phy->bp[i].data)); in rtl8152_fw_phy_union_apply()
5064 sram_write(tp, __le16_to_cpu(phy->bp_en.addr), __le16_to_cpu(phy->bp_en.data)); in rtl8152_fw_phy_union_apply()
5066 dev_dbg(&tp->intf->dev, "successfully applied %s\n", phy->info); in rtl8152_fw_phy_union_apply()
5069 static void rtl8152_fw_phy_nc_apply(struct r8152 *tp, struct fw_phy_nc *phy) in rtl8152_fw_phy_nc_apply() argument
5075 rtl_reset_ocp_base(tp); in rtl8152_fw_phy_nc_apply()
5078 sram_write(tp, mode_reg, __le16_to_cpu(phy->mode_pre)); in rtl8152_fw_phy_nc_apply()
5079 sram_write(tp, __le16_to_cpu(phy->ba_reg), in rtl8152_fw_phy_nc_apply()
5087 ocp_reg_write(tp, OCP_SRAM_ADDR, __le16_to_cpu(phy->fw_reg)); in rtl8152_fw_phy_nc_apply()
5089 ocp_reg_write(tp, OCP_SRAM_DATA, __le16_to_cpu(data[i])); in rtl8152_fw_phy_nc_apply()
5091 sram_write(tp, __le16_to_cpu(phy->patch_en_addr), in rtl8152_fw_phy_nc_apply()
5097 sram_write(tp, bp_index, __le16_to_cpu(phy->bp[i])); in rtl8152_fw_phy_nc_apply()
5101 sram_write(tp, mode_reg, __le16_to_cpu(phy->mode_post)); in rtl8152_fw_phy_nc_apply()
5103 dev_dbg(&tp->intf->dev, "successfully applied %s\n", phy->info); in rtl8152_fw_phy_nc_apply()
5106 static void rtl8152_fw_mac_apply(struct r8152 *tp, struct fw_mac *mac) in rtl8152_fw_mac_apply() argument
5124 if (fw_ver_reg && ocp_read_byte(tp, MCU_TYPE_USB, fw_ver_reg) >= mac->fw_ver_data) { in rtl8152_fw_mac_apply()
5125 dev_dbg(&tp->intf->dev, "%s firmware has been the newest\n", type ? "PLA" : "USB"); in rtl8152_fw_mac_apply()
5129 rtl_clear_bp(tp, type); in rtl8152_fw_mac_apply()
5134 if (tp->version == RTL_VER_04 && type == MCU_TYPE_PLA && in rtl8152_fw_mac_apply()
5135 !(ocp_read_word(tp, MCU_TYPE_PLA, PLA_MACDBG_POST) & DEBUG_OE)) { in rtl8152_fw_mac_apply()
5136 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MACDBG_PRE, DEBUG_LTSSM); in rtl8152_fw_mac_apply()
5137 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MACDBG_POST, DEBUG_LTSSM); in rtl8152_fw_mac_apply()
5146 generic_ocp_write(tp, __le16_to_cpu(mac->fw_reg), 0xff, length, data, in rtl8152_fw_mac_apply()
5149 ocp_write_word(tp, type, __le16_to_cpu(mac->bp_ba_addr), in rtl8152_fw_mac_apply()
5152 generic_ocp_write(tp, __le16_to_cpu(mac->bp_start), BYTE_EN_DWORD, in rtl8152_fw_mac_apply()
5157 ocp_write_word(tp, type, bp_en_addr, in rtl8152_fw_mac_apply()
5161 ocp_write_byte(tp, MCU_TYPE_USB, fw_ver_reg, in rtl8152_fw_mac_apply()
5164 dev_dbg(&tp->intf->dev, "successfully applied %s\n", mac->info); in rtl8152_fw_mac_apply()
5167 static void rtl8152_apply_firmware(struct r8152 *tp, bool power_cut) in rtl8152_apply_firmware() argument
5169 struct rtl_fw *rtl_fw = &tp->rtl_fw; in rtl8152_apply_firmware()
5183 rtl_fw->pre_fw(tp); in rtl8152_apply_firmware()
5193 rtl8152_fw_mac_apply(tp, (struct fw_mac *)block); in rtl8152_apply_firmware()
5200 rtl_pre_ram_code(tp, key_addr, __le16_to_cpu(key->key_data), !power_cut); in rtl8152_apply_firmware()
5206 rtl_post_ram_code(tp, key_addr, !power_cut); in rtl8152_apply_firmware()
5209 rtl8152_fw_phy_nc_apply(tp, (struct fw_phy_nc *)block); in rtl8152_apply_firmware()
5212 patch_phy = rtl8152_fw_phy_ver(tp, (struct fw_phy_ver *)block); in rtl8152_apply_firmware()
5221 rtl8152_fw_phy_union_apply(tp, (struct fw_phy_union *)block); in rtl8152_apply_firmware()
5225 rtl8152_fw_phy_fixup(tp, (struct fw_phy_fixup *)block); in rtl8152_apply_firmware()
5228 rtl_ram_code_speed_up(tp, (struct fw_phy_speed_up *)block, !power_cut); in rtl8152_apply_firmware()
5239 rtl_fw->post_fw(tp); in rtl8152_apply_firmware()
5241 rtl_reset_ocp_base(tp); in rtl8152_apply_firmware()
5243 dev_info(&tp->intf->dev, "load %s successfully\n", rtl_fw->version); in rtl8152_apply_firmware()
5246 static void rtl8152_release_firmware(struct r8152 *tp) in rtl8152_release_firmware() argument
5248 struct rtl_fw *rtl_fw = &tp->rtl_fw; in rtl8152_release_firmware()
5256 static int rtl8152_request_firmware(struct r8152 *tp) in rtl8152_request_firmware() argument
5258 struct rtl_fw *rtl_fw = &tp->rtl_fw; in rtl8152_request_firmware()
5262 dev_info(&tp->intf->dev, "skip request firmware\n"); in rtl8152_request_firmware()
5267 rc = request_firmware(&rtl_fw->fw, rtl_fw->fw_name, &tp->intf->dev); in rtl8152_request_firmware()
5271 rc = rtl8152_check_firmware(tp, rtl_fw); in rtl8152_request_firmware()
5279 dev_warn(&tp->intf->dev, in rtl8152_request_firmware()
5287 static void r8152_aldps_en(struct r8152 *tp, bool enable) in r8152_aldps_en() argument
5290 ocp_reg_write(tp, OCP_ALDPS_CONFIG, ENPWRSAVE | ENPDNPS | in r8152_aldps_en()
5293 ocp_reg_write(tp, OCP_ALDPS_CONFIG, ENPDNPS | LINKENA | in r8152_aldps_en()
5299 static inline void r8152_mmd_indirect(struct r8152 *tp, u16 dev, u16 reg) in r8152_mmd_indirect() argument
5301 ocp_reg_write(tp, OCP_EEE_AR, FUN_ADDR | dev); in r8152_mmd_indirect()
5302 ocp_reg_write(tp, OCP_EEE_DATA, reg); in r8152_mmd_indirect()
5303 ocp_reg_write(tp, OCP_EEE_AR, FUN_DATA | dev); in r8152_mmd_indirect()
5306 static u16 r8152_mmd_read(struct r8152 *tp, u16 dev, u16 reg) in r8152_mmd_read() argument
5310 r8152_mmd_indirect(tp, dev, reg); in r8152_mmd_read()
5311 data = ocp_reg_read(tp, OCP_EEE_DATA); in r8152_mmd_read()
5312 ocp_reg_write(tp, OCP_EEE_AR, 0x0000); in r8152_mmd_read()
5317 static void r8152_mmd_write(struct r8152 *tp, u16 dev, u16 reg, u16 data) in r8152_mmd_write() argument
5319 r8152_mmd_indirect(tp, dev, reg); in r8152_mmd_write()
5320 ocp_reg_write(tp, OCP_EEE_DATA, data); in r8152_mmd_write()
5321 ocp_reg_write(tp, OCP_EEE_AR, 0x0000); in r8152_mmd_write()
5324 static void r8152_eee_en(struct r8152 *tp, bool enable) in r8152_eee_en() argument
5329 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EEE_CR); in r8152_eee_en()
5330 config1 = ocp_reg_read(tp, OCP_EEE_CONFIG1) & ~sd_rise_time_mask; in r8152_eee_en()
5331 config2 = ocp_reg_read(tp, OCP_EEE_CONFIG2); in r8152_eee_en()
5332 config3 = ocp_reg_read(tp, OCP_EEE_CONFIG3) & ~fast_snr_mask; in r8152_eee_en()
5349 ocp_write_word(tp, MCU_TYPE_PLA, PLA_EEE_CR, ocp_data); in r8152_eee_en()
5350 ocp_reg_write(tp, OCP_EEE_CONFIG1, config1); in r8152_eee_en()
5351 ocp_reg_write(tp, OCP_EEE_CONFIG2, config2); in r8152_eee_en()
5352 ocp_reg_write(tp, OCP_EEE_CONFIG3, config3); in r8152_eee_en()
5355 static void r8153_eee_en(struct r8152 *tp, bool enable) in r8153_eee_en() argument
5360 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EEE_CR); in r8153_eee_en()
5361 config = ocp_reg_read(tp, OCP_EEE_CFG); in r8153_eee_en()
5371 ocp_write_word(tp, MCU_TYPE_PLA, PLA_EEE_CR, ocp_data); in r8153_eee_en()
5372 ocp_reg_write(tp, OCP_EEE_CFG, config); in r8153_eee_en()
5374 tp->ups_info.eee = enable; in r8153_eee_en()
5377 static void r8156_eee_en(struct r8152 *tp, bool enable) in r8156_eee_en() argument
5381 r8153_eee_en(tp, enable); in r8156_eee_en()
5383 config = ocp_reg_read(tp, OCP_EEE_ADV2); in r8156_eee_en()
5390 ocp_reg_write(tp, OCP_EEE_ADV2, config); in r8156_eee_en()
5393 static void rtl_eee_enable(struct r8152 *tp, bool enable) in rtl_eee_enable() argument
5395 switch (tp->version) { in rtl_eee_enable()
5400 r8152_eee_en(tp, true); in rtl_eee_enable()
5401 r8152_mmd_write(tp, MDIO_MMD_AN, MDIO_AN_EEE_ADV, in rtl_eee_enable()
5402 tp->eee_adv); in rtl_eee_enable()
5404 r8152_eee_en(tp, false); in rtl_eee_enable()
5405 r8152_mmd_write(tp, MDIO_MMD_AN, MDIO_AN_EEE_ADV, 0); in rtl_eee_enable()
5416 r8153_eee_en(tp, true); in rtl_eee_enable()
5417 ocp_reg_write(tp, OCP_EEE_ADV, tp->eee_adv); in rtl_eee_enable()
5419 r8153_eee_en(tp, false); in rtl_eee_enable()
5420 ocp_reg_write(tp, OCP_EEE_ADV, 0); in rtl_eee_enable()
5429 r8156_eee_en(tp, true); in rtl_eee_enable()
5430 ocp_reg_write(tp, OCP_EEE_ADV, tp->eee_adv); in rtl_eee_enable()
5432 r8156_eee_en(tp, false); in rtl_eee_enable()
5433 ocp_reg_write(tp, OCP_EEE_ADV, 0); in rtl_eee_enable()
5441 static void r8152b_enable_fc(struct r8152 *tp) in r8152b_enable_fc() argument
5445 anar = r8152_mdio_read(tp, MII_ADVERTISE); in r8152b_enable_fc()
5447 r8152_mdio_write(tp, MII_ADVERTISE, anar); in r8152b_enable_fc()
5449 tp->ups_info.flow_control = true; in r8152b_enable_fc()
5452 static void rtl8152_disable(struct r8152 *tp) in rtl8152_disable() argument
5454 r8152_aldps_en(tp, false); in rtl8152_disable()
5455 rtl_disable(tp); in rtl8152_disable()
5456 r8152_aldps_en(tp, true); in rtl8152_disable()
5459 static void r8152b_hw_phy_cfg(struct r8152 *tp) in r8152b_hw_phy_cfg() argument
5461 rtl8152_apply_firmware(tp, false); in r8152b_hw_phy_cfg()
5462 rtl_eee_enable(tp, tp->eee_en); in r8152b_hw_phy_cfg()
5463 r8152_aldps_en(tp, true); in r8152b_hw_phy_cfg()
5464 r8152b_enable_fc(tp); in r8152b_hw_phy_cfg()
5466 set_bit(PHY_RESET, &tp->flags); in r8152b_hw_phy_cfg()
5469 static void wait_oob_link_list_ready(struct r8152 *tp) in wait_oob_link_list_ready() argument
5475 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in wait_oob_link_list_ready()
5477 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); in wait_oob_link_list_ready()
5484 static void r8156b_wait_loading_flash(struct r8152 *tp) in r8156b_wait_loading_flash() argument
5486 if ((ocp_read_word(tp, MCU_TYPE_PLA, PLA_GPHY_CTRL) & GPHY_FLASH) && in r8156b_wait_loading_flash()
5487 !(ocp_read_word(tp, MCU_TYPE_USB, USB_GPHY_CTRL) & BYPASS_FLASH)) { in r8156b_wait_loading_flash()
5491 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8156b_wait_loading_flash()
5493 if (ocp_read_word(tp, MCU_TYPE_USB, USB_GPHY_CTRL) & GPHY_PATCH_DONE) in r8156b_wait_loading_flash()
5500 static void r8152b_exit_oob(struct r8152 *tp) in r8152b_exit_oob() argument
5504 ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); in r8152b_exit_oob()
5506 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); in r8152b_exit_oob()
5508 rxdy_gated_en(tp, true); in r8152b_exit_oob()
5509 r8153_teredo_off(tp); in r8152b_exit_oob()
5510 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML); in r8152b_exit_oob()
5511 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CR, 0x00); in r8152b_exit_oob()
5513 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); in r8152b_exit_oob()
5515 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data); in r8152b_exit_oob()
5517 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7); in r8152b_exit_oob()
5519 ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data); in r8152b_exit_oob()
5521 wait_oob_link_list_ready(tp); in r8152b_exit_oob()
5523 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7); in r8152b_exit_oob()
5525 ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data); in r8152b_exit_oob()
5527 wait_oob_link_list_ready(tp); in r8152b_exit_oob()
5529 rtl8152_nic_reset(tp); in r8152b_exit_oob()
5532 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL0, RXFIFO_THR1_NORMAL); in r8152b_exit_oob()
5534 if (tp->udev->speed == USB_SPEED_FULL || in r8152b_exit_oob()
5535 tp->udev->speed == USB_SPEED_LOW) { in r8152b_exit_oob()
5537 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL1, in r8152b_exit_oob()
5539 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL2, in r8152b_exit_oob()
5543 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL1, in r8152b_exit_oob()
5545 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL2, in r8152b_exit_oob()
5550 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_TXFIFO_CTRL, TXFIFO_THR_NORMAL2); in r8152b_exit_oob()
5552 ocp_write_byte(tp, MCU_TYPE_USB, USB_TX_AGG, TX_AGG_MAX_THRESHOLD); in r8152b_exit_oob()
5553 ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH, RX_THR_HIGH); in r8152b_exit_oob()
5554 ocp_write_dword(tp, MCU_TYPE_USB, USB_TX_DMA, in r8152b_exit_oob()
5557 rtl_rx_vlan_en(tp, tp->netdev->features & NETIF_F_HW_VLAN_CTAG_RX); in r8152b_exit_oob()
5559 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, RTL8152_RMS); in r8152b_exit_oob()
5561 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TCR0); in r8152b_exit_oob()
5563 ocp_write_word(tp, MCU_TYPE_PLA, PLA_TCR0, ocp_data); in r8152b_exit_oob()
5566 static void r8152b_enter_oob(struct r8152 *tp) in r8152b_enter_oob() argument
5570 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); in r8152b_enter_oob()
5572 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data); in r8152b_enter_oob()
5574 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL0, RXFIFO_THR1_OOB); in r8152b_enter_oob()
5575 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL1, RXFIFO_THR2_OOB); in r8152b_enter_oob()
5576 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL2, RXFIFO_THR3_OOB); in r8152b_enter_oob()
5578 rtl_disable(tp); in r8152b_enter_oob()
5580 wait_oob_link_list_ready(tp); in r8152b_enter_oob()
5582 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7); in r8152b_enter_oob()
5584 ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data); in r8152b_enter_oob()
5586 wait_oob_link_list_ready(tp); in r8152b_enter_oob()
5588 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, RTL8152_RMS); in r8152b_enter_oob()
5590 rtl_rx_vlan_en(tp, true); in r8152b_enter_oob()
5592 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_BDC_CR); in r8152b_enter_oob()
5594 ocp_write_word(tp, MCU_TYPE_PLA, PLA_BDC_CR, ocp_data); in r8152b_enter_oob()
5596 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); in r8152b_enter_oob()
5598 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data); in r8152b_enter_oob()
5600 rxdy_gated_en(tp, false); in r8152b_enter_oob()
5602 ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); in r8152b_enter_oob()
5604 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); in r8152b_enter_oob()
5607 static int r8153_pre_firmware_1(struct r8152 *tp) in r8153_pre_firmware_1() argument
5613 u32 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_WDT1_CTRL); in r8153_pre_firmware_1()
5615 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8153_pre_firmware_1()
5625 static int r8153_post_firmware_1(struct r8152 *tp) in r8153_post_firmware_1() argument
5628 if (ocp_read_byte(tp, MCU_TYPE_USB, USB_CSTMR) & FORCE_SUPER) in r8153_post_firmware_1()
5629 ocp_write_word(tp, MCU_TYPE_USB, USB_BP_4, BP4_SUPER_ONLY); in r8153_post_firmware_1()
5632 ocp_write_word(tp, MCU_TYPE_PLA, PLA_UPHY_TIMER, 36000 / 16); in r8153_post_firmware_1()
5637 static int r8153_pre_firmware_2(struct r8152 *tp) in r8153_pre_firmware_2() argument
5641 r8153_pre_firmware_1(tp); in r8153_pre_firmware_2()
5643 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_FIX_EN0); in r8153_pre_firmware_2()
5645 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_FIX_EN0, ocp_data); in r8153_pre_firmware_2()
5650 static int r8153_post_firmware_2(struct r8152 *tp) in r8153_post_firmware_2() argument
5655 if (ocp_read_byte(tp, MCU_TYPE_USB, USB_CSTMR) & FORCE_SUPER) { in r8153_post_firmware_2()
5656 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_BP_EN); in r8153_post_firmware_2()
5658 ocp_write_word(tp, MCU_TYPE_PLA, PLA_BP_EN, ocp_data); in r8153_post_firmware_2()
5662 ocp_write_word(tp, MCU_TYPE_PLA, PLA_UPHY_TIMER, 36000 / 16); in r8153_post_firmware_2()
5665 ocp_write_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS, U3P3_CHECK_EN | 4); in r8153_post_firmware_2()
5667 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_FIX_EN0); in r8153_post_firmware_2()
5669 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_FIX_EN0, ocp_data); in r8153_post_firmware_2()
5671 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_USB2PHY); in r8153_post_firmware_2()
5673 ocp_write_byte(tp, MCU_TYPE_USB, USB_USB2PHY, ocp_data); in r8153_post_firmware_2()
5678 static int r8153_post_firmware_3(struct r8152 *tp) in r8153_post_firmware_3() argument
5682 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_USB2PHY); in r8153_post_firmware_3()
5684 ocp_write_byte(tp, MCU_TYPE_USB, USB_USB2PHY, ocp_data); in r8153_post_firmware_3()
5686 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_FIX_EN1); in r8153_post_firmware_3()
5688 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_FIX_EN1, ocp_data); in r8153_post_firmware_3()
5693 static int r8153b_pre_firmware_1(struct r8152 *tp) in r8153b_pre_firmware_1() argument
5696 ocp_write_word(tp, MCU_TYPE_USB, USB_FC_TIMER, in r8153b_pre_firmware_1()
5702 static int r8153b_post_firmware_1(struct r8152 *tp) in r8153b_post_firmware_1() argument
5707 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_MISC_1); in r8153b_post_firmware_1()
5709 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_BP_EN); in r8153b_post_firmware_1()
5711 ocp_write_word(tp, MCU_TYPE_PLA, PLA_BP_EN, ocp_data); in r8153b_post_firmware_1()
5714 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_CTRL); in r8153b_post_firmware_1()
5716 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_CTRL, ocp_data); in r8153b_post_firmware_1()
5718 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_TASK); in r8153b_post_firmware_1()
5720 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_TASK, ocp_data); in r8153b_post_firmware_1()
5722 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_FIX_EN1); in r8153b_post_firmware_1()
5724 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_FIX_EN1, ocp_data); in r8153b_post_firmware_1()
5729 static int r8153c_post_firmware_1(struct r8152 *tp) in r8153c_post_firmware_1() argument
5733 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_CTRL); in r8153c_post_firmware_1()
5735 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_CTRL, ocp_data); in r8153c_post_firmware_1()
5737 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_TASK); in r8153c_post_firmware_1()
5739 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_TASK, ocp_data); in r8153c_post_firmware_1()
5744 static int r8156a_post_firmware_1(struct r8152 *tp) in r8156a_post_firmware_1() argument
5748 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_FIX_EN1); in r8156a_post_firmware_1()
5750 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_FIX_EN1, ocp_data); in r8156a_post_firmware_1()
5753 ocp_write_dword(tp, MCU_TYPE_USB, USB_UPHY3_MDCMDIO, 0x4026840e); in r8156a_post_firmware_1()
5754 ocp_write_dword(tp, MCU_TYPE_USB, USB_UPHY3_MDCMDIO, 0x4001acc9); in r8156a_post_firmware_1()
5759 static void r8153_aldps_en(struct r8152 *tp, bool enable) in r8153_aldps_en() argument
5763 data = ocp_reg_read(tp, OCP_POWER_CFG); in r8153_aldps_en()
5766 ocp_reg_write(tp, OCP_POWER_CFG, data); in r8153_aldps_en()
5771 ocp_reg_write(tp, OCP_POWER_CFG, data); in r8153_aldps_en()
5773 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8153_aldps_en()
5776 if (ocp_read_word(tp, MCU_TYPE_PLA, 0xe000) & 0x0100) in r8153_aldps_en()
5781 tp->ups_info.aldps = enable; in r8153_aldps_en()
5784 static void r8153_hw_phy_cfg(struct r8152 *tp) in r8153_hw_phy_cfg() argument
5790 r8153_aldps_en(tp, false); in r8153_hw_phy_cfg()
5793 rtl_eee_enable(tp, false); in r8153_hw_phy_cfg()
5795 rtl8152_apply_firmware(tp, false); in r8153_hw_phy_cfg()
5797 if (tp->version == RTL_VER_03) { in r8153_hw_phy_cfg()
5798 data = ocp_reg_read(tp, OCP_EEE_CFG); in r8153_hw_phy_cfg()
5800 ocp_reg_write(tp, OCP_EEE_CFG, data); in r8153_hw_phy_cfg()
5803 data = ocp_reg_read(tp, OCP_POWER_CFG); in r8153_hw_phy_cfg()
5805 ocp_reg_write(tp, OCP_POWER_CFG, data); in r8153_hw_phy_cfg()
5807 data = ocp_reg_read(tp, OCP_DOWN_SPEED); in r8153_hw_phy_cfg()
5809 ocp_reg_write(tp, OCP_DOWN_SPEED, data); in r8153_hw_phy_cfg()
5810 data = ocp_reg_read(tp, OCP_POWER_CFG); in r8153_hw_phy_cfg()
5812 ocp_reg_write(tp, OCP_POWER_CFG, data); in r8153_hw_phy_cfg()
5813 sram_write(tp, SRAM_IMPEDANCE, 0x0b13); in r8153_hw_phy_cfg()
5815 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR); in r8153_hw_phy_cfg()
5817 ocp_write_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR, ocp_data); in r8153_hw_phy_cfg()
5820 sram_write(tp, SRAM_LPF_CFG, 0xf70f); in r8153_hw_phy_cfg()
5823 sram_write(tp, SRAM_10M_AMP1, 0x00af); in r8153_hw_phy_cfg()
5824 sram_write(tp, SRAM_10M_AMP2, 0x0208); in r8153_hw_phy_cfg()
5826 if (tp->eee_en) in r8153_hw_phy_cfg()
5827 rtl_eee_enable(tp, true); in r8153_hw_phy_cfg()
5829 r8153_aldps_en(tp, true); in r8153_hw_phy_cfg()
5830 r8152b_enable_fc(tp); in r8153_hw_phy_cfg()
5832 switch (tp->version) { in r8153_hw_phy_cfg()
5839 r8153_u2p3en(tp, true); in r8153_hw_phy_cfg()
5843 set_bit(PHY_RESET, &tp->flags); in r8153_hw_phy_cfg()
5846 static u32 r8152_efuse_read(struct r8152 *tp, u8 addr) in r8152_efuse_read() argument
5850 ocp_write_word(tp, MCU_TYPE_PLA, PLA_EFUSE_CMD, EFUSE_READ_CMD | addr); in r8152_efuse_read()
5851 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EFUSE_CMD); in r8152_efuse_read()
5853 ocp_data |= ocp_read_word(tp, MCU_TYPE_PLA, PLA_EFUSE_DATA); in r8152_efuse_read()
5858 static void r8153b_hw_phy_cfg(struct r8152 *tp) in r8153b_hw_phy_cfg() argument
5863 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0); in r8153b_hw_phy_cfg()
5866 ocp_write_word(tp, MCU_TYPE_USB, USB_MISC_0, ocp_data); in r8153b_hw_phy_cfg()
5870 r8153_aldps_en(tp, false); in r8153b_hw_phy_cfg()
5873 rtl_eee_enable(tp, false); in r8153b_hw_phy_cfg()
5876 ocp_write_word(tp, MCU_TYPE_USB, USB_U1U2_TIMER, 500); in r8153b_hw_phy_cfg()
5878 data = r8153_phy_status(tp, 0); in r8153b_hw_phy_cfg()
5883 rtl8152_apply_firmware(tp, true); in r8153b_hw_phy_cfg()
5885 data = r8152_mdio_read(tp, MII_BMCR); in r8153b_hw_phy_cfg()
5887 r8152_mdio_write(tp, MII_BMCR, data); in r8153b_hw_phy_cfg()
5891 rtl8152_apply_firmware(tp, false); in r8153b_hw_phy_cfg()
5895 r8153b_green_en(tp, test_bit(GREEN_ETHERNET, &tp->flags)); in r8153b_hw_phy_cfg()
5897 data = sram_read(tp, SRAM_GREEN_CFG); in r8153b_hw_phy_cfg()
5899 sram_write(tp, SRAM_GREEN_CFG, data); in r8153b_hw_phy_cfg()
5900 data = ocp_reg_read(tp, OCP_NCTL_CFG); in r8153b_hw_phy_cfg()
5902 ocp_reg_write(tp, OCP_NCTL_CFG, data); in r8153b_hw_phy_cfg()
5909 ocp_data = r8152_efuse_read(tp, 0x7d); in r8153b_hw_phy_cfg()
5912 ocp_reg_write(tp, OCP_ADC_IOFFSET, data); in r8153b_hw_phy_cfg()
5918 ocp_data = ocp_reg_read(tp, 0xc426); in r8153b_hw_phy_cfg()
5924 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_UPS_CFG); in r8153b_hw_phy_cfg()
5926 ocp_write_word(tp, MCU_TYPE_USB, USB_UPS_CFG, ocp_data); in r8153b_hw_phy_cfg()
5929 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR); in r8153b_hw_phy_cfg()
5931 ocp_write_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR, ocp_data); in r8153b_hw_phy_cfg()
5934 if (!rtl_phy_patch_request(tp, true, true)) { in r8153b_hw_phy_cfg()
5935 data = ocp_reg_read(tp, OCP_POWER_CFG); in r8153b_hw_phy_cfg()
5937 ocp_reg_write(tp, OCP_POWER_CFG, data); in r8153b_hw_phy_cfg()
5938 tp->ups_info.eee_ckdiv = true; in r8153b_hw_phy_cfg()
5940 data = ocp_reg_read(tp, OCP_DOWN_SPEED); in r8153b_hw_phy_cfg()
5942 ocp_reg_write(tp, OCP_DOWN_SPEED, data); in r8153b_hw_phy_cfg()
5943 tp->ups_info.eee_cmod_lv = true; in r8153b_hw_phy_cfg()
5944 tp->ups_info._10m_ckdiv = true; in r8153b_hw_phy_cfg()
5945 tp->ups_info.eee_plloff_giga = true; in r8153b_hw_phy_cfg()
5947 ocp_reg_write(tp, OCP_SYSCLK_CFG, 0); in r8153b_hw_phy_cfg()
5948 ocp_reg_write(tp, OCP_SYSCLK_CFG, clk_div_expo(5)); in r8153b_hw_phy_cfg()
5949 tp->ups_info._250m_ckdiv = true; in r8153b_hw_phy_cfg()
5951 rtl_phy_patch_request(tp, false, true); in r8153b_hw_phy_cfg()
5954 if (tp->eee_en) in r8153b_hw_phy_cfg()
5955 rtl_eee_enable(tp, true); in r8153b_hw_phy_cfg()
5957 r8153_aldps_en(tp, true); in r8153b_hw_phy_cfg()
5958 r8152b_enable_fc(tp); in r8153b_hw_phy_cfg()
5960 set_bit(PHY_RESET, &tp->flags); in r8153b_hw_phy_cfg()
5963 static void r8153c_hw_phy_cfg(struct r8152 *tp) in r8153c_hw_phy_cfg() argument
5965 r8153b_hw_phy_cfg(tp); in r8153c_hw_phy_cfg()
5967 tp->ups_info.r_tune = true; in r8153c_hw_phy_cfg()
5970 static void rtl8153_change_mtu(struct r8152 *tp) in rtl8153_change_mtu() argument
5972 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, mtu_to_size(tp->netdev->mtu)); in rtl8153_change_mtu()
5973 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_MTPS, MTPS_JUMBO); in rtl8153_change_mtu()
5976 static void r8153_first_init(struct r8152 *tp) in r8153_first_init() argument
5980 rxdy_gated_en(tp, true); in r8153_first_init()
5981 r8153_teredo_off(tp); in r8153_first_init()
5983 ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); in r8153_first_init()
5985 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); in r8153_first_init()
5987 rtl8152_nic_reset(tp); in r8153_first_init()
5988 rtl_reset_bmu(tp); in r8153_first_init()
5990 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); in r8153_first_init()
5992 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data); in r8153_first_init()
5994 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7); in r8153_first_init()
5996 ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data); in r8153_first_init()
5998 wait_oob_link_list_ready(tp); in r8153_first_init()
6000 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7); in r8153_first_init()
6002 ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data); in r8153_first_init()
6004 wait_oob_link_list_ready(tp); in r8153_first_init()
6006 rtl_rx_vlan_en(tp, tp->netdev->features & NETIF_F_HW_VLAN_CTAG_RX); in r8153_first_init()
6008 rtl8153_change_mtu(tp); in r8153_first_init()
6010 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TCR0); in r8153_first_init()
6012 ocp_write_word(tp, MCU_TYPE_PLA, PLA_TCR0, ocp_data); in r8153_first_init()
6014 rtl8152_nic_reset(tp); in r8153_first_init()
6017 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL0, RXFIFO_THR1_NORMAL); in r8153_first_init()
6018 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL1, RXFIFO_THR2_NORMAL); in r8153_first_init()
6019 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL2, RXFIFO_THR3_NORMAL); in r8153_first_init()
6021 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_TXFIFO_CTRL, TXFIFO_THR_NORMAL2); in r8153_first_init()
6024 static void r8153_enter_oob(struct r8152 *tp) in r8153_enter_oob() argument
6028 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); in r8153_enter_oob()
6030 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data); in r8153_enter_oob()
6033 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL0, RXFIFO_THR1_OOB); in r8153_enter_oob()
6034 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL1, RXFIFO_THR2_OOB); in r8153_enter_oob()
6035 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL2, RXFIFO_THR3_OOB); in r8153_enter_oob()
6037 rtl_disable(tp); in r8153_enter_oob()
6038 rtl_reset_bmu(tp); in r8153_enter_oob()
6040 wait_oob_link_list_ready(tp); in r8153_enter_oob()
6042 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7); in r8153_enter_oob()
6044 ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data); in r8153_enter_oob()
6046 wait_oob_link_list_ready(tp); in r8153_enter_oob()
6048 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, 1522); in r8153_enter_oob()
6049 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_MTPS, MTPS_DEFAULT); in r8153_enter_oob()
6051 switch (tp->version) { in r8153_enter_oob()
6056 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG); in r8153_enter_oob()
6058 ocp_write_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG, ocp_data); in r8153_enter_oob()
6068 ocp_write_word(tp, MCU_TYPE_PLA, PLA_TEREDO_WAKE_BASE, 0x00ff); in r8153_enter_oob()
6075 rtl_rx_vlan_en(tp, true); in r8153_enter_oob()
6077 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_BDC_CR); in r8153_enter_oob()
6079 ocp_write_word(tp, MCU_TYPE_PLA, PLA_BDC_CR, ocp_data); in r8153_enter_oob()
6081 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); in r8153_enter_oob()
6083 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data); in r8153_enter_oob()
6085 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7); in r8153_enter_oob()
6087 ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data); in r8153_enter_oob()
6089 rxdy_gated_en(tp, false); in r8153_enter_oob()
6091 ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); in r8153_enter_oob()
6093 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); in r8153_enter_oob()
6096 static void rtl8153_disable(struct r8152 *tp) in rtl8153_disable() argument
6098 r8153_aldps_en(tp, false); in rtl8153_disable()
6099 rtl_disable(tp); in rtl8153_disable()
6100 rtl_reset_bmu(tp); in rtl8153_disable()
6101 r8153_aldps_en(tp, true); in rtl8153_disable()
6104 static u32 fc_pause_on_auto(struct r8152 *tp) in fc_pause_on_auto() argument
6106 return (ALIGN(mtu_to_size(tp->netdev->mtu), 1024) + 6 * 1024); in fc_pause_on_auto()
6109 static u32 fc_pause_off_auto(struct r8152 *tp) in fc_pause_off_auto() argument
6111 return (ALIGN(mtu_to_size(tp->netdev->mtu), 1024) + 14 * 1024); in fc_pause_off_auto()
6114 static void r8156_fc_parameter(struct r8152 *tp) in r8156_fc_parameter() argument
6116 u32 pause_on = tp->fc_pause_on ? tp->fc_pause_on : fc_pause_on_auto(tp); in r8156_fc_parameter()
6117 u32 pause_off = tp->fc_pause_off ? tp->fc_pause_off : fc_pause_off_auto(tp); in r8156_fc_parameter()
6119 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RX_FIFO_FULL, pause_on / 16); in r8156_fc_parameter()
6120 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RX_FIFO_EMPTY, pause_off / 16); in r8156_fc_parameter()
6123 static int rtl8156_enable(struct r8152 *tp) in rtl8156_enable() argument
6128 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl8156_enable()
6131 r8156_fc_parameter(tp); in rtl8156_enable()
6132 set_tx_qlen(tp); in rtl8156_enable()
6133 rtl_set_eee_plus(tp); in rtl8156_enable()
6134 r8153_set_rx_early_timeout(tp); in rtl8156_enable()
6135 r8153_set_rx_early_size(tp); in rtl8156_enable()
6137 speed = rtl8152_get_speed(tp); in rtl8156_enable()
6138 rtl_set_ifg(tp, speed); in rtl8156_enable()
6140 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4); in rtl8156_enable()
6145 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4, ocp_data); in rtl8156_enable()
6148 ocp_write_word(tp, MCU_TYPE_PLA, PLA_EEE_TXTWSYS, 0x11); in rtl8156_enable()
6150 ocp_write_word(tp, MCU_TYPE_PLA, PLA_EEE_TXTWSYS, 0x3d); in rtl8156_enable()
6152 if (tp->udev->speed == USB_SPEED_HIGH) { in rtl8156_enable()
6154 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_L1_CTRL); in rtl8156_enable()
6160 ocp_write_word(tp, MCU_TYPE_USB, USB_L1_CTRL, ocp_data); in rtl8156_enable()
6163 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_TASK); in rtl8156_enable()
6165 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_TASK, ocp_data); in rtl8156_enable()
6168 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_TASK, ocp_data); in rtl8156_enable()
6170 return rtl_enable(tp); in rtl8156_enable()
6173 static void rtl8156_disable(struct r8152 *tp) in rtl8156_disable() argument
6175 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RX_FIFO_FULL, 0); in rtl8156_disable()
6176 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RX_FIFO_EMPTY, 0); in rtl8156_disable()
6178 rtl8153_disable(tp); in rtl8156_disable()
6181 static int rtl8156b_enable(struct r8152 *tp) in rtl8156b_enable() argument
6186 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl8156b_enable()
6189 set_tx_qlen(tp); in rtl8156b_enable()
6190 rtl_set_eee_plus(tp); in rtl8156b_enable()
6192 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_RX_AGGR_NUM); in rtl8156b_enable()
6194 ocp_write_word(tp, MCU_TYPE_USB, USB_RX_AGGR_NUM, ocp_data); in rtl8156b_enable()
6196 r8153_set_rx_early_timeout(tp); in rtl8156b_enable()
6197 r8153_set_rx_early_size(tp); in rtl8156b_enable()
6199 speed = rtl8152_get_speed(tp); in rtl8156b_enable()
6200 rtl_set_ifg(tp, speed); in rtl8156b_enable()
6202 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4); in rtl8156b_enable()
6207 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4, ocp_data); in rtl8156b_enable()
6209 if (tp->udev->speed == USB_SPEED_HIGH) { in rtl8156b_enable()
6210 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_L1_CTRL); in rtl8156b_enable()
6216 ocp_write_word(tp, MCU_TYPE_USB, USB_L1_CTRL, ocp_data); in rtl8156b_enable()
6219 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_TASK); in rtl8156b_enable()
6221 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_TASK, ocp_data); in rtl8156b_enable()
6224 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_TASK, ocp_data); in rtl8156b_enable()
6226 return rtl_enable(tp); in rtl8156b_enable()
6229 static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u32 speed, u8 duplex, in rtl8152_set_speed() argument
6244 tp->ups_info.speed_duplex = FORCE_10M_FULL; in rtl8152_set_speed()
6246 tp->ups_info.speed_duplex = FORCE_10M_HALF; in rtl8152_set_speed()
6253 tp->ups_info.speed_duplex = FORCE_100M_FULL; in rtl8152_set_speed()
6255 tp->ups_info.speed_duplex = FORCE_100M_HALF; in rtl8152_set_speed()
6259 if (tp->mii.supports_gmii) { in rtl8152_set_speed()
6261 tp->ups_info.speed_duplex = NWAY_1000M_FULL; in rtl8152_set_speed()
6271 tp->mii.full_duplex = 1; in rtl8152_set_speed()
6273 tp->mii.full_duplex = 0; in rtl8152_set_speed()
6275 tp->mii.force_media = 1; in rtl8152_set_speed()
6283 if (tp->mii.supports_gmii) { in rtl8152_set_speed()
6286 if (tp->support_2500full) in rtl8152_set_speed()
6293 orig = r8152_mdio_read(tp, MII_ADVERTISE); in rtl8152_set_speed()
6298 tp->ups_info.speed_duplex = NWAY_10M_HALF; in rtl8152_set_speed()
6302 tp->ups_info.speed_duplex = NWAY_10M_FULL; in rtl8152_set_speed()
6307 tp->ups_info.speed_duplex = NWAY_100M_HALF; in rtl8152_set_speed()
6311 tp->ups_info.speed_duplex = NWAY_100M_FULL; in rtl8152_set_speed()
6315 r8152_mdio_write(tp, MII_ADVERTISE, new1); in rtl8152_set_speed()
6316 tp->mii.advertising = new1; in rtl8152_set_speed()
6319 if (tp->mii.supports_gmii) { in rtl8152_set_speed()
6320 orig = r8152_mdio_read(tp, MII_CTRL1000); in rtl8152_set_speed()
6326 tp->ups_info.speed_duplex = NWAY_1000M_FULL; in rtl8152_set_speed()
6330 r8152_mdio_write(tp, MII_CTRL1000, new1); in rtl8152_set_speed()
6333 if (tp->support_2500full) { in rtl8152_set_speed()
6334 orig = ocp_reg_read(tp, OCP_10GBT_CTRL); in rtl8152_set_speed()
6339 tp->ups_info.speed_duplex = NWAY_2500M_FULL; in rtl8152_set_speed()
6343 ocp_reg_write(tp, OCP_10GBT_CTRL, new1); in rtl8152_set_speed()
6348 tp->mii.force_media = 0; in rtl8152_set_speed()
6351 if (test_and_clear_bit(PHY_RESET, &tp->flags)) in rtl8152_set_speed()
6354 r8152_mdio_write(tp, MII_BMCR, bmcr); in rtl8152_set_speed()
6361 if ((r8152_mdio_read(tp, MII_BMCR) & BMCR_RESET) == 0) in rtl8152_set_speed()
6370 static void rtl8152_up(struct r8152 *tp) in rtl8152_up() argument
6372 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl8152_up()
6375 r8152_aldps_en(tp, false); in rtl8152_up()
6376 r8152b_exit_oob(tp); in rtl8152_up()
6377 r8152_aldps_en(tp, true); in rtl8152_up()
6380 static void rtl8152_down(struct r8152 *tp) in rtl8152_down() argument
6382 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) { in rtl8152_down()
6383 rtl_drop_queued_tx(tp); in rtl8152_down()
6387 r8152_power_cut_en(tp, false); in rtl8152_down()
6388 r8152_aldps_en(tp, false); in rtl8152_down()
6389 r8152b_enter_oob(tp); in rtl8152_down()
6390 r8152_aldps_en(tp, true); in rtl8152_down()
6393 static void rtl8153_up(struct r8152 *tp) in rtl8153_up() argument
6397 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl8153_up()
6400 r8153_u1u2en(tp, false); in rtl8153_up()
6401 r8153_u2p3en(tp, false); in rtl8153_up()
6402 r8153_aldps_en(tp, false); in rtl8153_up()
6403 r8153_first_init(tp); in rtl8153_up()
6405 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6); in rtl8153_up()
6407 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6, ocp_data); in rtl8153_up()
6409 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_LWAKE_CTRL_REG); in rtl8153_up()
6411 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_LWAKE_CTRL_REG, ocp_data); in rtl8153_up()
6413 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_SSPHYLINK1); in rtl8153_up()
6415 ocp_write_word(tp, MCU_TYPE_USB, USB_SSPHYLINK1, ocp_data); in rtl8153_up()
6417 r8153_aldps_en(tp, true); in rtl8153_up()
6419 switch (tp->version) { in rtl8153_up()
6426 r8153_u2p3en(tp, true); in rtl8153_up()
6430 r8153_u1u2en(tp, true); in rtl8153_up()
6433 static void rtl8153_down(struct r8152 *tp) in rtl8153_down() argument
6437 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) { in rtl8153_down()
6438 rtl_drop_queued_tx(tp); in rtl8153_down()
6442 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6); in rtl8153_down()
6444 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6, ocp_data); in rtl8153_down()
6446 r8153_u1u2en(tp, false); in rtl8153_down()
6447 r8153_u2p3en(tp, false); in rtl8153_down()
6448 r8153_power_cut_en(tp, false); in rtl8153_down()
6449 r8153_aldps_en(tp, false); in rtl8153_down()
6450 r8153_enter_oob(tp); in rtl8153_down()
6451 r8153_aldps_en(tp, true); in rtl8153_down()
6454 static void rtl8153b_up(struct r8152 *tp) in rtl8153b_up() argument
6458 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl8153b_up()
6461 r8153b_u1u2en(tp, false); in rtl8153b_up()
6462 r8153_u2p3en(tp, false); in rtl8153b_up()
6463 r8153_aldps_en(tp, false); in rtl8153b_up()
6465 r8153_first_init(tp); in rtl8153b_up()
6466 ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH, RX_THR_B); in rtl8153b_up()
6468 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3); in rtl8153b_up()
6470 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data); in rtl8153b_up()
6472 r8153_aldps_en(tp, true); in rtl8153b_up()
6474 if (tp->udev->speed >= USB_SPEED_SUPER) in rtl8153b_up()
6475 r8153b_u1u2en(tp, true); in rtl8153b_up()
6478 static void rtl8153b_down(struct r8152 *tp) in rtl8153b_down() argument
6482 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) { in rtl8153b_down()
6483 rtl_drop_queued_tx(tp); in rtl8153b_down()
6487 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3); in rtl8153b_down()
6489 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data); in rtl8153b_down()
6491 r8153b_u1u2en(tp, false); in rtl8153b_down()
6492 r8153_u2p3en(tp, false); in rtl8153b_down()
6493 r8153b_power_cut_en(tp, false); in rtl8153b_down()
6494 r8153_aldps_en(tp, false); in rtl8153b_down()
6495 r8153_enter_oob(tp); in rtl8153b_down()
6496 r8153_aldps_en(tp, true); in rtl8153b_down()
6499 static void rtl8153c_change_mtu(struct r8152 *tp) in rtl8153c_change_mtu() argument
6501 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, mtu_to_size(tp->netdev->mtu)); in rtl8153c_change_mtu()
6502 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_MTPS, 10 * 1024 / 64); in rtl8153c_change_mtu()
6504 ocp_write_word(tp, MCU_TYPE_PLA, PLA_TXFIFO_CTRL, 512 / 64); in rtl8153c_change_mtu()
6509 if (tp->netdev->mtu < 8000) in rtl8153c_change_mtu()
6510 ocp_write_word(tp, MCU_TYPE_PLA, PLA_TXFIFO_FULL, 2048 / 8); in rtl8153c_change_mtu()
6512 ocp_write_word(tp, MCU_TYPE_PLA, PLA_TXFIFO_FULL, 900 / 8); in rtl8153c_change_mtu()
6515 static void rtl8153c_up(struct r8152 *tp) in rtl8153c_up() argument
6519 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl8153c_up()
6522 r8153b_u1u2en(tp, false); in rtl8153c_up()
6523 r8153_u2p3en(tp, false); in rtl8153c_up()
6524 r8153_aldps_en(tp, false); in rtl8153c_up()
6526 rxdy_gated_en(tp, true); in rtl8153c_up()
6527 r8153_teredo_off(tp); in rtl8153c_up()
6529 ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); in rtl8153c_up()
6531 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); in rtl8153c_up()
6533 rtl8152_nic_reset(tp); in rtl8153c_up()
6534 rtl_reset_bmu(tp); in rtl8153c_up()
6536 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); in rtl8153c_up()
6538 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data); in rtl8153c_up()
6540 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7); in rtl8153c_up()
6542 ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data); in rtl8153c_up()
6544 wait_oob_link_list_ready(tp); in rtl8153c_up()
6546 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7); in rtl8153c_up()
6548 ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data); in rtl8153c_up()
6550 wait_oob_link_list_ready(tp); in rtl8153c_up()
6552 rtl_rx_vlan_en(tp, tp->netdev->features & NETIF_F_HW_VLAN_CTAG_RX); in rtl8153c_up()
6554 rtl8153c_change_mtu(tp); in rtl8153c_up()
6556 rtl8152_nic_reset(tp); in rtl8153c_up()
6559 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL0, 0x02); in rtl8153c_up()
6560 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_RXFIFO_FULL, 0x08); in rtl8153c_up()
6561 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL1, RXFIFO_THR2_NORMAL); in rtl8153c_up()
6562 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL2, RXFIFO_THR3_NORMAL); in rtl8153c_up()
6564 ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH, RX_THR_B); in rtl8153c_up()
6566 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_CONFIG); in rtl8153c_up()
6568 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CONFIG34); in rtl8153c_up()
6570 ocp_write_word(tp, MCU_TYPE_PLA, PLA_CONFIG34, ocp_data); in rtl8153c_up()
6572 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML); in rtl8153c_up()
6574 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3); in rtl8153c_up()
6576 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data); in rtl8153c_up()
6578 r8153_aldps_en(tp, true); in rtl8153c_up()
6579 r8153b_u1u2en(tp, true); in rtl8153c_up()
6582 static void rtl8156_change_mtu(struct r8152 *tp) in rtl8156_change_mtu() argument
6584 u32 rx_max_size = mtu_to_size(tp->netdev->mtu); in rtl8156_change_mtu()
6586 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, rx_max_size); in rtl8156_change_mtu()
6587 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_MTPS, MTPS_JUMBO); in rtl8156_change_mtu()
6588 r8156_fc_parameter(tp); in rtl8156_change_mtu()
6591 ocp_write_word(tp, MCU_TYPE_PLA, PLA_TXFIFO_CTRL, 512 / 64); in rtl8156_change_mtu()
6592 ocp_write_word(tp, MCU_TYPE_PLA, PLA_TXFIFO_FULL, in rtl8156_change_mtu()
6596 static void rtl8156_up(struct r8152 *tp) in rtl8156_up() argument
6600 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl8156_up()
6603 r8153b_u1u2en(tp, false); in rtl8156_up()
6604 r8153_u2p3en(tp, false); in rtl8156_up()
6605 r8153_aldps_en(tp, false); in rtl8156_up()
6607 rxdy_gated_en(tp, true); in rtl8156_up()
6608 r8153_teredo_off(tp); in rtl8156_up()
6610 ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); in rtl8156_up()
6612 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); in rtl8156_up()
6614 rtl8152_nic_reset(tp); in rtl8156_up()
6615 rtl_reset_bmu(tp); in rtl8156_up()
6617 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); in rtl8156_up()
6619 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data); in rtl8156_up()
6621 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7); in rtl8156_up()
6623 ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data); in rtl8156_up()
6625 rtl_rx_vlan_en(tp, tp->netdev->features & NETIF_F_HW_VLAN_CTAG_RX); in rtl8156_up()
6627 rtl8156_change_mtu(tp); in rtl8156_up()
6629 switch (tp->version) { in rtl8156_up()
6633 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_BMU_CONFIG); in rtl8156_up()
6635 ocp_write_word(tp, MCU_TYPE_USB, USB_BMU_CONFIG, ocp_data); in rtl8156_up()
6642 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_RXFIFO_FULL); in rtl8156_up()
6645 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RXFIFO_FULL, ocp_data); in rtl8156_up()
6647 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3); in rtl8156_up()
6649 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data); in rtl8156_up()
6651 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_SPEED_OPTION); in rtl8156_up()
6653 ocp_write_word(tp, MCU_TYPE_USB, USB_SPEED_OPTION, ocp_data); in rtl8156_up()
6655 ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH, 0x00600400); in rtl8156_up()
6657 if (tp->saved_wolopts != __rtl_get_wol(tp)) { in rtl8156_up()
6658 netif_warn(tp, ifup, tp->netdev, "wol setting is changed\n"); in rtl8156_up()
6659 __rtl_set_wol(tp, tp->saved_wolopts); in rtl8156_up()
6662 r8153_aldps_en(tp, true); in rtl8156_up()
6663 r8153_u2p3en(tp, true); in rtl8156_up()
6665 if (tp->udev->speed >= USB_SPEED_SUPER) in rtl8156_up()
6666 r8153b_u1u2en(tp, true); in rtl8156_up()
6669 static void rtl8156_down(struct r8152 *tp) in rtl8156_down() argument
6673 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) { in rtl8156_down()
6674 rtl_drop_queued_tx(tp); in rtl8156_down()
6678 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3); in rtl8156_down()
6680 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data); in rtl8156_down()
6682 r8153b_u1u2en(tp, false); in rtl8156_down()
6683 r8153_u2p3en(tp, false); in rtl8156_down()
6684 r8153b_power_cut_en(tp, false); in rtl8156_down()
6685 r8153_aldps_en(tp, false); in rtl8156_down()
6687 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); in rtl8156_down()
6689 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data); in rtl8156_down()
6692 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RXFIFO_FULL, 64 / 16); in rtl8156_down()
6693 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RX_FIFO_FULL, 1024 / 16); in rtl8156_down()
6694 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RX_FIFO_EMPTY, 4096 / 16); in rtl8156_down()
6696 rtl_disable(tp); in rtl8156_down()
6697 rtl_reset_bmu(tp); in rtl8156_down()
6699 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, 1522); in rtl8156_down()
6700 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_MTPS, MTPS_DEFAULT); in rtl8156_down()
6706 ocp_write_word(tp, MCU_TYPE_PLA, PLA_TEREDO_WAKE_BASE, 0x00ff); in rtl8156_down()
6708 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); in rtl8156_down()
6710 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data); in rtl8156_down()
6712 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7); in rtl8156_down()
6714 ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data); in rtl8156_down()
6716 rtl_rx_vlan_en(tp, true); in rtl8156_down()
6717 rxdy_gated_en(tp, false); in rtl8156_down()
6719 ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); in rtl8156_down()
6721 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); in rtl8156_down()
6723 r8153_aldps_en(tp, true); in rtl8156_down()
6726 static bool rtl8152_in_nway(struct r8152 *tp) in rtl8152_in_nway() argument
6730 ocp_write_word(tp, MCU_TYPE_PLA, PLA_OCP_GPHY_BASE, 0x2000); in rtl8152_in_nway()
6731 tp->ocp_base = 0x2000; in rtl8152_in_nway()
6732 ocp_write_byte(tp, MCU_TYPE_PLA, 0xb014, 0x4c); /* phy state */ in rtl8152_in_nway()
6733 nway_state = ocp_read_word(tp, MCU_TYPE_PLA, 0xb01a); in rtl8152_in_nway()
6742 static bool rtl8153_in_nway(struct r8152 *tp) in rtl8153_in_nway() argument
6744 u16 phy_state = ocp_reg_read(tp, OCP_PHY_STATE) & 0xff; in rtl8153_in_nway()
6752 static void r8156_mdio_force_mode(struct r8152 *tp) in r8156_mdio_force_mode() argument
6760 data = ocp_reg_read(tp, 0xa5b4); in r8156_mdio_force_mode()
6763 ocp_reg_write(tp, 0xa5b4, data); in r8156_mdio_force_mode()
6767 static void set_carrier(struct r8152 *tp) in set_carrier() argument
6769 struct net_device *netdev = tp->netdev; in set_carrier()
6770 struct napi_struct *napi = &tp->napi; in set_carrier()
6773 speed = rtl8152_get_speed(tp); in set_carrier()
6777 tp->rtl_ops.enable(tp); in set_carrier()
6781 rtl_start_rx(tp); in set_carrier()
6782 clear_bit(RTL8152_SET_RX_MODE, &tp->flags); in set_carrier()
6786 netif_info(tp, link, netdev, "carrier on\n"); in set_carrier()
6788 skb_queue_len(&tp->tx_queue) < tp->tx_qlen) { in set_carrier()
6794 tasklet_disable(&tp->tx_tl); in set_carrier()
6796 tp->rtl_ops.disable(tp); in set_carrier()
6798 tasklet_enable(&tp->tx_tl); in set_carrier()
6799 netif_info(tp, link, netdev, "carrier off\n"); in set_carrier()
6806 struct r8152 *tp = container_of(work, struct r8152, schedule.work); in rtl_work_func_t() local
6811 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags) || !netif_running(tp->netdev)) in rtl_work_func_t()
6814 if (usb_autopm_get_interface(tp->intf) < 0) in rtl_work_func_t()
6817 if (!test_bit(WORK_ENABLE, &tp->flags)) in rtl_work_func_t()
6820 if (!mutex_trylock(&tp->control)) { in rtl_work_func_t()
6821 schedule_delayed_work(&tp->schedule, 0); in rtl_work_func_t()
6825 if (test_and_clear_bit(RTL8152_LINK_CHG, &tp->flags)) in rtl_work_func_t()
6826 set_carrier(tp); in rtl_work_func_t()
6828 if (test_and_clear_bit(RTL8152_SET_RX_MODE, &tp->flags)) in rtl_work_func_t()
6829 _rtl8152_set_rx_mode(tp->netdev); in rtl_work_func_t()
6832 if (test_and_clear_bit(SCHEDULE_TASKLET, &tp->flags) && in rtl_work_func_t()
6833 netif_carrier_ok(tp->netdev)) in rtl_work_func_t()
6834 tasklet_schedule(&tp->tx_tl); in rtl_work_func_t()
6836 if (test_and_clear_bit(RX_EPROTO, &tp->flags) && in rtl_work_func_t()
6837 !list_empty(&tp->rx_done)) in rtl_work_func_t()
6838 napi_schedule(&tp->napi); in rtl_work_func_t()
6840 mutex_unlock(&tp->control); in rtl_work_func_t()
6843 usb_autopm_put_interface(tp->intf); in rtl_work_func_t()
6848 struct r8152 *tp = container_of(work, struct r8152, hw_phy_work.work); in rtl_hw_phy_work_func_t() local
6850 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl_hw_phy_work_func_t()
6853 if (usb_autopm_get_interface(tp->intf) < 0) in rtl_hw_phy_work_func_t()
6856 mutex_lock(&tp->control); in rtl_hw_phy_work_func_t()
6858 if (rtl8152_request_firmware(tp) == -ENODEV && tp->rtl_fw.retry) { in rtl_hw_phy_work_func_t()
6859 tp->rtl_fw.retry = false; in rtl_hw_phy_work_func_t()
6860 tp->rtl_fw.fw = NULL; in rtl_hw_phy_work_func_t()
6864 queue_delayed_work(system_long_wq, &tp->hw_phy_work, HZ * 10); in rtl_hw_phy_work_func_t()
6868 tp->rtl_ops.hw_phy_cfg(tp); in rtl_hw_phy_work_func_t()
6870 rtl8152_set_speed(tp, tp->autoneg, tp->speed, tp->duplex, in rtl_hw_phy_work_func_t()
6871 tp->advertising); in rtl_hw_phy_work_func_t()
6874 mutex_unlock(&tp->control); in rtl_hw_phy_work_func_t()
6876 usb_autopm_put_interface(tp->intf); in rtl_hw_phy_work_func_t()
6883 struct r8152 *tp = container_of(nb, struct r8152, pm_notifier); in rtl_notifier() local
6888 usb_autopm_get_interface(tp->intf); in rtl_notifier()
6893 usb_autopm_put_interface(tp->intf); in rtl_notifier()
6908 struct r8152 *tp = netdev_priv(netdev); in rtl8152_open() local
6911 if (work_busy(&tp->hw_phy_work.work) & WORK_BUSY_PENDING) { in rtl8152_open()
6912 cancel_delayed_work_sync(&tp->hw_phy_work); in rtl8152_open()
6913 rtl_hw_phy_work_func_t(&tp->hw_phy_work.work); in rtl8152_open()
6916 res = alloc_all_mem(tp); in rtl8152_open()
6920 res = usb_autopm_get_interface(tp->intf); in rtl8152_open()
6924 mutex_lock(&tp->control); in rtl8152_open()
6926 tp->rtl_ops.up(tp); in rtl8152_open()
6930 set_bit(WORK_ENABLE, &tp->flags); in rtl8152_open()
6932 res = usb_submit_urb(tp->intr_urb, GFP_KERNEL); in rtl8152_open()
6935 netif_device_detach(tp->netdev); in rtl8152_open()
6936 netif_warn(tp, ifup, netdev, "intr_urb submit failed: %d\n", in rtl8152_open()
6940 napi_enable(&tp->napi); in rtl8152_open()
6941 tasklet_enable(&tp->tx_tl); in rtl8152_open()
6943 mutex_unlock(&tp->control); in rtl8152_open()
6945 usb_autopm_put_interface(tp->intf); in rtl8152_open()
6947 tp->pm_notifier.notifier_call = rtl_notifier; in rtl8152_open()
6948 register_pm_notifier(&tp->pm_notifier); in rtl8152_open()
6953 mutex_unlock(&tp->control); in rtl8152_open()
6954 usb_autopm_put_interface(tp->intf); in rtl8152_open()
6956 free_all_mem(tp); in rtl8152_open()
6963 struct r8152 *tp = netdev_priv(netdev); in rtl8152_close() local
6967 unregister_pm_notifier(&tp->pm_notifier); in rtl8152_close()
6969 tasklet_disable(&tp->tx_tl); in rtl8152_close()
6970 clear_bit(WORK_ENABLE, &tp->flags); in rtl8152_close()
6971 usb_kill_urb(tp->intr_urb); in rtl8152_close()
6972 cancel_delayed_work_sync(&tp->schedule); in rtl8152_close()
6973 napi_disable(&tp->napi); in rtl8152_close()
6976 res = usb_autopm_get_interface(tp->intf); in rtl8152_close()
6977 if (res < 0 || test_bit(RTL8152_INACCESSIBLE, &tp->flags)) { in rtl8152_close()
6978 rtl_drop_queued_tx(tp); in rtl8152_close()
6979 rtl_stop_rx(tp); in rtl8152_close()
6981 mutex_lock(&tp->control); in rtl8152_close()
6983 tp->rtl_ops.down(tp); in rtl8152_close()
6985 mutex_unlock(&tp->control); in rtl8152_close()
6989 usb_autopm_put_interface(tp->intf); in rtl8152_close()
6991 free_all_mem(tp); in rtl8152_close()
6996 static void rtl_tally_reset(struct r8152 *tp) in rtl_tally_reset() argument
7000 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_RSTTALLY); in rtl_tally_reset()
7002 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RSTTALLY, ocp_data); in rtl_tally_reset()
7005 static void r8152b_init(struct r8152 *tp) in r8152b_init() argument
7010 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8152b_init()
7013 data = r8152_mdio_read(tp, MII_BMCR); in r8152b_init()
7016 r8152_mdio_write(tp, MII_BMCR, data); in r8152b_init()
7019 r8152_aldps_en(tp, false); in r8152b_init()
7021 if (tp->version == RTL_VER_01) { in r8152b_init()
7022 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE); in r8152b_init()
7024 ocp_write_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE, ocp_data); in r8152b_init()
7027 r8152_power_cut_en(tp, false); in r8152b_init()
7029 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR); in r8152b_init()
7031 ocp_write_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR, ocp_data); in r8152b_init()
7032 ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL); in r8152b_init()
7035 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL, ocp_data); in r8152b_init()
7038 ocp_write_word(tp, MCU_TYPE_PLA, PLA_GPHY_INTR_IMR, ocp_data); in r8152b_init()
7040 rtl_tally_reset(tp); in r8152b_init()
7043 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL); in r8152b_init()
7045 ocp_write_word(tp, MCU_TYPE_USB, USB_USB_CTRL, ocp_data); in r8152b_init()
7048 static void r8153_init(struct r8152 *tp) in r8153_init() argument
7054 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8153_init()
7057 r8153_u1u2en(tp, false); in r8153_init()
7060 if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) & in r8153_init()
7065 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8153_init()
7069 data = r8153_phy_status(tp, 0); in r8153_init()
7071 if (tp->version == RTL_VER_03 || tp->version == RTL_VER_04 || in r8153_init()
7072 tp->version == RTL_VER_05) in r8153_init()
7073 ocp_reg_write(tp, OCP_ADC_CFG, CKADSEL_L | ADC_EN | EN_EMI_L); in r8153_init()
7075 data = r8152_mdio_read(tp, MII_BMCR); in r8153_init()
7078 r8152_mdio_write(tp, MII_BMCR, data); in r8153_init()
7081 data = r8153_phy_status(tp, PHY_STAT_LAN_ON); in r8153_init()
7083 r8153_u2p3en(tp, false); in r8153_init()
7085 if (tp->version == RTL_VER_04) { in r8153_init()
7086 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_SSPHYLINK2); in r8153_init()
7089 ocp_write_word(tp, MCU_TYPE_USB, USB_SSPHYLINK2, ocp_data); in r8153_init()
7091 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_USB2PHY); in r8153_init()
7093 ocp_write_byte(tp, MCU_TYPE_USB, USB_USB2PHY, ocp_data); in r8153_init()
7094 } else if (tp->version == RTL_VER_05) { in r8153_init()
7095 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_DMY_REG0); in r8153_init()
7097 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_DMY_REG0, ocp_data); in r8153_init()
7099 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY1); in r8153_init()
7100 if (ocp_read_word(tp, MCU_TYPE_USB, USB_BURST_SIZE) == 0) in r8153_init()
7104 ocp_write_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY1, ocp_data); in r8153_init()
7105 } else if (tp->version == RTL_VER_06) { in r8153_init()
7106 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY1); in r8153_init()
7107 if (ocp_read_word(tp, MCU_TYPE_USB, USB_BURST_SIZE) == 0) in r8153_init()
7111 ocp_write_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY1, ocp_data); in r8153_init()
7113 r8153_queue_wake(tp, false); in r8153_init()
7115 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS); in r8153_init()
7116 if (rtl8152_get_speed(tp) & LINK_STATUS) in r8153_init()
7121 ocp_write_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS, ocp_data); in r8153_init()
7124 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY2); in r8153_init()
7126 ocp_write_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY2, ocp_data); in r8153_init()
7128 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_WDT11_CTRL); in r8153_init()
7130 ocp_write_word(tp, MCU_TYPE_USB, USB_WDT11_CTRL, ocp_data); in r8153_init()
7132 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE); in r8153_init()
7134 ocp_write_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE, ocp_data); in r8153_init()
7137 if (tp->version == RTL_VER_04 && tp->udev->speed < USB_SPEED_SUPER) in r8153_init()
7141 ocp_write_byte(tp, MCU_TYPE_USB, USB_LPM_CTRL, ocp_data); in r8153_init()
7143 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_AFE_CTRL2); in r8153_init()
7146 ocp_write_word(tp, MCU_TYPE_USB, USB_AFE_CTRL2, ocp_data); in r8153_init()
7148 ocp_write_word(tp, MCU_TYPE_USB, USB_CONNECT_TIMER, 0x0001); in r8153_init()
7150 r8153_power_cut_en(tp, false); in r8153_init()
7151 rtl_runtime_suspend_enable(tp, false); in r8153_init()
7152 r8153_mac_clk_speed_down(tp, false); in r8153_init()
7153 r8153_u1u2en(tp, true); in r8153_init()
7154 usb_enable_lpm(tp->udev); in r8153_init()
7156 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6); in r8153_init()
7158 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6, ocp_data); in r8153_init()
7160 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_LWAKE_CTRL_REG); in r8153_init()
7162 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_LWAKE_CTRL_REG, ocp_data); in r8153_init()
7165 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL); in r8153_init()
7167 if (tp->dell_tb_rx_agg_bug) in r8153_init()
7170 ocp_write_word(tp, MCU_TYPE_USB, USB_USB_CTRL, ocp_data); in r8153_init()
7172 rtl_tally_reset(tp); in r8153_init()
7174 switch (tp->udev->speed) { in r8153_init()
7177 tp->coalesce = COALESCE_SUPER; in r8153_init()
7180 tp->coalesce = COALESCE_HIGH; in r8153_init()
7183 tp->coalesce = COALESCE_SLOW; in r8153_init()
7188 static void r8153b_init(struct r8152 *tp) in r8153b_init() argument
7194 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8153b_init()
7197 r8153b_u1u2en(tp, false); in r8153b_init()
7200 if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) & in r8153b_init()
7205 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8153b_init()
7209 data = r8153_phy_status(tp, 0); in r8153b_init()
7211 data = r8152_mdio_read(tp, MII_BMCR); in r8153b_init()
7214 r8152_mdio_write(tp, MII_BMCR, data); in r8153b_init()
7217 data = r8153_phy_status(tp, PHY_STAT_LAN_ON); in r8153b_init()
7219 r8153_u2p3en(tp, false); in r8153b_init()
7222 ocp_write_word(tp, MCU_TYPE_USB, USB_MSC_TIMER, 0x0fff); in r8153b_init()
7224 r8153b_power_cut_en(tp, false); in r8153b_init()
7225 r8153b_ups_en(tp, false); in r8153b_init()
7226 r8153_queue_wake(tp, false); in r8153b_init()
7227 rtl_runtime_suspend_enable(tp, false); in r8153b_init()
7229 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS); in r8153b_init()
7230 if (rtl8152_get_speed(tp) & LINK_STATUS) in r8153b_init()
7235 ocp_write_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS, ocp_data); in r8153b_init()
7237 if (tp->udev->speed >= USB_SPEED_SUPER) in r8153b_init()
7238 r8153b_u1u2en(tp, true); in r8153b_init()
7240 usb_enable_lpm(tp->udev); in r8153b_init()
7243 r8153_mac_clk_speed_down(tp, true); in r8153b_init()
7245 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3); in r8153b_init()
7247 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data); in r8153b_init()
7249 if (tp->version == RTL_VER_09) { in r8153b_init()
7251 if (ocp_read_byte(tp, MCU_TYPE_PLA, 0xdc00) & BIT(5)) { in r8153b_init()
7252 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR); in r8153b_init()
7254 ocp_write_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR, ocp_data); in r8153b_init()
7258 set_bit(GREEN_ETHERNET, &tp->flags); in r8153b_init()
7261 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL); in r8153b_init()
7263 ocp_write_word(tp, MCU_TYPE_USB, USB_USB_CTRL, ocp_data); in r8153b_init()
7265 rtl_tally_reset(tp); in r8153b_init()
7267 tp->coalesce = 15000; /* 15 us */ in r8153b_init()
7270 static void r8153c_init(struct r8152 *tp) in r8153c_init() argument
7276 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8153c_init()
7279 r8153b_u1u2en(tp, false); in r8153c_init()
7282 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_CONFIG); in r8153c_init()
7283 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CONFIG5); in r8153c_init()
7285 ocp_write_word(tp, MCU_TYPE_PLA, PLA_CONFIG5, ocp_data); in r8153c_init()
7286 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, 0xcbf0); in r8153c_init()
7288 ocp_write_word(tp, MCU_TYPE_USB, 0xcbf0, ocp_data); in r8153c_init()
7291 if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) & in r8153c_init()
7296 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8153c_init()
7300 data = r8153_phy_status(tp, 0); in r8153c_init()
7302 data = r8152_mdio_read(tp, MII_BMCR); in r8153c_init()
7305 r8152_mdio_write(tp, MII_BMCR, data); in r8153c_init()
7308 data = r8153_phy_status(tp, PHY_STAT_LAN_ON); in r8153c_init()
7310 r8153_u2p3en(tp, false); in r8153c_init()
7313 ocp_write_word(tp, MCU_TYPE_USB, USB_MSC_TIMER, 0x0fff); in r8153c_init()
7315 r8153b_power_cut_en(tp, false); in r8153c_init()
7316 r8153c_ups_en(tp, false); in r8153c_init()
7317 r8153_queue_wake(tp, false); in r8153c_init()
7318 rtl_runtime_suspend_enable(tp, false); in r8153c_init()
7320 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS); in r8153c_init()
7321 if (rtl8152_get_speed(tp) & LINK_STATUS) in r8153c_init()
7327 ocp_write_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS, ocp_data); in r8153c_init()
7329 r8153b_u1u2en(tp, true); in r8153c_init()
7331 usb_enable_lpm(tp->udev); in r8153c_init()
7334 r8153_mac_clk_speed_down(tp, true); in r8153c_init()
7336 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_MISC_2); in r8153c_init()
7338 ocp_write_byte(tp, MCU_TYPE_USB, USB_MISC_2, ocp_data); in r8153c_init()
7340 set_bit(GREEN_ETHERNET, &tp->flags); in r8153c_init()
7343 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL); in r8153c_init()
7345 ocp_write_word(tp, MCU_TYPE_USB, USB_USB_CTRL, ocp_data); in r8153c_init()
7347 rtl_tally_reset(tp); in r8153c_init()
7349 tp->coalesce = 15000; /* 15 us */ in r8153c_init()
7352 static void r8156_hw_phy_cfg(struct r8152 *tp) in r8156_hw_phy_cfg() argument
7357 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0); in r8156_hw_phy_cfg()
7360 ocp_write_word(tp, MCU_TYPE_USB, USB_MISC_0, ocp_data); in r8156_hw_phy_cfg()
7363 data = r8153_phy_status(tp, 0); in r8156_hw_phy_cfg()
7366 rtl8152_apply_firmware(tp, true); in r8156_hw_phy_cfg()
7368 data = ocp_reg_read(tp, 0xa468); in r8156_hw_phy_cfg()
7370 ocp_reg_write(tp, 0xa468, data); in r8156_hw_phy_cfg()
7375 rtl8152_apply_firmware(tp, false); in r8156_hw_phy_cfg()
7380 r8153_aldps_en(tp, false); in r8156_hw_phy_cfg()
7383 rtl_eee_enable(tp, false); in r8156_hw_phy_cfg()
7385 data = r8153_phy_status(tp, PHY_STAT_LAN_ON); in r8156_hw_phy_cfg()
7388 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR); in r8156_hw_phy_cfg()
7390 ocp_write_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR, ocp_data); in r8156_hw_phy_cfg()
7392 switch (tp->version) { in r8156_hw_phy_cfg()
7394 data = ocp_reg_read(tp, 0xad40); in r8156_hw_phy_cfg()
7397 ocp_reg_write(tp, 0xad40, data); in r8156_hw_phy_cfg()
7399 data = ocp_reg_read(tp, 0xad4e); in r8156_hw_phy_cfg()
7401 ocp_reg_write(tp, 0xad4e, data); in r8156_hw_phy_cfg()
7402 data = ocp_reg_read(tp, 0xad16); in r8156_hw_phy_cfg()
7405 ocp_reg_write(tp, 0xad16, data); in r8156_hw_phy_cfg()
7406 data = ocp_reg_read(tp, 0xad32); in r8156_hw_phy_cfg()
7409 ocp_reg_write(tp, 0xad32, data); in r8156_hw_phy_cfg()
7410 data = ocp_reg_read(tp, 0xac08); in r8156_hw_phy_cfg()
7412 ocp_reg_write(tp, 0xac08, data); in r8156_hw_phy_cfg()
7413 data = ocp_reg_read(tp, 0xac8a); in r8156_hw_phy_cfg()
7416 ocp_reg_write(tp, 0xac8a, data); in r8156_hw_phy_cfg()
7417 data = ocp_reg_read(tp, 0xad18); in r8156_hw_phy_cfg()
7419 ocp_reg_write(tp, 0xad18, data); in r8156_hw_phy_cfg()
7420 data = ocp_reg_read(tp, 0xad1a); in r8156_hw_phy_cfg()
7422 ocp_reg_write(tp, 0xad1a, data); in r8156_hw_phy_cfg()
7423 data = ocp_reg_read(tp, 0xad1c); in r8156_hw_phy_cfg()
7425 ocp_reg_write(tp, 0xad1c, data); in r8156_hw_phy_cfg()
7427 data = sram_read(tp, 0x80ea); in r8156_hw_phy_cfg()
7430 sram_write(tp, 0x80ea, data); in r8156_hw_phy_cfg()
7431 data = sram_read(tp, 0x80eb); in r8156_hw_phy_cfg()
7434 sram_write(tp, 0x80eb, data); in r8156_hw_phy_cfg()
7435 data = sram_read(tp, 0x80f8); in r8156_hw_phy_cfg()
7438 sram_write(tp, 0x80f8, data); in r8156_hw_phy_cfg()
7439 data = sram_read(tp, 0x80f1); in r8156_hw_phy_cfg()
7442 sram_write(tp, 0x80f1, data); in r8156_hw_phy_cfg()
7444 data = sram_read(tp, 0x80fe); in r8156_hw_phy_cfg()
7447 sram_write(tp, 0x80fe, data); in r8156_hw_phy_cfg()
7448 data = sram_read(tp, 0x8102); in r8156_hw_phy_cfg()
7451 sram_write(tp, 0x8102, data); in r8156_hw_phy_cfg()
7452 data = sram_read(tp, 0x8015); in r8156_hw_phy_cfg()
7455 sram_write(tp, 0x8015, data); in r8156_hw_phy_cfg()
7456 data = sram_read(tp, 0x8100); in r8156_hw_phy_cfg()
7459 sram_write(tp, 0x8100, data); in r8156_hw_phy_cfg()
7460 data = sram_read(tp, 0x8014); in r8156_hw_phy_cfg()
7463 sram_write(tp, 0x8014, data); in r8156_hw_phy_cfg()
7464 data = sram_read(tp, 0x8016); in r8156_hw_phy_cfg()
7467 sram_write(tp, 0x8016, data); in r8156_hw_phy_cfg()
7468 data = sram_read(tp, 0x80dc); in r8156_hw_phy_cfg()
7471 sram_write(tp, 0x80dc, data); in r8156_hw_phy_cfg()
7472 data = sram_read(tp, 0x80df); in r8156_hw_phy_cfg()
7474 sram_write(tp, 0x80df, data); in r8156_hw_phy_cfg()
7475 data = sram_read(tp, 0x80e1); in r8156_hw_phy_cfg()
7477 sram_write(tp, 0x80e1, data); in r8156_hw_phy_cfg()
7479 data = ocp_reg_read(tp, 0xbf06); in r8156_hw_phy_cfg()
7482 ocp_reg_write(tp, 0xbf06, data); in r8156_hw_phy_cfg()
7484 sram_write(tp, 0x819f, 0xddb6); in r8156_hw_phy_cfg()
7486 ocp_reg_write(tp, 0xbc34, 0x5555); in r8156_hw_phy_cfg()
7487 data = ocp_reg_read(tp, 0xbf0a); in r8156_hw_phy_cfg()
7490 ocp_reg_write(tp, 0xbf0a, data); in r8156_hw_phy_cfg()
7492 data = ocp_reg_read(tp, 0xbd2c); in r8156_hw_phy_cfg()
7494 ocp_reg_write(tp, 0xbd2c, data); in r8156_hw_phy_cfg()
7497 data = ocp_reg_read(tp, 0xad16); in r8156_hw_phy_cfg()
7499 ocp_reg_write(tp, 0xad16, data); in r8156_hw_phy_cfg()
7500 data = ocp_reg_read(tp, 0xad32); in r8156_hw_phy_cfg()
7503 ocp_reg_write(tp, 0xad32, data); in r8156_hw_phy_cfg()
7504 data = ocp_reg_read(tp, 0xac08); in r8156_hw_phy_cfg()
7506 ocp_reg_write(tp, 0xac08, data); in r8156_hw_phy_cfg()
7507 data = ocp_reg_read(tp, 0xacc0); in r8156_hw_phy_cfg()
7510 ocp_reg_write(tp, 0xacc0, data); in r8156_hw_phy_cfg()
7511 data = ocp_reg_read(tp, 0xad40); in r8156_hw_phy_cfg()
7514 ocp_reg_write(tp, 0xad40, data); in r8156_hw_phy_cfg()
7515 data = ocp_reg_read(tp, 0xac14); in r8156_hw_phy_cfg()
7517 ocp_reg_write(tp, 0xac14, data); in r8156_hw_phy_cfg()
7518 data = ocp_reg_read(tp, 0xac80); in r8156_hw_phy_cfg()
7520 ocp_reg_write(tp, 0xac80, data); in r8156_hw_phy_cfg()
7521 data = ocp_reg_read(tp, 0xac5e); in r8156_hw_phy_cfg()
7524 ocp_reg_write(tp, 0xac5e, data); in r8156_hw_phy_cfg()
7525 ocp_reg_write(tp, 0xad4c, 0x00a8); in r8156_hw_phy_cfg()
7526 ocp_reg_write(tp, 0xac5c, 0x01ff); in r8156_hw_phy_cfg()
7527 data = ocp_reg_read(tp, 0xac8a); in r8156_hw_phy_cfg()
7530 ocp_reg_write(tp, 0xac8a, data); in r8156_hw_phy_cfg()
7531 ocp_reg_write(tp, 0xb87c, 0x8157); in r8156_hw_phy_cfg()
7532 data = ocp_reg_read(tp, 0xb87e); in r8156_hw_phy_cfg()
7535 ocp_reg_write(tp, 0xb87e, data); in r8156_hw_phy_cfg()
7536 ocp_reg_write(tp, 0xb87c, 0x8159); in r8156_hw_phy_cfg()
7537 data = ocp_reg_read(tp, 0xb87e); in r8156_hw_phy_cfg()
7540 ocp_reg_write(tp, 0xb87e, data); in r8156_hw_phy_cfg()
7543 ocp_reg_write(tp, 0xb87c, 0x80a2); in r8156_hw_phy_cfg()
7544 ocp_reg_write(tp, 0xb87e, 0x0153); in r8156_hw_phy_cfg()
7545 ocp_reg_write(tp, 0xb87c, 0x809c); in r8156_hw_phy_cfg()
7546 ocp_reg_write(tp, 0xb87e, 0x0153); in r8156_hw_phy_cfg()
7549 ocp_write_word(tp, MCU_TYPE_PLA, PLA_EEE_TXTWSYS_2P5G, 0x0056); in r8156_hw_phy_cfg()
7551 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_USB_CFG); in r8156_hw_phy_cfg()
7553 ocp_write_word(tp, MCU_TYPE_PLA, PLA_USB_CFG, ocp_data); in r8156_hw_phy_cfg()
7555 sram_write(tp, 0x8257, 0x020f); /* XG PLL */ in r8156_hw_phy_cfg()
7556 sram_write(tp, 0x80ea, 0x7843); /* GIGA Master */ in r8156_hw_phy_cfg()
7558 if (rtl_phy_patch_request(tp, true, true)) in r8156_hw_phy_cfg()
7562 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4); in r8156_hw_phy_cfg()
7564 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4, ocp_data); in r8156_hw_phy_cfg()
7566 data = ocp_reg_read(tp, OCP_DOWN_SPEED); in r8156_hw_phy_cfg()
7569 ocp_reg_write(tp, OCP_DOWN_SPEED, data); in r8156_hw_phy_cfg()
7570 tp->ups_info._10m_ckdiv = true; in r8156_hw_phy_cfg()
7571 tp->ups_info.eee_plloff_100 = false; in r8156_hw_phy_cfg()
7572 tp->ups_info.eee_plloff_giga = false; in r8156_hw_phy_cfg()
7574 data = ocp_reg_read(tp, OCP_POWER_CFG); in r8156_hw_phy_cfg()
7576 ocp_reg_write(tp, OCP_POWER_CFG, data); in r8156_hw_phy_cfg()
7577 tp->ups_info.eee_ckdiv = false; in r8156_hw_phy_cfg()
7579 ocp_reg_write(tp, OCP_SYSCLK_CFG, 0); in r8156_hw_phy_cfg()
7580 ocp_reg_write(tp, OCP_SYSCLK_CFG, sysclk_div_expo(5)); in r8156_hw_phy_cfg()
7581 tp->ups_info._250m_ckdiv = false; in r8156_hw_phy_cfg()
7583 rtl_phy_patch_request(tp, false, true); in r8156_hw_phy_cfg()
7586 data = ocp_reg_read(tp, 0xd068); in r8156_hw_phy_cfg()
7588 ocp_reg_write(tp, 0xd068, data); in r8156_hw_phy_cfg()
7591 data = sram_read(tp, 0x81a2); in r8156_hw_phy_cfg()
7593 sram_write(tp, 0x81a2, data); in r8156_hw_phy_cfg()
7594 data = ocp_reg_read(tp, 0xb54c); in r8156_hw_phy_cfg()
7597 ocp_reg_write(tp, 0xb54c, data); in r8156_hw_phy_cfg()
7600 data = ocp_reg_read(tp, 0xa454); in r8156_hw_phy_cfg()
7602 ocp_reg_write(tp, 0xa454, data); in r8156_hw_phy_cfg()
7605 data = ocp_reg_read(tp, OCP_10GBT_CTRL); in r8156_hw_phy_cfg()
7607 ocp_reg_write(tp, OCP_10GBT_CTRL, data); in r8156_hw_phy_cfg()
7608 data = ocp_reg_read(tp, 0xad4e); in r8156_hw_phy_cfg()
7610 ocp_reg_write(tp, 0xad4e, data); in r8156_hw_phy_cfg()
7611 data = ocp_reg_read(tp, 0xa86a); in r8156_hw_phy_cfg()
7613 ocp_reg_write(tp, 0xa86a, data); in r8156_hw_phy_cfg()
7616 if ((ocp_read_word(tp, MCU_TYPE_USB, USB_UPS_CFG) & MID_REVERSE) && in r8156_hw_phy_cfg()
7617 (ocp_reg_read(tp, 0xd068) & BIT(1))) { in r8156_hw_phy_cfg()
7620 data = ocp_reg_read(tp, 0xd068); in r8156_hw_phy_cfg()
7623 ocp_reg_write(tp, 0xd068, data); in r8156_hw_phy_cfg()
7624 swap_a = ocp_reg_read(tp, 0xd06a); in r8156_hw_phy_cfg()
7627 ocp_reg_write(tp, 0xd068, data); in r8156_hw_phy_cfg()
7628 swap_b = ocp_reg_read(tp, 0xd06a); in r8156_hw_phy_cfg()
7630 ocp_reg_write(tp, 0xd068, data); in r8156_hw_phy_cfg()
7631 ocp_reg_write(tp, 0xd06a, in r8156_hw_phy_cfg()
7634 ocp_reg_write(tp, 0xd068, data); in r8156_hw_phy_cfg()
7635 ocp_reg_write(tp, 0xd06a, in r8156_hw_phy_cfg()
7639 ocp_reg_write(tp, 0xd068, data); in r8156_hw_phy_cfg()
7640 swap_a = ocp_reg_read(tp, 0xd06a); in r8156_hw_phy_cfg()
7643 ocp_reg_write(tp, 0xd068, data); in r8156_hw_phy_cfg()
7644 swap_b = ocp_reg_read(tp, 0xd06a); in r8156_hw_phy_cfg()
7647 ocp_reg_write(tp, 0xd068, data); in r8156_hw_phy_cfg()
7648 ocp_reg_write(tp, 0xd06a, in r8156_hw_phy_cfg()
7652 ocp_reg_write(tp, 0xd068, data); in r8156_hw_phy_cfg()
7653 ocp_reg_write(tp, 0xd06a, in r8156_hw_phy_cfg()
7655 swap_a = ocp_reg_read(tp, 0xbd5a); in r8156_hw_phy_cfg()
7656 swap_b = ocp_reg_read(tp, 0xbd5c); in r8156_hw_phy_cfg()
7657 ocp_reg_write(tp, 0xbd5a, (swap_a & ~0x1f1f) | in r8156_hw_phy_cfg()
7660 ocp_reg_write(tp, 0xbd5c, (swap_b & ~0x1f1f) | in r8156_hw_phy_cfg()
7663 swap_a = ocp_reg_read(tp, 0xbc18); in r8156_hw_phy_cfg()
7664 swap_b = ocp_reg_read(tp, 0xbc1a); in r8156_hw_phy_cfg()
7665 ocp_reg_write(tp, 0xbc18, (swap_a & ~0x1f1f) | in r8156_hw_phy_cfg()
7668 ocp_reg_write(tp, 0xbc1a, (swap_b & ~0x1f1f) | in r8156_hw_phy_cfg()
7674 data = ocp_reg_read(tp, OCP_INTR_EN); in r8156_hw_phy_cfg()
7676 ocp_reg_write(tp, OCP_INTR_EN, data); in r8156_hw_phy_cfg()
7682 rtl_green_en(tp, test_bit(GREEN_ETHERNET, &tp->flags)); in r8156_hw_phy_cfg()
7684 data = ocp_reg_read(tp, 0xa428); in r8156_hw_phy_cfg()
7686 ocp_reg_write(tp, 0xa428, data); in r8156_hw_phy_cfg()
7687 data = ocp_reg_read(tp, 0xa5ea); in r8156_hw_phy_cfg()
7689 ocp_reg_write(tp, 0xa5ea, data); in r8156_hw_phy_cfg()
7690 tp->ups_info.lite_mode = 0; in r8156_hw_phy_cfg()
7692 if (tp->eee_en) in r8156_hw_phy_cfg()
7693 rtl_eee_enable(tp, true); in r8156_hw_phy_cfg()
7695 r8153_aldps_en(tp, true); in r8156_hw_phy_cfg()
7696 r8152b_enable_fc(tp); in r8156_hw_phy_cfg()
7697 r8153_u2p3en(tp, true); in r8156_hw_phy_cfg()
7699 set_bit(PHY_RESET, &tp->flags); in r8156_hw_phy_cfg()
7702 static void r8156b_hw_phy_cfg(struct r8152 *tp) in r8156b_hw_phy_cfg() argument
7707 switch (tp->version) { in r8156b_hw_phy_cfg()
7709 ocp_reg_write(tp, 0xbf86, 0x9000); in r8156b_hw_phy_cfg()
7710 data = ocp_reg_read(tp, 0xc402); in r8156b_hw_phy_cfg()
7712 ocp_reg_write(tp, 0xc402, data); in r8156b_hw_phy_cfg()
7714 ocp_reg_write(tp, 0xc402, data); in r8156b_hw_phy_cfg()
7715 ocp_reg_write(tp, 0xbd86, 0x1010); in r8156b_hw_phy_cfg()
7716 ocp_reg_write(tp, 0xbd88, 0x1010); in r8156b_hw_phy_cfg()
7717 data = ocp_reg_read(tp, 0xbd4e); in r8156b_hw_phy_cfg()
7720 ocp_reg_write(tp, 0xbd4e, data); in r8156b_hw_phy_cfg()
7721 data = ocp_reg_read(tp, 0xbf46); in r8156b_hw_phy_cfg()
7724 ocp_reg_write(tp, 0xbf46, data); in r8156b_hw_phy_cfg()
7728 r8156b_wait_loading_flash(tp); in r8156b_hw_phy_cfg()
7734 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0); in r8156b_hw_phy_cfg()
7737 ocp_write_word(tp, MCU_TYPE_USB, USB_MISC_0, ocp_data); in r8156b_hw_phy_cfg()
7740 data = r8153_phy_status(tp, 0); in r8156b_hw_phy_cfg()
7743 rtl8152_apply_firmware(tp, true); in r8156b_hw_phy_cfg()
7745 data = ocp_reg_read(tp, 0xa466); in r8156b_hw_phy_cfg()
7747 ocp_reg_write(tp, 0xa466, data); in r8156b_hw_phy_cfg()
7749 data = ocp_reg_read(tp, 0xa468); in r8156b_hw_phy_cfg()
7751 ocp_reg_write(tp, 0xa468, data); in r8156b_hw_phy_cfg()
7756 rtl8152_apply_firmware(tp, false); in r8156b_hw_phy_cfg()
7760 data = r8152_mdio_read(tp, MII_BMCR); in r8156b_hw_phy_cfg()
7763 r8152_mdio_write(tp, MII_BMCR, data); in r8156b_hw_phy_cfg()
7767 r8153_aldps_en(tp, false); in r8156b_hw_phy_cfg()
7770 rtl_eee_enable(tp, false); in r8156b_hw_phy_cfg()
7772 data = r8153_phy_status(tp, PHY_STAT_LAN_ON); in r8156b_hw_phy_cfg()
7775 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR); in r8156b_hw_phy_cfg()
7777 ocp_write_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR, ocp_data); in r8156b_hw_phy_cfg()
7779 switch (tp->version) { in r8156b_hw_phy_cfg()
7781 data = ocp_reg_read(tp, 0xbc08); in r8156b_hw_phy_cfg()
7783 ocp_reg_write(tp, 0xbc08, data); in r8156b_hw_phy_cfg()
7785 data = sram_read(tp, 0x8fff); in r8156b_hw_phy_cfg()
7788 sram_write(tp, 0x8fff, data); in r8156b_hw_phy_cfg()
7790 data = ocp_reg_read(tp, 0xacda); in r8156b_hw_phy_cfg()
7792 ocp_reg_write(tp, 0xacda, data); in r8156b_hw_phy_cfg()
7793 data = ocp_reg_read(tp, 0xacde); in r8156b_hw_phy_cfg()
7795 ocp_reg_write(tp, 0xacde, data); in r8156b_hw_phy_cfg()
7796 ocp_reg_write(tp, 0xac8c, 0x0ffc); in r8156b_hw_phy_cfg()
7797 ocp_reg_write(tp, 0xac46, 0xb7b4); in r8156b_hw_phy_cfg()
7798 ocp_reg_write(tp, 0xac50, 0x0fbc); in r8156b_hw_phy_cfg()
7799 ocp_reg_write(tp, 0xac3c, 0x9240); in r8156b_hw_phy_cfg()
7800 ocp_reg_write(tp, 0xac4e, 0x0db4); in r8156b_hw_phy_cfg()
7801 ocp_reg_write(tp, 0xacc6, 0x0707); in r8156b_hw_phy_cfg()
7802 ocp_reg_write(tp, 0xacc8, 0xa0d3); in r8156b_hw_phy_cfg()
7803 ocp_reg_write(tp, 0xad08, 0x0007); in r8156b_hw_phy_cfg()
7805 ocp_reg_write(tp, 0xb87c, 0x8560); in r8156b_hw_phy_cfg()
7806 ocp_reg_write(tp, 0xb87e, 0x19cc); in r8156b_hw_phy_cfg()
7807 ocp_reg_write(tp, 0xb87c, 0x8562); in r8156b_hw_phy_cfg()
7808 ocp_reg_write(tp, 0xb87e, 0x19cc); in r8156b_hw_phy_cfg()
7809 ocp_reg_write(tp, 0xb87c, 0x8564); in r8156b_hw_phy_cfg()
7810 ocp_reg_write(tp, 0xb87e, 0x19cc); in r8156b_hw_phy_cfg()
7811 ocp_reg_write(tp, 0xb87c, 0x8566); in r8156b_hw_phy_cfg()
7812 ocp_reg_write(tp, 0xb87e, 0x147d); in r8156b_hw_phy_cfg()
7813 ocp_reg_write(tp, 0xb87c, 0x8568); in r8156b_hw_phy_cfg()
7814 ocp_reg_write(tp, 0xb87e, 0x147d); in r8156b_hw_phy_cfg()
7815 ocp_reg_write(tp, 0xb87c, 0x856a); in r8156b_hw_phy_cfg()
7816 ocp_reg_write(tp, 0xb87e, 0x147d); in r8156b_hw_phy_cfg()
7817 ocp_reg_write(tp, 0xb87c, 0x8ffe); in r8156b_hw_phy_cfg()
7818 ocp_reg_write(tp, 0xb87e, 0x0907); in r8156b_hw_phy_cfg()
7819 ocp_reg_write(tp, 0xb87c, 0x80d6); in r8156b_hw_phy_cfg()
7820 ocp_reg_write(tp, 0xb87e, 0x2801); in r8156b_hw_phy_cfg()
7821 ocp_reg_write(tp, 0xb87c, 0x80f2); in r8156b_hw_phy_cfg()
7822 ocp_reg_write(tp, 0xb87e, 0x2801); in r8156b_hw_phy_cfg()
7823 ocp_reg_write(tp, 0xb87c, 0x80f4); in r8156b_hw_phy_cfg()
7824 ocp_reg_write(tp, 0xb87e, 0x6077); in r8156b_hw_phy_cfg()
7825 ocp_reg_write(tp, 0xb506, 0x01e7); in r8156b_hw_phy_cfg()
7827 ocp_reg_write(tp, 0xb87c, 0x8013); in r8156b_hw_phy_cfg()
7828 ocp_reg_write(tp, 0xb87e, 0x0700); in r8156b_hw_phy_cfg()
7829 ocp_reg_write(tp, 0xb87c, 0x8fb9); in r8156b_hw_phy_cfg()
7830 ocp_reg_write(tp, 0xb87e, 0x2801); in r8156b_hw_phy_cfg()
7831 ocp_reg_write(tp, 0xb87c, 0x8fba); in r8156b_hw_phy_cfg()
7832 ocp_reg_write(tp, 0xb87e, 0x0100); in r8156b_hw_phy_cfg()
7833 ocp_reg_write(tp, 0xb87c, 0x8fbc); in r8156b_hw_phy_cfg()
7834 ocp_reg_write(tp, 0xb87e, 0x1900); in r8156b_hw_phy_cfg()
7835 ocp_reg_write(tp, 0xb87c, 0x8fbe); in r8156b_hw_phy_cfg()
7836 ocp_reg_write(tp, 0xb87e, 0xe100); in r8156b_hw_phy_cfg()
7837 ocp_reg_write(tp, 0xb87c, 0x8fc0); in r8156b_hw_phy_cfg()
7838 ocp_reg_write(tp, 0xb87e, 0x0800); in r8156b_hw_phy_cfg()
7839 ocp_reg_write(tp, 0xb87c, 0x8fc2); in r8156b_hw_phy_cfg()
7840 ocp_reg_write(tp, 0xb87e, 0xe500); in r8156b_hw_phy_cfg()
7841 ocp_reg_write(tp, 0xb87c, 0x8fc4); in r8156b_hw_phy_cfg()
7842 ocp_reg_write(tp, 0xb87e, 0x0f00); in r8156b_hw_phy_cfg()
7843 ocp_reg_write(tp, 0xb87c, 0x8fc6); in r8156b_hw_phy_cfg()
7844 ocp_reg_write(tp, 0xb87e, 0xf100); in r8156b_hw_phy_cfg()
7845 ocp_reg_write(tp, 0xb87c, 0x8fc8); in r8156b_hw_phy_cfg()
7846 ocp_reg_write(tp, 0xb87e, 0x0400); in r8156b_hw_phy_cfg()
7847 ocp_reg_write(tp, 0xb87c, 0x8fca); in r8156b_hw_phy_cfg()
7848 ocp_reg_write(tp, 0xb87e, 0xf300); in r8156b_hw_phy_cfg()
7849 ocp_reg_write(tp, 0xb87c, 0x8fcc); in r8156b_hw_phy_cfg()
7850 ocp_reg_write(tp, 0xb87e, 0xfd00); in r8156b_hw_phy_cfg()
7851 ocp_reg_write(tp, 0xb87c, 0x8fce); in r8156b_hw_phy_cfg()
7852 ocp_reg_write(tp, 0xb87e, 0xff00); in r8156b_hw_phy_cfg()
7853 ocp_reg_write(tp, 0xb87c, 0x8fd0); in r8156b_hw_phy_cfg()
7854 ocp_reg_write(tp, 0xb87e, 0xfb00); in r8156b_hw_phy_cfg()
7855 ocp_reg_write(tp, 0xb87c, 0x8fd2); in r8156b_hw_phy_cfg()
7856 ocp_reg_write(tp, 0xb87e, 0x0100); in r8156b_hw_phy_cfg()
7857 ocp_reg_write(tp, 0xb87c, 0x8fd4); in r8156b_hw_phy_cfg()
7858 ocp_reg_write(tp, 0xb87e, 0xf400); in r8156b_hw_phy_cfg()
7859 ocp_reg_write(tp, 0xb87c, 0x8fd6); in r8156b_hw_phy_cfg()
7860 ocp_reg_write(tp, 0xb87e, 0xff00); in r8156b_hw_phy_cfg()
7861 ocp_reg_write(tp, 0xb87c, 0x8fd8); in r8156b_hw_phy_cfg()
7862 ocp_reg_write(tp, 0xb87e, 0xf600); in r8156b_hw_phy_cfg()
7864 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_USB_CFG); in r8156b_hw_phy_cfg()
7866 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_USB_CFG, ocp_data); in r8156b_hw_phy_cfg()
7867 ocp_reg_write(tp, 0xb87c, 0x813d); in r8156b_hw_phy_cfg()
7868 ocp_reg_write(tp, 0xb87e, 0x390e); in r8156b_hw_phy_cfg()
7869 ocp_reg_write(tp, 0xb87c, 0x814f); in r8156b_hw_phy_cfg()
7870 ocp_reg_write(tp, 0xb87e, 0x790e); in r8156b_hw_phy_cfg()
7871 ocp_reg_write(tp, 0xb87c, 0x80b0); in r8156b_hw_phy_cfg()
7872 ocp_reg_write(tp, 0xb87e, 0x0f31); in r8156b_hw_phy_cfg()
7873 data = ocp_reg_read(tp, 0xbf4c); in r8156b_hw_phy_cfg()
7875 ocp_reg_write(tp, 0xbf4c, data); in r8156b_hw_phy_cfg()
7876 data = ocp_reg_read(tp, 0xbcca); in r8156b_hw_phy_cfg()
7878 ocp_reg_write(tp, 0xbcca, data); in r8156b_hw_phy_cfg()
7879 ocp_reg_write(tp, 0xb87c, 0x8141); in r8156b_hw_phy_cfg()
7880 ocp_reg_write(tp, 0xb87e, 0x320e); in r8156b_hw_phy_cfg()
7881 ocp_reg_write(tp, 0xb87c, 0x8153); in r8156b_hw_phy_cfg()
7882 ocp_reg_write(tp, 0xb87e, 0x720e); in r8156b_hw_phy_cfg()
7883 ocp_reg_write(tp, 0xb87c, 0x8529); in r8156b_hw_phy_cfg()
7884 ocp_reg_write(tp, 0xb87e, 0x050e); in r8156b_hw_phy_cfg()
7885 data = ocp_reg_read(tp, OCP_EEE_CFG); in r8156b_hw_phy_cfg()
7887 ocp_reg_write(tp, OCP_EEE_CFG, data); in r8156b_hw_phy_cfg()
7889 sram_write(tp, 0x816c, 0xc4a0); in r8156b_hw_phy_cfg()
7890 sram_write(tp, 0x8170, 0xc4a0); in r8156b_hw_phy_cfg()
7891 sram_write(tp, 0x8174, 0x04a0); in r8156b_hw_phy_cfg()
7892 sram_write(tp, 0x8178, 0x04a0); in r8156b_hw_phy_cfg()
7893 sram_write(tp, 0x817c, 0x0719); in r8156b_hw_phy_cfg()
7894 sram_write(tp, 0x8ff4, 0x0400); in r8156b_hw_phy_cfg()
7895 sram_write(tp, 0x8ff1, 0x0404); in r8156b_hw_phy_cfg()
7897 ocp_reg_write(tp, 0xbf4a, 0x001b); in r8156b_hw_phy_cfg()
7898 ocp_reg_write(tp, 0xb87c, 0x8033); in r8156b_hw_phy_cfg()
7899 ocp_reg_write(tp, 0xb87e, 0x7c13); in r8156b_hw_phy_cfg()
7900 ocp_reg_write(tp, 0xb87c, 0x8037); in r8156b_hw_phy_cfg()
7901 ocp_reg_write(tp, 0xb87e, 0x7c13); in r8156b_hw_phy_cfg()
7902 ocp_reg_write(tp, 0xb87c, 0x803b); in r8156b_hw_phy_cfg()
7903 ocp_reg_write(tp, 0xb87e, 0xfc32); in r8156b_hw_phy_cfg()
7904 ocp_reg_write(tp, 0xb87c, 0x803f); in r8156b_hw_phy_cfg()
7905 ocp_reg_write(tp, 0xb87e, 0x7c13); in r8156b_hw_phy_cfg()
7906 ocp_reg_write(tp, 0xb87c, 0x8043); in r8156b_hw_phy_cfg()
7907 ocp_reg_write(tp, 0xb87e, 0x7c13); in r8156b_hw_phy_cfg()
7908 ocp_reg_write(tp, 0xb87c, 0x8047); in r8156b_hw_phy_cfg()
7909 ocp_reg_write(tp, 0xb87e, 0x7c13); in r8156b_hw_phy_cfg()
7911 ocp_reg_write(tp, 0xb87c, 0x8145); in r8156b_hw_phy_cfg()
7912 ocp_reg_write(tp, 0xb87e, 0x370e); in r8156b_hw_phy_cfg()
7913 ocp_reg_write(tp, 0xb87c, 0x8157); in r8156b_hw_phy_cfg()
7914 ocp_reg_write(tp, 0xb87e, 0x770e); in r8156b_hw_phy_cfg()
7915 ocp_reg_write(tp, 0xb87c, 0x8169); in r8156b_hw_phy_cfg()
7916 ocp_reg_write(tp, 0xb87e, 0x0d0a); in r8156b_hw_phy_cfg()
7917 ocp_reg_write(tp, 0xb87c, 0x817b); in r8156b_hw_phy_cfg()
7918 ocp_reg_write(tp, 0xb87e, 0x1d0a); in r8156b_hw_phy_cfg()
7920 data = sram_read(tp, 0x8217); in r8156b_hw_phy_cfg()
7923 sram_write(tp, 0x8217, data); in r8156b_hw_phy_cfg()
7924 data = sram_read(tp, 0x821a); in r8156b_hw_phy_cfg()
7927 sram_write(tp, 0x821a, data); in r8156b_hw_phy_cfg()
7928 sram_write(tp, 0x80da, 0x0403); in r8156b_hw_phy_cfg()
7929 data = sram_read(tp, 0x80dc); in r8156b_hw_phy_cfg()
7932 sram_write(tp, 0x80dc, data); in r8156b_hw_phy_cfg()
7933 sram_write(tp, 0x80b3, 0x0384); in r8156b_hw_phy_cfg()
7934 sram_write(tp, 0x80b7, 0x2007); in r8156b_hw_phy_cfg()
7935 data = sram_read(tp, 0x80ba); in r8156b_hw_phy_cfg()
7938 sram_write(tp, 0x80ba, data); in r8156b_hw_phy_cfg()
7939 sram_write(tp, 0x80b5, 0xf009); in r8156b_hw_phy_cfg()
7940 data = sram_read(tp, 0x80bd); in r8156b_hw_phy_cfg()
7943 sram_write(tp, 0x80bd, data); in r8156b_hw_phy_cfg()
7944 sram_write(tp, 0x80c7, 0xf083); in r8156b_hw_phy_cfg()
7945 sram_write(tp, 0x80dd, 0x03f0); in r8156b_hw_phy_cfg()
7946 data = sram_read(tp, 0x80df); in r8156b_hw_phy_cfg()
7949 sram_write(tp, 0x80df, data); in r8156b_hw_phy_cfg()
7950 sram_write(tp, 0x80cb, 0x2007); in r8156b_hw_phy_cfg()
7951 data = sram_read(tp, 0x80ce); in r8156b_hw_phy_cfg()
7954 sram_write(tp, 0x80ce, data); in r8156b_hw_phy_cfg()
7955 sram_write(tp, 0x80c9, 0x8009); in r8156b_hw_phy_cfg()
7956 data = sram_read(tp, 0x80d1); in r8156b_hw_phy_cfg()
7959 sram_write(tp, 0x80d1, data); in r8156b_hw_phy_cfg()
7960 sram_write(tp, 0x80a3, 0x200a); in r8156b_hw_phy_cfg()
7961 sram_write(tp, 0x80a5, 0xf0ad); in r8156b_hw_phy_cfg()
7962 sram_write(tp, 0x809f, 0x6073); in r8156b_hw_phy_cfg()
7963 sram_write(tp, 0x80a1, 0x000b); in r8156b_hw_phy_cfg()
7964 data = sram_read(tp, 0x80a9); in r8156b_hw_phy_cfg()
7967 sram_write(tp, 0x80a9, data); in r8156b_hw_phy_cfg()
7969 if (rtl_phy_patch_request(tp, true, true)) in r8156b_hw_phy_cfg()
7972 data = ocp_reg_read(tp, 0xb896); in r8156b_hw_phy_cfg()
7974 ocp_reg_write(tp, 0xb896, data); in r8156b_hw_phy_cfg()
7975 data = ocp_reg_read(tp, 0xb892); in r8156b_hw_phy_cfg()
7977 ocp_reg_write(tp, 0xb892, data); in r8156b_hw_phy_cfg()
7978 ocp_reg_write(tp, 0xb88e, 0xc23e); in r8156b_hw_phy_cfg()
7979 ocp_reg_write(tp, 0xb890, 0x0000); in r8156b_hw_phy_cfg()
7980 ocp_reg_write(tp, 0xb88e, 0xc240); in r8156b_hw_phy_cfg()
7981 ocp_reg_write(tp, 0xb890, 0x0103); in r8156b_hw_phy_cfg()
7982 ocp_reg_write(tp, 0xb88e, 0xc242); in r8156b_hw_phy_cfg()
7983 ocp_reg_write(tp, 0xb890, 0x0507); in r8156b_hw_phy_cfg()
7984 ocp_reg_write(tp, 0xb88e, 0xc244); in r8156b_hw_phy_cfg()
7985 ocp_reg_write(tp, 0xb890, 0x090b); in r8156b_hw_phy_cfg()
7986 ocp_reg_write(tp, 0xb88e, 0xc246); in r8156b_hw_phy_cfg()
7987 ocp_reg_write(tp, 0xb890, 0x0c0e); in r8156b_hw_phy_cfg()
7988 ocp_reg_write(tp, 0xb88e, 0xc248); in r8156b_hw_phy_cfg()
7989 ocp_reg_write(tp, 0xb890, 0x1012); in r8156b_hw_phy_cfg()
7990 ocp_reg_write(tp, 0xb88e, 0xc24a); in r8156b_hw_phy_cfg()
7991 ocp_reg_write(tp, 0xb890, 0x1416); in r8156b_hw_phy_cfg()
7992 data = ocp_reg_read(tp, 0xb896); in r8156b_hw_phy_cfg()
7994 ocp_reg_write(tp, 0xb896, data); in r8156b_hw_phy_cfg()
7996 rtl_phy_patch_request(tp, false, true); in r8156b_hw_phy_cfg()
7998 data = ocp_reg_read(tp, 0xa86a); in r8156b_hw_phy_cfg()
8000 ocp_reg_write(tp, 0xa86a, data); in r8156b_hw_phy_cfg()
8001 data = ocp_reg_read(tp, 0xa6f0); in r8156b_hw_phy_cfg()
8003 ocp_reg_write(tp, 0xa6f0, data); in r8156b_hw_phy_cfg()
8005 ocp_reg_write(tp, 0xbfa0, 0xd70d); in r8156b_hw_phy_cfg()
8006 ocp_reg_write(tp, 0xbfa2, 0x4100); in r8156b_hw_phy_cfg()
8007 ocp_reg_write(tp, 0xbfa4, 0xe868); in r8156b_hw_phy_cfg()
8008 ocp_reg_write(tp, 0xbfa6, 0xdc59); in r8156b_hw_phy_cfg()
8009 ocp_reg_write(tp, 0xb54c, 0x3c18); in r8156b_hw_phy_cfg()
8010 data = ocp_reg_read(tp, 0xbfa4); in r8156b_hw_phy_cfg()
8012 ocp_reg_write(tp, 0xbfa4, data); in r8156b_hw_phy_cfg()
8013 data = sram_read(tp, 0x817d); in r8156b_hw_phy_cfg()
8015 sram_write(tp, 0x817d, data); in r8156b_hw_phy_cfg()
8019 data = ocp_reg_read(tp, 0xac46); in r8156b_hw_phy_cfg()
8022 ocp_reg_write(tp, 0xac46, data); in r8156b_hw_phy_cfg()
8023 data = ocp_reg_read(tp, 0xad30); in r8156b_hw_phy_cfg()
8026 ocp_reg_write(tp, 0xad30, data); in r8156b_hw_phy_cfg()
8030 ocp_reg_write(tp, 0xb87c, 0x80f5); in r8156b_hw_phy_cfg()
8031 ocp_reg_write(tp, 0xb87e, 0x760e); in r8156b_hw_phy_cfg()
8032 ocp_reg_write(tp, 0xb87c, 0x8107); in r8156b_hw_phy_cfg()
8033 ocp_reg_write(tp, 0xb87e, 0x360e); in r8156b_hw_phy_cfg()
8034 ocp_reg_write(tp, 0xb87c, 0x8551); in r8156b_hw_phy_cfg()
8035 data = ocp_reg_read(tp, 0xb87e); in r8156b_hw_phy_cfg()
8038 ocp_reg_write(tp, 0xb87e, data); in r8156b_hw_phy_cfg()
8041 data = ocp_reg_read(tp, 0xbf00); in r8156b_hw_phy_cfg()
8044 ocp_reg_write(tp, 0xbf00, data); in r8156b_hw_phy_cfg()
8045 data = ocp_reg_read(tp, 0xbf46); in r8156b_hw_phy_cfg()
8048 ocp_reg_write(tp, 0xbf46, data); in r8156b_hw_phy_cfg()
8051 sram_write(tp, 0x8044, 0x2417); in r8156b_hw_phy_cfg()
8052 sram_write(tp, 0x804a, 0x2417); in r8156b_hw_phy_cfg()
8053 sram_write(tp, 0x8050, 0x2417); in r8156b_hw_phy_cfg()
8054 sram_write(tp, 0x8056, 0x2417); in r8156b_hw_phy_cfg()
8055 sram_write(tp, 0x805c, 0x2417); in r8156b_hw_phy_cfg()
8056 sram_write(tp, 0x8062, 0x2417); in r8156b_hw_phy_cfg()
8057 sram_write(tp, 0x8068, 0x2417); in r8156b_hw_phy_cfg()
8058 sram_write(tp, 0x806e, 0x2417); in r8156b_hw_phy_cfg()
8059 sram_write(tp, 0x8074, 0x2417); in r8156b_hw_phy_cfg()
8060 sram_write(tp, 0x807a, 0x2417); in r8156b_hw_phy_cfg()
8063 data = ocp_reg_read(tp, 0xbf84); in r8156b_hw_phy_cfg()
8066 ocp_reg_write(tp, 0xbf84, data); in r8156b_hw_phy_cfg()
8073 data = ocp_reg_read(tp, OCP_INTR_EN); in r8156b_hw_phy_cfg()
8075 ocp_reg_write(tp, OCP_INTR_EN, data); in r8156b_hw_phy_cfg()
8077 if (rtl_phy_patch_request(tp, true, true)) in r8156b_hw_phy_cfg()
8080 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4); in r8156b_hw_phy_cfg()
8082 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4, ocp_data); in r8156b_hw_phy_cfg()
8084 data = ocp_reg_read(tp, OCP_DOWN_SPEED); in r8156b_hw_phy_cfg()
8087 ocp_reg_write(tp, OCP_DOWN_SPEED, data); in r8156b_hw_phy_cfg()
8088 tp->ups_info._10m_ckdiv = true; in r8156b_hw_phy_cfg()
8089 tp->ups_info.eee_plloff_100 = false; in r8156b_hw_phy_cfg()
8090 tp->ups_info.eee_plloff_giga = false; in r8156b_hw_phy_cfg()
8092 data = ocp_reg_read(tp, OCP_POWER_CFG); in r8156b_hw_phy_cfg()
8094 ocp_reg_write(tp, OCP_POWER_CFG, data); in r8156b_hw_phy_cfg()
8095 tp->ups_info.eee_ckdiv = false; in r8156b_hw_phy_cfg()
8097 rtl_phy_patch_request(tp, false, true); in r8156b_hw_phy_cfg()
8099 rtl_green_en(tp, test_bit(GREEN_ETHERNET, &tp->flags)); in r8156b_hw_phy_cfg()
8101 data = ocp_reg_read(tp, 0xa428); in r8156b_hw_phy_cfg()
8103 ocp_reg_write(tp, 0xa428, data); in r8156b_hw_phy_cfg()
8104 data = ocp_reg_read(tp, 0xa5ea); in r8156b_hw_phy_cfg()
8106 ocp_reg_write(tp, 0xa5ea, data); in r8156b_hw_phy_cfg()
8107 tp->ups_info.lite_mode = 0; in r8156b_hw_phy_cfg()
8109 if (tp->eee_en) in r8156b_hw_phy_cfg()
8110 rtl_eee_enable(tp, true); in r8156b_hw_phy_cfg()
8112 r8153_aldps_en(tp, true); in r8156b_hw_phy_cfg()
8113 r8152b_enable_fc(tp); in r8156b_hw_phy_cfg()
8114 r8153_u2p3en(tp, true); in r8156b_hw_phy_cfg()
8116 set_bit(PHY_RESET, &tp->flags); in r8156b_hw_phy_cfg()
8119 static void r8156_init(struct r8152 *tp) in r8156_init() argument
8125 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8156_init()
8128 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_ECM_OP); in r8156_init()
8130 ocp_write_byte(tp, MCU_TYPE_USB, USB_ECM_OP, ocp_data); in r8156_init()
8132 ocp_write_word(tp, MCU_TYPE_USB, USB_SPEED_OPTION, 0); in r8156_init()
8134 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_ECM_OPTION); in r8156_init()
8136 ocp_write_word(tp, MCU_TYPE_USB, USB_ECM_OPTION, ocp_data); in r8156_init()
8138 r8153b_u1u2en(tp, false); in r8156_init()
8141 if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) & in r8156_init()
8146 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8156_init()
8150 data = r8153_phy_status(tp, 0); in r8156_init()
8152 data = ocp_reg_read(tp, 0xa468); in r8156_init()
8154 ocp_reg_write(tp, 0xa468, data); in r8156_init()
8157 data = r8152_mdio_read(tp, MII_BMCR); in r8156_init()
8160 r8152_mdio_write(tp, MII_BMCR, data); in r8156_init()
8163 data = r8153_phy_status(tp, PHY_STAT_LAN_ON); in r8156_init()
8166 r8153_u2p3en(tp, false); in r8156_init()
8169 ocp_write_word(tp, MCU_TYPE_USB, USB_MSC_TIMER, 0x0fff); in r8156_init()
8172 ocp_write_word(tp, MCU_TYPE_USB, USB_U1U2_TIMER, 500); in r8156_init()
8174 r8153b_power_cut_en(tp, false); in r8156_init()
8175 r8156_ups_en(tp, false); in r8156_init()
8176 r8153_queue_wake(tp, false); in r8156_init()
8177 rtl_runtime_suspend_enable(tp, false); in r8156_init()
8179 if (tp->udev->speed >= USB_SPEED_SUPER) in r8156_init()
8180 r8153b_u1u2en(tp, true); in r8156_init()
8182 usb_enable_lpm(tp->udev); in r8156_init()
8184 r8156_mac_clk_spd(tp, true); in r8156_init()
8186 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3); in r8156_init()
8188 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data); in r8156_init()
8190 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS); in r8156_init()
8191 if (rtl8152_get_speed(tp) & LINK_STATUS) in r8156_init()
8196 ocp_write_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS, ocp_data); in r8156_init()
8198 set_bit(GREEN_ETHERNET, &tp->flags); in r8156_init()
8201 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL); in r8156_init()
8203 ocp_write_word(tp, MCU_TYPE_USB, USB_USB_CTRL, ocp_data); in r8156_init()
8205 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_BMU_CONFIG); in r8156_init()
8207 ocp_write_byte(tp, MCU_TYPE_USB, USB_BMU_CONFIG, ocp_data); in r8156_init()
8209 r8156_mdio_force_mode(tp); in r8156_init()
8210 rtl_tally_reset(tp); in r8156_init()
8212 tp->coalesce = 15000; /* 15 us */ in r8156_init()
8215 static void r8156b_init(struct r8152 *tp) in r8156b_init() argument
8221 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8156b_init()
8224 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_ECM_OP); in r8156b_init()
8226 ocp_write_byte(tp, MCU_TYPE_USB, USB_ECM_OP, ocp_data); in r8156b_init()
8228 ocp_write_word(tp, MCU_TYPE_USB, USB_SPEED_OPTION, 0); in r8156b_init()
8230 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_ECM_OPTION); in r8156b_init()
8232 ocp_write_word(tp, MCU_TYPE_USB, USB_ECM_OPTION, ocp_data); in r8156b_init()
8234 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_U2P3_CTRL); in r8156b_init()
8236 ocp_write_word(tp, MCU_TYPE_USB, USB_U2P3_CTRL, ocp_data); in r8156b_init()
8238 r8153b_u1u2en(tp, false); in r8156b_init()
8240 switch (tp->version) { in r8156b_init()
8243 r8156b_wait_loading_flash(tp); in r8156b_init()
8250 if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) & in r8156b_init()
8255 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8156b_init()
8259 data = r8153_phy_status(tp, 0); in r8156b_init()
8261 data = ocp_reg_read(tp, 0xa468); in r8156b_init()
8263 ocp_reg_write(tp, 0xa468, data); in r8156b_init()
8265 data = ocp_reg_read(tp, 0xa466); in r8156b_init()
8267 ocp_reg_write(tp, 0xa466, data); in r8156b_init()
8270 data = r8152_mdio_read(tp, MII_BMCR); in r8156b_init()
8273 r8152_mdio_write(tp, MII_BMCR, data); in r8156b_init()
8276 data = r8153_phy_status(tp, PHY_STAT_LAN_ON); in r8156b_init()
8278 r8153_u2p3en(tp, false); in r8156b_init()
8281 ocp_write_word(tp, MCU_TYPE_USB, USB_MSC_TIMER, 0x0fff); in r8156b_init()
8284 ocp_write_word(tp, MCU_TYPE_USB, USB_U1U2_TIMER, 500); in r8156b_init()
8286 r8153b_power_cut_en(tp, false); in r8156b_init()
8287 r8156_ups_en(tp, false); in r8156b_init()
8288 r8153_queue_wake(tp, false); in r8156b_init()
8289 rtl_runtime_suspend_enable(tp, false); in r8156b_init()
8291 if (tp->udev->speed >= USB_SPEED_SUPER) in r8156b_init()
8292 r8153b_u1u2en(tp, true); in r8156b_init()
8294 usb_enable_lpm(tp->udev); in r8156b_init()
8296 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_RCR); in r8156b_init()
8298 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); in r8156b_init()
8300 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CPCR); in r8156b_init()
8302 ocp_write_word(tp, MCU_TYPE_PLA, PLA_CPCR, ocp_data); in r8156b_init()
8305 ocp_write_word(tp, MCU_TYPE_USB, USB_FC_TIMER, in r8156b_init()
8308 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_CTRL); in r8156b_init()
8309 if (!(ocp_read_word(tp, MCU_TYPE_PLA, PLA_POL_GPIO_CTRL) & DACK_DET_EN)) in r8156b_init()
8312 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_CTRL, ocp_data); in r8156b_init()
8314 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_TASK); in r8156b_init()
8316 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_TASK, ocp_data); in r8156b_init()
8318 r8156_mac_clk_spd(tp, true); in r8156b_init()
8320 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3); in r8156b_init()
8322 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data); in r8156b_init()
8324 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS); in r8156b_init()
8325 if (rtl8152_get_speed(tp) & LINK_STATUS) in r8156b_init()
8330 ocp_write_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS, ocp_data); in r8156b_init()
8332 set_bit(GREEN_ETHERNET, &tp->flags); in r8156b_init()
8335 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL); in r8156b_init()
8337 ocp_write_word(tp, MCU_TYPE_USB, USB_USB_CTRL, ocp_data); in r8156b_init()
8339 r8156_mdio_force_mode(tp); in r8156b_init()
8340 rtl_tally_reset(tp); in r8156b_init()
8342 tp->coalesce = 15000; /* 15 us */ in r8156b_init()
8378 struct r8152 *tp = usb_get_intfdata(intf); in rtl8152_pre_reset() local
8383 if (!tp || !test_bit(PROBED_WITH_NO_ERRORS, &tp->flags)) in rtl8152_pre_reset()
8386 netdev = tp->netdev; in rtl8152_pre_reset()
8391 tasklet_disable(&tp->tx_tl); in rtl8152_pre_reset()
8392 clear_bit(WORK_ENABLE, &tp->flags); in rtl8152_pre_reset()
8393 usb_kill_urb(tp->intr_urb); in rtl8152_pre_reset()
8394 cancel_delayed_work_sync(&tp->schedule); in rtl8152_pre_reset()
8395 napi_disable(&tp->napi); in rtl8152_pre_reset()
8397 mutex_lock(&tp->control); in rtl8152_pre_reset()
8398 set_bit(IN_PRE_RESET, &tp->flags); in rtl8152_pre_reset()
8399 tp->rtl_ops.disable(tp); in rtl8152_pre_reset()
8400 clear_bit(IN_PRE_RESET, &tp->flags); in rtl8152_pre_reset()
8401 mutex_unlock(&tp->control); in rtl8152_pre_reset()
8409 struct r8152 *tp = usb_get_intfdata(intf); in rtl8152_post_reset() local
8413 if (!tp || !test_bit(PROBED_WITH_NO_ERRORS, &tp->flags)) in rtl8152_post_reset()
8416 rtl_set_accessible(tp); in rtl8152_post_reset()
8419 if (determine_ethernet_addr(tp, &sa) >= 0) in rtl8152_post_reset()
8420 dev_set_mac_address (tp->netdev, &sa, NULL); in rtl8152_post_reset()
8422 netdev = tp->netdev; in rtl8152_post_reset()
8426 set_bit(WORK_ENABLE, &tp->flags); in rtl8152_post_reset()
8428 mutex_lock(&tp->control); in rtl8152_post_reset()
8429 tp->rtl_ops.enable(tp); in rtl8152_post_reset()
8430 rtl_start_rx(tp); in rtl8152_post_reset()
8432 mutex_unlock(&tp->control); in rtl8152_post_reset()
8435 napi_enable(&tp->napi); in rtl8152_post_reset()
8436 tasklet_enable(&tp->tx_tl); in rtl8152_post_reset()
8438 usb_submit_urb(tp->intr_urb, GFP_KERNEL); in rtl8152_post_reset()
8440 if (!list_empty(&tp->rx_done)) in rtl8152_post_reset()
8441 napi_schedule(&tp->napi); in rtl8152_post_reset()
8448 static bool delay_autosuspend(struct r8152 *tp) in delay_autosuspend() argument
8450 bool sw_linking = !!netif_carrier_ok(tp->netdev); in delay_autosuspend()
8451 bool hw_linking = !!(rtl8152_get_speed(tp) & LINK_STATUS); in delay_autosuspend()
8457 if (work_busy(&tp->schedule.work) || sw_linking != hw_linking) in delay_autosuspend()
8463 if (!sw_linking && tp->rtl_ops.in_nway(tp)) in delay_autosuspend()
8465 else if (!skb_queue_empty(&tp->tx_queue)) in delay_autosuspend()
8471 static int rtl8152_runtime_resume(struct r8152 *tp) in rtl8152_runtime_resume() argument
8473 struct net_device *netdev = tp->netdev; in rtl8152_runtime_resume()
8476 struct napi_struct *napi = &tp->napi; in rtl8152_runtime_resume()
8478 tp->rtl_ops.autosuspend_en(tp, false); in rtl8152_runtime_resume()
8480 set_bit(WORK_ENABLE, &tp->flags); in rtl8152_runtime_resume()
8483 if (rtl8152_get_speed(tp) & LINK_STATUS) { in rtl8152_runtime_resume()
8484 rtl_start_rx(tp); in rtl8152_runtime_resume()
8487 tp->rtl_ops.disable(tp); in rtl8152_runtime_resume()
8488 netif_info(tp, link, netdev, "linking down\n"); in rtl8152_runtime_resume()
8493 clear_bit(SELECTIVE_SUSPEND, &tp->flags); in rtl8152_runtime_resume()
8496 if (!list_empty(&tp->rx_done)) in rtl8152_runtime_resume()
8497 napi_schedule(&tp->napi); in rtl8152_runtime_resume()
8499 usb_submit_urb(tp->intr_urb, GFP_NOIO); in rtl8152_runtime_resume()
8502 tp->rtl_ops.autosuspend_en(tp, false); in rtl8152_runtime_resume()
8504 clear_bit(SELECTIVE_SUSPEND, &tp->flags); in rtl8152_runtime_resume()
8510 static int rtl8152_system_resume(struct r8152 *tp) in rtl8152_system_resume() argument
8512 struct net_device *netdev = tp->netdev; in rtl8152_system_resume()
8517 tp->rtl_ops.up(tp); in rtl8152_system_resume()
8519 set_bit(WORK_ENABLE, &tp->flags); in rtl8152_system_resume()
8520 usb_submit_urb(tp->intr_urb, GFP_NOIO); in rtl8152_system_resume()
8526 static int rtl8152_runtime_suspend(struct r8152 *tp) in rtl8152_runtime_suspend() argument
8528 struct net_device *netdev = tp->netdev; in rtl8152_runtime_suspend()
8531 if (!tp->rtl_ops.autosuspend_en) in rtl8152_runtime_suspend()
8534 set_bit(SELECTIVE_SUSPEND, &tp->flags); in rtl8152_runtime_suspend()
8537 if (netif_running(netdev) && test_bit(WORK_ENABLE, &tp->flags)) { in rtl8152_runtime_suspend()
8543 rcr = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); in rtl8152_runtime_suspend()
8545 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); in rtl8152_runtime_suspend()
8546 rxdy_gated_en(tp, true); in rtl8152_runtime_suspend()
8547 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, in rtl8152_runtime_suspend()
8550 rxdy_gated_en(tp, false); in rtl8152_runtime_suspend()
8551 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, rcr); in rtl8152_runtime_suspend()
8552 clear_bit(SELECTIVE_SUSPEND, &tp->flags); in rtl8152_runtime_suspend()
8559 clear_bit(WORK_ENABLE, &tp->flags); in rtl8152_runtime_suspend()
8560 usb_kill_urb(tp->intr_urb); in rtl8152_runtime_suspend()
8562 tp->rtl_ops.autosuspend_en(tp, true); in rtl8152_runtime_suspend()
8565 struct napi_struct *napi = &tp->napi; in rtl8152_runtime_suspend()
8568 rtl_stop_rx(tp); in rtl8152_runtime_suspend()
8569 rxdy_gated_en(tp, false); in rtl8152_runtime_suspend()
8570 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, rcr); in rtl8152_runtime_suspend()
8574 if (delay_autosuspend(tp)) { in rtl8152_runtime_suspend()
8575 rtl8152_runtime_resume(tp); in rtl8152_runtime_suspend()
8584 static int rtl8152_system_suspend(struct r8152 *tp) in rtl8152_system_suspend() argument
8586 struct net_device *netdev = tp->netdev; in rtl8152_system_suspend()
8590 if (netif_running(netdev) && test_bit(WORK_ENABLE, &tp->flags)) { in rtl8152_system_suspend()
8591 struct napi_struct *napi = &tp->napi; in rtl8152_system_suspend()
8593 clear_bit(WORK_ENABLE, &tp->flags); in rtl8152_system_suspend()
8594 usb_kill_urb(tp->intr_urb); in rtl8152_system_suspend()
8595 tasklet_disable(&tp->tx_tl); in rtl8152_system_suspend()
8597 cancel_delayed_work_sync(&tp->schedule); in rtl8152_system_suspend()
8598 tp->rtl_ops.down(tp); in rtl8152_system_suspend()
8600 tasklet_enable(&tp->tx_tl); in rtl8152_system_suspend()
8608 struct r8152 *tp = usb_get_intfdata(intf); in rtl8152_suspend() local
8611 mutex_lock(&tp->control); in rtl8152_suspend()
8614 ret = rtl8152_runtime_suspend(tp); in rtl8152_suspend()
8616 ret = rtl8152_system_suspend(tp); in rtl8152_suspend()
8618 mutex_unlock(&tp->control); in rtl8152_suspend()
8625 struct r8152 *tp = usb_get_intfdata(intf); in rtl8152_resume() local
8628 mutex_lock(&tp->control); in rtl8152_resume()
8630 rtl_reset_ocp_base(tp); in rtl8152_resume()
8632 if (test_bit(SELECTIVE_SUSPEND, &tp->flags)) in rtl8152_resume()
8633 ret = rtl8152_runtime_resume(tp); in rtl8152_resume()
8635 ret = rtl8152_system_resume(tp); in rtl8152_resume()
8637 mutex_unlock(&tp->control); in rtl8152_resume()
8644 struct r8152 *tp = usb_get_intfdata(intf); in rtl8152_reset_resume() local
8646 clear_bit(SELECTIVE_SUSPEND, &tp->flags); in rtl8152_reset_resume()
8647 rtl_reset_ocp_base(tp); in rtl8152_reset_resume()
8648 tp->rtl_ops.init(tp); in rtl8152_reset_resume()
8649 queue_delayed_work(system_long_wq, &tp->hw_phy_work, 0); in rtl8152_reset_resume()
8650 set_ethernet_addr(tp, true); in rtl8152_reset_resume()
8656 struct r8152 *tp = netdev_priv(dev); in rtl8152_get_wol() local
8658 if (usb_autopm_get_interface(tp->intf) < 0) in rtl8152_get_wol()
8661 if (!rtl_can_wakeup(tp)) { in rtl8152_get_wol()
8665 mutex_lock(&tp->control); in rtl8152_get_wol()
8667 wol->wolopts = __rtl_get_wol(tp); in rtl8152_get_wol()
8668 mutex_unlock(&tp->control); in rtl8152_get_wol()
8671 usb_autopm_put_interface(tp->intf); in rtl8152_get_wol()
8676 struct r8152 *tp = netdev_priv(dev); in rtl8152_set_wol() local
8679 if (!rtl_can_wakeup(tp)) in rtl8152_set_wol()
8685 ret = usb_autopm_get_interface(tp->intf); in rtl8152_set_wol()
8689 mutex_lock(&tp->control); in rtl8152_set_wol()
8691 __rtl_set_wol(tp, wol->wolopts); in rtl8152_set_wol()
8692 tp->saved_wolopts = wol->wolopts & WAKE_ANY; in rtl8152_set_wol()
8694 mutex_unlock(&tp->control); in rtl8152_set_wol()
8696 usb_autopm_put_interface(tp->intf); in rtl8152_set_wol()
8704 struct r8152 *tp = netdev_priv(dev); in rtl8152_get_msglevel() local
8706 return tp->msg_enable; in rtl8152_get_msglevel()
8711 struct r8152 *tp = netdev_priv(dev); in rtl8152_set_msglevel() local
8713 tp->msg_enable = value; in rtl8152_set_msglevel()
8719 struct r8152 *tp = netdev_priv(netdev); in rtl8152_get_drvinfo() local
8723 usb_make_path(tp->udev, info->bus_info, sizeof(info->bus_info)); in rtl8152_get_drvinfo()
8724 if (!IS_ERR_OR_NULL(tp->rtl_fw.fw)) in rtl8152_get_drvinfo()
8725 strscpy(info->fw_version, tp->rtl_fw.version, in rtl8152_get_drvinfo()
8733 struct r8152 *tp = netdev_priv(netdev); in rtl8152_get_link_ksettings() local
8736 if (!tp->mii.mdio_read) in rtl8152_get_link_ksettings()
8739 ret = usb_autopm_get_interface(tp->intf); in rtl8152_get_link_ksettings()
8743 mutex_lock(&tp->control); in rtl8152_get_link_ksettings()
8745 mii_ethtool_get_link_ksettings(&tp->mii, cmd); in rtl8152_get_link_ksettings()
8748 cmd->link_modes.supported, tp->support_2500full); in rtl8152_get_link_ksettings()
8750 if (tp->support_2500full) { in rtl8152_get_link_ksettings()
8753 ocp_reg_read(tp, OCP_10GBT_CTRL) & MDIO_AN_10GBT_CTRL_ADV2_5G); in rtl8152_get_link_ksettings()
8757 ocp_reg_read(tp, OCP_10GBT_STAT) & MDIO_AN_10GBT_STAT_LP2_5G); in rtl8152_get_link_ksettings()
8759 if (is_speed_2500(rtl8152_get_speed(tp))) in rtl8152_get_link_ksettings()
8763 mutex_unlock(&tp->control); in rtl8152_get_link_ksettings()
8765 usb_autopm_put_interface(tp->intf); in rtl8152_get_link_ksettings()
8774 struct r8152 *tp = netdev_priv(dev); in rtl8152_set_link_ksettings() local
8778 ret = usb_autopm_get_interface(tp->intf); in rtl8152_set_link_ksettings()
8810 mutex_lock(&tp->control); in rtl8152_set_link_ksettings()
8812 ret = rtl8152_set_speed(tp, cmd->base.autoneg, cmd->base.speed, in rtl8152_set_link_ksettings()
8815 tp->autoneg = cmd->base.autoneg; in rtl8152_set_link_ksettings()
8816 tp->speed = cmd->base.speed; in rtl8152_set_link_ksettings()
8817 tp->duplex = cmd->base.duplex; in rtl8152_set_link_ksettings()
8818 tp->advertising = advertising; in rtl8152_set_link_ksettings()
8821 mutex_unlock(&tp->control); in rtl8152_set_link_ksettings()
8823 usb_autopm_put_interface(tp->intf); in rtl8152_set_link_ksettings()
8858 struct r8152 *tp = netdev_priv(dev); in rtl8152_get_ethtool_stats() local
8861 if (usb_autopm_get_interface(tp->intf) < 0) in rtl8152_get_ethtool_stats()
8864 generic_ocp_read(tp, PLA_TALLYCNT, sizeof(tally), &tally, MCU_TYPE_PLA); in rtl8152_get_ethtool_stats()
8866 usb_autopm_put_interface(tp->intf); in rtl8152_get_ethtool_stats()
8892 static int r8152_get_eee(struct r8152 *tp, struct ethtool_eee *eee) in r8152_get_eee() argument
8897 val = r8152_mmd_read(tp, MDIO_MMD_PCS, MDIO_PCS_EEE_ABLE); in r8152_get_eee()
8900 val = r8152_mmd_read(tp, MDIO_MMD_AN, MDIO_AN_EEE_ADV); in r8152_get_eee()
8903 val = r8152_mmd_read(tp, MDIO_MMD_AN, MDIO_AN_EEE_LPABLE); in r8152_get_eee()
8906 eee->eee_enabled = tp->eee_en; in r8152_get_eee()
8909 eee->advertised = tp->eee_adv; in r8152_get_eee()
8915 static int r8152_set_eee(struct r8152 *tp, struct ethtool_eee *eee) in r8152_set_eee() argument
8919 tp->eee_en = eee->eee_enabled; in r8152_set_eee()
8920 tp->eee_adv = val; in r8152_set_eee()
8922 rtl_eee_enable(tp, tp->eee_en); in r8152_set_eee()
8927 static int r8153_get_eee(struct r8152 *tp, struct ethtool_eee *eee) in r8153_get_eee() argument
8932 val = ocp_reg_read(tp, OCP_EEE_ABLE); in r8153_get_eee()
8935 val = ocp_reg_read(tp, OCP_EEE_ADV); in r8153_get_eee()
8938 val = ocp_reg_read(tp, OCP_EEE_LPABLE); in r8153_get_eee()
8941 eee->eee_enabled = tp->eee_en; in r8153_get_eee()
8944 eee->advertised = tp->eee_adv; in r8153_get_eee()
8953 struct r8152 *tp = netdev_priv(net); in rtl_ethtool_get_eee() local
8956 if (!tp->rtl_ops.eee_get) { in rtl_ethtool_get_eee()
8961 ret = usb_autopm_get_interface(tp->intf); in rtl_ethtool_get_eee()
8965 mutex_lock(&tp->control); in rtl_ethtool_get_eee()
8967 ret = tp->rtl_ops.eee_get(tp, edata); in rtl_ethtool_get_eee()
8969 mutex_unlock(&tp->control); in rtl_ethtool_get_eee()
8971 usb_autopm_put_interface(tp->intf); in rtl_ethtool_get_eee()
8980 struct r8152 *tp = netdev_priv(net); in rtl_ethtool_set_eee() local
8983 if (!tp->rtl_ops.eee_set) { in rtl_ethtool_set_eee()
8988 ret = usb_autopm_get_interface(tp->intf); in rtl_ethtool_set_eee()
8992 mutex_lock(&tp->control); in rtl_ethtool_set_eee()
8994 ret = tp->rtl_ops.eee_set(tp, edata); in rtl_ethtool_set_eee()
8996 ret = mii_nway_restart(&tp->mii); in rtl_ethtool_set_eee()
8998 mutex_unlock(&tp->control); in rtl_ethtool_set_eee()
9000 usb_autopm_put_interface(tp->intf); in rtl_ethtool_set_eee()
9008 struct r8152 *tp = netdev_priv(dev); in rtl8152_nway_reset() local
9011 ret = usb_autopm_get_interface(tp->intf); in rtl8152_nway_reset()
9015 mutex_lock(&tp->control); in rtl8152_nway_reset()
9017 ret = mii_nway_restart(&tp->mii); in rtl8152_nway_reset()
9019 mutex_unlock(&tp->control); in rtl8152_nway_reset()
9021 usb_autopm_put_interface(tp->intf); in rtl8152_nway_reset()
9032 struct r8152 *tp = netdev_priv(netdev); in rtl8152_get_coalesce() local
9034 switch (tp->version) { in rtl8152_get_coalesce()
9043 coalesce->rx_coalesce_usecs = tp->coalesce; in rtl8152_get_coalesce()
9053 struct r8152 *tp = netdev_priv(netdev); in rtl8152_set_coalesce() local
9056 switch (tp->version) { in rtl8152_set_coalesce()
9068 ret = usb_autopm_get_interface(tp->intf); in rtl8152_set_coalesce()
9072 mutex_lock(&tp->control); in rtl8152_set_coalesce()
9074 if (tp->coalesce != coalesce->rx_coalesce_usecs) { in rtl8152_set_coalesce()
9075 tp->coalesce = coalesce->rx_coalesce_usecs; in rtl8152_set_coalesce()
9079 napi_disable(&tp->napi); in rtl8152_set_coalesce()
9080 tp->rtl_ops.disable(tp); in rtl8152_set_coalesce()
9081 tp->rtl_ops.enable(tp); in rtl8152_set_coalesce()
9082 rtl_start_rx(tp); in rtl8152_set_coalesce()
9083 clear_bit(RTL8152_SET_RX_MODE, &tp->flags); in rtl8152_set_coalesce()
9085 napi_enable(&tp->napi); in rtl8152_set_coalesce()
9090 mutex_unlock(&tp->control); in rtl8152_set_coalesce()
9092 usb_autopm_put_interface(tp->intf); in rtl8152_set_coalesce()
9100 struct r8152 *tp = netdev_priv(netdev); in rtl8152_get_tunable() local
9104 *(u32 *)d = tp->rx_copybreak; in rtl8152_get_tunable()
9117 struct r8152 *tp = netdev_priv(netdev); in rtl8152_set_tunable() local
9124 netif_err(tp, rx_err, netdev, in rtl8152_set_tunable()
9129 if (tp->rx_copybreak != val) { in rtl8152_set_tunable()
9131 mutex_lock(&tp->control); in rtl8152_set_tunable()
9132 napi_disable(&tp->napi); in rtl8152_set_tunable()
9133 tp->rx_copybreak = val; in rtl8152_set_tunable()
9134 napi_enable(&tp->napi); in rtl8152_set_tunable()
9135 mutex_unlock(&tp->control); in rtl8152_set_tunable()
9137 tp->rx_copybreak = val; in rtl8152_set_tunable()
9153 struct r8152 *tp = netdev_priv(netdev); in rtl8152_get_ringparam() local
9156 ring->rx_pending = tp->rx_pending; in rtl8152_get_ringparam()
9164 struct r8152 *tp = netdev_priv(netdev); in rtl8152_set_ringparam() local
9169 if (tp->rx_pending != ring->rx_pending) { in rtl8152_set_ringparam()
9171 mutex_lock(&tp->control); in rtl8152_set_ringparam()
9172 napi_disable(&tp->napi); in rtl8152_set_ringparam()
9173 tp->rx_pending = ring->rx_pending; in rtl8152_set_ringparam()
9174 napi_enable(&tp->napi); in rtl8152_set_ringparam()
9175 mutex_unlock(&tp->control); in rtl8152_set_ringparam()
9177 tp->rx_pending = ring->rx_pending; in rtl8152_set_ringparam()
9186 struct r8152 *tp = netdev_priv(netdev); in rtl8152_get_pauseparam() local
9190 if (usb_autopm_get_interface(tp->intf) < 0) in rtl8152_get_pauseparam()
9193 mutex_lock(&tp->control); in rtl8152_get_pauseparam()
9195 bmcr = r8152_mdio_read(tp, MII_BMCR); in rtl8152_get_pauseparam()
9196 lcladv = r8152_mdio_read(tp, MII_ADVERTISE); in rtl8152_get_pauseparam()
9197 rmtadv = r8152_mdio_read(tp, MII_LPA); in rtl8152_get_pauseparam()
9199 mutex_unlock(&tp->control); in rtl8152_get_pauseparam()
9201 usb_autopm_put_interface(tp->intf); in rtl8152_get_pauseparam()
9223 struct r8152 *tp = netdev_priv(netdev); in rtl8152_set_pauseparam() local
9228 ret = usb_autopm_get_interface(tp->intf); in rtl8152_set_pauseparam()
9232 mutex_lock(&tp->control); in rtl8152_set_pauseparam()
9234 if (pause->autoneg && !(r8152_mdio_read(tp, MII_BMCR) & BMCR_ANENABLE)) { in rtl8152_set_pauseparam()
9245 old = r8152_mdio_read(tp, MII_ADVERTISE); in rtl8152_set_pauseparam()
9248 r8152_mdio_write(tp, MII_ADVERTISE, new1); in rtl8152_set_pauseparam()
9251 mutex_unlock(&tp->control); in rtl8152_set_pauseparam()
9252 usb_autopm_put_interface(tp->intf); in rtl8152_set_pauseparam()
9285 struct r8152 *tp = netdev_priv(netdev); in rtl8152_ioctl() local
9289 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl8152_ioctl()
9292 res = usb_autopm_get_interface(tp->intf); in rtl8152_ioctl()
9302 mutex_lock(&tp->control); in rtl8152_ioctl()
9303 data->val_out = r8152_mdio_read(tp, data->reg_num); in rtl8152_ioctl()
9304 mutex_unlock(&tp->control); in rtl8152_ioctl()
9312 mutex_lock(&tp->control); in rtl8152_ioctl()
9313 r8152_mdio_write(tp, data->reg_num, data->val_in); in rtl8152_ioctl()
9314 mutex_unlock(&tp->control); in rtl8152_ioctl()
9321 usb_autopm_put_interface(tp->intf); in rtl8152_ioctl()
9329 struct r8152 *tp = netdev_priv(dev); in rtl8152_change_mtu() local
9332 switch (tp->version) { in rtl8152_change_mtu()
9342 ret = usb_autopm_get_interface(tp->intf); in rtl8152_change_mtu()
9346 mutex_lock(&tp->control); in rtl8152_change_mtu()
9351 if (tp->rtl_ops.change_mtu) in rtl8152_change_mtu()
9352 tp->rtl_ops.change_mtu(tp); in rtl8152_change_mtu()
9356 napi_disable(&tp->napi); in rtl8152_change_mtu()
9357 tasklet_disable(&tp->tx_tl); in rtl8152_change_mtu()
9358 tp->rtl_ops.disable(tp); in rtl8152_change_mtu()
9359 tp->rtl_ops.enable(tp); in rtl8152_change_mtu()
9360 rtl_start_rx(tp); in rtl8152_change_mtu()
9361 tasklet_enable(&tp->tx_tl); in rtl8152_change_mtu()
9362 napi_enable(&tp->napi); in rtl8152_change_mtu()
9368 mutex_unlock(&tp->control); in rtl8152_change_mtu()
9370 usb_autopm_put_interface(tp->intf); in rtl8152_change_mtu()
9389 static void rtl8152_unload(struct r8152 *tp) in rtl8152_unload() argument
9391 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl8152_unload()
9394 if (tp->version != RTL_VER_01) in rtl8152_unload()
9395 r8152_power_cut_en(tp, true); in rtl8152_unload()
9398 static void rtl8153_unload(struct r8152 *tp) in rtl8153_unload() argument
9400 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl8153_unload()
9403 r8153_power_cut_en(tp, false); in rtl8153_unload()
9406 static void rtl8153b_unload(struct r8152 *tp) in rtl8153b_unload() argument
9408 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl8153b_unload()
9411 r8153b_power_cut_en(tp, false); in rtl8153b_unload()
9414 static int rtl_ops_init(struct r8152 *tp) in rtl_ops_init() argument
9416 struct rtl_ops *ops = &tp->rtl_ops; in rtl_ops_init()
9419 switch (tp->version) { in rtl_ops_init()
9434 tp->rx_buf_sz = 16 * 1024; in rtl_ops_init()
9435 tp->eee_en = true; in rtl_ops_init()
9436 tp->eee_adv = MDIO_EEE_100TX; in rtl_ops_init()
9455 if (tp->udev->speed < USB_SPEED_SUPER) in rtl_ops_init()
9456 tp->rx_buf_sz = 16 * 1024; in rtl_ops_init()
9458 tp->rx_buf_sz = 32 * 1024; in rtl_ops_init()
9459 tp->eee_en = true; in rtl_ops_init()
9460 tp->eee_adv = MDIO_EEE_1000T | MDIO_EEE_100TX; in rtl_ops_init()
9477 tp->rx_buf_sz = 32 * 1024; in rtl_ops_init()
9478 tp->eee_en = true; in rtl_ops_init()
9479 tp->eee_adv = MDIO_EEE_1000T | MDIO_EEE_100TX; in rtl_ops_init()
9483 tp->eee_en = true; in rtl_ops_init()
9484 tp->eee_adv = MDIO_EEE_1000T | MDIO_EEE_100TX; in rtl_ops_init()
9499 tp->rx_buf_sz = 48 * 1024; in rtl_ops_init()
9500 tp->support_2500full = 1; in rtl_ops_init()
9505 tp->support_2500full = 1; in rtl_ops_init()
9508 tp->eee_en = true; in rtl_ops_init()
9509 tp->eee_adv = MDIO_EEE_1000T | MDIO_EEE_100TX; in rtl_ops_init()
9522 tp->rx_buf_sz = 48 * 1024; in rtl_ops_init()
9538 tp->rx_buf_sz = 32 * 1024; in rtl_ops_init()
9539 tp->eee_en = true; in rtl_ops_init()
9540 tp->eee_adv = MDIO_EEE_1000T | MDIO_EEE_100TX; in rtl_ops_init()
9545 dev_err(&tp->intf->dev, "Unknown Device\n"); in rtl_ops_init()
9568 static int rtl_fw_init(struct r8152 *tp) in rtl_fw_init() argument
9570 struct rtl_fw *rtl_fw = &tp->rtl_fw; in rtl_fw_init()
9572 switch (tp->version) { in rtl_fw_init()
9743 struct r8152 *tp; in rtl8152_probe_once() local
9755 tp = netdev_priv(netdev); in rtl8152_probe_once()
9756 tp->msg_enable = 0x7FFF; in rtl8152_probe_once()
9758 tp->udev = udev; in rtl8152_probe_once()
9759 tp->netdev = netdev; in rtl8152_probe_once()
9760 tp->intf = intf; in rtl8152_probe_once()
9761 tp->version = version; in rtl8152_probe_once()
9763 tp->pipe_ctrl_in = usb_rcvctrlpipe(udev, 0); in rtl8152_probe_once()
9764 tp->pipe_ctrl_out = usb_sndctrlpipe(udev, 0); in rtl8152_probe_once()
9765 tp->pipe_in = usb_rcvbulkpipe(udev, 1); in rtl8152_probe_once()
9766 tp->pipe_out = usb_sndbulkpipe(udev, 2); in rtl8152_probe_once()
9767 tp->pipe_intr = usb_rcvintpipe(udev, 3); in rtl8152_probe_once()
9773 tp->mii.supports_gmii = 0; in rtl8152_probe_once()
9776 tp->mii.supports_gmii = 1; in rtl8152_probe_once()
9780 ret = rtl_ops_init(tp); in rtl8152_probe_once()
9784 rtl_fw_init(tp); in rtl8152_probe_once()
9786 mutex_init(&tp->control); in rtl8152_probe_once()
9787 INIT_DELAYED_WORK(&tp->schedule, rtl_work_func_t); in rtl8152_probe_once()
9788 INIT_DELAYED_WORK(&tp->hw_phy_work, rtl_hw_phy_work_func_t); in rtl8152_probe_once()
9789 tasklet_setup(&tp->tx_tl, bottom_half); in rtl8152_probe_once()
9790 tasklet_disable(&tp->tx_tl); in rtl8152_probe_once()
9807 if (tp->version == RTL_VER_01) { in rtl8152_probe_once()
9812 tp->lenovo_macpassthru = rtl8152_supports_lenovo_macpassthru(udev); in rtl8152_probe_once()
9818 tp->dell_tb_rx_agg_bug = 1; in rtl8152_probe_once()
9826 switch (tp->version) { in rtl8152_probe_once()
9853 tp->mii.dev = netdev; in rtl8152_probe_once()
9854 tp->mii.mdio_read = read_mii_word; in rtl8152_probe_once()
9855 tp->mii.mdio_write = write_mii_word; in rtl8152_probe_once()
9856 tp->mii.phy_id_mask = 0x3f; in rtl8152_probe_once()
9857 tp->mii.reg_num_mask = 0x1f; in rtl8152_probe_once()
9858 tp->mii.phy_id = R8152_PHY_ID; in rtl8152_probe_once()
9860 tp->autoneg = AUTONEG_ENABLE; in rtl8152_probe_once()
9861 tp->speed = SPEED_100; in rtl8152_probe_once()
9862 tp->advertising = RTL_ADVERTISED_10_HALF | RTL_ADVERTISED_10_FULL | in rtl8152_probe_once()
9864 if (tp->mii.supports_gmii) { in rtl8152_probe_once()
9865 if (tp->support_2500full && in rtl8152_probe_once()
9866 tp->udev->speed >= USB_SPEED_SUPER) { in rtl8152_probe_once()
9867 tp->speed = SPEED_2500; in rtl8152_probe_once()
9868 tp->advertising |= RTL_ADVERTISED_2500_FULL; in rtl8152_probe_once()
9870 tp->speed = SPEED_1000; in rtl8152_probe_once()
9872 tp->advertising |= RTL_ADVERTISED_1000_FULL; in rtl8152_probe_once()
9874 tp->duplex = DUPLEX_FULL; in rtl8152_probe_once()
9876 tp->rx_copybreak = RTL8152_RXFG_HEADSZ; in rtl8152_probe_once()
9877 tp->rx_pending = 10 * RTL8152_MAX_RX; in rtl8152_probe_once()
9881 if (!rtl_can_wakeup(tp)) in rtl8152_probe_once()
9882 __rtl_set_wol(tp, 0); in rtl8152_probe_once()
9884 tp->saved_wolopts = __rtl_get_wol(tp); in rtl8152_probe_once()
9886 tp->rtl_ops.init(tp); in rtl8152_probe_once()
9889 tp->rtl_fw.retry = true; in rtl8152_probe_once()
9891 queue_delayed_work(system_long_wq, &tp->hw_phy_work, 0); in rtl8152_probe_once()
9892 set_ethernet_addr(tp, false); in rtl8152_probe_once()
9894 usb_set_intfdata(intf, tp); in rtl8152_probe_once()
9896 netif_napi_add(netdev, &tp->napi, r8152_poll); in rtl8152_probe_once()
9904 if (tp->saved_wolopts) in rtl8152_probe_once()
9912 if (test_bit(PROBE_SHOULD_RETRY, &tp->flags)) in rtl8152_probe_once()
9915 set_bit(PROBED_WITH_NO_ERRORS, &tp->flags); in rtl8152_probe_once()
9916 netif_info(tp, probe, netdev, "%s\n", DRIVER_VERSION); in rtl8152_probe_once()
9924 tasklet_kill(&tp->tx_tl); in rtl8152_probe_once()
9925 cancel_delayed_work_sync(&tp->hw_phy_work); in rtl8152_probe_once()
9926 if (tp->rtl_ops.unload) in rtl8152_probe_once()
9927 tp->rtl_ops.unload(tp); in rtl8152_probe_once()
9928 rtl8152_release_firmware(tp); in rtl8152_probe_once()
9931 if (test_bit(PROBE_SHOULD_RETRY, &tp->flags)) in rtl8152_probe_once()
9973 struct r8152 *tp = usb_get_intfdata(intf); in rtl8152_disconnect() local
9976 if (tp) { in rtl8152_disconnect()
9977 rtl_set_unplug(tp); in rtl8152_disconnect()
9979 unregister_netdev(tp->netdev); in rtl8152_disconnect()
9980 tasklet_kill(&tp->tx_tl); in rtl8152_disconnect()
9981 cancel_delayed_work_sync(&tp->hw_phy_work); in rtl8152_disconnect()
9982 if (tp->rtl_ops.unload) in rtl8152_disconnect()
9983 tp->rtl_ops.unload(tp); in rtl8152_disconnect()
9984 rtl8152_release_firmware(tp); in rtl8152_disconnect()
9985 free_netdev(tp->netdev); in rtl8152_disconnect()