Fixes for SONIC ethernet driver
Subsystems (3)
PATCH v2 7/12 net/sonic: Improve receive descriptor status flag check
In reply to Finn ThainAfter sonic_tx_timeout() calls sonic_init(), it can happen that sonic_rx() will subsequently encounter a receive descriptor with no flags set. Remove the comment that says that this can't happen.
When giving a receive descriptor to the SONIC, clear the descriptor status field. That way, any rx descriptor with flags set can only be a newly received packet.
Don't process a descriptor without the LPKT bit set. The buffer is still in use by the SONIC.
--- drivers/net/ethernet/natsemi/sonic.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
drivers/net/ethernet/natsemi/sonic.c +6 -10
@@ -430,7 +430,6 @@ static inline int index_from_addr(struct sonic_local *lp, dma_addr_t addr,static void sonic_rx (struct net_device *dev) {struct sonic_local *lp =netdev_priv (dev); -int status;int entry = lp->cur_rx;int prev_entry = lp->eol_rx;
@@ -441,9 +440,11 @@ static void sonic_rx(struct net_device *dev)u16 bufadr_l;u16 bufadr_h;int pkt_len; +u16 status =sonic_rda_get (dev, entry,SONIC_RD_STATUS ); + +/* If the RD has LPKT set, the chip has finished with the RB */ - status =sonic_rda_get (dev, entry,SONIC_RD_STATUS ); -if (status &SONIC_RCR_PRX ) { +if ((status &SONIC_RCR_PRX ) && (status &SONIC_RCR_LPKT )) {u32 addr = (sonic_rda_get (dev, entry,SONIC_RD_PKTPTR_H ) <<16 ) |sonic_rda_get (dev, entry,SONIC_RD_PKTPTR_L );
@@ -491,10 +492,6 @@ static void sonic_rx(struct net_device *dev) bufadr_h = (unsigned long )new_laddr >>16 ;sonic_rra_put (dev, i,SONIC_RR_BUFADR_L , bufadr_l);sonic_rra_put (dev, i,SONIC_RR_BUFADR_H , bufadr_h); - }else { -/* This should only happen, if we enable accepting broken packets. */ - } -if (status &SONIC_RCR_LPKT ) {/* * this was the last packet out of the current receive buffer * give the buffer back to the SONIC
@@ -507,12 +504,11 @@ static void sonic_rx(struct net_device *dev) __func__);SONIC_WRITE (SONIC_ISR ,SONIC_INT_RBE );/* clear the flag */ } - }else -printk (KERN_ERR "%s: rx desc without RCR_LPKT. Shouldn't happen !?\n" , - dev->name); + }/* * give back the descriptor */ +sonic_rda_put (dev, entry,SONIC_RD_STATUS ,0 );sonic_rda_put (dev, entry,SONIC_RD_IN_USE ,1 ); prev_entry = entry;
Signature · 1 line
2.24.1
PATCH v2 5/12 net/sonic: Fix receive buffer handling
In reply to Finn ThainThe SONIC can sometimes advance its rx buffer pointer (RRP register) without advancing its rx descriptor pointer (CRDA register). As a result the index of the current rx descriptor may not equal that of the current rx buffer. The driver mistakenly assumes that they are always equal. This assumption leads to incorrect packet lengths and possible packet duplication. Avoid this by calling a new function to locate the buffer corresponding to a given descriptor.
--- drivers/net/ethernet/natsemi/sonic.c | 36 ++++++++++++++++++++++++---- drivers/net/ethernet/natsemi/sonic.h | 5 ++-- 2 files changed, 34 insertions(+), 7 deletions(-)
drivers/net/ethernet/natsemi/sonic.c +31 -5
@@ -408,6 +408,22 @@ static irqreturn_t sonic_interrupt(int irq, void *dev_id)return IRQ_HANDLED ; } +/* Return the array index corresponding to a given Receive Buffer pointer. */ + +static inline int index_from_addr (struct sonic_local *lp,dma_addr_t addr, +unsigned int last) +{ +unsigned int i = last; + +do { + i = (i +1 ) &SONIC_RRS_MASK ; +if (addr == lp->rx_laddr[i]) +return i; + }while (i != last); + +return -ENOENT ; +} +/* * We have a good packet(s), pass it/them up the network stack. */
@@ -427,6 +443,16 @@ static void sonic_rx(struct net_device *dev) status =sonic_rda_get (dev, entry,SONIC_RD_STATUS );if (status &SONIC_RCR_PRX ) { +u32 addr = (sonic_rda_get (dev, entry, +SONIC_RD_PKTPTR_H ) <<16 ) | +sonic_rda_get (dev, entry,SONIC_RD_PKTPTR_L ); +int i =index_from_addr (lp, addr, entry); + +if (i <0 ) { +WARN_ONCE (1 ,"failed to find buffer!\n" ); +break ; + } +/* Malloc up new buffer. */ new_skb =netdev_alloc_skb (dev,SONIC_RBSIZE +2 );if (new_skb ==NULL ) {
@@ -448,7 +474,7 @@ static void sonic_rx(struct net_device *dev)/* now we have a new skb to replace it, pass the used one up the stack */ dma_unmap_single (lp->device, lp->rx_laddr[entry],SONIC_RBSIZE ,DMA_FROM_DEVICE ); - used_skb = lp->rx_skb[entry]; + used_skb = lp->rx_skb[i]; pkt_len =sonic_rda_get (dev, entry,SONIC_RD_PKTLEN );skb_trim (used_skb, pkt_len); used_skb->protocol =eth_type_trans (used_skb, dev);
@@ -457,13 +483,13 @@ static void sonic_rx(struct net_device *dev) lp->stats.rx_bytes += pkt_len;/* and insert the new skb */ - lp->rx_laddr[entry] = new_laddr; - lp->rx_skb[entry] = new_skb; + lp->rx_laddr[i] = new_laddr; + lp->rx_skb[i] = new_skb; bufadr_l = (unsigned long )new_laddr &0xffff ; bufadr_h = (unsigned long )new_laddr >>16 ; -sonic_rra_put (dev, entry,SONIC_RR_BUFADR_L , bufadr_l); -sonic_rra_put (dev, entry,SONIC_RR_BUFADR_H , bufadr_h); +sonic_rra_put (dev, i,SONIC_RR_BUFADR_L , bufadr_l); +sonic_rra_put (dev, i,SONIC_RR_BUFADR_H , bufadr_h); }else {/* This should only happen, if we enable accepting broken packets. */ }
drivers/net/ethernet/natsemi/sonic.h +3 -2
@@ -275,8 +275,9 @@#define SONIC_NUM_RDS SONIC_NUM_RRS/* number of receive descriptors */ #define SONIC_NUM_TDS 16/* number of transmit descriptors */ -#define SONIC_RDS_MASK (SONIC_NUM_RDS-1) -#define SONIC_TDS_MASK (SONIC_NUM_TDS-1) +#define SONIC_RRS_MASK (SONIC_NUM_RRS - 1) +#define SONIC_RDS_MASK (SONIC_NUM_RDS - 1) +#define SONIC_TDS_MASK (SONIC_NUM_TDS - 1)#define SONIC_RBSIZE 1520/* size of one resource buffer */
Signature · 1 line
2.24.1
PATCH v2 8/12 net/sonic: Fix receive buffer replenishment
In reply to Finn ThainAs soon as the driver is finished with a receive buffer it allocs a new one and overwrites the corresponding RRA entry with a new buffer pointer.
Problem is, the buffer pointer is split across two word-sized registers. It can't be updated in one atomic store. So this operation races with the chip while it stores received packets and advances its RRP register. This could result in memory corruption by a DMA write.
Avoid this problem by adding buffers only at the location given by the RWP register, in accordance with the National Semiconductor datasheet.
Re-factor this code into separate functions to calculate a RRA pointer and to update the RWP.
---
Changed since v1:
- Added WARN_ON() sanity check.
--- drivers/net/ethernet/natsemi/sonic.c | 152 ++++++++++++++++----------- drivers/net/ethernet/natsemi/sonic.h | 18 +++- 2 files changed, 107 insertions(+), 63 deletions(-)
drivers/net/ethernet/natsemi/sonic.c +91 -61
@@ -424,6 +424,61 @@ static inline int index_from_addr(struct sonic_local *lp, dma_addr_t addr,return -ENOENT ; } +/* Allocate and map a new skb to be used as a receive buffer. */ + +static bool sonic_alloc_rb (struct net_device *dev,struct sonic_local *lp, +struct sk_buff **new_skb,dma_addr_t *new_addr) +{ + *new_skb =netdev_alloc_skb (dev,SONIC_RBSIZE +2 ); +if (!*new_skb) +return false; + +if (SONIC_BUS_SCALE (lp->dma_bitmode) ==2 ) +skb_reserve (*new_skb,2 ); + + *new_addr =dma_map_single (lp->device,skb_put (*new_skb,SONIC_RBSIZE ), +SONIC_RBSIZE ,DMA_FROM_DEVICE ); +if (!*new_addr) { +dev_kfree_skb (*new_skb); + *new_skb =NULL ; +return false; + } + +return true; +} + +/* Place a new receive resource in the Receive Resource Area and update RWP. */ + +static void sonic_update_rra (struct net_device *dev,struct sonic_local *lp, +dma_addr_t old_addr,dma_addr_t new_addr) +{ +unsigned int entry =sonic_rr_entry (dev,SONIC_READ (SONIC_RWP )); +unsigned int end =sonic_rr_entry (dev,SONIC_READ (SONIC_RRP )); +u32 buf; + +/* The resources in the range [RRP, RWP) belong to the SONIC. This loop +* scans the other resources in the RRA, those in the range [RWP, RRP). +*/ +do { + buf = (sonic_rra_get (dev, entry,SONIC_RR_BUFADR_H ) <<16 ) | +sonic_rra_get (dev, entry,SONIC_RR_BUFADR_L ); + +if (buf == old_addr) +break ; + + entry = (entry +1 ) &SONIC_RRS_MASK ; + }while (entry != end); + +WARN_ONCE (buf != old_addr,"failed to find resource!\n" ); + +sonic_rra_put (dev, entry,SONIC_RR_BUFADR_H , new_addr >>16 ); +sonic_rra_put (dev, entry,SONIC_RR_BUFADR_L , new_addr &0xffff ); + + entry = (entry +1 ) &SONIC_RRS_MASK ; + +SONIC_WRITE (SONIC_RWP ,sonic_rr_addr (dev, entry)); +} +/* * We have a good packet(s), pass it/them up the network stack. */
@@ -432,19 +487,16 @@ static void sonic_rx(struct net_device *dev)struct sonic_local *lp =netdev_priv (dev);int entry = lp->cur_rx;int prev_entry = lp->eol_rx; +bool rbe = false;while (sonic_rda_get (dev, entry,SONIC_RD_IN_USE ) ==0 ) { -struct sk_buff *used_skb; -struct sk_buff *new_skb; -dma_addr_t new_laddr; -u16 bufadr_l; -u16 bufadr_h; -int pkt_len;u16 status =sonic_rda_get (dev, entry,SONIC_RD_STATUS );/* If the RD has LPKT set, the chip has finished with the RB */ if ((status &SONIC_RCR_PRX ) && (status &SONIC_RCR_LPKT )) { +struct sk_buff *new_skb; +dma_addr_t new_laddr;u32 addr = (sonic_rda_get (dev, entry,SONIC_RD_PKTPTR_H ) <<16 ) |sonic_rda_get (dev, entry,SONIC_RD_PKTPTR_L );
@@ -455,55 +507,35 @@ static void sonic_rx(struct net_device *dev)break ; } -/* Malloc up new buffer. */ - new_skb =netdev_alloc_skb (dev,SONIC_RBSIZE +2 ); -if (new_skb ==NULL ) { - lp->stats.rx_dropped++; -break ; - } -/* provide 16 byte IP header alignment unless DMA requires otherwise */ -if (SONIC_BUS_SCALE (lp->dma_bitmode) ==2 ) -skb_reserve (new_skb,2 ); - - new_laddr =dma_map_single (lp->device,skb_put (new_skb,SONIC_RBSIZE ), -SONIC_RBSIZE ,DMA_FROM_DEVICE ); -if (!new_laddr) { -dev_kfree_skb (new_skb); -printk (KERN_ERR "%s: Failed to map rx buffer, dropping packet.\n" , dev->name); +if (sonic_alloc_rb (dev, lp, &new_skb, &new_laddr)) { +struct sk_buff *used_skb = lp->rx_skb[i]; +int pkt_len; + +/* Pass the used buffer up the stack */ +dma_unmap_single (lp->device, addr,SONIC_RBSIZE , +DMA_FROM_DEVICE ); + + pkt_len =sonic_rda_get (dev, entry, +SONIC_RD_PKTLEN ); +skb_trim (used_skb, pkt_len); + used_skb->protocol =eth_type_trans (used_skb, + dev); +netif_rx (used_skb); + lp->stats.rx_packets++; + lp->stats.rx_bytes += pkt_len; + + lp->rx_skb[i] = new_skb; + lp->rx_laddr[i] = new_laddr; + }else { +/* Failed to obtain a new buffer so re-use it */ + new_laddr = addr; lp->stats.rx_dropped++; -break ; } - -/* now we have a new skb to replace it, pass the used one up the stack */ -dma_unmap_single (lp->device, lp->rx_laddr[entry],SONIC_RBSIZE ,DMA_FROM_DEVICE ); - used_skb = lp->rx_skb[i]; - pkt_len =sonic_rda_get (dev, entry,SONIC_RD_PKTLEN ); -skb_trim (used_skb, pkt_len); - used_skb->protocol =eth_type_trans (used_skb, dev); -netif_rx (used_skb); - lp->stats.rx_packets++; - lp->stats.rx_bytes += pkt_len; - -/* and insert the new skb */ - lp->rx_laddr[i] = new_laddr; - lp->rx_skb[i] = new_skb; - - bufadr_l = (unsigned long )new_laddr &0xffff ; - bufadr_h = (unsigned long )new_laddr >>16 ; -sonic_rra_put (dev, i,SONIC_RR_BUFADR_L , bufadr_l); -sonic_rra_put (dev, i,SONIC_RR_BUFADR_H , bufadr_h); -/* -* this was the last packet out of the current receive buffer -* give the buffer back to the SONIC +/* If RBE is already asserted when RWP advances then +* it's safe to clear RBE after processing this packet. */ - lp->cur_rwp +=SIZEOF_SONIC_RR *SONIC_BUS_SCALE (lp->dma_bitmode); -if (lp->cur_rwp >= lp->rra_end) lp->cur_rwp = lp->rra_laddr &0xffff ; -SONIC_WRITE (SONIC_RWP , lp->cur_rwp); -if (SONIC_READ (SONIC_ISR ) &SONIC_INT_RBE ) { -netif_dbg (lp, rx_err, dev,"%s: rx buffer exhausted\n" , - __func__); -SONIC_WRITE (SONIC_ISR ,SONIC_INT_RBE );/* clear the flag */ - } + rbe = rbe ||SONIC_READ (SONIC_ISR ) &SONIC_INT_RBE ; +sonic_update_rra (dev, lp, addr, new_laddr); }/* * give back the descriptor
@@ -525,6 +557,9 @@ static void sonic_rx(struct net_device *dev) sonic_rda_get(dev, lp->eol_rx, SONIC_RD_LINK)); lp->eol_rx = prev_entry; } + +if (rbe) +SONIC_WRITE (SONIC_ISR ,SONIC_INT_RBE );/* * If any worth-while packets have been received, netif_rx() * has done a mark_bh(NET_BH) for us and will work on them
@@ -639,15 +674,10 @@ static int sonic_init(struct net_device *dev) }/* initialize all RRA registers */ - lp->rra_end = (lp->rra_laddr +SONIC_NUM_RRS *SIZEOF_SONIC_RR * -SONIC_BUS_SCALE (lp->dma_bitmode)) &0xffff ; - lp->cur_rwp = (lp->rra_laddr + (SONIC_NUM_RRS -1 ) *SIZEOF_SONIC_RR * -SONIC_BUS_SCALE (lp->dma_bitmode)) &0xffff ; - -SONIC_WRITE (SONIC_RSA , lp->rra_laddr &0xffff ); -SONIC_WRITE (SONIC_REA , lp->rra_end); -SONIC_WRITE (SONIC_RRP , lp->rra_laddr &0xffff ); -SONIC_WRITE (SONIC_RWP , lp->cur_rwp); +SONIC_WRITE (SONIC_RSA ,sonic_rr_addr (dev,0 )); +SONIC_WRITE (SONIC_REA ,sonic_rr_addr (dev,SONIC_NUM_RRS )); +SONIC_WRITE (SONIC_RRP ,sonic_rr_addr (dev,0 )); +SONIC_WRITE (SONIC_RWP ,sonic_rr_addr (dev,SONIC_NUM_RRS -1 ));SONIC_WRITE (SONIC_URRA , lp->rra_laddr >>16 );SONIC_WRITE (SONIC_EOBC , (SONIC_RBSIZE >>1 ) - (lp->dma_bitmode ?2 :1 ));
drivers/net/ethernet/natsemi/sonic.h +16 -2
@@ -314,8 +314,6 @@ struct sonic_local {u32 rda_laddr;/* logical DMA address of RDA */ dma_addr_t rx_laddr[SONIC_NUM_RRS ];/* logical DMA addresses of rx skbuffs */ dma_addr_t tx_laddr[SONIC_NUM_TDS ];/* logical DMA addresses of tx skbuffs */ -unsigned int rra_end; -unsigned int cur_rwp;unsigned int cur_rx;unsigned int cur_tx;/* first unacked transmit packet */ unsigned int eol_rx;
@@ -450,6 +448,22 @@ static inline __u16 sonic_rra_get(struct net_device* dev, int entry, (entry * SIZEOF_SONIC_RR) + offset); } +static inline u16 sonic_rr_addr (struct net_device *dev,int entry) +{ +struct sonic_local *lp =netdev_priv (dev); + +return lp->rra_laddr + + entry *SIZEOF_SONIC_RR *SONIC_BUS_SCALE (lp->dma_bitmode); +} + +static inline u16 sonic_rr_entry (struct net_device *dev,u16 addr) +{ +struct sonic_local *lp =netdev_priv (dev); + +return (addr - (u16 )lp->rra_laddr) / (SIZEOF_SONIC_RR * +SONIC_BUS_SCALE (lp->dma_bitmode)); +} +static const char version[] ="sonic.c:v0.92 20.9.98 [email protected]\n" ;
Signature · 1 line
2.24.1
PATCH v2 11/12 net/sonic: Fix CAM initialization
In reply to Finn ThainSection 4.3.1 of the datasheet says,
This bit [TXP] must not be set if a Load CAM operation is in progress (LCAM is set). The SONIC will lock up if both bits are set simultaneously.
Testing has shown that the driver sometimes attempts to set LCAM while TXP is set. Avoid this by waiting for command completion before and after giving the LCAM command.
After issuing the Load CAM command, poll for !SONIC_CR_LCAM rather than SONIC_INT_LCD, because the SONIC_CR_TXP bit can't be used until !SONIC_CR_LCAM.
When in reset mode, take the opportunity to reset the CAM Enable register.
--- drivers/net/ethernet/natsemi/sonic.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)
drivers/net/ethernet/natsemi/sonic.c +12 -9
@@ -634,6 +634,8 @@ static void sonic_multicast_list(struct net_device *dev) (netdev_mc_count(dev) > 15)) { rcr |= SONIC_RCR_AMC; } else { +unsigned long flags; +netif_dbg (lp, ifup, dev,"%s: mc_count %d\n" , __func__,netdev_mc_count (dev));sonic_set_cam_enable (dev,1 );/* always enable our own address */
@@ -647,9 +649,14 @@ static void sonic_multicast_list(struct net_device *dev) i++; }SONIC_WRITE (SONIC_CDC ,16 ); -/* issue Load CAM command */ SONIC_WRITE (SONIC_CDP , lp->cda_laddr &0xffff ); + +/* LCAM and TXP commands can't be used simultaneously */ +local_irq_save (flags); +sonic_quiesce (dev,SONIC_CR_TXP );SONIC_WRITE (SONIC_CMD ,SONIC_CR_LCAM ); +sonic_quiesce (dev,SONIC_CR_LCAM ); +local_irq_restore (flags); } }
@@ -675,6 +682,9 @@ static int sonic_init(struct net_device *dev)SONIC_WRITE (SONIC_ISR ,0x7fff );SONIC_WRITE (SONIC_CMD ,SONIC_CR_RST ); +/* While in reset mode, clear CAM Enable register */ +SONIC_WRITE (SONIC_CE ,0 ); +/* * clear software reset flag, disable receiver, clear and * enable interrupts, then completely initialize the SONIC
@@ -785,14 +795,7 @@ static int sonic_init(struct net_device *dev)* load the CAM */ SONIC_WRITE (SONIC_CMD ,SONIC_CR_LCAM ); - - i =0 ; -while (i++ <100 ) { -if (SONIC_READ (SONIC_ISR ) &SONIC_INT_LCD ) -break ; - } -netif_dbg (lp, ifup, dev,"%s: CMD=%x, ISR=%x, i=%d\n" , __func__, -SONIC_READ (SONIC_CMD ),SONIC_READ (SONIC_ISR ), i); +sonic_quiesce (dev,SONIC_CR_LCAM );/* * enable receiver, disable loopback
Signature · 1 line
2.24.1
PATCH v2 4/12 net/sonic: Fix interface error stats collection
In reply to Finn ThainThe tx_aborted_errors statistic should count packets flagged with EXD, EXC, FU, or BCM bits because those bits denote an aborted transmission. That corresponds to the bitmask 0x0446, not 0x0642. Use macros for these constants to avoid mistakes. Better to leave out FIFO Underruns (FU) as there's a separate counter for that purpose.
Don't lump all these errors in with the general tx_errors counter as that's used for tx timeout events.
On the rx side, don't count RDE and RBAE interrupts as dropped packets. These interrupts don't indicate a lost packet, just a lack of resources. When a lack of resources results in a lost packet, this gets reported in the rx_missed_errors counter (along with RFO events).
Don't double-count rx_frame_errors and rx_crc_errors.
Don't use the general rx_errors counter for events that already have special counters.
--- drivers/net/ethernet/natsemi/sonic.c | 21 +++++++-------------- drivers/net/ethernet/natsemi/sonic.h | 1 + 2 files changed, 8 insertions(+), 14 deletions(-)
drivers/net/ethernet/natsemi/sonic.c +7 -14
@@ -325,18 +325,19 @@ static irqreturn_t sonic_interrupt(int irq, void *dev_id)if ((td_status =sonic_tda_get (dev, entry,SONIC_TD_STATUS )) ==0 )break ; -if (td_status &0x0001 ) { +if (td_status &SONIC_TCR_PTX ) { lp->stats.tx_packets++; lp->stats.tx_bytes +=sonic_tda_get (dev, entry,SONIC_TD_PKTSIZE ); }else { - lp->stats.tx_errors++; -if (td_status &0x0642 ) +if (td_status & (SONIC_TCR_EXD | +SONIC_TCR_EXC |SONIC_TCR_BCM )) lp->stats.tx_aborted_errors++; -if (td_status &0x0180 ) +if (td_status & + (SONIC_TCR_NCRS |SONIC_TCR_CRLS )) lp->stats.tx_carrier_errors++; -if (td_status &0x0020 ) +if (td_status &SONIC_TCR_OWC ) lp->stats.tx_window_errors++; -if (td_status &0x0004 ) +if (td_status &SONIC_TCR_FU ) lp->stats.tx_fifo_errors++; }
@@ -366,17 +367,14 @@ static irqreturn_t sonic_interrupt(int irq, void *dev_id)if (status &SONIC_INT_RFO ) {netif_dbg (lp, rx_err, dev,"%s: rx fifo overrun\n" , __func__); - lp->stats.rx_fifo_errors++; }if (status &SONIC_INT_RDE ) {netif_dbg (lp, rx_err, dev,"%s: rx descriptors exhausted\n" , __func__); - lp->stats.rx_dropped++; }if (status &SONIC_INT_RBAE ) {netif_dbg (lp, rx_err, dev,"%s: rx buffer area exceeded\n" , __func__); - lp->stats.rx_dropped++; }/* counter overruns; all counters are 16bit wide */
@@ -468,11 +466,6 @@ static void sonic_rx(struct net_device *dev)sonic_rra_put (dev, entry,SONIC_RR_BUFADR_H , bufadr_h); }else {/* This should only happen, if we enable accepting broken packets. */ - lp->stats.rx_errors++; -if (status &SONIC_RCR_FAER ) - lp->stats.rx_frame_errors++; -if (status &SONIC_RCR_CRCR ) - lp->stats.rx_crc_errors++; }if (status &SONIC_RCR_LPKT ) {/*
drivers/net/ethernet/natsemi/sonic.h +1 -0
@@ -175,6 +175,7 @@#define SONIC_TCR_NCRS 0x0100#define SONIC_TCR_CRLS 0x0080#define SONIC_TCR_EXC 0x0040 +#define SONIC_TCR_OWC 0x0020#define SONIC_TCR_PMB 0x0008#define SONIC_TCR_FU 0x0004#define SONIC_TCR_BCM 0x0002
Signature · 1 line
2.24.1
PATCH v2 9/12 net/sonic: Quiesce SONIC before re-initializing descriptor memory
In reply to Finn ThainMake sure the SONIC's DMA engine is idle before altering the transmit and receive descriptors. Add a helper for this as it will be needed again.
--- drivers/net/ethernet/natsemi/sonic.c | 26 ++++++++++++++++++++++++++ drivers/net/ethernet/natsemi/sonic.h | 3 +++ 2 files changed, 29 insertions(+)
drivers/net/ethernet/natsemi/sonic.c +26 -0
@@ -116,6 +116,25 @@ static int sonic_open(struct net_device *dev)return 0 ; } +/* Wait for the SONIC to become idle. */ + +static void sonic_quiesce (struct net_device *dev,u16 mask) +{ +struct sonic_local *__maybe_unused lp =netdev_priv (dev); +int i; +u16 bits; + +for (i =0 ; i <1000 ; ++i) { + bits =SONIC_READ (SONIC_CMD ) & mask; +if (!bits) +return ; +if (irqs_disabled () ||in_interrupt ()) +udelay (20 ); +else +usleep_range (100 ,200 ); + } +WARN_ONCE (1 ,"command deadline expired! 0x%04x\n" , bits); +}/* * Close the SONIC device
@@ -132,6 +151,9 @@ static int sonic_close(struct net_device *dev)/* * stop the SONIC, disable interrupts */ +SONIC_WRITE (SONIC_CMD ,SONIC_CR_RXDIS ); +sonic_quiesce (dev,SONIC_CR_ALL ); +SONIC_WRITE (SONIC_IMR ,0 );SONIC_WRITE (SONIC_ISR ,0x7fff );SONIC_WRITE (SONIC_CMD ,SONIC_CR_RST );
@@ -171,6 +193,9 @@ static void sonic_tx_timeout(struct net_device *dev)* put the Sonic into software-reset mode and * disable all interrupts before releasing DMA buffers */ +SONIC_WRITE (SONIC_CMD ,SONIC_CR_RXDIS ); +sonic_quiesce (dev,SONIC_CR_ALL ); +SONIC_WRITE (SONIC_IMR ,0 );SONIC_WRITE (SONIC_ISR ,0x7fff );SONIC_WRITE (SONIC_CMD ,SONIC_CR_RST );
@@ -657,6 +682,7 @@ static int sonic_init(struct net_device *dev)*/ SONIC_WRITE (SONIC_CMD ,0 );SONIC_WRITE (SONIC_CMD ,SONIC_CR_RXDIS ); +sonic_quiesce (dev,SONIC_CR_ALL );/* * initialize the receive resource area
drivers/net/ethernet/natsemi/sonic.h +3 -0
@@ -110,6 +110,9 @@#define SONIC_CR_TXP 0x0002#define SONIC_CR_HTX 0x0001 +#define SONIC_CR_ALL (SONIC_CR_LCAM | SONIC_CR_RRRA | \ + SONIC_CR_RXEN | SONIC_CR_TXP) +/* * SONIC data configuration bits */
Signature · 1 line
2.24.1
PATCH v2 10/12 net/sonic: Fix command register usage
In reply to Finn ThainThere are several issues relating to command register usage during chip initialization.
Firstly, the SONIC sometimes comes out of software reset with the Start Timer bit set. This gets logged as,
macsonic macsonic eth0: sonic_init: status=24, i=101
Avoid this by giving the Stop Timer command earlier than later.
Secondly, the loop that waits for the Read RRA command to complete has the break condition inverted. That's why the for loop iterates until its termination condition. Call the helper for this instead.
Finally, give the Receiver Enable command after clearing interrupts, not before, to avoid the possibility of losing an interrupt.
--- drivers/net/ethernet/natsemi/sonic.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-)
drivers/net/ethernet/natsemi/sonic.c +3 -15
@@ -664,7 +664,6 @@ static void sonic_multicast_list(struct net_device *dev)*/ static int sonic_init (struct net_device *dev) { -unsigned int cmd;struct sonic_local *lp =netdev_priv (dev);int i;
@@ -681,7 +680,7 @@ static int sonic_init(struct net_device *dev)* enable interrupts, then completely initialize the SONIC */ SONIC_WRITE (SONIC_CMD ,0 ); -SONIC_WRITE (SONIC_CMD ,SONIC_CR_RXDIS ); +SONIC_WRITE (SONIC_CMD ,SONIC_CR_RXDIS |SONIC_CR_STP );sonic_quiesce (dev,SONIC_CR_ALL );/*
@@ -711,14 +710,7 @@ static int sonic_init(struct net_device *dev)netif_dbg (lp, ifup, dev,"%s: issuing RRRA command\n" , __func__);SONIC_WRITE (SONIC_CMD ,SONIC_CR_RRRA ); - i =0 ; -while (i++ <100 ) { -if (SONIC_READ (SONIC_CMD ) &SONIC_CR_RRRA ) -break ; - } - -netif_dbg (lp, ifup, dev,"%s: status=%x, i=%d\n" , __func__, -SONIC_READ (SONIC_CMD ), i); +sonic_quiesce (dev,SONIC_CR_RRRA );/* * Initialize the receive descriptors so that they
@@ -806,15 +798,11 @@ static int sonic_init(struct net_device *dev)* enable receiver, disable loopback * and enable all interrupts */ -SONIC_WRITE (SONIC_CMD ,SONIC_CR_RXEN |SONIC_CR_STP );SONIC_WRITE (SONIC_RCR ,SONIC_RCR_DEFAULT );SONIC_WRITE (SONIC_TCR ,SONIC_TCR_DEFAULT );SONIC_WRITE (SONIC_ISR ,0x7fff );SONIC_WRITE (SONIC_IMR ,SONIC_IMR_DEFAULT ); - - cmd =SONIC_READ (SONIC_CMD ); -if ((cmd &SONIC_CR_RXEN ) ==0 || (cmd &SONIC_CR_STP ) ==0 ) -printk (KERN_ERR "sonic_init: failed, status=%x\n" , cmd); +SONIC_WRITE (SONIC_CMD ,SONIC_CR_RXEN );netif_dbg (lp, ifup, dev,"%s: new status=%x\n" , __func__,SONIC_READ (SONIC_CMD ));
Signature · 1 line
2.24.1
PATCH v2 12/12 net/sonic: Prevent tx watchdog timeout
In reply to Finn ThainSection 5.5.3.2 of the datasheet says,
If FIFO Underrun, Byte Count Mismatch, Excessive Collision, or Excessive Deferral (if enabled) errors occur, transmission ceases.
In this situation, the chip asserts a TXER interrupt rather than TXDN. But the handler for the TXDN is the only way that the transmit queue gets restarted. Hence, an aborted transmission can result in a watchdog timeout.
This problem can be reproduced on congested link, as that can result in excessive transmitter collisions. Another way to reproduce this is with a FIFO Underrun, which may be caused by DMA latency.
In event of a TXER interrupt, prevent a watchdog timeout by restarting transmission.
--- drivers/net/ethernet/natsemi/sonic.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
drivers/net/ethernet/natsemi/sonic.c +13 -4
@@ -411,10 +411,19 @@ static irqreturn_t sonic_interrupt(int irq, void *dev_id) lp->stats.rx_missed_errors +=65536 ;/* transmit error */ -if (status &SONIC_INT_TXER ) -if (SONIC_READ (SONIC_TCR ) &SONIC_TCR_FU ) -netif_dbg (lp, tx_err, dev,"%s: tx fifo underrun\n" , - __func__); +if (status &SONIC_INT_TXER ) { +u16 tcr =SONIC_READ (SONIC_TCR ); + +netif_dbg (lp, tx_err, dev,"%s: TXER intr, TCR %04x\n" , + __func__, tcr); + +if (tcr & (SONIC_TCR_EXD |SONIC_TCR_EXC | +SONIC_TCR_FU |SONIC_TCR_BCM )) { +/* Aborted transmission. Try again. */ +netif_stop_queue (dev); +SONIC_WRITE (SONIC_CMD ,SONIC_CR_TXP ); + } + }/* bus retry */ if (status &SONIC_INT_BR ) {
Signature · 1 line
2.24.1
PATCH v2 2/12 net/sonic: Clear interrupt flags immediately
In reply to Finn ThainThe chip can change a packet's descriptor status flags at any time. However, an active interrupt flag gets cleared rather late. This allows a race condition that could theoretically lose an interrupt. Fix this by clearing asserted interrupt flags immediately.
--- drivers/net/ethernet/natsemi/sonic.c | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-)
drivers/net/ethernet/natsemi/sonic.c +6 -22
@@ -299,10 +299,11 @@ static irqreturn_t sonic_interrupt(int irq, void *dev_id) } do { + SONIC_WRITE(SONIC_ISR, status); /* clear the interrupt(s) */ + if (status & SONIC_INT_PKTRX) { netif_dbg(lp, intr, dev, "%s: packet rx\n", __func__); sonic_rx(dev); /* got packet(s) */ - SONIC_WRITE(SONIC_ISR, SONIC_INT_PKTRX); /* clear the interrupt */ } if (status & SONIC_INT_TXDN) {
@@ -357,7 +358,6 @@ static irqreturn_t sonic_interrupt(int irq, void *dev_id)if (freed_some || lp->tx_skb[entry] ==NULL )netif_wake_queue (dev);/* The ring is no longer full */ lp->cur_tx = entry; -SONIC_WRITE (SONIC_ISR ,SONIC_INT_TXDN );/* clear the interrupt */ }/*
@@ -367,42 +367,31 @@ static irqreturn_t sonic_interrupt(int irq, void *dev_id)netif_dbg (lp, rx_err, dev,"%s: rx fifo overrun\n" , __func__); lp->stats.rx_fifo_errors++; -SONIC_WRITE (SONIC_ISR ,SONIC_INT_RFO );/* clear the interrupt */ }if (status &SONIC_INT_RDE ) {netif_dbg (lp, rx_err, dev,"%s: rx descriptors exhausted\n" , __func__); lp->stats.rx_dropped++; -SONIC_WRITE (SONIC_ISR ,SONIC_INT_RDE );/* clear the interrupt */ }if (status &SONIC_INT_RBAE ) {netif_dbg (lp, rx_err, dev,"%s: rx buffer area exceeded\n" , __func__); lp->stats.rx_dropped++; -SONIC_WRITE (SONIC_ISR ,SONIC_INT_RBAE );/* clear the interrupt */ }/* counter overruns; all counters are 16bit wide */ -if (status &SONIC_INT_FAE ) { +if (status &SONIC_INT_FAE ) lp->stats.rx_frame_errors +=65536 ; -SONIC_WRITE (SONIC_ISR ,SONIC_INT_FAE );/* clear the interrupt */ - } -if (status &SONIC_INT_CRC ) { +if (status &SONIC_INT_CRC ) lp->stats.rx_crc_errors +=65536 ; -SONIC_WRITE (SONIC_ISR ,SONIC_INT_CRC );/* clear the interrupt */ - } -if (status &SONIC_INT_MP ) { +if (status &SONIC_INT_MP ) lp->stats.rx_missed_errors +=65536 ; -SONIC_WRITE (SONIC_ISR ,SONIC_INT_MP );/* clear the interrupt */ - }/* transmit error */ -if (status &SONIC_INT_TXER ) { +if (status &SONIC_INT_TXER )if (SONIC_READ (SONIC_TCR ) &SONIC_TCR_FU )netif_dbg (lp, tx_err, dev,"%s: tx fifo underrun\n" , __func__); -SONIC_WRITE (SONIC_ISR ,SONIC_INT_TXER );/* clear the interrupt */ - }/* bus retry */ if (status &SONIC_INT_BR ) {
@@ -411,13 +400,8 @@ static irqreturn_t sonic_interrupt(int irq, void *dev_id)/* ... to help debug DMA problems causing endless interrupts. */ /* Bounce the eth interface to turn on the interrupt again. */ SONIC_WRITE (SONIC_IMR ,0 ); -SONIC_WRITE (SONIC_ISR ,SONIC_INT_BR );/* clear the interrupt */ } -/* load CAM done */ -if (status &SONIC_INT_LCD ) -SONIC_WRITE (SONIC_ISR ,SONIC_INT_LCD );/* clear the interrupt */ - status =SONIC_READ (SONIC_ISR ) &SONIC_IMR_DEFAULT ; }while (status);
Signature · 1 line
2.24.1
PATCH v2 1/12 net/sonic: Add mutual exclusion for accessing shared state
In reply to Finn ThainThe netif_stop_queue() call in sonic_send_packet() races with the netif_wake_queue() call in sonic_interrupt(). This causes issues like "NETDEV WATCHDOG: eth0 (macsonic): transmit queue 0 timed out". Fix this by disabling interrupts when accessing tx_skb[] and next_tx. Update a comment to clarify the synchronization properties.
---
Changed since v1:
- Added spin lock, as requested by Geert.
--- drivers/net/ethernet/natsemi/sonic.c | 44 +++++++++++++++++++--------- drivers/net/ethernet/natsemi/sonic.h | 1 + 2 files changed, 31 insertions(+), 14 deletions(-)
drivers/net/ethernet/natsemi/sonic.c +30 -14
@@ -64,6 +64,8 @@ static int sonic_open(struct net_device *dev)netif_dbg (lp, ifup, dev,"%s: initializing sonic driver\n" , __func__); +spin_lock_init (&lp->lock); +for (i =0 ; i <SONIC_NUM_RRS ; i++) {struct sk_buff *skb =netdev_alloc_skb (dev,SONIC_RBSIZE +2 );if (skb ==NULL ) {
@@ -206,8 +208,6 @@ static void sonic_tx_timeout(struct net_device *dev)* wake the tx queue * Concurrently with all of this, the SONIC is potentially writing to * the status flags of the TDs. -* Until some mutual exclusion is added, this code will not work with SMP. However, -* MIPS Jazz machines and m68k Macs were all uni-processor machines. */ static int sonic_send_packet (struct sk_buff *skb,struct net_device *dev)
@@ -215,7 +215,8 @@ static int sonic_send_packet(struct sk_buff *skb, struct net_device *dev)struct sonic_local *lp =netdev_priv (dev);dma_addr_t laddr;int length; -int entry = lp->next_tx; +int entry; +unsigned long flags;netif_dbg (lp, tx_queued, dev,"%s: skb=%p\n" , __func__, skb);
@@ -237,6 +238,10 @@ static int sonic_send_packet(struct sk_buff *skb, struct net_device *dev)return NETDEV_TX_OK ; } +spin_lock_irqsave (&lp->lock, flags); + + entry = lp->next_tx; +sonic_tda_put (dev, entry,SONIC_TD_STATUS ,0 );/* clear status */ sonic_tda_put (dev, entry,SONIC_TD_FRAG_COUNT ,1 );/* single fragment */ sonic_tda_put (dev, entry,SONIC_TD_PKTSIZE , length);/* length of packet */
@@ -246,10 +251,6 @@ static int sonic_send_packet(struct sk_buff *skb, struct net_device *dev)sonic_tda_put (dev, entry,SONIC_TD_LINK ,sonic_tda_get (dev, entry,SONIC_TD_LINK ) |SONIC_EOL ); -/* -* Must set tx_skb[entry] only after clearing status, and -* before clearing EOL and before stopping queue -*/ wmb (); lp->tx_len[entry] = length; lp->tx_laddr[entry] = laddr;
@@ -272,6 +273,8 @@ static int sonic_send_packet(struct sk_buff *skb, struct net_device *dev)SONIC_WRITE (SONIC_CMD ,SONIC_CR_TXP ); +spin_unlock_irqrestore (&lp->lock, flags); +return NETDEV_TX_OK ; }
@@ -284,9 +287,16 @@ static irqreturn_t sonic_interrupt(int irq, void *dev_id)struct net_device *dev = dev_id;struct sonic_local *lp =netdev_priv (dev);int status; +unsigned long flags; + +spin_lock_irqsave (&lp->lock, flags); + + status =SONIC_READ (SONIC_ISR ) &SONIC_IMR_DEFAULT ; +if (!status) { +spin_unlock_irqrestore (&lp->lock, flags); -if (!(status =SONIC_READ (SONIC_ISR ) &SONIC_IMR_DEFAULT ))return IRQ_NONE ; + } do { if (status & SONIC_INT_PKTRX) {
@@ -300,11 +310,12 @@ static irqreturn_t sonic_interrupt(int irq, void *dev_id)int td_status;int freed_some =0 ; -/* At this point, cur_tx is the index of a TD that is one of: -* unallocated/freed (status set & tx_skb[entry] clear) -* allocated and sent (status set & tx_skb[entry] set ) -* allocated and not yet sent (status clear & tx_skb[entry] set ) -* still being allocated by sonic_send_packet (status clear & tx_skb[entry] clear) +/* The state of a Transmit Descriptor may be inferred +* from { tx_skb[entry], td_status } as follows. +* { clear, clear } => the TD has never been used +* { set, clear } => the TD was handed to SONIC +* { set, set } => the TD was handed back +* { clear, set } => the TD is available for re-use */ netif_dbg (lp, intr, dev,"%s: tx done\n" , __func__);
@@ -406,7 +417,12 @@ static irqreturn_t sonic_interrupt(int irq, void *dev_id)/* load CAM done */ if (status &SONIC_INT_LCD )SONIC_WRITE (SONIC_ISR ,SONIC_INT_LCD );/* clear the interrupt */ - }while ((status =SONIC_READ (SONIC_ISR ) &SONIC_IMR_DEFAULT )); + + status =SONIC_READ (SONIC_ISR ) &SONIC_IMR_DEFAULT ; + }while (status); + +spin_unlock_irqrestore (&lp->lock, flags); +return IRQ_HANDLED ; }
drivers/net/ethernet/natsemi/sonic.h +1 -0
@@ -322,6 +322,7 @@ struct sonic_local {int msg_enable;struct device *device;/* generic device */ struct net_device_stats stats; +spinlock_t lock; };#define TX_TIMEOUT (3 * HZ)
Signature · 1 line
2.24.1
PATCH v2 6/12 net/sonic: Avoid needless receive descriptor EOL flag updates
In reply to Finn ThainThe while loop in sonic_rx() traverses the rx descriptor ring. It stops when it reaches a descriptor that the SONIC has not used. Each iteration advances the EOL flag so the SONIC can keep using more descriptors. Therefore, the while loop has no definite termination condition.
The algorithm described in the National Semiconductor literature is quite different. It consumes descriptors up to the one with its EOL flag set (which will also have its "in use" flag set). All freed descriptors are then returned to the ring at once, by adjusting the EOL flags (and link pointers).
Adopt the algorithm from datasheet as it's simpler, terminates quickly and avoids a lot of pointless descriptor EOL flag changes.
--- drivers/net/ethernet/natsemi/sonic.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
drivers/net/ethernet/natsemi/sonic.c +15 -6
@@ -432,6 +432,7 @@ static void sonic_rx(struct net_device *dev)struct sonic_local *lp =netdev_priv (dev);int status;int entry = lp->cur_rx; +int prev_entry = lp->eol_rx;while (sonic_rda_get (dev, entry,SONIC_RD_IN_USE ) ==0 ) {struct sk_buff *used_skb;
@@ -512,13 +513,21 @@ static void sonic_rx(struct net_device *dev)/* * give back the descriptor */ -sonic_rda_put (dev, entry,SONIC_RD_LINK , -sonic_rda_get (dev, entry,SONIC_RD_LINK ) |SONIC_EOL );sonic_rda_put (dev, entry,SONIC_RD_IN_USE ,1 ); -sonic_rda_put (dev, lp->eol_rx,SONIC_RD_LINK , -sonic_rda_get (dev, lp->eol_rx,SONIC_RD_LINK ) & ~SONIC_EOL ); - lp->eol_rx = entry; - lp->cur_rx = entry = (entry +1 ) &SONIC_RDS_MASK ; + + prev_entry = entry; + entry = (entry +1 ) &SONIC_RDS_MASK ; + } + + lp->cur_rx = entry; + +if (prev_entry != lp->eol_rx) { +/* Advance the EOL flag to put descriptors back into service */ +sonic_rda_put (dev, prev_entry,SONIC_RD_LINK ,SONIC_EOL | +sonic_rda_get (dev, prev_entry,SONIC_RD_LINK )); +sonic_rda_put (dev, lp->eol_rx,SONIC_RD_LINK , ~SONIC_EOL & +sonic_rda_get (dev, lp->eol_rx,SONIC_RD_LINK )); + lp->eol_rx = prev_entry; }/* * If any worth-while packets have been received, netif_rx()
Signature · 1 line
2.24.1
v2 cover Fixes for SONIC ethernet driver
Hi David,
Various SONIC driver problems have become apparent over the years, including tx watchdog timeouts, lost packets and duplicated packets.
The problems are mostly caused by bugs in buffer handling, locking and (re-)initialization code.
This patch series resolves these problems.
This series has been tested on National Semiconductor hardware (macsonic), qemu-system-m68k (macsonic) and qemu-system-mips64el (jazzsonic).
The emulated dp8393x device used in QEMU also has bugs. I have fixed the bugs that I know of in a series of patches at,
https://github.com/fthain/qemu/commits/sonic
---
Changed since v1:
- Minor revisions as described in commit logs.
- Deferred net-next patches.
Finn Thain (12):
net/sonic: Add mutual exclusion for accessing shared state net/sonic: Clear interrupt flags immediately net/sonic: Use MMIO accessors
net/sonic: Fix interface error stats collection net/sonic: Fix receive buffer handling
net/sonic: Avoid needless receive descriptor EOL flag updates net/sonic: Improve receive descriptor status flag check net/sonic: Fix receive buffer replenishment
net/sonic: Quiesce SONIC before re-initializing descriptor memory net/sonic: Fix command register usage
net/sonic: Fix CAM initialization
net/sonic: Prevent tx watchdog timeout
drivers/net/ethernet/natsemi/sonic.c | 380 ++++++++++++++++----------- drivers/net/ethernet/natsemi/sonic.h | 44 +++- 2 files changed, 262 insertions(+), 162 deletions(-)
Signature · 1 line
2.24.1
PATCH v2 3/12 net/sonic: Use MMIO accessors
The driver accesses descriptor memory which is simultaneously accessed by the chip, so the compiler must not be allowed to re-order CPU accesses. sonic_buf_get() used 'volatile' to prevent that. sonic_buf_put() should have done so too but was overlooked.
--- drivers/net/ethernet/natsemi/sonic.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/net/ethernet/natsemi/sonic.h +8 -8
@@ -345,30 +345,30 @@ static void sonic_msg_init(struct net_device *dev);as far as we can tell. */ /* OpenBSD calls this "SWO". I'd like to think that sonic_buf_put() is a much better name. */ -static inline void sonic_buf_put (void * base,int bitmode, +static inline void sonic_buf_put (u16 *base,int bitmode,int offset,__u16 val) { if (bitmode)#ifdef __BIG_ENDIAN - ((__u16 *) base + (offset*2 ))[1 ] = val; +__raw_writew (val, base + (offset *2 ) +1 );#else - ((__u16 *) base + (offset*2 ))[0 ] = val; +__raw_writew (val, base + (offset *2 ) +0 );#endif else - ((__u16 *) base)[offset] = val; + __raw_writew(val, base + (offset * 1) + 0); } -static inline __u16 sonic_buf_get (void * base,int bitmode, +static inline __u16 sonic_buf_get (u16 *base,int bitmode,int offset) { if (bitmode)#ifdef __BIG_ENDIAN -return ((volatile __u16 *) base + (offset*2 ))[1 ]; +return __raw_readw (base + (offset *2 ) +1 );#else -return ((volatile __u16 *) base + (offset*2 ))[0 ]; +return __raw_readw (base + (offset *2 ) +0 );#endif else - return ((volatile __u16 *) base)[offset]; + return __raw_readw(base + (offset * 1) + 0); }/* Inlines that you should actually use for reading/writing DMA buffers */
Signature · 1 line
2.24.1
Re: [PATCH net v2 01/12] net/sonic: Add mutual exclusion for accessing shared state
In reply to Finn ThainQuoted 11 lines · Finn Thain
The
netif_stop_queue()call insonic_send_packet()races with thenetif_wake_queue()call insonic_interrupt(). This causes issues like "NETDEV WATCHDOG: eth0 (macsonic): transmit queue 0 timed out". Fix this by disabling interrupts when accessing tx_skb[] andnext_tx. Update a comment to clarify the synchronization properties.Fixes efcce839360f ("[PATCH] macsonic/jazzsonic network drivers update")Tested-by Stan Johnson <[email protected]>Signed-off-by Finn Thain <[email protected]>
drivers/net/ethernet/natsemi/sonic.c static irqreturn_t sonic_interrupt(int irq, void *dev_id) · line 292
Quoted 6 lines
drivers/net/ethernet/natsemi/sonic.c +3
-0@@ -284,9 +287,16 @@ static irqreturn_t sonic_interrupt(int irq, void *dev_id)struct net_device *dev = dev_id;struct sonic_local *lp =netdev_priv (dev);int status; +unsigned long flags; + +spin_lock_irqsave (&lp->lock, flags);
This is a hard irq handler, no need to block hard irqs.
spin_lock() here is enough.
Quoted 41 lines
drivers/net/ethernet/natsemi/sonic.c +17
-7+ + status =SONIC_READ (SONIC_ISR ) &SONIC_IMR_DEFAULT ; +if (!status) { +spin_unlock_irqrestore (&lp->lock, flags); -if (!(status =SONIC_READ (SONIC_ISR ) &SONIC_IMR_DEFAULT ))return IRQ_NONE ; + } do { if (status & SONIC_INT_PKTRX) {@@ -300,11 +310,12 @@ static irqreturn_t sonic_interrupt(int irq, void *dev_id)int td_status;int freed_some =0 ; -/* At this point, cur_tx is the index of a TD that is one of: -* unallocated/freed (status set & tx_skb[entry] clear) -* allocated and sent (status set & tx_skb[entry] set ) -* allocated and not yet sent (status clear & tx_skb[entry] set ) -* still being allocated by sonic_send_packet (status clear & tx_skb[entry] clear) +/* The state of a Transmit Descriptor may be inferred +* from { tx_skb[entry], td_status } as follows. +* { clear, clear } => the TD has never been used +* { set, clear } => the TD was handed to SONIC +* { set, set } => the TD was handed back +* { clear, set } => the TD is available for re-use */ netif_dbg (lp, intr, dev,"%s: tx done\n" , __func__);@@ -406,7 +417,12 @@ static irqreturn_t sonic_interrupt(int irq, void *dev_id)/* load CAM done */ if (status &SONIC_INT_LCD )SONIC_WRITE (SONIC_ISR ,SONIC_INT_LCD );/* clear the interrupt */ - }while ((status =SONIC_READ (SONIC_ISR ) &SONIC_IMR_DEFAULT )); + + status =SONIC_READ (SONIC_ISR ) &SONIC_IMR_DEFAULT ; + }while (status); + +spin_unlock_irqrestore (&lp->lock, flags); +return IRQ_HANDLED ;
Re: [PATCH net v2 05/12] net/sonic: Fix receive buffer handling
In reply to Finn Thaindrivers/net/ethernet/natsemi/sonic.c static irqreturn_t sonic_interrupt(int irq, void *dev_id) · line 414
Quoted 5 lines · On Wed, 22 Jan 2020 08:22:08 +1100 Finn Thain <[email protected]>…
drivers/net/ethernet/natsemi/sonic.c +4
-0+/* Return the array index corresponding to a given Receive Buffer pointer. */ + +static inline int index_from_addr (struct sonic_local *lp,dma_addr_t addr, +unsigned int last)
Why the blank line between comment and the start of the function?
Also, the kernel standard is not to use the inline keyword on functions and let the compiler decide to inline if it wants to. The compiler is much smarter at knowing the architectural limitations than humans are.
Re: [PATCH net v2 01/12] net/sonic: Add mutual exclusion for accessing shared state
In reply to Eric DumazetQuoted 22 lines · Eric Dumazet
Quoted 11 lines · Finn Thain
The
netif_stop_queue()call insonic_send_packet()races with thenetif_wake_queue()call insonic_interrupt(). This causes issues like "NETDEV WATCHDOG: eth0 (macsonic): transmit queue 0 timed out". Fix this by disabling interrupts when accessing tx_skb[] andnext_tx. Update a comment to clarify the synchronization properties.Fixes efcce839360f ("[PATCH] macsonic/jazzsonic network drivers update")Tested-by Stan Johnson <[email protected]>Signed-off-by Finn Thain <[email protected]>drivers/net/ethernet/natsemi/sonic.c static irqreturn_t sonic_interrupt(int irq, void *dev_id) · line 292
Quoted 6 lines
drivers/net/ethernet/natsemi/sonic.c +3
-0@@ -284,9 +287,16 @@ static irqreturn_t sonic_interrupt(int irq, void *dev_id)struct net_device *dev = dev_id;struct sonic_local *lp =netdev_priv (dev);int status; +unsigned long flags; + +spin_lock_irqsave (&lp->lock, flags);This is a hard irq handler, no need to block hard irqs.
Quoted 2 lines
spin_lock()here is enough.
Well, yes, assuming we're dealing with SMP [1]. Probably just disabling pre-emption is all that will ever be needed.
Anyway, the real problem solved by disabling irqs is that macsonic must avoid re-entrance of sonic_interrupt(). [2]
[1]
https://lore.kernel.org/netdev/[email protected]/T/#m0523c8b2a26a410ed56889d9230c37ba1160d40a
[2]
https://lore.kernel.org/netdev/[email protected]/T/#m1c8ca580d2b45e61a628d17839978d0bd5aaf061
Re: [PATCH net v2 01/12] net/sonic: Add mutual exclusion for accessing shared state
Quoted 30 lines · Finn Thain
Quoted 22 lines · Eric Dumazet
Quoted 11 lines · Finn Thain
The
netif_stop_queue()call insonic_send_packet()races with thenetif_wake_queue()call insonic_interrupt(). This causes issues like "NETDEV WATCHDOG: eth0 (macsonic): transmit queue 0 timed out". Fix this by disabling interrupts when accessing tx_skb[] andnext_tx. Update a comment to clarify the synchronization properties.Fixes efcce839360f ("[PATCH] macsonic/jazzsonic network drivers update")Tested-by Stan Johnson <[email protected]>Signed-off-by Finn Thain <[email protected]>drivers/net/ethernet/natsemi/sonic.c static irqreturn_t sonic_interrupt(int irq, void *dev_id) · line 292
Quoted 6 lines
drivers/net/ethernet/natsemi/sonic.c +3
-0@@ -284,9 +287,16 @@ static irqreturn_t sonic_interrupt(int irq, void *dev_id)struct net_device *dev = dev_id;struct sonic_local *lp =netdev_priv (dev);int status; +unsigned long flags; + +spin_lock_irqsave (&lp->lock, flags);This is a hard irq handler, no need to block hard irqs.
Quoted 2 lines
spin_lock()here is enough.Well, yes, assuming we're dealing with SMP [1]. Probably just disabling pre-emption is all that will ever be needed.
Quoted 9 lines
Anyway, the real problem solved by disabling irqs is that macsonic must avoid re-entrance of
sonic_interrupt(). [2][1]
https://lore.kernel.org/netdev/[email protected]/T/#m0523c8b2a26a410ed56889d9230c37ba1160d40a[2]
https://lore.kernel.org/netdev/[email protected]/T/#m1c8ca580d2b45e61a628d17839978d0bd5aaf061
Oh well...
I would rather keep the m68k specific wrapper...
Please add a fat comment of why spin_lock_irqsave() is used, to avoid a future 'cleanup', since average network developer wont be aware of m68k oddities.
Re: [PATCH net v2 05/12] net/sonic: Fix receive buffer handling
In reply to Stephen HemmingerQuoted 11 lines · Stephen Hemminger
drivers/net/ethernet/natsemi/sonic.c static irqreturn_t sonic_interrupt(int irq, void *dev_id) · line 414
Quoted 5 lines · On Wed, 22 Jan 2020 08:22:08 +1100 Finn Thain <[email protected]>…
drivers/net/ethernet/natsemi/sonic.c +4
-0+/* Return the array index corresponding to a given Receive Buffer pointer. */ + +static inline int index_from_addr (struct sonic_local *lp,dma_addr_t addr, +unsigned int last)Why the blank line between comment and the start of the function?
The driver mostly uses this style:
/*
* We have a good packet(s), pass it/them up the network stack. */
static void sonic_rx(struct net_device *dev)
{
}
To my eyes, style I used is the closest readable approximation of the existing style that doesn't upset checkpatch.
Anyway, I will remove the blank lines.
Quoted 2 lines
Also, the kernel standard is not to use the inline keyword on functions and let the compiler decide to inline if it wants to.
OK.
Thanks for your review.
Re: [PATCH net v2 01/12] net/sonic: Add mutual exclusion for accessing shared state
In reply to Eric DumazetQuoted 34 lines · Eric Dumazet
Quoted 33 lines · Finn Thain
Quoted 22 lines · Eric Dumazet
Quoted 11 lines · Finn Thain
The
netif_stop_queue()call insonic_send_packet()races with thenetif_wake_queue()call insonic_interrupt(). This causes issues like "NETDEV WATCHDOG: eth0 (macsonic): transmit queue 0 timed out". Fix this by disabling interrupts when accessing tx_skb[] andnext_tx. Update a comment to clarify the synchronization properties.Fixes efcce839360f ("[PATCH] macsonic/jazzsonic network drivers update")Tested-by Stan Johnson <[email protected]>Signed-off-by Finn Thain <[email protected]>drivers/net/ethernet/natsemi/sonic.c static irqreturn_t sonic_interrupt(int irq, void *dev_id) · line 292
Quoted 6 lines
drivers/net/ethernet/natsemi/sonic.c +3
-0@@ -284,9 +287,16 @@ static irqreturn_t sonic_interrupt(int irq, void *dev_id)struct net_device *dev = dev_id;struct sonic_local *lp =netdev_priv (dev);int status; +unsigned long flags; + +spin_lock_irqsave (&lp->lock, flags);This is a hard irq handler, no need to block hard irqs.
Quoted 2 lines
spin_lock()here is enough.Well, yes, assuming we're dealing with SMP [1]. Probably just disabling pre-emption is all that will ever be needed.
Anyway, the real problem solved by disabling irqs is that macsonic must avoid re-entrance of
sonic_interrupt(). [2]
Quoted 7 lines
I was overlooking the fact that sonic_send_packet() really does have to exclude sonic_interrupt(). So disabling irqs is mandatory here, right?
Quoted 4 lines
Oh well...
I would rather keep the m68k specific wrapper...
If disabling irqs is unavoidable, the wrapper is redundant.
Quoted 4 lines
Please add a fat comment of why
spin_lock_irqsave()is used, to avoid a future 'cleanup', since average network developer wont be aware of m68k oddities.
OK.