Commit graph

663 commits

Author SHA1 Message Date
Bjoern A. Zeeb
f8612fa7e0 LinuxKPI: add 802.11 compat code
Add 802.11 compat code for mac80211 and to a minimal degree cfg80211.
This allows us to compile and use basic functionality of wireless
drivers such as iwlwifi.

This is a constant work in progress but having it in the tree will
allow others to test and more easy to track changes and avoid having
snapshots no longer applying to branches.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 6b4cac814e)
2021-12-30 18:27:45 +00:00
Bjoern A. Zeeb
fb3c236a4b LinuxKPI: import beginning of a new version of netdevice.h
Import a netdevice update complementing the last remaining bits of
the old ifnet derived implementation.  Along add a (for now) task
based NAPI implementation.

This is the minimal set of chnages which are needed for the initial
support of wireless drivers.  The NAPI implementation has an option to
still switch to "direct dispatch" as it had been used by these drivers
before not relying on a deferred context along with some printf tracing.
This has been helpful in the last weeks for debugging and will be
cleaned once we have had broader testing and are sure this is fine as-is.
Should we need a more time-sensitive or load-sensitive response
in the future we can always switch to something more sophisticated.

Sponsored by:		The FreeBSD Foundation
X-Differential Revision: D33075 (abandoned without feedback a while ago)

(cherry picked from commit d105895844)
2021-12-30 18:27:31 +00:00
Bjoern A. Zeeb
508c4fb4c3 LinuxKPI: add a work-in-progress skbuff implementation
This is a work-in-progress implementation of sk_buff compat code
used for wireless drivers only currently.
Bring in this version of the code as it has proven to be good enough
to have packets going for a few months.

The current implementation has several drawbacks including the need
for us to copy data between sk_buffs and mbufs.
Do not rely on the internals of this implementation.  They are highly
likely to change as we will improve the integration to FreeBSD mbufs.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 49ed6e979c)
2021-12-30 18:27:19 +00:00
Bjoern A. Zeeb
a34668185b modules: increase MAXMODNAME and provide backward compat
With various firmware files used by graphics and wireless drivers
we are exceeding the current 32 character module name (file path
in kldxref) length.
In order to overcome this issue bump it to the maximum path length
for the next version.
To be able to MFC provide backward compat support for another version
of the struct as the offsets for the second half change due to the
array size increase.

MAXMODNAME being defined to MAXPATHLEN needs param.h to be
included first.  With only 7 modules (or LinuxKPI module.h) not
doing that adjust them rather than including param.h in module.h [1].

Reported by:	Greg V (greg unrelenting.technology)
Sponsored by:	The FreeBSD Foundation
Suggested by:	imp [1]
Reviewed by:	imp (and others to different level)
Differential Revision:	https://reviews.freebsd.org/D32383

(cherry picked from commit df38ada293)
2021-12-30 18:26:18 +00:00
Bjoern A. Zeeb
111619ff70 LinuxKPI: add bcd.h
Add bcd2bin() in bcd.h.

Libkern does provide a bcd2bin() which cannot be used cirectly leaving
us with a conflict (see comment in file).
Rather than having code to re-define bcd2bin() for the LinuxKPI
make sure libkern.h is always included before the LinuxKPI version.
Then only re-define our local LinuxKPI implementation.  [1]
From the argument truncating wrapper call the libkern version.
If we change our libkern implementation in the future we can save
us the remainder of the hassle. [2].

Suggested by:	Johannes Berg (johannes sipsolutions.net) [1]
Suggested by:	ian [2]
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 548ada00e5)
(cherry picked from commit ae2268efd5)
2021-11-21 18:15:58 +00:00
Bjoern A. Zeeb
9d2d8a27d0 LinuxKPI: add strreplace() to string.h
Add strreplace() needed by a driver.

(cherry picked from commit a5e2a27dca)
2021-11-19 00:01:26 +00:00
Bjoern A. Zeeb
4459c16279 LinuxKPI: add kstrtou8() and kstrtou8_from_user() to kernel.h
Analogous to the other sized version of kstrto[u]<type>() and
kstrtobool_from_user() add the "u8" versions needed by a driver.

(cherry picked from commit b382b78503)
2021-11-19 00:01:26 +00:00
Bjoern A. Zeeb
a6a1ab040f LinuxKPI: add simple_open() to fs.h
Add a dummy simple_open() to fs.h as we have for other
(unsupported) functions.
This is needed by a wireless driver.

(cherry picked from commit 41dee251ee)
2021-11-19 00:01:26 +00:00
Bjoern A. Zeeb
009e6b6e71 LinuxKPI: module.h add MODULE_SUPPORTED_DEVICE()
Add a dummy MODULE_SUPPORTED_DEVICE define as we do for other
MODULE_* macros.  This is needed by a wireless driver.

(cherry picked from commit c5eec7b57c)
2021-11-19 00:01:26 +00:00
Bjoern A. Zeeb
c7fc9ca779 LinuxKPI: pci.h make pci_dev argument const for pci_{read,write}_config*()
Make the struct pci_dev argument to the pci_{read,write}_config*()
functions "const" to match the Linux definition as some drivers
try to pass in a const argument which we currently fail to honor.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit ed5600f532)
2021-11-19 00:01:26 +00:00
Bjoern A. Zeeb
dc70c937b1 LinuxKPI: pci.h / linux_pci.c rename pci_driver field
Rename the struct pci_driver {} field to the list_head from links
to node as a driver is actually initialsing this to {} which seems
questionable but it will at least make us match the Linux structure
field name.

Reviewed by:	manu, hselasky

(cherry picked from commit cf89934842)
2021-11-19 00:01:26 +00:00
Bjoern A. Zeeb
aaf3364151 LinuxKPI: add netdev_features.h
Add netdev_features.h as a spearate file from the future netdevice.h
implementation to avoid include problems with a future skbuff.h.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 490f9d8f0e)
2021-11-19 00:01:25 +00:00
Bjoern A. Zeeb
37b2cf4e6a LinuxKPI: implement dma_set_coherent_mask()
Coherent is lower 32bit only by default in Linux and our only default
dma mask is 64bit currently which violates expectations unless
dma_set_coherent_mask() was called explicitly with a different mask.

Implement coherent by creating a second tag, and storing the tags in the
objects and use the tag from the object wherever possible.
This currently does not update the scatterlist or pool (both could be
converted but S/G cannot be MFCed as easily).

There is a 2nd change embedded in the updated logic of
linux_dma_alloc_coherent() to always zero the allocation as
otherwise some drivers get cranky on uninialised garbage.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit c39eefe715)
(cherry picked from commit 1269873159)
2021-11-19 00:01:24 +00:00
Bjoern A. Zeeb
d005c4c6de LinuxKPI: dma-mapping.h unify "mask" and "dma_mask"
In some places we are using "mask" and others "dma_mask" for the
same thing.  Harmonize the various places to "dma_mask" as used in
linux_pci.c.  For the declaration remove the argument names to
avoid the entire problem.

This is in preparation for an upcoming change.
No functional changes intended.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 72c89ce97b)
2021-11-19 00:01:24 +00:00
Bjoern A. Zeeb
870e31d839 LinuxKPI: disable device_release_driver()
As reported by multiple people testing iwlwifi, device_release_driver()
can lead to a panic on secondary errors (usually during attach).
Disable device_release_driver() for the short-term to prevent the panic
but leave it in place so it can be re-worked and fixed properly for
the long-term more easily.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 93b14194ac)
2021-11-19 00:01:24 +00:00
Bjoern A. Zeeb
20c9dcd2ed LinuxKPI: add fsleep()
Add fsleep() function now required by rtw88.  This seems to be
making a decision depending on time to sleep on how to sleep.
Given our compat framework already is lenient on how long to sleep,
this is a cut down version.

