Commit Graph

336 Commits

Author SHA1 Message Date
mlelstv 965fbc37fb Don't try to discover wedges when the unit isn't online. 2024-02-24 22:06:49 +00:00
mlelstv ddea52491e Don't fetch data beyond end of inquiry buffer, which, here, is not
NUL-terminated.

Reduce target buffer to needed size (product name + NUL terminator).
2022-08-28 10:26:37 +00:00
riastradh ebc8106f69 sd(4): Use d_cfdriver/devtounit to avoid open/detach races. 2022-03-28 12:39:46 +00:00
jakllsch 7e64fd0859 use powerof2() in sd_validate_blksize() 2022-01-27 18:44:49 +00:00
dholland 4bdf3741c4 typo in comment 2021-05-30 06:46:46 +00:00
christos 45516a99e8 PR/55986: Ryo Onodera: DK_BUSY must have mask as second argument. Make cd.c
consistent by also using __BIT()
2021-02-10 16:30:01 +00:00
jakllsch 5e1437bacb spelling fixes in sd.c comments 2020-09-25 13:08:00 +00:00
maxv babb6cb124 constify 2020-04-13 08:05:02 +00:00
riastradh fcabfbde55 Add a flag to dk_dump for virtual disk devices.
If a disk is backed by a physical medium other than itself, such as
cgd(4), then it passes DK_DUMP_RECURSIVE to disable the recursion
detection for dk_dump.

If, however, a device represents a physical medium on its own, such
as wd(4), then it passes 0 instead.

With this, I can now dump to dk on cgd on dk on wd.
2020-03-01 03:21:54 +00:00
mlelstv 7ba6594f1f Set disk product name as disk type. The information can be queried through
drvctl(4).
2019-03-19 06:59:40 +00:00
christos 8e212b8902 Handle the SATA to USB external enclosure sold by "Sabrent" and
made by JMicro (vendor=0x152d product=0x0578). This bridge does
not understand FUA, so add a quirk for it.
2018-10-07 18:14:32 +00:00
mlelstv 3c54dead22 The atapibus detach path did hold the channel mutex while calling into autoconf,
which would trigger a panic when unplugging a USB ATAPI CDROM.

Align detach code for scsibus and atapibus to fix this.

Also avoid races when detaching devices by replacing callout_stop with
callout_halt.
2017-06-17 22:35:50 +00:00
jdolecek ce9e7213cd execute the cache page MODE SENSE with XS_CTL_SILENT; it's pretty normal
for e.g. USB sticks thus showing error is not really useful, and the pretty
printing triggers autoload of scsiverbose module and immediate deadlock when
the DIOCGCACHE call is made by WAPBL during root mount

adresses PR kern/52147 by Michael van Elst
2017-04-10 18:20:43 +00:00
jdolecek 6801660c77 expose disk device FUA/DPO support via DIOCGCACHE, and allow the flags
to be set for I/O; implement support in sd(4) and nvme(4)

discussed on tech-kern
2017-04-05 20:15:49 +00:00
mlelstv 6081459242 really keep request queued after resource shortage 2016-12-21 21:28:30 +00:00
mlelstv f572c6cbcd add comment about "missing" dk_start. 2016-12-16 14:58:53 +00:00
mlelstv 722016fe51 Refactored sd and cd to use common disk subroutines. 2016-12-10 10:26:38 +00:00
mlelstv b6a6db8fe4 Make scsipi framework MPSAFE.
Data structures are now protected by a per-adapter mutex at IPL_BIO
that is created by the scsibus or atapibus instance when the adapter
is configured.
The enable reference counter and the channel freeze counter which are
currently used by HBA code before the adapter is configured, are made
atomic.
The target drivers are now all tagged as D_MPSAFE.

Almost all HBA drivers still require the kernel lock to present,
so all callbacks into HBA code are still protected by kernel lock
unless the driver is tagged as SCSIPI_ADAPT_MPSAFE.

TODO: refactor sd and cd to use dksubr.
2016-11-20 15:37:19 +00:00
pgoyette 9300beb87f Avoid calling bufq_free() from critical code sections. 2016-11-20 02:38:24 +00:00
pooka 95d0d1d66e would you like some freshly ground _KERNEL_OPT with that?
yes?  excellent choice, sir/madam.
2015-08-24 23:13:15 +00:00
mlelstv 6f00c789e1 Use C99-style initializers for struct dkdriver. 2015-04-26 15:15:19 +00:00
riastradh 233f556c2e Convert sys/dev to use <sys/rndsource.h>. 2015-04-13 16:33:23 +00:00
christos c182898b0d We have three sets of DTYPE_ constants in the kernel:
altq		Drop 		Type
	disklabel	Disk 		Type
	file		Descriptor	Type
