Commit Graph

1513 Commits

Author SHA1 Message Date
jdolecek 2f9d652e0f fix deadlock in wdcwait() when xfer timeout happens while the atabus
thread sleeps in wdcwait() - check current lwp rather than relying
on global ATACH_TH_RUN channel flag

should fix the hang part of the problem reported in
http://mail-index.netbsd.org/netbsd-users/2020/03/12/msg024249.html

thanks to Paul Ripke for providing extensive debugging info
2020-04-04 21:36:15 +00:00
mlelstv ac2c1135e8 Allow open of RAWPART even when no medium is loaded.
Keep errors silent if no medium is loaded.

Fixes PR kern/55104
2020-03-27 11:15:33 +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
riastradh 13eca39faf Sprinkle some dtrace probes into scsi(4). 2020-02-19 16:05:41 +00:00
riastradh 16dde5e683 C99 initializers for scsipi_bustype. No functional change intended. 2020-02-19 16:04:39 +00:00
chs 64b2d7d8bf the number of possible ATAPI devices on an ATA bus is not always 2,
it is however many devices the underlying ATA bus can have (eg. 1 for SATA),
so initialize the scsipi chan_ntargets from the ATA ch_ndrives.
this fixes a memory read overrun detected by KASAN.
discussed with mlelstv@ and jdolecek@
2020-02-12 00:19:07 +00:00
thorpej d18dc54823 Adopt <net/if_stats.h>. 2020-01-29 05:52:27 +00:00
msaitoh a0403cde04 s/transfered/transferred/ 2019-12-27 09:41:48 +00:00
chs d47bcd296c in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
2019-11-10 21:16:21 +00:00
msaitoh 2d958b1323 Use unsigned to avoid undefined behavior in scsipi_{get,put}_tag().
Found by kUBSan.
2019-09-19 03:37:31 +00:00
mlelstv 5b1bc19ea9 use correct size when copying outgoing sense data. 2019-05-30 16:57:39 +00:00
msaitoh 8375928380 Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*. 2019-05-28 07:41:46 +00:00
mlelstv e94a06bbea Add sanity checks to SCIOCCOMMAND, adapter drivers might be confused or trigger
assertions (e.g. umass).
2019-05-26 08:12:41 +00:00
msaitoh 5542e458a9 Whitespace fix (mainly tabify). 2019-05-23 13:10:50 +00:00
msaitoh 7b05561282 No functional change:
- Change ac(was arpcom) to ec(ethercom)
 - Simplify MII structure initialization.
 - u_int*_t -> uint*_t.
 - KNF
2019-05-23 10:30:35 +00:00
kardel 55613ac346 Add simple position recovery when positioning to EOM by reading
the position with READ_POSITION.
this allows for
	mt eom
	mt st
to return the correct file position.
2019-05-19 19:06:53 +00:00
mlelstv 422da90206 Avoid null pointer deref in printing xfer mode when no target driver
is attached. Fixes kern/54157.
2019-05-03 16:06:56 +00:00
kardel 052322e3b1 Add reading of supported opcodes and their timeouts
at attachment time. Though this information is optional,
it allows to override our fixed timeouts with device
provided timeouts. These timeouts will override the
hardcoded values if the device provided timeouts
exceed the hardcoded values and are less than a day.

Using the device provided timeouts avoids premature
device resets and unreliable operation due to
inadequate timeouts.

Due to the limited implementations of USB
umass devices this feature is disabled for all
umass attached devices.
2019-03-28 10:44:29 +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
msaitoh 659e7a3c69 s/ are are / are /
s/ a a / a /
2019-03-08 08:35:58 +00:00
kamil e222246acd Correct printing type of b_blkno (int64_t) in st.c
Fixes build with kUBSan on NetBSD/i386.
2019-02-23 11:57:41 +00:00
kardel 0cce4ea2bd Fix, but disable the commented SUN compatibility in st.c to write
final file marks by opening and immediately closing the device
 in O_WRONLY mode. That code has not been working since around 1998.
 It can now be enabled with options ST_SUNCOMPAT.