(cherry picked from commit cc2723370b)
2021-11-19 00:01:23 +00:00
Bjoern A. Zeeb
9342ec5077 LinuxKPI: add read_poll_timeout()
Add an implementation of read_poll_timeout() and the atomic variant
which I did at some point last year for rtw88 and now updated based
on feedback.

(cherry picked from commit fed248a6ac)
2021-11-19 00:01:23 +00:00
Bjoern A. Zeeb
4c8e296374 LinuxKPI: add module_pci_driver() and pci_alloc_irq_vectors()
Add the two new functions needed by rtw88 to register the driver and
handle the module bits as well as a version of pci_alloc_irq_vectors()
for what is needed.

(cherry picked from commit 366d68f283)
2021-11-19 00:01:23 +00:00
Bjoern A. Zeeb
034475d66c LinuxKPI: add sign_extend32()
Add sign_extend32() replicating the 64 version.  This is needed by
the rtw88 driver.

(cherry picked from commit ea4dea8394)
2021-11-19 00:01:23 +00:00
Bjoern A. Zeeb
3ce981ee8e LinuxKPI: fix bug in le32p_replace_bits()
Fix a bug that slipped in in 90707c4e44
using the correct field in le32p_replace_bits().

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 22e20d852f)
2021-11-19 00:01:23 +00:00
Bjoern A. Zeeb
2314243b4a LinuxKPI: bitfield.h cleanup
Add a missing tab and remove an unnecessary return.
No functional changes.

(cherry picked from commit 4c8af633d1)
2021-11-19 00:01:23 +00:00
Bjoern A. Zeeb
e41baaefc4 LinuxKPI: dmi.h do not rely on implicit includes
Add sys/types.h to dmi.h and do not rely on other files to include
all needed headers in Linux land.  I ran into compile problems with
rtw88 otherwise.

(cherry picked from commit ac134e762e)
2021-11-19 00:01:22 +00:00
Bjoern A. Zeeb
79bc96d1fb LinuxKPI: add nexthdr definitions for IPv6
Add the nexthdr definitions for IPv6 which are used by wireless
drivers and were previously placed in an 80211 header file by
accident.

Obtained from:	bz_iwlwifi
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit b9d984e2c5)
2021-11-19 00:01:22 +00:00
Hans Petter Selasky
8ababf739a LinuxKPI: Add sysctl(8) knob to control verbosity of WARN_ON's.
The purpose of this change is to reduce the amount of dmesg(8) noise when
VT switching after a panic.

Submitted by:	Greg V <greg@unrelenting.technology>
Differential Revision:	https://reviews.freebsd.org/D30174
Sponsored by:	NVIDIA Networking

(cherry picked from commit 2390a1441e)
2021-11-12 15:31:24 +01:00
Jessica Clarke
fa82e6a103 LinuxKPI: Support lazy BAR allocation
Linux KPIs like pci_resource_start/len assume that BARs have been
allocated, but FreeBSD lazily allocates BARs if it cannot allocate the
firmware-allocated BARs. Thus using the Linux KPIs must force allocation
of the BARs rather than returning 0 for the start and length, which can
crash drm-kmod drivers that assume the BARs are valid. This is needed
for the AMDGPU driver to be able to attach on SiFive's HiFive Unmatched.

Reviewed by:	hselasky, jhb, mav
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D32447

(cherry picked from commit 82098c8bb5)
2021-10-24 19:51:15 +01:00
Jessica Clarke
feb3031f0a LinuxKPI: Implement _ioremap_attr for riscv
Now that riscv implements pmap_mapdev_attr we can enable the non-stub
implementation for riscv, which is needed for drm-kmod to not fail at
run time for drivers that need to map I/O regions.

Reviewed by:	hselasky, bz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D32446

(cherry picked from commit 60d962e041)
2021-10-24 19:51:12 +01:00
Vladimir Kondratyev
e1f5bed753 LinuxKPI: Import linux_page.c and some dependent code from drm-kmod
No functional changes intended

Reviewed by:	hselasky, manu, markj
Differential revision:  https://reviews.freebsd.org/D32167

(cherry picked from commit c072f6e856)
2021-10-13 12:07:53 +03:00
Vladimir Kondratyev
c6fb23b292 LinuxKPI: Update pte_fn_t definition to match Linux 5.3
Reviewed by:	emaste, hselasky, manu
Differential revision:	https://reviews.freebsd.org/D32166

(cherry picked from commit 88531adbfb)
2021-10-13 12:07:24 +03:00
Vladimir Kondratyev
9441d948aa LinuxKPI: Implement backlight_enable and backlight_disable functions
For now, disable backlight if brightness level is set to 0.
In the future we may implement separate knob in backlight(8).

Required by drm-kmod v5.6

Reviewed by:	hselasky, manu
Differential revision:	https://reviews.freebsd.org/D32165

(cherry picked from commit b52e363840)
2021-10-13 12:06:51 +03:00
Vladimir Kondratyev
f2a3116ab4 LinuxKPI: Add dummy pgprot_decrypted() implementation
to reduce number of #ifdefs in drm-kmod

Reviewed by:	hselasky
Differential revision:	https://reviews.freebsd.org/D32094

(cherry picked from commit 3d86f8f1d7)
2021-10-13 12:05:38 +03:00
Vladimir Kondratyev
8cf87dd59f LinuxKPI: Cast offset_in_page() parameter to unsigned long
to reduce number of patches in drm-kmod

Reviewed by:	hselasky
Differential revision:	https://reviews.freebsd.org/D32093

(cherry picked from commit 37eba5b77a)
2021-10-13 12:04:58 +03:00
Vladimir Kondratyev
0ed3a19a38 LinuxKPI: Import linux/poison.h header
Required by drm-kmod 5.6

Reviewed by:	hselasky, imp, manu
Obtained from:	OpenBSD
Differential revision:	https://reviews.freebsd.org/D32092

(cherry picked from commit 6efabdeede)
2021-10-13 12:04:11 +03:00
Vladimir Kondratyev
7db428f0bb LinuxKPI: Add helper functions to store integers to linux/xarray.h
Required by drm-kmod.

Reviewed by:	hselasky
Differential revision:	https://reviews.freebsd.org/D32091

(cherry picked from commit b59ffedae8)
2021-10-13 12:03:29 +03:00
Vladimir Kondratyev
4fba1853b5 LinuxKPI: stub anon_inode_getfile
Although drm-kmod contains better implementation which is able to
allocate real entries on pseudofs, this feature has never been used.

Starting from drm-kmod v5.6 old implementation began to leak entries
on each drm device close(). Now just drop pseudofs support instead of
fixing it in drm-kmod and provide stub in base.

Reviewed by:	hselasky, manu
Differential revision:	https://reviews.freebsd.org/D32069

(cherry picked from commit bd6d55adb4)
2021-10-13 12:02:17 +03:00
Vladimir Kondratyev
847ffc18dd LinuxKPI: Factor out vmf_insert_pfn_prot() routine
from GEM and TTM page fault handlers and move it in to base system. This
code is tightly integrated with LKPI mmap support to belong to drm-kmod.

As this routine requires associated vm_object to be locked, it got
additional _locked suffix.

Reviewed by:	hselasky, markj
Differential revision:	https://reviews.freebsd.org/D32068

(cherry picked from commit f6823dac8f)
2021-10-13 12:01:32 +03:00
Vladimir Kondratyev
2c26756366 LinuxKPI: implement _IOC_TYPE and _IOC_NR macros in linux/ioctl.h
They are used by drm-kmod

Reviewed by:	emaste, hselasky, manu
Differential revision:	https://reviews.freebsd.org/D31674

(cherry picked from commit b58c916f11)
2021-10-13 11:59:25 +03:00
Vladimir Kondratyev
fd6adf784e LinuxKPI: Remove FreeBSD struct resource from all LKPI headers
except linux/pci.h to avoid conflicts with Linux version.
This allows to #define resource in drm-kmod globally and strip some #ifdef-s

