Page MenuHomeFreeBSD

Porting athn from OpenBSD
Needs RevisionPublic

Authored by farhan_farhan.codes on Apr 18 2025, 3:39 AM.
Referenced Files
Unknown Object (File)
Sun, Oct 12, 5:46 PM
Unknown Object (File)
Wed, Oct 8, 8:50 PM
Unknown Object (File)
Thu, Oct 2, 3:55 AM
Unknown Object (File)
Tue, Sep 23, 8:48 AM
Unknown Object (File)
Sep 16 2025, 8:54 PM
Unknown Object (File)
Sep 15 2025, 12:59 AM
Unknown Object (File)
Sep 14 2025, 10:46 PM
Unknown Object (File)
Sep 12 2025, 9:13 AM

Details

Reviewers
adrian
bz
aokblast
Summary

Hi all,

I recently restarted my port of athn from OpenBSD. I began this effort in February 2022, forgot about it due to personal commitments, then restarted. I am working off USB device 0cf3:9271. I did not include OpenBSD's if_athn_pci.c, which I would not be able to test on. I kept the basic structure from OpenBSD, such as if_usb_attachhook, will flatten later.

Current state:

  • Attaches USB bus
  • Loads and processes firmware (ugh, that was tough)
  • Read/Write to registers work
  • athn_usb_attach -> athn_attach seem to work, though I may have made mistakes in porting.
  • Slowly uncommenting athn_parent -> athn_usb_init -> athn_init code, seems to work without a problem.

Current problems:

  • When I unload/unattach the driver, it causes the system to fully lock up only after athn_attach runs -- very frustrating, as it slows down development.
  • When I run ifconfig wlan0 up, it causes ifconfig to never end and Control-C does not terminate the process -- lower priority because I'm still working through the init code.
  • It's possible I messed up somewhere in the porting in athn_usb_attach and athn_attach.

My git repo is here: https://github.com/khanzf/freebsd-src/tree/ar9271-revived

Test Plan

Compile and load 3 modules in this order

make -C /usr/src/sys/modules/athnfw/ar9271fw load
make -C /usr/src/sys/modules/athn_usb unload
make -C /usr/src/sys/modules/athn unload

You should see debugging messages and the ieee80211_announce message.
Turn the device on with ifconfig wlan0 up but it will lock up the terminal.

Currently, unloading the module *will* cause your system to lock up. I do not know why yet.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

I think the current idea is avoiding directly import firmware file into repo. Perhaps we can separate the firmware out. The current approach is using firmware ports/pkg, before having that, we can just put it somewhere and ask people to grab it and put to the required place, for testing.

sys/contrib/dev/athn/LICENSE
2

Just be curious, is this a Realtek or Atheros product?

sys/contrib/dev/athn/LICENSE
2

Atheros device.

I think the current idea is avoiding directly import firmware file into repo. Perhaps we can separate the firmware out. The current approach is using firmware ports/pkg, before having that, we can just put it somewhere and ask people to grab it and put to the required place, for testing.

Or point them at the linux wireless firmware archive repo....

In D49884#1137462, @imp wrote:

I think the current idea is avoiding directly import firmware file into repo. Perhaps we can separate the firmware out. The current approach is using firmware ports/pkg, before having that, we can just put it somewhere and ask people to grab it and put to the required place, for testing.

Or point them at the linux wireless firmware archive repo....

Acknowledged. Might take me a bit of time.

farhan_farhan.codes marked an inline comment as done.

Working to update the athn_usb_init, currently working through the newstate handler.

Current Problem: Running into a recursive mutex based on FreeBSD/OpenBSD mutex styles.

Explanation:

FreeBSD and OpenBSD's locking mechanism is very different.
FreeBSD's idiom locks at the newstate call.
OpenBSD locks at the USB transfer equivalent.

Slowly reconciling the two.

Stuck on athn_usb_detach code or executes athn_usb_stop multiple times
I suspect this is due to the msleep on one threat and a wakeup on another, but I am not certain how to isolate the problem.

bz requested changes to this revision.Jul 9 2025, 10:54 PM
bz added a subscriber: bz.
bz added inline comments.
sys/contrib/dev/athn/LICENSE
2

So definitively the wrong license file

3

Also, do we want to stop putting new firmware into main and put it into ports?

sys/contrib/dev/athn/athn-ar9271fw.fw.uu
1

The .uu file is no longer needed, is it?

sys/dev/athn/usb/ar9271u.c
18

no needed anymore

sys/modules/athn/Makefile
1

You should remove these from all files

sys/modules/athnfw/Makefile.inc
14

even if the FW would stay in src.git, this should no longer be done.

This revision now requires changes to proceed.Jul 9 2025, 10:54 PM