netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* problem with kernel ipconfig over usb ethernet on v.2.6.33-rc3
@ 2010-01-10  8:27 christian pellegrin
  2010-01-10 21:38 ` David Miller
  0 siblings, 1 reply; 6+ messages in thread
From: christian pellegrin @ 2010-01-10  8:27 UTC (permalink / raw)
  To: netdev

Hi,

I noticed that kernel IP auto-configuration is not usable for
USB-ethenet dongles on newer kernel because it starts before the USB
devices are found (perhaps as a consequence of parallelization of
kernel boot; the built-in delay of 500ms is not enough).I'm using the
following patch (with a command line parameter ipconfigdelay=10) to
solve this situation, but it's a shameless cut & paste from rootdelay.
Is there any better solution or I'm just missing something?

Subject: [PATCH] introduced ipconfigdelay

this is needed for using ipconfig on usb ethernet devices

Signed-off-by: Christian Pellegrin <chripell@fsfe.org>
---
 net/ipv4/ipconfig.c |   18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
index 10a6a60..8108a8c 100644
--- a/net/ipv4/ipconfig.c
+++ b/net/ipv4/ipconfig.c
@@ -187,6 +187,13 @@ struct ic_device {
 static struct ic_device *ic_first_dev __initdata = NULL;/* List of
open device */
 static struct net_device *ic_dev __initdata = NULL;	/* Selected device */

+static unsigned int __initdata ipconfig_delay;
+static int __init ipconfig_delay_setup(char *str)
+{
+	ipconfig_delay = simple_strtoul(str, NULL, 0);
+	return 1;
+}
+
 static int __init ic_open_devs(void)
 {
 	struct ic_device *d, **last;
@@ -1325,8 +1332,16 @@ static int __init ip_auto_config(void)
 #ifdef IPCONFIG_DYNAMIC
  try_try_again:
 #endif
+
 	/* Give hardware a chance to settle */
-	msleep(CONF_PRE_OPEN);
+	if (ipconfig_delay) {
+		printk(KERN_INFO "Waiting %dsec before auto-configuring device...\n",
+		       ipconfig_delay);
+		ssleep(ipconfig_delay);
+	}
+	else {
+		msleep(CONF_PRE_OPEN);
+	}

 	/* Setup all network devices */
 	if (ic_open_devs() < 0)
@@ -1576,3 +1591,4 @@ static int __init
vendor_class_identifier_setup(char *addrs)
 __setup("ip=", ip_auto_config_setup);
 __setup("nfsaddrs=", nfsaddrs_config_setup);
 __setup("dhcpclass=", vendor_class_identifier_setup);
+__setup("ipconfigdelay=", ipconfig_delay_setup);
-- 
1.5.6.5


-- 
Christian Pellegrin, see http://www.evolware.org/chri/
"Real Programmers don't play tennis, or any other sport which requires
you to change clothes. Mountain climbing is OK, and Real Programmers
wear their climbing boots to work in case a mountain should suddenly
spring up in the middle of the computer room."

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

* Re: problem with kernel ipconfig over usb ethernet on v.2.6.33-rc3
  2010-01-10  8:27 problem with kernel ipconfig over usb ethernet on v.2.6.33-rc3 christian pellegrin
@ 2010-01-10 21:38 ` David Miller
  2010-01-11  7:18   ` christian pellegrin
  0 siblings, 1 reply; 6+ messages in thread
From: David Miller @ 2010-01-10 21:38 UTC (permalink / raw)
  To: chripell; +Cc: netdev

From: christian pellegrin <chripell@gmail.com>
Date: Sun, 10 Jan 2010 09:27:48 +0100

> Hi,
> 
> I noticed that kernel IP auto-configuration is not usable for
> USB-ethenet dongles on newer kernel because it starts before the USB
> devices are found (perhaps as a consequence of parallelization of
> kernel boot; the built-in delay of 500ms is not enough).I'm using the
> following patch (with a command line parameter ipconfigdelay=10) to
> solve this situation, but it's a shameless cut & paste from rootdelay.
> Is there any better solution or I'm just missing something?

How long does it actually take for the USB ethernet device
to become visible at this point?

Is 2 seconds enough?  For example.

If so, let's just change CONF_PRE_OPEN to "2" and change
msleep() to ssleep().

It's rediculious to require that users learn about obscure
kernel command line options in order for basic functionality
to work properly.

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

* Re: problem with kernel ipconfig over usb ethernet on v.2.6.33-rc3
  2010-01-10 21:38 ` David Miller
