Lines Matching full:ndev
344 static void sh_eth_rcv_snd_disable(struct net_device *ndev);
345 static struct net_device_stats *sh_eth_get_stats(struct net_device *ndev);
347 static void sh_eth_write(struct net_device *ndev, u32 data, int enum_index) in sh_eth_write() argument
349 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_write()
358 static u32 sh_eth_read(struct net_device *ndev, int enum_index) in sh_eth_read() argument
360 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_read()
369 static void sh_eth_modify(struct net_device *ndev, int enum_index, u32 clear, in sh_eth_modify() argument
372 sh_eth_write(ndev, (sh_eth_read(ndev, enum_index) & ~clear) | set, in sh_eth_modify()
413 static void sh_eth_select_mii(struct net_device *ndev) in sh_eth_select_mii() argument
415 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_select_mii()
432 netdev_warn(ndev, in sh_eth_select_mii()
438 sh_eth_write(ndev, value, RMII_MII); in sh_eth_select_mii()
441 static void sh_eth_set_duplex(struct net_device *ndev) in sh_eth_set_duplex() argument
443 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_set_duplex()
445 sh_eth_modify(ndev, ECMR, ECMR_DM, mdp->duplex ? ECMR_DM : 0); in sh_eth_set_duplex()
448 static void sh_eth_chip_reset(struct net_device *ndev) in sh_eth_chip_reset() argument
450 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_chip_reset()
457 static int sh_eth_soft_reset(struct net_device *ndev) in sh_eth_soft_reset() argument
459 sh_eth_modify(ndev, EDMR, EDMR_SRST_ETHER, EDMR_SRST_ETHER); in sh_eth_soft_reset()
461 sh_eth_modify(ndev, EDMR, EDMR_SRST_ETHER, 0); in sh_eth_soft_reset()
466 static int sh_eth_check_soft_reset(struct net_device *ndev) in sh_eth_check_soft_reset() argument
471 if (!(sh_eth_read(ndev, EDMR) & EDMR_SRST_GETHER)) in sh_eth_check_soft_reset()
476 netdev_err(ndev, "Device reset failed\n"); in sh_eth_check_soft_reset()
480 static int sh_eth_soft_reset_gether(struct net_device *ndev) in sh_eth_soft_reset_gether() argument
482 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_soft_reset_gether()
485 sh_eth_write(ndev, EDSR_ENALL, EDSR); in sh_eth_soft_reset_gether()
486 sh_eth_modify(ndev, EDMR, EDMR_SRST_GETHER, EDMR_SRST_GETHER); in sh_eth_soft_reset_gether()
488 ret = sh_eth_check_soft_reset(ndev); in sh_eth_soft_reset_gether()
493 sh_eth_write(ndev, 0, TDLAR); in sh_eth_soft_reset_gether()
494 sh_eth_write(ndev, 0, TDFAR); in sh_eth_soft_reset_gether()
495 sh_eth_write(ndev, 0, TDFXR); in sh_eth_soft_reset_gether()
496 sh_eth_write(ndev, 0, TDFFR); in sh_eth_soft_reset_gether()
497 sh_eth_write(ndev, 0, RDLAR); in sh_eth_soft_reset_gether()
498 sh_eth_write(ndev, 0, RDFAR); in sh_eth_soft_reset_gether()
499 sh_eth_write(ndev, 0, RDFXR); in sh_eth_soft_reset_gether()
500 sh_eth_write(ndev, 0, RDFFR); in sh_eth_soft_reset_gether()
504 sh_eth_write(ndev, 0, CSMR); in sh_eth_soft_reset_gether()
508 sh_eth_select_mii(ndev); in sh_eth_soft_reset_gether()
513 static void sh_eth_set_rate_gether(struct net_device *ndev) in sh_eth_set_rate_gether() argument
515 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_set_rate_gether()
522 sh_eth_write(ndev, GECMR_10, GECMR); in sh_eth_set_rate_gether()
525 sh_eth_write(ndev, GECMR_100, GECMR); in sh_eth_set_rate_gether()
528 sh_eth_write(ndev, GECMR_1000, GECMR); in sh_eth_set_rate_gether()
578 static void sh_eth_chip_reset_r8a7740(struct net_device *ndev) in sh_eth_chip_reset_r8a7740() argument
580 sh_eth_chip_reset(ndev); in sh_eth_chip_reset_r8a7740()
582 sh_eth_select_mii(ndev); in sh_eth_chip_reset_r8a7740()
632 static void sh_eth_set_rate_rcar(struct net_device *ndev) in sh_eth_set_rate_rcar() argument
634 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_set_rate_rcar()
638 sh_eth_modify(ndev, ECMR, ECMR_ELB, 0); in sh_eth_set_rate_rcar()
641 sh_eth_modify(ndev, ECMR, ECMR_ELB, ECMR_ELB); in sh_eth_set_rate_rcar()
795 static void sh_eth_set_rate_sh7724(struct net_device *ndev) in sh_eth_set_rate_sh7724() argument
797 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_set_rate_sh7724()
801 sh_eth_modify(ndev, ECMR, ECMR_RTM, 0); in sh_eth_set_rate_sh7724()
804 sh_eth_modify(ndev, ECMR, ECMR_RTM, ECMR_RTM); in sh_eth_set_rate_sh7724()
839 static void sh_eth_set_rate_sh7757(struct net_device *ndev) in sh_eth_set_rate_sh7757() argument
841 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_set_rate_sh7757()
845 sh_eth_write(ndev, 0, RTRATE); in sh_eth_set_rate_sh7757()
848 sh_eth_write(ndev, 1, RTRATE); in sh_eth_set_rate_sh7757()
890 static void sh_eth_chip_reset_giga(struct net_device *ndev) in sh_eth_chip_reset_giga() argument
901 sh_eth_chip_reset(ndev); in sh_eth_chip_reset_giga()
910 static void sh_eth_set_rate_giga(struct net_device *ndev) in sh_eth_set_rate_giga() argument
912 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_set_rate_giga()
919 sh_eth_write(ndev, 0x00000000, GECMR); in sh_eth_set_rate_giga()
922 sh_eth_write(ndev, 0x00000010, GECMR); in sh_eth_set_rate_giga()
925 sh_eth_write(ndev, 0x00000020, GECMR); in sh_eth_set_rate_giga()
1135 static void update_mac_address(struct net_device *ndev) in update_mac_address() argument
1137 sh_eth_write(ndev, in update_mac_address()
1138 (ndev->dev_addr[0] << 24) | (ndev->dev_addr[1] << 16) | in update_mac_address()
1139 (ndev->dev_addr[2] << 8) | (ndev->dev_addr[3]), MAHR); in update_mac_address()
1140 sh_eth_write(ndev, in update_mac_address()
1141 (ndev->dev_addr[4] << 8) | (ndev->dev_addr[5]), MALR); in update_mac_address()
1151 static void read_mac_address(struct net_device *ndev, unsigned char *mac) in read_mac_address() argument
1154 eth_hw_addr_set(ndev, mac); in read_mac_address()
1156 u32 mahr = sh_eth_read(ndev, MAHR); in read_mac_address()
1157 u32 malr = sh_eth_read(ndev, MALR); in read_mac_address()
1166 eth_hw_addr_set(ndev, addr); in read_mac_address()
1231 static int sh_eth_tx_free(struct net_device *ndev, bool sent_only) in sh_eth_tx_free() argument
1233 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_tx_free()
1247 netif_info(mdp, tx_done, ndev, in sh_eth_tx_free()
1265 ndev->stats.tx_packets++; in sh_eth_tx_free()
1266 ndev->stats.tx_bytes += le32_to_cpu(txdesc->len) >> 16; in sh_eth_tx_free()
1273 static void sh_eth_ring_free(struct net_device *ndev) in sh_eth_ring_free() argument
1275 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_ring_free()
1304 sh_eth_tx_free(ndev, false); in sh_eth_ring_free()
1318 static void sh_eth_ring_format(struct net_device *ndev) in sh_eth_ring_format() argument
1320 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_ring_format()
1342 skb = netdev_alloc_skb(ndev, skbuff_size); in sh_eth_ring_format()
1365 sh_eth_write(ndev, mdp->rx_desc_dma, RDLAR); in sh_eth_ring_format()
1367 sh_eth_write(ndev, mdp->rx_desc_dma, RDFAR); in sh_eth_ring_format()
1387 sh_eth_write(ndev, mdp->tx_desc_dma, TDLAR); in sh_eth_ring_format()
1389 sh_eth_write(ndev, mdp->tx_desc_dma, TDFAR); in sh_eth_ring_format()
1397 static int sh_eth_ring_init(struct net_device *ndev) in sh_eth_ring_init() argument
1399 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_ring_init()
1407 mdp->rx_buf_sz = (ndev->mtu <= 1492 ? PKT_BUF_SZ : in sh_eth_ring_init()
1408 (((ndev->mtu + 26 + 7) & ~7) + 2 + 16)); in sh_eth_ring_init()
1442 sh_eth_ring_free(ndev); in sh_eth_ring_init()
1447 static int sh_eth_dev_init(struct net_device *ndev) in sh_eth_dev_init() argument
1449 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_dev_init()
1453 ret = mdp->cd->soft_reset(ndev); in sh_eth_dev_init()
1458 sh_eth_write(ndev, 0x1, RMIIMODE); in sh_eth_dev_init()
1461 sh_eth_ring_format(ndev); in sh_eth_dev_init()
1463 sh_eth_write(ndev, NET_IP_ALIGN << 16, RPADIR); in sh_eth_dev_init()
1466 sh_eth_write(ndev, 0, EESIPR); in sh_eth_dev_init()
1470 sh_eth_write(ndev, EDMR_EL, EDMR); in sh_eth_dev_init()
1473 sh_eth_write(ndev, 0, EDMR); in sh_eth_dev_init()
1476 sh_eth_write(ndev, mdp->cd->fdr_value, FDR); in sh_eth_dev_init()
1477 sh_eth_write(ndev, 0, TFTR); in sh_eth_dev_init()
1480 sh_eth_write(ndev, RMCR_RNC, RMCR); in sh_eth_dev_init()
1482 sh_eth_write(ndev, mdp->cd->trscer_err_mask, TRSCER); in sh_eth_dev_init()
1486 sh_eth_modify(ndev, EDMR, EDMR_NBST, EDMR_NBST); in sh_eth_dev_init()
1490 sh_eth_write(ndev, 0x800, BCULR); in sh_eth_dev_init()
1492 sh_eth_write(ndev, mdp->cd->fcftr_value, FCFTR); in sh_eth_dev_init()
1495 sh_eth_write(ndev, 0, TRIMD); in sh_eth_dev_init()
1498 sh_eth_write(ndev, ndev->mtu + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN, in sh_eth_dev_init()
1501 sh_eth_modify(ndev, EESR, 0, 0); in sh_eth_dev_init()
1503 sh_eth_write(ndev, mdp->cd->eesipr_value, EESIPR); in sh_eth_dev_init()
1506 sh_eth_write(ndev, ECMR_ZPF | (mdp->duplex ? ECMR_DM : 0) | in sh_eth_dev_init()
1507 (ndev->features & NETIF_F_RXCSUM ? ECMR_RCSC : 0) | in sh_eth_dev_init()
1511 mdp->cd->set_rate(ndev); in sh_eth_dev_init()
1514 sh_eth_write(ndev, mdp->cd->ecsr_value, ECSR); in sh_eth_dev_init()
1517 sh_eth_write(ndev, mdp->cd->ecsipr_value, ECSIPR); in sh_eth_dev_init()
1520 update_mac_address(ndev); in sh_eth_dev_init()
1524 sh_eth_write(ndev, 1, APR); in sh_eth_dev_init()
1526 sh_eth_write(ndev, 1, MPR); in sh_eth_dev_init()
1528 sh_eth_write(ndev, TPAUSER_UNLIMITED, TPAUSER); in sh_eth_dev_init()
1531 sh_eth_write(ndev, EDRRR_R, EDRRR); in sh_eth_dev_init()
1536 static void sh_eth_dev_exit(struct net_device *ndev) in sh_eth_dev_exit() argument
1538 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_dev_exit()
1548 sh_eth_rcv_snd_disable(ndev); in sh_eth_dev_exit()
1551 sh_eth_write(ndev, 0, EDRRR); in sh_eth_dev_exit()
1559 sh_eth_get_stats(ndev); in sh_eth_dev_exit()
1560 mdp->cd->soft_reset(ndev); in sh_eth_dev_exit()
1564 sh_eth_write(ndev, 0x1, RMIIMODE); in sh_eth_dev_exit()
1567 update_mac_address(ndev); in sh_eth_dev_exit()
1584 static int sh_eth_rx(struct net_device *ndev, u32 intr_status, int *quota) in sh_eth_rx() argument
1586 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_rx()
1611 netif_info(mdp, rx_status, ndev, in sh_eth_rx()
1616 ndev->stats.rx_length_errors++; in sh_eth_rx()
1630 ndev->stats.rx_errors++; in sh_eth_rx()
1632 ndev->stats.rx_crc_errors++; in sh_eth_rx()
1634 ndev->stats.rx_frame_errors++; in sh_eth_rx()
1636 ndev->stats.rx_length_errors++; in sh_eth_rx()
1638 ndev->stats.rx_length_errors++; in sh_eth_rx()
1640 ndev->stats.rx_missed_errors++; in sh_eth_rx()
1642 ndev->stats.rx_over_errors++; in sh_eth_rx()
1656 skb->protocol = eth_type_trans(skb, ndev); in sh_eth_rx()
1657 if (ndev->features & NETIF_F_RXCSUM) in sh_eth_rx()
1660 ndev->stats.rx_packets++; in sh_eth_rx()
1661 ndev->stats.rx_bytes += pkt_len; in sh_eth_rx()
1663 ndev->stats.multicast++; in sh_eth_rx()
1678 skb = netdev_alloc_skb(ndev, skbuff_size); in sh_eth_rx()
1703 if (!(sh_eth_read(ndev, EDRRR) & EDRRR_R)) { in sh_eth_rx()
1706 u32 count = (sh_eth_read(ndev, RDFAR) - in sh_eth_rx()
1707 sh_eth_read(ndev, RDLAR)) >> 4; in sh_eth_rx()
1712 sh_eth_write(ndev, EDRRR_R, EDRRR); in sh_eth_rx()
1720 static void sh_eth_rcv_snd_disable(struct net_device *ndev) in sh_eth_rcv_snd_disable() argument
1723 sh_eth_modify(ndev, ECMR, ECMR_RE | ECMR_TE, 0); in sh_eth_rcv_snd_disable()
1726 static void sh_eth_rcv_snd_enable(struct net_device *ndev) in sh_eth_rcv_snd_enable() argument
1729 sh_eth_modify(ndev, ECMR, ECMR_RE | ECMR_TE, ECMR_RE | ECMR_TE); in sh_eth_rcv_snd_enable()
1733 static void sh_eth_emac_interrupt(struct net_device *ndev) in sh_eth_emac_interrupt() argument
1735 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_emac_interrupt()
1739 felic_stat = sh_eth_read(ndev, ECSR) & sh_eth_read(ndev, ECSIPR); in sh_eth_emac_interrupt()
1740 sh_eth_write(ndev, felic_stat, ECSR); /* clear int */ in sh_eth_emac_interrupt()
1742 ndev->stats.tx_carrier_errors++; in sh_eth_emac_interrupt()
1749 link_stat = sh_eth_read(ndev, PSR); in sh_eth_emac_interrupt()
1753 sh_eth_rcv_snd_disable(ndev); in sh_eth_emac_interrupt()
1756 sh_eth_modify(ndev, EESIPR, EESIPR_ECIIP, 0); in sh_eth_emac_interrupt()
1758 sh_eth_modify(ndev, ECSR, 0, 0); in sh_eth_emac_interrupt()
1759 sh_eth_modify(ndev, EESIPR, EESIPR_ECIIP, EESIPR_ECIIP); in sh_eth_emac_interrupt()
1761 sh_eth_rcv_snd_enable(ndev); in sh_eth_emac_interrupt()
1767 static void sh_eth_error(struct net_device *ndev, u32 intr_status) in sh_eth_error() argument
1769 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_error()
1775 ndev->stats.tx_aborted_errors++; in sh_eth_error()
1776 netif_err(mdp, tx_err, ndev, "Transmit Abort\n"); in sh_eth_error()
1784 ndev->stats.rx_frame_errors++; in sh_eth_error()
1790 ndev->stats.tx_fifo_errors++; in sh_eth_error()
1791 netif_err(mdp, tx_err, ndev, "Transmit Descriptor Empty\n"); in sh_eth_error()
1796 ndev->stats.tx_fifo_errors++; in sh_eth_error()
1797 netif_err(mdp, tx_err, ndev, "Transmit FIFO Under flow\n"); in sh_eth_error()
1802 ndev->stats.rx_over_errors++; in sh_eth_error()
1807 ndev->stats.rx_fifo_errors++; in sh_eth_error()
1812 ndev->stats.tx_fifo_errors++; in sh_eth_error()
1813 netif_err(mdp, tx_err, ndev, "Address Error\n"); in sh_eth_error()
1821 u32 edtrr = sh_eth_read(ndev, EDTRR); in sh_eth_error()
1824 netdev_err(ndev, "TX error. status=%8.8x cur_tx=%8.8x dirty_tx=%8.8x state=%8.8x EDTRR=%8.8x.\n", in sh_eth_error()
1826 (u32)ndev->state, edtrr); in sh_eth_error()
1828 sh_eth_tx_free(ndev, true); in sh_eth_error()
1833 sh_eth_write(ndev, mdp->cd->edtrr_trns, EDTRR); in sh_eth_error()
1836 netif_wake_queue(ndev); in sh_eth_error()
1842 struct net_device *ndev = netdev; in sh_eth_interrupt() local
1843 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_interrupt()
1851 intr_status = sh_eth_read(ndev, EESR); in sh_eth_interrupt()
1858 intr_enable = sh_eth_read(ndev, EESIPR); in sh_eth_interrupt()
1867 sh_eth_write(ndev, 0, EESIPR); in sh_eth_interrupt()
1874 sh_eth_write(ndev, intr_enable & ~EESR_RX_CHECK, in sh_eth_interrupt()
1878 netdev_warn(ndev, in sh_eth_interrupt()
1887 sh_eth_write(ndev, intr_status & cd->tx_check, EESR); in sh_eth_interrupt()
1889 sh_eth_tx_free(ndev, true); in sh_eth_interrupt()
1890 netif_wake_queue(ndev); in sh_eth_interrupt()
1895 sh_eth_emac_interrupt(ndev); in sh_eth_interrupt()
1899 sh_eth_write(ndev, intr_status & cd->eesr_err_check, EESR); in sh_eth_interrupt()
1901 sh_eth_error(ndev, intr_status); in sh_eth_interrupt()
1914 struct net_device *ndev = napi->dev; in sh_eth_poll() local
1919 intr_status = sh_eth_read(ndev, EESR); in sh_eth_poll()
1923 sh_eth_write(ndev, intr_status & EESR_RX_CHECK, EESR); in sh_eth_poll()
1925 if (sh_eth_rx(ndev, intr_status, "a)) in sh_eth_poll()
1933 sh_eth_write(ndev, mdp->cd->eesipr_value, EESIPR); in sh_eth_poll()
1939 static void sh_eth_adjust_link(struct net_device *ndev) in sh_eth_adjust_link() argument
1941 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_adjust_link()
1942 struct phy_device *phydev = ndev->phydev; in sh_eth_adjust_link()
1950 sh_eth_rcv_snd_disable(ndev); in sh_eth_adjust_link()
1957 mdp->cd->set_duplex(ndev); in sh_eth_adjust_link()
1964 mdp->cd->set_rate(ndev); in sh_eth_adjust_link()
1967 sh_eth_modify(ndev, ECMR, ECMR_TXF, 0); in sh_eth_adjust_link()
1980 sh_eth_rcv_snd_enable(ndev); in sh_eth_adjust_link()
1989 static int sh_eth_phy_init(struct net_device *ndev) in sh_eth_phy_init() argument
1991 struct device_node *np = ndev->dev.parent->of_node; in sh_eth_phy_init()
1992 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_phy_init()
2004 phydev = of_phy_connect(ndev, pn, in sh_eth_phy_init()
2017 phydev = phy_connect(ndev, phy_id, sh_eth_adjust_link, in sh_eth_phy_init()
2022 netdev_err(ndev, "failed to connect PHY\n"); in sh_eth_phy_init()
2036 static int sh_eth_phy_start(struct net_device *ndev) in sh_eth_phy_start() argument
2040 ret = sh_eth_phy_init(ndev); in sh_eth_phy_start()
2044 phy_start(ndev->phydev); in sh_eth_phy_start()
2057 static size_t __sh_eth_get_regs(struct net_device *ndev, u32 *buf) in __sh_eth_get_regs() argument
2059 struct sh_eth_private *mdp = netdev_priv(ndev); in __sh_eth_get_regs()
2092 #define add_reg(reg) add_reg_from(reg, sh_eth_read(ndev, reg)) in __sh_eth_get_regs()
2222 static int sh_eth_get_regs_len(struct net_device *ndev) in sh_eth_get_regs_len() argument
2224 return __sh_eth_get_regs(ndev, NULL); in sh_eth_get_regs_len()
2227 static void sh_eth_get_regs(struct net_device *ndev, struct ethtool_regs *regs, in sh_eth_get_regs() argument
2230 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_get_regs()
2235 __sh_eth_get_regs(ndev, buf); in sh_eth_get_regs()
2239 static u32 sh_eth_get_msglevel(struct net_device *ndev) in sh_eth_get_msglevel() argument
2241 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_get_msglevel()
2245 static void sh_eth_set_msglevel(struct net_device *ndev, u32 value) in sh_eth_set_msglevel() argument
2247 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_set_msglevel()
2267 static void sh_eth_get_ethtool_stats(struct net_device *ndev, in sh_eth_get_ethtool_stats() argument
2270 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_get_ethtool_stats()
2280 static void sh_eth_get_strings(struct net_device *ndev, u32 stringset, u8 *data) in sh_eth_get_strings() argument
2290 static void sh_eth_get_ringparam(struct net_device *ndev, in sh_eth_get_ringparam() argument
2295 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_get_ringparam()
2303 static int sh_eth_set_ringparam(struct net_device *ndev, in sh_eth_set_ringparam() argument
2308 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_set_ringparam()
2319 if (netif_running(ndev)) { in sh_eth_set_ringparam()
2320 netif_device_detach(ndev); in sh_eth_set_ringparam()
2321 netif_tx_disable(ndev); in sh_eth_set_ringparam()
2329 synchronize_irq(ndev->irq); in sh_eth_set_ringparam()
2331 sh_eth_write(ndev, 0x0000, EESIPR); in sh_eth_set_ringparam()
2333 sh_eth_dev_exit(ndev); in sh_eth_set_ringparam()
2336 sh_eth_ring_free(ndev); in sh_eth_set_ringparam()
2343 if (netif_running(ndev)) { in sh_eth_set_ringparam()
2344 ret = sh_eth_ring_init(ndev); in sh_eth_set_ringparam()
2346 netdev_err(ndev, "%s: sh_eth_ring_init failed.\n", in sh_eth_set_ringparam()
2350 ret = sh_eth_dev_init(ndev); in sh_eth_set_ringparam()
2352 netdev_err(ndev, "%s: sh_eth_dev_init failed.\n", in sh_eth_set_ringparam()
2357 netif_device_attach(ndev); in sh_eth_set_ringparam()
2363 static void sh_eth_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol) in sh_eth_get_wol() argument
2365 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_get_wol()
2376 static int sh_eth_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol) in sh_eth_set_wol() argument
2378 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_set_wol()
2409 static int sh_eth_open(struct net_device *ndev) in sh_eth_open() argument
2411 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_open()
2418 ret = request_irq(ndev->irq, sh_eth_interrupt, in sh_eth_open()
2419 mdp->cd->irq_flags, ndev->name, ndev); in sh_eth_open()
2421 netdev_err(ndev, "Can not assign IRQ number\n"); in sh_eth_open()
2426 ret = sh_eth_ring_init(ndev); in sh_eth_open()
2431 ret = sh_eth_dev_init(ndev); in sh_eth_open()
2436 ret = sh_eth_phy_start(ndev); in sh_eth_open()
2440 netif_start_queue(ndev); in sh_eth_open()
2447 free_irq(ndev->irq, ndev); in sh_eth_open()
2455 static void sh_eth_tx_timeout(struct net_device *ndev, unsigned int txqueue) in sh_eth_tx_timeout() argument
2457 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_tx_timeout()
2461 netif_stop_queue(ndev); in sh_eth_tx_timeout()
2463 netif_err(mdp, timer, ndev, in sh_eth_tx_timeout()
2465 sh_eth_read(ndev, EESR)); in sh_eth_tx_timeout()
2468 ndev->stats.tx_errors++; in sh_eth_tx_timeout()
2484 sh_eth_dev_init(ndev); in sh_eth_tx_timeout()
2486 netif_start_queue(ndev); in sh_eth_tx_timeout()
2491 struct net_device *ndev) in sh_eth_start_xmit() argument
2493 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_start_xmit()
2501 if (!sh_eth_tx_free(ndev, true)) { in sh_eth_start_xmit()
2502 netif_warn(mdp, tx_queued, ndev, "TxFD exhausted.\n"); in sh_eth_start_xmit()
2503 netif_stop_queue(ndev); in sh_eth_start_xmit()
2537 if (!(sh_eth_read(ndev, EDTRR) & mdp->cd->edtrr_trns)) in sh_eth_start_xmit()
2538 sh_eth_write(ndev, mdp->cd->edtrr_trns, EDTRR); in sh_eth_start_xmit()
2549 sh_eth_update_stat(struct net_device *ndev, unsigned long *stat, int reg) in sh_eth_update_stat() argument
2551 u32 delta = sh_eth_read(ndev, reg); in sh_eth_update_stat()
2555 sh_eth_write(ndev, 0, reg); in sh_eth_update_stat()
2559 static struct net_device_stats *sh_eth_get_stats(struct net_device *ndev) in sh_eth_get_stats() argument
2561 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_get_stats()
2564 return &ndev->stats; in sh_eth_get_stats()
2567 return &ndev->stats; in sh_eth_get_stats()
2569 sh_eth_update_stat(ndev, &ndev->stats.tx_dropped, TROCR); in sh_eth_get_stats()
2570 sh_eth_update_stat(ndev, &ndev->stats.collisions, CDCR); in sh_eth_get_stats()
2571 sh_eth_update_stat(ndev, &ndev->stats.tx_carrier_errors, LCCR); in sh_eth_get_stats()
2574 sh_eth_update_stat(ndev, &ndev->stats.tx_carrier_errors, in sh_eth_get_stats()
2576 sh_eth_update_stat(ndev, &ndev->stats.tx_carrier_errors, in sh_eth_get_stats()
2579 sh_eth_update_stat(ndev, &ndev->stats.tx_carrier_errors, in sh_eth_get_stats()
2583 return &ndev->stats; in sh_eth_get_stats()
2587 static int sh_eth_close(struct net_device *ndev) in sh_eth_close() argument
2589 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_close()
2591 netif_stop_queue(ndev); in sh_eth_close()
2598 synchronize_irq(ndev->irq); in sh_eth_close()
2600 sh_eth_write(ndev, 0x0000, EESIPR); in sh_eth_close()
2602 sh_eth_dev_exit(ndev); in sh_eth_close()
2605 if (ndev->phydev) { in sh_eth_close()
2606 phy_stop(ndev->phydev); in sh_eth_close()
2607 phy_disconnect(ndev->phydev); in sh_eth_close()
2610 free_irq(ndev->irq, ndev); in sh_eth_close()
2613 sh_eth_ring_free(ndev); in sh_eth_close()
2622 static int sh_eth_change_mtu(struct net_device *ndev, int new_mtu) in sh_eth_change_mtu() argument
2624 if (netif_running(ndev)) in sh_eth_change_mtu()
2627 WRITE_ONCE(ndev->mtu, new_mtu); in sh_eth_change_mtu()
2628 netdev_update_features(ndev); in sh_eth_change_mtu()
2644 static void sh_eth_tsu_enable_cam_entry_post(struct net_device *ndev, in sh_eth_tsu_enable_cam_entry_post() argument
2647 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_tsu_enable_cam_entry_post()
2655 static bool sh_eth_tsu_disable_cam_entry_post(struct net_device *ndev, in sh_eth_tsu_disable_cam_entry_post() argument
2658 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_tsu_disable_cam_entry_post()
2672 static int sh_eth_tsu_busy(struct net_device *ndev) in sh_eth_tsu_busy() argument
2675 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_tsu_busy()
2681 netdev_err(ndev, "%s: timeout\n", __func__); in sh_eth_tsu_busy()
2689 static int sh_eth_tsu_write_entry(struct net_device *ndev, u16 offset, in sh_eth_tsu_write_entry() argument
2692 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_tsu_write_entry()
2697 if (sh_eth_tsu_busy(ndev) < 0) in sh_eth_tsu_write_entry()
2702 if (sh_eth_tsu_busy(ndev) < 0) in sh_eth_tsu_write_entry()
2708 static void sh_eth_tsu_read_entry(struct net_device *ndev, u16 offset, u8 *addr) in sh_eth_tsu_read_entry() argument
2710 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_tsu_read_entry()
2724 static int sh_eth_tsu_find_entry(struct net_device *ndev, const u8 *addr) in sh_eth_tsu_find_entry() argument
2726 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_tsu_find_entry()
2732 sh_eth_tsu_read_entry(ndev, reg_offset, c_addr); in sh_eth_tsu_find_entry()
2740 static int sh_eth_tsu_find_empty(struct net_device *ndev) in sh_eth_tsu_find_empty() argument
2746 entry = sh_eth_tsu_find_entry(ndev, blank); in sh_eth_tsu_find_empty()
2750 static int sh_eth_tsu_disable_cam_entry_table(struct net_device *ndev, in sh_eth_tsu_disable_cam_entry_table() argument
2753 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_tsu_disable_cam_entry_table()
2762 ret = sh_eth_tsu_write_entry(ndev, reg_offset + entry * 8, blank); in sh_eth_tsu_disable_cam_entry_table()
2768 static int sh_eth_tsu_add_entry(struct net_device *ndev, const u8 *addr) in sh_eth_tsu_add_entry() argument
2770 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_tsu_add_entry()
2777 i = sh_eth_tsu_find_entry(ndev, addr); in sh_eth_tsu_add_entry()
2780 i = sh_eth_tsu_find_empty(ndev); in sh_eth_tsu_add_entry()
2783 ret = sh_eth_tsu_write_entry(ndev, reg_offset + i * 8, addr); in sh_eth_tsu_add_entry()
2793 sh_eth_tsu_enable_cam_entry_post(ndev, i); in sh_eth_tsu_add_entry()
2798 static int sh_eth_tsu_del_entry(struct net_device *ndev, const u8 *addr) in sh_eth_tsu_del_entry() argument
2800 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_tsu_del_entry()
2806 i = sh_eth_tsu_find_entry(ndev, addr); in sh_eth_tsu_del_entry()
2809 if (sh_eth_tsu_disable_cam_entry_post(ndev, i)) in sh_eth_tsu_del_entry()
2813 ret = sh_eth_tsu_disable_cam_entry_table(ndev, i); in sh_eth_tsu_del_entry()
2821 static int sh_eth_tsu_purge_all(struct net_device *ndev) in sh_eth_tsu_purge_all() argument
2823 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_tsu_purge_all()
2830 if (sh_eth_tsu_disable_cam_entry_post(ndev, i)) in sh_eth_tsu_purge_all()
2834 ret = sh_eth_tsu_disable_cam_entry_table(ndev, i); in sh_eth_tsu_purge_all()
2842 static void sh_eth_tsu_purge_mcast(struct net_device *ndev) in sh_eth_tsu_purge_mcast() argument
2844 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_tsu_purge_mcast()
2853 sh_eth_tsu_read_entry(ndev, reg_offset, addr); in sh_eth_tsu_purge_mcast()
2855 sh_eth_tsu_del_entry(ndev, addr); in sh_eth_tsu_purge_mcast()
2860 static void sh_eth_set_rx_mode(struct net_device *ndev) in sh_eth_set_rx_mode() argument
2862 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_set_rx_mode()
2869 * Depending on ndev->flags, set PRM or clear MCT in sh_eth_set_rx_mode()
2871 ecmr_bits = sh_eth_read(ndev, ECMR) & ~ECMR_PRM; in sh_eth_set_rx_mode()
2875 if (!(ndev->flags & IFF_MULTICAST)) { in sh_eth_set_rx_mode()
2876 sh_eth_tsu_purge_mcast(ndev); in sh_eth_set_rx_mode()
2879 if (ndev->flags & IFF_ALLMULTI) { in sh_eth_set_rx_mode()
2880 sh_eth_tsu_purge_mcast(ndev); in sh_eth_set_rx_mode()
2885 if (ndev->flags & IFF_PROMISC) { in sh_eth_set_rx_mode()
2886 sh_eth_tsu_purge_all(ndev); in sh_eth_set_rx_mode()
2890 netdev_for_each_mc_addr(ha, ndev) { in sh_eth_set_rx_mode()
2894 if (sh_eth_tsu_add_entry(ndev, ha->addr) < 0) { in sh_eth_set_rx_mode()
2896 sh_eth_tsu_purge_mcast(ndev); in sh_eth_set_rx_mode()
2905 sh_eth_write(ndev, ecmr_bits, ECMR); in sh_eth_set_rx_mode()
2910 static void sh_eth_set_rx_csum(struct net_device *ndev, bool enable) in sh_eth_set_rx_csum() argument
2912 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_set_rx_csum()
2918 sh_eth_rcv_snd_disable(ndev); in sh_eth_set_rx_csum()
2921 sh_eth_modify(ndev, ECMR, ECMR_RCSC, enable ? ECMR_RCSC : 0); in sh_eth_set_rx_csum()
2924 sh_eth_rcv_snd_enable(ndev); in sh_eth_set_rx_csum()
2929 static int sh_eth_set_features(struct net_device *ndev, in sh_eth_set_features() argument
2932 netdev_features_t changed = ndev->features ^ features; in sh_eth_set_features()
2933 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_set_features()
2936 sh_eth_set_rx_csum(ndev, features & NETIF_F_RXCSUM); in sh_eth_set_features()
2938 ndev->features = features; in sh_eth_set_features()
2951 static int sh_eth_vlan_rx_add_vid(struct net_device *ndev, in sh_eth_vlan_rx_add_vid() argument
2954 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_vlan_rx_add_vid()
2981 static int sh_eth_vlan_rx_kill_vid(struct net_device *ndev, in sh_eth_vlan_rx_kill_vid() argument
2984 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_vlan_rx_kill_vid()
3259 struct net_device *ndev; in sh_eth_drv_probe() local
3262 ndev = alloc_etherdev(sizeof(struct sh_eth_private)); in sh_eth_drv_probe()
3263 if (!ndev) in sh_eth_drv_probe()
3272 ndev->irq = ret; in sh_eth_drv_probe()
3274 SET_NETDEV_DEV(ndev, &pdev->dev); in sh_eth_drv_probe()
3276 mdp = netdev_priv(ndev); in sh_eth_drv_probe()
3285 ndev->base_addr = res->start; in sh_eth_drv_probe()
3323 ndev->max_mtu = 2000 - (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN); in sh_eth_drv_probe()
3324 ndev->min_mtu = ETH_MIN_MTU; in sh_eth_drv_probe()
3327 ndev->features = NETIF_F_RXCSUM; in sh_eth_drv_probe()
3328 ndev->hw_features = NETIF_F_RXCSUM; in sh_eth_drv_probe()
3333 ndev->netdev_ops = &sh_eth_netdev_ops_tsu; in sh_eth_drv_probe()
3335 ndev->netdev_ops = &sh_eth_netdev_ops; in sh_eth_drv_probe()
3336 ndev->ethtool_ops = &sh_eth_ethtool_ops; in sh_eth_drv_probe()
3337 ndev->watchdog_timeo = TX_TIMEOUT; in sh_eth_drv_probe()
3343 read_mac_address(ndev, pd->mac_addr); in sh_eth_drv_probe()
3344 if (!is_valid_ether_addr(ndev->dev_addr)) { in sh_eth_drv_probe()
3347 eth_hw_addr_random(ndev); in sh_eth_drv_probe()
3380 ndev->features |= NETIF_F_HW_VLAN_CTAG_FILTER; in sh_eth_drv_probe()
3385 mdp->cd->chip_reset(ndev); in sh_eth_drv_probe()
3393 sh_eth_write(ndev, 0x1, RMIIMODE); in sh_eth_drv_probe()
3402 netif_napi_add(ndev, &mdp->napi, sh_eth_poll); in sh_eth_drv_probe()
3405 ret = register_netdev(ndev); in sh_eth_drv_probe()
3413 netdev_info(ndev, "Base address at 0x%x, %pM, IRQ %d.\n", in sh_eth_drv_probe()
3414 (u32)ndev->base_addr, ndev->dev_addr, ndev->irq); in sh_eth_drv_probe()
3417 platform_set_drvdata(pdev, ndev); in sh_eth_drv_probe()
3427 free_netdev(ndev); in sh_eth_drv_probe()
3436 struct net_device *ndev = platform_get_drvdata(pdev); in sh_eth_drv_remove() local
3437 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_drv_remove()
3439 unregister_netdev(ndev); in sh_eth_drv_remove()
3443 free_netdev(ndev); in sh_eth_drv_remove()
3448 static int sh_eth_wol_setup(struct net_device *ndev) in sh_eth_wol_setup() argument
3450 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_wol_setup()
3453 synchronize_irq(ndev->irq); in sh_eth_wol_setup()
3455 sh_eth_write(ndev, EESIPR_ECIIP, EESIPR); in sh_eth_wol_setup()
3458 sh_eth_modify(ndev, ECMR, ECMR_MPDE, ECMR_MPDE); in sh_eth_wol_setup()
3460 return enable_irq_wake(ndev->irq); in sh_eth_wol_setup()
3463 static int sh_eth_wol_restore(struct net_device *ndev) in sh_eth_wol_restore() argument
3465 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_wol_restore()
3471 sh_eth_modify(ndev, ECMR, ECMR_MPDE, 0); in sh_eth_wol_restore()
3478 sh_eth_close(ndev); in sh_eth_wol_restore()
3479 ret = sh_eth_open(ndev); in sh_eth_wol_restore()
3483 return disable_irq_wake(ndev->irq); in sh_eth_wol_restore()
3488 struct net_device *ndev = dev_get_drvdata(dev); in sh_eth_suspend() local
3489 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_suspend()
3492 if (!netif_running(ndev)) in sh_eth_suspend()
3495 netif_device_detach(ndev); in sh_eth_suspend()
3498 ret = sh_eth_wol_setup(ndev); in sh_eth_suspend()
3500 ret = sh_eth_close(ndev); in sh_eth_suspend()
3507 struct net_device *ndev = dev_get_drvdata(dev); in sh_eth_resume() local
3508 struct sh_eth_private *mdp = netdev_priv(ndev); in sh_eth_resume()
3511 if (!netif_running(ndev)) in sh_eth_resume()
3515 ret = sh_eth_wol_restore(ndev); in sh_eth_resume()
3517 ret = sh_eth_open(ndev); in sh_eth_resume()
3522 netif_device_attach(ndev); in sh_eth_resume()