aboutsummaryrefslogtreecommitdiff
path: root/sys/cam
Commit message (Collapse)AuthorAgeFilesLines
* vfs: remove the unused thread argument from NDINIT*Mateusz Guzik2021-11-251-1/+1
| | | | | | See b4a58fbf640409a1 ("vfs: remove cn_thread") Bump __FreeBSD_version to 1400043.
* Fix "set but not used" warnings in CAM.Scott Long2021-11-255-16/+2
|
* cam: Unbreak CAM_IO_STATS buildWarner Losh2021-11-241-0/+7
| | | | | Fixes: 6637b7460066 Sponsored by: Netflix
* cam: Remove all the write-only variablesWarner Losh2021-11-248-42/+1
| | | | | | | | Delete all the write only variables in CAM. At worst, the only behavior change would be to prevent core dumps from chasing NULL pointers (though I think in all these cases the pointers can't be NULL). Sponsored by: Netflix
* sddadone: 'error' gets assigned only errno codes, never MMC_ERR codesAndriy Gapon2021-11-131-2/+2
| | | | MFC after: 2 weeks
* cam_iosched: Fix a commentWarner Losh2021-11-081-1/+1
| | | | | | Array elements were added, but this comment wasn't updated. Sponsored by: Netflix
* cam_periph: wired is really a bool, update it to a bool.Warner Losh2021-11-051-12/+13
| | | | | | Sponsored by: Netflix Reviewed by: scottl Differential Revision: https://reviews.freebsd.org/D32823
* cam: Remove trailing spaces from serial numbers tooWarner Losh2021-11-051-0/+8
| | | | | | | | | | | | | | | The SanDisk SD8SB8U1 and likely others pad their serial number with spaces on the end rather than the start (at least when connected to a SAS3008). This makes them difficult to wire unit numbers to with the serial because you have to specify the trailing spaces. Instead, strip out the trailing spaces. We already strip leading spaces both here. In addition, when glabel creates the devfs device nodes, leading and trailing spaces are removed already (so there will be no change there either). Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D32684
* cam_periph: Add ability to wire units to a serial numberWarner Losh2021-11-051-4/+12
| | | | | | | | | | | | | | | | | | | | | | | For scsi, ata and nvme, at least, we read a serial number from the device (if the device supports it, some scsi drives do not) and record it during the *_xpt probe device state machine before it posts the AC_FOUND_DEVICE async event. For mmc, no serial number is ever retrieved, so it's always NULL. Add the ability to match this serial number during device wiring. This mechanism is competely optional, and often times using a label and/or some other attribute of the device is easier. However, other times wiring a unit to a serial number simplifies management as most monitoring tools require the *daX device and having it stable from boot to boot helps with data continuity. It can be especially helpful for nvme where no other means exists to reliably tie a ndaX device to an underlying nvme drive and namespace. A similar mechanism exists in Linux to mange device unit numbers with udev. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D32683
* cam_periph: fix bug in camperiphunitnext logicWarner Losh2021-11-051-1/+2
| | | | | | | | | | | If we assigned just a lun as a wired unit (something that camperiphunit will accept), we failed to properly skip over that unit when computing a next unit number. Add lun so the code matches the comments that we have to skip all the same criteria that camperiphunit uses to select wired units for a driver. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D32682
* cam_periph: switch from negative logic to positive logicWarner Losh2021-11-051-4/+4
| | | | | | | | | | | When scanning the resources that are wired for this driver, skip any that whose number doesn't match newunit. They aren't relevant. Switch to positive logic to break out of the loop (and thus go to the next unit) if we find either a target resource or an at resource. This makes the code easier to read and modify. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D32681
* cam_periph: Remove vestigial "scbus" comparisonWarner Losh2021-11-051-5/+5
| | | | | | | | | | | | The code in camperiphunit rejects "scbus" as an 'at' location that would allow any other wiring to use that unit number. Yet in camperiphunitnext, if we have a no target and the 'at' location of 'scbus' it would be excluded on the basis that it's a wiring cadidate. This is improper and appears to be a hold-over of the pre-hints / pre-newbus config system, so remove it. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D32680
* scsi_cd: Improve TOC access validationMark Johnston2021-11-031-18/+19
| | | | | | | | | | | | | | | | | | | | | | | | | 1. During CD probing, we read the TOC header to find the number of entries, then read the TOC itself. The header determines the number of entries, which determines the amount of data to read from the device into the softc in the CD_STATE_MEDIA_TOC_FULL state. We hard-code a limit of 99 tracks (plus one for the lead-out) in the softc, but were not validating that the size reported by the media would fit in this hard-coded limit. Kernel memory corruption could occur if not.[1] Add validation to check this, and refuse to cache the TOC if it would not fit. 2. The CDIOCPLAYTRACKS ioctl uses caller provided track numbers to index into the TOC, but we only validate the starting index. Add validation of the ending index. Also, raise the hard-coded limit from 100 tracks to 170, per a suggestion from Ken. Reported by: C Turt <ecturt@gmail.com> [1] Reviewed by: ken, avg MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D32803
* cam_periph: style changeWarner Losh2021-11-031-1/+2
| | | | | | | | wrap a long line at 80 columns Sponsored by: Netflix Reviewed by: chs Differential Revision: https://reviews.freebsd.org/D32679
* ada: Fix intra-object buffer overread of identify stringsJessica Clarke2021-10-271-4/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | In the ATA/ATAPI spec these are space-padded fixed-length strings with no NUL-terminator (and byte swapped). When performing the identify we call ata_param_fixup to swap the bytes back to be in order, strip any leading/trailing spaces and coalesce consecutive spaces, padding with NULs. However, if the input has no padding spaces, the fixed-up strings are still not NUL-terminated. This causes two issues. The first is that strlcpy will truncate the string by replacing the final byte with a NUL. The second is that strlcpy will keep reading src until it finds a NUL in order to calculate the return value, which is defined as the length of src (so that callers can then compare it with the dsize input to see if the input string was truncated), thereby reading past the end of the buffer and into whatever adjacent fields are in the structure. In practice there's a NUL byte somewhere in the structure, but on CHERI with subobject bounds enabled in the compiler this overread will be detected and trap as a bounds violation. Note this matches ata_xpt's aprobedone, which does a bcopy to a malloc'ed buffer and manually NUL-terminates it for the CAM path's device's serial_num. Found by: CHERI Reviewed by: imp, scottl Differential Revision: https://reviews.freebsd.org/D32567
* cam(4): Limit search for disks in SES enclosure by single busAlexander Motin2021-10-051-0/+8
| | | | | | | | | | | | At least for SAS that we only support now disks are typically connected to the same bus as the enclosure. Limiting the search scope makes it much faster on systems with multiple buses and thousands of disks. Reviewed by: imp MFC after: 2 weeks Sponsored by: iXsystems, Inc. Differential Revision: https://reviews.freebsd.org/D32305
* cam(4): Improve XPT_DEV_MATCHAlexander Motin2021-10-054-66/+78
| | | | | | | | | | | | | | | | | Remove *_MATCH_NONE enums, making no sense and so never used. Make *_MATCH_ANY enums 0 (no any match flags set), previously used by *_MATCH_NONE. Bump CAM_VERSION to 0x1a reflecting those changes and add compat shims. When traversing through buses and devices do not descend if we can already see that requested pattern does not match the bus or device. It allows to save significant amount of time on system with thousands of disks when doing limited searches. Reviewed by: imp MFC after: 2 weeks Sponsored by: iXsystems, Inc. Differential Revision: https://reviews.freebsd.org/D32304
* cam: Add doxygen for cam_sim_freeWarner Losh2021-10-051-0/+13
| | | | | | Sponsored by: Netflix Reviewed by: mav Differential Revision: https://reviews.freebsd.org/D32303
* cam: Fix a typo in a commentGordon Bergling2021-10-021-1/+1
| | | | | | - s/perorming/performing/ MFC after: 3 days
* cam: Avoiding waking up doneq threads if we're dumpingMark Johnston2021-09-251-1/+1
| | | | | | | | | | | | | | Depending on the state of the target doneq thread at the time of the panic, the wakeup can hang indefinitely in thread_lock_block_wait(). That function should likely be modified to return immediately if the scheduler is stopped, but it is also preferable to avoid wakeups in general after a panic. Reported by: pho Reviewed by: mav, imp MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D32126
* libcam: Define depop structures and introduce scsi_wrapWarner Losh2021-09-202-0/+169
| | | | | | | | | | | | | | | Define structures related to the depop set of commands (GET PHYSICAL ELEMENT STATUS, REMOVE ELEMENT AND TRUNCATE, and RESTORE ELEMENT AND REBUILD) as well as the CDB construction routines. Also create scsi_wrap.c. This will have convenience routines that will do all the elements of allocating the ccb, generating the CDB, sending the command (looping as necessary for cases where data is returned, but it's size isn't known up front), etc. As this functionality is fleshed out, calling many camcontrol commands programatically gets much easier. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D29017
* iscsi: Abort data-out tasks queued on a terminating session.John Baldwin2021-09-151-0/+5
| | | | | | | | | | | | cfiscsi_datamove_out() can race with cfiscsi_session_terminate_tasks() and enqueue a new task after the latter function has aborted existing tasks. This could result in a deadlock as cfiscsi_session_terminate_tasks() waited forever for this task to complete. Reviewed by: mav Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D31892
* iscsi: Add a helper routine to abort a data-out task.John Baldwin2021-09-151-17/+22
| | | | | | Reviewed by: mav Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D31891
* Assert that invalid bus widths can't be passed to bus_width_str().John Baldwin2021-09-151-0/+2
| | | | | | | This appeases a -Wreturn-type warning from GCC. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D31935
* ctl(4): Do hole-punching for UNMAP to file-backed LUNsKa Ho Ng2021-09-141-2/+97
| | | | | | | | | | | This adds support for SCSI UNMAP command to file-backed LUNs, if the underlying file system has a non-zerofilling VOP_DEALLOCATE implementation where some or all parts of the requested operation range may be deallocated. Sponsored by: The FreeBSD Foundation Reviewed by: mav Differential Revision: https://reviews.freebsd.org/D31922
* Fix data race in scsi cd driver.Alexander Motin2021-09-131-5/+16
| | | | | | | | | There is a data race between cdsysctlinit and cdcheckmedia. Both functions change softc->flags without synchronization. Submitted by: Arseny Smalyuk <smalukav@gmail.com> MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D31726
* ses: Guard the elm_type_names declaration by _KERNELAlan Somers2021-09-021-0/+2
| | | | | MFC after: 2 weeks Sponsored by: Axcient
* ses: Correct spelling of "Temperature Sensor"Alan Somers2021-09-021-1/+1
| | | | | | | According to SES 4 revision 2 table 71, it should be singular. MFC after: 2 weeks Sponsored by: Axcient
* cam: revert second half of 75b5caa08efEdward Tomasz Napierala2021-09-011-8/+0
| | | | | | | | | This turns debugging printf() into a KASSERT(). Reviewed By: imp Sponsored by: NetApp, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D31523
* targ(4): Remove D_NEEDGIANT.Alexander Motin2021-08-211-1/+0
| | | | | | I don't believe this code needs Giant, if ever needed. MFC after: 1 month
* cam(4): Fix quick unplug/replug for SCSI.Alexander Motin2021-08-211-23/+38
| | | | | | | | | | | | | | | | If some device is plugged back in after unplug before the probe periph destroyed, it will just restart the probe process. But I've found that PROBE_INQUIRY_CKSUM flag not cleared between the iterations may cause AC_FOUND_DEVICE not reported on the second iteration, and because of AC_LOST_DEVICE reported during the first iteration, the device end up configured, but without any periphs attached. We've found that enabled serial console and 102-disk JBOD cause enough probe delays to easily trigger the issue for half of the disks. This change fixes it reliably on my tests. MFC after: 2 weeks Sponsored by: iXsystems, Inc.
* iscsi: Teach the iSCSI stack about "large" received PDUs.John Baldwin2021-08-181-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | When using iSCSI PDU offload (cxgbei) on T6 adapters, a burst of received PDUs can be reported via a single message to the driver. Previously the driver passed these multi-PDU bursts up to the iSCSI stack up as a single "large" PDU by rewriting the buffer offset, data segment length, and DataSN fields in the iSCSI header. The DataSN field in particular was rewritten so that each of the "large" PDUs used consecutively increasing values. While this worked, the forged DataSN values did not match the ExpDataSN value in the subsequent SCSI Response PDU. The initiator does not currently verify this value, but the forged DataSN values prevent adding a check. To avoid this, allow a logical iSCSI PDU (struct icl_pdu) to describe a burst of PDUs via a new 'ip_additional_pdus' field. Normally this field is set to zero when 'struct icl_pdu' represents a single PDU. If logical PDU represents a burst of on-the-wire PDUs, then 'ip_npdus' contains the count of additional on-the-wire PDUs. The header of this "large" PDU is still modified, but the DataSN field now contains the DataSN value of the first on-the-wire PDU in the burst. Reviewed by: mav Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D31577
* Fix a common typo in source code commentsGordon Bergling2021-08-141-1/+1
| | | | | | - s/definitons/definitions/ MFC after: 5 days
* Fix a few typos in source code commentsGordon Bergling2021-08-141-1/+1
| | | | | | - s/posbile/possible/ MFC after: 5 days
* cam(4): Mark all sysctls as CTLFLAG_MPSAFE.Alexander Motin2021-08-118-42/+22
| | | | | | This code does not use Giant lock for very long time. MFC after: 2 weeks
* cam: revert half of 75b5caa08efEdward Tomasz Napierala2021-08-081-8/+0
| | | | | | | | | | This turns debugging printf() into a KASSERT(). It's for ATA for now; SCSI will came later. Reviewed By: imp Sponsored by: NetApp, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D31380
* Fix some common typos in commentsGordon Bergling2021-08-081-1/+1
| | | | | | | | - s/configuraiton/configuration/ - s/specifed/specified/ - s/compatiblity/compatibility/ MFC after: 5 days
* iSCSI: Add support for segmentation offload for hardware offloads.John Baldwin2021-08-061-12/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Similar to TSO, iSCSI segmentation offload permits the upper layers to submit a "large" virtual PDU which is split up into multiple segments (PDUs) on the wire. Similar to how the TCP/IP headers are used as templates for TSO, the BHS at the start of a large PDU is used as a template to construct the specific BHS at the start of each PDU. In particular, the DataSN is incremented for each subsequent PDU, and the 'F' flag is only set on the last PDU. struct icl_conn has a new 'ic_hw_isomax' field which defaults to 0, but can be set to the largest virtual PDU a backend supports. If this value is non-zero, the iSCSI target and initiator use this size instead of 'ic_max_send_data_segment_length' to determine the maximum size for SCSI Data-In and SCSI Data-Out PDUs. Note that since PDUs can be constructed from multiple buffers before being dispatched, the target and initiator must wait for the PDU to be fully constructed before determining the number of DataSN values were consumed (and thus updating the per-transfer DataSN value used for the start of the next PDU). The target generates large PDUs for SCSI Data-In PDUs in cfiscsi_datamove_in(). The initiator generates large PDUs for SCSI Data-Out PDUs generated in response to an R2T. Reviewed by: mav Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D31222
* Add vn_lktype_write()Konstantin Belousov2021-08-041-15/+5
| | | | | | | | | and remove repetetive code that calculates vnode locking type for write. Reviewed by: khng, markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D31405
* cam: enable kern.cam.da.enable_uma_ccbs by defaultEdward Tomasz Napierala2021-08-011-1/+1
| | | | | | | | | | | This makes the da(4) driver use UMA for its CCBs by default, like ada(4) already does. Please let me know via email if you notice any suspicious kernel messages, Reviewed By: imp Sponsored by: NetApp, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D31257
* cam: clear stack-allocated CCB in the target layerEdward Tomasz Napierala2021-07-213-3/+11
| | | | | | | | | | | | | | Note that, as pointed out by scottl@, this code should really look a bit different, in that the stack allocations should be replaced with dynamic allocation, and the periph creation should be moved to a context where one can use M_WAITOK. See the review for more details. For now let's go with a minimal fix until we're done with UMA CCBs. Reviewed By: mav, imp Sponsored by: NetApp, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D30298
* cam: Mark the qos data is valid in xpd_done_direct() too.Warner Losh2021-07-171-0/+1
| | | | Sponsored by: Netflix
* cam_iosched: use tunable flag and make a bool really a boolWarner Losh2021-07-131-5/+3
| | | | | | | | | kern.cam.do_dynamic_iosched is really a bool, so change its type to bool. While I'm here, also use the CTLFLAG_TUN flag instead of a separate tunable line for it and kern.cam.iosched_alpha_bits. MFC After: 1 week Sponsored by: Netflix
* Fix potential NULL pointer dereference of device physical pathYoung Xiao2021-07-132-4/+10
| | | | | | | | | | | | | | | | | | | | | In ata_dev_advinfo() and nvme_dev_advinfo(), if the physical path is being stored and there is a malloc failure (malloc(9) is called with M_NOWAIT), we could wind up in a situation where the device's physpath_len is set to the length the user provided, but the physpath itself is NULL. If another context then comes in to fetch the physical path value, we would wind up trying to memcpy a NULL pointer into the caller's buffer. So, set the physpath_len to 0 when we free the physpath on entry into the store case for the physical path. Reset the length to a non-zero value only after we've successfully malloced a buffer to hold it. This code mirrors scsi_xpt.c does already as well. Signed-off-by: Young Xiao <92siuyang@gmail.com> Reviewed by: imp PR: 238014
* mmc_cam_sim_default_action: do not touch the ccb after dispatching itAndriy Gapon2021-07-121-2/+1
| | | | | | | | | | | | | | | | | | If MMC_SIM_CAM_REQUEST() is successful the ccb could be running or being completed as the method returns. Modifying the ccb status could override whatever status was already set by a MMC driver. I am not sure what was the purpose of setting the status to CAM_REQ_INVALID in the success path. I assume that it was to catch a possibility that the ccb could be completed without its status explicitly set. So, I am keeping the code, it's just moved to before the MMC_SIM_CAM_REQUEST call. Without this change I was getting random and phantom EIO errors on Rock64 running off an SD card (dwmmc driver) plus occasional panics like: Memory modified after free 0xffffa00003985800(2040) val=6 @ 0xffffa00003985854 panic: Most recently used by CAM CCB MFC after: 1 week
* cam: enable kern.cam.ada.enable_uma_ccbs by defaultEdward Tomasz Napierala2021-07-071-1/+1
| | | | | | | | | | | | | | This makes the ada(4) driver use UMA for its CCBs. While it's da(4) counterpart needs some more testing, this one seems to be safe now. Please let me know via email if you notice any suspicious kernel messages, Reviewed By: imp Sponsored by: NetApp, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D30567
* cam: drop unused 'saved_ccb' field from softcsEdward Tomasz Napierala2021-07-0610-10/+0
| | | | | | | | No functional changes. Do not MFC this, it changes kernel ABI. Sponsored by: NetApp, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D30698
* cam(4): preserve alloc_flags when copying CCBsEdward Tomasz Napierala2021-07-061-2/+23
| | | | | | | | | | | | | | | | | | Before UMA CCBs, all CCBs were of the same size, and could be trivially copied using bcopy(9). Now we have to preserve alloc_flags, otherwise we might end up attempting to free stack-allocated CCB to UMA; we also need to take CCB size into account. This fixes kernel panic which would occur when trying to access a stopped (as in, SCSI START STOP, also "ctladm stop") SCSI device. Reported By: Gary Jennejohn <gljennjohn@gmail.com> Tested By: Gary Jennejohn <gljennjohn@gmail.com> Reviewed By: imp Sponsored by: NetApp, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D31054
* cam: Fix GENERIC-MMCCAM buildWarner Losh2021-06-282-2/+2
| | | | | | | Fix forgotten argument and type error. MMCCAM isn't enabled by default, and I'd mistakenly thought it was, so these went undetected precommit. Sponsored by: Netflix
* cam_sim: remove unused sim_doneq memberWarner Losh2021-06-281-1/+0
| | | | | | | | Its use was removed in 227d67aa54 by mav when locking was revamped. Reviewed by: scottl@, mav@ Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D30890