8139cp: properly support change of MTU values [v2]
Subsystems (2)
PATCH 1/1 8139cp: properly support change of MTU values [v2]
The 8139cp driver has a change_mtu function that has not been enabled since the dawn of the git repository. However, the generic eth_change_mtu is not used in its place, so that invalid MTU values can be set on the interface.
Original patch salvages the broken code for the single case of setting the MTU while the interface is down, which is safe and also includes the range check. Now enhanced to support up or down interface.
v2: fix case where rxbufsz isn't changed in the up state case
Original patch from
http://lkml.indiana.edu/hypermail/linux/kernel/1202.2/00770.html
Testing: has been test on virtual 8139cp setup without issue, have no access real hardware 8139cp, need testing help.
--- drivers/net/ethernet/realtek/8139cp.c | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-)
drivers/net/ethernet/realtek/8139cp.c +4 -19
@@ -1226,12 +1226,9 @@ static void cp_tx_timeout(struct net_device *dev)spin_unlock_irqrestore (&cp->lock, flags); } -#ifdef BROKEN static int cp_change_mtu (struct net_device *dev,int new_mtu) {struct cp_private *cp =netdev_priv (dev); -int rc; -unsigned long flags;/* check for invalid MTU, according to hardware limits */ if (new_mtu <CP_MIN_MTU || new_mtu >CP_MAX_MTU )
@@ -1244,22 +1241,12 @@ static int cp_change_mtu(struct net_device *dev, int new_mtu)return 0 ; } -spin_lock_irqsave (&cp->lock, flags); - -cp_stop_hw (cp);/* stop h/w and free rings */ -cp_clean_rings (cp); - +/* network IS up, close it, reset MTU, and come up again. */ +cp_close (dev); dev->mtu = new_mtu; -cp_set_rxbufsize (cp);/* set new rx buf size */ - - rc =cp_init_rings (cp);/* realloc and restart h/w */ -cp_start_hw (cp); - -spin_unlock_irqrestore (&cp->lock, flags); - -return rc; +cp_set_rxbufsize (cp); +return cp_open (dev); } -#endif /* BROKEN */ static const char mii_2_8139_map[8 ] = { BasicModeCtrl,
@@ -1835,9 +1822,7 @@ static const struct net_device_ops cp_netdev_ops = { .ndo_start_xmit = cp_start_xmit, .ndo_tx_timeout = cp_tx_timeout, .ndo_set_features = cp_set_features, -#ifdef BROKEN .ndo_change_mtu = cp_change_mtu, -#endif #ifdef CONFIG_NET_POLL_CONTROLLER .ndo_poll_controller = cp_poll_controller,
Signature · 1 line
1.7.11.7
David Miller
maintainerFrom: John Greene <[email protected]>
Date: Mon, 3 Dec 2012 11:19:33 -0500
Quoted 12 lines
The 8139cp driver has a
change_mtufunction that has not been enabled since the dawn of the git repository. However, the genericeth_change_mtuis not used in its place, so that invalid MTU values can be set on the interface.Original patch salvages the broken code for the single case of setting the MTU while the interface is down, which is safe and also includes the range check. Now enhanced to support up or down interface.
v2: fix case where rxbufsz isn't changed in the up state case
Quoted 7 lines
Original patch from
http://lkml.indiana.edu/hypermail/linux/kernel/1202.2/00770.htmlTesting: has been test on virtual 8139cp setup without issue, have no access real hardware 8139cp, need testing help.
Signed-off-by "John Greene" <[email protected]>
I've applied this to net-next, if it triggers any problems we have some time to work it out before 3.8 is released.
David Miller <[email protected]> :
[...]
Quoted 2 lines
I've applied this to net-next, if it triggers any problems we have some time to work it out before 3.8 is released.
I have bounced the messages to David Woodhouse since he authored the last 8139cp changes in net-next and owns the hardware to notice regressions.
My message of two days ago was wrong : it is not possible for the irq handler to process a Tx event after the rings have been freed. Things still look racy wrt netpoll though.
Any objection against the patch below ?
(I did not gotoize the dev == NULL test: it is really unlikely and should go away).
drivers/net/ethernet/realtek/8139cp.c +11 -8
@@ -577,28 +577,30 @@ static irqreturn_t cp_interrupt (int irq, void *dev_instance) {struct net_device *dev = dev_instance;struct cp_private *cp; +int handled =0 ;u16 status;if (unlikely (dev ==NULL ))return IRQ_NONE ; cp =netdev_priv (dev); +spin_lock (&cp->lock); + status =cpr16 (IntrStatus);if (!status || (status ==0xFFFF )) -return IRQ_NONE ; + goto out_unlock; + + handled =1 ;netif_dbg (cp, intr, dev,"intr, status %04x cmd %02x cpcmd %04x\n" , status,cpr8 (Cmd),cpr16 (CpCmd));cpw16 (IntrStatus, status & ~cp_rx_intr_mask); -spin_lock (&cp->lock); -/* close possible race's with dev_close */ if (unlikely (!netif_running (dev))) {cpw16 (IntrMask,0 ); -spin_unlock (&cp->lock); -return IRQ_HANDLED ; + goto out_unlock; }if (status & (RxOK | RxErr | RxEmpty | RxFIFOOvr))
@@ -612,8 +614,6 @@ static irqreturn_t cp_interrupt (int irq, void *dev_instance)if (status & LinkChg)mii_check_media (&cp->mii_if,netif_msg_link (cp), false); -spin_unlock (&cp->lock); -if (status & PciErr) {u16 pci_status;
@@ -625,7 +625,10 @@ static irqreturn_t cp_interrupt (int irq, void *dev_instance)/* TODO: reset hardware */ } -return IRQ_HANDLED ; +out_unlock: +spin_unlock (&cp->lock); + +return IRQ_RETVAL (handled); }#ifdef CONFIG_NET_POLL_CONTROLLER
Quoted 8 lines · Francois Romieu
David Miller <[email protected]> :
[...]Quoted 2 lines
I've applied this to net-next, if it triggers any problems we have some time to work it out before 3.8 is released.
I have bounced the messages to David Woodhouse since he authored the last 8139cp changes in net-next and owns the hardware to notice regressions.
Thanks.
This almost works. The patch itself is fine, but the device can't receive packets larger than 2266 bytes (ping -s 2238). After that, I get rx_fifo errors. I think the RX FIFO is only 2KiB on the 8139cp, isn't it? So after that it's dependent on how fast it can shovel it out across the PCI bus. Which is "not fast" in this case.
Transmit appears to be fine.
Signature · 2 lines
David Woodhouse Open Source Technology Centre [email protected] Intel Corporation
Quoted 12 lines · David Woodhouse
Quoted 8 lines · Francois Romieu
David Miller <[email protected]> :
[...]Quoted 2 lines
I've applied this to net-next, if it triggers any problems we have some time to work it out before 3.8 is released.
I have bounced the messages to David Woodhouse since he authored the last 8139cp changes in net-next and owns the hardware to notice regressions.
Thanks.
Quoted 8 lines
This almost works. The patch itself is fine, but the device can't receive packets larger than 2266 bytes (ping -s 2238). After that, I get
rx_fifoerrors. I think the RX FIFO is only 2KiB on the 8139cp, isn't it? So after that it's dependent on how fast it can shovel it out across the PCI bus. Which is "not fast" in this case.Transmit appears to be fine.
Checked the datasheet (admittedly old v1.5 12/6/2001): yes FIFOs are 2k on both Rx and Tx. I need to check this on the emulator again, but it didn't fail with pings up to nearly 9000 bytes, apparently a difference of real vs. virtual hardware (perhaps an interesting science experiment to adjust MTU to what the underlying hardware does, but not today ;)
Still, this does fix reported problem that driver could be set to huge MTU erroneously, and now rejects really weird values as it should.
Thanks for the test, David.
Anything to add/subtract?
Francois: I noted your follow on patch, find merit in it as well. I need to digest it more fully and expect it should be a follow up to this barring any other issues from me: appreciate your help also!
Signature · 2 lines
John Greene [email protected]
Quoted 80 lines · Francois Romieu
David Miller <[email protected]> :
[...]Quoted 2 lines
I've applied this to net-next, if it triggers any problems we have some time to work it out before 3.8 is released.
I have bounced the messages to David Woodhouse since he authored the last 8139cp changes in net-next and owns the hardware to notice regressions.
My message of two days ago was wrong : it is not possible for the irq handler to process a Tx event after the rings have been freed. Things still look racy wrt netpoll though.
Any objection against the patch below ?
(I did not gotoize the dev == NULL test: it is really unlikely and should go away).
drivers/net/ethernet/realtek/8139cp.c +11
-9@@ -577,28 +577,30 @@ static irqreturn_t cp_interrupt (int irq, void *dev_instance) {struct net_device *dev = dev_instance;struct cp_private *cp; +int handled =0 ;u16 status;if (unlikely (dev ==NULL ))return IRQ_NONE ; cp =netdev_priv (dev); +spin_lock (&cp->lock); + status =cpr16 (IntrStatus);if (!status || (status ==0xFFFF )) -return IRQ_NONE ; + goto out_unlock; + + handled =1 ;netif_dbg (cp, intr, dev,"intr, status %04x cmd %02x cpcmd %04x\n" , status,cpr8 (Cmd),cpr16 (CpCmd));cpw16 (IntrStatus, status & ~cp_rx_intr_mask); -spin_lock (&cp->lock); -/* close possible race's with dev_close */ if (unlikely (!netif_running (dev))) {cpw16 (IntrMask,0 ); -spin_unlock (&cp->lock); -return IRQ_HANDLED ; + goto out_unlock; }if (status & (RxOK | RxErr | RxEmpty | RxFIFOOvr))@@ -612,8 +614,6 @@ static irqreturn_t cp_interrupt (int irq, void *dev_instance)if (status & LinkChg)mii_check_media (&cp->mii_if,netif_msg_link (cp), false); -spin_unlock (&cp->lock); -if (status & PciErr) {u16 pci_status;@@ -625,7 +625,10 @@ static irqreturn_t cp_interrupt (int irq, void *dev_instance)/* TODO: reset hardware */ } -return IRQ_HANDLED ; +out_unlock: +spin_unlock (&cp->lock); + +return IRQ_RETVAL (handled); }#ifdef CONFIG_NET_POLL_CONTROLLER --
Quoted 4 lines
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
I think this is a good change, interesting it isn't in already or causing more issues on multi-processor boxes already. (perhaps it is?).
So do you think these patches need to go together? I could make a case either way.
Is this upstream yet?
Signature · 2 lines
John Greene [email protected]
David Woodhouse
Tested-byQuoted 2 lines · John Greene
Still, this does fix reported problem that driver could be set to huge MTU erroneously, and now rejects really weird values as it should.
Yes, absolutely. As long as the caveat is understood, feel free to add
I did look through the datasheet to see if there's anything we can do to improve reception of large packets. We could try to reduce the Rx Fifo threshold, which we currently set at 512 bytes... but it isn't going to get us much further on this particular hardware. Might be nice to have it tunable though.
There's a v1.6 datasheet at http://realtek.info/pdf/rtl8139cp.pdf btw.
Signature · 1 line
dwmw2
Quoted 80 lines · Francois Romieu
David Miller <[email protected]> :
[...]Quoted 2 lines
I've applied this to net-next, if it triggers any problems we have some time to work it out before 3.8 is released.
I have bounced the messages to David Woodhouse since he authored the last 8139cp changes in net-next and owns the hardware to notice regressions.
My message of two days ago was wrong : it is not possible for the irq handler to process a Tx event after the rings have been freed. Things still look racy wrt netpoll though.
Any objection against the patch below ?
(I did not gotoize the dev == NULL test: it is really unlikely and should go away).
drivers/net/ethernet/realtek/8139cp.c +11
-9@@ -577,28 +577,30 @@ static irqreturn_t cp_interrupt (int irq, void *dev_instance) {struct net_device *dev = dev_instance;struct cp_private *cp; +int handled =0 ;u16 status;if (unlikely (dev ==NULL ))return IRQ_NONE ; cp =netdev_priv (dev); +spin_lock (&cp->lock); + status =cpr16 (IntrStatus);if (!status || (status ==0xFFFF )) -return IRQ_NONE ; + goto out_unlock; + + handled =1 ;netif_dbg (cp, intr, dev,"intr, status %04x cmd %02x cpcmd %04x\n" , status,cpr8 (Cmd),cpr16 (CpCmd));cpw16 (IntrStatus, status & ~cp_rx_intr_mask); -spin_lock (&cp->lock); -/* close possible race's with dev_close */ if (unlikely (!netif_running (dev))) {cpw16 (IntrMask,0 ); -spin_unlock (&cp->lock); -return IRQ_HANDLED ; + goto out_unlock; }if (status & (RxOK | RxErr | RxEmpty | RxFIFOOvr))@@ -612,8 +614,6 @@ static irqreturn_t cp_interrupt (int irq, void *dev_instance)if (status & LinkChg)mii_check_media (&cp->mii_if,netif_msg_link (cp), false); -spin_unlock (&cp->lock); -if (status & PciErr) {u16 pci_status;@@ -625,7 +625,10 @@ static irqreturn_t cp_interrupt (int irq, void *dev_instance)/* TODO: reset hardware */ } -return IRQ_HANDLED ; +out_unlock: +spin_unlock (&cp->lock); + +return IRQ_RETVAL (handled); }#ifdef CONFIG_NET_POLL_CONTROLLER --
Quoted 4 lines
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Francois,
Have incorporated this and test it on virtual hardware with on top of
cb64edb6b89491edfdbae52ba7db9a8b8391d339 (my original work now
upstream). I plan to submit your work herein upstream as well, with attribution to you, if that's ok?
Signature · 2 lines
John Greene [email protected]
John Greene <[email protected]> :
[...]
Quoted 4 lines
Have incorporated this and test it on virtual hardware with on top of
cb64edb6b89491edfdbae52ba7db9a8b8391d339(my original work now upstream). I plan to submit your work herein upstream as well, with attribution to you, if that's ok?
Sure, go ahead.
I have a nasty 8110s (old netgear) bug to keep me busy.
Signature · 1 line
Ueimor