Commit graph

966 commits

Author SHA1 Message Date
Dmitry Chagin
8f7fb96aaf LinuxKPI: Rename a short description of the kmalloc type.
To avoid duplication in the vmstat -m output rename the kmalloc type short
description to 'lkpikmalloc' as the Linux emulation layer historically names
its linux malloc type as 'linux'.

Reviewed by:		hselasky, kib, emaste
Differential Revision:	https://reviews.freebsd.org/D30928
MFC after:		2 weeks

(cherry picked from commit 5ca9d41700)
2022-06-17 22:30:28 +03:00
Dmitry Chagin
cc22c0d6bb LinuxKPI: Put compat code under appropriate condition.
Reviewed by:		hselasky, emaste, kib
Differential Revision:	https://reviews.freebsd.org/D30927
MFC after:		2 weeks

(cherry picked from commit 1fd26da926)
2022-06-17 22:30:28 +03:00
Dmitry Chagin
ba40604902 LinuxKPI: Use the proper API to determine the ABI of the running process.
Reviewed by:		markj, hselasky, kib
Differential Revision:	https://reviews.freebsd.org/D30924
MFC after:		2 weeks

(cherry picked from commit 945accf502)
2022-06-17 22:30:26 +03:00
Gordon Bergling
7ee205017a linux(4): Fix a typo in a source code comment
- s/accross/across/

(cherry picked from commit 8cf0d09462)
2022-06-10 14:31:50 +02:00
Bjoern A. Zeeb
994522a420 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

(cherry picked from commit 71df58aefc)
2022-06-08 16:11:19 +00:00
Bjoern A. Zeeb
b84aea440b 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

(cherry picked from commit dbc06dd98a)
2022-06-08 16:11:19 +00:00
Bjoern A. Zeeb
984a45d77b LinuxKPI 802.11 / iwlwifi / rtw88 : re-factor ieee802211_sta for MLO
Working on an update for rtw88 baed on wireless-testing I ran into
a build issue with struct ieee802211_sta.  Some fields were factored
out into their own struct apparently preparing for MLO (Multi Link
Operation).

In order to be able to update one driver we have to adjust both
rtw88 and iwlwifi (and the ones still out-of-tree) now.

This is mostly a sed-replace job and no functional changes are
intended.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 6cf748ad94)
2022-06-03 16:57:04 +00:00
Bjoern A. Zeeb
26526bf171 LinuxKPI: 802.11 updates
Add more values to the ieee80211_min_mpdu_start_spacing enum with
two missing given we do not know how they are called.  Also update
the reference while here.

Add struct ieee80211_hdr_3addr and correct the comment on the
ieee80211_hdr to match the one in net80211 to avoid future confusion.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit d296b65d89)
2022-06-03 16:56:56 +00:00
Bjoern A. Zeeb
bdd0de1a90 LinuxKPI: implement pcie_capability_set_word()
Implement pcie_capability_set_word() using the already available
read/write functions.
Also define the completion timeout disable value to our PCI one.
Both needed by a driver update.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	manu, hselasky
Differential Revision: https://reviews.freebsd.org/D35250

(cherry picked from commit 85eb99f9a4)
2022-06-03 16:56:49 +00:00
Bjoern A. Zeeb
465776a81e LinuxKPI: 802.11 add rfkill_soft_blocked()
Add rfkill_soft_blocked() to the list of things to implement in
preparation for an iwlwifi update.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 05d6f4d696)
2022-06-03 16:56:21 +00:00
Bjoern A. Zeeb
1f10f8aa0f LinuxKPI: skbuff: add memlimit tunable for 64bit systems
Some drivers, such as Realtek's rtw88, require 32bit DMA in
a single segment.  busdma(9) has a hard time providing this
currently for 3-ish pages at large quantities
(see lkpi_pci_nseg1_fail in linux_pci.c e86707418c).
Work around this for now by allowing a tunable to enforce
physical addresses allocation limits on 64bit platforms (ignoring PAE)
using "old-school" contigmalloc(9) to avoid bouncing.

