ARC vmac ethernet driver.
Subsystems (2)
cover ARC vmac ethernet 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, it is a full rewrite. Influenced heavily by dnet/bcm63xx_enet drivers.
This is a resubmission, changes are:
- Kconfig dependencies, HAS_DMA/CRC32/PHYLIB/MII
- removed mac_addr module parameter
- rebased linux tree: 3b72090a7317a034d1276a8fbe3b68c3cb77bd92
regards
Andreas
PATCH 1/1 ARC vmac ethernet driver.
--- drivers/net/Kconfig | 9 + drivers/net/Makefile | 1 + drivers/net/arcvmac.c | 1411 +++++++++++++++++++++++++++++++++++++++++++++++++ drivers/net/arcvmac.h | 268 ++++++++++ 4 files changed, 1689 insertions(+), 0 deletions(-)
drivers/net/Kconfig +9 -0
@@ -248,6 +248,15 @@ config AX88796_93CX6 help Select this if your platform comes with an external 93CX6 eeprom. +config ARCVMAC + tristate "ARC VMAC ethernet support" + depends on HAS_DMA + select MII + select PHYLIB + select CRC32 + help + MAC device present on Zoran Quatro43XX + config MACE tristate "MACE (Power Mac ethernet) support" depends on PPC_PMAC && PPC32
drivers/net/Makefile +1 -0
@@ -137,6 +137,7 @@ obj-$(CONFIG_ULTRA32) += smc-ultra32.o 8390.o obj-$(CONFIG_E2100) += e2100.o 8390.o obj-$(CONFIG_ES3210) += es3210.o 8390.o obj-$(CONFIG_LNE390) += lne390.o 8390.o +obj-$(CONFIG_ARCVMAC) += arcvmac.o obj-$(CONFIG_NE3210) += ne3210.o 8390.o obj-$(CONFIG_SB1250_MAC) += sb1250-mac.o obj-$(CONFIG_B44) += b44.o
drivers/net/arcvmac.c new file +1411 -0
1,411 lines not on this page · raw message
drivers/net/arcvmac.h new file +268 -0
268 lines not on this page · raw message
Signature · 1 line
1.7.1
David Miller
maintainerFrom: Andreas Fenkart <[email protected]>
Date: Fri, 15 Oct 2010 09:54:14 +0200
drivers/net/arcvmac.c line 31
Quoted 3 lines
drivers/net/arcvmac.c new file +3
-0+ +#undef DEBUG +
Please remove this.
drivers/net/arcvmac.c line 259
Quoted 4 lines
drivers/net/arcvmac.c new file +4
-0+#if 0 +/* FIXME: what is it used for? */ +platform_set_drvdata (ap->dev, ap->mii_bus); +#endif
Resolve this one way or another, either figure out what it's used for and keep it or remove it if it is unnedeed.
drivers/net/arcvmac.c line 464
Quoted 2 lines
drivers/net/arcvmac.c new file +2
-0+/* IP header Alignment (14 byte Ethernet header) */ +skb_reserve (skb,2 );
Use "NET_IP_ALIGN", not "2", different architectures want to use different values.
drivers/net/arcvmac.c line 534
Quoted 1 line
drivers/net/arcvmac.c new file +1
-0+skb_reserve (merge_skb,2 );
Same thing here, use NET_IP_ALIGN.
drivers/net/arcvmac.h line 127
Quoted 5 lines
drivers/net/arcvmac.h new file +5
-0+/* arcvmac private data structures */ +struct vmac_buffer_desc { +unsigned int info; +dma_addr_t data; +};
If this is the actual descriptor used by the hardware you cannot define it this way.
dma_addr_t is a variable type, on some platforms it is a "u32", on others it is a "u64" but you cannot assume one way or another.
Also, are these values big or little endian? You must use the appropriate endian types such as __be32 et al. and then access the members using the proper conversion functions.
Quoted 11 lines · David Miller
From: Andreas Fenkart <[email protected]>
Date: Fri, 15 Oct 2010 09:54:14 +0200drivers/net/arcvmac.h line 127
Quoted 5 lines
drivers/net/arcvmac.h new file +5
-0+/* arcvmac private data structures */ +struct vmac_buffer_desc { +unsigned int info; +dma_addr_t data; +};If this is the actual descriptor used by the hardware you cannot define it this way.
Changed to this
/* arcvmac private data structures */
struct vmac_buffer_desc {
__le32 info;
__le32 data;
};Quoted 4 lines
dma_addr_tis a variable type, on some platforms it is a "u32", on others it is a "u64" but you cannot assume one way or another.
Added this check
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;
}Quoted 4 lines
Also, are these values big or little endian? You must use the appropriate endian types such as
__be32et al. and then access the members using the proper conversion functions.
Using cpu_to_le32 / le32_to_cpu when accessing register map, buffer descriptors.
Andreas
PATCH 1/1 arcvmac submit #4.
--- drivers/net/Kconfig | 7 + drivers/net/Makefile | 1 + drivers/net/arcvmac.c | 1493 +++++++++++++++++++++++++++++++++++++++++++++++++ drivers/net/arcvmac.h | 267 +++++++++ 4 files changed, 1768 insertions(+), 0 deletions(-)
drivers/net/Kconfig +7 -0
@@ -236,6 +236,13 @@ config AX88796_93CX6 help Select this if your platform comes with an external 93CX6 eeprom. +config ARCVMAC + tristate "ARC VMAC ethernet support" + select MII + select PHYLIB + help + MAC present on Zoran Quatro43XX + config MACE tristate "MACE (Power Mac ethernet) support" depends on PPC_PMAC && PPC32
drivers/net/Makefile +1 -0
@@ -134,6 +134,7 @@ obj-$(CONFIG_ULTRA32) += smc-ultra32.o 8390.o obj-$(CONFIG_E2100) += e2100.o 8390.o obj-$(CONFIG_ES3210) += es3210.o 8390.o obj-$(CONFIG_LNE390) += lne390.o 8390.o +obj-$(CONFIG_ARCVMAC) += arcvmac.o obj-$(CONFIG_NE3210) += ne3210.o 8390.o obj-$(CONFIG_SB1250_MAC) += sb1250-mac.o obj-$(CONFIG_B44) += b44.o
drivers/net/arcvmac.c new file +1493 -0
1,493 lines not on this page · raw message
drivers/net/arcvmac.h new file +267 -0
267 lines not on this page · raw message
Signature · 1 line
1.7.2.3
Re: [PATCH 1/1] arcvmac submit #4.
Pls ignore this patch. I had to readd the Kconfig dependencies.
Pls comment on patch #4a
PATCH 1/1 arcvmac submit #4a.
--- drivers/net/Kconfig | 10 + drivers/net/Makefile | 1 + drivers/net/arcvmac.c | 1493 +++++++++++++++++++++++++++++++++++++++++++++++++ drivers/net/arcvmac.h | 267 +++++++++ 4 files changed, 1771 insertions(+), 0 deletions(-)
drivers/net/Kconfig +10 -0
@@ -236,6 +236,16 @@ config AX88796_93CX6 help Select this if your platform comes with an external 93CX6 eeprom. +config ARCVMAC + tristate "ARC VMAC ethernet support" + depends on HAS_DMA + select MII + select PHYLIB + select CRC32 + + help + MAC present on Zoran Quatro43XX + config MACE tristate "MACE (Power Mac ethernet) support" depends on PPC_PMAC && PPC32
drivers/net/Makefile +1 -0
@@ -134,6 +134,7 @@ obj-$(CONFIG_ULTRA32) += smc-ultra32.o 8390.o obj-$(CONFIG_E2100) += e2100.o 8390.o obj-$(CONFIG_ES3210) += es3210.o 8390.o obj-$(CONFIG_LNE390) += lne390.o 8390.o +obj-$(CONFIG_ARCVMAC) += arcvmac.o obj-$(CONFIG_NE3210) += ne3210.o 8390.o obj-$(CONFIG_SB1250_MAC) += sb1250-mac.o obj-$(CONFIG_B44) += b44.o
drivers/net/arcvmac.c new file +1493 -0
1,493 lines not on this page · raw message
drivers/net/arcvmac.h new file +267 -0
267 lines not on this page · raw message
Signature · 1 line
1.7.2.3
David Miller
maintainerRe: [PATCH 1/1] arcvmac submit #4a.
From: Andreas Fenkart <[email protected]>
Date: Thu, 2 Dec 2010 14:21:52 +0100
Quoted 2 lines
Signed-off-by Andreas Fenkart <[email protected]>
Generates many warnings on 64-bit platforms, also doesn't build on any platform because it uses interfaces we removed a long time ago (multicast count and list).
If you want anyone to take your submission seriously, at the very least you should at least test the build against current sources before submitting.
drivers/net/arcvmac.c: In function ‘vmac_ioctl’:drivers/net/arcvmac.c:333: warning: passing argument 2 of ‘phy_mii_ioctl’ from incompatible pointer type include/linux/phy.h:511: note: expected ‘struct ifreq *’ but argument is of type ‘struct mii_ioctl_data *’ drivers/net/arcvmac.c: In function ‘vmacether_get_drvinfo’:drivers/net/arcvmac.c:344: warning: format ‘%x’ expects type ‘unsigned int’, but argument 4 has type ‘resource_size_t’ drivers/net/arcvmac.c: In function ‘alloc_buffers_unlocked’:drivers/net/arcvmac.c:966: warning: cast from pointer to integer of different size drivers/net/arcvmac.c:966: warning: cast from pointer to integer of different size drivers/net/arcvmac.c: In function ‘create_multicast_filter’:drivers/net/arcvmac.c:1260: error: ‘struct net_device’ has no member named ‘mc_count’ drivers/net/arcvmac.c:1264: error: ‘struct net_device’ has no member named ‘mc_list’ drivers/net/arcvmac.c:1264: error: dereferencing pointer to incomplete type drivers/net/arcvmac.c:1265: error: dereferencing pointer to incomplete typedrivers/net/arcvmac.c: In function ‘vmac_set_multicast_list’:drivers/net/arcvmac.c:1293: error: ‘struct net_device’ has no member named ‘mc_count’ drivers/net/arcvmac.c: In function ‘vmac_probe’:drivers/net/arcvmac.c:1438: warning: format ‘%08x’ expects type ‘unsigned int’, bu
PATCH 1/1 ARC VMAC ethernet driver.
--- drivers/net/Kconfig | 10 + drivers/net/Makefile | 1 + drivers/net/arcvmac.c | 1495 +++++++++++++++++++++++++++++++++++++++++++++++++ drivers/net/arcvmac.h | 266 +++++++++ 4 files changed, 1772 insertions(+), 0 deletions(-)
drivers/net/Kconfig +10 -0
@@ -251,6 +251,16 @@ config AX88796_93CX6 help Select this if your platform comes with an external 93CX6 eeprom. +config ARCVMAC + tristate "ARC VMAC ethernet support" + depends on HAS_DMA + select MII + select PHYLIB + select CRC32 + + help + MAC present on Zoran Quatro43XX + config MACE tristate "MACE (Power Mac ethernet) support" depends on PPC_PMAC && PPC32
drivers/net/Makefile +1 -0
@@ -140,6 +140,7 @@ obj-$(CONFIG_ULTRA32) += smc-ultra32.o 8390.o obj-$(CONFIG_E2100) += e2100.o 8390.o obj-$(CONFIG_ES3210) += es3210.o 8390.o obj-$(CONFIG_LNE390) += lne390.o 8390.o +obj-$(CONFIG_ARCVMAC) += arcvmac.o obj-$(CONFIG_NE3210) += ne3210.o 8390.o obj-$(CONFIG_SB1250_MAC) += sb1250-mac.o obj-$(CONFIG_B44) += b44.o
drivers/net/arcvmac.c new file +1495 -0
1,495 lines not on this page · raw message
drivers/net/arcvmac.h new file +266 -0
266 lines not on this page · raw message
Signature · 1 line
1.7.2.3
Re: [PATCH 1/1] ARC VMAC ethernet driver.
drivers/net/arcvmac.c line 674
Quoted 5 lines · Andreas Fenkart
Signed-off-by Andreas Fenkart <[email protected]>drivers/net/arcvmac.c new file +2
-0+ processed++; + skb->dev = dev;
eth_type_trans() already sets "skb->dev = dev;"
drivers/net/arcvmac.c line 676
Quoted 2 lines
drivers/net/arcvmac.c new file +2
-0+ skb->protocol =eth_type_trans (skb, dev); + ap->stats.rx_packets++;
Hmm, why dont you use dev->stats internal structure ? No need to maintain a shadow in ap->stats.
drivers/net/arcvmac.c line 678
Quoted 2 lines
drivers/net/arcvmac.c new file +2
-0+ ap->stats.rx_bytes += skb->len; + dev->last_rx = jiffies;
/* last_rx = jiffies; not needed anymore */
drivers/net/arcvmac.c line 679
Quoted 1 line
drivers/net/arcvmac.c new file +1
-0+netif_rx (skb);
A NAPI driver should use netif_receive_skb(), not netif_rx()
Re: [PATCH 1/1] ARC VMAC ethernet driver.
fixed, pls find new version in reply to this mail.
2011/2/15 Eric Dumazet <[email protected]>:
Quoted 25 lines · Andreas Fenkart
Quoted 5 lines
Signed-off-by Andreas Fenkart <[email protected]>+ processed++;
+skb->dev= dev;eth_type_trans() already sets "
skb->dev= dev;"Quoted 2 lines
+
skb->protocol=eth_type_trans(skb, dev);
+ ap->stats.rx_packets++;Hmm, why dont you use
dev->statsinternal structure ? No need to maintain a shadow inap->stats.Quoted 2 lines
+
ap->stats.rx_bytes+=skb->len;
+dev->last_rx= jiffies;/*
last_rx= jiffies; not needed anymore */Quoted 1 line
+
netif_rx(skb);A NAPI driver should use
netif_receive_skb(), notnetif_rx()
PATCH 1/1 ARC VMAC ethernet driver.
--- drivers/net/Kconfig | 10 + drivers/net/Makefile | 1 + drivers/net/arcvmac.c | 1494 +++++++++++++++++++++++++++++++++++++++++++++++++ drivers/net/arcvmac.h | 265 +++++++++ 4 files changed, 1770 insertions(+), 0 deletions(-)
drivers/net/Kconfig +10 -0
@@ -251,6 +251,16 @@ config AX88796_93CX6 help Select this if your platform comes with an external 93CX6 eeprom. +config ARCVMAC + tristate "ARC VMAC ethernet support" + depends on HAS_DMA + select MII + select PHYLIB + select CRC32 + + help + MAC present on Zoran Quatro43XX + config MACE tristate "MACE (Power Mac ethernet) support" depends on PPC_PMAC && PPC32
drivers/net/Makefile +1 -0
@@ -140,6 +140,7 @@ obj-$(CONFIG_ULTRA32) += smc-ultra32.o 8390.o obj-$(CONFIG_E2100) += e2100.o 8390.o obj-$(CONFIG_ES3210) += es3210.o 8390.o obj-$(CONFIG_LNE390) += lne390.o 8390.o +obj-$(CONFIG_ARCVMAC) += arcvmac.o obj-$(CONFIG_NE3210) += ne3210.o 8390.o obj-$(CONFIG_SB1250_MAC) += sb1250-mac.o obj-$(CONFIG_B44) += b44.o
drivers/net/arcvmac.c new file +1494 -0
1,494 lines not on this page · raw message
drivers/net/arcvmac.h new file +265 -0
265 lines not on this page · raw message
Signature · 1 line
1.7.2.3
Re: [PATCH 1/1] ARC VMAC ethernet driver.
Quoted 22 lines · Andreas Fenkart
Signed-off-by Andreas Fenkart <[email protected]>--- drivers/net/Kconfig | 10 + drivers/net/Makefile | 1 + drivers/net/arcvmac.c | 1494 +++++++++++++++++++++++++++++++++++++++++++++++++ drivers/net/arcvmac.h | 265 +++++++++ 4 files changed, 1770 insertions(+), 0 deletions(-)drivers/net/arcvmac.c new file +11
-0+/* merge buffer chaining */ +struct sk_buff *vmac_merge_rx_buffers_unlocked (struct net_device *dev, +struct vmac_buffer_desc *after, +int pkt_len)/* data */ +{ +struct vmac_priv *ap =netdev_priv (dev); +struct sk_buff *merge_skb, *cur_skb; +struct dma_fifo *rx_ring; +struct vmac_buffer_desc *desc; + +/* locking: same as vmac_rx_receive */
drivers/net/arcvmac.c line 530
Quoted 10 lines
drivers/net/arcvmac.c new file +10
-0+ + rx_ring = &ap->rx_ring; + desc = &ap->rxbd[rx_ring->tail]; + +WARN_ON (desc == after); + +/* strip FCS */ + pkt_len -=4 ; + + merge_skb =netdev_alloc_skb_ip_align (dev, pkt_len +NET_IP_ALIGN );
You can remove the "+ NET_IP_ALIGN", its already done in netdev_alloc_skb_ip_align()
Also, it seems strange you want to build one big SKB (no frag), while this NIC is able to feed multiple frags.
(Change to get a SKB to hold a 9000 bytes frame is very very low if your memory gets fragmented)
Quoted 56 lines
drivers/net/arcvmac.c new file +55
-0+if (!merge_skb) { +dev_err (&ap->pdev->dev,"failed to allocate merged rx_skb, rx skb's left %d\n" , +fifo_used (rx_ring)); + +return NULL ; + } + +while (desc != after && pkt_len) { +struct vmac_buffer_desc *desc; +int buf_len, valid; + +/* desc needs wrapping */ + desc = &ap->rxbd[rx_ring->tail]; + cur_skb = ap->rx_skbuff[rx_ring->tail]; +WARN_ON (!cur_skb); + +dma_unmap_single (&ap->pdev->dev, desc->data, ap->rx_skb_size, +DMA_FROM_DEVICE ); + +/* do not copy FCS */ + buf_len =le32_to_cpu (desc->info) &BD_LEN ; + valid =min (pkt_len, buf_len); + pkt_len -= valid; + +memcpy (skb_put (merge_skb, valid), cur_skb->data, valid); + +fifo_inc_tail (rx_ring); + } + +/* merging_pressure++ */ + +if (unlikely (pkt_len !=0 )) +dev_err (&ap->pdev->dev,"buffer chaining bytes missing %d\n" , + pkt_len); + +WARN_ON (desc != after); + +return merge_skb; +} + + +int vmac_start_xmit (struct sk_buff *skb,struct net_device *dev) +{ +struct vmac_priv *ap =netdev_priv (dev); +struct vmac_buffer_desc *desc; +unsigned long flags; +unsigned int tmp; + +/* 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 ); +
drivers/net/arcvmac.c
Quoted 10 lines
drivers/net/arcvmac.c new file +10
-0+if (unlikely (fifo_full (&ap->tx_ring))) { +netif_stop_queue (dev); +vmac_toggle_txint (dev,1 ); +dev_err (&ap->pdev->dev,"xmit called with no tx desc available\n" ); +return NETDEV_TX_BUSY ; + } + +if (unlikely (skb->len <ETH_ZLEN )) { +struct sk_buff *short_skb; + short_skb =netdev_alloc_skb_ip_align (dev,ETH_ZLEN );
I guess you dont really need the _ip_align() version here
Quoted 11 lines
drivers/net/arcvmac.c new file +11
-0+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; + } + +/* fill descriptor */ + ap->tx_skbuff[ap->tx_ring.head] = skb;
drivers/net/arcvmac.c line 902
Quoted 10 lines
drivers/net/arcvmac.c new file +10
-0+ 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 ); + +/* dma might already be polling */ +wmb (); + desc->info =cpu_to_le32 (BD_DMA_OWN |BD_FRST |BD_LAST | skb->len); +wmb ();
Not sure you need this wmb();
drivers/net/arcvmac.c line 913
Quoted 11 lines
drivers/net/arcvmac.c new file +11
-0+ +/* lock device data */ +spin_lock_irqsave (&ap->lock, flags); + +/* kick tx dma */ + tmp =vmac_readl (ap,STAT ); +vmac_writel (ap, tmp |TXPL_MASK ,STAT ); + + dev->stats.tx_packets++; + dev->stats.tx_bytes += skb->len; + dev->trans_start = jiffies;
trans_start doesnt need to be set anymore in drivers.
Quoted 34 lines
drivers/net/arcvmac.c new file +32
-0+fifo_inc_head (&ap->tx_ring); + +/* vmac_tx_reclaim outside of vmac_tx_timeout */ +if (fifo_used (&ap->tx_ring) >8 ) +vmac_tx_reclaim_unlocked (dev,0 ); + +/* unlock device data */ +spin_unlock_irqrestore (&ap->lock, flags); + +/* stop queue if no more desc available */ +if (fifo_full (&ap->tx_ring)) { +netif_stop_queue (dev); +vmac_toggle_txint (dev,1 ); + } + +return NETDEV_TX_OK ; +} + +static void create_multicast_filter (struct net_device *dev, +unsigned long *bitmask) +{ +unsigned long crc; +char *addrs; + +/* locking: done by net_device */ + +WARN_ON (netdev_mc_count (dev) ==0 ); +WARN_ON (dev->flags &IFF_ALLMULTI ); + + bitmask[0 ] = bitmask[1 ] =0 ; + + {
drivers/net/arcvmac.c
Quoted 10 lines
drivers/net/arcvmac.c new file +10
-0+struct netdev_hw_addr *ha; +netdev_for_each_mc_addr (ha, dev) { + addrs = ha->addr; + +/* skip non-multicast addresses */ +if (!(*addrs &1 )) +continue ; + + crc =ether_crc_le (ETH_ALEN , addrs); +set_bit (crc >>26 , bitmask);
I am wondering if it works on 64bit arches ;)
drivers/net/arcvmac.c line 1304
Quoted 6 lines
drivers/net/arcvmac.c new file +5
-0+ } + } +} + +static struct ethtool_ops vmac_ethtool_ops = {
please add const qualifier
static const struct ethtool_ops vmac_ethtool_ops = {
Quoted 48 lines
drivers/net/arcvmac.c new file +47
-0+ .get_settings = vmacether_get_settings, + .set_settings = vmacether_set_settings, + .get_drvinfo = vmacether_get_drvinfo, + .get_link = ethtool_op_get_link, +}; + +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" ); + 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; + +spin_lock_init (&ap->lock); + +SET_NETDEV_DEV (dev, &pdev->dev);
drivers/net/arcvmac.c line 1406
Quoted 10 lines
drivers/net/arcvmac.c new file +10
-0+ ap->dev = dev; + ap->pdev = pdev; + +/* init rx timeout (used for oom) */ +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,2 );
2 ?
You have 16 skb in RX ring, please use 16 (or 64)
Quoted 73 lines
drivers/net/arcvmac.c new file +43
-0+ dev->netdev_ops = &vmac_netdev_ops; + dev->ethtool_ops = &vmac_ethtool_ops; + + dev->flags |=IFF_MULTICAST ; + + dev->base_addr = (unsigned long )ap->regs;/* TODO */ + +/* 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; + +/* mac address intialize, set vmac_open */ +read_mac_reg (dev, dev->dev_addr);/* TODO */ + +if (!is_valid_ether_addr (dev->dev_addr)) +random_ether_addr (dev->dev_addr); + + err =register_netdev (dev); +if (err) { +dev_err (&pdev->dev,"Cannot register net device, aborting.\n" ); + goto err_out; + } + +/* release the memory region, till open is called */ +put_register_map (ap); + +dev_info (&pdev->dev,"ARC VMAC at 0x%pP irq %d %pM\n" , &mem->start, + dev->irq, dev->dev_addr); +platform_set_drvdata (pdev, ap); + +return 0 ; + +err_out: +free_netdev (dev); +return err; +} +drivers/net/arcvmac.h new file +23
-0@@ -0,0 +1,265 @@ +/* +* ARC VMAC Driver +* +* Copyright (C) 2003-2006 Codito Technologies, for linux-2.4 port +* Copyright (C) 2006-2007 Celunite Inc, for linux-2.6 port +* Copyright (C) 2007-2008 Sagem Communications, Fehmi HAFSI +* Copyright (C) 2009-2011 Sagem Communications, 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 +*
drivers/net/arcvmac.h line 33
Quoted 10 lines
drivers/net/arcvmac.h new file +10
-0+*/ + +#ifndef _ARCVMAC_H +#define _ARCVMAC_H + +#define DRV_NAME "arcvmac" +#define DRV_VERSION "1.0" + +/* Buffer descriptors */ +#define TX_BDT_LEN 16/* Number of receive BD's */
16 is a bit small. Is it a hardware limitation or user choice ?
drivers/net/arcvmac.h line 34
Quoted 1 line
drivers/net/arcvmac.h new file +1
-0+#define RX_BDT_LEN 256/* Number of transmit BD's */
If hardware permits it, I suggest using 128 RX and 128 TX descs
Quoted 159 lines
drivers/net/arcvmac.h new file +159
-0+ +/* BD poll rate, in 1024 cycles. @100Mhz: x * 1024 cy * 10ns = 1ms */ +#define POLLRATE_TIME 200 + +/* next power of two, bigger than ETH_FRAME_LEN + VLAN */ +#define MAX_RX_BUFFER_LEN 0x800/* 2^11 = 2048 = 0x800 */ +#define MAX_TX_BUFFER_LEN 0x800/* 2^11 = 2048 = 0x800 */ + +/* 14 bytes of ethernet header, 4 bytes VLAN, FCS, +* plus extra pad to prevent buffer chaining of +* maximum sized ethernet packets (1514 bytes) */ +#define VMAC_BUFFER_PAD (ETH_HLEN + 4 + ETH_FCS_LEN + 4) + +/* VMAC register definitions, offsets in bytes */ +#define VMAC_ID 0x00 + +/* 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 */ +# define RXFR_MASK 0x00000200/* RXFRAMEERR counter rolled over */ +# define RXFL_MASK 0x00000400/* RXOFLOWERR counter rolled over */ +# define MDIO_MASK 0x00001000/* MDIO complete */ +# define TXPL_MASK 0x80000000/* TXPOLL */ + +#define VMAC_CONTROL 0x0c +# define EN_MASK 0x00000001/* VMAC enable */ +# define TXRN_MASK 0x00000008/* TX enable */ +# define RXRN_MASK 0x00000010/* RX enable */ +# define DSBC_MASK 0x00000100/* Disable receive broadcast */ +# define ENFL_MASK 0x00000400/* Enable Full Duplex */ +# define PROM_MASK 0x00000800/* Promiscuous mode */ + +#define VMAC_POLLRATE 0x10 + +#define VMAC_RXERR 0x14 +# define RXERR_CRC 0x000000ff +# define RXERR_FRM 0x0000ff00 +# define RXERR_OFLO 0x00ff0000/* fifo overflow */ + +#define VMAC_MISS 0x18 +#define VMAC_TXRINGPTR 0x1c +#define VMAC_RXRINGPTR 0x20 +#define VMAC_ADDRL 0x24 +#define VMAC_ADDRH 0x28 +#define VMAC_LAFL 0x2c +#define VMAC_LAFH 0x30 +#define VMAC_MAC_TXRING_HEAD 0x38 +#define VMAC_MAC_RXRING_HEAD 0x3C + +#define VMAC_MDIO_DATA 0x34 +# define MDIO_SFD 0xC0000000 +# define MDIO_OP 0x30000000 +# define MDIO_ID_MASK 0x0F800000 +# define MDIO_REG_MASK 0x007C0000 +# define MDIO_TA 0x00030000 +# define MDIO_DATA_MASK 0x0000FFFF +/* common combinations */ +# define MDIO_BASE 0x40020000 +# define MDIO_OP_READ 0x20000000 +# define MDIO_OP_WRITE 0x10000000 + +/* Buffer descriptor INFO bit masks */ +#define BD_DMA_OWN 0x80000000/* buffer ownership, 0 CPU, 1 DMA */ +#define BD_BUFF 0x40000000/* buffer invalid, rx */ +#define BD_UFLO 0x20000000/* underflow, tx */ +#define BD_LTCL 0x10000000/* late collision, tx */ +#define BD_RETRY_CT 0x0f000000/* tx */ +#define BD_DROP 0x00800000/* drop, more than 16 retries, tx */ +#define BD_DEFER 0x00400000/* traffic on the wire, tx */ +#define BD_CARLOSS 0x00200000/* carrier loss while transmission, tx, rx? */ +/* 20:19 reserved */ +#define BD_ADCR 0x00040000/* add crc, ignored if not disaddcrc */ +#define BD_LAST 0x00020000/* Last buffer in chain */ +#define BD_FRST 0x00010000/* First buffer in chain */ +/* 15:11 reserved */ +#define BD_LEN 0x000007FF + +/* common combinations */ +#define BD_TX_ERR (BD_UFLO | BD_LTCL | BD_RETRY_CT | BD_DROP | \ + BD_DEFER | BD_CARLOSS) + + +/* arcvmac private data structures */ +struct vmac_buffer_desc { +__le32 info; +__le32 data; +}; + +struct dma_fifo { +int head;/* head */ +int tail;/* tail */ +int size; +}; + +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; +struct resource *mem; + +/* DMA ring buffers */ +struct vmac_buffer_desc *rxbd; +dma_addr_t rxbd_dma; + +struct vmac_buffer_desc *txbd; +dma_addr_t txbd_dma; + +/* socket buffers */ +struct sk_buff *rx_skbuff[RX_BDT_LEN ]; +struct sk_buff *tx_skbuff[TX_BDT_LEN ]; +int rx_skb_size; + +/* skb / dma desc managing */ +struct dma_fifo rx_ring;/* valid rx buffers */ +struct dma_fifo tx_ring; + +/* descriptor last polled/processed by the VMAC */ +unsigned long dma_rx_head; + +/* timer to retry rx skb allocation, if failed during receive */ +struct timer_list refill_timer; +spinlock_t refill_lock; + +struct napi_struct napi; + +/* rx buffer chaining */ +int rx_merge_error; +int tx_timeout_error; + +/* PHY stuff */ +struct mii_bus *mii_bus; +struct phy_device *phy_dev; + +int link; +int speed; +int duplex; + +/* debug */ +int shutdown; +}; + +/* 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
drivers/net/arcvmac.h line 203
Quoted 10 lines
drivers/net/arcvmac.h new file +10
-0+* 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); + +static inline int fifo_empty (struct dma_fifo *f) +{ +return (f->head == f->tail);
return f->head == f->tail;
Quoted 44 lines
drivers/net/arcvmac.h new file +44
-0+} + +static inline int fifo_free (struct dma_fifo *f) +{ +int free; + + free = f->tail - f->head; +if (free <=0 ) + free += f->size; + +return free; +} + +static inline int fifo_used (struct dma_fifo *f) +{ +int used; + + used = f->head - f->tail; +if (used <0 ) + used += f->size; + +return used; +} + +static inline int fifo_full (struct dma_fifo *f) +{ +return (fifo_used (f) +1 ) == f->size; +} + +/* manipulate */ +static inline void fifo_init (struct dma_fifo *fifo,int size) +{ + fifo->size = size; + fifo->head = fifo->tail =0 ;/* empty */ +} + +static inline void fifo_inc_head (struct dma_fifo *fifo) +{ +BUG_ON (fifo_full (fifo)); + fifo->head =fifo_inc_ct (fifo->head, fifo->size); +} + +static inline void fifo_inc_tail (struct dma_fifo *fifo) +{
drivers/net/arcvmac.h line 257
Quoted 10 lines
drivers/net/arcvmac.h new file +10
-0+BUG_ON (fifo_empty (fifo)); + fifo->tail =fifo_inc_ct (fifo->tail, fifo->size); +} + +/* internal funcs */ +static inline void fifo_dump (struct dma_fifo *fifo) +{ +printk (KERN_INFO "fifo: head %d, tail %d, size %d\n" , fifo->head, + fifo->tail, + fifo->size);
pr_info() is preferred in new code
Quoted 8 lines
drivers/net/arcvmac.h new file +8
-0+} + +static inline int fifo_inc_ct (int ct,int size) +{ +return (++ct == size) ?0 : ct; +} + +#endif /* _ARCVMAC_H */