Commit graph

1173 commits

Author SHA1 Message Date
Olivier Certner
88a7dd1118 LinuxKPI: Have kvzalloc() rely on kvmalloc(), not kmalloc()
Since commit 19df0c5abcb9d4e9 ("LinuxKPI: make __kmalloc() play by the
rules"), kmalloc() systematically allocates contiguous physical memory,
as it should.  However, kvzalloc() was left defined in terms of
kmalloc(), which makes it allocate contiguous physical memory too.  This
is a too stringent restriction, as kvzalloc() is supposed to be a simple
page-zeroing wrapper around kvmalloc().

According to Linux's documentation ("memory-allocation.rst"), kvmalloc()
first tries to allocate contiguous memory, falling back to
non-contiguous one if that fails.  Thus, callers are already supposed to
deal with the possibility of non-contiguous memory being returned.

Reviewed by:    bz
Fixes:          19df0c5abcb9 ("LinuxKPI: make __kmalloc() play by the rules")
MFC after:      10 days
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D51247

(cherry picked from commit 986edb19a49c7d7d3050c759d9b0826283492ebf)

Forgotten on commit to main/-CURRENT:
PR:             277476
2025-07-31 12:43:10 +02:00
Ed Maste
9e24f4a6d8 linuxkpi: Remove incorrect + 1 from HWEIGHT* macros
Fixes: 4cc8a9da49 ("LinuxKPI: add HWEIGHT32()")
Reviewed by:	bz
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D51010

(cherry picked from commit cdbff1b2999660b31b2de076d04670722a555ed2)
2025-07-28 10:15:31 +02:00
Bjoern A. Zeeb
55b4ef5444 LinuxKPI: skbuff: make csum_unfold return __wsum
Given the internal field now stores a __wsum csum (after we added
the type) also make sure csum_unfold() returns a __wsum.

Sponsored by:	The FreeBSD Foundation
Fixes:		59481c7db234

(cherry picked from commit 36ca21722c2700e00e41444a29aeabf246eea90d)
2025-07-16 08:45:25 +02:00
Bjoern A. Zeeb
1ca66ac330 LinuxKPI: skbuff: add dummy skb_copy_header()
There's one case which needs skb_copy_header();  add a dummy function
for now until we get to the code which uses it to test an implementation.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 84c5998ccb0b3e8a401d1f2b5a32649e88847d63)
2025-07-16 08:45:25 +02:00
Bjoern A. Zeeb
6e214c2140 LinuxKPI: add struct_group_tagged()
Restructure struct_group() into a wrapper around __struct_group().
Various callers have arguments annotated as /* no foo */ so try to
add all we can find.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	dumbbell
Differential Revision: https://reviews.freebsd.org/D50157

(cherry picked from commit 54d0e1772fb6b83d72725764e0a5d3ead8337673)
2025-07-16 08:45:06 +02:00
Bjoern A. Zeeb
1a1a1ffd85 LinuxKPI: add ktime_get_boottime_seconds()
ktime_get_boottime_seconds() is needed by an updated iwlwifi driver.

Sposored by:	The FreeBSD Foundation
Reviewed by:	dumbbell
Differential Revision: https://reviews.freebsd.org/D50005

(cherry picked from commit 93b82146c43b8ecad4fd7694ec1daf6d79cca65c)
2025-07-16 08:44:48 +02:00
Bjoern A. Zeeb
2ca8d402df LinuxKPI: add is_unicast_ether_addr()
Needed by mediatek/mt76 wireless driver.

While here adjust the way is_multicast_ether_addr() is implemented
to not look weird. [1]

Sponsored by:	The FreeBSD Foundation
Suggested by:	emaste [1]
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D50152

(cherry picked from commit a4618caa43c16e6e672c27dac1943fd833f8bd8f)
2025-07-16 08:43:58 +02:00
Bjoern A. Zeeb
ddb311ffab LinuxKPI: add _devcd_free_sgtable() to devcoredump.h
It may be that once we implement freeing of chained tables
_devcd_free_sgtable() will become our _lkpi_dev_coredumpsg_free()
but further investigations need to happen.  For now make an
updated iwlwifi driver happy which should not need more.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	dumbbell
Differential Revision: https://reviews.freebsd.org/D50006

