Commit graph

1023 commits

Author SHA1 Message Date
Vladimir Kondratyev
c535e8ae7f 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

(cherry picked from commit 7f88d742e578c4cef4e26ce10b9a936e58237964)
2024-02-17 23:58:38 +03:00
Vladimir Kondratyev
96e464b8d5 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

(cherry picked from commit 2b037743a77dcf31095fe1fedd21870b3aa6494b)
2024-02-17 23:58:38 +03:00
Vladimir Kondratyev
edeb8cfad0 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

(cherry picked from commit 5ae2e6f913fa1df5f3262255558b76af05409a09)
2024-02-17 23:58:38 +03:00
Vladimir Kondratyev
cdceed0413 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

(cherry picked from commit 1b2f43a7427ebf51561867f6c497833268014512)
2024-02-17 23:58:38 +03:00
Vladimir Kondratyev
ada94bf9e8 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

(cherry picked from commit 64e30cba3f0432fa684728b67850b6254d3713ea)
2024-02-17 23:58:38 +03:00
Vladimir Kondratyev
4d5091c23c 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

(cherry picked from commit a39ed121eab16bd2579422f71df7ef29b55965d1)
2024-02-17 23:58:38 +03:00
Vladimir Kondratyev
fcfc3fe00d 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

(cherry picked from commit c7312643b7e5f01adc2a3094c5139f5dcab5f0a4)
2024-02-17 23:58:38 +03:00
Vladimir Kondratyev
67cc189db4 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

(cherry picked from commit af787b8e8b803dbb2c6bd06629974ba39bd0fb70)
2024-02-17 23:58:37 +03:00
Vladimir Kondratyev
f3ce597171 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

(cherry picked from commit e964da141523e1eec2322082936cdb20ba0cf4a7)
2024-02-17 23:58:37 +03:00
Vladimir Kondratyev
06db4f5b62 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

(cherry picked from commit 66f9a98335dcc2a3c1eead0d80ccc9fee12bbb31)
2024-02-17 23:58:37 +03:00
Vladimir Kondratyev
460a6c6a9f LinuxKPI: Implement ioread64()
Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu, bz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42801

(cherry picked from commit dcfc983373c3e3dcd7025e5f65832ab696832261)
2024-02-17 23:58:37 +03:00
Vladimir Kondratyev
11b0824a80 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

(cherry picked from commit f8ab2f5bae1d4e4e13f95f4738c9bb49fcda6261)
2024-02-17 23:58:37 +03:00
Vladimir Kondratyev
c254bc21dd 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

(cherry picked from commit 1bce29bcf121c1e16205fabb100f798d88f757c1)
2024-02-17 23:58:37 +03:00
Vladimir Kondratyev
21d85c41bb 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

(cherry picked from commit fa862482fb0a8759984437d71221b17377625491)
2024-02-17 23:58:36 +03:00
Vladimir Kondratyev
c3a10c2332 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

(cherry picked from commit 31ef29091b0fbadefb4ccfb21e4b30ca7ddca3ed)
2024-02-17 23:58:36 +03:00
Vladimir Kondratyev
8291858235 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

(cherry picked from commit a01259965319897b836019f1d4dcf1b5a5a6ea1a)
2024-02-17 23:58:36 +03:00
Vladimir Kondratyev
1341925217 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

(cherry picked from commit ae1084ff01bf9d9a9a2c56caf6c7095f3e96f579)
2024-02-17 23:58:36 +03:00
Vladimir Kondratyev
914a0c5e1b 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

(cherry picked from commit 96ab16ebab6319dce9b3041961b0ab6e20a4fecc)
2024-02-17 23:58:36 +03:00
Jean-Sébastien Pédron
356bfb0878 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

(cherry picked from commit d6d1e73e5f66f3b12881fffceff58ca54b506792)
2024-02-17 23:58:36 +03:00
Jean-Sébastien Pédron
daebad715c 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

