History log of /freebsd-current/sys/compat/linuxkpi/common/src/linux_80211.c
Revision Date Author Comments
# 45bce6fa 18-Feb-2024 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: lock MO tx/wake_tx_queue() downcalls

Lock the two TX MO downcalls into driver/firmware in
lkpi_80211_txq_tx_one() to make sure they cannot happen in the
middle of other (net80211 triggered) updates calling down into
the driver/firmware.

Sponsored by: The FreeBSD Foundation (commit)
MFC after: 3 days
Reviewed by: cc
Differential Revision: https://reviews.freebsd.org/D43966


# d1af434d 13-May-2024 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: rename chanctx_conf for consistency

We used to call the struct ieee80211_chanctx_conf variable "conf"
in some places but that becomes confusing with bss_conf and other
"conf" bits. On the vif it is already called chanctx_conf thus also
rename it on the internal struct lkpi_chanctx and for our variables
in the implementation.

This should not have any external visibility.
No functional changes intended.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D45185


# 5a4d2461 21-May-2024 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: change teardown order to avoid iwlwifi firmware crashes

While the previous order worked well for iwlwifi 22000 and later chipsets
(AXxxx, BE200), earlier chipsets had trouble and ran into firmware crashes.
Change the teardown order to avoid these problems. The inline comments
in lkpi_sta_run_to_init() (and lkpi_disassoc()) try to document the new
order and also the old problems we were seeing (too early sta removal or
silent non-removal) leading to follow-up problems.

There is a possible further problem still lingering but a lot harder to
trigger (see comment in review) and likely related to some other doings
so we'll track it separately.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days
PR: 275255
Tested with: AX210, 8265 (bz); 9260 (Bakul Shah)
Differential Revision: https://reviews.freebsd.org/D45293


# 1665ef97 16-Feb-2024 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: disable early queue wakeup workaround; better classify

We used to call lkpi_wake_tx_queues() for all queues early on in order
to make sure they are ready. Turns out whatever logic in iwlwifi
startup is working correctly these days under LinuxKPI so this is no
longer needed. As the comment indicated the "workaround" did not
always work. Disable it for now.

The second part of the improvement is to properly classify Non-QOS
non-data frames (mgmt and ctl frames for now, unless we have to be
even more careful in the future about certain sub-types) as TID 7/VO.
Contrary to net80211 we must not promote PAE frames.

PR: 274382
MFC after: 3 day
Reviewed by: cc
Differential Revision: https://reviews.freebsd.org/D43944


# ac867c20 18-Feb-2024 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: remove unneeded re-lookup in lkpi_80211_txq_tx_one()

Given we are passed the lsta in as a function argument there is no
need to re-lookup the sta by ni and possibly not find it.
We know the sta and ni from the lsta and whether it is uploaded to
firmware or not we can check directly from the local lsta flag.

MFC after: 3 days
Reviewed by: cc
Differential Revision: https://reviews.freebsd.org/D43965


# 906521f8 04-Mar-2024 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: return proper value for IEEE80211_CRYPTO_AES_CCM

In case of LKPI_80211_HW_CRYPTO we convert from LinuxKPI cipher_suites
to net80211 ic_cryptocaps fields. For WLAN_CIPHER_SUITE_CCMP we
accidentally returned the bit number instead of the shifted value
which leads to ieee80211_crypto_newkey() setting IEEE80211_KEY_SWCRYPT,
which in turned lead to us trying to decode the frame again despite
HW had already done it. This was found out of a discussion in D43634.

MFC after: 3 days
Reviewed by: cc, adrian
Differential Revision: https://reviews.freebsd.org/D44208


# 759a996d 12-Feb-2024 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: implement a deferred RX path

Some calls, e.g., action frames cause us to call through all the
way down to firmware from the RX path without any deferral in
net80211.

For LinuxKPI and iwlwifi this goes (with omissions) like this:
lkpi_napi_task -> linuxkpi_ieee80211_rx -> ieee80211_input_mimo ->
sta_input -> ht_recv_action_ba_addba_request ->
lkpi_ic_ampdu_rx_start -> iwl_mvm_mac_ampdu_action ->
iwl_trans_txq_send_hcmd. At that point we are waiting for an
interrupt from the firmware but given the lkpi_napi_task has not
finished (and may have more to dispatch based on budget and what
was received) we will not see the new interrupt/fw response.
With no answer from the firmware, the software timeout in the
driver kills the command and the firmware and issues a complete
restart.

Implement the deferred RX path in LinuxKPI for the moment.
At a later point we should carefully shift this into net80211.

This fixes the hangs for (*ic_ampdu_rx_start)() calls with iwlwifi.

MFC after: 3 days
PR: 276083
Reviewed by: cc
Differential Revision: https://reviews.freebsd.org/D43968


# fa4e4257 14-Feb-2024 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: lsta txq locking cleanup

Rename the LSTA lock to LSTA_TXQ lock as that is really what it is and
put down the full set of macros. Replace the init and destroy with the
macro invocation rather than direct code.

Put locking around the txq_ready unset and check. Move the taskq_enqueue
call under lock to be sure we do not call it anymore after txq_ready
got unset.

Leave a comment related to the node reference which is passed into the
TX path on the recvif mbuf pointer.

Fixes: 0936c648ad0ee
PR: 274382 (possibly)
MFC after: 1 day
Reviewed by: emaste
Differential Revision: https://reviews.freebsd.org/D43909


# 0936c648 05-Feb-2024 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: update the ni/lsta reference cycle

Update the ni/lsta reference cycle, add extra checks and assertions.
This is to accomodate problems we were seeing based on net80211
behaviour (join1() and (*iv_update_bss)() as well as state changes for
new iv_bss nodes during an active session).
This should hopefully help to stabilise behaviour until the underlying
problems gets properly addressed (for this and all other device drivers).

PR: 272607, 273985, 274003
MFC after: 3 days
Reviewed by: cc
Differential Revision: https://reviews.freebsd.org/D43753


# 2ac8a218 03-Feb-2024 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: band-aid for invalid state changes after (*iv_update_bss)

With firmware based solutions we cannot just jump from an active session
to a new iv_bss node without tearing down state for the old and bringing
up the new node. This likely used to work on softmac based cards/drivers
where one could essentially set the state and fire at will.