(not to mention constants that contain the string DTYPE).
Let's make them two, by changing the disklabel one to be DisK TYPE since the
other disklabel constants seem to do that. Not many userland programs use
these constants (and the ones that they do are mostly in ifdefs). They will
be fixed shortly.
2015-01-02 19:42:05 +00:00
christos c60db2e923 make more drivers use disk_ioctl, and add a dev parameter to it so that
we can merge the "easy" disklabel ioctls to it. Ultimately all this will
go do dk_ioctl once all the drivers have been converted.
2014-12-31 19:52:04 +00:00
christos 3be6bb2414 Centralize wedge ioctls in disk_ioctl. 2014-12-31 17:06:48 +00:00
mlelstv bdddf44518 disk_blocksize and disk_set_info relay the same information
to the disk subsystem.

Make disk_set_info also set blocksize shift values.
Remove every call to disk_blocksize.

Keep disk_blocksize for ABI compatibility, make it also set dg_secsize.
2014-12-31 08:24:50 +00:00
mlelstv 64c07f5206 support DIOCMWEDGES ioctl. 2014-11-04 07:51:54 +00:00
matt 42ec0ad229 Don't use new as a variable name. 2014-09-05 05:30:42 +00:00
tls ea6af427bd Merge tls-earlyentropy branch into HEAD. 2014-08-10 16:44:32 +00:00
dholland f9228f4225 Add d_discard to all struct cdevsw instances I could find.
All have been set to "nodiscard"; some should get a real implementation.
2014-07-25 08:10:31 +00:00
dholland 8c70ef39af Add d_discard to all struct bdevsw instances I could find.
I've set them all to nodiscard. Some of them (wd, dk, vnd, ld,
raidframe, maybe cgd) should be implemented for real.
2014-07-25 08:02:18 +00:00
dholland a68f9396b6 Change (mostly mechanically) every cdevsw/bdevsw I can find to use
designated initializers.

I have not built every extant kernel so I have probably broken at
least one build; however I've also found and fixed some wrong
cdevsw/bdevsw entries so even if so I think we come out ahead.
2014-03-16 05:20:22 +00:00
martin b083a17f72 Mark a diagnostic-only variable 2013-10-25 16:01:56 +00:00
skrll 36b20552e1 Remove unnecessary initialisation of error 2013-09-28 09:01:36 +00:00
kiyohara e7fba601e4 Reset variable error to 0 before handle each ioctl cmd. Or returns EPASSTHROUGH
when some cmds. (e.g. ODIOCGDINFO)
2013-09-26 16:00:54 +00:00
tls 5819ac2839 Convert the entropy pool framework from pseudo-callout-driven to
soft interrupt driven operation.

Add a polling mode of operation -- now we can ask hardware random number
generators to top us up just when we need it (bcm2835_rng and amdpm
converted as examples).

Fix a stall noticed with repeated reads from /dev/random while testing.
2013-06-13 00:55:01 +00:00
christos 7b845fa9dc phase 1 of disk geometry cleanup:
- centralize the geometry -> plist code so that we don't have
	  n useless copies of it.
2013-05-29 00:47:48 +00:00
jakllsch d673e87705 Clamp sectors per unit in the default disklabel to the maximum value,
instead of allowing it to wrap, as is already done in wd(4).
2013-04-16 21:01:09 +00:00
bouyer 63d14cff85 Expand struct scsipi_bustype {} in a ABI-backward-compatible way to
pass more informations about the bus:
- bustype_type has 2 different bytes, one holding the existing
  SCSIPI_BUSTYPE_* (scsi, atapi, ata), and one for a per-SCSIPI_BUSTYPE_*
  subtype. Introduce macros to build or extract bustype_type.
- for SCSIPI_BUSTYPE_SCSI, define subtypes for parallel SCSI, Fibre Channel,
  SAS and USB, to specify the transport method. SCSIPI_BUSTYPE_SCSI_PSCSI
  is 0 so that bustype_type value doesn't change for existing code
- for non-SCSIPI_BUSTYPE_SCSI busses there's no defined subtype yet,
  so the bustype_type value doesn't change.