Reviewed by:	hselasky, manu
Differential revision:	https://reviews.freebsd.org/D31673

(cherry picked from commit 66ea390652)
2021-10-13 11:58:39 +03:00
Vladimir Kondratyev
a029968046 LinuxKPI: Implement get_file_rcu()
get_file_rcu() grabs a file if the file->f_count is not zero.

Required by drm-kmod 5.6

Reviewed by:	hselasky, manu (previous version)
Differential revision:	https://reviews.freebsd.org/D31672

(cherry picked from commit a81b36c6d3)
2021-10-13 11:57:46 +03:00
Jessica Clarke
e79989d823 LinuxKPI: Add more #ifdef VM_MEMATTR_WRITE_COMBINING guards
One of the three uses is already guarded; this guards the remaining ones
to support architectures like riscv that do not provide write-combining,
and is needed to build drm-kmod on riscv.

Reviewed by:	hselasky, manu
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D31999

(cherry picked from commit 8167c92f65)
2021-10-10 14:36:53 +01:00
Warner Losh
0437d10e35 direct commit: fix KBI for pci_dev
Move all the new elemenets to the end of the structure for 13. We
allocate this inside the linuxkpi code, so the size isn't enccoded in
client modules. However, the offsets to the different fields are
encoded. Tihs modifies 04456f7118, 40a215e38a, and 3a606aadf2
and will likely create merge conflicts there (and that's a good thing
since the elements need to be moved to the end of the structure when
merging).

Tweak irq_ent to be binary compatible. Since this is inlined into the
clients, all clients have to agree on the irq_ent offsets.

Restore visibility to linux_kmem_cache_free_rcu
linux_kmem_cache_free_rcu was made static in 10235ad056, however
client drivers depended on calling it directly. Make it visible again to
restore the 13.0-Release KBI for linuxkpi.

Bump FreeBSD_version to 1300515 for restoration of 13.0 KBI. Since this
commmit changes the linuxkpi KBI (this time back to 13.0 release to
restore the status quo of), you'll need to recompile everything that
uses it (you needed to earlier as well, but those were silent
recompilation events). The plus side is that our packages (built using
13.0) for drm-kmod 5.4 work again on -stable systems.

Reviewed by:		bz, wulf
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D31363
2021-09-22 09:00:16 -06:00
Vladimir Kondratyev
801a4bcab6 LinuxKPI: Implement sequence counters and sequential locks
as a thin wrapper around native version found in sys/seqc.h.
This replaces out-of-base GPLv2-licensed code used by drm-kmod.

Reviewed by:	hselasky
Differential revision:	https://reviews.freebsd.org/D31006

(cherry picked from commit 8b33cb8303)
2021-07-21 01:43:52 +03:00
Vladimir Kondratyev
22310af02d LinuxKPI: Implement strscpy
strscpy copies the src string, or as much of it as fits, into the dst
buffer.  The dst buffer is always NUL terminated, unless it's zero-sized.
strscpy returns the number of characters copied (not including the
trailing NUL) or -E2BIG if len is 0 or src was truncated.

Currently drm-kmod replaces strscpy with strncpy that is not quite
correct as strncpy does not NUL-terminate truncated strings and returns
different values on exit.

Reviewed by:	hselasky, imp, manu
Differential revision:	https://reviews.freebsd.org/D31005

(cherry picked from commit 019391bf85)
2021-07-21 01:43:52 +03:00
Vladimir Kondratyev
80b8638e12 LinuxKPI: Use macro for implementation of some dma_map_* functions
This allows to remove unimplemented attrs parameter which type differs
between Linux kernel versions and to compile both drm-kmod and ofed
callers unmodified.
Also convert it to 'unsigned long' type to match modern Linuxes.

Reviewed by:	hselasky
Differential revision:	https://reviews.freebsd.org/D30932

