Commit graph

39042 commits

Author SHA1 Message Date
Alexander Motin
0e6969a0f4 nvme(4): Add MSI and single MSI-X support.
If we can't allocate more MSI-X vectors, accept using single shared.
If we can't allocate any MSI-X, try to allocate 2 MSI vectors, but
accept single shared.  If still no luck, fall back to shared INTx.

This provides maximal flexibility in some limited scenarios.  For
example, vmd(4) does not support INTx and can handle only limited
number of MSI/MSI-X vectors without sharing.

MFC after:	1 week

(cherry picked from commit e3bdf3da76)
2021-09-06 21:24:54 -04:00
Alexander Motin
d9cacf0b66 nvme(4): Do not panic on admin queue construct error.
MFC after:	1 week

(cherry picked from commit 31111372e6)
2021-09-06 21:24:53 -04:00
Alexander Motin
a996b55ab3 mpr(4): Fix unmatched devq release.
Before this change devq was frozen only if some command was sent to
the target after reset started, but release was called always.  This
change freezes the devq immediately, leaving mprsas_action_scsiio()
check only to cover race condition due to different lock devq use.

This should also avoid unnecessary requeue of the commands, creating
additional log noise and confusing some broken apps.

MFC after:	2 weeks
Sponsored by:	iXsystems, Inc.

(cherry picked from commit 9781c28c6d)
2021-09-02 20:35:27 -04:00
Alexander Motin
0149aaeb8f mpr(4): Handle mprsas_alloc_tm() errors on device removal.
SAS9305-16e with firmware 16.00.01.00 report HighPriorityCredit of
only 8, while for comparison some other combinations I have report
100 or even 128.  In case of large JBOD detach requirement to send
target reset command to each target same time overflows the limit,
and without adequate handling makes devices stuck in half-detached
state, preventing later re-attach.

To handle that in case of allocation error mark the target with new
MPRSAS_TARGET_TOREMOVE flag, and retry the removal attempt next time
something else free high priority command.  With this patch I can
successfully detach/attach 102 disk JBOD from/to the SAS9305-16e.

MFC after:	2 weeks
Sponsored by:	iXsystems, Inc.

(cherry picked from commit e3c5965c25)
2021-09-02 20:35:27 -04:00
Warner Losh
a2784b47e4 mpr/mps: Minor state machine fix
When a DMA chain can't be loaded, set the state to STATE_INQUEUE so that
the mp[rs]_complete_command can properly fail the command.

Sponsored by:		Netflix

(cherry picked from commit 33755dbb20)
2021-09-02 20:34:22 -04:00
Kenneth D. Merry
8a6e5ade16 Fix mpr(4) and mps(4) state transitions and a use-after-free panic.
When the mpr(4) and mps(4) drivers probe a SATA device, they issue an
ATA Identify command (via mp{s,r}sas_get_sata_identify()) before the
target is fully setup in the driver.  The drivers wait for completion of
the identify command, and have a 5 second timeout.  If the timeout
fires, the command is marked with the SATA_ID_TIMEOUT flag so it can be
freed later.

That is where the use-after-free problem comes in.  Once the ATA
Identify times out, the driver sends a target reset, and then frees any
identify commands that have timed out.  But, once the target reset
completes, commands that were queued to the drive are returned to the
driver by the controller.

At that point, the driver (in mp{s,r}_intr_locked()) looks up the
command descriptor for that particular SMID, marks it CM_STATE_BUSY and
sends it on for completion handling.

The problem at this stage is that the command has already been freed,
and put on the free queue, so its state is CM_STATE_FREE.  If INVARIANTS
are turned on, we get a panic as soon as this command is allocated,
because its state is no longer CM_STATE_FREE, but rather CM_STATE_BUSY.

So, the solution is to not free ATA Identify commands that get stuck
until they actually return from the controller.  Hopefully this works
correctly on older firmware versions.  If not, it could result in
commands hanging around indefinitely.  But, the alternative is a
use-after-free panic or assertion (in the INVARIANTS case).

This also tightens up the state transitions between CM_STATE_FREE,
CM_STATE_BUSY and CM_STATE_INQUEUE, so that the state transitions happen
once, and we have assertions to make sure that commands are in the
correct state before transitioning to the next state.  Also, for each
state assertion, we print out the current state of the command if it is
incorrect.

mp{s,r}.c:      Add a new sysctl variable, dump_reqs_alltypes,
                that controls the behavior of the dump_reqs sysctl.
                If dump_reqs_alltypes is non-zero, it will dump
                all commands, not just the commands that are in the
                CM_STATE_INQUEUE state.  (You can see the commands
                that are in the queue by using mp{s,r}util debug
                dumpreqs.)

                Make sure that the INQUEUE -> BUSY state transition
                happens in one place, the mp{s,r}_complete_command
                routine.

