Improvements for SONIC ethernet drivers
Subsystems (3)
PATCH 3/7 net/sonic: Remove redundant next_tx variable
In reply to Finn ThainThe eol_tx variable is the one that matters to the tx algorithm because packets are always placed at the end of the list. The next_tx variable just confuses things so remove it.
--- drivers/net/ethernet/natsemi/sonic.c | 8 ++++---- drivers/net/ethernet/natsemi/sonic.h | 1 - 2 files changed, 4 insertions(+), 5 deletions(-)
drivers/net/ethernet/natsemi/sonic.c +4 -4
@@ -300,7 +300,7 @@ static int sonic_send_packet(struct sk_buff *skb, struct net_device *dev)spin_lock_irqsave (&lp->lock, flags); - entry = lp->next_tx; + entry = (lp->eol_tx +1 ) &SONIC_TDS_MASK ;sonic_tda_put (dev, entry,SONIC_TD_STATUS ,0 );/* clear status */ sonic_tda_put (dev, entry,SONIC_TD_FRAG_COUNT ,1 );/* single fragment */
@@ -321,8 +321,8 @@ static int sonic_send_packet(struct sk_buff *skb, struct net_device *dev) sonic_tda_get(dev, lp->eol_tx, SONIC_TD_LINK) & ~SONIC_EOL); lp->eol_tx = entry; - lp->next_tx = (entry +1 ) &SONIC_TDS_MASK ; -if (lp->tx_skb[lp->next_tx] !=NULL ) { + entry = (entry +1 ) &SONIC_TDS_MASK ; +if (lp->tx_skb[entry]) {/* The ring is full, the ISR has yet to process the next TD. */ netif_dbg (lp, tx_queued, dev,"%s: stopping queue\n" , __func__);netif_stop_queue (dev);
@@ -811,7 +811,7 @@ static int sonic_init(struct net_device *dev)SONIC_WRITE (SONIC_UTDA , lp->tda_laddr >>16 );SONIC_WRITE (SONIC_CTDA , lp->tda_laddr &0xffff ); - lp->cur_tx = lp->next_tx =0 ; + lp->cur_tx =0 ; lp->eol_tx =SONIC_NUM_TDS -1 ;/*
drivers/net/ethernet/natsemi/sonic.h +0 -1
@@ -321,7 +321,6 @@ struct sonic_local {unsigned int cur_tx;/* first unacked transmit packet */ unsigned int eol_rx;unsigned int eol_tx;/* last unacked transmit packet */ -unsigned int next_tx;/* next free TD */ int msg_enable;struct device *device;/* generic device */ struct net_device_stats stats;
Signature · 1 line
2.24.1
PATCH 5/7 net/sonic: Remove explicit memory barriers
In reply to Finn ThainThe explicit memory barriers are redundant now that proper locking and MMIO accessors have been employed.
--- drivers/net/ethernet/natsemi/sonic.c | 2 -- 1 file changed, 2 deletions(-)
drivers/net/ethernet/natsemi/sonic.c +0 -2
@@ -311,12 +311,10 @@ 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 ); -wmb (); lp->tx_len[entry] = length; lp->tx_laddr[entry] = laddr; lp->tx_skb[entry] = skb; -wmb ();sonic_tda_put (dev, lp->eol_tx,SONIC_TD_LINK ,sonic_tda_get (dev, lp->eol_tx,SONIC_TD_LINK ) & ~SONIC_EOL ); lp->eol_tx = entry;
Signature · 1 line
2.24.1
PATCH 6/7 net/sonic: Start packet transmission immediately
In reply to Finn ThainGive the transmit command as soon as the transmit descriptor is ready.
--- drivers/net/ethernet/natsemi/sonic.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/net/ethernet/natsemi/sonic.c +7 -6
@@ -311,12 +311,17 @@ 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 ); +sonic_tda_put (dev, lp->eol_tx,SONIC_TD_LINK , ~SONIC_EOL & +sonic_tda_get (dev, lp->eol_tx,SONIC_TD_LINK )); + +netif_dbg (lp, tx_queued, dev,"%s: issuing Tx command\n" , __func__); + +SONIC_WRITE (SONIC_CMD ,SONIC_CR_TXP ); + lp->tx_len[entry] = length; lp->tx_laddr[entry] = laddr; lp->tx_skb[entry] = skb; -sonic_tda_put (dev, lp->eol_tx,SONIC_TD_LINK , -sonic_tda_get (dev, lp->eol_tx,SONIC_TD_LINK ) & ~SONIC_EOL ); lp->eol_tx = entry; entry = (entry +1 ) &SONIC_TDS_MASK ;
@@ -327,10 +332,6 @@ static int sonic_send_packet(struct sk_buff *skb, struct net_device *dev)/* after this packet, wait for ISR to free up some TDAs */ } -netif_dbg (lp, tx_queued, dev,"%s: issuing Tx command\n" , __func__); - -SONIC_WRITE (SONIC_CMD ,SONIC_CR_TXP ); -spin_unlock_irqrestore (&lp->lock, flags);return NETDEV_TX_OK ;
Signature · 1 line
2.24.1
PATCH 7/7 net/macsonic: Remove interrupt handler wrapper
In reply to Finn ThainOn m68k, local irqs remain enabled while interrupt handlers execute. Therefore the macsonic driver has had to disable interrupts to avoid re-entering sonic_interrupt().
As of commit 865ad2f2201d ("net/sonic: Add mutual exclusion for accessing shared state"), sonic_interrupt() became re-entrant, and its wrapper became redundant.
--- drivers/net/ethernet/natsemi/macsonic.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-)
drivers/net/ethernet/natsemi/macsonic.c +4 -15
@@ -114,17 +114,6 @@ static inline void bit_reverse_addr(unsigned char addr[6]) addr[i] =bitrev8 (addr[i]); } -static irqreturn_t macsonic_interrupt (int irq,void *dev_id) -{ -irqreturn_t result; -unsigned long flags; - -local_irq_save (flags); - result =sonic_interrupt (irq, dev_id); -local_irq_restore (flags); -return result; -} -static int macsonic_open (struct net_device * dev) {int retval;
@@ -135,12 +124,12 @@ static int macsonic_open(struct net_device* dev) dev->name, dev->irq); goto err; } -/* Under the A/UX interrupt scheme, the onboard SONIC interrupt comes -* in at priority level 3. However, we sometimes get the level 2 inter- -* rupt as well, which must prevent re-entrance of the sonic handler. +/* Under the A/UX interrupt scheme, the onboard SONIC interrupt gets +* moved from level 2 to level 3. Unfortunately we still get some +* level 2 interrupts so register the handler for both. */ if (dev->irq ==IRQ_AUTO_3 ) { - retval =request_irq (IRQ_NUBUS_9 , macsonic_interrupt,0 , + retval =request_irq (IRQ_NUBUS_9 , sonic_interrupt,0 ,"sonic" , dev);if (retval) { printk(KERN_ERR "%s: unable to get IRQ %d.\n",
Signature · 1 line
2.24.1
cover Improvements for SONIC ethernet drivers
Hi David,
Now that the necessary sonic driver fixes have been merged, and the merge window has closed again, I'm sending the remainder of my sonic driver patch queue.
A couple of these patches will have to be applied in sequence to avoid 'git am' rejects. The others are independent and could have been submitted individually. Please let me know if I should do that.
The complete sonic driver patch queue was tested on National Semiconductor hardware (macsonic), qemu-system-m68k (macsonic) and qemu-system-mips64el (jazzsonic).
Finn Thain (7):
net/sonic: Remove obsolete comment net/sonic: Refactor duplicated code net/sonic: Remove redundant next_tx variable net/sonic: Remove redundant netif_start_queue() call net/sonic: Remove explicit memory barriers net/sonic: Start packet transmission immediately net/macsonic: Remove interrupt handler wrapper
drivers/net/ethernet/natsemi/jazzsonic.c | 31 +---------- drivers/net/ethernet/natsemi/macsonic.c | 48 +++-------------- drivers/net/ethernet/natsemi/sonic.c | 66 +++++++++++++++++------- drivers/net/ethernet/natsemi/sonic.h | 2 +- drivers/net/ethernet/natsemi/xtsonic.c | 40 +------------- 5 files changed, 60 insertions(+), 127 deletions(-)
Signature · 1 line
2.24.1
PATCH 1/7 net/sonic: Remove obsolete comment
The comment is meaningless since mark_bh() was removed a long time ago.
--- drivers/net/ethernet/natsemi/sonic.c | 5 ----- 1 file changed, 5 deletions(-)
drivers/net/ethernet/natsemi/sonic.c +0 -5
@@ -594,11 +594,6 @@ static void sonic_rx(struct net_device *dev)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 -* when we get to the bottom-half routine. -*/ }
Signature · 1 line
2.24.1
PATCH 2/7 net/sonic: Refactor duplicated code
In reply to Finn ThainNo functional change.
--- drivers/net/ethernet/natsemi/jazzsonic.c | 31 ++---------------- drivers/net/ethernet/natsemi/macsonic.c | 29 ++--------------- drivers/net/ethernet/natsemi/sonic.c | 36 +++++++++++++++++++++ drivers/net/ethernet/natsemi/sonic.h | 1 + drivers/net/ethernet/natsemi/xtsonic.c | 40 ++---------------------- 5 files changed, 44 insertions(+), 93 deletions(-)
drivers/net/ethernet/natsemi/jazzsonic.c +2 -29
@@ -147,39 +147,12 @@ static int sonic_probe1(struct net_device *dev) dev->dev_addr[i*2 +1 ] = val >>8 ; } - err = -ENOMEM ; - -/* Initialize the device structure. */ - lp->dma_bitmode =SONIC_BITMODE32 ; -/* Allocate the entire chunk of memory for the descriptors. -Note that this cannot cross a 64K boundary. */ - lp->descriptors =dma_alloc_coherent (lp->device, -SIZEOF_SONIC_DESC * -SONIC_BUS_SCALE (lp->dma_bitmode), - &lp->descriptors_laddr, -GFP_KERNEL ); -if (lp->descriptors ==NULL ) + err =sonic_alloc_descriptors (dev); +if (err) goto out; -/* Now set up the pointers to point to the appropriate places */ - lp->cda = lp->descriptors; - lp->tda = lp->cda + (SIZEOF_SONIC_CDA - *SONIC_BUS_SCALE (lp->dma_bitmode)); - lp->rda = lp->tda + (SIZEOF_SONIC_TD *SONIC_NUM_TDS - *SONIC_BUS_SCALE (lp->dma_bitmode)); - lp->rra = lp->rda + (SIZEOF_SONIC_RD *SONIC_NUM_RDS - *SONIC_BUS_SCALE (lp->dma_bitmode)); - - lp->cda_laddr = lp->descriptors_laddr; - lp->tda_laddr = lp->cda_laddr + (SIZEOF_SONIC_CDA - *SONIC_BUS_SCALE (lp->dma_bitmode)); - lp->rda_laddr = lp->tda_laddr + (SIZEOF_SONIC_TD *SONIC_NUM_TDS - *SONIC_BUS_SCALE (lp->dma_bitmode)); - lp->rra_laddr = lp->rda_laddr + (SIZEOF_SONIC_RD *SONIC_NUM_RDS - *SONIC_BUS_SCALE (lp->dma_bitmode)); - dev->netdev_ops = &sonic_netdev_ops; dev->watchdog_timeo =TX_TIMEOUT ;
drivers/net/ethernet/natsemi/macsonic.c +3 -26
@@ -186,33 +186,10 @@ static const struct net_device_ops macsonic_netdev_ops = {static int macsonic_init (struct net_device *dev) {struct sonic_local * lp =netdev_priv (dev); +int err =sonic_alloc_descriptors (dev); -/* Allocate the entire chunk of memory for the descriptors. -Note that this cannot cross a 64K boundary. */ - lp->descriptors =dma_alloc_coherent (lp->device, -SIZEOF_SONIC_DESC * -SONIC_BUS_SCALE (lp->dma_bitmode), - &lp->descriptors_laddr, -GFP_KERNEL ); -if (lp->descriptors ==NULL ) -return -ENOMEM ; - -/* Now set up the pointers to point to the appropriate places */ - lp->cda = lp->descriptors; - lp->tda = lp->cda + (SIZEOF_SONIC_CDA - *SONIC_BUS_SCALE (lp->dma_bitmode)); - lp->rda = lp->tda + (SIZEOF_SONIC_TD *SONIC_NUM_TDS - *SONIC_BUS_SCALE (lp->dma_bitmode)); - lp->rra = lp->rda + (SIZEOF_SONIC_RD *SONIC_NUM_RDS - *SONIC_BUS_SCALE (lp->dma_bitmode)); - - lp->cda_laddr = lp->descriptors_laddr; - lp->tda_laddr = lp->cda_laddr + (SIZEOF_SONIC_CDA - *SONIC_BUS_SCALE (lp->dma_bitmode)); - lp->rda_laddr = lp->tda_laddr + (SIZEOF_SONIC_TD *SONIC_NUM_TDS - *SONIC_BUS_SCALE (lp->dma_bitmode)); - lp->rra_laddr = lp->rda_laddr + (SIZEOF_SONIC_RD *SONIC_NUM_RDS - *SONIC_BUS_SCALE (lp->dma_bitmode)); +if (err) +return err; dev->netdev_ops = &macsonic_netdev_ops; dev->watchdog_timeo =TX_TIMEOUT ;
drivers/net/ethernet/natsemi/sonic.c +36 -0
@@ -50,6 +50,42 @@ static void sonic_msg_init(struct net_device *dev)netif_dbg (lp, drv, dev,"%s" , version); } +static int sonic_alloc_descriptors (struct net_device *dev) +{ +struct sonic_local *lp =netdev_priv (dev); + +/* Allocate a chunk of memory for the descriptors. Note that this +* must not cross a 64K boundary. It is smaller than one page which +* means that page alignment is a sufficient condition. +*/ + lp->descriptors = +dma_alloc_coherent (lp->device, +SIZEOF_SONIC_DESC * +SONIC_BUS_SCALE (lp->dma_bitmode), + &lp->descriptors_laddr,GFP_KERNEL ); + +if (!lp->descriptors) +return -ENOMEM ; + + lp->cda = lp->descriptors; + lp->tda = lp->cda +SIZEOF_SONIC_CDA * +SONIC_BUS_SCALE (lp->dma_bitmode); + lp->rda = lp->tda +SIZEOF_SONIC_TD *SONIC_NUM_TDS * +SONIC_BUS_SCALE (lp->dma_bitmode); + lp->rra = lp->rda +SIZEOF_SONIC_RD *SONIC_NUM_RDS * +SONIC_BUS_SCALE (lp->dma_bitmode); + + lp->cda_laddr = lp->descriptors_laddr; + lp->tda_laddr = lp->cda_laddr +SIZEOF_SONIC_CDA * +SONIC_BUS_SCALE (lp->dma_bitmode); + lp->rda_laddr = lp->tda_laddr +SIZEOF_SONIC_TD *SONIC_NUM_TDS * +SONIC_BUS_SCALE (lp->dma_bitmode); + lp->rra_laddr = lp->rda_laddr +SIZEOF_SONIC_RD *SONIC_NUM_RDS * +SONIC_BUS_SCALE (lp->dma_bitmode); + +return 0 ; +} +/* * Open/initialize the SONIC controller. *
drivers/net/ethernet/natsemi/sonic.h +1 -0
@@ -342,6 +342,7 @@ static void sonic_multicast_list(struct net_device *dev);static int sonic_init (struct net_device *dev);static void sonic_tx_timeout (struct net_device *dev,unsigned int txqueue);static void sonic_msg_init (struct net_device *dev); +static int sonic_alloc_descriptors (struct net_device *dev);/* Internal inlines for reading/writing DMA buffers. Note that bus size and endianness matter here, whereas they don't for registers,
drivers/net/ethernet/natsemi/xtsonic.c +2 -38
@@ -167,47 +167,11 @@ static int __init sonic_probe1(struct net_device *dev) dev->dev_addr[i*2 +1 ] = val >>8 ; } -/* Initialize the device structure. */ - lp->dma_bitmode =SONIC_BITMODE32 ; -/* -* Allocate local private descriptor areas in uncached space. -* The entire structure must be located within the same 64kb segment. -* A simple way to ensure this is to allocate twice the -* size of the structure -- given that the structure is -* much less than 64 kB, at least one of the halves of -* the allocated area will be contained entirely in 64 kB. -* We also allocate extra space for a pointer to allow freeing -* this structure later on (in xtsonic_cleanup_module()). -*/ - lp->descriptors =dma_alloc_coherent (lp->device, -SIZEOF_SONIC_DESC * -SONIC_BUS_SCALE (lp->dma_bitmode), - &lp->descriptors_laddr, -GFP_KERNEL ); -if (lp->descriptors ==NULL ) { - err = -ENOMEM ; + err =sonic_alloc_descriptors (dev); +if (err) goto out; - } - - lp->cda = lp->descriptors; - lp->tda = lp->cda + (SIZEOF_SONIC_CDA - *SONIC_BUS_SCALE (lp->dma_bitmode)); - lp->rda = lp->tda + (SIZEOF_SONIC_TD *SONIC_NUM_TDS - *SONIC_BUS_SCALE (lp->dma_bitmode)); - lp->rra = lp->rda + (SIZEOF_SONIC_RD *SONIC_NUM_RDS - *SONIC_BUS_SCALE (lp->dma_bitmode)); - -/* get the virtual dma address */ - - lp->cda_laddr = lp->descriptors_laddr; - lp->tda_laddr = lp->cda_laddr + (SIZEOF_SONIC_CDA - *SONIC_BUS_SCALE (lp->dma_bitmode)); - lp->rda_laddr = lp->tda_laddr + (SIZEOF_SONIC_TD *SONIC_NUM_TDS - *SONIC_BUS_SCALE (lp->dma_bitmode)); - lp->rra_laddr = lp->rda_laddr + (SIZEOF_SONIC_RD *SONIC_NUM_RDS - *SONIC_BUS_SCALE (lp->dma_bitmode)); dev->netdev_ops = &xtsonic_netdev_ops; dev->watchdog_timeo =TX_TIMEOUT ;
Signature · 1 line
2.24.1
PATCH 4/7 net/sonic: Remove redundant netif_start_queue() call
In reply to Finn ThainThe transmit queue must be running already otherwise sonic_send_packet() would not have been called. If the queue was stopped by the interrupt handler, the interrupt handler will restart it again.
--- drivers/net/ethernet/natsemi/sonic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/natsemi/sonic.c +1 -1
@@ -327,7 +327,7 @@ static int sonic_send_packet(struct sk_buff *skb, struct net_device *dev)netif_dbg (lp, tx_queued, dev,"%s: stopping queue\n" , __func__);netif_stop_queue (dev);/* after this packet, wait for ISR to free up some TDAs */ - }else netif_start_queue (dev); + }netif_dbg (lp, tx_queued, dev,"%s: issuing Tx command\n" , __func__);
Signature · 1 line
2.24.1
David Miller
maintainerFrom: Finn Thain <[email protected]>
Date: Sun, 16 Feb 2020 08:03:32 +1100
Quoted 11 lines
Now that the necessary sonic driver fixes have been merged, and the merge window has closed again, I'm sending the remainder of my sonic driver patch queue.
A couple of these patches will have to be applied in sequence to avoid 'git am' rejects. The others are independent and could have been submitted individually. Please let me know if I should do that.
The complete sonic driver patch queue was tested on National Semiconductor hardware (macsonic), qemu-system-m68k (macsonic) and qemu-system-mips64el (jazzsonic).
Series applied, thanks.