Commit df2f7ec8 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by David S. Miller

ep93xx_eth.c general cleanup

General cleanup of the ep93xx_eth driver.

1) Use pr_fmt() to prefix the module name and __func__ to the error 
   messages.
2) <linux/io.h> instead of <asm/io.h>
3) <mach/hardware.h> instead of <mach/ep93xx-regs.h> and <mach/platform.h>
4) Move the ep93xx_mdio_read (and ep93xx_mdio_write) function to eliminate
   the function prototype.
5) Change all the printk(<level> messages to pr_<level> and remove the 
   __func__ argument.
6) Use platform_get_{resource/irq} to get the platform resources and add
   an error check.
7) Use resource_size() for request_mem_region() and ioremap().
8) Use %pM to print the MAC address at the end of the probe.
9) Use dev->dev_addr not data->dev_addr for the MAC argument because a
   random address could be used if the platform does not supply one.

The message at the end of the probe is left as a printk since it displays
cleaner without the function name that would be displayed with pr_info().
Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Acked-by: default avatarLennert Buytenhek <kernel@wantstofly.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent e2eb8e38
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
* (at your option) any later version. * (at your option) any later version.
*/ */
#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
#include <linux/dma-mapping.h> #include <linux/dma-mapping.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/kernel.h> #include <linux/kernel.h>
...@@ -20,9 +22,9 @@ ...@@ -20,9 +22,9 @@
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <mach/ep93xx-regs.h> #include <linux/io.h>
#include <mach/platform.h>
#include <asm/io.h> #include <mach/hardware.h>
#define DRV_MODULE_NAME "ep93xx-eth" #define DRV_MODULE_NAME "ep93xx-eth"
#define DRV_MODULE_VERSION "0.1" #define DRV_MODULE_VERSION "0.1"
...@@ -185,7 +187,47 @@ struct ep93xx_priv ...@@ -185,7 +187,47 @@ struct ep93xx_priv
#define wrw(ep, off, val) __raw_writew((val), (ep)->base_addr + (off)) #define wrw(ep, off, val) __raw_writew((val), (ep)->base_addr + (off))
#define wrl(ep, off, val) __raw_writel((val), (ep)->base_addr + (off)) #define wrl(ep, off, val) __raw_writel((val), (ep)->base_addr + (off))
static int ep93xx_mdio_read(struct net_device *dev, int phy_id, int reg); static int ep93xx_mdio_read(struct net_device *dev, int phy_id, int reg)
{
struct ep93xx_priv *ep = netdev_priv(dev);
int data;
int i;
wrl(ep, REG_MIICMD, REG_MIICMD_READ | (phy_id << 5) | reg);
for (i = 0; i < 10; i++) {
if ((rdl(ep, REG_MIISTS) & REG_MIISTS_BUSY) == 0)
break;
msleep(1);
}
if (i == 10) {
pr_info("mdio read timed out\n");
data = 0xffff;
} else {
data = rdl(ep, REG_MIIDATA);
}
return data;
}
static void ep93xx_mdio_write(struct net_device *dev, int phy_id, int reg, int data)
{
struct ep93xx_priv *ep = netdev_priv(dev);
int i;
wrl(ep, REG_MIIDATA, data);
wrl(ep, REG_MIICMD, REG_MIICMD_WRITE | (phy_id << 5) | reg);
for (i = 0; i < 10; i++) {
if ((rdl(ep, REG_MIISTS) & REG_MIISTS_BUSY) == 0)
break;
msleep(1);
}
if (i == 10)
pr_info("mdio write timed out\n");
}
static struct net_device_stats *ep93xx_get_stats(struct net_device *dev) static struct net_device_stats *ep93xx_get_stats(struct net_device *dev)
{ {
...@@ -217,14 +259,11 @@ static int ep93xx_rx(struct net_device *dev, int processed, int budget) ...@@ -217,14 +259,11 @@ static int ep93xx_rx(struct net_device *dev, int processed, int budget)
rstat->rstat1 = 0; rstat->rstat1 = 0;
if (!(rstat0 & RSTAT0_EOF)) if (!(rstat0 & RSTAT0_EOF))
printk(KERN_CRIT "ep93xx_rx: not end-of-frame " pr_crit("not end-of-frame %.8x %.8x\n", rstat0, rstat1);
" %.8x %.8x\n", rstat0, rstat1);
if (!(rstat0 & RSTAT0_EOB)) if (!(rstat0 & RSTAT0_EOB))
printk(KERN_CRIT "ep93xx_rx: not end-of-buffer " pr_crit("not end-of-buffer %.8x %.8x\n", rstat0, rstat1);
" %.8x %.8x\n", rstat0, rstat1);
if ((rstat1 & RSTAT1_BUFFER_INDEX) >> 16 != entry) if ((rstat1 & RSTAT1_BUFFER_INDEX) >> 16 != entry)
printk(KERN_CRIT "ep93xx_rx: entry mismatch " pr_crit("entry mismatch %.8x %.8x\n", rstat0, rstat1);
" %.8x %.8x\n", rstat0, rstat1);
if (!(rstat0 & RSTAT0_RWE)) { if (!(rstat0 & RSTAT0_RWE)) {
ep->stats.rx_errors++; ep->stats.rx_errors++;
...@@ -241,8 +280,7 @@ static int ep93xx_rx(struct net_device *dev, int processed, int budget) ...@@ -241,8 +280,7 @@ static int ep93xx_rx(struct net_device *dev, int processed, int budget)
length = rstat1 & RSTAT1_FRAME_LENGTH; length = rstat1 & RSTAT1_FRAME_LENGTH;
if (length > MAX_PKT_SIZE) { if (length > MAX_PKT_SIZE) {
printk(KERN_NOTICE "ep93xx_rx: invalid length " pr_notice("invalid length %.8x %.8x\n", rstat0, rstat1);
" %.8x %.8x\n", rstat0, rstat1);
goto err; goto err;
} }
...@@ -371,11 +409,9 @@ static void ep93xx_tx_complete(struct net_device *dev) ...@@ -371,11 +409,9 @@ static void ep93xx_tx_complete(struct net_device *dev)
tstat->tstat0 = 0; tstat->tstat0 = 0;
if (tstat0 & TSTAT0_FA) if (tstat0 & TSTAT0_FA)
printk(KERN_CRIT "ep93xx_tx_complete: frame aborted " pr_crit("frame aborted %.8x\n", tstat0);
" %.8x\n", tstat0);
if ((tstat0 & TSTAT0_BUFFER_INDEX) != entry) if ((tstat0 & TSTAT0_BUFFER_INDEX) != entry)
printk(KERN_CRIT "ep93xx_tx_complete: entry mismatch " pr_crit("entry mismatch %.8x\n", tstat0);
" %.8x\n", tstat0);
if (tstat0 & TSTAT0_TXWE) { if (tstat0 & TSTAT0_TXWE) {
int length = ep->descs->tdesc[entry].tdesc1 & 0xfff; int length = ep->descs->tdesc[entry].tdesc1 & 0xfff;
...@@ -536,7 +572,7 @@ static int ep93xx_start_hw(struct net_device *dev) ...@@ -536,7 +572,7 @@ static int ep93xx_start_hw(struct net_device *dev)
} }
if (i == 10) { if (i == 10) {
printk(KERN_CRIT DRV_MODULE_NAME ": hw failed to reset\n"); pr_crit("hw failed to reset\n");
return 1; return 1;
} }
...@@ -581,7 +617,7 @@ static int ep93xx_start_hw(struct net_device *dev) ...@@ -581,7 +617,7 @@ static int ep93xx_start_hw(struct net_device *dev)
} }
if (i == 10) { if (i == 10) {
printk(KERN_CRIT DRV_MODULE_NAME ": hw failed to start\n"); pr_crit("hw failed to start\n");
return 1; return 1;
} }
...@@ -617,7 +653,7 @@ static void ep93xx_stop_hw(struct net_device *dev) ...@@ -617,7 +653,7 @@ static void ep93xx_stop_hw(struct net_device *dev)
} }
if (i == 10) if (i == 10)
printk(KERN_CRIT DRV_MODULE_NAME ": hw failed to reset\n"); pr_crit("hw failed to reset\n");
} }
static int ep93xx_open(struct net_device *dev) static int ep93xx_open(struct net_device *dev)
...@@ -681,48 +717,6 @@ static int ep93xx_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) ...@@ -681,48 +717,6 @@ static int ep93xx_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
return generic_mii_ioctl(&ep->mii, data, cmd, NULL); return generic_mii_ioctl(&ep->mii, data, cmd, NULL);
} }
static int ep93xx_mdio_read(struct net_device *dev, int phy_id, int reg)
{
struct ep93xx_priv *ep = netdev_priv(dev);
int data;
int i;
wrl(ep, REG_MIICMD, REG_MIICMD_READ | (phy_id << 5) | reg);
for (i = 0; i < 10; i++) {
if ((rdl(ep, REG_MIISTS) & REG_MIISTS_BUSY) == 0)
break;
msleep(1);
}
if (i == 10) {
printk(KERN_INFO DRV_MODULE_NAME ": mdio read timed out\n");
data = 0xffff;
} else {
data = rdl(ep, REG_MIIDATA);
}
return data;
}
static void ep93xx_mdio_write(struct net_device *dev, int phy_id, int reg, int data)
{
struct ep93xx_priv *ep = netdev_priv(dev);
int i;
wrl(ep, REG_MIIDATA, data);
wrl(ep, REG_MIICMD, REG_MIICMD_WRITE | (phy_id << 5) | reg);
for (i = 0; i < 10; i++) {
if ((rdl(ep, REG_MIISTS) & REG_MIISTS_BUSY) == 0)
break;
msleep(1);
}
if (i == 10)
printk(KERN_INFO DRV_MODULE_NAME ": mdio write timed out\n");
}
static void ep93xx_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) static void ep93xx_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
{ {
strcpy(info->driver, DRV_MODULE_NAME); strcpy(info->driver, DRV_MODULE_NAME);
...@@ -825,12 +819,19 @@ static int ep93xx_eth_probe(struct platform_device *pdev) ...@@ -825,12 +819,19 @@ static int ep93xx_eth_probe(struct platform_device *pdev)
struct ep93xx_eth_data *data; struct ep93xx_eth_data *data;
struct net_device *dev; struct net_device *dev;
struct ep93xx_priv *ep; struct ep93xx_priv *ep;
struct resource *mem;
int irq;
int err; int err;
if (pdev == NULL) if (pdev == NULL)
return -ENODEV; return -ENODEV;
data = pdev->dev.platform_data; data = pdev->dev.platform_data;
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
irq = platform_get_irq(pdev, 0);
if (!mem || irq < 0)
return -ENXIO;
dev = ep93xx_dev_alloc(data); dev = ep93xx_dev_alloc(data);
if (dev == NULL) { if (dev == NULL) {
err = -ENOMEM; err = -ENOMEM;
...@@ -842,8 +843,7 @@ static int ep93xx_eth_probe(struct platform_device *pdev) ...@@ -842,8 +843,7 @@ static int ep93xx_eth_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, dev); platform_set_drvdata(pdev, dev);
ep->res = request_mem_region(pdev->resource[0].start, ep->res = request_mem_region(mem->start, resource_size(mem),
pdev->resource[0].end - pdev->resource[0].start + 1,
dev_name(&pdev->dev)); dev_name(&pdev->dev));
if (ep->res == NULL) { if (ep->res == NULL) {
dev_err(&pdev->dev, "Could not reserve memory region\n"); dev_err(&pdev->dev, "Could not reserve memory region\n");
...@@ -851,14 +851,13 @@ static int ep93xx_eth_probe(struct platform_device *pdev) ...@@ -851,14 +851,13 @@ static int ep93xx_eth_probe(struct platform_device *pdev)
goto err_out; goto err_out;
} }
ep->base_addr = ioremap(pdev->resource[0].start, ep->base_addr = ioremap(mem->start, resource_size(mem));
pdev->resource[0].end - pdev->resource[0].start);
if (ep->base_addr == NULL) { if (ep->base_addr == NULL) {
dev_err(&pdev->dev, "Failed to ioremap ethernet registers\n"); dev_err(&pdev->dev, "Failed to ioremap ethernet registers\n");
err = -EIO; err = -EIO;
goto err_out; goto err_out;
} }
ep->irq = pdev->resource[1].start; ep->irq = irq;
ep->mii.phy_id = data->phy_id; ep->mii.phy_id = data->phy_id;
ep->mii.phy_id_mask = 0x1f; ep->mii.phy_id_mask = 0x1f;
...@@ -877,11 +876,8 @@ static int ep93xx_eth_probe(struct platform_device *pdev) ...@@ -877,11 +876,8 @@ static int ep93xx_eth_probe(struct platform_device *pdev)
goto err_out; goto err_out;
} }
printk(KERN_INFO "%s: ep93xx on-chip ethernet, IRQ %d, " printk(KERN_INFO "%s: ep93xx on-chip ethernet, IRQ %d, %pM\n",
"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x.\n", dev->name, dev->name, ep->irq, dev->dev_addr);
ep->irq, data->dev_addr[0], data->dev_addr[1],
data->dev_addr[2], data->dev_addr[3],
data->dev_addr[4], data->dev_addr[5]);
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment