[U-Boot] [PATCH 01/10] usb: emul: Remove maxpacketsize in usb_emul_setup_device()

This parameter is never used.
Signed-off-by: Bin Meng bmeng.cn@gmail.com ---
drivers/usb/emul/sandbox_flash.c | 3 +-- drivers/usb/emul/sandbox_hub.c | 3 +-- drivers/usb/emul/sandbox_keyb.c | 3 +-- drivers/usb/emul/usb-emul-uclass.c | 4 ++-- include/usb.h | 5 ++--- 5 files changed, 7 insertions(+), 11 deletions(-)
diff --git a/drivers/usb/emul/sandbox_flash.c b/drivers/usb/emul/sandbox_flash.c index 98d20c0..2f84b36 100644 --- a/drivers/usb/emul/sandbox_flash.c +++ b/drivers/usb/emul/sandbox_flash.c @@ -390,8 +390,7 @@ static int sandbox_flash_bind(struct udevice *dev) fs[2].id = STRINGID_SERIAL; fs[2].s = dev->name;
- return usb_emul_setup_device(dev, PACKET_SIZE_64, plat->flash_strings, - flash_desc_list); + return usb_emul_setup_device(dev, plat->flash_strings, flash_desc_list); }
static int sandbox_flash_probe(struct udevice *dev) diff --git a/drivers/usb/emul/sandbox_hub.c b/drivers/usb/emul/sandbox_hub.c index 1432858..9ed7000 100644 --- a/drivers/usb/emul/sandbox_hub.c +++ b/drivers/usb/emul/sandbox_hub.c @@ -274,8 +274,7 @@ static int sandbox_hub_submit_control_msg(struct udevice *bus,
static int sandbox_hub_bind(struct udevice *dev) { - return usb_emul_setup_device(dev, PACKET_SIZE_64, hub_strings, - hub_desc_list); + return usb_emul_setup_device(dev, hub_strings, hub_desc_list); }
static int sandbox_child_post_bind(struct udevice *dev) diff --git a/drivers/usb/emul/sandbox_keyb.c b/drivers/usb/emul/sandbox_keyb.c index 2735985..cff0176 100644 --- a/drivers/usb/emul/sandbox_keyb.c +++ b/drivers/usb/emul/sandbox_keyb.c @@ -208,8 +208,7 @@ static int sandbox_keyb_bind(struct udevice *dev) fs[2].id = STRINGID_SERIAL; fs[2].s = dev->name;
- return usb_emul_setup_device(dev, PACKET_SIZE_8, plat->keyb_strings, - keyb_desc_list); + return usb_emul_setup_device(dev, plat->keyb_strings, keyb_desc_list); }
static int sandbox_keyb_probe(struct udevice *dev) diff --git a/drivers/usb/emul/usb-emul-uclass.c b/drivers/usb/emul/usb-emul-uclass.c index 6e03c1e..e4a267b 100644 --- a/drivers/usb/emul/usb-emul-uclass.c +++ b/drivers/usb/emul/usb-emul-uclass.c @@ -229,8 +229,8 @@ int usb_emul_int(struct udevice *emul, struct usb_device *udev, return ops->interrupt(emul, udev, pipe, buffer, length, interval); }
-int usb_emul_setup_device(struct udevice *dev, int maxpacketsize, - struct usb_string *strings, void **desc_list) +int usb_emul_setup_device(struct udevice *dev, struct usb_string *strings, + void **desc_list) { struct usb_dev_platdata *plat = dev_get_parent_platdata(dev); struct usb_generic_descriptor **ptr; diff --git a/include/usb.h b/include/usb.h index 0ddc082..1563c9a 100644 --- a/include/usb.h +++ b/include/usb.h @@ -976,7 +976,6 @@ int usb_get_max_xfer_size(struct usb_device *dev, size_t *size); * the USB emulation uclass about the features of the emulator. * * @dev: Emulation device - * @maxpacketsize: Maximum packet size (e.g. PACKET_SIZE_64) * @strings: List of USB string descriptors, terminated by a NULL * entry * @desc_list: List of points or USB descriptors, terminated by NULL. @@ -984,8 +983,8 @@ int usb_get_max_xfer_size(struct usb_device *dev, size_t *size); * and others follow on after that. * @return 0 if OK, -ENOSYS if not implemented, other -ve on error */ -int usb_emul_setup_device(struct udevice *dev, int maxpacketsize, - struct usb_string *strings, void **desc_list); +int usb_emul_setup_device(struct udevice *dev, struct usb_string *strings, + void **desc_list);
/** * usb_emul_control() - Send a control packet to an emulator

There is no such a parameter called 'bus'.
Signed-off-by: Bin Meng bmeng.cn@gmail.com ---
include/usb.h | 1 - 1 file changed, 1 deletion(-)
diff --git a/include/usb.h b/include/usb.h index 1563c9a..3d51731 100644 --- a/include/usb.h +++ b/include/usb.h @@ -1035,7 +1035,6 @@ int usb_emul_find(struct udevice *bus, ulong pipe, struct udevice **emulp); /** * usb_emul_find_for_dev() - Find an emulator for a particular device * - * @bus: USB bus (controller) * @dev: USB device to check * @emulp: Returns pointer to emulator, or NULL if not found * @return 0 if found, -ve on error

At present 'usb tree' shows that the root hub on the Sandbox USB controller is at full speed. But its device descriptor says it's USB 2.0, so let's report it as a high speed device.
Signed-off-by: Bin Meng bmeng.cn@gmail.com ---
drivers/usb/host/usb-sandbox.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
diff --git a/drivers/usb/host/usb-sandbox.c b/drivers/usb/host/usb-sandbox.c index 5e3d96c..f85d36b 100644 --- a/drivers/usb/host/usb-sandbox.c +++ b/drivers/usb/host/usb-sandbox.c @@ -12,6 +12,10 @@
DECLARE_GLOBAL_DATA_PTR;
+struct sandbox_usb_ctrl { + int rootdev; +}; + static void usbmon_trace(struct udevice *bus, ulong pipe, struct devrequest *setup, struct udevice *emul) { @@ -40,6 +44,7 @@ static int sandbox_submit_control(struct udevice *bus, void *buffer, int length, struct devrequest *setup) { + struct sandbox_usb_ctrl *ctrl = dev_get_priv(bus); struct udevice *emul; int ret;
@@ -49,6 +54,14 @@ static int sandbox_submit_control(struct udevice *bus, usbmon_trace(bus, pipe, setup, emul); if (ret) return ret; + + if (usb_pipedevice(pipe) == ctrl->rootdev) { + if (setup->request == USB_REQ_SET_ADDRESS) { + debug("%s: Set root hub's USB address\n", __func__); + ctrl->rootdev = le16_to_cpu(setup->value); + } + } + ret = usb_emul_control(emul, udev, pipe, buffer, length, setup); if (ret < 0) { debug("ret=%d\n", ret); @@ -107,6 +120,16 @@ static int sandbox_submit_int(struct udevice *bus, struct usb_device *udev,
static int sandbox_alloc_device(struct udevice *dev, struct usb_device *udev) { + struct sandbox_usb_ctrl *ctrl = dev_get_priv(dev); + + /* + * Root hub will be the first device to be initailized. + * If this device is a root hub, initialize its device speed + * to high speed as we are a USB 2.0 controller. + */ + if (ctrl->rootdev == 0) + udev->speed = USB_SPEED_HIGH; + return 0; }
@@ -133,4 +156,5 @@ U_BOOT_DRIVER(usb_sandbox) = { .of_match = sandbox_usb_ids, .probe = sandbox_usb_probe, .ops = &sandbox_usb_ops, + .priv_auto_alloc_size = sizeof(struct sandbox_usb_ctrl), };

Current emulator select logic in usb_emul_find_devnum() is to test the USB address. The USB address of the device being enumerated is initialized to zero at the beginning of the enumeration process in usb_setup_device(). At this point, the saved USB address in the platform data has not been assigned to any valid USB address either. This means: the logic will select an emulator device according to its sequence of declaring order in the device tree. Take test.dts for example, flash-stick@0 will be selected before flash-stick@1. But unfortunately such logic is wrong.
In fact USB devices show up in a random order during the enumeration which means usb_emul_find_devnum() may be called on port 3 for keyb@3 before on port 0 for flash-stick@0.
To fix this, we introduce a new emulator uclass specific platdata to store the USB device's port number on its parent hub, and update the logic to test the port number instead.
Signed-off-by: Bin Meng bmeng.cn@gmail.com ---
drivers/usb/emul/sandbox_hub.c | 2 ++ drivers/usb/emul/usb-emul-uclass.c | 42 +++++++++++++++++++++++++++++++++----- drivers/usb/host/usb-sandbox.c | 6 +++--- include/usb.h | 18 ++++++++++++++-- 4 files changed, 58 insertions(+), 10 deletions(-)
diff --git a/drivers/usb/emul/sandbox_hub.c b/drivers/usb/emul/sandbox_hub.c index 9ed7000..8ed7a0f 100644 --- a/drivers/usb/emul/sandbox_hub.c +++ b/drivers/usb/emul/sandbox_hub.c @@ -280,8 +280,10 @@ static int sandbox_hub_bind(struct udevice *dev) static int sandbox_child_post_bind(struct udevice *dev) { struct sandbox_hub_platdata *plat = dev_get_parent_platdata(dev); + struct usb_emul_platdata *emul = dev_get_uclass_platdata(dev);
plat->port = dev_read_u32_default(dev, "reg", -1); + emul->port1 = plat->port + 1;
return 0; } diff --git a/drivers/usb/emul/usb-emul-uclass.c b/drivers/usb/emul/usb-emul-uclass.c index e4a267b..1203eb2 100644 --- a/drivers/usb/emul/usb-emul-uclass.c +++ b/drivers/usb/emul/usb-emul-uclass.c @@ -107,7 +107,7 @@ static int usb_emul_get_descriptor(struct usb_dev_platdata *plat, int value, return upto ? upto : length ? -EIO : 0; }
-static int usb_emul_find_devnum(int devnum, struct udevice **emulp) +static int usb_emul_find_devnum(int devnum, int port1, struct udevice **emulp) { struct udevice *dev; struct uclass *uc; @@ -120,7 +120,37 @@ static int usb_emul_find_devnum(int devnum, struct udevice **emulp) uclass_foreach_dev(dev, uc) { struct usb_dev_platdata *udev = dev_get_parent_platdata(dev);
- if (udev->devnum == devnum) { + /* + * devnum is initialzied to zero at the beginning of the + * enumeration process in usb_setup_device(). At this + * point, udev->devnum has not been assigned to any valid + * USB address either, so we can't rely on the comparison + * result between udev->devnum and devnum to select an + * emulator device. + */ + if (!devnum) { + struct usb_emul_platdata *plat; + + /* + * If the parent is sandbox USB controller, we are + * the root hub. And there is only one root hub + * in the system. + */ + if (device_get_uclass_id(dev->parent) == UCLASS_USB) { + debug("%s: Found emulator '%s'\n", + __func__, dev->name); + *emulp = dev; + return 0; + } + + plat = dev_get_uclass_platdata(dev); + if (plat->port1 == port1) { + debug("%s: Found emulator '%s', port %d\n", + __func__, dev->name, port1); + *emulp = dev; + return 0; + } + } else if (udev->devnum == devnum) { debug("%s: Found emulator '%s', addr %d\n", __func__, dev->name, udev->devnum); *emulp = dev; @@ -132,18 +162,19 @@ static int usb_emul_find_devnum(int devnum, struct udevice **emulp) return -ENOENT; }
-int usb_emul_find(struct udevice *bus, ulong pipe, struct udevice **emulp) +int usb_emul_find(struct udevice *bus, ulong pipe, int port1, + struct udevice **emulp) { int devnum = usb_pipedevice(pipe);
- return usb_emul_find_devnum(devnum, emulp); + return usb_emul_find_devnum(devnum, port1, emulp); }
int usb_emul_find_for_dev(struct udevice *dev, struct udevice **emulp) { struct usb_dev_platdata *udev = dev_get_parent_platdata(dev);
- return usb_emul_find_devnum(udev->devnum, emulp); + return usb_emul_find_devnum(udev->devnum, 0, emulp); }
int usb_emul_control(struct udevice *emul, struct usb_device *udev, @@ -276,6 +307,7 @@ UCLASS_DRIVER(usb_emul) = { .id = UCLASS_USB_EMUL, .name = "usb_emul", .post_bind = dm_scan_fdt_dev, + .per_device_platdata_auto_alloc_size = sizeof(struct usb_emul_platdata), .per_child_auto_alloc_size = sizeof(struct usb_device), .per_child_platdata_auto_alloc_size = sizeof(struct usb_dev_platdata), }; diff --git a/drivers/usb/host/usb-sandbox.c b/drivers/usb/host/usb-sandbox.c index f85d36b..15055b3 100644 --- a/drivers/usb/host/usb-sandbox.c +++ b/drivers/usb/host/usb-sandbox.c @@ -50,7 +50,7 @@ static int sandbox_submit_control(struct udevice *bus,
/* Just use child of dev as emulator? */ debug("%s: bus=%s\n", __func__, bus->name); - ret = usb_emul_find(bus, pipe, &emul); + ret = usb_emul_find(bus, pipe, udev->portnr, &emul); usbmon_trace(bus, pipe, setup, emul); if (ret) return ret; @@ -83,7 +83,7 @@ static int sandbox_submit_bulk(struct udevice *bus, struct usb_device *udev,
/* Just use child of dev as emulator? */ debug("%s: bus=%s\n", __func__, bus->name); - ret = usb_emul_find(bus, pipe, &emul); + ret = usb_emul_find(bus, pipe, udev->portnr, &emul); usbmon_trace(bus, pipe, NULL, emul); if (ret) return ret; @@ -109,7 +109,7 @@ static int sandbox_submit_int(struct udevice *bus, struct usb_device *udev,
/* Just use child of dev as emulator? */ debug("%s: bus=%s\n", __func__, bus->name); - ret = usb_emul_find(bus, pipe, &emul); + ret = usb_emul_find(bus, pipe, udev->portnr, &emul); usbmon_trace(bus, pipe, NULL, emul); if (ret) return ret; diff --git a/include/usb.h b/include/usb.h index 3d51731..63edddd 100644 --- a/include/usb.h +++ b/include/usb.h @@ -653,6 +653,18 @@ struct usb_bus_priv { };
/** + * struct usb_emul_platdata - platform data about the USB emulator + * + * Given a USB emulator (UCLASS_USB_EMUL) 'dev', this is + * dev_get_uclass_platdata(dev). + * + * @port1: USB emulator device port number on the parent hub + */ +struct usb_emul_platdata { + int port1; /* Port number (numbered from 1) */ +}; + +/** * struct dm_usb_ops - USB controller operations * * This defines the operations supoorted on a USB controller. Common @@ -1023,14 +1035,16 @@ int usb_emul_int(struct udevice *emul, struct usb_device *udev, /** * usb_emul_find() - Find an emulator for a particular device * - * Check @pipe to find a device number on bus @bus and return it. + * Check @pipe and @port1 to find a device number on bus @bus and return it. * * @bus: USB bus (controller) * @pipe: Describes pipe being used, and includes the device number + * @port1: Describes port number on the parent hub * @emulp: Returns pointer to emulator, or NULL if not found * @return 0 if found, -ve on error */ -int usb_emul_find(struct udevice *bus, ulong pipe, struct udevice **emulp); +int usb_emul_find(struct udevice *bus, ulong pipe, int port1, + struct udevice **emulp);
/** * usb_emul_find_for_dev() - Find an emulator for a particular device

This can be useful outside of the sandbox usb emulation uclass driver. Expose it as a public API with a proper prefix (usb_emul_).
Signed-off-by: Bin Meng bmeng.cn@gmail.com ---
drivers/usb/emul/usb-emul-uclass.c | 5 ++--- include/usb.h | 11 +++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/emul/usb-emul-uclass.c b/drivers/usb/emul/usb-emul-uclass.c index 1203eb2..359d0da 100644 --- a/drivers/usb/emul/usb-emul-uclass.c +++ b/drivers/usb/emul/usb-emul-uclass.c @@ -52,7 +52,7 @@ static int usb_emul_get_string(struct usb_string *strings, int index, return -EINVAL; }
-static struct usb_generic_descriptor **find_descriptor( +struct usb_generic_descriptor **usb_emul_find_descriptor( struct usb_generic_descriptor **ptr, int type, int index) { debug("%s: type=%x, index=%d\n", __func__, type, index); @@ -91,8 +91,7 @@ static int usb_emul_get_descriptor(struct usb_dev_platdata *plat, int value, length); }
- ptr = find_descriptor((struct usb_generic_descriptor **)plat->desc_list, - type, index); + ptr = usb_emul_find_descriptor(plat->desc_list, type, index); if (!ptr) { debug("%s: Could not find descriptor type %d, index %d\n", __func__, type, index); diff --git a/include/usb.h b/include/usb.h index 63edddd..3766514 100644 --- a/include/usb.h +++ b/include/usb.h @@ -1056,6 +1056,17 @@ int usb_emul_find(struct udevice *bus, ulong pipe, int port1, int usb_emul_find_for_dev(struct udevice *dev, struct udevice **emulp);
/** + * usb_emul_find_descriptor() - Find a USB descriptor of a particular device + * + * @ptr: a pointer to a list of USB descriptor pointers + * @type: type of USB descriptor to find + * @index: if @type is USB_DT_CONFIG, this is the configuration value + * @return a pointer to the USB descriptor found, NULL if not found + */ +struct usb_generic_descriptor **usb_emul_find_descriptor( + struct usb_generic_descriptor **ptr, int type, int index); + +/** * usb_emul_reset() - Reset all emulators ready for use * * Clear out any address information in the emulators and make then ready for

At present the usb hub emulator always reports its downstream port speed as full speed. Actually it is high speed for sandbox-flash, and low speed for sandbox-keyb. We can determine the device speed by checking its device descriptor bcdUSB field, and do the proper hub port status report based on that.
Signed-off-by: Bin Meng bmeng.cn@gmail.com ---
drivers/usb/emul/sandbox_hub.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/emul/sandbox_hub.c b/drivers/usb/emul/sandbox_hub.c index 8ed7a0f..9a0f47b 100644 --- a/drivers/usb/emul/sandbox_hub.c +++ b/drivers/usb/emul/sandbox_hub.c @@ -121,9 +121,12 @@ struct sandbox_hub_priv { int change[SANDBOX_NUM_PORTS]; };
-static struct udevice *hub_find_device(struct udevice *hub, int port) +static struct udevice *hub_find_device(struct udevice *hub, int port, + enum usb_device_speed *speed) { struct udevice *dev; + struct usb_generic_descriptor **gen_desc; + struct usb_device_descriptor **dev_desc;
for (device_find_first_child(hub, &dev); dev; @@ -131,8 +134,27 @@ static struct udevice *hub_find_device(struct udevice *hub, int port) struct sandbox_hub_platdata *plat;
plat = dev_get_parent_platdata(dev); - if (plat->port == port) + if (plat->port == port) { + gen_desc = plat->plat.desc_list; + gen_desc = usb_emul_find_descriptor(gen_desc, + USB_DT_DEVICE, 0); + dev_desc = (struct usb_device_descriptor **)gen_desc; + + switch (le16_to_cpu((*dev_desc)->bcdUSB)) { + case 0x0100: + *speed = USB_SPEED_LOW; + break; + case 0x0101: + *speed = USB_SPEED_FULL; + break; + case 0x0200: + default: + *speed = USB_SPEED_HIGH; + break; + } + return dev; + } }
return NULL; @@ -146,7 +168,8 @@ static int clrset_post_state(struct udevice *hub, int port, int clear, int set) int ret = 0;
if ((clear | set) & USB_PORT_STAT_POWER) { - struct udevice *dev = hub_find_device(hub, port); + enum usb_device_speed speed; + struct udevice *dev = hub_find_device(hub, port, &speed);
if (dev) { if (set & USB_PORT_STAT_POWER) { @@ -156,6 +179,10 @@ static int clrset_post_state(struct udevice *hub, int port, int clear, int set) if (!ret) { set |= USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE; + if (speed == USB_SPEED_LOW) + set |= USB_PORT_STAT_LOW_SPEED; + else if (speed == USB_SPEED_HIGH) + set |= USB_PORT_STAT_HIGH_SPEED; }
} else if (clear & USB_PORT_STAT_POWER) {

At present we only do device_remove() during usb stop. The DM API device_remove() only marks the device state as inactivated, but still keeps its USB topology (eg: parent, children, etc) in the DM device structure. There is no issue if we only start USB subsystem once and never stop it. But a big issue occurs when we do 'usb stop' and 'usb start' multiple times.
Strange things may be observed with current implementation, like: - the enumeration may report only 1 mass storage device is detected, but the total number of USB devices is correct. - USB keyboard does not work anymore after a bunch of 'usb reset' even if 'usb tree' shows it is correctly identified. - read/write flash drive via 'fatload usb' may complain "Bad device"
In fact, every time when USB host controller starts the enumeration process, it takes random time for each USB port to show up online, hence each USB device may appear in a different order from previous enumeration, and gets assigned to a totally different USB address. As a result, we end up using a stale USB topology in the DM device structure which still reflects the previous enumeration result, and it may create an exact same DM device name like generic_bus_0_dev_7 that is already in the DM device structure. And since the DM device structure is there, there is no device_bind() call to bind driver to the device during current enumeration process, eventually creating an inconsistent software representation of the hardware topology, a non-working USB subsystem.
The fix is to clear the unused USB topology in the usb_stop(), by calling device_unbind() on each controller's root hub device, and the unbinding will unbind all of its children automatically.
For Sandbox, we need scan the device tree each time when we start the USB stack, in order to re-create the emulated USB devices and bind drivers for them before we actually do the driver probe.
Signed-off-by: Bin Meng bmeng.cn@gmail.com ---
drivers/usb/host/usb-uclass.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index bc44fc3..8a9f810 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -164,6 +164,7 @@ int usb_get_max_xfer_size(struct usb_device *udev, size_t *size) int usb_stop(void) { struct udevice *bus; + struct udevice *rh; struct uclass *uc; struct usb_uclass_priv *uc_priv; int err = 0, ret; @@ -179,6 +180,18 @@ int usb_stop(void) ret = device_remove(bus, DM_REMOVE_NORMAL); if (ret && !err) err = ret; + + /* Locate root hub device */ + device_find_first_child(bus, &rh); + if (rh) { + /* + * All USB devices are children of root hub. + * Unbinding root hub will unbind all of its children. + */ + ret = device_unbind(rh); + if (ret && !err) + err = ret; + } } #ifdef CONFIG_BLK ret = blk_unbind_all(IF_TYPE_USB); @@ -262,6 +275,21 @@ int usb_init(void) /* init low_level USB */ printf("USB%d: ", count); count++; + +#ifdef CONFIG_SANDBOX + /* + * For Sandbox, we need scan the device tree each time when we + * start the USB stack, in order to re-create the emulated USB + * devices and bind drivers for them before we actually do the + * driver probe. + */ + ret = dm_scan_fdt_dev(bus); + if (ret) { + printf("Sandbox USB device scan failed (%d)\n", ret); + continue; + } +#endif + ret = device_probe(bus); if (ret == -ENODEV) { /* No such device. */ puts("Port not available.\n");

With the root hub unbinding in usb_stop(), there is no need to do a blk uclass specific unbind operation.
Signed-off-by: Bin Meng bmeng.cn@gmail.com ---
drivers/usb/host/usb-uclass.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index 8a9f810..bfc0556 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -193,11 +193,7 @@ int usb_stop(void) err = ret; } } -#ifdef CONFIG_BLK - ret = blk_unbind_all(IF_TYPE_USB); - if (ret && !err) - err = ret; -#endif + #ifdef CONFIG_SANDBOX struct udevice *dev;

With the root hub unbinding in usb_stop(), there is no need to do a Sandbox-specific reset operation. usb_emul_reset() is no longer used anywhere, drop it.
Signed-off-by: Bin Meng bmeng.cn@gmail.com ---
drivers/usb/emul/usb-emul-uclass.c | 8 -------- drivers/usb/host/usb-uclass.c | 11 ----------- include/usb.h | 8 -------- 3 files changed, 27 deletions(-)
diff --git a/drivers/usb/emul/usb-emul-uclass.c b/drivers/usb/emul/usb-emul-uclass.c index 359d0da..fbe11f3 100644 --- a/drivers/usb/emul/usb-emul-uclass.c +++ b/drivers/usb/emul/usb-emul-uclass.c @@ -294,14 +294,6 @@ int usb_emul_setup_device(struct udevice *dev, struct usb_string *strings, return 0; }
-void usb_emul_reset(struct udevice *dev) -{ - struct usb_dev_platdata *plat = dev_get_parent_platdata(dev); - - plat->devnum = 0; - plat->configno = 0; -} - UCLASS_DRIVER(usb_emul) = { .id = UCLASS_USB_EMUL, .name = "usb_emul", diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index bfc0556..4e40f4b 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -194,17 +194,6 @@ int usb_stop(void) } }
-#ifdef CONFIG_SANDBOX - struct udevice *dev; - - /* Reset all enulation devices */ - ret = uclass_get(UCLASS_USB_EMUL, &uc); - if (ret) - return ret; - - uclass_foreach_dev(dev, uc) - usb_emul_reset(dev); -#endif #ifdef CONFIG_USB_STORAGE usb_stor_reset(); #endif diff --git a/include/usb.h b/include/usb.h index 3766514..57a7d8d 100644 --- a/include/usb.h +++ b/include/usb.h @@ -1067,14 +1067,6 @@ struct usb_generic_descriptor **usb_emul_find_descriptor( struct usb_generic_descriptor **ptr, int type, int index);
/** - * usb_emul_reset() - Reset all emulators ready for use - * - * Clear out any address information in the emulators and make then ready for - * a new USB scan - */ -void usb_emul_reset(struct udevice *dev); - -/** * usb_show_tree() - show the USB device tree * * This shows a list of active USB devices along with basic information about

Now that we have changed to remove all devices under the root hub in usb_stop(), and corrected the USB emulator select logic, it makes no sense to do various tests based on 'usb tree' output since the order of devices is no longer fixed. Remove these USB test cases related to 'usb tree'.
For the USB remove test, ideally we should remove an emulator device node from the device tree, but this is so far not working. Change to test the 'usb stop' only.
Signed-off-by: Bin Meng bmeng.cn@gmail.com ---
test/dm/usb.c | 163 ++-------------------------------------------------------- 1 file changed, 5 insertions(+), 158 deletions(-)
diff --git a/test/dm/usb.c b/test/dm/usb.c index b46ae60..4fd249b 100644 --- a/test/dm/usb.c +++ b/test/dm/usb.c @@ -99,10 +99,10 @@ static int count_usb_devices(void) return count; }
-/* test that we can remove an emulated device and it is then not found */ -static int dm_test_usb_remove(struct unit_test_state *uts) +/* test that no USB devices are found after we stop the stack */ +static int dm_test_usb_stop(struct unit_test_state *uts) { - struct udevice *dev, *emul; + struct udevice *dev;
/* Scan and check that all devices are present */ state_set_skip_delays(true); @@ -112,164 +112,11 @@ static int dm_test_usb_remove(struct unit_test_state *uts) ut_assertok(uclass_get_device(UCLASS_MASS_STORAGE, 2, &dev)); ut_asserteq(6, count_usb_devices()); ut_assertok(usb_stop()); - ut_asserteq(6, count_usb_devices()); - - /* Remove the second emulation device */ - ut_assertok(uclass_find_device_by_name(UCLASS_USB_EMUL, "flash-stick@1", - &dev)); - ut_assertok(device_unbind(dev)); - - /* Rescan - only the first and third should be present */ - ut_assertok(usb_init()); - ut_assertok(uclass_get_device(UCLASS_MASS_STORAGE, 0, &dev)); - ut_assertok(usb_emul_find_for_dev(dev, &emul)); - ut_asserteq_str("flash-stick@0", emul->name); - ut_assertok(uclass_get_device(UCLASS_MASS_STORAGE, 1, &dev)); - ut_assertok(usb_emul_find_for_dev(dev, &emul)); - ut_asserteq_str("flash-stick@2", emul->name); - - ut_asserteq(-ENODEV, uclass_get_device(UCLASS_MASS_STORAGE, 2, &dev)); - - ut_asserteq(5, count_usb_devices()); - ut_assertok(usb_stop()); - ut_asserteq(5, count_usb_devices()); - - return 0; -} -DM_TEST(dm_test_usb_remove, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); - -const char usb_tree_base[] = -" 1 Hub (12 Mb/s, 100mA)\n" -" | sandbox hub 2345\n" -" |\n" -" |\b+-2 Mass Storage (12 Mb/s, 100mA)\n" -" | sandbox flash flash-stick@0\n" -" | \n" -" |\b+-3 Mass Storage (12 Mb/s, 100mA)\n" -" | sandbox flash flash-stick@1\n" -" | \n" -" |\b+-4 Mass Storage (12 Mb/s, 100mA)\n" -" | sandbox flash flash-stick@2\n" -" | \n" -" |\b+-5 Human Interface (12 Mb/s, 100mA)\n" -" sandbox keyboard keyb@3\n" -" \n"; - -/* test that the 'usb tree' command output looks correct */ -static int dm_test_usb_tree(struct unit_test_state *uts) -{ - char *data; - int len; - - state_set_skip_delays(true); - ut_assertok(usb_init()); - console_record_reset_enable(); - usb_show_tree(); - len = membuff_getraw(&gd->console_out, -1, true, &data); - if (len) - data[len] = '\0'; - ut_asserteq_str(usb_tree_base, data); - ut_assertok(usb_stop()); - - return 0; -} -DM_TEST(dm_test_usb_tree, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); - -const char usb_tree_remove[] = -" 1 Hub (12 Mb/s, 100mA)\n" -" | sandbox hub 2345\n" -" |\n" -" |\b+-2 Mass Storage (12 Mb/s, 100mA)\n" -" | sandbox flash flash-stick@0\n" -" | \n" -" |\b+-3 Mass Storage (12 Mb/s, 100mA)\n" -" | sandbox flash flash-stick@2\n" -" | \n" -" |\b+-4 Human Interface (12 Mb/s, 100mA)\n" -" sandbox keyboard keyb@3\n" -" \n"; - -/* - * test that the 'usb tree' command output looks correct when we remove a - * device - */ -static int dm_test_usb_tree_remove(struct unit_test_state *uts) -{ - struct udevice *dev; - char *data; - int len; - - /* Remove the second emulation device */ - ut_assertok(uclass_find_device_by_name(UCLASS_USB_EMUL, "flash-stick@1", - &dev)); - ut_assertok(device_unbind(dev)); - - state_set_skip_delays(true); - ut_assertok(usb_init()); - console_record_reset_enable(); - usb_show_tree(); - len = membuff_getraw(&gd->console_out, -1, true, &data); - if (len) - data[len] = '\0'; - ut_asserteq_str(usb_tree_remove, data); - ut_assertok(usb_stop()); - - return 0; -} -DM_TEST(dm_test_usb_tree_remove, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); - -const char usb_tree_reorder[] = -" 1 Hub (12 Mb/s, 100mA)\n" -" | sandbox hub 2345\n" -" |\n" -" |\b+-2 Mass Storage (12 Mb/s, 100mA)\n" -" | sandbox flash flash-stick@0\n" -" | \n" -" |\b+-3 Mass Storage (12 Mb/s, 100mA)\n" -" | sandbox flash flash-stick@2\n" -" | \n" -" |\b+-4 Human Interface (12 Mb/s, 100mA)\n" -" | sandbox keyboard keyb@3\n" -" | \n" -" |\b+-5 Mass Storage (12 Mb/s, 100mA)\n" -" sandbox flash flash-stick@1\n" -" \n"; - -/* - * test that the 'usb tree' command output looks correct when we reorder two - * devices. - */ -static int dm_test_usb_tree_reorder(struct unit_test_state *uts) -{ - struct udevice *dev, *parent; - char *data; - int len; - - /* Remove the second emulation device */ - ut_assertok(uclass_find_device_by_name(UCLASS_USB_EMUL, "flash-stick@1", - &dev)); - parent = dev->parent; - - /* Reorder the devices in the parent list and uclass list */ - list_del(&dev->sibling_node); - list_add_tail(&dev->sibling_node, &parent->child_head); - - list_del(&dev->uclass_node); - list_add_tail(&dev->uclass_node, &dev->uclass->dev_head); - - state_set_skip_delays(true); - ut_assertok(usb_init()); - console_record_reset_enable(); - usb_show_tree(); - len = membuff_getraw(&gd->console_out, -1, true, &data); - if (len) - data[len] = '\0'; - ut_asserteq_str(usb_tree_reorder, data); - ut_assertok(usb_stop()); + ut_asserteq(0, count_usb_devices());
return 0; } -DM_TEST(dm_test_usb_tree_reorder, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); +DM_TEST(dm_test_usb_stop, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
static int dm_test_usb_keyb(struct unit_test_state *uts) {

On 10/01/2017 03:19 PM, Bin Meng wrote:
This parameter is never used.
Signed-off-by: Bin Meng bmeng.cn@gmail.com
Applied all to u-boot-usb/master , buildtesting .
drivers/usb/emul/sandbox_flash.c | 3 +-- drivers/usb/emul/sandbox_hub.c | 3 +-- drivers/usb/emul/sandbox_keyb.c | 3 +-- drivers/usb/emul/usb-emul-uclass.c | 4 ++-- include/usb.h | 5 ++--- 5 files changed, 7 insertions(+), 11 deletions(-)
diff --git a/drivers/usb/emul/sandbox_flash.c b/drivers/usb/emul/sandbox_flash.c index 98d20c0..2f84b36 100644 --- a/drivers/usb/emul/sandbox_flash.c +++ b/drivers/usb/emul/sandbox_flash.c @@ -390,8 +390,7 @@ static int sandbox_flash_bind(struct udevice *dev) fs[2].id = STRINGID_SERIAL; fs[2].s = dev->name;
- return usb_emul_setup_device(dev, PACKET_SIZE_64, plat->flash_strings,
flash_desc_list);
- return usb_emul_setup_device(dev, plat->flash_strings, flash_desc_list);
}
static int sandbox_flash_probe(struct udevice *dev) diff --git a/drivers/usb/emul/sandbox_hub.c b/drivers/usb/emul/sandbox_hub.c index 1432858..9ed7000 100644 --- a/drivers/usb/emul/sandbox_hub.c +++ b/drivers/usb/emul/sandbox_hub.c @@ -274,8 +274,7 @@ static int sandbox_hub_submit_control_msg(struct udevice *bus,
static int sandbox_hub_bind(struct udevice *dev) {
- return usb_emul_setup_device(dev, PACKET_SIZE_64, hub_strings,
hub_desc_list);
- return usb_emul_setup_device(dev, hub_strings, hub_desc_list);
}
static int sandbox_child_post_bind(struct udevice *dev) diff --git a/drivers/usb/emul/sandbox_keyb.c b/drivers/usb/emul/sandbox_keyb.c index 2735985..cff0176 100644 --- a/drivers/usb/emul/sandbox_keyb.c +++ b/drivers/usb/emul/sandbox_keyb.c @@ -208,8 +208,7 @@ static int sandbox_keyb_bind(struct udevice *dev) fs[2].id = STRINGID_SERIAL; fs[2].s = dev->name;
- return usb_emul_setup_device(dev, PACKET_SIZE_8, plat->keyb_strings,
keyb_desc_list);
- return usb_emul_setup_device(dev, plat->keyb_strings, keyb_desc_list);
}
static int sandbox_keyb_probe(struct udevice *dev) diff --git a/drivers/usb/emul/usb-emul-uclass.c b/drivers/usb/emul/usb-emul-uclass.c index 6e03c1e..e4a267b 100644 --- a/drivers/usb/emul/usb-emul-uclass.c +++ b/drivers/usb/emul/usb-emul-uclass.c @@ -229,8 +229,8 @@ int usb_emul_int(struct udevice *emul, struct usb_device *udev, return ops->interrupt(emul, udev, pipe, buffer, length, interval); }
-int usb_emul_setup_device(struct udevice *dev, int maxpacketsize,
struct usb_string *strings, void **desc_list)
+int usb_emul_setup_device(struct udevice *dev, struct usb_string *strings,
void **desc_list)
{ struct usb_dev_platdata *plat = dev_get_parent_platdata(dev); struct usb_generic_descriptor **ptr; diff --git a/include/usb.h b/include/usb.h index 0ddc082..1563c9a 100644 --- a/include/usb.h +++ b/include/usb.h @@ -976,7 +976,6 @@ int usb_get_max_xfer_size(struct usb_device *dev, size_t *size);
- the USB emulation uclass about the features of the emulator.
- @dev: Emulation device
- @maxpacketsize: Maximum packet size (e.g. PACKET_SIZE_64)
- @strings: List of USB string descriptors, terminated by a NULL
entry
- @desc_list: List of points or USB descriptors, terminated by NULL.
@@ -984,8 +983,8 @@ int usb_get_max_xfer_size(struct usb_device *dev, size_t *size);
and others follow on after that.
- @return 0 if OK, -ENOSYS if not implemented, other -ve on error
*/ -int usb_emul_setup_device(struct udevice *dev, int maxpacketsize,
struct usb_string *strings, void **desc_list);
+int usb_emul_setup_device(struct udevice *dev, struct usb_string *strings,
void **desc_list);
/**
- usb_emul_control() - Send a control packet to an emulator
participants (2)
-
Bin Meng
-
Marek Vasut