Commit graph

1050 commits

Author SHA1 Message Date
Bjoern A. Zeeb
ce707e674f LinuxKPI: add PCI_VENDOR_ID_ITTIM
Add PCI_VENDOR_ID_ITTIM as needed by mt76.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2024-04-02 10:03:31 +00:00
Tom Coldrick
d3befb534b LinuxKPI: Queue skbuffs at tail in __skb_queue_tail
Correct skb_queue_tail to queue the buffer at the tail of the skbuff.
The skbuff is a circular doubly-linked list, and we call with a pointer
to the head of the list.  Thus queueing before the head gives us a
queueing at the tail.

As a motivating factor, the current behaviour (queueing at the head) was
causing frequent kernel panics from my RTL8822BE wireless card, which
uses the rtw88 driver.  Interrupts can cause buffers to be added to the
rtwdev c2h_queue while the queue is being drained in rtw_c2h_work.
Queueing at the head would leave the nascent entry in the linked list
pointing to the old, now freed, memory for the buffer being processed.
When rtw_c2h_work is next called, we try reading this and so panic.

Reviewed by:	emaste, bz
MFC after:	1 week
Differential Revision: https://reviews.freebsd.org/D44192
2024-03-04 09:33:12 -05:00
Bjoern A. Zeeb
7061745867 LinuxKPI: sort dev_<loglevel>() functions
Sort the dev_<loglevel> functions by loglevel order, add the dev_alert()
version and an indentation change.

No functional changes.

MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D43719
2024-02-14 22:05:21 +00:00
Bjoern A. Zeeb
53eb2c63c9 LinuxKPI: 802.11: correct HT protection fields
It seems during the initial buildup of the file, the defines were
either mixed or not flagged as "FIXME".
Define the values through to the net80211 definitions and also
annotate them by at least some standards reference.

MFC after:	3 days
Fixes:		6b4cac814e
Reviewed by:	cc
Differential Revision: https://reviews.freebsd.org/D43658
2024-02-14 19:36:30 +00:00
Vladimir Kondratyev
c0b8047bdc 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
2024-02-11 01:01:50 +03:00
Vladimir Kondratyev
db65db64fb Revert "LinuxKPI: Add explicit software context to FPU sections"
kmalloc() support within FPU sections will be redone in other way.

This reverts commit 5a3bd28167.

Sponsored by:	Serenity Cyber Security, LLC
Requested by:	jhb
2024-02-11 01:01:50 +03:00
Vladimir Kondratyev
7f1a7506cb Revert "LinuxKPI: Do not use explicit context in FPU sections on powerpc64"
kmalloc() support within FPU sections will be redone in other way.

This reverts commit b4efc62776.

Sponsored by:	Serenity Cyber Security, LLC
Requested by:	jhb
2024-02-11 01:01:50 +03:00
Bjoern A. Zeeb
2d9d35837d LinuxKPI: implement memset_after()
memset_after() is needed by iwlwifi d3.c.

MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D43644
2024-02-03 13:50:32 +00:00
Bjoern A. Zeeb
2f029bf911 LinuxKPI: 802.11: extend ieee80211_key_seq and WLAN_KEY_LEN_* defines
For iwlwifi(4) d3.c we need another struct in struct ieee80211_key_seq
and related WLAN_KEY_LEN_* defines in.

MFC after:	3 days
Reviewed by:	cc, emaste
Differential Revision: https://reviews.freebsd.org/D43646
2024-02-03 13:31:50 +00:00
Gleb Smirnoff
f79a8585bb sockets: garbage collect SS_ISCONFIRMING
Fixes:	8df32b19de
2024-01-30 10:38:33 -08:00
Ed Maste
7e77089dcc linuxkpi: remove invalid KASSERT from hash_add_rcu
hash_add_rcu asserted that the node's prev pointer was NULL in an
attempt to detect addition of a node already on a list, but the caller
is not required to provide a zeroed node.

Reported in https://github.com/freebsd/drm-kmod/issues/282

