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)
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)
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)
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)
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)
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)
In sg_pcopy_from_buffer() is an error in that skip can underflow
and lead to bogus page arithmetics which may lead to memory corruption
or more likely panics. Once we found a s/g page to copy into there
is nothing to skip anymore so simply set skip to 0.
Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D30676
(cherry picked from commit edfcdffefc)
Restructure some code and add support for various "managed" versions
for PCI resource management.
This is beyond of what iwlwifi needs but some was found with other
wireless drivers and it mostly all goes together.
Add one FreeBSD sepcific feature returning the resource rather than
the handle to allow us to use bus_*() functions in drivers directly.
Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D30558
(cherry picked from commit d4a4960c65)
(cherry picked from commit 5f88df77a6)
(cherry picked from commit 539228d372)
Move request_irq() to an internal function which serves request_irq()
and the newly added request_threaded_irq() and devm_request_threaded_irq().
Likewise factor out parts of free_irq() to also be used with
devm_free_irq(). Add the storage and call to a thread_handler in case
of IRQ_WAKE_THREAD.
This is needed for the iwlwifi driver.
Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D30549
(cherry picked from commit d16b6cb178)
Add dummy functions for dealing with "HotPlug" events which we currently
do not support.
Add pci_dev_get(), pci_find_ext_capability() and pci_pme_capable().
The added pcie_find_root_port() is a bit special as we need to create
another linux pci device; for that make lkpinew_pci_dev() public
which is also helpful for other cases when we want to use the Linux
routines to check for device identifiers only and need a container
for the "bsddev" to use natively. This has proven to avoid basic
checking code for the sake of rewriting it to native field names
elsewhere. Given we cache the newly created "root" we also need to
make sure we clean it up.
Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D30521
(cherry picked from commit 8e106c5230)
dmam_pool_create() is a "managed" version of dma_pool_create() which
will cleanup everything left when the device goes away using the
devres framework. For that add an internal cleanup function to be
called from devres release.
This is used by at least one wireless driver.
Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D30520
(cherry picked from commit 2afeed13b5)
Add two new (though untested) functions to linux/device.h which are
dealing with manually managing the device/driver and are used by
at least one wireless driver. We may have to re-fine them in the
future.
Move the devres declarations further up so they can be used earlier
in the file.
Sponsored by: The FreeBSD Foundation
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D30519
(cherry picked from commit 644b4f1176)
While currently the ifp gets cast to a net_device and then returned
and consumers are expecting an ifp again, allow parallel usage now and
in the future by extending and also passing the ifp directly back in
the netdev_notifier_info. Add a function to return the ifp instead of
the net_device.
Sponsored by: The FreeBSD Foundation
Suggested by: hselasky
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D30522
(cherry picked from commit 801cf532e7)
Add HWEIGHT32() macro needed by iwlwifi and while here add the 8/16/64
variants likewise.
Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D30501
(cherry picked from commit 4cc8a9da49)
Now that mlx4 and ofed either are operating on ifnet functions
directly or have a private copy of these macros, we can remove them
from linux/netdevice.h.
With this only the #define for net_device to ifnet is left.
Sponsored by: The FreeBSD Foundation
Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D30478
(cherry picked from commit 9b6835f3ab)
This removes all unused bits from linux/netdevice.h and migrates two
inline functions into the mlx4 and ofed code respectively.
This gets the mlx4/ofed (struct ifnet) specific bits down to 7 lines
in netdevice.h.
Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky, kib
Differential Revision: https://reviews.freebsd.org/D30461
(cherry picked from commit c35034b338)
Add DECLARE_EWMA() which expands to a per-name EWMA implementation
as used by multiple wireless drivers.
Sposnored by: The FreeBSD Foundation
Reviewed by: hselasky, cperciva, dwmalone
Differential Revision: https://reviews.freebsd.org/D30415
(cherry picked from commit 32f753f270)
Add linux/bsearch.h which only includes libkern.h as the sort(9)
functions seem to be compatible.
Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D30417
(cherry picked from commit f4a145b136)
Add a definition for SMP_CACHE_BYTES and while here include sys/param.h
for CACHE_LINE_SIZE as otherwise code might not compile standalone.
Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D30419
(cherry picked from commit e21652c13c)
Add fallthrough, ____cacheline_aligned_in_smp, and smp_mb() to
linux/compiler.h.
Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D30420
(cherry picked from commit da717031c9)
Add linux/cpu.h for cpumask_*() functions found in wireless drivers
and make sure cpu_online_mask is always initialised.
Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D30421
(cherry picked from commit 5fce802722)
Add linux/devcoredump.h with stub implementation of dev_coredumpv()
and dev_coredumpsg() which only free the passed in SG table as needed
for iwlwifi.
Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D30423
(cherry picked from commit 29923fea03)
Replace the implementation for ether_addr_equal() with
ether_addr_equal_unaligned() and add a define for ether_addr_equal()
pointing to the now ether_addr_equal_unaligned() implementation.
This way ether_addr_equal_unaligned() cannot be broken by accident [1].
Suggested by: emaste [1]
Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D30425
(cherry picked from commit 834227ba6e)
Add an implementation for irq_set_affinity_hint() to linux/interrupt.h
and include linux/hardirq.h for synchronize_irq() as needed by
wireless drivers.
Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D30427
(cherry picked from commit 602e4e433d)
Add header files for struct and accessors for IPv4, UDP, and TCP.
Only parts of the fields of the structs have been seen while working
on wireless drivers. The remaining field names are filled up with
the FreeBSD field names for now. If you have insights into their
correct naming in Linux, feel free to adjust.
Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D30428
(cherry picked from commit b26fb63f2b)
This is used by wireless drivers. Use the time_after() macro as
done for the "after_eq" version.
Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D30430
(cherry picked from commit 8620fe4c10)
BUILD_BUG_ON() can be used inside functions where the definition to
CTASSERT() (_Static_assert()) seems to not work.
Go back to an old-style CTASSERT() implementation but also add a
variable dclaration to avoid "unsued typedef" errors and dummy-use
the variable to avoid "unusued variable" errors. Given it is all
self-contained in a block and not used outside this should be
optimised away.
Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D30431
(cherry picked from commit 1082490cd8)
Add yet another version of the various module_param_named() use cases.
This one deals with "charp".
Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D30433
(cherry picked from commit c1661d59e6)
Add more definitions for various PCI uses to linux/pci.h. Almost all
are defined to their FreeBSD counterparts which are described there.
Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D30434
(cherry picked from commit fc1d840901)
Add a define for rcu_dereference_check() to rcu_dereference_protected()
which ignores the check argument. Our lockdep compat implementation
for use cases found in iwlwifi would return 1 anyway.
Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D30436
(cherry picked from commit fa58da02f7)
Add linux/stringify.h as directly included by drivers. Remove the
definitions from compiler.h and include the new header in places
where the stringify macros are already used without linuxkpi.
I have adjusted the Copyright of the new file according to the commit
originaly adding the macros (99e690772a).
Sposnored by: The FreeBSD Foundation
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D30440
(cherry picked from commit 43b4c00643)
Add a placeholder struct for guid_t which is needed by ACPI consumers
in at least one wireless driver.
Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D30439
(cherry picked from commit cae1683120)
The two functions in linux/inetdevice.h are highly FreeBSD/ifnet
specific. This is a result of struct net_device being mapped to
struct ifnet.
The only known consumer of these functions are two files in the
ofed/infiniband code.
As a first step of cleaning up copy linux/inetdevice.h to
rdma/ib_addr_freebsd.h. (It stayed a separate file to preserve
copyright and license of the original file; otherwise it could be
merged into ib_addr.h where more EPOCH/vnet/.. are already used).
Slightly rename the function to not conflict with LinuxKPI
in the future.
Remove the three last, now unneeded includes of inetdevice.h and
zap linux/inetdevice.h to an empty header file with only the forward
include to netdevice.h remaining.
Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky, kib
Differential Revision: https://reviews.freebsd.org/D29434
(cherry picked from commit 7069b4c6a4)
Introduce struct netdev_notifier_info as a container to pass
net_device to the callback functions.
Adjust netdev_notifier_info_to_dev() to return the net_device field.
Add explicit casts from ifp to ni->dev even though currently
struct net_device is defined to struct ifnet. This is needed in
preparation for untangling this and improving the net_device compat
code.
Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D29365
(cherry picked from commit fdcfe8a298)
Add a net_ratelimit() compat implementation based on ppsratecheck().
Add a sysctl to allow tuning of the number of messages.
Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D29399
(cherry picked from commit bc042266b2)
We are not aware of any out-of-tree consumers anymore
which would need KPI support for before Linux version 5.
Update the two in-tree consumers to use the new KPI.
This allows us to remove the extra version check and
will also give access to {lower,upper}_32_bits() unconditionally.
Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky, rlibby, rstone
X-MFC: to 13 only
Differential Revision: https://reviews.freebsd.org/D29391
(cherry picked from commit 3b1ecc9fa1)
Add stubs for struct lockdep_map and three accessor functions
used by iwlwifi.
Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky, emaste
Differential Revision: https://reviews.freebsd.org/D29398
(cherry picked from commit f1069375d9)
brcm80211 include pci_ids.h directly while historically we were tracking
IDs in pci.h. Move the current set of IDs from pci.h to pci_ids.h and
while here add IDs for Realtek and Broadcom as well as a network class
as needed by their wireless drivers.
We still include pci_ids.h from pci.h so this should not change anything.
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D29400
(cherry picked from commit 5a402a3ae3)
Add various protocol IDs found in various wireless drivers.
Also add ETH_FRAME_LEN and struct ethhdr.
Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D29397
(cherry picked from commit 3cce818c46)
Add ERFKILL and EBADE found in iwlwifi and brcmfmac wireless drivers.
While here add a comment above the block of error numbers above 500 to
document expectations.
Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky, emaste
Differential Revision: https://reviews.freebsd.org/D29396
(cherry picked from commit 4b0632cfc5)
ieee80211_node.h uses LIST_HEAD() which LinuxKPI redefines and this
can lead to problems (see comment there). Make sure the net80211
header file is handled correctly by adding it to the list of files
to include before re-defining the macro.
Also add header files needed as dependencies.
Sponsored by: The FreeBSD Foundation
Reviewed by: philip, hselasky
Differential Revision: https://reviews.freebsd.org/D29336
(cherry picked from commit de8a7cc703)