(cherry picked from commit 71576ed24b56143429a3b6774a7862965c2dea88)
2025-07-16 08:43:07 +02:00
Bjoern A. Zeeb
bf1e748dfd LinuxKPI: netdev features style, annotate, and add %b decoding mask
Start to sort through the netdevice features to match them with
FreeBSD.  Annotate them a bit more verbose though the names are
pretty telling already.

While here adjust style(9) as well.

Lastly add the bit definitions for use with printf(9) %b as names
read easier than bitmasks.  We will use that in LinuxKPI 802.11.

No functional changes.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 4b6b9c1368b346f7093153d14e7931403ac3202d)
2025-07-16 08:42:44 +02:00
Bjoern A. Zeeb
5ddd593b7a LinuxKPI: netdev: add NETIF_F_HW_TC
Add a new flag needed by mt76.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 9c05d6320cc091ffb43002a149c04c122ccb798c)
2025-07-16 08:42:42 +02:00
Bjoern A. Zeeb
743d465e86 LinuxKPI: MODULE_DEVICE_TABLE() factor out the bus specific MODULE_PNP_INFO()
In order to be able to use MODULE_DEVICE_TABLE() with multiple bus
attachments, factor out the bus-specfic MODULE_PNP_INFO() and place
it next to the structure defining the table.

As it turns out bnxt(4) has been using the MODULE_DEVICE_TABLE() with
PCI attachments for the "auxillary" bus so far.  That makes little sense.
Define the MODULE_PNP_INFO() to nothing for that.  We may consider
pulling these LinucKPI bits in semi-native drivers into LinuxKPI
one day as that route is not really sustainabke.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	imp, dumbbell
Differential Revision: https://reviews.freebsd.org/D51049

(cherry picked from commit 2f5666c1727c949491f73e6c3277b7b542131714)
2025-07-16 08:34:33 +02:00
Bjoern A. Zeeb
9860e47f49 LinuxKPI: MODULE_DEVICE_TABLE() remove hard coded pci
While we currently only use MODULE_DEVICE_TABLE() for pci (or so I
thought [*]), this may soon change.  Remove a hard coded "pci" for
the bus and use the bus name passed in as _bus.

[*] see follow-up change

Sponsored by:	The FreeBSD Foundation
Reviewed by:	imp, dumbbell
Differential Revision: https://reviews.freebsd.org/D51048

(cherry picked from commit f58e032410c93d67c83d6bce8a3e6711f377a4be)
2025-07-16 08:34:33 +02:00
Bjoern A. Zeeb
bc1acdbcb8 LinuxKPI: Implement dma_map_resource/dma_unmap_resource functions
dma_map_resource() and dma_unmap_resource() functions are used to map
and unmap of memory-mapped IO resources so they can be accessed by
the device.

Required by drm-kmod v5.5 to be built.

While for drm-kmod 6.6-lts only amdgpu uses these in one place and
the code apparently has not been exercised a lot it has been around
like this for years.  With changing the underlying implementations
bring it into the tree; should we find errors with it they can also
be fixed here.

Bump __FreeBSD version to be able to detect this change.

Obtained from:	D30933 (by wulf)
Sponsored by:	The FreeBSD Foundation
Reviewed by:	dumbbell
Differential Revision: https://reviews.freebsd.org/D49625

(cherry picked from commit a02180cf60a6a0102669b678e9c81ad9f1aa4d91)
2025-07-16 08:34:33 +02:00
Bjoern A. Zeeb
bef3edfe61 LinuxKPI: add missing bus_dmamap_sync() calls or exclude them
Rename linux_dma_unmap() to lkpi_dma_unmap(), and linux_dma_map_phys()
to lkpi_dma_map_phys() so that we get the full set of function
arguments (direction and attributes were missing).
Leave the old functions as wrappers as they are called from drm-kmod
linuxkpi/bsd still, and leaving them also allows us to MFC this
change.

Add missing bus_dmamap_sync() calls.  Rather than inlining them
in each inline function push them down to the actual implementation.
From there do not inline them either but call the appropriate
function dealing with the sync so that we do not have the same
code splattered in many places.

Adhere to the DMA_ATTR_SKIP_CPU_SYNC attribute and skip synching
when requested.

A previous, less complete version of this change already allowed
me to load firmware on arm64 for iwlwifi (again).

There are four more places which are not currently done as the
functions which came with an OFED sync a long time ago seem to be
unused these days.  Leaving a pr_debug("TODO") call there.

