summaryrefslogtreecommitdiff
path: root/sys/scsi/sd.c
AgeCommit message (Collapse)Author
2020-03-10Access 4-byte address field with _4btol() not _8btol(), fixingKenneth R Westerback
detecton of a 0 value. CID 1488899
2020-02-20Relax the grip the dead hand of QBUS (a.k.a. MAXPHYS) has on theKenneth R Westerback
throat of physio(). Allows individual devices to eventually be modified to support larger physio() (a.k.a. 'raw') i/o's if they prove capable of them. No immediate functional change. Tested for many weeks by and ok robert@.
2020-02-05Nuke unnecessary abstraction 'scsi_minphys()' which just callsKenneth R Westerback
'minphys()'. Just use & check for NULL instead, since 'minphys()' is always called on the code path ([cd|sd|st]minphys) that calls physio().
2020-01-26Shuffle some names around to make reading the code less headacheKenneth R Westerback
inducing. Rename scsi_adapter member 'scsi_minphys' to 'dev_minphys' to reflect what it is supposed to do. Use consistent naming convention (<dev>_minphys) for the actual device functions. No functional change.
2020-01-25Ensure scsi_minphys() is always called on the physio() path.Kenneth R Westerback
Will allow simplification of individual driver *minphys() functions. ok jmatthew@ as part of larger diff
2019-12-08Various cleanup tweaks. 'return' is not a function. KNF. Whitespace,Kenneth R Westerback
Comment fixes.
2019-12-05Shrink scsi_mode_do_sense() parameter list by eliminating the threeKenneth R Westerback
pointers returning possible block descriptor values for block size, block count and density. Most calls were passing "NULL, NULL, NULL" since they did not care. Call scsi_parse_blkdesc() directly in those few cases where one or more of the values is of interest. No intentional functional change.
2019-12-03Check for expected mode sense page code as well as expected mode page length ↵Kenneth R Westerback
when constructing the pointer to the page data. Remove now unneeded DISK_PGCODE(). Usual misc whitespace/modernization tweaks to functions being modified.
2019-11-29DISK_PGCODE() #define includes a check for NULL, so no need toKenneth R Westerback
do the same check before invoking it.
2019-11-28Always pass a pointer to 'big' to scsi_do_mode_sense().Kenneth R Westerback
Sets up some simplifications.
2019-11-26Reinitialize 'err' to ensure we are not checking a stale value.Kenneth R Westerback
Discovered by and ok tim@
2019-11-25Move struct scsi_read_cap_data and struct scsi_read_cap_data_16 toKenneth R Westerback
scsi_all.h. Add scsi_read_cap_10() and scsi_read_cap_16() functions to scsi_base.c, i.e. move logic to do actual READ_CAPACITY commands out of sd_read_cap() and sd_read_cap_16(). This will allow the READ_CAPACITY code to be reused by cd(4). Return -1 for errors where the error code is just discarded, reducing ENOMEM, ENXIO, EIO uses. No intentional functional change.
2019-11-23Consistently use ISSET() to check for set flags.Kenneth R Westerback
2019-11-23Consistently use !ISSET() to check for unset flags.Kenneth R Westerback
2019-11-09Shuffle sd_get_parms() logic to ensure we only update sc->params withKenneth R Westerback
a complete set of validated (possibly fictitious) data. Add SCSIDEBUG output showing mismatch between disksize and cyls * heads * sectors.
2019-11-09Fix SCSIDEBUG display of VPD inquiry data.Kenneth R Westerback
Remove extraneous whitespace in SCSIDEBUG read capacity display.
2019-11-09Fix SCSIDEBUG compile. Missed a %lx -> %x.Kenneth R Westerback
2019-11-08The u_long fields in struct disk_parms (secsize, heads, cyls, sectors)Kenneth R Westerback
are always initializd to u_int32_t values. And are then copied into u_int32_t fields in the disklabel. Switch them to u_int32_t. Cluebats and ok deraadt@ jca@
2019-11-07sd_size() is a wrapper around sd_read_cap_10() and sd_read_cap_16() soKenneth R Westerback
rename it sd_read_cap(). Reduces possible confusion with the unrelated sdsize().
2019-10-23There used to be three possible return values from sd_get_parms(), butKenneth R Westerback
for some years it's been a succeed/fail function. So switch to using 0/-1 as return values and nuke SDGP_RESULT_OFFLINE and SDGP_RESULT_OK #defines. Shake out logic inside sd_get_parms() to take account of the change, making it clearer. Removes a possible panic().
2019-10-22No need to always pass the same thing to sd_get_parms(). One lessKenneth R Westerback
parameter to worry about.
2019-10-19Use !ISSET() for unset flag checks.Kenneth R Westerback
2019-10-19Use ISSET() for the easier flag checks.Kenneth R Westerback
2019-10-19Fix typo in previous, link->flag is link->flags.Kenneth R Westerback
2019-10-19Resolve mix of '&=' and CLR() usage in favour of CLR().Kenneth R Westerback
2019-10-19Resolve mix of '|=' and SET() usage in favour of SET().Kenneth R Westerback
2019-09-29Introduce SC_DEBUG_SENSE() and simplify code by eliminating a bunchKenneth R Westerback
of three line SCSIDEBUG chunks.
2019-09-29Tweak some whitespace to make autoindenter happy. Use consistent naming ↵Kenneth R Westerback
idiom for the debug functions.
2019-09-27Add/tweak #endif comments to make spelunking via grep more rewarding.Kenneth R Westerback
2019-09-20Print inquiry and read capacity (10 and 16) data under SCSIDEBUG.Kenneth R Westerback
2019-09-15With the recent fixes to SCSI version detection we reproduced aKenneth R Westerback
problem encountered by FreeBSD and Linux when they started to try issuing READ CAPACITY 16 commands to 'newer' devices. i.e. some USB devices return bad data instead of an error when they can't handle the command. Reproduce the FreeBSD solution (r233746 by mav@) by issuing READ CAPACITY 16 commands only to devices that claim to be REALLY new (a.k.a. newer than SPC-2, a.k.a. newer than SCSI-3), or which indicate they really are bigger than can be reported via READ CAPACITY 10. Should fix some USB devices claiming to have 71,776,119,061,217,281 or 33,601,071,049,867,265 sectors.
2019-09-14Typo in comment. scsi_size() is actually sd_size().Kenneth R Westerback
2019-09-01Adopt the SCSI versioning #define's from FreeBSD. Eliminate theKenneth R Westerback
now unneeded version_to_spc() mapping array, a duplicate #define and a couple of magic numbers. Toss in some comments for future generations of spelunkers. Makes it possible to check for specific SPC versions when new features or eliminated features require such a check. No intentional functional change.
2019-08-28Introduce SCSI0(), SCSI2() and SCSI3() defines to clarify (some) usesKenneth R Westerback
of SCSISPC() when checking the values of the INQUIRY version field.
2019-01-20No leading space(s) before labels.Kenneth R Westerback
Prodded by guenther@
2019-01-20When retiring a SCSI request, sometimes the buf's b_error value isKenneth R Westerback
forcibly set to a value. Make sure that in all those cases the B_ERROR flag is cleared (if b_error is being set to 0) or set (if b_error is being set to non-zero) appropriately. ok dlg@ jmatthew@
2017-12-30Don't pull in <sys/file.h> just to get fcntl.hPhilip Guenther
ok deraadt@ krw@
2017-09-08If you use sys/param.h, you don't need sys/types.hTheo de Raadt
2017-05-29sd: flush cache when closing writable FDStefan Fritsch
Don't skip the cache flush until the last opening of the device is closed. Otherwise, when umounting a writable partition while a different partition is still mounted read-only, the necessary disk flush may be delayed for a very long time. ok krw@ deraadt@
2017-05-29Add an ioctl to tell storage devices to flush their internal cachesStefan Fritsch
Currently implemented for wd and sd. Initially ported from netbsd by pedro@ ok deraadt@
2017-05-29To prevent anyone else from stumbling on this (now) archaic bit ofKenneth R Westerback
history, nuke all mentions of XS_NO_CCB and the #define. 2006 - 2017. R.I.P. ok kettenis@ inferred ok dlg@
2017-05-04Also pass the blk offset to disk_unbusy(), so that it can pass it toTheo de Raadt
the random subsystem as entropy. This value is pretty much unknown, and anyways our entropy input ring does not saturate from knowns. ok mikeb djm
2016-03-19Do not run into sdgetdisklabel() when scsi disk is dying. AddAlexander Bluhm
special error handling in sdopen() as temporary hack. OK krw@
2016-03-18After sleeping and before accessing sc_link, check that scsi diskAlexander Bluhm
is not dying. OK krw@
2016-03-17Do not access the scsi link structure in sdclose() if the diskAlexander Bluhm
device is already dying. Delete the sc_timeout when setting the SDF_DYING flag as the timeout delete in sdclose() may not be reached. OK krw@
2016-03-16Add SDF_DYING checks to more functions in scsi disk, to prevent anAlexander Bluhm
use after free of the scsi link structure during detach. OK krw@
2016-03-12Standardize on calling local scsi_link variables 'link' instead ofKenneth R Westerback
'sc_link'. 'sc_link' is a field in the various device *_softc structures, where the sc_ prefix was for 'softc'. Reduces potential mental confusion. Newer code from down under was already using 'link'. No functional change. Prompted by bluhm@'s adventures in scsi. ok dlg@ jmatthew@
2016-03-12When unplugging an USB umass stick, the kernel could panic becauseAlexander Bluhm
of a use after free. In sdopen() the scsi link pointer is taken from the scsi disk struct. While the scsi disk memory is refcounted by autoconf, the scsi link may be detached and freed during sleep. The solution is to check wether the disk is dying after every sleep. The SDF_DYING flag is set before scsi bus and scsi disk are detached, so without this flag the link must be valid. input and OK krw@
2016-02-03Do not access the scsi link of the disk at the beginning of sdopen()Alexander Bluhm
and sdminphys() if the scsi disk is dying. The memory of the link may have been freed already. OK krw@
2016-02-03When accessing the scsi link of a scsi disk, use a variable "sc_link"Alexander Bluhm
everywhere. This is the first step to fix a use after free of the sc_link when the disk detaches. If a function gets a scsi transfer, the scsi link is always valid. Call this variable "link" consistently. OK krw@