Commit graph

1226 commits

Author SHA1 Message Date
Bjoern A. Zeeb
63a327b954 LinuxKPI: 802.11: use net80211 IEEE80211_HTCAP_* definitions
Rather than using the values and leaving net80211 names in a comment
define the LinuxKPI IEEE80211_HT_CAP_* to the net80211 IEEE80211_HTCAP_*
names.  That way errors like the one fixed in 3e0915b7b6 are less
likely to happen.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2024-06-07 23:57:04 +00:00
Bjoern A. Zeeb
3753988c5d 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
MFC after:	3 days
Differential Revision: https://reviews.freebsd.org/D45358
2024-06-07 22:57:04 +00:00
Bjoern A. Zeeb
3e0915b7b6 LinuxKPI: 802.11: Fix definition of IEEE80211_HT_CAP_RX_STBC
IEEE80211_HT_CAP_RX_STBC was set to 0x100 instead of 0x300.
Correct to get the expected behavior.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Fixes:		b0f7376822 LinuxKPI: 802.11 header updates
Reviewed by:	adrian
Differential Revision: https://reviews.freebsd.org/D45506
2024-06-07 21:16:49 +00:00
Vladimir Kondratyev
db42bd1f71 LinuxKPI: Convert Linux integer types to ISO C99 in linux/kstrtox.h
Sponsored by:	Serenity Cyber Security, LLC
MFC after:	1 week
Reviewed by:	bz, emaste
Differential Revision:	https://reviews.freebsd.org/D45465
2024-06-06 23:42:07 +03:00
Vladimir Kondratyev
d207a2dee3 LinuxKPI: Add kstrtoll to linux/kstrtox.h
kstrtoll converts a string to a long long.

Sponsored by:	Serenity Cyber Security, LLC
MFC after:	1 week
Reviewed by:	bz, emaste
Differential Revision:	https://reviews.freebsd.org/D45455
2024-06-06 23:42:07 +03:00
Vladimir Kondratyev
a97f3a9ec9 LinuxKPI: Move kstrto* functions to linux/kstrtox.h
from linux/kernel.h to match Linux and
allow direct linux/kstrtox.h inclusion.

Sponsored by:	Serenity Cyber Security, LLC
MFC after:	1 week
Reviewed by:	bz
Differential Revision:	https://reviews.freebsd.org/D45454
2024-06-06 23:42:07 +03:00
Vladimir Kondratyev
afc450fac9 LinuxKPI: Add abs_diff to linux/math.h
It returns absolute value of the difference between the arguments.

Add LinuxKPI version check as the macro was moved from drm-kmod to
linux/math.h in Linux kernel commit 46f12960aad (6.6 timeframe).

Sponsored by:	Serenity Cyber Security, LLC
MFC after:	1 week
Reviewed by:	bz, emaste
Differential Revision:	https://reviews.freebsd.org/D45453
2024-06-06 23:42:07 +03:00
Vladimir Kondratyev
588064e658 LinuxKPI: Move linux/math.h content out of linux/kernel.h
To match Linux and allow direct linux/math.h inclusion.

Sponsored by:	Serenity Cyber Security, LLC
MFC after:	1 week
Reviewed by:	bz
Differential Revision:	https://reviews.freebsd.org/D45452
2024-06-06 23:42:07 +03:00
Vladimir Kondratyev
07c7c41ca1 LinuxKPI: Add min_not_zero() to linux/minmax.h
It returns the minimum that is not zero, except both equals to zero.

Sponsored by:	Serenity Cyber Security, LLC
MFC after:	1 week
Reviewed by:	bz, emaste, ssaxena
Differential Revision:	https://reviews.freebsd.org/D45450
Differential Revision:	https://reviews.freebsd.org/D45451
2024-06-06 23:42:06 +03:00
Vladimir Kondratyev
f79474c4e3 LinuxKPI: Move linux/minmax.h content out of linux/kernel.h
To match Linux and allow direct linux/minmax.h inclusion.

Sponsored by:	Serenity Cyber Security, LLC
MFC after:	1 week
Reviewed by:	bz
Differential Revision:	https://reviews.freebsd.org/D45449
2024-06-06 23:42:06 +03:00
Vladimir Kondratyev
cb8bfc4db8 LinuxKPI: Move page_address definition from linux/gfp.h to linux/mm.h
To match Linux. Some future changes may depend on proper location.