A patch needing a custom kernel compiled was tested in the last weeks
by rtw88 users providing the 32bit limit only hardcoded.  The 36bit
limit can be found in iwlwifi so is added as a testing option along.

This is put in as a bandaid for now, so people no longer need to patch
and compile their own kernels to use rtw88 and to allow us to MFC the
driver as well before the amounts of commits to track increases by
much more.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 6a50157090)
2022-06-03 15:48:15 +00:00
Vladimir Kondratyev
185159f77c LinuxKPI: Switch irq_work implementation back to standard taskqueue
from fast one as dmabuf does not run callbacks from critical sections
since drm-kmod 5.7.
Consumers which requires fair irq_work like drm-kmod 5.4 must #define
LKPI_IRQ_WORK_USE_FAST_TQ somewhere in source file before linux/irq_work.h
inclusion to enable old behavior.

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

(cherry picked from commit 71fe907dfb)
2022-06-02 00:50:14 +03:00
Vladimir Kondratyev
42c04803d2 LinuxKPI: Do not use forward declaration for struct llist_node
in linux/irq_work.h as irq_work structure contains full version of
llist_node rather than reference to it.

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

(cherry picked from commit bec4576e4c)
2022-06-02 00:50:14 +03:00
Vladimir Kondratyev
a3e1754f45 LinuxKPI: IRQ work add TASKQUEUE_FAIL_IF_PENDING flag to taskqueue_enqueue
call to match Linux.

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

(cherry picked from commit fa30bff5da)
2022-06-02 00:50:14 +03:00
Vladimir Kondratyev
2c9bb9c618 LinuxKPI: Implement kthread_worker related functions
Kthread worker is a single thread workqueue which can be used in cases
where specific kthread association is necessary, for example, when it
should have RT priority or be assigned to certain cgroup.

This change implements Linux v4.9 interface which mostly hides kthread
internals from users thus allowing to use ordinary taskqueue(9) KPI.
As kthread worker prohibits enqueueing of already pending or canceling
tasks some minimal changes to taskqueue(9) were done.
taskqueue_enqueue_flags() was added to taskqueue KPI which accepts extra
flags parameter. It contains one or more of the following flags:

TASKQUEUE_FAIL_IF_PENDING - taskqueue_enqueue_flags() fails if the task
    is already scheduled to execution. EEXIST is returned and the
    ta_pending counter value remains unchanged.
TASKQUEUE_FAIL_IF_CANCELING - taskqueue_enqueue_flags() fails if the
    task is in the canceling state and ECANCELED is returned.

Required by:	drm-kmod 5.10

MFC after:	1 week
Reviewed by:	hselasky, Pau Amma (docs)
Differential Revision:	https://reviews.freebsd.org/D35051

(cherry picked from commit b6f87b78b5)
2022-06-02 00:50:14 +03:00
Vladimir Kondratyev
8f41e6af53 LinuxKPI: Implement sched_set_fifo(_low) functions
Required by:	drm-kmod

MFC after:	1 week
Reviewed by:	hselasky, manu
Differential Revision:	https://reviews.freebsd.org/D35050

(cherry picked from commit 0093bc3cd1)
2022-06-02 00:50:14 +03:00
Vladimir Kondratyev
0ed20f0139 LinuxKPI: Add some pollution required by drm-kmod to linux/sched.h
MFC after:	1 week
Reviewed by:	hselasky, manu
Differential Revision:	https://reviews.freebsd.org/D35050

(cherry picked from commit 1ebd7aeeca)
2022-06-02 00:50:14 +03:00
Vladimir Kondratyev
54aeef3a79 LinuxKPI: Add cpu_latency_qos_request_active stub to linux/pm_qos.h
Required by:	drm-kmod 5.10