mp{s,r}_sas.c:  Make sure we print the current command type in
                command state assertions.

mp{s,r}_sas_lsi.c:
                Add a new completion handler,
                mp{s,r}sas_ata_id_complete.  This completion
                handler will free data allocated for an ATA
                Identify command and free the command structure.

                In mp{s,r}_ata_id_timeout, do not set the command
                state to CM_STATE_BUSY.  The command is still in
                queue in the controller.  Since we were blocking
                waiting for this command to complete, there was
                no completion handler previously.  Set the
                completion handler, so that whenever the command
                does come back, it will get freed properly.

                Do not free ATA Identify commands that have timed
                out in mp{s,r}sas_add_device().  Wait for them
                to actually come back from the controller.

mp{s,r}var.h:   Add a dump_reqs_alltypes variable for the new
                dump_reqs_alltypes sysctl.

                Make sure we print the current state for state
                transition asserts.

This was tested in the Spectra Logic test bed (as described in the
review), as well Netflix's Open Connect fleet (where panics dropped from
a dozen or two a month to zero).

Reviewed by:		imp@ (who is handling the commit with ken's OK)
Sponsored by:		Spectra Logic
Differential Revision:	https://reviews.freebsd.org/D25476

(cherry picked from commit 175ad3d003)
2021-09-02 20:33:28 -04:00
Gordon Bergling
aa9d47d9de Fix a common typo in man pages and src comments
- s/desciptor/descriptor/

(cherry picked from commit b1603638e3)
2021-09-02 08:13:48 +02:00
Alexander Motin
c4bd6b589c pcib(4): Write window registers after resource adjustment
When adjusting resources we should write updated window base/limit into
the registers.  Without this newly added address range won't be routed
through the bridge properly.

Use MIN()/MAX() against current window base/limit to not shrink it on
the other side if the window is shared by several resources.

Align passed resource start/end to the set window granularity to keep
it properly aligned.  Currently this is mostly called by other bridges
having the same window alignment, but it may be change one day.

Reviewed by:	jrtc27, jhb
MFC after:	1 week
Sponsored by:	iXsystems, Inc.
Differential Revision: 	https://reviews.freebsd.org/D31693
2021-09-01 16:55:13 -04:00
Jessica Clarke
8ee90cc8d3 pci_pci: Support growing windows in bus_adjust_resource for NEW_PCIB
If we allocate a new window for a bridge rather than reusing an existing
one set up by firmware to cover all the devices then the new window only
includes the range needed for the first device to allocate the resource.
If a request comes in to adjust this resource in order to extend a
downstream window for another device then this will fail as the rman
doesn't have any space, so we must first grow the bridge's own window.

This is needed to support successfully attaching more than one PCI
device on SiFive's HiFive Unmatched, which has the following topology:

  Root Port <---> Bridge <---> Bridge <-+-> Bridge <---> (Unused)
   (pcib0)        (pcib1)      (pcib2)  |   (pcib3)
                                        +-> Bridge <---> xHCI
                                        |   (pcib4)
                                        +-> Bridge <---> M.2 E-key
                                        |   (pcib5)
                                        +-> Bridge <---> M.2 M-key
                                        |   (pcib6)
                                        +-> Bridge <---> x16 slot
                                            (pcib7)

Without this, the xHCI endpoint successfully attaches but NVMe M.2 M-key
endpoint fails to attach as, when its adjacent bridge (pcib6) attempts
to allocate a window from its parent (pcib2) on the other side of the
switch, its parent attempts to grow its own window by calling
bus_adjust_resource on its own parent (pcib1) which fails to call the
root port device (pcib0) to request more memory to grow its own window.
Had the root port been directly connected to the switch without the
bridge in the middle then the existing code would have worked, but the
extra hop broke it.

Reviewed by:	jhb
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D31035
2021-09-01 16:55:13 -04:00
Gordon Bergling
52237be90c isci(4): Fix a common typo in src comments
- s/exlusive/exclusive/

(cherry picked from commit 2dfcc3a91d)
2021-09-01 06:34:00 +02:00
Gordon Bergling
70af7d622c Fix a common typo in source code comments
- s/concurently/concurrently/

(cherry picked from commit 5d785ad65e)
2021-09-01 06:33:35 +02:00
Gordon Bergling
dbb74dd891 Fix some common typos in source code comments
- s/priviledged/privileged/
- s/funtion/function/
- s/doens't/doesn't/
- s/sychronization/synchronization/

(cherry picked from commit 5bdf58e196)
2021-08-31 08:13:15 +02:00
Gordon Bergling
1c327515a9 sound(4): Fix some common typos in comments
- s/doens't/doesn't/
- s/apropriate/appropriate/
- s/intepretation/interpretation/

(cherry picked from commit 58d868c88d)
2021-08-31 08:12:40 +02:00
Alfredo Dal'Ava Junior
7e583075a4 virtio-modern: fix PCI common read/write functions on big endian targets
Virtio modern has the common data organized in little endian, but
on powerpc64 BE it was reading and writing in the wrong endian.

Submitted by:	Leonardo Bianconi <leonardo.bianconi@eldorado.org.br>
Reviewed by:	bryanv, alfredo
Sponsored by:	Eldorado Research Institute (eldorado.org.br)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D28947

(cherry picked from commit fb53b42e36)
2021-08-30 13:14:20 -03:00
Mark Johnston
9d3454e1e1 pci: Add an ioctl to perform I/O to BARs
This is useful for bhyve, which otherwise has to use /dev/io to handle
accesses to I/O port BARs when PCI passthrough is in use.

Reviewed by:	imp, kib
Discussed with:	jhb
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 7e14be0b07)
2021-08-29 12:39:42 -04:00
Kevin Bowling
8b043521b4 intel ethernet: Use ether_gen_addr(9)
Use ether_gen_addr(9) for VF MAC generation