- provide scsi_fc_bustype, scsi_sas_bustype and scsi_usb_bustype
  along with scsi_bustype to be used by bus driver where appropriate
- scsipi_print_xfer_mode(): more existing code under a
  (SCSIPI_BUSTYPE_SCSI, SCSIPI_BUSTYPE_SCSI_PSCSI) case, as
  sync/wide parameters only make sense for parallel SCSI.
  For (SCSIPI_BUSTYPE_SCSI, SCSIPI_BUSTYPE_SCSI_FC) and
  (SCSIPI_BUSTYPE_SCSI, SCSIPI_BUSTYPE_SCSI_SAS), only print
  tagged queing status if enabled. Just be silent for other
  bustypes.

This change is prompted by this problem:
right now, FC (e.g. isp(4)) and SAS (e.g. mfi(4)) don't
  do anything for ADAPTER_REQ_SET_XFER_MODE, and especially never
  call scsipi_async_event(ASYNC_EVENT_XFER_MODE), so sd(4) always
  runs untagged. Doing a scsipi_async_event(ASYNC_EVENT_XFER_MODE) with
  appropriate parameters is enough to enable tagged queuing,
  but then scsipi will print:
  sd0: async, 8-bit transfers, tagged queueing
  which is harmless (async, 8-bit transfers doens't make sense on SAS anyway)
  but will confuse users. With this change scsipi will only print:
  sd0: tagged queueing
  which is correct.

In the long run, knowning the underlying transport in scsipi will
allow better handling of device which are not parallel SCSI.

Another change adding an extra callback to struct scsipi_bustype {}
will come (so that scsipi_print_xfer_mode(), which is SCSI-specific,
can be moved out of scsipi_base, and split into per-subtype callback),
but this will break kernel ABI and so is not suitable for
netbsd-6, so will be commmited later. The above is enough to get
tagged queuing on FC and SAS in netbsd-6.
2012-04-19 17:45:20 +00:00
christos d365bff1e6 Add a quirk for the Apple iPod whose mode sense commands fails with not ready.
Seems to work just fine if we send a start command first...
2012-04-06 22:50:39 +00:00
tls 7b0b7dedd9 Entropy-pool implementation move and cleanup.
1) Move core entropy-pool code and source/sink/sample management code
   to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
   source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
   avoid expensive operations on disabled entropy sources; make the
   rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
   have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
   system events, and skew between clocks, with a sample implementation
   for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files).  Tested with release
builds on amd64 and evbarm and live testing on amd64.
2012-02-02 19:42:57 +00:00
joerg 67a671ee08 Replace memset with incorrect size argument with M_ZERO. 2011-11-25 12:39:55 +00:00
jmcneill d2b1c474ba Add an FSILENT flag and use it to suppress "Medium Not Present" scsipi
spam when trying to access offline drives at boot.
2011-07-30 12:08:36 +00:00
jakllsch 2b2a5770cc Implement DIOC[GS]STRATEGY for sd(4). 2010-04-14 22:26:33 +00:00
dyoung c1b390d493 A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.
2010-02-24 22:37:54 +00:00
dyoung cd6e1fbf91 Expand PMF_FN_* macros. 2010-01-08 19:53:10 +00:00
rmind 40cf6f3659 Remove uarea swap-out functionality:
- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code.  Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.
2009-10-21 21:11:57 +00:00
jnemeth 1af929341b Fix previous where the call of sd_set_properties was moved from
the end of sdattach() to the end of sd_get_parms().  The code at
the bottom of sd_get_parms() was only used for optical drives or
in the case where the drive geometry couldn't be retrived for some
reason, to create a fake geometry.  The case for setting up the
real geometry was handled above that code.
2009-08-03 09:40:45 +00:00
jakllsch 23eef70a5f Move call of sd_set_properties() to end of sd_get_parms(), rather than
sdattach().  This allows DIOCGDISKINFO to do the right thing even when
the media has changed.  Note that drvctl -p will only DTRT if disk has
been opened since the most recent media chenged.
2009-06-21 14:06:49 +00:00
haad f5b48500f1 Add support for DIOCGDISKINFO to disk like device drivers. Change
partutil.c::getdiskinfo to use it to get disk geometry info.
Use DIOCGWEDGEINFO ioctl to get information about partition size, if disk
driver doesn't support it use old DIOCGDINFO. This patch adds support for
wedge like devices(lvm logical volumes, ZFS zvol partitions) to newfs and
other tools.

No objections on tech-userlevel@.
2009-06-05 21:52:31 +00:00