Commit Graph

4752 Commits

Author SHA1 Message Date
Bjoern A. Zeeb
a3baca22d0 LinuxKPI: 802.11: fix types and whitespace
Correct struct member types, fix whitespace, and remove superfluous
return statements in void functions.

No functional changes.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2023-01-31 13:39:04 +00:00
Jean-Sébastien Pédron
b9ef068943
linuxkpi: Define dev_is_platform() and to_platform_device()
The former returns false and the latter returns NULL.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38163
2023-01-30 23:10:03 +01:00
Jean-Sébastien Pédron
11aaefc9ca
linuxkpi: Try to solve headers dependencies
I'm sure I got it wrong but at least the DRM drivers compile.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38157
2023-01-30 23:09:52 +01:00
Jean-Sébastien Pédron
29d0c85c86
linuxkpi: Add io_mapping_map_local_wc() and io_mapping_unmap_local()
`io_mapping_map_local_wc()` is synonymous to `io_mapping_map_atomic_wc()`.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38156
2023-01-30 23:09:38 +01:00
Jean-Sébastien Pédron
9dafbd0c69
linuxkpi: Add kmap_local_page_prot() and kunmap_local()
They are synonymous to `kmap_atomic_prot()` and `kunmap_atomic()`
respectively.

While here, fix several style(9) issues.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38155
2023-01-30 23:09:22 +01:00
Jean-Sébastien Pédron
7649b89cc1
linuxkpi: Add <linux/pgtable.h>
For now, it's empty. It is included by the DRM drivers but nothing is
missing otherwise. Perhaps something we already defined should be in
`pgtable.h` instead of another header.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38153
2023-01-30 23:09:13 +01:00
Jean-Sébastien Pédron
25faccaaca
linuxkpi: Add <linux/limits.h>
For now, it's empty. It is included by the DRM drivers but nothing is
missing otherwise. Perhaps something we already defined should be in
`limits.h` instead of another header.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38147
2023-01-30 23:08:59 +01:00
Jean-Sébastien Pédron
19be627cfd
linuxkpi: Define might_alloc()
... as a no-op.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38146
2023-01-30 23:08:45 +01:00
Jean-Sébastien Pédron
e400b69599
linuxkpi: Add freeram and freehigh to struct sysinfo
The struct layout is modified with this commit because new fields are
added in the middle, keeping original Linux order.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D37932
2023-01-30 23:08:32 +01:00
Bjoern A. Zeeb
dbbf46ebba LinuxKPI: skbuff: implement skb_free_frag()
Using the work from 55038a6306 implement
skb_free_frag() calling page_frag_free().

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2023-01-28 15:33:12 +00:00
Dmitry Chagin
9922bccbc9 linux(4): Convert mount exported flags for statfs system calls.
MFC after:		1 week
2023-01-28 13:20:27 +03:00
Dmitry Chagin
953688e823 linux(4): Rework statfs conversion routine.
Rework the routines to convert a native statfs structure (with fixed-size 64-bit
counters) to a Linux statfs structure (with long-sized counters) for 32-bit apps.

Instead of following Linux and return an EOVERFLOW error from statfs() family of
syscalls when actual fs stat value(s) are large enough to not fit into 32 bits,
apply scale logics used by FreeBSD to convert a 5.x statfs structure to a 4.x
statfs structure.

For more details see cc479dda.

Tested by:		glebius
MFC after:		1 week
2023-01-28 13:19:41 +03:00
John Baldwin
4d77927e2a linuxkpi: Use a proper declaration for pm_suspend_via_firmware.
Reported by:	GCC -Wstrict-prototypes
2023-01-27 19:41:35 -08:00
Jean-Sébastien Pédron
3d751b7a71
linuxkpi: Add pin_user_pages*() functions
They were defined in the i915 DRM driver. I move the code in linuxkpi so
it can benefit other drivers.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38078
2023-01-27 21:54:39 +01:00
Jean-Sébastien Pédron
3e0856b63f
linuxkpi: Fix sg_alloc_table_from_pages() to have the same API as Linux
It now returns a `struct scatterlist *` pointer instead of an error
code only.

The implementation is incomplete because it doesn't use the `prv`
argument.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38077
2023-01-27 21:53:59 +01:00
Jean-Sébastien Pédron
8c46bd9f86
linuxkpi: Include linux/sched/mm.h from linux/sched.h
At least one file in the DRM drivers benefits from some namespace
pollution to use `fs_reclaim_acquire()`/`fs_reclaim_release()`. They are
defined in `linux/sched/mm.h` and this header must be included
indirectly into the DRM drivers' source file.

I couldn't find how it was included. Therefore this commit includes
`linux/sched/mm.h` from `linux/sched.h`. This is not the case in Linux
but fixes the issue with the DRM drivers.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D37912
2023-01-27 21:53:44 +01:00
Bjoern A. Zeeb
68b1d16250 LinuxKPI: linux_pci.c: fix whitespace
Properly indent a line.  No functional change.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2023-01-27 15:27:42 +00:00
Bjoern A. Zeeb
0d0ca120a7 LinuxKPI: pci.h move function declaration to top of file.
No functional changes.

X-MFC-with:	49b6d5ed14
Sponsored by:	The FreeBSD Foundation
2023-01-26 14:33:31 +00:00
Jean-Sébastien Pédron
a04aa80e77
lindebugfs: Add debugfs_create_file_size()
This is the same as `debugfs_create_file()` but takes the initial size
of the file. In FreeBSD, the given size is ignored and
`debugfs_create_file()` is called.

Reviewed by:	emaste, manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D37914
2023-01-25 23:23:16 +01:00
Jean-Sébastien Pédron
66cc55a041
linuxkpi: Define PCI_STD_NUM_BARS in <linux/pci.h>
Reviewed by:	emaste, manu
Approved by:	emaste, manu
Differential Revision:	https://reviews.freebsd.org/D38162
2023-01-25 22:57:32 +01:00
Jean-Sébastien Pédron
ccd31b4645
linuxkpi: Define pm_suspend_target_state in <linux/suspend.h>
It is set to `PM_SUSPEND_ON`.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38161
2023-01-25 22:57:21 +01:00
Jean-Sébastien Pédron
4152ce2139
linuxkpi: Add msix_cap to struct pci_dev
At the same time, define `PCI_MSIX_FLAGS`and `PCI_MSIX_FLAGS_ENABLE`.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38160
2023-01-25 22:57:08 +01:00
Jean-Sébastien Pédron
e64afbc215
linuxkpi: Add sysfs_emit_at() in <linux/sysfs.h>
Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38159
2023-01-25 22:56:56 +01:00
Jean-Sébastien Pédron
47877d61af
linuxkpi: Define is_cow_mapping(flags) as false
Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38158
2023-01-25 22:56:40 +01:00
Jean-Sébastien Pédron
3d47e3bf7b
linuxkpi: Include <linux/vmalloc.h> from <linux/pagemap.h>
I'm not sure this is correct, but it gives access to the definition of
`PAGE_KERNEL` in `ttm_tt.c` in the DRM drivers.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38154
2023-01-25 22:50:52 +01:00
Jean-Sébastien Pédron
b34cd67243
linuxkpi: Add seqcount_ww_mutex_t in <linux/seqlock.h>
It is defined as a synonymous to `seqcount_mutex_t`.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38152
2023-01-25 22:50:38 +01:00
Jean-Sébastien Pédron
d9f1cb6774
linuxkpi: Define DEFINE_WD_CLASS(name) in <linux/ww_mutex.h>
It is defined as a synonymous to `DEFINE_WW_CLASS(name)`.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38151
2023-01-25 22:50:27 +01:00
Jean-Sébastien Pédron
04cbeeb597
linuxkpi: Adds more SZ_* macros
`SZ_2K` and `SZ_1G` were defined in irdma. They are removed from this
driver.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38150
2023-01-25 22:50:07 +01:00
Jean-Sébastien Pédron
f27b1399d6
linuxkpi: Define ENOKEY to 126.
This is the same error code as Linux. This value is unused on FreeBSD.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38149
2023-01-25 22:49:53 +01:00
Jean-Sébastien Pédron
49b6d5ed14
linuxkpi: Add pci_device_is_present()
This calls bus_child_present(9) internally.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38148
2023-01-25 22:49:38 +01:00
Jean-Sébastien Pédron
bbff0400c1
linuxkpi: Define dev_dbg_ratelimited()
Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38145
2023-01-25 22:48:32 +01:00
Jean-Sébastien Pédron
9491ea7c68
linuxkpi: Fix atomic_long_sub() overflow
By (ab)using `atomic_long_add_return()`, `atomic_long_sub()` was making
the atomic long overflow. Indeed the underlying FreeBSD atomic is based
on an unsigned long.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38090
2023-01-25 22:26:54 +01:00
Jean-Sébastien Pédron
b99bc86232
linuxkpi: Add io_mapping_map_user() and remap_pfn_range()
The code comes from the i915 DRM driver.

In Linux commits b739f125e4ebd73d10ed30a856574e13649119ed and
b12d691ea5e01db42ccf3b4207e57cb3ce7cfe91 (Linux 5.13), the i915 DRM
driver dropped specific implementations to use Linux generic functions.
Therefore I moved the FreeBSD code from that i915 driver to linuxkpi.

However, these commits were later reverted (also in Linux 5.13) so the
i915 driver doesn't use these functions. But perhaps it will help in the
future.

