summaryrefslogtreecommitdiff
path: root/sys/dev/mps
Commit message (Collapse)AuthorAgeFilesLines
* Make MAXPHYS tunable. Bump MAXPHYS to 1M.Konstantin Belousov2020-11-281-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Replace MAXPHYS by runtime variable maxphys. It is initialized from MAXPHYS by default, but can be also adjusted with the tunable kern.maxphys. Make b_pages[] array in struct buf flexible. Size b_pages[] for buffer cache buffers exactly to atop(maxbcachebuf) (currently it is sized to atop(MAXPHYS)), and b_pages[] for pbufs is sized to atop(maxphys) + 1. The +1 for pbufs allow several pbuf consumers, among them vmapbuf(), to use unaligned buffers still sized to maxphys, esp. when such buffers come from userspace (*). Overall, we save significant amount of otherwise wasted memory in b_pages[] for buffer cache buffers, while bumping MAXPHYS to desired high value. Eliminate all direct uses of the MAXPHYS constant in kernel and driver sources, except a place which initialize maxphys. Some random (and arguably weird) uses of MAXPHYS, e.g. in linuxolator, are converted straight. Some drivers, which use MAXPHYS to size embeded structures, get private MAXPHYS-like constant; their convertion is out of scope for this work. Changes to cam/, dev/ahci, dev/ata, dev/mpr, dev/mpt, dev/mvs, dev/siis, where either submitted by, or based on changes by mav. Suggested by: mav (*) Reviewed by: imp, mav, imp, mckusick, scottl (intermediate versions) Tested by: pho Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D27225 Notes: svn path=/head/; revision=368124
* Introduce support of SCSI Command Priority.Alexander Motin2020-10-251-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | SAM-3 specification introduced concept of Task Priority, that was renamed to Command Priority in SAM-4, and supported by all modern SCSI transports. It provides 15 levels of relative priorities: 1 - highest, 15 - lowest and 0 - default. SAT specification for SATA devices translates priorities 1-3 into NCQ high priority. This change adds new "priority" field into empty spots of struct ccb_scsiio and struct ccb_accept_tio of CAM and struct ctl_scsiio of CTL. Respective support is added into iscsi(4), isp(4), mpr(4), mps(4) and ocs_fc(4) drivers for both initiator and where applicable target roles. Minimal support was added to CTL to receive the priority value from different frontends, pass it between HA controllers and report in few places. This patch does not add consumers of this functionality, so nothing should really change yet, since the field is still set to 0 (default) on initiator and not actively used on target. Those are to be implemented separately. I've confirmed priority working on WD Red SATA disks connected via mpr(4) and properly transferred to CTL target via iscsi(4), isp(4) and ocs_fc(4). While there, added missing tag_action support to ocs_fc(4) initiator role. MFC after: 1 month Relnotes: yes Sponsored by: iXsystems, Inc. Notes: svn path=/head/; revision=367044
* Bring the request_descriptor union into harmony internally. NoScott Long2020-10-131-3/+3
| | | | | | | functional change. Notes: svn path=/head/; revision=366668
* Refine the busdma template interface. Provide tools for filling in fieldsScott Long2020-09-143-30/+24
| | | | | | | | | | that can be extended, but also ensure compile-time type checking. Refactor common code out of arch-specific implementations. Move the mpr and mps drivers to this new API. The template type remains visible to the consumer so that it can be allocated on the stack, but should be considered opaque. Notes: svn path=/head/; revision=365706
* Convert the mps driver to use busdma templatesScott Long2020-09-113-89/+46
| | | | Notes: svn path=/head/; revision=365644
* mps: clean up empty lines in .c and .h filesMateusz Guzik2020-09-0122-282/+14
| | | | Notes: svn path=/head/; revision=365203
* Remove extra memset() left after r342388.Alexander Motin2020-08-041-1/+0
| | | | | | | | | | | | | This memset() wiped MPI2_FUNCTION_SCSI_TASK_MGMT set by mprsas_alloc_tm(), that broke target reset on device removal, making later re-insertion into the same slot impossible, since firmware was still waiting for the driver to finish with the removed device. MFC after: 1 week Sponsored by: iXsystems, Inc. Notes: svn path=/head/; revision=363852
* mpr(4), mps(4): Stop checking for failures from malloc(M_WAITOK).Mark Johnston2020-07-273-30/+0
| | | | | | | | | | | PR: 240545 Submitted by: Andrew Reiter <arr@watson.org> Reviewed by: imp MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D25766 Notes: svn path=/head/; revision=363608
* Add a small hack to the ioctl header files so that both mpr and mps canScott Long2020-04-161-0/+2
| | | | | | | | be included. This isn't a great solution, but fixing it correctly is a bigger task and this is the lesser of the existing evils. Notes: svn path=/head/; revision=360001
* Centralize compatability translation macros.Brooks Davis2020-04-141-10/+1
| | | | | | | | | | | | | | | | Copy the CP, PTRIN, etc macros from freebsd32.h into a sys/abi_compat.h and replace existing definitation with includes where required. This eliminates duplicate code and allows Linux and FreeBSD compatability headers to be included in the same files. Input from: cem, jhb Obtained from: CheriBSD MFC after: 2 weeks Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D24275 Notes: svn path=/head/; revision=359937
* Increase buffer in mprsas_log_command() from 192 to 224 bytes.Alexander Motin2020-03-131-1/+1
| | | | | | | | | | | 192 bytes are not enough to print long commands, such as ATA COMMAND PASS THROUGH(16), that makes debug output difficult to read. MFC after: 2 weeks Sponsored by: iXsystems, Inc. Notes: svn path=/head/; revision=358959
* Remove support for all pre FreeBSD 11.0 versions from mpr and mps.Warner Losh2020-02-263-279/+2
| | | | | | | | | | Remove a number of workarounds for older versions of FreeBSD. FreeBSD stable/10 was branched over 6 years ago. All of these changes date from about that time or earlier. These workarounds are extensive and get in the way of understanding the current flow in the driver. Notes: svn path=/head/; revision=358351
* Mark more nodes as CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT (17 of many)Pawel Biernacki2020-02-261-6/+10
| | | | | | | | | | | | | | | | | | | r357614 added CTLFLAG_NEEDGIANT to make it easier to find nodes that are still not MPSAFE (or already are but aren’t properly marked). Use it in preparation for a general review of all nodes. This is non-functional change that adds annotations to SYSCTL_NODE and SYSCTL_PROC nodes using one of the soon-to-be-required flags. Mark all obvious cases as MPSAFE. All entries that haven't been marked as MPSAFE before are by default marked as NEEDGIANT Approved by: kib (mentor, blanket) Commented by: kib, gallatin, melifaro Differential Revision: https://reviews.freebsd.org/D23718 Notes: svn path=/head/; revision=358333
* Before issing the REMOVE_DEVICE command to the firmware, make sure that allWarner Losh2020-02-252-18/+55
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | commands have completed. It's not OK to force complete any pending commands before we send the REMOVE_DEVICE. Instead, make sure that all pending commands are complete before sending that. By trying to second guess the firmware here, we run the risk of completing commands twice, which leads to corruption. This removes the forced completion of commands introduced in r218811. So it's a partial backout of that commit, but replaces it with a more rebust mechanism. Either these commands will complete due to the TARGET RESET, or they will timeout and be aborted, but they will all complete. Add assert that all commands are complete to REMOVE_DEVICE completion routine. We attempt to assure this programatically, so we shouldn't have any commands in the queue because we've waited for them all. Any commands that make it into our action routine after we mark the target in removal will complete immediately with an error. When we're removing a target that's not a volume, advertise up the stack that it's actually gone, as opposed to having a transient selection error we should retry. Do this both in the action routine, and when we get a notification of an aborted command. We don't do this for volumes because the driver tries hard not to advertise to the OS a volume has disappeared. Apply these changes to both mpr and mps since they are based on quite similar designs. Discussed with: scottl@ Differential Revision: https://reviews.freebsd.org/D23768 Notes: svn path=/head/; revision=358308
* Advertise the MPI Message Version that's contained in the IOCFacts messageScott Long2020-02-072-2/+13
| | | | | | | | | | | | in the sysctl block for the driver. mpsutil/mprutil needs this so it can know how big of a buffer to allocate when requesting the IOCFacts from the controller. This eliminates the kernel console messages about wrong allocation sizes. Reported by: imp Notes: svn path=/head/; revision=357651
* mps(4): add missing cam(4) dependencyConrad Meyer2020-01-191-0/+1
| | | | | | | | | | | | | | | | | On a MINIMAL kernel, mps.ko wouldn't load because it uses the xpt_hold_boot symbol from CAM, but didn't have a dependency on cam(4). (CEM: Some context: when linking loaded modules, the kernel dynamic linker only looks for definitions in explictly marked dependency modules. Also, the identical mpr(4) driver uses the same CAM function, but already had the correct MODULE_DEPEND(), so no similar change is needed there.) Submitted by: Greg V <greg AT unrelenting.technology> Reviewed by: imp, myself Differential Revision: https://reviews.freebsd.org/D23272 Notes: svn path=/head/; revision=356901
* Fix leak in state machine for commands.Warner Losh2019-11-241-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | When we get a device departed message from the firmware, we send a TARGET_REST to the device to let the firmware know we're done and as part of the recovery process. This will abort all the commands. While the documentation says the IOC is responsible for writing the completion message for all the commands pending with an aborted status, we sometimes have queued commands for the target that haven't been completed so are in the INQUEUE state. So, when we later complete the pending CCB as aborted, these commands are freed and we hit the "state not busy" panic. Elsewhere where we dequeue commands, we move the state to BUSY from INQUEUE. Do that here as well. In talking to Ken, Scott and Justin, they recommended a series of tests to see if this is 100% safe. Those tests are ongoing, but preliminary tests suggest this is safe as we see no duplicate completions when we hit this case at work. We have a machine that has a dodgy powersupply which usually doesn't apply power to a few drives, but sometimes does when the machine is under heavy load so we get a rash of the connect / disconnect messages over half an hour. Without this change, we'd see state not busy panic. With this change, the drives just annoyingly come and go without affecting the rest of the machine, but without a complete error injection test suite, it's hard to know if all edge cases are now covered or not. Discussed with: scottl, ken, gibbs Notes: svn path=/head/; revision=355056
* Fix bugs in recovery path and improve cm trackingWarner Losh2019-07-084-17/+35
| | | | | | | | | | | | | | | | | | | | | Eliminate the TIMEDOUT state. This state really conveyed two different concepts: I timed out during recovery (and my command got put on the recovery queue), and I timed out diring discovery (which doesn't). Separate those two concepts into two flags. Use the TIMEDOUT flag to fail requests as timed out. Use the on queue flag to remove them from the queue. In mps_intr_locked for MPI2_RPY_DESCRIPT_FLAGS_ADDRESS_REPLY message type, when completing commands, ignore the ones that are not in state INQUEUE. They were already completed as part of the recovery process. When we complete them twice, we wind up with entries on the free queue that are marked as busy, trigging asserts. Reviewed by: scottl (earlier version, just for mpr) Differential Revision: https://reviews.freebsd.org/D20785 Notes: svn path=/head/; revision=349849
* Fix busy status leak in case of incorrect passthrough args.Alexander Motin2019-05-301-2/+4
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=348417
* Extract eventfilter declarations to sys/_eventfilter.hConrad Meyer2019-05-201-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | This allows replacing "sys/eventfilter.h" includes with "sys/_eventfilter.h" in other header files (e.g., sys/{bus,conf,cpu}.h) and reduces header pollution substantially. EVENTHANDLER_DECLARE and EVENTHANDLER_LIST_DECLAREs were moved out of .c files into appropriate headers (e.g., sys/proc.h, powernv/opal.h). As a side effect of reduced header pollution, many .c files and headers no longer contain needed definitions. The remainder of the patch addresses adding appropriate includes to fix those files. LOCK_DEBUG and LOCK_FILE_LINE_ARG are moved to sys/_lock.h, as required by sys/mutex.h since r326106 (but silently protected by header pollution prior to this change). No functional change (intended). Of course, any out of tree modules that relied on header pollution for sys/eventhandler.h, sys/lock.h, or sys/mutex.h inclusion need to be fixed. __FreeBSD_version has been bumped. Notes: svn path=/head/; revision=347984
* Add missing newline to debug printf.Warner Losh2019-05-081-1/+1
| | | | Notes: svn path=/head/; revision=347237
* Add missing break statements. Coverity CID 1400446.Scott Long2019-03-271-0/+2
| | | | | | | Reported by: mav Notes: svn path=/head/; revision=345573
* Add event table decoding for SAS Broadcast Primitive events.Scott Long2019-03-241-0/+10
| | | | Notes: svn path=/head/; revision=345485
* Fix a transposition error from the previous commitScott Long2019-03-241-1/+1
| | | | Notes: svn path=/head/; revision=345482
* r329522 created problemss with commands that enter the TIMEDOUT state butScott Long2019-03-241-3/+2
| | | | | | | | | | | | | | are successfully returned by the card (usually due to an abort being issued as part of timeout recovery). Remove what amounts to an insufficient KASSERT, and don't overwrite the state value. State should probably be re-designed, and that will be done with a future commit. Reported by: phk, bei.io Reviewed by: imp, mav Differential Revision: D19677 Notes: svn path=/head/; revision=345479
* Port over the SCSI sense handling fix from mpr(4) in r342528, and fixScott Long2018-12-311-3/+5
| | | | | | | whitespace to match. Notes: svn path=/head/; revision=342660
* Further refactoring for task management commands. Also fix a relatedScott Long2018-12-241-15/+16
| | | | | | | typo from the previous commit. Notes: svn path=/head/; revision=342388
* Commands for user-initated device resets should come from the high-priorityScott Long2018-12-241-2/+2
| | | | | | | allocator. Prior to this change, they would leak from the normal allocator. Notes: svn path=/head/; revision=342387
* First step in refactoring and fixing the error recovery and task managementScott Long2018-12-243-18/+14
| | | | | | | | code in the mpr and mps drivers. Eliminate duplicated code and fix some comments. Notes: svn path=/head/; revision=342386
* mps(4), mpr(4): remove SATA ID command cancellation hackConrad Meyer2018-12-213-63/+31
| | | | | | | | | | | | | | | | Add a generic mechanism to override mp?_wait_command's timeout behavior, which continues to invoke reinit by default. Invokers who set cm_timeout_handler may avoid automatic reinit and do their own handling. Adapt mp?sas_get_sata_identify to this mechanism and remove its callout hack. Reviewed by: scottl Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D18614 Notes: svn path=/head/; revision=342355
* mps(4), mpr(4): Fix lifetime of command buffer for mp?sas_get_sata_identifyConrad Meyer2018-12-212-5/+12
| | | | | | | | | | | | | | In the event that the ID command timed out, mps(4)/mpr(4) did not free the command until it could be cancelled. However, it freed the associated buffer (cm_data). Fix the lifetime issue by freeing the associated buffer only after Abort Task or controller reset. Reviewed by: scottl Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D18612 Notes: svn path=/head/; revision=342354
* Copy and clear the reply descriptor atomically. This prevents concurrencyScott Long2018-12-091-5/+14
| | | | | | | | in the interrupt handlers (usually due to timeout/error recovery) from seeing and processing the same descriptor twice. Notes: svn path=/head/; revision=341755
* Add PNP info to PCI attachments of cbb, cxgb, ida, iwn, ixl, ixlv,Warner Losh2018-09-261-4/+4
| | | | | | | | | | | | | mfi, mps, mpr, mvs, my, oce, pcn, ral, rl. This only labels existing pci device tables, and has no probe / attach code changes. Reviewed by: imp, chuck Submitted by: Lakhan Shiva Kamireddy <lakhanshiva@gmail.com> Sponsored by: Google, Inc. (GSoC 2018) Approved by: re (glen) Notes: svn path=/head/; revision=338949
* Port the mps panic-safe shutdown_final handling to mprWarner Losh2018-08-131-0/+2
| | | | | | | | | | | | | r330951 by smh fixed the mps driver to avoid deadlocks when panicing. The same code is needed for mpr, so port it here, along with the fix which allows the CCBs scheduled to complete avoiding at least a scary message and likely other unintended consequences. Sponsored by: Netflix Differential Review: https://reviews.freebsd.org/D16663 Notes: svn path=/head/; revision=337725
* Call xpt_sim_poll in shutdown_final handler.Warner Losh2018-08-131-1/+4
| | | | | | | | | | | | | | | When we're shutting down, we send a number of start/stop commands to the known targets. We have to wait for them to complete. During a panic, the interrupts are off, and using pause to wait for them to fire and complete won't work: we have to poll after pause returns so the completion routines of the CCBs run so we decrement work outstanding counts. Sponsored by: Netflix Differential Review: https://reviews.freebsd.org/D16663 Notes: svn path=/head/; revision=337724
* Move most of the contents of opt_compat.h to opt_global.h.Brooks Davis2018-04-061-2/+0
| | | | | | | | | | | | | | | | | | | | | opt_compat.h is mentioned in nearly 180 files. In-progress network driver compabibility improvements may add over 100 more so this is closer to "just about everywhere" than "only some files" per the guidance in sys/conf/options. Keep COMPAT_LINUX32 in opt_compat.h as it is confined to a subset of sys/compat/linux/*.c. A fake _COMPAT_LINUX option ensure opt_compat.h is created on all architectures. Move COMPAT_LINUXKPI to opt_dontuse.h as it is only used to control the set of compiled files. Reviewed by: kib, cem, jhb, jtl Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D14941 Notes: svn path=/head/; revision=332122
* Disable T10 Protection Information / EEDP handling for type 2 protection.Kenneth D. Merry2018-03-231-2/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The mps(4) and mpr(4) drivers and hardware handle T10 Protection Information, which is a system of checksums and guard blocks to protect data while it is being transferred and while it is on disk. It is also known as T10 DIF. For more details, see section 4.22 of the SBC-4 spec. Supporting Type 2 protection requires using 32 byte CDBs, and filling in the fields in those CDBs. We don't yet support that in the da(4) driver. Type 1 and Type 3 protection don't require that, and can be handled by the mps(4)/mpr(4) driver's code and firmware without any additional input from the da(4) driver. If a drive has Type 2 protection enabled (you frequently see this with SAS drives shipped from Dell), don't set the various EEDP fields in the mps(4)/mpr(4) driver command fields. Otherwise, you wind up with errors like this that would otherwise make no sense: (da9:mpr0:0:18:0): READ(10). CDB: 28 00 00 00 00 00 00 02 00 00 (da9:mpr0:0:18:0): CAM status: SCSI Status Error (da9:mpr0:0:18:0): SCSI status: Check Condition (da9:mpr0:0:18:0): SCSI sense: ILLEGAL REQUEST asc:20,0 (Invalid command operation code) (da9:mpr0:0:18:0): (da9:mpr0:0:18:0): Field Replaceable Unit: 0 (da9:mpr0:0:18:0): Command Specific Info: 0 (da9:mpr0:0:18:0): (da9:mpr0:0:18:0): Descriptor 0x80: f8 21 (da9:mpr0:0:18:0): Descriptor 0x81: 00 00 00 00 00 00 (da9:mpr0:0:18:0): Error 22, Unretryable error In other words, what kind of strange SAS hard drive doesn't support a standard 10 byte SCSI READ command? In this case, one that has Type 2 protection enabled. We can revisit this when we put Type 2 protection support in the da(4) driver, but for now this will help people who put Type 2 formatted drives in a system and wonder what in the world is going on. MFC after: 3 days Sponsored by: Spectra Logic Notes: svn path=/head/; revision=331422
* Fix mps deadlock when handling panicSteven Hartland2018-03-142-14/+21
| | | | | | | | | | | | | | | | | | | | During shutdown mps waits for its SSU requests to complete however when performing a reboot after handling a panic the scheduler is stopped so getmicrotime which is used can be non-functional. Switch to using the same method as shutdown_panic to ensure we actually complete. In addition reduce the timeout when RB_NOSYNC is set in howto as we expect this to fail. Reviewed by: slm MFC after: 1 week Sponsored by: Multiplay Differential Revision: https://reviews.freebsd.org/D12776 Notes: svn path=/head/; revision=330951
* Implement a sysctl to dump in-flight I/O state for debugging. The tool toScott Long2018-03-121-0/+70
| | | | | | | | | parse it will be committed in a separate action. Sponsored by: Netflix Notes: svn path=/head/; revision=330789
* Allow physically non-contiguous chain frames allocation in mps(4)/mpr(4).Alexander Motin2018-02-272-37/+53
| | | | | | | | | | | | | | | | | | | | | Chain frames required to satisfy all 2K of declared I/Os of 128KB each take more then a megabyte of a physical memory, all of which existing code tries allocate as physically contiguous. This patch removes that physical contiguousness requirement, leaving only virtual contiguousness. I was thinking about other ways of allocation, but the less granular allocation becomes, the bigger is the overhead and/or complexity, reaching about 100% overhead if allocate each frame separately. The patch also bumps the chain frames hard limit from 2K to 16K. It is more than enough for the case of default REQ_FRAMES and MAXPHYS (the drivers will allocate less than that automatically), while in case of increased MAXPHYS it will control maximal memory usage. Sponsored by: iXsystems, Inc. Differential Revision: https://reviews.freebsd.org/D14420 Notes: svn path=/head/; revision=330049
* Improve command lifecycle debugging and detection of problems.Scott Long2018-02-183-21/+49
| | | | | | | Sponsored by: Netflix Notes: svn path=/head/; revision=329522
* Fix non-64-bit platform build by printing bus_addr_t values using %#jxLi-Wen Hsu2018-02-131-12/+12
| | | | | | | | Reviewed by: slm Differential Revision: https://reviews.freebsd.org/D14344 Notes: svn path=/head/; revision=329220
* Print out the shared memory queues during initializationScott Long2018-02-111-0/+13
| | | | | | | Sponsored by: Netflix Notes: svn path=/head/; revision=329137
* Teach mps(4) and mpr(4) drivers to autotune chain frames.Alexander Motin2018-02-103-28/+41
| | | | | | | | | | | | | | | | This is a first part of the change. It makes the drivers to calculate the required number of chain frames to satisfy worst case scenarios, but it does not change existing overly strict limits on them. The next step will be to rewrite the allocator to not require megabytes of physically contiguous address space, that may be problematic if done after boot, after doing which the limits can be removed. Until that this code can just correct user set limits, if they are set too high. Sponsored by: iXsystems, Inc. Differential Revision: https://reviews.freebsd.org/D14261 Notes: svn path=/head/; revision=329096
* Cache the value of the request and reply frame size since it's used quiteScott Long2018-02-064-19/+33
| | | | | | | | | | | a bit in the normal operation of the driver. Covert it to represent bytes instead of 32bit words. Fix what I believe to be is a bug in this respect with the Tri-mode cards. Sponsored by: Netflix Notes: svn path=/head/; revision=328950
* Fix queue length reporting in mps(4) and mpr(4).Alexander Motin2018-02-063-4/+7
| | | | | | | | | | | | | | | Both drivers were found to report CAM bigger queue depth then they really can handle. It made them later under high load with many disks return some of submitted requests back with CAM_REQUEUE_REQ status for later resubmission. Reviewed by: scottl MFC after: 1 week Sponsored by: iXsystems, Inc. Differential Revision: https://reviews.freebsd.org/D14215 Notes: svn path=/head/; revision=328937
* Diagnostic buffer fixes for the mps(4) and mpr(4) drivers.Kenneth D. Merry2018-02-063-14/+165
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In mp{r,s}_diag_register(), which is used to register diagnostic buffers with the mp{r,s}(4) firmware, we allocate DMAable memory. There were several issues here: o No checking of the bus_dmamap_load() return value. If the load failed or got deferred, mp{r,s}_diag_register() continued on as if nothing had happened. We now check the return value and bail out if it fails. o No waiting for a deferred load callback. bus_dmamap_load() calls a supplied callback when the mapping is done. This is generally done immediately, but it can be deferred. mp{r,s}_diag_register() did not check to see whether the callback was already done before proceeding on. We now sleep until the callback is done if it is deferred. o No call to bus_dmamap_sync(... BUS_DMASYNC_PREREAD) after the memory is allocated and loaded. This is necessary on some platforms to synchronize host memory that is going to be updated by a device. Both drivers would also panic if the firmware was reinitialized while a diagnostic buffer operation was in progress. This fixes that problem as well. (The driver will reinitialize the firmware in various circumstances, but the problem I ran into was that the firmware would generate an IOC Fault due to a PCIe error.) mp{r,s}var.h: Add a new structure, struct mpr_busdma_context, that is used for deferred busdma load callbacks. Add a prototype for mp{r,s}_memaddr_wait_cb(). mp{r,s}.c: Add a new busdma callback function, mp{r,s}_memaddr_wait_cb(). This provides synchronization for callers that want to wait on a deferred bus_dmamap_load() callback. mp{r,s}_user.c: In bus_dmamap_register(), add a call to bus_dmamap_sync() with the BUS_DMASYNC_PREREAD flag set after an allocation is loaded. Also, check the return value of bus_dmamap_load(). If it fails, bail out. If it is EINPROGRESS, wait for the callback to happen. We use an interruptible sleep (msleep with PCATCH) and let the callback clean things up if we get interrupted. In mpr_diag_read_buffer() and mps_diag_read_buffer(), call bus_dmamap_sync(..., BUS_DMASYNC_POSTREAD) before copying the data out to make sure the data is in stable storage. In mp{r,s}_post_fw_diag_buffer() and mp{r,s}_release_fw_diag_buffer(), check the reply to see whether it is NULL. It can be NULL (and the command non-NULL) if the controller gets reinitialized while we're waiting for the command to complete but the driver structures aren't reallocated. The driver structures generally won't be reallocated unless there is a firmware upgrade that changes one of the IOCFacts. When freeing diagnostic buffers in mp{r,s}_diag_register() and mp{r,s}_diag_unregister(), zero/NULL out the buffer after freeing it. This will prevent a duplicate free in some situations. Sponsored by: Spectra Logic Reviewed by: mav, scottl MFC after: 1 week Differential Revision: D13453 Notes: svn path=/head/; revision=328936
* Fix a case where a request frame can be composed that requires 2 or moreScott Long2018-02-061-11/+11
| | | | | | | | | | | | | SGList elements, but there's only enough space in the request frame for either 1 element or a chain frame pointer. Previously, the code would hit the wrong case, add the SGList element, but then fail to add the chain frame due to lack of space. Re-arrange the code to catch this case earlier and handle it. Sponsored by: Netflix Notes: svn path=/head/; revision=328919
* Unsign some values related to allocation.Pedro F. Giffuni2018-01-221-1/+1
| | | | | | | | | | | | | | When allocating memory through malloc(9), we always expect the amount of memory requested to be unsigned as a negative value would either stand for an error or an overflow. Unsign some values, found when considering the use of mallocarray(9), to avoid unnecessary casting. Also consider that indexes should be of at least the same size/type as the upper limit they pretend to index. MFC after: 3 weeks Notes: svn path=/head/; revision=328238
* Revert r327828, r327949, r327953, r328016-r328026, r328041:Pedro F. Giffuni2018-01-212-12/+12
| | | | | | | | | | | | | | | | | | Uses of mallocarray(9). The use of mallocarray(9) has rocketed the required swap to build FreeBSD. This is likely caused by the allocation size attributes which put extra pressure on the compiler. Given that most of these checks are superfluous we have to choose better where to use mallocarray(9). We still have more uses of mallocarray(9) but hopefully this is enough to bring swap usage to a reasonable level. Reported by: wosch PR: 225197 Notes: svn path=/head/; revision=328218