The Driver Contract¶
This page lists what Linux and the rest of the openwifi stack expect from the openwifi driver. The Linux Driver explains how the driver works. Read this page before you change the driver, and check your change against it afterwards. Each section names a rule, the code in driver/sdr.c that follows it, and what goes wrong when the driver breaks it. The page also points out where the current driver does not follow a rule.
A broken rule rarely crashes the kernel. Instead, it shows up as a client that drops off after a minute, a rate that never climbs, or an iw command that reports success and changes nothing. The symptom usually appears far from the change that caused it.
Sources for this page
The driver behavior described here is from the master branch of open-sdr/openwifi as of November 2026. The mac80211 rules come from include/net/mac80211.h and net/mac80211/main.c in Linux 6.12, the kernel listed in Versions this wiki targets. When the code and this page disagree, the code is right.
Who does what¶
openwifi is a SoftMAC driver. mac80211 runs the 802.11 management state machine and makes most decisions. The driver and the FPGA carry out the time-critical parts. The split tells you which side has to change when you add a feature.
| Task | Done by | Notes |
|---|---|---|
| Authentication, association, and other MLME work | mac80211 |
The same as for any SoftMAC driver. |
| Scanning | mac80211 |
There is no hw_scan callback. mac80211 scans by calling config with each channel in turn. |
| Rate selection | mac80211 (minstrel_ht) |
The driver reads the chosen rate with ieee80211_get_tx_rate(). A rate forced through sdrctl overrides it (see the warning below). |
| Encryption and decryption | mac80211, in software |
There is no set_key callback, so CCMP runs on the ARM cores. See hostapd & wpa_supplicant. |
| Station tracking | mac80211 |
There is no sta_add or sta_state callback. |
| Sequence numbers | Driver | Only for frames that carry IEEE80211_TX_CTL_ASSIGN_SEQ, from the counter priv->seqno. |
| Duration field of HT frames | Driver | gen_ht_duration_id() writes it, because mac80211 computes it only for legacy rates. |
| Beacon timing | Driver, in software | A delayed work item. See Beacons. |
| CSMA/CA, ACK, retransmission, TSF | FPGA (xpu) |
The driver configures them through registers. |
| Frame filtering | FPGA (xpu) |
Configured by configure_filter and bss_info_changed. |
A forced rate is invisible to rate control
When you force a data rate with the drv_tx registers (see TX rate and MCS override), openwifi_tx() sends at the forced rate. The TX status it reports still names the rate mac80211 chose, as a TODO in the source notes. minstrel_ht then records successes and failures against a rate that was never used. Clear the forced rate before you measure rate-control behavior.
The driver also forces one rate itself. An FPGA bug makes the TX core hang on aggregated frames at HT MCS 0, so openwifi_tx() sends those frames at MCS 1, and the TX status still reports MCS 0.
Capabilities declared at probe time¶
openwifi_dev_probe() describes the device to mac80211 before it calls ieee80211_register_hw(). mac80211 and cfg80211 plan around that description for as long as the driver is loaded, and iw list prints it. Each flag and field states something about the driver, and code elsewhere in the driver has to make it true.
Hardware flags¶
| Flag | Meaning | Implemented by | If it is not true |
|---|---|---|---|
RX_INCLUDES_FCS |
Every received frame ends with its 4-byte FCS. | openwifi_rx_interrupt(), which copies the frame together with its FCS. |
mac80211 still cuts 4 bytes from the end of every frame. Remove the FCS without clearing the flag and every frame loses 4 bytes of content. |
SIGNAL_DBM |
rx_status.signal is in dBm. |
openwifi_rx_interrupt(), which converts rssi_half_db with the per-band rssi_correction. |
Signal values in iw dev sdr0 station dump and in scan results are wrong, and RSSI threshold events fire at the wrong level. |
REPORTS_TX_ACK_STATUS |
Every TX status says correctly whether the frame was acknowledged. | openwifi_tx_interrupt(), which sets IEEE80211_TX_STAT_ACK from the ACK bitmap the FPGA returns. |
Stations disconnect, and an AP can drop its clients or fail to associate them. See What mac80211 does with the ACK status. |
BEACON_TX_STATUS |
Beacons get a TX status like any other frame. | Beacons go through openwifi_tx() and come back through the TX interrupt. |
With this flag set, mac80211 copies beacons to monitor interfaces only from the TX status. Monitor captures lose the board's own beacons. |
AP_LINK_PS |
In AP mode, the driver detects when each client sleeps and reports it with ieee80211_sta_ps_transition(). |
Nothing. The driver never calls that function. | See the warning below. |
AMPDU_AGGREGATION |
The driver handles ampdu_action and sends A-MPDUs. Set only when test_mode bit 0 is set. |
openwifi_ampdu_action() and tx_intf. |
mac80211 sets up aggregation sessions that the hardware cannot serve. See Turning on A-MPDU aggregation. |
Clients in power save mode are not handled in AP mode
AP_LINK_PS tells mac80211 to ignore the power management bit in incoming frames, because the flag says the driver reports sleeping clients itself. openwifi sets the flag but never calls ieee80211_sta_ps_transition(). As a result, no layer marks a client as asleep, and mac80211 never buffers frames for one. A client in power save mode can miss frames the AP sends while it sleeps. Turn off power save on clients when you test (see Getting the best throughput). To support power save, either call ieee80211_sta_ps_transition() from the RX path or clear the flag so that mac80211 reads the bit itself.
What mac80211 does with the ACK status¶
REPORTS_TX_ACK_STATUS turns the ACK bit of each TX status into an input for connection management. In Linux 6.12, mac80211 relies on it in these places:
- Connection monitoring in station mode. To check that the AP is still there,
mac80211sends a null data frame and waits for its ACK status. Without the flag it would send a probe request instead. If no ACK is reported, the station concludes that the AP is gone and disconnects. - Authentication and association in station mode.
mac80211times its authentication and association retries from the TX status of each request. - Association in AP mode.
mac80211passes the TX status of each association response tohostapd. If the client did not acknowledge the response,hostapdremoves the client from the driver. Currenthostapdcan still complete the association later, if the client sends a data frame. - Lost clients in AP mode. For each client,
mac80211counts frames that were not acknowledged. After 50 lost frames in a row and no ACK for one second, it sends a packet-loss event to user space.hostapddisconnects the client on that event whendisassoc_low_ack=1is set in its configuration. - Rate control.
minstrel_htreads the ACK bit and the attempt count of every frame to choose the next rate.
The code in the TX interrupt that computes tx_fail is therefore part of the contract. Frames the driver drops before they reach the air are also reported as not acknowledged (see Transmit), so they count toward the loss limit too.
Other capability fields¶
| Field | Value | Meaning |
|---|---|---|
queues |
MAX_NUM_HW_QUEUE (4) |
skb_get_queue_mapping() returns 0 to 3, and the driver stops and wakes queues by those numbers. A frame with a higher number is dropped and reported as lost. |
max_rates |
1 | Only rates[0] carries a rate. The driver ends every status rate list with rates[1].idx = -1. |
extra_tx_headroom |
LEN_MPDU_DELIM (4 bytes) |
mac80211 leaves room in front of each frame for the A-MPDU delimiter. openwifi_tx() still reallocates the skb if the headroom is short. |
interface_modes, iface_combinations |
See Interfaces | The interface types cfg80211 may create, and how many at once. |
available_antennas_tx, available_antennas_rx |
3, meaning both antennas | set_antenna accepts these masks. For RX it accepts only one antenna at a time. |
bands |
2.4 and 5 GHz | The 8 OFDM rates and HT MCS 0 to 7 at 20 MHz. Short GI is advertised only when test_mode bit 1 is set (see Short guard interval). Both rate tables also list the four 802.11b rates, which the PHY cannot send (see About 802.11b). |
| Regulatory domain | Custom domain 99, applied with REGULATORY_STRICT_REG and REGULATORY_CUSTOM_REG |
2402 to 2494 MHz with CCK disabled, and 5150 to 5875 MHz, each at up to 20 dBm. Channels outside these ranges are disabled. |
perm_addr |
66:55:44:33:22:xx, last byte random from 1 to 250 |
The MAC address an interface gets unless you set another one. |
| Extended feature | NL80211_EXT_FEATURE_CQM_RSSI_LIST |
wpa_supplicant can register several RSSI thresholds. The thresholds are only meaningful while SIGNAL_DBM holds. |
radar_detect_widths in iface_combinations |
20 MHz (HT and non-HT), 40 MHz, and 80 MHz | The driver can detect radar at these channel widths. Nothing implements this (see the warning below). |
Radar channels are advertised without radar detection
The 5 GHz channel table in driver/sdr.h flags channels 52 to 64 with IEEE80211_CHAN_RADAR, and radar_detect_widths tells cfg80211 that the driver can detect radar there. hostapd can therefore start an AP on these channels after a CAC. openwifi has no radar detection and never calls ieee80211_radar_detected(), so the CAC always passes and the AP stays on the channel when radar appears. Do not run an AP on channels 52 to 64 where DFS rules apply.
Callbacks¶
mac80211 refuses to create the device when a required callback is missing. In Linux 6.12, ieee80211_alloc_hw_nm() requires tx, wake_tx_queue, start, stop, add_interface, remove_interface, config, and configure_filter. It also requires channel-context callbacks. A driver that does not manage channel contexts itself must use all three of mac80211's emulation helpers. The "Context" column gives the rule from the comment above struct ieee80211_ops in mac80211.h.
| Callback | Required | Context | What openwifi does |
|---|---|---|---|
tx |
Yes | Must be atomic | Builds the per-frame FPGA configuration and starts a DMA transfer into one of the four hardware queues. See Transmit. |
wake_tx_queue |
Yes | Not stated | Uses mac80211's own ieee80211_handle_wake_tx_queue(), which pulls frames from the mac80211 queues and calls tx. |
add_chanctx, remove_chanctx, change_chanctx |
Yes, as a set | Can sleep | Uses the ieee80211_emulate_*_chanctx helpers, which turn channel-context changes into config calls. |
switch_vif_chanctx |
No | Can sleep | Uses ieee80211_emulate_switch_vif_chanctx. |
start |
Yes | Can sleep | Initializes the five cores, writes the permanent MAC address into the xpu, claims both DMA channels and both interrupts, and turns the radio on through set_antenna. mac80211 asks that a started device have no MAC address until an interface is added, so that it acknowledges no frames before then. If a step fails, start frees the rings but keeps any DMA channel or interrupt it already claimed, and returns -1 instead of the original error code. |
stop |
Yes | Can sleep | Mutes the transmitter, disables both interrupts, frees the rings, and releases the DMA channels and interrupts. |
add_interface |
Yes | Can sleep | Accepts station, AP, ad-hoc, monitor, and mesh point. Writes the interface's MAC address into the xpu. See Interfaces. |
remove_interface |
Yes | Can sleep | Frees the interface slot. Leaves the MAC address in the xpu, although mac80211 asks drivers to clear it when the last interface goes away. |
config |
Yes | Can sleep | Tunes the radio to the new channel on IEEE80211_CONF_CHANGE_CHANNEL. When the restrict_freq_mhz sysfs value is set, it tunes to that frequency instead. Ignores every other change. |
configure_filter |
Yes | Can sleep | Writes the filter flags to XPU_REG_FILTER_FLAG. See Frame filtering. |
prepare_multicast |
No | Must be atomic | Returns the length of the multicast list. There is no hardware multicast filter. |
bss_info_changed |
No | Can sleep | Writes the BSSID to the xpu filter and the short-slot setting to the xpu. Starts and stops the beacon work item. Prints all other changes. |
conf_tx |
No | Can sleep | Writes CWmin and CWmax for one queue into XPU_REG_CSMA_CFG. |
ampdu_action |
No | Can sleep | Accepts TX sessions at once and programs tx_intf. Accepts RX sessions and does nothing. Returns -EOPNOTSUPP when aggregation is off. |
set_antenna, get_antenna |
No | Not stated | Selects TX antennas (mask 1 to 3) and one RX antenna (mask 1 or 2) on the AD9361, in tx_intf, and in rx_intf. Rejects an RX mask of 3 with -EINVAL, which mac80211 allows. |
get_tsf, set_tsf, reset_tsf |
No | Can sleep | Read, load, or zero the 64-bit TSF in the xpu. |
set_rts_threshold |
No | Can sleep | Returns 0 and does nothing. |
rfkill_poll |
No | Can sleep | Reports the radio as switched off when the AD9361 TX attenuation is at least 89.75 dB (AD9361_RADIO_OFF_TX_ATT). |
testmode_cmd |
No | Can sleep | Handles sdrctl commands. See User space. |
ampdu_action must also tell mac80211 when a TX aggregation session changes state:
- Answer every
IEEE80211_AMPDU_TX_STARTwithieee80211_start_tx_ba_cb_irqsafe(), or by returningIEEE80211_AMPDU_TX_START_IMMEDIATE. Otherwise the session never starts. - After
IEEE80211_AMPDU_TX_STOP_CONT, send the frames still queued for the session without aggregation, then callieee80211_stop_tx_ba_cb_irqsafe(). Otherwise the session never ends. - After
IEEE80211_AMPDU_TX_STOP_FLUSH, no callback is needed, becausemac80211is removing the station.IEEE80211_AMPDU_TX_STOP_FLUSH_CONTcomes when the station is removed before the driver has finished an earlier stop, and the driver should drop the frames it still holds.
openwifi calls ieee80211_start_tx_ba_cb_irqsafe() and ieee80211_stop_tx_ba_cb_irqsafe() directly from openwifi_ampdu_action(). It calls the stop callback for all three stop actions, without waiting for queued frames.
Frame filtering¶
configure_filter must clear the bits it cannot honor from *total_flags, because that is how mac80211 learns what the hardware filters. openwifi keeps only SDR_SUPPORTED_FILTERS (FIF_ALLMULTI, FIF_BCN_PRBRESP_PROMISC, FIF_CONTROL, FIF_OTHER_BSS, FIF_PSPOLL, and FIF_PROBE_REQ). It always adds FIF_ALLMULTI, since there is no multicast filter. When FIF_BCN_PRBRESP_PROMISC, FIF_CONTROL, FIF_OTHER_BSS, and FIF_PSPOLL are all set, the driver treats the request as monitor mode and passes every frame up. The rx_monitor_all sysfs value forces the same mode.
Requests openwifi accepts and ignores¶
Several requests succeed from the point of view of Linux but change nothing in the hardware. Check this list before you debug a setting that seems to have no effect.
- TX power.
iw dev sdr0 set txpowerreaches the driver throughbss_info_changedandconfig, and neither changes the AD9361. Set the attenuation withsdrctlinstead (see TX power and attenuation). - RTS threshold.
set_rts_thresholdreturns success and does nothing. Whenmac80211asks for RTS/CTS on a frame,openwifi_tx()prints a warning and sends the frame without it. CTS-to-self protection does work. - AIFS and TXOP.
conf_txuses only CWmin and CWmax. When thecw_max_min_cfgsysfs value is not zero, it replaces the values frommac80211for all four queues. - Other
configchanges.configacts only on channel changes. Changes to power save, retry limits, and the otherIEEE80211_CONF_CHANGE_*bits are ignored. The per-frame retry limit frommac80211still applies, throughrates[0].count. - Some
bss_info_changedchanges. Basic rates, ERP CTS protection, and the beacon interval are only printed. ERP protection still works, becausemac80211also setsIEEE80211_TX_RC_USE_CTS_PROTECTon each frame that needs it. A new beacon interval also takes effect, because the beacon work item readsbeacon_inton every run. - RX aggregation sessions.
ampdu_actionacceptsIEEE80211_AMPDU_RX_STARTandIEEE80211_AMPDU_RX_STOPwithout doing anything. The receiver handles A-MPDUs without per-session state. - TX aggregation size.
IEEE80211_AMPDU_TX_OPERATIONALprograms a buffer size of 4, whateverbuf_sizethe peer agreed to.mac80211forbids aggregates with more subframes thanbuf_size, so a peer that agrees to fewer than 4 receives larger aggregates than it allowed.
Frame ownership¶
Transmit¶
mac80211 hands each frame to openwifi_tx() as an skb. From then until the driver reports its status, the driver owns the skb. These rules keep that ownership correct:
- Never sleep in
tx.mac80211requirestxto be atomic, andieee80211_handle_wake_tx_queue()calls it while holding a spinlock. Allocate withGFP_ATOMIC, and do not take a mutex or callmsleep()on this path. openwifi breaks this rule in its padding code. Whenskb_tailroom()is too small for the DMA padding,openwifi_tx()copies the frame withskb_copy_expand(..., GFP_KERNEL), which can sleep. - Return every frame exactly once. Every
skbthat entersopenwifi_tx()goes back tomac80211throughieee80211_tx_status_irqsafe(). Normallyopenwifi_tx_interrupt()does this. A frame the driver drops goes back throughreport_pkt_loss_due_to_driver_drop(), which reports it as sent once without an ACK. Do not free a TXskbyourself. A frame that never comes back leaks memory, andmac80211code that waits for its status waits until it times out. A frame reported twice is a use-after-free. If you replace theskb(as the padding and headroom code does withskb_copy_expand()andskb_realloc_headroom()), free the old one, report the new one, and update every pointer into the old data. The A-MPDU padding code misses that last step. It takesdma_buffrom the oldskbbefore the copy and keeps using it afterwards, so the MPDU CRC is written to freed memory and the DMA transfer reads from it. - Use one status function.
mac80211does not allowieee80211_tx_status_irqsafe(),ieee80211_tx_status_skb(), andieee80211_tx_status_ni()to be mixed on one device. openwifi uses only the_irqsafeform. - Fill the status the same way every time. Before you call
ieee80211_tx_status_irqsafe():- Call
ieee80211_tx_info_clear_status(). - Set
IEEE80211_TX_STAT_ACKonly when the frame was acknowledged. - Set
status.rates[0].countto the number of attempts (nof_retx + 1) andstatus.rates[1].idxto -1, becausemax_ratesis 1. - For an A-MPDU subframe, set
IEEE80211_TX_STAT_AMPDU, setampdu_lento 1, and setampdu_ack_lenfrom the block ACK bitmap. Remove the 4-byte MPDU delimiter withskb_pull(), becauseopenwifi_tx()added it andmac80211expects the frame to start at the 802.11 header.
- Call
- Stop and wake by Linux queue number.
ieee80211_stop_queue()andieee80211_wake_queue()take themac80211queue number, which ispriofromskb_get_queue_mapping(). It can differ from the driver ring and the FPGA queue, because time slicing can send a priority to another ring.ring->stop_flagrecords which Linux queue stopped a ring, and the TX interrupt wakes that queue once the FPGA has room again (RING_ROOM_THRESHOLD). Every stop needs a matching wake, or that access category stays silent. Never callnetif_stop_queue(), whichmac80211forbids.
The driver also has a recovery path for a ring that seems stuck. When openwifi_tx() finds the next descriptor still occupied but a free one further along the ring, it reports the frames in between as lost and wakes the stopped queue, because their TX interrupt never arrives.
Beacons¶
openwifi has no hardware beacon timer. When bss_info_changed reports BSS_CHANGED_BEACON_ENABLED or BSS_CHANGED_BEACON, the driver cancels and reschedules a delayed work item, openwifi_beacon_work(). Each run takes a fresh beacon from ieee80211_beacon_get(), writes the current TSF into its timestamp field, and sends it through openwifi_tx() on queue 0. The work item then reschedules itself after beacon_int times 1024 microseconds, and it skips a beacon when queue 0 is stopped. Beacon timing therefore depends on when the kernel runs the work item.
The work item lives in the interface's private data, so it must stop before the interface goes away. Neither stop nor remove_interface cancels it. The only cancel is in bss_info_changed, when mac80211 turns beaconing off, which happens before an AP, ad-hoc, or mesh interface goes down. If you add a work item of your own, cancel it in remove_interface or stop.
Receive¶
openwifi_rx_interrupt() builds one struct ieee80211_rx_status per frame and passes the frame to ieee80211_rx_irqsafe(). Like the TX status functions, the RX functions must not be mixed: use only the _irqsafe form. The skb is allocated with dev_alloc_skb(), which is safe in the interrupt handler.
| Field | Set from | Notes |
|---|---|---|
freq, band |
The current channel, dev->conf.chandef.chan |
Not the tuned LO. With restrict_freq_mhz set, the radio listens on a different frequency from the one reported. |
signal |
RSSI in dBm | Required by SIGNAL_DBM. |
rate_idx, encoding, bw |
The rate field of the RX header | A legacy rate becomes an index into the band's rate table through wifi_rate_table_mapping. An HT rate uses RX_ENC_HT with its MCS. Bandwidth is always 20 MHz. |
enc_flags |
The short GI bit | |
mactime |
The 64-bit TSF in the RX header | Flagged RX_FLAG_MACTIME_START, meaning the TSF at the start of the frame. |
flag |
The FCS-OK bit | A frame with a bad FCS gets RX_FLAG_FAILED_FCS_CRC. mac80211 drops it from normal processing and passes it only to monitor interfaces. |
ampdu_reference, RX_FLAG_AMPDU_* |
The aggregation bits | ampdu_reference counts up after the last subframe of each aggregate. |
antenna |
The selected RX antenna |
Interfaces¶
interface_modes and iface_combinations tell cfg80211 which interfaces it may create. add_interface runs later, when an interface comes up, and is where the driver accepts or refuses it.
| Type | Advertised | add_interface |
Notes |
|---|---|---|---|
| Station | Yes | Accepts | |
| AP | Yes | Accepts | |
| Ad-hoc (IBSS) | Yes | Accepts | |
| Monitor | Yes | Accepts | |
| Mesh point | Yes | Accepts | Counted in the interface limits only when the kernel has CONFIG_MAC80211_MESH. |
| P2P client, P2P GO | Yes | Accepts | mac80211 passes them as station and AP with vif->p2p set. |
| OCB | Yes | Refuses with -EOPNOTSUPP |
iw can create the interface, but bringing it up fails. |
If you add a type to interface_modes, add it to the switch in openwifi_add_interface() in the same change.
The FPGA holds one MAC address
iface_combinations allows up to MAX_NUM_VIF (4) interfaces on one channel. The xpu has a single MAC address register, and every add_interface call overwrites it with the new interface's address. The FPGA then filters unicast frames and sends ACKs only for the interface added most recently. The address stays in the register after that interface is removed. Run several interfaces at once only when they share one MAC address, or extend the xpu first.
Shared with the rest of openwifi¶
The FPGA¶
The driver and the FPGA share several layouts that no compiler checks. They ship as a matched set (see Versions this wiki targets), so a change on one side needs the same change on the other.
- Register addresses.
driver/hw_def.hgives each register as a word offset that must match aslv_regNin the core's*_s_axi.v. See Where the registers are defined. -
Per-frame TX words.
openwifi_tx()packs these words and writes them totx_intfbefore each DMA transfer:phy_hdr_config = ( ht_aggr_start<<20 | rate_hw_value<<16 | use_ht_rate<<15 | use_short_gi<<14 | use_ht_aggr<<13 | len_psdu ); tx_config = ( prio<<26 | ring->bd_wr_idx<<20 | queue_idx<<18 | retry_limit_hw_value<<14 | pkt_need_ack<<13 | num_dma_symbol ); -
TX status words.
openwifi_tx_interrupt()decodesTX_INTF_REG_PKT_INFO1toTX_INTF_REG_PKT_INFO4. The FPGA returns the descriptor index and the Linux priority that it received intx_config, and the driver uses them to find each frame'sskb. For a frame that is not aggregated, bit 0 of the block ACK bitmap is the ACK result.num_slot_randomandcwdescribe the backoff the FPGA used, and the driver only prints them.nof_retx = (reg_val1&0xF); last_bd_rd_idx = ((reg_val1>>5)&(NUM_TX_BD-1)); queue_idx = ((reg_val1>>15)&(MAX_NUM_HW_QUEUE-1)); prio = ((reg_val1>>17)&0x3); num_slot_random = ((reg_val1>>19)&0x1FF); cw = ((reg_val1>>28)&0xF); pkt_cnt = (reg_val2&0x3F); blk_ack_ssn = ((reg_val2>>6)&0xFFF); // PKT_INFO3 and PKT_INFO4 hold the 64-bit block ACK bitmap -
Descriptor count.
NUM_TX_BD(64) must match the FIFO depth intx_bit_intf.v.openwifi_tx_interrupt()also writes 64 as a literal number when it computesbd_rd_idx, so change that line together withNUM_TX_BD. - RX buffer slots. Each slot starts with the 16-byte header described in The receive path inside the driver. After processing a slot, the driver writes 0 to the 16-bit field at offset 10, which
rx_intfsets to mark a new packet. The handler finds new packets by that field, so the write is part of the handshake withrx_intf.
User space¶
sdrctl and the scripts in user_space/ depend on numbers and names defined in the driver. None of them fail at build time when the driver changes.
| Interface | Defined in | Used by | Rule |
|---|---|---|---|
sdrctl command and attribute numbers |
user_space/sdrctl_src/nl80211_testmode_def.h, which sdr.c includes directly |
sdrctl |
One copy serves both sides. Add new entries at new numbers and never renumber old ones, or an sdrctl built earlier sends the wrong command. |
| Register categories 1 to 9 | enum sdrctl_reg_cat in driver/sdr.h, and again as literal numbers in user_space/sdrctl_src/cmd.c |
sdrctl dev sdr0 set reg <category> ... |
Two copies. Change both together. See Two channels to user space. |
Driver register indices (DRV_TX_REG_IDX_*, DRV_RX_REG_IDX_*, DRV_XPU_REG_IDX_*) |
driver/sdr.h |
Scripts and documented commands, by number. For example, set_lbt_th.sh writes drv_xpu 0. |
Moving an index breaks every script and command that uses the old number. See the register reference. |
| sysfs attribute names | driver/sysfs_intf.c |
stat_enable.sh, rx_stat_show.sh, tx_stat_show.sh, cw_max_min_cfg.sh, set_restrict_freq.sh, and others |
The scripts open the files by name. A rename breaks them silently. |
| sysfs directory | The device-tree node names | Every sysfs script, which tries /sys/devices/platform/fpga-axi@0/fpga-axi@0:sdr and then /sys/devices/soc0/fpga-axi@0/fpga-axi@0:sdr |
Renaming the fpga-axi@0 node or the sdr node moves the directory. |
The device tree¶
The driver finds its hardware through the device tree, as described in How the driver finds its hardware. These names and indices must match:
| Item | Value | Read by |
|---|---|---|
Main node compatible |
sdr,sdr |
openwifi_dev_of_ids in sdr.c |
Core node compatible |
sdr,xpu, sdr,tx_intf, sdr,rx_intf, sdr,openofdm_tx, sdr,openofdm_rx |
The per-core modules |
| DMA channel names | rx_dma_s2mm, tx_dma_mm2s |
openwifi_start() |
| Interrupt indices | 1 for RX, 3 for TX | openwifi_start() |
Root model string and the lmk node |
Decide hardware_type and fpga_type (see board detection) |
openwifi_dev_probe() |
ad9361-phy on the SPI bus, cf-ad9361-dds-core-lpc platform device |
Must exist and be probed by the Analog Devices drivers (except on the RFSoC4x2) | openwifi_dev_probe() |
The DMA channels and interrupts are claimed in start, not at probe. A wrong name or index therefore does not fail when the module loads. It fails when sdr0 comes up.
When the kernel changes¶
The mac80211 driver interface changes between kernel versions. A driver written for an older kernel fails in one of two ways:
- A required callback is missing.
ieee80211_alloc_hw()prints a kernel warning and returnsNULL.sdr.koloads, but the probe fails andsdr0never appears. - A callback signature changed. The build fails, or it prints an incompatible pointer type warning. Treat that warning as an error, because the kernel calls the function with the new arguments.
Upstream openwifi already follows the Linux 6.12 interface:
wake_tx_queueis set toieee80211_handle_wake_tx_queue.- The channel-context callbacks use the emulation helpers.
conf_txtakes alink_idargument, andstoptakes asuspendargument.ieee80211_beacon_get()takes a link ID, which openwifi passes as 0.- Station capabilities come from
sta->deflink, for examplelink->ht_capinopenwifi_ampdu_action().
The OpenWrt build uses a newer mac80211 (see the version table), where config, set_antenna, get_antenna, and set_rts_threshold take an extra radio_idx argument. sdr.c keeps both forms behind #ifdef OPENWRT, including the calls to openwifi_set_antenna() in openwifi_start() and openwifi_dev_probe(). When you change one of these functions, change both branches and build both variants.
For a new kernel, read the checks at the top of ieee80211_alloc_hw_nm() in net/mac80211/main.c for the required callbacks. Read the comment above struct ieee80211_ops in include/net/mac80211.h for the context rule of each one.
Before you merge a driver change¶
Run these checks on a board, with the changed driver loaded through wgd.sh.
-
Compare the capabilities Linux sees. Any difference you did not intend is a contract change.
# With the unchanged driver loaded iw list > /root/iw_list_before.txt # Load the changed driver with wgd.sh, then run iw list > /root/iw_list_after.txt diff /root/iw_list_before.txt /root/iw_list_after.txt -
Bring the interface down and up twice, then reload the driver. A
startthat does not undo a partial setup, or astopthat leaks a DMA channel or an interrupt, fails on the second round.startalready leaks when one of its own steps fails (see Callbacks), so find the first failure in the kernel log before you blame the second. - Run as a station and leave the link idle for several minutes. The station must stay connected. Connection monitoring depends on the ACK status (see What mac80211 does with the ACK status).
- Run as an AP with a client and send traffic. Compare the TX ACK failure counters with the unchanged driver on the same setup (see Statistics via sysfs). A large rise points at the TX status path before the radio link.
- Run an iperf regression check. See Regression check after a driver or FPGA change.
-
Check the kernel log for warnings. A
WARNING: CPUline is aWARN_ONin the kernel or inmac80211. On a kernel built withCONFIG_DEBUG_ATOMIC_SLEEP, a sleep intxprintsBUG: sleeping function called from invalid context. TheGFP_KERNELcopy inopenwifi_tx()(see Transmit) can print this line on an unchanged driver, so compare with the unchanged driver before you blame your change.dmesg | grep -E "WARNING: CPU|BUG:" -
If you changed a callback that has an
OPENWRTbranch, build both variants.