Page MenuHomeFreeBSD

USB4 initial work on suspend routine
Needs ReviewPublic

Authored by obiwac on Mar 22 2025, 1:50 AM.
Tags
Referenced Files
F172483545: D49453.diff
Fri, Sep 18, 7:04 PM
Unknown Object (File)
Thu, Sep 17, 4:39 PM
Unknown Object (File)
Wed, Sep 16, 11:23 PM
Unknown Object (File)
Tue, Sep 15, 4:07 PM
Unknown Object (File)
Tue, Sep 15, 11:26 AM
Unknown Object (File)
Tue, Sep 8, 1:41 AM
Unknown Object (File)
Mon, Sep 7, 7:19 PM
Unknown Object (File)
Wed, Sep 2, 9:54 PM
Subscribers

Details

Summary

Initial work on a suspend routine for USB4 on v1.0 host interfaces. At the moment I'm not quite concerned about resume, as it would already be quite nice to be able to suspend USB4 routers as this is a prerequisite for S0i3 on AMD.

This will also work on v2.0, but we might want to handle this differently in the future for these hosts.

Test Plan

Tested on AMD Pink Sardine controller (1022:1668/9), which is host interface version 1.0. The SLPR (sleep ready) bit is being set by the hardware.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 63048
Build 59932: arc lint + arc unit

Event Timeline

sys/dev/thunderbolt/router.c
379

Why don't we want these events?

394

Do we want to be verbose about being in this state to see if we need to implement this or if we can punt? Or is it a 'gotta do eventually'?

396

50ms is a long time to wait here...

408

And we wait 50ms multiple times. 100 if I'm reading the code right 5 seconds sleeping in a suspend path seems potentially unwise if we have to do this for multiple bridges. Is there a way to avoid that?

419

This will prevent the whole system from shutting down.... how likely is this timeout?

sys/dev/thunderbolt/router.c
379

Sorry, I should make this clearer.

The initial work on USB4 is meant to get suspend working well enough for the firmware on AMD systems to enter S0i3, since these are handed over to the OS in a powered-on state. Currently, I want to make sure we don't wake up for any reasons as I'm not handling resume and am not intending to handle resume in the near future.

394

I think leaving as is fine; the spec just mentions that, while we can wait for ROP_CMPLT on v2, polling as on v1 routers is also fine. So more of a "gotta do eventually".

396

This comes from tSetSR and is the time between setting SLP and SLPR being set by the router.

408

Actually, I think tSetSR is the maximum time the router has to set SLPR after SLP. I will double check this tomorrow, because this means we can immediately poll once every maybe 5 ms a maximum of 10 times.

419

I'm guessing this is unlikeley but if this is the case then I'll downgrade this to a simple warning I guess.

Don't touch router defines; this should be done in D49452.

The changes seem reasonable. My general concerns with the change are just related to documentation, follow up and potential future collaboration (especially if I start helping out in this space in the next few months).

sys/dev/thunderbolt/nhi.c
429

I assume that the only reason why we don't have resume code after this change is that we don't actually properly initialize NHI today. Is that correct? If so, this warrants another TODO and follow up issue.

sys/dev/thunderbolt/router.c
379

Sorry, I should make this clearer.

The initial work on USB4 is meant to get suspend working well enough for the firmware on AMD systems to enter S0i3, since these are handed over to the OS in a powered-on state. Currently, I want to make sure we don't wake up for any reasons as I'm not handling resume and am not intending to handle resume in the near future.

I seems like it deserves documentation in the manpage and comment, as well as a tracking issue: this helps avoid the scenario where a random user will file a bug saying the feature doesn't work ("it's already documented clearly here") and helps encourage those who have the knowledge/capability to collaborate with enhancements/fixes.

404

Please use NHI_SLPR_WAIT_US instead of 50 ms here (using another constant to convert from microseconds to milliseconds is reasonable because the constant is expressed in microseconds).

417–418

Please keep the string constant/format strings intact so it's greppable by humans.

425–427

Please file a follow up issue here.

sys/dev/thunderbolt/nhi.c
429

Fair point, either way there should be a comment here explaining why nhi_resume does nothing.

sys/dev/thunderbolt/router.c
417–418

As an aside, we should note this in style(9) if we don't already

obiwac marked 8 inline comments as done.

rebase + respond to comments

sys/dev/thunderbolt/router.c
404

opted to just do / 1000 inline because no existing constant and this is obvious enough

417–418

what exactly should style(9) say about this? i unwrapped this line because it was <= 80 chars anyway, but if the string makes the line significantly longer we should wrap anyway. what's the threshold?

419

actually I think it is best for this to error hard. I don't want people thinking they can enter S0i3 when actually they aren't (because this driver failed to suspend). I am in the process of adding some proactive diagnostics if we know we didn't enter S0i3 on resume, but I'd still like to keep it like this. We can replace with return (0); if this causes problems for people using S3 once we load this kernel module by default

425–427

should i really file bugzilla PRs for each TODO I have in my code? this is all very unfinished anyway...