Also dma_[un]map_resource() when brought in from drm-kmod/linuxkpi/bsd
(D30933) should be adjusted to pass the full arguments as the amdgpu
callers are requesting to skip synching.

Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D45294

(cherry picked from commit f99d393f7f787ff080c12b92243adcc310ac7c58)
2025-07-16 08:34:33 +02:00
Bjoern A. Zeeb
6cdd444452 net80211: LinuxKPI: migrate HE defines to net80211, put correct values
Migrate most LinuxKPI 802.11 definitions for HE IEs to net80211.
During that process also properly define them as most of them only
had dummy values.  Some of the definitions are sparse;  that is, only
the bits used by drivers so far were listed and annotated with the
standards section.

There seems to be little point to mangle the names and have two copies
of all these bit field definitions.  We can add "_S" (shift/mask)
variants to those we need in net80211 (if we do).

Sponsored by:	The FreeBSD Foundation
Reviewed by:	adrian
Differential Revision: https://reviews.freebsd.org/D50677

(cherry picked from commit 2ab7cbdc346e2a174a7bee4ce44c4f78b1ca093b)
2025-07-09 10:05:45 +02:00
Bjoern A. Zeeb
4d66e0f884 LinuxKPI: 802.11: mark struct ieee80211_ht_cap __packed
In lkpi_sta_sync_ht_from_ni() we are casting the information element (IE)
data to this struct as net80211 does not save the mcs/rx_mask.
Not marking the structs packed results in the mcs information not being
copied correctly and rx_nss calculations possibly being off.  Even worse,
at a later stage iwlwifi mvm/rs.c would extract the mcs values from the
same field to pass to the firmware which will than crash in an assert
as we would want to do HT with an empty MCS set.

Sponsored by:	The FreeBSD Foundation
Discovered:	while testing other features on arm64.
Approved by:	re (cperciva)

(cherry picked from commit 6cbf8a04b1864d933506301cabe213a9c918d968)
(cherry picked from commit 9ccf7aeaa5dc5ceb3bf896d84ee50294b841043b)
2025-05-27 22:44:20 +00:00
Bjoern A. Zeeb
873c0ea648 LinuxKPI: 802.11: header updates for mt76
Add more structs, fields, flags, defines.

Sponsored by:	The FreeBSD Foundation
Approved by:	re (cperciva)

(cherry picked from commit 675e6b1c68ba71af1853952f7df4d84399340009)
(cherry picked from commit 6a0dbc0a1246c9825f0892bb6dd957f5d081057a)
2025-05-08 21:22:53 +00:00
Bjoern A. Zeeb
62c010b651 LinuxKPI: define time64_t
Define time64_t to int64_t for all supported architectures
unconditionally.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	imp, markj, emaste
Differential Revision: https://reviews.freebsd.org/D50004

(cherry picked from commit 8b51cd07f69e9a5052f660d96a8feb7af4b387c1)
2025-04-29 10:49:34 +00:00
Bjoern A. Zeeb
85bd58055f LinuxKPI: sysfs: implement sysfs_match_string()
Use a macro to automatically gather the length of the array while
we can.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D50007

(cherry picked from commit f94d7319540b9b2256be60c2c666efe0b6e635ef)
2025-04-29 10:49:33 +00:00
Bjoern A. Zeeb
6510caf356 LinuxKPI: pci: add pci_info()
Add pci_info() needed for a driver update.  While here prefix
__VA_ARGS__ with ## for pci_err and pci_info in case we are only
passed a string without format arguments.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D50009

(cherry picked from commit e29d72ac3ddd9b97d945c5c64bc817e501bb113c)
2025-04-29 10:49:33 +00:00
Bjoern A. Zeeb
1eb45fe4c2 LinuxKPI: extend struct and enum for leds
An updated rtw88 driver requires minimal changes to leds.h.  On
the positive side we can now remove the __DUMMY from the enum as we
actually have a valid field name.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D50002

(cherry picked from commit 69880fede78fc769ad417e5a984fb9fee7815d8b)
2025-04-29 10:49:33 +00:00
Bjoern A. Zeeb
5fc174c52f LinuxKPI: add container_of_const()
Implement container_of_const() needed for wireless driver updates.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D49999