Reviewed by:	Intel Networking (erj), kevans
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D31616

(cherry picked from commit 0e5811a2a9)
2021-08-26 18:33:48 -07:00
Kevin Bowling
524ea0dea9 e1000: Update intel shared code
Sync the e1000 shared code with DPDK shared code
"cid-gigabit.2020.06.05.tar.gz released by ND"

Primary focus was on client platforms (ich8lan). More work remains here
but we need an Intel contact for client networking.

Reviewed by:	grehan, Intel Networking (erj, earlier rev)
Obtained from:	DPDK <http://git.dpdk.org/dpdk/tree/drivers/net/e1000/base>
MFC after:	1 week
Sponsored by:	me
Differential Revision:	https://reviews.freebsd.org/D31547

(cherry picked from commit fc7682b17f)
2021-08-25 17:31:17 -07:00
Alexander Motin
2daa57cafb Mark some sysctls as CTLFLAG_MPSAFE.
MFC after:	2 weeks

(cherry picked from commit b776de6796)
2021-08-24 21:53:18 -04:00
Alexander Motin
17c83ffd10 ntb_hw_intel(4): Add CTLFLAG_MPSAFE flags.
I should have added those in 50f16247a1.

MFC after:	2 weeks

(cherry picked from commit 94feb1f1eb)
2021-08-23 22:35:30 -04:00
Alexander Motin
a58ed3b4f4 ntb_hw_intel(4): Remove CTLFLAG_NEEDGIANT flags.
Most of the sysctls just read hardware registers.  They don't need
any locking.

MFC after:	2 weeks

(cherry picked from commit 50f16247a1)
2021-08-23 22:29:46 -04:00
Alexander Motin
ccda3e7069 ntb_transport(4): Mark callouts MP-safe.
The only thing around NTB using Giant lock is NewBus, and these callouts
have nothing to do with it.

MFC after:	2 weeks

(cherry picked from commit c6902e7796)
2021-08-23 22:29:46 -04:00
Kevin Bowling
784459fc16 ixgbe: Avoid sbuf_trim(9) in sysctl handler
This was an error, we cannot use sbuf_trim(9) in the
ixgbe_sbuf_fw_version function because it also gets called in
the context of sbuf_new_for_sysctl(9). sbuf(9) explains the interaction
with drain functions as used by sbuf_new_for_sysctl(9).

Reviewed by:	imp
Fixes:		7660e4ea5c
MFC after:	1 day
Differential Revision:	https://reviews.freebsd.org/D31633

(cherry picked from commit 5de5419b5e)
2021-08-23 17:50:02 -07:00
Vladimir Kondratyev
04a49585bb evdev: Use bit_foreach helper macro
for traversing all bits set in the bitstring(9).

While here move bit_change() definition to common header.

(cherry picked from commit 5f99ae56c9)
2021-08-24 01:23:41 +03:00
Vladimir Kondratyev
290677c3d6 hms(4): Allow attachment to pointer top level collection.
to be in line with Microsoft mouse driver [1]

[1] https://docs.microsoft.com/en-us/windows-hardware/drivers/hid/top-level-collections-opened-by-windows-for-system-use