We track (*iv_update_bss) calls from net80211 and set a local flag that
we are out of synch and do not allow any further operations up the state
machine until we hit INIT or SCAN. That means someone will take the state
down, clean up firmware state and then we can join again and build up
state.

Apparently this problem has been "known" for a while as native iwm(4) and
others have similar workarounds (though less strict) and can be equally
pestered into bad states. For LinuxKPI all the KASSERTs just massively
brought this problem out. The solution will be some rewrites in net80211.
Until then, try to keep us more stable at least and not die on second
join1() calls triggered by service netif start wlan0 and similar.

PR: 271979, 271988, 275255, 263613, 274003
Sponsored by: The FreeBSD Foundation (2023, partial)
MFC after: 3 days
Reviewed by: cc
Differential Revision: https://reviews.freebsd.org/D43725


# 8cb9b68f 09-Jan-2024 John Baldwin <jhb@FreeBSD.org>

sys: Use mbufq_empty instead of comparing mbufq_len against 0

Reviewed by: bz, emaste
Sponsored by: Chelsio Communications
Differential Revision: https://reviews.freebsd.org/D43338


# eac3646f 11-Dec-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: more TXQ implementation and locking

Implement ieee80211_handle_wake_tx_queue() and ieee80211_tx_dequeue_ni()
while looking at the code. They are needed by various wireless drivers.

Introduce an ltxq lock and protect the skbq by that.
This prevents panics due to a race between a driver upcall and
the net80211 tx downcall. While the former should be rcu protected we
cannot rely on that.
It remains questionable if we need to protect further fields there
(with a different lock?).

Also introduce a txq_mtx on the lhw which needs to be further deployed
but we need to come up with a good strategy to not end up with 7 different
locks.

Sponsored by: The FreeBSD Foundation
PR: 274178, 275710
Tested by: cc
MFC after: 3 days


# 9fb91463 26-Oct-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: bring in some HT code

Fix defines and structures to use proper types.

Bring in basic ni->sta synchronization, some channel width handling,
and overload the net80211 functions so that we can talk to
driver/firmware to setup parameters. We will likely not need one
or two of those but it is good for tracing currently.

Cover HT and bits of VHT code in LinuxKPI behind apropriate #ifdef
which are currently not enabled (like LKPI_80211_HW_CRYPTO) until
confirmed to work.
Last, IEEE80211_AMPDU_RX_START made some firmware unhappy.

This will allow others to work on it and test as well.

Sponsored by: The FreeBSD Foundation
MFC after: 10 days


# de607e3c 29-Oct-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

net80211: move net_epoch into net80211

Move the net_epoch into net80211 around the if_input calls and out of
the driver (in this first case LinuxKPI). This reduces coverage but
also allows us to alloc in calls like (*ampdu_rx_start) which do not
actually pass data up the stack.

The follow-up commits will revert b65f813c1ab99448278961c5ca80dc422b1eae29,
21c4082de9e2cf9a0fd81a9a981ab06022956847,
17c328b6aebfa03cd1c2cbfbbc617e3b341bf1e4,
af2441fbc7fa9e522e7f8697e5a181bdd4ff9e00,
and 6c3e93cb5a4aa4b8a2d8d4d326f2a7c34d3a4458 for ath.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days
Tested by: few (rtwn, ath, iwlwifi, ...)
Reviewed by: adrian
Differential Revision: https://reviews.freebsd.org/D42427


# fdafd315 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

sys: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by: Netflix


# 562adbe1 27-Oct-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

net80211: migrate ic_vhtcaps, ic_vht_mcsinfo, ic_flags_vht

Like for the VAP rename ic_flags_vht to ic_vht_flags for consistency to
keep "VHT" fields together and merge ic_vhtcaps and ic_vht_mcsinfo
into struct ieee80211_vht_cap ic_vht_cap.

While the structure layout changes no other functional changes intended.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days
Reviewed by: adrian, cc
Differential Revision: https://reviews.freebsd.org/D42421


# 78ca45df 27-Oct-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: deal with scan_ie_len

We only need to reserve the extra space for DSSS if
NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES is set, so add the conditional.
Also add checks in case scan_ie_len will grow beyond the maximum.
Given this is currently unlikely, leave the cleanup for later as
some other restructuring should be done first.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days
Reviewed by: cc
Differential Revision: https://reviews.freebsd.org/D42425


# 5856761f 25-Oct-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: fix ieee80211_add_channel_cbw() argument

Fix the last argument passed to ieee80211_add_channel_cbw() in
lkpi_ic_getradiocaps() for both 2Ghz and 5Ghz bands.
We passed in the unmodified version rather than the adjusted version
based on the per-band channel information possibly leaving
ieee80211_channel_flags enabled which should not be.

So far this should not have made a difference given we did not enable
HT or VHT.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days
Reviewed by: cc
Differential Revision: https://reviews.freebsd.org/D42424


# 45c27ad5 25-Oct-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: error on state transition failure

The state transition failures we were seeing in the early days are
solved. If we now experience one stop processing before passing
over to net80211 (sta_newstate()) and before updating iv_state on
the vap.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days
Reviewed by: cc
Differential Revision: https://reviews.freebsd.org/D42423


# 018d93ec 09-Oct-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: add unconditional error reporting

Multiple reports have shown missed state transitions in net80211 without
major cause obvious (or with a txq warning in iwlwifi).
In order to better track down potential problems add unconditional
ic_printf calls to any case in the lkpi state machine compat code which
would let us return with an error in the hope that it helps us to catch
the actual problems.
Also remove the debug conditions from ieee80211_{beacon,connection}_loss
which can also cause state transitions to have the ic_printf all the time
there too.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# 0d2cb6a6 04-Oct-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: hide txq debugging behind checks

Two txq debug messages were left unconditionally. Hide them behind
ifdef/if() condition checks for selective debugging only.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# 6c38c6b1 03-Oct-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: fix re-creation of VAP

After dbf7691999abe (as indicated in that commit message) EEXISTS
errors may be seen. From current investigation that is due to the
single-VAP support in LinuxKPI 802.11 and the related calls to
mo_start() and mo_stop() and them being disabled in ic_parent()
currently. Calling mo_stop() in lkpi_ic_vap_delete() seems to
fix the problem and new VAPs (wlan interfaces) can be created again
after being destroyed.

