Commit graph

706 commits

Author SHA1 Message Date
John Baldwin
e77b37914a <linux/overflow.h>: Don't use __has_builtin().
GCC only added support for __has_builtin in GCC 10.  However, all
supported versions of GCC and clang include these builtins so just use
them unconditionally.

This fixes the build with GCC 9.

Reviewed by:	manu, hselasky, imp
Differential Revision:	https://reviews.freebsd.org/D31942

(cherry picked from commit 9553c6af88)
2022-05-10 15:51:49 -07:00
Mark Johnston
097991f8ff linuxkpi: Mitigate a seqlock livelock
Disable preemption in seqlock write sections when using the _irqsave
variant.  This ensures that a writer can't be preempted and subsequently
starved by a reader running in a callout handler on the same CPU.

This fixes occasional display hangs seen when using the i915 driver.

Tested by:	emaste, wulf
Reviewed by:	wulf, hselasky
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit efb8f0b8db)
2022-05-09 08:32:09 -04:00
Alex Richardson
95c6e44054 linuxkpi: implement ida_alloc()
Needed for the virtio-gpu driver.

Reviewed By:	#linuxkpi, manu, bz, hselasky
Differential Revision: https://reviews.freebsd.org/D32366

(cherry picked from commit d98f2712c7)
2022-05-07 13:08:55 +01:00
Alex Richardson
763198cc50 linuxkpi: Allow BUILD_BUG_ON in if statements without braces
I got a compilation failure in virtio-gpu without this change.

Reviewed By:	#linuxkpi, manu, bz, hselasky
Differential Revision: https://reviews.freebsd.org/D32366

(cherry picked from commit 6d15ccde4d)
2022-05-07 13:08:46 +01:00
Alex Richardson
82b4e784f3 linuxkpi: Add sg_init_one
Needed for the virtio-gpu driver.

Reviewed By:	#linuxkpi, manu, bz, hselasky
Differential Revision: https://reviews.freebsd.org/D32366

(cherry picked from commit 2686b10db4)
2022-05-07 12:57:31 +01:00
Emmanuel Vadot
825b33fccd linuxkpi: Add for_each_sgtable_dma_sg and for_each_sgtable_dma_page
Variants of for_each_sg/for_each_sg_dma_page but they operate on sgtable
structs.
Needed by drm v5.10

MFC after:	1 week
Sponsored by:	Beckhoff Automation GmbH & Co. KG

(cherry picked from commit 1aca8a6ec6)
2022-04-27 18:38:06 +02:00
Emmanuel Vadot
5c6eeda048 linuxkpi: Implement dma_max_mapping_size
Simply returns SCATTERLIST_MAX_SEGMENT.
Needed by drm v5.10

MFC after:	1 week
Sponsored by:	Beckhoff Automation GmbH & Co. KG

(cherry picked from commit 1acf9b2770)
2022-04-27 18:38:06 +02:00
Emmanuel Vadot
a2b1b471e8 linuxkpi: Change irq_work_queue to return a bool
This was changed in Linux v5.10

MFC after:	1 week
Sponsored by:	Beckhoff Automation GmbH & Co .KG

(cherry picked from commit 2192bc3255)
2022-04-27 18:38:06 +02:00
Emmanuel Vadot
62dc9911d9 linuxkpi: Add llnode member in struct irq_work
This was added in Linux v5.8 and started to be used in drm code in v5.9

MFC after:	1 week
Sponsored by:	Beckhoff Automation GmbH & Co. KG

(cherry picked from commit 17ee6aca65)
2022-04-27 18:38:05 +02:00
Emmanuel Vadot
e6afd48804 linuxkpi: Add down_write_nest_lock
Simply calls down_write like in Linux (when CONFIG_DEBUG_LOCK_ALLOC isn't
specified)
Needed by drm v5.10

MFC after:	1 month
Reviewed by:	hselasky
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D34642

(cherry picked from commit f9413897cb)
2022-04-27 18:34:47 +02:00
Emmanuel Vadot
4a5270b3c8 linuxkpi: Add kstrtouint_from_user
Like kstrtoint_from_user but for uint.
Needed by drm v5.10

MFC after:	1 month
Reviewed by:	hselasky
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D34642

(cherry picked from commit 8e587a5f13)
2022-04-27 18:34:47 +02:00
Emmanuel Vadot
6c25e63c06 linuxkpi: Add cond_resched_lock
If we need to resched it takes the lock, resched, release the lock
and returns 1, otherwise simply returns 0.

Needed by drm v5.9

MFC after:	1 month
Reviewed by:	hselasky
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D34620

