summaryrefslogtreecommitdiff
path: root/drivers/net
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/ethernet/faraday/ftgmac100.c268
-rw-r--r--drivers/net/phy/broadcom.c13
2 files changed, 219 insertions, 62 deletions
diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
index 6d0c5d5eea6d..7eae1978b696 100644
--- a/drivers/net/ethernet/faraday/ftgmac100.c
+++ b/drivers/net/ethernet/faraday/ftgmac100.c
@@ -31,6 +31,7 @@
#include <linux/phy.h>
#include <linux/platform_device.h>
#include <net/ip.h>
+#include <net/ncsi.h>
#include "ftgmac100.h"
@@ -68,12 +69,16 @@ struct ftgmac100 {
struct net_device *netdev;
struct device *dev;
+ struct ncsi_dev *ndev;
struct napi_struct napi;
struct mii_bus *mii_bus;
int phy_irq[PHY_MAX_ADDR];
struct phy_device *phydev;
int old_speed;
+
+ bool use_ncsi;
+ bool enabled;
};
static int ftgmac100_alloc_rx_page(struct ftgmac100 *priv,
@@ -86,7 +91,6 @@ static int ftgmac100_alloc_rx_page(struct ftgmac100 *priv,
FTGMAC100_INT_XPKT_ETH | \
FTGMAC100_INT_XPKT_LOST | \
FTGMAC100_INT_AHB_ERR | \
- FTGMAC100_INT_PHYSTS_CHG | \
FTGMAC100_INT_RPKT_BUF | \
FTGMAC100_INT_NO_RXBUF)
@@ -134,7 +138,7 @@ static int ftgmac100_reset_hw(struct ftgmac100 *priv)
return -EIO;
}
-static void ftgmac100_set_mac(struct ftgmac100 *priv, const unsigned char *mac)
+static void ftgmac100_do_set_mac(struct ftgmac100 *priv, const unsigned char *mac)
{
unsigned int maddr = mac[0] << 8 | mac[1];
unsigned int laddr = mac[2] << 24 | mac[3] << 16 | mac[4] << 8 | mac[5];
@@ -143,6 +147,57 @@ static void ftgmac100_set_mac(struct ftgmac100 *priv, const unsigned char *mac)
iowrite32(laddr, priv->base + FTGMAC100_OFFSET_MAC_LADR);
}
+static void ftgmac100_setup_mac(struct ftgmac100 *priv)
+{
+ unsigned char mac[6];
+ unsigned int m;
+ unsigned int l;
+
+ /* XXX TODO: Read from device-tree if provided */
+
+ m = ioread32(priv->base + FTGMAC100_OFFSET_MAC_MADR);
+ l = ioread32(priv->base + FTGMAC100_OFFSET_MAC_LADR);
+
+ mac[0] = (m >> 8) & 0xff;
+ mac[1] = (m ) & 0xff;
+ mac[2] = (l >> 24) & 0xff;
+ mac[3] = (l >> 16) & 0xff;
+ mac[4] = (l >> 8) & 0xff;
+ mac[5] = (l ) & 0xff;
+
+ /* XXX Temp workaround for u-boot garbage */
+ if (!is_valid_ether_addr(mac)) {
+ mac[5] = (m >> 8) & 0xff;
+ mac[4] = (m ) & 0xff;
+ mac[3] = (l >> 24) & 0xff;
+ mac[2] = (l >> 16) & 0xff;
+ mac[1] = (l >> 8) & 0xff;
+ mac[0] = (l ) & 0xff;
+ }
+
+ if (!is_valid_ether_addr(mac)) {
+ eth_hw_addr_random(priv->netdev);
+ dev_info(priv->dev, "Generated random MAC address %pM\n",
+ priv->netdev->dev_addr);
+ } else {
+ dev_info(priv->dev, "Read MAC address from chip %pM\n", mac);
+ memcpy(priv->netdev->dev_addr, mac, 6);
+ }
+}
+
+static int ftgmac100_set_mac_addr(struct net_device *dev, void *p)
+{
+ struct ftgmac100 *priv = netdev_priv(dev);
+
+ int ret = eth_prepare_mac_addr_change(dev, p);
+ if (ret < 0)
+ return ret;
+ eth_commit_mac_addr_change(dev, p);
+ ftgmac100_do_set_mac(priv, dev->dev_addr);
+
+ return 0;
+}
+
static void ftgmac100_init_hw(struct ftgmac100 *priv)
{
/* setup ring buffer base registers */
@@ -157,7 +212,7 @@ static void ftgmac100_init_hw(struct ftgmac100 *priv)
iowrite32(FTGMAC100_APTC_RXPOLL_CNT(1), priv->base + FTGMAC100_OFFSET_APTC);
- ftgmac100_set_mac(priv, priv->netdev->dev_addr);
+ ftgmac100_do_set_mac(priv, priv->netdev->dev_addr);
}
#define MACCR_ENABLE_ALL (FTGMAC100_MACCR_TXDMA_EN | \
@@ -956,6 +1011,8 @@ static int ftgmac100_get_settings(struct net_device *netdev,
{
struct ftgmac100 *priv = netdev_priv(netdev);
+ if (!priv->phydev)
+ return -EINVAL;
return phy_ethtool_gset(priv->phydev, cmd);
}
@@ -964,6 +1021,8 @@ static int ftgmac100_set_settings(struct net_device *netdev,
{
struct ftgmac100 *priv = netdev_priv(netdev);
+ if (!priv->phydev)
+ return -EINVAL;
return phy_ethtool_sset(priv->phydev, cmd);
}
@@ -982,7 +1041,11 @@ static irqreturn_t ftgmac100_interrupt(int irq, void *dev_id)
struct net_device *netdev = dev_id;
struct ftgmac100 *priv = netdev_priv(netdev);
- if (likely(netif_running(netdev))) {
+ /* When running in NCSI mode, the interface should be
+ * ready to receive or transmit NCSI packet before it's
+ * opened.
+ */
+ if (likely(priv->use_ncsi || netif_running(netdev))) {
/* Disable interrupts for polling */
iowrite32(0, priv->base + FTGMAC100_OFFSET_IER);
napi_schedule(&priv->napi);
@@ -1036,13 +1099,12 @@ static int ftgmac100_poll(struct napi_struct *napi, int budget)
}
if (status & (FTGMAC100_INT_NO_RXBUF | FTGMAC100_INT_RPKT_LOST |
- FTGMAC100_INT_AHB_ERR | FTGMAC100_INT_PHYSTS_CHG)) {
+ FTGMAC100_INT_AHB_ERR)) {
if (net_ratelimit())
- netdev_info(netdev, "[ISR] = 0x%x: %s%s%s%s\n", status,
+ netdev_info(netdev, "[ISR] = 0x%x: %s%s%s\n", status,
status & FTGMAC100_INT_NO_RXBUF ? "NO_RXBUF " : "",
status & FTGMAC100_INT_RPKT_LOST ? "RPKT_LOST " : "",
- status & FTGMAC100_INT_AHB_ERR ? "AHB_ERR " : "",
- status & FTGMAC100_INT_PHYSTS_CHG ? "PHYSTS_CHG" : "");
+ status & FTGMAC100_INT_AHB_ERR ? "AHB_ERR " : "");
if (status & FTGMAC100_INT_NO_RXBUF) {
/* RX buffer unavailable */
@@ -1095,17 +1157,32 @@ static int ftgmac100_open(struct net_device *netdev)
goto err_hw;
ftgmac100_init_hw(priv);
- ftgmac100_start_hw(priv, 10);
+ ftgmac100_start_hw(priv, priv->use_ncsi ? 100 : 10);
- phy_start(priv->phydev);
+ if (priv->phydev)
+ phy_start(priv->phydev);
+ else if (priv->use_ncsi)
+ netif_carrier_on(priv->netdev);
napi_enable(&priv->napi);
netif_start_queue(netdev);
/* enable all interrupts */
iowrite32(INT_MASK_ALL_ENABLED, priv->base + FTGMAC100_OFFSET_IER);
+ /* Start the NCSI device */
+ if (priv->use_ncsi){
+ err = ncsi_start_dev(priv->ndev);
+ if (err)
+ goto err_ncsi;
+ }
+
+ priv->enabled = true;
return 0;
+err_ncsi:
+ napi_disable(&priv->napi);
+ netif_stop_queue(netdev);
+ iowrite32(0, priv->base + FTGMAC100_OFFSET_IER);
err_hw:
free_irq(priv->irq, netdev);
err_irq:
@@ -1114,16 +1191,21 @@ err_alloc:
return err;
}
-static int ftgmac100_stop(struct net_device *netdev)
+static int ftgmac100_stop_dev(struct net_device *netdev)
{
struct ftgmac100 *priv = netdev_priv(netdev);
+ if (!priv->enabled)
+ return 0;
+
/* disable all interrupts */
+ priv->enabled = false;
iowrite32(0, priv->base + FTGMAC100_OFFSET_IER);
netif_stop_queue(netdev);
napi_disable(&priv->napi);
- phy_stop(priv->phydev);
+ if (priv->phydev)
+ phy_stop(priv->phydev);
ftgmac100_stop_hw(priv);
free_irq(priv->irq, netdev);
@@ -1132,6 +1214,10 @@ static int ftgmac100_stop(struct net_device *netdev)
return 0;
}
+static int ftgmac100_stop(struct net_device *netdev)
+{
+ return ftgmac100_stop_dev(netdev);
+}
static int ftgmac100_hard_start_xmit(struct sk_buff *skb,
struct net_device *netdev)
{
@@ -1166,18 +1252,78 @@ static int ftgmac100_do_ioctl(struct net_device *netdev, struct ifreq *ifr, int
{
struct ftgmac100 *priv = netdev_priv(netdev);
+ if (!priv->phydev)
+ return -EINVAL;
return phy_mii_ioctl(priv->phydev, ifr, cmd);
}
+static int ftgmac100_setup_mdio(struct ftgmac100 *priv)
+{
+ int i, err = 0;
+
+ /* initialize mdio bus */
+ priv->mii_bus = mdiobus_alloc();
+ if (!priv->mii_bus) {
+ err = -EIO;
+ goto err_alloc_mdiobus;
+ }
+
+ priv->mii_bus->name = "ftgmac100_mdio";
+ snprintf(priv->mii_bus->id, MII_BUS_ID_SIZE, "ftgmac100_mii");
+
+ priv->mii_bus->priv = priv->netdev;
+ priv->mii_bus->read = ftgmac100_mdiobus_read;
+ priv->mii_bus->write = ftgmac100_mdiobus_write;
+ priv->mii_bus->irq = priv->phy_irq;
+
+ for (i = 0; i < PHY_MAX_ADDR; i++)
+ priv->mii_bus->irq[i] = PHY_POLL;
+
+ err = mdiobus_register(priv->mii_bus);
+ if (err) {
+ dev_err(priv->dev, "Cannot register MDIO bus!\n");
+ goto err_register_mdiobus;
+ }
+
+ err = ftgmac100_mii_probe(priv);
+ if (err) {
+ dev_err(priv->dev, "MII Probe failed!\n");
+ goto err_mii_probe;
+ }
+ return 0;
+
+err_mii_probe:
+ mdiobus_unregister(priv->mii_bus);
+err_register_mdiobus:
+ mdiobus_free(priv->mii_bus);
+err_alloc_mdiobus:
+ return err;
+}
+
+static void ftgmac100_destroy_mdio(struct ftgmac100 *priv)
+{
+ if (!priv->use_ncsi)
+ return;
+ phy_disconnect(priv->phydev);
+ mdiobus_unregister(priv->mii_bus);
+ mdiobus_free(priv->mii_bus);
+}
+
static const struct net_device_ops ftgmac100_netdev_ops = {
.ndo_open = ftgmac100_open,
.ndo_stop = ftgmac100_stop,
.ndo_start_xmit = ftgmac100_hard_start_xmit,
- .ndo_set_mac_address = eth_mac_addr,
+ .ndo_set_mac_address = ftgmac100_set_mac_addr,
.ndo_validate_addr = eth_validate_addr,
.ndo_do_ioctl = ftgmac100_do_ioctl,
};
+static void ftgmac100_ncsi_handler(struct ncsi_dev *nd)
+{
+ if (nd->nd_state == ncsi_dev_state_functional)
+ pr_info("NCSI interface %s\n",
+ nd->nd_link_up ? "up" : "down");
+}
/******************************************************************************
* struct platform_driver functions
*****************************************************************************/
@@ -1187,8 +1333,7 @@ static int ftgmac100_probe(struct platform_device *pdev)
int irq;
struct net_device *netdev;
struct ftgmac100 *priv;
- int err;
- int i;
+ int err = 0;
if (!pdev)
return -ENODEV;
@@ -1208,16 +1353,29 @@ static int ftgmac100_probe(struct platform_device *pdev)
goto err_alloc_etherdev;
}
+ /* Check for NCSI mode */
+ priv = netdev_priv(netdev);
SET_NETDEV_DEV(netdev, &pdev->dev);
+ if (pdev->dev.of_node &&
+ of_get_property(pdev->dev.of_node, "use-nc-si", NULL)) {
+ dev_info(&pdev->dev, "Using NCSI interface\n");
+ priv->phydev = NULL;
+ priv->use_ncsi = true;
+ } else {
+ priv->use_ncsi = false;
+ }
netdev->ethtool_ops = &ftgmac100_ethtool_ops;
netdev->netdev_ops = &ftgmac100_netdev_ops;
- netdev->features = NETIF_F_IP_CSUM | NETIF_F_GRO;
+ if (pdev->dev.of_node &&
+ of_get_property(pdev->dev.of_node, "no-hw-checksum", NULL))
+ netdev->features = NETIF_F_GRO;
+ else
+ netdev->features = NETIF_F_IP_CSUM | NETIF_F_GRO;
platform_set_drvdata(pdev, netdev);
/* setup private data */
- priv = netdev_priv(netdev);
priv->netdev = netdev;
priv->dev = &pdev->dev;
@@ -1244,60 +1402,41 @@ static int ftgmac100_probe(struct platform_device *pdev)
priv->irq = irq;
- /* initialize mdio bus */
- priv->mii_bus = mdiobus_alloc();
- if (!priv->mii_bus) {
- err = -EIO;
- goto err_alloc_mdiobus;
- }
-
- priv->mii_bus->name = "ftgmac100_mdio";
- snprintf(priv->mii_bus->id, MII_BUS_ID_SIZE, "ftgmac100_mii");
-
- priv->mii_bus->priv = netdev;
- priv->mii_bus->read = ftgmac100_mdiobus_read;
- priv->mii_bus->write = ftgmac100_mdiobus_write;
- priv->mii_bus->irq = priv->phy_irq;
-
- for (i = 0; i < PHY_MAX_ADDR; i++)
- priv->mii_bus->irq[i] = PHY_POLL;
+ /* Read MAC address or setup a new one */
+ ftgmac100_setup_mac(priv);
- err = mdiobus_register(priv->mii_bus);
- if (err) {
- dev_err(&pdev->dev, "Cannot register MDIO bus!\n");
- goto err_register_mdiobus;
- }
+ /* Register NCSI device */
+ if (priv->use_ncsi) {
+ priv->ndev = ncsi_register_dev(netdev, ftgmac100_ncsi_handler);
+ if (!priv->ndev)
+ goto err_ncsi_dev;
+ } else {
+ err = ftgmac100_setup_mdio(priv);
- err = ftgmac100_mii_probe(priv);
- if (err) {
- dev_err(&pdev->dev, "MII Probe failed!\n");
- goto err_mii_probe;
+ /* Survive PHY probe failure, chances things will work if the
+ * PHY was setup by the bootloader
+ */
+ if (err)
+ dev_warn(&pdev->dev, "Error %d setting up MDIO\n", err);
}
- /* register network device */
+ /* Register network device */
err = register_netdev(netdev);
if (err) {
dev_err(&pdev->dev, "Failed to register netdev\n");
goto err_register_netdev;
}
- netdev_info(netdev, "irq %d, mapped at %p\n", priv->irq, priv->base);
-
- if (!is_valid_ether_addr(netdev->dev_addr)) {
- eth_hw_addr_random(netdev);
- netdev_info(netdev, "generated random MAC address %pM\n",
- netdev->dev_addr);
- }
+ netdev_dbg(netdev, "irq %d, mapped at %p\n", priv->irq, priv->base);
return 0;
err_register_netdev:
- phy_disconnect(priv->phydev);
-err_mii_probe:
- mdiobus_unregister(priv->mii_bus);
-err_register_mdiobus:
- mdiobus_free(priv->mii_bus);
-err_alloc_mdiobus:
+ if (!priv->use_ncsi)
+ ftgmac100_destroy_mdio(priv);
+ else
+ ncsi_unregister_dev(priv->ndev);
+err_ncsi_dev:
iounmap(priv->base);
err_ioremap:
release_resource(priv->res);
@@ -1318,9 +1457,7 @@ static int __exit ftgmac100_remove(struct platform_device *pdev)
unregister_netdev(netdev);
- phy_disconnect(priv->phydev);
- mdiobus_unregister(priv->mii_bus);
- mdiobus_free(priv->mii_bus);
+ ftgmac100_destroy_mdio(priv);
iounmap(priv->base);
release_resource(priv->res);
@@ -1330,11 +1467,18 @@ static int __exit ftgmac100_remove(struct platform_device *pdev)
return 0;
}
+static const struct of_device_id ftgmac100_of_match[] = {
+ { .compatible = "faraday,ftgmac100" },
+ { }
+};
+MODULE_DEVICE_TABLE(of, ftgmac100_of_match);
+
static struct platform_driver ftgmac100_driver = {
.probe = ftgmac100_probe,
- .remove = __exit_p(ftgmac100_remove),
+ .remove = ftgmac100_remove,
.driver = {
- .name = DRV_NAME,
+ .name = DRV_NAME,
+ .of_match_table = ftgmac100_of_match,
},
};
diff --git a/drivers/net/phy/broadcom.c b/drivers/net/phy/broadcom.c
index 3ce5d9514623..95208b0e36ca 100644
--- a/drivers/net/phy/broadcom.c
+++ b/drivers/net/phy/broadcom.c
@@ -604,6 +604,18 @@ static struct phy_driver broadcom_drivers[] = {
.ack_interrupt = brcm_fet_ack_interrupt,
.config_intr = brcm_fet_config_intr,
.driver = { .owner = THIS_MODULE },
+}, {
+ .phy_id = PHY_ID_BCM54210E,
+ .phy_id_mask = 0xfffffff0,
+ .name = "Broadcom BCM54210E",
+ .features = PHY_BASIC_FEATURES |
+ SUPPORTED_Pause | SUPPORTED_Asym_Pause,
+ .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
+ .config_init = bcm54xx_config_init,
+ .config_aneg = genphy_config_aneg,
+ .read_status = genphy_read_status,
+ .ack_interrupt = bcm_phy_ack_intr,
+ .config_intr = bcm_phy_config_intr,
} };
module_phy_driver(broadcom_drivers);
@@ -621,6 +633,7 @@ static struct mdio_device_id __maybe_unused broadcom_tbl[] = {
{ PHY_ID_BCM57780, 0xfffffff0 },
{ PHY_ID_BCMAC131, 0xfffffff0 },
{ PHY_ID_BCM5241, 0xfffffff0 },
+ { PHY_ID_BCM54210E, 0xfffffff0},
{ }
};