(cherry picked from commit 6841b9987e83fdd9a5b05ceafc20811469222d8b)
2025-04-29 10:49:33 +00:00
Bjoern A. Zeeb
6c08f9a5c6 LinuxKPI: add cleanup.h to mutex.h
Some code relies on header pollution (or self-sustainability).
Add cleanup.h to mutex.h as that is one case it seems to be used with.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D50001

(cherry picked from commit 059136a95aca2e550b62ef40ab25a184d8141124)
2025-04-29 10:49:33 +00:00
Bjoern A. Zeeb
5c0182cbe5 LinuxKPI: add ASMEDIA vendor ID for PCI
This is needed for rtw89 updates.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	emaste, zarychtam_plan-b.pwste.edu.pl
Differential Revision: https://reviews.freebsd.org/D50000

(cherry picked from commit c8e2458de590d7427ef3311412b8ddbc326cd3b5)
2025-04-29 10:49:32 +00:00
Bjoern A. Zeeb
92a74b3bce LinuxKPI: 802.11: updates to headers for driver update
Move some structs into the appropriate header to be visible.
Add new fields to structs and enums.

Remove arguments from two functions (one function currently unused
by drivers in the tree, for the other the argument was unused).
Adjust the iwlwifi accordingly.  This is in preparation for new
driver versions to allow a smooth transition.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit e6010da63903cc6d9aac0077ab861cfd6bae2aa7)
2025-04-29 10:49:32 +00:00
Bjoern A. Zeeb
d416d659b9 LinuxKPI: 802.11: fix TKIP RX/TX MIC offsets
TKIP has a special key buffer.  While keylen only identifies the
key length, the two MIC are appended.  The LinuxKPI offsets for
these were unfortunately never set correct which lead to constant
Micheal counter measures as the MIC never was correct when calculations
were offloaded to firmware.  This is the first half of the fix.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit a23908728efce08cfd10b13ed34de1361d0a980f)
2025-04-29 10:49:31 +00:00
Bjoern A. Zeeb
ce537904d4 LinuxKPI: skbuff: fix types, shuffle fields
Fix the types of a few remaining fields.
Shuffle the fields around so the important ones align to 64byte on a
64bit platform.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 59481c7db2340c9e64f9d3d9d05dafc2d72c157e)
2025-04-29 10:49:29 +00:00
Bjoern A. Zeeb
7f4088f428 LinuxKPI: skbuff: remove _alloc_len field
Initially we saved the exact allocation length for contigfree(9).
contigfree can now be replaced by free(9) so there is no need to
remember that value anymore.  Removing it also simplifies the
linuxkpi_kfree_skb() code.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 73e3969fd435eea296b44f3bd40ff76c042c9a36)
2025-04-29 10:49:29 +00:00
Bjoern A. Zeeb
bb9b11bc64 LinuxKPI: add type for __wsum
Seems this is the correct type for the csum field in an sk_buff.
Add it as uint32_t __bitwise__.

Sponsored by;	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D49831

(cherry picked from commit c925e0a77606d07e4d93204a1d35530176c4b344)
2025-04-29 10:49:29 +00:00
Bjoern A. Zeeb
f4aa407e89 LinuxKPI: 802.11: CONFIG_PM_SLEEP / WoWLAN header adjustments
Sort out some (though not yet all) changes needed for CONFIG_PM_SLEEP
and respectively WoWLAN support (so we can compile it in).  This is
just one further step towards proper suspend/resume support.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit b42c339c59fd00f2d97f6854b17b54b340019d0c)
2025-04-18 14:36:00 +00:00
Bjoern A. Zeeb
64ec6ddac0 LinuxKPI: 802.11: crypto pn lengths
Define the last missing PN length and for consistency use them
in struct ieee80211_key_seq (even though a 6 is a 6 is a 6).

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit c8a6676eb652b59fee545dc3e24ffec21bd0cd8d)
2025-04-18 14:36:00 +00:00
Bjoern A. Zeeb
719721ca4b LinuxKPI: add seq_hex_dump()
Move the implementation of print_hex_dump() into linux_compat.c as
lkpi_hex_dump() taking an extra function pointer and argument.
Add two internal wrappers for printf and sbuf_printf to get a common
function definition (sbuf_printf takes the extra argument).

Use these to implement print_hex_dump() and the newly added
seq_hex_dump().

This allows us to re-use the same implementation of print_hex_dump()
for both functions without duplicating the code.