MFC after:	1 week
Reviewers:	hselasky, manu
Differential Revision:	https://reviews.freebsd.org/D35049

(cherry picked from commit 6bcd132222)
2022-06-02 00:50:14 +03:00
Vladimir Kondratyev
99421af3d9 LinuxKPI: Fix typo in cond_resched_lock
Lock must be released rather than acquired around mi_switch call.

MFC after:	1 week
Reviewed by:	hselasky, manu
Differential Revision:	https://reviews.freebsd.org/D35048

(cherry picked from commit 41559beb00)
2022-06-02 00:50:13 +03:00
Vladimir Kondratyev
6f8b356c0b LinuxKPI: Convert lkpi-shrinker lock to sx.
This fixes "might_sleep() with the following non-sleepable locks held:
exclusive sleep mutex lkpi-shrinker" warnings.

MFC after:	1 week
Reviewed by:	hselasky, manu
Differential Revision:	https://reviews.freebsd.org/D35047

(cherry picked from commit 29d5f0c148)
2022-06-02 00:50:13 +03:00
Hans Petter Selasky
2f382e4469 LinuxKPI: Implement linux/hashtable.h for FreeBSD.
This implementation uses the concurrency kit, CK, API directly which is
suitable for use with EPOCH(9) and RCU under FreeBSD.

No functional change intended.

The initial "linux/hash.h" code was obtained from DragonFlyBSD via
FreeBSD's drm-kmod in ports.

Differential Revision:	https://reviews.freebsd.org/D35162
Reviewed by:	bz@ and markj@
MFC after:	1 week
Sponsored by:	NVIDIA Networking

(cherry picked from commit f9e90c2473)
2022-06-02 00:50:13 +03:00
John Baldwin
f70fe58d0a linuxkpi xarray: Correct expression in assertion.
Reported by:	GCC -Wparantheses
Reviewed by:	wulf, hselasky
Differential Revision:	https://reviews.freebsd.org/D34197

(cherry picked from commit b0c1600a8c)
2022-05-10 17:07:41 -07:00
John Baldwin
ffefb63627 linuxkpi: Add parentheses to pacify -Wparentheses warnings from GCC.
Reviewed by:	bz, emaste
Differential Revision:	https://reviews.freebsd.org/D34145

(cherry picked from commit 7043ca9140)
2022-05-10 17:06:44 -07:00
John Baldwin
e77b37914a <linux/overflow.h>: Don't use __has_builtin().
GCC only added support for __has_builtin in GCC 10.  However, all
supported versions of GCC and clang include these builtins so just use
them unconditionally.

This fixes the build with GCC 9.

Reviewed by:	manu, hselasky, imp
Differential Revision:	https://reviews.freebsd.org/D31942

(cherry picked from commit 9553c6af88)
2022-05-10 15:51:49 -07:00
Mark Johnston
097991f8ff linuxkpi: Mitigate a seqlock livelock
Disable preemption in seqlock write sections when using the _irqsave
variant.  This ensures that a writer can't be preempted and subsequently
starved by a reader running in a callout handler on the same CPU.

This fixes occasional display hangs seen when using the i915 driver.

Tested by:	emaste, wulf
Reviewed by:	wulf, hselasky
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit efb8f0b8db)
2022-05-09 08:32:09 -04:00
Alex Richardson
95c6e44054 linuxkpi: implement ida_alloc()
Needed for the virtio-gpu driver.

Reviewed By:	#linuxkpi, manu, bz, hselasky
Differential Revision: https://reviews.freebsd.org/D32366

(cherry picked from commit d98f2712c7)
2022-05-07 13:08:55 +01:00
Alex Richardson
763198cc50 linuxkpi: Allow BUILD_BUG_ON in if statements without braces
I got a compilation failure in virtio-gpu without this change.

Reviewed By:	#linuxkpi, manu, bz, hselasky
Differential Revision: https://reviews.freebsd.org/D32366