To sum up, the code comes from the i915 DRM driver but it doesn't use it
(i.e. it continues to use its internal implementation).

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38088
2023-01-25 22:26:54 +01:00
Jean-Sébastien Pédron
4fee6659c4
linuxkpi: Add sysfs_emit()
Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38086
2023-01-25 22:26:54 +01:00
Jean-Sébastien Pédron
0d4d9ee6f0
linuxkpi: Add complete field to struct dev_pm_ops
This change breaks the KBI.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38085
2023-01-25 22:26:54 +01:00
Jean-Sébastien Pédron
270a133480
linuxkpi: Add pm_suspend_via_firmware()
Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38084
2023-01-25 22:26:53 +01:00
Jean-Sébastien Pédron
710c6084d1
linuxkpi: Add pm_runtime_suspended()
Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38083
2023-01-25 22:26:53 +01:00
Jean-Sébastien Pédron
2272ccaa68
linuxkpi: Define tasklet_unlock_spin_wait() as tasklet_unlock_wait()
Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38080
2023-01-25 22:26:53 +01:00
Jean-Sébastien Pédron
a609ed7959
linuxkpi: Define synchronize_hardirq()
It currently does the same as `synchronize_irq()`.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38079
2023-01-25 22:26:53 +01:00
Jean-Sébastien Pédron
976aa07a88
lindebugfs: Add missing debugfs_create_u*() and debugfs_create_x*()
The `debugfs_create_x*()` variants are the same as their
`debugfs_create_u*()` equivalent, but they work with lowercase
hexadecimal.

While here, fix a few style(9) issues.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D38087
2023-01-25 22:26:52 +01:00
Jean-Sébastien Pédron
f2044a3030
lindebugfs: Add debugfs_create_atomic_t()
Reviewed by:	jfree
Approved by:	jfree
Differential Revision:	https://reviews.freebsd.org/D37915
2023-01-25 22:26:32 +01:00
Jean-Sébastien Pédron
bb651c77f5
linuxkpi: Define hrtimer_try_to_cancel()
It is the same as callout_stop(9) but the return values are different.

Reviewed by:	hselasky
Approved by:	hselasky
Differential Revision:	https://reviews.freebsd.org/D38081
2023-01-18 23:02:24 +01:00
Jean-Sébastien Pédron
e8ce32bea3
linuxkpi: Define EBADSLT to 57
This is the same error code as Linux.

As emaste@ noted in the review, FreeBSD defines the following errno
values in `sys/errno.h`:
* 56 is `EISCONN`
* 57 is `ENOTCONN`

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D37935
2023-01-16 19:27:21 +01:00
Jean-Sébastien Pédron
cf8f392260
linuxkpi: Add memalloc_noreclaim_save() and memalloc_noreclaim_restore()
They are no-ops.

Reviewed by:	emaste, manu
Approved by:	emaste, manu
Differential Revision:	https://reviews.freebsd.org/D37933
2023-01-16 19:27:16 +01:00
Jean-Sébastien Pédron
ed53e350d7
linuxkpi: Define ioremap_cache()
It uses the `VM_MEMATTR_WRITE_BACK` flag on FreeBSD.

It replaces `ioremap_wb()` which doesn't exist in Linux. Perhaps it
existed in the past and was removed.

Reviewed by:	emaste, manu
Approved by:	emaste, manu
Differential Revision:	https://reviews.freebsd.org/D37916
2023-01-16 19:11:58 +01:00
Jean-Sébastien Pédron
3aa335d00a
linuxkpi: Add gfp_mask field to struct shrink_control
bz@ asked if the KBI breakage is a concern here. My answer was that this
is the first time in the DRM drivers in Linux 5.13 (the version I'm
working on) that this structure is initialized (as a variable local to
the function in this case), so it shouldn't be a problem for the DRM
drivers.

However, I can't speak for other drivers maintained outside of the src
tree.

Reviewed by:	emaste, manu
Approved by:	emaste, manu
Differential Revision:	https://reviews.freebsd.org/D37913
2023-01-16 19:11:58 +01:00
Jean-Sébastien Pédron
c0c1c599c0
linuxkpi: Define GFP_NOFS in linux/gfp.h
Reviewed by:	emaste, manu
Approved by:	emaste, manu
Differential Revision:	https://reviews.freebsd.org/D37910
2023-01-16 19:11:52 +01:00
Bjoern A. Zeeb
4b56afaf7b LinuxKPI: implement irq_get_msi_desc()
Add irq_get_msi_desc() as a wrapper around a PCI function which will
allocate a single cached value (see comment on struct) for the
msi_desc requested if it doesn't exist yet and handle freeing it
when the PCI device goes away.  We take the values from the ivars of
the native (FreeBSD) device.

While changing struct pci_dev also add the msi_cap field requested by
a wireless driver.

Bump __FreeBSD_version so these changes can be detected.

MFC after:	3 days
X-MFC: move fields to end of struct (alloc happens in linux_pci.c)
Reviewed by:	hselasky (earlier version)
Differential Revision: https://reviews.freebsd.org/D37523
2023-01-13 00:43:23 +00:00
Bjoern A. Zeeb
8f61992d7c LinuxKPI: pci: add [linuxkpi_]pci_get_device()
Add a version of pci_get_device() as linuxkpi_pci_get_device()
not (yet) supporting the last argument.
Due to conflicts we cannot redefine it as we would normally do
in LinuxKPI so drivers have to be adjusted.

MFC after:	3 days
Differential Revision: https://reviews.freebsd.org/D37593
2023-01-13 00:40:57 +00:00
Bjoern A. Zeeb
e9715b1c44 LinuxKPI: fix pci_alloc_irq_vectors() for MSI
pci_alloc_irq_vectors() is given a min and max vector value.
pci_enable_msi() will always succeed independent of these arguments as
it does not know about them.  Further it will only ever allocate
1 "vector" not supporting any other amount.
So upfront check that (a) the available pci_msi_count() can satisfy the
requested minv and (b) given the pci_enable_msi() hard coded limit check
that minv is not larger than 1.
If we cannot satisfy either requirement return an error.

This fixes problems with drivers which check that the returned value
of allocated "vectors" will match their requests and only otherwise try
to fall back to ask for 1 or deal otherwise.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Reviewed by:	hselasky (earlier version)
Differential Revision: https://reviews.freebsd.org/D37522
2023-01-13 00:39:24 +00:00
Bjoern A. Zeeb
75388b9ca5 LinuxKPI: add (skeleton) functions to make drivers compile
Add more functions to netdevice.h (netif_napi_add_tx() being the only
one implemented) and add platform_device.h and netlink.h in order to
make driver code compile.
The skeleton functions are used only in very limited scope and not at
all in our usage so far but add (invasive) #ifdef if removed.
Add pr_debug() calls to each of them in order to log a TODO (if DEBUG
compiled in) and someone should hit them in the future.

MFC after:	3 days
Commented on by: hselasky (earlier version)
Differential Revision: https://reviews.freebsd.org/D37599
2023-01-13 00:38:11 +00:00
Bjoern A. Zeeb
f82cf28b31 LinuxKPI: add kstrtou32_from_user() and mac_pton()
While here:
- fix an argument of kstrtouint_from_user() to correct signedness.
- make kstrtou32() call kstrtouint() to avoid duplication (keep inline
  function)

Add kstrtou32_from_user() based on other examples in the file
making it a copy of the now fixed kstrtouint_from_user().

Also add a rudimentarily hacked up version of mac_pton() which is
leanient accepting non-well-formed input but so far only with ':'
separators.  It does not seem to obviously belong to any networking
header file so add it here.

Both new functions are needed for debugfs support for iwlwifi hence
coming together in one commit.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Commented on by:	emaste
Differential Revision: https://reviews.freebsd.org/D37088
2023-01-13 00:34:32 +00:00
Bjoern A. Zeeb
51e94a4658 LinuxKPI: fix possible NULL dereference in linuxkpi_page_frag_alloc()
Fix a possible NULL pointer deref in case alloc_pages() fails.
This is theoretical so far as up to now no code in the tree uses
linuxkpi_page_frag_alloc().

Reported by:	Coverity via emaste
Coverity ID:	1502345
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
X-MFC-with:	55038a6306
2023-01-11 23:40:05 +00:00
Val Packett
0b4531511e copyright: chase my name and email change
Reviewed by:	imp, emaste
Differential Revision:	https://reviews.freebsd.org/D37945
2023-01-06 15:28:42 -05:00
Jean-Sébastien Pédron
17f2b12a38
linuxkpi: Define lockdep_assert_none_held_once()
This is defined as a no-op even when INVARIANTS is defined. I admit I
don't know how to implement that in FreeBSD and didn't search
thoroughly.

Reviewed by:	bz
Approved by:	bz
Differential Revision:	https://reviews.freebsd.org/D37911
2023-01-02 22:07:31 +01:00
Jean-Sébastien Pédron
8dfb5571c4
linuxkpi: Include errno.h from acpi/video.h
This defines `ENODEV` used in this header. This fixes a build failure in
the DRM drivers.

Reviewed by:	bz
Approved by:	bz
Differential Revision:	https://reviews.freebsd.org/D37909
2023-01-02 22:05:27 +01:00
Bjoern A. Zeeb
4052b0e4b2 LinuxKPI: pm.h add pm_sleep_ptr and DEFINE_SIMPLE_DEV_PM_OPS
Extend pm.h by pm_sleep_ptr and DEFINE_SIMPLE_DEV_PM_OPS().
For the moment this duplicates some parts (as can be seen in the earlier
review I tried to simplify bits but given our implementation this
was easier in the end).

