Commit graph

766 commits

Author SHA1 Message Date
John Baldwin
ffefb63627 linuxkpi: Add parentheses to pacify -Wparentheses warnings from GCC.
Reviewed by:	bz, emaste
Differential Revision:	https://reviews.freebsd.org/D34145

(cherry picked from commit 7043ca9140)
2022-05-10 17:06:44 -07:00
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
Bjoern A. Zeeb
5961670050 LinuxKPI: 802.11: fill in two more TODOs
Implement ieee80211_is_data_present() and a subset of
ieee80211_is_bufferable_mmpdu() which hopefully is good enough in
the compat code for now.
This is partly in preparation for some TXQ changes coming up soon.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 00614c9c2d)
2022-05-04 13:13:11 +00:00
Bjoern A. Zeeb
d5e65e74eb LinuxKPI: 802.11 ieee80211_sn_sub() fix
In ieee80211_sn_sub() we need to shift the mask before applying it.
This fixes the logic from 978f25e840.

Reported by:	J.R. Oldroyd (fbsd opal.com)
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit b3e7f403a5)
2022-05-04 13:12:54 +00: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
f71daf6a11 LinuxKPI: 802.11: start adding rate control to ieee80211_tx_status()
Start adding rate control feedback in ieee80211_tx_status() in order
for net80211 to be able to report something back (which may not
yet be the view of the firmware).  iwlwifi is reporting back an MSC 0
even with HT disabled (to be investigated) so we cannot (yet) use
the firmware/driver rate feedback directly.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 383b3e8f50)
2022-04-18 09:32:58 +00:00
Bjoern A. Zeeb
e4e2ad470e LinuxKPI: 802.11: implement ieee80211_probereq_get()
Implement ieee80211_probereq_get() needed by Realtek drivers.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit ade774b19f)
2022-04-18 09:32:58 +00: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
797188ba9a LinuxKPI: 802.11: add ieee80211_beacon_get_tim(), ieee80211_sn_sub()
Add a dummy implementation for ieee80211_beacon_get_tim().
Add the implementation for ieee80211_sn_sub().

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 978f25e840)
2022-04-14 16:38:11 +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
Bjoern A. Zeeb
7b9d8e33bc LinuxKPI: 802.11: fix RSSI (and NF)
As in 4a22cd6c4e nf and rss should be
signed and not unsigned.  Change the types in the header and while
here change a magic number to a define as done elsewhere (value does
not change).

When calculating c_rssi we need to make it relative so subtract nf.
And while here improve the debug output.

This will hopefully fix ifconfig wlanN list scan S:N output which
tools use to chose a BSSID and help net80211 internal calculations.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 60970a328e)
2022-04-05 14:47:13 +00:00
Bjoern A. Zeeb
2a8e509ba3 LinuxKPI: 802.11: fix compat code for i386
Compiling another driver on i386 revealed two problems:
- ieee80211_tx_info.status.status_driver_data space needs to be
  calculated.  While a pointer is 32bit vm_paddr_t is 64 bit on i386
  so we didn't fit more than one of these in but needed more space.
- the arguments to ieee80211_txq_get_depth() are expected to
  unsigned long and not uint64_t.

No user noticable changes.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 86220d3cbd)
2022-04-05 14:46:58 +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
4836b8ac0e LinuxKPI: 802.11: use cfg80211_chandef_create()
Rather than manually setting up a chandef and then effectively forcing
a memcpy, use cfg80211_chandef_create() to do the work for us entirely.
This works here as we do not store the resulting chandef separately
for other use.

While here remove a duplicate assignment in cfg80211_chandef_create().

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 4a07abdeb8)
2022-03-27 18:12:17 +00:00
Bjoern A. Zeeb
24c2117baf LinuxKPI: 802.11: implement ieee80211_beacon_loss()
Implement ieee80211_beacon_loss() similar to
ieee80211_connection_loss() with different state handling.
While here leave a comment in connection_loss() about the state
change argument.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit bb81db90f7)
2022-03-27 18:08:58 +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
ec504d3049 linuxkpi: Add atomic64_fetch_add
Linux variant of atomic_fetchadd_64.

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

(cherry picked from commit 1889bed23d)
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
8082bc8e57 linuxkpi: Add user_write_access_*
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/D34284

(cherry picked from commit 4f689b302f)
2022-03-05 12:12:43 +01:00