Fixes: dbf7691999abe ("improve lkpi_ic_vap_delete()")
Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# dbf76919 30-Sep-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: improve lkpi_ic_vap_delete()

Changing the order of cleanup in lkpi_ic_vap_delete() will avoid
firmware crashes or a direct panic as observed as ieee80211_vap_detach()
will do most cleanup for us and get us into the correct state.

The solution is not fully developed yet and one may not be able
to create a new vap (lkpi_ic_vap_create may fail with error 17)
afterwards. It is supposed to be a step towards more stability
for now.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days
PR: 269842


# 16e688b2 30-Sep-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: fix problem removing sta

Move the call to lkpi_disassoc() before the state change to
IEEE80211_STA_NOTEXIST which will remove the sta (from firmware).
Based on a comment it seems that originally we had to do it the
other way round.
iwlwifi(4) has a check and will silently not remove the sta from
the firmware when vif->cfg.assoc is still set (see iwl_mvm_sta_del()).
This leads to the LinuxKPI 802.11 code thinking the sta is gone as
downward state changes by the mac80211 op (*sta_state)() may not fail.
Once we try to assoc with a newly added station later, iwlwifi firmware
will run into an assert having two ap_sta set on the same vif.
We can observe that problem in iwlwifi(4) having __le32 sta_id = 1
instead of sta_id = 0 in iwl_mvm_sta_cfg_cmd{} on the HCMD.

This should fix one of the most seen problems with iwlwifi(4), e.g.,
when running service netif restart wlan0 or
service wpa_supplicant restart wlan0.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# 673d62fc 25-Sep-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: fill regulatory_hint() with some life

Start implementing regulatory_hint() using a .c file based allocation
helper function so we could change structures in the future with
better chances to keep compatibility.
This sets wiphy->regd needed by various LinuxKPI based WiFi drivers.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# c5e25798 25-Sep-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

LiunxKPI: 802.11: move ieee80211_chanctx_conf into lkpi private struct

Factor out ieee80211_chanctx_conf into struct lkpi_chanctx in order to
keep local state as well. In first instance that is added_to_drv
only. For now we stay single-chanctx only but this paves the path
to make it a list.
Use the new information to implement ieee80211_iter_chan_contexts_atomic().

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# fb3c249e 24-Sep-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: avoid symbol clash on UP to AC mapping

tid_to_mac80211_ac is an exported symbol in and likely based on iwlwifi,
which leads to a symbol clash in NetBSD. Rename our local LinuxKPI copy
to a better name and add a comment where to find a copy of the mapping
table.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days
Reported by: Phil Nelson (phil netbsd org)


# 6ffb7bd4 20-Sep-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: setup a default link[0] and adjust related needs

Setup more link_conf/deflink fields for vif/sta as are needed to allow
us to work with the KPI bits in a non-MLO configuration.
In lkpi_sta_scan_to_auth() set the bss_conf values before calling into
the driver for chanctx setup/updates as certain values (e.g., beacon_int)
need to be set before; we still call the MO function for the updates
after to keep the expected workflow.
Deal with the (to be dealt with otherwise later) net80211 ni swaps and
update the addresses on the deflink as well as otherwise firmware will
hit asserts or things will not work (e.g. indicating the peer is us).

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# a6042e17 20-Sep-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: inialize tx queue params

When adding a VAP (vif) initialize its tx queue parameters calling
mo_conf_tx().
I could not spot net80211 providing some of the values needed before
having a node so currrently we use hard-coded values with a comment
with a reference on how to properly calculate the values in the future
(e.g., in case of 11b or other cases).

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# 8d58a057 20-Sep-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: change ic_parent() to not call mo_stop()/mo_start()

Driven by net80211 we may call mac80211 ops stop() and start() mostly
when toggling a first VAP. While this is FreeBSD behaviour the firmware
based LinuxKPI drivers seem to possibly clear state in the case of stop()
triggering further errors down the line.
We call mo_start() when starting the VAP and mo_stop() when destroying
it now only. In the future (e.g., in multi-VAP setups) we may need to
re-address some of this so keep the code under #ifdef.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# 616e1330 20-Sep-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: adjust code to new structure layout

With past commits new structures were added. Now switch over some
bss_conf fields into vif->cfg where they got moved to and remove the
old fields. This allows drivers to find the expected values in the
now expected places and work better.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# 68541546 16-Sep-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: pass non-0/NULL arguments to MO functions

In [1] we updated the KPI for various mac80211 ops functions to deal
with MLD code. Newer iwlwifi driver and firmware supports these
functions so we need to pass non-dummy (0, NULL) arguments to them.
Start extending the internel MO functions by these arguments and
pass down values from LinuxKPI 802.11 code.
It is assumed that further work will be needed to have all the
right fields available to at least work in the lgeacy way of a
single link.

Sponsored by: The FreeBSD Foundation
Improves: 549198b1ab95 (update mac80211 KPI) [1]
MFC after: 3 days


# f454a4a1 14-Sep-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: fix counting the number of supbands

While the main purpose was to assign an(y) early chandef with the
loop, later additions made use of it to also count supbands as well
as to initialise max_rates.
Due to the main goal we can exit the loop early and not properly
count and initialise supbands and max_rates.
Move the terminating condition into the loop and make it a continue
rather than ending the loop.

Fixes: d9945d7821b9b ("improve hw_scan")
Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# e1e90be0 14-Sep-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: make sure bssid for scans (probe_req) is set

In b0f73768220e9 we added bssid[] to struct cfg80211_scan_request
likely while working on mt76 and did not need it (yet) back then.
iwlwifi started to use the field in Linux f1fec51cda70f (April 2023).
Without it set firmware crashes when trying to send probe requests
((empty) SSID also given to hw_scan).
For now always set the field to the wildcard BSSID.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# adff403f 16-May-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: update compat code for updated drivers

Adjust and add structs, fields, functions to make more modern versions
of LinuxKPI based wireless drivers (based on wireless-testing (
wt-2023-06-09, wt-2023-07-24, and later)) compile.

Some of these changes can only be applied once all drivers get
updated to not break the old versions currently in the tree.
Mark those changes with __FOR_LATER_DRV_UPDATE for now and flip the
switch at a later point.

