Skip to content

wifi: ath9k: Add PTP patch from wifi-ptp project #6882

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

Draft
wants to merge 3 commits into
base: rpi-6.12.y
Choose a base branch
from

Conversation

6by9
Copy link
Contributor

@6by9 6by9 commented Jun 4, 2025

@6by9
Copy link
Contributor Author

6by9 commented Jun 4, 2025

I am NOT proposing that this gets merged here, but created it for #4358

Copy link
Contributor

@jacob-keller jacob-keller left a comment

Choose a reason for hiding this comment

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

Here's what I think you want to implement, assuming sc->cc_mult is the base multiplier. I also suggested converting the ath_warn to ath_dbg so that its not spammy unless enabled as frequency can be adjusted multiple times per second depending on the synchronization rate. Hope this helps!

mult = sc->cc_mult;
adj = mult;
adj *= scaled_ppm;
diff = div_u64(adj, 1000000000ULL);
Copy link
Contributor

Choose a reason for hiding this comment

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

The mistake here is still using 1,000,000,000 (1 billion). You need to use 1million * 2^16, but you can actually just replace this all with adjust_by_scaled_ppm.

Choose a reason for hiding this comment

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

thank you!

Comment on lines 8 to 18
#if 0
struct ath_softc *sc = container_of(ptp, struct ath_softc, ptp_clock_info);
unsigned long flags;
int neg_adj = 0;
u32 mult, diff;
u64 adj;

if (scaled_ppm < 0) {
neg_adj = -1;
scaled_ppm = -scaled_ppm;
}
mult = sc->cc_mult;
adj = mult;
adj *= scaled_ppm;
diff = div_u64(adj, 1000000000ULL);

spin_lock_irqsave(&sc->systim_lock, flags);
timecounter_read(&sc->tc);
sc->cc.mult = neg_adj ? mult - diff : mult + diff;
spin_unlock_irqrestore(&sc->systim_lock, flags);

ath_warn(ath9k_hw_common(sc->sc_ah), "phc adjust adj=%llu freq=%u\n", adj, diff);
#endif

return 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#if 0
struct ath_softc *sc = container_of(ptp, struct ath_softc, ptp_clock_info);
unsigned long flags;
int neg_adj = 0;
u32 mult, diff;
u64 adj;
if (scaled_ppm < 0) {
neg_adj = -1;
scaled_ppm = -scaled_ppm;
}
mult = sc->cc_mult;
adj = mult;
adj *= scaled_ppm;
diff = div_u64(adj, 1000000000ULL);
spin_lock_irqsave(&sc->systim_lock, flags);
timecounter_read(&sc->tc);
sc->cc.mult = neg_adj ? mult - diff : mult + diff;
spin_unlock_irqrestore(&sc->systim_lock, flags);
ath_warn(ath9k_hw_common(sc->sc_ah), "phc adjust adj=%llu freq=%u\n", adj, diff);
#endif
return 0;
struct ath_softc *sc = container_of(ptp, struct ath_softc, ptp_clock_info);
unsigned long flags;
spin_lock_irqsave(&sc->systim_lock, flags);
timecounter_read(&sc->tc);
sc->cc.mult = adjust_by_scaled_ppm(sc->cc_mult, scaled_ppm);
spin_unlock_irqrestore(&sc->systim_lock, flags);
ath_dbg(ath9k_hw_common(sc->sc_ah), ATH_DBG_CONFIG, "phc adjust adj=%llu freq=%u\n", adj, diff);
return 0;

Copy link
Contributor

Choose a reason for hiding this comment

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

The whitespace is probably not correct here for kernel style, but you should get the idea. You could also pull adjust_by_scaled_ppm to outside the lock, but I don't think its necessary, since its really just a few multiplications and division.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whitespace and coding style are a bit of a mess generally with these changes, but that can be a task for others to fix up if they were ever to think of upstreaming them (I have no idea if it would even be considered upstream).
I did try a checkpatch --fix-inplace, but it only addressed a small fraction of the issues.

@6by9 6by9 force-pushed the rpi-6.12.y-ath9k-ptp branch from 3b8126e to 8b8afcd Compare June 12, 2025 16:35
Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
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.

3 participants