(cherry picked from commit 38138beb42d1892dbd8ebb29c01c4471c86d8845)
2024-02-17 23:58:36 +03:00
Jean-Sébastien Pédron
0b3e4b3cc9 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

(cherry picked from commit d752a5e82ac92603fadf82e7de75878e1f5d054a)
2024-02-17 23:58:35 +03:00
Jean-Sébastien Pédron
af41c1bee4 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

(cherry picked from commit 509707e8b6b7326c7f4793b6e291f0a8e6939412)
2024-02-17 23:58:35 +03:00
Jean-Sébastien Pédron
0fef6cb729 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

(cherry picked from commit b723bcd05a991d446491e914f2b9f35e66227398)
2024-02-17 23:58:35 +03:00
Jean-Sébastien Pédron
3b97bdb453 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

(cherry picked from commit 80446fc7b5e5d22e2bac28bc0474dbe2fec83e43)
2024-02-17 23:58:35 +03:00
Jean-Sébastien Pédron
843107faca 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

(cherry picked from commit 4e0d3f7b3c3295e51ded2bab39f36842f405b4eb)
2024-02-17 23:58:35 +03:00
Jean-Sébastien Pédron
586c0e9676 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

(cherry picked from commit 50a56453dadbd05eb1c43addaf2773a1ef417445)
2024-02-17 23:58:35 +03:00
Jean-Sébastien Pédron
f07f18ec2c linuxkpi: Include <linux/rbtree.h> from <linux/hrtimer.h> and <linux/mm_types.h>
[Why]
Some files in DRM rely on this indirect include to use `struct rb_*`.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D42835

(cherry picked from commit b292c995cfa88cc73d5d77b6b94ae1b78296793f)
2024-02-17 23:58:35 +03:00
Jean-Sébastien Pédron
bb01efa6f8 linuxkpi: Fix uses of pmap_change_attr()
[Why]
This function takes an offset and a length as argument, not a physical
address and a number of pages.

This misuse caused the `set_memory_*()` and
`arch_io_reserve_memtype_wc()` functions to return EINVAL.

Another problem was the fact that they returned errors as a positive
integer, whereas Linux uses negative integers.

[How]
Physical addresses and number of pages are converted to offset+length in
the `set_memory_*()` functions.

`arch_io_reserve_memtype_wc()` now calls `pmap_change_attr()` directly
instead of using `set_memory_wc()`.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D42053

(cherry picked from commit 1e99b2ee90956f275c3668e92a408400f2dada1c)
2024-02-17 23:58:34 +03:00
Olivier Certner
f946a5ec96 linuxkpi: dma_get_cache_alignment(): Fix off-by-one result
Substituting 'uma_align_cache' by the appropriately named accessor
uma_get_cache_align_mask() made apparent that dma_get_cache_alignment()
was off by one, since it was defined to be the mask derived from the
alignment value.

Reviewed by:            markj, bz
MFC after:              2 weeks
Sponsored by:           The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D42264

(cherry picked from commit 2c7dd66d09a1b92a4698232996cded6e5315b3bd)
2023-11-16 10:07:18 -05:00
Olivier Certner
4587326893 uma: Hide 'uma_align_cache'; Create/rename accessors
Create the uma_get_cache_align_mask() accessor and put it in a separate
private header so as to minimize namespace pollution in header/source
files that need only this function and not the whole 'uma.h' header.

Make sure the accessors have '_mask' as a suffix, so that callers are
aware that the real alignment is the power of two that is the mask plus
one.  Rename the stem to something more explicit.  Rename
uma_set_cache_align_mask()'s single parameter to 'mask'.

Hide 'uma_align_cache' to ensure that it cannot be set in any other way
then by a call to uma_set_cache_align_mask(), which will perform sanity
checks in a further commit.  While here, rename it to
'uma_cache_align_mask'.

This is also in preparation for some further changes, such as improving
the sanity checks, eliminating internal resolving of UMA_ALIGN_CACHE and
changing the type of the 'uma_cache_align_mask' variable.