Reviewed by:	bz, manu
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D43645
2024-01-29 11:40:17 -05:00
Mark Johnston
344a04ad2c linuxkpi: Annotate an unused variable as such
This addresses a -Wunused-but-set-variable warning in the gcc builds.

No functional change intended.

Reported by:	Jenkins
2023-12-27 10:11:33 -05:00
Vladimir Kondratyev
dbca442414 LinuxKPI: Constify src parameter of bitmap_copy
in bitmap_from_arr32() to fix build on 32 bit archs.

Sponsored by:	Serenity Cyber Security, LLC
Fixes:	5ae2e6f913 ("LinuxKPI: Add bitmap_intersects(), bitmap_from_arr32()")
MFC after:	1 week
2023-12-24 15:48:06 +03:00
Vladimir Kondratyev
73ccd188c4 LinuxKPI: Define ioread64() in linux/io.h only on 64 bit archs.
32 bit archs includes nonatomic version from linux/io-64-nonatomic-*.h

Sponsored by:   Serenity Cyber Security, LLC
Fixes:		dcfc983373 ("LinuxKPI: Implement ioread64()")
MFC after:      1 week
2023-12-24 15:48:06 +03:00
Vladimir Kondratyev
b4efc62776 LinuxKPI: Do not use explicit context in FPU sections on powerpc64
It is not supported yet.

Sponsored by:	Serenity Cyber Security, LLC
Fixes:	5a3bd28167 ("LinuxKPI: Add explicit software context to FPU sections")
MFC after:	1 week
2023-12-24 15:48:06 +03:00
Vladimir Kondratyev
5a3bd28167 LinuxKPI: Add explicit software context to FPU sections
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
currently on FreeBSD as its malloc function can not be run within a
critical section. Allocate memory for FPU context to overcome such
restriction.

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu (previous version), markj
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42822
2023-12-24 11:20:01 +03:00
Vladimir Kondratyev
808ae4e29b 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
MFC TODO:	Move pcie_cap_lock to bottom to preserve KBI compatibility
Differential Revision:	https://reviews.freebsd.org/D42821
2023-12-24 11:20:00 +03:00
Vladimir Kondratyev
730387b64e LinuxKPI: Add linux/apple-gmux.h
Sponsored by:	Serenity Cyber Security, LLC
Obtained from:	OpenBSD
Reviewed by:	manu, bz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42819
2023-12-24 11:20:00 +03:00
Vladimir Kondratyev
c58ddc2546 LinuxKPI: Rename linux_list_add to __list_add() in linux/list.h
to match Linux

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu, bz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42818
2023-12-24 11:20:00 +03:00
Vladimir Kondratyev
9903d83d67 LinuxKPI: Add linux/ioport.h header
Sponsored by:	Serenity Cyber Security, LLC
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42817
2023-12-24 11:20:00 +03:00
Vladimir Kondratyev
7f88d742e5 LinuxKPI: Add get_random_u64() function
Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu, bz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42816
2023-12-24 11:20:00 +03:00
Vladimir Kondratyev
2b037743a7 LinuxKPI: Add linux/dynamic_debug.h header
Sponsored by:	Serenity Cyber Security, LLC
Obtained from:	OpenBSD
Reviewed by:	manu
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42815
2023-12-24 11:20:00 +03:00
Vladimir Kondratyev
5ae2e6f913 LinuxKPI: Add bitmap_intersects(), bitmap_from_arr32()
and bitmap_shift_right() functions to linux/bitmap.h

They perform calculation of two bitmaps intersection,
copying the contents of u32 array of bits to bitmap and
logical right shifting of the bits in a bitmap.

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42812
2023-12-24 11:19:59 +03:00
Vladimir Kondratyev
1b2f43a742 LinuxKPI: Add cancel_work() function.
Cancel a work not waiting for it to finish.

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu, kib
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42811
2023-12-24 11:19:59 +03:00
Vladimir Kondratyev
64e30cba3f LinuxKPI: Add write_seqcount_invalidate() and seqprop_sequence()
functions to linux/seqlock.h

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42810
2023-12-24 11:19:59 +03:00
Vladimir Kondratyev
a39ed121ea LinuxKPI: Chase for new "name" argument of register_shrinker()
Linux uses it only if SHRINKER_DEBUG config option is enabled. Ignore it.

