Re: [patch 1/7] wusb: teach choose_address() about wireless devices

Inaky Perez-Gonzalez <[email protected]>
Newsgroups gmane.linux.usb.devel,gmane.linux.drivers.uwb
Organization Intel Corporation
Message-ID <[email protected]>
On Monday 06 August 2007, Alan Stern wrote:
> On Fri, 3 Aug 2007, Inaky Perez-Gonzalez wrote:
> 

> > + *
> > + * We add 2 as an offset for two reasons: (1) dev addr 0 is reserved
> > + * by USB for default address; (2) Linux's USB stack uses always #1 for
> > + * the root hub of the controller. So port 0 has address #2.
> 
> This comment is a little confusing since the code really adds 1, not 2:

> > +	if (udev->wusb) {
> > +		devnum = udev->portnum + 1;
> 
> See?  Besides, the USB specs I've run across define port numbers
> starting at 1, not 0.  Maybe the WUSB spec is different.

/me checks the patch (again) -- my bad in the comment. udev->portnum 
is 1 based (as USB says). ergo for +1 will make the device address be 
2 based. So default address is #0 (choose_address() won't use), root
hub is "port #0", device address #1, any other device is #2 or higher.

device_address - 2 yields the port index (0 based) for the WUSB code.

Fixed patch inlined

wusb: teach choose_address() about wireless devices

Modify choose_address() so it knows about our special scheme of
addressing WUSB devices (1:1 w/ port number).

Signed-off-by: Inaky Perez-Gonzalez <[email protected]>

---
 drivers/usb/core/hub.c |   34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)

Index: linux.hg/drivers/usb/core/hub.c
===================================================================
--- linux.hg.orig/drivers/usb/core/hub.c	2007-07-31 12:18:53.000000000 -0700
+++ linux.hg/drivers/usb/core/hub.c	2007-07-31 12:18:58.000000000 -0700
@@ -1077,21 +1077,42 @@
 	spin_unlock_irqrestore(&device_state_lock, flags);
 }
 
+/*
+ * WUSB devices are simple: they have no hubs behind, so the mapping
+ * device <-> virtual port number becomes 1:1. Why? to simplify the
+ * life of the device connection logic in
+ * drivers/usb/wusbcore/devconnect.c. When we do the initial secret
+ * handshake we need to assign a temporary address in the unauthorized
+ * space. For simplicity we use the first virtual port number found to
+ * be free [drivers/usb/wusbcore/devconnect.c:wusbhc_devconnect_ack()]
+ * and that becomes it's address [X < 128] or its unauthorized address
+ * [X | 0x80].
+ *
+ * We add 1 as an offset to the one-based USB-stack port number
+ * (zero-based wusb virtual port index) for two reasons: (a) dev addr
+ * 0 is reserved by USB for default address; (b) Linux's USB stack
+ * uses always #1 for the root hub of the controller. So USB stack's
+ * port #1, which is wusb virtual-port #0 has address #2.
+ */
 static void choose_address(struct usb_device *udev)
 {
 	int		devnum;
 	struct usb_bus	*bus = udev->bus;
 
 	/* If khubd ever becomes multithreaded, this will need a lock */
-
-	/* Try to allocate the next devnum beginning at bus->devnum_next. */
-	devnum = find_next_zero_bit(bus->devmap.devicemap, 128,
-			bus->devnum_next);
-	if (devnum >= 128)
-		devnum = find_next_zero_bit(bus->devmap.devicemap, 128, 1);
-
-	bus->devnum_next = ( devnum >= 127 ? 1 : devnum + 1);
-
+	if (udev->wusb) {
+		devnum = udev->portnum + 1;
+		BUG_ON(test_bit(devnum, bus->devmap.devicemap));
+	} else {
+		/* Try to allocate the next devnum beginning at
+		 * bus->devnum_next. */
+		devnum = find_next_zero_bit(bus->devmap.devicemap, 128,
+					    bus->devnum_next);
+		if (devnum >= 128)
+			devnum = find_next_zero_bit(bus->devmap.devicemap,
+						    128, 1);
+		bus->devnum_next = ( devnum >= 127 ? 1 : devnum + 1);
+	}
 	if (devnum < 128) {
 		set_bit(devnum, bus->devmap.devicemap);
 		udev->devnum = devnum;
@@ -2522,6 +2541,7 @@
 		udev->speed = USB_SPEED_UNKNOWN;
  		udev->bus_mA = hub->mA_per_port;
 		udev->level = hdev->level + 1;
+		udev->wusb = hub_is_wusb(hub);
 
 		/* set the address */
 		choose_address(udev);


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.