Sponsored by:	Serenity Cyber Security, LLC
MFC after:	1 week
Reviewed by:	bz, emaste
Differential Revision:	https://reviews.freebsd.org/D45448
2024-06-06 23:42:06 +03:00
Alvin Chen
21f4cf5ccf LinuxKPI: lockdep_assert: wrong 'cond' used in WARN_ON MACRO
'cond' in WARN_ON need be bracketed,
otherwise it is wrong for multiple conditions.

Reviewed by:	wulf
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D44604
2024-06-06 23:42:06 +03:00
Doug Moore
b0056b31e9 libkern: add ilog2 macro
The kernel source contains several definitions of an ilog2 function;
some are slower than necessary, and one of them is incorrect.
Elimininate them all and define an ilog2 macro in libkern to replace
them, in a way that is fast, correct for all argument types, and, in a
GENERIC kernel, includes a check for an invalid zero parameter.

Folks at Microsoft have verified that having a correct ilog2
definition for their MANA driver doesn't break it.

Reviewed by:	alc, markj, mhorne (older version), jhibbits (older version)
Differential Revision:	https://reviews.freebsd.org/D45170
Differential Revision:	https://reviews.freebsd.org/D45235
2024-06-03 11:37:55 -05:00
Bjoern A. Zeeb
ecd1d1f1da LinuxKPI: remove extern from function declarations
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Reviewed by:	emaste (earlier version, found another two)
Differential Revision: https://reviews.freebsd.org/D45386
2024-05-30 21:01:57 +00:00
Bjoern A. Zeeb
bb025df257 LinuxKPI: add FIELD_PREP_CONST()
Add FIELD_PREP_CONST() like FIELD_PREP() without any extra checks likely
expected on this version in Linux.  This is called by an updated wireless
driver.

Sposnored by:	The FreeBSD Foundation
MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D45180
2024-05-21 23:27:10 +00:00
Bjoern A. Zeeb
8e4b8e9d80 LinuxKPI: add kvmemdup()
Add kvmemdup() as a variant of kmemdup().  While currently it could
just call kmemdup() we duplicate the code and use kvmalloc() in case
someone will change the implementation of kvmalloc/kvfree in slab.h.
This is used by an updated wireless driver.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D45181
2024-05-21 22:14:50 +00:00
Bjoern A. Zeeb
69b6c4a6ec LinuxKPI: 802.11: fix for_each_sta_active_link()
Likely a c&p error from for_each_vif_active_link() to
for_each_sta_active_link().
We are checking the nitems on the vif instead of the sta in this macro.
Function wise there is no difference as the arrays are the same size
but for correctness fix this.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2024-05-21 22:12:00 +00:00
Emmanuel Vadot
a7b222db12 linuxkpi: rwlock: Fix rwlock_init
Some linux code re-init some spinlock so add MTX_NEW to mtx_init.

Reported by:    rlibby
Fixes:          5c0a192348 ("linuxkpi: rwlock: Simplify code")
2024-05-17 07:59:02 +02:00
Emmanuel Vadot
cff79fd026 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:		ae38a1a1bf ("linuxkpi: spinlock: Simplify code")
2024-05-17 07:58:59 +02:00
Austin Shafer
28a59100b5 linuxkpi: Provide a non-NULL value for THIS_MODULE
THIS_MODULE is used to differentiate modules on Linux. We currently
completely stub out any Linux struct module usage, but THIS_MODULE
is still used to populate the "owner" fields of various drivers.
Even though we don't actually dereference these "owner" fields they
are still used by drivers to check if devices/dmabufs/etc come
from different modules. For example, during DRM GEM import some
drivers check if the dmabuf's owner matches the dev's owner. If
they match because they are both NULL drivers may incorrectly think
two resources come from the same module.

This adds a general purpose __this_linker_file which will point to
the linker file of the module that uses it. We can then use that
pointer to have a valid value for THIS_MODULE.

Reviewed by:	bz, jhb
Differential Revision:	https://reviews.freebsd.org/D44306
2024-05-16 10:36:36 -07:00
Emmanuel Vadot
abb1a1340e linuxkpi: refcount: Use atomic_t directly
Simply use a typedef for refcount_t on atomic_t, this allow us
to use a nativ type and also changing struct kref to directly use
a refcount_t like Linux.