While here and cleanup the SIMPLE_DEV_PM_OPS() bits (white-space only).

MFC after:	3 days
Reviewed by:	hselasky
Differential Revision: https://reviews.freebsd.org/D37527
2022-12-31 02:51:09 +00:00
Bjoern A. Zeeb
55038a6306 LinuxKPI: add simplified vesion of page_frag_cache
For the moment and the currently only consumer (mt76) add a simplified
version of the page_frag_cache.  We will only accept fragement sizes up
to 1 PAGE_SIZE (KASSERT) and we will always return a full page.
Should we add more consumers or small (or large) objects would become a
problem we can always add a more elaborate version.

Discussed with:	markj
Reviewed by:	markj (,hselasky commented as well)
MFC after:	3 days
Differential Revision: https://reviews.freebsd.org/D37595
2022-12-31 02:45:44 +00:00
Bjoern A. Zeeb
4b0af11437 LinuxKPI: 802.11: move ieee80211_{unregister,restart}_hw out of header
Migrate the two functions from the header into the implementation file
in order to have access to more facilities and not to run into possible
allocation/locking/... problems in the future.

Sponsored by:	The FreeBSD Foundation
MFC after:	10 days
2022-12-31 02:24:23 +00:00
Bjoern A. Zeeb
c990500bf1 LinuxKPI; 802.11: update mac80211.h structures and fields
Cleanup some fields and structures and add new ones.

Sponsored by:	The FreeBSD Foundation
MFC after:	10 days
2022-12-31 02:15:28 +00:00
Bjoern A. Zeeb
3391199496 LinuxKPI: 802.11: implement ieee80211_get_hdrlen_from_skb()
Implement ieee80211_get_hdrlen_from_skb() doing basic sanity checks
on lengths (minimal length or skb data length vs. header length).

Sponsored by:	The FreeBSD Foundation
MFC after:	10 days
2022-12-31 02:02:01 +00:00
Bjoern A. Zeeb
13d87d92e4 LinuxKPI: 802.11: implement cfg80211_get_ies_channel_number()
Using the previous changes implement cfg80211_get_ies_channel_number()
either based on DSPARMS (or for the future HTINFO).

Sponsored by:	The FreeBSD Foundation
MFC after:	10 days
2022-12-31 01:59:20 +00:00
Bjoern A. Zeeb
5db817d864 LinuxKPI: 802.11: implement some *eleme/ie* lookup functions
Implement cfg80211_find_elem(), ieee80211_bss_get_elem(),
ieee80211_bss_get_ie(), and cfg80211_find_vendor_ie() with the last
one having a short cut always also checking oui_type in the pattern.

Sponsored by:	The FreeBSD Foundation
MFC after:	10 days
2022-12-31 01:33:28 +00:00
Bjoern A. Zeeb
5edde07c2a LinuxKPI: 802.11: implement cfg80211_{get,put}_bss
Implement cfg80211_{get,put}_bss currently doing malloc/free bits,
so hopefully the drivers get the calls right.

cfg80211_get_bss() sets up a lookup structure which may also take a
result (first hit wins) and calls ieee80211_scan_iterate() comparing
the various values in the iterator funcion.  Some of the checks are
partially pointless (as it seems the drivers are not interested in
these parts [ANY] but we keep them for documentation purposes should
futher values arise in the future).

We currently only iterate over the first VAP which will do for now.

Sponsored by:	The FreeBSD Foundation
MFC after:	10 days
2022-12-31 01:18:16 +00:00
Bjoern A. Zeeb
b6b352e4c7 LinuxKPI: 802.11: set sta supported legacy rates
When initializing the sta set the per-band supported legacy rates
as some drivers take the information from there.

Sponsored by:	The FreeBSD Foundation
MFC after:	10 days
2022-12-31 00:33:34 +00:00
Vladimir Kondratyev
68f08e26e2 LinuxKPI: linux/seqlock.h: Fix write_seqcount_(begin|end)
in seqcount_mutex_t case with removal of extraneous mutex lock/unlock
calls and addition of missing critical section.
While here strip one inline wrap layer to reduce code size.

Fixes startup lockup of i915kms after update to drm-kmod v5.12

Reviewed by:	hselasky, bz
MFC after:	1week
Differential Revision:	https://reviews.freebsd.org/D37699
2022-12-24 12:01:20 +03:00
Konstantin Belousov
140ceb5d95 ptrace(2): add PT_SC_REMOTE remote syscall request
Reviewed by:	markj
Discussed with:	jhb
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D37590
2022-12-22 23:11:35 +02:00
Konstantin Belousov
f081a291a1 compat32: move struct ptrace_sc_ret32 definition from .c to .h
Reviewed by:	markj
Sponsoreed by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D37590
2022-12-22 23:11:35 +02:00
Emmanuel Vadot
ccd8c4488a linuxkpi: seq_read: Fix off by one error
strscpy needs the buffer length not the string length (so including
the '\0').

Reviewed by:	bz
Fixes:	f697b9432d ("linuxkpi: drm-kmod debugfs support")
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D37771
2022-12-21 21:11:31 +01:00
Mateusz Guzik
e6bc24b038 kref: switch internal type to atomic_t and bring back const to kref_read
This unbreak drm-kmod build.

the const is part of Linux API

Unfortunately drm-kmod uses hand-rolled refcount* calls on a kref
object. For now go the easy route of keeping it operational by casting
stuff internally.

The general goal here is to make FreeBSD refcount API use an opaque
type, hence the ongoing removal of hand-rolled accesses.

Reported by:	emaste
2022-12-13 20:46:58 +00:00
Mateusz Guzik
67e628b7a6 kref: replace hand-rolled atomic ops with refcount API
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D37608
2022-12-13 09:24:57 +00:00
Emmanuel Vadot
72621b543e linuxkpi: Fix style for dma_map_sgtable
Reported by:	bz
Sponsored by:	Beckhoff Automation GmbH & Co. KG
2022-12-06 16:52:16 +01:00
Austin Shafer
4085bde9fa linuxkpi: Fix return value of dma_map_sgtable
dma_map_sgtable internally uses the dma_map_sg_attrs helper. The problem is
that dma_map_sg_attrs returns the number of entries mapped, whereas
dma_map_sgtable returns nonzero on failure. This leads to dma_map_sgtable
returning non-zero-but-positive values which tricks other areas of the stack
into thinking nents is a valid pointer.

This checks if nents is valid and returns zero if so, updating the nents field
in sgt. This fixes PRIME render offload with nvidia-drm.

Fixes:	9202c95f47 ("linuxkpi: Add dma_{un,}map_sgtable")
2022-12-06 16:25:53 +01:00
Jean-Sébastien Pédron
e101c1c2c9 linuxkpi: Introduce module_param() of type bint
In Linux, this limits the accepted value to -1, 0 and 1.
In FreeBSD, this remains a signed integer with no specific constraints.

This change is a requirement to update our DRM drivers to Linux 5.12.

Differential Revision:	https://reviews.freebsd.org/D37364
2022-12-01 15:03:00 +01:00
Jean-Sébastien Pédron
0adc02a979 linuxkpi: Add PCIE_SPEED_{32,64}_0GT PCI-E bus speed constants
This change is a requirement to update our DRM drivers to Linux 5.12.

Differential Revision:	https://reviews.freebsd.org/D37363
2022-12-01 15:02:27 +01:00
Jean-Sébastien Pédron
e79a57d4ec linuxkpi: Add cmpxchg64() in <asm/atomic.h>
Differential Revision:	https://reviews.freebsd.org/D36966
2022-12-01 14:59:16 +01:00
Jean-Sébastien Pédron
18e4112337 linuxkpi: Add seqcount_mutex_t support in <linux/seqlock.h>
To achieve that, the header uses the C11 type generic selection keyboard
_Generic() because the macros are supposed to work with seqcount_t
and seqcount_mutex_t.

Differential Revision:	https://reviews.freebsd.org/D36965
2022-12-01 14:58:27 +01:00
Bjoern A. Zeeb
69cc163001 LinuxKPI: 802.11: minor header updates
- add comments for enum values constantly looked up, and another one to
  a net80211 equivalent (should possibly re-define those in the future?)
- add another nl80211_sta_info flag
- add enum environment_cap used in cfg80211.h in the future.

MFC after:	3 days
2022-11-28 21:21:06 +00:00
Bjoern A. Zeeb
5504bd59a3 LinuxKPI: SKB update
- skb_reset_tail_pointer(): we do not do offsets so do a plain reset
- skb_add_rx_frag(): adjust data_len to keep track of the frag
- based on that implement skb_is_nonlinear() and skb_linearize()
- implement build_skb() and adjust linuxkpi_kfree_skb() and ddb macro.

Sponsored by:	The FreeBSD Foundation (partially)
MFC after:	3 days
2022-11-28 20:54:57 +00:00
Bjoern A. Zeeb
ce9f36610e LinuxKPI: SKB: implement skb_peek()
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-11-28 18:47:08 +00:00
Bjoern A. Zeeb
23c73dbae7 LinuxKPI: iwlwifi: rtw88: rtw89: remove budget argument from netif_napi_add()
In preparation for future updates remove the budget argument from the
netif_napi_add() in drivers and update LinuxKPI to reflect that it is
gone and only set it internally.  This required changes to the currently
committed wireless drivers based on LinuxKPI (iwlwifi, rtw88, rtw89).

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-11-28 17:30:40 +00:00
Bjoern A. Zeeb
1b91eba37b LinuxKPI: ethtool.h add more definitions
While we do not currently use ethtool, add the definitions to avoid
other longer-term maintenance problems with drivers.