(cherry picked from commit 9b8016548e)
2022-04-27 18:34:47 +02:00
Bjoern A. Zeeb
c39947cdd3 LinuxKPI: skbuff: start implementing skb_copy()
Implement skb_copy() with omissions of fragments and possibly other fields
for now.  Should we hit frags at any point a log message will let us know.
For the few cases we need this currently this is enough.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 349b042b90)
2022-04-18 09:32:58 +00:00
Bjoern A. Zeeb
bfa2e8f840 LinuxKPI: skbuff: dev_kfree_skb_irq() and improvements
While it is currently unclear if we will have to defer work in
dev_kfree_skb_irq() to call dev_kfree_skb().
We only have one caller which seems to be fine on FreeBSD by calling
it directly for now.

While here shortcut skb_put()/skb_put_data() saving us work if there
are no adjustments to do.
Also adjust the logging in skb_is_gso() to avoid getting spammed by it.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 952643ea45)
2022-04-18 09:32:57 +00:00
Bjoern A. Zeeb
94b9567f75 LinuxKPI: add ALIGN_DOWN()
Add ALIGN_DOWN as rounddown2() along ALIGN() which is implemented as
roundup2().

Sponsored by:	The FreeBSD Foundation
Reviewed by:	manu, hselasky (now with less ())
Differential Revision: https://reviews.freebsd.org/D34844

(cherry picked from commit 97f2e93a66)
2022-04-14 16:38:16 +00:00
Bjoern A. Zeeb
48e84cceac LinuxKPI: skbuff: handle dev_alloc_skb() correctly
dev_alloc_skb() comapred to alloc_skb() reserves some headroom
at the beginning of the skb which is used by drivers.
Split the code for the two cases and reserve NET_SKB_PAD space,
which should at least be 32 octets.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 9df5f29caf)
2022-04-14 16:38:01 +00:00
Warner Losh
4e94b3542d linuxkpi: move io_mapping_create_wc to .c
Move io_mapping_create_wc to .c because it encodes the size of struct
io_mapping so we move this from the client module to the linuxkpi
module.

Sponsored by:		Netflix
Reviewed by:		hselasky, emaste
Differential Revision:	https://reviews.freebsd.org/D34776

(cherry picked from commit 132b00f906)
2022-04-05 08:40:11 -06:00
Warner Losh
211621030e linuxkpi: Move lkpi_pcim_iomap_devres_find to .c file
lkpi_pcim_iomap_devres_find encodes the size of struct pcim_iomap_devres
in the code, so move from .h to .c to move from client driver to
linuxkpi module.

Sponsored by:		Netflix
Reviewed by:		hselasky
Differential Revision:	https://reviews.freebsd.org/D34775

(cherry picked from commit 2bf3361d56)
2022-04-05 08:40:11 -06:00
Warner Losh
bc01b38394 linuxkpi: Move pci_alloc_irq_vectors to .c file
pci_alloc_irq_vectors encodes the size of struct msix_entry
into its code. Move from .h to .c to move this knowledge from
client modules to linuxkpi module.

Sponsored by:		Netflix
Reviewed by:		hselasky
Differential Revision:	https://reviews.freebsd.org/D34774

(cherry picked from commit 36b5c44002)
2022-04-05 08:40:11 -06:00
Warner Losh
4859994c42 linuxkpi: Move pci_request_region and _lkpi_pci_iomap into .c
Both pci_request_region and _lkpi_pci_iomap encode the size of struct
pci_mmio_region into their code. Move from .h to .c files to move that
knowledge from the client drivers into the linuxkpi module.

Sponsored by:		Netflix
Reviewed by:		hselasky
Differential Revision:	https://reviews.freebsd.org/D34773

(cherry picked from commit 1cdb25340f)
2022-04-05 08:40:11 -06:00
Warner Losh
2cd55de380 linuxkpi: Move lkpi_pci_devres_get_alloc into .c file
lkpi_pci_devres_get_alloc encodes the struct pci_devres into its
code. Move from .h file to .c file to move this knowledge into linuxkpi
module.

Sponsored by:		Netflix
Reviewed by:		hselasky, emaste
Differential Revision:	https://reviews.freebsd.org/D34772

(cherry picked from commit 3ea682e21e)
2022-04-05 08:40:10 -06:00
Warner Losh
d1f93d6721 linuxkpi: Move cdev_alloc into .c file
Move cdev_alloc into linux_compat.c since it encodes the size of struct
linux_cdev into the client modules otherwise.

Sponsored by:		Netflix
Reviewed by:		hselasky, emaste
Differential Revision:	https://reviews.freebsd.org/D34771