2019-02-12 13:49:13 +00:00
kardel 60af930abe Fix PR kern/53949:
Fix inconsistent/incomplete file mark handling to conform again
to mtio(4) at close(2) time. This was necessary as the PREVENT/ALLOW
bracket was reduced from a whole mount session to cover only the
open(2)/close(2) time on ~2002-03-22. The rationale was to allow
robots and humans to change the media during a mount session.

Unfortunately this lead to file marks being written to potentially other
media at the beginning on drives that used the two file marks as EOM
pattern. In order for that to happen the media had to be removed after
data and at most one file mark had been written before removal.

The mount error message has been clarified and a warning about
potential data/file mark lossage on UNIT ATTENTION
during an active mount session with unfinished file marks has been
added.

While there, fix, but disable the commented SUN compatibility to write
final file marks by opening and immediately closing the device
in O_WRONLY mode. That code has not been working since around 1998.
It can now be enabled with options ST_SUNCOMPAT.

Additionally debug output coverage has been extended.
2019-02-12 13:43:40 +00:00
mrg f09e0846f7 avoid a fallthru checker complaint and make one case like the rest. NFCI. 2019-02-05 11:11:32 +00:00
msaitoh 091e15265d Remove very old IFF_NOTRAILERS flag. 2019-02-05 06:17:00 +00:00
mrg fbffadb9f8 - add or adjust /* FALLTHROUGH */ where appropriate
- add __unreachable() after functions that can return but won't in
  this case, and thus can't be marked __dead easily
2019-02-03 03:19:25 +00:00
tsutsui 314bc7176f Add NOLUNS quirk for more SEAGATE SCA/WIDE drives.
Tested on NetBSD/luna68k and LUNA with SCA 80pin -> NARROW 50pin and
WIDE 68pin -> NARROW 50pin connectors.
2019-01-12 13:59:53 +00:00
bouyer 36b5c50e88 Add more KASSERTS about locking. 2018-11-24 18:15:23 +00:00
jdolecek 7804de8da0 pass correct status + error to *_atapi_phase_complete(), so that
the function is actually able to recognize when there was an error;
tested via reading a cd0 device in QEMU with ejected cdrom

bug was introduced with jdolecek-ncq branch

fixes PR kern/53724 by Andreas Gustafsson
2018-11-12 20:54:03 +00:00
jdolecek 65a96d6bf9 hold channel lock during whole ata_dmaerr()/ata_downgrade_mode() -
according to code inspection this is safe, none of the set_modes
hooks execute anything which would be taking the lock

adresses PR kern/53714 by Andreas Gustafsson
2018-11-12 18:51:01 +00:00
jdolecek 3fa9d7b0da Merge jdolecek-ncqfixes branch
- ata_xfer's are dynamicall allocated as needed using a pool, no longer
  limited to number of possible openings supported by controller; dump
  and recovery paths use dedicated pre-allocated storage
- moved callouts and condvars from ata_xfer to queue or channel, so that
  ata_xfer does not need special initialization
- slot allocation now done when xfer is being activated, uncoupled
  from memory allocation; active slots are no longer tracked by controller
  code
- channel and drive reset is done always via the atabus thread, and
  now executes with channel locked the whole time
- NCQ recovery moved to shared function, and run via the thread also
- added some workarounds for buggy error recovery AHCI emulation in QEMU
  and Parallels

designed to primarily fix kern/52614, but might also help with kern/47041
and kern/53183
2018-10-22 20:13:47 +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
mrg 85526a327c don't print a blank line that ends up in logs and console output. 2018-09-16 23:20:18 +00:00
riastradh d1579b2d70 Rename min/max -> uimin/uimax for better honesty.
These functions are defined on unsigned int.  The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER!  Some subsystems have

	#define min(a, b)	((a) < (b) ? (a) : (b))
	#define max(a, b)	((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX.  Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate.  But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all.  (Who knows, maybe in some cases integer