Also migrate ETH_GSTRING_LEN into here from if_ether.h as it seems this
is where it belongs.

MFC after:	3 days
Differential Revision: https://reviews.freebsd.org/D37214
2022-11-28 17:25:58 +00:00
Bjoern A. Zeeb
0fce2dc157 LinuxKPI,lindebugfs: add u8 base type and blob support
Add debugfs_create_u8() based on other already present implementations.
Add a read-only implementation for debugfs_create_blob().

Both are needed for iwlwifi debugfs support.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
OKed by:	jfree (earlier version)
Differential Revision: https://reviews.freebsd.org/D37090
2022-11-28 17:21:50 +00:00
Bjoern A. Zeeb
af393426b3 LinuxKPI: add a no-op generic_file_llseek()
This is needed for debugfs implementations in drivers.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
OKed by:	jfree
Differential Revision: https://reviews.freebsd.org/D37092
2022-11-28 17:14:10 +00:00
Bjoern A. Zeeb
5f2f582ccc LinuxKPI: pci.h add more MSI related constanst and pci_is_enabled()
Add more MSI related constansts defined to our native defines and
pci_is_enabled().  All are needed for another wireless driver.

MFC after:	3 days
Differential Revision: https://reviews.freebsd.org/D37225
2022-11-28 17:11:47 +00:00
Ed Maste
eafafebe47 compat32: retire now-unused MIPS support
This reverts commit a6d20bbaa2.
2022-11-23 09:33:43 -05:00
Bjoern A. Zeeb
325ba12055 LinuxKPI: in efi.h include queue.h
sys/linker.h needs sys/queue.h;  this gets another wireless driver
closer to compiling on main.

MFC after:	3 days
2022-11-15 23:08:05 +00:00
Bjoern A. Zeeb
5d310ea8c5 LinuxKPI: add memset_startat macro
Add a memset_startat() macro which sets a pattern from a struct member
to the end of the struct.   Needed by a wireless driver.

MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D37389
2022-11-15 12:52:10 +00:00
Jean-Sébastien Pédron
208d02fd5d
linuxkpi: Define ZERO_OR_NULL_PTR() in <linux/slab.h>
On Linux, the `kmalloc()` family of functions returns a special value if
the size of the allocation is zero. This macro verifies if the pointer
is NULL (the allocation failed) or the size is 0 (the allocation was not
performed AFAIU). This special value can be passed to `kfree()`.

On FreeBSD, our `malloc(9)` functions don't return a special value for
0-size allocations. Therefore we can simply compare the result against
NULL.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D37367
2022-11-11 21:03:25 +01:00
Jean-Sébastien Pédron
86a1c5d129
linuxkpi: Define pci_reset_function() in <linux/pci.h>
Currently, it always returns an error on FreeBSD.

Reviewed by:	bz manu
Approved by:	bz manu
Differential Revision:	https://reviews.freebsd.org/D37366
2022-11-11 21:00:36 +01:00
Jean-Sébastien Pédron
42bb586116
linuxkpi: Include <linux/list.h> and <linux/kernel.h> from <linux/mutex.h>
They are not really used in this header. However they are included in
Linux and at least the DRM drivers unfortunately rely on this namespace
pollution.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D37365
2022-11-11 20:59:40 +01:00
Jean-Sébastien Pédron
24c7853f39
linuxkpi: Add <linux/mman.h> which includes <linux/smp.h>
This is used by `i915_gem.c` in the i915 DRM driver to get access to
`wbinvd_on_all_cpus()`.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D36970
2022-11-11 20:57:46 +01:00
Jean-Sébastien Pédron
708a570255
linuxkpi: Add <linux/page-flags.h>
It just provides a `PageHighMem()` macro stub.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D36961
2022-11-11 20:56:42 +01:00
Jean-Sébastien Pédron
58cf3a69a5
linuxkpi: Define boot_cpu_data.x86_max_cores
Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D36971
2022-11-11 18:43:07 +01:00
Jean-Sébastien Pédron
c4163160e4
linuxkpi: Add dev_warn_once() in <linux/device.h>
Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D36968
2022-11-11 18:42:31 +01:00
Jean-Sébastien Pédron
23ebeac87f
linuxkpi: Add list_for_each_entry_from_rcu() in <linux/rculist.h>
Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D36967
2022-11-11 18:42:10 +01:00
Jean-Sébastien Pédron
d3584f9283
linuxkpi: Define typeof_member() in <linux/kernel.h>
Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D36964
2022-11-11 18:41:36 +01:00
Jean-Sébastien Pédron
0e5569a08c
linuxkpi: Add <linux/dma-buf-map.h>
I took the implementation from OpenBSD, commit
d55ef580b1748517027c3eabdb715316ca5b1442.

The only difference is the addition of `dma_buf_map_is_equal()`.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D36963
2022-11-11 18:40:57 +01:00
Jean-Sébastien Pédron
c9c1255012
linuxkpi: Add <linux/mmzone.h>
It provides the `MAX_ORDER` constant.

Reviewed by:	emaste manu
Approved by:	emaste manu
Differential Revision:	https://reviews.freebsd.org/D36962
2022-11-11 18:39:48 +01:00
Jean-Sébastien Pédron
1676c97d5d
linuxkpi: Add <acpi/actbl.h>
It simply includes the same header in FreeBSD (which is located
elsewhere).

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D36960
2022-11-11 18:38:06 +01:00
Jean-Sébastien Pédron
1ad6b2b1da
linuxkpi: Add krealloc_array()
In FreeBSD, this is a wrapper on top of `realloc()`.

V2: Check if `n * size` would overflow and return `NULL` if that's the
    case. Suggested by hselasky@ and emaste@.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D36959
2022-11-11 18:37:34 +01:00
Jean-Sébastien Pédron
0b8a423d07
linuxkpi: Introduce module_param() of type hexint
In Linux, this affects how the value is formatted. In FreeBSD, this
remains an unsigned integer.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D36958
2022-11-11 18:36:46 +01:00
Jean-Sébastien Pédron
c72dd0aabe
linuxkpi: Introduce vma_set_file()
This code was moved from the i915 driver in Linux 5.11.

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D36957
2022-11-11 18:36:00 +01:00
Jean-Sébastien Pédron
415ca4d27d
linuxkpi: Include <linux/shinker.h> in <linux/mm.h>
This is done like this in Linux.

Reviewed by:	emaste manu
Approved by:	emaste manu
Differential Revision:	https://reviews.freebsd.org/D36956
2022-11-11 18:34:19 +01:00
Jean-Sébastien Pédron
f021c5c4a1
linuxkpi: Update struct irq_work
The previous `llnode` field is moved inside another field `node`.

This `node` field is a `struct __call_single_node` in Linux. Here, we
simply add an anonymous struct with the `llnode` field inside. That
field's new name is `llist` now.

V2: Use an anonymous union to keep the structure backward compatible
    with drivers using the previous `llnode` field. This was suggested
    by wufl@ and hselasky@. Thank you!

Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D36955
2022-11-11 18:32:58 +01:00
Jean-Sébastien Pédron
bfe6bfd79e
linuxkpi: Add __GFP_NOMEMALLOC kmalloc flag
Reviewed by:	manu
Approved by:	manu
Differential Revision:	https://reviews.freebsd.org/D36954
2022-11-11 18:30:31 +01:00
Emmanuel Vadot
ee247fc1e9 linuxkpi: Move cpu_relax out of ifdef for x86
It's needed by drm-kmod and this allow building on arm64 and powerpc.

Reported by:	jhibbits
Sponsored by:	Beckhoff Automation GmbH & Co. KG
2022-11-10 12:50:51 +01:00
Alex S
9f7bf94ee2 linux(4): Fix get_robust_list() syscall return value.
The system call returns the head of the robust futex list. The list head is stored
in the location pointed to by the head argument. When copying data between address
spaces use proper head storage size as it depends on an emulated ABI.

PR:		267616
MFC after:	3 days
2022-11-09 00:17:17 +03:00
Bjoern A. Zeeb
b5c3819c7b LinuxKPI: add virt_to_phys()
Add virt_to_phys() as a define to vtophys().
This is used by a wireless driver for dma related work; sigh.

MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D37301
2022-11-08 18:18:01 +00:00
Bjoern A. Zeeb
f2978460c7 LinuxKPI: tasklet add (*callback) support
In addition to (*func) tasklet also seems to have a (*callback) with
a different argument.  Add support for this and add tasklet_setup()
as well for support in more drivers.

The from_tasklet() definition is duplicated in the tree; hide it there
under #ifndef to avoid a re-definition.  People should generally add
LinuxKPI bits to linuxkpi rather than private files if they also rely
on other LinuxKPI bits.

X-MFC:		DO NOT MFC, space allocated by drivers not us.
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D37216
2022-11-08 18:14:17 +00:00
Bjoern A. Zeeb
e2361e04b0 LinuxKPI: implement cpumask_of()
Add a static set of cpumasks for all (possible) cpus with only the one
indexed cpu enabled in each set.
This is needed for cpumask_of(_cpuid) which returns a cpumask (cpuset)
with only cpu _cpuid enabled and is used by one wireless driver at least.

MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D37223
2022-11-08 18:11:55 +00:00
Bjoern A. Zeeb
a62d5ff5b0 LinuxKPI: add linux/leds.h
This is just a dummy enum and struct in order to make drivers compile
more happily as some parts are simply not hidden behind #ifdefs and
this avoids a longer-term maintenance problem.

MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D37215
2022-11-07 12:52:41 +00:00
Bjoern A. Zeeb
6e8d676131 LinuxKPI: add devm_request_irq()
Add devm_request_irq() needed by a driver.  Turns out all we need
is a wrapper with the right arguments to lkpi_request_irq().

MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D37217
2022-11-07 12:51:01 +00:00
Bjoern A. Zeeb
6a647ae514 LinuxKPI: string.h implement memcpy_and_pad()
Add a memcpy variant which takes length of source and destination
buffers and a padding character in case there is free space in the
destination.  This is used by a wireless driver.

MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D37226
2022-11-07 12:49:01 +00:00
Bjoern A. Zeeb
4a67f1df8b LinuxKPI: 802.11: enable WME support
Most of the WME code has been there disabled for months.  One of the
reasons was that it lead to crashes early on.  It is now understood
that the crashes are independent event and we can enable WME.
Update the code and deal with the calls from net80211 and adjust the
updates to when mac80211 drivers expect them, coherently put it under
LKPI_80211_WME and enable the define locally.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-11-07 12:39:46 +00:00
Elliott Mitchell
21cc0918c7 sys: Nuke double-semicolons
A distinct number of double-semicolons have ended up in FreeBSD.  Take a
pass at getting rid of many of these harmless typos.

Reviewed by: emaste, rrs
Pull Request: https://github.com/freebsd/freebsd-src/pull/609
Differential Revision: https://reviews.freebsd.org/D31716
2022-11-02 09:34:20 -06:00
Bjoern A. Zeeb
e7fe037310 LinuxKPI: 802.11: pass internal variable to lkpi_80211_mo_sta_state()
With mac80211 operations (MO) tracing on we have seen some ill-ordered
executions of MO functions.  In order to limit visibility of the mac80211
sta, pass the internal version into lkpi_80211_mo_sta_state() and only
there convert to the argument needed.  This mostly eases tracing and
debugging.

Sposnored by:	The FreeBSD Foundation
MFC after:	3 days
2022-11-01 00:00:18 +00:00
Bjoern A. Zeeb
05e640dc9e LinuxKPI: 802.11: update struct member types
Update struct member types for ongoing work towards HT support.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-10-31 22:24:08 +00:00
Bjoern A. Zeeb
1d70218e9e LinuxKPI: 802.11 update header files
Adjust struct members, add more (for HE dummy) defines, add more
(wrapper) functions in order to acoomodate another driver.

MFC after:	3 days
2022-10-31 22:09:25 +00:00
Bjoern A. Zeeb
cca40d7cc7 LinuxKPI: add timekeeping.h, another dummy (empty) header file
The file is included by a driver but it seems we don't need to implement
anything here.

MFC after:	3 days
2022-10-30 17:35:24 +00:00
Ed Maste
43d0c2ddd2 netlink: use (void) for function definitions with no arguments
For some of these Clang produced a warning that "a function declaration
without a prototype is deprecated in all versions of C".  In other cases
the function defintion used () which did not match the header
declaration, which used (void).

Sponsored by:	The FreeBSD Foundation
2022-10-27 11:14:00 -04:00
Bjoern A. Zeeb
b5a8107590 LinuxKPI: seq_file add "private" versions.
Add __seq_open_private() and seq_release_private() needed by iwlwifi
debugfs support.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D37089
2022-10-24 21:39:48 +00:00
Bjoern A. Zeeb
d3975204e4 LinuxKPI: add MSEC_PER_SEC
Sponsored by:	The FreeBSD Foundation
Reviewed by:	imp, emaste
MFC after:	3 days
Differential Revision: https://reviews.freebsd.org/D37087
2022-10-23 21:54:36 +00:00
Bjoern A. Zeeb
64d3da0063 LinuxKPI: 802.11: add MO tracing
Add a macro to each implemented mac80211 operation.  This currently
turns into a printf if LINUXKPI_80211_DEBUG is defined but in the
future could become a different probe as well.
This is helpful for quick analysis and boot-time problem debugging
when DTrace and other frameworks may be harder to use.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-10-23 21:48:22 +00:00
Bjoern A. Zeeb
0080f30ff1 LinuxKPI: 802.11: add changes to support debugfs in iwlwifi
Add new fields (also have to move a struct up, no changes there)
in order to make iwlwifi debugfs support compile.

Sposnored by:	The FreeBSD Foundation
MFC after:	3 days
2022-10-22 20:42:35 +00:00
John Grafton
4c9db9566e linprocfs: Add net/route.
PR:			266482
Reviewed by:		melifaro, me
Differential revision:	https://reviews.freebsd.org/D36949
MFC after:		1 week
2022-10-22 13:52:58 +03:00
Ed Maste
9f6097d6a6 linuxkpi: retire now-unused MIPS support
Reviewed by:	bz, manu
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D37023
2022-10-17 16:31:20 -04:00
Jake Freeland
4cb3cb2de2 LinuxKPI: Add pci_power querying for drm-kmod
Adds a few struct members and a function to get i915_runtime_pm_status()
to compile in drm-kmod.

Differential Revision:	https://reviews.freebsd.org/D36749
Sponsored by:   Google, Inc. (GSoC 2022)
2022-10-06 10:15:41 +02:00
Alexander V. Chernikov
7c40e2d5f6 linuxolator: add netlink support
Add the glue code to support netlink in Linuxolator.
linux_common(4) now depends on netlink(4).

All netlink protocol constants are consistent with the Linux version.
However, certain OS-specific constants such as AF_INET6, interface
flags or default routing table id, are different between FreeBSD and
Linux. Thus, it may be needed to rewrite some message parts or even
rewrite the whole message, adding or removing some TLVs. The core
netlink implementation code provides efficient rewriting callbacks
 which Linuxolator now uses.

Reviewed by:	dchagin
Differential Revision: https://reviews.freebsd.org/D36361
MFC after:	2 months
2022-10-01 14:16:45 +00:00
Ed Schouten
af3c78886f Alter the prototype of qsort_r(3) to match POSIX, which adopted the
glibc-based interface.

Unfortunately, the glibc maintainers, despite knowing the existence
of the FreeBSD qsort_r(3) interface in 2004 and refused to add the
same interface to glibc based on grounds of the lack of standardization
and portability concerns, has decided it was a good idea to introduce
their own qsort_r(3) interface in 2007 as a GNU extension with a
slightly different and incompatible interface.

With the adoption of their interface as POSIX standard, let's switch
to the same prototype, there is no need to remain incompatible.

C++ and C applications written for the historical FreeBSD interface
get source level compatibility when building in C++ mode, or when
building with a C compiler with C11 generics support, provided that
the caller passes a fifth parameter of qsort_r() that exactly matches
the historical FreeBSD comparator function pointer type and does not
redefine the historical qsort_r(3) prototype in their source code.

Symbol versioning is used to keep old binaries working.

MFC:			never
Relnotes:		yes
Reviewed by:		cem, imp, hps, pauamma
Differential revision:	https://reviews.freebsd.org/D17083
2022-09-30 15:26:30 -07:00
Hans Petter Selasky
dd6bb9abf0 LinuxKPI: Use SYSCTL_FOREACH()
Differential Revision:  https://reviews.freebsd.org/D36748
MFC after:	1 week
Sponsored by:	NVIDIA Networking
2022-09-28 13:59:55 +02:00
Alan Somers
d3f96f6610 Fix O(n^2) behavior in sysctl
Sysctl OIDs were internally stored in linked lists, triggering O(n^2)
behavior when userland iterates over many of them.  The slowdown is
noticeable for MIBs that have > 100 children (for example, vm.uma).  But
it's unignorable for kstat.zfs when a pool has > 1000 datasets.

Convert the linked lists into RB trees.  This produces a ~25x speedup
for listing kstat.zfs with 4100 datasets, and no measurable penalty for
small dataset counts.

Bump __FreeBSD_version for the KPI change.

Sponsored by:	Axcient
Reviewed by:	mjg
Differential Revision: https://reviews.freebsd.org/D36500
2022-09-26 18:03:34 -06:00
Bjoern A. Zeeb
0b9bc97342 LinuxKPI: add DMA_MAPPING_ERROR
While we deal with 0 returned, some drivers directly use and check for
DMA_MAPPING_ERROR.  Add the case and check for both in dma_mapping_error().

MFC after:	1 week
Reviewed by:	hselasky
Differential Revision: https://reviews.freebsd.org/D36686
2022-09-26 19:42:02 +00:00
Bjoern A. Zeeb
f486b35247 LinuxKPI: add struct dmi_header and unsupported dmi_walk()
Add a structure definition as well as a dummy dmi_walk for now
which returns an error as not supported.  Our current dmi implementation
is special but does not give access to all details but rather only
information from kenv which does not suffice all use cases.

MFC after:	1 week
Reviewed by:	hselasky
Differential Revision: https://reviews.freebsd.org/D36687
2022-09-26 19:40:49 +00:00
John Baldwin
f49fd63a6a kmem_malloc/free: Use void * instead of vm_offset_t for kernel pointers.
Reviewed by:	kib, markj
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D36549
2022-09-22 15:09:19 -07:00
John Baldwin
7ae99f80b6 pmap_unmapdev/bios: Accept a pointer instead of a vm_offset_t.
This matches the return type of pmap_mapdev/bios.

