Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USB: Fix reconnect issues #16193

Merged
merged 8 commits into from
May 22, 2019
Merged

Conversation

finikorg
Copy link
Collaborator

@finikorg finikorg commented May 16, 2019

I still need to check suspend / resume properly working.

Fixes #15917

@finikorg finikorg changed the title USB: Fix reconnect issues WIP: USB: Fix reconnect issues May 16, 2019
@jfischer-no jfischer-no added area: USB Universal Serial Bus bug The issue is a bug, or the PR is fixing a bug labels May 16, 2019
@finikorg finikorg force-pushed the disconnect branch 2 times, most recently from 4c9413a to d53a683 Compare May 16, 2019 13:00
subsys/usb/usb_device.c Outdated Show resolved Hide resolved
Copy link
Collaborator

@loicpoulain loicpoulain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@barsok barsok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found an issue which rakon then reported -- fixed. Verified on an own piece of HW.

Copy link
Collaborator

@masz-nordic masz-nordic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows USB3CV tests to be executed again, but following cases from Chapter 9 Tests still fail:

  • TD 9.1, 9.2, 9.3, 9.4, 9.5, 9.7 in Configured state:

    • Set Configuration failed for Configuration Value : 1
    • (1.1.2) Devices must support being set to Addressed/Configured state.
  • TD 9.9, 9.13:

    • Set Configuration failed for Configuration Value : 1
    • (1.1.2) Devices must support being set to Addressed/Configured state.
  • TD 9.16:

    • Enumeration failed at iteration 1 (General failure)

@finikorg
Copy link
Collaborator Author

This allows USB3CV tests to be executed again, but following cases from Chapter 9 Tests still fail:

* TD 9.1, 9.2, 9.3, 9.4, 9.5, 9.7 in Configured state:
  
  * `Set Configuration failed for Configuration Value : 1`
  * `(1.1.2) Devices must support being set to Addressed/Configured state.`

* TD 9.9, 9.13:
  
  * `Set Configuration failed for Configuration Value : 1`
  * `(1.1.2) Devices must support being set to Addressed/Configured state.`

* TD 9.16:
  
  * `Enumeration failed at iteration 1 (General failure)`

Are those failures resulting from the PR? Can they be reproduced on master?

@masz-nordic
Copy link
Collaborator

On master the USB3CV tests do not work at all:

SetConfiguration() failed.
  No device:  deleting node!
  Device configuration failed!
  SetConfiguration() failed.
  No device:  deleting node!
  Device configuration failed!
A device was not found.  
Check that device is plugged into correct port.
Couldn't initialize common subsystems.
Function CVCommon_InitializeTestSuite did not succeed.  Return value = 0x80000000

@finikorg
Copy link
Collaborator Author

On master the USB3CV tests do not work at all:

SetConfiguration() failed.
  No device:  deleting node!
  Device configuration failed!
  SetConfiguration() failed.
  No device:  deleting node!
  Device configuration failed!
A device was not found.  
Check that device is plugged into correct port.
Couldn't initialize common subsystems.
Function CVCommon_InitializeTestSuite did not succeed.  Return value = 0x80000000

OK, This is probably because of extra checks we have added. I think we should address this in a separate issue.

@finikorg
Copy link
Collaborator Author

@masz-nordic Does this fix the issues?

diff --git a/subsys/usb/usb_device.c b/subsys/usb/usb_device.c
index 9e70966d10..765766cd5d 100644
--- a/subsys/usb/usb_device.c
+++ b/subsys/usb/usb_device.c
@@ -500,7 +500,6 @@ static bool set_endpoint(const struct usb_ep_descriptor *ep_desc)
 
        if (usb_dc_ep_enable(ep_cfg.ep_addr) < 0) {
                LOG_ERR("Failed to enable endpoint %x", ep_cfg.ep_addr);
-               return false;
        }
 
        usb_dev.configured = true;

@masz-nordic
Copy link
Collaborator

@finikorg It fixes 9.1, 9.2, 9.3, 9.4, 9.5, 9.7 in Configured state and 9.9. But 9.13 and 9.16 still fail.
Additionally, there are new failures:

  • 9.1, 9.2, 9.3, 9.4, 9.5, 9.7 in Default state
  • 9.1, 9.2, 9.3, 9.4, 9.5, 9.7 in Addressed state

All of them fail with:

Set Configuration failed for Configuration Value : 0
(1.1.2) Devices must support being set to Addressed/Configured state.

@finikorg
Copy link
Collaborator Author

Then we need to "fix" another bug :)

        if (usb_dc_ep_configure(&ep_cfg) < 0) {
                LOG_ERR("Failed to configure endpoint %x", ep_cfg.ep_addr);
-               return false;
        }

@masz-nordic
Copy link
Collaborator

Still same failures as in previous case. Logs:

[00:01:11.285,858] <dbg> usb_hid.hid_custom_handle_req: Standard request: bRequest 0x9 bmRequestType 0x0 len 0
[00:01:11.285,858] <dbg> usb_device.usb_handle_std_device_req: REQ_SET_CONFIGURATION, conf 0x0
[00:01:11.285,858] <dbg> usb_device.usb_set_configuration: Device not configured - invalid configuration
[00:01:11.285,888] <dbg> usb_hid.hid_status_cb: cfg 0x200033a8 status 3
[00:01:11.285,888] <dbg> usb_hid.hid_do_status_cb: USB device configured
[00:01:11.285,888] <dbg> usb_device.usb_handle_std_device_req: USB Set Configuration failed
[00:01:11.285,888] <dbg> usb_device.usb_handle_request: Handler Error 0
[00:01:11.285,919] <dbg> usb_device.usb_print_setup: Setup: 0 9 0 0 0
[00:01:11.285,919] <dbg> usb_device.usb_handle_control_transfer: usb_handle_request failed

