netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFT PATCH] 8139cp: properly support change of MTU values [v2]
@ 2012-12-03 16:19 John Greene
  2012-12-03 18:52 ` David Miller
  0 siblings, 1 reply; 9+ messages in thread
From: John Greene @ 2012-12-03 16:19 UTC (permalink / raw)
  To: netdev; +Cc: John Greene, David S. Miller

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.

Signed-off-by: "John Greene" <jogreene@redhat.com>
CC: "David S. Miller" <davem@davemloft.net>
---
 drivers/net/ethernet/realtek/8139cp.c | 23 ++++-------------------
 1 file changed, 4 insertions(+), 19 deletions(-)

diff --git a/drivers/net/ethernet/realtek/8139cp.c b/drivers/net/ethernet/realtek/8139cp.c
index 6cb96b4..0da3f5e 100644
--- a/drivers/net/ethernet/realtek/8139cp.c
+++ b/drivers/net/ethernet/realtek/8139cp.c
@@ -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,
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [RFT PATCH] 8139cp: properly support change of MTU values [v2]
  2012-12-03 16:19 [RFT PATCH] 8139cp: properly support change of MTU values [v2] John Greene
@ 2012-12-03 18:52 ` David Miller
  2012-12-03 20:46   ` Francois Romieu
  0 siblings, 1 reply; 9+ messages in thread
From: David Miller @ 2012-12-03 18:52 UTC (permalink / raw)
  To: jogreene; +Cc: netdev

From: John Greene <jogreene@redhat.com>
Date: Mon,  3 Dec 2012 11:19:33 -0500

> 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.
> 
> Signed-off-by: "John Greene" <jogreene@redhat.com>

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.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RFT PATCH] 8139cp: properly support change of MTU values [v2]
  2012-12-03 18:52 ` David Miller
@ 2012-12-03 20:46   ` Francois Romieu
  2012-12-04 15:44     ` David Woodhouse
                       ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Francois Romieu @ 2012-12-03 20:46 UTC (permalink / raw)
  To: jogreene; +Cc: David Miller, netdev, dwmw2

David Miller <davem@davemloft.net> :
[...]
> 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).

diff --git a/drivers/net/ethernet/realtek/8139cp.c b/drivers/net/ethernet/realtek/8139cp.c
index 0da3f5e..57cd542 100644
--- a/drivers/net/ethernet/realtek/8139cp.c
+++ b/drivers/net/ethernet/realtek/8139cp.c
@@ -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

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [RFT PATCH] 8139cp: properly support change of MTU values [v2]
  2012-12-03 20:46   ` Francois Romieu
@ 2012-12-04 15:44     ` David Woodhouse
  2012-12-04 19:04       ` John Greene
  2012-12-05 19:41     ` John Greene
  2012-12-13 19:56     ` John Greene
  2 siblings, 1 reply; 9+ messages in thread
From: David Woodhouse @ 2012-12-04 15:44 UTC (permalink / raw)
  To: Francois Romieu; +Cc: jogreene, David Miller, netdev

[-- Attachment #1: Type: text/plain, Size: 934 bytes --]

On Mon, 2012-12-03 at 21:46 +0100, Francois Romieu wrote:
> David Miller <davem@davemloft.net> :
> [...]
> > 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.

-- 
David Woodhouse                            Open Source Technology Centre
David.Woodhouse@intel.com                              Intel Corporation




[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 6171 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RFT PATCH] 8139cp: properly support change of MTU values [v2]
  2012-12-04 15:44     ` David Woodhouse
@ 2012-12-04 19:04       ` John Greene
  2012-12-06  1:34         ` David Woodhouse
  0 siblings, 1 reply; 9+ messages in thread
From: John Greene @ 2012-12-04 19:04 UTC (permalink / raw)
  To: David Woodhouse; +Cc: Francois Romieu, David Miller, netdev

On 12/04/2012 10:44 AM, David Woodhouse wrote:
> On Mon, 2012-12-03 at 21:46 +0100, Francois Romieu wrote:
>> David Miller <davem@davemloft.net> :
>> [...]
>>> 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.
>
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!



