Commit graph

22 commits

Author SHA1 Message Date
Zhenlei Huang
ae8388f726 mpi3mr(4): Stop checking for failures from malloc(M_WAITOK)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D45852

(cherry picked from commit 849f9ac370bd66993ce5cc6fca0d2ef9bd03c2c9)
2024-09-30 12:44:25 +08:00
Warner Losh
e2b71e1490 mpi3mr: Minor tweak to task queue pausing
Use a while loop with cancel / drain to make sure that all tasks have
completed before proceeding to reset.

Suggested by:		jhb
Sponsored by:		Netflix

(cherry picked from commit 272a406042608da9bc3e67e41c6b7fc31d4166b8)
2024-01-19 12:16:50 -05:00
Warner Losh
344cdef0cc mpi3mr: Assume dma_hiaddr is BUS_SPACE_MAXADDR
No sense having a variable for this. So use BUS_SPACE_MAXADDR and remove
dma_hiaddr from softc.

Suggested by:		jhb
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D42808

(cherry picked from commit 1ec7c672bc2854a1efb1d50f189d4881163c16c6)
2024-01-19 12:16:50 -05:00
Warner Losh
ac7d9eaf06 mpi3mr: Replace can't happen DataLength == 0 with an assert
Replace the test for DataLength == 0 with an assert. It can't happen,
but an assert doesn't hurt. Emacs removed some trailing white space too.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D42807

(cherry picked from commit 2361a0056fc16b5e11df2aa948aaa633ac01d685)
2024-01-19 12:16:50 -05:00
Alexander Motin
23a5782dc0 mpi3mr: Use template for main busdma tag.
Use the simpler template code for the parent busdma tag for all I/O to
this card.

Reviewed by:		mav, jhb, imp
Differential Revision:	https://reviews.freebsd.org/D42607

(cherry picked from commit 489eee0d41dce317678adb0dae8d509a5f1d6d93)
2024-01-19 12:16:50 -05:00
Alexander Motin
2d84c6e894 mpi3mr: Make these bus_dmamap_load calls synchronous
These calls "should" all be synchrounous. There's no bouncing that's
needed for them (at least in the typical case that we have a sane card
that has more bits of dma addresses decoded than we have memory), so
there's no errors possible. Ensure these calls are really synchronous
with BUS_DMA_NOWAIT flags (which should never fail now that the
bus_dmamem_alloc() has succeeded).

Reviewed by:		mav, jhb, imp
Differential Revision:	https://reviews.freebsd.org/D42606

(cherry picked from commit 39a3e6a812ad9c089bd2c4935193f1b3c4c5c35a)
2024-01-19 12:16:50 -05:00
Alexander Motin
c8afd30bdb mpi3mr: Fix MAXPHYS usage
This usage is obsolete. Replace with maximum bus space size. maxphys
will sort itself out at higher levels.

Reviewed by:		mav, jhb, imp
Differential Revision:	https://reviews.freebsd.org/D42605

(cherry picked from commit 4e6d128bd823e5b5d0b058f918c7036978a0e8bf)
2024-01-19 12:16:50 -05:00
Warner Losh
835db41823 mpi3mr: Add firmware version
Publish the firmware version on the card like we do for mps/mpr.

Sponsored by:		Netflix
Reviewed by:		mav
Differential Revision:	https://reviews.freebsd.org/D42588

(cherry picked from commit 28a274342ea0b0666b56704477d2d1c17564942e)
2024-01-19 12:16:50 -05:00
Warner Losh
3b4d16889b mpi3mr: Trivial trailing white space reduction
Sponsored by:		Netflix

(cherry picked from commit ee7c431c4991febefcd15f16caa0e2b17c73b7b6)
2024-01-19 12:16:50 -05:00
Warner Losh
c3b67deaf5 mpi3mr: Honor the dma mask from IOCFacts
The number of signficant bits that are decoded are returned in the flags
field of the IOCFacts structure from the device.  Rather than assume the
worst with a pessimal 32-bit maximum, look at this value and pass it
along to all the dma map creation requests.

A lof of those creations are repetitive and could just inherit from the
base tag if we moved to the templated interface.  This is called out as
desireable future work not done at this time.

In addition, due to a chicken and an egg problem, we have to allocate
some of the maps with a 32-bit loaddr.  These are the ones we need to
read iocfacts.  And they are fine to be so restricted: they are little
used after startup, and when they are used, bouncing is fine.

Sponsored by:		Netflix
Reviewed by:		mav
Differential Revision:	https://reviews.freebsd.org/D42559