(cherry picked from commit aca0bcbca3)
2022-04-05 08:40:10 -06:00
Warner Losh
98d2b4a158 linuxkpi: Move class_create to .c file
class_create encodes the size of struct class into the generated
code. Move from .h file to .c file to move this knowledge from the
client modules that call this into the linuxkpi module.

Sponsored by:		Netflix
Reviewed by:		hselasky, emaste
Differential Revision:	https://reviews.freebsd.org/D34769

(cherry picked from commit 1341ac9f9c)
2022-04-05 08:40:10 -06:00
Warner Losh
417f1c8149 linuxkpi: Move device_create_groups_vargs to linux_compat.c
device_create_groups_vargs encodes the size of struct device. Move
definition from .h to .c to move this size into the linuxkpi module
rather than encoding it in all client driver modules.

Sponsored by:		Netflix
Reviewed by:		hselasky, emaste
Differential Revision:	https://reviews.freebsd.org/D34768

(cherry picked from commit 702b687503)
2022-04-05 08:40:10 -06:00
Warner Losh
2f3d11894b linuxkpi: move kobject_create to .c file
kobject_create knows the size of struct kobject. Move it to
linux_compat.c so this knowledge is confined to the loadable module and
not the clients.

Sponsored by:		Netflix
Reviewed by:		hselasky, emaste
Differential Revision:	https://reviews.freebsd.org/D34767

(cherry picked from commit 36929b5584)
2022-04-05 08:40:10 -06:00
Warner Losh
86d5c66106 linuxkpi: add padding to struct pci_driver
Add 32 or 64 bytes of padding to struct pci_driver at the end in the
_spare field like we should have done when we branched stable/13, but
neglected to do so since we didn't properly anticipate the need.

We cannot safely use these spare fields until after 13.0 EOL since
drivers compiled on 13.0 won't have that space reserved and we'll step
on something else using them. This isn't 100% KBI compatible through the
13.x release branch, but is compatible enough so that drm packages built
on the oldest supported release will work on the latest stable/13 and
any newer releases. It's not ideal, but makes the best of a bad
situation and is a pragmatic approach that belatedly builds in some
future proofing.

Direct commit to stable/13 because this is not relevant to main in this
exact form.

Sponsored by:		Netflix
Reviewed by:		bz
Differential Revision:	https://reviews.freebsd.org/D34754
2022-04-04 22:54:49 -06:00
Warner Losh
aa61c28b42 linuxkpi: Restore the KBI for struct pci_driver
The size of the 13.0 version of struct pci_driver was 92 or 184 bytes on
32- or 64-bit systems respectively. We recently added bsd_probe_return
at the end of this struct, breaking the KBI on the stable/13 branch.

Fix this by removing the isdrm member. We don't need it because we can
do a strcmp in the few places that need it as they aren't performance
critical. Move the newly added bsd_probe_return to that slot. It's the
same size in all our supported KBIs as bool and fits into that slot due
to padding rules.

Direct commit to stable/13 because this is not relevant to main.

Sponsored by:		Netflix
Reviewed by:		bz
Differential Revision:	https://reviews.freebsd.org/D34754
2022-04-04 22:48:27 -06:00
Bjoern A. Zeeb
e269958566 LinuxKPI: 802.11: cleanup debugging
Cleanup some debugging.  Rename the global variable to be less
generic.  Hide all debugging behind #ifdef for now and turn off.
Rename the debugging sysctl so we can start adding more to the
subtree.

There is a need to change that wildly grown infrastructure into
something more homogenic soon but this should do for 13.1.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 9d9ba2b79b)
2022-03-27 18:13:00 +00:00
Bjoern A. Zeeb
32d1d7fee6 LinuxKPI: skbuff: fix skb_queue_splice_init()
In skb_queue_splice_init() we set a next value and then used that new
value to further update the remaining linking rather than the original
value.  Introduce another temporary variable 'n' to hold the original
value and use that.
While here rename q and h to from and to as otherwise it was too
confusing to read.

Also initialize skb->prev and skb->next to point to skb itself if
for nothing else at least to aid debugging.

Reported by:	phk (panic in iwl_txq_reclaim)
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 6a8973c332)
2022-03-27 18:08:53 +00:00
Bjoern A. Zeeb
5013623384 LinuxKPI: pci: implement pci_upstream_bridge()
Allow drivers to query the "upstream PCI bridge".
Currently we point back to ourselves on pdev->bus->self rather than
to the parent PCI bridge.
We keep this as status-quo with an extra comment and only on-demand
allocate a pci_dev for the parent bridge if we are asked for in
pci_upstream_bridge().
When releasing the pci_dev we check if pdev->bus->self has changed
and call pci_dev_put() to release the reference count on the parent
bridge as well.