Initial implementation:	D49381 by dumbbell
Sponsored by:	The FreeBSD Foundation
Reviewed by:	dumbbell
Differential Revision: https://reviews.freebsd.org/D49637

(cherry picked from commit 4359672e656af5e6758d0aae147212e58f445f5b)
2025-04-18 14:35:58 +00:00
Bjoern A. Zeeb
ebe210ca70 LinuxKPI; cleanup slab.h a bit; move more free() into slab.c
Move kfree() into slab.c as an implementation and hide the private
function linux_kfree_async() entirely.

Remove a ; at the end of a define and sort some defines into place.

Remove extern from function declarations and move the closer to where
they belong.

Sort the functions into "base allocator/free" functions--these have
an implementation in slab.c and are ensuring contiguous physical
memory allocations.

Followed by inline functions using these base allocators to implement
their functionality; vmalloc/kvalloc, and misc functions.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	dumbbell
Differential Revision: https://reviews.freebsd.org/D49572

(cherry picked from commit a3e6f97bf57c1d323487d07369aec66542f995ce)
2025-04-18 14:35:58 +00:00
Bjoern A. Zeeb
516eb937b2 LinuxKPI: implement krealloc() for memory being contiguous
Implement krealloc_array() using krealloc().  Implement krealloc()
doing the various size checks ourselves and use realloc() or kmalloc()
depending on old and new allocation sizes.
This way we can ensure that allocated memory stays physically contiguous.

Sponsored by:	The FreeBSD Foundation
Suggested by:	jhb (see D46657)
Reviewed by:	jhb, markj
Differential Revision: https://reviews.freebsd.org/D49571

(cherry picked from commit 1c95d401ebe5075ebb38b57638830713a496f107)
2025-04-18 14:35:58 +00:00
Bjoern A. Zeeb
3404752d55 LinuxKPI: switch mallocarray to an lkpi implementation using __kmalloc()
With mallocarray() we cannot guarantee that any size larger than
PAGE_SIZE will be contiguous.  Switch kmalloc_array() and
kmalloc_array_node() to use __kmalloc()/lkpi___kmalloc_node() as their
underlying implementation which now does provide that guarantee.
Likewise adjust kcalloc_node() to use kmalloc_array_node().
This means we only have two (plain + _node) underlying allocation
routines for the entire category of functions.

Also adjust kvmalloc() and kvmalloc_array() to be a "mirrored"
implementation to their non-v counterparts. These may return
non-contiguous memory so can use malloc().

Sponsored by:	The FreeBSD Foundation
Reviewed by:	jhb
Extra thanks to: jhb for helping sorting this out
Differential Revision: https://reviews.freebsd.org/D46657

(cherry picked from commit 1c81ebec74d8a71c770f7835d3bc6e02c13467a0)
2025-04-18 14:35:57 +00:00
Mathieu
831e6fb0ba
LinuxKPI: make linux_alloc_pages() honor __GFP_NORETRY
This is to fix slowdowns with drm-kmod that get worse over time as
physical memory become more fragmented (and probably also depending on
other factors).

Based on information posted in this bug report:
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=277476

By default, linux_alloc_pages() retries failed allocations by calling
vm_page_reclaim_contig() to attempt to free contiguous physical memory
pages. vm_page_reclaim_contig() does not always succeed and calling it
can be very slow even when it fails. When physical memory is very
fragmented, vm_page_reclaim_contig() can end up being called (and
failing) after every allocation attempt. This could cause very
noticeable graphical desktop hangs (which could last seconds).

The drm-kmod code in question attempts to allocate multiple contiguous
pages at once but does not actually require them to be contiguous. It
can fallback to doing multiple smaller allocations when larger
allocations fail. It passes alloc_pages() the __GFP_NORETRY flag in this
case.

This patch makes linux_alloc_pages() fail early (without retrying) when
this flag is passed.