(cherry picked from commit 91d961356d03465635c4784fab48acdd1304e1e0)
2024-01-19 12:16:50 -05:00
Warner Losh
fda7cc79aa mpi3mr: Fix EINPROGRESS errors hanging the card
Move enqueueing of commands to bus_dmamap_load_ccb callback

Fix fundamental difference between FreeBSD and Linux. On Linux, your dma
load callback always happends before it returns, so drivers are written
to load the map, then submit to hardware. On FreeBSD, the callback may
be deferred and return EINPROGRESS. This means the callback is
responsible for queueing the request to the hardware is done after the
SGL list is created. Make a number of interrelated cahnages:

At the end of mpi3mr_prepare_sgls, add a call to mpi3mr_enqueue_request.

Split the hardware submission out from the end of mpi3mr_action_scsiio
and move it into a new routine mpi3mr_enqueue_request.

Move all error completion from the end of mpi3mr_action_scsiio to where
the error is detected. We cannot pass errors back from the
mpi3mr_enqueue_request to do this on a 'failed' mpi3mr in a centralized
place (since it has to be fire and forget).

Add comments about zero length SGLs never making it into
mpi3mr_prepare_sgls. Keep the code there for the moment, but we only set
cm->data to non-NULL when scsiio_req->DataLength is not zero. So the
datalength can't be zero and we can't send the zero SGLs.

Add commentts about other "impossible" tests in mpi3mr_prepare_sgls that
really should be simple asserts of some flavor.

Eliminate cm->error_code, since we can't pass data back from the
mpi3mr_prepare_sgl callback anymore.

In mpi3mr_map_request, call mpi3mr_enqueue_request for the no data case.
This seems to work even though we've not done the special zero length
handling that was in mpi3mr_prepare_sgls, giving further evidence to it
not actually being needed. This is needed for SCSI CDBs that have no
data to pass to the drive like TEST UNIT READY.

With this change, and the prior ones, we're now able to run with mpi3mr
on 128GB systems and very heavy disk load (so many buffers land > 4GB:
the driver instructs busdma to never use memory abouve 4GB, which may be
too conservative, but an issue for another time).

Sponsored by:		Netflix
Reviewed by:		sumit.saxena_broadcom.com, mav, jhb
Differential Revision:	https://reviews.freebsd.org/D42543

(cherry picked from commit 3208a189c1e2c4ef35daa432fe45629a043d7047)
2024-01-19 12:16:50 -05:00
Warner Losh
ac4f33d2cd mpi3mr: Cleaup setting of status in processing scsiio requests
More uniformly use mpi3mr_set_ccbstatus in mpi3mr_action_scsiio.  The
routine mostly used it, but also has setting of status by hand. In those
cases where we want to error out the request, use this routine.

As part of this, move setting CAM_SIM_QUEUED later in the function to
when we're sure it's been queued. Remove the places we clear it before
this.

Sponsored by:		Netflix
Reviewed by:		mav, jhb
Differential Revision:	https://reviews.freebsd.org/D42542

(cherry picked from commit cf8c23230aabd30aa9251975dbe705da559a2d02)
2024-01-19 12:16:49 -05:00
Warner Losh
c351a6ec91 mpi3mr: Only set callout_owned when we create a timeout
Since we assume there's a timeout to cancel when this is true, only set
it true when we set the timeout. Otherwise we may try to cancel a timeout
when there's been an error in submission.

Sponsored by:		Netflix
Reviewed by:		mav
Differential Revision:	https://reviews.freebsd.org/D42541

(cherry picked from commit 1cfd01111eb6a28ca5043e928aa8e9099064177a)
2024-01-19 12:16:49 -05:00
Warner Losh
3c12997a1c mpi3mr: Minor style fix
Fold two lines to make this more readable.

Sponsored by:		Netflix
Reviewed by:		mav, jhb
Differential Revision:	https://reviews.freebsd.org/D42540

(cherry picked from commit e2b27df9eb324fa6e72e29d3185dcd6b390efa9d)
2024-01-19 12:16:49 -05:00
Warner Losh
54fa0d10f6 mpi3mr: Reduce the scope of the reset_mutext
Reduce the scope of reset_mutext to protect the msleep in the watch dog
thread as well as the MPI3MR_FLAGS_SHUTDOWN bit. Use it to protect the
wakeup in mpi3mr_detach so this thread can exit sooner when we're trying
to do an orderly shutdown. Optimize the flow to check the sleep and
other conditions before going to sleep.

It's an open question if this should protect sc->unrecoverable, and if
we should wakeup the watchdog thread when we set it. We might also want
to move too booleans for the three flags that we have now in
mpi3mr_flags. There are a number of U8s that should really be bools and
we might want to also group them together to pack softc better.

Sponsored by:		Netflix
Reviewed by:		mav
Differential Revision:	https://reviews.freebsd.org/D42539

