net/macb: driver enhancement concerning GEM support, ring logic and cleanup
Subsystems (4)
v4 cover net/macb: driver enhancement concerning GEM support, ring logic and cleanup
This is an enhancement work that began several years ago. I try to catchup with some performance improvement that has been implemented then by Havard. The ring index logic and the TX error path modification are the biggest changes but some cleanup/debugging have been added along the way.
The GEM revision will benefit from the Gigabit support.
Newer pinctrl infrastructure support is added but it is optional.
The series has been tested on several Atmel AT91 SoC with the two MACB/GEM flavors.
v4: - remove unneeded device tree header includes
- modified the computation of available entries in ring buffer
v3: - rebased on net-next to take into account current effor to merge
at91_ether with macb drivers
- add additional patch to use the new pinctrl infrastructure
v2: - modify the tx error handling: now uses a workqueue
- information provided by ethtool -i were not accurate: removed
Havard Skinnemoen (4):
net/macb: memory barriers cleanup
net/macb: change debugging messages
net/macb: clean up ring buffer logic
net/macb: Offset first RX buffer by two bytes
Jean-Christophe PLAGNIOL-VILLARD (1):
net/macb: add pinctrl consumer support
Nicolas Ferre (4):
net/macb: remove macb_get_drvinfo()
net/macb: tx status is more than 8 bits now net/macb: ethtool interface: add register dump feature net/macb: better manage tx errors
Patrice Vilchez (1):
net/macb: Add support for Gigabit Ethernet mode
drivers/net/ethernet/cadence/at91_ether.c | 6 +- drivers/net/ethernet/cadence/macb.c | 448 +++++++++++++++++++++--------- drivers/net/ethernet/cadence/macb.h | 30 +- 3 files changed, 337 insertions(+), 147 deletions(-)
Signature · 1 line
1.8.0
PATCH v4 1/10 net/macb: Add support for Gigabit Ethernet mode
From: Patrice Vilchez <[email protected]>
Add Gigabit Ethernet mode to GEM cadence IP and enable RGMII connection.
--- drivers/net/ethernet/cadence/macb.c | 15 ++++++++++++--- drivers/net/ethernet/cadence/macb.h | 4 ++++ 2 files changed, 16 insertions(+), 3 deletions(-)
drivers/net/ethernet/cadence/macb.c +12 -3
@@ -152,13 +152,17 @@ static void macb_handle_link_change(struct net_device *dev) reg =macb_readl (bp,NCFGR ); reg &= ~(MACB_BIT (SPD ) |MACB_BIT (FD )); +if (macb_is_gem (bp)) + reg &= ~GEM_BIT (GBE );if (phydev->duplex) reg |=MACB_BIT (FD );if (phydev->speed ==SPEED_100 ) reg |=MACB_BIT (SPD ); +if (phydev->speed ==SPEED_1000 ) + reg |=GEM_BIT (GBE ); -macb_writel (bp,NCFGR , reg); +macb_or_gem_writel (bp,NCFGR , reg); bp->speed = phydev->speed; bp->duplex = phydev->duplex;
@@ -216,7 +220,10 @@ static int macb_mii_probe(struct net_device *dev) }/* mask with MAC supported features */ - phydev->supported &=PHY_BASIC_FEATURES ; +if (macb_is_gem (bp)) + phydev->supported &=PHY_GBIT_FEATURES ; +else + phydev->supported &=PHY_BASIC_FEATURES ; phydev->advertising = phydev->supported;
@@ -1388,7 +1395,9 @@ static int __init macb_probe(struct platform_device *pdev) bp->phy_interface = err; } - if (bp->phy_interface == PHY_INTERFACE_MODE_RMII) +if (bp->phy_interface ==PHY_INTERFACE_MODE_RGMII ) +macb_or_gem_writel (bp,USRIO ,GEM_BIT (RGMII )); + else if (bp->phy_interface == PHY_INTERFACE_MODE_RMII)#if defined(CONFIG_ARCH_AT91 )macb_or_gem_writel (bp,USRIO , (MACB_BIT (RMII ) |MACB_BIT (CLKEN )));
drivers/net/ethernet/cadence/macb.h +4 -0
@@ -149,6 +149,8 @@#define MACB_IRXFCS_SIZE 1/* GEM specific NCFGR bitfields. */ +#define GEM_GBE_OFFSET 10 +#define GEM_GBE_SIZE 1#define GEM_CLK_OFFSET 18#define GEM_CLK_SIZE 3#define GEM_DBW_OFFSET 21
@@ -252,6 +254,8 @@/* Bitfields in USRIO (AT91) */ #define MACB_RMII_OFFSET 0#define MACB_RMII_SIZE 1 +#define GEM_RGMII_OFFSET 0/* GEM gigabit mode */ +#define GEM_RGMII_SIZE 1#define MACB_CLKEN_OFFSET 1#define MACB_CLKEN_SIZE 1
Signature · 1 line
1.8.0
PATCH v4 2/10 net/macb: memory barriers cleanup
In reply to Nicolas FerreFrom: Havard Skinnemoen <[email protected]>
Remove a couple of unneeded barriers and document the remaining ones.
--- drivers/net/ethernet/cadence/macb.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
drivers/net/ethernet/cadence/macb.c +14 -4
@@ -373,7 +373,9 @@ static void macb_tx(struct macb *bp)BUG_ON (skb ==NULL ); +/* Make hw descriptor updates visible to CPU */ rmb (); + bufstat = bp->tx_ring[tail].ctrl;if (!(bufstat &MACB_BIT (TX_USED )))
@@ -416,7 +418,10 @@ static int macb_rx_frame(struct macb *bp, unsigned int first_frag,if (frag == last_frag)break ; } + +/* Make descriptor updates visible to hardware */ wmb (); +return 1 ; }
@@ -437,12 +442,14 @@ static int macb_rx_frame(struct macb *bp, unsigned int first_frag, frag_len); offset +=RX_BUFFER_SIZE ; bp->rx_ring[frag].addr &= ~MACB_BIT (RX_USED ); -wmb ();if (frag == last_frag)break ; } +/* Make descriptor updates visible to hardware */ +wmb (); + skb->protocol =eth_type_trans (skb, bp->dev); bp->stats.rx_packets++;
@@ -462,6 +469,8 @@ static void discard_partial_frame(struct macb *bp, unsigned int begin,for (frag = begin; frag != end; frag =NEXT_RX (frag)) bp->rx_ring[frag].addr &= ~MACB_BIT (RX_USED ); + +/* Make descriptor updates visible to hardware */ wmb ();/*
@@ -480,7 +489,9 @@ static int macb_rx(struct macb *bp, int budget)for (; budget >0 ; tail =NEXT_RX (tail)) {u32 addr, ctrl; +/* Make hw descriptor updates visible to CPU */ rmb (); + addr = bp->rx_ring[tail].addr; ctrl = bp->rx_ring[tail].ctrl;
@@ -675,6 +686,8 @@ static int macb_start_xmit(struct sk_buff *skb, struct net_device *dev) bp->tx_ring[entry].addr = mapping; bp->tx_ring[entry].ctrl = ctrl; + +/* Make newly initialized descriptor visible to hardware */ wmb (); entry =NEXT_TX (entry);
@@ -783,9 +796,6 @@ static void macb_init_rings(struct macb *bp)static void macb_reset_hw (struct macb *bp) { -/* Make sure we have the write buffer for ourselves */ -wmb (); -/* * Disable RX and TX (XXX: Should we halt the transmission * more gracefully?)
Signature · 1 line
1.8.0
PATCH v4 3/10 net/macb: change debugging messages
In reply to Nicolas FerreFrom: Havard Skinnemoen <[email protected]>
Convert some noisy netdev_dbg() statements to netdev_vdbg(). Defining DEBUG will no longer fill up the logs; VERBOSE_DEBUG still does. Add one more verbose debug for ISR status.
--- drivers/net/ethernet/cadence/macb.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)
drivers/net/ethernet/cadence/macb.c +12 -10
@@ -314,7 +314,7 @@ static void macb_tx(struct macb *bp) status =macb_readl (bp,TSR );macb_writel (bp,TSR , status); -netdev_dbg (bp->dev,"macb_tx status = %02lx\n" , (unsigned long )status); +netdev_vdbg (bp->dev,"macb_tx status = %02lx\n" , (unsigned long )status);if (status & (MACB_BIT (UND ) |MACB_BIT (TSR_RLE ))) {int i;
@@ -381,7 +381,7 @@ static void macb_tx(struct macb *bp)if (!(bufstat &MACB_BIT (TX_USED )))break ; -netdev_dbg (bp->dev,"skb %u (data %p) TX complete\n" , +netdev_vdbg (bp->dev,"skb %u (data %p) TX complete\n" , tail, skb->data);dma_unmap_single (&bp->pdev->dev, rp->mapping, skb->len,DMA_TO_DEVICE );
@@ -407,7 +407,7 @@ static int macb_rx_frame(struct macb *bp, unsigned int first_frag, len =MACB_BFEXT (RX_FRMLEN , bp->rx_ring[last_frag].ctrl); -netdev_dbg (bp->dev,"macb_rx_frame frags %u - %u (len %u)\n" , +netdev_vdbg (bp->dev,"macb_rx_frame frags %u - %u (len %u)\n" , first_frag, last_frag, len); skb =netdev_alloc_skb (bp->dev, len +RX_OFFSET );
@@ -454,7 +454,7 @@ static int macb_rx_frame(struct macb *bp, unsigned int first_frag, bp->stats.rx_packets++; bp->stats.rx_bytes += len; -netdev_dbg (bp->dev,"received skb of length %u, csum: %08x\n" , +netdev_vdbg (bp->dev,"received skb of length %u, csum: %08x\n" , skb->len, skb->csum);netif_receive_skb (skb);
@@ -536,7 +536,7 @@ static int macb_poll(struct napi_struct *napi, int budget) work_done =0 ; -netdev_dbg (bp->dev,"poll: status = %08lx, budget = %d\n" , +netdev_vdbg (bp->dev,"poll: status = %08lx, budget = %d\n" , (unsigned long )status, budget); work_done =macb_rx (bp, budget);
@@ -575,6 +575,8 @@ static irqreturn_t macb_interrupt(int irq, void *dev_id)break ; } +netdev_vdbg (bp->dev,"isr = 0x%08lx\n" , (unsigned long )status); +if (status &MACB_RX_INT_FLAGS ) {/* * There's no point taking any more interrupts
@@ -586,7 +588,7 @@ static irqreturn_t macb_interrupt(int irq, void *dev_id)macb_writel (bp,IDR ,MACB_RX_INT_FLAGS );if (napi_schedule_prep (&bp->napi)) { -netdev_dbg (bp->dev,"scheduling RX softirq\n" ); +netdev_vdbg (bp->dev,"scheduling RX softirq\n" );__napi_schedule (&bp->napi); } }
@@ -648,8 +650,8 @@ static int macb_start_xmit(struct sk_buff *skb, struct net_device *dev)u32 ctrl;unsigned long flags; -#ifdef DEBUG -netdev_dbg (bp->dev, +#if defined(DEBUG ) && defined(VERBOSE_DEBUG ) +netdev_vdbg (bp->dev,"start_xmit: len %u head %p data %p tail %p end %p\n" , skb->len, skb->head, skb->data,skb_tail_pointer (skb),skb_end_pointer (skb));
@@ -671,12 +673,12 @@ static int macb_start_xmit(struct sk_buff *skb, struct net_device *dev) } entry = bp->tx_head; -netdev_dbg (bp->dev,"Allocated ring entry %u\n" , entry); +netdev_vdbg (bp->dev,"Allocated ring entry %u\n" , entry); mapping =dma_map_single (&bp->pdev->dev, skb->data, len,DMA_TO_DEVICE ); bp->tx_skb[entry].skb = skb; bp->tx_skb[entry].mapping = mapping; -netdev_dbg (bp->dev,"Mapped skb data %p to DMA addr %08lx\n" , +netdev_vdbg (bp->dev,"Mapped skb data %p to DMA addr %08lx\n" , skb->data, (unsigned long )mapping); ctrl =MACB_BF (TX_FRMLEN , len);
Signature · 1 line
1.8.0
PATCH v4 4/10 net/macb: remove macb_get_drvinfo()
In reply to Nicolas FerreThis function has little meaning so remove it altogether and let ethtool core fill in the fields automatically.
--- drivers/net/ethernet/cadence/macb.c | 11 ----------- 1 file changed, 11 deletions(-)
drivers/net/ethernet/cadence/macb.c +0 -11
@@ -1225,20 +1225,9 @@ static int macb_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)return phy_ethtool_sset (phydev, cmd); } -static void macb_get_drvinfo (struct net_device *dev, -struct ethtool_drvinfo *info) -{ -struct macb *bp =netdev_priv (dev); - -strcpy (info->driver, bp->pdev->dev.driver->name); -strcpy (info->version,"$Revision: 1.14 $" ); -strcpy (info->bus_info,dev_name (&bp->pdev->dev)); -} -const struct ethtool_ops macb_ethtool_ops = { .get_settings = macb_get_settings, .set_settings = macb_set_settings, - .get_drvinfo = macb_get_drvinfo, .get_link = ethtool_op_get_link, .get_ts_info = ethtool_op_get_ts_info, };
Signature · 1 line
1.8.0
PATCH v4 5/10 net/macb: tx status is more than 8 bits now
In reply to Nicolas FerreOn some revision of GEM, TSR status register has more information.
--- drivers/net/ethernet/cadence/macb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/cadence/macb.c +1 -1
@@ -314,7 +314,7 @@ static void macb_tx(struct macb *bp) status =macb_readl (bp,TSR );macb_writel (bp,TSR , status); -netdev_vdbg (bp->dev,"macb_tx status = %02lx\n" , (unsigned long )status); +netdev_vdbg (bp->dev,"macb_tx status = 0x%03lx\n" , (unsigned long )status);if (status & (MACB_BIT (UND ) |MACB_BIT (TSR_RLE ))) {int i;
Signature · 1 line
1.8.0
PATCH v4 6/10 net/macb: clean up ring buffer logic
In reply to Nicolas FerreFrom: Havard Skinnemoen <[email protected]>
Instead of masking head and tail every time we increment them, just let them wrap through UINT_MAX and mask them when subscripting. Add simple accessor functions to do the subscripting properly to minimize the chances of messing this up.
This makes the code slightly smaller, and hopefully faster as well. Also, doing the ring buffer management this way will simplify things a lot when making the ring sizes configurable in the future.
Available number of descriptors in ring buffer function by David Laight.
--- drivers/net/ethernet/cadence/at91_ether.c | 6 +- drivers/net/ethernet/cadence/macb.c | 172 +++++++++++++++++++----------- drivers/net/ethernet/cadence/macb.h | 22 ++-- 3 files changed, 127 insertions(+), 73 deletions(-)
drivers/net/ethernet/cadence/at91_ether.c +3 -3
@@ -156,7 +156,7 @@ static int at91ether_start(struct net_device *dev)int i; lp->rx_ring =dma_alloc_coherent (&lp->pdev->dev, -MAX_RX_DESCR *sizeof (struct dma_desc ), +MAX_RX_DESCR *sizeof (struct macb_dma_desc ), &lp->rx_ring_dma,GFP_KERNEL );if (!lp->rx_ring) {netdev_err (lp->dev,"unable to alloc rx ring DMA buffer\n" );
@@ -170,7 +170,7 @@ static int at91ether_start(struct net_device *dev)netdev_err (lp->dev,"unable to alloc rx data DMA buffer\n" );dma_free_coherent (&lp->pdev->dev, -MAX_RX_DESCR *sizeof (struct dma_desc ), +MAX_RX_DESCR *sizeof (struct macb_dma_desc ), lp->rx_ring, lp->rx_ring_dma); lp->rx_ring =NULL ;return -ENOMEM ;
@@ -256,7 +256,7 @@ static int at91ether_close(struct net_device *dev)netif_stop_queue (dev);dma_free_coherent (&lp->pdev->dev, -MAX_RX_DESCR *sizeof (struct dma_desc ), +MAX_RX_DESCR *sizeof (struct macb_dma_desc ), lp->rx_ring, lp->rx_ring_dma); lp->rx_ring =NULL ;
drivers/net/ethernet/cadence/macb.c +109 -63
311 lines not on this page · raw message
drivers/net/ethernet/cadence/macb.h +15 -7
@@ -362,7 +362,12 @@ __v; \ }) -struct dma_desc { +/** +* struct macb_dma_desc - Hardware DMA descriptor +* @addr: DMA address of data buffer +* @ctrl: Control and status bits +*/ +struct macb_dma_desc {u32 addr;u32 ctrl; };
@@ -427,7 +432,12 @@ struct dma_desc {#define MACB_TX_USED_OFFSET 31#define MACB_TX_USED_SIZE 1 -struct ring_info { +/** +* struct macb_tx_skb - data about an skb which is being transmitted +* @skb: skb currently being transmitted +* @mapping: DMA address of the skb's data buffer +*/ +struct macb_tx_skb {struct sk_buff *skb;dma_addr_t mapping; };
@@ -512,12 +522,12 @@ struct macb {void __iomem *regs;unsigned int rx_tail; -struct dma_desc *rx_ring; +struct macb_dma_desc *rx_ring;void *rx_buffers;unsigned int tx_head, tx_tail; -struct dma_desc *tx_ring; -struct ring_info *tx_skb; +struct macb_dma_desc *tx_ring; +struct macb_tx_skb *tx_skb;spinlock_t lock;struct platform_device *pdev;
@@ -535,8 +545,6 @@ struct macb {dma_addr_t tx_ring_dma;dma_addr_t rx_buffers_dma; -unsigned int rx_pending, tx_pending; -struct mii_bus *mii_bus;struct phy_device *phy_dev;unsigned int link;
Signature · 1 line
1.8.0
PATCH v4 7/10 net/macb: ethtool interface: add register dump feature
In reply to Nicolas FerreAdd macb_get_regs() ethtool function and its helper function:macb_get_regs_len().
The version field is deduced from the IP revision which gives the "MACB or GEM" information. An additional version field is reserved.
--- drivers/net/ethernet/cadence/macb.c | 40 +++++++++++++++++++++++++++++++++++++ drivers/net/ethernet/cadence/macb.h | 3 +++ 2 files changed, 43 insertions(+)
drivers/net/ethernet/cadence/macb.c +40 -0
@@ -1273,9 +1273,49 @@ static int macb_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)return phy_ethtool_sset (phydev, cmd); } +static int macb_get_regs_len (struct net_device *netdev) +{ +return MACB_GREGS_NBR *sizeof (u32); +} + +static void macb_get_regs (struct net_device *dev,struct ethtool_regs *regs, +void *p) +{ +struct macb *bp =netdev_priv (dev); +unsigned int tail, head; +u32 *regs_buff = p; + + regs->version = (macb_readl (bp,MID ) & ((1 <<MACB_REV_SIZE ) -1 )) + |MACB_GREGS_VERSION ; + + tail =macb_tx_ring_wrap (bp->tx_tail); + head =macb_tx_ring_wrap (bp->tx_head); + + regs_buff[0 ] =macb_readl (bp,NCR ); + regs_buff[1 ] =macb_or_gem_readl (bp,NCFGR ); + regs_buff[2 ] =macb_readl (bp,NSR ); + regs_buff[3 ] =macb_readl (bp,TSR ); + regs_buff[4 ] =macb_readl (bp,RBQP ); + regs_buff[5 ] =macb_readl (bp,TBQP ); + regs_buff[6 ] =macb_readl (bp,RSR ); + regs_buff[7 ] =macb_readl (bp,IMR ); + + regs_buff[8 ] = tail; + regs_buff[9 ] = head; + regs_buff[10 ] =macb_tx_dma (bp, tail); + regs_buff[11 ] =macb_tx_dma (bp, head); + +if (macb_is_gem (bp)) { + regs_buff[12 ] =gem_readl (bp,USRIO ); + regs_buff[13 ] =gem_readl (bp,DMACFG ); + } +} +const struct ethtool_ops macb_ethtool_ops = { .get_settings = macb_get_settings, .set_settings = macb_set_settings, + .get_regs_len = macb_get_regs_len, + .get_regs = macb_get_regs, .get_link = ethtool_op_get_link, .get_ts_info = ethtool_op_get_ts_info, };
drivers/net/ethernet/cadence/macb.h +3 -0
@@ -10,6 +10,9 @@#ifndef _MACB_H#define _MACB_H +#define MACB_GREGS_NBR 16 +#define MACB_GREGS_VERSION 1 +/* MACB register offsets */ #define MACB_NCR 0x0000#define MACB_NCFGR 0x0004
Signature · 1 line
1.8.0
PATCH v4 8/10 net/macb: better manage tx errors
In reply to Nicolas FerreHandle all TX errors, not only underruns. TX error management is deferred to a dedicated workqueue.
Reinitialize the TX ring after treating all remaining frames, and restart the controller when everything has been cleaned up properly. Napi is not stopped during this task as the driver only handles napi for RX for now.
With this sequence, we do not need a special check during the xmit method as the packets will be caught by TX disable during workqueue execution.
--- drivers/net/ethernet/cadence/macb.c | 166 ++++++++++++++++++++++++------------ drivers/net/ethernet/cadence/macb.h | 1 + 2 files changed, 113 insertions(+), 54 deletions(-)
drivers/net/ethernet/cadence/macb.c +112 -54
@@ -44,6 +44,16 @@#define MACB_RX_INT_FLAGS (MACB_BIT(RCOMP) | MACB_BIT(RXUBR) \ | MACB_BIT(ISR_ROVR)) +#define MACB_TX_ERR_FLAGS (MACB_BIT(ISR_TUND) \ + | MACB_BIT(ISR_RLE) \ + | MACB_BIT(TXERR)) +#define MACB_TX_INT_FLAGS (MACB_TX_ERR_FLAGS | MACB_BIT(TCOMP)) + +/* +* Graceful stop timeouts in us. We should allow up to +* 1 frame time (10 Mbits/s, full-duplex, ignoring collisions) +*/ +#define MACB_HALT_TIMEOUT 1230/* Ring buffer accessors */ static unsigned int macb_tx_ring_wrap (unsigned int index)
@@ -339,66 +349,113 @@ static void macb_update_stats(struct macb *bp) *p +=__raw_readl (reg); } -static void macb_tx (struct macb *bp) +static int macb_halt_tx (struct macb *bp) { -unsigned int tail; -unsigned int head; -u32 status; +unsigned long halt_time, timeout; +u32 status; - status =macb_readl (bp,TSR ); -macb_writel (bp,TSR , status); +macb_writel (bp,NCR ,macb_readl (bp,NCR ) |MACB_BIT (THALT )); -netdev_vdbg (bp->dev,"macb_tx status = 0x%03lx\n" , (unsigned long )status); + timeout = jiffies +usecs_to_jiffies (MACB_HALT_TIMEOUT ); +do { + halt_time = jiffies; + status =macb_readl (bp,TSR ); +if (!(status &MACB_BIT (TGO ))) +return 0 ; -if (status & (MACB_BIT (UND ) |MACB_BIT (TSR_RLE ))) { -int i; -netdev_err (bp->dev,"TX %s, resetting buffers\n" , - status &MACB_BIT (UND ) ? -"underrun" :"retry limit exceeded" ); +usleep_range (10 ,250 ); + }while (time_before (halt_time, timeout)); -/* Transfer ongoing, disable transmitter, to avoid confusion */ -if (status &MACB_BIT (TGO )) -macb_writel (bp,NCR ,macb_readl (bp,NCR ) & ~MACB_BIT (TE )); +return -ETIMEDOUT ; +} - head = bp->tx_head; +static void macb_tx_error_task (struct work_struct *work) +{ + struct macb *bp = container_of(work, struct macb, tx_error_task); +struct macb_tx_skb *tx_skb; +struct sk_buff *skb; +unsigned int tail; -/*Mark all the buffer as used to avoid sending a lost buffer*/ -for (i =0 ; i <TX_RING_SIZE ; i++) - bp->tx_ring[i].ctrl =MACB_BIT (TX_USED ); +netdev_vdbg (bp->dev,"macb_tx_error_task: t = %u, h = %u\n" , + bp->tx_tail, bp->tx_head); -/* Add wrap bit */ - bp->tx_ring[TX_RING_SIZE -1 ].ctrl |=MACB_BIT (TX_WRAP ); +/* Make sure nobody is trying to queue up new packets */ +netif_stop_queue (bp->dev); -/* free transmit buffer in upper layer*/ -for (tail = bp->tx_tail; tail != head; tail++) { -struct macb_tx_skb *tx_skb; -struct sk_buff *skb; +/* +* Stop transmission now +* (in case we have just queued new packets) +*/ +if (macb_halt_tx (bp)) +/* Just complain for now, reinitializing TX path can be good */ +netdev_err (bp->dev,"BUG: halt tx timed out\n" ); -rmb (); +/* No need for the lock here as nobody will interrupt us anymore */ - tx_skb =macb_tx_skb (bp, tail); - skb = tx_skb->skb; +/* +* Treat frames in TX queue including the ones that caused the error. +* Free transmit buffers in upper layer. +*/ +for (tail = bp->tx_tail; tail != bp->tx_head; tail++) { +struct macb_dma_desc *desc; +u32 ctrl; -dma_unmap_single (&bp->pdev->dev, tx_skb->mapping, - skb->len,DMA_TO_DEVICE ); - tx_skb->skb =NULL ; -dev_kfree_skb_irq (skb); - } + desc =macb_tx_desc (bp, tail); + ctrl = desc->ctrl; + tx_skb =macb_tx_skb (bp, tail); + skb = tx_skb->skb; - bp->tx_head = bp->tx_tail =0 ; +if (ctrl &MACB_BIT (TX_USED )) { +netdev_vdbg (bp->dev,"txerr skb %u (data %p) TX complete\n" , +macb_tx_ring_wrap (tail), skb->data); + bp->stats.tx_packets++; + bp->stats.tx_bytes += skb->len; + }else { +/* +* "Buffers exhausted mid-frame" errors may only happen +* if the driver is buggy, so complain loudly about those. +* Statistics are updated by hardware. +*/ +if (ctrl &MACB_BIT (TX_BUF_EXHAUSTED )) +netdev_err (bp->dev, +"BUG: TX buffers exhausted mid-frame\n" ); -/* Enable the transmitter again */ -if (status &MACB_BIT (TGO )) -macb_writel (bp,NCR ,macb_readl (bp,NCR ) |MACB_BIT (TE )); + desc->ctrl = ctrl |MACB_BIT (TX_USED ); + } + +dma_unmap_single (&bp->pdev->dev, tx_skb->mapping, skb->len, +DMA_TO_DEVICE ); + tx_skb->skb =NULL ; +dev_kfree_skb (skb); } -if (!(status &MACB_BIT (COMP ))) -/* -* This may happen when a buffer becomes complete -* between reading the ISR and scanning the -* descriptors. Nothing to worry about. -*/ -return ; +/* Make descriptor updates visible to hardware */ +wmb (); + +/* Reinitialize the TX desc queue */ +macb_writel (bp,TBQP , bp->tx_ring_dma); +/* Make TX ring reflect state of hardware */ + bp->tx_head = bp->tx_tail =0 ; + +/* Now we are ready to start transmission again */ +netif_wake_queue (bp->dev); + +/* Housework before enabling TX IRQ */ +macb_writel (bp,TSR ,macb_readl (bp,TSR )); +macb_writel (bp,IER ,MACB_TX_INT_FLAGS ); +} + +static void macb_tx_interrupt (struct macb *bp) +{ +unsigned int tail; +unsigned int head; +u32 status; + + status =macb_readl (bp,TSR ); +macb_writel (bp,TSR , status); + +netdev_vdbg (bp->dev,"macb_tx_interrupt status = 0x%03lx\n" , + (unsigned long )status); head = bp->tx_head;for (tail = bp->tx_tail; tail != head; tail++) {
@@ -638,9 +695,14 @@ static irqreturn_t macb_interrupt(int irq, void *dev_id) } } -if (status & (MACB_BIT (TCOMP ) |MACB_BIT (ISR_TUND ) | -MACB_BIT (ISR_RLE ))) -macb_tx (bp); +if (unlikely (status & (MACB_TX_ERR_FLAGS ))) { +macb_writel (bp,IDR ,MACB_TX_INT_FLAGS ); +schedule_work (&bp->tx_error_task); +break ; + } + +if (status &MACB_BIT (TCOMP )) +macb_tx_interrupt (bp);/* * Link change detection isn't possible with RMII, so we'll
@@ -970,13 +1032,8 @@ static void macb_init_hw(struct macb *bp)macb_writel (bp,NCR ,MACB_BIT (RE ) |MACB_BIT (TE ) |MACB_BIT (MPE ));/* Enable interrupts */ -macb_writel (bp,IER , (MACB_BIT (RCOMP ) - |MACB_BIT (RXUBR ) - |MACB_BIT (ISR_TUND ) - |MACB_BIT (ISR_RLE ) - |MACB_BIT (TXERR ) - |MACB_BIT (TCOMP ) - |MACB_BIT (ISR_ROVR ) +macb_writel (bp,IER , (MACB_RX_INT_FLAGS + |MACB_TX_INT_FLAGS |MACB_BIT (HRESP ))); }
@@ -1428,6 +1485,7 @@ static int __init macb_probe(struct platform_device *pdev) bp->dev = dev;spin_lock_init (&bp->lock); +INIT_WORK (&bp->tx_error_task, macb_tx_error_task); bp->pclk =clk_get (&pdev->dev,"pclk" );if (IS_ERR (bp->pclk)) {
drivers/net/ethernet/cadence/macb.h +1 -0
@@ -538,6 +538,7 @@ struct macb {struct clk *hclk;struct net_device *dev;struct napi_struct napi; +struct work_struct tx_error_task;struct net_device_stats stats;union {struct macb_stats macb;
Signature · 1 line
1.8.0
PATCH v4 9/10 net/macb: Offset first RX buffer by two bytes
In reply to Nicolas FerreFrom: Havard Skinnemoen <[email protected]>
Make the ethernet frame payload word-aligned, possibly making the memcpy into the skb a bit faster. This will be even more important after we eliminate the copy altogether.
Also eliminate the redundant RX_OFFSET constant -- it has the same definition and purpose as NET_IP_ALIGN.
--- drivers/net/ethernet/cadence/macb.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-)
drivers/net/ethernet/cadence/macb.c +16 -7
@@ -33,9 +33,6 @@#define RX_RING_SIZE 512/* must be power of 2 */ #define RX_RING_BYTES (sizeof(struct macb_dma_desc) * RX_RING_SIZE) -/* Make the IP header word-aligned (the ethernet header is 14 bytes) */ -#define RX_OFFSET 2 -#define TX_RING_SIZE 128/* must be power of 2 */ #define TX_RING_BYTES (sizeof(struct macb_dma_desc) * TX_RING_SIZE)
@@ -498,7 +495,7 @@ static int macb_rx_frame(struct macb *bp, unsigned int first_frag, {unsigned int len;unsigned int frag; -unsigned int offset =0 ; +unsigned int offset;struct sk_buff *skb;struct macb_dma_desc *desc;
@@ -509,7 +506,16 @@ static int macb_rx_frame(struct macb *bp, unsigned int first_frag,macb_rx_ring_wrap (first_frag), macb_rx_ring_wrap(last_frag), len); - skb =netdev_alloc_skb (bp->dev, len +RX_OFFSET ); +/* +* The ethernet header starts NET_IP_ALIGN bytes into the +* first buffer. Since the header is 14 bytes, this makes the +* payload word-aligned. +* +* Instead of calling skb_reserve(NET_IP_ALIGN), we just copy +* the two padding bytes into the skb so that we avoid hitting +* the slowpath in memcpy(), and pull them off afterwards. +*/ + skb =netdev_alloc_skb (bp->dev, len +NET_IP_ALIGN );if (!skb) { bp->stats.rx_dropped++;for (frag = first_frag; ; frag++) {
@@ -525,7 +531,8 @@ static int macb_rx_frame(struct macb *bp, unsigned int first_frag,return 1 ; } -skb_reserve (skb,RX_OFFSET ); + offset =0 ; + len +=NET_IP_ALIGN ;skb_checksum_none_assert (skb);skb_put (skb, len);
@@ -549,10 +556,11 @@ static int macb_rx_frame(struct macb *bp, unsigned int first_frag,/* Make descriptor updates visible to hardware */ wmb (); +__skb_pull (skb,NET_IP_ALIGN ); skb->protocol =eth_type_trans (skb, bp->dev); bp->stats.rx_packets++; - bp->stats.rx_bytes += len; + bp->stats.rx_bytes += skb->len;netdev_vdbg (bp->dev,"received skb of length %u, csum: %08x\n" , skb->len, skb->csum);netif_receive_skb (skb);
@@ -1012,6 +1020,7 @@ static void macb_init_hw(struct macb *bp)__macb_set_hwaddr (bp); config =macb_mdc_clk_div (bp); + config |=MACB_BF (RBOF ,NET_IP_ALIGN );/* Make eth data aligned */ config |=MACB_BIT (PAE );/* PAuse Enable */ config |=MACB_BIT (DRFCS );/* Discard Rx FCS */ config |=MACB_BIT (BIG );/* Receive oversized frames */
Signature · 1 line
1.8.0
PATCH v4 10/10 net/macb: add pinctrl consumer support
In reply to Nicolas FerreFrom: Jean-Christophe PLAGNIOL-VILLARD <[email protected]>
If no pinctrl available just report a warning as some architecture may not need to do anything.
--- drivers/net/ethernet/cadence/macb.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/net/ethernet/cadence/macb.c +11 -0
@@ -26,6 +26,7 @@#include <linux/of.h> #include <linux/of_device.h> #include <linux/of_net.h> +#include <linux/pinctrl/consumer.h> #include "macb.h"
@@ -1472,6 +1473,7 @@ static int __init macb_probe(struct platform_device *pdev)struct phy_device *phydev;u32 config;int err = -ENXIO ; +struct pinctrl *pinctrl; regs =platform_get_resource (pdev,IORESOURCE_MEM ,0 );if (!regs) {
@@ -1479,6 +1481,15 @@ static int __init macb_probe(struct platform_device *pdev) goto err_out; } + pinctrl =devm_pinctrl_get_select_default (&pdev->dev); +if (IS_ERR (pinctrl)) { + err =PTR_ERR (pinctrl); +if (err == -EPROBE_DEFER ) + goto err_out; + +dev_warn (&pdev->dev,"No pinctrl provided\n" ); + } + err = -ENOMEM ; dev =alloc_etherdev (sizeof (*bp));if (!dev)
Signature · 1 line
1.8.0
Quoted 34 lines · Nicolas Ferre
This is an enhancement work that began several years ago. I try to catchup with some performance improvement that has been implemented then by Havard. The ring index logic and the TX error path modification are the biggest changes but some cleanup/debugging have been added along the way.
The GEM revision will benefit from the Gigabit support.
Newer pinctrl infrastructure support is added but it is optional.The series has been tested on several Atmel AT91 SoC with the two MACB/GEM flavors.
v4: - remove unneeded device tree header includes
- modified the computation of available entries in ring buffer
v3: - rebased on net-next to take into account current effor to merge
at91_etherwith macb drivers
- add additional patch to use the new pinctrl infrastructure
v2: - modify the tx error handling: now uses a workqueue
- information provided by ethtool -i were not accurate: removedHavard Skinnemoen (4):
net/macb: memory barriers cleanup
net/macb: change debugging messages
net/macb: clean up ring buffer logic
net/macb: Offset first RX buffer by two bytesJean-Christophe PLAGNIOL-VILLARD (1):
net/macb: add pinctrl consumer supportNicolas Ferre (4):
net/macb: removemacb_get_drvinfo()
net/macb: tx status is more than 8 bits now net/macb: ethtool interface: add register dump feature net/macb: better manage tx errors
Quoted 7 lines
Patrice Vilchez (1):
net/macb: Add support for Gigabit Ethernet modedrivers/net/ethernet/cadence/at91_ether.c | 6 +- drivers/net/ethernet/cadence/macb.c | 448 +++++++++++++++++++++--------- drivers/net/ethernet/cadence/macb.h | 30 +- 3 files changed, 337 insertions(+), 147 deletions(-)
Best Regards,
J.
Quoted 4 lines
Signature · 2 lines
-- 1.8.0
David Miller
maintainerFrom: Nicolas Ferre <[email protected]>
Date: Wed, 31 Oct 2012 17:04:49 +0100
Quoted 10 lines
This is an enhancement work that began several years ago. I try to catchup with some performance improvement that has been implemented then by Havard. The ring index logic and the TX error path modification are the biggest changes but some cleanup/debugging have been added along the way.
The GEM revision will benefit from the Gigabit support.
Newer pinctrl infrastructure support is added but it is optional.The series has been tested on several Atmel AT91 SoC with the two MACB/GEM flavors.
Quoted 7 lines
v4: - remove unneeded device tree header includes
- modified the computation of available entries in ring buffer
v3: - rebased on net-next to take into account current effor to merge
at91_etherwith macb drivers
- add additional patch to use the new pinctrl infrastructure
v2: - modify the tx error handling: now uses a workqueue
- information provided by ethtool -i were not accurate: removed
Series applied to net-next