(cherry picked from commit 6d15ccde4d)
2022-05-07 13:08:46 +01:00
Alex Richardson
82b4e784f3 linuxkpi: Add sg_init_one
Needed for the virtio-gpu driver.

Reviewed By:	#linuxkpi, manu, bz, hselasky
Differential Revision: https://reviews.freebsd.org/D32366

(cherry picked from commit 2686b10db4)
2022-05-07 12:57:31 +01:00
Bjoern A. Zeeb
5961670050 LinuxKPI: 802.11: fill in two more TODOs
Implement ieee80211_is_data_present() and a subset of
ieee80211_is_bufferable_mmpdu() which hopefully is good enough in
the compat code for now.
This is partly in preparation for some TXQ changes coming up soon.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 00614c9c2d)
2022-05-04 13:13:11 +00:00
Bjoern A. Zeeb
1a86fec11b 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

(cherry picked from commit 3540911bfd)
2022-05-04 13:13:06 +00:00
Bjoern A. Zeeb
d5e65e74eb LinuxKPI: 802.11 ieee80211_sn_sub() fix
In ieee80211_sn_sub() we need to shift the mask before applying it.
This fixes the logic from 978f25e840.

Reported by:	J.R. Oldroyd (fbsd opal.com)
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit b3e7f403a5)
2022-05-04 13:12:54 +00:00
Emmanuel Vadot
825b33fccd linuxkpi: Add for_each_sgtable_dma_sg and for_each_sgtable_dma_page
Variants of for_each_sg/for_each_sg_dma_page but they operate on sgtable
structs.
Needed by drm v5.10

MFC after:	1 week
Sponsored by:	Beckhoff Automation GmbH & Co. KG

(cherry picked from commit 1aca8a6ec6)
2022-04-27 18:38:06 +02:00
Emmanuel Vadot
5c6eeda048 linuxkpi: Implement dma_max_mapping_size
Simply returns SCATTERLIST_MAX_SEGMENT.
Needed by drm v5.10

MFC after:	1 week
Sponsored by:	Beckhoff Automation GmbH & Co. KG

(cherry picked from commit 1acf9b2770)
2022-04-27 18:38:06 +02:00
Emmanuel Vadot
a2b1b471e8 linuxkpi: Change irq_work_queue to return a bool
This was changed in Linux v5.10

MFC after:	1 week
Sponsored by:	Beckhoff Automation GmbH & Co .KG

(cherry picked from commit 2192bc3255)
2022-04-27 18:38:06 +02:00
Emmanuel Vadot
62dc9911d9 linuxkpi: Add llnode member in struct irq_work
This was added in Linux v5.8 and started to be used in drm code in v5.9

MFC after:	1 week
Sponsored by:	Beckhoff Automation GmbH & Co. KG

(cherry picked from commit 17ee6aca65)
2022-04-27 18:38:05 +02:00
Emmanuel Vadot
e6afd48804 linuxkpi: Add down_write_nest_lock
Simply calls down_write like in Linux (when CONFIG_DEBUG_LOCK_ALLOC isn't
specified)
Needed by drm v5.10

MFC after:	1 month
Reviewed by:	hselasky
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D34642

(cherry picked from commit f9413897cb)
2022-04-27 18:34:47 +02:00
Emmanuel Vadot
4a5270b3c8 linuxkpi: Add kstrtouint_from_user
Like kstrtoint_from_user but for uint.
Needed by drm v5.10

MFC after:	1 month
Reviewed by:	hselasky
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D34642

(cherry picked from commit 8e587a5f13)
2022-04-27 18:34:47 +02:00
Emmanuel Vadot
6c25e63c06 linuxkpi: Add cond_resched_lock
If we need to resched it takes the lock, resched, release the lock
and returns 1, otherwise simply returns 0.

Needed by drm v5.9

MFC after:	1 month
Reviewed by:	hselasky
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D34620