Sponsored by:	Serenity Cyber Security, LLC
Reviewers:	manu, bz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42809
2023-12-24 11:19:59 +03:00
Vladimir Kondratyev
c7312643b7 LinuxKPI: Add ida_alloc_min()
ida_alloc_min() allocates an unused ID. between min and INT_MAX.

While here allow end parameter of ida_simple_get() be larger than
INT_MAX. Linux caps the value to INT_MAX.

Sponsored by:	Serenity Cyber Security, LLC
Reviewers:	manu, bz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42806
2023-12-24 11:19:59 +03:00
Vladimir Kondratyev
af787b8e8b LinuxKPI: Add IOMEM_ERR_PTR() to linux/io.h
The function creates an error pointer.

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu, bz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42805
2023-12-24 11:19:59 +03:00
Vladimir Kondratyev
e964da1415 LinuxKPI: Add ktime_get_raw_fast_ns() to linux/ktime.h
It is implemented like ktime_get_raw_ns() function but uses less
precise getnanouptime() call.

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu, bz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42804
2023-12-24 11:19:59 +03:00
Vladimir Kondratyev
66f9a98335 LinuxKPI: Add xa_(un)lock_irq to linux/xarray.h
On FreeBSD they are equal to non-irq version.

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu, bz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42803
2023-12-24 11:19:59 +03:00
Vladimir Kondratyev
dcfc983373 LinuxKPI: Implement ioread64()
Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu, bz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42801
2023-12-24 11:19:58 +03:00
Vladimir Kondratyev
f8ab2f5bae LinuxKPI: Add linux/iosys-map.h header
Sponsored by:	Serenity Cyber Security, LLC
Obtained from:	OpenBSD
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42799
2023-12-24 11:19:58 +03:00
Vladimir Kondratyev
1bce29bcf1 LinuxKPI: Add some header pollution and dummy headers
required by recent drm-kmod to be succesfully compiled.

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu, bz
Obtained from:	OpenBSD (partially)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42798
2023-12-24 11:19:58 +03:00
Vladimir Kondratyev
fa862482fb LinuxKPI: Split linux/container_of.h off from linux/kernel.h
Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu, bz
MFC after:      1 week
Differential Revision:	https://reviews.freebsd.org/D42796
2023-12-24 11:19:58 +03:00
Vladimir Kondratyev
31ef29091b LinuxKPI: Add static_assert() macro
And move it along BUILD_BUG family in to
linux/build_bug.h to match Linux.

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu, bz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42800
2023-12-24 11:19:58 +03:00
Vladimir Kondratyev
a012599653 LinuxKPI: Implement dev_dbg_once() macro
Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu, bz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42795
2023-12-24 11:19:58 +03:00
Vladimir Kondratyev
ae1084ff01 LinuxKPI: Add str_on_off and other helpers to linux/string_helpers.h
Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu, bz, imp (previous version)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42794
2023-12-24 11:19:58 +03:00
Vladimir Kondratyev
96ab16ebab LinuxKPI: Remove sys/rman.h include from LKPI headers.
sys/rman.h defines `resource` structure which conflicts with the Linux
structure of the same name. To fix that remove reference to sys/rman.h
from linux/pci.h and move resource management code to linux_pci.c.
Update consumers which were depending on linux/pci.h pollution.

No functional changes intended.