@finikorg
Copy link
Collaborator Author

@masz-nordic what sample are you using? I had tests with frdm_k64f and HID it was passing all tests.

@masz-nordic
Copy link
Collaborator

@finikorg hid-mouse with nrf52840_pca10056.

@jfischer-no
Copy link
Collaborator

jfischer-no commented May 20, 2019

@masz-nordic Can you please apply and test again? (https://gist.github.com/acsplayon/b594d6b2207f8923edb071fdee499b36)

diff --git a/drivers/usb/device/usb_dc_nrfx.c b/drivers/usb/device/usb_dc_nrfx.c
index e3ba244b9c..86c7e39351 100644
--- a/drivers/usb/device/usb_dc_nrfx.c
+++ b/drivers/usb/device/usb_dc_nrfx.c
@@ -637,6 +637,8 @@ static void ep_ctx_reset(struct nrf_usbd_ep_ctx *ep_ctx)
        ep_ctx->buf.curr = ep_ctx->buf.data;
        ep_ctx->buf.len  = 0U;
 
+       ep_ctx->cfg.en = false;
+
        ep_ctx->read_complete = true;
        ep_ctx->read_pending = false;
        ep_ctx->write_in_progress = false;

@masz-nordic
Copy link
Collaborator

@jfischer-phytec-iot This fixes 9.16. Other still fail, here is the trace from Default state tests:

16193

If this is nRF specific issue and this PR fixes USB3CV for other platforms, let's merge it and I will investigate fails in a separate case.

@finikorg
Copy link
Collaborator Author

I have tested frdm_k64f, stm32f723e_disco, nucleo_f412zg they are all passing, I will check also reel_board.

@jfischer-no jfischer-no changed the title WIP: USB: Fix reconnect issues USB: Fix reconnect issues May 20, 2019
Copy link
Collaborator

@jfischer-no jfischer-no left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@finikorg
Copy link
Collaborator Author

@masz-nordic Tests are passing for reel_board also if I disable USB_DEVICE_REMOTE_WAKEUP

Add usb_cancel_transfers() helper to cancel all ongoing transfers.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Only call callback when transfer is not cancelled.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Cancel all usb transfers when receiving USB_DC_DISCONNECTED.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Add extra logs catching problem with re-enabling endpoints.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Fix supended -> suspended.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Disable endpoints on following events: USB_DC_DISCONNECTED
and USB_DC_SUSPEND.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Fixes USB3CV Tool tests. One case is enabling endpoints with Set
Interface after Set Configuration. In this case we report warning and
continue without returning error.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Set false to enable flag on USB Reset.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
@masz-nordic
Copy link
Collaborator

@finikorg: Which test mode are you using? I have tested reel_board with Compliance Test on Chapter 9 Tests [USB 2 devices] and it still fails.

@finikorg
Copy link
Collaborator Author

@finikorg: Which test mode are you using? I have tested reel_board with Compliance Test on Chapter 9 Tests [USB 2 devices] and it still fails.

Yes Compliance "Chapter 9 Tests [USB 2 devices]", only Remote Wakeup TD 9.12 is failing.

I am on top of my above mentioned PR, my reel_board is the oldest version, probably you have newer one?

@jfischer-no
Copy link
Collaborator

@masz-nordic Anything against to merge it?

@masz-nordic
Copy link
Collaborator

@finikorg Mine is 1507.1. I disabled remote wakeup in Kconfig (apart from prj.conf) too and now it only fails 9.21 and 9.16.

@jfischer-phytec-iot No, if this fixes problems from the original issue it is fine. I will create a separate one for USB3CV testcases.

@nashif nashif requested a review from rakons May 21, 2019 20:15
@carlescufi carlescufi merged commit 03ef375 into zephyrproject-rtos:master May 22, 2019
@finikorg finikorg deleted the disconnect branch May 22, 2019 11:41
jfischer-no pushed a commit to jfischer-no/zephyr that referenced this pull request Apr 13, 2023
This reverts commit f206170
introduced as workaround for nRF USBD device controller in PR
zephyrproject-rtos#16193.

This commit may be reverted due to changes made in
commit e326c58
("usb: device: Do not cancel transfers on suspend").

Signed-off-by: Nickolas Lapp <nickolaslapp@gmail.com>
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
carlescufi pushed a commit that referenced this pull request Apr 17, 2023
This reverts commit f206170
introduced as workaround for nRF USBD device controller in PR
#16193.

This commit may be reverted due to changes made in
commit e326c58
("usb: device: Do not cancel transfers on suspend").

Signed-off-by: Nickolas Lapp <nickolaslapp@gmail.com>
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
coreboot-org-bot pushed a commit to coreboot/zephyr-cros that referenced this pull request Apr 18, 2023
This reverts commit f206170
introduced as workaround for nRF USBD device controller in PR
zephyrproject-rtos/zephyr#16193.

This commit may be reverted due to changes made in
commit e326c58
("usb: device: Do not cancel transfers on suspend").

(cherry picked from commit 81e4934)

Original-Signed-off-by: Nickolas Lapp <nickolaslapp@gmail.com>
Original-Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
GitOrigin-RevId: 81e4934
Change-Id: I1ee50ed7ec2f84e30c5c7df1c359277889b58b42
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/4432938
Tested-by: CopyBot Service Account <copybot.service@gmail.com>
Commit-Queue: Keith Short <keithshort@chromium.org>
Tested-by: Keith Short <keithshort@chromium.org>
Reviewed-by: Keith Short <keithshort@chromium.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: USB Universal Serial Bus bug The issue is a bug, or the PR is fixing a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

USB disconnect/reconnect
7 participants