ARC VMAC driver.
Subsystems (2)
PATCH 1/1 ARC VMAC driver.
This is a driver for the MAC IP block from ARC International. It is based on an existing driver found in ARC Linux distribution, but essentially, a full rewrite.
--- drivers/net/ethernet/Kconfig | 9 + drivers/net/ethernet/Makefile | 1 + drivers/net/ethernet/arcvmac.c | 1480 ++++++++++++++++++++++++++++++++++++++++ drivers/net/ethernet/arcvmac.h | 269 ++++++++ 4 files changed, 1759 insertions(+), 0 deletions(-) create mode 100644 drivers/net/ethernet/arcvmac.c create mode 100644 drivers/net/ethernet/arcvmac.h
drivers/net/ethernet/Kconfig +9 -0
@@ -23,6 +23,15 @@ source "drivers/net/ethernet/aeroflex/Kconfig" source "drivers/net/ethernet/alteon/Kconfig" source "drivers/net/ethernet/amd/Kconfig" source "drivers/net/ethernet/apple/Kconfig" + +config ARCVMAC + tristate "ARC VMAC ethernet driver" + select MII + select PHYLIB + select CRC32 + help + MAC present Zoran43xx, IP from ARC international + source "drivers/net/ethernet/atheros/Kconfig" source "drivers/net/ethernet/cadence/Kconfig" source "drivers/net/ethernet/adi/Kconfig"
drivers/net/ethernet/Makefile +1 -0
@@ -9,6 +9,7 @@ obj-$(CONFIG_GRETH) += aeroflex/ obj-$(CONFIG_NET_VENDOR_ALTEON) += alteon/ obj-$(CONFIG_NET_VENDOR_AMD) += amd/ obj-$(CONFIG_NET_VENDOR_APPLE) += apple/ +obj-$(CONFIG_ARCVMAC) += arcvmac.o obj-$(CONFIG_NET_VENDOR_ATHEROS) += atheros/ obj-$(CONFIG_NET_ATMEL) += cadence/ obj-$(CONFIG_NET_BFIN) += adi/
drivers/net/ethernet/arcvmac.c new file +1480 -0
1,480 lines not on this page · raw message
drivers/net/ethernet/arcvmac.h new file +269 -0
269 lines not on this page · raw message
Signature · 1 line
1.7.9.1
David Miller
maintainerFrom: Andreas Fenkart <[email protected]>
Date: Mon, 5 Mar 2012 10:59:45 +0100
Review
Quoted 1 line
(quoted diff) +1
-0+ unsigned mac_lo, mac_hi;
Please never say just "unsigned" but instead use "unsigned int" But in this case you're dealing with a fixed sized value so "u32" is most appropriate.
Review
Quoted 1 line
(quoted diff) +1
-0+ unsigned mac_lo, mac_hi;
Same here.
Quoted 1 line
+static void
vmac_mdio_xmit(struct vmac_priv *ap, unsigned val)
Again. So please fix this up in the entire driver.
drivers/net/ethernet/arcvmac.c line 137
Quoted 1 line
drivers/net/ethernet/arcvmac.c new file +1
-0+int report_change =0 ;
Please use 'bool' as the type and 'true' and 'false' as the values.
drivers/net/ethernet/arcvmac.c line 248
Quoted 3 lines
drivers/net/ethernet/arcvmac.c new file +3
-0+ ap->mii_bus =mdiobus_alloc (); +if (ap->mii_bus ==NULL ) +return -ENOMEM ;
Use "if (!ap->mii_bus)" for null pointer checks.
drivers/net/ethernet/arcvmac.c line 260
Quoted 2 lines
drivers/net/ethernet/arcvmac.c new file +2
-0+ ap->mii_bus->irq =kmalloc (sizeof (int ) *PHY_MAX_ADDR ,GFP_KERNEL ); +if (!ap->mii_bus->irq)
Which inconsistently you do correctly here.
drivers/net/ethernet/arcvmac.c line 354
Quoted 3 lines
drivers/net/ethernet/arcvmac.c new file +3
-0+struct vmac_priv *ap =netdev_priv (dev); +dev_dbg (&ap->pdev->dev,"rx error counter overrun. status = 0x%x\n" , + status);
Please add an empty line between the function variable declarations and the first actual code statement.
drivers/net/ethernet/arcvmac.c line 434
Quoted 4 lines
drivers/net/ethernet/arcvmac.c new file +4
-0+if (!fifo_empty (&ap->rx_ring)) { +dev_err (&ap->pdev->dev,"failed to reclaim %d rx sk_buff\n" , +fifo_used (&ap->rx_ring)); + }
You don't need openning and closing braces for a single line basic block. It just takes up an unnecessary extra line in the source.
drivers/net/ethernet/arcvmac.c line 596
Quoted 3 lines
drivers/net/ethernet/arcvmac.c new file +3
-0+/* locking: fct owns rx_ring tail to current DMA read position, alias +* 'received packets'. rx_refill owns area outside rx_ring, doesn't +* modify tail */
Code comments:
/* Like * this. */ /* Or like this. */ /* But not * like this. */
There are other instances of this issue in the driver, please fix those too.
drivers/net/ethernet/arcvmac.c line 708
Quoted 1 line
drivers/net/ethernet/arcvmac.c new file +1
-0+unsigned long tmp;
This is a 32-bit value not a long which is a non-fixed-sized type and might be 64-bit. You definitely want to use "u32" for these.
Quoted 1 line
+static void
vmac_toggle_rxint_unlocked(struct net_device *dev, int enable)
Use 'bool' for all the places where you do this "enable" argument in functions.
drivers/net/ethernet/arcvmac.c line 773
Quoted 1 line
drivers/net/ethernet/arcvmac.c new file +1
-0+ if ((status & RXINT_MASK) && (vmac_readl(ap, ENABLE) && RXINT_MASK) &&
All of these register bit tests are wrong, you're using "&& RXINT_MASK" instead of "& RXINT_MASK".
drivers/net/ethernet/arcvmac.c line 779
Quoted 1 line
drivers/net/ethernet/arcvmac.c new file +1
-0+if ((status &TXINT_MASK ) && (vmac_readl (ap,ENABLE ) &&TXINT_MASK )) {
Same bug.
drivers/net/ethernet/arcvmac.c line 798
Quoted 4 lines
drivers/net/ethernet/arcvmac.c new file +4
-0+static int vmac_tx_reclaim_unlocked (struct net_device *dev,int force) +{ +struct vmac_priv *ap =netdev_priv (dev); +int released =0 ;
Use 'bool' and true/false for 'force' and 'released'.
drivers/net/ethernet/arcvmac.c line 833
Quoted 1 line
drivers/net/ethernet/arcvmac.c new file +1
-0+dev_kfree_skb_any (skb);
You only need to use the significantly more expensive dev_kfree_skb_any() if this code can run in a hardware interrupt handler.
This is a NAPI driver and therefore it should only do reclaim from NAPI poll and thus software interrupt context. Therefore you can use dev_kfree_skb() which is 10 times faster than dev_kfree_skb_any() which results in a new software interrupt getting queued up.
drivers/net/ethernet/arcvmac.c line 878
Quoted 11 lines
drivers/net/ethernet/arcvmac.c new file +11
-0+if (unlikely (skb->len <ETH_ZLEN )) { +struct sk_buff *short_skb; + short_skb =netdev_alloc_skb (dev,ETH_ZLEN ); +if (!short_skb) +return NETDEV_TX_LOCKED ; + +memset (short_skb->data,0 ,ETH_ZLEN ); +memcpy (skb_put (short_skb,ETH_ZLEN ), skb->data, skb->len); +dev_kfree_skb (skb); + skb = short_skb; + }
Don't reinvent the wheel, use skb_pad() or similar, which is much more efficient than this open-coded version.
drivers/net/ethernet/arcvmac.c line 886
Quoted 2 lines
drivers/net/ethernet/arcvmac.c new file +2
-0+ desc->data =dma_map_single (&ap->pdev->dev, skb->data, skb->len, +DMA_TO_DEVICE );
Align the argument up to the openning parenthesis on the previous line:
desc->data = dma_map_single(&ap->pdev->dev, skb->data, skb->len, DMA_TO_DEVICE);
drivers/net/ethernet/arcvmac.c line 923
Quoted 3 lines
drivers/net/ethernet/arcvmac.c new file +3
-0+ ap->rxbd =dma_alloc_coherent (&ap->pdev->dev, size, + &ap->rxbd_dma, +GFP_KERNEL );
Same problem.
drivers/net/ethernet/arcvmac.c line 924
Quoted 1 line
drivers/net/ethernet/arcvmac.c new file +1
-0+if (ap->rxbd ==NULL )
Test with "if (!ptr)" not "if (ptr == NULL)"
drivers/net/ethernet/arcvmac.c line 931
Quoted 3 lines
drivers/net/ethernet/arcvmac.c new file +3
-0+ ap->txbd =dma_alloc_coherent (&ap->pdev->dev, size, + &ap->txbd_dma, +GFP_KERNEL );
Argument alignment.
Quoted 2 lines
(quoted diff) +2
-0+ dma_free_coherent(&ap->pdev->dev, sizeof(*ap->txbd) * ap->tx_ring.size, + ap->txbd, ap->txbd_dma);
...
Review
Quoted 2 lines
(quoted diff) +2
-0+ dma_free_coherent(&ap->pdev->dev, sizeof(*ap->rxbd) * ap->rx_ring.size, + ap->rxbd, ap->rxbd_dma);
Again and again.
drivers/net/ethernet/arcvmac.c line 970
Quoted 4 lines
drivers/net/ethernet/arcvmac.c new file +4
-0+dma_free_coherent (&ap->pdev->dev,sizeof (ap->txbd) * ap->tx_ring.size, + ap->txbd, ap->txbd_dma); +dma_free_coherent (&ap->pdev->dev,sizeof (ap->rxbd) * ap->rx_ring.size, + ap->rxbd, ap->rxbd_dma);
More of the same.
drivers/net/ethernet/arcvmac.c line 1002
Quoted 1 line
drivers/net/ethernet/arcvmac.c new file +1
-0+if (ap ==NULL )
Test "if (!ap)" instad.
drivers/net/ethernet/arcvmac.c line 1038
Quoted 2 lines
drivers/net/ethernet/arcvmac.c new file +2
-0+dev_err (&ap->pdev->dev,"Unable to request IRQ %d (error %d)\n" , + dev->irq, err);
Argument alignment.
drivers/net/ethernet/arcvmac.c line 1045
Quoted 2 lines
drivers/net/ethernet/arcvmac.c new file +2
-0+ temp |=ERR_MASK |TXCH_MASK |MSER_MASK |RXCR_MASK |RXFR_MASK | \ +RXFL_MASK ;
There is no reason to escape the newline with a "\" here, get rid of that.
drivers/net/ethernet/arcvmac.c line 1067
Quoted 2 lines
drivers/net/ethernet/arcvmac.c new file +2
-0+dev_info (&ap->pdev->dev,"PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n" , + phydev->drv->name,dev_name (&phydev->dev), phydev->irq);
Argument alignment.
drivers/net/ethernet/arcvmac.c line 1083
Quoted 1 line
drivers/net/ethernet/arcvmac.c new file +1
-0+unsigned int temp;
Use "u32" for the type.
drivers/net/ethernet/arcvmac.c line 1233
Quoted 2 lines
drivers/net/ethernet/arcvmac.c new file +2
-0+static void create_multicast_filter (struct net_device *dev, +int32_t *bitmask)
Argument alignment.
drivers/net/ethernet/arcvmac.c line 1265
Quoted 1 line
drivers/net/ethernet/arcvmac.c new file +1
-0+int promisc, reg;
Use 'bool' for 'promisc', use 'u32' for 'reg'.
drivers/net/ethernet/arcvmac.c line 1266
Quoted 1 line
drivers/net/ethernet/arcvmac.c new file +1
-0+int32_t bitmask[2 ];
Don't use int32_t in the kernel, use 'u32' instead.
drivers/net/ethernet/arcvmac.c line 1352
Quoted 2 lines
drivers/net/ethernet/arcvmac.c new file +2
-0+if (dma_get_mask (&pdev->dev) >DMA_BIT_MASK (32 ) || + pdev->dev.coherent_dma_mask >DMA_BIT_MASK (32 )) {
Align things properly:
if (dma_get_mask(&pdev->dev) > DMA_BIT_MASK(32) ||
pdev->dev.coherent_dma_mask > DMA_BIT_MASK(32)) {drivers/net/ethernet/arcvmac.c line 1396
Quoted 1 line
drivers/net/ethernet/arcvmac.c new file +1
-0+ dev->flags |=IFF_MULTICAST ;
Why in the world do you need to do this? The ethernet generic setup takes care of this for you.
drivers/net/ethernet/arcvmac.c line 1414
Quoted 2 lines
drivers/net/ethernet/arcvmac.c new file +2
-0+if (!is_valid_ether_addr (dev->dev_addr)) +random_ether_addr (dev->dev_addr);
Use dev_hw_addr_random() which will properly set the NET_ADDR_RANDOM attribute properly too.
drivers/net/ethernet/arcvmac.c line 1426
Quoted 2 lines
drivers/net/ethernet/arcvmac.c new file +2
-0+dev_info (&pdev->dev,"ARC VMAC at 0x%pP irq %d %pM\n" , &mem->start, + dev->irq, dev->dev_addr);
Align the arguments properly.
Quoted 1 line
+struct
vmac_priv{
Get rid of that ugly tab, use a single space instead.
Quoted 1 line
+static inline int
fifo_empty(struct dma_fifo *f)
Return 'bool'.
Quoted 1 line
+static inline int
fifo_full(struct dma_fifo *f)
Return 'bool'.
drivers/net/ethernet/arcvmac.h line 261
Quoted 3 lines
drivers/net/ethernet/arcvmac.h new file +3
-0+pr_info ("fifo: head %d, tail %d, size %d\n" , fifo->head, + fifo->tail, + fifo->size);
Align arguments properly.
David,
Am 5. März 2012 21:30 schrieb David Miller <[email protected]>:
Quoted 224 lines
From: Andreas Fenkart <[email protected]>
Date: Mon, 5 Mar 2012 10:59:45 +0100Quoted 1 line
+ unsigned
mac_lo,mac_hi;Please never say just "unsigned" but instead use "unsigned int" But in this case you're dealing with a fixed sized value so "u32" is most appropriate.
Quoted 1 line
+ unsigned
mac_lo,mac_hi;Same here.
Quoted 1 line
+static void
vmac_mdio_xmit(struct vmac_priv *ap, unsigned val)Again. So please fix this up in the entire driver.
Quoted 1 line
+ int
report_change= 0;Please use 'bool' as the type and 'true' and 'false' as the values.
Quoted 3 lines
+
ap->mii_bus=mdiobus_alloc();
+ if (ap->mii_bus== NULL)
+ return-ENOMEM;Use "if (!ap->mii_bus)" for null pointer checks.
Quoted 2 lines
+
ap->mii_bus->irq=kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL);
+ if (!ap->mii_bus->irq)Which inconsistently you do correctly here.
Quoted 3 lines
+ struct
vmac_priv*ap =netdev_priv(dev);
+ dev_dbg(&ap->pdev->dev, "rx error counter overrun. status = 0x%x\n",
+ status);Please add an empty line between the function variable declarations and the first actual code statement.
Quoted 4 lines
+ if (!fifo_empty(&ap->rx_ring)) {
+ dev_err(&ap->pdev->dev, "failed to reclaim %d rx sk_buff\n",
+fifo_used(&ap->rx_ring));
+ }You don't need openning and closing braces for a single line basic block. It just takes up an unnecessary extra line in the source.
Quoted 3 lines
+ /* locking: fct owns
rx_ringtail to current DMA read position, alias
+ * 'received packets'.rx_refillowns area outsiderx_ring, doesn't
+ * modify tail */Code comments:
/* Like
* this.
*//* Or like this. */
/* But not
* like this. */There are other instances of this issue in the driver, please fix those too.
Quoted 1 line
+ unsigned long tmp;
This is a 32-bit value not a long which is a non-fixed-sized type and might be 64-bit. You definitely want to use "u32" for these.
Quoted 1 line
+static void
vmac_toggle_rxint_unlocked(struct net_device *dev, int enable)Use 'bool' for all the places where you do this "enable" argument in functions.
Quoted 1 line
+ if ((status &
RXINT_MASK) && (vmac_readl(ap, ENABLE)&&RXINT_MASK) &&All of these register bit tests are wrong, you're using "&&
RXINT_MASK" instead of "&RXINT_MASK".Quoted 1 line
+ if ((status &
TXINT_MASK) && (vmac_readl(ap, ENABLE)&&TXINT_MASK)) {Same bug.
drivers/net/ethernet/arcvmac.c line 798
Quoted 4 lines
drivers/net/ethernet/arcvmac.c new file +4
-0+static int vmac_tx_reclaim_unlocked (struct net_device *dev,int force) +{ + struct vmac_priv *ap = netdev_priv(dev); + int released = 0;Use 'bool' and true/false for 'force' and 'released'.
Quoted 1 line
+
dev_kfree_skb_any(skb);You only need to use the significantly more expensive
dev_kfree_skb_any()if this code can run in a hardware interrupt handler.This is a NAPI driver and therefore it should only do reclaim from NAPI poll and thus software interrupt context. Therefore you can use
dev_kfree_skb()which is 10 times faster thandev_kfree_skb_any()which results in a new software interrupt getting queued up.Quoted 11 lines
+ if (
unlikely(skb->len < ETH_ZLEN)) {
+ structsk_buff*short_skb;
+short_skb=netdev_alloc_skb(dev, ETH_ZLEN);
+ if (!short_skb)
+ returnNETDEV_TX_LOCKED;
+
+memset(short_skb->data, 0, ETH_ZLEN);
+memcpy(skb_put(short_skb, ETH_ZLEN), skb->data, skb->len);
+dev_kfree_skb(skb);
+ skb =short_skb;
+ }Don't reinvent the wheel, use
skb_pad()or similar, which is much more efficient than this open-coded version.Quoted 2 lines
+
desc->data= dma_map_single(&ap->pdev->dev,skb->data,skb->len,
+DMA_TO_DEVICE);Align the argument up to the openning parenthesis on the previous line:
desc->data =
dma_map_single(&ap->pdev->dev, skb->data, skb->len, DMA_TO_DEVICE);Quoted 3 lines
+
ap->rxbd= dma_alloc_coherent(&ap->pdev->dev, size,
+&ap->rxbd_dma,
+GFP_KERNEL);Same problem.
Quoted 1 line
+ if (
ap->rxbd== NULL)Test with "if (!ptr)" not "if (ptr == NULL)"
Quoted 3 lines
+
ap->txbd= dma_alloc_coherent(&ap->pdev->dev, size,
+&ap->txbd_dma,
+GFP_KERNEL);Argument alignment.
Quoted 2 lines
+ dma_free_coherent(&ap->pdev->dev,
sizeof(*ap->txbd)*ap->tx_ring.size,
+ap->txbd,ap->txbd_dma);...
Quoted 2 lines
+ dma_free_coherent(&ap->pdev->dev,
sizeof(*ap->rxbd)*ap->rx_ring.size,
+ap->rxbd,ap->rxbd_dma);Again and again.
Quoted 4 lines
+ dma_free_coherent(&ap->pdev->dev,
sizeof(ap->txbd)*ap->tx_ring.size,
+ap->txbd,ap->txbd_dma);
+ dma_free_coherent(&ap->pdev->dev,sizeof(ap->rxbd)*ap->rx_ring.size,
+ap->rxbd,ap->rxbd_dma);More of the same.
Quoted 1 line
+ if (ap == NULL)
Test "if (!ap)" instad.
Quoted 2 lines
+ dev_err(&ap->pdev->dev, "Unable to request IRQ %d (error %d)\n",
+dev->irq, err);Argument alignment.
Quoted 2 lines
+ temp |=
ERR_MASK|TXCH_MASK|MSER_MASK|RXCR_MASK|RXFR_MASK| \
+RXFL_MASK;There is no reason to escape the newline with a "\" here, get rid of that.
Quoted 2 lines
+ dev_info(&ap->pdev->dev, "PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n",
+ phydev->drv->name,dev_name(&phydev->dev),phydev->irq);Argument alignment.
Quoted 1 line
+ unsigned int temp;
Use "u32" for the type.
Quoted 2 lines
+static void create_multicast_filter(struct
net_device*dev,
+int32_t*bitmask)Argument alignment.
Quoted 1 line
+ int promisc, reg;
Use 'bool' for 'promisc', use 'u32' for 'reg'.
Quoted 1 line
+
int32_tbitmask[2];Don't use
int32_tin the kernel, use 'u32' instead.Quoted 2 lines
+ if (
dma_get_mask(&pdev->dev)>DMA_BIT_MASK(32)||
+pdev->dev.coherent_dma_mask>DMA_BIT_MASK(32)) {Align things properly:
if (
dma_get_mask(&pdev->dev)>DMA_BIT_MASK(32)||pdev->dev.coherent_dma_mask>DMA_BIT_MASK(32)) {Quoted 1 line
+
dev->flags|=IFF_MULTICAST;Why in the world do you need to do this? The ethernet generic setup takes care of this for you.
Quoted 2 lines
+ if (!is_valid_ether_addr(dev->dev_addr))
+random_ether_addr(dev->dev_addr);Use
dev_hw_addr_random()which will properly set theNET_ADDR_RANDOMattribute properly too.Quoted 2 lines
+ dev_info(&pdev->dev, "ARC VMAC at 0x%pP irq %d %pM\n",
&mem->start,
+dev->irq,dev->dev_addr);Align the arguments properly.
Quoted 1 line
+struct
vmac_priv{Get rid of that ugly tab, use a single space instead.
Quoted 1 line
+static inline int
fifo_empty(struct dma_fifo *f)Return 'bool'.
Quoted 8 lines
Quoted 1 line
+static inline int
fifo_full(struct dma_fifo *f)Return 'bool'.
Quoted 3 lines
+ pr_info("fifo: head %d, tail %d, size %d\n",
fifo->head,
+fifo->tail,
+fifo->size);Align arguments properly.
Thanks. I fixed and I'll be sending out a rev 2 shortly.
Regards
Andi
PATCH 1/1 ARC VMAC driver.
This is a driver for the MAC IP block from ARC International. It is based on an existing driver found in ARC Linux distribution, but essentially, a full rewrite.
--- drivers/net/ethernet/Kconfig | 9 + drivers/net/ethernet/Makefile | 1 + drivers/net/ethernet/arcvmac.c | 1472 ++++++++++++++++++++++++++++++++++++++++ drivers/net/ethernet/arcvmac.h | 269 ++++++++ 4 files changed, 1751 insertions(+), 0 deletions(-)
drivers/net/ethernet/Kconfig +9 -0
@@ -23,6 +23,15 @@ source "drivers/net/ethernet/aeroflex/Kconfig" source "drivers/net/ethernet/alteon/Kconfig" source "drivers/net/ethernet/amd/Kconfig" source "drivers/net/ethernet/apple/Kconfig" + +config ARCVMAC + tristate "ARC VMAC ethernet driver" + select MII + select PHYLIB + select CRC32 + help + MAC present Zoran43xx, IP from ARC international + source "drivers/net/ethernet/atheros/Kconfig" source "drivers/net/ethernet/cadence/Kconfig" source "drivers/net/ethernet/adi/Kconfig"
drivers/net/ethernet/Makefile +1 -0
@@ -9,6 +9,7 @@ obj-$(CONFIG_GRETH) += aeroflex/ obj-$(CONFIG_NET_VENDOR_ALTEON) += alteon/ obj-$(CONFIG_NET_VENDOR_AMD) += amd/ obj-$(CONFIG_NET_VENDOR_APPLE) += apple/ +obj-$(CONFIG_ARCVMAC) += arcvmac.o obj-$(CONFIG_NET_VENDOR_ATHEROS) += atheros/ obj-$(CONFIG_NET_ATMEL) += cadence/ obj-$(CONFIG_NET_BFIN) += adi/
drivers/net/ethernet/arcvmac.c new file +1472 -0
1,472 lines not on this page · raw message
drivers/net/ethernet/arcvmac.h new file +269 -0
269 lines not on this page · raw message
Signature · 1 line
1.7.9.1
Hi Andreas,
Quoted 5 lines · Andreas Fenkart
This is a driver for the MAC IP block from ARC International. It is based on an existing driver found in ARC Linux distribution, but essentially, a full rewrite.
Signed-off-by Andreas Fenkart<[email protected]>
I have some phylib-related comments inline.
Quoted 131 lines
--- drivers/net/ethernet/Kconfig | 9 + drivers/net/ethernet/Makefile | 1 + drivers/net/ethernet/arcvmac.c | 1472 ++++++++++++++++++++++++++++++++++++++++ drivers/net/ethernet/arcvmac.h | 269 ++++++++ 4 files changed, 1751 insertions(+), 0 deletions(-)drivers/net/ethernet/Kconfig +9
-0@@ -23,6 +23,15 @@ source "drivers/net/ethernet/aeroflex/Kconfig" source "drivers/net/ethernet/alteon/Kconfig" source "drivers/net/ethernet/amd/Kconfig" source "drivers/net/ethernet/apple/Kconfig" + +config ARCVMAC + tristate "ARC VMAC ethernet driver" + select MII + select PHYLIB + select CRC32 + help + MAC present Zoran43xx, IP from ARC international + source "drivers/net/ethernet/atheros/Kconfig" source "drivers/net/ethernet/cadence/Kconfig" source "drivers/net/ethernet/adi/Kconfig"drivers/net/ethernet/Makefile +1
-0@@ -9,6 +9,7 @@ obj-$(CONFIG_GRETH) += aeroflex/ obj-$(CONFIG_NET_VENDOR_ALTEON) += alteon/ obj-$(CONFIG_NET_VENDOR_AMD) += amd/ obj-$(CONFIG_NET_VENDOR_APPLE) += apple/ +obj-$(CONFIG_ARCVMAC) += arcvmac.o obj-$(CONFIG_NET_VENDOR_ATHEROS) += atheros/ obj-$(CONFIG_NET_ATMEL) += cadence/ obj-$(CONFIG_NET_BFIN) += adi/drivers/net/ethernet/arcvmac.c new file +86
-0@@ -0,0 +1,1472 @@ +/* +* ARC VMAC Driver +* +* Copyright (C) 2009-2012 Andreas Fenkart +* All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Initial work taken from arc linux distribution, any bugs are mine +* +* -----<snip>----- +* Copyright (C) 2003-2006 Codito Technologies, for linux-2.4 port +* Copyright (C) 2006-2007 Celunite Inc, for linux-2.6 port +* Authors: [email protected], [email protected] +* -----<snip>----- +*/ + +#include <linux/clk.h> +#include <linux/crc32.h> +#include <linux/delay.h> +#include <linux/dma-mapping.h> +#include <linux/etherdevice.h> +#include <linux/init.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/netdevice.h> +#include <linux/phy.h> +#include <linux/platform_device.h> +#include <linux/slab.h> +#include <linux/sched.h> +#include <linux/types.h> + +#include "arcvmac.h" + +/* Register access macros */ +#define vmac_writel (port, value, reg) \ + writel(cpu_to_le32(value), (port)->regs + VMAC_##reg) +#define vmac_readl (port, reg) le32_to_cpu(readl((port)->regs + VMAC_##reg)) + +static int get_register_map (struct vmac_priv *ap); +static int put_register_map (struct vmac_priv *ap); +static void update_vmac_stats_unlocked (struct net_device *dev); +static int vmac_tx_reclaim_unlocked (struct net_device *dev,bool force); + +static unsigned char *read_mac_reg (struct net_device *dev, +unsigned char hwaddr[ETH_ALEN ]) +{ +struct vmac_priv *ap =netdev_priv (dev); +u32 mac_lo, mac_hi; + +WARN_ON (!hwaddr); + mac_lo =vmac_readl (ap,ADDRL ); + mac_hi =vmac_readl (ap,ADDRH ); + + hwaddr[0 ] = (mac_lo>>0 )&0xff ; + hwaddr[1 ] = (mac_lo>>8 )&0xff ; + hwaddr[2 ] = (mac_lo>>16 )&0xff ; + hwaddr[3 ] = (mac_lo>>24 )&0xff ; + hwaddr[4 ] = (mac_hi>>0 )&0xff ; + hwaddr[5 ] = (mac_hi>>8 )&0xff ; +return hwaddr; +} + +static void write_mac_reg (struct net_device *dev,unsigned char * hwaddr) +{ +struct vmac_priv *ap =netdev_priv (dev); +u32 mac_lo, mac_hi; + + mac_lo = hwaddr[3 ]<<24 | hwaddr[2 ]<<16 | hwaddr[1 ]<<8 | + hwaddr[0 ]; + mac_hi = hwaddr[5 ]<<8 | hwaddr[4 ];
drivers/net/ethernet/arcvmac.c line 96
Quoted 10 lines
drivers/net/ethernet/arcvmac.c new file +10
-0+ +vmac_writel (ap, mac_lo,ADDRL ); +vmac_writel (ap, mac_hi,ADDRH ); +} + +static void vmac_mdio_xmit (struct vmac_priv *ap,u32 val) +{ +init_completion (&ap->mdio_complete); +vmac_writel (ap, val,MDIO_DATA ); +wait_for_completion (&ap->mdio_complete);
I would rather switch to a variant which allows a timeout, just in case the MDIO transaction never completes, so you are not stuck here, and you can guarantee the maximum waiting time. You might also want to test if you need the _interruptible variant too in case you have a process like ethtool calling into your driver's ethtool ops callbacks. Then you also need to propagate the error to the callers.
drivers/net/ethernet/arcvmac.c
Quoted 9 lines
drivers/net/ethernet/arcvmac.c new file +9
-0+} + +static int vmac_mdio_read (struct mii_bus *bus,int phy_id,int phy_reg) +{ +struct vmac_priv *vmac = bus->priv; +u32 val; + +/* only 5 bits allowed for phy-addr and reg_offset */ +WARN_ON (phy_id& ~0x1f || phy_reg& ~0x1f );
A WARN_ON() here is a little too hard, just return -EINVAL.
Quoted 7 lines
drivers/net/ethernet/arcvmac.c new file +7
-0+ + val =MDIO_BASE |MDIO_OP_READ ; + val |= phy_id<<23 | phy_reg<<18 ; +vmac_mdio_xmit (vmac, val); + + val =vmac_readl (vmac,MDIO_DATA ); +return val&MDIO_DATA_MASK ;
drivers/net/ethernet/arcvmac.c
Quoted 10 lines
drivers/net/ethernet/arcvmac.c new file +10
-0+} + +static int vmac_mdio_write (struct mii_bus *bus,int phy_id,int phy_reg, +u16 value) +{ +struct vmac_priv *vmac = bus->priv; +u32 val; + +/* only 5 bits allowed for phy-addr and reg_offset */ +WARN_ON (phy_id& ~0x1f || phy_reg& ~0x1f );
Same here.
Quoted 55 lines
drivers/net/ethernet/arcvmac.c new file +55
-0+ + val =MDIO_BASE |MDIO_OP_WRITE ; + val |= phy_id<<23 | phy_reg<<18 ; + val |= (value&MDIO_DATA_MASK ); +vmac_mdio_xmit (vmac, val); + +return 0 ; +} + +static void vmac_handle_link_change (struct net_device *dev) +{ +struct vmac_priv *ap =netdev_priv (dev); +struct phy_device *phydev = ap->phy_dev; +unsigned long flags; +bool report_change = false; + +spin_lock_irqsave (&ap->lock, flags); + +if (phydev->duplex != ap->duplex) { +u32 tmp; + + tmp =vmac_readl (ap,ENABLE ); + +if (phydev->duplex) + tmp |=ENFL_MASK ; +else + tmp&= ~ENFL_MASK ; + +vmac_writel (ap, tmp,ENABLE ); + + ap->duplex = phydev->duplex; + report_change = true; + } + +if (phydev->speed != ap->speed) { + ap->speed = phydev->speed; + report_change = true; + } + +if (phydev->link != ap->link) { + ap->link = phydev->link; + report_change = true; + } + +spin_unlock_irqrestore (&ap->lock, flags); + +if (report_change) +phy_print_status (ap->phy_dev); +} + +static int __devinit vmac_mii_probe (struct net_device *dev) +{ +struct vmac_priv *ap =netdev_priv (dev); +struct phy_device *phydev =NULL ; +struct clk *vmac_clk;
drivers/net/ethernet/arcvmac.c line 187
Quoted 10 lines
drivers/net/ethernet/arcvmac.c new file +10
-0+unsigned long clock_rate; +int phy_addr, err; + +/* find the first phy */ +for (phy_addr =0 ; phy_addr<PHY_MAX_ADDR ; phy_addr++) { +if (ap->mii_bus->phy_map[phy_addr]) { + phydev = ap->mii_bus->phy_map[phy_addr]; +break ; + } + }
Use phy_find_first() instead of open-coding the iteration.
Quoted 57 lines
drivers/net/ethernet/arcvmac.c new file +57
-0+ +if (!phydev) { +dev_err (&ap->pdev->dev,"no PHY found\n" ); +return -ENODEV ; + } + +/* FIXME: add pin_irq, if avail */ + + phydev =phy_connect (dev,dev_name (&phydev->dev), + &vmac_handle_link_change,0 , +PHY_INTERFACE_MODE_MII ); + +if (IS_ERR (phydev)) { + err =PTR_ERR (phydev); +dev_err (&ap->pdev->dev,"could not attach to PHY %d\n" , err); + goto err_out; + } + + phydev->supported&=PHY_BASIC_FEATURES ; + phydev->supported |= SUPPORTED_Asym_Pause | SUPPORTED_Pause; + + vmac_clk =clk_get (&ap->pdev->dev,"arcvmac" ); +if (IS_ERR (vmac_clk)) { + err =PTR_ERR (vmac_clk); + goto err_disconnect; + } + + clock_rate =clk_get_rate (vmac_clk); +clk_put (vmac_clk); + +dev_dbg (&ap->pdev->dev,"vmac_clk: %lu Hz\n" , clock_rate); + +if (clock_rate<25000000 ) + phydev->supported&= ~(SUPPORTED_100baseT_Half | + SUPPORTED_100baseT_Full); + + phydev->advertising = phydev->supported; + + ap->link =0 ; + ap->speed =0 ; + ap->duplex =-1 ; + ap->phy_dev = phydev; + +return 0 ; + +err_disconnect: +phy_disconnect (phydev); +err_out: +return err; +} + +static int __devinit vmac_mii_init (struct vmac_priv *ap) +{ +unsigned long flags; +int err, i; + +spin_lock_irqsave (&ap->lock, flags);
drivers/net/ethernet/arcvmac.c line 254
Quoted 10 lines
drivers/net/ethernet/arcvmac.c new file +10
-0+ + ap->mii_bus =mdiobus_alloc (); +if (!ap->mii_bus) +return -ENOMEM ; + + ap->mii_bus->name ="vmac_mii_bus" ; + ap->mii_bus->read =&vmac_mdio_read; + ap->mii_bus->write =&vmac_mdio_write; + +snprintf (ap->mii_bus->id,MII_BUS_ID_SIZE ,"%x" ,0 );
Please use an unique name such as:
snprintf(ap->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x", ap->pdev->name, ap->pdev->id);
drivers/net/ethernet/arcvmac.c line 261
Quoted 7 lines
drivers/net/ethernet/arcvmac.c new file +7
-0+ + ap->mii_bus->priv = ap; + + err = -ENOMEM ; + ap->mii_bus->irq =kmalloc (sizeof (int ) *PHY_MAX_ADDR ,GFP_KERNEL ); +if (!ap->mii_bus->irq) + goto err_out;
This is a little unusual, rather do this:
if (!ap->mii_bus->irq) {
err = -ENOMEM;
goto err_out;
}Quoted 17 lines
drivers/net/ethernet/arcvmac.c new file +17
-0+ +for (i =0 ; i<PHY_MAX_ADDR ; i++) + ap->mii_bus->irq[i] =PHY_POLL ; + +spin_unlock_irqrestore (&ap->lock, flags); + +/* locking: mdio concurrency */ + + err =mdiobus_register (ap->mii_bus); +if (err) + goto err_out_free_mdio_irq; + + err =vmac_mii_probe (ap->dev); +if (err) + goto err_out_unregister_bus; + +return 0 ;
drivers/net/ethernet/arcvmac.c line 288
Quoted 10 lines
drivers/net/ethernet/arcvmac.c new file +10
-0+ +err_out_unregister_bus: +mdiobus_unregister (ap->mii_bus); +err_out_free_mdio_irq: +kfree (ap->mii_bus->irq); +err_out: +mdiobus_free (ap->mii_bus); +return err; +} +
--
Florian
Andreas Fenkart <[email protected]> :
Quoted 18 lines
This is a driver for the MAC IP block from ARC International. It is based on an existing driver found in ARC Linux distribution, but essentially, a full rewrite.
Signed-off-by Andreas Fenkart <[email protected]>--- drivers/net/ethernet/Kconfig | 9 + drivers/net/ethernet/Makefile | 1 + drivers/net/ethernet/arcvmac.c | 1472 ++++++++++++++++++++++++++++++++++++++++ drivers/net/ethernet/arcvmac.h | 269 ++++++++ 4 files changed, 1751 insertions(+), 0 deletions(-)drivers/net/ethernet/Kconfig +0
-0@@ -23,6 +23,15 @@ source "drivers/net/ethernet/aeroflex/Kconfig" source "drivers/net/ethernet/alteon/Kconfig"
drivers/net/ethernet/Kconfig source "drivers/net/ethernet/aeroflex/Kconfig" · line 33
Quoted 10 lines
drivers/net/ethernet/Kconfig +8
-0source "drivers/net/ethernet/amd/Kconfig" source "drivers/net/ethernet/apple/Kconfig" + +config ARCVMAC + tristate "ARC VMAC ethernet driver" + select MII + select PHYLIB + select CRC32 + help + MAC present Zoran43xx, IP from ARC international
It may not hurt to tell if it targets gigabit or fast ethernet.
drivers/net/ethernet/Makefile obj-$(CONFIG_GRETH) += aeroflex/ · line 12
Quoted 13 lines
drivers/net/ethernet/Kconfig +1
-0+ source "drivers/net/ethernet/atheros/Kconfig" source "drivers/net/ethernet/cadence/Kconfig" source "drivers/net/ethernet/adi/Kconfig"drivers/net/ethernet/Makefile +1
-0@@ -9,6 +9,7 @@ obj-$(CONFIG_GRETH) += aeroflex/ obj-$(CONFIG_NET_VENDOR_ALTEON) += alteon/ obj-$(CONFIG_NET_VENDOR_AMD) += amd/ obj-$(CONFIG_NET_VENDOR_APPLE) += apple/ +obj-$(CONFIG_ARCVMAC) += arcvmac.o
I am not sure we want it directly under drivers/net/ethernet.
[...]
Quoted 5 lines
drivers/net/ethernet/arcvmac.c new file +0
-0
[...]
drivers/net/ethernet/arcvmac.c line 66
Quoted 6 lines
drivers/net/ethernet/arcvmac.c new file +6
-0+ unsigned char hwaddr[ETH_ALEN]) +{ +struct vmac_priv *ap =netdev_priv (dev); +u32 mac_lo, mac_hi; + +WARN_ON (!hwaddr);
Useless. It will issue a nice Oops a few lines below anyway.
Quoted 11 lines
drivers/net/ethernet/arcvmac.c new file +11
-0+ mac_lo =vmac_readl (ap,ADDRL ); + mac_hi =vmac_readl (ap,ADDRH ); + + hwaddr[0 ] = (mac_lo >>0 ) &0xff ; + hwaddr[1 ] = (mac_lo >>8 ) &0xff ; + hwaddr[2 ] = (mac_lo >>16 ) &0xff ; + hwaddr[3 ] = (mac_lo >>24 ) &0xff ; + hwaddr[4 ] = (mac_hi >>0 ) &0xff ; + hwaddr[5 ] = (mac_hi >>8 ) &0xff ; +return hwaddr; +}
[...]
drivers/net/ethernet/arcvmac.c line 246
Quoted 8 lines
drivers/net/ethernet/arcvmac.c new file +8
-0+static int __devinit vmac_mii_init (struct vmac_priv *ap) +{ +unsigned long flags; +int err, i; + +spin_lock_irqsave (&ap->lock, flags); + + ap->mii_bus =mdiobus_alloc ();
Bug: non GFP_ATOMIC alloc with spinlock held.
drivers/net/ethernet/arcvmac.c line 259
Quoted 13 lines
drivers/net/ethernet/arcvmac.c new file +13
-0+if (!ap->mii_bus) +return -ENOMEM ; + + ap->mii_bus->name ="vmac_mii_bus" ; + ap->mii_bus->read = &vmac_mdio_read; + ap->mii_bus->write = &vmac_mdio_write; + +snprintf (ap->mii_bus->id,MII_BUS_ID_SIZE ,"%x" ,0 ); + + ap->mii_bus->priv = ap; + + err = -ENOMEM ; + ap->mii_bus->irq =kmalloc (sizeof (int ) *PHY_MAX_ADDR ,GFP_KERNEL );
Sic.
[...]
drivers/net/ethernet/arcvmac.c line 293
Quoted 5 lines
drivers/net/ethernet/arcvmac.c new file +5
-0+static void vmac_mii_exit_unlocked (struct net_device *dev) +{ +struct vmac_priv *ap =netdev_priv (dev); + +if (ap->phy_dev)
It can't be NULL.
Quoted 5 lines
drivers/net/ethernet/arcvmac.c new file +5
-0+phy_disconnect (ap->phy_dev); + +mdiobus_unregister (ap->mii_bus); +kfree (ap->mii_bus->irq); +mdiobus_free (ap->mii_bus);
drivers/net/ethernet/arcvmac.c line 308
Quoted 10 lines
drivers/net/ethernet/arcvmac.c new file +10
-0+} + +static int vmacether_get_settings (struct net_device *dev, +struct ethtool_cmd *cmd) +{ +struct vmac_priv *ap =netdev_priv (dev); +struct phy_device *phydev = ap->phy_dev; + +if (!phydev) +return -ENODEV ;
It can't be NULL here either.
Please check you driver. Most of times, it can't be NULL.
drivers/net/ethernet/arcvmac.c line 320
Quoted 12 lines
drivers/net/ethernet/arcvmac.c new file +12
-0+ +return phy_ethtool_gset (phydev, cmd); +} + +static int vmacether_set_settings (struct net_device *dev, +struct ethtool_cmd *cmd) +{ +struct vmac_priv *ap =netdev_priv (dev); +struct phy_device *phydev = ap->phy_dev; + +if (!phydev) +return -ENODEV ;
Sic.
Quoted 4 lines
drivers/net/ethernet/arcvmac.c new file +4
-0+ +return phy_ethtool_sset (phydev, cmd); +} +
drivers/net/ethernet/arcvmac.c line 334
Quoted 10 lines
drivers/net/ethernet/arcvmac.c new file +10
-0+static int vmac_ioctl (struct net_device *dev,struct ifreq *rq,int cmd) +{ +struct vmac_priv *ap =netdev_priv (dev); +struct phy_device *phydev = ap->phy_dev; + +if (!netif_running (dev)) +return -EINVAL ; + +if (!phydev) +return -ENODEV ;
Sic.
[...]
Quoted 9 lines
drivers/net/ethernet/arcvmac.c new file +9
-0+static int update_error_counters_unlocked (struct net_device *dev,int status) +{ +struct vmac_priv *ap =netdev_priv (dev); + +dev_dbg (&ap->pdev->dev,"rx error counter overrun. status = 0x%x\n" , + status); + +/* programming error */ +WARN_ON (status &TXCH_MASK );
drivers/net/ethernet/arcvmac.c line 368
Quoted 10 lines
drivers/net/ethernet/arcvmac.c new file +10
-0+WARN_ON (!(status & (MSER_MASK |RXCR_MASK |RXFR_MASK |RXFL_MASK ))); + +if (status &MSER_MASK ) + dev->stats.rx_over_errors +=256 ;/* ran out of BD */ +if (status &RXCR_MASK ) + dev->stats.rx_crc_errors +=256 ; +if (status &RXFR_MASK ) + dev->stats.rx_frame_errors +=256 ; +if (status &RXFL_MASK ) + dev->stats.rx_fifo_errors +=256 ;
I would not mind a local &dev->stats variable.
[...]
Quoted 11 lines
drivers/net/ethernet/arcvmac.c new file +11
-0+static void update_tx_errors_unlocked (struct net_device *dev,int status) +{ +struct vmac_priv *ap =netdev_priv (dev); + +if (status &BD_UFLO ) + dev->stats.tx_fifo_errors++; + +if (ap->duplex) +return ; + +/* half duplex flags */
drivers/net/ethernet/arcvmac.c line 393
Quoted 10 lines
drivers/net/ethernet/arcvmac.c new file +10
-0+if (status &BD_LTCL ) + dev->stats.tx_window_errors++; +if (status &BD_RETRY_CT ) + dev->stats.collisions += (status &BD_RETRY_CT ) >>24 ; +if (status &BD_DROP )/* too many retries */ + dev->stats.tx_aborted_errors++; +if (status &BD_DEFER ) +dev_vdbg (&ap->pdev->dev,"\"defer to traffic\"\n" ); +if (status &BD_CARLOSS ) + dev->stats.tx_carrier_errors++;
Same thing as above.
[...]
drivers/net/ethernet/arcvmac.c line 732
Quoted 6 lines
drivers/net/ethernet/arcvmac.c new file +6
-0+static int vmac_poll (struct napi_struct *napi,int budget) +{ +struct vmac_priv *ap; +int rx_work_done; + + ap = container_of(napi, struct vmac_priv, napi);
You can 'struct vmac_priv *ap = container_of(napi ..."
drivers/net/ethernet/arcvmac.c line 740
Quoted 8 lines
drivers/net/ethernet/arcvmac.c new file +8
-0+ +vmac_tx_reclaim_unlocked (ap->dev, false); + + rx_work_done =vmac_rx_receive (ap->dev, budget); +if (rx_work_done >= budget) { +/* rx queue is not yet empty/clean */ +return rx_work_done; + }
Please no comment nor curly brace.
Quoted 14 lines
drivers/net/ethernet/arcvmac.c new file +14
-0+ +/* no more packet in rx/tx queue, remove device from poll queue */ +napi_complete (napi); + +/* clear status, only 1' affect register state */ +vmac_writel (ap,RXINT_MASK |TXINT_MASK ,STAT ); + +/* reenable IRQ */ +vmac_toggle_rxint_unlocked (ap->dev, true); +vmac_toggle_txint_unlocked (ap->dev, true); + +return rx_work_done; +} +
drivers/net/ethernet/arcvmac.c line 764
Quoted 10 lines
drivers/net/ethernet/arcvmac.c new file +10
-0+static irqreturn_t vmac_intr (int irq,void *dev_instance) +{ +struct net_device *dev = dev_instance; +struct vmac_priv *ap =netdev_priv (dev); +u32 status; + +spin_lock (&ap->lock); + + status =vmac_readl (ap,STAT ); +vmac_writel (ap, status,STAT );
I do not know what you are trying to achieve with the lock but it is not held in start_xmit when STAT is written.
Quoted 13 lines
drivers/net/ethernet/arcvmac.c new file +13
-0+ +if (unlikely (ap->shutdown)) +dev_err (&ap->pdev->dev,"ISR during close\n" ); + +if (unlikely (!status & (RXINT_MASK |MDIO_MASK |ERR_MASK ))) +dev_err (&ap->pdev->dev,"Spurious IRQ\n" ); + +if ((status &RXINT_MASK ) && (vmac_readl (ap,ENABLE ) &RXINT_MASK ) && + (ap->dma_rx_head !=vmac_readl (ap,MAC_RXRING_HEAD ))) { +vmac_toggle_rxint_unlocked (dev, false); +napi_schedule (&ap->napi); + } +
drivers/net/ethernet/arcvmac.c line 787
Quoted 10 lines
drivers/net/ethernet/arcvmac.c new file +10
-0+if ((status &TXINT_MASK ) && (vmac_readl (ap,ENABLE ) &TXINT_MASK )) { +vmac_toggle_txint_unlocked (dev, false); +napi_schedule (&ap->napi); + } + +if (status &MDIO_MASK ) +complete (&ap->mdio_complete); + +if (unlikely (status &ERR_MASK )) +update_error_counters_unlocked (dev, status);
Do yourself a favor : move everything to NAPI context.
[...]
Quoted 32 lines
drivers/net/ethernet/arcvmac.c new file +32
-0+static int vmac_start_xmit (struct sk_buff *skb,struct net_device *dev) +{ +struct vmac_priv *ap =netdev_priv (dev); +struct vmac_buffer_desc *desc; + +/* running under xmit lock */ +/* locking: modifies tx_ring head, tx_reclaim only tail */ + +/* no scatter/gatter see features below */ +WARN_ON (skb_shinfo (skb)->nr_frags !=0 ); +WARN_ON (skb->len >MAX_TX_BUFFER_LEN ); + +if (unlikely (fifo_full (&ap->tx_ring))) { +netif_stop_queue (dev); +dev_err (&ap->pdev->dev, +"xmit called while no tx desc available\n" ); +return NETDEV_TX_BUSY ; + } + +if (unlikely (skb->len <ETH_ZLEN )) { +if (skb_padto (skb,ETH_ZLEN )) +return NETDEV_TX_OK ; +skb_put (skb,ETH_ZLEN - skb->len); + } + +/* fill descriptor */ + ap->tx_skbuff[ap->tx_ring.head] = skb; + desc = &ap->txbd[ap->tx_ring.head]; +WARN_ON (desc->info &cpu_to_le32 (BD_DMA_OWN )); + + desc->data =dma_map_single (&ap->pdev->dev, skb->data, skb->len, +DMA_TO_DEVICE );
drivers/net/ethernet/arcvmac.c line 889
Quoted 10 lines
drivers/net/ethernet/arcvmac.c new file +10
-0+ +/* dma might already be polling */ +wmb (); + desc->info =cpu_to_le32 (BD_DMA_OWN |BD_FRST |BD_LAST | skb->len); + +/* kick tx dma, only 1' affect register */ +vmac_writel (ap,TXPL_MASK ,STAT ); + + dev->stats.tx_packets++; + dev->stats.tx_bytes += skb->len;
No byte queue limit ?
Quoted 32 lines
drivers/net/ethernet/arcvmac.c new file +32
-0+fifo_inc_head (&ap->tx_ring); + +/* stop queue if no more desc available */ +if (fifo_full (&ap->tx_ring)) +netif_stop_queue (dev); + +return NETDEV_TX_OK ; +} + +static int alloc_buffers_unlocked (struct net_device *dev) +{ +struct vmac_priv *ap =netdev_priv (dev); +int size, err = -ENOMEM ; + +fifo_init (&ap->rx_ring,RX_BDT_LEN ); +fifo_init (&ap->tx_ring,TX_BDT_LEN ); + +/* initialize skb list */ +memset (ap->rx_skbuff,0 ,sizeof (ap->rx_skbuff)); +memset (ap->tx_skbuff,0 ,sizeof (ap->tx_skbuff)); + +/* allocate DMA received descriptors */ + size =sizeof (*ap->rxbd) * ap->rx_ring.size; + ap->rxbd =dma_alloc_coherent (&ap->pdev->dev, size, + &ap->rxbd_dma, +GFP_KERNEL ); +if (!ap->rxbd) + goto err_out; + +/* allocate DMA transmit descriptors */ + size =sizeof (*ap->txbd) * ap->tx_ring.size; + ap->txbd = dma_alloc_coherent(&ap->pdev->dev, size,
drivers/net/ethernet/arcvmac.c line 931
Quoted 10 lines
drivers/net/ethernet/arcvmac.c new file +10
-0+ &ap->txbd_dma, + GFP_KERNEL); +if (!ap->txbd) + goto err_free_rxbd; + +/* ensure 8-byte aligned */ +WARN_ON (((uintptr_t )ap->txbd &0x7 ) || ((uintptr_t )ap->rxbd &0x7 )); + +memset (ap->txbd,0 ,sizeof (*ap->txbd) * ap->tx_ring.size); +memset (ap->rxbd,0 ,sizeof (*ap->rxbd) * ap->rx_ring.size);
It is already zeroed after dma_alloc_coherent.
[...]
Quoted 16 lines
drivers/net/ethernet/arcvmac.c new file +16
-0+static int vmac_open (struct net_device *dev) +{ +struct vmac_priv *ap =netdev_priv (dev); +struct phy_device *phydev; +unsigned long flags; +u32 mask, ctrl; +int err =0 ; + +/* locking: no concurrency yet */ + +if (!ap) +return -ENODEV ; + +spin_lock_irqsave (&ap->lock, flags); + ap->shutdown = false; +
drivers/net/ethernet/arcvmac.c line 1009
Quoted 10 lines
drivers/net/ethernet/arcvmac.c new file +10
-0+ err =get_register_map (ap); +if (err) +return err; + +vmac_hw_init (dev); + +/* mac address changed? */ +write_mac_reg (dev, dev->dev_addr); + + err =alloc_buffers_unlocked (dev);
dma_alloc_coherent(... GFP_KERNEL) with spinlock held.
What are you trying to lock against anyway ?
[...]
Quoted 19 lines
drivers/net/ethernet/arcvmac.c new file +19
-0+static int vmac_close (struct net_device *dev) +{ +struct vmac_priv *ap =netdev_priv (dev); +unsigned long flags; +u32 tmp; + +/* locking: protect everything, DMA / IRQ / timer */ +spin_lock_irqsave (&ap->lock, flags); + +/* complete running transfer, then stop */ + tmp =vmac_readl (ap,CONTROL ); + tmp &= ~(TXRN_MASK |RXRN_MASK ); +vmac_writel (ap, tmp,CONTROL ); + +/* save statistics, before unmapping */ +update_vmac_stats_unlocked (dev); + +/* reenable IRQ, process pending */ +spin_unlock_irqrestore (&ap->lock, flags);
drivers/net/ethernet/arcvmac.c line 1100
Quoted 10 lines
drivers/net/ethernet/arcvmac.c new file +10
-0+ +set_current_state (TASK_INTERRUPTIBLE ); +schedule_timeout (msecs_to_jiffies (20 )); + +/* shut it down now */ +spin_lock_irqsave (&ap->lock, flags); + ap->shutdown = true; + +netif_stop_queue (dev); +napi_disable (&ap->napi);
Bug: napi_disable may sleep and the driver is holding a spinlock.
Quoted 15 lines
drivers/net/ethernet/arcvmac.c new file +15
-0+/* disable phy */ +phy_stop (ap->phy_dev); +vmac_mii_exit_unlocked (dev); +netif_carrier_off (dev); + +/* disable interrupts */ +vmac_writel (ap,0 ,ENABLE ); +free_irq (dev->irq, dev); + +/* turn off vmac */ +vmac_writel (ap,0 ,CONTROL ); +/* vmac_reset_hw(vmac) */ + +/* locking: concurrency off */ +spin_unlock_irqrestore (&ap->lock, flags);
[...]
drivers/net/ethernet/arcvmac.c line 1128
Quoted 3 lines
drivers/net/ethernet/arcvmac.c new file +3
-0+static void update_vmac_stats_unlocked (struct net_device *dev) +{ +struct net_device_stats *_stats = &dev->stats;
What's wrong with plain 'stats' ?
[...]
Quoted 4 lines
drivers/net/ethernet/arcvmac.c new file +4
-0+static void create_multicast_filter (struct net_device *dev, +int32_t *bitmask) +{ +char *addrs;
drivers/net/ethernet/arcvmac.c line 1238
Quoted 10 lines
drivers/net/ethernet/arcvmac.c new file +10
-0+u32 crc; + +/* locking: done by net_device */ + +WARN_ON (netdev_mc_count (dev) ==0 ); +WARN_ON (dev->flags &IFF_ALLMULTI ); + + bitmask[0 ] = bitmask[1 ] =0 ; + + {
?
[...]
Quoted 28 lines
drivers/net/ethernet/arcvmac.c new file +28
-0+static int __devinit vmac_probe (struct platform_device *pdev) +{ +struct net_device *dev; +struct vmac_priv *ap; +struct resource *mem; +int err; + +/* locking: no concurrency */ + +if (dma_get_mask (&pdev->dev) >DMA_BIT_MASK (32 ) || + pdev->dev.coherent_dma_mask >DMA_BIT_MASK (32 )) { +dev_err (&pdev->dev, +"arcvmac supports only 32-bit DMA addresses\n" ); +return -ENODEV ; + } + + dev =alloc_etherdev (sizeof (*ap)); +if (!dev) { +dev_err (&pdev->dev,"etherdev alloc failed, aborting.\n" ); +return -ENOMEM ; + } + + ap =netdev_priv (dev); + + err = -ENODEV ; + mem =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!mem) { +dev_err (&pdev->dev,"no mmio resource defined\n" );
drivers/net/ethernet/arcvmac.c line 1372
Quoted 10 lines
drivers/net/ethernet/arcvmac.c new file +10
-0+ goto err_out; + } + ap->mem = mem; + + err =platform_get_irq (pdev,0 ); +if (err <0 ) { +dev_err (&pdev->dev,"no irq found\n" ); + goto err_out; + } + dev->irq = err;
net_device.{irq, base_addr} have been obsolete for years. Please don't use it to expose kernel internals to userspace.
Quoted 8 lines
drivers/net/ethernet/arcvmac.c new file +8
-0+ +spin_lock_init (&ap->lock); + +SET_NETDEV_DEV (dev, &pdev->dev); + ap->dev = dev; + ap->pdev = pdev; + +/* init rx timeout (used for oom) */
drivers/net/ethernet/arcvmac.c line 1390
Quoted 10 lines
drivers/net/ethernet/arcvmac.c new file +10
-0+init_timer (&ap->refill_timer); + ap->refill_timer.function = vmac_refill_rx_timer; + ap->refill_timer.data = (unsigned long )dev; +spin_lock_init (&ap->refill_lock); + +netif_napi_add (dev, &ap->napi, vmac_poll,64 ); + dev->netdev_ops = &vmac_netdev_ops; + dev->ethtool_ops = &vmac_ethtool_ops; + + dev->base_addr = (unsigned long )ap->regs;
(see above)
drivers/net/ethernet/arcvmac.c line 1400
Quoted 10 lines
drivers/net/ethernet/arcvmac.c new file +10
-0+ +/* prevent buffer chaining, favor speed over space */ + ap->rx_skb_size =ETH_FRAME_LEN +VMAC_BUFFER_PAD ; + +/* private struct functional */ + +/* temporarily map registers to fetch mac addr */ + err =get_register_map (ap); +if (err) + goto err_out;
Please use 'goto err_perform_some_unwinding_action' style.
You don't need to be literate. 'goto err_napi_del' will be good enough :o)
drivers/net/ethernet/arcvmac.c line 1411
Quoted 11 lines
drivers/net/ethernet/arcvmac.c new file +11
-0+ +/* mac address intialize, set vmac_open */ +read_mac_reg (dev, dev->dev_addr); + +if (!is_valid_ether_addr (dev->dev_addr)) +dev_hw_addr_random (dev, dev->dev_addr); + + err =register_netdev (dev); +if (err) { +dev_err (&pdev->dev,"Cannot register net device, aborting.\n" ); + goto err_out;
Should be something like 'goto err_I_wont_leak_register_memory_region'
drivers/net/ethernet/arcvmac.c line 1414
Quoted 3 lines
drivers/net/ethernet/arcvmac.c new file +3
-0+ } + +/* release the memory region, till open is called */
Why ? It adds a failure opportunity.
[...]
Quoted 5 lines
drivers/net/ethernet/arcvmac.h new file +0
-0
[...]
drivers/net/ethernet/arcvmac.h line 63
Quoted 9 lines
drivers/net/ethernet/arcvmac.h new file +9
-0+/* stat/enable use same bit mask */ +#define VMAC_STAT 0x04 +#define VMAC_ENABLE 0x08 +# define TXINT_MASK 0x00000001/* Transmit interrupt */ +# define RXINT_MASK 0x00000002/* Receive interrupt */ +# define ERR_MASK 0x00000004/* Error interrupt */ +# define TXCH_MASK 0x00000008/* Transmit chaining error */ +# define MSER_MASK 0x00000010/* Missed packet counter error */ +# define RXCR_MASK 0x00000100/* RXCRCERR counter rolled over */
Please keep things aligned and add the extra space after "define" (see tg3.h).
[...]
drivers/net/ethernet/arcvmac.h line 147
Quoted 9 lines
drivers/net/ethernet/arcvmac.h new file +9
-0+struct vmac_priv { +struct net_device *dev; +struct platform_device *pdev; + +struct completion mdio_complete; +spinlock_t lock;/* protects structure plus hw regs of device */ + +/* base address of register set */ +char *regs;
It should be __iomem annotated.
[...]
drivers/net/ethernet/arcvmac.h line 203
Quoted 13 lines
drivers/net/ethernet/arcvmac.h new file +13
-0+/* DMA ring management */ + +/* for a fifo with size n, +* - [0..n] fill levels are n + 1 states +* - there are only n different deltas (head - tail) values +* => not all fill levels can be represented with head, tail +* pointers only +* we give up the n fill level, aka fifo full */ + +/* sacrifice one elt as a sentinel */ +static inline int fifo_used (struct dma_fifo *f); +static inline int fifo_inc_ct (int ct,int size); +static inline void fifo_dump (struct dma_fifo *fifo);
Please reorder and remove the forward declarations.
Signature · 1 line
Ueimor