Sponsored by:	Serenity Cyber Security, LLC
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42792
2023-12-24 11:19:57 +03:00
Jean-Sébastien Pédron
fe84281803
linuxkpi: Add struct kset support in <linux/kobject.h>
[Why]
The amdgpu DRM driver started to use it in Linux 5.18.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D43020
2023-12-13 19:57:52 +01:00
Jean-Sébastien Pédron
d6d1e73e5f
linuxkpi: Include <linux/string_helpers.h> from <linux/seq_file.h>
[Why]
The i915 DRM driver in Linux 5.18 relies on this indirect include.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D43030
2023-12-13 19:54:32 +01:00
Jean-Sébastien Pédron
38138beb42
linuxkpi: Add <linux/string_helpers.h> and str_yes_no()
[Why]
This header and str_yes_no() are now used by the i915 DRM driver in
Linux 5.18.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D43014
2023-12-13 19:54:32 +01:00
Jean-Sébastien Pédron
59cbead6b1
linuxkpi: Add support for suspend_noirq callback in struct dev_pm_ops
[Why]
This callback is being used by the amdgpu DRM driver in Linux 5.18.

[How]
The callback is called after `suspend_late()`.

Reviewed by:	emaste, manu
Approved by:	emaste, manu
Differential Revision:	https://reviews.freebsd.org/D43029
2023-12-13 19:18:47 +01:00
Jean-Sébastien Pédron
d752a5e82a
linuxkpi: Fix __ATTR_RO() in <linux/sysfs.h>
[Why]
The passed structure may not have a `.store` field. This is the case in
the amdgpu DRM driver starting with Linux 5.18.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D43023
2023-12-13 19:18:46 +01:00
Jean-Sébastien Pédron
509707e8b6
linuxkpi: Add sysfs_create_link() in <linux/sysfs.h>
[Why]
The amdgpu DRM driver started to use it in Linux 5.18.

[How]
The function is a no-op as I'm not sure how to implement this with
sysctls yet.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D43022
2023-12-13 19:18:46 +01:00
Jean-Sébastien Pédron
b723bcd05a
linuxkpi: Add list_for_each_prev_safe() in <linux/list.h>
[Why]
The amdgpu DRM driver started to use it in Linux 5.18.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D43021
2023-12-13 19:18:46 +01:00
Jean-Sébastien Pédron
80446fc7b5
linuxkpi: Move struct kobject code to linux_kobject.c
[Why]
`linux_compat.c` is already too long. I will need to add `struct kset`
in a follow-up commit, so let's move the existing `struct kobject` code
to its own file.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D43019
2023-12-13 19:18:46 +01:00
Jean-Sébastien Pédron
4e0d3f7b3c
linuxkpi: Move invalidate_mapping_pages() to <linux/pagemap.h>
[Why]
This is consistent with Linux.

[How]
The definition is moved from <linux/shmem_fs.h> to <linux/pagemap.h> and
the latter is included from the former. This is how it is done on Linux.

Prototypes are also expanded with argument names. I got a build failure
in the DRM 5.18 drivers because the compiler considered that the
`pgoff_t` argument was there twice.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D43018
2023-12-13 19:18:46 +01:00
Jean-Sébastien Pédron
50a56453da
linuxkpi: Include <linux/types.h> from <linux/cc_platform.h>
[Why]
We need this for the `bool` type.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D43016
2023-12-13 19:18:42 +01:00
Jean-Sébastien Pédron
8a8e86b819
Revert "linuxkpi: GFP_KERNEL equals M_NOWAIT now"
This change seems to break some drivers such as the mlx5*(4) drivers.

As kib@ says:
> According to the 'official' Linux kernel documentation, the GFP_KERNEL
> flag implies sleepable context.

It was introduced while working on the new vt(4)/DRM integration [1].
During this work, doing sleepable allocations broke vt(4) and the DRM
drivers. However, I made further improvements and some locking-related
fixed to the new integration without revisiting the need for it.

After more testing, the improvements to the integration mentionned above
seems to make the change to `GFP_KERNEL` unneeded now. I can thus
revert it to restore expectations of other drivers.

This reverts commit 14dcd40983.

[1] https://github.com/freebsd/drm-kmod/pull/243

Reviewed by:	kib
Approved by:	kib
Differential Revision:	https://reviews.freebsd.org/D42962
2023-12-07 21:53:44 +01:00
Bjoern A. Zeeb
9fb914634e 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
2023-12-01 22:26:28 +00:00