diff options
Diffstat (limited to 'drivers/net/ethernet/renesas/sh_eth.c')
-rw-r--r-- | drivers/net/ethernet/renesas/sh_eth.c | 263 |
1 files changed, 159 insertions, 104 deletions
diff --git a/drivers/net/ethernet/renesas/sh_eth.c b/drivers/net/ethernet/renesas/sh_eth.c index 040cb94e8219..e4bff181c910 100644 --- a/drivers/net/ethernet/renesas/sh_eth.c +++ b/drivers/net/ethernet/renesas/sh_eth.c | |||
@@ -1,8 +1,9 @@ | |||
1 | /* SuperH Ethernet device driver | 1 | /* SuperH Ethernet device driver |
2 | * | 2 | * |
3 | * Copyright (C) 2006-2012 Nobuhiro Iwamatsu | 3 | * Copyright (C) 2006-2012 Nobuhiro Iwamatsu |
4 | * Copyright (C) 2008-2013 Renesas Solutions Corp. | 4 | * Copyright (C) 2008-2014 Renesas Solutions Corp. |
5 | * Copyright (C) 2013 Cogent Embedded, Inc. | 5 | * Copyright (C) 2013-2014 Cogent Embedded, Inc. |
6 | * Copyright (C) 2014 Codethink Limited | ||
6 | * | 7 | * |
7 | * This program is free software; you can redistribute it and/or modify it | 8 | * This program is free software; you can redistribute it and/or modify it |
8 | * under the terms and conditions of the GNU General Public License, | 9 | * under the terms and conditions of the GNU General Public License, |
@@ -27,6 +28,10 @@ | |||
27 | #include <linux/platform_device.h> | 28 | #include <linux/platform_device.h> |
28 | #include <linux/mdio-bitbang.h> | 29 | #include <linux/mdio-bitbang.h> |
29 | #include <linux/netdevice.h> | 30 | #include <linux/netdevice.h> |
31 | #include <linux/of.h> | ||
32 | #include <linux/of_device.h> | ||
33 | #include <linux/of_irq.h> | ||
34 | #include <linux/of_net.h> | ||
30 | #include <linux/phy.h> | 35 | #include <linux/phy.h> |
31 | #include <linux/cache.h> | 36 | #include <linux/cache.h> |
32 | #include <linux/io.h> | 37 | #include <linux/io.h> |
@@ -36,6 +41,7 @@ | |||
36 | #include <linux/if_vlan.h> | 41 | #include <linux/if_vlan.h> |
37 | #include <linux/clk.h> | 42 | #include <linux/clk.h> |
38 | #include <linux/sh_eth.h> | 43 | #include <linux/sh_eth.h> |
44 | #include <linux/of_mdio.h> | ||
39 | 45 | ||
40 | #include "sh_eth.h" | 46 | #include "sh_eth.h" |
41 | 47 | ||
@@ -394,7 +400,8 @@ static void sh_eth_select_mii(struct net_device *ndev) | |||
394 | value = 0x0; | 400 | value = 0x0; |
395 | break; | 401 | break; |
396 | default: | 402 | default: |
397 | pr_warn("PHY interface mode was not setup. Set to MII.\n"); | 403 | netdev_warn(ndev, |
404 | "PHY interface mode was not setup. Set to MII.\n"); | ||
398 | value = 0x1; | 405 | value = 0x1; |
399 | break; | 406 | break; |
400 | } | 407 | } |
@@ -848,7 +855,7 @@ static int sh_eth_check_reset(struct net_device *ndev) | |||
848 | cnt--; | 855 | cnt--; |
849 | } | 856 | } |
850 | if (cnt <= 0) { | 857 | if (cnt <= 0) { |
851 | pr_err("Device reset failed\n"); | 858 | netdev_err(ndev, "Device reset failed\n"); |
852 | ret = -ETIMEDOUT; | 859 | ret = -ETIMEDOUT; |
853 | } | 860 | } |
854 | return ret; | 861 | return ret; |
@@ -866,7 +873,7 @@ static int sh_eth_reset(struct net_device *ndev) | |||
866 | 873 | ||
867 | ret = sh_eth_check_reset(ndev); | 874 | ret = sh_eth_check_reset(ndev); |
868 | if (ret) | 875 | if (ret) |
869 | goto out; | 876 | return ret; |
870 | 877 | ||
871 | /* Table Init */ | 878 | /* Table Init */ |
872 | sh_eth_write(ndev, 0x0, TDLAR); | 879 | sh_eth_write(ndev, 0x0, TDLAR); |
@@ -893,7 +900,6 @@ static int sh_eth_reset(struct net_device *ndev) | |||
893 | EDMR); | 900 | EDMR); |
894 | } | 901 | } |
895 | 902 | ||
896 | out: | ||
897 | return ret; | 903 | return ret; |
898 | } | 904 | } |
899 | 905 | ||
@@ -1257,7 +1263,7 @@ static int sh_eth_dev_init(struct net_device *ndev, bool start) | |||
1257 | /* Soft Reset */ | 1263 | /* Soft Reset */ |
1258 | ret = sh_eth_reset(ndev); | 1264 | ret = sh_eth_reset(ndev); |
1259 | if (ret) | 1265 | if (ret) |
1260 | goto out; | 1266 | return ret; |
1261 | 1267 | ||
1262 | if (mdp->cd->rmiimode) | 1268 | if (mdp->cd->rmiimode) |
1263 | sh_eth_write(ndev, 0x1, RMIIMODE); | 1269 | sh_eth_write(ndev, 0x1, RMIIMODE); |
@@ -1336,7 +1342,6 @@ static int sh_eth_dev_init(struct net_device *ndev, bool start) | |||
1336 | netif_start_queue(ndev); | 1342 | netif_start_queue(ndev); |
1337 | } | 1343 | } |
1338 | 1344 | ||
1339 | out: | ||
1340 | return ret; | 1345 | return ret; |
1341 | } | 1346 | } |
1342 | 1347 | ||
@@ -1550,8 +1555,7 @@ ignore_link: | |||
1550 | /* Unused write back interrupt */ | 1555 | /* Unused write back interrupt */ |
1551 | if (intr_status & EESR_TABT) { /* Transmit Abort int */ | 1556 | if (intr_status & EESR_TABT) { /* Transmit Abort int */ |
1552 | ndev->stats.tx_aborted_errors++; | 1557 | ndev->stats.tx_aborted_errors++; |
1553 | if (netif_msg_tx_err(mdp)) | 1558 | netif_err(mdp, tx_err, ndev, "Transmit Abort\n"); |
1554 | dev_err(&ndev->dev, "Transmit Abort\n"); | ||
1555 | } | 1559 | } |
1556 | } | 1560 | } |
1557 | 1561 | ||
@@ -1560,45 +1564,38 @@ ignore_link: | |||
1560 | if (intr_status & EESR_RFRMER) { | 1564 | if (intr_status & EESR_RFRMER) { |
1561 | /* Receive Frame Overflow int */ | 1565 | /* Receive Frame Overflow int */ |
1562 | ndev->stats.rx_frame_errors++; | 1566 | ndev->stats.rx_frame_errors++; |
1563 | if (netif_msg_rx_err(mdp)) | 1567 | netif_err(mdp, rx_err, ndev, "Receive Abort\n"); |
1564 | dev_err(&ndev->dev, "Receive Abort\n"); | ||
1565 | } | 1568 | } |
1566 | } | 1569 | } |
1567 | 1570 | ||
1568 | if (intr_status & EESR_TDE) { | 1571 | if (intr_status & EESR_TDE) { |
1569 | /* Transmit Descriptor Empty int */ | 1572 | /* Transmit Descriptor Empty int */ |
1570 | ndev->stats.tx_fifo_errors++; | 1573 | ndev->stats.tx_fifo_errors++; |
1571 | if (netif_msg_tx_err(mdp)) | 1574 | netif_err(mdp, tx_err, ndev, "Transmit Descriptor Empty\n"); |
1572 | dev_err(&ndev->dev, "Transmit Descriptor Empty\n"); | ||
1573 | } | 1575 | } |
1574 | 1576 | ||
1575 | if (intr_status & EESR_TFE) { | 1577 | if (intr_status & EESR_TFE) { |
1576 | /* FIFO under flow */ | 1578 | /* FIFO under flow */ |
1577 | ndev->stats.tx_fifo_errors++; | 1579 | ndev->stats.tx_fifo_errors++; |
1578 | if (netif_msg_tx_err(mdp)) | 1580 | netif_err(mdp, tx_err, ndev, "Transmit FIFO Under flow\n"); |
1579 | dev_err(&ndev->dev, "Transmit FIFO Under flow\n"); | ||
1580 | } | 1581 | } |
1581 | 1582 | ||
1582 | if (intr_status & EESR_RDE) { | 1583 | if (intr_status & EESR_RDE) { |
1583 | /* Receive Descriptor Empty int */ | 1584 | /* Receive Descriptor Empty int */ |
1584 | ndev->stats.rx_over_errors++; | 1585 | ndev->stats.rx_over_errors++; |
1585 | 1586 | netif_err(mdp, rx_err, ndev, "Receive Descriptor Empty\n"); | |
1586 | if (netif_msg_rx_err(mdp)) | ||
1587 | dev_err(&ndev->dev, "Receive Descriptor Empty\n"); | ||
1588 | } | 1587 | } |
1589 | 1588 | ||
1590 | if (intr_status & EESR_RFE) { | 1589 | if (intr_status & EESR_RFE) { |
1591 | /* Receive FIFO Overflow int */ | 1590 | /* Receive FIFO Overflow int */ |
1592 | ndev->stats.rx_fifo_errors++; | 1591 | ndev->stats.rx_fifo_errors++; |
1593 | if (netif_msg_rx_err(mdp)) | 1592 | netif_err(mdp, rx_err, ndev, "Receive FIFO Overflow\n"); |
1594 | dev_err(&ndev->dev, "Receive FIFO Overflow\n"); | ||
1595 | } | 1593 | } |
1596 | 1594 | ||
1597 | if (!mdp->cd->no_ade && (intr_status & EESR_ADE)) { | 1595 | if (!mdp->cd->no_ade && (intr_status & EESR_ADE)) { |
1598 | /* Address Error */ | 1596 | /* Address Error */ |
1599 | ndev->stats.tx_fifo_errors++; | 1597 | ndev->stats.tx_fifo_errors++; |
1600 | if (netif_msg_tx_err(mdp)) | 1598 | netif_err(mdp, tx_err, ndev, "Address Error\n"); |
1601 | dev_err(&ndev->dev, "Address Error\n"); | ||
1602 | } | 1599 | } |
1603 | 1600 | ||
1604 | mask = EESR_TWB | EESR_TABT | EESR_ADE | EESR_TDE | EESR_TFE; | 1601 | mask = EESR_TWB | EESR_TABT | EESR_ADE | EESR_TDE | EESR_TFE; |
@@ -1609,9 +1606,9 @@ ignore_link: | |||
1609 | u32 edtrr = sh_eth_read(ndev, EDTRR); | 1606 | u32 edtrr = sh_eth_read(ndev, EDTRR); |
1610 | 1607 | ||
1611 | /* dmesg */ | 1608 | /* dmesg */ |
1612 | dev_err(&ndev->dev, "TX error. status=%8.8x cur_tx=%8.8x dirty_tx=%8.8x state=%8.8x EDTRR=%8.8x.\n", | 1609 | netdev_err(ndev, "TX error. status=%8.8x cur_tx=%8.8x dirty_tx=%8.8x state=%8.8x EDTRR=%8.8x.\n", |
1613 | intr_status, mdp->cur_tx, mdp->dirty_tx, | 1610 | intr_status, mdp->cur_tx, mdp->dirty_tx, |
1614 | (u32)ndev->state, edtrr); | 1611 | (u32)ndev->state, edtrr); |
1615 | /* dirty buffer free */ | 1612 | /* dirty buffer free */ |
1616 | sh_eth_txfree(ndev); | 1613 | sh_eth_txfree(ndev); |
1617 | 1614 | ||
@@ -1656,9 +1653,9 @@ static irqreturn_t sh_eth_interrupt(int irq, void *netdev) | |||
1656 | EESIPR); | 1653 | EESIPR); |
1657 | __napi_schedule(&mdp->napi); | 1654 | __napi_schedule(&mdp->napi); |
1658 | } else { | 1655 | } else { |
1659 | dev_warn(&ndev->dev, | 1656 | netdev_warn(ndev, |
1660 | "ignoring interrupt, status 0x%08lx, mask 0x%08lx.\n", | 1657 | "ignoring interrupt, status 0x%08lx, mask 0x%08lx.\n", |
1661 | intr_status, intr_enable); | 1658 | intr_status, intr_enable); |
1662 | } | 1659 | } |
1663 | } | 1660 | } |
1664 | 1661 | ||
@@ -1757,27 +1754,42 @@ static void sh_eth_adjust_link(struct net_device *ndev) | |||
1757 | /* PHY init function */ | 1754 | /* PHY init function */ |
1758 | static int sh_eth_phy_init(struct net_device *ndev) | 1755 | static int sh_eth_phy_init(struct net_device *ndev) |
1759 | { | 1756 | { |
1757 | struct device_node *np = ndev->dev.parent->of_node; | ||
1760 | struct sh_eth_private *mdp = netdev_priv(ndev); | 1758 | struct sh_eth_private *mdp = netdev_priv(ndev); |
1761 | char phy_id[MII_BUS_ID_SIZE + 3]; | ||
1762 | struct phy_device *phydev = NULL; | 1759 | struct phy_device *phydev = NULL; |
1763 | 1760 | ||
1764 | snprintf(phy_id, sizeof(phy_id), PHY_ID_FMT, | ||
1765 | mdp->mii_bus->id, mdp->phy_id); | ||
1766 | |||
1767 | mdp->link = 0; | 1761 | mdp->link = 0; |
1768 | mdp->speed = 0; | 1762 | mdp->speed = 0; |
1769 | mdp->duplex = -1; | 1763 | mdp->duplex = -1; |
1770 | 1764 | ||
1771 | /* Try connect to PHY */ | 1765 | /* Try connect to PHY */ |
1772 | phydev = phy_connect(ndev, phy_id, sh_eth_adjust_link, | 1766 | if (np) { |
1773 | mdp->phy_interface); | 1767 | struct device_node *pn; |
1768 | |||
1769 | pn = of_parse_phandle(np, "phy-handle", 0); | ||
1770 | phydev = of_phy_connect(ndev, pn, | ||
1771 | sh_eth_adjust_link, 0, | ||
1772 | mdp->phy_interface); | ||
1773 | |||
1774 | if (!phydev) | ||
1775 | phydev = ERR_PTR(-ENOENT); | ||
1776 | } else { | ||
1777 | char phy_id[MII_BUS_ID_SIZE + 3]; | ||
1778 | |||
1779 | snprintf(phy_id, sizeof(phy_id), PHY_ID_FMT, | ||
1780 | mdp->mii_bus->id, mdp->phy_id); | ||
1781 | |||
1782 | phydev = phy_connect(ndev, phy_id, sh_eth_adjust_link, | ||
1783 | mdp->phy_interface); | ||
1784 | } | ||
1785 | |||
1774 | if (IS_ERR(phydev)) { | 1786 | if (IS_ERR(phydev)) { |
1775 | dev_err(&ndev->dev, "phy_connect failed\n"); | 1787 | netdev_err(ndev, "failed to connect PHY\n"); |
1776 | return PTR_ERR(phydev); | 1788 | return PTR_ERR(phydev); |
1777 | } | 1789 | } |
1778 | 1790 | ||
1779 | dev_info(&ndev->dev, "attached PHY %d (IRQ %d) to driver %s\n", | 1791 | netdev_info(ndev, "attached PHY %d (IRQ %d) to driver %s\n", |
1780 | phydev->addr, phydev->irq, phydev->drv->name); | 1792 | phydev->addr, phydev->irq, phydev->drv->name); |
1781 | 1793 | ||
1782 | mdp->phydev = phydev; | 1794 | mdp->phydev = phydev; |
1783 | 1795 | ||
@@ -1958,12 +1970,12 @@ static int sh_eth_set_ringparam(struct net_device *ndev, | |||
1958 | 1970 | ||
1959 | ret = sh_eth_ring_init(ndev); | 1971 | ret = sh_eth_ring_init(ndev); |
1960 | if (ret < 0) { | 1972 | if (ret < 0) { |
1961 | dev_err(&ndev->dev, "%s: sh_eth_ring_init failed.\n", __func__); | 1973 | netdev_err(ndev, "%s: sh_eth_ring_init failed.\n", __func__); |
1962 | return ret; | 1974 | return ret; |
1963 | } | 1975 | } |
1964 | ret = sh_eth_dev_init(ndev, false); | 1976 | ret = sh_eth_dev_init(ndev, false); |
1965 | if (ret < 0) { | 1977 | if (ret < 0) { |
1966 | dev_err(&ndev->dev, "%s: sh_eth_dev_init failed.\n", __func__); | 1978 | netdev_err(ndev, "%s: sh_eth_dev_init failed.\n", __func__); |
1967 | return ret; | 1979 | return ret; |
1968 | } | 1980 | } |
1969 | 1981 | ||
@@ -2004,7 +2016,7 @@ static int sh_eth_open(struct net_device *ndev) | |||
2004 | ret = request_irq(ndev->irq, sh_eth_interrupt, | 2016 | ret = request_irq(ndev->irq, sh_eth_interrupt, |
2005 | mdp->cd->irq_flags, ndev->name, ndev); | 2017 | mdp->cd->irq_flags, ndev->name, ndev); |
2006 | if (ret) { | 2018 | if (ret) { |
2007 | dev_err(&ndev->dev, "Can not assign IRQ number\n"); | 2019 | netdev_err(ndev, "Can not assign IRQ number\n"); |
2008 | goto out_napi_off; | 2020 | goto out_napi_off; |
2009 | } | 2021 | } |
2010 | 2022 | ||
@@ -2042,10 +2054,9 @@ static void sh_eth_tx_timeout(struct net_device *ndev) | |||
2042 | 2054 | ||
2043 | netif_stop_queue(ndev); | 2055 | netif_stop_queue(ndev); |
2044 | 2056 | ||
2045 | if (netif_msg_timer(mdp)) { | 2057 | netif_err(mdp, timer, ndev, |
2046 | dev_err(&ndev->dev, "%s: transmit timed out, status %8.8x, resetting...\n", | 2058 | "transmit timed out, status %8.8x, resetting...\n", |
2047 | ndev->name, (int)sh_eth_read(ndev, EESR)); | 2059 | (int)sh_eth_read(ndev, EESR)); |
2048 | } | ||
2049 | 2060 | ||
2050 | /* tx_errors count up */ | 2061 | /* tx_errors count up */ |
2051 | ndev->stats.tx_errors++; | 2062 | ndev->stats.tx_errors++; |
@@ -2080,8 +2091,7 @@ static int sh_eth_start_xmit(struct sk_buff *skb, struct net_device *ndev) | |||
2080 | spin_lock_irqsave(&mdp->lock, flags); | 2091 | spin_lock_irqsave(&mdp->lock, flags); |
2081 | if ((mdp->cur_tx - mdp->dirty_tx) >= (mdp->num_tx_ring - 4)) { | 2092 | if ((mdp->cur_tx - mdp->dirty_tx) >= (mdp->num_tx_ring - 4)) { |
2082 | if (!sh_eth_txfree(ndev)) { | 2093 | if (!sh_eth_txfree(ndev)) { |
2083 | if (netif_msg_tx_queued(mdp)) | 2094 | netif_warn(mdp, tx_queued, ndev, "TxFD exhausted.\n"); |
2084 | dev_warn(&ndev->dev, "TxFD exhausted.\n"); | ||
2085 | netif_stop_queue(ndev); | 2095 | netif_stop_queue(ndev); |
2086 | spin_unlock_irqrestore(&mdp->lock, flags); | 2096 | spin_unlock_irqrestore(&mdp->lock, flags); |
2087 | return NETDEV_TX_BUSY; | 2097 | return NETDEV_TX_BUSY; |
@@ -2098,8 +2108,8 @@ static int sh_eth_start_xmit(struct sk_buff *skb, struct net_device *ndev) | |||
2098 | skb->len + 2); | 2108 | skb->len + 2); |
2099 | txdesc->addr = dma_map_single(&ndev->dev, skb->data, skb->len, | 2109 | txdesc->addr = dma_map_single(&ndev->dev, skb->data, skb->len, |
2100 | DMA_TO_DEVICE); | 2110 | DMA_TO_DEVICE); |
2101 | if (skb->len < ETHERSMALL) | 2111 | if (skb->len < ETH_ZLEN) |
2102 | txdesc->buffer_length = ETHERSMALL; | 2112 | txdesc->buffer_length = ETH_ZLEN; |
2103 | else | 2113 | else |
2104 | txdesc->buffer_length = skb->len; | 2114 | txdesc->buffer_length = skb->len; |
2105 | 2115 | ||
@@ -2251,7 +2261,7 @@ static int sh_eth_tsu_busy(struct net_device *ndev) | |||
2251 | udelay(10); | 2261 | udelay(10); |
2252 | timeout--; | 2262 | timeout--; |
2253 | if (timeout <= 0) { | 2263 | if (timeout <= 0) { |
2254 | dev_err(&ndev->dev, "%s: timeout\n", __func__); | 2264 | netdev_err(ndev, "%s: timeout\n", __func__); |
2255 | return -ETIMEDOUT; | 2265 | return -ETIMEDOUT; |
2256 | } | 2266 | } |
2257 | } | 2267 | } |
@@ -2571,37 +2581,30 @@ static void sh_eth_tsu_init(struct sh_eth_private *mdp) | |||
2571 | } | 2581 | } |
2572 | 2582 | ||
2573 | /* MDIO bus release function */ | 2583 | /* MDIO bus release function */ |
2574 | static int sh_mdio_release(struct net_device *ndev) | 2584 | static int sh_mdio_release(struct sh_eth_private *mdp) |
2575 | { | 2585 | { |
2576 | struct mii_bus *bus = dev_get_drvdata(&ndev->dev); | ||
2577 | |||
2578 | /* unregister mdio bus */ | 2586 | /* unregister mdio bus */ |
2579 | mdiobus_unregister(bus); | 2587 | mdiobus_unregister(mdp->mii_bus); |
2580 | |||
2581 | /* remove mdio bus info from net_device */ | ||
2582 | dev_set_drvdata(&ndev->dev, NULL); | ||
2583 | 2588 | ||
2584 | /* free bitbang info */ | 2589 | /* free bitbang info */ |
2585 | free_mdio_bitbang(bus); | 2590 | free_mdio_bitbang(mdp->mii_bus); |
2586 | 2591 | ||
2587 | return 0; | 2592 | return 0; |
2588 | } | 2593 | } |
2589 | 2594 | ||
2590 | /* MDIO bus init function */ | 2595 | /* MDIO bus init function */ |
2591 | static int sh_mdio_init(struct net_device *ndev, int id, | 2596 | static int sh_mdio_init(struct sh_eth_private *mdp, |
2592 | struct sh_eth_plat_data *pd) | 2597 | struct sh_eth_plat_data *pd) |
2593 | { | 2598 | { |
2594 | int ret, i; | 2599 | int ret, i; |
2595 | struct bb_info *bitbang; | 2600 | struct bb_info *bitbang; |
2596 | struct sh_eth_private *mdp = netdev_priv(ndev); | 2601 | struct platform_device *pdev = mdp->pdev; |
2602 | struct device *dev = &mdp->pdev->dev; | ||
2597 | 2603 | ||
2598 | /* create bit control struct for PHY */ | 2604 | /* create bit control struct for PHY */ |
2599 | bitbang = devm_kzalloc(&ndev->dev, sizeof(struct bb_info), | 2605 | bitbang = devm_kzalloc(dev, sizeof(struct bb_info), GFP_KERNEL); |
2600 | GFP_KERNEL); | 2606 | if (!bitbang) |
2601 | if (!bitbang) { | 2607 | return -ENOMEM; |
2602 | ret = -ENOMEM; | ||
2603 | goto out; | ||
2604 | } | ||
2605 | 2608 | ||
2606 | /* bitbang init */ | 2609 | /* bitbang init */ |
2607 | bitbang->addr = mdp->addr + mdp->reg_offset[PIR]; | 2610 | bitbang->addr = mdp->addr + mdp->reg_offset[PIR]; |
@@ -2614,44 +2617,42 @@ static int sh_mdio_init(struct net_device *ndev, int id, | |||
2614 | 2617 | ||
2615 | /* MII controller setting */ | 2618 | /* MII controller setting */ |
2616 | mdp->mii_bus = alloc_mdio_bitbang(&bitbang->ctrl); | 2619 | mdp->mii_bus = alloc_mdio_bitbang(&bitbang->ctrl); |
2617 | if (!mdp->mii_bus) { | 2620 | if (!mdp->mii_bus) |
2618 | ret = -ENOMEM; | 2621 | return -ENOMEM; |
2619 | goto out; | ||
2620 | } | ||
2621 | 2622 | ||
2622 | /* Hook up MII support for ethtool */ | 2623 | /* Hook up MII support for ethtool */ |
2623 | mdp->mii_bus->name = "sh_mii"; | 2624 | mdp->mii_bus->name = "sh_mii"; |
2624 | mdp->mii_bus->parent = &ndev->dev; | 2625 | mdp->mii_bus->parent = dev; |
2625 | snprintf(mdp->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x", | 2626 | snprintf(mdp->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x", |
2626 | mdp->pdev->name, id); | 2627 | pdev->name, pdev->id); |
2627 | 2628 | ||
2628 | /* PHY IRQ */ | 2629 | /* PHY IRQ */ |
2629 | mdp->mii_bus->irq = devm_kzalloc(&ndev->dev, | 2630 | mdp->mii_bus->irq = devm_kzalloc(dev, sizeof(int) * PHY_MAX_ADDR, |
2630 | sizeof(int) * PHY_MAX_ADDR, | ||
2631 | GFP_KERNEL); | 2631 | GFP_KERNEL); |
2632 | if (!mdp->mii_bus->irq) { | 2632 | if (!mdp->mii_bus->irq) { |
2633 | ret = -ENOMEM; | 2633 | ret = -ENOMEM; |
2634 | goto out_free_bus; | 2634 | goto out_free_bus; |
2635 | } | 2635 | } |
2636 | 2636 | ||
2637 | for (i = 0; i < PHY_MAX_ADDR; i++) | 2637 | /* register MDIO bus */ |
2638 | mdp->mii_bus->irq[i] = PHY_POLL; | 2638 | if (dev->of_node) { |
2639 | if (pd->phy_irq > 0) | 2639 | ret = of_mdiobus_register(mdp->mii_bus, dev->of_node); |
2640 | mdp->mii_bus->irq[pd->phy] = pd->phy_irq; | 2640 | } else { |
2641 | for (i = 0; i < PHY_MAX_ADDR; i++) | ||
2642 | mdp->mii_bus->irq[i] = PHY_POLL; | ||
2643 | if (pd->phy_irq > 0) | ||
2644 | mdp->mii_bus->irq[pd->phy] = pd->phy_irq; | ||
2645 | |||
2646 | ret = mdiobus_register(mdp->mii_bus); | ||
2647 | } | ||
2641 | 2648 | ||
2642 | /* register mdio bus */ | ||
2643 | ret = mdiobus_register(mdp->mii_bus); | ||
2644 | if (ret) | 2649 | if (ret) |
2645 | goto out_free_bus; | 2650 | goto out_free_bus; |
2646 | 2651 | ||
2647 | dev_set_drvdata(&ndev->dev, mdp->mii_bus); | ||
2648 | |||
2649 | return 0; | 2652 | return 0; |
2650 | 2653 | ||
2651 | out_free_bus: | 2654 | out_free_bus: |
2652 | free_mdio_bitbang(mdp->mii_bus); | 2655 | free_mdio_bitbang(mdp->mii_bus); |
2653 | |||
2654 | out: | ||
2655 | return ret; | 2656 | return ret; |
2656 | } | 2657 | } |
2657 | 2658 | ||
@@ -2676,7 +2677,6 @@ static const u16 *sh_eth_get_register_offset(int register_type) | |||
2676 | reg_offset = sh_eth_offset_fast_sh3_sh2; | 2677 | reg_offset = sh_eth_offset_fast_sh3_sh2; |
2677 | break; | 2678 | break; |
2678 | default: | 2679 | default: |
2679 | pr_err("Unknown register type (%d)\n", register_type); | ||
2680 | break; | 2680 | break; |
2681 | } | 2681 | } |
2682 | 2682 | ||
@@ -2710,6 +2710,48 @@ static const struct net_device_ops sh_eth_netdev_ops_tsu = { | |||
2710 | .ndo_change_mtu = eth_change_mtu, | 2710 | .ndo_change_mtu = eth_change_mtu, |
2711 | }; | 2711 | }; |
2712 | 2712 | ||
2713 | #ifdef CONFIG_OF | ||
2714 | static struct sh_eth_plat_data *sh_eth_parse_dt(struct device *dev) | ||
2715 | { | ||
2716 | struct device_node *np = dev->of_node; | ||
2717 | struct sh_eth_plat_data *pdata; | ||
2718 | const char *mac_addr; | ||
2719 | |||
2720 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); | ||
2721 | if (!pdata) | ||
2722 | return NULL; | ||
2723 | |||
2724 | pdata->phy_interface = of_get_phy_mode(np); | ||
2725 | |||
2726 | mac_addr = of_get_mac_address(np); | ||
2727 | if (mac_addr) | ||
2728 | memcpy(pdata->mac_addr, mac_addr, ETH_ALEN); | ||
2729 | |||
2730 | pdata->no_ether_link = | ||
2731 | of_property_read_bool(np, "renesas,no-ether-link"); | ||
2732 | pdata->ether_link_active_low = | ||
2733 | of_property_read_bool(np, "renesas,ether-link-active-low"); | ||
2734 | |||
2735 | return pdata; | ||
2736 | } | ||
2737 | |||
2738 | static const struct of_device_id sh_eth_match_table[] = { | ||
2739 | { .compatible = "renesas,gether-r8a7740", .data = &r8a7740_data }, | ||
2740 | { .compatible = "renesas,ether-r8a7778", .data = &r8a777x_data }, | ||
2741 | { .compatible = "renesas,ether-r8a7779", .data = &r8a777x_data }, | ||
2742 | { .compatible = "renesas,ether-r8a7790", .data = &r8a779x_data }, | ||
2743 | { .compatible = "renesas,ether-r8a7791", .data = &r8a779x_data }, | ||
2744 | { .compatible = "renesas,ether-r7s72100", .data = &r7s72100_data }, | ||
2745 | { } | ||
2746 | }; | ||
2747 | MODULE_DEVICE_TABLE(of, sh_eth_match_table); | ||
2748 | #else | ||
2749 | static inline struct sh_eth_plat_data *sh_eth_parse_dt(struct device *dev) | ||
2750 | { | ||
2751 | return NULL; | ||
2752 | } | ||
2753 | #endif | ||
2754 | |||
2713 | static int sh_eth_drv_probe(struct platform_device *pdev) | 2755 | static int sh_eth_drv_probe(struct platform_device *pdev) |
2714 | { | 2756 | { |
2715 | int ret, devno = 0; | 2757 | int ret, devno = 0; |
@@ -2723,15 +2765,12 @@ static int sh_eth_drv_probe(struct platform_device *pdev) | |||
2723 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 2765 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
2724 | if (unlikely(res == NULL)) { | 2766 | if (unlikely(res == NULL)) { |
2725 | dev_err(&pdev->dev, "invalid resource\n"); | 2767 | dev_err(&pdev->dev, "invalid resource\n"); |
2726 | ret = -EINVAL; | 2768 | return -EINVAL; |
2727 | goto out; | ||
2728 | } | 2769 | } |
2729 | 2770 | ||
2730 | ndev = alloc_etherdev(sizeof(struct sh_eth_private)); | 2771 | ndev = alloc_etherdev(sizeof(struct sh_eth_private)); |
2731 | if (!ndev) { | 2772 | if (!ndev) |
2732 | ret = -ENOMEM; | 2773 | return -ENOMEM; |
2733 | goto out; | ||
2734 | } | ||
2735 | 2774 | ||
2736 | /* The sh Ether-specific entries in the device structure. */ | 2775 | /* The sh Ether-specific entries in the device structure. */ |
2737 | ndev->base_addr = res->start; | 2776 | ndev->base_addr = res->start; |
@@ -2763,6 +2802,8 @@ static int sh_eth_drv_probe(struct platform_device *pdev) | |||
2763 | pm_runtime_enable(&pdev->dev); | 2802 | pm_runtime_enable(&pdev->dev); |
2764 | pm_runtime_resume(&pdev->dev); | 2803 | pm_runtime_resume(&pdev->dev); |
2765 | 2804 | ||
2805 | if (pdev->dev.of_node) | ||
2806 | pd = sh_eth_parse_dt(&pdev->dev); | ||
2766 | if (!pd) { | 2807 | if (!pd) { |
2767 | dev_err(&pdev->dev, "no platform data\n"); | 2808 | dev_err(&pdev->dev, "no platform data\n"); |
2768 | ret = -EINVAL; | 2809 | ret = -EINVAL; |
@@ -2778,8 +2819,22 @@ static int sh_eth_drv_probe(struct platform_device *pdev) | |||
2778 | mdp->ether_link_active_low = pd->ether_link_active_low; | 2819 | mdp->ether_link_active_low = pd->ether_link_active_low; |
2779 | 2820 | ||
2780 | /* set cpu data */ | 2821 | /* set cpu data */ |
2781 | mdp->cd = (struct sh_eth_cpu_data *)id->driver_data; | 2822 | if (id) { |
2823 | mdp->cd = (struct sh_eth_cpu_data *)id->driver_data; | ||
2824 | } else { | ||
2825 | const struct of_device_id *match; | ||
2826 | |||
2827 | match = of_match_device(of_match_ptr(sh_eth_match_table), | ||
2828 | &pdev->dev); | ||
2829 | mdp->cd = (struct sh_eth_cpu_data *)match->data; | ||
2830 | } | ||
2782 | mdp->reg_offset = sh_eth_get_register_offset(mdp->cd->register_type); | 2831 | mdp->reg_offset = sh_eth_get_register_offset(mdp->cd->register_type); |
2832 | if (!mdp->reg_offset) { | ||
2833 | dev_err(&pdev->dev, "Unknown register type (%d)\n", | ||
2834 | mdp->cd->register_type); | ||
2835 | ret = -EINVAL; | ||
2836 | goto out_release; | ||
2837 | } | ||
2783 | sh_eth_set_default_cpu_data(mdp->cd); | 2838 | sh_eth_set_default_cpu_data(mdp->cd); |
2784 | 2839 | ||
2785 | /* set function */ | 2840 | /* set function */ |
@@ -2825,6 +2880,13 @@ static int sh_eth_drv_probe(struct platform_device *pdev) | |||
2825 | } | 2880 | } |
2826 | } | 2881 | } |
2827 | 2882 | ||
2883 | /* MDIO bus init */ | ||
2884 | ret = sh_mdio_init(mdp, pd); | ||
2885 | if (ret) { | ||
2886 | dev_err(&ndev->dev, "failed to initialise MDIO\n"); | ||
2887 | goto out_release; | ||
2888 | } | ||
2889 | |||
2828 | netif_napi_add(ndev, &mdp->napi, sh_eth_poll, 64); | 2890 | netif_napi_add(ndev, &mdp->napi, sh_eth_poll, 64); |
2829 | 2891 | ||
2830 | /* network device register */ | 2892 | /* network device register */ |
@@ -2832,31 +2894,23 @@ static int sh_eth_drv_probe(struct platform_device *pdev) | |||
2832 | if (ret) | 2894 | if (ret) |
2833 | goto out_napi_del; | 2895 | goto out_napi_del; |
2834 | 2896 | ||
2835 | /* mdio bus init */ | ||
2836 | ret = sh_mdio_init(ndev, pdev->id, pd); | ||
2837 | if (ret) | ||
2838 | goto out_unregister; | ||
2839 | |||
2840 | /* print device information */ | 2897 | /* print device information */ |
2841 | pr_info("Base address at 0x%x, %pM, IRQ %d.\n", | 2898 | netdev_info(ndev, "Base address at 0x%x, %pM, IRQ %d.\n", |
2842 | (u32)ndev->base_addr, ndev->dev_addr, ndev->irq); | 2899 | (u32)ndev->base_addr, ndev->dev_addr, ndev->irq); |
2843 | 2900 | ||
2844 | platform_set_drvdata(pdev, ndev); | 2901 | platform_set_drvdata(pdev, ndev); |
2845 | 2902 | ||
2846 | return ret; | 2903 | return ret; |
2847 | 2904 | ||
2848 | out_unregister: | ||
2849 | unregister_netdev(ndev); | ||
2850 | |||
2851 | out_napi_del: | 2905 | out_napi_del: |
2852 | netif_napi_del(&mdp->napi); | 2906 | netif_napi_del(&mdp->napi); |
2907 | sh_mdio_release(mdp); | ||
2853 | 2908 | ||
2854 | out_release: | 2909 | out_release: |
2855 | /* net_dev free */ | 2910 | /* net_dev free */ |
2856 | if (ndev) | 2911 | if (ndev) |
2857 | free_netdev(ndev); | 2912 | free_netdev(ndev); |
2858 | 2913 | ||
2859 | out: | ||
2860 | return ret; | 2914 | return ret; |
2861 | } | 2915 | } |
2862 | 2916 | ||
@@ -2865,9 +2919,9 @@ static int sh_eth_drv_remove(struct platform_device *pdev) | |||
2865 | struct net_device *ndev = platform_get_drvdata(pdev); | 2919 | struct net_device *ndev = platform_get_drvdata(pdev); |
2866 | struct sh_eth_private *mdp = netdev_priv(ndev); | 2920 | struct sh_eth_private *mdp = netdev_priv(ndev); |
2867 | 2921 | ||
2868 | sh_mdio_release(ndev); | ||
2869 | unregister_netdev(ndev); | 2922 | unregister_netdev(ndev); |
2870 | netif_napi_del(&mdp->napi); | 2923 | netif_napi_del(&mdp->napi); |
2924 | sh_mdio_release(mdp); | ||
2871 | pm_runtime_disable(&pdev->dev); | 2925 | pm_runtime_disable(&pdev->dev); |
2872 | free_netdev(ndev); | 2926 | free_netdev(ndev); |
2873 | 2927 | ||
@@ -2920,6 +2974,7 @@ static struct platform_driver sh_eth_driver = { | |||
2920 | .driver = { | 2974 | .driver = { |
2921 | .name = CARDNAME, | 2975 | .name = CARDNAME, |
2922 | .pm = SH_ETH_PM_OPS, | 2976 | .pm = SH_ETH_PM_OPS, |
2977 | .of_match_table = of_match_ptr(sh_eth_match_table), | ||
2923 | }, | 2978 | }, |
2924 | }; | 2979 | }; |
2925 | 2980 | ||