Reviewed by:		bz
Sponsored by:		Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D45207
2024-05-16 09:40:46 +02:00
Emmanuel Vadot
5c0a192348 linuxkpi: rwlock: Simplify code
Just use a typedef for rwlock_t, no need to create a useless
structure.

Reviewed by:		bz
Sponsored by:		Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D45206
2024-05-16 09:40:03 +02:00
Emmanuel Vadot
ae38a1a1bf 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
2024-05-16 09:39:36 +02:00
Elliott Mitchell
a9e0f316b3 kern/intr: redeclare intr_setaffinity()'s third arg constant
This matches reality and allows removal of a __DECONST().

Fixes: 4c72d075a5 ("LinuxKPI: const argument to irq_set_affinity_hint()")
Fixes: 9b33b154b5 ("Add support to cpuset for binding hardware interrupts")
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1126
2024-05-09 17:14:35 -06:00
Tijl Coosemans
2ae0f5a4d0 linuxkpi: Make arch_io_*_memtype_wc amd64-only
Linux only implements these functions on x86.  They return 0 on other
architectures.  The FreeBSD implementation calls PHYS_TO_DMAP but this
panics on i386 because it does not have a direct map so return 0 on i386
as well for now.  These functions are only used by graphics/drm-*-kmod
to mark the VRAM aperture write-combining but this is also accomplished
by a call to vm_phys_fictitious_reg_range so this change is sufficient
to fix drm-*-kmod on i386 for FreeBSD 14.1.

Reviewed by:	kib
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D45125
2024-05-08 20:52:37 +02:00
Tijl Coosemans
7206f7c619 linuxkpi: Fix set_memory_*
set_memory_* is currently implemented using PHYS_TO_DMAP but not all
architectures have a DMAP.  Looking at how this function is used the
given address isn't physical but virtual so the PHYS_TO_DMAP call can
simply be removed.

Also cast numpages before shifting it to avoid overflow.

Reviewed by:	kib, markj
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D45057
2024-05-03 15:27:29 +02:00
Emmanuel Vadot
11d79c4756 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
2024-04-30 07:42:31 +02:00
Bjoern A. Zeeb
563c72e213 LinuxKPI: utsname.h add missing SPDX-License-Identifier
Reported by:	markj (2023-05-24; sorry took me a while)
MFC after:	3 days
2024-04-19 18:23:12 +00:00
Bjoern A. Zeeb
2a8c50592f LinuxKPI: add __counted_by() and __nonstring
Add checks for __counted_by(_x) and __nonstring as and depending
on compiler support enable the attribute/feature.

This is needed to make mtk76 and ath1xk drivers compile.

Sposnored by:	The FreeBSD Foundation
MFC after:	3 days
Reviewed by:	emaste, dim
Differential Revision: https://reviews.freebsd.org/D44587
2024-04-15 19:31:49 +00:00
Bjoern A. Zeeb
170c2e0e2b LinuxKPI: add devm_kfree()
mt76 calls devm_kfree() directly, so alias it to our
lkpi_devm_kmalloc_release() function.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Differential Revision: https://reviews.freebsd.org/D44589
2024-04-15 16:55:59 +00:00
Bjoern A. Zeeb
21761f2ede 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
MFC after:	3 days
Reviewed by:	emaste (previous version)
Differential Revision:	https://reviews.freebsd.org/D44591
2024-04-15 16:19:47 +00:00
Bjoern A. Zeeb
3d3ec17825 LinuxKPI: sk_buff: implement skb_queue_splice_tail_init()
Implement skb_queue_splice_tail_init() and SKB_DATA_ALIGN() as
needed by the mt76 wireless driver.

Sponsord by:	The FreeBD Foundation
MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D44590
2024-04-15 16:06:11 +00:00
Bjoern A. Zeeb
738c02ba24 LinuxKPI: add dev_alloc_pages()
Add dev_alloc_pages() though it seems a weird KPI, not passing a dev
despite its name.  Used by updated wireless driver.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D44588
2024-04-12 23:15:27 +00:00
Bjoern A. Zeeb
f674f016c0 LinuxKPI: add BITS_TO_BYTES()
Just like BITS_TO_LONG() ... used in rtw89.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D44603
2024-04-12 23:11:47 +00:00
Bjoern A. Zeeb
218b2ccf8c LinuxKPI: implement memzero_explicit()
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D44586
2024-04-12 23:09:19 +00:00
Bjoern A. Zeeb
a1cdddcf15 LinuxKPI: add further constants to pci.h
Updated wireless drivers require more knowledge about PCI (BAR) bits.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Reviewed by:	jhb
Differential Revision: https://reviews.freebsd.org/D44573
2024-04-12 23:08:06 +00:00
Vladimir Kondratyev
4e7aa03b70 LinuxKPI: Stub sysfs_remove_link in linux/sysfs.h
sysfs_create_link is stubbed already. Stub sysfs_remove_link too to be
feature-complete.

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	emaste
MFC after:	1 week
2024-04-08 09:47:43 +03:00
Vladimir Kondratyev
56041ee817 LinuxKPI: Add want_init_on_free to linux/mm.h
want_init_on_free returns if heap memory zeroing on free is enabled.
FreeBSD does not zeroes heap memory on free().