-- 
John Greene
jogreene@redhat.com

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RFT PATCH] 8139cp: properly support change of MTU values [v2]
  2012-12-03 20:46   ` Francois Romieu
  2012-12-04 15:44     ` David Woodhouse
@ 2012-12-05 19:41     ` John Greene
  2012-12-13 19:56     ` John Greene
  2 siblings, 0 replies; 9+ messages in thread
From: John Greene @ 2012-12-05 19:41 UTC (permalink / raw)
  To: Francois Romieu; +Cc: David Miller, netdev, dwmw2

On 12/03/2012 03:46 PM, Francois Romieu wrote:
> David Miller <davem@davemloft.net> :
> [...]
>> 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).
>
> diff --git a/drivers/net/ethernet/realtek/8139cp.c b/drivers/net/ethernet/realtek/8139cp.c
> index 0da3f5e..57cd542 100644
> --- a/drivers/net/ethernet/realtek/8139cp.c
> +++ b/drivers/net/ethernet/realtek/8139cp.c
> @@ -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
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> 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?

-- 
John Greene
jogreene@redhat.com

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RFT PATCH] 8139cp: properly support change of MTU values [v2]
  2012-12-04 19:04       ` John Greene
@ 2012-12-06  1:34         ` David Woodhouse
  0 siblings, 0 replies; 9+ messages in thread
From: David Woodhouse @ 2012-12-06  1:34 UTC (permalink / raw)
  To: John Greene; +Cc: Francois Romieu, David Miller, netdev

[-- Attachment #1: Type: text/plain, Size: 732 bytes --]

On Tue, 2012-12-04 at 14:04 -0500, John Greene wrote:
> 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
Tested-by: David Woodhouse <David.Woodhouse@intel.com>

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.

-- 
dwmw2


[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 6171 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RFT PATCH] 8139cp: properly support change of MTU values [v2]
  2012-12-03 20:46   ` Francois Romieu
  2012-12-04 15:44     ` David Woodhouse
  2012-12-05 19:41     ` John Greene
@ 2012-12-13 19:56     ` John Greene
  2012-12-13 22:36       ` Francois Romieu
  2 siblings, 1 reply; 9+ messages in thread
From: John Greene @ 2012-12-13 19:56 UTC (permalink / raw)
  To: Francois Romieu; +Cc: David Miller, netdev, dwmw2

On 12/03/2012 03:46 PM, Francois Romieu wrote:
> David Miller <davem@davemloft.net> :
> [...]
>> 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).
>
> diff --git a/drivers/net/ethernet/realtek/8139cp.c b/drivers/net/ethernet/realtek/8139cp.c
> index 0da3f5e..57cd542 100644
> --- a/drivers/net/ethernet/realtek/8139cp.c
> +++ b/drivers/net/ethernet/realtek/8139cp.c
> @@ -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
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> 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?


-- 
John Greene
jogreene@redhat.com

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RFT PATCH] 8139cp: properly support change of MTU values [v2]
  2012-12-13 19:56     ` John Greene
@ 2012-12-13 22:36       ` Francois Romieu
  0 siblings, 0 replies; 9+ messages in thread
From: Francois Romieu @ 2012-12-13 22:36 UTC (permalink / raw)
  To: John Greene; +Cc: David Miller, netdev, dwmw2

John Greene <jogreene@redhat.com> :
[...]
> 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.

-- 
Ueimor

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2012-12-13 23:02 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-03 16:19 [RFT PATCH] 8139cp: properly support change of MTU values [v2] John Greene
2012-12-03 18:52 ` David Miller
2012-12-03 20:46   ` Francois Romieu
2012-12-04 15:44     ` David Woodhouse
2012-12-04 19:04       ` John Greene
2012-12-06  1:34         ` David Woodhouse
2012-12-05 19:41     ` John Greene
2012-12-13 19:56     ` John Greene
2012-12-13 22:36       ` Francois Romieu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).