Reviewed by:	kib, markj
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D36548
2022-09-22 15:08:52 -07:00
Bjoern A. Zeeb
f7c0c1590e LinuxKPI: cache.h add L1_CACHE_ALIGN()
Sponsored by:	The FreeBSD Foundation
MFC after:	7 days
Reviewed by:	hselasky
Differential Revision: https://reviews.freebsd.org/D36655
2022-09-22 15:10:04 +00:00
Bjoern A. Zeeb
30048f6142 LinuxKPI: pci.h split up pcim_iomap_regions_request_all()
Factor out parts of pcim_iomap_regions_request_all() into
pcim_iomap_regions() now needed for a driver.

Sponsored by:	The FreeBSD Foundation
MFC after:	7 days
Reviewed by:	hselasky
Differential Revision: https://reviews.freebsd.org/D36654
2022-09-22 15:10:04 +00:00
Bjoern A. Zeeb
8e30f49256 LinuxKPI: if_ether.h add more constants
In addition to the ones added last year add more found in modern
drivers.

Sponsored by:	The FreeBSD Foundation
MFC after:	7 days
Reviewed by:	hselasky
Differential Revision: https://reviews.freebsd.org/D36656
2022-09-22 15:10:04 +00:00
Bjoern A. Zeeb
046b82842c LinuxKPI: io.h constify arguments and add more functions
Constify "*from" arguments and add __ioread32_copy() and
__ioread64_copy() based on the already existing implementations.

Sponsored by:	The FreeBSD Foundation
MFC after:	7 days
Reviewed by:	hselasky
Differential Revision: https://reviews.freebsd.org/D36657
2022-09-22 15:10:04 +00:00
Bjoern A. Zeeb
7105f0d967 LinuxKPI: dma-mapping: add dmam_alloc_coherent()
Add the devres version dmam_alloc_coherent() of dma_alloc_coherent()
along with the ancillary free function.

Sponsored by:	The FreeBSD Foundation
MFC after:	7 days
Reviewed by:	hselasky
Differential Revision: https://reviews.freebsd.org/D36661
2022-09-22 15:10:03 +00:00
Bjoern A. Zeeb
f9f4988dc4 LinuxKPI: tracepoint.h add more defines
Add some more defines used in drivers to make it easier to compile.

MFC after:	7 days
Reviewed by:	hselasky, emaste
Differential Revision: https://reviews.freebsd.org/D36660
2022-09-22 15:10:03 +00:00
Bjoern A. Zeeb
fdc7ef3c98 LinuxKPI: pci_ids.h Add more Vendor IDs.
Add PCI vendor IDs found in ath and mt76 drivers.  This should make it
easier for me and others not having to re-define them locally.

MFC after:	7 days
Reviewed by:	hselasky, emaste
Differential Revision: https://reviews.freebsd.org/D36659
2022-09-22 15:10:03 +00:00
Bjoern A. Zeeb
b27c3aa800 LinuxKPI: lockdep.h add lockdep_{,un}register_key()
Add NOPs for lockdep_{,un}register_key().

Sponsored by:	The FreeBSD Foundation
MFC after:	7 days
Reviewed by:	hselasky, emaste
Differential Revision: https://reviews.freebsd.org/D36658
2022-09-22 15:10:03 +00:00
Bjoern A. Zeeb
c41d83548b LinuxKPI: pci.h add more defines and functions
Add #defines for PCI_DEVICE_ID and repoint the PCI_VENDOR_ID one.
Add dev_is_pci().
Add pcie_capability_clear_word() according to similar implementations.

Sponsored by:	The FreeBSD Foundation
MFC after:	7 days
Reviewed by:	hselasky, emaste
Differential Revision: https://reviews.freebsd.org/D36653
2022-09-22 15:10:03 +00:00
Bjoern A. Zeeb
e999fbf077 LinuxKPI: device.h add devm_kmemdup()
Add devm_kmemdup() as needed by a networking driver.

Sponsored by:	The FreeBSD Foundation
MFC after:	7 days
eviewed by: 	hselasky, emaste
Differential Revision: https://reviews.freebsd.org/D36652
2022-09-22 15:09:26 +00:00
Bjoern A. Zeeb
8ea48fc59e LinuxKPI: device.h remove duplicate #include
linux/types.h is included twice; reduce to the first.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-09-21 17:25:34 +00:00
Bjoern A. Zeeb
f02e21159b LinuxKPI: 802.11: add more header compat bits
First part adding more bits in order to synch up drivers to the same
level and enable a new ones.

MFC after:	3 days
2022-09-21 17:12:48 +00:00
Hans Petter Selasky
cbda8bed15 linuxkpi: Resolve duplicate global symbol name to fix LINT kernel build.
seq_printf() is defined in both spl_procfs_list.c and linux_seq_file.c .
Fix this by renaming the LinuxKPI ones and use macros to invoke the
correct function.

Reported by:	jfree@
Differential Revision:  https://reviews.freebsd.org/D35883
MFC after:	1 week
Sponsored by:	NVIDIA Networking
2022-09-20 22:37:15 +02:00
Jake Freeland
f697b9432d linuxkpi: drm-kmod debugfs support
This diff extends LinuxKPI to support simple attribute files in debugfs.
These simple attributes are an essential component for compiling drm-kmod
with CONFIG_DEBUG_FS enabled.
This will allow for easier graphics driver debugging using
Intel's igt-gpu-tools.

Reviewed by:	hselasky
Differential Revision:	https://reviews.freebsd.org/D35883
Sponsored by:	Google, Inc. (GSoC 2022)
2022-09-20 19:41:10 +02:00
Jake Freeland
a11195df34 linuxkpi: Add strndup_user
Reviewed by:	hselasky, markj
Differential Revision:	https://reviews.freebsd.org/D36350
Sponsored by:	Google, Inc. (GSoC 2022)
2022-09-20 19:40:05 +02:00
Jake Freeland
a06eeeaa1d linuxkpi: Add EPOLL aliases
Reviewed by:	hselasky
Differential Revision:	https://reviews.freebsd.org/D36527
Sponsored by:	Google, Inc. (GSoC 2022)
2022-09-20 19:39:52 +02:00
Jake Freeland
f0b0f28f35 linuxkpi: Add down_read_killable()
Reviewed by:	hselasky
Differential Revision:	https://reviews.freebsd.org/D36528
Sponsored by:	Google, Inc. (GSoC 2022)
2022-09-20 19:39:32 +02:00
Mateusz Guzik
c3707bd3d6 linuxkpi: use SI_SUB_EVENTHANDLER + 1, like other consumers
Otherwise it may try to initialize before eventhandler subsystem.
2022-09-17 23:52:23 +00:00
Jessica Clarke
7b673a2c73 freebsd32: Make sendmsg match native ABI for unpadded final control message
The API says that CMSG_SPACE should be used for msg_controllen, but in
practice the native ABI allows you to only use CMSG_LEN for the final
(typically only) control message, and real-world software does this,
including Wayland. For freebsd32, this is in practice mostly harmless,
since control messages are generally used to carry file descriptors,
which are already 4 bytes in size and thus no padding is needed, but
they can carry other quantities that may not result in an aligned
length. This was discovered after CheriBSD's freebsd64 equivalent was
updated to match the freebsd32 implementation, as that uses 8 byte
alignment which does break the file descriptor use case, and thus
Wayland.

This used to be addressed by aligning buflen before the first iteration,
but that allowed unwanted invalid inputs and was lost in 1b1428dcc8,
with no safer equivalent put in its place.

Reviewed by:	brooks, kib, markj
Obtained from:	CheriBSD
Fixes:		1b1428dcc8 ("Fix a TOCTOU vulnerability in freebsd32_copyin_control().")
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D36554
2022-09-15 17:16:22 +01:00
Doug Moore
4893472c9a rb_tree: pass parent to RB_INSERT_COLOR
Change RB_COLOR_INSERT to take a parent parameter, to avoid looking up
a value already available. Make adjustments to a linux rbtree header,
which invokes it.

Reviewed by:	alc, hselasky
Differential Revision:	https://reviews.freebsd.org/D36114
2022-09-13 01:11:47 -05:00
Mateusz Guzik
3212ad15ab Add getsock
All but one consumers of getsock_cap only pass 4 arguments.
Take advantage of it.
2022-09-10 19:47:47 +00:00
Bjoern A. Zeeb
800aa9cd3d LinuxKPI: 80211 (+net80211): update and cleanup headers
Fix types for various struct fields (initially added as int).

Move structs and inline functions logically together, e.g., for wowlan.
Add more skeleton functions and #defines needed for iwlwifi d3.c
in the future.

Add struct ieee80211_vht_cap (without "_ie") to net80211 and remove
duplicate definitions in LinuxKPI headers now using net80211 structs.
For now leave ieee80211_ie_vhtcap in net80211.  I am not sure yet if we
actually need it as such.  That'll be cleaned up with more VHT updates
in net80211 in the future.

No functional changes in currently compiled code intended.

Try to implement ieee80211_action_contains_tpc() as I ran into it with
an older iwlwifi chipset.  This depends on c994352a88.

Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
2022-09-09 18:40:23 +00:00
Bjoern A. Zeeb
d6d687daaa LinuxKPI: 80211: add ieee80211_stop_tx_ba_session()
rtw89 needs ieee80211_stop_tx_ba_session().
Add the skeleton function for now so we can implement BA functions all
together.