Sponsored by: The FreeBSD Foundation
MFC after: 20 days


# 685dc743 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

sys: Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# a5ae63ed 10-Jun-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: initialize txq

In 5a9a0d7803382321b5f9fff1deae5fb08463cf1a we omitted the initialization
of the per-hw txq settings. Fix this.

Sponsored by: The FreeBSD Foundation
MFC after: 10 days
Fixes: 5a9a0d7803382321b5f9fff1deae5fb08463cf1a


# 3206587a 10-Jun-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: improve scan handling

Under certain circumstances a hw_scan may be downgraded to a software
scan. Handle these situations better and make sure we free resources
in all cases once. [1]

Also leave a note about scanning all bands (or we would have to switch
bands manually).

In both cases hardware doing and driver saying seem not entirely
consistent for all and all firmware.

Sponsored by: The FreeBSD Foundation
MFC after: 10 days
Reported by: imp [1]


# cfccc7f3 02-Apr-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: remove extra spaces

Remove two extra spaces. No functional change.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# 8ac540d3 31-Mar-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: adjust locking

Split up the lhw lock and the scan lock. The latter is a mtx
while the former changes from mtx to sx as mac80211 downcalls may
sleep (and the ic lock is not usable in that case either and a larger
project to fix).
This will also enforce some lookups under lock (mostly scan) as well
as general protection for more compat code and avoid a possible
deadlock with one of the upcoming callbacks from driver into the
compat code.

Sponsored by: The FreeBSD Foundation
MFC after: 7 days


# 3f0083c4 31-Mar-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: use ic_printf more consistently

Rather than printing ic_name ourselves (or not at all) use ic_printf()
as a common function from net80211 where possible.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# 3689f8ae 05-Mar-2023 Colin Percival <cperciva@FreeBSD.org>

linux_80211: Don't dequeue lsta if not queued

This fixes an instapanic when restarting wpa_supplicant on my laptop's
iwlwifi device. After this change, iwlwifi enters a nonfunctional
state if wpa_supplicant is restarted, but "service netif restart wlan0"
is enough to get it working again.

releng/13.2 candidate.

Reviewed by: bz
MFC after: 3 days


# 0cbcfa19 07-Feb-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: deal with stopped queues

Following 5a9a0d7803382321b5f9fff1deae5fb08463cf1a initialize the
queue values explicitly and deal with a stopped queue in
ieee80211_tx_dequeue().

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# b0ddb44f 31-Jan-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: fix indent in lkpi_wake_tx_queues()

Fix indentation in lkpi_wake_tx_queues().
No functional changes.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# 3dd98026 31-Jan-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: enhance lkpi_scan_ies_add() for HT and VHT