@ 2010-01-11  7:18   ` christian pellegrin
  2010-03-10 22:33     ` David Miller
  0 siblings, 1 reply; 6+ messages in thread
From: christian pellegrin @ 2010-01-11  7:18 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

On Sun, Jan 10, 2010 at 10:38 PM, David Miller <davem@davemloft.net> wrote:
>
> How long does it actually take for the USB ethernet device
> to become visible at this point?
>
> Is 2 seconds enough?  For example.

no, it's around 8-9 seconds

>
> It's rediculious to require that users learn about obscure
> kernel command line options in order for basic functionality
> to work properly.
>

I agree with you, unfortunately rootdelay is there and it's rather
difficult to boot from USB mass storage or even SCSI arrays without
it. If you think it's worth the hassle (maybe this is not a common
user case: I have to develop on embedded systems where the hardware
designers try to save every possible euro by not including proper
ethernet MACs; on desktop systems having initrd/initramfs setting up
the device and waiting for them via udevd solved the problem (but they
don't use kernel ipconfig either in this case)) I can try more
elaborate schemes like: if the ethX specified by ip= is not present at
the first try just wait 10 seconds and try again (perhaps repeat this
two time just to be sure).

-- 
Christian Pellegrin, see http://www.evolware.org/chri/
"Real Programmers don't play tennis, or any other sport which requires
you to change clothes. Mountain climbing is OK, and Real Programmers
wear their climbing boots to work in case a mountain should suddenly
spring up in the middle of the computer room."

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

* Re: problem with kernel ipconfig over usb ethernet on v.2.6.33-rc3
  2010-01-11  7:18   ` christian pellegrin
@ 2010-03-10 22:33     ` David Miller
  2010-03-12  7:50       ` christian pellegrin
  0 siblings, 1 reply; 6+ messages in thread
From: David Miller @ 2010-03-10 22:33 UTC (permalink / raw)
  To: chripell; +Cc: netdev

From: christian pellegrin <chripell@gmail.com>
Date: Mon, 11 Jan 2010 08:18:13 +0100

> I can try more elaborate schemes like: if the ethX specified by ip=
> is not present at the first try just wait 10 seconds and try again
> (perhaps repeat this two time just to be sure).

Please let me know if this patch makes your setup work
properly.

It loops one second at a time, for up to 12 seconds, waiting
for a usable non-loopback device to appear.

diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
index 10a6a60..6789092 100644
--- a/net/ipv4/ipconfig.c
+++ b/net/ipv4/ipconfig.c
@@ -187,6 +187,16 @@ struct ic_device {
 static struct ic_device *ic_first_dev __initdata = NULL;/* List of open device */
 static struct net_device *ic_dev __initdata = NULL;	/* Selected device */
 
+static bool __init ic_device_match(struct net_device *dev)
+{
+	if (user_dev_name[0] ? !strcmp(dev->name, user_dev_name) :
+	    (!(dev->flags & IFF_LOOPBACK) &&
+	     (dev->flags & (IFF_POINTOPOINT|IFF_BROADCAST)) &&
+	     strncmp(dev->name, "dummy", 5)))
+		return true;
+	return false;
+}
+
 static int __init ic_open_devs(void)
 {
 	struct ic_device *d, **last;
@@ -207,10 +217,7 @@ static int __init ic_open_devs(void)
 	for_each_netdev(&init_net, dev) {
 		if (dev->flags & IFF_LOOPBACK)
 			continue;
-		if (user_dev_name[0] ? !strcmp(dev->name, user_dev_name) :
-		    (!(dev->flags & IFF_LOOPBACK) &&
-		     (dev->flags & (IFF_POINTOPOINT|IFF_BROADCAST)) &&
-		     strncmp(dev->name, "dummy", 5))) {
+		if (ic_device_match(dev)) {
 			int able = 0;
 			if (dev->mtu >= 364)
 				able |= IC_BOOTP;
@@ -228,7 +235,7 @@ static int __init ic_open_devs(void)
 			}
 			if (!(d = kmalloc(sizeof(struct ic_device), GFP_KERNEL))) {
 				rtnl_unlock();
-				return -1;
+				return -ENOMEM;
 			}
 			d->dev = dev;
 			*last = d;
@@ -253,7 +260,7 @@ static int __init ic_open_devs(void)
 			printk(KERN_ERR "IP-Config: Device `%s' not found.\n", user_dev_name);
 		else
 			printk(KERN_ERR "IP-Config: No network devices available.\n");
-		return -1;
+		return -ENODEV;
 	}
 	return 0;
 }