Reviewed by:            markj, kib
MFC after:              2 weeks
Sponsored by:           The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D42258

(cherry picked from commit dc8f7692fd1de628814f4eaf4a233dccf4c92199)
2023-11-16 10:07:07 -05:00
Austin Shafer
2709483a72 linuxkpi: fix iteration in __sg_alloc_table_from_pages
Commit 3f686532c9 tried to fix an issue with not properly starting
at the first page in the sg list to prevent a panic. This worked but
with the side effect of incrementing "s" during the final iteration
causing it to be NULL since the list had ended.
In cases non-DEBUG kernels this causes a panic with drm-5.15, since
"s" is NULL when we later pass it to sg_mark_end().
This change decouples the iteration sg from the return value so that
it is never incremented past the final page in the chain.

Reviewed by:	manu
Differential Revision: https://reviews.freebsd.org/D41574

(cherry picked from commit 09b0401e91a92bcb58ea1873857b42f8211f660f)
2023-10-06 12:47:39 +00:00
Bjoern A. Zeeb
46e5d2b0c6 LinuxKPI: skbuff: remove assumption about mac_header
It seems the mac_header can be set to offset 0 for frames received.
Remove the warning splattering messages to the console for each packet.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit f0e59b6903c881859d7f4eaf269b2336b774c7bc)
2023-10-04 15:19:18 +00:00
Emmanuel Vadot
15314c51e8 kern: Globally define abs64
So we can use it in non-linuxkpi sources.

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

(cherry picked from commit 229c65a83fbe0ede8c617e35d8f8c14d5ebadc19)
2023-09-18 21:13:45 +00:00
Bjoern A. Zeeb
cbb3ec2523 mt76: update driver from upstream
This is a set of updates of the mt76 driver based on wireless-testing
(wt-2023-05-11) 711dca0ca3d77414f8f346e564e9c8640147f40d (after v6.4-rc1),
  This adds support for mt7996 as well.
(wt-2023-06-09) 7bd20e011626ccc3ad53e57873452b1716fcfaaa (after v6.4-rc5),
(wt-2023-07-24) 62e409149b62a285e89018e49b2e115757fb9022 (after v6.5-rc3),
(wt-2023-08-06) 2a220a15be657a24868368892e3e2caba2115283 (after v6.5-rc4).

The current version of LinuxKPI lacks support for "page pool" which
needs enhancing and updating a decade or so old shortcut mapping
struct page directly to struct vm_page.

MFC after:	20 days
2023-08-21 01:34:03 +00:00
Bjoern A. Zeeb
adff403fe7 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
2023-08-21 00:39:57 +00:00
Bjoern A. Zeeb
e039b38d46 LinuxKPI: skbuff: add skb_cow_head()
Add dummy implementation of skb_cow_head().

Sponsored by:	The FreeBSD Foundation
MFC after:	10 days
2023-08-19 04:55:56 +00:00
Bjoern A. Zeeb
149c457de1 LinuxKPI: skbuff: fix tracing
Fix arguments to a trace line and remove another trace line until we
actually will have the skb to trace along with a future implementation.

Sponsored by:	The FreeBSD Foundation
MFC after:	10 days
2023-08-19 04:53:00 +00:00
Doug Moore
b6a61d6836 linuxkpi math: fix kassert in math64.h
Include <sys/systm.h> in math64.h, so that KASSERT and bool are
defined, to allow compilation to succeed after
b80ea45237 and dabbbebcb0f5...
2023-08-18 00:31:03 -05:00
Kyle Evans
dabbbebcb0 linuxkpi: fix buildkernel after b80ea45237
Unbalanced parentheses broke the build; re-balance.

