Lines Matching refs:tp
889 void (*init)(struct r8152 *tp);
890 int (*enable)(struct r8152 *tp);
891 void (*disable)(struct r8152 *tp);
892 void (*up)(struct r8152 *tp);
893 void (*down)(struct r8152 *tp);
894 void (*unload)(struct r8152 *tp);
895 int (*eee_get)(struct r8152 *tp, struct ethtool_keee *eee);
896 int (*eee_set)(struct r8152 *tp, struct ethtool_keee *eee);
897 bool (*in_nway)(struct r8152 *tp);
898 void (*hw_phy_cfg)(struct r8152 *tp);
899 void (*autosuspend_en)(struct r8152 *tp, bool enable);
900 void (*change_mtu)(struct r8152 *tp);
928 int (*pre_fw)(struct r8152 *tp);
929 int (*post_fw)(struct r8152 *tp);
1215 static void rtl_set_inaccessible(struct r8152 *tp) in rtl_set_inaccessible() argument
1217 set_bit(RTL8152_INACCESSIBLE, &tp->flags); in rtl_set_inaccessible()
1221 static void rtl_set_accessible(struct r8152 *tp) in rtl_set_accessible() argument
1223 clear_bit(RTL8152_INACCESSIBLE, &tp->flags); in rtl_set_accessible()
1228 int r8152_control_msg(struct r8152 *tp, unsigned int pipe, __u8 request, in r8152_control_msg() argument
1232 struct usb_device *udev = tp->udev; in r8152_control_msg()
1235 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8152_control_msg()
1250 tp->reg_access_reset_count = 0; in r8152_control_msg()
1264 rtl_set_inaccessible(tp); in r8152_control_msg()
1271 if (!test_bit(PROBED_WITH_NO_ERRORS, &tp->flags)) { in r8152_control_msg()
1272 set_bit(PROBE_SHOULD_RETRY, &tp->flags); in r8152_control_msg()
1284 if (test_bit(IN_PRE_RESET, &tp->flags)) in r8152_control_msg()
1287 if (tp->reg_access_reset_count < REGISTER_ACCESS_MAX_RESETS) { in r8152_control_msg()
1288 usb_queue_reset_device(tp->intf); in r8152_control_msg()
1289 tp->reg_access_reset_count++; in r8152_control_msg()
1290 } else if (tp->reg_access_reset_count == REGISTER_ACCESS_MAX_RESETS) { in r8152_control_msg()
1300 int get_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data) in get_registers() argument
1309 ret = r8152_control_msg(tp, tp->pipe_ctrl_in, in get_registers()
1324 int set_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data) in set_registers() argument
1333 ret = r8152_control_msg(tp, tp->pipe_ctrl_out, in set_registers()
1342 static void rtl_set_unplug(struct r8152 *tp) in rtl_set_unplug() argument
1344 if (tp->udev->state == USB_STATE_NOTATTACHED) in rtl_set_unplug()
1345 rtl_set_inaccessible(tp); in rtl_set_unplug()
1348 static int generic_ocp_read(struct r8152 *tp, u16 index, u16 size, in generic_ocp_read() argument
1354 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in generic_ocp_read()
1366 ret = get_registers(tp, index, type, limit, data); in generic_ocp_read()
1374 ret = get_registers(tp, index, type, size, data); in generic_ocp_read()
1386 rtl_set_unplug(tp); in generic_ocp_read()
1391 static int generic_ocp_write(struct r8152 *tp, u16 index, u16 byteen, in generic_ocp_write() argument
1398 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in generic_ocp_write()
1415 ret = set_registers(tp, index, type | byen, 4, data); in generic_ocp_write()
1433 ret = set_registers(tp, index, in generic_ocp_write()
1443 ret = set_registers(tp, index, in generic_ocp_write()
1458 ret = set_registers(tp, index, type | byen, 4, data); in generic_ocp_write()
1463 rtl_set_unplug(tp); in generic_ocp_write()
1469 int pla_ocp_read(struct r8152 *tp, u16 index, u16 size, void *data) in pla_ocp_read() argument
1471 return generic_ocp_read(tp, index, size, data, MCU_TYPE_PLA); in pla_ocp_read()
1475 int pla_ocp_write(struct r8152 *tp, u16 index, u16 byteen, u16 size, void *data) in pla_ocp_write() argument
1477 return generic_ocp_write(tp, index, byteen, size, data, MCU_TYPE_PLA); in pla_ocp_write()
1481 int usb_ocp_write(struct r8152 *tp, u16 index, u16 byteen, u16 size, void *data) in usb_ocp_write() argument
1483 return generic_ocp_write(tp, index, byteen, size, data, MCU_TYPE_USB); in usb_ocp_write()
1486 static u32 ocp_read_dword(struct r8152 *tp, u16 type, u16 index) in ocp_read_dword() argument
1490 generic_ocp_read(tp, index, sizeof(data), &data, type); in ocp_read_dword()
1495 static void ocp_write_dword(struct r8152 *tp, u16 type, u16 index, u32 data) in ocp_write_dword() argument
1499 generic_ocp_write(tp, index, BYTE_EN_DWORD, sizeof(tmp), &tmp, type); in ocp_write_dword()
1502 static u16 ocp_read_word(struct r8152 *tp, u16 type, u16 index) in ocp_read_word() argument
1512 generic_ocp_read(tp, index, sizeof(tmp), &tmp, type | byen); in ocp_read_word()
1521 static void ocp_write_word(struct r8152 *tp, u16 type, u16 index, u32 data) in ocp_write_word() argument
1539 generic_ocp_write(tp, index, byen, sizeof(tmp), &tmp, type); in ocp_write_word()
1542 static u8 ocp_read_byte(struct r8152 *tp, u16 type, u16 index) in ocp_read_byte() argument
1550 generic_ocp_read(tp, index, sizeof(tmp), &tmp, type); in ocp_read_byte()
1559 static void ocp_write_byte(struct r8152 *tp, u16 type, u16 index, u32 data) in ocp_write_byte() argument
1577 generic_ocp_write(tp, index, byen, sizeof(tmp), &tmp, type); in ocp_write_byte()
1580 static u16 ocp_reg_read(struct r8152 *tp, u16 addr) in ocp_reg_read() argument
1585 if (ocp_base != tp->ocp_base) { in ocp_reg_read()
1586 ocp_write_word(tp, MCU_TYPE_PLA, PLA_OCP_GPHY_BASE, ocp_base); in ocp_reg_read()
1587 tp->ocp_base = ocp_base; in ocp_reg_read()
1591 return ocp_read_word(tp, MCU_TYPE_PLA, ocp_index); in ocp_reg_read()
1594 static void ocp_reg_write(struct r8152 *tp, u16 addr, u16 data) in ocp_reg_write() argument
1599 if (ocp_base != tp->ocp_base) { in ocp_reg_write()
1600 ocp_write_word(tp, MCU_TYPE_PLA, PLA_OCP_GPHY_BASE, ocp_base); in ocp_reg_write()
1601 tp->ocp_base = ocp_base; in ocp_reg_write()
1605 ocp_write_word(tp, MCU_TYPE_PLA, ocp_index, data); in ocp_reg_write()
1608 static inline void r8152_mdio_write(struct r8152 *tp, u32 reg_addr, u32 value) in r8152_mdio_write() argument
1610 ocp_reg_write(tp, OCP_BASE_MII + reg_addr * 2, value); in r8152_mdio_write()
1613 static inline int r8152_mdio_read(struct r8152 *tp, u32 reg_addr) in r8152_mdio_read() argument
1615 return ocp_reg_read(tp, OCP_BASE_MII + reg_addr * 2); in r8152_mdio_read()
1618 static void sram_write(struct r8152 *tp, u16 addr, u16 data) in sram_write() argument
1620 ocp_reg_write(tp, OCP_SRAM_ADDR, addr); in sram_write()
1621 ocp_reg_write(tp, OCP_SRAM_DATA, data); in sram_write()
1624 static u16 sram_read(struct r8152 *tp, u16 addr) in sram_read() argument
1626 ocp_reg_write(tp, OCP_SRAM_ADDR, addr); in sram_read()
1627 return ocp_reg_read(tp, OCP_SRAM_DATA); in sram_read()
1632 struct r8152 *tp = netdev_priv(netdev); in read_mii_word() local
1635 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in read_mii_word()
1641 ret = r8152_mdio_read(tp, reg); in read_mii_word()
1649 struct r8152 *tp = netdev_priv(netdev); in write_mii_word() local
1651 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in write_mii_word()
1657 r8152_mdio_write(tp, reg, val); in write_mii_word()
1661 r8152_submit_rx(struct r8152 *tp, struct rx_agg *agg, gfp_t mem_flags);
1664 rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u32 speed, u8 duplex,
1670 struct r8152 *tp = netdev_priv(netdev); in __rtl8152_set_mac_address() local
1678 ret = usb_autopm_get_interface(tp->intf); in __rtl8152_set_mac_address()
1683 mutex_lock(&tp->control); in __rtl8152_set_mac_address()
1687 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_CONFIG); in __rtl8152_set_mac_address()
1688 pla_ocp_write(tp, PLA_IDR, BYTE_EN_SIX_BYTES, 8, addr->sa_data); in __rtl8152_set_mac_address()
1689 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML); in __rtl8152_set_mac_address()
1691 mutex_unlock(&tp->control); in __rtl8152_set_mac_address()
1694 usb_autopm_put_interface(tp->intf); in __rtl8152_set_mac_address()
1708 static int vendor_mac_passthru_addr_read(struct r8152 *tp, struct sockaddr *sa) in vendor_mac_passthru_addr_read() argument
1720 if (tp->lenovo_macpassthru) { in vendor_mac_passthru_addr_read()
1726 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0); in vendor_mac_passthru_addr_read()
1729 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, EFUSE); in vendor_mac_passthru_addr_read()
1731 netif_dbg(tp, probe, tp->netdev, in vendor_mac_passthru_addr_read()
1737 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_MISC_1); in vendor_mac_passthru_addr_read()
1739 netif_dbg(tp, probe, tp->netdev, in vendor_mac_passthru_addr_read()
1756 netif_warn(tp, probe, tp->netdev, in vendor_mac_passthru_addr_read()
1764 netif_warn(tp, probe, tp->netdev, in vendor_mac_passthru_addr_read()
1770 netif_warn(tp, probe, tp->netdev, in vendor_mac_passthru_addr_read()
1777 tp->netdev->addr_assign_type = NET_ADDR_STOLEN; in vendor_mac_passthru_addr_read()
1778 netif_info(tp, probe, tp->netdev, in vendor_mac_passthru_addr_read()
1786 static int determine_ethernet_addr(struct r8152 *tp, struct sockaddr *sa) in determine_ethernet_addr() argument
1788 struct net_device *dev = tp->netdev; in determine_ethernet_addr()
1793 ret = eth_platform_get_mac_address(&tp->udev->dev, sa->sa_data); in determine_ethernet_addr()
1795 if (tp->version == RTL_VER_01) { in determine_ethernet_addr()
1796 ret = pla_ocp_read(tp, PLA_IDR, 8, sa->sa_data); in determine_ethernet_addr()
1801 ret = vendor_mac_passthru_addr_read(tp, sa); in determine_ethernet_addr()
1803 ret = pla_ocp_read(tp, PLA_BACKUP, 8, in determine_ethernet_addr()
1809 netif_err(tp, probe, dev, "Get ether addr fail\n"); in determine_ethernet_addr()
1811 netif_err(tp, probe, dev, "Invalid ether addr %pM\n", in determine_ethernet_addr()
1815 netif_info(tp, probe, dev, "Random ether addr %pM\n", in determine_ethernet_addr()
1823 static int set_ethernet_addr(struct r8152 *tp, bool in_resume) in set_ethernet_addr() argument
1825 struct net_device *dev = tp->netdev; in set_ethernet_addr()
1829 ret = determine_ethernet_addr(tp, &sa); in set_ethernet_addr()
1833 if (tp->version == RTL_VER_01) in set_ethernet_addr()
1846 struct r8152 *tp; in read_bulk_callback() local
1853 tp = agg->context; in read_bulk_callback()
1854 if (!tp) in read_bulk_callback()
1857 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in read_bulk_callback()
1860 if (!test_bit(WORK_ENABLE, &tp->flags)) in read_bulk_callback()
1863 netdev = tp->netdev; in read_bulk_callback()
1870 usb_mark_last_busy(tp->udev); in read_bulk_callback()
1877 spin_lock_irqsave(&tp->rx_lock, flags); in read_bulk_callback()
1878 list_add_tail(&agg->list, &tp->rx_done); in read_bulk_callback()
1879 spin_unlock_irqrestore(&tp->rx_lock, flags); in read_bulk_callback()
1880 napi_schedule(&tp->napi); in read_bulk_callback()
1883 rtl_set_unplug(tp); in read_bulk_callback()
1884 netif_device_detach(tp->netdev); in read_bulk_callback()
1888 spin_lock_irqsave(&tp->rx_lock, flags); in read_bulk_callback()
1889 list_add_tail(&agg->list, &tp->rx_done); in read_bulk_callback()
1890 spin_unlock_irqrestore(&tp->rx_lock, flags); in read_bulk_callback()
1891 set_bit(RX_EPROTO, &tp->flags); in read_bulk_callback()
1892 schedule_delayed_work(&tp->schedule, 1); in read_bulk_callback()
1906 r8152_submit_rx(tp, agg, GFP_ATOMIC); in read_bulk_callback()
1914 struct r8152 *tp; in write_bulk_callback() local
1922 tp = agg->context; in write_bulk_callback()
1923 if (!tp) in write_bulk_callback()
1926 netdev = tp->netdev; in write_bulk_callback()
1937 spin_lock_irqsave(&tp->tx_lock, flags); in write_bulk_callback()
1938 list_add_tail(&agg->list, &tp->tx_free); in write_bulk_callback()
1939 spin_unlock_irqrestore(&tp->tx_lock, flags); in write_bulk_callback()
1941 usb_autopm_put_interface_async(tp->intf); in write_bulk_callback()
1946 if (!test_bit(WORK_ENABLE, &tp->flags)) in write_bulk_callback()
1949 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in write_bulk_callback()
1952 if (!skb_queue_empty(&tp->tx_queue)) in write_bulk_callback()
1953 tasklet_schedule(&tp->tx_tl); in write_bulk_callback()
1958 struct r8152 *tp; in intr_callback() local
1963 tp = urb->context; in intr_callback()
1964 if (!tp) in intr_callback()
1967 if (!test_bit(WORK_ENABLE, &tp->flags)) in intr_callback()
1970 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in intr_callback()
1978 netif_device_detach(tp->netdev); in intr_callback()
1982 netif_info(tp, intr, tp->netdev, in intr_callback()
1987 netif_info(tp, intr, tp->netdev, in intr_callback()
1992 netif_info(tp, intr, tp->netdev, "intr status %d\n", status); in intr_callback()
1998 if (!netif_carrier_ok(tp->netdev)) { in intr_callback()
1999 set_bit(RTL8152_LINK_CHG, &tp->flags); in intr_callback()
2000 schedule_delayed_work(&tp->schedule, 0); in intr_callback()
2003 if (netif_carrier_ok(tp->netdev)) { in intr_callback()
2004 netif_stop_queue(tp->netdev); in intr_callback()
2005 set_bit(RTL8152_LINK_CHG, &tp->flags); in intr_callback()
2006 schedule_delayed_work(&tp->schedule, 0); in intr_callback()
2013 rtl_set_unplug(tp); in intr_callback()
2014 netif_device_detach(tp->netdev); in intr_callback()
2016 netif_err(tp, intr, tp->netdev, in intr_callback()
2031 static void free_rx_agg(struct r8152 *tp, struct rx_agg *agg) in free_rx_agg() argument
2039 atomic_dec(&tp->rx_count); in free_rx_agg()
2042 static struct rx_agg *alloc_rx_agg(struct r8152 *tp, gfp_t mflags) in alloc_rx_agg() argument
2044 struct net_device *netdev = tp->netdev; in alloc_rx_agg()
2046 unsigned int order = get_order(tp->rx_buf_sz); in alloc_rx_agg()
2064 rx_agg->context = tp; in alloc_rx_agg()
2068 spin_lock_irqsave(&tp->rx_lock, flags); in alloc_rx_agg()
2069 list_add_tail(&rx_agg->info_list, &tp->rx_info); in alloc_rx_agg()
2070 spin_unlock_irqrestore(&tp->rx_lock, flags); in alloc_rx_agg()
2072 atomic_inc(&tp->rx_count); in alloc_rx_agg()
2083 static void free_all_mem(struct r8152 *tp) in free_all_mem() argument
2089 spin_lock_irqsave(&tp->rx_lock, flags); in free_all_mem()
2091 list_for_each_entry_safe(agg, agg_next, &tp->rx_info, info_list) in free_all_mem()
2092 free_rx_agg(tp, agg); in free_all_mem()
2094 spin_unlock_irqrestore(&tp->rx_lock, flags); in free_all_mem()
2096 WARN_ON(atomic_read(&tp->rx_count)); in free_all_mem()
2099 usb_free_urb(tp->tx_info[i].urb); in free_all_mem()
2100 tp->tx_info[i].urb = NULL; in free_all_mem()
2102 kfree(tp->tx_info[i].buffer); in free_all_mem()
2103 tp->tx_info[i].buffer = NULL; in free_all_mem()
2104 tp->tx_info[i].head = NULL; in free_all_mem()
2107 usb_free_urb(tp->intr_urb); in free_all_mem()
2108 tp->intr_urb = NULL; in free_all_mem()
2110 kfree(tp->intr_buff); in free_all_mem()
2111 tp->intr_buff = NULL; in free_all_mem()
2114 static int alloc_all_mem(struct r8152 *tp) in alloc_all_mem() argument
2116 struct net_device *netdev = tp->netdev; in alloc_all_mem()
2117 struct usb_interface *intf = tp->intf; in alloc_all_mem()
2124 spin_lock_init(&tp->rx_lock); in alloc_all_mem()
2125 spin_lock_init(&tp->tx_lock); in alloc_all_mem()
2126 INIT_LIST_HEAD(&tp->rx_info); in alloc_all_mem()
2127 INIT_LIST_HEAD(&tp->tx_free); in alloc_all_mem()
2128 INIT_LIST_HEAD(&tp->rx_done); in alloc_all_mem()
2129 skb_queue_head_init(&tp->tx_queue); in alloc_all_mem()
2130 skb_queue_head_init(&tp->rx_queue); in alloc_all_mem()
2131 atomic_set(&tp->rx_count, 0); in alloc_all_mem()
2134 if (!alloc_rx_agg(tp, GFP_KERNEL)) in alloc_all_mem()
2160 INIT_LIST_HEAD(&tp->tx_info[i].list); in alloc_all_mem()
2161 tp->tx_info[i].context = tp; in alloc_all_mem()
2162 tp->tx_info[i].urb = urb; in alloc_all_mem()
2163 tp->tx_info[i].buffer = buf; in alloc_all_mem()
2164 tp->tx_info[i].head = tx_agg_align(buf); in alloc_all_mem()
2166 list_add_tail(&tp->tx_info[i].list, &tp->tx_free); in alloc_all_mem()
2169 tp->intr_urb = usb_alloc_urb(0, GFP_KERNEL); in alloc_all_mem()
2170 if (!tp->intr_urb) in alloc_all_mem()
2173 tp->intr_buff = kmalloc(INTBUFSIZE, GFP_KERNEL); in alloc_all_mem()
2174 if (!tp->intr_buff) in alloc_all_mem()
2177 tp->intr_interval = (int)ep_intr->desc.bInterval; in alloc_all_mem()
2178 usb_fill_int_urb(tp->intr_urb, tp->udev, tp->pipe_intr, in alloc_all_mem()
2179 tp->intr_buff, INTBUFSIZE, intr_callback, in alloc_all_mem()
2180 tp, tp->intr_interval); in alloc_all_mem()
2185 free_all_mem(tp); in alloc_all_mem()
2189 static struct tx_agg *r8152_get_tx_agg(struct r8152 *tp) in r8152_get_tx_agg() argument
2194 if (list_empty(&tp->tx_free)) in r8152_get_tx_agg()
2197 spin_lock_irqsave(&tp->tx_lock, flags); in r8152_get_tx_agg()
2198 if (!list_empty(&tp->tx_free)) { in r8152_get_tx_agg()
2201 cursor = tp->tx_free.next; in r8152_get_tx_agg()
2205 spin_unlock_irqrestore(&tp->tx_lock, flags); in r8152_get_tx_agg()
2214 static void r8152_csum_workaround(struct r8152 *tp, struct sk_buff *skb, in r8152_csum_workaround() argument
2218 netdev_features_t features = tp->netdev->features; in r8152_csum_workaround()
2245 stats = &tp->netdev->stats; in r8152_csum_workaround()
2270 static int r8152_tx_csum(struct r8152 *tp, struct tx_desc *desc, in r8152_tx_csum() argument
2285 netif_warn(tp, tx_err, tp->netdev, in r8152_tx_csum()
2318 netif_warn(tp, tx_err, tp->netdev, in r8152_tx_csum()
2358 static int r8152_tx_agg_fill(struct r8152 *tp, struct tx_agg *agg) in r8152_tx_agg_fill() argument
2360 struct sk_buff_head skb_head, *tx_queue = &tp->tx_queue; in r8152_tx_agg_fill()
2393 if (r8152_tx_csum(tp, tx_desc, skb, skb->len)) { in r8152_tx_agg_fill()
2394 r8152_csum_workaround(tp, skb, &skb_head); in r8152_tx_agg_fill()
2404 struct net_device_stats *stats = &tp->netdev->stats; in r8152_tx_agg_fill()
2420 if (tp->dell_tb_rx_agg_bug) in r8152_tx_agg_fill()
2430 netif_tx_lock(tp->netdev); in r8152_tx_agg_fill()
2432 if (netif_queue_stopped(tp->netdev) && in r8152_tx_agg_fill()
2433 skb_queue_len(&tp->tx_queue) < tp->tx_qlen) in r8152_tx_agg_fill()
2434 netif_wake_queue(tp->netdev); in r8152_tx_agg_fill()
2436 netif_tx_unlock(tp->netdev); in r8152_tx_agg_fill()
2438 ret = usb_autopm_get_interface_async(tp->intf); in r8152_tx_agg_fill()
2442 usb_fill_bulk_urb(agg->urb, tp->udev, tp->pipe_out, in r8152_tx_agg_fill()
2448 usb_autopm_put_interface_async(tp->intf); in r8152_tx_agg_fill()
2454 static u8 r8152_rx_csum(struct r8152 *tp, struct rx_desc *rx_desc) in r8152_rx_csum() argument
2459 if (!(tp->netdev->features & NETIF_F_RXCSUM)) in r8152_rx_csum()
2483 static inline bool rx_count_exceed(struct r8152 *tp) in rx_count_exceed() argument
2485 return atomic_read(&tp->rx_count) > RTL8152_MAX_RX; in rx_count_exceed()
2493 static struct rx_agg *rtl_get_free_rx(struct r8152 *tp, gfp_t mflags) in rtl_get_free_rx() argument
2498 spin_lock_irqsave(&tp->rx_lock, flags); in rtl_get_free_rx()
2500 list_for_each_entry_safe(agg, agg_next, &tp->rx_used, list) { in rtl_get_free_rx()
2507 if (rx_count_exceed(tp)) { in rtl_get_free_rx()
2509 free_rx_agg(tp, agg); in rtl_get_free_rx()
2515 spin_unlock_irqrestore(&tp->rx_lock, flags); in rtl_get_free_rx()
2517 if (!agg_free && atomic_read(&tp->rx_count) < tp->rx_pending) in rtl_get_free_rx()
2518 agg_free = alloc_rx_agg(tp, mflags); in rtl_get_free_rx()
2523 static int rx_bottom(struct r8152 *tp, int budget) in rx_bottom() argument
2528 struct napi_struct *napi = &tp->napi; in rx_bottom()
2530 if (!skb_queue_empty(&tp->rx_queue)) { in rx_bottom()
2532 struct sk_buff *skb = __skb_dequeue(&tp->rx_queue); in rx_bottom()
2533 struct net_device *netdev = tp->netdev; in rx_bottom()
2548 if (list_empty(&tp->rx_done) || work_done >= budget) in rx_bottom()
2551 clear_bit(RX_EPROTO, &tp->flags); in rx_bottom()
2553 spin_lock_irqsave(&tp->rx_lock, flags); in rx_bottom()
2554 list_splice_init(&tp->rx_done, &rx_queue); in rx_bottom()
2555 spin_unlock_irqrestore(&tp->rx_lock, flags); in rx_bottom()
2580 agg_free = rtl_get_free_rx(tp, GFP_ATOMIC); in rx_bottom()
2587 struct net_device *netdev = tp->netdev; in rx_bottom()
2593 WARN_ON_ONCE(skb_queue_len(&tp->rx_queue) >= 1000); in rx_bottom()
2607 if (!agg_free || tp->rx_copybreak > len) in rx_bottom()
2619 rx_frag_head_sz = tp->rx_copybreak; in rx_bottom()
2636 skb->ip_summed = r8152_rx_csum(tp, rx_desc); in rx_bottom()
2670 __skb_queue_tail(&tp->rx_queue, skb); in rx_bottom()
2683 spin_lock_irqsave(&tp->rx_lock, flags); in rx_bottom()
2685 list_add(&agg_free->list, &tp->rx_used); in rx_bottom()
2687 list_add_tail(&agg->list, &tp->rx_used); in rx_bottom()
2691 spin_unlock_irqrestore(&tp->rx_lock, flags); in rx_bottom()
2696 ret = r8152_submit_rx(tp, agg, GFP_ATOMIC); in rx_bottom()
2705 spin_lock_irqsave(&tp->rx_lock, flags); in rx_bottom()
2706 list_splice(&rx_queue, &tp->rx_done); in rx_bottom()
2707 spin_unlock_irqrestore(&tp->rx_lock, flags); in rx_bottom()
2714 static void tx_bottom(struct r8152 *tp) in tx_bottom() argument
2719 struct net_device *netdev = tp->netdev; in tx_bottom()
2722 if (skb_queue_empty(&tp->tx_queue)) in tx_bottom()
2725 agg = r8152_get_tx_agg(tp); in tx_bottom()
2729 res = r8152_tx_agg_fill(tp, agg); in tx_bottom()
2734 rtl_set_unplug(tp); in tx_bottom()
2740 netif_warn(tp, tx_err, netdev, in tx_bottom()
2744 spin_lock_irqsave(&tp->tx_lock, flags); in tx_bottom()
2745 list_add_tail(&agg->list, &tp->tx_free); in tx_bottom()
2746 spin_unlock_irqrestore(&tp->tx_lock, flags); in tx_bottom()
2753 struct r8152 *tp = from_tasklet(tp, t, tx_tl); in bottom_half() local
2755 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in bottom_half()
2758 if (!test_bit(WORK_ENABLE, &tp->flags)) in bottom_half()
2763 if (!netif_carrier_ok(tp->netdev)) in bottom_half()
2766 clear_bit(SCHEDULE_TASKLET, &tp->flags); in bottom_half()
2768 tx_bottom(tp); in bottom_half()
2773 struct r8152 *tp = container_of(napi, struct r8152, napi); in r8152_poll() local
2779 work_done = rx_bottom(tp, budget); in r8152_poll()
2784 if (!list_empty(&tp->rx_done)) in r8152_poll()
2793 int r8152_submit_rx(struct r8152 *tp, struct rx_agg *agg, gfp_t mem_flags) in r8152_submit_rx() argument
2798 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags) || in r8152_submit_rx()
2799 !test_bit(WORK_ENABLE, &tp->flags) || !netif_carrier_ok(tp->netdev)) in r8152_submit_rx()
2802 usb_fill_bulk_urb(agg->urb, tp->udev, tp->pipe_in, in r8152_submit_rx()
2803 agg->buffer, tp->rx_buf_sz, in r8152_submit_rx()
2808 rtl_set_unplug(tp); in r8152_submit_rx()
2809 netif_device_detach(tp->netdev); in r8152_submit_rx()
2815 spin_lock_irqsave(&tp->rx_lock, flags); in r8152_submit_rx()
2816 list_add_tail(&agg->list, &tp->rx_done); in r8152_submit_rx()
2817 spin_unlock_irqrestore(&tp->rx_lock, flags); in r8152_submit_rx()
2819 netif_err(tp, rx_err, tp->netdev, in r8152_submit_rx()
2822 napi_schedule(&tp->napi); in r8152_submit_rx()
2828 static void rtl_drop_queued_tx(struct r8152 *tp) in rtl_drop_queued_tx() argument
2830 struct net_device_stats *stats = &tp->netdev->stats; in rtl_drop_queued_tx()
2831 struct sk_buff_head skb_head, *tx_queue = &tp->tx_queue; in rtl_drop_queued_tx()
2850 struct r8152 *tp = netdev_priv(netdev); in rtl8152_tx_timeout() local
2852 netif_warn(tp, tx_err, netdev, "Tx timeout\n"); in rtl8152_tx_timeout()
2854 usb_queue_reset_device(tp->intf); in rtl8152_tx_timeout()
2859 struct r8152 *tp = netdev_priv(netdev); in rtl8152_set_rx_mode() local
2862 set_bit(RTL8152_SET_RX_MODE, &tp->flags); in rtl8152_set_rx_mode()
2863 schedule_delayed_work(&tp->schedule, 0); in rtl8152_set_rx_mode()
2869 struct r8152 *tp = netdev_priv(netdev); in _rtl8152_set_rx_mode() local
2875 ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); in _rtl8152_set_rx_mode()
2881 netif_notice(tp, link, netdev, "Promiscuous mode enabled\n"); in _rtl8152_set_rx_mode()
2911 pla_ocp_write(tp, PLA_MAR, BYTE_EN_DWORD, sizeof(tmp), tmp); in _rtl8152_set_rx_mode()
2912 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); in _rtl8152_set_rx_mode()
2935 struct r8152 *tp = netdev_priv(netdev); in rtl8152_start_xmit() local
2939 skb_queue_tail(&tp->tx_queue, skb); in rtl8152_start_xmit()
2941 if (!list_empty(&tp->tx_free)) { in rtl8152_start_xmit()
2942 if (test_bit(SELECTIVE_SUSPEND, &tp->flags)) { in rtl8152_start_xmit()
2943 set_bit(SCHEDULE_TASKLET, &tp->flags); in rtl8152_start_xmit()
2944 schedule_delayed_work(&tp->schedule, 0); in rtl8152_start_xmit()
2946 usb_mark_last_busy(tp->udev); in rtl8152_start_xmit()
2947 tasklet_schedule(&tp->tx_tl); in rtl8152_start_xmit()
2949 } else if (skb_queue_len(&tp->tx_queue) > tp->tx_qlen) { in rtl8152_start_xmit()
2956 static void r8152b_reset_packet_filter(struct r8152 *tp) in r8152b_reset_packet_filter() argument
2960 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_FMC); in r8152b_reset_packet_filter()
2962 ocp_write_word(tp, MCU_TYPE_PLA, PLA_FMC, ocp_data); in r8152b_reset_packet_filter()
2964 ocp_write_word(tp, MCU_TYPE_PLA, PLA_FMC, ocp_data); in r8152b_reset_packet_filter()
2967 static void rtl8152_nic_reset(struct r8152 *tp) in rtl8152_nic_reset() argument
2972 switch (tp->version) { in rtl8152_nic_reset()
2976 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CR); in rtl8152_nic_reset()
2978 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CR, ocp_data); in rtl8152_nic_reset()
2980 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_BMU_RESET); in rtl8152_nic_reset()
2982 ocp_write_word(tp, MCU_TYPE_USB, USB_BMU_RESET, ocp_data); in rtl8152_nic_reset()
2984 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL); in rtl8152_nic_reset()
2986 ocp_write_word(tp, MCU_TYPE_USB, USB_USB_CTRL, ocp_data); in rtl8152_nic_reset()
2988 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CR); in rtl8152_nic_reset()
2990 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CR, ocp_data); in rtl8152_nic_reset()
2992 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_BMU_RESET); in rtl8152_nic_reset()
2994 ocp_write_word(tp, MCU_TYPE_USB, USB_BMU_RESET, ocp_data); in rtl8152_nic_reset()
2996 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL); in rtl8152_nic_reset()
2998 ocp_write_word(tp, MCU_TYPE_USB, USB_USB_CTRL, ocp_data); in rtl8152_nic_reset()
3002 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CR, CR_RST); in rtl8152_nic_reset()
3005 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl8152_nic_reset()
3007 if (!(ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CR) & CR_RST)) in rtl8152_nic_reset()
3015 static void set_tx_qlen(struct r8152 *tp) in set_tx_qlen() argument
3017 tp->tx_qlen = agg_buf_sz / (mtu_to_size(tp->netdev->mtu) + sizeof(struct tx_desc)); in set_tx_qlen()
3020 static inline u16 rtl8152_get_speed(struct r8152 *tp) in rtl8152_get_speed() argument
3022 return ocp_read_word(tp, MCU_TYPE_PLA, PLA_PHYSTATUS); in rtl8152_get_speed()
3025 static void rtl_eee_plus_en(struct r8152 *tp, bool enable) in rtl_eee_plus_en() argument
3029 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EEEP_CR); in rtl_eee_plus_en()
3034 ocp_write_word(tp, MCU_TYPE_PLA, PLA_EEEP_CR, ocp_data); in rtl_eee_plus_en()
3037 static void rtl_set_eee_plus(struct r8152 *tp) in rtl_set_eee_plus() argument
3039 if (rtl8152_get_speed(tp) & _10bps) in rtl_set_eee_plus()
3040 rtl_eee_plus_en(tp, true); in rtl_set_eee_plus()
3042 rtl_eee_plus_en(tp, false); in rtl_set_eee_plus()
3045 static void rxdy_gated_en(struct r8152 *tp, bool enable) in rxdy_gated_en() argument
3049 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MISC_1); in rxdy_gated_en()
3054 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MISC_1, ocp_data); in rxdy_gated_en()
3057 static int rtl_start_rx(struct r8152 *tp) in rtl_start_rx() argument
3066 spin_lock_irqsave(&tp->rx_lock, flags); in rtl_start_rx()
3068 INIT_LIST_HEAD(&tp->rx_done); in rtl_start_rx()
3069 INIT_LIST_HEAD(&tp->rx_used); in rtl_start_rx()
3071 list_splice_init(&tp->rx_info, &tmp_list); in rtl_start_rx()
3073 spin_unlock_irqrestore(&tp->rx_lock, flags); in rtl_start_rx()
3080 spin_lock_irqsave(&tp->rx_lock, flags); in rtl_start_rx()
3081 list_add_tail(&agg->list, &tp->rx_used); in rtl_start_rx()
3082 spin_unlock_irqrestore(&tp->rx_lock, flags); in rtl_start_rx()
3084 spin_lock_irqsave(&tp->rx_lock, flags); in rtl_start_rx()
3085 list_add_tail(&agg->list, &tp->rx_done); in rtl_start_rx()
3086 spin_unlock_irqrestore(&tp->rx_lock, flags); in rtl_start_rx()
3088 ret = r8152_submit_rx(tp, agg, GFP_KERNEL); in rtl_start_rx()
3092 spin_lock_irqsave(&tp->rx_lock, flags); in rtl_start_rx()
3093 WARN_ON(!list_empty(&tp->rx_info)); in rtl_start_rx()
3094 list_splice(&tmp_list, &tp->rx_info); in rtl_start_rx()
3095 spin_unlock_irqrestore(&tp->rx_lock, flags); in rtl_start_rx()
3100 static int rtl_stop_rx(struct r8152 *tp) in rtl_stop_rx() argument
3114 spin_lock_irqsave(&tp->rx_lock, flags); in rtl_stop_rx()
3115 list_splice_init(&tp->rx_info, &tmp_list); in rtl_stop_rx()
3116 spin_unlock_irqrestore(&tp->rx_lock, flags); in rtl_stop_rx()
3123 free_rx_agg(tp, agg); in rtl_stop_rx()
3129 spin_lock_irqsave(&tp->rx_lock, flags); in rtl_stop_rx()
3130 WARN_ON(!list_empty(&tp->rx_info)); in rtl_stop_rx()
3131 list_splice(&tmp_list, &tp->rx_info); in rtl_stop_rx()
3132 spin_unlock_irqrestore(&tp->rx_lock, flags); in rtl_stop_rx()
3134 while (!skb_queue_empty(&tp->rx_queue)) in rtl_stop_rx()
3135 dev_kfree_skb(__skb_dequeue(&tp->rx_queue)); in rtl_stop_rx()
3140 static void rtl_set_ifg(struct r8152 *tp, u16 speed) in rtl_set_ifg() argument
3144 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TCR1); in rtl_set_ifg()
3148 ocp_write_word(tp, MCU_TYPE_PLA, PLA_TCR1, ocp_data); in rtl_set_ifg()
3150 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4); in rtl_set_ifg()
3152 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4, ocp_data); in rtl_set_ifg()
3155 ocp_write_word(tp, MCU_TYPE_PLA, PLA_TCR1, ocp_data); in rtl_set_ifg()
3157 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4); in rtl_set_ifg()
3159 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4, ocp_data); in rtl_set_ifg()
3163 static inline void r8153b_rx_agg_chg_indicate(struct r8152 *tp) in r8153b_rx_agg_chg_indicate() argument
3165 ocp_write_byte(tp, MCU_TYPE_USB, USB_UPT_RXDMA_OWN, in r8153b_rx_agg_chg_indicate()
3169 static int rtl_enable(struct r8152 *tp) in rtl_enable() argument
3173 r8152b_reset_packet_filter(tp); in rtl_enable()
3175 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CR); in rtl_enable()
3177 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CR, ocp_data); in rtl_enable()
3179 switch (tp->version) { in rtl_enable()
3189 r8153b_rx_agg_chg_indicate(tp); in rtl_enable()
3193 rxdy_gated_en(tp, false); in rtl_enable()
3198 static int rtl8152_enable(struct r8152 *tp) in rtl8152_enable() argument
3200 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl8152_enable()
3203 set_tx_qlen(tp); in rtl8152_enable()
3204 rtl_set_eee_plus(tp); in rtl8152_enable()
3206 return rtl_enable(tp); in rtl8152_enable()
3209 static void r8153_set_rx_early_timeout(struct r8152 *tp) in r8153_set_rx_early_timeout() argument
3211 u32 ocp_data = tp->coalesce / 8; in r8153_set_rx_early_timeout()
3213 switch (tp->version) { in r8153_set_rx_early_timeout()
3218 ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_TIMEOUT, in r8153_set_rx_early_timeout()
3228 ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_TIMEOUT, in r8153_set_rx_early_timeout()
3230 ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EXTRA_AGGR_TMR, in r8153_set_rx_early_timeout()
3239 ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_TIMEOUT, in r8153_set_rx_early_timeout()
3241 ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EXTRA_AGGR_TMR, in r8153_set_rx_early_timeout()
3250 static void r8153_set_rx_early_size(struct r8152 *tp) in r8153_set_rx_early_size() argument
3252 u32 ocp_data = tp->rx_buf_sz - rx_reserved_size(tp->netdev->mtu); in r8153_set_rx_early_size()
3254 switch (tp->version) { in r8153_set_rx_early_size()
3259 ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_SIZE, in r8153_set_rx_early_size()
3265 ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_SIZE, in r8153_set_rx_early_size()
3274 ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_SIZE, in r8153_set_rx_early_size()
3283 static int rtl8153_enable(struct r8152 *tp) in rtl8153_enable() argument
3287 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl8153_enable()
3290 set_tx_qlen(tp); in rtl8153_enable()
3291 rtl_set_eee_plus(tp); in rtl8153_enable()
3292 r8153_set_rx_early_timeout(tp); in rtl8153_enable()
3293 r8153_set_rx_early_size(tp); in rtl8153_enable()
3295 rtl_set_ifg(tp, rtl8152_get_speed(tp)); in rtl8153_enable()
3297 switch (tp->version) { in rtl8153_enable()
3300 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_TASK); in rtl8153_enable()
3302 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_TASK, ocp_data); in rtl8153_enable()
3305 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_TASK, ocp_data); in rtl8153_enable()
3311 return rtl_enable(tp); in rtl8153_enable()
3314 static void rtl_disable(struct r8152 *tp) in rtl_disable() argument
3319 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) { in rtl_disable()
3320 rtl_drop_queued_tx(tp); in rtl_disable()
3324 ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); in rtl_disable()
3326 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); in rtl_disable()
3328 rtl_drop_queued_tx(tp); in rtl_disable()
3331 usb_kill_urb(tp->tx_info[i].urb); in rtl_disable()
3333 rxdy_gated_en(tp, true); in rtl_disable()
3336 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl_disable()
3338 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); in rtl_disable()
3345 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl_disable()
3347 if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_TCR0) & TCR0_TX_EMPTY) in rtl_disable()
3352 rtl_stop_rx(tp); in rtl_disable()
3354 rtl8152_nic_reset(tp); in rtl_disable()
3357 static void r8152_power_cut_en(struct r8152 *tp, bool enable) in r8152_power_cut_en() argument
3361 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_UPS_CTRL); in r8152_power_cut_en()
3366 ocp_write_word(tp, MCU_TYPE_USB, USB_UPS_CTRL, ocp_data); in r8152_power_cut_en()
3368 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_PM_CTRL_STATUS); in r8152_power_cut_en()
3370 ocp_write_word(tp, MCU_TYPE_USB, USB_PM_CTRL_STATUS, ocp_data); in r8152_power_cut_en()
3373 static void rtl_rx_vlan_en(struct r8152 *tp, bool enable) in rtl_rx_vlan_en() argument
3377 switch (tp->version) { in rtl_rx_vlan_en()
3388 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CPCR); in rtl_rx_vlan_en()
3393 ocp_write_word(tp, MCU_TYPE_PLA, PLA_CPCR, ocp_data); in rtl_rx_vlan_en()
3403 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_RCR1); in rtl_rx_vlan_en()
3408 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RCR1, ocp_data); in rtl_rx_vlan_en()
3417 struct r8152 *tp = netdev_priv(dev); in rtl8152_set_features() local
3420 ret = usb_autopm_get_interface(tp->intf); in rtl8152_set_features()
3424 mutex_lock(&tp->control); in rtl8152_set_features()
3428 rtl_rx_vlan_en(tp, true); in rtl8152_set_features()
3430 rtl_rx_vlan_en(tp, false); in rtl8152_set_features()
3433 mutex_unlock(&tp->control); in rtl8152_set_features()
3435 usb_autopm_put_interface(tp->intf); in rtl8152_set_features()
3443 static u32 __rtl_get_wol(struct r8152 *tp) in __rtl_get_wol() argument
3448 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CONFIG34); in __rtl_get_wol()
3452 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CONFIG5); in __rtl_get_wol()
3460 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CFG_WOL); in __rtl_get_wol()
3467 static void __rtl_set_wol(struct r8152 *tp, u32 wolopts) in __rtl_set_wol() argument
3471 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_CONFIG); in __rtl_set_wol()
3473 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CONFIG34); in __rtl_set_wol()
3477 ocp_write_word(tp, MCU_TYPE_PLA, PLA_CONFIG34, ocp_data); in __rtl_set_wol()
3479 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CONFIG5); in __rtl_set_wol()
3487 ocp_write_word(tp, MCU_TYPE_PLA, PLA_CONFIG5, ocp_data); in __rtl_set_wol()
3489 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML); in __rtl_set_wol()
3491 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CFG_WOL); in __rtl_set_wol()
3495 ocp_write_word(tp, MCU_TYPE_PLA, PLA_CFG_WOL, ocp_data); in __rtl_set_wol()
3498 device_set_wakeup_enable(&tp->udev->dev, true); in __rtl_set_wol()
3500 device_set_wakeup_enable(&tp->udev->dev, false); in __rtl_set_wol()
3503 static void r8153_mac_clk_speed_down(struct r8152 *tp, bool enable) in r8153_mac_clk_speed_down() argument
3505 u32 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL2); in r8153_mac_clk_speed_down()
3513 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL2, ocp_data); in r8153_mac_clk_speed_down()
3516 static void r8156_mac_clk_spd(struct r8152 *tp, bool enable) in r8156_mac_clk_spd() argument
3523 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL, in r8156_mac_clk_spd()
3526 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL2); in r8156_mac_clk_spd()
3529 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL2, ocp_data); in r8156_mac_clk_spd()
3531 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL2); in r8156_mac_clk_spd()
3533 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL2, ocp_data); in r8156_mac_clk_spd()
3537 static void r8153_u1u2en(struct r8152 *tp, bool enable) in r8153_u1u2en() argument
3546 usb_ocp_write(tp, USB_TOLERANCE, BYTE_EN_SIX_BYTES, sizeof(u1u2), u1u2); in r8153_u1u2en()
3549 static void r8153b_u1u2en(struct r8152 *tp, bool enable) in r8153b_u1u2en() argument
3553 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_LPM_CONFIG); in r8153b_u1u2en()
3559 ocp_write_word(tp, MCU_TYPE_USB, USB_LPM_CONFIG, ocp_data); in r8153b_u1u2en()
3562 static void r8153_u2p3en(struct r8152 *tp, bool enable) in r8153_u2p3en() argument
3566 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_U2P3_CTRL); in r8153_u2p3en()
3571 ocp_write_word(tp, MCU_TYPE_USB, USB_U2P3_CTRL, ocp_data); in r8153_u2p3en()
3574 static void r8153b_ups_flags(struct r8152 *tp) in r8153b_ups_flags() argument
3578 if (tp->ups_info.green) in r8153b_ups_flags()
3581 if (tp->ups_info.aldps) in r8153b_ups_flags()
3584 if (tp->ups_info.eee) in r8153b_ups_flags()
3587 if (tp->ups_info.flow_control) in r8153b_ups_flags()
3590 if (tp->ups_info.eee_ckdiv) in r8153b_ups_flags()
3593 if (tp->ups_info.eee_cmod_lv) in r8153b_ups_flags()
3596 if (tp->ups_info.r_tune) in r8153b_ups_flags()
3599 if (tp->ups_info._10m_ckdiv) in r8153b_ups_flags()
3602 if (tp->ups_info.eee_plloff_100) in r8153b_ups_flags()
3605 if (tp->ups_info.eee_plloff_giga) in r8153b_ups_flags()
3608 if (tp->ups_info._250m_ckdiv) in r8153b_ups_flags()
3611 if (tp->ups_info.ctap_short_off) in r8153b_ups_flags()
3614 switch (tp->ups_info.speed_duplex) { in r8153b_ups_flags()
3646 ocp_write_dword(tp, MCU_TYPE_USB, USB_UPS_FLAGS, ups_flags); in r8153b_ups_flags()
3649 static void r8156_ups_flags(struct r8152 *tp) in r8156_ups_flags() argument
3653 if (tp->ups_info.green) in r8156_ups_flags()
3656 if (tp->ups_info.aldps) in r8156_ups_flags()
3659 if (tp->ups_info.eee) in r8156_ups_flags()
3662 if (tp->ups_info.flow_control) in r8156_ups_flags()
3665 if (tp->ups_info.eee_ckdiv) in r8156_ups_flags()
3668 if (tp->ups_info._10m_ckdiv) in r8156_ups_flags()
3671 if (tp->ups_info.eee_plloff_100) in r8156_ups_flags()
3674 if (tp->ups_info.eee_plloff_giga) in r8156_ups_flags()
3677 if (tp->ups_info._250m_ckdiv) in r8156_ups_flags()
3680 switch (tp->ups_info.speed_duplex) { in r8156_ups_flags()
3715 switch (tp->ups_info.lite_mode) { in r8156_ups_flags()
3728 ocp_write_dword(tp, MCU_TYPE_USB, USB_UPS_FLAGS, ups_flags); in r8156_ups_flags()
3731 static void rtl_green_en(struct r8152 *tp, bool enable) in rtl_green_en() argument
3735 data = sram_read(tp, SRAM_GREEN_CFG); in rtl_green_en()
3740 sram_write(tp, SRAM_GREEN_CFG, data); in rtl_green_en()
3742 tp->ups_info.green = enable; in rtl_green_en()
3745 static void r8153b_green_en(struct r8152 *tp, bool enable) in r8153b_green_en() argument
3748 sram_write(tp, 0x8045, 0); /* 10M abiq&ldvbias */ in r8153b_green_en()
3749 sram_write(tp, 0x804d, 0x1222); /* 100M short abiq&ldvbias */ in r8153b_green_en()
3750 sram_write(tp, 0x805d, 0x0022); /* 1000M short abiq&ldvbias */ in r8153b_green_en()
3752 sram_write(tp, 0x8045, 0x2444); /* 10M abiq&ldvbias */ in r8153b_green_en()
3753 sram_write(tp, 0x804d, 0x2444); /* 100M short abiq&ldvbias */ in r8153b_green_en()
3754 sram_write(tp, 0x805d, 0x2444); /* 1000M short abiq&ldvbias */ in r8153b_green_en()
3757 rtl_green_en(tp, true); in r8153b_green_en()
3760 static u16 r8153_phy_status(struct r8152 *tp, u16 desired) in r8153_phy_status() argument
3766 data = ocp_reg_read(tp, OCP_PHY_STATUS); in r8153_phy_status()
3777 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8153_phy_status()
3784 static void r8153b_ups_en(struct r8152 *tp, bool enable) in r8153b_ups_en() argument
3786 u32 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_POWER_CUT); in r8153b_ups_en()
3789 r8153b_ups_flags(tp); in r8153b_ups_en()
3792 ocp_write_byte(tp, MCU_TYPE_USB, USB_POWER_CUT, ocp_data); in r8153b_ups_en()
3794 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_MISC_2); in r8153b_ups_en()
3796 ocp_write_byte(tp, MCU_TYPE_USB, USB_MISC_2, ocp_data); in r8153b_ups_en()
3799 ocp_write_byte(tp, MCU_TYPE_USB, USB_POWER_CUT, ocp_data); in r8153b_ups_en()
3801 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_MISC_2); in r8153b_ups_en()
3803 ocp_write_byte(tp, MCU_TYPE_USB, USB_MISC_2, ocp_data); in r8153b_ups_en()
3805 if (ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0) & PCUT_STATUS) { in r8153b_ups_en()
3809 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8153b_ups_en()
3811 if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) & in r8153b_ups_en()
3817 tp->rtl_ops.hw_phy_cfg(tp); in r8153b_ups_en()
3819 rtl8152_set_speed(tp, tp->autoneg, tp->speed, in r8153b_ups_en()
3820 tp->duplex, tp->advertising); in r8153b_ups_en()
3825 static void r8153c_ups_en(struct r8152 *tp, bool enable) in r8153c_ups_en() argument
3827 u32 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_POWER_CUT); in r8153c_ups_en()
3830 r8153b_ups_flags(tp); in r8153c_ups_en()
3833 ocp_write_byte(tp, MCU_TYPE_USB, USB_POWER_CUT, ocp_data); in r8153c_ups_en()
3835 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_MISC_2); in r8153c_ups_en()
3838 ocp_write_byte(tp, MCU_TYPE_USB, USB_MISC_2, ocp_data); in r8153c_ups_en()
3841 ocp_write_byte(tp, MCU_TYPE_USB, USB_POWER_CUT, ocp_data); in r8153c_ups_en()
3843 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_MISC_2); in r8153c_ups_en()
3845 ocp_write_byte(tp, MCU_TYPE_USB, USB_MISC_2, ocp_data); in r8153c_ups_en()
3847 if (ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0) & PCUT_STATUS) { in r8153c_ups_en()
3851 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8153c_ups_en()
3853 if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) & in r8153c_ups_en()
3859 tp->rtl_ops.hw_phy_cfg(tp); in r8153c_ups_en()
3861 rtl8152_set_speed(tp, tp->autoneg, tp->speed, in r8153c_ups_en()
3862 tp->duplex, tp->advertising); in r8153c_ups_en()
3865 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_CONFIG); in r8153c_ups_en()
3867 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CONFIG34); in r8153c_ups_en()
3869 ocp_write_word(tp, MCU_TYPE_PLA, PLA_CONFIG34, ocp_data); in r8153c_ups_en()
3871 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML); in r8153c_ups_en()
3875 static void r8156_ups_en(struct r8152 *tp, bool enable) in r8156_ups_en() argument
3877 u32 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_POWER_CUT); in r8156_ups_en()
3880 r8156_ups_flags(tp); in r8156_ups_en()
3883 ocp_write_byte(tp, MCU_TYPE_USB, USB_POWER_CUT, ocp_data); in r8156_ups_en()
3885 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_MISC_2); in r8156_ups_en()
3887 ocp_write_byte(tp, MCU_TYPE_USB, USB_MISC_2, ocp_data); in r8156_ups_en()
3889 switch (tp->version) { in r8156_ups_en()
3892 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_UPHY_XTAL); in r8156_ups_en()
3894 ocp_write_byte(tp, MCU_TYPE_USB, USB_UPHY_XTAL, ocp_data); in r8156_ups_en()
3901 ocp_write_byte(tp, MCU_TYPE_USB, USB_POWER_CUT, ocp_data); in r8156_ups_en()
3903 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_MISC_2); in r8156_ups_en()
3905 ocp_write_byte(tp, MCU_TYPE_USB, USB_MISC_2, ocp_data); in r8156_ups_en()
3907 if (ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0) & PCUT_STATUS) { in r8156_ups_en()
3908 tp->rtl_ops.hw_phy_cfg(tp); in r8156_ups_en()
3910 rtl8152_set_speed(tp, tp->autoneg, tp->speed, in r8156_ups_en()
3911 tp->duplex, tp->advertising); in r8156_ups_en()
3916 static void r8153_power_cut_en(struct r8152 *tp, bool enable) in r8153_power_cut_en() argument
3920 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_POWER_CUT); in r8153_power_cut_en()
3925 ocp_write_word(tp, MCU_TYPE_USB, USB_POWER_CUT, ocp_data); in r8153_power_cut_en()
3927 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0); in r8153_power_cut_en()
3929 ocp_write_word(tp, MCU_TYPE_USB, USB_MISC_0, ocp_data); in r8153_power_cut_en()
3932 static void r8153b_power_cut_en(struct r8152 *tp, bool enable) in r8153b_power_cut_en() argument
3936 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_POWER_CUT); in r8153b_power_cut_en()
3941 ocp_write_word(tp, MCU_TYPE_USB, USB_POWER_CUT, ocp_data); in r8153b_power_cut_en()
3943 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0); in r8153b_power_cut_en()
3945 ocp_write_word(tp, MCU_TYPE_USB, USB_MISC_0, ocp_data); in r8153b_power_cut_en()
3948 static void r8153_queue_wake(struct r8152 *tp, bool enable) in r8153_queue_wake() argument
3952 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_INDICATE_FALG); in r8153_queue_wake()
3957 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_INDICATE_FALG, ocp_data); in r8153_queue_wake()
3959 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_SUSPEND_FLAG); in r8153_queue_wake()
3961 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_SUSPEND_FLAG, ocp_data); in r8153_queue_wake()
3963 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS); in r8153_queue_wake()
3965 ocp_write_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS, ocp_data); in r8153_queue_wake()
3968 static bool rtl_can_wakeup(struct r8152 *tp) in rtl_can_wakeup() argument
3970 struct usb_device *udev = tp->udev; in rtl_can_wakeup()
3975 static void rtl_runtime_suspend_enable(struct r8152 *tp, bool enable) in rtl_runtime_suspend_enable() argument
3980 __rtl_set_wol(tp, WAKE_ANY); in rtl_runtime_suspend_enable()
3982 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_CONFIG); in rtl_runtime_suspend_enable()
3984 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CONFIG34); in rtl_runtime_suspend_enable()
3986 ocp_write_word(tp, MCU_TYPE_PLA, PLA_CONFIG34, ocp_data); in rtl_runtime_suspend_enable()
3988 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML); in rtl_runtime_suspend_enable()
3992 __rtl_set_wol(tp, tp->saved_wolopts); in rtl_runtime_suspend_enable()
3994 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_CONFIG); in rtl_runtime_suspend_enable()
3996 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CONFIG34); in rtl_runtime_suspend_enable()
3998 ocp_write_word(tp, MCU_TYPE_PLA, PLA_CONFIG34, ocp_data); in rtl_runtime_suspend_enable()
4000 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML); in rtl_runtime_suspend_enable()
4004 static void rtl8153_runtime_enable(struct r8152 *tp, bool enable) in rtl8153_runtime_enable() argument
4007 r8153_u1u2en(tp, false); in rtl8153_runtime_enable()
4008 r8153_u2p3en(tp, false); in rtl8153_runtime_enable()
4009 rtl_runtime_suspend_enable(tp, true); in rtl8153_runtime_enable()
4011 rtl_runtime_suspend_enable(tp, false); in rtl8153_runtime_enable()
4013 switch (tp->version) { in rtl8153_runtime_enable()
4020 r8153_u2p3en(tp, true); in rtl8153_runtime_enable()
4024 r8153_u1u2en(tp, true); in rtl8153_runtime_enable()
4028 static void rtl8153b_runtime_enable(struct r8152 *tp, bool enable) in rtl8153b_runtime_enable() argument
4031 r8153_queue_wake(tp, true); in rtl8153b_runtime_enable()
4032 r8153b_u1u2en(tp, false); in rtl8153b_runtime_enable()
4033 r8153_u2p3en(tp, false); in rtl8153b_runtime_enable()
4034 rtl_runtime_suspend_enable(tp, true); in rtl8153b_runtime_enable()
4035 r8153b_ups_en(tp, true); in rtl8153b_runtime_enable()
4037 r8153b_ups_en(tp, false); in rtl8153b_runtime_enable()
4038 r8153_queue_wake(tp, false); in rtl8153b_runtime_enable()
4039 rtl_runtime_suspend_enable(tp, false); in rtl8153b_runtime_enable()
4040 if (tp->udev->speed >= USB_SPEED_SUPER) in rtl8153b_runtime_enable()
4041 r8153b_u1u2en(tp, true); in rtl8153b_runtime_enable()
4045 static void rtl8153c_runtime_enable(struct r8152 *tp, bool enable) in rtl8153c_runtime_enable() argument
4048 r8153_queue_wake(tp, true); in rtl8153c_runtime_enable()
4049 r8153b_u1u2en(tp, false); in rtl8153c_runtime_enable()
4050 r8153_u2p3en(tp, false); in rtl8153c_runtime_enable()
4051 rtl_runtime_suspend_enable(tp, true); in rtl8153c_runtime_enable()
4052 r8153c_ups_en(tp, true); in rtl8153c_runtime_enable()
4054 r8153c_ups_en(tp, false); in rtl8153c_runtime_enable()
4055 r8153_queue_wake(tp, false); in rtl8153c_runtime_enable()
4056 rtl_runtime_suspend_enable(tp, false); in rtl8153c_runtime_enable()
4057 r8153b_u1u2en(tp, true); in rtl8153c_runtime_enable()
4061 static void rtl8156_runtime_enable(struct r8152 *tp, bool enable) in rtl8156_runtime_enable() argument
4064 r8153_queue_wake(tp, true); in rtl8156_runtime_enable()
4065 r8153b_u1u2en(tp, false); in rtl8156_runtime_enable()
4066 r8153_u2p3en(tp, false); in rtl8156_runtime_enable()
4067 rtl_runtime_suspend_enable(tp, true); in rtl8156_runtime_enable()
4069 r8153_queue_wake(tp, false); in rtl8156_runtime_enable()
4070 rtl_runtime_suspend_enable(tp, false); in rtl8156_runtime_enable()
4071 r8153_u2p3en(tp, true); in rtl8156_runtime_enable()
4072 if (tp->udev->speed >= USB_SPEED_SUPER) in rtl8156_runtime_enable()
4073 r8153b_u1u2en(tp, true); in rtl8156_runtime_enable()
4077 static void r8153_teredo_off(struct r8152 *tp) in r8153_teredo_off() argument
4081 switch (tp->version) { in r8153_teredo_off()
4089 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG); in r8153_teredo_off()
4092 ocp_write_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG, ocp_data); in r8153_teredo_off()
4108 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG, 0xff); in r8153_teredo_off()
4112 ocp_write_word(tp, MCU_TYPE_PLA, PLA_WDT6_CTRL, WDT6_SET_MODE); in r8153_teredo_off()
4113 ocp_write_word(tp, MCU_TYPE_PLA, PLA_REALWOW_TIMER, 0); in r8153_teredo_off()
4114 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_TEREDO_TIMER, 0); in r8153_teredo_off()
4117 static void rtl_reset_bmu(struct r8152 *tp) in rtl_reset_bmu() argument
4121 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_BMU_RESET); in rtl_reset_bmu()
4123 ocp_write_byte(tp, MCU_TYPE_USB, USB_BMU_RESET, ocp_data); in rtl_reset_bmu()
4125 ocp_write_byte(tp, MCU_TYPE_USB, USB_BMU_RESET, ocp_data); in rtl_reset_bmu()
4129 static void rtl_clear_bp(struct r8152 *tp, u16 type) in rtl_clear_bp() argument
4134 switch (tp->version) { in rtl_clear_bp()
4143 ocp_write_word(tp, MCU_TYPE_USB, USB_BP2_EN, 0); in rtl_clear_bp()
4152 ocp_write_byte(tp, type, PLA_BP_EN, 0); in rtl_clear_bp()
4161 ocp_write_word(tp, type, USB_BP2_EN, 0); in rtl_clear_bp()
4166 generic_ocp_write(tp, PLA_BP_0, BYTE_EN_DWORD, bp_num << 1, bp, type); in rtl_clear_bp()
4170 ocp_write_word(tp, type, PLA_BP_BA, 0); in rtl_clear_bp()
4173 static inline void rtl_reset_ocp_base(struct r8152 *tp) in rtl_reset_ocp_base() argument
4175 tp->ocp_base = -1; in rtl_reset_ocp_base()
4178 static int rtl_phy_patch_request(struct r8152 *tp, bool request, bool wait) in rtl_phy_patch_request() argument
4183 data = ocp_reg_read(tp, OCP_PHY_PATCH_CMD); in rtl_phy_patch_request()
4191 ocp_reg_write(tp, OCP_PHY_PATCH_CMD, data); in rtl_phy_patch_request()
4196 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl_phy_patch_request()
4200 ocp_data = ocp_reg_read(tp, OCP_PHY_PATCH_STAT); in rtl_phy_patch_request()
4206 !(ocp_reg_read(tp, OCP_PHY_PATCH_STAT) & PATCH_READY)) { in rtl_phy_patch_request()
4207 dev_err(&tp->intf->dev, "PHY patch request fail\n"); in rtl_phy_patch_request()
4208 rtl_phy_patch_request(tp, false, false); in rtl_phy_patch_request()
4215 static void rtl_patch_key_set(struct r8152 *tp, u16 key_addr, u16 patch_key) in rtl_patch_key_set() argument
4218 sram_write(tp, key_addr, patch_key); in rtl_patch_key_set()
4219 sram_write(tp, SRAM_PHY_LOCK, PHY_PATCH_LOCK); in rtl_patch_key_set()
4223 sram_write(tp, 0x0000, 0x0000); in rtl_patch_key_set()
4225 data = ocp_reg_read(tp, OCP_PHY_LOCK); in rtl_patch_key_set()
4227 ocp_reg_write(tp, OCP_PHY_LOCK, data); in rtl_patch_key_set()
4229 sram_write(tp, key_addr, 0x0000); in rtl_patch_key_set()
4236 rtl_pre_ram_code(struct r8152 *tp, u16 key_addr, u16 patch_key, bool wait) in rtl_pre_ram_code() argument
4238 if (rtl_phy_patch_request(tp, true, wait)) in rtl_pre_ram_code()
4241 rtl_patch_key_set(tp, key_addr, patch_key); in rtl_pre_ram_code()
4246 static int rtl_post_ram_code(struct r8152 *tp, u16 key_addr, bool wait) in rtl_post_ram_code() argument
4248 rtl_patch_key_set(tp, key_addr, 0); in rtl_post_ram_code()
4250 rtl_phy_patch_request(tp, false, wait); in rtl_post_ram_code()
4255 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
4261 switch (tp->version) { in rtl8152_is_fw_phy_speed_up_ok()
4285 dev_err(&tp->intf->dev, "invalid fw_offset\n"); in rtl8152_is_fw_phy_speed_up_ok()
4291 dev_err(&tp->intf->dev, "invalid block length\n"); in rtl8152_is_fw_phy_speed_up_ok()
4296 dev_err(&tp->intf->dev, "invalid register to load firmware\n"); in rtl8152_is_fw_phy_speed_up_ok()
4305 static bool rtl8152_is_fw_phy_ver_ok(struct r8152 *tp, struct fw_phy_ver *ver) in rtl8152_is_fw_phy_ver_ok() argument
4309 switch (tp->version) { in rtl8152_is_fw_phy_ver_ok()
4321 dev_err(&tp->intf->dev, "invalid block length\n"); in rtl8152_is_fw_phy_ver_ok()
4326 dev_err(&tp->intf->dev, "invalid phy ver addr\n"); in rtl8152_is_fw_phy_ver_ok()
4335 static bool rtl8152_is_fw_phy_fixup_ok(struct r8152 *tp, struct fw_phy_fixup *fix) in rtl8152_is_fw_phy_fixup_ok() argument
4339 switch (tp->version) { in rtl8152_is_fw_phy_fixup_ok()
4351 dev_err(&tp->intf->dev, "invalid block length\n"); in rtl8152_is_fw_phy_fixup_ok()
4357 dev_err(&tp->intf->dev, "invalid phy fixup\n"); in rtl8152_is_fw_phy_fixup_ok()
4366 static bool rtl8152_is_fw_phy_union_ok(struct r8152 *tp, struct fw_phy_union *phy) in rtl8152_is_fw_phy_union_ok() argument
4372 switch (tp->version) { in rtl8152_is_fw_phy_union_ok()
4386 dev_err(&tp->intf->dev, "invalid fw_offset\n"); in rtl8152_is_fw_phy_union_ok()
4392 dev_err(&tp->intf->dev, "invalid block length\n"); in rtl8152_is_fw_phy_union_ok()
4397 dev_err(&tp->intf->dev, "invalid pre_num %d\n", phy->pre_num); in rtl8152_is_fw_phy_union_ok()
4402 dev_err(&tp->intf->dev, "invalid bp_num %d\n", phy->bp_num); in rtl8152_is_fw_phy_union_ok()
4411 static bool rtl8152_is_fw_phy_nc_ok(struct r8152 *tp, struct fw_phy_nc *phy) in rtl8152_is_fw_phy_nc_ok() argument
4417 switch (tp->version) { in rtl8152_is_fw_phy_nc_ok()
4433 dev_err(&tp->intf->dev, "fw_offset too small\n"); in rtl8152_is_fw_phy_nc_ok()
4439 dev_err(&tp->intf->dev, "invalid fw_offset\n"); in rtl8152_is_fw_phy_nc_ok()
4445 dev_err(&tp->intf->dev, "invalid block length\n"); in rtl8152_is_fw_phy_nc_ok()
4450 dev_err(&tp->intf->dev, "invalid register to load firmware\n"); in rtl8152_is_fw_phy_nc_ok()
4455 dev_err(&tp->intf->dev, "invalid base address register\n"); in rtl8152_is_fw_phy_nc_ok()
4460 dev_err(&tp->intf->dev, in rtl8152_is_fw_phy_nc_ok()
4466 dev_err(&tp->intf->dev, in rtl8152_is_fw_phy_nc_ok()
4472 dev_err(&tp->intf->dev, in rtl8152_is_fw_phy_nc_ok()
4478 dev_err(&tp->intf->dev, "invalid break point number\n"); in rtl8152_is_fw_phy_nc_ok()
4487 static bool rtl8152_is_fw_mac_ok(struct r8152 *tp, struct fw_mac *mac) in rtl8152_is_fw_mac_ok() argument
4496 switch (tp->version) { in rtl8152_is_fw_mac_ok()
4533 switch (tp->version) { in rtl8152_is_fw_mac_ok()
4569 dev_err(&tp->intf->dev, "fw_offset too small\n"); in rtl8152_is_fw_mac_ok()
4575 dev_err(&tp->intf->dev, "invalid fw_offset\n"); in rtl8152_is_fw_mac_ok()
4581 dev_err(&tp->intf->dev, "invalid block length\n"); in rtl8152_is_fw_mac_ok()
4586 dev_err(&tp->intf->dev, "invalid register to load firmware\n"); in rtl8152_is_fw_mac_ok()
4591 dev_err(&tp->intf->dev, "invalid base address register\n"); in rtl8152_is_fw_mac_ok()
4596 dev_err(&tp->intf->dev, "invalid enabled mask register\n"); in rtl8152_is_fw_mac_ok()
4601 dev_err(&tp->intf->dev, in rtl8152_is_fw_mac_ok()
4607 dev_err(&tp->intf->dev, "invalid break point number\n"); in rtl8152_is_fw_mac_ok()
4613 dev_err(&tp->intf->dev, "unused bp%u is not zero\n", i); in rtl8152_is_fw_mac_ok()
4627 static long rtl8152_fw_verify_checksum(struct r8152 *tp, in rtl8152_fw_verify_checksum() argument
4644 dev_err(&tp->intf->dev, "digestsize incorrect (%u)\n", in rtl8152_fw_verify_checksum()
4664 dev_err(&tp->intf->dev, "checksum fail\n"); in rtl8152_fw_verify_checksum()
4674 static long rtl8152_check_firmware(struct r8152 *tp, struct rtl_fw *rtl_fw) in rtl8152_check_firmware() argument
4683 dev_err(&tp->intf->dev, "file too small\n"); in rtl8152_check_firmware()
4687 ret = rtl8152_fw_verify_checksum(tp, fw_hdr, fw->size); in rtl8152_check_firmware()
4708 dev_err(&tp->intf->dev, in rtl8152_check_firmware()
4713 if (!rtl8152_is_fw_mac_ok(tp, (struct fw_mac *)block)) { in rtl8152_check_firmware()
4714 dev_err(&tp->intf->dev, in rtl8152_check_firmware()
4722 dev_err(&tp->intf->dev, in rtl8152_check_firmware()
4727 if (!rtl8152_is_fw_mac_ok(tp, (struct fw_mac *)block)) { in rtl8152_check_firmware()
4728 dev_err(&tp->intf->dev, in rtl8152_check_firmware()
4742 dev_err(&tp->intf->dev, in rtl8152_check_firmware()
4748 dev_err(&tp->intf->dev, in rtl8152_check_firmware()
4757 dev_err(&tp->intf->dev, in rtl8152_check_firmware()
4763 dev_err(&tp->intf->dev, in rtl8152_check_firmware()
4772 dev_err(&tp->intf->dev, in rtl8152_check_firmware()
4778 dev_err(&tp->intf->dev, in rtl8152_check_firmware()
4783 if (!rtl8152_is_fw_phy_nc_ok(tp, (struct fw_phy_nc *)block)) { in rtl8152_check_firmware()
4784 dev_err(&tp->intf->dev, in rtl8152_check_firmware()
4797 dev_err(&tp->intf->dev, "PHY_UNION_NC out of order\n"); in rtl8152_check_firmware()
4802 dev_err(&tp->intf->dev, "multiple PHY_UNION_NC encountered\n"); in rtl8152_check_firmware()
4806 if (!rtl8152_is_fw_phy_union_ok(tp, (struct fw_phy_union *)block)) { in rtl8152_check_firmware()
4807 dev_err(&tp->intf->dev, "check PHY_UNION_NC failed\n"); in rtl8152_check_firmware()
4818 dev_err(&tp->intf->dev, "PHY_UNION_NC1 out of order\n"); in rtl8152_check_firmware()
4823 dev_err(&tp->intf->dev, "multiple PHY NC1 encountered\n"); in rtl8152_check_firmware()
4827 if (!rtl8152_is_fw_phy_union_ok(tp, (struct fw_phy_union *)block)) { in rtl8152_check_firmware()
4828 dev_err(&tp->intf->dev, "check PHY_UNION_NC1 failed\n"); in rtl8152_check_firmware()
4838 dev_err(&tp->intf->dev, "PHY_UNION_NC2 out of order\n"); in rtl8152_check_firmware()
4843 dev_err(&tp->intf->dev, "multiple PHY NC2 encountered\n"); in rtl8152_check_firmware()
4847 if (!rtl8152_is_fw_phy_union_ok(tp, (struct fw_phy_union *)block)) { in rtl8152_check_firmware()
4848 dev_err(&tp->intf->dev, "check PHY_UNION_NC2 failed\n"); in rtl8152_check_firmware()
4857 dev_err(&tp->intf->dev, "PHY_UNION_UC2 out of order\n"); in rtl8152_check_firmware()
4862 dev_err(&tp->intf->dev, "multiple PHY UC2 encountered\n"); in rtl8152_check_firmware()
4866 if (!rtl8152_is_fw_phy_union_ok(tp, (struct fw_phy_union *)block)) { in rtl8152_check_firmware()
4867 dev_err(&tp->intf->dev, "check PHY_UNION_UC2 failed\n"); in rtl8152_check_firmware()
4875 dev_err(&tp->intf->dev, "PHY_UNION_UC out of order\n"); in rtl8152_check_firmware()
4880 dev_err(&tp->intf->dev, "multiple PHY UC encountered\n"); in rtl8152_check_firmware()
4884 if (!rtl8152_is_fw_phy_union_ok(tp, (struct fw_phy_union *)block)) { in rtl8152_check_firmware()
4885 dev_err(&tp->intf->dev, "check PHY_UNION_UC failed\n"); in rtl8152_check_firmware()
4891 if (!rtl8152_is_fw_phy_union_ok(tp, (struct fw_phy_union *)block)) { in rtl8152_check_firmware()
4892 dev_err(&tp->intf->dev, "check RTL_FW_PHY_UNION_MISC failed\n"); in rtl8152_check_firmware()
4897 if (!rtl8152_is_fw_phy_fixup_ok(tp, (struct fw_phy_fixup *)block)) { in rtl8152_check_firmware()
4898 dev_err(&tp->intf->dev, "check PHY fixup failed\n"); in rtl8152_check_firmware()
4904 dev_err(&tp->intf->dev, "multiple PHY firmware encountered"); in rtl8152_check_firmware()
4908 if (!rtl8152_is_fw_phy_speed_up_ok(tp, (struct fw_phy_speed_up *)block)) { in rtl8152_check_firmware()
4909 dev_err(&tp->intf->dev, "check PHY speed up failed\n"); in rtl8152_check_firmware()
4922 dev_err(&tp->intf->dev, "Invalid order to set PHY version\n"); in rtl8152_check_firmware()
4927 dev_err(&tp->intf->dev, "multiple PHY version encountered"); in rtl8152_check_firmware()
4931 if (!rtl8152_is_fw_phy_ver_ok(tp, (struct fw_phy_ver *)block)) { in rtl8152_check_firmware()
4932 dev_err(&tp->intf->dev, "check PHY version failed\n"); in rtl8152_check_firmware()
4938 dev_warn(&tp->intf->dev, "Unknown type %u is found\n", in rtl8152_check_firmware()
4949 dev_err(&tp->intf->dev, "without PHY_STOP\n"); in rtl8152_check_firmware()
4958 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
4963 rtl_reset_ocp_base(tp); in rtl_ram_code_speed_up()
4965 if (sram_read(tp, SRAM_GPHY_FW_VER) >= __le16_to_cpu(phy->version)) { in rtl_ram_code_speed_up()
4966 dev_dbg(&tp->intf->dev, "PHY firmware has been the newest\n"); in rtl_ram_code_speed_up()
4974 if (rtl_phy_patch_request(tp, true, wait)) in rtl_ram_code_speed_up()
4986 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_GPHY_CTRL); in rtl_ram_code_speed_up()
4988 ocp_write_word(tp, MCU_TYPE_USB, USB_GPHY_CTRL, ocp_data); in rtl_ram_code_speed_up()
4990 generic_ocp_write(tp, __le16_to_cpu(phy->fw_reg), 0xff, size, data, MCU_TYPE_USB); in rtl_ram_code_speed_up()
4995 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_POL_GPIO_CTRL); in rtl_ram_code_speed_up()
4997 ocp_write_word(tp, MCU_TYPE_PLA, PLA_POL_GPIO_CTRL, ocp_data); in rtl_ram_code_speed_up()
5000 if (!(ocp_read_word(tp, MCU_TYPE_PLA, PLA_POL_GPIO_CTRL) & POL_GPHY_PATCH)) in rtl_ram_code_speed_up()
5005 dev_err(&tp->intf->dev, "ram code speedup mode timeout\n"); in rtl_ram_code_speed_up()
5010 rtl_reset_ocp_base(tp); in rtl_ram_code_speed_up()
5012 rtl_phy_patch_request(tp, false, wait); in rtl_ram_code_speed_up()
5014 if (sram_read(tp, SRAM_GPHY_FW_VER) == __le16_to_cpu(phy->version)) in rtl_ram_code_speed_up()
5015 dev_dbg(&tp->intf->dev, "successfully applied %s\n", phy->info); in rtl_ram_code_speed_up()
5017 dev_err(&tp->intf->dev, "ram code speedup mode fail\n"); in rtl_ram_code_speed_up()
5020 static int rtl8152_fw_phy_ver(struct r8152 *tp, struct fw_phy_ver *phy_ver) in rtl8152_fw_phy_ver() argument
5027 rtl_reset_ocp_base(tp); in rtl8152_fw_phy_ver()
5029 if (sram_read(tp, ver_addr) >= ver) { in rtl8152_fw_phy_ver()
5030 dev_dbg(&tp->intf->dev, "PHY firmware has been the newest\n"); in rtl8152_fw_phy_ver()
5034 sram_write(tp, ver_addr, ver); in rtl8152_fw_phy_ver()
5036 dev_dbg(&tp->intf->dev, "PHY firmware version %x\n", ver); in rtl8152_fw_phy_ver()
5041 static void rtl8152_fw_phy_fixup(struct r8152 *tp, struct fw_phy_fixup *fix) in rtl8152_fw_phy_fixup() argument
5045 rtl_reset_ocp_base(tp); in rtl8152_fw_phy_fixup()
5048 data = ocp_reg_read(tp, addr); in rtl8152_fw_phy_fixup()
5067 ocp_reg_write(tp, addr, data); in rtl8152_fw_phy_fixup()
5069 dev_dbg(&tp->intf->dev, "applied ocp %x %x\n", addr, data); in rtl8152_fw_phy_fixup()
5072 static void rtl8152_fw_phy_union_apply(struct r8152 *tp, struct fw_phy_union *phy) in rtl8152_fw_phy_union_apply() argument
5078 rtl_reset_ocp_base(tp); in rtl8152_fw_phy_union_apply()
5082 sram_write(tp, __le16_to_cpu(phy->pre_set[i].addr), in rtl8152_fw_phy_union_apply()
5090 ocp_reg_write(tp, OCP_SRAM_ADDR, __le16_to_cpu(phy->fw_reg)); in rtl8152_fw_phy_union_apply()
5092 ocp_reg_write(tp, OCP_SRAM_DATA, __le16_to_cpu(data[i])); in rtl8152_fw_phy_union_apply()
5096 sram_write(tp, __le16_to_cpu(phy->bp[i].addr), __le16_to_cpu(phy->bp[i].data)); in rtl8152_fw_phy_union_apply()
5099 sram_write(tp, __le16_to_cpu(phy->bp_en.addr), __le16_to_cpu(phy->bp_en.data)); in rtl8152_fw_phy_union_apply()
5101 dev_dbg(&tp->intf->dev, "successfully applied %s\n", phy->info); in rtl8152_fw_phy_union_apply()
5104 static void rtl8152_fw_phy_nc_apply(struct r8152 *tp, struct fw_phy_nc *phy) in rtl8152_fw_phy_nc_apply() argument
5110 rtl_reset_ocp_base(tp); in rtl8152_fw_phy_nc_apply()
5113 sram_write(tp, mode_reg, __le16_to_cpu(phy->mode_pre)); in rtl8152_fw_phy_nc_apply()
5114 sram_write(tp, __le16_to_cpu(phy->ba_reg), in rtl8152_fw_phy_nc_apply()
5122 ocp_reg_write(tp, OCP_SRAM_ADDR, __le16_to_cpu(phy->fw_reg)); in rtl8152_fw_phy_nc_apply()
5124 ocp_reg_write(tp, OCP_SRAM_DATA, __le16_to_cpu(data[i])); in rtl8152_fw_phy_nc_apply()
5126 sram_write(tp, __le16_to_cpu(phy->patch_en_addr), in rtl8152_fw_phy_nc_apply()
5132 sram_write(tp, bp_index, __le16_to_cpu(phy->bp[i])); in rtl8152_fw_phy_nc_apply()
5136 sram_write(tp, mode_reg, __le16_to_cpu(phy->mode_post)); in rtl8152_fw_phy_nc_apply()
5138 dev_dbg(&tp->intf->dev, "successfully applied %s\n", phy->info); in rtl8152_fw_phy_nc_apply()
5141 static void rtl8152_fw_mac_apply(struct r8152 *tp, struct fw_mac *mac) in rtl8152_fw_mac_apply() argument
5159 if (fw_ver_reg && ocp_read_byte(tp, MCU_TYPE_USB, fw_ver_reg) >= mac->fw_ver_data) { in rtl8152_fw_mac_apply()
5160 dev_dbg(&tp->intf->dev, "%s firmware has been the newest\n", type ? "PLA" : "USB"); in rtl8152_fw_mac_apply()
5164 rtl_clear_bp(tp, type); in rtl8152_fw_mac_apply()
5169 if (tp->version == RTL_VER_04 && type == MCU_TYPE_PLA && in rtl8152_fw_mac_apply()
5170 !(ocp_read_word(tp, MCU_TYPE_PLA, PLA_MACDBG_POST) & DEBUG_OE)) { in rtl8152_fw_mac_apply()
5171 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MACDBG_PRE, DEBUG_LTSSM); in rtl8152_fw_mac_apply()
5172 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MACDBG_POST, DEBUG_LTSSM); in rtl8152_fw_mac_apply()
5181 if (generic_ocp_write(tp, __le16_to_cpu(mac->fw_reg), 0xff, length, in rtl8152_fw_mac_apply()
5183 dev_err(&tp->intf->dev, "Write %s fw fail\n", in rtl8152_fw_mac_apply()
5188 ocp_write_word(tp, type, __le16_to_cpu(mac->bp_ba_addr), in rtl8152_fw_mac_apply()
5191 if (generic_ocp_write(tp, __le16_to_cpu(mac->bp_start), BYTE_EN_DWORD, in rtl8152_fw_mac_apply()
5194 dev_err(&tp->intf->dev, "Write %s bp fail\n", in rtl8152_fw_mac_apply()
5201 ocp_write_word(tp, type, bp_en_addr, in rtl8152_fw_mac_apply()
5205 ocp_write_byte(tp, MCU_TYPE_USB, fw_ver_reg, in rtl8152_fw_mac_apply()
5208 dev_dbg(&tp->intf->dev, "successfully applied %s\n", mac->info); in rtl8152_fw_mac_apply()
5211 static void rtl8152_apply_firmware(struct r8152 *tp, bool power_cut) in rtl8152_apply_firmware() argument
5213 struct rtl_fw *rtl_fw = &tp->rtl_fw; in rtl8152_apply_firmware()
5227 rtl_fw->pre_fw(tp); in rtl8152_apply_firmware()
5237 rtl8152_fw_mac_apply(tp, (struct fw_mac *)block); in rtl8152_apply_firmware()
5244 rtl_pre_ram_code(tp, key_addr, __le16_to_cpu(key->key_data), !power_cut); in rtl8152_apply_firmware()
5250 rtl_post_ram_code(tp, key_addr, !power_cut); in rtl8152_apply_firmware()
5253 rtl8152_fw_phy_nc_apply(tp, (struct fw_phy_nc *)block); in rtl8152_apply_firmware()
5256 patch_phy = rtl8152_fw_phy_ver(tp, (struct fw_phy_ver *)block); in rtl8152_apply_firmware()
5265 rtl8152_fw_phy_union_apply(tp, (struct fw_phy_union *)block); in rtl8152_apply_firmware()
5269 rtl8152_fw_phy_fixup(tp, (struct fw_phy_fixup *)block); in rtl8152_apply_firmware()
5272 rtl_ram_code_speed_up(tp, (struct fw_phy_speed_up *)block, !power_cut); in rtl8152_apply_firmware()
5283 rtl_fw->post_fw(tp); in rtl8152_apply_firmware()
5285 rtl_reset_ocp_base(tp); in rtl8152_apply_firmware()
5287 dev_dbg(&tp->intf->dev, "load %s successfully\n", rtl_fw->version); in rtl8152_apply_firmware()
5290 static void rtl8152_release_firmware(struct r8152 *tp) in rtl8152_release_firmware() argument
5292 struct rtl_fw *rtl_fw = &tp->rtl_fw; in rtl8152_release_firmware()
5300 static int rtl8152_request_firmware(struct r8152 *tp) in rtl8152_request_firmware() argument
5302 struct rtl_fw *rtl_fw = &tp->rtl_fw; in rtl8152_request_firmware()
5306 dev_info(&tp->intf->dev, "skip request firmware\n"); in rtl8152_request_firmware()
5311 rc = request_firmware(&rtl_fw->fw, rtl_fw->fw_name, &tp->intf->dev); in rtl8152_request_firmware()
5315 rc = rtl8152_check_firmware(tp, rtl_fw); in rtl8152_request_firmware()
5323 dev_warn(&tp->intf->dev, in rtl8152_request_firmware()
5331 static void r8152_aldps_en(struct r8152 *tp, bool enable) in r8152_aldps_en() argument
5334 ocp_reg_write(tp, OCP_ALDPS_CONFIG, ENPWRSAVE | ENPDNPS | in r8152_aldps_en()
5337 ocp_reg_write(tp, OCP_ALDPS_CONFIG, ENPDNPS | LINKENA | in r8152_aldps_en()
5343 static inline void r8152_mmd_indirect(struct r8152 *tp, u16 dev, u16 reg) in r8152_mmd_indirect() argument
5345 ocp_reg_write(tp, OCP_EEE_AR, FUN_ADDR | dev); in r8152_mmd_indirect()
5346 ocp_reg_write(tp, OCP_EEE_DATA, reg); in r8152_mmd_indirect()
5347 ocp_reg_write(tp, OCP_EEE_AR, FUN_DATA | dev); in r8152_mmd_indirect()
5350 static u16 r8152_mmd_read(struct r8152 *tp, u16 dev, u16 reg) in r8152_mmd_read() argument
5354 r8152_mmd_indirect(tp, dev, reg); in r8152_mmd_read()
5355 data = ocp_reg_read(tp, OCP_EEE_DATA); in r8152_mmd_read()
5356 ocp_reg_write(tp, OCP_EEE_AR, 0x0000); in r8152_mmd_read()
5361 static void r8152_mmd_write(struct r8152 *tp, u16 dev, u16 reg, u16 data) in r8152_mmd_write() argument
5363 r8152_mmd_indirect(tp, dev, reg); in r8152_mmd_write()
5364 ocp_reg_write(tp, OCP_EEE_DATA, data); in r8152_mmd_write()
5365 ocp_reg_write(tp, OCP_EEE_AR, 0x0000); in r8152_mmd_write()
5368 static void r8152_eee_en(struct r8152 *tp, bool enable) in r8152_eee_en() argument
5373 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EEE_CR); in r8152_eee_en()
5374 config1 = ocp_reg_read(tp, OCP_EEE_CONFIG1) & ~sd_rise_time_mask; in r8152_eee_en()
5375 config2 = ocp_reg_read(tp, OCP_EEE_CONFIG2); in r8152_eee_en()
5376 config3 = ocp_reg_read(tp, OCP_EEE_CONFIG3) & ~fast_snr_mask; in r8152_eee_en()
5393 ocp_write_word(tp, MCU_TYPE_PLA, PLA_EEE_CR, ocp_data); in r8152_eee_en()
5394 ocp_reg_write(tp, OCP_EEE_CONFIG1, config1); in r8152_eee_en()
5395 ocp_reg_write(tp, OCP_EEE_CONFIG2, config2); in r8152_eee_en()
5396 ocp_reg_write(tp, OCP_EEE_CONFIG3, config3); in r8152_eee_en()
5399 static void r8153_eee_en(struct r8152 *tp, bool enable) in r8153_eee_en() argument
5404 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EEE_CR); in r8153_eee_en()
5405 config = ocp_reg_read(tp, OCP_EEE_CFG); in r8153_eee_en()
5415 ocp_write_word(tp, MCU_TYPE_PLA, PLA_EEE_CR, ocp_data); in r8153_eee_en()
5416 ocp_reg_write(tp, OCP_EEE_CFG, config); in r8153_eee_en()
5418 tp->ups_info.eee = enable; in r8153_eee_en()
5421 static void r8156_eee_en(struct r8152 *tp, bool enable) in r8156_eee_en() argument
5425 r8153_eee_en(tp, enable); in r8156_eee_en()
5427 config = ocp_reg_read(tp, OCP_EEE_ADV2); in r8156_eee_en()
5434 ocp_reg_write(tp, OCP_EEE_ADV2, config); in r8156_eee_en()
5437 static void rtl_eee_enable(struct r8152 *tp, bool enable) in rtl_eee_enable() argument
5439 switch (tp->version) { in rtl_eee_enable()
5444 r8152_eee_en(tp, true); in rtl_eee_enable()
5445 r8152_mmd_write(tp, MDIO_MMD_AN, MDIO_AN_EEE_ADV, in rtl_eee_enable()
5446 tp->eee_adv); in rtl_eee_enable()
5448 r8152_eee_en(tp, false); in rtl_eee_enable()
5449 r8152_mmd_write(tp, MDIO_MMD_AN, MDIO_AN_EEE_ADV, 0); in rtl_eee_enable()
5460 r8153_eee_en(tp, true); in rtl_eee_enable()
5461 ocp_reg_write(tp, OCP_EEE_ADV, tp->eee_adv); in rtl_eee_enable()
5463 r8153_eee_en(tp, false); in rtl_eee_enable()
5464 ocp_reg_write(tp, OCP_EEE_ADV, 0); in rtl_eee_enable()
5473 r8156_eee_en(tp, true); in rtl_eee_enable()
5474 ocp_reg_write(tp, OCP_EEE_ADV, tp->eee_adv); in rtl_eee_enable()
5476 r8156_eee_en(tp, false); in rtl_eee_enable()
5477 ocp_reg_write(tp, OCP_EEE_ADV, 0); in rtl_eee_enable()
5485 static void r8152b_enable_fc(struct r8152 *tp) in r8152b_enable_fc() argument
5489 anar = r8152_mdio_read(tp, MII_ADVERTISE); in r8152b_enable_fc()
5491 r8152_mdio_write(tp, MII_ADVERTISE, anar); in r8152b_enable_fc()
5493 tp->ups_info.flow_control = true; in r8152b_enable_fc()
5496 static void rtl8152_disable(struct r8152 *tp) in rtl8152_disable() argument
5498 r8152_aldps_en(tp, false); in rtl8152_disable()
5499 rtl_disable(tp); in rtl8152_disable()
5500 r8152_aldps_en(tp, true); in rtl8152_disable()
5503 static void r8152b_hw_phy_cfg(struct r8152 *tp) in r8152b_hw_phy_cfg() argument
5505 rtl8152_apply_firmware(tp, false); in r8152b_hw_phy_cfg()
5506 rtl_eee_enable(tp, tp->eee_en); in r8152b_hw_phy_cfg()
5507 r8152_aldps_en(tp, true); in r8152b_hw_phy_cfg()
5508 r8152b_enable_fc(tp); in r8152b_hw_phy_cfg()
5510 set_bit(PHY_RESET, &tp->flags); in r8152b_hw_phy_cfg()
5513 static void wait_oob_link_list_ready(struct r8152 *tp) in wait_oob_link_list_ready() argument
5519 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in wait_oob_link_list_ready()
5521 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); in wait_oob_link_list_ready()
5528 static void r8156b_wait_loading_flash(struct r8152 *tp) in r8156b_wait_loading_flash() argument
5530 if ((ocp_read_word(tp, MCU_TYPE_PLA, PLA_GPHY_CTRL) & GPHY_FLASH) && in r8156b_wait_loading_flash()
5531 !(ocp_read_word(tp, MCU_TYPE_USB, USB_GPHY_CTRL) & BYPASS_FLASH)) { in r8156b_wait_loading_flash()
5535 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8156b_wait_loading_flash()
5537 if (ocp_read_word(tp, MCU_TYPE_USB, USB_GPHY_CTRL) & GPHY_PATCH_DONE) in r8156b_wait_loading_flash()
5544 static void r8152b_exit_oob(struct r8152 *tp) in r8152b_exit_oob() argument
5548 ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); in r8152b_exit_oob()
5550 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); in r8152b_exit_oob()
5552 rxdy_gated_en(tp, true); in r8152b_exit_oob()
5553 r8153_teredo_off(tp); in r8152b_exit_oob()
5554 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML); in r8152b_exit_oob()
5555 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CR, 0x00); in r8152b_exit_oob()
5557 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); in r8152b_exit_oob()
5559 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data); in r8152b_exit_oob()
5561 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7); in r8152b_exit_oob()
5563 ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data); in r8152b_exit_oob()
5565 wait_oob_link_list_ready(tp); in r8152b_exit_oob()
5567 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7); in r8152b_exit_oob()
5569 ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data); in r8152b_exit_oob()
5571 wait_oob_link_list_ready(tp); in r8152b_exit_oob()
5573 rtl8152_nic_reset(tp); in r8152b_exit_oob()
5576 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL0, RXFIFO_THR1_NORMAL); in r8152b_exit_oob()
5578 if (tp->udev->speed == USB_SPEED_FULL || in r8152b_exit_oob()
5579 tp->udev->speed == USB_SPEED_LOW) { in r8152b_exit_oob()
5581 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL1, in r8152b_exit_oob()
5583 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL2, in r8152b_exit_oob()
5587 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL1, in r8152b_exit_oob()
5589 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL2, in r8152b_exit_oob()
5594 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_TXFIFO_CTRL, TXFIFO_THR_NORMAL2); in r8152b_exit_oob()
5596 ocp_write_byte(tp, MCU_TYPE_USB, USB_TX_AGG, TX_AGG_MAX_THRESHOLD); in r8152b_exit_oob()
5597 ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH, RX_THR_HIGH); in r8152b_exit_oob()
5598 ocp_write_dword(tp, MCU_TYPE_USB, USB_TX_DMA, in r8152b_exit_oob()
5601 rtl_rx_vlan_en(tp, tp->netdev->features & NETIF_F_HW_VLAN_CTAG_RX); in r8152b_exit_oob()
5603 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, RTL8152_RMS); in r8152b_exit_oob()
5605 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TCR0); in r8152b_exit_oob()
5607 ocp_write_word(tp, MCU_TYPE_PLA, PLA_TCR0, ocp_data); in r8152b_exit_oob()
5610 static void r8152b_enter_oob(struct r8152 *tp) in r8152b_enter_oob() argument
5614 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); in r8152b_enter_oob()
5616 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data); in r8152b_enter_oob()
5618 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL0, RXFIFO_THR1_OOB); in r8152b_enter_oob()
5619 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL1, RXFIFO_THR2_OOB); in r8152b_enter_oob()
5620 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL2, RXFIFO_THR3_OOB); in r8152b_enter_oob()
5622 rtl_disable(tp); in r8152b_enter_oob()
5624 wait_oob_link_list_ready(tp); in r8152b_enter_oob()
5626 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7); in r8152b_enter_oob()
5628 ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data); in r8152b_enter_oob()
5630 wait_oob_link_list_ready(tp); in r8152b_enter_oob()
5632 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, RTL8152_RMS); in r8152b_enter_oob()
5634 rtl_rx_vlan_en(tp, true); in r8152b_enter_oob()
5636 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_BDC_CR); in r8152b_enter_oob()
5638 ocp_write_word(tp, MCU_TYPE_PLA, PLA_BDC_CR, ocp_data); in r8152b_enter_oob()
5640 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); in r8152b_enter_oob()
5642 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data); in r8152b_enter_oob()
5644 rxdy_gated_en(tp, false); in r8152b_enter_oob()
5646 ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); in r8152b_enter_oob()
5648 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); in r8152b_enter_oob()
5651 static int r8153_pre_firmware_1(struct r8152 *tp) in r8153_pre_firmware_1() argument
5657 u32 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_WDT1_CTRL); in r8153_pre_firmware_1()
5659 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8153_pre_firmware_1()
5669 static int r8153_post_firmware_1(struct r8152 *tp) in r8153_post_firmware_1() argument
5672 if (ocp_read_byte(tp, MCU_TYPE_USB, USB_CSTMR) & FORCE_SUPER) in r8153_post_firmware_1()
5673 ocp_write_word(tp, MCU_TYPE_USB, USB_BP_4, BP4_SUPER_ONLY); in r8153_post_firmware_1()
5676 ocp_write_word(tp, MCU_TYPE_PLA, PLA_UPHY_TIMER, 36000 / 16); in r8153_post_firmware_1()
5681 static int r8153_pre_firmware_2(struct r8152 *tp) in r8153_pre_firmware_2() argument
5685 r8153_pre_firmware_1(tp); in r8153_pre_firmware_2()
5687 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_FIX_EN0); in r8153_pre_firmware_2()
5689 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_FIX_EN0, ocp_data); in r8153_pre_firmware_2()
5694 static int r8153_post_firmware_2(struct r8152 *tp) in r8153_post_firmware_2() argument
5699 if (ocp_read_byte(tp, MCU_TYPE_USB, USB_CSTMR) & FORCE_SUPER) { in r8153_post_firmware_2()
5700 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_BP_EN); in r8153_post_firmware_2()
5702 ocp_write_word(tp, MCU_TYPE_PLA, PLA_BP_EN, ocp_data); in r8153_post_firmware_2()
5706 ocp_write_word(tp, MCU_TYPE_PLA, PLA_UPHY_TIMER, 36000 / 16); in r8153_post_firmware_2()
5709 ocp_write_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS, U3P3_CHECK_EN | 4); in r8153_post_firmware_2()
5711 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_FIX_EN0); in r8153_post_firmware_2()
5713 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_FIX_EN0, ocp_data); in r8153_post_firmware_2()
5715 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_USB2PHY); in r8153_post_firmware_2()
5717 ocp_write_byte(tp, MCU_TYPE_USB, USB_USB2PHY, ocp_data); in r8153_post_firmware_2()
5722 static int r8153_post_firmware_3(struct r8152 *tp) in r8153_post_firmware_3() argument
5726 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_USB2PHY); in r8153_post_firmware_3()
5728 ocp_write_byte(tp, MCU_TYPE_USB, USB_USB2PHY, ocp_data); in r8153_post_firmware_3()
5730 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_FIX_EN1); in r8153_post_firmware_3()
5732 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_FIX_EN1, ocp_data); in r8153_post_firmware_3()
5737 static int r8153b_pre_firmware_1(struct r8152 *tp) in r8153b_pre_firmware_1() argument
5740 ocp_write_word(tp, MCU_TYPE_USB, USB_FC_TIMER, in r8153b_pre_firmware_1()
5746 static int r8153b_post_firmware_1(struct r8152 *tp) in r8153b_post_firmware_1() argument
5751 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_MISC_1); in r8153b_post_firmware_1()
5753 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_BP_EN); in r8153b_post_firmware_1()
5755 ocp_write_word(tp, MCU_TYPE_PLA, PLA_BP_EN, ocp_data); in r8153b_post_firmware_1()
5758 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_CTRL); in r8153b_post_firmware_1()
5760 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_CTRL, ocp_data); in r8153b_post_firmware_1()
5762 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_TASK); in r8153b_post_firmware_1()
5764 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_TASK, ocp_data); in r8153b_post_firmware_1()
5766 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_FIX_EN1); in r8153b_post_firmware_1()
5768 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_FIX_EN1, ocp_data); in r8153b_post_firmware_1()
5773 static int r8153c_post_firmware_1(struct r8152 *tp) in r8153c_post_firmware_1() argument
5777 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_CTRL); in r8153c_post_firmware_1()
5779 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_CTRL, ocp_data); in r8153c_post_firmware_1()
5781 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_TASK); in r8153c_post_firmware_1()
5783 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_TASK, ocp_data); in r8153c_post_firmware_1()
5788 static int r8156a_post_firmware_1(struct r8152 *tp) in r8156a_post_firmware_1() argument
5792 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_FIX_EN1); in r8156a_post_firmware_1()
5794 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_FIX_EN1, ocp_data); in r8156a_post_firmware_1()
5797 ocp_write_dword(tp, MCU_TYPE_USB, USB_UPHY3_MDCMDIO, 0x4026840e); in r8156a_post_firmware_1()
5798 ocp_write_dword(tp, MCU_TYPE_USB, USB_UPHY3_MDCMDIO, 0x4001acc9); in r8156a_post_firmware_1()
5803 static void r8153_aldps_en(struct r8152 *tp, bool enable) in r8153_aldps_en() argument
5807 data = ocp_reg_read(tp, OCP_POWER_CFG); in r8153_aldps_en()
5810 ocp_reg_write(tp, OCP_POWER_CFG, data); in r8153_aldps_en()
5815 ocp_reg_write(tp, OCP_POWER_CFG, data); in r8153_aldps_en()
5817 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8153_aldps_en()
5820 if (ocp_read_word(tp, MCU_TYPE_PLA, 0xe000) & 0x0100) in r8153_aldps_en()
5825 tp->ups_info.aldps = enable; in r8153_aldps_en()
5828 static void r8153_hw_phy_cfg(struct r8152 *tp) in r8153_hw_phy_cfg() argument
5834 r8153_aldps_en(tp, false); in r8153_hw_phy_cfg()
5837 rtl_eee_enable(tp, false); in r8153_hw_phy_cfg()
5839 rtl8152_apply_firmware(tp, false); in r8153_hw_phy_cfg()
5841 if (tp->version == RTL_VER_03) { in r8153_hw_phy_cfg()
5842 data = ocp_reg_read(tp, OCP_EEE_CFG); in r8153_hw_phy_cfg()
5844 ocp_reg_write(tp, OCP_EEE_CFG, data); in r8153_hw_phy_cfg()
5847 data = ocp_reg_read(tp, OCP_POWER_CFG); in r8153_hw_phy_cfg()
5849 ocp_reg_write(tp, OCP_POWER_CFG, data); in r8153_hw_phy_cfg()
5851 data = ocp_reg_read(tp, OCP_DOWN_SPEED); in r8153_hw_phy_cfg()
5853 ocp_reg_write(tp, OCP_DOWN_SPEED, data); in r8153_hw_phy_cfg()
5854 data = ocp_reg_read(tp, OCP_POWER_CFG); in r8153_hw_phy_cfg()
5856 ocp_reg_write(tp, OCP_POWER_CFG, data); in r8153_hw_phy_cfg()
5857 sram_write(tp, SRAM_IMPEDANCE, 0x0b13); in r8153_hw_phy_cfg()
5859 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR); in r8153_hw_phy_cfg()
5861 ocp_write_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR, ocp_data); in r8153_hw_phy_cfg()
5864 sram_write(tp, SRAM_LPF_CFG, 0xf70f); in r8153_hw_phy_cfg()
5867 sram_write(tp, SRAM_10M_AMP1, 0x00af); in r8153_hw_phy_cfg()
5868 sram_write(tp, SRAM_10M_AMP2, 0x0208); in r8153_hw_phy_cfg()
5870 if (tp->eee_en) in r8153_hw_phy_cfg()
5871 rtl_eee_enable(tp, true); in r8153_hw_phy_cfg()
5873 r8153_aldps_en(tp, true); in r8153_hw_phy_cfg()
5874 r8152b_enable_fc(tp); in r8153_hw_phy_cfg()
5876 switch (tp->version) { in r8153_hw_phy_cfg()
5883 r8153_u2p3en(tp, true); in r8153_hw_phy_cfg()
5887 set_bit(PHY_RESET, &tp->flags); in r8153_hw_phy_cfg()
5890 static u32 r8152_efuse_read(struct r8152 *tp, u8 addr) in r8152_efuse_read() argument
5894 ocp_write_word(tp, MCU_TYPE_PLA, PLA_EFUSE_CMD, EFUSE_READ_CMD | addr); in r8152_efuse_read()
5895 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EFUSE_CMD); in r8152_efuse_read()
5897 ocp_data |= ocp_read_word(tp, MCU_TYPE_PLA, PLA_EFUSE_DATA); in r8152_efuse_read()
5902 static void r8153b_hw_phy_cfg(struct r8152 *tp) in r8153b_hw_phy_cfg() argument
5907 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0); in r8153b_hw_phy_cfg()
5910 ocp_write_word(tp, MCU_TYPE_USB, USB_MISC_0, ocp_data); in r8153b_hw_phy_cfg()
5914 r8153_aldps_en(tp, false); in r8153b_hw_phy_cfg()
5917 rtl_eee_enable(tp, false); in r8153b_hw_phy_cfg()
5920 ocp_write_word(tp, MCU_TYPE_USB, USB_U1U2_TIMER, 500); in r8153b_hw_phy_cfg()
5922 data = r8153_phy_status(tp, 0); in r8153b_hw_phy_cfg()
5927 rtl8152_apply_firmware(tp, true); in r8153b_hw_phy_cfg()
5929 data = r8152_mdio_read(tp, MII_BMCR); in r8153b_hw_phy_cfg()
5931 r8152_mdio_write(tp, MII_BMCR, data); in r8153b_hw_phy_cfg()
5935 rtl8152_apply_firmware(tp, false); in r8153b_hw_phy_cfg()
5939 r8153b_green_en(tp, test_bit(GREEN_ETHERNET, &tp->flags)); in r8153b_hw_phy_cfg()
5941 data = sram_read(tp, SRAM_GREEN_CFG); in r8153b_hw_phy_cfg()
5943 sram_write(tp, SRAM_GREEN_CFG, data); in r8153b_hw_phy_cfg()
5944 data = ocp_reg_read(tp, OCP_NCTL_CFG); in r8153b_hw_phy_cfg()
5946 ocp_reg_write(tp, OCP_NCTL_CFG, data); in r8153b_hw_phy_cfg()
5953 ocp_data = r8152_efuse_read(tp, 0x7d); in r8153b_hw_phy_cfg()
5956 ocp_reg_write(tp, OCP_ADC_IOFFSET, data); in r8153b_hw_phy_cfg()
5962 ocp_data = ocp_reg_read(tp, 0xc426); in r8153b_hw_phy_cfg()
5968 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_UPS_CFG); in r8153b_hw_phy_cfg()
5970 ocp_write_word(tp, MCU_TYPE_USB, USB_UPS_CFG, ocp_data); in r8153b_hw_phy_cfg()
5973 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR); in r8153b_hw_phy_cfg()
5975 ocp_write_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR, ocp_data); in r8153b_hw_phy_cfg()
5978 if (!rtl_phy_patch_request(tp, true, true)) { in r8153b_hw_phy_cfg()
5979 data = ocp_reg_read(tp, OCP_POWER_CFG); in r8153b_hw_phy_cfg()
5981 ocp_reg_write(tp, OCP_POWER_CFG, data); in r8153b_hw_phy_cfg()
5982 tp->ups_info.eee_ckdiv = true; in r8153b_hw_phy_cfg()
5984 data = ocp_reg_read(tp, OCP_DOWN_SPEED); in r8153b_hw_phy_cfg()
5986 ocp_reg_write(tp, OCP_DOWN_SPEED, data); in r8153b_hw_phy_cfg()
5987 tp->ups_info.eee_cmod_lv = true; in r8153b_hw_phy_cfg()
5988 tp->ups_info._10m_ckdiv = true; in r8153b_hw_phy_cfg()
5989 tp->ups_info.eee_plloff_giga = true; in r8153b_hw_phy_cfg()
5991 ocp_reg_write(tp, OCP_SYSCLK_CFG, 0); in r8153b_hw_phy_cfg()
5992 ocp_reg_write(tp, OCP_SYSCLK_CFG, clk_div_expo(5)); in r8153b_hw_phy_cfg()
5993 tp->ups_info._250m_ckdiv = true; in r8153b_hw_phy_cfg()
5995 rtl_phy_patch_request(tp, false, true); in r8153b_hw_phy_cfg()
5998 if (tp->eee_en) in r8153b_hw_phy_cfg()
5999 rtl_eee_enable(tp, true); in r8153b_hw_phy_cfg()
6001 r8153_aldps_en(tp, true); in r8153b_hw_phy_cfg()
6002 r8152b_enable_fc(tp); in r8153b_hw_phy_cfg()
6004 set_bit(PHY_RESET, &tp->flags); in r8153b_hw_phy_cfg()
6007 static void r8153c_hw_phy_cfg(struct r8152 *tp) in r8153c_hw_phy_cfg() argument
6009 r8153b_hw_phy_cfg(tp); in r8153c_hw_phy_cfg()
6011 tp->ups_info.r_tune = true; in r8153c_hw_phy_cfg()
6014 static void rtl8153_change_mtu(struct r8152 *tp) in rtl8153_change_mtu() argument
6016 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, mtu_to_size(tp->netdev->mtu)); in rtl8153_change_mtu()
6017 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_MTPS, MTPS_JUMBO); in rtl8153_change_mtu()
6020 static void r8153_first_init(struct r8152 *tp) in r8153_first_init() argument
6024 rxdy_gated_en(tp, true); in r8153_first_init()
6025 r8153_teredo_off(tp); in r8153_first_init()
6027 ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); in r8153_first_init()
6029 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); in r8153_first_init()
6031 rtl8152_nic_reset(tp); in r8153_first_init()
6032 rtl_reset_bmu(tp); in r8153_first_init()
6034 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); in r8153_first_init()
6036 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data); in r8153_first_init()
6038 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7); in r8153_first_init()
6040 ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data); in r8153_first_init()
6042 wait_oob_link_list_ready(tp); in r8153_first_init()
6044 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7); in r8153_first_init()
6046 ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data); in r8153_first_init()
6048 wait_oob_link_list_ready(tp); in r8153_first_init()
6050 rtl_rx_vlan_en(tp, tp->netdev->features & NETIF_F_HW_VLAN_CTAG_RX); in r8153_first_init()
6052 rtl8153_change_mtu(tp); in r8153_first_init()
6054 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TCR0); in r8153_first_init()
6056 ocp_write_word(tp, MCU_TYPE_PLA, PLA_TCR0, ocp_data); in r8153_first_init()
6058 rtl8152_nic_reset(tp); in r8153_first_init()
6061 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL0, RXFIFO_THR1_NORMAL); in r8153_first_init()
6062 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL1, RXFIFO_THR2_NORMAL); in r8153_first_init()
6063 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL2, RXFIFO_THR3_NORMAL); in r8153_first_init()
6065 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_TXFIFO_CTRL, TXFIFO_THR_NORMAL2); in r8153_first_init()
6068 static void r8153_enter_oob(struct r8152 *tp) in r8153_enter_oob() argument
6072 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); in r8153_enter_oob()
6074 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data); in r8153_enter_oob()
6077 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL0, RXFIFO_THR1_OOB); in r8153_enter_oob()
6078 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL1, RXFIFO_THR2_OOB); in r8153_enter_oob()
6079 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL2, RXFIFO_THR3_OOB); in r8153_enter_oob()
6081 rtl_disable(tp); in r8153_enter_oob()
6082 rtl_reset_bmu(tp); in r8153_enter_oob()
6084 wait_oob_link_list_ready(tp); in r8153_enter_oob()
6086 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7); in r8153_enter_oob()
6088 ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data); in r8153_enter_oob()
6090 wait_oob_link_list_ready(tp); in r8153_enter_oob()
6092 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, 1522); in r8153_enter_oob()
6093 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_MTPS, MTPS_DEFAULT); in r8153_enter_oob()
6095 switch (tp->version) { in r8153_enter_oob()
6100 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG); in r8153_enter_oob()
6102 ocp_write_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG, ocp_data); in r8153_enter_oob()
6112 ocp_write_word(tp, MCU_TYPE_PLA, PLA_TEREDO_WAKE_BASE, 0x00ff); in r8153_enter_oob()
6119 rtl_rx_vlan_en(tp, true); in r8153_enter_oob()
6121 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_BDC_CR); in r8153_enter_oob()
6123 ocp_write_word(tp, MCU_TYPE_PLA, PLA_BDC_CR, ocp_data); in r8153_enter_oob()
6125 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); in r8153_enter_oob()
6127 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data); in r8153_enter_oob()
6129 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7); in r8153_enter_oob()
6131 ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data); in r8153_enter_oob()
6133 rxdy_gated_en(tp, false); in r8153_enter_oob()
6135 ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); in r8153_enter_oob()
6137 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); in r8153_enter_oob()
6140 static void rtl8153_disable(struct r8152 *tp) in rtl8153_disable() argument
6142 r8153_aldps_en(tp, false); in rtl8153_disable()
6143 rtl_disable(tp); in rtl8153_disable()
6144 rtl_reset_bmu(tp); in rtl8153_disable()
6145 r8153_aldps_en(tp, true); in rtl8153_disable()
6148 static u32 fc_pause_on_auto(struct r8152 *tp) in fc_pause_on_auto() argument
6150 return (ALIGN(mtu_to_size(tp->netdev->mtu), 1024) + 6 * 1024); in fc_pause_on_auto()
6153 static u32 fc_pause_off_auto(struct r8152 *tp) in fc_pause_off_auto() argument
6155 return (ALIGN(mtu_to_size(tp->netdev->mtu), 1024) + 14 * 1024); in fc_pause_off_auto()
6158 static void r8156_fc_parameter(struct r8152 *tp) in r8156_fc_parameter() argument
6160 u32 pause_on = tp->fc_pause_on ? tp->fc_pause_on : fc_pause_on_auto(tp); in r8156_fc_parameter()
6161 u32 pause_off = tp->fc_pause_off ? tp->fc_pause_off : fc_pause_off_auto(tp); in r8156_fc_parameter()
6163 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RX_FIFO_FULL, pause_on / 16); in r8156_fc_parameter()
6164 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RX_FIFO_EMPTY, pause_off / 16); in r8156_fc_parameter()
6167 static int rtl8156_enable(struct r8152 *tp) in rtl8156_enable() argument
6172 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl8156_enable()
6175 r8156_fc_parameter(tp); in rtl8156_enable()
6176 set_tx_qlen(tp); in rtl8156_enable()
6177 rtl_set_eee_plus(tp); in rtl8156_enable()
6178 r8153_set_rx_early_timeout(tp); in rtl8156_enable()
6179 r8153_set_rx_early_size(tp); in rtl8156_enable()
6181 speed = rtl8152_get_speed(tp); in rtl8156_enable()
6182 rtl_set_ifg(tp, speed); in rtl8156_enable()
6184 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4); in rtl8156_enable()
6189 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4, ocp_data); in rtl8156_enable()
6192 ocp_write_word(tp, MCU_TYPE_PLA, PLA_EEE_TXTWSYS, 0x11); in rtl8156_enable()
6194 ocp_write_word(tp, MCU_TYPE_PLA, PLA_EEE_TXTWSYS, 0x3d); in rtl8156_enable()
6196 if (tp->udev->speed == USB_SPEED_HIGH) { in rtl8156_enable()
6198 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_L1_CTRL); in rtl8156_enable()
6204 ocp_write_word(tp, MCU_TYPE_USB, USB_L1_CTRL, ocp_data); in rtl8156_enable()
6207 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_TASK); in rtl8156_enable()
6209 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_TASK, ocp_data); in rtl8156_enable()
6212 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_TASK, ocp_data); in rtl8156_enable()
6214 return rtl_enable(tp); in rtl8156_enable()
6217 static void rtl8156_disable(struct r8152 *tp) in rtl8156_disable() argument
6219 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RX_FIFO_FULL, 0); in rtl8156_disable()
6220 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RX_FIFO_EMPTY, 0); in rtl8156_disable()
6222 rtl8153_disable(tp); in rtl8156_disable()
6225 static int rtl8156b_enable(struct r8152 *tp) in rtl8156b_enable() argument
6230 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl8156b_enable()
6233 set_tx_qlen(tp); in rtl8156b_enable()
6234 rtl_set_eee_plus(tp); in rtl8156b_enable()
6236 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_RX_AGGR_NUM); in rtl8156b_enable()
6238 ocp_write_word(tp, MCU_TYPE_USB, USB_RX_AGGR_NUM, ocp_data); in rtl8156b_enable()
6240 r8153_set_rx_early_timeout(tp); in rtl8156b_enable()
6241 r8153_set_rx_early_size(tp); in rtl8156b_enable()
6243 speed = rtl8152_get_speed(tp); in rtl8156b_enable()
6244 rtl_set_ifg(tp, speed); in rtl8156b_enable()
6246 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4); in rtl8156b_enable()
6251 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4, ocp_data); in rtl8156b_enable()
6253 if (tp->udev->speed == USB_SPEED_HIGH) { in rtl8156b_enable()
6254 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_L1_CTRL); in rtl8156b_enable()
6260 ocp_write_word(tp, MCU_TYPE_USB, USB_L1_CTRL, ocp_data); in rtl8156b_enable()
6263 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_TASK); in rtl8156b_enable()
6265 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_TASK, ocp_data); in rtl8156b_enable()
6268 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_TASK, ocp_data); in rtl8156b_enable()
6270 return rtl_enable(tp); in rtl8156b_enable()
6273 static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u32 speed, u8 duplex, in rtl8152_set_speed() argument
6288 tp->ups_info.speed_duplex = FORCE_10M_FULL; in rtl8152_set_speed()
6290 tp->ups_info.speed_duplex = FORCE_10M_HALF; in rtl8152_set_speed()
6297 tp->ups_info.speed_duplex = FORCE_100M_FULL; in rtl8152_set_speed()
6299 tp->ups_info.speed_duplex = FORCE_100M_HALF; in rtl8152_set_speed()
6303 if (tp->mii.supports_gmii) { in rtl8152_set_speed()
6305 tp->ups_info.speed_duplex = NWAY_1000M_FULL; in rtl8152_set_speed()
6315 tp->mii.full_duplex = 1; in rtl8152_set_speed()
6317 tp->mii.full_duplex = 0; in rtl8152_set_speed()
6319 tp->mii.force_media = 1; in rtl8152_set_speed()
6327 if (tp->mii.supports_gmii) { in rtl8152_set_speed()
6330 if (tp->support_2500full) in rtl8152_set_speed()
6337 orig = r8152_mdio_read(tp, MII_ADVERTISE); in rtl8152_set_speed()
6342 tp->ups_info.speed_duplex = NWAY_10M_HALF; in rtl8152_set_speed()
6346 tp->ups_info.speed_duplex = NWAY_10M_FULL; in rtl8152_set_speed()
6351 tp->ups_info.speed_duplex = NWAY_100M_HALF; in rtl8152_set_speed()
6355 tp->ups_info.speed_duplex = NWAY_100M_FULL; in rtl8152_set_speed()
6359 r8152_mdio_write(tp, MII_ADVERTISE, new1); in rtl8152_set_speed()
6360 tp->mii.advertising = new1; in rtl8152_set_speed()
6363 if (tp->mii.supports_gmii) { in rtl8152_set_speed()
6364 orig = r8152_mdio_read(tp, MII_CTRL1000); in rtl8152_set_speed()
6370 tp->ups_info.speed_duplex = NWAY_1000M_FULL; in rtl8152_set_speed()
6374 r8152_mdio_write(tp, MII_CTRL1000, new1); in rtl8152_set_speed()
6377 if (tp->support_2500full) { in rtl8152_set_speed()
6378 orig = ocp_reg_read(tp, OCP_10GBT_CTRL); in rtl8152_set_speed()
6383 tp->ups_info.speed_duplex = NWAY_2500M_FULL; in rtl8152_set_speed()
6387 ocp_reg_write(tp, OCP_10GBT_CTRL, new1); in rtl8152_set_speed()
6392 tp->mii.force_media = 0; in rtl8152_set_speed()
6395 if (test_and_clear_bit(PHY_RESET, &tp->flags)) in rtl8152_set_speed()
6398 r8152_mdio_write(tp, MII_BMCR, bmcr); in rtl8152_set_speed()
6405 if ((r8152_mdio_read(tp, MII_BMCR) & BMCR_RESET) == 0) in rtl8152_set_speed()
6414 static void rtl8152_up(struct r8152 *tp) in rtl8152_up() argument
6416 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl8152_up()
6419 r8152_aldps_en(tp, false); in rtl8152_up()
6420 r8152b_exit_oob(tp); in rtl8152_up()
6421 r8152_aldps_en(tp, true); in rtl8152_up()
6424 static void rtl8152_down(struct r8152 *tp) in rtl8152_down() argument
6426 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) { in rtl8152_down()
6427 rtl_drop_queued_tx(tp); in rtl8152_down()
6431 r8152_power_cut_en(tp, false); in rtl8152_down()
6432 r8152_aldps_en(tp, false); in rtl8152_down()
6433 r8152b_enter_oob(tp); in rtl8152_down()
6434 r8152_aldps_en(tp, true); in rtl8152_down()
6437 static void rtl8153_up(struct r8152 *tp) in rtl8153_up() argument
6441 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl8153_up()
6444 r8153_u1u2en(tp, false); in rtl8153_up()
6445 r8153_u2p3en(tp, false); in rtl8153_up()
6446 r8153_aldps_en(tp, false); in rtl8153_up()
6447 r8153_first_init(tp); in rtl8153_up()
6449 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6); in rtl8153_up()
6451 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6, ocp_data); in rtl8153_up()
6453 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_LWAKE_CTRL_REG); in rtl8153_up()
6455 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_LWAKE_CTRL_REG, ocp_data); in rtl8153_up()
6457 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_SSPHYLINK1); in rtl8153_up()
6459 ocp_write_word(tp, MCU_TYPE_USB, USB_SSPHYLINK1, ocp_data); in rtl8153_up()
6461 r8153_aldps_en(tp, true); in rtl8153_up()
6463 switch (tp->version) { in rtl8153_up()
6470 r8153_u2p3en(tp, true); in rtl8153_up()
6474 r8153_u1u2en(tp, true); in rtl8153_up()
6477 static void rtl8153_down(struct r8152 *tp) in rtl8153_down() argument
6481 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) { in rtl8153_down()
6482 rtl_drop_queued_tx(tp); in rtl8153_down()
6486 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6); in rtl8153_down()
6488 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6, ocp_data); in rtl8153_down()
6490 r8153_u1u2en(tp, false); in rtl8153_down()
6491 r8153_u2p3en(tp, false); in rtl8153_down()
6492 r8153_power_cut_en(tp, false); in rtl8153_down()
6493 r8153_aldps_en(tp, false); in rtl8153_down()
6494 r8153_enter_oob(tp); in rtl8153_down()
6495 r8153_aldps_en(tp, true); in rtl8153_down()
6498 static void rtl8153b_up(struct r8152 *tp) in rtl8153b_up() argument
6502 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl8153b_up()
6505 r8153b_u1u2en(tp, false); in rtl8153b_up()
6506 r8153_u2p3en(tp, false); in rtl8153b_up()
6507 r8153_aldps_en(tp, false); in rtl8153b_up()
6509 r8153_first_init(tp); in rtl8153b_up()
6510 ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH, RX_THR_B); in rtl8153b_up()
6512 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3); in rtl8153b_up()
6514 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data); in rtl8153b_up()
6516 r8153_aldps_en(tp, true); in rtl8153b_up()
6518 if (tp->udev->speed >= USB_SPEED_SUPER) in rtl8153b_up()
6519 r8153b_u1u2en(tp, true); in rtl8153b_up()
6522 static void rtl8153b_down(struct r8152 *tp) in rtl8153b_down() argument
6526 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) { in rtl8153b_down()
6527 rtl_drop_queued_tx(tp); in rtl8153b_down()
6531 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3); in rtl8153b_down()
6533 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data); in rtl8153b_down()
6535 r8153b_u1u2en(tp, false); in rtl8153b_down()
6536 r8153_u2p3en(tp, false); in rtl8153b_down()
6537 r8153b_power_cut_en(tp, false); in rtl8153b_down()
6538 r8153_aldps_en(tp, false); in rtl8153b_down()
6539 r8153_enter_oob(tp); in rtl8153b_down()
6540 r8153_aldps_en(tp, true); in rtl8153b_down()
6543 static void rtl8153c_change_mtu(struct r8152 *tp) in rtl8153c_change_mtu() argument
6545 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, mtu_to_size(tp->netdev->mtu)); in rtl8153c_change_mtu()
6546 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_MTPS, 10 * 1024 / 64); in rtl8153c_change_mtu()
6548 ocp_write_word(tp, MCU_TYPE_PLA, PLA_TXFIFO_CTRL, 512 / 64); in rtl8153c_change_mtu()
6553 if (tp->netdev->mtu < 8000) in rtl8153c_change_mtu()
6554 ocp_write_word(tp, MCU_TYPE_PLA, PLA_TXFIFO_FULL, 2048 / 8); in rtl8153c_change_mtu()
6556 ocp_write_word(tp, MCU_TYPE_PLA, PLA_TXFIFO_FULL, 900 / 8); in rtl8153c_change_mtu()
6559 static void rtl8153c_up(struct r8152 *tp) in rtl8153c_up() argument
6563 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl8153c_up()
6566 r8153b_u1u2en(tp, false); in rtl8153c_up()
6567 r8153_u2p3en(tp, false); in rtl8153c_up()
6568 r8153_aldps_en(tp, false); in rtl8153c_up()
6570 rxdy_gated_en(tp, true); in rtl8153c_up()
6571 r8153_teredo_off(tp); in rtl8153c_up()
6573 ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); in rtl8153c_up()
6575 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); in rtl8153c_up()
6577 rtl8152_nic_reset(tp); in rtl8153c_up()
6578 rtl_reset_bmu(tp); in rtl8153c_up()
6580 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); in rtl8153c_up()
6582 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data); in rtl8153c_up()
6584 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7); in rtl8153c_up()
6586 ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data); in rtl8153c_up()
6588 wait_oob_link_list_ready(tp); in rtl8153c_up()
6590 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7); in rtl8153c_up()
6592 ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data); in rtl8153c_up()
6594 wait_oob_link_list_ready(tp); in rtl8153c_up()
6596 rtl_rx_vlan_en(tp, tp->netdev->features & NETIF_F_HW_VLAN_CTAG_RX); in rtl8153c_up()
6598 rtl8153c_change_mtu(tp); in rtl8153c_up()
6600 rtl8152_nic_reset(tp); in rtl8153c_up()
6603 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL0, 0x02); in rtl8153c_up()
6604 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_RXFIFO_FULL, 0x08); in rtl8153c_up()
6605 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL1, RXFIFO_THR2_NORMAL); in rtl8153c_up()
6606 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL2, RXFIFO_THR3_NORMAL); in rtl8153c_up()
6608 ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH, RX_THR_B); in rtl8153c_up()
6610 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_CONFIG); in rtl8153c_up()
6612 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CONFIG34); in rtl8153c_up()
6614 ocp_write_word(tp, MCU_TYPE_PLA, PLA_CONFIG34, ocp_data); in rtl8153c_up()
6616 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML); in rtl8153c_up()
6618 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3); in rtl8153c_up()
6620 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data); in rtl8153c_up()
6622 r8153_aldps_en(tp, true); in rtl8153c_up()
6623 r8153b_u1u2en(tp, true); in rtl8153c_up()
6626 static void rtl8156_change_mtu(struct r8152 *tp) in rtl8156_change_mtu() argument
6628 u32 rx_max_size = mtu_to_size(tp->netdev->mtu); in rtl8156_change_mtu()
6630 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, rx_max_size); in rtl8156_change_mtu()
6631 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_MTPS, MTPS_JUMBO); in rtl8156_change_mtu()
6632 r8156_fc_parameter(tp); in rtl8156_change_mtu()
6635 ocp_write_word(tp, MCU_TYPE_PLA, PLA_TXFIFO_CTRL, 512 / 64); in rtl8156_change_mtu()
6636 ocp_write_word(tp, MCU_TYPE_PLA, PLA_TXFIFO_FULL, in rtl8156_change_mtu()
6640 static void rtl8156_up(struct r8152 *tp) in rtl8156_up() argument
6644 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl8156_up()
6647 r8153b_u1u2en(tp, false); in rtl8156_up()
6648 r8153_u2p3en(tp, false); in rtl8156_up()
6649 r8153_aldps_en(tp, false); in rtl8156_up()
6651 rxdy_gated_en(tp, true); in rtl8156_up()
6652 r8153_teredo_off(tp); in rtl8156_up()
6654 ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); in rtl8156_up()
6656 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); in rtl8156_up()
6658 rtl8152_nic_reset(tp); in rtl8156_up()
6659 rtl_reset_bmu(tp); in rtl8156_up()
6661 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); in rtl8156_up()
6663 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data); in rtl8156_up()
6665 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7); in rtl8156_up()
6667 ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data); in rtl8156_up()
6669 rtl_rx_vlan_en(tp, tp->netdev->features & NETIF_F_HW_VLAN_CTAG_RX); in rtl8156_up()
6671 rtl8156_change_mtu(tp); in rtl8156_up()
6673 switch (tp->version) { in rtl8156_up()
6677 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_BMU_CONFIG); in rtl8156_up()
6679 ocp_write_word(tp, MCU_TYPE_USB, USB_BMU_CONFIG, ocp_data); in rtl8156_up()
6686 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_RXFIFO_FULL); in rtl8156_up()
6689 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RXFIFO_FULL, ocp_data); in rtl8156_up()
6691 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3); in rtl8156_up()
6693 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data); in rtl8156_up()
6695 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_SPEED_OPTION); in rtl8156_up()
6697 ocp_write_word(tp, MCU_TYPE_USB, USB_SPEED_OPTION, ocp_data); in rtl8156_up()
6699 ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH, 0x00600400); in rtl8156_up()
6701 if (tp->saved_wolopts != __rtl_get_wol(tp)) { in rtl8156_up()
6702 netif_warn(tp, ifup, tp->netdev, "wol setting is changed\n"); in rtl8156_up()
6703 __rtl_set_wol(tp, tp->saved_wolopts); in rtl8156_up()
6706 r8153_aldps_en(tp, true); in rtl8156_up()
6707 r8153_u2p3en(tp, true); in rtl8156_up()
6709 if (tp->udev->speed >= USB_SPEED_SUPER) in rtl8156_up()
6710 r8153b_u1u2en(tp, true); in rtl8156_up()
6713 static void rtl8156_down(struct r8152 *tp) in rtl8156_down() argument
6717 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) { in rtl8156_down()
6718 rtl_drop_queued_tx(tp); in rtl8156_down()
6722 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3); in rtl8156_down()
6724 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data); in rtl8156_down()
6726 r8153b_u1u2en(tp, false); in rtl8156_down()
6727 r8153_u2p3en(tp, false); in rtl8156_down()
6728 r8153b_power_cut_en(tp, false); in rtl8156_down()
6729 r8153_aldps_en(tp, false); in rtl8156_down()
6731 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); in rtl8156_down()
6733 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data); in rtl8156_down()
6736 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RXFIFO_FULL, 64 / 16); in rtl8156_down()
6737 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RX_FIFO_FULL, 1024 / 16); in rtl8156_down()
6738 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RX_FIFO_EMPTY, 4096 / 16); in rtl8156_down()
6740 rtl_disable(tp); in rtl8156_down()
6741 rtl_reset_bmu(tp); in rtl8156_down()
6743 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, 1522); in rtl8156_down()
6744 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_MTPS, MTPS_DEFAULT); in rtl8156_down()
6750 ocp_write_word(tp, MCU_TYPE_PLA, PLA_TEREDO_WAKE_BASE, 0x00ff); in rtl8156_down()
6752 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); in rtl8156_down()
6754 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data); in rtl8156_down()
6756 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7); in rtl8156_down()
6758 ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data); in rtl8156_down()
6760 rtl_rx_vlan_en(tp, true); in rtl8156_down()
6761 rxdy_gated_en(tp, false); in rtl8156_down()
6763 ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); in rtl8156_down()
6765 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); in rtl8156_down()
6767 r8153_aldps_en(tp, true); in rtl8156_down()
6770 static bool rtl8152_in_nway(struct r8152 *tp) in rtl8152_in_nway() argument
6774 ocp_write_word(tp, MCU_TYPE_PLA, PLA_OCP_GPHY_BASE, 0x2000); in rtl8152_in_nway()
6775 tp->ocp_base = 0x2000; in rtl8152_in_nway()
6776 ocp_write_byte(tp, MCU_TYPE_PLA, 0xb014, 0x4c); /* phy state */ in rtl8152_in_nway()
6777 nway_state = ocp_read_word(tp, MCU_TYPE_PLA, 0xb01a); in rtl8152_in_nway()
6786 static bool rtl8153_in_nway(struct r8152 *tp) in rtl8153_in_nway() argument
6788 u16 phy_state = ocp_reg_read(tp, OCP_PHY_STATE) & 0xff; in rtl8153_in_nway()
6796 static void r8156_mdio_force_mode(struct r8152 *tp) in r8156_mdio_force_mode() argument
6804 data = ocp_reg_read(tp, 0xa5b4); in r8156_mdio_force_mode()
6807 ocp_reg_write(tp, 0xa5b4, data); in r8156_mdio_force_mode()
6811 static void set_carrier(struct r8152 *tp) in set_carrier() argument
6813 struct net_device *netdev = tp->netdev; in set_carrier()
6814 struct napi_struct *napi = &tp->napi; in set_carrier()
6817 speed = rtl8152_get_speed(tp); in set_carrier()
6821 tp->rtl_ops.enable(tp); in set_carrier()
6825 rtl_start_rx(tp); in set_carrier()
6826 clear_bit(RTL8152_SET_RX_MODE, &tp->flags); in set_carrier()
6830 netif_info(tp, link, netdev, "carrier on\n"); in set_carrier()
6832 skb_queue_len(&tp->tx_queue) < tp->tx_qlen) { in set_carrier()
6838 tasklet_disable(&tp->tx_tl); in set_carrier()
6840 tp->rtl_ops.disable(tp); in set_carrier()
6842 tasklet_enable(&tp->tx_tl); in set_carrier()
6843 netif_info(tp, link, netdev, "carrier off\n"); in set_carrier()
6850 struct r8152 *tp = container_of(work, struct r8152, schedule.work); in rtl_work_func_t() local
6855 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags) || !netif_running(tp->netdev)) in rtl_work_func_t()
6858 if (usb_autopm_get_interface(tp->intf) < 0) in rtl_work_func_t()
6861 if (!test_bit(WORK_ENABLE, &tp->flags)) in rtl_work_func_t()
6864 if (!mutex_trylock(&tp->control)) { in rtl_work_func_t()
6865 schedule_delayed_work(&tp->schedule, 0); in rtl_work_func_t()
6869 if (test_and_clear_bit(RTL8152_LINK_CHG, &tp->flags)) in rtl_work_func_t()
6870 set_carrier(tp); in rtl_work_func_t()
6872 if (test_and_clear_bit(RTL8152_SET_RX_MODE, &tp->flags)) in rtl_work_func_t()
6873 _rtl8152_set_rx_mode(tp->netdev); in rtl_work_func_t()
6876 if (test_and_clear_bit(SCHEDULE_TASKLET, &tp->flags) && in rtl_work_func_t()
6877 netif_carrier_ok(tp->netdev)) in rtl_work_func_t()
6878 tasklet_schedule(&tp->tx_tl); in rtl_work_func_t()
6880 if (test_and_clear_bit(RX_EPROTO, &tp->flags) && in rtl_work_func_t()
6881 !list_empty(&tp->rx_done)) in rtl_work_func_t()
6882 napi_schedule(&tp->napi); in rtl_work_func_t()
6884 mutex_unlock(&tp->control); in rtl_work_func_t()
6887 usb_autopm_put_interface(tp->intf); in rtl_work_func_t()
6892 struct r8152 *tp = container_of(work, struct r8152, hw_phy_work.work); in rtl_hw_phy_work_func_t() local
6894 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl_hw_phy_work_func_t()
6897 if (usb_autopm_get_interface(tp->intf) < 0) in rtl_hw_phy_work_func_t()
6900 mutex_lock(&tp->control); in rtl_hw_phy_work_func_t()
6902 if (rtl8152_request_firmware(tp) == -ENODEV && tp->rtl_fw.retry) { in rtl_hw_phy_work_func_t()
6903 tp->rtl_fw.retry = false; in rtl_hw_phy_work_func_t()
6904 tp->rtl_fw.fw = NULL; in rtl_hw_phy_work_func_t()
6908 queue_delayed_work(system_long_wq, &tp->hw_phy_work, HZ * 10); in rtl_hw_phy_work_func_t()
6912 tp->rtl_ops.hw_phy_cfg(tp); in rtl_hw_phy_work_func_t()
6914 rtl8152_set_speed(tp, tp->autoneg, tp->speed, tp->duplex, in rtl_hw_phy_work_func_t()
6915 tp->advertising); in rtl_hw_phy_work_func_t()
6918 mutex_unlock(&tp->control); in rtl_hw_phy_work_func_t()
6920 usb_autopm_put_interface(tp->intf); in rtl_hw_phy_work_func_t()
6927 struct r8152 *tp = container_of(nb, struct r8152, pm_notifier); in rtl_notifier() local
6932 usb_autopm_get_interface(tp->intf); in rtl_notifier()
6937 usb_autopm_put_interface(tp->intf); in rtl_notifier()
6952 struct r8152 *tp = netdev_priv(netdev); in rtl8152_open() local
6955 if (work_busy(&tp->hw_phy_work.work) & WORK_BUSY_PENDING) { in rtl8152_open()
6956 cancel_delayed_work_sync(&tp->hw_phy_work); in rtl8152_open()
6957 rtl_hw_phy_work_func_t(&tp->hw_phy_work.work); in rtl8152_open()
6960 res = alloc_all_mem(tp); in rtl8152_open()
6964 res = usb_autopm_get_interface(tp->intf); in rtl8152_open()
6968 mutex_lock(&tp->control); in rtl8152_open()
6970 tp->rtl_ops.up(tp); in rtl8152_open()
6974 set_bit(WORK_ENABLE, &tp->flags); in rtl8152_open()
6976 res = usb_submit_urb(tp->intr_urb, GFP_KERNEL); in rtl8152_open()
6979 netif_device_detach(tp->netdev); in rtl8152_open()
6980 netif_warn(tp, ifup, netdev, "intr_urb submit failed: %d\n", in rtl8152_open()
6984 napi_enable(&tp->napi); in rtl8152_open()
6985 tasklet_enable(&tp->tx_tl); in rtl8152_open()
6987 mutex_unlock(&tp->control); in rtl8152_open()
6989 usb_autopm_put_interface(tp->intf); in rtl8152_open()
6991 tp->pm_notifier.notifier_call = rtl_notifier; in rtl8152_open()
6992 register_pm_notifier(&tp->pm_notifier); in rtl8152_open()
6997 mutex_unlock(&tp->control); in rtl8152_open()
6998 usb_autopm_put_interface(tp->intf); in rtl8152_open()
7000 free_all_mem(tp); in rtl8152_open()
7007 struct r8152 *tp = netdev_priv(netdev); in rtl8152_close() local
7011 unregister_pm_notifier(&tp->pm_notifier); in rtl8152_close()
7013 tasklet_disable(&tp->tx_tl); in rtl8152_close()
7014 clear_bit(WORK_ENABLE, &tp->flags); in rtl8152_close()
7015 usb_kill_urb(tp->intr_urb); in rtl8152_close()
7016 cancel_delayed_work_sync(&tp->schedule); in rtl8152_close()
7017 napi_disable(&tp->napi); in rtl8152_close()
7020 res = usb_autopm_get_interface(tp->intf); in rtl8152_close()
7021 if (res < 0 || test_bit(RTL8152_INACCESSIBLE, &tp->flags)) { in rtl8152_close()
7022 rtl_drop_queued_tx(tp); in rtl8152_close()
7023 rtl_stop_rx(tp); in rtl8152_close()
7025 mutex_lock(&tp->control); in rtl8152_close()
7027 tp->rtl_ops.down(tp); in rtl8152_close()
7029 mutex_unlock(&tp->control); in rtl8152_close()
7033 usb_autopm_put_interface(tp->intf); in rtl8152_close()
7035 free_all_mem(tp); in rtl8152_close()
7040 static void rtl_tally_reset(struct r8152 *tp) in rtl_tally_reset() argument
7044 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_RSTTALLY); in rtl_tally_reset()
7046 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RSTTALLY, ocp_data); in rtl_tally_reset()
7049 static void r8152b_init(struct r8152 *tp) in r8152b_init() argument
7054 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8152b_init()
7057 data = r8152_mdio_read(tp, MII_BMCR); in r8152b_init()
7060 r8152_mdio_write(tp, MII_BMCR, data); in r8152b_init()
7063 r8152_aldps_en(tp, false); in r8152b_init()
7065 if (tp->version == RTL_VER_01) { in r8152b_init()
7066 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE); in r8152b_init()
7068 ocp_write_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE, ocp_data); in r8152b_init()
7071 r8152_power_cut_en(tp, false); in r8152b_init()
7073 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR); in r8152b_init()
7075 ocp_write_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR, ocp_data); in r8152b_init()
7076 ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL); in r8152b_init()
7079 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL, ocp_data); in r8152b_init()
7082 ocp_write_word(tp, MCU_TYPE_PLA, PLA_GPHY_INTR_IMR, ocp_data); in r8152b_init()
7084 rtl_tally_reset(tp); in r8152b_init()
7087 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL); in r8152b_init()
7089 ocp_write_word(tp, MCU_TYPE_USB, USB_USB_CTRL, ocp_data); in r8152b_init()
7092 static void r8153_init(struct r8152 *tp) in r8153_init() argument
7098 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8153_init()
7101 r8153_u1u2en(tp, false); in r8153_init()
7104 if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) & in r8153_init()
7109 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8153_init()
7113 data = r8153_phy_status(tp, 0); in r8153_init()
7115 if (tp->version == RTL_VER_03 || tp->version == RTL_VER_04 || in r8153_init()
7116 tp->version == RTL_VER_05) in r8153_init()
7117 ocp_reg_write(tp, OCP_ADC_CFG, CKADSEL_L | ADC_EN | EN_EMI_L); in r8153_init()
7119 data = r8152_mdio_read(tp, MII_BMCR); in r8153_init()
7122 r8152_mdio_write(tp, MII_BMCR, data); in r8153_init()
7125 data = r8153_phy_status(tp, PHY_STAT_LAN_ON); in r8153_init()
7127 r8153_u2p3en(tp, false); in r8153_init()
7129 if (tp->version == RTL_VER_04) { in r8153_init()
7130 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_SSPHYLINK2); in r8153_init()
7133 ocp_write_word(tp, MCU_TYPE_USB, USB_SSPHYLINK2, ocp_data); in r8153_init()
7135 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_USB2PHY); in r8153_init()
7137 ocp_write_byte(tp, MCU_TYPE_USB, USB_USB2PHY, ocp_data); in r8153_init()
7138 } else if (tp->version == RTL_VER_05) { in r8153_init()
7139 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_DMY_REG0); in r8153_init()
7141 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_DMY_REG0, ocp_data); in r8153_init()
7143 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY1); in r8153_init()
7144 if (ocp_read_word(tp, MCU_TYPE_USB, USB_BURST_SIZE) == 0) in r8153_init()
7148 ocp_write_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY1, ocp_data); in r8153_init()
7149 } else if (tp->version == RTL_VER_06) { in r8153_init()
7150 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY1); in r8153_init()
7151 if (ocp_read_word(tp, MCU_TYPE_USB, USB_BURST_SIZE) == 0) in r8153_init()
7155 ocp_write_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY1, ocp_data); in r8153_init()
7157 r8153_queue_wake(tp, false); in r8153_init()
7159 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS); in r8153_init()
7160 if (rtl8152_get_speed(tp) & LINK_STATUS) in r8153_init()
7165 ocp_write_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS, ocp_data); in r8153_init()
7168 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY2); in r8153_init()
7170 ocp_write_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY2, ocp_data); in r8153_init()
7172 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_WDT11_CTRL); in r8153_init()
7174 ocp_write_word(tp, MCU_TYPE_USB, USB_WDT11_CTRL, ocp_data); in r8153_init()
7176 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE); in r8153_init()
7178 ocp_write_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE, ocp_data); in r8153_init()
7181 if (tp->version == RTL_VER_04 && tp->udev->speed < USB_SPEED_SUPER) in r8153_init()
7185 ocp_write_byte(tp, MCU_TYPE_USB, USB_LPM_CTRL, ocp_data); in r8153_init()
7187 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_AFE_CTRL2); in r8153_init()
7190 ocp_write_word(tp, MCU_TYPE_USB, USB_AFE_CTRL2, ocp_data); in r8153_init()
7192 ocp_write_word(tp, MCU_TYPE_USB, USB_CONNECT_TIMER, 0x0001); in r8153_init()
7194 r8153_power_cut_en(tp, false); in r8153_init()
7195 rtl_runtime_suspend_enable(tp, false); in r8153_init()
7196 r8153_mac_clk_speed_down(tp, false); in r8153_init()
7197 r8153_u1u2en(tp, true); in r8153_init()
7198 usb_enable_lpm(tp->udev); in r8153_init()
7200 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6); in r8153_init()
7202 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6, ocp_data); in r8153_init()
7204 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_LWAKE_CTRL_REG); in r8153_init()
7206 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_LWAKE_CTRL_REG, ocp_data); in r8153_init()
7209 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL); in r8153_init()
7211 if (tp->dell_tb_rx_agg_bug) in r8153_init()
7214 ocp_write_word(tp, MCU_TYPE_USB, USB_USB_CTRL, ocp_data); in r8153_init()
7216 rtl_tally_reset(tp); in r8153_init()
7218 switch (tp->udev->speed) { in r8153_init()
7221 tp->coalesce = COALESCE_SUPER; in r8153_init()
7224 tp->coalesce = COALESCE_HIGH; in r8153_init()
7227 tp->coalesce = COALESCE_SLOW; in r8153_init()
7232 static void r8153b_init(struct r8152 *tp) in r8153b_init() argument
7238 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8153b_init()
7241 r8153b_u1u2en(tp, false); in r8153b_init()
7244 if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) & in r8153b_init()
7249 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8153b_init()
7253 data = r8153_phy_status(tp, 0); in r8153b_init()
7255 data = r8152_mdio_read(tp, MII_BMCR); in r8153b_init()
7258 r8152_mdio_write(tp, MII_BMCR, data); in r8153b_init()
7261 data = r8153_phy_status(tp, PHY_STAT_LAN_ON); in r8153b_init()
7263 r8153_u2p3en(tp, false); in r8153b_init()
7266 ocp_write_word(tp, MCU_TYPE_USB, USB_MSC_TIMER, 0x0fff); in r8153b_init()
7268 r8153b_power_cut_en(tp, false); in r8153b_init()
7269 r8153b_ups_en(tp, false); in r8153b_init()
7270 r8153_queue_wake(tp, false); in r8153b_init()
7271 rtl_runtime_suspend_enable(tp, false); in r8153b_init()
7273 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS); in r8153b_init()
7274 if (rtl8152_get_speed(tp) & LINK_STATUS) in r8153b_init()
7279 ocp_write_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS, ocp_data); in r8153b_init()
7281 if (tp->udev->speed >= USB_SPEED_SUPER) in r8153b_init()
7282 r8153b_u1u2en(tp, true); in r8153b_init()
7284 usb_enable_lpm(tp->udev); in r8153b_init()
7287 r8153_mac_clk_speed_down(tp, true); in r8153b_init()
7289 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3); in r8153b_init()
7291 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data); in r8153b_init()
7293 if (tp->version == RTL_VER_09) { in r8153b_init()
7295 if (ocp_read_byte(tp, MCU_TYPE_PLA, 0xdc00) & BIT(5)) { in r8153b_init()
7296 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR); in r8153b_init()
7298 ocp_write_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR, ocp_data); in r8153b_init()
7302 set_bit(GREEN_ETHERNET, &tp->flags); in r8153b_init()
7305 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL); in r8153b_init()
7307 ocp_write_word(tp, MCU_TYPE_USB, USB_USB_CTRL, ocp_data); in r8153b_init()
7309 rtl_tally_reset(tp); in r8153b_init()
7311 tp->coalesce = 15000; /* 15 us */ in r8153b_init()
7314 static void r8153c_init(struct r8152 *tp) in r8153c_init() argument
7320 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8153c_init()
7323 r8153b_u1u2en(tp, false); in r8153c_init()
7326 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_CONFIG); in r8153c_init()
7327 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CONFIG5); in r8153c_init()
7329 ocp_write_word(tp, MCU_TYPE_PLA, PLA_CONFIG5, ocp_data); in r8153c_init()
7330 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, 0xcbf0); in r8153c_init()
7332 ocp_write_word(tp, MCU_TYPE_USB, 0xcbf0, ocp_data); in r8153c_init()
7335 if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) & in r8153c_init()
7340 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8153c_init()
7344 data = r8153_phy_status(tp, 0); in r8153c_init()
7346 data = r8152_mdio_read(tp, MII_BMCR); in r8153c_init()
7349 r8152_mdio_write(tp, MII_BMCR, data); in r8153c_init()
7352 data = r8153_phy_status(tp, PHY_STAT_LAN_ON); in r8153c_init()
7354 r8153_u2p3en(tp, false); in r8153c_init()
7357 ocp_write_word(tp, MCU_TYPE_USB, USB_MSC_TIMER, 0x0fff); in r8153c_init()
7359 r8153b_power_cut_en(tp, false); in r8153c_init()
7360 r8153c_ups_en(tp, false); in r8153c_init()
7361 r8153_queue_wake(tp, false); in r8153c_init()
7362 rtl_runtime_suspend_enable(tp, false); in r8153c_init()
7364 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS); in r8153c_init()
7365 if (rtl8152_get_speed(tp) & LINK_STATUS) in r8153c_init()
7371 ocp_write_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS, ocp_data); in r8153c_init()
7373 r8153b_u1u2en(tp, true); in r8153c_init()
7375 usb_enable_lpm(tp->udev); in r8153c_init()
7378 r8153_mac_clk_speed_down(tp, true); in r8153c_init()
7380 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_MISC_2); in r8153c_init()
7382 ocp_write_byte(tp, MCU_TYPE_USB, USB_MISC_2, ocp_data); in r8153c_init()
7384 set_bit(GREEN_ETHERNET, &tp->flags); in r8153c_init()
7387 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL); in r8153c_init()
7389 ocp_write_word(tp, MCU_TYPE_USB, USB_USB_CTRL, ocp_data); in r8153c_init()
7391 rtl_tally_reset(tp); in r8153c_init()
7393 tp->coalesce = 15000; /* 15 us */ in r8153c_init()
7396 static void r8156_hw_phy_cfg(struct r8152 *tp) in r8156_hw_phy_cfg() argument
7401 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0); in r8156_hw_phy_cfg()
7404 ocp_write_word(tp, MCU_TYPE_USB, USB_MISC_0, ocp_data); in r8156_hw_phy_cfg()
7407 data = r8153_phy_status(tp, 0); in r8156_hw_phy_cfg()
7410 rtl8152_apply_firmware(tp, true); in r8156_hw_phy_cfg()
7412 data = ocp_reg_read(tp, 0xa468); in r8156_hw_phy_cfg()
7414 ocp_reg_write(tp, 0xa468, data); in r8156_hw_phy_cfg()
7419 rtl8152_apply_firmware(tp, false); in r8156_hw_phy_cfg()
7424 r8153_aldps_en(tp, false); in r8156_hw_phy_cfg()
7427 rtl_eee_enable(tp, false); in r8156_hw_phy_cfg()
7429 data = r8153_phy_status(tp, PHY_STAT_LAN_ON); in r8156_hw_phy_cfg()
7432 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR); in r8156_hw_phy_cfg()
7434 ocp_write_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR, ocp_data); in r8156_hw_phy_cfg()
7436 switch (tp->version) { in r8156_hw_phy_cfg()
7438 data = ocp_reg_read(tp, 0xad40); in r8156_hw_phy_cfg()
7441 ocp_reg_write(tp, 0xad40, data); in r8156_hw_phy_cfg()
7443 data = ocp_reg_read(tp, 0xad4e); in r8156_hw_phy_cfg()
7445 ocp_reg_write(tp, 0xad4e, data); in r8156_hw_phy_cfg()
7446 data = ocp_reg_read(tp, 0xad16); in r8156_hw_phy_cfg()
7449 ocp_reg_write(tp, 0xad16, data); in r8156_hw_phy_cfg()
7450 data = ocp_reg_read(tp, 0xad32); in r8156_hw_phy_cfg()
7453 ocp_reg_write(tp, 0xad32, data); in r8156_hw_phy_cfg()
7454 data = ocp_reg_read(tp, 0xac08); in r8156_hw_phy_cfg()
7456 ocp_reg_write(tp, 0xac08, data); in r8156_hw_phy_cfg()
7457 data = ocp_reg_read(tp, 0xac8a); in r8156_hw_phy_cfg()
7460 ocp_reg_write(tp, 0xac8a, data); in r8156_hw_phy_cfg()
7461 data = ocp_reg_read(tp, 0xad18); in r8156_hw_phy_cfg()
7463 ocp_reg_write(tp, 0xad18, data); in r8156_hw_phy_cfg()
7464 data = ocp_reg_read(tp, 0xad1a); in r8156_hw_phy_cfg()
7466 ocp_reg_write(tp, 0xad1a, data); in r8156_hw_phy_cfg()
7467 data = ocp_reg_read(tp, 0xad1c); in r8156_hw_phy_cfg()
7469 ocp_reg_write(tp, 0xad1c, data); in r8156_hw_phy_cfg()
7471 data = sram_read(tp, 0x80ea); in r8156_hw_phy_cfg()
7474 sram_write(tp, 0x80ea, data); in r8156_hw_phy_cfg()
7475 data = sram_read(tp, 0x80eb); in r8156_hw_phy_cfg()
7478 sram_write(tp, 0x80eb, data); in r8156_hw_phy_cfg()
7479 data = sram_read(tp, 0x80f8); in r8156_hw_phy_cfg()
7482 sram_write(tp, 0x80f8, data); in r8156_hw_phy_cfg()
7483 data = sram_read(tp, 0x80f1); in r8156_hw_phy_cfg()
7486 sram_write(tp, 0x80f1, data); in r8156_hw_phy_cfg()
7488 data = sram_read(tp, 0x80fe); in r8156_hw_phy_cfg()
7491 sram_write(tp, 0x80fe, data); in r8156_hw_phy_cfg()
7492 data = sram_read(tp, 0x8102); in r8156_hw_phy_cfg()
7495 sram_write(tp, 0x8102, data); in r8156_hw_phy_cfg()
7496 data = sram_read(tp, 0x8015); in r8156_hw_phy_cfg()
7499 sram_write(tp, 0x8015, data); in r8156_hw_phy_cfg()
7500 data = sram_read(tp, 0x8100); in r8156_hw_phy_cfg()
7503 sram_write(tp, 0x8100, data); in r8156_hw_phy_cfg()
7504 data = sram_read(tp, 0x8014); in r8156_hw_phy_cfg()
7507 sram_write(tp, 0x8014, data); in r8156_hw_phy_cfg()
7508 data = sram_read(tp, 0x8016); in r8156_hw_phy_cfg()
7511 sram_write(tp, 0x8016, data); in r8156_hw_phy_cfg()
7512 data = sram_read(tp, 0x80dc); in r8156_hw_phy_cfg()
7515 sram_write(tp, 0x80dc, data); in r8156_hw_phy_cfg()
7516 data = sram_read(tp, 0x80df); in r8156_hw_phy_cfg()
7518 sram_write(tp, 0x80df, data); in r8156_hw_phy_cfg()
7519 data = sram_read(tp, 0x80e1); in r8156_hw_phy_cfg()
7521 sram_write(tp, 0x80e1, data); in r8156_hw_phy_cfg()
7523 data = ocp_reg_read(tp, 0xbf06); in r8156_hw_phy_cfg()
7526 ocp_reg_write(tp, 0xbf06, data); in r8156_hw_phy_cfg()
7528 sram_write(tp, 0x819f, 0xddb6); in r8156_hw_phy_cfg()
7530 ocp_reg_write(tp, 0xbc34, 0x5555); in r8156_hw_phy_cfg()
7531 data = ocp_reg_read(tp, 0xbf0a); in r8156_hw_phy_cfg()
7534 ocp_reg_write(tp, 0xbf0a, data); in r8156_hw_phy_cfg()
7536 data = ocp_reg_read(tp, 0xbd2c); in r8156_hw_phy_cfg()
7538 ocp_reg_write(tp, 0xbd2c, data); in r8156_hw_phy_cfg()
7541 data = ocp_reg_read(tp, 0xad16); in r8156_hw_phy_cfg()
7543 ocp_reg_write(tp, 0xad16, data); in r8156_hw_phy_cfg()
7544 data = ocp_reg_read(tp, 0xad32); in r8156_hw_phy_cfg()
7547 ocp_reg_write(tp, 0xad32, data); in r8156_hw_phy_cfg()
7548 data = ocp_reg_read(tp, 0xac08); in r8156_hw_phy_cfg()
7550 ocp_reg_write(tp, 0xac08, data); in r8156_hw_phy_cfg()
7551 data = ocp_reg_read(tp, 0xacc0); in r8156_hw_phy_cfg()
7554 ocp_reg_write(tp, 0xacc0, data); in r8156_hw_phy_cfg()
7555 data = ocp_reg_read(tp, 0xad40); in r8156_hw_phy_cfg()
7558 ocp_reg_write(tp, 0xad40, data); in r8156_hw_phy_cfg()
7559 data = ocp_reg_read(tp, 0xac14); in r8156_hw_phy_cfg()
7561 ocp_reg_write(tp, 0xac14, data); in r8156_hw_phy_cfg()
7562 data = ocp_reg_read(tp, 0xac80); in r8156_hw_phy_cfg()
7564 ocp_reg_write(tp, 0xac80, data); in r8156_hw_phy_cfg()
7565 data = ocp_reg_read(tp, 0xac5e); in r8156_hw_phy_cfg()
7568 ocp_reg_write(tp, 0xac5e, data); in r8156_hw_phy_cfg()
7569 ocp_reg_write(tp, 0xad4c, 0x00a8); in r8156_hw_phy_cfg()
7570 ocp_reg_write(tp, 0xac5c, 0x01ff); in r8156_hw_phy_cfg()
7571 data = ocp_reg_read(tp, 0xac8a); in r8156_hw_phy_cfg()
7574 ocp_reg_write(tp, 0xac8a, data); in r8156_hw_phy_cfg()
7575 ocp_reg_write(tp, 0xb87c, 0x8157); in r8156_hw_phy_cfg()
7576 data = ocp_reg_read(tp, 0xb87e); in r8156_hw_phy_cfg()
7579 ocp_reg_write(tp, 0xb87e, data); in r8156_hw_phy_cfg()
7580 ocp_reg_write(tp, 0xb87c, 0x8159); in r8156_hw_phy_cfg()
7581 data = ocp_reg_read(tp, 0xb87e); in r8156_hw_phy_cfg()
7584 ocp_reg_write(tp, 0xb87e, data); in r8156_hw_phy_cfg()
7587 ocp_reg_write(tp, 0xb87c, 0x80a2); in r8156_hw_phy_cfg()
7588 ocp_reg_write(tp, 0xb87e, 0x0153); in r8156_hw_phy_cfg()
7589 ocp_reg_write(tp, 0xb87c, 0x809c); in r8156_hw_phy_cfg()
7590 ocp_reg_write(tp, 0xb87e, 0x0153); in r8156_hw_phy_cfg()
7593 ocp_write_word(tp, MCU_TYPE_PLA, PLA_EEE_TXTWSYS_2P5G, 0x0056); in r8156_hw_phy_cfg()
7595 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_USB_CFG); in r8156_hw_phy_cfg()
7597 ocp_write_word(tp, MCU_TYPE_PLA, PLA_USB_CFG, ocp_data); in r8156_hw_phy_cfg()
7599 sram_write(tp, 0x8257, 0x020f); /* XG PLL */ in r8156_hw_phy_cfg()
7600 sram_write(tp, 0x80ea, 0x7843); /* GIGA Master */ in r8156_hw_phy_cfg()
7602 if (rtl_phy_patch_request(tp, true, true)) in r8156_hw_phy_cfg()
7606 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4); in r8156_hw_phy_cfg()
7608 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4, ocp_data); in r8156_hw_phy_cfg()
7610 data = ocp_reg_read(tp, OCP_DOWN_SPEED); in r8156_hw_phy_cfg()
7613 ocp_reg_write(tp, OCP_DOWN_SPEED, data); in r8156_hw_phy_cfg()
7614 tp->ups_info._10m_ckdiv = true; in r8156_hw_phy_cfg()
7615 tp->ups_info.eee_plloff_100 = false; in r8156_hw_phy_cfg()
7616 tp->ups_info.eee_plloff_giga = false; in r8156_hw_phy_cfg()
7618 data = ocp_reg_read(tp, OCP_POWER_CFG); in r8156_hw_phy_cfg()
7620 ocp_reg_write(tp, OCP_POWER_CFG, data); in r8156_hw_phy_cfg()
7621 tp->ups_info.eee_ckdiv = false; in r8156_hw_phy_cfg()
7623 ocp_reg_write(tp, OCP_SYSCLK_CFG, 0); in r8156_hw_phy_cfg()
7624 ocp_reg_write(tp, OCP_SYSCLK_CFG, sysclk_div_expo(5)); in r8156_hw_phy_cfg()
7625 tp->ups_info._250m_ckdiv = false; in r8156_hw_phy_cfg()
7627 rtl_phy_patch_request(tp, false, true); in r8156_hw_phy_cfg()
7630 data = ocp_reg_read(tp, 0xd068); in r8156_hw_phy_cfg()
7632 ocp_reg_write(tp, 0xd068, data); in r8156_hw_phy_cfg()
7635 data = sram_read(tp, 0x81a2); in r8156_hw_phy_cfg()
7637 sram_write(tp, 0x81a2, data); in r8156_hw_phy_cfg()
7638 data = ocp_reg_read(tp, 0xb54c); in r8156_hw_phy_cfg()
7641 ocp_reg_write(tp, 0xb54c, data); in r8156_hw_phy_cfg()
7644 data = ocp_reg_read(tp, 0xa454); in r8156_hw_phy_cfg()
7646 ocp_reg_write(tp, 0xa454, data); in r8156_hw_phy_cfg()
7649 data = ocp_reg_read(tp, OCP_10GBT_CTRL); in r8156_hw_phy_cfg()
7651 ocp_reg_write(tp, OCP_10GBT_CTRL, data); in r8156_hw_phy_cfg()
7652 data = ocp_reg_read(tp, 0xad4e); in r8156_hw_phy_cfg()
7654 ocp_reg_write(tp, 0xad4e, data); in r8156_hw_phy_cfg()
7655 data = ocp_reg_read(tp, 0xa86a); in r8156_hw_phy_cfg()
7657 ocp_reg_write(tp, 0xa86a, data); in r8156_hw_phy_cfg()
7660 if ((ocp_read_word(tp, MCU_TYPE_USB, USB_UPS_CFG) & MID_REVERSE) && in r8156_hw_phy_cfg()
7661 (ocp_reg_read(tp, 0xd068) & BIT(1))) { in r8156_hw_phy_cfg()
7664 data = ocp_reg_read(tp, 0xd068); in r8156_hw_phy_cfg()
7667 ocp_reg_write(tp, 0xd068, data); in r8156_hw_phy_cfg()
7668 swap_a = ocp_reg_read(tp, 0xd06a); in r8156_hw_phy_cfg()
7671 ocp_reg_write(tp, 0xd068, data); in r8156_hw_phy_cfg()
7672 swap_b = ocp_reg_read(tp, 0xd06a); in r8156_hw_phy_cfg()
7674 ocp_reg_write(tp, 0xd068, data); in r8156_hw_phy_cfg()
7675 ocp_reg_write(tp, 0xd06a, in r8156_hw_phy_cfg()
7678 ocp_reg_write(tp, 0xd068, data); in r8156_hw_phy_cfg()
7679 ocp_reg_write(tp, 0xd06a, in r8156_hw_phy_cfg()
7683 ocp_reg_write(tp, 0xd068, data); in r8156_hw_phy_cfg()
7684 swap_a = ocp_reg_read(tp, 0xd06a); in r8156_hw_phy_cfg()
7687 ocp_reg_write(tp, 0xd068, data); in r8156_hw_phy_cfg()
7688 swap_b = ocp_reg_read(tp, 0xd06a); in r8156_hw_phy_cfg()
7691 ocp_reg_write(tp, 0xd068, data); in r8156_hw_phy_cfg()
7692 ocp_reg_write(tp, 0xd06a, in r8156_hw_phy_cfg()
7696 ocp_reg_write(tp, 0xd068, data); in r8156_hw_phy_cfg()
7697 ocp_reg_write(tp, 0xd06a, in r8156_hw_phy_cfg()
7699 swap_a = ocp_reg_read(tp, 0xbd5a); in r8156_hw_phy_cfg()
7700 swap_b = ocp_reg_read(tp, 0xbd5c); in r8156_hw_phy_cfg()
7701 ocp_reg_write(tp, 0xbd5a, (swap_a & ~0x1f1f) | in r8156_hw_phy_cfg()
7704 ocp_reg_write(tp, 0xbd5c, (swap_b & ~0x1f1f) | in r8156_hw_phy_cfg()
7707 swap_a = ocp_reg_read(tp, 0xbc18); in r8156_hw_phy_cfg()
7708 swap_b = ocp_reg_read(tp, 0xbc1a); in r8156_hw_phy_cfg()
7709 ocp_reg_write(tp, 0xbc18, (swap_a & ~0x1f1f) | in r8156_hw_phy_cfg()
7712 ocp_reg_write(tp, 0xbc1a, (swap_b & ~0x1f1f) | in r8156_hw_phy_cfg()
7718 data = ocp_reg_read(tp, OCP_INTR_EN); in r8156_hw_phy_cfg()
7720 ocp_reg_write(tp, OCP_INTR_EN, data); in r8156_hw_phy_cfg()
7726 rtl_green_en(tp, test_bit(GREEN_ETHERNET, &tp->flags)); in r8156_hw_phy_cfg()
7728 data = ocp_reg_read(tp, 0xa428); in r8156_hw_phy_cfg()
7730 ocp_reg_write(tp, 0xa428, data); in r8156_hw_phy_cfg()
7731 data = ocp_reg_read(tp, 0xa5ea); in r8156_hw_phy_cfg()
7733 ocp_reg_write(tp, 0xa5ea, data); in r8156_hw_phy_cfg()
7734 tp->ups_info.lite_mode = 0; in r8156_hw_phy_cfg()
7736 if (tp->eee_en) in r8156_hw_phy_cfg()
7737 rtl_eee_enable(tp, true); in r8156_hw_phy_cfg()
7739 r8153_aldps_en(tp, true); in r8156_hw_phy_cfg()
7740 r8152b_enable_fc(tp); in r8156_hw_phy_cfg()
7741 r8153_u2p3en(tp, true); in r8156_hw_phy_cfg()
7743 set_bit(PHY_RESET, &tp->flags); in r8156_hw_phy_cfg()
7746 static void r8156b_hw_phy_cfg(struct r8152 *tp) in r8156b_hw_phy_cfg() argument
7751 switch (tp->version) { in r8156b_hw_phy_cfg()
7753 ocp_reg_write(tp, 0xbf86, 0x9000); in r8156b_hw_phy_cfg()
7754 data = ocp_reg_read(tp, 0xc402); in r8156b_hw_phy_cfg()
7756 ocp_reg_write(tp, 0xc402, data); in r8156b_hw_phy_cfg()
7758 ocp_reg_write(tp, 0xc402, data); in r8156b_hw_phy_cfg()
7759 ocp_reg_write(tp, 0xbd86, 0x1010); in r8156b_hw_phy_cfg()
7760 ocp_reg_write(tp, 0xbd88, 0x1010); in r8156b_hw_phy_cfg()
7761 data = ocp_reg_read(tp, 0xbd4e); in r8156b_hw_phy_cfg()
7764 ocp_reg_write(tp, 0xbd4e, data); in r8156b_hw_phy_cfg()
7765 data = ocp_reg_read(tp, 0xbf46); in r8156b_hw_phy_cfg()
7768 ocp_reg_write(tp, 0xbf46, data); in r8156b_hw_phy_cfg()
7772 r8156b_wait_loading_flash(tp); in r8156b_hw_phy_cfg()
7778 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0); in r8156b_hw_phy_cfg()
7781 ocp_write_word(tp, MCU_TYPE_USB, USB_MISC_0, ocp_data); in r8156b_hw_phy_cfg()
7784 data = r8153_phy_status(tp, 0); in r8156b_hw_phy_cfg()
7787 rtl8152_apply_firmware(tp, true); in r8156b_hw_phy_cfg()
7789 data = ocp_reg_read(tp, 0xa466); in r8156b_hw_phy_cfg()
7791 ocp_reg_write(tp, 0xa466, data); in r8156b_hw_phy_cfg()
7793 data = ocp_reg_read(tp, 0xa468); in r8156b_hw_phy_cfg()
7795 ocp_reg_write(tp, 0xa468, data); in r8156b_hw_phy_cfg()
7800 rtl8152_apply_firmware(tp, false); in r8156b_hw_phy_cfg()
7804 data = r8152_mdio_read(tp, MII_BMCR); in r8156b_hw_phy_cfg()
7807 r8152_mdio_write(tp, MII_BMCR, data); in r8156b_hw_phy_cfg()
7811 r8153_aldps_en(tp, false); in r8156b_hw_phy_cfg()
7814 rtl_eee_enable(tp, false); in r8156b_hw_phy_cfg()
7816 data = r8153_phy_status(tp, PHY_STAT_LAN_ON); in r8156b_hw_phy_cfg()
7819 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR); in r8156b_hw_phy_cfg()
7821 ocp_write_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR, ocp_data); in r8156b_hw_phy_cfg()
7823 switch (tp->version) { in r8156b_hw_phy_cfg()
7825 data = ocp_reg_read(tp, 0xbc08); in r8156b_hw_phy_cfg()
7827 ocp_reg_write(tp, 0xbc08, data); in r8156b_hw_phy_cfg()
7829 data = sram_read(tp, 0x8fff); in r8156b_hw_phy_cfg()
7832 sram_write(tp, 0x8fff, data); in r8156b_hw_phy_cfg()
7834 data = ocp_reg_read(tp, 0xacda); in r8156b_hw_phy_cfg()
7836 ocp_reg_write(tp, 0xacda, data); in r8156b_hw_phy_cfg()
7837 data = ocp_reg_read(tp, 0xacde); in r8156b_hw_phy_cfg()
7839 ocp_reg_write(tp, 0xacde, data); in r8156b_hw_phy_cfg()
7840 ocp_reg_write(tp, 0xac8c, 0x0ffc); in r8156b_hw_phy_cfg()
7841 ocp_reg_write(tp, 0xac46, 0xb7b4); in r8156b_hw_phy_cfg()
7842 ocp_reg_write(tp, 0xac50, 0x0fbc); in r8156b_hw_phy_cfg()
7843 ocp_reg_write(tp, 0xac3c, 0x9240); in r8156b_hw_phy_cfg()
7844 ocp_reg_write(tp, 0xac4e, 0x0db4); in r8156b_hw_phy_cfg()
7845 ocp_reg_write(tp, 0xacc6, 0x0707); in r8156b_hw_phy_cfg()
7846 ocp_reg_write(tp, 0xacc8, 0xa0d3); in r8156b_hw_phy_cfg()
7847 ocp_reg_write(tp, 0xad08, 0x0007); in r8156b_hw_phy_cfg()
7849 ocp_reg_write(tp, 0xb87c, 0x8560); in r8156b_hw_phy_cfg()
7850 ocp_reg_write(tp, 0xb87e, 0x19cc); in r8156b_hw_phy_cfg()
7851 ocp_reg_write(tp, 0xb87c, 0x8562); in r8156b_hw_phy_cfg()
7852 ocp_reg_write(tp, 0xb87e, 0x19cc); in r8156b_hw_phy_cfg()
7853 ocp_reg_write(tp, 0xb87c, 0x8564); in r8156b_hw_phy_cfg()
7854 ocp_reg_write(tp, 0xb87e, 0x19cc); in r8156b_hw_phy_cfg()
7855 ocp_reg_write(tp, 0xb87c, 0x8566); in r8156b_hw_phy_cfg()
7856 ocp_reg_write(tp, 0xb87e, 0x147d); in r8156b_hw_phy_cfg()
7857 ocp_reg_write(tp, 0xb87c, 0x8568); in r8156b_hw_phy_cfg()
7858 ocp_reg_write(tp, 0xb87e, 0x147d); in r8156b_hw_phy_cfg()
7859 ocp_reg_write(tp, 0xb87c, 0x856a); in r8156b_hw_phy_cfg()
7860 ocp_reg_write(tp, 0xb87e, 0x147d); in r8156b_hw_phy_cfg()
7861 ocp_reg_write(tp, 0xb87c, 0x8ffe); in r8156b_hw_phy_cfg()
7862 ocp_reg_write(tp, 0xb87e, 0x0907); in r8156b_hw_phy_cfg()
7863 ocp_reg_write(tp, 0xb87c, 0x80d6); in r8156b_hw_phy_cfg()
7864 ocp_reg_write(tp, 0xb87e, 0x2801); in r8156b_hw_phy_cfg()
7865 ocp_reg_write(tp, 0xb87c, 0x80f2); in r8156b_hw_phy_cfg()
7866 ocp_reg_write(tp, 0xb87e, 0x2801); in r8156b_hw_phy_cfg()
7867 ocp_reg_write(tp, 0xb87c, 0x80f4); in r8156b_hw_phy_cfg()
7868 ocp_reg_write(tp, 0xb87e, 0x6077); in r8156b_hw_phy_cfg()
7869 ocp_reg_write(tp, 0xb506, 0x01e7); in r8156b_hw_phy_cfg()
7871 ocp_reg_write(tp, 0xb87c, 0x8013); in r8156b_hw_phy_cfg()
7872 ocp_reg_write(tp, 0xb87e, 0x0700); in r8156b_hw_phy_cfg()
7873 ocp_reg_write(tp, 0xb87c, 0x8fb9); in r8156b_hw_phy_cfg()
7874 ocp_reg_write(tp, 0xb87e, 0x2801); in r8156b_hw_phy_cfg()
7875 ocp_reg_write(tp, 0xb87c, 0x8fba); in r8156b_hw_phy_cfg()
7876 ocp_reg_write(tp, 0xb87e, 0x0100); in r8156b_hw_phy_cfg()
7877 ocp_reg_write(tp, 0xb87c, 0x8fbc); in r8156b_hw_phy_cfg()
7878 ocp_reg_write(tp, 0xb87e, 0x1900); in r8156b_hw_phy_cfg()
7879 ocp_reg_write(tp, 0xb87c, 0x8fbe); in r8156b_hw_phy_cfg()
7880 ocp_reg_write(tp, 0xb87e, 0xe100); in r8156b_hw_phy_cfg()
7881 ocp_reg_write(tp, 0xb87c, 0x8fc0); in r8156b_hw_phy_cfg()
7882 ocp_reg_write(tp, 0xb87e, 0x0800); in r8156b_hw_phy_cfg()
7883 ocp_reg_write(tp, 0xb87c, 0x8fc2); in r8156b_hw_phy_cfg()
7884 ocp_reg_write(tp, 0xb87e, 0xe500); in r8156b_hw_phy_cfg()
7885 ocp_reg_write(tp, 0xb87c, 0x8fc4); in r8156b_hw_phy_cfg()
7886 ocp_reg_write(tp, 0xb87e, 0x0f00); in r8156b_hw_phy_cfg()
7887 ocp_reg_write(tp, 0xb87c, 0x8fc6); in r8156b_hw_phy_cfg()
7888 ocp_reg_write(tp, 0xb87e, 0xf100); in r8156b_hw_phy_cfg()
7889 ocp_reg_write(tp, 0xb87c, 0x8fc8); in r8156b_hw_phy_cfg()
7890 ocp_reg_write(tp, 0xb87e, 0x0400); in r8156b_hw_phy_cfg()
7891 ocp_reg_write(tp, 0xb87c, 0x8fca); in r8156b_hw_phy_cfg()
7892 ocp_reg_write(tp, 0xb87e, 0xf300); in r8156b_hw_phy_cfg()
7893 ocp_reg_write(tp, 0xb87c, 0x8fcc); in r8156b_hw_phy_cfg()
7894 ocp_reg_write(tp, 0xb87e, 0xfd00); in r8156b_hw_phy_cfg()
7895 ocp_reg_write(tp, 0xb87c, 0x8fce); in r8156b_hw_phy_cfg()
7896 ocp_reg_write(tp, 0xb87e, 0xff00); in r8156b_hw_phy_cfg()
7897 ocp_reg_write(tp, 0xb87c, 0x8fd0); in r8156b_hw_phy_cfg()
7898 ocp_reg_write(tp, 0xb87e, 0xfb00); in r8156b_hw_phy_cfg()
7899 ocp_reg_write(tp, 0xb87c, 0x8fd2); in r8156b_hw_phy_cfg()
7900 ocp_reg_write(tp, 0xb87e, 0x0100); in r8156b_hw_phy_cfg()
7901 ocp_reg_write(tp, 0xb87c, 0x8fd4); in r8156b_hw_phy_cfg()
7902 ocp_reg_write(tp, 0xb87e, 0xf400); in r8156b_hw_phy_cfg()
7903 ocp_reg_write(tp, 0xb87c, 0x8fd6); in r8156b_hw_phy_cfg()
7904 ocp_reg_write(tp, 0xb87e, 0xff00); in r8156b_hw_phy_cfg()
7905 ocp_reg_write(tp, 0xb87c, 0x8fd8); in r8156b_hw_phy_cfg()
7906 ocp_reg_write(tp, 0xb87e, 0xf600); in r8156b_hw_phy_cfg()
7908 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_USB_CFG); in r8156b_hw_phy_cfg()
7910 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_USB_CFG, ocp_data); in r8156b_hw_phy_cfg()
7911 ocp_reg_write(tp, 0xb87c, 0x813d); in r8156b_hw_phy_cfg()
7912 ocp_reg_write(tp, 0xb87e, 0x390e); in r8156b_hw_phy_cfg()
7913 ocp_reg_write(tp, 0xb87c, 0x814f); in r8156b_hw_phy_cfg()
7914 ocp_reg_write(tp, 0xb87e, 0x790e); in r8156b_hw_phy_cfg()
7915 ocp_reg_write(tp, 0xb87c, 0x80b0); in r8156b_hw_phy_cfg()
7916 ocp_reg_write(tp, 0xb87e, 0x0f31); in r8156b_hw_phy_cfg()
7917 data = ocp_reg_read(tp, 0xbf4c); in r8156b_hw_phy_cfg()
7919 ocp_reg_write(tp, 0xbf4c, data); in r8156b_hw_phy_cfg()
7920 data = ocp_reg_read(tp, 0xbcca); in r8156b_hw_phy_cfg()
7922 ocp_reg_write(tp, 0xbcca, data); in r8156b_hw_phy_cfg()
7923 ocp_reg_write(tp, 0xb87c, 0x8141); in r8156b_hw_phy_cfg()
7924 ocp_reg_write(tp, 0xb87e, 0x320e); in r8156b_hw_phy_cfg()
7925 ocp_reg_write(tp, 0xb87c, 0x8153); in r8156b_hw_phy_cfg()
7926 ocp_reg_write(tp, 0xb87e, 0x720e); in r8156b_hw_phy_cfg()
7927 ocp_reg_write(tp, 0xb87c, 0x8529); in r8156b_hw_phy_cfg()
7928 ocp_reg_write(tp, 0xb87e, 0x050e); in r8156b_hw_phy_cfg()
7929 data = ocp_reg_read(tp, OCP_EEE_CFG); in r8156b_hw_phy_cfg()
7931 ocp_reg_write(tp, OCP_EEE_CFG, data); in r8156b_hw_phy_cfg()
7933 sram_write(tp, 0x816c, 0xc4a0); in r8156b_hw_phy_cfg()
7934 sram_write(tp, 0x8170, 0xc4a0); in r8156b_hw_phy_cfg()
7935 sram_write(tp, 0x8174, 0x04a0); in r8156b_hw_phy_cfg()
7936 sram_write(tp, 0x8178, 0x04a0); in r8156b_hw_phy_cfg()
7937 sram_write(tp, 0x817c, 0x0719); in r8156b_hw_phy_cfg()
7938 sram_write(tp, 0x8ff4, 0x0400); in r8156b_hw_phy_cfg()
7939 sram_write(tp, 0x8ff1, 0x0404); in r8156b_hw_phy_cfg()
7941 ocp_reg_write(tp, 0xbf4a, 0x001b); in r8156b_hw_phy_cfg()
7942 ocp_reg_write(tp, 0xb87c, 0x8033); in r8156b_hw_phy_cfg()
7943 ocp_reg_write(tp, 0xb87e, 0x7c13); in r8156b_hw_phy_cfg()
7944 ocp_reg_write(tp, 0xb87c, 0x8037); in r8156b_hw_phy_cfg()
7945 ocp_reg_write(tp, 0xb87e, 0x7c13); in r8156b_hw_phy_cfg()
7946 ocp_reg_write(tp, 0xb87c, 0x803b); in r8156b_hw_phy_cfg()
7947 ocp_reg_write(tp, 0xb87e, 0xfc32); in r8156b_hw_phy_cfg()
7948 ocp_reg_write(tp, 0xb87c, 0x803f); in r8156b_hw_phy_cfg()
7949 ocp_reg_write(tp, 0xb87e, 0x7c13); in r8156b_hw_phy_cfg()
7950 ocp_reg_write(tp, 0xb87c, 0x8043); in r8156b_hw_phy_cfg()
7951 ocp_reg_write(tp, 0xb87e, 0x7c13); in r8156b_hw_phy_cfg()
7952 ocp_reg_write(tp, 0xb87c, 0x8047); in r8156b_hw_phy_cfg()
7953 ocp_reg_write(tp, 0xb87e, 0x7c13); in r8156b_hw_phy_cfg()
7955 ocp_reg_write(tp, 0xb87c, 0x8145); in r8156b_hw_phy_cfg()
7956 ocp_reg_write(tp, 0xb87e, 0x370e); in r8156b_hw_phy_cfg()
7957 ocp_reg_write(tp, 0xb87c, 0x8157); in r8156b_hw_phy_cfg()
7958 ocp_reg_write(tp, 0xb87e, 0x770e); in r8156b_hw_phy_cfg()
7959 ocp_reg_write(tp, 0xb87c, 0x8169); in r8156b_hw_phy_cfg()
7960 ocp_reg_write(tp, 0xb87e, 0x0d0a); in r8156b_hw_phy_cfg()
7961 ocp_reg_write(tp, 0xb87c, 0x817b); in r8156b_hw_phy_cfg()
7962 ocp_reg_write(tp, 0xb87e, 0x1d0a); in r8156b_hw_phy_cfg()
7964 data = sram_read(tp, 0x8217); in r8156b_hw_phy_cfg()
7967 sram_write(tp, 0x8217, data); in r8156b_hw_phy_cfg()
7968 data = sram_read(tp, 0x821a); in r8156b_hw_phy_cfg()
7971 sram_write(tp, 0x821a, data); in r8156b_hw_phy_cfg()
7972 sram_write(tp, 0x80da, 0x0403); in r8156b_hw_phy_cfg()
7973 data = sram_read(tp, 0x80dc); in r8156b_hw_phy_cfg()
7976 sram_write(tp, 0x80dc, data); in r8156b_hw_phy_cfg()
7977 sram_write(tp, 0x80b3, 0x0384); in r8156b_hw_phy_cfg()
7978 sram_write(tp, 0x80b7, 0x2007); in r8156b_hw_phy_cfg()
7979 data = sram_read(tp, 0x80ba); in r8156b_hw_phy_cfg()
7982 sram_write(tp, 0x80ba, data); in r8156b_hw_phy_cfg()
7983 sram_write(tp, 0x80b5, 0xf009); in r8156b_hw_phy_cfg()
7984 data = sram_read(tp, 0x80bd); in r8156b_hw_phy_cfg()
7987 sram_write(tp, 0x80bd, data); in r8156b_hw_phy_cfg()
7988 sram_write(tp, 0x80c7, 0xf083); in r8156b_hw_phy_cfg()
7989 sram_write(tp, 0x80dd, 0x03f0); in r8156b_hw_phy_cfg()
7990 data = sram_read(tp, 0x80df); in r8156b_hw_phy_cfg()
7993 sram_write(tp, 0x80df, data); in r8156b_hw_phy_cfg()
7994 sram_write(tp, 0x80cb, 0x2007); in r8156b_hw_phy_cfg()
7995 data = sram_read(tp, 0x80ce); in r8156b_hw_phy_cfg()
7998 sram_write(tp, 0x80ce, data); in r8156b_hw_phy_cfg()
7999 sram_write(tp, 0x80c9, 0x8009); in r8156b_hw_phy_cfg()
8000 data = sram_read(tp, 0x80d1); in r8156b_hw_phy_cfg()
8003 sram_write(tp, 0x80d1, data); in r8156b_hw_phy_cfg()
8004 sram_write(tp, 0x80a3, 0x200a); in r8156b_hw_phy_cfg()
8005 sram_write(tp, 0x80a5, 0xf0ad); in r8156b_hw_phy_cfg()
8006 sram_write(tp, 0x809f, 0x6073); in r8156b_hw_phy_cfg()
8007 sram_write(tp, 0x80a1, 0x000b); in r8156b_hw_phy_cfg()
8008 data = sram_read(tp, 0x80a9); in r8156b_hw_phy_cfg()
8011 sram_write(tp, 0x80a9, data); in r8156b_hw_phy_cfg()
8013 if (rtl_phy_patch_request(tp, true, true)) in r8156b_hw_phy_cfg()
8016 data = ocp_reg_read(tp, 0xb896); in r8156b_hw_phy_cfg()
8018 ocp_reg_write(tp, 0xb896, data); in r8156b_hw_phy_cfg()
8019 data = ocp_reg_read(tp, 0xb892); in r8156b_hw_phy_cfg()
8021 ocp_reg_write(tp, 0xb892, data); in r8156b_hw_phy_cfg()
8022 ocp_reg_write(tp, 0xb88e, 0xc23e); in r8156b_hw_phy_cfg()
8023 ocp_reg_write(tp, 0xb890, 0x0000); in r8156b_hw_phy_cfg()
8024 ocp_reg_write(tp, 0xb88e, 0xc240); in r8156b_hw_phy_cfg()
8025 ocp_reg_write(tp, 0xb890, 0x0103); in r8156b_hw_phy_cfg()
8026 ocp_reg_write(tp, 0xb88e, 0xc242); in r8156b_hw_phy_cfg()
8027 ocp_reg_write(tp, 0xb890, 0x0507); in r8156b_hw_phy_cfg()
8028 ocp_reg_write(tp, 0xb88e, 0xc244); in r8156b_hw_phy_cfg()
8029 ocp_reg_write(tp, 0xb890, 0x090b); in r8156b_hw_phy_cfg()
8030 ocp_reg_write(tp, 0xb88e, 0xc246); in r8156b_hw_phy_cfg()
8031 ocp_reg_write(tp, 0xb890, 0x0c0e); in r8156b_hw_phy_cfg()
8032 ocp_reg_write(tp, 0xb88e, 0xc248); in r8156b_hw_phy_cfg()
8033 ocp_reg_write(tp, 0xb890, 0x1012); in r8156b_hw_phy_cfg()
8034 ocp_reg_write(tp, 0xb88e, 0xc24a); in r8156b_hw_phy_cfg()
8035 ocp_reg_write(tp, 0xb890, 0x1416); in r8156b_hw_phy_cfg()
8036 data = ocp_reg_read(tp, 0xb896); in r8156b_hw_phy_cfg()
8038 ocp_reg_write(tp, 0xb896, data); in r8156b_hw_phy_cfg()
8040 rtl_phy_patch_request(tp, false, true); in r8156b_hw_phy_cfg()
8042 data = ocp_reg_read(tp, 0xa86a); in r8156b_hw_phy_cfg()
8044 ocp_reg_write(tp, 0xa86a, data); in r8156b_hw_phy_cfg()
8045 data = ocp_reg_read(tp, 0xa6f0); in r8156b_hw_phy_cfg()
8047 ocp_reg_write(tp, 0xa6f0, data); in r8156b_hw_phy_cfg()
8049 ocp_reg_write(tp, 0xbfa0, 0xd70d); in r8156b_hw_phy_cfg()
8050 ocp_reg_write(tp, 0xbfa2, 0x4100); in r8156b_hw_phy_cfg()
8051 ocp_reg_write(tp, 0xbfa4, 0xe868); in r8156b_hw_phy_cfg()
8052 ocp_reg_write(tp, 0xbfa6, 0xdc59); in r8156b_hw_phy_cfg()
8053 ocp_reg_write(tp, 0xb54c, 0x3c18); in r8156b_hw_phy_cfg()
8054 data = ocp_reg_read(tp, 0xbfa4); in r8156b_hw_phy_cfg()
8056 ocp_reg_write(tp, 0xbfa4, data); in r8156b_hw_phy_cfg()
8057 data = sram_read(tp, 0x817d); in r8156b_hw_phy_cfg()
8059 sram_write(tp, 0x817d, data); in r8156b_hw_phy_cfg()
8063 data = ocp_reg_read(tp, 0xac46); in r8156b_hw_phy_cfg()
8066 ocp_reg_write(tp, 0xac46, data); in r8156b_hw_phy_cfg()
8067 data = ocp_reg_read(tp, 0xad30); in r8156b_hw_phy_cfg()
8070 ocp_reg_write(tp, 0xad30, data); in r8156b_hw_phy_cfg()
8074 ocp_reg_write(tp, 0xb87c, 0x80f5); in r8156b_hw_phy_cfg()
8075 ocp_reg_write(tp, 0xb87e, 0x760e); in r8156b_hw_phy_cfg()
8076 ocp_reg_write(tp, 0xb87c, 0x8107); in r8156b_hw_phy_cfg()
8077 ocp_reg_write(tp, 0xb87e, 0x360e); in r8156b_hw_phy_cfg()
8078 ocp_reg_write(tp, 0xb87c, 0x8551); in r8156b_hw_phy_cfg()
8079 data = ocp_reg_read(tp, 0xb87e); in r8156b_hw_phy_cfg()
8082 ocp_reg_write(tp, 0xb87e, data); in r8156b_hw_phy_cfg()
8085 data = ocp_reg_read(tp, 0xbf00); in r8156b_hw_phy_cfg()
8088 ocp_reg_write(tp, 0xbf00, data); in r8156b_hw_phy_cfg()
8089 data = ocp_reg_read(tp, 0xbf46); in r8156b_hw_phy_cfg()
8092 ocp_reg_write(tp, 0xbf46, data); in r8156b_hw_phy_cfg()
8095 sram_write(tp, 0x8044, 0x2417); in r8156b_hw_phy_cfg()
8096 sram_write(tp, 0x804a, 0x2417); in r8156b_hw_phy_cfg()
8097 sram_write(tp, 0x8050, 0x2417); in r8156b_hw_phy_cfg()
8098 sram_write(tp, 0x8056, 0x2417); in r8156b_hw_phy_cfg()
8099 sram_write(tp, 0x805c, 0x2417); in r8156b_hw_phy_cfg()
8100 sram_write(tp, 0x8062, 0x2417); in r8156b_hw_phy_cfg()
8101 sram_write(tp, 0x8068, 0x2417); in r8156b_hw_phy_cfg()
8102 sram_write(tp, 0x806e, 0x2417); in r8156b_hw_phy_cfg()
8103 sram_write(tp, 0x8074, 0x2417); in r8156b_hw_phy_cfg()
8104 sram_write(tp, 0x807a, 0x2417); in r8156b_hw_phy_cfg()
8107 data = ocp_reg_read(tp, 0xbf84); in r8156b_hw_phy_cfg()
8110 ocp_reg_write(tp, 0xbf84, data); in r8156b_hw_phy_cfg()
8117 data = ocp_reg_read(tp, OCP_INTR_EN); in r8156b_hw_phy_cfg()
8119 ocp_reg_write(tp, OCP_INTR_EN, data); in r8156b_hw_phy_cfg()
8121 if (rtl_phy_patch_request(tp, true, true)) in r8156b_hw_phy_cfg()
8124 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4); in r8156b_hw_phy_cfg()
8126 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4, ocp_data); in r8156b_hw_phy_cfg()
8128 data = ocp_reg_read(tp, OCP_DOWN_SPEED); in r8156b_hw_phy_cfg()
8131 ocp_reg_write(tp, OCP_DOWN_SPEED, data); in r8156b_hw_phy_cfg()
8132 tp->ups_info._10m_ckdiv = true; in r8156b_hw_phy_cfg()
8133 tp->ups_info.eee_plloff_100 = false; in r8156b_hw_phy_cfg()
8134 tp->ups_info.eee_plloff_giga = false; in r8156b_hw_phy_cfg()
8136 data = ocp_reg_read(tp, OCP_POWER_CFG); in r8156b_hw_phy_cfg()
8138 ocp_reg_write(tp, OCP_POWER_CFG, data); in r8156b_hw_phy_cfg()
8139 tp->ups_info.eee_ckdiv = false; in r8156b_hw_phy_cfg()
8141 rtl_phy_patch_request(tp, false, true); in r8156b_hw_phy_cfg()
8143 rtl_green_en(tp, test_bit(GREEN_ETHERNET, &tp->flags)); in r8156b_hw_phy_cfg()
8145 data = ocp_reg_read(tp, 0xa428); in r8156b_hw_phy_cfg()
8147 ocp_reg_write(tp, 0xa428, data); in r8156b_hw_phy_cfg()
8148 data = ocp_reg_read(tp, 0xa5ea); in r8156b_hw_phy_cfg()
8150 ocp_reg_write(tp, 0xa5ea, data); in r8156b_hw_phy_cfg()
8151 tp->ups_info.lite_mode = 0; in r8156b_hw_phy_cfg()
8153 if (tp->eee_en) in r8156b_hw_phy_cfg()
8154 rtl_eee_enable(tp, true); in r8156b_hw_phy_cfg()
8156 r8153_aldps_en(tp, true); in r8156b_hw_phy_cfg()
8157 r8152b_enable_fc(tp); in r8156b_hw_phy_cfg()
8158 r8153_u2p3en(tp, true); in r8156b_hw_phy_cfg()
8160 set_bit(PHY_RESET, &tp->flags); in r8156b_hw_phy_cfg()
8163 static void r8156_init(struct r8152 *tp) in r8156_init() argument
8169 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8156_init()
8172 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_ECM_OP); in r8156_init()
8174 ocp_write_byte(tp, MCU_TYPE_USB, USB_ECM_OP, ocp_data); in r8156_init()
8176 ocp_write_word(tp, MCU_TYPE_USB, USB_SPEED_OPTION, 0); in r8156_init()
8178 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_ECM_OPTION); in r8156_init()
8180 ocp_write_word(tp, MCU_TYPE_USB, USB_ECM_OPTION, ocp_data); in r8156_init()
8182 r8153b_u1u2en(tp, false); in r8156_init()
8185 if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) & in r8156_init()
8190 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8156_init()
8194 data = r8153_phy_status(tp, 0); in r8156_init()
8196 data = ocp_reg_read(tp, 0xa468); in r8156_init()
8198 ocp_reg_write(tp, 0xa468, data); in r8156_init()
8201 data = r8152_mdio_read(tp, MII_BMCR); in r8156_init()
8204 r8152_mdio_write(tp, MII_BMCR, data); in r8156_init()
8207 data = r8153_phy_status(tp, PHY_STAT_LAN_ON); in r8156_init()
8210 r8153_u2p3en(tp, false); in r8156_init()
8213 ocp_write_word(tp, MCU_TYPE_USB, USB_MSC_TIMER, 0x0fff); in r8156_init()
8216 ocp_write_word(tp, MCU_TYPE_USB, USB_U1U2_TIMER, 500); in r8156_init()
8218 r8153b_power_cut_en(tp, false); in r8156_init()
8219 r8156_ups_en(tp, false); in r8156_init()
8220 r8153_queue_wake(tp, false); in r8156_init()
8221 rtl_runtime_suspend_enable(tp, false); in r8156_init()
8223 if (tp->udev->speed >= USB_SPEED_SUPER) in r8156_init()
8224 r8153b_u1u2en(tp, true); in r8156_init()
8226 usb_enable_lpm(tp->udev); in r8156_init()
8228 r8156_mac_clk_spd(tp, true); in r8156_init()
8230 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3); in r8156_init()
8232 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data); in r8156_init()
8234 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS); in r8156_init()
8235 if (rtl8152_get_speed(tp) & LINK_STATUS) in r8156_init()
8240 ocp_write_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS, ocp_data); in r8156_init()
8242 set_bit(GREEN_ETHERNET, &tp->flags); in r8156_init()
8245 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL); in r8156_init()
8247 ocp_write_word(tp, MCU_TYPE_USB, USB_USB_CTRL, ocp_data); in r8156_init()
8249 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_BMU_CONFIG); in r8156_init()
8251 ocp_write_byte(tp, MCU_TYPE_USB, USB_BMU_CONFIG, ocp_data); in r8156_init()
8253 r8156_mdio_force_mode(tp); in r8156_init()
8254 rtl_tally_reset(tp); in r8156_init()
8256 tp->coalesce = 15000; /* 15 us */ in r8156_init()
8259 static void r8156b_init(struct r8152 *tp) in r8156b_init() argument
8265 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8156b_init()
8268 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_ECM_OP); in r8156b_init()
8270 ocp_write_byte(tp, MCU_TYPE_USB, USB_ECM_OP, ocp_data); in r8156b_init()
8272 ocp_write_word(tp, MCU_TYPE_USB, USB_SPEED_OPTION, 0); in r8156b_init()
8274 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_ECM_OPTION); in r8156b_init()
8276 ocp_write_word(tp, MCU_TYPE_USB, USB_ECM_OPTION, ocp_data); in r8156b_init()
8278 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_U2P3_CTRL); in r8156b_init()
8280 ocp_write_word(tp, MCU_TYPE_USB, USB_U2P3_CTRL, ocp_data); in r8156b_init()
8282 r8153b_u1u2en(tp, false); in r8156b_init()
8284 switch (tp->version) { in r8156b_init()
8287 r8156b_wait_loading_flash(tp); in r8156b_init()
8294 if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) & in r8156b_init()
8299 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in r8156b_init()
8303 data = r8153_phy_status(tp, 0); in r8156b_init()
8305 data = ocp_reg_read(tp, 0xa468); in r8156b_init()
8307 ocp_reg_write(tp, 0xa468, data); in r8156b_init()
8309 data = ocp_reg_read(tp, 0xa466); in r8156b_init()
8311 ocp_reg_write(tp, 0xa466, data); in r8156b_init()
8314 data = r8152_mdio_read(tp, MII_BMCR); in r8156b_init()
8317 r8152_mdio_write(tp, MII_BMCR, data); in r8156b_init()
8320 data = r8153_phy_status(tp, PHY_STAT_LAN_ON); in r8156b_init()
8322 r8153_u2p3en(tp, false); in r8156b_init()
8325 ocp_write_word(tp, MCU_TYPE_USB, USB_MSC_TIMER, 0x0fff); in r8156b_init()
8328 ocp_write_word(tp, MCU_TYPE_USB, USB_U1U2_TIMER, 500); in r8156b_init()
8330 r8153b_power_cut_en(tp, false); in r8156b_init()
8331 r8156_ups_en(tp, false); in r8156b_init()
8332 r8153_queue_wake(tp, false); in r8156b_init()
8333 rtl_runtime_suspend_enable(tp, false); in r8156b_init()
8335 if (tp->udev->speed >= USB_SPEED_SUPER) in r8156b_init()
8336 r8153b_u1u2en(tp, true); in r8156b_init()
8338 usb_enable_lpm(tp->udev); in r8156b_init()
8340 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_RCR); in r8156b_init()
8342 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); in r8156b_init()
8344 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CPCR); in r8156b_init()
8346 ocp_write_word(tp, MCU_TYPE_PLA, PLA_CPCR, ocp_data); in r8156b_init()
8349 ocp_write_word(tp, MCU_TYPE_USB, USB_FC_TIMER, in r8156b_init()
8352 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_CTRL); in r8156b_init()
8353 if (!(ocp_read_word(tp, MCU_TYPE_PLA, PLA_POL_GPIO_CTRL) & DACK_DET_EN)) in r8156b_init()
8356 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_CTRL, ocp_data); in r8156b_init()
8358 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_TASK); in r8156b_init()
8360 ocp_write_word(tp, MCU_TYPE_USB, USB_FW_TASK, ocp_data); in r8156b_init()
8362 r8156_mac_clk_spd(tp, true); in r8156b_init()
8364 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3); in r8156b_init()
8366 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data); in r8156b_init()
8368 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS); in r8156b_init()
8369 if (rtl8152_get_speed(tp) & LINK_STATUS) in r8156b_init()
8374 ocp_write_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS, ocp_data); in r8156b_init()
8376 set_bit(GREEN_ETHERNET, &tp->flags); in r8156b_init()
8379 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL); in r8156b_init()
8381 ocp_write_word(tp, MCU_TYPE_USB, USB_USB_CTRL, ocp_data); in r8156b_init()
8383 r8156_mdio_force_mode(tp); in r8156b_init()
8384 rtl_tally_reset(tp); in r8156b_init()
8386 tp->coalesce = 15000; /* 15 us */ in r8156b_init()
8422 struct r8152 *tp = usb_get_intfdata(intf); in rtl8152_pre_reset() local
8427 if (!tp || !test_bit(PROBED_WITH_NO_ERRORS, &tp->flags)) in rtl8152_pre_reset()
8430 netdev = tp->netdev; in rtl8152_pre_reset()
8435 tasklet_disable(&tp->tx_tl); in rtl8152_pre_reset()
8436 clear_bit(WORK_ENABLE, &tp->flags); in rtl8152_pre_reset()
8437 usb_kill_urb(tp->intr_urb); in rtl8152_pre_reset()
8438 cancel_delayed_work_sync(&tp->schedule); in rtl8152_pre_reset()
8439 napi_disable(&tp->napi); in rtl8152_pre_reset()
8441 mutex_lock(&tp->control); in rtl8152_pre_reset()
8442 set_bit(IN_PRE_RESET, &tp->flags); in rtl8152_pre_reset()
8443 tp->rtl_ops.disable(tp); in rtl8152_pre_reset()
8444 clear_bit(IN_PRE_RESET, &tp->flags); in rtl8152_pre_reset()
8445 mutex_unlock(&tp->control); in rtl8152_pre_reset()
8453 struct r8152 *tp = usb_get_intfdata(intf); in rtl8152_post_reset() local
8457 if (!tp || !test_bit(PROBED_WITH_NO_ERRORS, &tp->flags)) in rtl8152_post_reset()
8460 rtl_set_accessible(tp); in rtl8152_post_reset()
8463 if (determine_ethernet_addr(tp, &sa) >= 0) in rtl8152_post_reset()
8464 dev_set_mac_address (tp->netdev, &sa, NULL); in rtl8152_post_reset()
8466 netdev = tp->netdev; in rtl8152_post_reset()
8470 set_bit(WORK_ENABLE, &tp->flags); in rtl8152_post_reset()
8472 mutex_lock(&tp->control); in rtl8152_post_reset()
8473 tp->rtl_ops.enable(tp); in rtl8152_post_reset()
8474 rtl_start_rx(tp); in rtl8152_post_reset()
8476 mutex_unlock(&tp->control); in rtl8152_post_reset()
8479 napi_enable(&tp->napi); in rtl8152_post_reset()
8480 tasklet_enable(&tp->tx_tl); in rtl8152_post_reset()
8482 usb_submit_urb(tp->intr_urb, GFP_KERNEL); in rtl8152_post_reset()
8484 if (!list_empty(&tp->rx_done)) in rtl8152_post_reset()
8485 napi_schedule(&tp->napi); in rtl8152_post_reset()
8492 static bool delay_autosuspend(struct r8152 *tp) in delay_autosuspend() argument
8494 bool sw_linking = !!netif_carrier_ok(tp->netdev); in delay_autosuspend()
8495 bool hw_linking = !!(rtl8152_get_speed(tp) & LINK_STATUS); in delay_autosuspend()
8501 if (work_busy(&tp->schedule.work) || sw_linking != hw_linking) in delay_autosuspend()
8507 if (!sw_linking && tp->rtl_ops.in_nway(tp)) in delay_autosuspend()
8509 else if (!skb_queue_empty(&tp->tx_queue)) in delay_autosuspend()
8515 static int rtl8152_runtime_resume(struct r8152 *tp) in rtl8152_runtime_resume() argument
8517 struct net_device *netdev = tp->netdev; in rtl8152_runtime_resume()
8520 struct napi_struct *napi = &tp->napi; in rtl8152_runtime_resume()
8522 tp->rtl_ops.autosuspend_en(tp, false); in rtl8152_runtime_resume()
8524 set_bit(WORK_ENABLE, &tp->flags); in rtl8152_runtime_resume()
8527 if (rtl8152_get_speed(tp) & LINK_STATUS) { in rtl8152_runtime_resume()
8528 rtl_start_rx(tp); in rtl8152_runtime_resume()
8531 tp->rtl_ops.disable(tp); in rtl8152_runtime_resume()
8532 netif_info(tp, link, netdev, "linking down\n"); in rtl8152_runtime_resume()
8537 clear_bit(SELECTIVE_SUSPEND, &tp->flags); in rtl8152_runtime_resume()
8540 if (!list_empty(&tp->rx_done)) in rtl8152_runtime_resume()
8541 napi_schedule(&tp->napi); in rtl8152_runtime_resume()
8543 usb_submit_urb(tp->intr_urb, GFP_NOIO); in rtl8152_runtime_resume()
8546 tp->rtl_ops.autosuspend_en(tp, false); in rtl8152_runtime_resume()
8548 clear_bit(SELECTIVE_SUSPEND, &tp->flags); in rtl8152_runtime_resume()
8554 static int rtl8152_system_resume(struct r8152 *tp) in rtl8152_system_resume() argument
8556 struct net_device *netdev = tp->netdev; in rtl8152_system_resume()
8561 tp->rtl_ops.up(tp); in rtl8152_system_resume()
8563 set_bit(WORK_ENABLE, &tp->flags); in rtl8152_system_resume()
8564 usb_submit_urb(tp->intr_urb, GFP_NOIO); in rtl8152_system_resume()
8577 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl8152_system_resume()
8578 usb_reset_device(tp->udev); in rtl8152_system_resume()
8583 static int rtl8152_runtime_suspend(struct r8152 *tp) in rtl8152_runtime_suspend() argument
8585 struct net_device *netdev = tp->netdev; in rtl8152_runtime_suspend()
8588 if (!tp->rtl_ops.autosuspend_en) in rtl8152_runtime_suspend()
8591 set_bit(SELECTIVE_SUSPEND, &tp->flags); in rtl8152_runtime_suspend()
8594 if (netif_running(netdev) && test_bit(WORK_ENABLE, &tp->flags)) { in rtl8152_runtime_suspend()
8600 rcr = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); in rtl8152_runtime_suspend()
8602 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); in rtl8152_runtime_suspend()
8603 rxdy_gated_en(tp, true); in rtl8152_runtime_suspend()
8604 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, in rtl8152_runtime_suspend()
8607 rxdy_gated_en(tp, false); in rtl8152_runtime_suspend()
8608 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, rcr); in rtl8152_runtime_suspend()
8609 clear_bit(SELECTIVE_SUSPEND, &tp->flags); in rtl8152_runtime_suspend()
8616 clear_bit(WORK_ENABLE, &tp->flags); in rtl8152_runtime_suspend()
8617 usb_kill_urb(tp->intr_urb); in rtl8152_runtime_suspend()
8619 tp->rtl_ops.autosuspend_en(tp, true); in rtl8152_runtime_suspend()
8622 struct napi_struct *napi = &tp->napi; in rtl8152_runtime_suspend()
8625 rtl_stop_rx(tp); in rtl8152_runtime_suspend()
8626 rxdy_gated_en(tp, false); in rtl8152_runtime_suspend()
8627 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, rcr); in rtl8152_runtime_suspend()
8631 if (delay_autosuspend(tp)) { in rtl8152_runtime_suspend()
8632 rtl8152_runtime_resume(tp); in rtl8152_runtime_suspend()
8641 static int rtl8152_system_suspend(struct r8152 *tp) in rtl8152_system_suspend() argument
8643 struct net_device *netdev = tp->netdev; in rtl8152_system_suspend()
8647 if (netif_running(netdev) && test_bit(WORK_ENABLE, &tp->flags)) { in rtl8152_system_suspend()
8648 struct napi_struct *napi = &tp->napi; in rtl8152_system_suspend()
8650 clear_bit(WORK_ENABLE, &tp->flags); in rtl8152_system_suspend()
8651 usb_kill_urb(tp->intr_urb); in rtl8152_system_suspend()
8652 tasklet_disable(&tp->tx_tl); in rtl8152_system_suspend()
8654 cancel_delayed_work_sync(&tp->schedule); in rtl8152_system_suspend()
8655 tp->rtl_ops.down(tp); in rtl8152_system_suspend()
8657 tasklet_enable(&tp->tx_tl); in rtl8152_system_suspend()
8664 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl8152_system_suspend()
8665 pm_wakeup_event(&tp->udev->dev, 0); in rtl8152_system_suspend()
8672 struct r8152 *tp = usb_get_intfdata(intf); in rtl8152_suspend() local
8675 mutex_lock(&tp->control); in rtl8152_suspend()
8678 ret = rtl8152_runtime_suspend(tp); in rtl8152_suspend()
8680 ret = rtl8152_system_suspend(tp); in rtl8152_suspend()
8682 mutex_unlock(&tp->control); in rtl8152_suspend()
8689 struct r8152 *tp = usb_get_intfdata(intf); in rtl8152_resume() local
8692 mutex_lock(&tp->control); in rtl8152_resume()
8694 rtl_reset_ocp_base(tp); in rtl8152_resume()
8696 if (test_bit(SELECTIVE_SUSPEND, &tp->flags)) in rtl8152_resume()
8697 ret = rtl8152_runtime_resume(tp); in rtl8152_resume()
8699 ret = rtl8152_system_resume(tp); in rtl8152_resume()
8701 mutex_unlock(&tp->control); in rtl8152_resume()
8708 struct r8152 *tp = usb_get_intfdata(intf); in rtl8152_reset_resume() local
8710 clear_bit(SELECTIVE_SUSPEND, &tp->flags); in rtl8152_reset_resume()
8711 rtl_reset_ocp_base(tp); in rtl8152_reset_resume()
8712 tp->rtl_ops.init(tp); in rtl8152_reset_resume()
8713 queue_delayed_work(system_long_wq, &tp->hw_phy_work, 0); in rtl8152_reset_resume()
8714 set_ethernet_addr(tp, true); in rtl8152_reset_resume()
8720 struct r8152 *tp = netdev_priv(dev); in rtl8152_get_wol() local
8722 if (usb_autopm_get_interface(tp->intf) < 0) in rtl8152_get_wol()
8725 if (!rtl_can_wakeup(tp)) { in rtl8152_get_wol()
8729 mutex_lock(&tp->control); in rtl8152_get_wol()
8731 wol->wolopts = __rtl_get_wol(tp); in rtl8152_get_wol()
8732 mutex_unlock(&tp->control); in rtl8152_get_wol()
8735 usb_autopm_put_interface(tp->intf); in rtl8152_get_wol()
8740 struct r8152 *tp = netdev_priv(dev); in rtl8152_set_wol() local
8743 if (!rtl_can_wakeup(tp)) in rtl8152_set_wol()
8749 ret = usb_autopm_get_interface(tp->intf); in rtl8152_set_wol()
8753 mutex_lock(&tp->control); in rtl8152_set_wol()
8755 __rtl_set_wol(tp, wol->wolopts); in rtl8152_set_wol()
8756 tp->saved_wolopts = wol->wolopts & WAKE_ANY; in rtl8152_set_wol()
8758 mutex_unlock(&tp->control); in rtl8152_set_wol()
8760 usb_autopm_put_interface(tp->intf); in rtl8152_set_wol()
8768 struct r8152 *tp = netdev_priv(dev); in rtl8152_get_msglevel() local
8770 return tp->msg_enable; in rtl8152_get_msglevel()
8775 struct r8152 *tp = netdev_priv(dev); in rtl8152_set_msglevel() local
8777 tp->msg_enable = value; in rtl8152_set_msglevel()
8783 struct r8152 *tp = netdev_priv(netdev); in rtl8152_get_drvinfo() local
8787 usb_make_path(tp->udev, info->bus_info, sizeof(info->bus_info)); in rtl8152_get_drvinfo()
8788 if (!IS_ERR_OR_NULL(tp->rtl_fw.fw)) in rtl8152_get_drvinfo()
8789 strscpy(info->fw_version, tp->rtl_fw.version, in rtl8152_get_drvinfo()
8797 struct r8152 *tp = netdev_priv(netdev); in rtl8152_get_link_ksettings() local
8800 if (!tp->mii.mdio_read) in rtl8152_get_link_ksettings()
8803 ret = usb_autopm_get_interface(tp->intf); in rtl8152_get_link_ksettings()
8807 mutex_lock(&tp->control); in rtl8152_get_link_ksettings()
8809 mii_ethtool_get_link_ksettings(&tp->mii, cmd); in rtl8152_get_link_ksettings()
8812 cmd->link_modes.supported, tp->support_2500full); in rtl8152_get_link_ksettings()
8814 if (tp->support_2500full) { in rtl8152_get_link_ksettings()
8817 ocp_reg_read(tp, OCP_10GBT_CTRL) & MDIO_AN_10GBT_CTRL_ADV2_5G); in rtl8152_get_link_ksettings()
8821 ocp_reg_read(tp, OCP_10GBT_STAT) & MDIO_AN_10GBT_STAT_LP2_5G); in rtl8152_get_link_ksettings()
8823 if (is_speed_2500(rtl8152_get_speed(tp))) in rtl8152_get_link_ksettings()
8827 mutex_unlock(&tp->control); in rtl8152_get_link_ksettings()
8829 usb_autopm_put_interface(tp->intf); in rtl8152_get_link_ksettings()
8838 struct r8152 *tp = netdev_priv(dev); in rtl8152_set_link_ksettings() local
8842 ret = usb_autopm_get_interface(tp->intf); in rtl8152_set_link_ksettings()
8874 mutex_lock(&tp->control); in rtl8152_set_link_ksettings()
8876 ret = rtl8152_set_speed(tp, cmd->base.autoneg, cmd->base.speed, in rtl8152_set_link_ksettings()
8879 tp->autoneg = cmd->base.autoneg; in rtl8152_set_link_ksettings()
8880 tp->speed = cmd->base.speed; in rtl8152_set_link_ksettings()
8881 tp->duplex = cmd->base.duplex; in rtl8152_set_link_ksettings()
8882 tp->advertising = advertising; in rtl8152_set_link_ksettings()
8885 mutex_unlock(&tp->control); in rtl8152_set_link_ksettings()
8887 usb_autopm_put_interface(tp->intf); in rtl8152_set_link_ksettings()
8922 struct r8152 *tp = netdev_priv(dev); in rtl8152_get_ethtool_stats() local
8925 if (usb_autopm_get_interface(tp->intf) < 0) in rtl8152_get_ethtool_stats()
8928 generic_ocp_read(tp, PLA_TALLYCNT, sizeof(tally), &tally, MCU_TYPE_PLA); in rtl8152_get_ethtool_stats()
8930 usb_autopm_put_interface(tp->intf); in rtl8152_get_ethtool_stats()
8956 static int r8152_get_eee(struct r8152 *tp, struct ethtool_keee *eee) in r8152_get_eee() argument
8961 val = r8152_mmd_read(tp, MDIO_MMD_PCS, MDIO_PCS_EEE_ABLE); in r8152_get_eee()
8964 val = r8152_mmd_read(tp, MDIO_MMD_AN, MDIO_AN_EEE_ADV); in r8152_get_eee()
8967 val = r8152_mmd_read(tp, MDIO_MMD_AN, MDIO_AN_EEE_LPABLE); in r8152_get_eee()
8970 eee->eee_enabled = tp->eee_en; in r8152_get_eee()
8973 eee->eee_active = phy_check_valid(tp->speed, tp->duplex, common); in r8152_get_eee()
8978 static int r8152_set_eee(struct r8152 *tp, struct ethtool_keee *eee) in r8152_set_eee() argument
8982 tp->eee_en = eee->eee_enabled; in r8152_set_eee()
8983 tp->eee_adv = val; in r8152_set_eee()
8985 rtl_eee_enable(tp, tp->eee_en); in r8152_set_eee()
8990 static int r8153_get_eee(struct r8152 *tp, struct ethtool_keee *eee) in r8153_get_eee() argument
8995 val = ocp_reg_read(tp, OCP_EEE_ABLE); in r8153_get_eee()
8998 val = ocp_reg_read(tp, OCP_EEE_ADV); in r8153_get_eee()
9001 val = ocp_reg_read(tp, OCP_EEE_LPABLE); in r8153_get_eee()
9004 eee->eee_enabled = tp->eee_en; in r8153_get_eee()
9007 eee->eee_active = phy_check_valid(tp->speed, tp->duplex, common); in r8153_get_eee()
9015 struct r8152 *tp = netdev_priv(net); in rtl_ethtool_get_eee() local
9018 if (!tp->rtl_ops.eee_get) { in rtl_ethtool_get_eee()
9023 ret = usb_autopm_get_interface(tp->intf); in rtl_ethtool_get_eee()
9027 mutex_lock(&tp->control); in rtl_ethtool_get_eee()
9029 ret = tp->rtl_ops.eee_get(tp, edata); in rtl_ethtool_get_eee()
9031 mutex_unlock(&tp->control); in rtl_ethtool_get_eee()
9033 usb_autopm_put_interface(tp->intf); in rtl_ethtool_get_eee()
9042 struct r8152 *tp = netdev_priv(net); in rtl_ethtool_set_eee() local
9045 if (!tp->rtl_ops.eee_set) { in rtl_ethtool_set_eee()
9050 ret = usb_autopm_get_interface(tp->intf); in rtl_ethtool_set_eee()
9054 mutex_lock(&tp->control); in rtl_ethtool_set_eee()
9056 ret = tp->rtl_ops.eee_set(tp, edata); in rtl_ethtool_set_eee()
9058 ret = mii_nway_restart(&tp->mii); in rtl_ethtool_set_eee()
9060 mutex_unlock(&tp->control); in rtl_ethtool_set_eee()
9062 usb_autopm_put_interface(tp->intf); in rtl_ethtool_set_eee()
9070 struct r8152 *tp = netdev_priv(dev); in rtl8152_nway_reset() local
9073 ret = usb_autopm_get_interface(tp->intf); in rtl8152_nway_reset()
9077 mutex_lock(&tp->control); in rtl8152_nway_reset()
9079 ret = mii_nway_restart(&tp->mii); in rtl8152_nway_reset()
9081 mutex_unlock(&tp->control); in rtl8152_nway_reset()
9083 usb_autopm_put_interface(tp->intf); in rtl8152_nway_reset()
9094 struct r8152 *tp = netdev_priv(netdev); in rtl8152_get_coalesce() local
9096 switch (tp->version) { in rtl8152_get_coalesce()
9105 coalesce->rx_coalesce_usecs = tp->coalesce; in rtl8152_get_coalesce()
9115 struct r8152 *tp = netdev_priv(netdev); in rtl8152_set_coalesce() local
9118 switch (tp->version) { in rtl8152_set_coalesce()
9130 ret = usb_autopm_get_interface(tp->intf); in rtl8152_set_coalesce()
9134 mutex_lock(&tp->control); in rtl8152_set_coalesce()
9136 if (tp->coalesce != coalesce->rx_coalesce_usecs) { in rtl8152_set_coalesce()
9137 tp->coalesce = coalesce->rx_coalesce_usecs; in rtl8152_set_coalesce()
9141 napi_disable(&tp->napi); in rtl8152_set_coalesce()
9142 tp->rtl_ops.disable(tp); in rtl8152_set_coalesce()
9143 tp->rtl_ops.enable(tp); in rtl8152_set_coalesce()
9144 rtl_start_rx(tp); in rtl8152_set_coalesce()
9145 clear_bit(RTL8152_SET_RX_MODE, &tp->flags); in rtl8152_set_coalesce()
9147 napi_enable(&tp->napi); in rtl8152_set_coalesce()
9152 mutex_unlock(&tp->control); in rtl8152_set_coalesce()
9154 usb_autopm_put_interface(tp->intf); in rtl8152_set_coalesce()
9162 struct r8152 *tp = netdev_priv(netdev); in rtl8152_get_tunable() local
9166 *(u32 *)d = tp->rx_copybreak; in rtl8152_get_tunable()
9179 struct r8152 *tp = netdev_priv(netdev); in rtl8152_set_tunable() local
9186 netif_err(tp, rx_err, netdev, in rtl8152_set_tunable()
9191 if (tp->rx_copybreak != val) { in rtl8152_set_tunable()
9193 mutex_lock(&tp->control); in rtl8152_set_tunable()
9194 napi_disable(&tp->napi); in rtl8152_set_tunable()
9195 tp->rx_copybreak = val; in rtl8152_set_tunable()
9196 napi_enable(&tp->napi); in rtl8152_set_tunable()
9197 mutex_unlock(&tp->control); in rtl8152_set_tunable()
9199 tp->rx_copybreak = val; in rtl8152_set_tunable()
9215 struct r8152 *tp = netdev_priv(netdev); in rtl8152_get_ringparam() local
9218 ring->rx_pending = tp->rx_pending; in rtl8152_get_ringparam()
9226 struct r8152 *tp = netdev_priv(netdev); in rtl8152_set_ringparam() local
9231 if (tp->rx_pending != ring->rx_pending) { in rtl8152_set_ringparam()
9233 mutex_lock(&tp->control); in rtl8152_set_ringparam()
9234 napi_disable(&tp->napi); in rtl8152_set_ringparam()
9235 tp->rx_pending = ring->rx_pending; in rtl8152_set_ringparam()
9236 napi_enable(&tp->napi); in rtl8152_set_ringparam()
9237 mutex_unlock(&tp->control); in rtl8152_set_ringparam()
9239 tp->rx_pending = ring->rx_pending; in rtl8152_set_ringparam()
9248 struct r8152 *tp = netdev_priv(netdev); in rtl8152_get_pauseparam() local
9252 if (usb_autopm_get_interface(tp->intf) < 0) in rtl8152_get_pauseparam()
9255 mutex_lock(&tp->control); in rtl8152_get_pauseparam()
9257 bmcr = r8152_mdio_read(tp, MII_BMCR); in rtl8152_get_pauseparam()
9258 lcladv = r8152_mdio_read(tp, MII_ADVERTISE); in rtl8152_get_pauseparam()
9259 rmtadv = r8152_mdio_read(tp, MII_LPA); in rtl8152_get_pauseparam()
9261 mutex_unlock(&tp->control); in rtl8152_get_pauseparam()
9263 usb_autopm_put_interface(tp->intf); in rtl8152_get_pauseparam()
9285 struct r8152 *tp = netdev_priv(netdev); in rtl8152_set_pauseparam() local
9290 ret = usb_autopm_get_interface(tp->intf); in rtl8152_set_pauseparam()
9294 mutex_lock(&tp->control); in rtl8152_set_pauseparam()
9296 if (pause->autoneg && !(r8152_mdio_read(tp, MII_BMCR) & BMCR_ANENABLE)) { in rtl8152_set_pauseparam()
9307 old = r8152_mdio_read(tp, MII_ADVERTISE); in rtl8152_set_pauseparam()
9310 r8152_mdio_write(tp, MII_ADVERTISE, new1); in rtl8152_set_pauseparam()
9313 mutex_unlock(&tp->control); in rtl8152_set_pauseparam()
9314 usb_autopm_put_interface(tp->intf); in rtl8152_set_pauseparam()
9347 struct r8152 *tp = netdev_priv(netdev); in rtl8152_ioctl() local
9351 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl8152_ioctl()
9354 res = usb_autopm_get_interface(tp->intf); in rtl8152_ioctl()
9364 mutex_lock(&tp->control); in rtl8152_ioctl()
9365 data->val_out = r8152_mdio_read(tp, data->reg_num); in rtl8152_ioctl()
9366 mutex_unlock(&tp->control); in rtl8152_ioctl()
9374 mutex_lock(&tp->control); in rtl8152_ioctl()
9375 r8152_mdio_write(tp, data->reg_num, data->val_in); in rtl8152_ioctl()
9376 mutex_unlock(&tp->control); in rtl8152_ioctl()
9383 usb_autopm_put_interface(tp->intf); in rtl8152_ioctl()
9391 struct r8152 *tp = netdev_priv(dev); in rtl8152_change_mtu() local
9394 switch (tp->version) { in rtl8152_change_mtu()
9404 ret = usb_autopm_get_interface(tp->intf); in rtl8152_change_mtu()
9408 mutex_lock(&tp->control); in rtl8152_change_mtu()
9413 if (tp->rtl_ops.change_mtu) in rtl8152_change_mtu()
9414 tp->rtl_ops.change_mtu(tp); in rtl8152_change_mtu()
9418 napi_disable(&tp->napi); in rtl8152_change_mtu()
9419 tasklet_disable(&tp->tx_tl); in rtl8152_change_mtu()
9420 tp->rtl_ops.disable(tp); in rtl8152_change_mtu()
9421 tp->rtl_ops.enable(tp); in rtl8152_change_mtu()
9422 rtl_start_rx(tp); in rtl8152_change_mtu()
9423 tasklet_enable(&tp->tx_tl); in rtl8152_change_mtu()
9424 napi_enable(&tp->napi); in rtl8152_change_mtu()
9430 mutex_unlock(&tp->control); in rtl8152_change_mtu()
9432 usb_autopm_put_interface(tp->intf); in rtl8152_change_mtu()
9451 static void rtl8152_unload(struct r8152 *tp) in rtl8152_unload() argument
9453 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl8152_unload()
9456 if (tp->version != RTL_VER_01) in rtl8152_unload()
9457 r8152_power_cut_en(tp, true); in rtl8152_unload()
9460 static void rtl8153_unload(struct r8152 *tp) in rtl8153_unload() argument
9462 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl8153_unload()
9465 r8153_power_cut_en(tp, false); in rtl8153_unload()
9468 static void rtl8153b_unload(struct r8152 *tp) in rtl8153b_unload() argument
9470 if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) in rtl8153b_unload()
9473 r8153b_power_cut_en(tp, false); in rtl8153b_unload()
9476 static int rtl_ops_init(struct r8152 *tp) in rtl_ops_init() argument
9478 struct rtl_ops *ops = &tp->rtl_ops; in rtl_ops_init()
9481 switch (tp->version) { in rtl_ops_init()
9496 tp->rx_buf_sz = 16 * 1024; in rtl_ops_init()
9497 tp->eee_en = true; in rtl_ops_init()
9498 tp->eee_adv = MDIO_EEE_100TX; in rtl_ops_init()
9517 if (tp->udev->speed < USB_SPEED_SUPER) in rtl_ops_init()
9518 tp->rx_buf_sz = 16 * 1024; in rtl_ops_init()
9520 tp->rx_buf_sz = 32 * 1024; in rtl_ops_init()
9521 tp->eee_en = true; in rtl_ops_init()
9522 tp->eee_adv = MDIO_EEE_1000T | MDIO_EEE_100TX; in rtl_ops_init()
9539 tp->rx_buf_sz = 32 * 1024; in rtl_ops_init()
9540 tp->eee_en = true; in rtl_ops_init()
9541 tp->eee_adv = MDIO_EEE_1000T | MDIO_EEE_100TX; in rtl_ops_init()
9545 tp->eee_en = true; in rtl_ops_init()
9546 tp->eee_adv = MDIO_EEE_1000T | MDIO_EEE_100TX; in rtl_ops_init()
9561 tp->rx_buf_sz = 48 * 1024; in rtl_ops_init()
9562 tp->support_2500full = 1; in rtl_ops_init()
9567 tp->support_2500full = 1; in rtl_ops_init()
9570 tp->eee_en = true; in rtl_ops_init()
9571 tp->eee_adv = MDIO_EEE_1000T | MDIO_EEE_100TX; in rtl_ops_init()
9584 tp->rx_buf_sz = 48 * 1024; in rtl_ops_init()
9600 tp->rx_buf_sz = 32 * 1024; in rtl_ops_init()
9601 tp->eee_en = true; in rtl_ops_init()
9602 tp->eee_adv = MDIO_EEE_1000T | MDIO_EEE_100TX; in rtl_ops_init()
9607 dev_err(&tp->intf->dev, "Unknown Device\n"); in rtl_ops_init()
9630 static int rtl_fw_init(struct r8152 *tp) in rtl_fw_init() argument
9632 struct rtl_fw *rtl_fw = &tp->rtl_fw; in rtl_fw_init()
9634 switch (tp->version) { in rtl_fw_init()
9805 struct r8152 *tp; in rtl8152_probe_once() local
9817 tp = netdev_priv(netdev); in rtl8152_probe_once()
9818 tp->msg_enable = 0x7FFF; in rtl8152_probe_once()
9820 tp->udev = udev; in rtl8152_probe_once()
9821 tp->netdev = netdev; in rtl8152_probe_once()
9822 tp->intf = intf; in rtl8152_probe_once()
9823 tp->version = version; in rtl8152_probe_once()
9825 tp->pipe_ctrl_in = usb_rcvctrlpipe(udev, 0); in rtl8152_probe_once()
9826 tp->pipe_ctrl_out = usb_sndctrlpipe(udev, 0); in rtl8152_probe_once()
9827 tp->pipe_in = usb_rcvbulkpipe(udev, 1); in rtl8152_probe_once()
9828 tp->pipe_out = usb_sndbulkpipe(udev, 2); in rtl8152_probe_once()
9829 tp->pipe_intr = usb_rcvintpipe(udev, 3); in rtl8152_probe_once()
9835 tp->mii.supports_gmii = 0; in rtl8152_probe_once()
9838 tp->mii.supports_gmii = 1; in rtl8152_probe_once()
9842 ret = rtl_ops_init(tp); in rtl8152_probe_once()
9846 rtl_fw_init(tp); in rtl8152_probe_once()
9848 mutex_init(&tp->control); in rtl8152_probe_once()
9849 INIT_DELAYED_WORK(&tp->schedule, rtl_work_func_t); in rtl8152_probe_once()
9850 INIT_DELAYED_WORK(&tp->hw_phy_work, rtl_hw_phy_work_func_t); in rtl8152_probe_once()
9851 tasklet_setup(&tp->tx_tl, bottom_half); in rtl8152_probe_once()
9852 tasklet_disable(&tp->tx_tl); in rtl8152_probe_once()
9869 if (tp->version == RTL_VER_01) { in rtl8152_probe_once()
9874 tp->lenovo_macpassthru = rtl8152_supports_lenovo_macpassthru(udev); in rtl8152_probe_once()
9880 tp->dell_tb_rx_agg_bug = 1; in rtl8152_probe_once()
9888 switch (tp->version) { in rtl8152_probe_once()
9915 tp->mii.dev = netdev; in rtl8152_probe_once()
9916 tp->mii.mdio_read = read_mii_word; in rtl8152_probe_once()
9917 tp->mii.mdio_write = write_mii_word; in rtl8152_probe_once()
9918 tp->mii.phy_id_mask = 0x3f; in rtl8152_probe_once()
9919 tp->mii.reg_num_mask = 0x1f; in rtl8152_probe_once()
9920 tp->mii.phy_id = R8152_PHY_ID; in rtl8152_probe_once()
9922 tp->autoneg = AUTONEG_ENABLE; in rtl8152_probe_once()
9923 tp->speed = SPEED_100; in rtl8152_probe_once()
9924 tp->advertising = RTL_ADVERTISED_10_HALF | RTL_ADVERTISED_10_FULL | in rtl8152_probe_once()
9926 if (tp->mii.supports_gmii) { in rtl8152_probe_once()
9927 if (tp->support_2500full && in rtl8152_probe_once()
9928 tp->udev->speed >= USB_SPEED_SUPER) { in rtl8152_probe_once()
9929 tp->speed = SPEED_2500; in rtl8152_probe_once()
9930 tp->advertising |= RTL_ADVERTISED_2500_FULL; in rtl8152_probe_once()
9932 tp->speed = SPEED_1000; in rtl8152_probe_once()
9934 tp->advertising |= RTL_ADVERTISED_1000_FULL; in rtl8152_probe_once()
9936 tp->duplex = DUPLEX_FULL; in rtl8152_probe_once()
9938 tp->rx_copybreak = RTL8152_RXFG_HEADSZ; in rtl8152_probe_once()
9939 tp->rx_pending = 10 * RTL8152_MAX_RX; in rtl8152_probe_once()
9943 if (!rtl_can_wakeup(tp)) in rtl8152_probe_once()
9944 __rtl_set_wol(tp, 0); in rtl8152_probe_once()
9946 tp->saved_wolopts = __rtl_get_wol(tp); in rtl8152_probe_once()
9948 tp->rtl_ops.init(tp); in rtl8152_probe_once()
9951 tp->rtl_fw.retry = true; in rtl8152_probe_once()
9953 queue_delayed_work(system_long_wq, &tp->hw_phy_work, 0); in rtl8152_probe_once()
9954 set_ethernet_addr(tp, false); in rtl8152_probe_once()
9956 usb_set_intfdata(intf, tp); in rtl8152_probe_once()
9958 netif_napi_add(netdev, &tp->napi, r8152_poll); in rtl8152_probe_once()
9966 if (tp->saved_wolopts) in rtl8152_probe_once()
9974 if (test_bit(PROBE_SHOULD_RETRY, &tp->flags)) in rtl8152_probe_once()
9977 set_bit(PROBED_WITH_NO_ERRORS, &tp->flags); in rtl8152_probe_once()
9978 netif_info(tp, probe, netdev, "%s\n", DRIVER_VERSION); in rtl8152_probe_once()
9986 tasklet_kill(&tp->tx_tl); in rtl8152_probe_once()
9987 cancel_delayed_work_sync(&tp->hw_phy_work); in rtl8152_probe_once()
9988 if (tp->rtl_ops.unload) in rtl8152_probe_once()
9989 tp->rtl_ops.unload(tp); in rtl8152_probe_once()
9990 rtl8152_release_firmware(tp); in rtl8152_probe_once()
9993 if (test_bit(PROBE_SHOULD_RETRY, &tp->flags)) in rtl8152_probe_once()
10035 struct r8152 *tp = usb_get_intfdata(intf); in rtl8152_disconnect() local
10038 if (tp) { in rtl8152_disconnect()
10039 rtl_set_unplug(tp); in rtl8152_disconnect()
10041 unregister_netdev(tp->netdev); in rtl8152_disconnect()
10042 tasklet_kill(&tp->tx_tl); in rtl8152_disconnect()
10043 cancel_delayed_work_sync(&tp->hw_phy_work); in rtl8152_disconnect()
10044 if (tp->rtl_ops.unload) in rtl8152_disconnect()
10045 tp->rtl_ops.unload(tp); in rtl8152_disconnect()
10046 rtl8152_release_firmware(tp); in rtl8152_disconnect()
10047 free_netdev(tp->netdev); in rtl8152_disconnect()