This code moves pci_is_root_bus() higher up in pci.h but no functional
change there.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	hselasky, (jhb some earlier)
Thanks to:	wulf for handling drm-kmod
Differential Revision: https://reviews.freebsd.org/D34305

(cherry picked from commit b3b836251f)
2022-03-27 18:08:35 +00:00
Bjoern A. Zeeb
a94b233d5d LinuxKPI: pci.h MODULE_DEVICE_TABLE to MODULE_PNP_INFO
Implement MODULE_PNP_INFO() support in LinuxKPI for the Linux
MODULE_DEVICE_TABLE.

This will allow us to auto-load LinuxKPI PCI drivers (drm-kmod do
not currently as they attach to vgapci0 which in turn grabs the PCI
to my understanding) and make any loading from loader or kld_list in
rc.conf unnecessary; see devmatch(8) for more information.

We need to ensure there is a DRIVER_MODULE() (or probably just
a DECLARE_MODULE but that makes not much difference) before the
MODULE_PNP_INFO (which we otherwise would not need).

Sponsored by:	The FreeBSD Foundation
Reviewed by:	imp, hselasky, manu
Differential Revision:	https://reviews.freebsd.org/D26651

(cherry picked from commit 5493c6277a)
2022-03-27 18:08:08 +00:00
Bjoern A. Zeeb
3166cea632 LinuxKPI: allow a driver to override the default pci probe result
Add bsd_probe_return which a driver can set in their 'struct pci_driver'
definition to set a driver-sepcific LinuxKPI pci return value.
This is helpful in case of multiple drivers with overlapping IDs,
such as iwlwifi(4) and iwm(4).

Contrary to an earlier version we now assume 0 is not BUS_PROBE_SPECIFIC
(which no driver should really return these days) but the bss initialized
value (bsd_probe_return unset) and we will return BUS_PROBE_DEFAULT.

Suggested by:	jhb
Reviewed by:	jhb
Reviewed by:	hselasky, imp (earlier versions)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33915

(cherry picked from commit b91dd79ba3)
2022-03-27 18:06:33 +00:00
Bjoern A. Zeeb
a8c3d6b716 LinuxKPI: remove duplicate include
Remove a duplicate bus.h include from pci.h.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit fbedd9d708)
2022-03-27 18:05:00 +00:00
Hans Petter Selasky
d17c5a4f62 LinuxKPI: Add comment describing proper use of the on_each_cpu() function.
Sponsored by:		NVIDIA Networking

(cherry picked from commit c6cf874c7d)
2022-03-17 10:55:15 +01:00
Emmanuel Vadot
61b0043efb linuxkpi: Add mmap_lock.h
This contain mmap_read_lock, mmap_read_unlock and mmap_write_lock_killable
which are abstraction around down_read, up_read and down_write_killable.
Note that in Linux 5.8 mmap_sem was renamed to mmap_lock.
We might want to do the same at some point but some drivers still uses
the old mmap locking API.

Reviewed by:	bz
MFC after:	2 weeks
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D34297

(cherry picked from commit 995c3b88d4)
2022-03-05 12:12:44 +01:00
Emmanuel Vadot
db4c095026 linuxkpi: Add orderly_poweroff
This simply poweroff the system.
Needed by drm-kmod v5.8

Reviewed by:	bz
MFC after:	2 weeks
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D34287

(cherry picked from commit 8021ba6723)
2022-03-05 12:12:44 +01:00
Emmanuel Vadot
3d148ca784 linuxkpi: Add dev_emerg
Needed by drm-kmod v5.8

Reviewed by:	bz
MFC after:	2 weeks
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D34286

(cherry picked from commit e3f1af9b33)
2022-03-05 12:12:44 +01:00
Emmanuel Vadot
78281dd986 linuxkpi: Add backlight_device_set_brightness
This simply set the brightness of a backlight device.
Needed by drm-kmod v5.8

Reviewed by:	bz, emaste
MFC after:	2 weeks
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D34285

(cherry picked from commit 2cc3af6e1d)
2022-03-05 12:12:44 +01:00
Emmanuel Vadot
48df337c9e linuxkpi: Add list_rotate_to_front
This just calls list_move_tail.

Reviewed by:	hselasky, bz
Sponsored by:	Beckhoff Automation GmbH & Co. KG
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D34251

(cherry picked from commit bf7deecfe7)
2022-03-05 12:12:43 +01:00
Emmanuel Vadot
090eb6f388 linuxkpi: Add __var_waitqueue
This returns the wait queue based on the object but in LinuxKPI
we only have one waitqueue for this.