(cherry picked from commit 98a6984a9e)
2021-07-21 01:43:52 +03:00
Vladimir Kondratyev
907f980064 LinuxKPI: Implement irq_work_sync() routine.
irq_work_sync() performs draining of irq_work task.
Required by drm-kmod.

Reviewed by:	hselasky
Differential revision:	https://reviews.freebsd.org/D30818

(cherry picked from commit 864b11007a)
2021-07-21 01:43:52 +03:00
Vladimir Kondratyev
ddebb8c0f7 LinuxKPI: Add compiler barriers to list_for_each_entry_lockless macro
so this list-traversal primitive may safely run concurrently with the
_rcu list-mutation primitives such as list_add_rcu() as long as the
traversal is guarded by rcu_read_lock().

Do it by reusing the "list_for_each_entry_rcu" macro which does the same.
On Linux it implements some additional lockdep stuff which we skip.

Also move the macro to linux/rculist.h where it resides on Linux.

Reviewed by:	hselasky
Differential revision:	https://reviews.freebsd.org/D30795

(cherry picked from commit c0862b2b1f)
2021-07-21 01:43:52 +03:00
Vladimir Kondratyev
71d815861f LinuxKPI: Change flags parameter type of atomic_dec_and_lock_irqsave
On Linux atomic_dec_and_lock_irqsave is a wrapper macro which provides
a reference to third parameter rather than parameter value itself to
implementation routine called _atomic_dec_and_lock_irqsave [1].

While here, implement a fast path.

[1] https://github.com/torvalds/linux/blob/master/include/linux/spinlock.h#L476

Reviewed by:	hselasky
Differential revision:	https://reviews.freebsd.org/D30781

(cherry picked from commit c77ec79b57)
2021-07-21 01:43:52 +03:00
Vladimir Kondratyev
6279188417 LinuxKPI: Add #defines required by drm-kmod v5.5
Reviewed by:	hselasky, manu
Differential revision:	https://reviews.freebsd.org/D30767

(cherry picked from commit 78a02d8b33)
2021-07-21 01:43:52 +03:00
Vladimir Kondratyev
10235ad056 LinuxKPI: Allow kmem_cache_free() to be called from critical sections
as it is required by i915kms driver from Linux kernel v 5.5.
This is done with asynchronous freeing of requested memory areas from
taskqueue thread. As memory to be freed is reused to store linked list
entry, backing UMA zone item size is rounded up to pointer size.

While here, make struct linux_kmem_cache private to LKPI to reduce amount
of BSD headers included by linux/slab.h and switch RCU code to usage of
LKPI's linux_irq_work_tq taskqueue to avoid injection of current into
system-wide taskqueue_fast thread context.

Submitted by:	nc (initial version for drm-kmod)
Reviewed by:	manu, nc
Differential revision:	https://reviews.freebsd.org/D30760

(cherry picked from commit a2b83b59db)
2021-07-21 01:43:52 +03:00
Neel Chauhan
511bbe502e linuxkpi: Add spin_trylock_irqsave() macro
This is needed by the drm-kmod 5.6 update.

Reviewed by:		hselasky
Differential Revision:	https://reviews.freebsd.org/D30706

(cherry picked from commit 086cfe4df8)
2021-07-17 18:08:06 -07:00
Bjoern A. Zeeb
f9fa2908cf LinuxKPI: avoid userret: Returning with with pinned thread
Some code manually calls local_bh_disable() and spin_lock() but
then calls spin_unlock_bh() (or vice versa).
Our code then calls local_bh_disable() again from spin_lock()
which means we have the thread pin count increased twice and that
means we get out of synch and are still pinned when returning to
user space.

Avoid this by adding the explicit local_bh_{enable,disable}() to
the spin_[un]lock_bh() versions.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	hselasky
Differential Revision: https://reviews.freebsd.org/D30711

(cherry picked from commit 46ae23a402)
2021-07-18 00:35:04 +00:00