truncation is actually intended!)
2018-09-03 16:29:22 +00:00
mlelstv 0b4ba8daf5 Wait in detach if the discovery thread is still running. Avoids crashes
when a device is attached/detached rapidly.
2018-09-01 07:20:29 +00:00
mlelstv 43a5ce6146 Make wdcdebug_atapi_mask configurable like the other debug variables. 2018-09-01 07:19:19 +00:00
kamil 1879ee6236 Avoid undefined behavior in scsipiconf.h in _4ltol() and _4btol()
Do not shift (through integer promotion) a signed value in an operation
than can change the bit of signedness.

sys/dev/scsipi/scsipiconf.h:808:17, left shift of 255 by 24 places cannot be represented in type 'int'

Detected with Kernel Undefined Behavior Sanitizer.

Reported by <Harry Pantazis>
2018-07-04 03:17:01 +00:00
msaitoh 3cd62456f9 Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

 This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
2018-06-26 06:47:57 +00:00
msaitoh 4b508fb16e It's not required to include net/bpfdesc.h. Remove it. 2018-06-22 04:17:40 +00:00
mlelstv 76e339c2fc Use separate lock to protect internal state and release locks when
calling biodone.
2018-03-24 08:08:19 +00:00
kamil 75b6fdf893 Revert previous commit in st.c in order to unbreak build
There are various build errors like:
/usr/src/sys/dev/scsipi/st.c: In function 'stattach':
/usr/src/sys/dev/scsipi/st.c:398:16: error: 'struct st_softc'
has no member named 'buf_defer'; did you mean 'buf_queue'?
  bufq_alloc(&st->buf_defer, "fcfs", 0);

Original (reverted) commit:
  Use separate lock to protect internal state and release locks when
  calling biodone.
2018-03-24 01:45:22 +00:00
mlelstv 9fba504861 Use separate lock to protect internal state and release locks when
calling biodone.
2018-03-23 06:01:07 +00:00
jdolecek 3d3c2e6bb1 fix comment - scsipi_rw_big was renamed to scsipi_rw_10 a while ago 2017-11-04 21:02:37 +00:00
maya 18b796d442 Use C99 initializer for filterops
Mostly done with spatch with touchups for indentation

@@
expression a;
identifier b,c,d;
identifier p;
@@
const struct filterops p =
- 	{ a, b, c, d
+ 	{
+ 	.f_isfd = a,
+ 	.f_attach = b,
+ 	.f_detach = c,
+ 	.f_event = d,
};
2017-10-25 08:12:37 +00:00
msaitoh 916c83ee9b If if_initialize() failed in the attach function, free resources and return. 2017-10-23 09:31:17 +00:00
jdolecek 2ee262ca2c reintroduce ATACH_IRQ_WAIT flag for attachments using wdcintr(), only
process the interrupt when the flag is set - this fixes spurious interrupt
during post-reset drive setup in wdc_ata_bio_start(), and wdc_atapi_start()

while those functions set WDCTL_IDS, this seems to be ignored by certain
(maybe all) PCI-IDE controllers; usually the implicit KERNEL_LOCK() would
prevent the interrupt anyway, but not when the start routine is started
from the atabus thread, which doesn't take it

fixes 'panic: wdc_ata_bio_intr: bad state' reported on current-users
by Chavdar Ivanov
2017-10-17 18:52:50 +00:00
jdolecek 7ba88ded53 revert the logic in wdc_atapi_intr() for wdc_wait_for_unbusy() to what it
was before NCQ merge; it got broken during the efford to remove ch_status
and ch_error on the branch

fixes atapi timeouts in vbox and with real harware reported separately
by Abhinav Upadhyay, Pault Goyette, Chavdar Ivanov, and Rares
Aioanei; with a bit of luck it could also fix PR kern/52605 and/or PR
kern/52606 by Martin Husemann
2017-10-10 21:37:49 +00:00
christos 58c1488ec8 don't initialize tfd twice. 2017-10-08 21:33:38 +00:00
christos 11d6f11f63 initialize tfd 2017-10-08 21:29:34 +00:00
joerg efda439fbd Initialize tfd even when not waiting for DSC. 2017-10-08 21:18:14 +00:00