(cherry picked from commit 9b8016548e)
2022-04-27 18:34:47 +02:00
Bjoern A. Zeeb
f71daf6a11 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

(cherry picked from commit 383b3e8f50)
2022-04-18 09:32:58 +00:00
Bjoern A. Zeeb
e4e2ad470e LinuxKPI: 802.11: implement ieee80211_probereq_get()
Implement ieee80211_probereq_get() needed by Realtek drivers.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit ade774b19f)
2022-04-18 09:32:58 +00:00
Bjoern A. Zeeb
c39947cdd3 LinuxKPI: skbuff: start implementing skb_copy()
Implement skb_copy() with omissions of fragments and possibly other fields
for now.  Should we hit frags at any point a log message will let us know.
For the few cases we need this currently this is enough.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 349b042b90)
2022-04-18 09:32:58 +00:00
Bjoern A. Zeeb
3c1373110f 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

(cherry picked from commit d9945d7821)
2022-04-18 09:32:58 +00:00
Bjoern A. Zeeb
bfa2e8f840 LinuxKPI: skbuff: dev_kfree_skb_irq() and improvements
While it is currently unclear if we will have to defer work in
dev_kfree_skb_irq() to call dev_kfree_skb().
We only have one caller which seems to be fine on FreeBSD by calling
it directly for now.

While here shortcut skb_put()/skb_put_data() saving us work if there
are no adjustments to do.
Also adjust the logging in skb_is_gso() to avoid getting spammed by it.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 952643ea45)
2022-04-18 09:32:57 +00:00
Bjoern A. Zeeb
4b63d8489e 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

(cherry picked from commit 8891c45563)
2022-04-18 09:32:57 +00:00
Bjoern A. Zeeb
94b9567f75 LinuxKPI: add ALIGN_DOWN()
Add ALIGN_DOWN as rounddown2() along ALIGN() which is implemented as
roundup2().

Sponsored by:	The FreeBSD Foundation
Reviewed by:	manu, hselasky (now with less ())
Differential Revision: https://reviews.freebsd.org/D34844

(cherry picked from commit 97f2e93a66)
2022-04-14 16:38:16 +00:00
Bjoern A. Zeeb
797188ba9a LinuxKPI: 802.11: add ieee80211_beacon_get_tim(), ieee80211_sn_sub()
Add a dummy implementation for ieee80211_beacon_get_tim().
Add the implementation for ieee80211_sn_sub().

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 978f25e840)
2022-04-14 16:38:11 +00:00
Bjoern A. Zeeb
fcc5031c9c LinuxKPI: 802.11: further fix RSSI calculations
60970a328e 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

(cherry picked from commit 170acccf1e)
2022-04-14 16:38:06 +00:00
Bjoern A. Zeeb
48e84cceac LinuxKPI: skbuff: handle dev_alloc_skb() correctly
dev_alloc_skb() comapred to alloc_skb() reserves some headroom
at the beginning of the skb which is used by drivers.
Split the code for the two cases and reserve NET_SKB_PAD space,
which should at least be 32 octets.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 9df5f29caf)
2022-04-14 16:38:01 +00:00
Bjoern A. Zeeb
46d08fd085 LinuxKPI: PCI: add counter for linux_dma_map_phys_common() errors
LinuxKPI is asking for single-segment mappings.  Some (wireless) drivers
are using this to map multi-pages and our busdma framework is not very
friendly to that as single-segments [D31823].  Add a counter so we can
track when this happens to gather more information.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	hselasky
Differential Revision: https://reviews.freebsd.org/D34715

(cherry picked from commit e86707418c)
2022-04-14 16:37:53 +00:00
Bjoern A. Zeeb
7b9d8e33bc LinuxKPI: 802.11: fix RSSI (and NF)
As in 4a22cd6c4e 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

(cherry picked from commit 60970a328e)
2022-04-05 14:47:13 +00:00