(cherry picked from commit 9b78891df1)
2021-08-24 01:22:43 +03:00
Vladimir Kondratyev
bb5eb85e5c ps4dshock(4): Fix touchpad width in HID report descriptor
(cherry picked from commit 9b2b5f42b4)
2021-08-24 01:22:13 +03:00
Greg V
2de8a0d209 hid: move proper hat switch handling from ps4dshock to hgame
Generic "DirectInput" HID gamepads need this handling too.

Reviewed by:	wulf

(cherry picked from commit 51b2216114)
2021-08-24 01:21:49 +03:00
Jack
6c8f2d24d4 hmt(4): Do not ignore constant usages in HID report descriptor parser
This fixes hmt to work with MELF0411 1FD2:7012 touchscreen

Obtained from:	sysutils/iichid

(cherry picked from commit cb910670ac)
2021-08-24 01:21:24 +03:00
Vladimir Kondratyev
a711310d2d hid: Add extra constant to units of measurement
Some devices like eGalax touchscreens use value of 0x33 instead of 0x13
for inches as unit of measure.

Reported by:	Mark Kane <mark_AT_kane_DOT_mn>

(cherry picked from commit be75951af1)
2021-08-24 01:20:30 +03:00
Vladimir Kondratyev
ec86cee5db evdev: Do not check maximal contact number for MT initialization
This allows singletouch devices which use multitouch protocols to work.

Reported by:	Mark Kane <mark_AT_kane_DOT_mn>

(cherry picked from commit e40fec4ec9)
2021-08-24 01:20:06 +03:00
Vladimir Kondratyev
5517f7f9e7 hmt(4): Store Contact Count in separate variable.
No functional changes.

(cherry picked from commit 95add157e3)
2021-08-24 01:19:43 +03:00
Kevin Bowling
1a72c3d76a e1000: always enable PCSD when RSS hashing
To enable RSS hashing in the NIC, the PCSD bit must be set.

By default, this is never set when RXCSUM is disabled - which
causes problems higher up in the stack.

While here improve the RXCSUM flag assignments when enabling or
disabling IFCAP_RXCSUM.

See also: https://lists.freebsd.org/pipermail/freebsd-current/2020-May/076148.html

Reviewed by:	markj, Franco Fichtner <franco@opnsense.org>,
		Stephan de Wit <stephan.dewt@yahoo.co.uk>
Obtained from:	OPNsense
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D31501
Co-authored-by: Stephan de Wit <stephan.dewt@yahoo.co.uk>
Co-authored-by: Franco Fichtner <franco@opnsense.org>

(cherry picked from commit 69e8e8ea3d)
2021-08-23 09:23:43 -07:00
Konstantin Belousov
1ff28f8a0d coretemp: use x86_msr_op for thermal MSR access
(cherry picked from commit 4cc6fe1e5b)
2021-08-23 12:24:40 +03:00
Konstantin Belousov
56f6a96f93 x86_msr_op: extend the KPI to allow MSR read and single-CPU operations
(cherry picked from commit d0bc4b4666)
2021-08-23 12:24:39 +03:00
Alexander Motin
66e088e12b kbdmux(4): Make callout handler mpsafe.
Both callout and taskqueue now have drain() routines not requiring
external locking.  It allows to remove TASK flag and manual drain,
so the only thing remaining for lock to protect inside the callout
handler is ks_inq_length zero comparison, that can be lockless.

MFC after:	2 weeks

(cherry picked from commit e5018628e7)
2021-08-21 20:27:25 -04:00
Gordon Bergling
af89e052b9 Fix a typo that was introduced while fixing a typo
- s/enrtry/entry/

(cherry picked from commit 646f3a36c8)
2021-08-19 14:32:05 +02:00
Gordon Bergling
ab4864fba2 Fix some common typos in source code comments
- s/struture/structure/
- s/structre/structure/

(cherry picked from commit 17db4b52fb)
2021-08-19 09:28:06 +02:00
Gordon Bergling
ac7cf0c636 Fix a few typos in source code comments
- s/procesing/processing/

(cherry picked from commit 288e553623)
2021-08-19 09:27:34 +02:00
Gordon Bergling
ca2e359c02 Fix a common typo in a comment
- s/enrty/entry/

(cherry picked from commit 86b74b7368)
2021-08-19 09:26:58 +02:00
Gordon Bergling
f296898fb7 Fix a common typo in source code comments
- s/aligment/alignment/