Add code (currently disabled by #ifdef) for HT and VHT to
lkpi_scan_ies_add(). Switch to a local variable for ic given
the new code also needs the value.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# 5a9a0d78 31-Jan-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: basic implementation of *queue(s)/*txq*

Very basic implementations of ieee80211_{wake,stop}_queue[s],
as well as ieee80211_txq_schedule_start(), ieee80211_next_txq(),
and ieee80211_schedule_txq().
Various combinations of these are used by different wireless
drivers, incl. iwlwifi.

Sponsored by: The FreeBSD Foundation (parts of this work)
MFC after: 3 days


# a8397571 31-Jan-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: implement ieee80211_tx_status_ext()

Add an implementation of ieee80211_tx_status_ext() extending the
internal linuxkpi_ieee80211_tx_status() implementation.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# e30e05d3 31-Jan-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: extend linuxkpi_ieee80211_rx()

Extend linuxkpi_ieee80211_rx() by another argument for
the ieee80211_rx_list() implementation (even though the argument
is currently ignored).

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# 4b0af114 30-Dec-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: move ieee80211_{unregister,restart}_hw out of header

Migrate the two functions from the header into the implementation file
in order to have access to more facilities and not to run into possible
allocation/locking/... problems in the future.

Sponsored by: The FreeBSD Foundation
MFC after: 10 days


# 5edde07c 30-Dec-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: implement cfg80211_{get,put}_bss

Implement cfg80211_{get,put}_bss currently doing malloc/free bits,
so hopefully the drivers get the calls right.

cfg80211_get_bss() sets up a lookup structure which may also take a
result (first hit wins) and calls ieee80211_scan_iterate() comparing
the various values in the iterator funcion. Some of the checks are
partially pointless (as it seems the drivers are not interested in
these parts [ANY] but we keep them for documentation purposes should
futher values arise in the future).

We currently only iterate over the first VAP which will do for now.

Sponsored by: The FreeBSD Foundation
MFC after: 10 days


# b6b352e4 30-Dec-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: set sta supported legacy rates

When initializing the sta set the per-band supported legacy rates
as some drivers take the information from there.

Sponsored by: The FreeBSD Foundation
MFC after: 10 days


# 4a67f1df 06-Nov-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: enable WME support

Most of the WME code has been there disabled for months. One of the
reasons was that it lead to crashes early on. It is now understood
that the crashes are independent event and we can enable WME.
Update the code and deal with the calls from net80211 and adjust the
updates to when mac80211 drivers expect them, coherently put it under
LKPI_80211_WME and enable the define locally.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# e7fe0373 31-Oct-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: pass internal variable to lkpi_80211_mo_sta_state()

With mac80211 operations (MO) tracing on we have seen some ill-ordered
executions of MO functions. In order to limit visibility of the mac80211
sta, pass the internal version into lkpi_80211_mo_sta_state() and only
there convert to the argument needed. This mostly eases tracing and
debugging.

Sposnored by: The FreeBSD Foundation
MFC after: 3 days


# 64d3da00 23-Oct-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: add MO tracing

Add a macro to each implemented mac80211 operation. This currently
turns into a printf if LINUXKPI_80211_DEBUG is defined but in the
future could become a different probe as well.
This is helpful for quick analysis and boot-time problem debugging
when DTrace and other frameworks may be harder to use.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# e3a0b120 05-Sep-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 80211 / iwlwifi: improve queue management

For one initialise vif->hw_queues later set in lkpi_80211_txq_tx_one()
for drivers using them. This may still need slightly more cleanup once
we get QUEUE_CONTROL-supporting drivers into the tree.

For the other rework and improve how we deal with tid/ac/txq in
lkpi_80211_txq_tx_one() and cleanup old comments and unused code.
This seems to reduce (remove) "Invalid TXQ id" reports from iwlwifi.
(The assumption is that the frame(s) triggering this WARN_ONCE or the
added FreeBSD specific logging were sent with lkpi_80211_mo_tx()).

Adjust the one logging from e674ddec0b4138274539587fe9336b577ff1242a
to IWL_DEBUG_TX so that now this is fixed it is also not always logged
anymore but leave it in case we need to further debug queues in the
future.

Tested by: pstef, Kevin Oberman (rkoberman gmail.com)
Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# ec190d91 05-Sep-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 80211: improve linuxkpi_ieee80211_get_tid()

Continue what was started in 26a36948331bd08d9afaddfc0da724eacdb953dd
in iwlwifi and extend out internal implementation of
linuxkpi_ieee80211_get_tid() by an argument as to whether "no-QoS"
answers are acceptable. For the LinuxKPI ieee80211_get_tid() set
this to false as the Linux derived drivers seem to do extra checks
for the QoS-Data frame before acquiring the tid.
Add KASSERTs to enforce the extra argument.
This allows us to use the net80211 variant in LinuxKPI for other
means explicitly documenting that we do accept a IEEE80211_NONQOS_TID.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# a486fbbd 03-Sep-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 80211: scanning code updates

For consistency rename LKPI_SCAN_RUNNING adding a LHW_ prefix.
Add a local flag LKPI_LHW_SCAN_HW mirroring the net80211
IEEE80211_FEXT_SCAN_OFFLOAD flag.
Slightly simplify the code.
Overload (*ic_scan_curchan) and (*ic_scan_mindwell) so that we can
call the net80211 implementation in case of software scan but skip it
in case of full-offload scans.
Also add a bandaid to our (*ic_set_channel) implementation to not siwtch
channels if we have an active hw_scan running.

Obtained from: bz/wireless-dev
Sponsored by: The FreeBSD Foundation (partially)
MFC after: 4 days


# 527687a9 03-Sep-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 80211: implement (*get_antenna) and set ic_[rt]xstream

Implement the mac80211 (*get_antenna) call and after checking any
antenna information present query the current configuration on startup
(both informations should be identical at this point in theory).
Both the wiphy variables and function call report a bitmask not a count.
Count the bits for net80211 for as long as we get away with just a
number in ic_[rt]xstream.

Sponsored by: The FreeBSD Foundation
MFC after: 4 days


# b35f6cd0 03-Sep-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 80211: make HW_CRYPTO compileable again

Rename TRY_HW_CRYPTO to LKPI_80211_HW_CRYPTO for consitency and make
it compileable again in case someone wants to sit down and make it
work. It's probably not too much to do. Otherwise I might eventually
get around to it.

Obtained from: bz/wireless-dev
Sponsored by: The FreeBSD Foundation
MFC after: 4 days


# caaa79c3 27-Aug-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI 802.11: change type of bssid in struct ieee80211_bss_conf

Enabling other driver code found that the bssid in
struct ieee80211_bss_conf is not an array but expected to be
a const pointer (const, != NULL checks).
Adjust accordingly in the header and in the LinuxKPI compat code.
There initialization now needs to be a static array always present
as we need a value before we will have a BSS (node in scan_to_auth)
as the mac80211 driver (*handlers) are expecting the pointer to be
not NULL (copying without checks).
This is a pre-req to enable d3 (CONFIG_PM[_SLEEP]) in the future.

Tested by: Tomoaki AOKI (junchoon dec.sakura.ne.jp)
Tested by: Berislav Purgar (bpurgar gmail.com)
Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# d8dd6b32 30-Jul-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: add missing linuxkpi_cfg80211_bss_flush()

Add the missing implementation of linuxkpi_cfg80211_bss_flush().
without this we get unresolved symbols and drivers won't load.

Reported by: eduardo, Berislav Purgar (bpurgar gmail.com)
MFC after: 3 days
X-MFC-Squash: b0f73768220e945deebebefc4a2d63ae6a3bfe19


# b0f73768 29-Jul-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11 header updates

While working on new and updates to drivers more structs, fields,
functions, .. were found, had to be shuffled around, ..
Some of these are (so far still dummy) functions or not properly
typed fields. The IEEE80211_HE_ constants are all still dummy.
This was msotly as a start to make new (out-of-tree) things compile.

Sponsored by: The FreeBSD Foundation (minor VHT/chan width bits)
MFC after: 1 week


# 841719c0 26-Jun-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: remove an early bandaid to make sure queues are allocated

iwlwifi allocates queues on first wakeup. This takes a lot longer on
FreeBSD's work implementation that it seems to on Linux based on some
discussion. That meant that we couldn't get non-data frames out quickly
enough initially and failed to associate.
d0d2911035192473e8bd3f6b99ed5ca9b1b29e47 should have solved most of this
for us with iwlwifi. None of the other drivers ported to LinuxKPI/802.11
up to today will call a dequeue so we get notified when the queus are
allocated or even need to do so.
Remove the bandaid initilly put in for iwlwifi now and speed up the
overall process of getting us associated.

MFC after: 3 days


# e24e8103 26-Jun-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: cleanup lsta better

This changes cleans up lsta from the VIF station list as well as
deals with freeing the lsta itself so it is not leaked.

lkpi_iv_update_bss() makes this more complicated than it should be
as we ties more sta state (incl. drv/fw) to the node that net80211
does not know about. There is more work to be done detangling this
now that is better understood.

MFC after: 3 days


# ed3ef56b 26-Jun-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: sync sta->addr in lkpi_iv_update_bss()

In lkpi_iv_update_bss() introduced in d9f59799fc3e7 we swap lsta and
along with that sta and drv state if ni gets reused and swapped under
us by net80211. What we did not do was to sync sta->addr which later
(usually in lkpi_sta_assoc_to_run) during a bss_info update cause
problems in drivers (or firmware) as the BSSID and the station address
were not aligned.

If this proves to hold up to fix iwlwifi issues seem on firmware
for older chipsets, multi-assoc runs, and rtw89 (which this fixes)
we should add asserts that lkpi_iv_update_bss() can only happen in
pre-auth stages and/or make sure we factor out synching more state
fields.

Found debugging: rtw89
MFC after: 3 days


# 9597f7cb 26-Jun-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

Revert "LinuxKPI: 802.11: fix iwlwifi fw assert with older chipsets"

This reverts commit 013e516dc9b1b32e9422ab02a875a05fc2d32f39.


# fb6eaf74 11-Jun-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: fix compiling with DEBUG

Fix a build with DEBUG after d0d2911035192473e8bd3f6b99ed5ca9b1b29e47
which lost the __func__, __LINE__ argument in an updated tracing line.

Reported by: Tomoaki AOKI (junchoon dec.sakura.ne.jp)
MFC after: 2 days
X-MFC with: d0d2911035192473e8bd3f6b99ed5ca9b1b29e47


# 013e516d 10-Jun-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: fix iwlwifi fw assert with older chipsets

A problem which showed up on 13.1 between BETA3 and RC1 was that on older
chipsets the fw would crash. While some 0x18 ADD_STA problems were seen
before, d9f59799fc3e was the actual trigger for this problem
(in 0x28 MAC_CONTEXT command) in a squashed merge to the releng branch.
Strangely there were no changes to assoc_to_run in that revision so other
circumstances may be the actual cause but swapping the bss_info update and
the sta_state in that function seem to make my 8265 happy while AX200 and
AX210 stay good.

Thanks to everyone who helped debug this.

Sponsored by: The FreeBSD Foundation (partially)
MFC after: 3 days


# d0d29110 10-Jun-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: rework handling of the special IEEE80211_NUM_TIDS queue

Rework the way we are dealing with the last queue. If the driver
opts in to STA_MMPDU_TXQ then preferably send all non-data frames
via the last (IEEE80211_NUM_TIDS) queue which otherwise is not used
in station mode.
If we do not have that queue we do individual tx() calls for non-data
frames now.
Everything else goes via the selected queue if possible for as long as
we have a ni (sta) and otherwise resorts to direct tx.

Tested on: Intel AX200 and AX210
Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# 71df58ae 05-Jun-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: plug a ni leak in lkpi_sta_assoc_to_run()

In lkpi_sta_assoc_to_run() we are going through some code segments
twice (auth->assoc, assoc->authorized). The 2nd time we shall not
re-gain a reference on the net80211 node as otherwise it'll leak.
Likewise we do not have to re-set lsta and sta.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# dbc06dd9 05-Jun-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11 plug mbuf leak in error cases

Manually free the mbuf in certain error cases from net80211 to not
leak it.
Note that the differences between ieee80211_input_mimo() and
ieee80211_input_mimo_all(), the former not consuming the mbuf while
the later does, is confusing.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# 3540911b 30-Apr-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: use ieee80211_beacon_miss()

In ieee80211_beacon_loss() call into net80211::ieee80211_beacon_miss()
rather than manually bouncing our state. That should give us the
ability to send a probereq and see if the AP is till there rather than
right away going to scan.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# e2c5ab09 18-Apr-2022 John Baldwin <jhb@FreeBSD.org>

linuxkpi_ieee80211_tx_status: Mark ridx as unused.

__diagused only squelches warnings for variables used under
INVARIANTS, it does not apply to custom debug knobs like
LINUXKPI_DEBUG_80211. Use __unused instead.


# d9945d78 15-Apr-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: improve hw_scan

Initially we were using the IEs from ieee80211_probereq_ie() of net80211
and put them into the common_ies field. Start by manually building the
per-band and common IE parts as drivers put them back together.
This also involves allocating the req.ie as one buffer for all IEs over
all bands and setting req.ie_len correctly based on how many bytes we
put in.

Manually building per-band scan IEs we still use the net80211 routines
to add IEs to the buffer (mostly).

This is needed by Realtek drivers but will equally used by others.
Realtek would simply panic due to skbs being allocated with the wrong
length.

Longer-term this will help us, e.g., when not supporting VHT on 2Ghz
and we would have to do this anyway.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# 8891c455 15-Apr-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: use an sx lock to protect the list of vifs

Use an sx lock to protect the list of vifs. We could use the
linux mutex compat for this but our current implementation may
re-acquire the lock recursively so allow this. The change is
mainly motivated by the fact that some callers may sleep in the
interator function called. Recursiveness is needed because we
see find_sta_by_ifaddr() being called from an iterator function
from iterate_interfaces().

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# 383b3e8f 15-Apr-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: start adding rate control to ieee80211_tx_status()

Start adding rate control feedback in ieee80211_tx_status() in order
for net80211 to be able to report something back (which may not
yet be the view of the firmware). iwlwifi is reporting back an MSC 0
even with HT disabled (to be investigated) so we cannot (yet) use
the firmware/driver rate feedback directly.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# ade774b1 14-Apr-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: implement ieee80211_probereq_get()

Implement ieee80211_probereq_get() needed by Realtek drivers.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# 170acccf 08-Apr-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: further fix RSSI calculations

60970a328e280b25b05f1d9a9de1ef91af573c4a did one half of the job
of making rssi relative to nf and numbers for radiotap were fine.
net80211 internally works with .5 dBm units thus we need to apply a
* 2 to the value we pass in to c_rssi; leave a comment explaining.

Note: it is only ifconfig in user space which re-adjust it for printing
or contrib/wpa for calculations. Other applications getting values
from kernel also have to apply the maths.

In collaboration with: J.R. Oldroyd (fbsd opal.com)
Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# 60970a32 01-Apr-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: fix RSSI (and NF)

As in 4a22cd6c4e5f4fc4a38aa7400742d4005c5ae3de nf and rss should be
signed and not unsigned. Change the types in the header and while
here change a magic number to a define as done elsewhere (value does
not change).

When calculating c_rssi we need to make it relative so subtract nf.
And while here improve the debug output.

This will hopefully fix ifconfig wlanN list scan S:N output which
tools use to chose a BSSID and help net80211 internal calculations.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# 86220d3c 31-Mar-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: fix compat code for i386

Compiling another driver on i386 revealed two problems:
- ieee80211_tx_info.status.status_driver_data space needs to be
calculated. While a pointer is 32bit vm_paddr_t is 64 bit on i386
so we didn't fit more than one of these in but needed more space.
- the arguments to ieee80211_txq_get_depth() are expected to
unsigned long and not uint64_t.

No user noticable changes.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# 9d9ba2b7 24-Mar-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: cleanup debugging

Cleanup some debugging. Rename the global variable to be less
generic. Hide all debugging behind #ifdef for now and turn off.
Rename the debugging sysctl so we can start adding more to the
subtree.

There is a need to change that wildly grown infrastructure into
something more homogenic soon but this should do for 13.1.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# 196cfd0b 24-Mar-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: improve hw_scan fallback to sw_scan

Extending what was started in d3ef7fb459ff924911e5276db0c04b13cd8074d9,
when a driver signals that hw_scan is not possible and expects a sw_scan
to be preformed we triggered a sw_scan towards the driver but did not
let net80211 know.
Cancel the initial scan towards net80211. If we we defer to sw_scan
then clear IEEE80211_FEXT_SCAN_OFFLOAD so net80211 will send probe
requests, and actively start a new scan with net80211.
This may have to be further refined in the future but seems to work
for the moment.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# 321735f4 24-Mar-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: remove special handling for (*ic_scan_curchan)

Remove the originally disabling of (*ic_scan_curchan), which for iwlwifi
was not needed. The condition always only was approximate.

A set IEEE80211_FEXT_SCAN_OFFLOAD will still prevent net80211 from sending
probe_reqs if handled by driver/firmware.
ic_scan_curchan will re-arm the timer to switch channels for drivers which
need it (e.g., rtw88, but that again is a NOP for iwlwifi).

So enabling ic_scan_curchan should not have further side effects for iwlwifi
but allow other drivers to work better.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# 768dd32a 24-Mar-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: check IEEE80211_FEXT_SCAN_OFFLOAD on vap

When checking for IEEE80211_FEXT_SCAN_OFFLOAD, do so on the vap rather
than ic. This brings us in line with what net80211 does.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# b2cf3c21 24-Mar-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: make lkpi_ic_set_channel() unconditional

For (*config)() based drivers not using chanctx we need to use
ic_set_channel() to switch channels. So far this was disabled
based on scanning flags (as swscan is one of the initial use cases
for this function). Now make it only dependent on (*config)()
for the moment to save us the work if (*config)() is not supported.

For iwlwifi (*config)() is a NOP so no functional changes there
but for other drivers such as rtw88 this will allow us to scan and
set the channel (which helps to receive on channels other than 1).

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# 4a07abde 24-Mar-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: use cfg80211_chandef_create()

Rather than manually setting up a chandef and then effectively forcing
a memcpy, use cfg80211_chandef_create() to do the work for us entirely.
This works here as we do not store the resulting chandef separately
for other use.

While here remove a duplicate assignment in cfg80211_chandef_create().

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# 67674c1c 23-Mar-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: fix lkpi_lsta_dump() debugging

Fix two last-minute changes of d9f59799fc3e7940c47aa674c25994e640eae45e:
(1) for consitency name the debugging function lkpi_lsta_dump()
(2) pass in the original node (ni) rather than taking it from the lsta
to avoid problems realted to bss_update as mentioned in the above
commit.

No functional changes for users.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days
X-MFC with: d9f59799fc3e7940c47aa674c25994e640eae45e


# d9f59799 22-Mar-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: rework sta state machine compatibility

Rework the state machine parts for various reasons:
(1) to add sta tracing to be able to better follow ni and lsta state
(2) factor out/implement lkpi_lsta_remove() to unlink the lsta and
free the ni reference.
(3) avoid calling lkpi_disassoc() when you would think you should as
changing BSS_CHANGED_ASSOC setting vif->bss_conf.assoc to false
triggers a sta removal from firmware in iwlwifi which then triggers
follow-up errors. I do not understand why they use flags and state
and ?? in parallel (too many options and ways to do things?).
(4) when "roaming" (or being disassoc/deauth) from an AP both net80211
and apparently so mac80211 re-start with a new node/sta. This
results in us losing one or the other state in the compat layer
or not updating firmware appropriately. To resolve this make use
of (a) the newly introduced (*iv_update_bss)() and (b) always tear
a station down to "State 1" (INIT/SCAN/pre-AUTH) and only if needed
re-create the new one (if we go to AUTH).
A slightly earlier version has survived a night of wpa_supplicant
and hostapd fighting each other over disassoc and deauth and
re-associating/authorizing.

While there update a few comments and typos and do a few minor auxiliary
changes which are hard or not worth to extract.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# fa8f007d 22-Mar-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: factor out dtim/tsf updates

Factor out dtim/tsf setting/updates into lkpi_update_dtim_tsf()
with tracing and add an extra update call.
This avoids some code duplication and puts maintainance into a
single place.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# 4f61ef8b 22-Mar-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: factor out lkpi_lsta_alloc() from lkpi_ic_node_alloc()

Split lkpi_ic_node_alloc() into two functions to make the code simpler
and to allow lkpi_lsta_alloc() to be re-used from another part of the
code related to (*iv_update_bss)().

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# bb81db90 22-Mar-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: implement ieee80211_beacon_loss()

Implement ieee80211_beacon_loss() similar to
ieee80211_connection_loss() with different state handling.
While here leave a comment in connection_loss() about the state
change argument.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# c0cadd99 16-Feb-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11 simplify beacon checks in rx path

In linuxkpi_ieee80211_rx() check if the frame is a beacon once upfront
and use the result for enhanced debugging and further checks.
This was done intially for rx_status->device_timestamp debugging.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# cc4e78d5 16-Feb-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11 advertise full offload scanning based on hw_scan only

We disabled hw_scan for drivers not advertising SINGLE_SCAN_ON_ALL_BANDS.
Do not depend on this hw flag to set IEEE80211_FEXT_SCAN_OFFLOAD for
net80211 as otherwise scanning will never work.
Long-term we probably want to re-think how we do/integrate hw_scan
better in net80211.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# 3d09d310 16-Feb-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: disable ic_headroom for the moment

There is a problem with some drivers, such as rtw88, asking for more
headroom than we currently can handle throughout the stack (we have
other legacy wireless driver in the tree with similar problems).
This may trigger an assertion in the TCP syncache where we are checking
for a reply to fit in MHLEN.
While for the moment we still copy data from mbufs to skbs,
we can simply disable the extra headroom request in ic_headroom and
deal with it ourselves (which we already did anyway).
Leave a link to the thread on freebsd-transport detailing more of the
problem so we can find it again and solve it here or there.

MFC after: 3 days


# 61a68e50 15-Feb-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11 enahnce linuxkpi_ieee80211_iterate_interfaces()

Add support for IEEE80211_IFACE_SKIP_SDATA_NOT_IN_DRIVER in
linuxkpi_ieee80211_iterate_interfaces() needed by a driver.

MFC after: 3 days


# c5b96b3e 15-Feb-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11 assign an(y) early chandef

The Realtek driver assumes an early chandef to be set. At the time
of linuxkpi_ieee80211_ifattach() we do not really know one yet so
try to find the first one which is available and set that.
This prevents a NULL-deref panic.

MFC after: 3 days


# 652e22d3 15-Feb-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: defer workq allocation until we have a name

Turned out all the workq's taskqueues were named "wlanNA" if you had
more then one card in a machine as by the time we called wiphy_name()
the device name was not set yet and we returned the fallback.

Move the alloc_ordered_workqueue() from linuxkpi_ieee80211_alloc_hw()
to linuxkpi_ieee80211_ifattach() at which time the device name has
to be set to give us a unique name.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# d3ef7fb4 15-Feb-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11 scan update

Realtek's rtw88 is returning a hard-coded 1 in case they cannot
hw_scan (fw not advertising it). In that case if we want any scan
to run we need to fall-back to sw scan. Start dealing with this.
Long-term we probably need to keep internal state.

MFC after: 3 days


# 6baea331 15-Feb-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: skbuff updates

Various updates to skbuff for new/updated drivers and some housekeeping:
- update types and struct members, add new (stub) functions
- improve freeing of frags.
- fix an issue with sleeping during alloc for dev_alloc_skb().
- Adjust a KASSERT for skb_reserve() which apparently can be called
multiple times if no data was put into the skb yet.
- move the sysctl from linux_8022.c (which may be in a different module)
to linux_skbuff.c so in case we turn debugging on we do not run into
unresolved symbols. Rename the sysctl variable to be less conflicting
and update debugging macros along with that; also add IMPROVE().
- add DDB support to show an skbuff.
- adjust comments/whitespace.

No functional changes intended for iwlwifi.

Sponsored by: The FreeBSD Foundation (partially)
MFC after: 3 days


# 2e183d99 15-Feb-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11 header updates and add/adjust source dependencies.

This update is for more/newer versions of drivers:
- add and properly place more structs, enums, defines needed by drivers.
- correct types of struct fields.
- make various function arguments const.
- move REG_RULE() macro to its own file regulatory.h and
use macros for calculations.
- add linuxkpi_ieee80211_get_channel() implementation.
- change linuxkpi_ieee80211_ifattach() to return int for error checking.

No intended functional changes for iwlwifi.

Sponsored by: The FreeBSD Foundation (partially)
MFC after: 3 days


# cee56e77 14-Feb-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11: get rid of lkpi_ic_getradiocaps warnings

Users are seeing warnings about 2 channels (1 per band)
triggered by an ioctl from wpa_supplicant usually:
lkpi_ic_getradiocaps: Adding chan ... returned error 55
This was an early FAQ.

Check the current number of channels against maxchans and the return
code from net80211. In case net80211 reports that we reached the limit
do not print the warning and do not try to add further channels.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# c8dafefa 15-Jan-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11 Refine/add DTIM/TSF handling

Correct data types related to delivery traffic indication map (DTIM)/
timing synchronization function (TSF) and implement/refine their
handling. This information is used/needed by iwlwifi to set a station
as associated. This will hopefully avoid more "no beacon heard"
time event failures.

The recording of the Linux specific sync_device_ts is done in the
receive path for now in case we do have the right information
available. I need to investigate as to how-much it may make sense
to also migrate it into net80211 in the future depending on the
usage in other drivers (or how we did handle this in the past in
natively ported versions, e.g. iwm).

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# f3229b62 15-Jan-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11 handle connection loss differently

Rather than just bouncing back to SCAN bounce to INIT on connection
loss. This is should be refined in the future as the comment already
indicates but we need to tie two different worlds together.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# bec76628 10-Jan-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11 fix locking in lkpi_stop_hw_scan()

In lkpi_stop_hw_scan() we have to unlock around cancelling the
hardware scan and an msleep to wait for the confirmation that the
scan ended. Otherwise we are sleeping with the non-sleepable
net80211 com lock held. At the same time we need to hold the lhw
lock for the msleep().
This lock change got lost in the refactoring of lkpi_iv_newstate().

Reported by: ambrisko, delphij
PR: 261075
MFC after: 3 days
Sponsored by: The FreeBSD Foundation


# 312ba38a 10-Jan-2022 Ruslan Makhmatkhanov <rm@FreeBSD.org>

LinuxKPI: 802.11 correctly spell queues

PR: 261078
MFC after: 3 days
Sponsored by: The FreeBSD Foundation


# 086be6a8 08-Jan-2022 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11 handle IEEE80211_CONF_IDLE better

We never initialized hw->conf.flags for IEEE80211_CONF_IDLE but
on set_channel we would clear it and announce a change.
This lead to a problem that drivers may do some work every time
which was not needed and may lead to unexpected behaviour (for no
better driver code).

Properly initialize conf.flags with IEEE80211_CONF_IDLE.
Factor out the toggling into a function and clear IDLE while
sw scanning and when associated and set again when scan ends
or we are bouncing out of assoc.

MFC after: 3 days


# 500be2e8 31-Dec-2021 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: 802.11 fix queue wait

We are using a bandaid to wait for queues after station creation
looping and pausing.
The abort condition was looping in the wrong direction so we were
potentially waiting forever if queues never became ready.
From initial user test data we also found that the wait time was
too low in some cases so increase the length.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# 6b4cac81 26-Dec-2021 Bjoern A. Zeeb <bz@FreeBSD.org>

LinuxKPI: add 802.11 compat code

Add 802.11 compat code for mac80211 and to a minimal degree cfg80211.
This allows us to compile and use basic functionality of wireless
drivers such as iwlwifi.

This is a constant work in progress but having it in the tree will
allow others to test and more easy to track changes and avoid having
snapshots no longer applying to branches.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days