Sponsored by:	Serenity Cyber Security
Reviewed by:	emaste
MFC after:	1 week
2024-04-08 09:47:43 +03:00
Vladimir Kondratyev
f7ea333e2b LinuxKPI: Add ACPI_ID_LEN const to linux/mod_devicetable.h
Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	emaste
MFC after:	1 week
2024-04-08 09:47:43 +03:00
Vladimir Kondratyev
f1206503e5 LinuxKPI: Add pci_dev_id to linux/pci.h
It returns bus/device/function number for given PCI device.
Also add intermediate PCI_DEVID macro used in some drivers.

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	emaste
MFC after:	1 week
2024-04-08 09:47:43 +03:00
Vladimir Kondratyev
e8f59f4d31 LinuxKPI: Add the accelerator PCIe class
Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	emaste
MFC after:	1 week
2024-04-08 09:47:43 +03:00
Vladimir Kondratyev
e0eeeca8b8 LinuxKPI: Add PTR_IF macro
Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	emaste
MFC after:	1 week
2024-04-08 09:47:42 +03:00
Vladimir Kondratyev
06902a4479 LinuxKPI: Add vm_flags_(clear|set) functions
Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	emaste
MFC after:	1 week
2024-04-08 09:47:42 +03:00
Vladimir Kondratyev
9289c1f6f1 LinuxKPI: Add get_random_u32_below function
get_random_u32_below returns a random integer in the interval [0, ceil),
with uniform distribution.

Sponsored by:	Serenity CyberSecurity, LLC
Reviewed by:	emaste
MFC after:	1 week
2024-04-08 09:47:42 +03:00
Vladimir Kondratyev
38c276a43f LinuxKPI: Add VM_ACCESS_FLAGS define to linux/mm.h
VM_ACCESS_FLAGS is a basic access permission flags.

Sponsored by:	Serenity CyberSecurity, LLC
Reviewed by:	emaste
MFC after:	1 week
2024-04-08 09:47:42 +03:00
Vladimir Kondratyev
3208d4ad2b LinuxKPI: Import vanilla linux/overflow.h
It is dual-licensed (GPLv2 & MIT) and self-contained header file.
No need to reimplement it.

Sponsored by:	Serenity CyberSecurity, LLC
Reviewed by:	emaste
MFC after:	1 week
2024-04-08 09:47:42 +03:00
Vladimir Kondratyev
8cfd1dd821 LinuxKPI: Move [SU](8|16|32|64)_(MAX|MIN) defines to linux/limits.h
Some source files get them from linux/limits.h directly rather than from
linux/kernel.h.
While here replace Linux constant values with sys/stdint.h provided ones.

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	emaste
MFC after:	1 week
2024-04-08 09:47:42 +03:00
Vladimir Kondratyev
1970388766 LinuxKPI: Add strnchr function
strnchr() finds a character in a length limited string.

Sponsored by:	Serenity CyberSecurity, LLC
Reviewed by:	emaste
MFC after:	1 month
2024-04-08 09:47:42 +03:00
Vladimir Kondratyev
aafe4126f7 LinuxKPI: Add ms_to_ktime
Sponsored by:	Serenity CyberSecurity, LLC
Reviewed by:	emaste
MFC after:	1 week
2024-04-08 09:47:42 +03:00
Zhenlei Huang
317cc829ee LinuxKPI: Remove the temporary variable fileid from the macro request_module
The variable fileid stores the result from kern_kldload() but never gets
used. Since the third parameter `*fileid` of kern_kldload() can be NULL,
this unused variable can be safely removed.

No functional change intended.

Reviewed by:	emaste, bz, #linuxkpi
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D44583
2024-04-06 00:26:09 +08:00