Fixes:	b80ea45237 ("LinuxKPI: implement mul_u64_u64_div_u64()")
2023-08-18 00:12:37 -05:00
Bjoern A. Zeeb
b80ea45237 LinuxKPI: implement mul_u64_u64_div_u64()
Implement mul_u64_u64_div_u64() for an updated iwlwifi driver (though
we do not yet use it there; it is used for in-kernel ptp on wifi).

Sponsored by:	The FreeBSD Foundation
Submitted by:	cperciva
MFC after:	10 days
Reviewed by:	cperciva, dwmalone
Differential Revision: https://reviews.freebsd.org/D40120
2023-08-18 01:20:39 +00:00
Warner Losh
71625ec9ad sys: Remove $FreeBSD$: one-line .c comment pattern
Remove /^/[*/]\s*\$FreeBSD\$.*\n/
2023-08-16 11:54:24 -06:00
Warner Losh
95ee2897e9 sys: Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:11 -06:00
Bjoern A. Zeeb
d1ea07642c LinuxKPI: cleanup internal calls to VM_PAGE_TO_PHYS
Replace FreeBSD native VM_PAGE_TO_PHYS() calls with page_to_phys()
allowing us to work on a struct page in the future using the one
single public Linux KPI interface to map to a native FreeBSD vm_page.

This should be a NOP.

Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
Reviewed by:	markj
Differential Revision: https://reviews.freebsd.org/D41256
2023-08-07 00:57:42 +00:00
Bjoern A. Zeeb
9e9c682ff3 LinuxKPI: reduce usage of struct vm_page and vm_page_t
We currently define (Linux) page to (FreeBSD) vm_page.
Cleanup some of the direct struct vm_page and vm_page_t declarations
and usages in the Linux KPI and make them 'struct page' or
'struct page *' to prepare for more upcoming work.

This should be a NOP.

Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
Reviewed by:	markj
Differential Revision: https://reviews.freebsd.org/D41255
2023-08-07 00:55:30 +00:00
Bjoern A. Zeeb
f74c09f3ec LinuxKPI: pci.h add more constants
Add two more PCI_EXP_LNKSTA_CLS constants to the compat defines
needed by wireless drivers.

Sponsored by:	The FreeBSD Foundation
MFC after:	10 days
Reviewed by:	manu, emaste
Differential Revision: https://reviews.freebsd.org/D41258
2023-08-07 00:54:03 +00:00
Bjoern A. Zeeb
1dcd1a5392 LinuxKPI: implement get_random_u32_inclusive()
Implementation of get_random_u32_inclusive().
This is needed by an update for wireless drivers.

Sponsored by:	The FreeBSD Foundation
MFC after:	10 days
Differential Revision: https://reviews.freebsd.org/D40121
2023-08-07 00:52:41 +00:00
Bjoern A. Zeeb
1b18fb7faa LinuxKPI: list.h add list_count_nodes()
Implement list_count_nodes() using a simple loop.  This is needed by
an updated wireless driver.

Sponsored by:	The FreeBSD Foundation
MFC after:	10 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D40757
2023-06-28 01:32:29 +00:00
Bjoern A. Zeeb
08bc2cc4c4 LinuxKPI: cast jiffies_to_msecs() result
jiffies_to_msecs() is expected to return an uint_t.  In order to avoid
changing printf format strings, properly cast the result to the
expected type.

Sponsored by:	The FreeBSD Foundation
MFC after:	10 days
Reviewed by:	hselasky
Differential Revision: https://reviews.freebsd.org/D40486
2023-06-26 07:54:24 +00:00
Corvin Köhne
740d76544a
linuxkpi: advance platform_device
These are required by some linux driver like:
https://github.com/beckhoff/bbapi

Reviewed by:		manu
MFC after:		1 week
Sponsored by:		Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D39554
2023-06-13 09:49:01 +02:00
Bjoern A. Zeeb
bee50f894b LinuxKPI: qcom: update QMI and MHI
Minor updates to QMI and MHI (mostly making arguments const)
in order to facilitate porting the next generation athk driver.

MFC after:	10 days
2023-06-10 23:06:04 +00:00