aboutsummaryrefslogtreecommitdiff
path: root/sys/cam/ata
Commit message (Collapse)AuthorAgeFilesLines
* ata_da: add quirk to disable NCQ TRIM for Samsung 860/870 SSDsAndriy Gapon2024-02-191-0/+16
| | | | | | | | | | | | | | | | | | NCQ TRIM for Samsung 860/870 SSDs results in data corruption on systems with some SATA controllers. This can be easily reproduced using ZFS which uses TRIM and is able to detect block content changes. Linux bug report for this issue: https://bugzilla.kernel.org/show_bug.cgi?id=201693 Since at present we can not limit a quirk based on the contorller / SIM, apply the quirk in all cases. Reviewed by: imp MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D43961
* ada: Another NCQ Trim instability driveWarner Losh2024-02-191-0/+5
| | | | | | | | The Seagate IronWolf 110 SATA SSD drive has been reported to be unstable with NCQ trim enabled. PR: 264139 Sponsored by: Netflix
* CAM: Replace random sbuf_printf() with cheaper cat/putc.Alexander Motin2023-11-223-20/+20
|
* CAM: Use sbuf_new_for_sysctl() in more placesAlexander Motin2023-11-221-8/+4
| | | | | | There is no need to allocate buffer, worry about overflows, etc. MFC after: 2 weeks
* cam: Remove left-over sys/cdefs.h in sys/camWarner Losh2023-11-063-3/+0
| | | | | | | These weren't removed when $FreeBSD$ was removed. They aren't needed and now are a style(9) nonconformity. Sponsored by: Netflix
* cam: Minor opt_cam.h cleanupWarner Losh2023-11-061-2/+0
| | | | | | | | | | | | | | sys/cam/cam.h includes opt_cam.h, so none of the clients need to do this. cam.h does all the right dancing to conditionally include opt_cam.h only when it makes sense. It generally only matters when cam_debug.h is included (it must be included before that). Many of the stray opt_cam.h includes were after cam_debug.h which would be a problem were it not included in cam/cam.h. The other users of CAM options that aren't debug all already include cam/cam.h. Also trim unneeded sys/cdefs.h files from the files touched. Sponsored by: Netflix
* cam/ata: Postpone removal of two compat sysctls until 15Zhenlei Huang2023-11-021-2/+2
| | | | | | | | | | | Prefer UNMAPPEDIO and ROTATING from flags sysctl. See 1. aeab0812e68c (Add flags sysctl to ada) 2. cf3ff63e55e4 (Convert unmappedio over to a flag) 3. 96eb32bf0f5a (Convert rotating to a flag bit) Reviewed by: imp, ken, #cam MFC after: immediately (we want this in 14.0) Differential Revision: https://reviews.freebsd.org/D42402
* sys: Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-164-8/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* sys: Remove $FreeBSD$: two-line .h patternWarner Losh2023-08-161-2/+0
| | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
* cam: Remove non-sbuf announce/denounce proto and xport opsJohn Baldwin2023-08-011-89/+0
| | | | | | Reviewed by: mav, imp Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D41264
* cam/ata: Migrate to modern uintXX_t from u_intXX_tWarner Losh2023-07-255-74/+74
| | | | | | | | As per https://lists.freebsd.org/archives/freebsd-scsi/2023-July/000257.html move to the modern uintXX_t. MFC After: 3 days Sponsored by: Netflix
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-125-5/+5
| | | | | | | | | The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch up to that fact and revert to their recommended match of BSD-2-Clause. Discussed with: pfg MFC After: 3 days Sponsored by: Netflix
* cam: Properly mask out the status bits to get completion codeWarner Losh2023-04-151-2/+2
| | | | | | | | | | | | | | | | | | ccb_h.status has two parts: the actual status and some addition bits to indicate additional information. It must be masked before comparing against completion codes. Add new inline function cam_ccb_success to simplify this to test whether or not the request succeeded. Most of the code already does this, but a few places don't (the rest likely should be converted to use cam_ccb_status and/or cam_ccb_success, but that's for another day). This caused at least one bug in recognizing devices behind a SATA port multiplexer, though some of these checks were fine with the special knowledge of the code paths involved. PR: 270459 Sponsored by: Netflix MFC After: 1 week (and maybe a EN requst) Reviewed by: ken, mav Differential Revision: https://reviews.freebsd.org/D39572
* Delay GEOM disk_create() until CAM periph probe completes.Alexander Motin2022-07-141-19/+17
| | | | | | | | | | | | | | | | | | | | | | | | | Before this patch CAM periph drivers called both disk_alloc() and disk_create() same time on periph creation. But then prevented disks from opening until the periph probe completion with cam_periph_hold(). As result, especially if disk misbehaves during the probe, GEOM event thread, triggered to taste the disk, got blocked on open attempt, potentially for a long time, unable to process other events. This patch moves disk_create() call from periph creation to the end of the probe. To allow disk_create() calls from non-sleepable CAM contexts some of its duties requiring memory allocations are moved either back to disk_alloc() or forward to g_disk_create(), so now disk_alloc() and disk_add_alias() are the only disk methods that require sleeping. If disk fails during the probe disk_create() may just be skipped, going directly to disk_destroy(). Other method calls during that time are just ignored. Since GEOM may now see the disks after CAM bus scan is already completed, introduce per-periph boot hold functions. Enclosure driver already had such mechanism, so just generalize it. Reviewed by: imp MFC after: 1 month Sponsored by: iXsystems, Inc. Differential Revision: https://reviews.freebsd.org/D35784
* kerneldump: remove physical argument from d_dumperMitchell Horne2022-05-131-2/+2
| | | | | | | | | | | The physical address argument is essentially ignored by every dumper method. In addition, the dump routines don't actually pass a real address; every call to dump_append() passes a value of zero for physical. Reviewed by: markj MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D35173
* ada: Move commentWarner Losh2022-05-041-9/+6
| | | | | | | Move the comment about releasing ccb before periph to adaprobedone() where it belongs. Sponsored by: Netflix
* ada: Retry commands with retries left on CAM_SEL_TIMEOUTWarner Losh2022-05-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The AHCI and ATA SIMs will return CAM_SEL_TIMEOUT when an underlying device has stopped responding. This is usually seen after a timeouted out command and can be a transient event. Rather than fail the peripheral immediately after seeing this, queue a retry. For transient events, this allows drives to continue to provide data, though with some added latency, just like we do when we have some other kind of retriable error. If the error isn't transient (the drive is truly gone), then we'll discover that eventually and fail the transaction and invalidate the drive like we do today. This helps us avoid a panic at the end of camperiphfree when CAM_PERIPH_NEW_DEV_FOUND is set. However, the deferred callback should be queued to xpt_async_td instead of being made inline there. This issue will be solved in a different patch that does that. PR 263703. This also helps us avoid another bug where we can drop all references to the device (causing us to go through camperiphfree and destroy the path) while we have an I/O pending in the ata_da state machine (usually in state ADA_STATE_RAHEAD with ATA_SETFEATURES ATA_SF_ENAB_RCACHE command). It's not clear why the reference that we take out to do the reprobe isn't effective at blocking this. By retrying this condition, though we avoid this bug (at least more often, I don't have a good reproduction test case, I just see this panic a few times a month at work on systems that have transient disk errors on ahci connected SATA SSDs). PR 263704. It's too soon to know how much this helps us avoid this bug. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D34977
* adaasync: Harmonize with daasyncWarner Losh2022-04-261-5/+3
| | | | | | | | | | | | | | | We should call cam_periph_async() always, like SCSI does. This routine is supposed to be more of a catch-all. cam_periph_async() only does actions for AC_LOST_DEVICE. It ignores all other events (today), but this may not always be true. So this is a nop change. Drop in a 'break' so we don't fall through unnecessarily. Sponsored by: Netflix Reviewed by: mav Differential Revision: https://reviews.freebsd.org/D35057
* ada: Eliminate dead codeWarner Losh2022-04-251-4/+0
| | | | | | | | | | | | We never use the cgd that we get from the XPT_GDEV_TYPE call. Prior to 9a6844d55fe33 we used it to determine if READ AHEAD or WRITE CACHING was supported. However, all that information was moved into adasetflags so we no longer need to this since it's cached in the softc and updated with the IDENTIFY data changes automatically. Sponsored by: Netflix Reviewed by: mav Differential Revision: https://reviews.freebsd.org/D35039
* cam: Small reorg of ata xpt async codeWarner Losh2022-04-251-35/+37
| | | | | | | | | Use a switch rather than a nested if to simplify the async event processing code. No functional changes intended. Sponsored by: Netflix Reviewed by: mav Differential Revision: https://reviews.freebsd.org/D35038
* ada/da: Borrow comment from nda about cleanupWarner Losh2022-04-241-3/+4
| | | | | | | Remove a XXX comment and replace it with a more accurate comment about what happens to I/O queued to the hardware. Sponsored by: Netflix
* ata/nvme: Add commentWarner Losh2022-04-241-0/+4
| | | | | | Steal the comment from daonninvalidate about the call to disk_gone(). Sponsored by: Netflix
* CAM: Replicate e0ceec676dc8 from da to ada and nda.Alexander Motin2022-04-241-0/+3
| | | | MFC after: 1 week
* cam: Fix typos in source code commentsGordon Bergling2022-04-021-2/+2
| | | | | | - s/paniced/panicked/ MFC after: 3 days
* ata_xpt: Rename probe_softc to aprobe_softcWarner Losh2022-01-151-11/+11
| | | | | | | | | | Since both scsi_xpt and ata_xpt use the same name for the softc, this can lead to problems in gdb. Avoid the issue by renaming the ata probe_softc to aprobe_softc as has been done for the aprobe in 0f280cbd0a3a9. This was overlooked at the time. Sponsored by: Netflix MFC After: 2 weeks
* add and use defintions for ATA power modesAndriy Gapon2022-01-111-2/+2
| | | | | | | | | Those can be returned by CHECK POWER MODE command (0xe5). Note that some of the definitions duplicate definitions for Extended Power Conditions. MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D33646
* cam: Relax callouts precisions.Alexander Motin2022-01-071-6/+7
| | | | | | | | On large systems even relatively rare callouts may fire many times per second. This should allow them to aggregate better, since we do not require any precision when polling for media change, etc. MFC after: 2 weeks
* adaspindown: check disk power mode before sending IDLE commandAndriy Gapon2021-12-241-0/+47
| | | | | | | | | If a disk is already in STANDBY mode, then setting IDLE mode can actually spin it up. Reviewed by: mav MFC after: 4 weeks Differential Revision: https://reviews.freebsd.org/D33588
* 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): Mark all sysctls as CTLFLAG_MPSAFE.Alexander Motin2021-08-111-3/+3
| | | | | | 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 potential NULL pointer dereference of device physical pathYoung Xiao2021-07-131-2/+5
| | | | | | | | | | | | | | | | | | | | | 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
* 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: turn KASSERTs into printfs for nowEdward Tomasz Napierala2021-05-161-0/+8
| | | | | | | | | | | | | It looks like I've missed a couple of places where we don't clear stack-allocated CCBs. Don't panic when that happens, just print a warning. This is a temporary measure until I get those cases fixed. Reviewed By: markj Sponsored by: NetApp, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D30296
* cam: add missing zeroing of a stack-allocated CCB.Edward Tomasz Napierala2021-05-161-0/+1
| | | | | | | | This could cause a panic at boot. Reported By: Shawn Webb <shawn.webb AT hardenedbsd.org> Sponsored by: NetApp, Inc. Sponsored by: Klara, Inc.
* cam: allocate CCBs from UMA for SCSI and ATA IOEdward Tomasz Napierala2021-05-152-0/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch makes it possible for CAM to use small CCBs allocated from an periph-specific UMA zone instead of the usual, huge ones. The end result is that CCBs issued via da(4) take 544B (size of ccb_scsiio) instead of the usual 2kB (size of 'union ccb', ~1.5kB, rounded up by malloc(9)). For ATA it's 272B. We waste less memory, we avoid zeroing the unused 1kB, and it should be easier to allocate those CCBs in low memory conditions. It should also be possible to use uma_zone_reserve(9) to improve behaviour in low memory conditions even further. Note that this does not change the size, or the layout, of CCBs as such. CCBs get allocated in various different ways, in particular on the stack, and I don't want to redo all that. Instead, this provides an opt-in mechanism for the periph to declare "my start() callback is fine with receiving a CCB allocated from this UMA zone". In other words, most of the code works exactly as it used to; the change only happens to IOs issued by xpt_run_allockq(), which is - conveniently - pretty much all that matters for performance. The reason for doing it this way is that it's pretty small, localized change, and can be implemented gradually and iteratively: take a periph, make sure its start() callback only casts the CCBs it takes to a particular type of CCB, for example ccb_scsiio, and that it only casts CCBs returned by cam_periph_getccb() to that type, then add UMA zone for that size, and declare it safe to XPT. This is disabled by default. Set 'kern.cam.ada.enable_uma_ccbs=1' and 'kern.cam.da.enable_uma_ccbs=1' tunables to enable it. Testing is welcome; I will flip the default to enable in two weeks from now. Reviewed By: imp Sponsored by: NetApp, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D28674
* cam: make sure to clear even more CCBs allocated on the stackEdward Tomasz Napierala2021-04-112-0/+5
| | | | | | | | | | | This is my second pass, this time over all of CAM except for the SCSI target bits. There should be no functional changes. Reviewed By: imp Sponsored by: NetApp, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D29549
* cam: Don't permit crashdumps on non-pollable devices.John Baldwin2021-02-111-1/+2
| | | | | | | | | | | If a disk's SIM doesn't support polling, then it can't be used to store crashdumps. Leave d_dump NULL in that case so that dumpon(8) fails gracefully rather than having dumps fail at crash time. Reviewed by: scottl, mav, imp MFC after: 2 weeks Sponsored by: Chelsio Differential Revision: https://reviews.freebsd.org/D28454
* ada(4): remove remainder of MD geometry translation supportMarius Strobl2020-12-251-9/+0
| | | | | This was missed in 9cf738228dc8563732f7cb332737a6d2b732e2e3 and r359718 respectively.
* 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
* Fix sbuf_finish() error code check in user-space.Alexander Motin2020-10-131-2/+12
| | | | | | | | MFC after: 1 week Sponsored by: iXsystems, Inc. Notes: svn path=/head/; revision=366689
* cam: clean up empty lines in .c and .h filesMateusz Guzik2020-09-013-13/+3
| | | | Notes: svn path=/head/; revision=365225
* [ata_da] remove duplicate definition; it trips up ye olde gcc-6 on mips32Adrian Chadd2020-05-271-1/+0
| | | | | | | Checked first with: irc Notes: svn path=/head/; revision=361546
* cam: ANSIfy 0-argument function definitionsConrad Meyer2020-05-161-1/+1
| | | | | | | | | | No functional change. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D24854 Notes: svn path=/head/; revision=361111
* Make the ata probe* and xpt* routines aprobe* and axpt* respectively.Warner Losh2020-05-131-51/+50
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Often, in traiging core files, one only has a traceback of where a panic occurred. We have probe* and xpt* routines that live in both the scsi and ata layers with identical names. To make one or the other stand out, prefix all the probe and xpt routines in ata with an 'a'. I've left the scsi ones alone since they were there first and are more numerous. I also rejected using #define to do this as being too confusing. I chose this method because the CAM name for the probe device was already 'aprobe'. Normally, this doesn't matter because file scope protects one from interfering with the other. However, due to the indirect nature of CAM's state machine, you don't know if the following traceback is SCSI or ATA: xpt_done probedone xpt_done_process xpt_done_td fork_exit nvme and mmc already have unique names. MFC: 1 week Differential revision: https://reviews.freebsd.org/D24825 Notes: svn path=/head/; revision=360999
* Convert rotating to a flag bit.Warner Losh2020-04-271-9/+12
| | | | | | | | Move rotating to a flag bit. Add bit definitions for it. Create a compat sysctl for it. Notes: svn path=/head/; revision=360412
* Convert unmappedio over to a flag.Warner Losh2020-04-271-7/+25
| | | | | | | | Make unmappedio a flag. Move it to the flags definition. Add compat sysctl for it. Notes: svn path=/head/; revision=360411
* Add flags sysctl to adaWarner Losh2020-04-271-1/+49
| | | | | | | | Report the ada device flags like we do the da devices. No booleans have (yet) been converted, but iomapped and rotating are planned. Notes: svn path=/head/; revision=360410
* Now that we don't have special-case geom hacking defined in md_var.h, stopWarner Losh2020-04-071-2/+0
| | | | | | | | including it. sparc64 was the last straggler here, but these weren't removed at the time. Notes: svn path=/head/; revision=359718
* Add a quirk for the WDC Green series of SSDs to disable NCQ TRIM, as thisScott Long2020-02-271-0/+5
| | | | | | | | | | | avoids silent data corruption. PR: 225666 Submitted by: anders lundgren MFC after: 3 days Notes: svn path=/head/; revision=358366