Skip to content

Handle PSP asynchronous USB receive cancellation and retries - #76

Open
fjtrujy wants to merge 1 commit into
masterfrom
fix/psp-async-receive-lifecycle
Open

fjtrujy wants to merge 1 commit into
masterfrom
fix/psp-async-receive-lifecycle

Conversation

@fjtrujy

@fjtrujy fjtrujy commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Scope

This PR isolates PSP asynchronous USB receive lifecycle and cleanup from the earlier combined #72.

  • Process detach before an async receive completion and do not submit requests when the connection is gone.
  • Handle successful zero-length completions by rearming the receive endpoint, without treating a zero-length USB packet as an error.
  • Treat retcode == -3 as cancellation (per PSPSDK), not as a transient I/O error; clear the connected state and wait for the usual attach/HELLO handshake instead of resubmitting on a cancelled endpoint.
  • For other receive errors, schedule a retry through a 100 ms timed event wait rather than blocking the USB event thread with sceKernelDelayThread. Detach/attach events remain serviceable while waiting.
  • Retry a failed sceUsbbdReqRecv() submission while the USB bus remains connected, rather than logging once and permanently losing the receiver.
  • Validate the receive length before copying data and check sceUsbGetState() & PSP_USB_CONNECTION_ESTABLISHED before queueing new work.
  • Only mark connected after the initial async receive has been queued successfully; clear connection state on start/stop and fix the event flag cleanup assignment.

Verification

  • make -C usbhostfs -j4 with the installed PSP SDK: passes.
  • make -C tests test: existing host C regression passes.
  • git diff --check: passes.
  • Rebased onto current master so already merged directory, host handle and PSP bulk-transfer fixes are not reverted or duplicated.

Remaining validation

The revised cancelled/error/zero-length completion logic has not been tested on a physical PSP yet. In particular we need to exercise USB disconnect/reconnect, error and cancellation behavior. Build success and a host-side test do not validate the PSP's kernel USB request lifecycle.

The independently investigated long-idle hang remains tracked in #74; this PR does not claim to fix its root cause. Please re-review the revised async error handling before merging.

@fjtrujy
fjtrujy force-pushed the fix/psp-async-receive-lifecycle branch from 33775b2 to bd55cc8 Compare October 29, 2026 08:58
@fjtrujy fjtrujy changed the title Rearm PSP asynchronous USB receives after errors Handle PSP asynchronous USB receive cancellation and retries Oct 29, 2026
Distinguish successful empty completions, cancelled receive requests and retryable errors. Handle detach before async completion, verify USB state before rearming, and retry transient failures through timed event waits without blocking attach/detach processing.

Validate receive bounds, mark connected only after successful initial submission and fix event flag cleanup during module shutdown.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants