Commit graph

598 commits

Author SHA1 Message Date
Bjoern A. Zeeb
a27b3695d1 LinuxKPI: 802.11: improvements to (*ampdu_action)() callers
Annotate lkpi_ic_recv_action(), lkpi_ic_send_action(), and
lkpi_ic_ampdu_enable() with HT specifc debug logging as we only hook
them up currently for debug tracing but later should not need them
anymore.

Start the implementation for lkpi_ic_addba_request(),
lkpi_ic_addba_response(), and lkpi_ic_addba_stop().

Improve the implementation of lkpi_ic_ampdu_rx_start() and
lkpi_ic_ampdu_rx_stop().

Sponsored by:	The FreeBSD Foundation (commit)

(cherry picked from commit 310743c4ccc545d58401cb9fb7761432e12a9fb5)
2024-11-14 01:53:12 +00:00
Bjoern A. Zeeb
ce5b0b7b99 LinuxKPI: 802.11: hookup net80211 callbacks dependent on (*ampdu_action)()
If a LinuxkPI base wireless driver does not support the (*ampdu_action)()
ieee80211_ops function for offloading parts to firmware there is no
reason for us to hook into the net80211 callbacks either but simply
to let software (net80211) handle this.

Sponsored by:	The FreeBSD Foundation (commit)

(cherry picked from commit 86bc7259d3d558495511a0a23d137b4a6cd030f3)
2024-11-14 01:53:12 +00:00
Bjoern A. Zeeb
8d9b4e219f LinuxKPI: 802.11: improve lladdr change to not use ifnet internals
The changes from 4aff4048 were based on net80211 which is still using
if_private.h details.  Adjust the code to no longer depend on internal
details of ifnet.  We also switch the "check"-functionn from if_init to
if_transmit which we can query.  Given we do have a per-vif eventhandler
we could do without that check but would still need to check
if_getflags() for IFF_UP.

Sponsored by:	The FreeBSD Foundation
Reported by:	jhibbits
Fixes:		4aff4048
Reviewed by:	jhibbits
Differential Revision: https://reviews.freebsd.org/D47490

(cherry picked from commit edab5a280e0b4a53d0f3e34957075c7efe048e8d)
2024-11-14 01:53:12 +00:00
Bjoern A. Zeeb
d964b9d8ed LinuxKPI: 802.11: adjustments for v6.11 iwlwifi, rtw88 and rtw89
Bring ing the LinuxKPI 802.11 compat bits which are not altering
the mac80211 ops KPI.

* Add various functions for driver updates.
* Add functions (some compat code to I assume cleanup some
  mac80211 ops) emulating chanctx changes doing (*config) updates.
* Adjust structs and defines.
* Deal with an enum growing more than 32 bits in printf.
* Add a mtx to struct wiphy which is exposed to the drivers.
  Handle initialization and destruction for now.
* Implementation of wiphy_work and wiphy_delayed_work.
* Set was_assoc for deassoc/deauth in prep_tx_info.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit ac1d519c01ca8beb59f27962c7052d09a03f72c8)
2024-10-31 14:33:57 +00:00
Bjoern A. Zeeb
8341284368 LinuxKPI: update rcu_dereference_*() and lockdep_is_held()
Update rcu_dereference_{check,protected}() to call the check and log
once if it fails and if the RCU debug sysctl is turned on.
Also add proper checks for conditions passed in to these functions.
For that implement linux_rcu_read_lock_held() (lots of help from wulf).

(While here also remove extraneous extern for function prototypes).

Update lockdep_is_held() to always be an inline function with argument
annotation so that we do no longer have unused variables
in callers which only call lockdep_is_held().

Sponsored by:	The FreeBSD Foundation
Reviewed by:	wulf
Differential Revision:  https://reviews.freebsd.org/D46842

(cherry picked from commit 5c92f84bb607c692ce4fa762a7a3c4b86a2fa281)
2024-10-31 14:33:57 +00:00
Bjoern A. Zeeb
1579a25f0a LinuxKPI: pci: rename PCI_IRQ_LEGACY to PCI_IRQ_INTX
PCI_IRQ_LEGACY was added in 366d68f283 (likely) for rtw88 only.
The define now got renamed and I cannot find any other use but
rtw88 and rtw89.
We keep the old name as comapt while driver updates are in
progress enabling it defining LINUXKPI_VERSION for the two drivers.

Sponsored by;	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D46822

(cherry picked from commit 157e93e0e8138fbaa6ab5d5b20b0c23f903667a6)
2024-10-31 14:33:56 +00:00
Bjoern A. Zeeb
0dee359c09 LinuxKPI: netdevice: add alloc_netdev_dummy()
Add alloc_netdev_dummy() which is needed by an updated rtw88 driver.
Given we already call linuxkpi_init_dummy_netdev() ourselves allow the
setup function to be NULL to not initialize and start a tasq td twice.

Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D46802

(cherry picked from commit 105331f658e2f14fb4daa64dcd076c7369505295)
2024-10-31 14:33:56 +00:00
Austin Shafer
65de0f1855 LinuxKPI: 802.11: fix ieee80211_schedule_txq() to avoid rtw89 panic
rtw89 TX path was faulting in linuxkpi_ieee80211_next_txq() due to a
"double scheduling" check in linuxkpI_ieee80211_schedule_txq() being
incorrect:
the next pointer may be NULL there if the element is the last in the
tailq, so correctly check tqe_prev.  Without the fix we may have queued
the same element to the tailq twice, and because it was the last element
and had a NULL tqe_next, that NULL value would get propogated into
another node's tqe_prev on removal, and other such nastiness.

With this rtw89 no longer panics.

Reviewed by:	bz
Differential Revision: https://reviews.freebsd.org/D47006

(cherry picked from commit 41b746e05231b44c87f3a3087a7fe29966af6d0f)
2024-10-16 21:46:19 +00:00
Mikhail Pchelin
a92626b33e linux80211: fix default deflink.rx_nss
Native Linux implementation sets this as a maximum between 1 and
ht/vht/eht rx SS'es, FreeBSD does the same, but uses 0 as a minimum,
which leads setting it to 0 if we're not in ht/vht case.

This 0 was breaking rtw89 driver, when it was trying to determine
SS number by subtracting 1 from rx_nss and passing the value to the
hardware.

After this patch rtw89 association and simple ping work reliably,
but more work is needed to make the driver robust with heavy traffic
(iperf3) and being long idle.

Reviewed by:	bz
Sponsored by:	Future Crew LLC
Differential Revision:	https://reviews.freebsd.org/D46528

(cherry picked from commit f5a58c2da23930ee4870f2eb54788f4669b9aa33)
2024-10-09 19:19:21 +00:00
Zhenlei Huang
7bea79c1ab LinuxKPI: 802.11: Stop checking for failures from malloc(M_WAITOK)
As a consequence lkpi_ieee80211_ifalloc() now does not fail. Remove
unneeded NULL check.

MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D45852

(cherry picked from commit 7bcb1228558b4325fab39616e2e3b2573a9e7da6)
2024-09-30 12:44:17 +08:00
Bjoern A. Zeeb
314069ff8c LinuxKPI: 802.11: support manual lladdr changes
Allow a user to change the "ether" address by ifconfig while a VAP is
not UP.  Compared to net80211 (given we have no callback) we register
an eventhandler per-vif (a global one would force us to use hacks to
derive if a vap is indeed also a lkpi_80211 vif).

Sponsored by:	The FreeBSD Foundation
PR:		277356
Tested by:	lwhsu
Differential Revision: https://reviews.freebsd.org/D46121

(cherry picked from commit 4aff4048f5b1b6ab0b905726853ba6083e37cc37)
2024-09-28 10:35:13 +00:00
Bjoern A. Zeeb
78556119d5 LinuxKPI: 802.11: consistently spell TRACE-RX: as such
We have TRACE in one place and TRACE-RX in another.  Spell it
"TRACE-RX: %s: ..." everywhere.  Helps with pattern matching.

Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D45818

(cherry picked from commit bd206a6f4a87214ae8c1b32f1051b07362080361)
2024-09-28 10:35:13 +00:00
Bjoern A. Zeeb
af034dcbb2 LinuxKPI: 802.11 compile in debugging based on IEEE80211 debugging
If IEEE80211 debugging is turned on in kernel configs also turn on
LinuxKPI 802.11 and SKB debugging (sysctls) to have them available.

Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D45820

(cherry picked from commit 59d262fe969af5a8a83f0ccd7586c9bd2c8fb1f3)
2024-09-28 10:35:12 +00:00
Bjoern A. Zeeb
f9edc5b3f6 LinuxKPI: move __kmalloc from slab.h to slab.c
In order to allow the allocator to change in the future move it into
the implementation file from being an inline function in the header.

While here factor out the size calculation and add a comment as-to why
this is done.  We will need the size (_s) in the future to make a
decision on how to allocate.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D45815

(cherry picked from commit 1f7df757017404011732196e65981d9325f7a89f)
2024-09-28 10:35:12 +00:00
Vladimir Kondratyev
59d36b8969 LinuxKPI: update linuxkpi_video to Linux 6.6
disable hdmi_audio_infoframe_pack_for_dp function for now as it depends
on not imported yet drm sources and is not used by drm-kmod.

Reviewed by:	manu
Sponsored by:	Serenity CyberSecurity, LLC
Differential Revision:	https://reviews.freebsd.org/D46224

(cherry picked from commit c89d94ad5d95fd15e891b2723caae8a6104ee153)
2024-08-11 13:12:38 +03:00
Vladimir Kondratyev
a9a364864e LinuxKPI: Fix resource leak on pci_iounmap-ing of PCI BAR
If the resource was allocated with want_iomap_res flag set.

Sponsored by:	Serenity CyberSecurity, LLC
MFC after:	1 week
Reviewed by:	manu, bz
Differential Revision:	https://reviews.freebsd.org/D45905

(cherry picked from commit 14fc33ea3a0571ca70e609b6f9e67db39f7c6140)
2024-08-02 00:16:33 +03:00
Vladimir Kondratyev
7403f2c657 LinuxKPI: Add pci_iomap_range function
pci_iomap_range creates a virtual mapping cookie for a PCI BAR.
As compared with pci_iomap it got extra offset parameter.

Sponsored by:	Serenity CyberSecurity, LLC
MFC after:	1 week
Reviewed by:	manu, bz
Differential Revision:	https://reviews.freebsd.org/D45904

(cherry picked from commit fcc350c375f776318d0da8021109631492ab9261)
2024-08-02 00:16:23 +03:00
Vladimir Kondratyev
d23c4b1a55 LinuxKPI: Add acpi_dev_get_first_match_dev and acpi_device_handle
acpi_dev_get_first_match_dev returns the first match of ACPI device
and acpi_device_handle returns its ACPI handle.

Sponsored by:	Serenity Cyber Security, LLC
MFC after:	1 week
Reviewed by:	manu
Differential Revision:	https://reviews.freebsd.org/D45847

(cherry picked from commit 3e90716331cdbdee7465213d389a33f90dad11cf)
2024-08-02 00:15:51 +03:00
Vladimir Kondratyev
b71e429d54 LinuxKPI: Add devm_device_add_group to linux/device.h
devm_device_add_group creates a managed attribute group for a device.

Sponsored by:	Serenity Cyber Security, LLC
MFC after:	1 week
Reviewed by:	manu
Differential Revision:	https://reviews.freebsd.org/D45845

(cherry picked from commit a1181662d3707d8165d7153a0aa5d76ea1ddc11a)
2024-08-02 00:15:28 +03:00
Vladimir Kondratyev
8a6ec29756 LinuxKPI: Automatically enable drm support for devices named "drmn"
This allows replace linux_pci_(un)register_drm_driver calls with driver
renaming to FreeBSD name.

Sponsored by:	Serenity CyberSecurity, LLC
MFC after:	1 week
Reviewed by:	manu, bz
Differential Revision:	https://reviews.freebsd.org/D45906

(cherry picked from commit 5d20075f8b9f7107aa0a246e5165d9816e816a44)
2024-08-02 00:14:03 +03:00
Vladimir Kondratyev
88ca9c8226 LinuxKPI: Add DEFINE_DEBUGFS_ATTRIBUTE_SIGNED to linux/debugfs.h
Sponsored by:	Serenity CyberSecurity, LLC
MFC after:	1 week
Reviewed by:	manu
Differential Revision:	https://reviews.freebsd.org/D45615

(cherry picked from commit 8c5c572125665e3fd8a033d1a8b0a370e5a43e24)
2024-08-02 00:09:41 +03:00
Vladimir Kondratyev
c0b32a4ea4 LinuxKPI: Remove linux/sched.h include from linux/kernel.h header
This include prevents usage of any kernel.h helpers in sched.h and
all of dependencies. Linux does not have it too.
Fix building of kernel and drm-kmod after than.

Sponsored by:	Serenity CyberSecurity, LLC
MFC after:	1 week
Reviewed by:	manu, bz
Differential Revision:	https://reviews.freebsd.org/D45692

(cherry picked from commit 256eb8d5361143b7d436a195530e0eefe1450e6d)
2024-08-02 00:09:41 +03:00
Austin Shafer
89e485e04d linuxkpi: Allow ida_destroy and idr_destroy to be called multiple times
This fixes some weird behavior triggered by nvidia-drm.ko: some DRM
cleanup functions will be called multiple times, leading to a double
free. drm_mode_config_cleanup will be called twice, causing ida_destroy
to be called twice. Although calling the cleanup twice doesn't seem
very clean, on Linux this seems to be permissable as it handles it
just fine. Not doing these checks causes mutex panics and double frees.

In order to preserve this behavior this change checks if the objects
have already been destroyed and bails if so. This fixes the panic seen
when unloading the nvidia-drm driver.

MFC after:	1 week
Reviewed by:	bz, manu
Differential revision:	https://reviews.freebsd.org/D44865

(cherry picked from commit 613723bac219cb08ac1ad0afd3e07850d7fccc10)
2024-08-02 00:09:39 +03:00
Vladimir Kondratyev
5ea6546660 LinuxKPI: Improve timer_shutdown_sync
timer_shutdown_sync not only shutdowns a timer but prevents it rearming.

Sponsored by:	Serenity CyberSecurity, LLC
Reviewed by:	emaste
MFC after:	1 week

(cherry picked from commit 61fb195e8dd08d4b006a176c09682f061424cb95)
2024-08-02 00:09:38 +03:00
Vladimir Kondratyev
73b587e2ee LinuxKPI: Set suspend type on syspend/resume cycle enter
Recent amdgpu depends on pm_suspend_target_state value to separate
S3 and S0ix support.

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu (in bugzilla)
MFC after:	1 week

(cherry picked from commit 8ace984e477b0ee1fcc317752603ec4fe9c7f636)
2024-08-02 00:09:37 +03:00
Bjoern A. Zeeb
2ab1b827d4 LinuxKPI: 802.11: make sure we can send DISASSOC or DEAUTH frames
The "Invalid TXQ" error from iwlwifi seems to be triggered by a
frame being sent for a sta which is no longer known to the driver/fw.

While we make sure to trigger the sending of the frame in net80211
early enough (by calling (*iv_newstate)() early on rather than at
the end), TX in LinuxKPI is run in a deferred task.  When we drop the
net80211 ic lock again and re-acquire the LHW lock the packet may not
yet have made it to the driver.
Work around this between the (ic and lhw) locks by making sure
(a) no new packets get queued after we return from (*iv_newstate)(),
and (b) the TX task has run or gets cancelled and we manually push
any remaining packets out (or let lsta_free() clean them up).
The disabled packet queuing now also needs to be re-enabled in
scan_to_auth() in case an lsta is staying in service or gets re-used.

Also make sure that any following lkpi_wake_tx_queues() calls no
longer ignore queues which have not seen a prior dequeue.
This former workaround "feature" (ltxq->seen_dequeue) should be
fully garbage collected in a later change on its own.

Sponsored by:	The FreeBSD Foundation
PR:		274382
Tested by:	emaste, lwhsu, thj, rkoberman at gmail.com
Accepted by:	adrian
Differential Revision: https://reviews.freebsd.org/D45508

(cherry picked from commit 886653492945f7e945eb9bdaf5bc2ae26df96236)
2024-06-12 13:59:46 +00:00
Bjoern A. Zeeb
9e36362f6a LinuxKPI: 802.11: close race lkpi_sta_scan_to_auth()/(*iv_update_bss)()
We have to unlock the net80211 ic lock in order to be able to call
sleepable downcalls to the driver/firmware; a 2nd thread may go through
net80211::join1() and (*iv_update_bss)() after we checked and unlocked.
Re-check status at the end of the function under the ic lock so that we
do not accidentally set lvif_bss_synched to true again despite it no
longer being true.

This should fix a race where we lost the (*iv_update_bss)() state
during startup where one SCAN->AUTH is followed by a (then) AUTH->AUTH
and lkpi_sta_a_to_a() did the wrong thing.

Once we re-consider net80211 state and allowing a second join
on a different node or iv_bss update without previously tearing down
the older node we can likely undo a lot of these extra checks and
workarounds.

Sponsored by:	The FreeBSD Foundation (updated version)
Tested by:	emaste (on and off)
Reviewd by:	cc
Differential Revision: https://reviews.freebsd.org/D43967

(cherry picked from commit 105b9df26ee0286f3a5a7d191075e068dee1c4a2)
2024-06-12 13:59:32 +00:00
Bjoern A. Zeeb
29f9003cbb LinuxKPI: 802.11: initalize lsta to NULL in linuxkpi_ieee80211_rx()
The logic following this new assignment in some cases may not set lsta
but the later tracing is checking for it to be != NULL.
With lsta not initialized that check may not hold up and later we would
dereference lsta->state and possibly panic.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D45507

(cherry picked from commit 582469016aed4fac3a7ead24dc31000edbb7e823)
2024-06-12 13:59:11 +00:00
Bjoern A. Zeeb
49f29c4183 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)
Reviewed by:	cc
Differential Revision: https://reviews.freebsd.org/D43966

(cherry picked from commit 45bce6fa306fc3a211949f63c9bbb7932fe5a3bd)
2024-06-12 13:59:04 +00:00
Bjoern A. Zeeb
323db2cbbb 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
Differential Revision: https://reviews.freebsd.org/D45185

(cherry picked from commit d1af434d99941d32a09c48fb3ef77ef83e203d29)
2024-06-12 13:58:56 +00:00
Bjoern A. Zeeb
7ad7453748 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
PR:		275255
Tested with:	AX210, 8265 (bz); 9260 (Bakul Shah)
Differential Revision: https://reviews.freebsd.org/D45293

(cherry picked from commit 5a4d24610fc6143ac1d570fe2b5160e8ae893c2c)
2024-06-12 13:58:36 +00:00
Bjoern A. Zeeb
31c476da2d LinuxKPI: pm: add SET_SYSTEM_SLEEP_PM_OPS() and device_can_wakeup()
Add the SET_SYSTEM_SLEEP_PM_OPS() by factoring some other macro code
out in order to set the suspend/resume functions when the struct is
already given.  Such is the case in iwlwifi d3.

Also add an initial implementation of device_can_wakeup().  Though
this is likely all we need we have no way of setting the flag for it
yet so leave a pr_debug() and a comment there as well.  Until we want
to support WoWLAN this is likely not needed for wireless.
Doing it the proper way checking a bool in 'struct dev_pm_info' would
change 'struct device' and with that 'struct pci_dev' and break the
KBI.  In favour of mergeability this version does not implement the
full functionality yet.

Both help to make an updated iwlwifi d3 compile.

Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D45358

(cherry picked from commit 3753988c5d22393fbdefb6aa16b5a5a699d05642)
2024-06-12 13:57:44 +00:00
Emmanuel Vadot
183b64dfd8 linuxkpi: spinlock: Simplify code
Just use a typedef for spinlock_t, no need to create a useless
structure.

Reviewed by:		bz, emaste
Sponsored by:		Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D45205

(cherry picked from commit ae38a1a1bfdf320089c254e4dbffdf4769d89110)

linuxkpi: Fix spin_lock_init

Some linux code re-init some spinlock so add MTX_NEW to mtx_init.

Reported by:	David Wolfskill <david@catwhisker.org>
Fixes:		ae38a1a1bfdf ("linuxkpi: spinlock: Simplify code")

(cherry picked from commit cff79fd02636f34010d8b835cc9e55401fa76e74)
2024-06-04 13:22:40 +02:00
Emmanuel Vadot
5080cf0846 linuxkpi: Add linuxkpi_video module
This contain the hdmi code and the aperture code like in linux.

Differential Revision:	https://reviews.freebsd.org/D44925
Reviewed by:		bz
Obtained from:		drm-kmod
Sponsored by:		Beckhoff Automation GmbH & Co. KG

(cherry picked from commit 11d79c4756b7c85faf7c4a268c301a41ce0887b9)
2024-06-04 13:06:45 +02:00
Emmanuel Vadot
13671022eb linuxkpi: hdmi: Split the module declaration to a new file
In order to have a proper linuxkpi_video kmod, move the module declaration
to a new file as linuxkpi_video will also include linux_hdmi.c

Differential Revision:	https://reviews.freebsd.org/D44926
Reviewed by:		bz, emaste, wulf
Sponsored by:		Beckhoff Automation GmbH & Co. KG

(cherry picked from commit 7f84bb34a1d191949ec519a01c0c574f5e827c88)
2024-06-04 13:06:40 +02:00
Bjoern A. Zeeb
b5cf81e209 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.

Reviewed by:	cc
Differential Revision: https://reviews.freebsd.org/D43944

(cherry picked from commit 1665ef979d3adab05d178480077674ab5978e4f0)
2024-04-22 17:00:27 +00:00
Bjoern A. Zeeb
fb94767f78 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.

Reviewed by:	cc
Differential Revision: https://reviews.freebsd.org/D43965

(cherry picked from commit ac867c20e67423e5019ab90148c387ea127eeffb)
2024-04-22 17:00:16 +00:00
Bjoern A. Zeeb
25e0847ef7 LinuxKPI: napi_schedule() requires return value, implement napi_is_scheduled()
A newer version of iwlwifi requires a return value from napi_schedule();
unclear if the function always should have been bool. Add the bool to test
based on the napi_schedule_prep() result.

Also add napi_is_scheduled() for rtw89.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	emaste (previous version)
Differential Revision:	https://reviews.freebsd.org/D44591

(cherry picked from commit 21761f2ede4ebad13e78112b9409c1f20f946781)
2024-04-22 17:00:00 +00:00
Bjoern A. Zeeb
e74405a4d6 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.

Reviewed by:	cc, adrian

(cherry picked from commit 906521f8176b13533556d742db4ab28e847b85c0)
2024-04-01 23:46:10 +00:00
Bjoern A. Zeeb
dd167e5907 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.

PR:		276083
Reviewed by:	cc

(cherry picked from commit 759a996d610d9354aac5c48a6bdc9cedcba2f48b)
2024-04-01 23:46:10 +00:00
Bjoern A. Zeeb
035424535b 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)
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D43909

(cherry picked from commit fa4e4257943650c0b5f58c01bb0bdfadea61dfb2)
2024-02-18 18:31:18 +00:00
Bjoern A. Zeeb
12887199b3 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
Reviewed by:	cc
Differential Revision: https://reviews.freebsd.org/D43753

(cherry picked from commit 0936c648ad0ee5152dc19f261e77fe9c1833fe05)
2024-02-18 18:31:17 +00:00
Bjoern A. Zeeb
8c450ea108 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)
Reviewed by:	cc
Differential Revision: https://reviews.freebsd.org/D43725

(cherry picked from commit 2ac8a2189ac6707f48f77ef2e36baf696a0d2f40)
2024-02-18 18:31:17 +00:00
Bjoern A. Zeeb
1c7be8ecad 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

(cherry picked from commit eac3646fcdd445297cade756630335e23e92ea13)
2024-02-18 18:31:14 +00:00
Bjoern A. Zeeb
19a405d238 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

(cherry picked from commit 9fb914634eff85b3b36bcbf39c1faf2967b0aa9e)
2024-02-18 18:31:13 +00:00
Bjoern A. Zeeb
8e599ff98d 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 b65f813c1a,
21c4082de9,
17c328b6ae,
af2441fbc7,
and 6c3e93cb5a for ath.

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

(cherry picked from commit de607e3c230be88f6232b9c9fd6c37199648dc8c)
2024-02-18 16:42:21 +00:00
Bjoern A. Zeeb
7730aec6b7 LinuxKPI: reduce impact of large MAXCPU
Start scaling arrays dynamically instead of using MAXCPU, resulting in
extra allocations on startup but reducing the overall memory footprint.
For the static single CPU mask we provide two versions to further save
memory depending on a low or high CPU count system.  The threshold to
switch is currently at 128 CPUs on 64bit platforms.
More detailed comments on the implementations can be found in the code.

If I am not wrong on a MAXCPU=65536 system the memory footprint should
roughly go down from 512M to 1.5M for the static single CPU mask.

Submitted by:	olce (most of this final version)
Sponsored by:	The FreeBSD Foundation
PR:		274316
Differential Revision: https://reviews.freebsd.org/D42345

(cherry picked from commit 488e8a7faca51a71987fbf00cd36cfcd19269db7)
2024-02-18 16:41:24 +00:00
Vladimir Kondratyev
6d4b6edcf3 LinuxKPI: Allow kmalloc to be called when FPU protection is enabled
Amdgpu driver does a lot of memory allocations in FPU-protected sections
of code for certain display cores, e.g. for DCN30. This does not work
on FreeBSD as its malloc function can not be run within a critical
section. Check this condition and temporally exit from FPU-protected
context to workaround issue and reduce source code patching.

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu (previous version)
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D42822

(cherry picked from commit c0b8047bdc13040eafb162c4b7b5dba11034ff4b)
2024-02-17 23:58:39 +03:00
Vladimir Kondratyev
455fa56ad4 LinuxKPI: Add acpi_dev_present() function.
acpi_dev_present detects that a given ACPI device is present based on
Hardware ID, Unique ID and Hardware Revision of the device.

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42823

(cherry picked from commit 04952a9456e226460d1d95c42ea53861b1133b1a)
2024-02-17 23:58:39 +03:00
Vladimir Kondratyev
a87884e34e LinuxKPI: Add pcie_capability_clear_and_set_word() function
It does a Read-Modify-Write operation using clear and set bitmasks on
PCI Express Capability Register at pos. As certain PCI Express
Capability Registers are accessed concurrently in RMW fashion, hence
require locking which is handled transparently to the caller.

Sponsored by:	Serenity CyberSecurity, LLC
Reviewed by:	manu, bz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42821

(cherry picked from commit 808ae4e29b6b9c9acc7eab013c5045370df8182a)
2024-02-17 23:58:39 +03:00