MFC after:	3 days
2022-09-09 16:30:00 +00:00
Felix Palmen
600f161295 linuxkpi: Add non-atomic readq()/writeq()
The non-atomic versions are required by drm-510-kmod to build on 32-bit
architectures.

Approved by:		hselasky, manu, tcberner (mentor)
Differential Revision:	https://reviews.freebsd.org/D36507
2022-09-09 16:59:41 +02:00
Doug Moore
d0354fa7b6 rb_tree: reduce duplication in balancing code
Change RB_INSERT_COLOR and RB_REMOVE_COLOR so that the blocks of code
that are identical except for left and right being exchanged are made
only one block with a variable to indicate left- or right-handedness.

Rename RB macros so that those not intended for external use begin
with an underscore.

Add comments to the balancing code so that another might understand it.

Reviewed by:	alc, kib
MFC after:	3 weeks
Differential Revision:	https://reviews.freebsd.org/D36393
2022-09-07 23:46:19 -05:00
Bjoern A. Zeeb
549198b1ab LinuxKPI, dev: 80211 update mac80211 KPI
Update the mac80211 ops KPI for (*conf_tx), (*assign_vif_chanctx),
(*unassign_vif_chanctx), (*start_ap), and (*stop_ap), as well as
ieee80211_beacon_get_tim() and ieee80211_beacon_get_template().

Update in-tree drivers iwlwifi and rtw88 accordingly based on upstream
changes (as well as out-of-tree ones).  This was triggered by trying to
synchronize more drivers to a common state.

MFC after:	1 week
2022-09-07 23:38:54 +00:00
Bjoern A. Zeeb
ac07a3b8b6 LinuxKPI: netdev: expose napi state
There are drivers directly accessing napi->state testing for bits
(NAPI_STATE_SCHED encountered so far).  Rename the internal _flags
struct field to state and expose our internal state flag bits along
with the one official aliased.

As I left in a comment, I wished Linux would hide these accesses
behind inline functions or by other means and not public expose
the implementation details.

MFC after:	1 week
2022-09-07 23:35:41 +00:00
Bjoern A. Zeeb
fb3c549738 LinuxKPI: firmware: add request_partial_firmware_into_buf()
A (so far out-of-tree) driver update needs
request_partial_firmware_into_buf().  Given we load the full .ko file
using firmware(9) just do that and copy the requeste data into the
buffer (rather than poissibly only reading portions of the firmware
file).

MFC after:	1 week
2022-09-07 23:33:45 +00:00
Bjoern A. Zeeb
e3a0b1202b LinuxKPI: 80211 / iwlwifi: improve queue management
For one initialise vif->hw_queues later set in lkpi_80211_txq_tx_one()
for drivers using them.  This may still need slightly more cleanup once
we get QUEUE_CONTROL-supporting drivers into the tree.

For the other rework and improve how we deal with tid/ac/txq in
lkpi_80211_txq_tx_one() and cleanup old comments and unused code.
This seems to reduce (remove) "Invalid TXQ id" reports from iwlwifi.
(The assumption is that the frame(s) triggering this WARN_ONCE or the
added FreeBSD specific logging were sent with lkpi_80211_mo_tx()).

Adjust the one logging from e674ddec0b
to IWL_DEBUG_TX so that now this is fixed it is also not always logged
anymore but leave it in case we need to further debug queues in the
future.

Tested by:	pstef, Kevin Oberman (rkoberman gmail.com)
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-09-05 21:03:03 +00:00
Bjoern A. Zeeb
ec190d9150 LinuxKPI: 80211: improve linuxkpi_ieee80211_get_tid()
Continue what was started in 26a3694833
in iwlwifi and extend out internal implementation of
linuxkpi_ieee80211_get_tid() by an argument as to whether "no-QoS"
answers are acceptable.  For the LinuxKPI ieee80211_get_tid() set
this to false as the Linux derived drivers seem to do extra checks
for the QoS-Data frame before acquiring the tid.
Add KASSERTs to enforce the extra argument.
This allows us to use the net80211 variant in LinuxKPI for other
means explicitly documenting that we do accept a IEEE80211_NONQOS_TID.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-09-05 20:57:17 +00:00
Bjoern A. Zeeb
a486fbbd78 LinuxKPI: 80211: scanning code updates
For consistency rename LKPI_SCAN_RUNNING adding a LHW_ prefix.
Add a local flag LKPI_LHW_SCAN_HW mirroring the net80211
IEEE80211_FEXT_SCAN_OFFLOAD flag.
Slightly simplify the code.
Overload (*ic_scan_curchan) and (*ic_scan_mindwell) so that we can
call the net80211 implementation in case of software scan but skip it
in case of full-offload scans.
Also add a bandaid to our (*ic_set_channel) implementation to not siwtch
channels if we have an active hw_scan running.

Obtained from:	bz/wireless-dev
Sponsored by:	The FreeBSD Foundation (partially)
MFC after:	4 days
2022-09-03 23:40:51 +00:00
Bjoern A. Zeeb
527687a9e3 LinuxKPI: 80211: implement (*get_antenna) and set ic_[rt]xstream
Implement the mac80211 (*get_antenna) call and after checking any
antenna information present query the current configuration on startup
(both informations should be identical at this point in theory).
Both the wiphy variables and function call report a bitmask not a count.
Count the bits for net80211 for as long as we get away with just a
number in ic_[rt]xstream.

Sponsored by:	The FreeBSD Foundation
MFC after:	4 days
2022-09-03 23:11:05 +00:00
Bjoern A. Zeeb
b35f6cd066 LinuxKPI: 80211: make HW_CRYPTO compileable again
Rename TRY_HW_CRYPTO to LKPI_80211_HW_CRYPTO for consitency and make
it compileable again in case someone wants to sit down and make it
work.  It's probably not too much to do.  Otherwise I might eventually
get around to it.

Obtained from:	bz/wireless-dev
Sponsored by:	The FreeBSD Foundation
MFC after:	4 days
2022-09-03 22:51:16 +00:00
Bjoern A. Zeeb
c9b7e9df18 net80211 / drivers: rename to IEEE80211_FC0_SUBTYPE_QOS_DATA
Going through the Frame (Sub)types the "QOS Data" being called "QOS"
scheme leads to a naming conflict for QOS_CFPOLL and QOS_CFACKPOLL
(if added).   Rename QOS* to QOS_DATA* to avoid the conflict and
to also better match the standards name.

No functional changes intended.

Sponsored by:	The FreeBSD Foundation
MFC after:	5 days
Reviewed by:	hselasky
Differential Revision: https://reviews.freebsd.org/D36409
2022-09-03 21:04:13 +00:00
Tijl Coosemans
fdc1894795 linuxkpi: on i386 only use first_msi_irq if apic is in kernel config 2022-09-01 14:08:15 +02:00
Bjoern A. Zeeb
caaa79c3f8 LinuxKPI 802.11: change type of bssid in struct ieee80211_bss_conf
Enabling other driver code found that the bssid in
struct ieee80211_bss_conf is not an array but expected to be
a const pointer (const, != NULL checks).
Adjust accordingly in the header and in the LinuxKPI compat code.
There initialization now needs to be a static array always present
as we need a value before we will have a BSS (node in scan_to_auth)
as the mac80211 driver (*handlers) are expecting the pointer to be
not NULL (copying without checks).
This is a pre-req to enable d3 (CONFIG_PM[_SLEEP]) in the future.

Tested by:	Tomoaki AOKI (junchoon dec.sakura.ne.jp)
Tested by:	Berislav Purgar (bpurgar gmail.com)
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-08-27 14:54:02 +00:00
Brooks Davis
c46697b9cb freebsd32_sendmsg: fix control message ABI
When a freebsd32 caller uses all or most allowed space for control
messages (MCLBYTES == 2K) then the message may no longer fit when
the messages are padded for 64-bit alignment.  Historically we've just
shrugged and said there is no ABI guarantee.  We ran into this on
CheriBSD where a capsicumized 64-bit nm would fail when called with more
than 64 files.

Fix this by not gratutiously capping size of mbuf data we'll allocate
to MCLBYTES and let m_get2 allocate up to MJUMPAGESIZE (4K or larger).
Instead of hard-coding a length check, let m_get2 do it and check for a
NULL return.

Reviewed by:	markj, jhb, emaste
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D36322
2022-08-24 18:34:39 +01:00
Emmanuel Vadot
6364180582 linuxkpi: unbreak linux_i2cbb
This is a joint work with manu.

- fixed conditions in do_i2c_transfer and i2c_transfer as linux_i2cbb
  does not set adapter->algo->master_xfer but does set
  adapter->algo_data;
- fixed parent bus specification for linux_i2cbb driver module;
- actually implemented iicbb_transfer method;
- added iicbb_pre_xfer and iicbb_post_xfer methods;
- removed unnecessary and harmful delays (and other extra logic) from
  iicbb methods as iicbb driver already has them;
- added setting of iicbb speed based on algo_data->udelay, so that iicbb
  uses correct delays;