[olce: The problem this patch fixes is longer and longer GUI freezes as
a machine's memory gets filled and becomes fragmented, when using amdgpu
from DRM kmod 5.15 and DRM kmod 6.1 (DRM kmod 5.10 is unaffected; newer
Linux kernel introduced an "optimization" by which a pool of pages is
filled preferentially with contiguous pages, which triggered the problem
for us).  The original commit message above evokes freezes lasting
seconds, but I occasionally witnessed some lasting tens of minutes,
rendering a machine completely useless.

The patch has been reviewed for its potential impacts to other LinuxKPI
parts and our existing DRM kmods' code.  In particular, there is no
other user of __GFP_NORETRY/GFP_NORETRY with Linux's alloc_pages*()
functions in our tree or DRM kmod ports.

It has also been tested extensively, by me for months against 14-STABLE
and sporadically on -CURRENT on a RX580, and by several others as
reported below and as is visible in more details in the quoted bugzilla
PR and in the initial drm-kmod issue at
https://github.com/freebsd/drm-kmod/issues/302, on a variety of other
AMD GPUs (several RX580, RX570, Radeon Pro WX5100, Green Sardine 5600G,
Ryzen 9 4900H with embedded Renoir).]

PR:             277476
Reported by:    Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
Reviewed by:    olce
Tested by:      many (olce, Pierre Pronchery, Evgenii Khramtsov, chaplina, rk)
MFC after:      2 weeks
Relnotes:       yes
Sponsored by:   The FreeBSD Foundation (review and part of testing)

(cherry picked from commit 718d1928f8748fe4429c011296f94f194d63c695)
2025-04-08 15:38:29 +02:00
Lutz Bichler
872c817d52 linuxkpi: Correct DIV_ROUND_DOWN_ULL
This fixes a black screen issue with the i915 DRM driver from Linux v6.8

Fixes: c4e0746e7d ("LinuxKPI: Add helper macros IS_ALIGNED and DIV_ROUND_DOWN_ULL.")
Pull request: https://github.com/freebsd/freebsd-src/pull/1612

(cherry picked from commit ef037a028af7cc331e36ca6c8e2eb5612cdb1130)
2025-03-18 09:27:37 -04:00
Bjoern A. Zeeb
e00588ed9c LinuxKPI: skbuff: add synchronization primitives and missing bits
Make a pass over skbuff.h:
- implement some missing bits,
- sprinkle some const,
- add locking and read/write_once calls as needed to provide
  synchronization as expected by Linux,
- fix some typos,
- remove return from void functions,
- adjust tracing macros.

Sponsored by:	The FreeBSD Foundation
PR:		283903 (rtw88 skb leak)
Tested by:	Guillaume Outters (guillaume-freebsd outters.eu)
Tested by:	oleg.nauman gmail.com
Differential Revision: https://reviews.freebsd.org/D49101

(cherry picked from commit 2ab4a41956159e7c974979693cb0b13cf552128e)
2025-02-26 02:39:41 +00:00
Bjoern A. Zeeb
c1895bd9c0 LinuxKPI: 802.11: improve cfg80211_chandef_create()
Implement cfg80211_chandef_create() to work with HT.  Update enum
with HT channel types.  When calling the function from LinuxKPI 802.11
code, pass in NL80211_CHAN_HT20 if HT is supported rather than NO_HT.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 11450726d3cf8d76d2113d7cabe995f8ef31ec5a)
2025-02-26 02:39:13 +00:00
Bjoern A. Zeeb
a960f6e717 LinuxKPI: 802.11: dump station_info using (*sta_statistics)() as sysctl
Implement the mac80211 (*sta_statistics) to obtain station statistics.
Fix up struct station_info for that.
Add supporting funtions to decode station_info and rate_info_bw fields
to make the output more usable to human beings.

Add a per-VIF (VAP) sysctl to export that information.  This is mostly
used for now to see what the driver/fw thinks about its TX rate.
We should later gather this information in different ways and pass it
to net80211 to export it to user space so we can finally have nice
station information (also for the non-AP side).

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 408394185fe9be0c158189b7671bde316ac14ac9)
2025-02-24 20:26:49 +00:00
Bjoern A. Zeeb
b2999f0227 LinuxKPI: 802.11/skb: add extra information for skb alloc failures
rtw88 seems to have an skb leak still.

Add a WARN_ONCE to __skb_queue_purge() just to make sure there is no
glitch due to missing locking.

Also add a rolling error reporting for skb allocation failures in
LinuxKPI to gather some more information if possible about queue
states.