@@ -1303,6 +1310,32 @@ __be32 __init root_nfs_parse_addr(char *name)
 	return addr;
 }
 
+#define DEVICE_WAIT_MAX		12 /* 12 seconds */
+
+static int __init wait_for_devices(void)
+{
+	int i;
+
+	msleep(CONF_PRE_OPEN);
+	for (i = 0; i < DEVICE_WAIT_MAX; i++) {
+		struct net_device *dev;
+		int found = 0;
+
+		rtnl_lock();
+		for_each_netdev(&init_net, dev) {
+			if (ic_device_match(dev)) {
+				found = 1;
+				break;
+			}
+		}
+		rtnl_unlock();
+		if (found)
+			return 0;
+		ssleep(1);
+	}
+	return -ENODEV;
+}
+
 /*
  *	IP Autoconfig dispatcher.
  */
@@ -1313,6 +1346,7 @@ static int __init ip_auto_config(void)
 #ifdef IPCONFIG_DYNAMIC
 	int retries = CONF_OPEN_RETRIES;
 #endif
+	int err;
 
 #ifdef CONFIG_PROC_FS
 	proc_net_fops_create(&init_net, "pnp", S_IRUGO, &pnp_seq_fops);
@@ -1325,12 +1359,15 @@ static int __init ip_auto_config(void)
 #ifdef IPCONFIG_DYNAMIC
  try_try_again:
 #endif
-	/* Give hardware a chance to settle */
-	msleep(CONF_PRE_OPEN);
+	/* Wait for devices to appear */
+	err = wait_for_devices();
+	if (err)
+		return err;
 
 	/* Setup all network devices */
-	if (ic_open_devs() < 0)
-		return -1;
+	err = ic_open_devs();
+	if (err)
+		return err;
 
 	/* Give drivers a chance to settle */
 	ssleep(CONF_POST_OPEN);

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

* Re: problem with kernel ipconfig over usb ethernet on v.2.6.33-rc3
  2010-03-10 22:33     ` David Miller
@ 2010-03-12  7:50       ` christian pellegrin
  2010-03-12  7:55         ` David Miller
  0 siblings, 1 reply; 6+ messages in thread
From: christian pellegrin @ 2010-03-12  7:50 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

Hi,

On Wed, Mar 10, 2010 at 11:33 PM, David Miller <davem@davemloft.net> wrote:
>
> Please let me know if this patch makes your setup work
> properly.

tested and it works, thanks.

Tested-by: Christian Pellegrin <chripell@fsfe.org>

-- 
Christian Pellegrin, see http://www.evolware.org/chri/
"Real Programmers don't play tennis, or any other sport which requires
you to change clothes. Mountain climbing is OK, and Real Programmers
wear their climbing boots to work in case a mountain should suddenly
spring up in the middle of the computer room."

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

* Re: problem with kernel ipconfig over usb ethernet on v.2.6.33-rc3
  2010-03-12  7:50       ` christian pellegrin
@ 2010-03-12  7:55         ` David Miller
  0 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2010-03-12  7:55 UTC (permalink / raw)
  To: chripell; +Cc: netdev

From: christian pellegrin <chripell@gmail.com>
Date: Fri, 12 Mar 2010 08:50:25 +0100

> Hi,
> 
> On Wed, Mar 10, 2010 at 11:33 PM, David Miller <davem@davemloft.net> wrote:
>>
>> Please let me know if this patch makes your setup work
>> properly.
> 
> tested and it works, thanks.
> 
> Tested-by: Christian Pellegrin <chripell@fsfe.org>

Thanks a lot for testing, I'll push this around.

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

end of thread, other threads:[~2010-03-12  7:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-10  8:27 problem with kernel ipconfig over usb ethernet on v.2.6.33-rc3 christian pellegrin
2010-01-10 21:38 ` David Miller
2010-01-11  7:18   ` christian pellegrin
2010-03-10 22:33     ` David Miller
2010-03-12  7:50       ` christian pellegrin
2010-03-12  7:55         ` David Miller

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).