(cherry picked from commit 7c4913093a759adf2e4c7d65535aee04aadee4df)
2024-01-19 12:16:49 -05:00
Warner Losh
e82c6e941e mpi3mr: Remove unused fields in struct mpi3mr_cmd
All of these fields are either unused, or just initialized. Remove
them. This saves about 1MB of memory for the cards that I have which can
do 8k transactions at once.

Sponsored by:		Netflix
Reviewed by:		mav, jhb
Differential Revision:	https://reviews.freebsd.org/D42538

(cherry picked from commit a2b046620c54db977196128b3c53da2704b9fd20)
2024-01-19 12:16:49 -05:00
Warner Losh
0d2cce768c mpi3mr: Don't hold fwevt_lock over call to taskqueue_drain
Holding fwevt_lock when we call taskqueue_drain can lead to deadlock
because it's draining a queue needs fwevt_lock to do work, so that other
thread will try to take out the lock and block, making the thread never
finish and taskqueue_drain never complete. There's a witness
warning/error for this which was exposed when the lock was converted to
a MTX_DEF lock from a MTX_SPIN prior to committing to the FreeBSD tree.

The lock appears to be to protect against additional items being added
to the event list while we're doing a reset. Since the taskqueue is
blocked, items can get added to the list, but won't be processed during
the reset, but there is still a (likely small) race between the
taskqueue_drain and the taskqueue_block calls where an interrupt could
fire on another CPU, resulting in a task being enqueued and started
before the block can take effect. The only way to fix that race is to
turn off interrupt processing during a reset. So we replace a deadlock
with a smaller race.

Sponsored by:		Netflix
Reviewed by:		sumit.saxena_broadcom.com, mav, jhb
Differential Revision:	https://reviews.freebsd.org/D42537

(cherry picked from commit b411372b7d17ae7e5d6c944732d41b979bde2ac4)
2024-01-19 12:16:49 -05:00
Mark Johnston
8adca661c2 mpi3mr: Check for copyin errors in mpi3mr_map_data_buffer_dma()
A failed copyin will cause the driver to use the contents of
uninitialized buffers instead, which is unlikely to be the behaviour
that we want.  Check for errors.

This is in preparation for annotating copyin() and related functions
with __result_use_check.

Reviewed by:	imp
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D43098

(cherry picked from commit 6bfb7306ef92aaccffae42ed00ce6d7201b76966)
2024-01-01 19:29:45 -05:00
Sumit Saxena
10bbea2e25 mpi3mr: Move creation of watchdog to interupt config hook
Move creation of watchdog process from just before we configure the
interrupt config hook to into the config hook itself. This prevents it
from racing the config intr hook and doing an extra reset of the
card. This extra reset is usually harmless, but sometimes it can prevent
discovery of devices if done at just the wrong time. This can lead to no
disks being registered in a box full of disks, for example. Starting it
later eliminates this race, making discovery reliable.

Reviewed by: imp

(cherry picked from commit 7e02c7074c4c6df77b860e0dbcd032a2ea04b98b)
2023-10-19 15:21:12 -06:00
Warner Losh
685dc743dc sys: Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:36 -06:00
Ed Maste
7a91ccd2fb mpi3mr: fix GCC kernel build
Previously every file that included mpi3mr_app.h but did not use
mpi3mr_mgmt_info reported error: 'mpi3mr_mgmt_info' defined but not
used.

Fixes: 2d1d418e1e ("mpi3mr: 3rd Generation Tri-Mode NVMe/SAS/SATA...")
Reported by:	amd64-gcc12 Cirrus-CI job
Sponsored by:	The FreeBSD Foundation
2023-06-19 12:16:39 -04:00
Sumit Saxena
2d1d418e1e mpi3mr: 3rd Generation Tri-Mode NVMe/SAS/SATA MegaRaid / eHBA
This is Broadcom's mpi3mr driver for FreeBSD version 8.6.0.2.0.
The mpi3mr driver supports Broadcom SAS4116-based cards in the 9600
series: 9670W-16i, 9670-24i, 9660-16i, 9620-16i, 9600-24i, 9600-16i,
9600W-16e, 9600-16e, 9600-8i8e.

Initially only available as a module and on amd64/arm64, since that's
how it has been tested to date. Future commits will add it to the kernel
build and may expand the architectures it is supported on.

Co-authored-by: Chandrakanth Patil <chandrakanth.patil@broadcom.com>
Feedback-by: ken (prior versions)
Reviewed-by: imp
RelNotes: yes
Differential-Revision: https://reviews.freebsd.org/D36771
Differential-Revision: https://reviews.freebsd.org/D36772
2023-06-15 08:52:40 -06:00