(cherry picked from commit a1581cd735)
2021-08-19 09:18:35 +02:00
Kevin Bowling
15b57cbfde e1000: rctl/srrctl buffer size init, rfctl fix
Simplify the setup of srrctl.BSIZEPKT on igb class NICs.
Improve the setup of rctl.BSIZE on lem and em class NICs.
Don't try to touch rfctl on lem class NICs.
Manipulate rctl.BSEX correctly on lem and em class NICs.

Approved by:	markj
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D31457

(cherry picked from commit 12e8addd32)
2021-08-16 18:35:04 -07:00
Marius Strobl
5dd1d72e5b e1000: fix build after b761f26492 (orig c1655b0f)
(cherry picked from commit c262e8e87e)
2021-08-16 18:31:43 -07:00
Marius Strobl
b761f26492 e1000: consistently use the hw variables
It's rather confusing when adapter->hw and hw are mixed and matched
within a particular function.
Some of this was missed in cd1cf2fc1d
and r353778 respectively.

(cherry picked from commit c1655b0f89)
2021-08-16 18:29:19 -07:00
Kevin Bowling
0d0726a769 e1000: Fix lem/em UDP rx csum offload
Rebase on igb code and unify lem/em implementations.

PR:		257642
Reported by:	Nick Reilly <nreilly@blackberry.com>
Reviewed by:	karels, emaste
Tested by:	Nick Reilly <nreilly@blackberry.com>
Approved by:	grehan
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D31449

(cherry picked from commit 015075f383)
2021-08-15 17:56:45 -07:00
Vladimir Kondratyev
f2f52fbfdb psm(4): Probe Synaptics touchpad with active multiplexing mode enabled
if it is only multiplexed device. Also enable syncbit checks for them.
This fixes touchpad recognition on Panasonic Toughbook CF-MX4 laptop.

Reported by:	Tomasz "CeDeROM" CEDRO <tomek_AT_cedro_DOT_info>
PR:		253279
Differential revision:	https://reviews.freebsd.org/D28502

(cherry picked from commit f5998d20ed)
2021-08-16 03:47:18 +03:00
Vladimir Kondratyev
c3bccba63d iichid(4): Perform bus_teardown_intr/bus_setup_intr to disable interrupts
during suspend/resume cycle. Previously used bus_generic_suspend_intr and
bus_generic_resume_intr may cause interrupt storm because of missed
interrupt acknowledges caused by blocking of intr handler.

Reported by:	J.R. Oldroyd <jr_AT_opal_DOT_com>

(cherry picked from commit 82626fef62)
2021-08-16 03:46:18 +03:00
J.R. Oldroyd
094860333a iichid(4): disable interrupt on suspend
Commit message of the identical change in Linux driver says:
"When an I2C HID device is powered off during system sleep, as a result
of removing its power resources (by the ACPI core) the interrupt line
might go low as well.  This results inadvertent interrupts."

This change fixes suspend/resume on Asus S510UQ laptops.

While here add a couple of typo fixes as well as a slight change to the
iichid_attach() code to have the power_on flag set properly.

Submitted by:	J.R. Oldroyd <jr_AT_opal_DOT_com>
Reviewed by:	wulf

(cherry picked from commit 5236888db7)
2021-08-16 03:45:44 +03:00
Kevin Bowling
2257c7810c igc: sync igc_txrx with igb(4)
Reviewed by:	grehan
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D31227

(cherry picked from commit d02e436353)
2021-08-15 12:25:16 -07:00
Peter Grehan
d7388d33b4 MFC 517904de5c: igc(4): Introduce new driver for the Intel I225 Ethernet controller.
This controller supports 2.5G/1G/100MB/10MB speeds, and allows
tx/rx checksum offload, TSO, LRO, and multi-queue operation.

The driver was derived from code contributed by Intel, and modified
by Netgate to fit into the iflib framework.

Thanks to Mike Karels for testing and feedback on the driver.

Reviewed by:	bcr (manpages), kbowling, scottl, erj
Relnotes:	yes
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D30668

(cherry picked from commit 517904de5c)
2021-08-15 20:33:54 +10:00
Gordon Bergling
64085efb67 hms(4): Fix a typo in sysctl description
- s/threshhold/threshold/

(cherry picked from commit 4b4850aefe)
2021-08-15 07:56:02 +02:00
Alexander Motin
7eb023696a coretemp(4): Switch to smp_rendezvous_cpus().
Use of smp_rendezvous_cpus() instead of sched_bind() allows to not
block indefinitely if target CPU is running some thread with higher
priority, while all we need is single rdmsr/wrmsr instruction call.
I guess it should also be much cheaper than full thread migration.

MFC after:	2 weeks
Sponsored by:	iXsystems, Inc.

(cherry picked from commit 74f80bc1af)
2021-08-12 21:48:17 -04:00