When compiling the kernel with gcc 14, errors similar to the following
are emitted:
sys/dev/cxgbe/iw_cxgbe/ev.c: In function 'c4iw_ev_handler':
sys/compat/linuxkpi/common/include/linux/xarray.h:132:23: error: statement with no effect [-Werror=unused-value]
132 | flags == 0; \
sys/dev/cxgbe/iw_cxgbe/ev.c:274:17: note: in expansion of macro 'xa_unlock_irqrestore'
274 | xa_unlock_irqrestore(&dev->cqs, flag);
| ^~~~~~~~~~~~~~~~~~~~
sys/compat/linuxkpi/common/include/linux/xarray.h:132:23: error: statement with no effect [-Werror=unused-value]
132 | flags == 0; \
sys/dev/cxgbe/iw_cxgbe/ev.c:283:17: note: in expansion of macro 'xa_unlock_irqrestore'
283 | xa_unlock_irqrestore(&dev->cqs, flag);
| ^~~~~~~~~~~~~~~~~~~~
It looks like the intent of the "flags == 0" statement was to make the
'flags' macro argument not unused, but it still results in a warning.
Use the construct "(void)flags" instead.
Reviewed by: bz
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D59787
(cherry picked from commit aca53fc2a6879f45dcbe1a60f91f14a5f6d48448)
This is what FreeBSD now does for memdup_user and memdup_array_user
(which is wrong for memdup, but correct for vmemdup).
The amdgpu DRM driver started this in Linux ~6.12.86+
Reviewed by: wulf
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D57444
(cherry picked from commit 302c6d25da6907ec762ff8937fa86d380743b000)
The DRM drivers generic code started to use it in Linux 6.13.
Reviewed by: emaste
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D57582
(cherry picked from commit 50aa145171bc88edde8cf3b7eb13dbbf88a3f8a7)
`DEFINE_CLASS()` is in fact named `LINUXKPI_DEFINE_CLASS()` because it
conflicts with `DEFINE_CLASS()` defined in <sys/kobj.h>.
This macro defines a type and a pair of constructor/destructor
functions.
They are to be used by `CLASS()`: this one declares a variable,
initialise it with the constructor and set the `__cleanup()` attribute
to call the destructor once the variable goes out of scope.
The DRM drivers generic code started to use `CLASS()` in Linux 6.13. It
requires the `fd` class to be defined in <linux/file.h>.
Reviewed by: bz
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D57583
(cherry picked from commit f2a2e02ae54b836d1e23648756a050406f65111e)
We can implement device_set_wakeup_capable() in the !CONFIG_PM_SLEEP
case; we do not have the infrastructure in place for the CONFIG_PM_SLEEP
case so leave a pr_debug TODO.
Needed by an upcoming wireless driver.
Reviewed by: dumbbell
Differential Revision: https://reviews.freebsd.org/D58883
(cherry picked from commit a424fb3519ebf8fb972e7ba45ba19df322992b00)
Add the #define for PCI_IRQ_AFFINITY and leave a pr_debug note in
pci_alloc_irq_vectors() that it is unimplemented.
The flag is needed by an upcoming WiFi driver.
Reviewed by: dumbbell
Differential Revision: https://reviews.freebsd.org/D58881
(cherry picked from commit b589e403a2c3bd2a94fb2ab88cd23255c68a9f05)
We use one to implement the other given direction stays unused.
This is needed by an upcoming wifi driver.
Reviewed by: dumbbell
Differential Revision: https://reviews.freebsd.org/D58880
(cherry picked from commit c3fa17a6a331db8aad03e9cb89ba97e1811ab381)
lkpi_pci_msi_desc_alloc() takes an unsigned int, not an int.
While here make sure the prototype is visibile in interrupt.h as
well before use to avoid -Wimplicit-function-declaration errors.
Discovered while working on a wireless driver.
Reviewed by: dumbbell
Differential Revision: https://reviews.freebsd.org/D58879
(cherry picked from commit cfb23b01e269e8a0a84066637b82b746f01b46b4)
For pci_select_bars() we use the LinuxKPI internal information, while
for pci_select_bars() we fall back to the native PCI stack.
Needed by a wifi driver.
Reviewed by: dumbbell
Differential Revision: https://reviews.freebsd.org/D58878
(cherry picked from commit 55c07af60172b211116be47010fc0831aafc99e8)
Needed by a wireless driver (not really using it) to compile.
Reviewed by: dumbbell
Differential Revision: https://reviews.freebsd.org/D58877
(cherry picked from commit 401d0922a4bfcf40d3ae1866a0d90f955264def0)
Add #include rculist.h to ethtool.h to fullfill expectations of
Linux drivers without having to modify them.
Reviewed by: dumbbell, emaste
Differential Revision: https://reviews.freebsd.org/D58874
(cherry picked from commit 4570a1bf760a3cd63eb7dd9e3ebbc3cf103bda4d)
list_for_each_entry_rcu() can take an optional condition. Add the
macro argument so code remains compiling but do not do anything with
it just yet.
Leave comments as list_for_each_entry_rcu() likely should have a
different implementation.
Sponsored by: The FreeBSD Foundation
Reviewed by: dumbbell
Differential Revision: https://reviews.freebsd.org/D59292
(cherry picked from commit e975ce86ff11a330128f5b21c7cd11c28d3aff87)
The presence of the PCI power management capability does not imply that
a function can signal PME# from every power state. Drivers which
advertise wake based only on pci_has_pm() can consequently expose wake
modes that cannot work.
Add pci_has_pme() to query the PME_Support bitmap for a specific state.
Use it to implement LinuxKPI pci_pme_capable(), removing its duplicate
PME_Support decoder.
Validated the helper against PCI PMC capability values from 82571EB,
82573L, 82579LM, I210, I225, and I226-V controllers. The 82571 and
82573 reported PMC 0xc822, while the I226-V reported 0xc823. In both
values, bits 15, 14, and 11 advertise PME from D3cold, D3hot, and D0;
the low-bit difference is only the PM capability version.
Sponsored by: BBOX.io
(cherry picked from commit c4e24e95c3f905b817d4bfc6e93457eb297bfa4b)
According to Linux documentation the nents argument to dma_unmap_sg()
must be the number one passed in, not the number of DMA addresses.
In LinuxKPI this means orig_nents and not nents, so adjust this.
Given nents and orig_nents should always be the same in LinuxKPI,
this should only be a NOP for correctness.
Reviewed by: bz, aokblast (LGTM)
Differential Revision: https://reviews.freebsd.org/D57842
(cherry picked from commit 33574d47d9dea317b9a4bfe543c4f20be6a565ef)
Implement dma_sync_sg_for_{cpu, device}() and
dma_sync_sgtable_for_device().
These functions are useful for my GSoC 2026 project, udmabuf.
Reviewed by: bz
Differential Revision: https://reviews.freebsd.org/D57766
(cherry picked from commit 9dec0cd79c693951fc58d82a99918fc5a02cbcd0)
In dma_sync_single_for_cpu(), the DMA_BIDIRECTIONAL direction currently
performs BUS_DMASYNC_POSTREAD followed by BUS_DMASYNC_PREREAD. This
patch corrects the mapping to use BUS_DMASYNC_POSTREAD |
BUS_DMASYNC_POSTWRITE.
When ownership of the DMA area is transferred to the CPU, we must assume
the previous device access was bidirectional. Both POST operations are
necessary to ensure the CPU sees a consistent view of memory after
potential device reads and writes. A PREREAD is unnecessary here because
the device will no longer access the memory since ownership has been
transferred to the CPU.
Conversely, for dma_sync_single_for_device(), ownership is being
transferred back to the hardware. The buffer must be prepared for
potential bidirectional access by the device, requiring
BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE.
PR: 293381, 297155
Reported by: Zishun Yi <zishun.yi.dev@gmail.com>
Reported by: Kim Shrier (fbsdbugs westryn.net)
Fixes: 95edb10b47 ("LinuxKPI: implement dma_sync_single_for_*, apply to (un)map single/sg")
Signed-off-by: Zishun Yi <zishun.yi.dev@gmail.com>
Reviewed by: aokblast, bz
Differential Revision: https://reviews.freebsd.org/D55497
(cherry picked from commit 6e1436d748273be52fb155914db3efae075a8619)
Add more defines, structures, sort struct field types, add inline
functions (partially implemented) all needed for the upcoming
espwl(4) wireless driver.
(cherry picked from commit 9b13e6ce5b099af0958a824fa37c70538a8b6d2a)
Two of the "page macros" can be abstracted elsewhere in the upcoming
struct page work, so sort them away from the four which are here to
stay.
No functional change.
Sponsored by: The FreeBSD Foundation
Reviewed by: emaste
Differential Revision: https://reviews.freebsd.org/D58299
(cherry picked from commit 0b8d22019dcf708a8d047817963658783cd53c46)
With upcoming changes to 'struct page' this will make the lines
easier to read by using the predefined macros from param.h.
Sponsored by: The FreeBSD Foundation
Reviewed by: markj, kib
Differential Revision: https://reviews.freebsd.org/D58298
(cherry picked from commit f45506c6a6f4742cd5129d636902b61045c4754b)
clear_page() would normally live in asm/page.h but adding the file
and fixing the dependencies would be too much for a single line.
Move the function to the end of the file with a clear separator
and make it clear that it does not operate on a 'struct page'
but on a page address by changing the argument name and leaving
a comment.
The function is currently used by at least mthca(4) as the only
in-tree consumer, and drm-kmod ttm_pool.c.
No functional changes.
Sponsored by: The FreeBSD Foundation
Reviewed by: emaste
Differential Revision: https://reviews.freebsd.org/D58296
(cherry picked from commit 0845efe88b355547b103dca90e69e46a3ebdd016)
Add more defines, structures, sort struct field types, add inline
functions (partially implemented) all needed for the upcoming
espwl(4) wireless driver.
(cherry picked from commit 9b13e6ce5b099af0958a824fa37c70538a8b6d2a)
Add sg_init_marker() which is needed by mt76 drivers USB attachment.
Sponosored by: The FreeBSD Foundation
Reviewed by: emaste, dumbbell
Differential Revision: https://reviews.freebsd.org/D57594
(cherry picked from commit 3d0b6c69dced4936fccff6733912a0ef93214dbe)
Include <linux/types.h> for `false`. This is needed by amdgpu somewhere
between Linux 6.12 and 6.15.
Reviewed by: Minsoo Choo <minsoo@minsoo.io>, bz
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D57415
(cherry picked from commit 67df313015906d84d90df8e37795885e81cf8da5)
Add a KERNEL_VERSION() macro which normally would be in linux/version.h.
On Linux that file is auto-generated and we are supporting more than
one Linux version in LinuxKPI anyway so any further defines in there
would likely be wrong.
Adding the macro helps to support (vendor/out of tree) drivers more
easily which are supporting multiple Linux versions.
Reviewed by: dumbbell
Differential Revision: https://reviews.freebsd.org/D57590
(cherry picked from commit c5d6e2085a471cbb75cc7b88b37a2fe6276c16f8)
The amdgpu driver in drm-kmod will attempt to update/reserve certain GPU
VRAM ranges as write-combining. Depending on the system, this address
range may fall outside of FreeBSD's constructed DMAP. We cannot use
pmap_change_attr() in this case.
When INVARIANTS is enabled, this results in the following:
panic: physical address 0x880000000 not covered by the DMAP
Add a guard against triggering the KASSERT in PHYS_TO_DMAP().
This limitation in our implementation of arch_io_reserve_memtype_wc() is
already known in drm-kmod's amdgpu_bo_init(), and errors are ignored
there (see "BSDFIXME"). This change is only to eliminate the preventable
assertion failure within this scheme.
Tested by: kevans
Reviewed by: kib, emaste
MFC after: 3 days
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D56971
(cherry picked from commit 988c03980452a56fb0fbb15e18b0a644602d0ab3)
The __maybe_unused attribute should be used for variables which may or
may not be used, such as when their only use is in an assertion. This
attribute is functionally identical to __unused, suppressing compiler
warnings for particular variable if it remains unused.
Reviewed by: Minsoo Choo <minsoo@minsoo.io>, imp
Differential Revision: https://reviews.freebsd.org/D56517
(cherry picked from commit 84a95741805d84f0074a34d61b93ccf86f422cf3)
These calls are used for buddy pages at least in drm's ttm_pool, which
leads to a panic when we invoke lowmem handlers and drm tries to shrink
the pool.
Cope with numpages > 1 by traversing the contiguous pages and executing
the adjustment there, as well, as suggested by markj@. Previous
versions have tried to use the corresponding `set_memory_*()` functions,
but it is believed that not updating `md.pat_mode` breaks subsequent
userspace mappings in ways that may result in things like screen tearing
or other artifacts when running i915kms.
This stabilized my amdgpu laptop running two VMs, chromium and a
concurrent buildworld.
Reviewed by: bz, markj
(cherry picked from commit 67f7f2781daa9bd398b424ffe2bd0be67f37f03d)
(cherry picked from commit 8dad29555a5807bf21941807752e1589e20312de)
Add print masks for tx status flags and use them in the TX tracing
in order to more easily debug TX problems.
As a result it was easier to determine that some dirver like the mt7921
(or mt76) do not always zero the status bits of the tx status information
(it is a union with the control bits passed on TX) and thus we get bogus
values back (rather than having flags in a different place than we thought).
Sponsored by: The FreeBSD Foundation
(cherry picked from commit 0cb3b9229876a2a83d217779cf5ecd09eb153fc3)
Add an internal flag which is set by skb_mark_for_recycle() and upon
"skb_free" then selects whether the skb is freed or returned to the
page pool.
There will likely be more details to figure out once the LinuxKPI page
work is done and we support more of the page pool than the bare minimum.
Sponsored by: The FreeBSD Foundation
(cherry picked from commit e4795d3dbee71c463429e2901dad111fbc2d08fc)
skb_linearize() is used by mt7921, mt7925, and in the general mt76 tx dma
code. __skb_linearize() is used in the general iwlwifi TX code but given
the way we currently create TX skbs in LinuxKPI 802.11 we never hit that
case.
Sponsored by: The FreeBSD Foundation
(cherry picked from commit 9de11cc26ab61d7f80e8af84dbc55d8cbd6f832d)
Implement napi_build_skb() around linuxkpi_build_skb().
Sponsored by: The FreeBSD Foundation
(cherry picked from commit b36460e5ec4659d0fa14b35c9342c5a154b3db7d)
Add skb_put_zero() as a simple wrapper around __skb_put_zero().
Sponsored by: The FreeBSD Foundation
(cherry picked from commit 32c983449a7c802bf47578d5304c6d505db7821a)
Deal with SKB_TRACE_FMT optional arguments; while here properly indent.
Add KASSERT to __skb_unlink() to catch incorrect skbuffs encountered
while debugging a wireless driver (which had other pre-conditions failing).
Sponsored by: The FreeBSD Foundation
(cherry picked from commit e5bcf7b99fcbe06d381525ffdd5027b846cdc1d3)
In Linux v6.17 system_wq was replaced (renamed to) system_percpu_wq,
with the old name still present.
We just alias system_percpu_wq to linux_system_short_wq like we do
for system_wq to keep both around for the forseeable future.
Note: the original system_wq was a per-cpu queue upstream as well
based on my understanding but we never implemented it as such.
That means we are still lacking a per-cpu implementation for
system_percpu_wq but at least we do not change the status-quo
of the LinuxKPI implementation with this.
Note2: we should add a check somewhere for LINUXKPI_VESION >=
61700 to print a warning if anyone still uses the system_wq
to detect any possible sami-native or out-of-tree drivers
relying on this and not properly updating.
Sponsored by: The FreeBSD Foundation
Reviewed by: dumbbell; emaste (comments on previous review)
Differential Revision: https://reviews.freebsd.org/D57730
(cherry picked from commit 058ce52660fb52ada41462d339fb1ce6aca48cf3)
pm_runtime_resume_and_get is used by new versions of amdgpu, and began
use between Linux kernel version 6.12, and 6.14.
Reviewed by: dumbbell
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D57463
(cherry picked from commit 7e1245aafeece1a56af292c2652c6b835ccb6f10)
This fixes an "unused variable" warning when building DRM drivers.
Approved by: re (cperciva)
Reviewed by: emaste
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D56780
(cherry picked from commit 658bb99db9c7872f92ccb86ed2674c72636436d2)
(cherry picked from commit c81f516512111fa5ac8d5a9f3f7e64c2fb5ab5a3)
This macro will return non-zero if there are threads waiting for this
lock; otherwise, it will return zero.
The function assumes (but does not assert) that the caller already holds
the lock and that it is interested in other threads waiting for it to
release the lock.
The motivation to add this is the implementation of
`rwsem_is_contended()` in linuxkpi.
This Linux function indicates the same thing to the caller: if other
threads are waiting for this semaphore.
The amdgpu DRM driver started to use `rwsem_is_contended()` in Linux
6.12.
Reviewed by: bz, olce
Sponsored by: The FreeBSD Foundation
(cherry picked from commit eebb643bb3799ae90dd248f0b5047ec481b26f68)
In Linux 7.1, `__copy_from_user_inatomic_nocache()` was renamed to
`copy_from_user_inatomic_nontemporal()`. This change was backported to
several LTS branches.
This includes Linux 6.12.x and the i915 DRM driver started to use it in
that version.
Reviewed by: bz
Sponsored by: The FreeBSD Foundation
(cherry picked from commit 713b4ce8ef46d7df4ffe50ab6733bb128dbe3cbd)
The `DEFINE_XARRAY*()` macros are used to declare a static xarray.
As the structure embeds a mutex(9), we also need to declare the static
mutex after the `struct xarray`. Thus the slightly awkward definition
of `DEFINE_XARRAY_FLAGS()`.
The DRM generic code started to use `DEFINE_XARRAY_ALLOC()` in Linux
6.12.
Reviewed by: bz
Sponsored by: The FreeBSD Foundation
(cherry picked from commit 796fff59a5d32bc3be14feaeb228fc15ef43eb32)
The `xa_alloc*()` functions family takes a `struct xa_limit` to describe
the range of IDs the caller wants to allocate. We were using a single
mask to qualify a maximum ID only.
This commit changes that to use the same `struct xa_limit`. The logic
did not change, except it now supports a minimum ID as well.
The definition of `XA_LIMIT()` macro is adapted, as well as the
definitions of `xa_limit_*` (only `xa_limit_32b` existed, the other two
are added with this commit).
The DRM generic code started to use this `struct xa_limit` in Linux
6.12.
Reviewed by: bz
Sponsored by: The FreeBSD Foundation
(cherry picked from commit 783d018cf954f99032a0a4f655af8916024598a8)
It indicates to `alloc_pages()` to allocate the pages from the current
NUMA domain. If it couldn't, it should not retry elsewhere and return
failure.
Reviewed by: bz
Sponsored by: The FreeBSD Foundation
(cherry picked from commit 06a51a510a60ca29193b2cdb8120b630ea9ef18c)
This flag combines `GFP_KERNEL` and `__GFP_ACCOUNT`. The latter is also
defined in this commit. It is defined as a no-op flag as it is not
implemented.
The DRM generic code started to use it in Linux 6.12.x.
Reviewed by: bz
Sponsored by: The FreeBSD Foundation
(cherry picked from commit af01ffbfb1c0a0104d3a4c7dd1342ed7c81c6c54)