Reviewed by:	hselasky, bz
MFC after:	2 weeks
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D34250

(cherry picked from commit cb15ed7da2)
2022-03-05 12:12:43 +01:00
Bjoern A. Zeeb
e596e01cc9 LinuxKPI: update 802.11 headers
Add new defines, struct members, and (stub) functions needed for an
updated iwlwifi.  Most of the defines are for rfkill or HE.

Pull in a case statement from the upcoming iwlwifi update to
not break the build.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit d875aa1587)
(cherry picked from commit 9ad210c159)
2022-02-27 23:41:54 +00:00
Bjoern A. Zeeb
4605fd58a3 LinuxKPI: change DECLARE_FLEX_ARRAY()
DECLARE_FLEX_ARRAY can be used inside a structure.  On FreeBSD due to
-Wgnu-variable-sized-type-not-at-end this yields an error.  Use [0]
instead of [] to overcome this.

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

(cherry picked from commit fab601c5b7)
2022-02-27 23:41:54 +00:00
Bjoern A. Zeeb
7d510d1398 LinuxKPI: add MODULE_IMPORT_NS()
Add dummy MODULE_IMPORT_NS() used by an updated iwlwifi.

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

(cherry picked from commit f6fb9b524f)
2022-02-27 23:41:54 +00:00
Bjoern A. Zeeb
d3caff9be6 LinuxKPI: skbuff.h add skb_postpush_rcsum()
Add a stub for skb_postpush_rcsum() needed by an updated iwlwifi.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit a3e07b6ef3)
2022-02-27 23:41:54 +00:00
Bjoern A. Zeeb
ddcb65c526 LinuxKPI: implement dma_sync_single_for_*, apply to (un)map single/sg
Implement dma_sync_single_for_{cpu,device} translating the Linux
DMA_ flags to BUS_DMASYNC_ combinations.  Make map_single/unmap_single*
functions call the respective sync function.   Apply the same logic to
the scatter-gather list map/unmap functions.

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

(cherry picked from commit 95edb10b47)
2022-02-20 16:26:01 +00:00
Bjoern A. Zeeb
6ddbe66d02 LinuxKPI: 802.11 header updates and add/adjust source dependencies.
This update is for more/newer versions of drivers:
- add and properly place more structs, enums, defines needed by drivers.
- correct types of struct fields.
- make various function arguments const.
- move REG_RULE() macro to its own file regulatory.h and
  use macros for calculations.
- add linuxkpi_ieee80211_get_channel() implementation.
- change linuxkpi_ieee80211_ifattach() to return int for error checking.

No intended functional changes for iwlwifi.

Sponsored by:	The FreeBSD Foundation (partially)

(cherry picked from commit 2e183d999c)
2022-02-20 16:25:43 +00:00
Bjoern A. Zeeb
5221620a8b LinuxKPI: skbuff updates
Various updates to skbuff for new/updated drivers and some housekeeping:
- update types and struct members, add new (stub) functions
- improve freeing of frags.
- fix an issue with sleeping during alloc for dev_alloc_skb().
- Adjust a KASSERT for skb_reserve() which apparently can be called
  multiple times if no data was put into the skb yet.
- move the sysctl from linux_8022.c (which may be in a different module)
  to linux_skbuff.c so in case we turn debugging on we do not run into
  unresolved symbols.  Rename the sysctl variable to be less conflicting
  and update debugging macros along with that; also add IMPROVE().
- add DDB support to show an skbuff.
- adjust comments/whitespace.

No functional changes intended for iwlwifi.

Sponsored by:	The FreeBSD Foundation (partially)

(cherry picked from commit 6baea3312d)
2022-02-20 16:25:37 +00:00
Bjoern A. Zeeb
0422c15541 LinuxKPI: pci.h add more defines
Add and sort in more defines needed by newer drivers.

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

(cherry picked from commit c4f52f71de)
2022-02-20 16:25:13 +00:00
Bjoern A. Zeeb
a108252a71 LinuxKPI: lockdep add lockdep_assert_not_held()
Add lockdep_assert_not_held() asserting LA_UNLOCKED as needed by a
driver.

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

(cherry picked from commit 064c110f4b)
2022-02-20 16:25:03 +00:00
Bjoern A. Zeeb
c3ffeddb47 LinuxKPI: add kstrtoint_from_user() and DECLARE_FLEX_ARRAY()
Add an implementation of kstrtoint_from_user() based on the other
implementations and an attempt at DECLARE_FLEX_ARRAY() which works
for the driver needing it.

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

(cherry picked from commit c840d5cec2)
2022-02-20 16:24:51 +00:00