PR:		265920
Fixes:		1961a14a47 linuxkpi: Add i2c support
MFC after:	2 weeks
Sponsored by:	Beckhoff Automation GmbH & Co. KG (manu's work)
2022-08-24 16:23:37 +03:00
Doug Moore
02d0c43c9e rb_tree: speed-up double rotation
RB_ROTATE_LEFT (and it symmetric twin) modify the rb-tree, adjusting
pointers so that what started as a proper tree ends up a proper
tree. When two consecutive rotations move the same node up the tree,
some of the pointers changed in the first rotation are immediately
changed again in the second - namely, the pointer from the rising node
to its new parent, and the pointer from that parent back to the rising
node. This change removes from RB_ROTATE macros the responsibility for
managing those two pointers, and leaves it to the code that calls for
rotations to fix up those pointers afterward. That drops a comparison
and a pair of assignments from every INSERT_COLOR or REMOVE_COLOR call
that ends in a double rotation.

A side-effect of this change is that the SWAP_CHILD macro must take as
a parameter a pointer to the node that is changing children, where it
is now computed from the old child. Since this macro is called in a
couple of places besides the RB_ROTATE macros, those calls are also
affected.

Reviewed by:	alc
MFC after:	3 weeks
Differential Revision:	https://reviews.freebsd.org/D36266
2022-08-19 18:11:29 -05:00
Emmanuel Vadot
319a4bddb0 linuxkpi: i2c: Fix 7bit/8bit addressing
Linux is using 7 bit addressing while FreeBSD uses 8 bit addresses
internally, but i2c(8) uses 7 bit address.
This confused me when originally doing the code and I thought that
0x50 was the 8bit EDID address while it's the 7bit address and since
I did all my testing using this I didn't noticed the problem.

Reported by:	avg
PR:		265920 (somewhat)
2022-08-19 14:39:16 +02:00
Bjoern A. Zeeb
8d37116489 net80211: LinuxKPI 802.11: harmonize IEEE80211_VHT_MCS_*
Rather than defining the same values in two places and having to do
conflict resulution on the name in LKPI, change the defines to an
enum in net80211.  In addition to de-duplication this also gives us
value checks in certain cases.

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Reviewed by:	adrian
Differential Revision: https://reviews.freebsd.org/D36250
2022-08-18 20:34:30 +00:00
Bjoern A. Zeeb
4a7e8c7bd4 LinuxKPI: extend kfifo to be usable
Implement some basic kfifo pieces as needed by drivers.

MFC after:	2 weeks
Reviewed by:	wulf, hselasky
Differential Revision: https://reviews.freebsd.org/D35829
2022-08-18 20:26:20 +00:00
Emmanuel Vadot
7bf65b00c6 linuxkpi: Add I2C_NAME_SIZE and I2C_MODULE_PREFIX defines
Both are needed by drm-kmod

Obtained from:	drm-kmod
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	//reviews.freebsd.org/D36212
2022-08-18 09:47:19 +02:00
Emmanuel Vadot
4b4ab8c310 linuxkpi: Add linux/vgaarb.h
Needed by drm-kmod.

Reviewed by:	bz
Obtained from:	Linux
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36104
2022-08-18 09:47:15 +02:00
Emmanuel Vadot
73e342328b linuxkpi: Add video/mipi_display.h
Needed by drm-kmod.

Reviewed by:	bz
Obtained from:	OpenBSD
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36103
2022-08-18 09:47:12 +02:00
Emmanuel Vadot
afe53d7f7a linuxkpi: acpi/video.h: Add stubs acpi_video_{register,unregister}
Needed by i915.

Reviewed by:	bz
Obtained from:	drm-kmod
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36102
2022-08-18 09:47:07 +02:00
Emmanuel Vadot
76d93395c5 linuxkpi: Add __copy_to_user_inatomic and __copy_from_user_inatomic
Reviewed by:	bz
Obtained from:	drm-kmod
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36113
2022-08-18 09:47:04 +02:00
Emmanuel Vadot
bf27839aa9 linuxkpi: Add add_taint stub
Needed by drm-kmod.

Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36112
2022-08-18 09:47:00 +02:00
Emmanuel Vadot
4b2cb13e91 linuxkpi: Add few more include in linux/kernel.h
Those are needed and also included in linux (via polution).

Reviewed by:	bz
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36111
2022-08-18 09:46:57 +02:00
Emmanuel Vadot
d4eeb02986 linuxkpi: Add a bunch of dummy include
All those are needed for drm-kmod.
Add them to base in another directory that will be append in the CFLAGS.

Reviewed by:	bz
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36110
2022-08-18 09:46:54 +02:00
Emmanuel Vadot
6d3d565316 linuxkpi: swap.h: Fix include
Add needed includes so we can use it.

Reviewed by:	bz
Fixes:	c3f4f28c63 ("linuxkpi: Add some basic swap functions")
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36109
2022-08-18 09:46:50 +02:00
Emmanuel Vadot
35b7625ed0 linuxkpi: Add stub kmem_cache_shrink
Needed by drm-kmod.

Reviewed by:	bz
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36108
2022-08-18 09:46:47 +02:00
Emmanuel Vadot
b2c860060c linuxkpi: Add asm/processor.h
Also fill the boot_cpu_data struct as drm needs it.

Reviewed by:	bz
Obtained from:	drm-kmod
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36107
2022-08-18 09:46:43 +02:00
Emmanuel Vadot
9202c95f47 linuxkpi: Add dma_{un,}map_sgtable
Variant of dma_{un,}map_sg_attrs for struct sg_table.

Reviewed by:	bz
Obtained from:	drm-kmod
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36106
2022-08-18 09:46:40 +02:00
Emmanuel Vadot
b1c82bd402 linuxkpi: Add linux/stackdepot.h
With a typedef needed by drm-kmod.

Reviewed by:	bz
Obtained from:	drm-kmod
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36105
2022-08-18 09:46:36 +02:00
Emmanuel Vadot
fd62b3fa1e linuxkpi: pgtable: Add more defines
Needed by drm-kmod

Reviewed by:	bz
Obtained from:	drm-kmod
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36101
2022-08-18 09:46:33 +02:00
Emmanuel Vadot
8828ebd6fc linuxkpi: Add sched/mm.h
With stubs needed by drm-kmod.

Obtained from:	drm-kmod
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36100
2022-08-18 09:46:29 +02:00
Emmanuel Vadot
1a6874e3a4 linuxkpi: Add refcount_dec_and_test
In Linux this takes a refcount_t argument but in linuxkpi struct kref
uses an atomic_t for the refcount and code in drm directly uses this
function with a kref so use an atomic_t here.

Reviewed by:	bz
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36099
2022-08-18 09:46:25 +02:00
Emmanuel Vadot
4370e9f1cf linuxkpi: Add for_each_sgtable_{sg,page}
Needed by drm-kmod.

Reviewed by:	bz
Obtained from:	drm-kmod
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D36098
2022-08-18 09:46:22 +02:00
Gleb Smirnoff
e7d02be19d protosw: refactor protosw and domain static declaration and load
o Assert that every protosw has pr_attach.  Now this structure is
  only for socket protocols declarations and nothing else.
o Merge struct pr_usrreqs into struct protosw.  This was suggested
  in 1996 by wollman@ (see 7b187005d1), and later reiterated
  in 2006 by rwatson@ (see 6fbb9cf860).
o Make struct domain hold a variable sized array of protosw pointers.
  For most protocols these pointers are initialized statically.
  Those domains that may have loadable protocols have spacers. IPv4
  and IPv6 have 8 spacers each (andre@ dff3237ee5).
o For inetsw and inet6sw leave a comment noting that many protosw
  entries very likely are dead code.
o Refactor pf_proto_[un]register() into protosw_[un]register().
o Isolate pr_*_notsupp() methods into uipc_domain.c

Reviewed by:		melifaro
Differential revision:	https://reviews.freebsd.org/D36232
2022-08-17 11:50:32 -07:00
Konstantin Belousov
00d17cf342 elf_note_prpsinfo: handle more failures from proc_getargv()
Resulting sbuf_len() from proc_getargv() might return 0 if user mangled
ps_strings enough. Also, sbuf_len() API contract is to return -1 if the
buffer overflowed. The later should not occur because get_ps_strings()
checks for catenated length, but check for this subtle detail explicitly
as well to be more resilent.

The end result is that p_comm is used in this situations.

Approved by:	so
Security:	FreeBSD-SA-22:09.elf
Reported by:	Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
Reviewed by:	delphij, markj
admbugs:	988
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D35391
2022-08-09 15:44:45 -04:00
Emmanuel Vadot
521abc32e2 linuxkpi: io.h: Only exclude armv6 and armv7 for asm/set_memory.h
Other arches like powerpc* needs it.

Fixes:  d387a1b4b1 ("linuxkpi: io.h: Do not include asm/set_memory.h for armv6 and armv7")
Fixes:  789dbdbb48 ("linuxkpi: Add arch_io_{reserve,free}_memtype_wc")
Sponsored by:	Beckhoff Automation GmbH & Co. KG
2022-08-08 20:22:44 +02:00
Emmanuel Vadot
d387a1b4b1 linuxkpi: io.h: Do not include asm/set_memory.h for armv6 and armv7
They do not have the same pmap api and this cannot work for those arch.

Fixes:	789dbdbb48 ("linuxkpi: Add arch_io_{reserve,free}_memtype_wc")
Sponsored by:	Beckhoff Automation GmbH & Co. KG
2022-08-08 18:55:58 +02:00
Konstantin Belousov
1b0a4974c5 thread_create(): call cpu_copy_thread() after td_pflags is zeroed
By calling the function too early we might still have the td_pflags
value cached from the previous struct thread use. cpu_copy_thread()
depends on correct value for TDP_KTHREAD at least on x86.

Reported, bisected, and tested by:	pho
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D36069
2022-08-08 19:44:17 +03:00