diff options
author | H Hartley Sweeten <hsweeten@visionengravers.com> | 2010-01-08 03:53:03 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-01-08 03:53:03 -0500 |
commit | df2f7ec8c09ce879245c3309d859218188123ef1 (patch) | |
tree | 423d022048f001c5c073e6380b846b158eab2033 /drivers/net/arm | |
parent | e2eb8e38592f28d8be4a518f44d3385272dedddb (diff) |
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: H Hartley Sweeten <hsweeten@visionengravers.com>
Acked-by: Lennert Buytenhek <kernel@wantstofly.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/arm')
-rw-r--r-- | drivers/net/arm/ep93xx_eth.c | 140 |
1 files changed, 68 insertions, 72 deletions
diff --git a/drivers/net/arm/ep93xx_eth.c b/drivers/net/arm/ep93xx_eth.c index b25467ac895c..bf72d57a0afd 100644 --- a/drivers/net/arm/ep93xx_eth.c +++ b/drivers/net/arm/ep93xx_eth.c | |||
@@ -9,6 +9,8 @@ | |||
9 | * (at your option) any later version. | 9 | * (at your option) any later version. |
10 | */ | 10 | */ |
11 | 11 | ||
12 | #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__ | ||
13 | |||
12 | #include <linux/dma-mapping.h> | 14 | #include <linux/dma-mapping.h> |
13 | #include <linux/module.h> | 15 | #include <linux/module.h> |
14 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
@@ -20,9 +22,9 @@ | |||
20 | #include <linux/moduleparam.h> | 22 | #include <linux/moduleparam.h> |
21 | #include <linux/platform_device.h> | 23 | #include <linux/platform_device.h> |
22 | #include <linux/delay.h> | 24 | #include <linux/delay.h> |
23 | #include <mach/ep93xx-regs.h> | 25 | #include <linux/io.h> |
24 | #include <mach/platform.h> | 26 | |
25 | #include <asm/io.h> | 27 | #include <mach/hardware.h> |
26 | 28 | ||
27 | #define DRV_MODULE_NAME "ep93xx-eth" | 29 | #define DRV_MODULE_NAME "ep93xx-eth" |
28 | #define DRV_MODULE_VERSION "0.1" | 30 | #define DRV_MODULE_VERSION "0.1" |
@@ -185,7 +187,47 @@ struct ep93xx_priv | |||
185 | #define wrw(ep, off, val) __raw_writew((val), (ep)->base_addr + (off)) | 187 | #define wrw(ep, off, val) __raw_writew((val), (ep)->base_addr + (off)) |
186 | #define wrl(ep, off, val) __raw_writel((val), (ep)->base_addr + (off)) | 188 | #define wrl(ep, off, val) __raw_writel((val), (ep)->base_addr + (off)) |
187 | 189 | ||
188 | static int ep93xx_mdio_read(struct net_device *dev, int phy_id, int reg); | 190 | static int ep93xx_mdio_read(struct net_device *dev, int phy_id, int reg) |
191 | { | ||
192 | struct ep93xx_priv *ep = netdev_priv(dev); | ||
193 | int data; | ||
194 | int i; | ||
195 | |||
196 | wrl(ep, REG_MIICMD, REG_MIICMD_READ | (phy_id << 5) | reg); | ||
197 | |||
198 | for (i = 0; i < 10; i++) { | ||
199 | if ((rdl(ep, REG_MIISTS) & REG_MIISTS_BUSY) == 0) | ||
200 | break; | ||
201 | msleep(1); | ||
202 | } | ||
203 | |||
204 | if (i == 10) { | ||
205 | pr_info("mdio read timed out\n"); | ||
206 | data = 0xffff; | ||
207 | } else { | ||
208 | data = rdl(ep, REG_MIIDATA); | ||
209 | } | ||
210 | |||
211 | return data; | ||
212 | } | ||
213 | |||
214 | static void ep93xx_mdio_write(struct net_device *dev, int phy_id, int reg, int data) | ||
215 | { | ||
216 | struct ep93xx_priv *ep = netdev_priv(dev); | ||
217 | int i; | ||
218 | |||
219 | wrl(ep, REG_MIIDATA, data); | ||
220 | wrl(ep, REG_MIICMD, REG_MIICMD_WRITE | (phy_id << 5) | reg); | ||
221 | |||
222 | for (i = 0; i < 10; i++) { | ||
223 | if ((rdl(ep, REG_MIISTS) & REG_MIISTS_BUSY) == 0) | ||
224 | break; | ||
225 | msleep(1); | ||
226 | } | ||
227 | |||
228 | if (i == 10) | ||
229 | pr_info("mdio write timed out\n"); | ||
230 | } | ||
189 | 231 | ||
190 | static struct net_device_stats *ep93xx_get_stats(struct net_device *dev) | 232 | static struct net_device_stats *ep93xx_get_stats(struct net_device *dev) |
191 | { | 233 | { |
@@ -217,14 +259,11 @@ static int ep93xx_rx(struct net_device *dev, int processed, int budget) | |||
217 | rstat->rstat1 = 0; | 259 | rstat->rstat1 = 0; |
218 | 260 | ||
219 | if (!(rstat0 & RSTAT0_EOF)) | 261 | if (!(rstat0 & RSTAT0_EOF)) |
220 | printk(KERN_CRIT "ep93xx_rx: not end-of-frame " | 262 | pr_crit("not end-of-frame %.8x %.8x\n", rstat0, rstat1); |
221 | " %.8x %.8x\n", rstat0, rstat1); | ||
222 | if (!(rstat0 & RSTAT0_EOB)) | 263 | if (!(rstat0 & RSTAT0_EOB)) |
223 | printk(KERN_CRIT "ep93xx_rx: not end-of-buffer " | 264 | pr_crit("not end-of-buffer %.8x %.8x\n", rstat0, rstat1); |
224 | " %.8x %.8x\n", rstat0, rstat1); | ||
225 | if ((rstat1 & RSTAT1_BUFFER_INDEX) >> 16 != entry) | 265 | if ((rstat1 & RSTAT1_BUFFER_INDEX) >> 16 != entry) |
226 | printk(KERN_CRIT "ep93xx_rx: entry mismatch " | 266 | pr_crit("entry mismatch %.8x %.8x\n", rstat0, rstat1); |
227 | " %.8x %.8x\n", rstat0, rstat1); | ||
228 | 267 | ||
229 | if (!(rstat0 & RSTAT0_RWE)) { | 268 | if (!(rstat0 & RSTAT0_RWE)) { |
230 | ep->stats.rx_errors++; | 269 | ep->stats.rx_errors++; |
@@ -241,8 +280,7 @@ static int ep93xx_rx(struct net_device *dev, int processed, int budget) | |||
241 | 280 | ||
242 | length = rstat1 & RSTAT1_FRAME_LENGTH; | 281 | length = rstat1 & RSTAT1_FRAME_LENGTH; |
243 | if (length > MAX_PKT_SIZE) { | 282 | if (length > MAX_PKT_SIZE) { |
244 | printk(KERN_NOTICE "ep93xx_rx: invalid length " | 283 | pr_notice("invalid length %.8x %.8x\n", rstat0, rstat1); |
245 | " %.8x %.8x\n", rstat0, rstat1); | ||
246 | goto err; | 284 | goto err; |
247 | } | 285 | } |
248 | 286 | ||
@@ -371,11 +409,9 @@ static void ep93xx_tx_complete(struct net_device *dev) | |||
371 | tstat->tstat0 = 0; | 409 | tstat->tstat0 = 0; |
372 | 410 | ||
373 | if (tstat0 & TSTAT0_FA) | 411 | if (tstat0 & TSTAT0_FA) |
374 | printk(KERN_CRIT "ep93xx_tx_complete: frame aborted " | 412 | pr_crit("frame aborted %.8x\n", tstat0); |
375 | " %.8x\n", tstat0); | ||
376 | if ((tstat0 & TSTAT0_BUFFER_INDEX) != entry) | 413 | if ((tstat0 & TSTAT0_BUFFER_INDEX) != entry) |
377 | printk(KERN_CRIT "ep93xx_tx_complete: entry mismatch " | 414 | pr_crit("entry mismatch %.8x\n", tstat0); |
378 | " %.8x\n", tstat0); | ||
379 | 415 | ||
380 | if (tstat0 & TSTAT0_TXWE) { | 416 | if (tstat0 & TSTAT0_TXWE) { |
381 | int length = ep->descs->tdesc[entry].tdesc1 & 0xfff; | 417 | int length = ep->descs->tdesc[entry].tdesc1 & 0xfff; |
@@ -536,7 +572,7 @@ static int ep93xx_start_hw(struct net_device *dev) | |||
536 | } | 572 | } |
537 | 573 | ||
538 | if (i == 10) { | 574 | if (i == 10) { |
539 | printk(KERN_CRIT DRV_MODULE_NAME ": hw failed to reset\n"); | 575 | pr_crit("hw failed to reset\n"); |
540 | return 1; | 576 | return 1; |
541 | } | 577 | } |
542 | 578 | ||
@@ -581,7 +617,7 @@ static int ep93xx_start_hw(struct net_device *dev) | |||
581 | } | 617 | } |
582 | 618 | ||
583 | if (i == 10) { | 619 | if (i == 10) { |
584 | printk(KERN_CRIT DRV_MODULE_NAME ": hw failed to start\n"); | 620 | pr_crit("hw failed to start\n"); |
585 | return 1; | 621 | return 1; |
586 | } | 622 | } |
587 | 623 | ||
@@ -617,7 +653,7 @@ static void ep93xx_stop_hw(struct net_device *dev) | |||
617 | } | 653 | } |
618 | 654 | ||
619 | if (i == 10) | 655 | if (i == 10) |
620 | printk(KERN_CRIT DRV_MODULE_NAME ": hw failed to reset\n"); | 656 | pr_crit("hw failed to reset\n"); |
621 | } | 657 | } |
622 | 658 | ||
623 | static int ep93xx_open(struct net_device *dev) | 659 | 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 | return generic_mii_ioctl(&ep->mii, data, cmd, NULL); | 717 | return generic_mii_ioctl(&ep->mii, data, cmd, NULL); |
682 | } | 718 | } |
683 | 719 | ||
684 | static int ep93xx_mdio_read(struct net_device *dev, int phy_id, int reg) | ||
685 | { | ||
686 | struct ep93xx_priv *ep = netdev_priv(dev); | ||
687 | int data; | ||
688 | int i; | ||
689 | |||
690 | wrl(ep, REG_MIICMD, REG_MIICMD_READ | (phy_id << 5) | reg); | ||
691 | |||
692 | for (i = 0; i < 10; i++) { | ||
693 | if ((rdl(ep, REG_MIISTS) & REG_MIISTS_BUSY) == 0) | ||
694 | break; | ||
695 | msleep(1); | ||
696 | } | ||
697 | |||
698 | if (i == 10) { | ||
699 | printk(KERN_INFO DRV_MODULE_NAME ": mdio read timed out\n"); | ||
700 | data = 0xffff; | ||
701 | } else { | ||
702 | data = rdl(ep, REG_MIIDATA); | ||
703 | } | ||
704 | |||
705 | return data; | ||
706 | } | ||
707 | |||
708 | static void ep93xx_mdio_write(struct net_device *dev, int phy_id, int reg, int data) | ||
709 | { | ||
710 | struct ep93xx_priv *ep = netdev_priv(dev); | ||
711 | int i; | ||
712 | |||
713 | wrl(ep, REG_MIIDATA, data); | ||
714 | wrl(ep, REG_MIICMD, REG_MIICMD_WRITE | (phy_id << 5) | reg); | ||
715 | |||
716 | for (i = 0; i < 10; i++) { | ||
717 | if ((rdl(ep, REG_MIISTS) & REG_MIISTS_BUSY) == 0) | ||
718 | break; | ||
719 | msleep(1); | ||
720 | } | ||
721 | |||
722 | if (i == 10) | ||
723 | printk(KERN_INFO DRV_MODULE_NAME ": mdio write timed out\n"); | ||
724 | } | ||
725 | |||
726 | static void ep93xx_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) | 720 | static void ep93xx_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) |
727 | { | 721 | { |
728 | strcpy(info->driver, DRV_MODULE_NAME); | 722 | strcpy(info->driver, DRV_MODULE_NAME); |
@@ -825,12 +819,19 @@ static int ep93xx_eth_probe(struct platform_device *pdev) | |||
825 | struct ep93xx_eth_data *data; | 819 | struct ep93xx_eth_data *data; |
826 | struct net_device *dev; | 820 | struct net_device *dev; |
827 | struct ep93xx_priv *ep; | 821 | struct ep93xx_priv *ep; |
822 | struct resource *mem; | ||
823 | int irq; | ||
828 | int err; | 824 | int err; |
829 | 825 | ||
830 | if (pdev == NULL) | 826 | if (pdev == NULL) |
831 | return -ENODEV; | 827 | return -ENODEV; |
832 | data = pdev->dev.platform_data; | 828 | data = pdev->dev.platform_data; |
833 | 829 | ||
830 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
831 | irq = platform_get_irq(pdev, 0); | ||
832 | if (!mem || irq < 0) | ||
833 | return -ENXIO; | ||
834 | |||
834 | dev = ep93xx_dev_alloc(data); | 835 | dev = ep93xx_dev_alloc(data); |
835 | if (dev == NULL) { | 836 | if (dev == NULL) { |
836 | err = -ENOMEM; | 837 | err = -ENOMEM; |
@@ -842,23 +843,21 @@ static int ep93xx_eth_probe(struct platform_device *pdev) | |||
842 | 843 | ||
843 | platform_set_drvdata(pdev, dev); | 844 | platform_set_drvdata(pdev, dev); |
844 | 845 | ||
845 | ep->res = request_mem_region(pdev->resource[0].start, | 846 | ep->res = request_mem_region(mem->start, resource_size(mem), |
846 | pdev->resource[0].end - pdev->resource[0].start + 1, | 847 | dev_name(&pdev->dev)); |
847 | dev_name(&pdev->dev)); | ||
848 | if (ep->res == NULL) { | 848 | if (ep->res == NULL) { |
849 | dev_err(&pdev->dev, "Could not reserve memory region\n"); | 849 | dev_err(&pdev->dev, "Could not reserve memory region\n"); |
850 | err = -ENOMEM; | 850 | err = -ENOMEM; |
851 | goto err_out; | 851 | goto err_out; |
852 | } | 852 | } |
853 | 853 | ||
854 | ep->base_addr = ioremap(pdev->resource[0].start, | 854 | ep->base_addr = ioremap(mem->start, resource_size(mem)); |
855 | pdev->resource[0].end - pdev->resource[0].start); | ||
856 | if (ep->base_addr == NULL) { | 855 | if (ep->base_addr == NULL) { |
857 | dev_err(&pdev->dev, "Failed to ioremap ethernet registers\n"); | 856 | dev_err(&pdev->dev, "Failed to ioremap ethernet registers\n"); |
858 | err = -EIO; | 857 | err = -EIO; |
859 | goto err_out; | 858 | goto err_out; |
860 | } | 859 | } |
861 | ep->irq = pdev->resource[1].start; | 860 | ep->irq = irq; |
862 | 861 | ||
863 | ep->mii.phy_id = data->phy_id; | 862 | ep->mii.phy_id = data->phy_id; |
864 | ep->mii.phy_id_mask = 0x1f; | 863 | ep->mii.phy_id_mask = 0x1f; |
@@ -877,11 +876,8 @@ static int ep93xx_eth_probe(struct platform_device *pdev) | |||
877 | goto err_out; | 876 | goto err_out; |
878 | } | 877 | } |
879 | 878 | ||
880 | printk(KERN_INFO "%s: ep93xx on-chip ethernet, IRQ %d, " | 879 | printk(KERN_INFO "%s: ep93xx on-chip ethernet, IRQ %d, %pM\n", |
881 | "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x.\n", dev->name, | 880 | dev->name, ep->irq, dev->dev_addr); |
882 | ep->irq, data->dev_addr[0], data->dev_addr[1], | ||
883 | data->dev_addr[2], data->dev_addr[3], | ||
884 | data->dev_addr[4], data->dev_addr[5]); | ||
885 | 881 | ||
886 | return 0; | 882 | return 0; |
887 | 883 | ||