This is a corrected version of what was initially part of D48474.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit bcf1d8ee355213eef4a125c0b8518f1cb4f35df4)
(cherry picked from commit 1432e0f20ccde8eaa23d3d3e20fca2989cd344b6)
2025-02-24 20:26:49 +00:00
Bjoern A. Zeeb
75418cb419 LinuxKPI: 802.11: make struct ieee80211_tx_info a bit more packed
Given I was looking at the struct make it more packed at the beginning
at least.  In fact it did not shrink but the tx_time_est got expanded.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 470aaf42c3c0661821a8744ae7c29b096adb4aa3)
2025-02-24 20:26:48 +00:00
Bjoern A. Zeeb
6b244c7666 LinuxKPI: 802.11: fill in a lot more RX status fields
Convert a lot more LinuxKPI rx_status fields to net80211 rx_stats
bits for as much as we can see fit.  Factor the entire logic out
into its own function as it got quite long.

Now only net80211 needs to start using more of these values and
report them.

Also fix some related fields and struct definitions in LinuxKPI.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 49010ba706d39fba0d8bc128d96e6122e65eb8ad)
2025-02-24 20:26:48 +00:00
Bjoern A. Zeeb
b3c037c2bc net80211 / LinuxKPI 802.11: add 802.11-2016 VHT Extended NSS BW defines
Add the mask and shift for the VHT Extended NSS BW Support field.
Document them in net80211 and further related bitmasks in LinuxKPI.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	adrian
Differential Revision: https://reviews.freebsd.org/D48975

(cherry picked from commit 75fb66d8241d0487baf482c975c1de3b55d9a315)
2025-02-24 20:26:47 +00:00
Bjoern A. Zeeb
c5978cd3e4 net80211 / LinuxKPI 802.11: use enum ieee80211_sta_rx_bw for ni_chw
net80211 node ni_chw currently encodes the channel width as Mhz number.
LinuxKPI 802.11 uses enum ieee80211_sta_rx_bw for the same.

Rather than keeping the "20" and "40" throughout the code (eventually
expanded to 80/160/320) switch them over to use the enum throughout.

Once we get to 320Mhz channel widths we would otherwise also need to
extend the uint8_t in struct ieee80211_node; making
enum ieee80211_sta_rx_bw __packed allows us for lots more channel
widths without breaking the KBI.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	adrian
Differential Revision: https://reviews.freebsd.org/D47891

(cherry picked from commit ca389486a9599768e0ba69dca13c208020623083)
(cherry picked from commit 2c8b0d6205f6f98855773e3a82640b50abb2f2f6)
2025-02-10 14:52:08 +00:00
Doug Moore
6f309b9d56 log2: move log2 functions from linuxkpi to libkern
Linux has a header file that defines an ilog2 function and some simple
functions/macros that use it: roundup_pow_of_two, is_power_of_2,
rounddown_pow_of_two, and order_base_2.  This change moves three of
those simple functions (all but is_power_of_2) from linuxkpi to
libkern.  It also deletes a few implementations of these functions
that have previously been copied into code for various device drivers,
so that they can use the libkern version.  The is_power_of_2 macro was
not moved because powerof2 in param.h provides almost the same service
already (except that they disagree about whether 0 is a power of two).

Since the linux definitions of these functions were copied into
FreeBSD 11 years ago, linux has improved them, and this change
provides those improvements.  In particular, a giant table of log
values for evaluating ilog2 for constant values is no longer
necessary.

Reviewed by:	alc, markj (previous version)
Differential Revision:	https://reviews.freebsd.org/D45536

(cherry picked from commit c8b0c33b03ac072413b27bed2bdae2ae27426f3a)
2025-02-10 04:29:23 -06:00
Doug Moore
4ed1837853 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

(cherry picked from commit b0056b31e90029553894d17c441cbb2c06d31412)
2025-02-10 04:27:12 -06:00
Olivier Certner
11dde2c8b7
atomics: Constify loads: Remove now superfluous uses of DECONST()
No functional change (intended).

Reviewed by:    kib
MFC after:      4 days
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D48497

(cherry picked from commit 9b7157c690723279d448fc7ea9c1f9374ad4511a)
2025-01-27 19:19:57 +01:00
Mark Johnston
48155c983c kern: Make fileops and filterops tables const where possible
No functional change intended.

MFC after:	1 week

(cherry picked from commit ef9ffb8594eee294334ced627755bf5b46b48f9f)
2024-12-03 01:03:42 +00:00
Austin Shafer
d95675349a 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

(cherry picked from commit 28a59100b54ff245a45fbd328266266f1c14eb8c)
2024-11-30 08:55:57 -05:00