History log of /openbsd-current/sys/dev/ic/twe.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.67 16-Apr-2022 naddy

constify SCSI adapter entry points

ok krw@


Revision tags: OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.66 14-Jul-2021 daniel

fix "logically dead code" flagged by coverity

It looks like twe was refactored in 2011 and one error check was missed.
While the device may no longer be widely used, this helps reduce the
coverity alert count.

CID 1453371

ok krw@


Revision tags: OPENBSD_6_9_BASE
# 1.65 07-Mar-2021 jsg

ansi


# 1.64 15-Oct-2020 krw

Replace local *_copy_internal_data() with scsi_copy_internal_data().


Revision tags: OPENBSD_6_8_BASE
# 1.63 22-Sep-2020 krw

Since dlg@'s 2009 scsi midlayer refactoring the 'struct scsi_generic *cmd'
member of 'struct scsi_xfer' has always been pointed at the 'struct scsi_generic
cmdstore' member of the same instance. So nuke 'cmdstore' and remove the '*'
from cmd. Take the address of cmd as required by the various casts.

No intentional functional change.

luna88k test by aoyama@, sparc64 test by jmatthew@

Identification of 2009's last *cmd use and ok jmatthew@


# 1.62 05-Sep-2020 krw

Replace '32' with SID_SCSI2_ALEN (a.k.a. 31) when building emulated INQUIRY
responses. This is what the SCSI specifications say is the correct value and
already used in several cases.


# 1.61 03-Sep-2020 krw

Replace '.response_format = 2' with '.response_format = SID_SCSI2_RESPONSE'.


# 1.60 02-Sep-2020 krw

When building emulated INQUIRY results use the SCSI_REV_* #define's to
initialize the 'version' field. Not numbers.


# 1.59 01-Sep-2020 krw

Rename [READ|WRITE]_BIG to [READ|WRITE]_10. Rename struct scsi_rw_big to
struct scsi_rw_10.

ok gnezdo@ jmatthew@ (who also did sparc64 compile test)


# 1.58 24-Jul-2020 krw

Turning on various scsi drivers' *DEBUG options reveals that this has
rarely (if ever) been done.

Fix many printf format errors to calm clang and gcc on amd64, i386,
hppa. Missing #include, complaints if 'option <blah>DEBUG' is used in
config files, etc. All in debug code.


# 1.57 20-Jul-2020 krw

Move remaining scsi bus initialization info from "prototype scsi link"
fields to struct scsibus_attach_args. Nuke the struct scsi_link *
(saa_sc_link) in scaibus_attach_args.

Explicitly initialize each field in scsibus_attach_args variables.


# 1.56 19-Jul-2020 krw

Move the adapter related items (luns, adapter, adapter_target,
adapter_buswidth, adapter_softc) from struct scsi_link to struct
scsibus_attach_args.

Additional compile tests by jmatthew@ (sparc64) and aoyam@ (luna88k).


# 1.55 16-Jul-2020 krw

Access adapter softc via link->bus->sb_adapter_softc.

In sparc64 autoconf access 'luns' via sb_luns and 'adapter_buswidth'
via sb_adapter_buswidth.

Removes last post-config uses of the copies of bus related
information in scsi_link.


# 1.54 27-Jun-2020 krw

Nuke trailing whitespace.


# 1.53 27-Jun-2020 krw

No need to bzero()/memset() 'struct scsibus_attach_args' variables
immediately before initializing the only field in the struct.


# 1.52 24-Jun-2020 krw

Use SDEV_NO_ADAPTER_TARGET instead of the value that is being
aassigned to adapter_buswidth to indicate the adapter is not a target
on the bus.

ok dlg@ as part of a larger diff.


Revision tags: OPENBSD_6_7_BASE
# 1.51 15-Feb-2020 krw

*_minphys() functions that cap i/o sizes at a value larger than the
value minphys() uses (MAXPHYS) are pointless since minphys() is always
called after the *_minphys() function.

MAXPHYS (64 * 1024) == 16 * 4096. 4096 is the smallest PAGE_SIZE we
have. So a *_minphys() function that caps the i/o size at N *
PAGE_SIZE where N is > 16 is just wasting cycles.

Nuke adv_minphys (40 * PAGE_SIZE), adw_minphys (254 * PAGE_SIZE),
ahc_minphys (128 * PAGE_SIZE), ahd_minphys (128 * PAGE_SIZE),
ami_minphys (26 * PAGE_SIZE), cac_minphys (65535 (!!!) * 512),
iha_minphsy (32 * PAGE_SIZE), trm_minphys (31 * PAGE_SIZE),
twe_minphys (62 * PAGE_SIZE). uha_minphys (32 * PAGE_SIZE),


# 1.50 26-Jan-2020 krw

Shuffle some names around to make reading the code less headache
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.


# 1.49 25-Jan-2020 krw

Drivers that implement their own *minphys() don't need to call the
system minphys(). scsi_minphys() will do that and cd/sd/st will call
scsi_minphys().

ok jmatthew@ as part of larger diff


# 1.48 23-Jan-2020 krw

Use a consistant idiom/format when declaring scsi_adapter structures
in drivers. Terse one liners, NULLs instead of 0's, explicitly specify
all members, etc.

Nuke #ifdef notyet blocks related to the scsi_adapter in aic.

No intentional functional change.

ok tedu@


# 1.47 31-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok kn@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.46 22-Jan-2016 jsg

remove a surplus splbio
ok deraadt@ krw@


Revision tags: OPENBSD_5_8_BASE
# 1.45 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.44 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.43 18-Nov-2013 deraadt

format string


# 1.42 18-Nov-2013 deraadt

simplify kthread_create(). no more stdarg
ok matthew guenther mikeb


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.41 17-Jul-2011 matthew

Backout a bunch of my SCSI commits from c2k11. At least one of these
is causing problems when trying to boot sparc64 from an isp(4).

Verified to fix the sparc64/isp(4) regression by krw@; ok deraadt@


# 1.40 08-Jul-2011 matthew

First batch of converting SCSI HBAs from setting saa_targets and
saa_luns instead of adapter_buswidth and luns in the prototype link.

ok dlg@, miod@


# 1.39 03-Apr-2011 dlg

move twe over to iopools so we can get rid of another NO_CCB user. this
also cuts the aen drain over to using an iohandler so it can be made
reliable.

this compiles, but i havent got hardware to test with. its going in as a
way to force testing. if there's a problem with the code then let me know
or back it out.

"man up" k2k11


Revision tags: OPENBSD_4_9_BASE
# 1.38 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


Revision tags: OPENBSD_4_8_BASE
# 1.37 28-Jun-2010 krw

Remove all adapter-specific 'struct scsi_device's. They are never used. First
step in elminating 'struct scsi_device' entirely.

Spotted and initial diff from matthew@.

ok matthew@ dlg@ deraadt@ marco@ miod@


# 1.36 20-May-2010 krw

New scsi code seems to be stable. Pluck previously identified
low-hanging splbio/splx pairs that are no longer needed and see if
this reveals any hidden scsi flaws.

ok dlg@


# 1.35 29-Mar-2010 krw

Initialize various uninitialized variables. Found by jsg@ via Clang.

Feedback from miod@ and kettenis@.

ok beck@


# 1.34 23-Mar-2010 krw

Change the scsi_cmd function member of scsi_adapter from int to
void. Use XS_NO_CCB error in the scsi command (xs) to report the
NO_CCB condition. Eliminates all SUCCESSFULLY_QUEUED and COMPLETE
confusion and untangles the midlayer from the adapter a bit more.

Eyes and some fixes by miod@

There may be some compile issues on little used (i.e. I don't have
any) drivers but the change is mechanical and thus easy to remedy.

ok dlg@


Revision tags: OPENBSD_4_7_BASE
# 1.33 09-Jan-2010 krw

Zap all setting of ITSDONE in drivers that don't look at it. Nobody
else cares so it's just noise. Drivers that actually look at ITSDONE
are unchanged.

ok marco@ (for his files) dlg@ beck@


# 1.32 22-Nov-2009 krw

Bring last drivers fully into the NO_CCB world by replacing
TRY_AGAIN_LATER uses with equivalent NO_CCB. Eliminates confusion
between the two as was always intended. buf I/O's that can't be
started get pushed back onto the front of the queue and retried.
Others get sent back to originator as failures. No more epi-cycle
looping inside the SCSI midlayer hoping the problem goes away.

Various testers, no objection from miod@ as vs(4) was tested by
nick@.


# 1.31 03-Sep-2009 dlg

must call scsi_done before returning complete.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.30 16-Feb-2009 miod

Extend the scsi_adapter minphys() callback to take a struct scsi_link *
as additional argument. This will allow intermediate layers between
scsi devices such as sd and scsi host adapters to take appropriate
action if necessary.


Revision tags: OPENBSD_4_4_BASE
# 1.29 24-Jul-2008 thib

the softc sc_lock lockmgr lock is unused, so remove it.

ok krw@, dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.28 20-Oct-2007 krw

Call scsi_done() at SPLBIO. 'looks olright' says mickey.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.27 29-Dec-2006 pedro

Avoid void * arithmetic, okay deraadt@, suggestions from millert@


# 1.26 28-Nov-2006 dlg

give scsi controllers a real attach args to fill in when attaching scsibus.

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.25 03-Dec-2005 krw

The first thing done when XXX_scsi_cmd() returns TRY_AGAIN_LATER is
to set xs->error to XS_BUSY. So it is pointless and misleading to
set xs->error to XS_TIMEOUT, XS_DRIVER_STUFFUP or XS_BUSY just before
returning TRY_AGAIN_LATER.

No functional change.


# 1.24 15-Sep-2005 krw

Don't fake MODE SENSE page 4 info inside raid drivers, just let sd
fake a geometry. Page 4 info does not get used for size information.
Eliminate now unused union scsi_disk_pages.

ok marco@ mickey@ pre-lock.


Revision tags: OPENBSD_3_8_BASE
# 1.23 03-Jul-2005 krw

Fix data_length values in simulationed MODE SENSE page 4 responses so
that scsi_do_mode_sense() accepts them.

The data_length value does not include itself, and the pg_length value
in a mode page does not include itself or the page_code fields. We
were +1 on the former and -2 on the latter resulting in a data_length
value that was too small by one.

Eliminates 'mode sense page 5 not simulated' messages.

ok marco@


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.22 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


# 1.21 02-Jun-2003 mickey

kill the caluses three and four on some of my code


Revision tags: UBC_SYNC_A
# 1.20 27-Apr-2003 ho

strcpy/sprintf cleanup of sys/dev. miod@, deraadt@ says to commit.


# 1.19 09-Apr-2003 mickey

missing nl in the error msg and a return afterwards


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.18 17-Sep-2002 mickey

deal w/ the dma in a special thread to follow the busdma semantics. this fixes panics on unaligned physio; w/ help and testing from daniel@lucq.org


Revision tags: OPENBSD_3_1_BASE
# 1.17 14-Mar-2002 millert

First round of __P removal in sys


# 1.16 31-Jan-2002 mickey

scsi_done() is unsafe, rearrange locking to compensate


Revision tags: UBC_BASE
# 1.15 06-Dec-2001 mickey

branches: 1.15.2;
clear all inrterrupts separately and before enabling any.
this prevents stray interrupts and sometimes hangs,
caused by looping on stray unmapped interrupt.


# 1.14 05-Nov-2001 art

Switch everything to the new bus_dmamap_sync API.
Most work by Wilbern Cobb <vedge@csoft.org> with some fixes from me, mickey@
and drahn@.


Revision tags: OPENBSD_3_0_BASE
# 1.13 24-Sep-2001 mickey

get rid of kvtop, not that it matters that much


# 1.12 04-Jul-2001 espie

case labels without statements are not permitted by ANSI C... and gcc 3.0
warns about them.


# 1.11 18-May-2001 mickey

stupidous debug was left enabled


# 1.10 10-May-2001 mickey

branches: 1.10.2;
dmamem_unmap the memory before dmamem_freeig it.
only affects unaligned transfers (such as disklabel, fsck and dump).
we used to get away w/ this due to older pmap, uvm or both.
be more precise w/ double-buffer on command failure as well.
once at it, allow more than 1 segment for double-buffer to be allocated.
also fix a couple of endianesses and command timeouts.


Revision tags: OPENBSD_2_9_BASE
# 1.9 14-Mar-2001 mickey

branches: 1.9.2;
it seems sometimes it takes up to 35 seconds to init; from Chris Kuethe ckuethe@[[gecko.]math.]ualberta.ca


# 1.8 09-Mar-2001 mickey

missing twe_unlock for failed get_ccb() for i/o scsi cmd, which was impossible to trigger in twese case because of how maxcmds is calculated


# 1.7 19-Feb-2001 mickey

propoer dmaable memory allocations


# 1.6 07-Jan-2001 mickey

fix a few scsi_done() usages.
simplify locking a bit.
disable write cache if said so in the scsi_xfer.
a few more commands, from freebsd.


# 1.5 08-Nov-2000 mickey

oops, oops w/ no configured units


# 1.4 07-Nov-2000 mickey

estimate sc_link.openings on the number of configured units


Revision tags: OPENBSD_2_8_BASE
# 1.3 25-Sep-2000 mickey

do not do queue locking in get/put_ccb, since calling blocks
have gotten it already locked appropriately.
only try to satiate the command queue if there was a command interrupt,
it seems it's quite well-behaving this way.
dispose allocated resources if twe_attach() fails.


# 1.2 15-Sep-2000 mickey

forgot to turn off debugging


# 1.1 15-Sep-2000 mickey

3ware escalade ide raid controllers


# 1.66 14-Jul-2021 daniel

fix "logically dead code" flagged by coverity

It looks like twe was refactored in 2011 and one error check was missed.
While the device may no longer be widely used, this helps reduce the
coverity alert count.

CID 1453371

ok krw@


Revision tags: OPENBSD_6_9_BASE
# 1.65 07-Mar-2021 jsg

ansi


# 1.64 15-Oct-2020 krw

Replace local *_copy_internal_data() with scsi_copy_internal_data().


Revision tags: OPENBSD_6_8_BASE
# 1.63 22-Sep-2020 krw

Since dlg@'s 2009 scsi midlayer refactoring the 'struct scsi_generic *cmd'
member of 'struct scsi_xfer' has always been pointed at the 'struct scsi_generic
cmdstore' member of the same instance. So nuke 'cmdstore' and remove the '*'
from cmd. Take the address of cmd as required by the various casts.

No intentional functional change.

luna88k test by aoyama@, sparc64 test by jmatthew@

Identification of 2009's last *cmd use and ok jmatthew@


# 1.62 05-Sep-2020 krw

Replace '32' with SID_SCSI2_ALEN (a.k.a. 31) when building emulated INQUIRY
responses. This is what the SCSI specifications say is the correct value and
already used in several cases.


# 1.61 03-Sep-2020 krw

Replace '.response_format = 2' with '.response_format = SID_SCSI2_RESPONSE'.


# 1.60 02-Sep-2020 krw

When building emulated INQUIRY results use the SCSI_REV_* #define's to
initialize the 'version' field. Not numbers.


# 1.59 01-Sep-2020 krw

Rename [READ|WRITE]_BIG to [READ|WRITE]_10. Rename struct scsi_rw_big to
struct scsi_rw_10.

ok gnezdo@ jmatthew@ (who also did sparc64 compile test)


# 1.58 24-Jul-2020 krw

Turning on various scsi drivers' *DEBUG options reveals that this has
rarely (if ever) been done.

Fix many printf format errors to calm clang and gcc on amd64, i386,
hppa. Missing #include, complaints if 'option <blah>DEBUG' is used in
config files, etc. All in debug code.


# 1.57 20-Jul-2020 krw

Move remaining scsi bus initialization info from "prototype scsi link"
fields to struct scsibus_attach_args. Nuke the struct scsi_link *
(saa_sc_link) in scaibus_attach_args.

Explicitly initialize each field in scsibus_attach_args variables.


# 1.56 19-Jul-2020 krw

Move the adapter related items (luns, adapter, adapter_target,
adapter_buswidth, adapter_softc) from struct scsi_link to struct
scsibus_attach_args.

Additional compile tests by jmatthew@ (sparc64) and aoyam@ (luna88k).


# 1.55 16-Jul-2020 krw

Access adapter softc via link->bus->sb_adapter_softc.

In sparc64 autoconf access 'luns' via sb_luns and 'adapter_buswidth'
via sb_adapter_buswidth.

Removes last post-config uses of the copies of bus related
information in scsi_link.


# 1.54 27-Jun-2020 krw

Nuke trailing whitespace.


# 1.53 27-Jun-2020 krw

No need to bzero()/memset() 'struct scsibus_attach_args' variables
immediately before initializing the only field in the struct.


# 1.52 24-Jun-2020 krw

Use SDEV_NO_ADAPTER_TARGET instead of the value that is being
aassigned to adapter_buswidth to indicate the adapter is not a target
on the bus.

ok dlg@ as part of a larger diff.


Revision tags: OPENBSD_6_7_BASE
# 1.51 15-Feb-2020 krw

*_minphys() functions that cap i/o sizes at a value larger than the
value minphys() uses (MAXPHYS) are pointless since minphys() is always
called after the *_minphys() function.

MAXPHYS (64 * 1024) == 16 * 4096. 4096 is the smallest PAGE_SIZE we
have. So a *_minphys() function that caps the i/o size at N *
PAGE_SIZE where N is > 16 is just wasting cycles.

Nuke adv_minphys (40 * PAGE_SIZE), adw_minphys (254 * PAGE_SIZE),
ahc_minphys (128 * PAGE_SIZE), ahd_minphys (128 * PAGE_SIZE),
ami_minphys (26 * PAGE_SIZE), cac_minphys (65535 (!!!) * 512),
iha_minphsy (32 * PAGE_SIZE), trm_minphys (31 * PAGE_SIZE),
twe_minphys (62 * PAGE_SIZE). uha_minphys (32 * PAGE_SIZE),


# 1.50 26-Jan-2020 krw

Shuffle some names around to make reading the code less headache
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.


# 1.49 25-Jan-2020 krw

Drivers that implement their own *minphys() don't need to call the
system minphys(). scsi_minphys() will do that and cd/sd/st will call
scsi_minphys().

ok jmatthew@ as part of larger diff


# 1.48 23-Jan-2020 krw

Use a consistant idiom/format when declaring scsi_adapter structures
in drivers. Terse one liners, NULLs instead of 0's, explicitly specify
all members, etc.

Nuke #ifdef notyet blocks related to the scsi_adapter in aic.

No intentional functional change.

ok tedu@


# 1.47 31-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok kn@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.46 22-Jan-2016 jsg

remove a surplus splbio
ok deraadt@ krw@


Revision tags: OPENBSD_5_8_BASE
# 1.45 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.44 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.43 18-Nov-2013 deraadt

format string


# 1.42 18-Nov-2013 deraadt

simplify kthread_create(). no more stdarg
ok matthew guenther mikeb


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.41 17-Jul-2011 matthew

Backout a bunch of my SCSI commits from c2k11. At least one of these
is causing problems when trying to boot sparc64 from an isp(4).

Verified to fix the sparc64/isp(4) regression by krw@; ok deraadt@


# 1.40 08-Jul-2011 matthew

First batch of converting SCSI HBAs from setting saa_targets and
saa_luns instead of adapter_buswidth and luns in the prototype link.

ok dlg@, miod@


# 1.39 03-Apr-2011 dlg

move twe over to iopools so we can get rid of another NO_CCB user. this
also cuts the aen drain over to using an iohandler so it can be made
reliable.

this compiles, but i havent got hardware to test with. its going in as a
way to force testing. if there's a problem with the code then let me know
or back it out.

"man up" k2k11


Revision tags: OPENBSD_4_9_BASE
# 1.38 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


Revision tags: OPENBSD_4_8_BASE
# 1.37 28-Jun-2010 krw

Remove all adapter-specific 'struct scsi_device's. They are never used. First
step in elminating 'struct scsi_device' entirely.

Spotted and initial diff from matthew@.

ok matthew@ dlg@ deraadt@ marco@ miod@


# 1.36 20-May-2010 krw

New scsi code seems to be stable. Pluck previously identified
low-hanging splbio/splx pairs that are no longer needed and see if
this reveals any hidden scsi flaws.

ok dlg@


# 1.35 29-Mar-2010 krw

Initialize various uninitialized variables. Found by jsg@ via Clang.

Feedback from miod@ and kettenis@.

ok beck@


# 1.34 23-Mar-2010 krw

Change the scsi_cmd function member of scsi_adapter from int to
void. Use XS_NO_CCB error in the scsi command (xs) to report the
NO_CCB condition. Eliminates all SUCCESSFULLY_QUEUED and COMPLETE
confusion and untangles the midlayer from the adapter a bit more.

Eyes and some fixes by miod@

There may be some compile issues on little used (i.e. I don't have
any) drivers but the change is mechanical and thus easy to remedy.

ok dlg@


Revision tags: OPENBSD_4_7_BASE
# 1.33 09-Jan-2010 krw

Zap all setting of ITSDONE in drivers that don't look at it. Nobody
else cares so it's just noise. Drivers that actually look at ITSDONE
are unchanged.

ok marco@ (for his files) dlg@ beck@


# 1.32 22-Nov-2009 krw

Bring last drivers fully into the NO_CCB world by replacing
TRY_AGAIN_LATER uses with equivalent NO_CCB. Eliminates confusion
between the two as was always intended. buf I/O's that can't be
started get pushed back onto the front of the queue and retried.
Others get sent back to originator as failures. No more epi-cycle
looping inside the SCSI midlayer hoping the problem goes away.

Various testers, no objection from miod@ as vs(4) was tested by
nick@.


# 1.31 03-Sep-2009 dlg

must call scsi_done before returning complete.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.30 16-Feb-2009 miod

Extend the scsi_adapter minphys() callback to take a struct scsi_link *
as additional argument. This will allow intermediate layers between
scsi devices such as sd and scsi host adapters to take appropriate
action if necessary.


Revision tags: OPENBSD_4_4_BASE
# 1.29 24-Jul-2008 thib

the softc sc_lock lockmgr lock is unused, so remove it.

ok krw@, dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.28 20-Oct-2007 krw

Call scsi_done() at SPLBIO. 'looks olright' says mickey.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.27 29-Dec-2006 pedro

Avoid void * arithmetic, okay deraadt@, suggestions from millert@


# 1.26 28-Nov-2006 dlg

give scsi controllers a real attach args to fill in when attaching scsibus.

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.25 03-Dec-2005 krw

The first thing done when XXX_scsi_cmd() returns TRY_AGAIN_LATER is
to set xs->error to XS_BUSY. So it is pointless and misleading to
set xs->error to XS_TIMEOUT, XS_DRIVER_STUFFUP or XS_BUSY just before
returning TRY_AGAIN_LATER.

No functional change.


# 1.24 15-Sep-2005 krw

Don't fake MODE SENSE page 4 info inside raid drivers, just let sd
fake a geometry. Page 4 info does not get used for size information.
Eliminate now unused union scsi_disk_pages.

ok marco@ mickey@ pre-lock.


Revision tags: OPENBSD_3_8_BASE
# 1.23 03-Jul-2005 krw

Fix data_length values in simulationed MODE SENSE page 4 responses so
that scsi_do_mode_sense() accepts them.

The data_length value does not include itself, and the pg_length value
in a mode page does not include itself or the page_code fields. We
were +1 on the former and -2 on the latter resulting in a data_length
value that was too small by one.

Eliminates 'mode sense page 5 not simulated' messages.

ok marco@


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.22 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


# 1.21 02-Jun-2003 mickey

kill the caluses three and four on some of my code


Revision tags: UBC_SYNC_A
# 1.20 27-Apr-2003 ho

strcpy/sprintf cleanup of sys/dev. miod@, deraadt@ says to commit.


# 1.19 09-Apr-2003 mickey

missing nl in the error msg and a return afterwards


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.18 17-Sep-2002 mickey

deal w/ the dma in a special thread to follow the busdma semantics. this fixes panics on unaligned physio; w/ help and testing from daniel@lucq.org


Revision tags: OPENBSD_3_1_BASE
# 1.17 14-Mar-2002 millert

First round of __P removal in sys


# 1.16 31-Jan-2002 mickey

scsi_done() is unsafe, rearrange locking to compensate


Revision tags: UBC_BASE
# 1.15 06-Dec-2001 mickey

branches: 1.15.2;
clear all inrterrupts separately and before enabling any.
this prevents stray interrupts and sometimes hangs,
caused by looping on stray unmapped interrupt.


# 1.14 05-Nov-2001 art

Switch everything to the new bus_dmamap_sync API.
Most work by Wilbern Cobb <vedge@csoft.org> with some fixes from me, mickey@
and drahn@.


Revision tags: OPENBSD_3_0_BASE
# 1.13 24-Sep-2001 mickey

get rid of kvtop, not that it matters that much


# 1.12 04-Jul-2001 espie

case labels without statements are not permitted by ANSI C... and gcc 3.0
warns about them.


# 1.11 18-May-2001 mickey

stupidous debug was left enabled


# 1.10 10-May-2001 mickey

branches: 1.10.2;
dmamem_unmap the memory before dmamem_freeig it.
only affects unaligned transfers (such as disklabel, fsck and dump).
we used to get away w/ this due to older pmap, uvm or both.
be more precise w/ double-buffer on command failure as well.
once at it, allow more than 1 segment for double-buffer to be allocated.
also fix a couple of endianesses and command timeouts.


Revision tags: OPENBSD_2_9_BASE
# 1.9 14-Mar-2001 mickey

branches: 1.9.2;
it seems sometimes it takes up to 35 seconds to init; from Chris Kuethe ckuethe@[[gecko.]math.]ualberta.ca


# 1.8 09-Mar-2001 mickey

missing twe_unlock for failed get_ccb() for i/o scsi cmd, which was impossible to trigger in twese case because of how maxcmds is calculated


# 1.7 19-Feb-2001 mickey

propoer dmaable memory allocations


# 1.6 07-Jan-2001 mickey

fix a few scsi_done() usages.
simplify locking a bit.
disable write cache if said so in the scsi_xfer.
a few more commands, from freebsd.


# 1.5 08-Nov-2000 mickey

oops, oops w/ no configured units


# 1.4 07-Nov-2000 mickey

estimate sc_link.openings on the number of configured units


Revision tags: OPENBSD_2_8_BASE
# 1.3 25-Sep-2000 mickey

do not do queue locking in get/put_ccb, since calling blocks
have gotten it already locked appropriately.
only try to satiate the command queue if there was a command interrupt,
it seems it's quite well-behaving this way.
dispose allocated resources if twe_attach() fails.


# 1.2 15-Sep-2000 mickey

forgot to turn off debugging


# 1.1 15-Sep-2000 mickey

3ware escalade ide raid controllers


# 1.65 07-Mar-2021 jsg

ansi


# 1.64 15-Oct-2020 krw

Replace local *_copy_internal_data() with scsi_copy_internal_data().


Revision tags: OPENBSD_6_8_BASE
# 1.63 22-Sep-2020 krw

Since dlg@'s 2009 scsi midlayer refactoring the 'struct scsi_generic *cmd'
member of 'struct scsi_xfer' has always been pointed at the 'struct scsi_generic
cmdstore' member of the same instance. So nuke 'cmdstore' and remove the '*'
from cmd. Take the address of cmd as required by the various casts.

No intentional functional change.

luna88k test by aoyama@, sparc64 test by jmatthew@

Identification of 2009's last *cmd use and ok jmatthew@


# 1.62 05-Sep-2020 krw

Replace '32' with SID_SCSI2_ALEN (a.k.a. 31) when building emulated INQUIRY
responses. This is what the SCSI specifications say is the correct value and
already used in several cases.


# 1.61 03-Sep-2020 krw

Replace '.response_format = 2' with '.response_format = SID_SCSI2_RESPONSE'.


# 1.60 02-Sep-2020 krw

When building emulated INQUIRY results use the SCSI_REV_* #define's to
initialize the 'version' field. Not numbers.


# 1.59 01-Sep-2020 krw

Rename [READ|WRITE]_BIG to [READ|WRITE]_10. Rename struct scsi_rw_big to
struct scsi_rw_10.

ok gnezdo@ jmatthew@ (who also did sparc64 compile test)


# 1.58 24-Jul-2020 krw

Turning on various scsi drivers' *DEBUG options reveals that this has
rarely (if ever) been done.

Fix many printf format errors to calm clang and gcc on amd64, i386,
hppa. Missing #include, complaints if 'option <blah>DEBUG' is used in
config files, etc. All in debug code.


# 1.57 20-Jul-2020 krw

Move remaining scsi bus initialization info from "prototype scsi link"
fields to struct scsibus_attach_args. Nuke the struct scsi_link *
(saa_sc_link) in scaibus_attach_args.

Explicitly initialize each field in scsibus_attach_args variables.


# 1.56 19-Jul-2020 krw

Move the adapter related items (luns, adapter, adapter_target,
adapter_buswidth, adapter_softc) from struct scsi_link to struct
scsibus_attach_args.

Additional compile tests by jmatthew@ (sparc64) and aoyam@ (luna88k).


# 1.55 16-Jul-2020 krw

Access adapter softc via link->bus->sb_adapter_softc.

In sparc64 autoconf access 'luns' via sb_luns and 'adapter_buswidth'
via sb_adapter_buswidth.

Removes last post-config uses of the copies of bus related
information in scsi_link.


# 1.54 27-Jun-2020 krw

Nuke trailing whitespace.


# 1.53 27-Jun-2020 krw

No need to bzero()/memset() 'struct scsibus_attach_args' variables
immediately before initializing the only field in the struct.


# 1.52 24-Jun-2020 krw

Use SDEV_NO_ADAPTER_TARGET instead of the value that is being
aassigned to adapter_buswidth to indicate the adapter is not a target
on the bus.

ok dlg@ as part of a larger diff.


Revision tags: OPENBSD_6_7_BASE
# 1.51 15-Feb-2020 krw

*_minphys() functions that cap i/o sizes at a value larger than the
value minphys() uses (MAXPHYS) are pointless since minphys() is always
called after the *_minphys() function.

MAXPHYS (64 * 1024) == 16 * 4096. 4096 is the smallest PAGE_SIZE we
have. So a *_minphys() function that caps the i/o size at N *
PAGE_SIZE where N is > 16 is just wasting cycles.

Nuke adv_minphys (40 * PAGE_SIZE), adw_minphys (254 * PAGE_SIZE),
ahc_minphys (128 * PAGE_SIZE), ahd_minphys (128 * PAGE_SIZE),
ami_minphys (26 * PAGE_SIZE), cac_minphys (65535 (!!!) * 512),
iha_minphsy (32 * PAGE_SIZE), trm_minphys (31 * PAGE_SIZE),
twe_minphys (62 * PAGE_SIZE). uha_minphys (32 * PAGE_SIZE),


# 1.50 26-Jan-2020 krw

Shuffle some names around to make reading the code less headache
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.


# 1.49 25-Jan-2020 krw

Drivers that implement their own *minphys() don't need to call the
system minphys(). scsi_minphys() will do that and cd/sd/st will call
scsi_minphys().

ok jmatthew@ as part of larger diff


# 1.48 23-Jan-2020 krw

Use a consistant idiom/format when declaring scsi_adapter structures
in drivers. Terse one liners, NULLs instead of 0's, explicitly specify
all members, etc.

Nuke #ifdef notyet blocks related to the scsi_adapter in aic.

No intentional functional change.

ok tedu@


# 1.47 31-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok kn@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.46 22-Jan-2016 jsg

remove a surplus splbio
ok deraadt@ krw@


Revision tags: OPENBSD_5_8_BASE
# 1.45 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.44 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.43 18-Nov-2013 deraadt

format string


# 1.42 18-Nov-2013 deraadt

simplify kthread_create(). no more stdarg
ok matthew guenther mikeb


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.41 17-Jul-2011 matthew

Backout a bunch of my SCSI commits from c2k11. At least one of these
is causing problems when trying to boot sparc64 from an isp(4).

Verified to fix the sparc64/isp(4) regression by krw@; ok deraadt@


# 1.40 08-Jul-2011 matthew

First batch of converting SCSI HBAs from setting saa_targets and
saa_luns instead of adapter_buswidth and luns in the prototype link.

ok dlg@, miod@


# 1.39 03-Apr-2011 dlg

move twe over to iopools so we can get rid of another NO_CCB user. this
also cuts the aen drain over to using an iohandler so it can be made
reliable.

this compiles, but i havent got hardware to test with. its going in as a
way to force testing. if there's a problem with the code then let me know
or back it out.

"man up" k2k11


Revision tags: OPENBSD_4_9_BASE
# 1.38 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


Revision tags: OPENBSD_4_8_BASE
# 1.37 28-Jun-2010 krw

Remove all adapter-specific 'struct scsi_device's. They are never used. First
step in elminating 'struct scsi_device' entirely.

Spotted and initial diff from matthew@.

ok matthew@ dlg@ deraadt@ marco@ miod@


# 1.36 20-May-2010 krw

New scsi code seems to be stable. Pluck previously identified
low-hanging splbio/splx pairs that are no longer needed and see if
this reveals any hidden scsi flaws.

ok dlg@


# 1.35 29-Mar-2010 krw

Initialize various uninitialized variables. Found by jsg@ via Clang.

Feedback from miod@ and kettenis@.

ok beck@


# 1.34 23-Mar-2010 krw

Change the scsi_cmd function member of scsi_adapter from int to
void. Use XS_NO_CCB error in the scsi command (xs) to report the
NO_CCB condition. Eliminates all SUCCESSFULLY_QUEUED and COMPLETE
confusion and untangles the midlayer from the adapter a bit more.

Eyes and some fixes by miod@

There may be some compile issues on little used (i.e. I don't have
any) drivers but the change is mechanical and thus easy to remedy.

ok dlg@


Revision tags: OPENBSD_4_7_BASE
# 1.33 09-Jan-2010 krw

Zap all setting of ITSDONE in drivers that don't look at it. Nobody
else cares so it's just noise. Drivers that actually look at ITSDONE
are unchanged.

ok marco@ (for his files) dlg@ beck@


# 1.32 22-Nov-2009 krw

Bring last drivers fully into the NO_CCB world by replacing
TRY_AGAIN_LATER uses with equivalent NO_CCB. Eliminates confusion
between the two as was always intended. buf I/O's that can't be
started get pushed back onto the front of the queue and retried.
Others get sent back to originator as failures. No more epi-cycle
looping inside the SCSI midlayer hoping the problem goes away.

Various testers, no objection from miod@ as vs(4) was tested by
nick@.


# 1.31 03-Sep-2009 dlg

must call scsi_done before returning complete.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.30 16-Feb-2009 miod

Extend the scsi_adapter minphys() callback to take a struct scsi_link *
as additional argument. This will allow intermediate layers between
scsi devices such as sd and scsi host adapters to take appropriate
action if necessary.


Revision tags: OPENBSD_4_4_BASE
# 1.29 24-Jul-2008 thib

the softc sc_lock lockmgr lock is unused, so remove it.

ok krw@, dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.28 20-Oct-2007 krw

Call scsi_done() at SPLBIO. 'looks olright' says mickey.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.27 29-Dec-2006 pedro

Avoid void * arithmetic, okay deraadt@, suggestions from millert@


# 1.26 28-Nov-2006 dlg

give scsi controllers a real attach args to fill in when attaching scsibus.

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.25 03-Dec-2005 krw

The first thing done when XXX_scsi_cmd() returns TRY_AGAIN_LATER is
to set xs->error to XS_BUSY. So it is pointless and misleading to
set xs->error to XS_TIMEOUT, XS_DRIVER_STUFFUP or XS_BUSY just before
returning TRY_AGAIN_LATER.

No functional change.


# 1.24 15-Sep-2005 krw

Don't fake MODE SENSE page 4 info inside raid drivers, just let sd
fake a geometry. Page 4 info does not get used for size information.
Eliminate now unused union scsi_disk_pages.

ok marco@ mickey@ pre-lock.


Revision tags: OPENBSD_3_8_BASE
# 1.23 03-Jul-2005 krw

Fix data_length values in simulationed MODE SENSE page 4 responses so
that scsi_do_mode_sense() accepts them.

The data_length value does not include itself, and the pg_length value
in a mode page does not include itself or the page_code fields. We
were +1 on the former and -2 on the latter resulting in a data_length
value that was too small by one.

Eliminates 'mode sense page 5 not simulated' messages.

ok marco@


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.22 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


# 1.21 02-Jun-2003 mickey

kill the caluses three and four on some of my code


Revision tags: UBC_SYNC_A
# 1.20 27-Apr-2003 ho

strcpy/sprintf cleanup of sys/dev. miod@, deraadt@ says to commit.


# 1.19 09-Apr-2003 mickey

missing nl in the error msg and a return afterwards


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.18 17-Sep-2002 mickey

deal w/ the dma in a special thread to follow the busdma semantics. this fixes panics on unaligned physio; w/ help and testing from daniel@lucq.org


Revision tags: OPENBSD_3_1_BASE
# 1.17 14-Mar-2002 millert

First round of __P removal in sys


# 1.16 31-Jan-2002 mickey

scsi_done() is unsafe, rearrange locking to compensate


Revision tags: UBC_BASE
# 1.15 06-Dec-2001 mickey

branches: 1.15.2;
clear all inrterrupts separately and before enabling any.
this prevents stray interrupts and sometimes hangs,
caused by looping on stray unmapped interrupt.


# 1.14 05-Nov-2001 art

Switch everything to the new bus_dmamap_sync API.
Most work by Wilbern Cobb <vedge@csoft.org> with some fixes from me, mickey@
and drahn@.


Revision tags: OPENBSD_3_0_BASE
# 1.13 24-Sep-2001 mickey

get rid of kvtop, not that it matters that much


# 1.12 04-Jul-2001 espie

case labels without statements are not permitted by ANSI C... and gcc 3.0
warns about them.


# 1.11 18-May-2001 mickey

stupidous debug was left enabled


# 1.10 10-May-2001 mickey

branches: 1.10.2;
dmamem_unmap the memory before dmamem_freeig it.
only affects unaligned transfers (such as disklabel, fsck and dump).
we used to get away w/ this due to older pmap, uvm or both.
be more precise w/ double-buffer on command failure as well.
once at it, allow more than 1 segment for double-buffer to be allocated.
also fix a couple of endianesses and command timeouts.


Revision tags: OPENBSD_2_9_BASE
# 1.9 14-Mar-2001 mickey

branches: 1.9.2;
it seems sometimes it takes up to 35 seconds to init; from Chris Kuethe ckuethe@[[gecko.]math.]ualberta.ca


# 1.8 09-Mar-2001 mickey

missing twe_unlock for failed get_ccb() for i/o scsi cmd, which was impossible to trigger in twese case because of how maxcmds is calculated


# 1.7 19-Feb-2001 mickey

propoer dmaable memory allocations


# 1.6 07-Jan-2001 mickey

fix a few scsi_done() usages.
simplify locking a bit.
disable write cache if said so in the scsi_xfer.
a few more commands, from freebsd.


# 1.5 08-Nov-2000 mickey

oops, oops w/ no configured units


# 1.4 07-Nov-2000 mickey

estimate sc_link.openings on the number of configured units


Revision tags: OPENBSD_2_8_BASE
# 1.3 25-Sep-2000 mickey

do not do queue locking in get/put_ccb, since calling blocks
have gotten it already locked appropriately.
only try to satiate the command queue if there was a command interrupt,
it seems it's quite well-behaving this way.
dispose allocated resources if twe_attach() fails.


# 1.2 15-Sep-2000 mickey

forgot to turn off debugging


# 1.1 15-Sep-2000 mickey

3ware escalade ide raid controllers


# 1.64 15-Oct-2020 krw

Replace local *_copy_internal_data() with scsi_copy_internal_data().


Revision tags: OPENBSD_6_8_BASE
# 1.63 22-Sep-2020 krw

Since dlg@'s 2009 scsi midlayer refactoring the 'struct scsi_generic *cmd'
member of 'struct scsi_xfer' has always been pointed at the 'struct scsi_generic
cmdstore' member of the same instance. So nuke 'cmdstore' and remove the '*'
from cmd. Take the address of cmd as required by the various casts.

No intentional functional change.

luna88k test by aoyama@, sparc64 test by jmatthew@

Identification of 2009's last *cmd use and ok jmatthew@


# 1.62 05-Sep-2020 krw

Replace '32' with SID_SCSI2_ALEN (a.k.a. 31) when building emulated INQUIRY
responses. This is what the SCSI specifications say is the correct value and
already used in several cases.


# 1.61 03-Sep-2020 krw

Replace '.response_format = 2' with '.response_format = SID_SCSI2_RESPONSE'.


# 1.60 02-Sep-2020 krw

When building emulated INQUIRY results use the SCSI_REV_* #define's to
initialize the 'version' field. Not numbers.


# 1.59 01-Sep-2020 krw

Rename [READ|WRITE]_BIG to [READ|WRITE]_10. Rename struct scsi_rw_big to
struct scsi_rw_10.

ok gnezdo@ jmatthew@ (who also did sparc64 compile test)


# 1.58 24-Jul-2020 krw

Turning on various scsi drivers' *DEBUG options reveals that this has
rarely (if ever) been done.

Fix many printf format errors to calm clang and gcc on amd64, i386,
hppa. Missing #include, complaints if 'option <blah>DEBUG' is used in
config files, etc. All in debug code.


# 1.57 20-Jul-2020 krw

Move remaining scsi bus initialization info from "prototype scsi link"
fields to struct scsibus_attach_args. Nuke the struct scsi_link *
(saa_sc_link) in scaibus_attach_args.

Explicitly initialize each field in scsibus_attach_args variables.


# 1.56 19-Jul-2020 krw

Move the adapter related items (luns, adapter, adapter_target,
adapter_buswidth, adapter_softc) from struct scsi_link to struct
scsibus_attach_args.

Additional compile tests by jmatthew@ (sparc64) and aoyam@ (luna88k).


# 1.55 16-Jul-2020 krw

Access adapter softc via link->bus->sb_adapter_softc.

In sparc64 autoconf access 'luns' via sb_luns and 'adapter_buswidth'
via sb_adapter_buswidth.

Removes last post-config uses of the copies of bus related
information in scsi_link.


# 1.54 27-Jun-2020 krw

Nuke trailing whitespace.


# 1.53 27-Jun-2020 krw

No need to bzero()/memset() 'struct scsibus_attach_args' variables
immediately before initializing the only field in the struct.


# 1.52 24-Jun-2020 krw

Use SDEV_NO_ADAPTER_TARGET instead of the value that is being
aassigned to adapter_buswidth to indicate the adapter is not a target
on the bus.

ok dlg@ as part of a larger diff.


Revision tags: OPENBSD_6_7_BASE
# 1.51 15-Feb-2020 krw

*_minphys() functions that cap i/o sizes at a value larger than the
value minphys() uses (MAXPHYS) are pointless since minphys() is always
called after the *_minphys() function.

MAXPHYS (64 * 1024) == 16 * 4096. 4096 is the smallest PAGE_SIZE we
have. So a *_minphys() function that caps the i/o size at N *
PAGE_SIZE where N is > 16 is just wasting cycles.

Nuke adv_minphys (40 * PAGE_SIZE), adw_minphys (254 * PAGE_SIZE),
ahc_minphys (128 * PAGE_SIZE), ahd_minphys (128 * PAGE_SIZE),
ami_minphys (26 * PAGE_SIZE), cac_minphys (65535 (!!!) * 512),
iha_minphsy (32 * PAGE_SIZE), trm_minphys (31 * PAGE_SIZE),
twe_minphys (62 * PAGE_SIZE). uha_minphys (32 * PAGE_SIZE),


# 1.50 26-Jan-2020 krw

Shuffle some names around to make reading the code less headache
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.


# 1.49 25-Jan-2020 krw

Drivers that implement their own *minphys() don't need to call the
system minphys(). scsi_minphys() will do that and cd/sd/st will call
scsi_minphys().

ok jmatthew@ as part of larger diff


# 1.48 23-Jan-2020 krw

Use a consistant idiom/format when declaring scsi_adapter structures
in drivers. Terse one liners, NULLs instead of 0's, explicitly specify
all members, etc.

Nuke #ifdef notyet blocks related to the scsi_adapter in aic.

No intentional functional change.

ok tedu@


# 1.47 31-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok kn@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.46 22-Jan-2016 jsg

remove a surplus splbio
ok deraadt@ krw@


Revision tags: OPENBSD_5_8_BASE
# 1.45 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.44 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.43 18-Nov-2013 deraadt

format string


# 1.42 18-Nov-2013 deraadt

simplify kthread_create(). no more stdarg
ok matthew guenther mikeb


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.41 17-Jul-2011 matthew

Backout a bunch of my SCSI commits from c2k11. At least one of these
is causing problems when trying to boot sparc64 from an isp(4).

Verified to fix the sparc64/isp(4) regression by krw@; ok deraadt@


# 1.40 08-Jul-2011 matthew

First batch of converting SCSI HBAs from setting saa_targets and
saa_luns instead of adapter_buswidth and luns in the prototype link.

ok dlg@, miod@


# 1.39 03-Apr-2011 dlg

move twe over to iopools so we can get rid of another NO_CCB user. this
also cuts the aen drain over to using an iohandler so it can be made
reliable.

this compiles, but i havent got hardware to test with. its going in as a
way to force testing. if there's a problem with the code then let me know
or back it out.

"man up" k2k11


Revision tags: OPENBSD_4_9_BASE
# 1.38 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


Revision tags: OPENBSD_4_8_BASE
# 1.37 28-Jun-2010 krw

Remove all adapter-specific 'struct scsi_device's. They are never used. First
step in elminating 'struct scsi_device' entirely.

Spotted and initial diff from matthew@.

ok matthew@ dlg@ deraadt@ marco@ miod@


# 1.36 20-May-2010 krw

New scsi code seems to be stable. Pluck previously identified
low-hanging splbio/splx pairs that are no longer needed and see if
this reveals any hidden scsi flaws.

ok dlg@


# 1.35 29-Mar-2010 krw

Initialize various uninitialized variables. Found by jsg@ via Clang.

Feedback from miod@ and kettenis@.

ok beck@


# 1.34 23-Mar-2010 krw

Change the scsi_cmd function member of scsi_adapter from int to
void. Use XS_NO_CCB error in the scsi command (xs) to report the
NO_CCB condition. Eliminates all SUCCESSFULLY_QUEUED and COMPLETE
confusion and untangles the midlayer from the adapter a bit more.

Eyes and some fixes by miod@

There may be some compile issues on little used (i.e. I don't have
any) drivers but the change is mechanical and thus easy to remedy.

ok dlg@


Revision tags: OPENBSD_4_7_BASE
# 1.33 09-Jan-2010 krw

Zap all setting of ITSDONE in drivers that don't look at it. Nobody
else cares so it's just noise. Drivers that actually look at ITSDONE
are unchanged.

ok marco@ (for his files) dlg@ beck@


# 1.32 22-Nov-2009 krw

Bring last drivers fully into the NO_CCB world by replacing
TRY_AGAIN_LATER uses with equivalent NO_CCB. Eliminates confusion
between the two as was always intended. buf I/O's that can't be
started get pushed back onto the front of the queue and retried.
Others get sent back to originator as failures. No more epi-cycle
looping inside the SCSI midlayer hoping the problem goes away.

Various testers, no objection from miod@ as vs(4) was tested by
nick@.


# 1.31 03-Sep-2009 dlg

must call scsi_done before returning complete.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.30 16-Feb-2009 miod

Extend the scsi_adapter minphys() callback to take a struct scsi_link *
as additional argument. This will allow intermediate layers between
scsi devices such as sd and scsi host adapters to take appropriate
action if necessary.


Revision tags: OPENBSD_4_4_BASE
# 1.29 24-Jul-2008 thib

the softc sc_lock lockmgr lock is unused, so remove it.

ok krw@, dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.28 20-Oct-2007 krw

Call scsi_done() at SPLBIO. 'looks olright' says mickey.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.27 29-Dec-2006 pedro

Avoid void * arithmetic, okay deraadt@, suggestions from millert@


# 1.26 28-Nov-2006 dlg

give scsi controllers a real attach args to fill in when attaching scsibus.

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.25 03-Dec-2005 krw

The first thing done when XXX_scsi_cmd() returns TRY_AGAIN_LATER is
to set xs->error to XS_BUSY. So it is pointless and misleading to
set xs->error to XS_TIMEOUT, XS_DRIVER_STUFFUP or XS_BUSY just before
returning TRY_AGAIN_LATER.

No functional change.


# 1.24 15-Sep-2005 krw

Don't fake MODE SENSE page 4 info inside raid drivers, just let sd
fake a geometry. Page 4 info does not get used for size information.
Eliminate now unused union scsi_disk_pages.

ok marco@ mickey@ pre-lock.


Revision tags: OPENBSD_3_8_BASE
# 1.23 03-Jul-2005 krw

Fix data_length values in simulationed MODE SENSE page 4 responses so
that scsi_do_mode_sense() accepts them.

The data_length value does not include itself, and the pg_length value
in a mode page does not include itself or the page_code fields. We
were +1 on the former and -2 on the latter resulting in a data_length
value that was too small by one.

Eliminates 'mode sense page 5 not simulated' messages.

ok marco@


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.22 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


# 1.21 02-Jun-2003 mickey

kill the caluses three and four on some of my code


Revision tags: UBC_SYNC_A
# 1.20 27-Apr-2003 ho

strcpy/sprintf cleanup of sys/dev. miod@, deraadt@ says to commit.


# 1.19 09-Apr-2003 mickey

missing nl in the error msg and a return afterwards


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.18 17-Sep-2002 mickey

deal w/ the dma in a special thread to follow the busdma semantics. this fixes panics on unaligned physio; w/ help and testing from daniel@lucq.org


Revision tags: OPENBSD_3_1_BASE
# 1.17 14-Mar-2002 millert

First round of __P removal in sys


# 1.16 31-Jan-2002 mickey

scsi_done() is unsafe, rearrange locking to compensate


Revision tags: UBC_BASE
# 1.15 06-Dec-2001 mickey

branches: 1.15.2;
clear all inrterrupts separately and before enabling any.
this prevents stray interrupts and sometimes hangs,
caused by looping on stray unmapped interrupt.


# 1.14 05-Nov-2001 art

Switch everything to the new bus_dmamap_sync API.
Most work by Wilbern Cobb <vedge@csoft.org> with some fixes from me, mickey@
and drahn@.


Revision tags: OPENBSD_3_0_BASE
# 1.13 24-Sep-2001 mickey

get rid of kvtop, not that it matters that much


# 1.12 04-Jul-2001 espie

case labels without statements are not permitted by ANSI C... and gcc 3.0
warns about them.


# 1.11 18-May-2001 mickey

stupidous debug was left enabled


# 1.10 10-May-2001 mickey

branches: 1.10.2;
dmamem_unmap the memory before dmamem_freeig it.
only affects unaligned transfers (such as disklabel, fsck and dump).
we used to get away w/ this due to older pmap, uvm or both.
be more precise w/ double-buffer on command failure as well.
once at it, allow more than 1 segment for double-buffer to be allocated.
also fix a couple of endianesses and command timeouts.


Revision tags: OPENBSD_2_9_BASE
# 1.9 14-Mar-2001 mickey

branches: 1.9.2;
it seems sometimes it takes up to 35 seconds to init; from Chris Kuethe ckuethe@[[gecko.]math.]ualberta.ca


# 1.8 09-Mar-2001 mickey

missing twe_unlock for failed get_ccb() for i/o scsi cmd, which was impossible to trigger in twese case because of how maxcmds is calculated


# 1.7 19-Feb-2001 mickey

propoer dmaable memory allocations


# 1.6 07-Jan-2001 mickey

fix a few scsi_done() usages.
simplify locking a bit.
disable write cache if said so in the scsi_xfer.
a few more commands, from freebsd.


# 1.5 08-Nov-2000 mickey

oops, oops w/ no configured units


# 1.4 07-Nov-2000 mickey

estimate sc_link.openings on the number of configured units


Revision tags: OPENBSD_2_8_BASE
# 1.3 25-Sep-2000 mickey

do not do queue locking in get/put_ccb, since calling blocks
have gotten it already locked appropriately.
only try to satiate the command queue if there was a command interrupt,
it seems it's quite well-behaving this way.
dispose allocated resources if twe_attach() fails.


# 1.2 15-Sep-2000 mickey

forgot to turn off debugging


# 1.1 15-Sep-2000 mickey

3ware escalade ide raid controllers


# 1.63 22-Sep-2020 krw

Since dlg@'s 2009 scsi midlayer refactoring the 'struct scsi_generic *cmd'
member of 'struct scsi_xfer' has always been pointed at the 'struct scsi_generic
cmdstore' member of the same instance. So nuke 'cmdstore' and remove the '*'
from cmd. Take the address of cmd as required by the various casts.

No intentional functional change.

luna88k test by aoyama@, sparc64 test by jmatthew@

Identification of 2009's last *cmd use and ok jmatthew@


# 1.62 05-Sep-2020 krw

Replace '32' with SID_SCSI2_ALEN (a.k.a. 31) when building emulated INQUIRY
responses. This is what the SCSI specifications say is the correct value and
already used in several cases.


# 1.61 03-Sep-2020 krw

Replace '.response_format = 2' with '.response_format = SID_SCSI2_RESPONSE'.


# 1.60 02-Sep-2020 krw

When building emulated INQUIRY results use the SCSI_REV_* #define's to
initialize the 'version' field. Not numbers.


# 1.59 01-Sep-2020 krw

Rename [READ|WRITE]_BIG to [READ|WRITE]_10. Rename struct scsi_rw_big to
struct scsi_rw_10.

ok gnezdo@ jmatthew@ (who also did sparc64 compile test)


# 1.58 24-Jul-2020 krw

Turning on various scsi drivers' *DEBUG options reveals that this has
rarely (if ever) been done.

Fix many printf format errors to calm clang and gcc on amd64, i386,
hppa. Missing #include, complaints if 'option <blah>DEBUG' is used in
config files, etc. All in debug code.


# 1.57 20-Jul-2020 krw

Move remaining scsi bus initialization info from "prototype scsi link"
fields to struct scsibus_attach_args. Nuke the struct scsi_link *
(saa_sc_link) in scaibus_attach_args.

Explicitly initialize each field in scsibus_attach_args variables.


# 1.56 19-Jul-2020 krw

Move the adapter related items (luns, adapter, adapter_target,
adapter_buswidth, adapter_softc) from struct scsi_link to struct
scsibus_attach_args.

Additional compile tests by jmatthew@ (sparc64) and aoyam@ (luna88k).


# 1.55 16-Jul-2020 krw

Access adapter softc via link->bus->sb_adapter_softc.

In sparc64 autoconf access 'luns' via sb_luns and 'adapter_buswidth'
via sb_adapter_buswidth.

Removes last post-config uses of the copies of bus related
information in scsi_link.


# 1.54 27-Jun-2020 krw

Nuke trailing whitespace.


# 1.53 27-Jun-2020 krw

No need to bzero()/memset() 'struct scsibus_attach_args' variables
immediately before initializing the only field in the struct.


# 1.52 24-Jun-2020 krw

Use SDEV_NO_ADAPTER_TARGET instead of the value that is being
aassigned to adapter_buswidth to indicate the adapter is not a target
on the bus.

ok dlg@ as part of a larger diff.


Revision tags: OPENBSD_6_7_BASE
# 1.51 15-Feb-2020 krw

*_minphys() functions that cap i/o sizes at a value larger than the
value minphys() uses (MAXPHYS) are pointless since minphys() is always
called after the *_minphys() function.

MAXPHYS (64 * 1024) == 16 * 4096. 4096 is the smallest PAGE_SIZE we
have. So a *_minphys() function that caps the i/o size at N *
PAGE_SIZE where N is > 16 is just wasting cycles.

Nuke adv_minphys (40 * PAGE_SIZE), adw_minphys (254 * PAGE_SIZE),
ahc_minphys (128 * PAGE_SIZE), ahd_minphys (128 * PAGE_SIZE),
ami_minphys (26 * PAGE_SIZE), cac_minphys (65535 (!!!) * 512),
iha_minphsy (32 * PAGE_SIZE), trm_minphys (31 * PAGE_SIZE),
twe_minphys (62 * PAGE_SIZE). uha_minphys (32 * PAGE_SIZE),


# 1.50 26-Jan-2020 krw

Shuffle some names around to make reading the code less headache
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.


# 1.49 25-Jan-2020 krw

Drivers that implement their own *minphys() don't need to call the
system minphys(). scsi_minphys() will do that and cd/sd/st will call
scsi_minphys().

ok jmatthew@ as part of larger diff


# 1.48 23-Jan-2020 krw

Use a consistant idiom/format when declaring scsi_adapter structures
in drivers. Terse one liners, NULLs instead of 0's, explicitly specify
all members, etc.

Nuke #ifdef notyet blocks related to the scsi_adapter in aic.

No intentional functional change.

ok tedu@


# 1.47 31-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok kn@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.46 22-Jan-2016 jsg

remove a surplus splbio
ok deraadt@ krw@


Revision tags: OPENBSD_5_8_BASE
# 1.45 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.44 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.43 18-Nov-2013 deraadt

format string


# 1.42 18-Nov-2013 deraadt

simplify kthread_create(). no more stdarg
ok matthew guenther mikeb


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.41 17-Jul-2011 matthew

Backout a bunch of my SCSI commits from c2k11. At least one of these
is causing problems when trying to boot sparc64 from an isp(4).

Verified to fix the sparc64/isp(4) regression by krw@; ok deraadt@


# 1.40 08-Jul-2011 matthew

First batch of converting SCSI HBAs from setting saa_targets and
saa_luns instead of adapter_buswidth and luns in the prototype link.

ok dlg@, miod@


# 1.39 03-Apr-2011 dlg

move twe over to iopools so we can get rid of another NO_CCB user. this
also cuts the aen drain over to using an iohandler so it can be made
reliable.

this compiles, but i havent got hardware to test with. its going in as a
way to force testing. if there's a problem with the code then let me know
or back it out.

"man up" k2k11


Revision tags: OPENBSD_4_9_BASE
# 1.38 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


Revision tags: OPENBSD_4_8_BASE
# 1.37 28-Jun-2010 krw

Remove all adapter-specific 'struct scsi_device's. They are never used. First
step in elminating 'struct scsi_device' entirely.

Spotted and initial diff from matthew@.

ok matthew@ dlg@ deraadt@ marco@ miod@


# 1.36 20-May-2010 krw

New scsi code seems to be stable. Pluck previously identified
low-hanging splbio/splx pairs that are no longer needed and see if
this reveals any hidden scsi flaws.

ok dlg@


# 1.35 29-Mar-2010 krw

Initialize various uninitialized variables. Found by jsg@ via Clang.

Feedback from miod@ and kettenis@.

ok beck@


# 1.34 23-Mar-2010 krw

Change the scsi_cmd function member of scsi_adapter from int to
void. Use XS_NO_CCB error in the scsi command (xs) to report the
NO_CCB condition. Eliminates all SUCCESSFULLY_QUEUED and COMPLETE
confusion and untangles the midlayer from the adapter a bit more.

Eyes and some fixes by miod@

There may be some compile issues on little used (i.e. I don't have
any) drivers but the change is mechanical and thus easy to remedy.

ok dlg@


Revision tags: OPENBSD_4_7_BASE
# 1.33 09-Jan-2010 krw

Zap all setting of ITSDONE in drivers that don't look at it. Nobody
else cares so it's just noise. Drivers that actually look at ITSDONE
are unchanged.

ok marco@ (for his files) dlg@ beck@


# 1.32 22-Nov-2009 krw

Bring last drivers fully into the NO_CCB world by replacing
TRY_AGAIN_LATER uses with equivalent NO_CCB. Eliminates confusion
between the two as was always intended. buf I/O's that can't be
started get pushed back onto the front of the queue and retried.
Others get sent back to originator as failures. No more epi-cycle
looping inside the SCSI midlayer hoping the problem goes away.

Various testers, no objection from miod@ as vs(4) was tested by
nick@.


# 1.31 03-Sep-2009 dlg

must call scsi_done before returning complete.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.30 16-Feb-2009 miod

Extend the scsi_adapter minphys() callback to take a struct scsi_link *
as additional argument. This will allow intermediate layers between
scsi devices such as sd and scsi host adapters to take appropriate
action if necessary.


Revision tags: OPENBSD_4_4_BASE
# 1.29 24-Jul-2008 thib

the softc sc_lock lockmgr lock is unused, so remove it.

ok krw@, dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.28 20-Oct-2007 krw

Call scsi_done() at SPLBIO. 'looks olright' says mickey.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.27 29-Dec-2006 pedro

Avoid void * arithmetic, okay deraadt@, suggestions from millert@


# 1.26 28-Nov-2006 dlg

give scsi controllers a real attach args to fill in when attaching scsibus.

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.25 03-Dec-2005 krw

The first thing done when XXX_scsi_cmd() returns TRY_AGAIN_LATER is
to set xs->error to XS_BUSY. So it is pointless and misleading to
set xs->error to XS_TIMEOUT, XS_DRIVER_STUFFUP or XS_BUSY just before
returning TRY_AGAIN_LATER.

No functional change.


# 1.24 15-Sep-2005 krw

Don't fake MODE SENSE page 4 info inside raid drivers, just let sd
fake a geometry. Page 4 info does not get used for size information.
Eliminate now unused union scsi_disk_pages.

ok marco@ mickey@ pre-lock.


Revision tags: OPENBSD_3_8_BASE
# 1.23 03-Jul-2005 krw

Fix data_length values in simulationed MODE SENSE page 4 responses so
that scsi_do_mode_sense() accepts them.

The data_length value does not include itself, and the pg_length value
in a mode page does not include itself or the page_code fields. We
were +1 on the former and -2 on the latter resulting in a data_length
value that was too small by one.

Eliminates 'mode sense page 5 not simulated' messages.

ok marco@


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.22 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


# 1.21 02-Jun-2003 mickey

kill the caluses three and four on some of my code


Revision tags: UBC_SYNC_A
# 1.20 27-Apr-2003 ho

strcpy/sprintf cleanup of sys/dev. miod@, deraadt@ says to commit.


# 1.19 09-Apr-2003 mickey

missing nl in the error msg and a return afterwards


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.18 17-Sep-2002 mickey

deal w/ the dma in a special thread to follow the busdma semantics. this fixes panics on unaligned physio; w/ help and testing from daniel@lucq.org


Revision tags: OPENBSD_3_1_BASE
# 1.17 14-Mar-2002 millert

First round of __P removal in sys


# 1.16 31-Jan-2002 mickey

scsi_done() is unsafe, rearrange locking to compensate


Revision tags: UBC_BASE
# 1.15 06-Dec-2001 mickey

branches: 1.15.2;
clear all inrterrupts separately and before enabling any.
this prevents stray interrupts and sometimes hangs,
caused by looping on stray unmapped interrupt.


# 1.14 05-Nov-2001 art

Switch everything to the new bus_dmamap_sync API.
Most work by Wilbern Cobb <vedge@csoft.org> with some fixes from me, mickey@
and drahn@.


Revision tags: OPENBSD_3_0_BASE
# 1.13 24-Sep-2001 mickey

get rid of kvtop, not that it matters that much


# 1.12 04-Jul-2001 espie

case labels without statements are not permitted by ANSI C... and gcc 3.0
warns about them.


# 1.11 18-May-2001 mickey

stupidous debug was left enabled


# 1.10 10-May-2001 mickey

branches: 1.10.2;
dmamem_unmap the memory before dmamem_freeig it.
only affects unaligned transfers (such as disklabel, fsck and dump).
we used to get away w/ this due to older pmap, uvm or both.
be more precise w/ double-buffer on command failure as well.
once at it, allow more than 1 segment for double-buffer to be allocated.
also fix a couple of endianesses and command timeouts.


Revision tags: OPENBSD_2_9_BASE
# 1.9 14-Mar-2001 mickey

branches: 1.9.2;
it seems sometimes it takes up to 35 seconds to init; from Chris Kuethe ckuethe@[[gecko.]math.]ualberta.ca


# 1.8 09-Mar-2001 mickey

missing twe_unlock for failed get_ccb() for i/o scsi cmd, which was impossible to trigger in twese case because of how maxcmds is calculated


# 1.7 19-Feb-2001 mickey

propoer dmaable memory allocations


# 1.6 07-Jan-2001 mickey

fix a few scsi_done() usages.
simplify locking a bit.
disable write cache if said so in the scsi_xfer.
a few more commands, from freebsd.


# 1.5 08-Nov-2000 mickey

oops, oops w/ no configured units


# 1.4 07-Nov-2000 mickey

estimate sc_link.openings on the number of configured units


Revision tags: OPENBSD_2_8_BASE
# 1.3 25-Sep-2000 mickey

do not do queue locking in get/put_ccb, since calling blocks
have gotten it already locked appropriately.
only try to satiate the command queue if there was a command interrupt,
it seems it's quite well-behaving this way.
dispose allocated resources if twe_attach() fails.


# 1.2 15-Sep-2000 mickey

forgot to turn off debugging


# 1.1 15-Sep-2000 mickey

3ware escalade ide raid controllers


# 1.62 05-Sep-2020 krw

Replace '32' with SID_SCSI2_ALEN (a.k.a. 31) when building emulated INQUIRY
responses. This is what the SCSI specifications say is the correct value and
already used in several cases.


# 1.61 03-Sep-2020 krw

Replace '.response_format = 2' with '.response_format = SID_SCSI2_RESPONSE'.


# 1.60 02-Sep-2020 krw

When building emulated INQUIRY results use the SCSI_REV_* #define's to
initialize the 'version' field. Not numbers.


# 1.59 01-Sep-2020 krw

Rename [READ|WRITE]_BIG to [READ|WRITE]_10. Rename struct scsi_rw_big to
struct scsi_rw_10.

ok gnezdo@ jmatthew@ (who also did sparc64 compile test)


# 1.58 24-Jul-2020 krw

Turning on various scsi drivers' *DEBUG options reveals that this has
rarely (if ever) been done.

Fix many printf format errors to calm clang and gcc on amd64, i386,
hppa. Missing #include, complaints if 'option <blah>DEBUG' is used in
config files, etc. All in debug code.


# 1.57 20-Jul-2020 krw

Move remaining scsi bus initialization info from "prototype scsi link"
fields to struct scsibus_attach_args. Nuke the struct scsi_link *
(saa_sc_link) in scaibus_attach_args.

Explicitly initialize each field in scsibus_attach_args variables.


# 1.56 19-Jul-2020 krw

Move the adapter related items (luns, adapter, adapter_target,
adapter_buswidth, adapter_softc) from struct scsi_link to struct
scsibus_attach_args.

Additional compile tests by jmatthew@ (sparc64) and aoyam@ (luna88k).


# 1.55 16-Jul-2020 krw

Access adapter softc via link->bus->sb_adapter_softc.

In sparc64 autoconf access 'luns' via sb_luns and 'adapter_buswidth'
via sb_adapter_buswidth.

Removes last post-config uses of the copies of bus related
information in scsi_link.


# 1.54 27-Jun-2020 krw

Nuke trailing whitespace.


# 1.53 27-Jun-2020 krw

No need to bzero()/memset() 'struct scsibus_attach_args' variables
immediately before initializing the only field in the struct.


# 1.52 24-Jun-2020 krw

Use SDEV_NO_ADAPTER_TARGET instead of the value that is being
aassigned to adapter_buswidth to indicate the adapter is not a target
on the bus.

ok dlg@ as part of a larger diff.


Revision tags: OPENBSD_6_7_BASE
# 1.51 15-Feb-2020 krw

*_minphys() functions that cap i/o sizes at a value larger than the
value minphys() uses (MAXPHYS) are pointless since minphys() is always
called after the *_minphys() function.

MAXPHYS (64 * 1024) == 16 * 4096. 4096 is the smallest PAGE_SIZE we
have. So a *_minphys() function that caps the i/o size at N *
PAGE_SIZE where N is > 16 is just wasting cycles.

Nuke adv_minphys (40 * PAGE_SIZE), adw_minphys (254 * PAGE_SIZE),
ahc_minphys (128 * PAGE_SIZE), ahd_minphys (128 * PAGE_SIZE),
ami_minphys (26 * PAGE_SIZE), cac_minphys (65535 (!!!) * 512),
iha_minphsy (32 * PAGE_SIZE), trm_minphys (31 * PAGE_SIZE),
twe_minphys (62 * PAGE_SIZE). uha_minphys (32 * PAGE_SIZE),


# 1.50 26-Jan-2020 krw

Shuffle some names around to make reading the code less headache
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.


# 1.49 25-Jan-2020 krw

Drivers that implement their own *minphys() don't need to call the
system minphys(). scsi_minphys() will do that and cd/sd/st will call
scsi_minphys().

ok jmatthew@ as part of larger diff


# 1.48 23-Jan-2020 krw

Use a consistant idiom/format when declaring scsi_adapter structures
in drivers. Terse one liners, NULLs instead of 0's, explicitly specify
all members, etc.

Nuke #ifdef notyet blocks related to the scsi_adapter in aic.

No intentional functional change.

ok tedu@


# 1.47 31-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok kn@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.46 22-Jan-2016 jsg

remove a surplus splbio
ok deraadt@ krw@


Revision tags: OPENBSD_5_8_BASE
# 1.45 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.44 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.43 18-Nov-2013 deraadt

format string


# 1.42 18-Nov-2013 deraadt

simplify kthread_create(). no more stdarg
ok matthew guenther mikeb


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.41 17-Jul-2011 matthew

Backout a bunch of my SCSI commits from c2k11. At least one of these
is causing problems when trying to boot sparc64 from an isp(4).

Verified to fix the sparc64/isp(4) regression by krw@; ok deraadt@


# 1.40 08-Jul-2011 matthew

First batch of converting SCSI HBAs from setting saa_targets and
saa_luns instead of adapter_buswidth and luns in the prototype link.

ok dlg@, miod@


# 1.39 03-Apr-2011 dlg

move twe over to iopools so we can get rid of another NO_CCB user. this
also cuts the aen drain over to using an iohandler so it can be made
reliable.

this compiles, but i havent got hardware to test with. its going in as a
way to force testing. if there's a problem with the code then let me know
or back it out.

"man up" k2k11


Revision tags: OPENBSD_4_9_BASE
# 1.38 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


Revision tags: OPENBSD_4_8_BASE
# 1.37 28-Jun-2010 krw

Remove all adapter-specific 'struct scsi_device's. They are never used. First
step in elminating 'struct scsi_device' entirely.

Spotted and initial diff from matthew@.

ok matthew@ dlg@ deraadt@ marco@ miod@


# 1.36 20-May-2010 krw

New scsi code seems to be stable. Pluck previously identified
low-hanging splbio/splx pairs that are no longer needed and see if
this reveals any hidden scsi flaws.

ok dlg@


# 1.35 29-Mar-2010 krw

Initialize various uninitialized variables. Found by jsg@ via Clang.

Feedback from miod@ and kettenis@.

ok beck@


# 1.34 23-Mar-2010 krw

Change the scsi_cmd function member of scsi_adapter from int to
void. Use XS_NO_CCB error in the scsi command (xs) to report the
NO_CCB condition. Eliminates all SUCCESSFULLY_QUEUED and COMPLETE
confusion and untangles the midlayer from the adapter a bit more.

Eyes and some fixes by miod@

There may be some compile issues on little used (i.e. I don't have
any) drivers but the change is mechanical and thus easy to remedy.

ok dlg@


Revision tags: OPENBSD_4_7_BASE
# 1.33 09-Jan-2010 krw

Zap all setting of ITSDONE in drivers that don't look at it. Nobody
else cares so it's just noise. Drivers that actually look at ITSDONE
are unchanged.

ok marco@ (for his files) dlg@ beck@


# 1.32 22-Nov-2009 krw

Bring last drivers fully into the NO_CCB world by replacing
TRY_AGAIN_LATER uses with equivalent NO_CCB. Eliminates confusion
between the two as was always intended. buf I/O's that can't be
started get pushed back onto the front of the queue and retried.
Others get sent back to originator as failures. No more epi-cycle
looping inside the SCSI midlayer hoping the problem goes away.

Various testers, no objection from miod@ as vs(4) was tested by
nick@.


# 1.31 03-Sep-2009 dlg

must call scsi_done before returning complete.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.30 16-Feb-2009 miod

Extend the scsi_adapter minphys() callback to take a struct scsi_link *
as additional argument. This will allow intermediate layers between
scsi devices such as sd and scsi host adapters to take appropriate
action if necessary.


Revision tags: OPENBSD_4_4_BASE
# 1.29 24-Jul-2008 thib

the softc sc_lock lockmgr lock is unused, so remove it.

ok krw@, dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.28 20-Oct-2007 krw

Call scsi_done() at SPLBIO. 'looks olright' says mickey.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.27 29-Dec-2006 pedro

Avoid void * arithmetic, okay deraadt@, suggestions from millert@


# 1.26 28-Nov-2006 dlg

give scsi controllers a real attach args to fill in when attaching scsibus.

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.25 03-Dec-2005 krw

The first thing done when XXX_scsi_cmd() returns TRY_AGAIN_LATER is
to set xs->error to XS_BUSY. So it is pointless and misleading to
set xs->error to XS_TIMEOUT, XS_DRIVER_STUFFUP or XS_BUSY just before
returning TRY_AGAIN_LATER.

No functional change.


# 1.24 15-Sep-2005 krw

Don't fake MODE SENSE page 4 info inside raid drivers, just let sd
fake a geometry. Page 4 info does not get used for size information.
Eliminate now unused union scsi_disk_pages.

ok marco@ mickey@ pre-lock.


Revision tags: OPENBSD_3_8_BASE
# 1.23 03-Jul-2005 krw

Fix data_length values in simulationed MODE SENSE page 4 responses so
that scsi_do_mode_sense() accepts them.

The data_length value does not include itself, and the pg_length value
in a mode page does not include itself or the page_code fields. We
were +1 on the former and -2 on the latter resulting in a data_length
value that was too small by one.

Eliminates 'mode sense page 5 not simulated' messages.

ok marco@


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.22 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


# 1.21 02-Jun-2003 mickey

kill the caluses three and four on some of my code


Revision tags: UBC_SYNC_A
# 1.20 27-Apr-2003 ho

strcpy/sprintf cleanup of sys/dev. miod@, deraadt@ says to commit.


# 1.19 09-Apr-2003 mickey

missing nl in the error msg and a return afterwards


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.18 17-Sep-2002 mickey

deal w/ the dma in a special thread to follow the busdma semantics. this fixes panics on unaligned physio; w/ help and testing from daniel@lucq.org


Revision tags: OPENBSD_3_1_BASE
# 1.17 14-Mar-2002 millert

First round of __P removal in sys


# 1.16 31-Jan-2002 mickey

scsi_done() is unsafe, rearrange locking to compensate


Revision tags: UBC_BASE
# 1.15 06-Dec-2001 mickey

branches: 1.15.2;
clear all inrterrupts separately and before enabling any.
this prevents stray interrupts and sometimes hangs,
caused by looping on stray unmapped interrupt.


# 1.14 05-Nov-2001 art

Switch everything to the new bus_dmamap_sync API.
Most work by Wilbern Cobb <vedge@csoft.org> with some fixes from me, mickey@
and drahn@.


Revision tags: OPENBSD_3_0_BASE
# 1.13 24-Sep-2001 mickey

get rid of kvtop, not that it matters that much


# 1.12 04-Jul-2001 espie

case labels without statements are not permitted by ANSI C... and gcc 3.0
warns about them.


# 1.11 18-May-2001 mickey

stupidous debug was left enabled


# 1.10 10-May-2001 mickey

branches: 1.10.2;
dmamem_unmap the memory before dmamem_freeig it.
only affects unaligned transfers (such as disklabel, fsck and dump).
we used to get away w/ this due to older pmap, uvm or both.
be more precise w/ double-buffer on command failure as well.
once at it, allow more than 1 segment for double-buffer to be allocated.
also fix a couple of endianesses and command timeouts.


Revision tags: OPENBSD_2_9_BASE
# 1.9 14-Mar-2001 mickey

branches: 1.9.2;
it seems sometimes it takes up to 35 seconds to init; from Chris Kuethe ckuethe@[[gecko.]math.]ualberta.ca


# 1.8 09-Mar-2001 mickey

missing twe_unlock for failed get_ccb() for i/o scsi cmd, which was impossible to trigger in twese case because of how maxcmds is calculated


# 1.7 19-Feb-2001 mickey

propoer dmaable memory allocations


# 1.6 07-Jan-2001 mickey

fix a few scsi_done() usages.
simplify locking a bit.
disable write cache if said so in the scsi_xfer.
a few more commands, from freebsd.


# 1.5 08-Nov-2000 mickey

oops, oops w/ no configured units


# 1.4 07-Nov-2000 mickey

estimate sc_link.openings on the number of configured units


Revision tags: OPENBSD_2_8_BASE
# 1.3 25-Sep-2000 mickey

do not do queue locking in get/put_ccb, since calling blocks
have gotten it already locked appropriately.
only try to satiate the command queue if there was a command interrupt,
it seems it's quite well-behaving this way.
dispose allocated resources if twe_attach() fails.


# 1.2 15-Sep-2000 mickey

forgot to turn off debugging


# 1.1 15-Sep-2000 mickey

3ware escalade ide raid controllers


# 1.61 03-Sep-2020 krw

Replace '.response_format = 2' with '.response_format = SID_SCSI2_RESPONSE'.


# 1.60 02-Sep-2020 krw

When building emulated INQUIRY results use the SCSI_REV_* #define's to
initialize the 'version' field. Not numbers.


# 1.59 01-Sep-2020 krw

Rename [READ|WRITE]_BIG to [READ|WRITE]_10. Rename struct scsi_rw_big to
struct scsi_rw_10.

ok gnezdo@ jmatthew@ (who also did sparc64 compile test)


# 1.58 24-Jul-2020 krw

Turning on various scsi drivers' *DEBUG options reveals that this has
rarely (if ever) been done.

Fix many printf format errors to calm clang and gcc on amd64, i386,
hppa. Missing #include, complaints if 'option <blah>DEBUG' is used in
config files, etc. All in debug code.


# 1.57 20-Jul-2020 krw

Move remaining scsi bus initialization info from "prototype scsi link"
fields to struct scsibus_attach_args. Nuke the struct scsi_link *
(saa_sc_link) in scaibus_attach_args.

Explicitly initialize each field in scsibus_attach_args variables.


# 1.56 19-Jul-2020 krw

Move the adapter related items (luns, adapter, adapter_target,
adapter_buswidth, adapter_softc) from struct scsi_link to struct
scsibus_attach_args.

Additional compile tests by jmatthew@ (sparc64) and aoyam@ (luna88k).


# 1.55 16-Jul-2020 krw

Access adapter softc via link->bus->sb_adapter_softc.

In sparc64 autoconf access 'luns' via sb_luns and 'adapter_buswidth'
via sb_adapter_buswidth.

Removes last post-config uses of the copies of bus related
information in scsi_link.


# 1.54 27-Jun-2020 krw

Nuke trailing whitespace.


# 1.53 27-Jun-2020 krw

No need to bzero()/memset() 'struct scsibus_attach_args' variables
immediately before initializing the only field in the struct.


# 1.52 24-Jun-2020 krw

Use SDEV_NO_ADAPTER_TARGET instead of the value that is being
aassigned to adapter_buswidth to indicate the adapter is not a target
on the bus.

ok dlg@ as part of a larger diff.


Revision tags: OPENBSD_6_7_BASE
# 1.51 15-Feb-2020 krw

*_minphys() functions that cap i/o sizes at a value larger than the
value minphys() uses (MAXPHYS) are pointless since minphys() is always
called after the *_minphys() function.

MAXPHYS (64 * 1024) == 16 * 4096. 4096 is the smallest PAGE_SIZE we
have. So a *_minphys() function that caps the i/o size at N *
PAGE_SIZE where N is > 16 is just wasting cycles.

Nuke adv_minphys (40 * PAGE_SIZE), adw_minphys (254 * PAGE_SIZE),
ahc_minphys (128 * PAGE_SIZE), ahd_minphys (128 * PAGE_SIZE),
ami_minphys (26 * PAGE_SIZE), cac_minphys (65535 (!!!) * 512),
iha_minphsy (32 * PAGE_SIZE), trm_minphys (31 * PAGE_SIZE),
twe_minphys (62 * PAGE_SIZE). uha_minphys (32 * PAGE_SIZE),


# 1.50 26-Jan-2020 krw

Shuffle some names around to make reading the code less headache
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.


# 1.49 25-Jan-2020 krw

Drivers that implement their own *minphys() don't need to call the
system minphys(). scsi_minphys() will do that and cd/sd/st will call
scsi_minphys().

ok jmatthew@ as part of larger diff


# 1.48 23-Jan-2020 krw

Use a consistant idiom/format when declaring scsi_adapter structures
in drivers. Terse one liners, NULLs instead of 0's, explicitly specify
all members, etc.

Nuke #ifdef notyet blocks related to the scsi_adapter in aic.

No intentional functional change.

ok tedu@


# 1.47 31-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok kn@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.46 22-Jan-2016 jsg

remove a surplus splbio
ok deraadt@ krw@


Revision tags: OPENBSD_5_8_BASE
# 1.45 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.44 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.43 18-Nov-2013 deraadt

format string


# 1.42 18-Nov-2013 deraadt

simplify kthread_create(). no more stdarg
ok matthew guenther mikeb


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.41 17-Jul-2011 matthew

Backout a bunch of my SCSI commits from c2k11. At least one of these
is causing problems when trying to boot sparc64 from an isp(4).

Verified to fix the sparc64/isp(4) regression by krw@; ok deraadt@


# 1.40 08-Jul-2011 matthew

First batch of converting SCSI HBAs from setting saa_targets and
saa_luns instead of adapter_buswidth and luns in the prototype link.

ok dlg@, miod@


# 1.39 03-Apr-2011 dlg

move twe over to iopools so we can get rid of another NO_CCB user. this
also cuts the aen drain over to using an iohandler so it can be made
reliable.

this compiles, but i havent got hardware to test with. its going in as a
way to force testing. if there's a problem with the code then let me know
or back it out.

"man up" k2k11


Revision tags: OPENBSD_4_9_BASE
# 1.38 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


Revision tags: OPENBSD_4_8_BASE
# 1.37 28-Jun-2010 krw

Remove all adapter-specific 'struct scsi_device's. They are never used. First
step in elminating 'struct scsi_device' entirely.

Spotted and initial diff from matthew@.

ok matthew@ dlg@ deraadt@ marco@ miod@


# 1.36 20-May-2010 krw

New scsi code seems to be stable. Pluck previously identified
low-hanging splbio/splx pairs that are no longer needed and see if
this reveals any hidden scsi flaws.

ok dlg@


# 1.35 29-Mar-2010 krw

Initialize various uninitialized variables. Found by jsg@ via Clang.

Feedback from miod@ and kettenis@.

ok beck@


# 1.34 23-Mar-2010 krw

Change the scsi_cmd function member of scsi_adapter from int to
void. Use XS_NO_CCB error in the scsi command (xs) to report the
NO_CCB condition. Eliminates all SUCCESSFULLY_QUEUED and COMPLETE
confusion and untangles the midlayer from the adapter a bit more.

Eyes and some fixes by miod@

There may be some compile issues on little used (i.e. I don't have
any) drivers but the change is mechanical and thus easy to remedy.

ok dlg@


Revision tags: OPENBSD_4_7_BASE
# 1.33 09-Jan-2010 krw

Zap all setting of ITSDONE in drivers that don't look at it. Nobody
else cares so it's just noise. Drivers that actually look at ITSDONE
are unchanged.

ok marco@ (for his files) dlg@ beck@


# 1.32 22-Nov-2009 krw

Bring last drivers fully into the NO_CCB world by replacing
TRY_AGAIN_LATER uses with equivalent NO_CCB. Eliminates confusion
between the two as was always intended. buf I/O's that can't be
started get pushed back onto the front of the queue and retried.
Others get sent back to originator as failures. No more epi-cycle
looping inside the SCSI midlayer hoping the problem goes away.

Various testers, no objection from miod@ as vs(4) was tested by
nick@.


# 1.31 03-Sep-2009 dlg

must call scsi_done before returning complete.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.30 16-Feb-2009 miod

Extend the scsi_adapter minphys() callback to take a struct scsi_link *
as additional argument. This will allow intermediate layers between
scsi devices such as sd and scsi host adapters to take appropriate
action if necessary.


Revision tags: OPENBSD_4_4_BASE
# 1.29 24-Jul-2008 thib

the softc sc_lock lockmgr lock is unused, so remove it.

ok krw@, dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.28 20-Oct-2007 krw

Call scsi_done() at SPLBIO. 'looks olright' says mickey.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.27 29-Dec-2006 pedro

Avoid void * arithmetic, okay deraadt@, suggestions from millert@


# 1.26 28-Nov-2006 dlg

give scsi controllers a real attach args to fill in when attaching scsibus.

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.25 03-Dec-2005 krw

The first thing done when XXX_scsi_cmd() returns TRY_AGAIN_LATER is
to set xs->error to XS_BUSY. So it is pointless and misleading to
set xs->error to XS_TIMEOUT, XS_DRIVER_STUFFUP or XS_BUSY just before
returning TRY_AGAIN_LATER.

No functional change.


# 1.24 15-Sep-2005 krw

Don't fake MODE SENSE page 4 info inside raid drivers, just let sd
fake a geometry. Page 4 info does not get used for size information.
Eliminate now unused union scsi_disk_pages.

ok marco@ mickey@ pre-lock.


Revision tags: OPENBSD_3_8_BASE
# 1.23 03-Jul-2005 krw

Fix data_length values in simulationed MODE SENSE page 4 responses so
that scsi_do_mode_sense() accepts them.

The data_length value does not include itself, and the pg_length value
in a mode page does not include itself or the page_code fields. We
were +1 on the former and -2 on the latter resulting in a data_length
value that was too small by one.

Eliminates 'mode sense page 5 not simulated' messages.

ok marco@


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.22 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


# 1.21 02-Jun-2003 mickey

kill the caluses three and four on some of my code


Revision tags: UBC_SYNC_A
# 1.20 27-Apr-2003 ho

strcpy/sprintf cleanup of sys/dev. miod@, deraadt@ says to commit.


# 1.19 09-Apr-2003 mickey

missing nl in the error msg and a return afterwards


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.18 17-Sep-2002 mickey

deal w/ the dma in a special thread to follow the busdma semantics. this fixes panics on unaligned physio; w/ help and testing from daniel@lucq.org


Revision tags: OPENBSD_3_1_BASE
# 1.17 14-Mar-2002 millert

First round of __P removal in sys


# 1.16 31-Jan-2002 mickey

scsi_done() is unsafe, rearrange locking to compensate


Revision tags: UBC_BASE
# 1.15 06-Dec-2001 mickey

branches: 1.15.2;
clear all inrterrupts separately and before enabling any.
this prevents stray interrupts and sometimes hangs,
caused by looping on stray unmapped interrupt.


# 1.14 05-Nov-2001 art

Switch everything to the new bus_dmamap_sync API.
Most work by Wilbern Cobb <vedge@csoft.org> with some fixes from me, mickey@
and drahn@.


Revision tags: OPENBSD_3_0_BASE
# 1.13 24-Sep-2001 mickey

get rid of kvtop, not that it matters that much


# 1.12 04-Jul-2001 espie

case labels without statements are not permitted by ANSI C... and gcc 3.0
warns about them.


# 1.11 18-May-2001 mickey

stupidous debug was left enabled


# 1.10 10-May-2001 mickey

branches: 1.10.2;
dmamem_unmap the memory before dmamem_freeig it.
only affects unaligned transfers (such as disklabel, fsck and dump).
we used to get away w/ this due to older pmap, uvm or both.
be more precise w/ double-buffer on command failure as well.
once at it, allow more than 1 segment for double-buffer to be allocated.
also fix a couple of endianesses and command timeouts.


Revision tags: OPENBSD_2_9_BASE
# 1.9 14-Mar-2001 mickey

branches: 1.9.2;
it seems sometimes it takes up to 35 seconds to init; from Chris Kuethe ckuethe@[[gecko.]math.]ualberta.ca


# 1.8 09-Mar-2001 mickey

missing twe_unlock for failed get_ccb() for i/o scsi cmd, which was impossible to trigger in twese case because of how maxcmds is calculated


# 1.7 19-Feb-2001 mickey

propoer dmaable memory allocations


# 1.6 07-Jan-2001 mickey

fix a few scsi_done() usages.
simplify locking a bit.
disable write cache if said so in the scsi_xfer.
a few more commands, from freebsd.


# 1.5 08-Nov-2000 mickey

oops, oops w/ no configured units


# 1.4 07-Nov-2000 mickey

estimate sc_link.openings on the number of configured units


Revision tags: OPENBSD_2_8_BASE
# 1.3 25-Sep-2000 mickey

do not do queue locking in get/put_ccb, since calling blocks
have gotten it already locked appropriately.
only try to satiate the command queue if there was a command interrupt,
it seems it's quite well-behaving this way.
dispose allocated resources if twe_attach() fails.


# 1.2 15-Sep-2000 mickey

forgot to turn off debugging


# 1.1 15-Sep-2000 mickey

3ware escalade ide raid controllers


# 1.61 03-Sep-2020 krw

Replace '.response_format = 2' with '.response_format = SID_SCSI2_RESPONSE'.


# 1.60 02-Sep-2020 krw

When building emulated INQUIRY results use the SCSI_REV_* #define's to
initialize the 'version' field. Not numbers.


# 1.59 01-Sep-2020 krw

Rename [READ|WRITE]_BIG to [READ|WRITE]_10. Rename struct scsi_rw_big to
struct scsi_rw_10.

ok gnezdo@ jmatthew@ (who also did sparc64 compile test)


# 1.58 24-Jul-2020 krw

Turning on various scsi drivers' *DEBUG options reveals that this has
rarely (if ever) been done.

Fix many printf format errors to calm clang and gcc on amd64, i386,
hppa. Missing #include, complaints if 'option <blah>DEBUG' is used in
config files, etc. All in debug code.


# 1.57 20-Jul-2020 krw

Move remaining scsi bus initialization info from "prototype scsi link"
fields to struct scsibus_attach_args. Nuke the struct scsi_link *
(saa_sc_link) in scaibus_attach_args.

Explicitly initialize each field in scsibus_attach_args variables.


# 1.56 19-Jul-2020 krw

Move the adapter related items (luns, adapter, adapter_target,
adapter_buswidth, adapter_softc) from struct scsi_link to struct
scsibus_attach_args.

Additional compile tests by jmatthew@ (sparc64) and aoyam@ (luna88k).


# 1.55 16-Jul-2020 krw

Access adapter softc via link->bus->sb_adapter_softc.

In sparc64 autoconf access 'luns' via sb_luns and 'adapter_buswidth'
via sb_adapter_buswidth.

Removes last post-config uses of the copies of bus related
information in scsi_link.


# 1.54 27-Jun-2020 krw

Nuke trailing whitespace.


# 1.53 27-Jun-2020 krw

No need to bzero()/memset() 'struct scsibus_attach_args' variables
immediately before initializing the only field in the struct.


# 1.52 24-Jun-2020 krw

Use SDEV_NO_ADAPTER_TARGET instead of the value that is being
aassigned to adapter_buswidth to indicate the adapter is not a target
on the bus.

ok dlg@ as part of a larger diff.


Revision tags: OPENBSD_6_7_BASE
# 1.51 15-Feb-2020 krw

*_minphys() functions that cap i/o sizes at a value larger than the
value minphys() uses (MAXPHYS) are pointless since minphys() is always
called after the *_minphys() function.

MAXPHYS (64 * 1024) == 16 * 4096. 4096 is the smallest PAGE_SIZE we
have. So a *_minphys() function that caps the i/o size at N *
PAGE_SIZE where N is > 16 is just wasting cycles.

Nuke adv_minphys (40 * PAGE_SIZE), adw_minphys (254 * PAGE_SIZE),
ahc_minphys (128 * PAGE_SIZE), ahd_minphys (128 * PAGE_SIZE),
ami_minphys (26 * PAGE_SIZE), cac_minphys (65535 (!!!) * 512),
iha_minphsy (32 * PAGE_SIZE), trm_minphys (31 * PAGE_SIZE),
twe_minphys (62 * PAGE_SIZE). uha_minphys (32 * PAGE_SIZE),


# 1.50 26-Jan-2020 krw

Shuffle some names around to make reading the code less headache
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.


# 1.49 25-Jan-2020 krw

Drivers that implement their own *minphys() don't need to call the
system minphys(). scsi_minphys() will do that and cd/sd/st will call
scsi_minphys().

ok jmatthew@ as part of larger diff


# 1.48 23-Jan-2020 krw

Use a consistant idiom/format when declaring scsi_adapter structures
in drivers. Terse one liners, NULLs instead of 0's, explicitly specify
all members, etc.

Nuke #ifdef notyet blocks related to the scsi_adapter in aic.

No intentional functional change.

ok tedu@


# 1.47 31-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok kn@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.46 22-Jan-2016 jsg

remove a surplus splbio
ok deraadt@ krw@


Revision tags: OPENBSD_5_8_BASE
# 1.45 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.44 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.43 18-Nov-2013 deraadt

format string


# 1.42 18-Nov-2013 deraadt

simplify kthread_create(). no more stdarg
ok matthew guenther mikeb


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.41 17-Jul-2011 matthew

Backout a bunch of my SCSI commits from c2k11. At least one of these
is causing problems when trying to boot sparc64 from an isp(4).

Verified to fix the sparc64/isp(4) regression by krw@; ok deraadt@


# 1.40 08-Jul-2011 matthew

First batch of converting SCSI HBAs from setting saa_targets and
saa_luns instead of adapter_buswidth and luns in the prototype link.

ok dlg@, miod@


# 1.39 03-Apr-2011 dlg

move twe over to iopools so we can get rid of another NO_CCB user. this
also cuts the aen drain over to using an iohandler so it can be made
reliable.

this compiles, but i havent got hardware to test with. its going in as a
way to force testing. if there's a problem with the code then let me know
or back it out.

"man up" k2k11


Revision tags: OPENBSD_4_9_BASE
# 1.38 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


Revision tags: OPENBSD_4_8_BASE
# 1.37 28-Jun-2010 krw

Remove all adapter-specific 'struct scsi_device's. They are never used. First
step in elminating 'struct scsi_device' entirely.

Spotted and initial diff from matthew@.

ok matthew@ dlg@ deraadt@ marco@ miod@


# 1.36 20-May-2010 krw

New scsi code seems to be stable. Pluck previously identified
low-hanging splbio/splx pairs that are no longer needed and see if
this reveals any hidden scsi flaws.

ok dlg@


# 1.35 29-Mar-2010 krw

Initialize various uninitialized variables. Found by jsg@ via Clang.

Feedback from miod@ and kettenis@.

ok beck@


# 1.34 23-Mar-2010 krw

Change the scsi_cmd function member of scsi_adapter from int to
void. Use XS_NO_CCB error in the scsi command (xs) to report the
NO_CCB condition. Eliminates all SUCCESSFULLY_QUEUED and COMPLETE
confusion and untangles the midlayer from the adapter a bit more.

Eyes and some fixes by miod@

There may be some compile issues on little used (i.e. I don't have
any) drivers but the change is mechanical and thus easy to remedy.

ok dlg@


Revision tags: OPENBSD_4_7_BASE
# 1.33 09-Jan-2010 krw

Zap all setting of ITSDONE in drivers that don't look at it. Nobody
else cares so it's just noise. Drivers that actually look at ITSDONE
are unchanged.

ok marco@ (for his files) dlg@ beck@


# 1.32 22-Nov-2009 krw

Bring last drivers fully into the NO_CCB world by replacing
TRY_AGAIN_LATER uses with equivalent NO_CCB. Eliminates confusion
between the two as was always intended. buf I/O's that can't be
started get pushed back onto the front of the queue and retried.
Others get sent back to originator as failures. No more epi-cycle
looping inside the SCSI midlayer hoping the problem goes away.

Various testers, no objection from miod@ as vs(4) was tested by
nick@.


# 1.31 03-Sep-2009 dlg

must call scsi_done before returning complete.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.30 16-Feb-2009 miod

Extend the scsi_adapter minphys() callback to take a struct scsi_link *
as additional argument. This will allow intermediate layers between
scsi devices such as sd and scsi host adapters to take appropriate
action if necessary.


Revision tags: OPENBSD_4_4_BASE
# 1.29 24-Jul-2008 thib

the softc sc_lock lockmgr lock is unused, so remove it.

ok krw@, dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.28 20-Oct-2007 krw

Call scsi_done() at SPLBIO. 'looks olright' says mickey.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.27 29-Dec-2006 pedro

Avoid void * arithmetic, okay deraadt@, suggestions from millert@


# 1.26 28-Nov-2006 dlg

give scsi controllers a real attach args to fill in when attaching scsibus.

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.25 03-Dec-2005 krw

The first thing done when XXX_scsi_cmd() returns TRY_AGAIN_LATER is
to set xs->error to XS_BUSY. So it is pointless and misleading to
set xs->error to XS_TIMEOUT, XS_DRIVER_STUFFUP or XS_BUSY just before
returning TRY_AGAIN_LATER.

No functional change.


# 1.24 15-Sep-2005 krw

Don't fake MODE SENSE page 4 info inside raid drivers, just let sd
fake a geometry. Page 4 info does not get used for size information.
Eliminate now unused union scsi_disk_pages.

ok marco@ mickey@ pre-lock.


Revision tags: OPENBSD_3_8_BASE
# 1.23 03-Jul-2005 krw

Fix data_length values in simulationed MODE SENSE page 4 responses so
that scsi_do_mode_sense() accepts them.

The data_length value does not include itself, and the pg_length value
in a mode page does not include itself or the page_code fields. We
were +1 on the former and -2 on the latter resulting in a data_length
value that was too small by one.

Eliminates 'mode sense page 5 not simulated' messages.

ok marco@


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.22 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


# 1.21 02-Jun-2003 mickey

kill the caluses three and four on some of my code


Revision tags: UBC_SYNC_A
# 1.20 27-Apr-2003 ho

strcpy/sprintf cleanup of sys/dev. miod@, deraadt@ says to commit.


# 1.19 09-Apr-2003 mickey

missing nl in the error msg and a return afterwards


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.18 17-Sep-2002 mickey

deal w/ the dma in a special thread to follow the busdma semantics. this fixes panics on unaligned physio; w/ help and testing from daniel@lucq.org


Revision tags: OPENBSD_3_1_BASE
# 1.17 14-Mar-2002 millert

First round of __P removal in sys


# 1.16 31-Jan-2002 mickey

scsi_done() is unsafe, rearrange locking to compensate


Revision tags: UBC_BASE
# 1.15 06-Dec-2001 mickey

branches: 1.15.2;
clear all inrterrupts separately and before enabling any.
this prevents stray interrupts and sometimes hangs,
caused by looping on stray unmapped interrupt.


# 1.14 05-Nov-2001 art

Switch everything to the new bus_dmamap_sync API.
Most work by Wilbern Cobb <vedge@csoft.org> with some fixes from me, mickey@
and drahn@.


Revision tags: OPENBSD_3_0_BASE
# 1.13 24-Sep-2001 mickey

get rid of kvtop, not that it matters that much


# 1.12 04-Jul-2001 espie

case labels without statements are not permitted by ANSI C... and gcc 3.0
warns about them.


# 1.11 18-May-2001 mickey

stupidous debug was left enabled


# 1.10 10-May-2001 mickey

branches: 1.10.2;
dmamem_unmap the memory before dmamem_freeig it.
only affects unaligned transfers (such as disklabel, fsck and dump).
we used to get away w/ this due to older pmap, uvm or both.
be more precise w/ double-buffer on command failure as well.
once at it, allow more than 1 segment for double-buffer to be allocated.
also fix a couple of endianesses and command timeouts.


Revision tags: OPENBSD_2_9_BASE
# 1.9 14-Mar-2001 mickey

branches: 1.9.2;
it seems sometimes it takes up to 35 seconds to init; from Chris Kuethe ckuethe@[[gecko.]math.]ualberta.ca


# 1.8 09-Mar-2001 mickey

missing twe_unlock for failed get_ccb() for i/o scsi cmd, which was impossible to trigger in twese case because of how maxcmds is calculated


# 1.7 19-Feb-2001 mickey

propoer dmaable memory allocations


# 1.6 07-Jan-2001 mickey

fix a few scsi_done() usages.
simplify locking a bit.
disable write cache if said so in the scsi_xfer.
a few more commands, from freebsd.


# 1.5 08-Nov-2000 mickey

oops, oops w/ no configured units


# 1.4 07-Nov-2000 mickey

estimate sc_link.openings on the number of configured units


Revision tags: OPENBSD_2_8_BASE
# 1.3 25-Sep-2000 mickey

do not do queue locking in get/put_ccb, since calling blocks
have gotten it already locked appropriately.
only try to satiate the command queue if there was a command interrupt,
it seems it's quite well-behaving this way.
dispose allocated resources if twe_attach() fails.


# 1.2 15-Sep-2000 mickey

forgot to turn off debugging


# 1.1 15-Sep-2000 mickey

3ware escalade ide raid controllers


# 1.59 01-Sep-2020 krw

Rename [READ|WRITE]_BIG to [READ|WRITE]_10. Rename struct scsi_rw_big to
struct scsi_rw_10.

ok gnezdo@ jmatthew@ (who also did sparc64 compile test)


# 1.58 24-Jul-2020 krw

Turning on various scsi drivers' *DEBUG options reveals that this has
rarely (if ever) been done.

Fix many printf format errors to calm clang and gcc on amd64, i386,
hppa. Missing #include, complaints if 'option <blah>DEBUG' is used in
config files, etc. All in debug code.


# 1.57 20-Jul-2020 krw

Move remaining scsi bus initialization info from "prototype scsi link"
fields to struct scsibus_attach_args. Nuke the struct scsi_link *
(saa_sc_link) in scaibus_attach_args.

Explicitly initialize each field in scsibus_attach_args variables.


# 1.56 19-Jul-2020 krw

Move the adapter related items (luns, adapter, adapter_target,
adapter_buswidth, adapter_softc) from struct scsi_link to struct
scsibus_attach_args.

Additional compile tests by jmatthew@ (sparc64) and aoyam@ (luna88k).


# 1.55 16-Jul-2020 krw

Access adapter softc via link->bus->sb_adapter_softc.

In sparc64 autoconf access 'luns' via sb_luns and 'adapter_buswidth'
via sb_adapter_buswidth.

Removes last post-config uses of the copies of bus related
information in scsi_link.


# 1.54 27-Jun-2020 krw

Nuke trailing whitespace.


# 1.53 27-Jun-2020 krw

No need to bzero()/memset() 'struct scsibus_attach_args' variables
immediately before initializing the only field in the struct.


# 1.52 24-Jun-2020 krw

Use SDEV_NO_ADAPTER_TARGET instead of the value that is being
aassigned to adapter_buswidth to indicate the adapter is not a target
on the bus.

ok dlg@ as part of a larger diff.


Revision tags: OPENBSD_6_7_BASE
# 1.51 15-Feb-2020 krw

*_minphys() functions that cap i/o sizes at a value larger than the
value minphys() uses (MAXPHYS) are pointless since minphys() is always
called after the *_minphys() function.

MAXPHYS (64 * 1024) == 16 * 4096. 4096 is the smallest PAGE_SIZE we
have. So a *_minphys() function that caps the i/o size at N *
PAGE_SIZE where N is > 16 is just wasting cycles.

Nuke adv_minphys (40 * PAGE_SIZE), adw_minphys (254 * PAGE_SIZE),
ahc_minphys (128 * PAGE_SIZE), ahd_minphys (128 * PAGE_SIZE),
ami_minphys (26 * PAGE_SIZE), cac_minphys (65535 (!!!) * 512),
iha_minphsy (32 * PAGE_SIZE), trm_minphys (31 * PAGE_SIZE),
twe_minphys (62 * PAGE_SIZE). uha_minphys (32 * PAGE_SIZE),


# 1.50 26-Jan-2020 krw

Shuffle some names around to make reading the code less headache
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.


# 1.49 25-Jan-2020 krw

Drivers that implement their own *minphys() don't need to call the
system minphys(). scsi_minphys() will do that and cd/sd/st will call
scsi_minphys().

ok jmatthew@ as part of larger diff


# 1.48 23-Jan-2020 krw

Use a consistant idiom/format when declaring scsi_adapter structures
in drivers. Terse one liners, NULLs instead of 0's, explicitly specify
all members, etc.

Nuke #ifdef notyet blocks related to the scsi_adapter in aic.

No intentional functional change.

ok tedu@


# 1.47 31-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok kn@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.46 22-Jan-2016 jsg

remove a surplus splbio
ok deraadt@ krw@


Revision tags: OPENBSD_5_8_BASE
# 1.45 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.44 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.43 18-Nov-2013 deraadt

format string


# 1.42 18-Nov-2013 deraadt

simplify kthread_create(). no more stdarg
ok matthew guenther mikeb


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.41 17-Jul-2011 matthew

Backout a bunch of my SCSI commits from c2k11. At least one of these
is causing problems when trying to boot sparc64 from an isp(4).

Verified to fix the sparc64/isp(4) regression by krw@; ok deraadt@


# 1.40 08-Jul-2011 matthew

First batch of converting SCSI HBAs from setting saa_targets and
saa_luns instead of adapter_buswidth and luns in the prototype link.

ok dlg@, miod@


# 1.39 03-Apr-2011 dlg

move twe over to iopools so we can get rid of another NO_CCB user. this
also cuts the aen drain over to using an iohandler so it can be made
reliable.

this compiles, but i havent got hardware to test with. its going in as a
way to force testing. if there's a problem with the code then let me know
or back it out.

"man up" k2k11


Revision tags: OPENBSD_4_9_BASE
# 1.38 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


Revision tags: OPENBSD_4_8_BASE
# 1.37 28-Jun-2010 krw

Remove all adapter-specific 'struct scsi_device's. They are never used. First
step in elminating 'struct scsi_device' entirely.

Spotted and initial diff from matthew@.

ok matthew@ dlg@ deraadt@ marco@ miod@


# 1.36 20-May-2010 krw

New scsi code seems to be stable. Pluck previously identified
low-hanging splbio/splx pairs that are no longer needed and see if
this reveals any hidden scsi flaws.

ok dlg@


# 1.35 29-Mar-2010 krw

Initialize various uninitialized variables. Found by jsg@ via Clang.

Feedback from miod@ and kettenis@.

ok beck@


# 1.34 23-Mar-2010 krw

Change the scsi_cmd function member of scsi_adapter from int to
void. Use XS_NO_CCB error in the scsi command (xs) to report the
NO_CCB condition. Eliminates all SUCCESSFULLY_QUEUED and COMPLETE
confusion and untangles the midlayer from the adapter a bit more.

Eyes and some fixes by miod@

There may be some compile issues on little used (i.e. I don't have
any) drivers but the change is mechanical and thus easy to remedy.

ok dlg@


Revision tags: OPENBSD_4_7_BASE
# 1.33 09-Jan-2010 krw

Zap all setting of ITSDONE in drivers that don't look at it. Nobody
else cares so it's just noise. Drivers that actually look at ITSDONE
are unchanged.

ok marco@ (for his files) dlg@ beck@


# 1.32 22-Nov-2009 krw

Bring last drivers fully into the NO_CCB world by replacing
TRY_AGAIN_LATER uses with equivalent NO_CCB. Eliminates confusion
between the two as was always intended. buf I/O's that can't be
started get pushed back onto the front of the queue and retried.
Others get sent back to originator as failures. No more epi-cycle
looping inside the SCSI midlayer hoping the problem goes away.

Various testers, no objection from miod@ as vs(4) was tested by
nick@.


# 1.31 03-Sep-2009 dlg

must call scsi_done before returning complete.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.30 16-Feb-2009 miod

Extend the scsi_adapter minphys() callback to take a struct scsi_link *
as additional argument. This will allow intermediate layers between
scsi devices such as sd and scsi host adapters to take appropriate
action if necessary.


Revision tags: OPENBSD_4_4_BASE
# 1.29 24-Jul-2008 thib

the softc sc_lock lockmgr lock is unused, so remove it.

ok krw@, dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.28 20-Oct-2007 krw

Call scsi_done() at SPLBIO. 'looks olright' says mickey.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.27 29-Dec-2006 pedro

Avoid void * arithmetic, okay deraadt@, suggestions from millert@


# 1.26 28-Nov-2006 dlg

give scsi controllers a real attach args to fill in when attaching scsibus.

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.25 03-Dec-2005 krw

The first thing done when XXX_scsi_cmd() returns TRY_AGAIN_LATER is
to set xs->error to XS_BUSY. So it is pointless and misleading to
set xs->error to XS_TIMEOUT, XS_DRIVER_STUFFUP or XS_BUSY just before
returning TRY_AGAIN_LATER.

No functional change.


# 1.24 15-Sep-2005 krw

Don't fake MODE SENSE page 4 info inside raid drivers, just let sd
fake a geometry. Page 4 info does not get used for size information.
Eliminate now unused union scsi_disk_pages.

ok marco@ mickey@ pre-lock.


Revision tags: OPENBSD_3_8_BASE
# 1.23 03-Jul-2005 krw

Fix data_length values in simulationed MODE SENSE page 4 responses so
that scsi_do_mode_sense() accepts them.

The data_length value does not include itself, and the pg_length value
in a mode page does not include itself or the page_code fields. We
were +1 on the former and -2 on the latter resulting in a data_length
value that was too small by one.

Eliminates 'mode sense page 5 not simulated' messages.

ok marco@


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.22 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


# 1.21 02-Jun-2003 mickey

kill the caluses three and four on some of my code


Revision tags: UBC_SYNC_A
# 1.20 27-Apr-2003 ho

strcpy/sprintf cleanup of sys/dev. miod@, deraadt@ says to commit.


# 1.19 09-Apr-2003 mickey

missing nl in the error msg and a return afterwards


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.18 17-Sep-2002 mickey

deal w/ the dma in a special thread to follow the busdma semantics. this fixes panics on unaligned physio; w/ help and testing from daniel@lucq.org


Revision tags: OPENBSD_3_1_BASE
# 1.17 14-Mar-2002 millert

First round of __P removal in sys


# 1.16 31-Jan-2002 mickey

scsi_done() is unsafe, rearrange locking to compensate


Revision tags: UBC_BASE
# 1.15 06-Dec-2001 mickey

branches: 1.15.2;
clear all inrterrupts separately and before enabling any.
this prevents stray interrupts and sometimes hangs,
caused by looping on stray unmapped interrupt.


# 1.14 05-Nov-2001 art

Switch everything to the new bus_dmamap_sync API.
Most work by Wilbern Cobb <vedge@csoft.org> with some fixes from me, mickey@
and drahn@.


Revision tags: OPENBSD_3_0_BASE
# 1.13 24-Sep-2001 mickey

get rid of kvtop, not that it matters that much


# 1.12 04-Jul-2001 espie

case labels without statements are not permitted by ANSI C... and gcc 3.0
warns about them.


# 1.11 18-May-2001 mickey

stupidous debug was left enabled


# 1.10 10-May-2001 mickey

branches: 1.10.2;
dmamem_unmap the memory before dmamem_freeig it.
only affects unaligned transfers (such as disklabel, fsck and dump).
we used to get away w/ this due to older pmap, uvm or both.
be more precise w/ double-buffer on command failure as well.
once at it, allow more than 1 segment for double-buffer to be allocated.
also fix a couple of endianesses and command timeouts.


Revision tags: OPENBSD_2_9_BASE
# 1.9 14-Mar-2001 mickey

branches: 1.9.2;
it seems sometimes it takes up to 35 seconds to init; from Chris Kuethe ckuethe@[[gecko.]math.]ualberta.ca


# 1.8 09-Mar-2001 mickey

missing twe_unlock for failed get_ccb() for i/o scsi cmd, which was impossible to trigger in twese case because of how maxcmds is calculated


# 1.7 19-Feb-2001 mickey

propoer dmaable memory allocations


# 1.6 07-Jan-2001 mickey

fix a few scsi_done() usages.
simplify locking a bit.
disable write cache if said so in the scsi_xfer.
a few more commands, from freebsd.


# 1.5 08-Nov-2000 mickey

oops, oops w/ no configured units


# 1.4 07-Nov-2000 mickey

estimate sc_link.openings on the number of configured units


Revision tags: OPENBSD_2_8_BASE
# 1.3 25-Sep-2000 mickey

do not do queue locking in get/put_ccb, since calling blocks
have gotten it already locked appropriately.
only try to satiate the command queue if there was a command interrupt,
it seems it's quite well-behaving this way.
dispose allocated resources if twe_attach() fails.


# 1.2 15-Sep-2000 mickey

forgot to turn off debugging


# 1.1 15-Sep-2000 mickey

3ware escalade ide raid controllers


# 1.58 24-Jul-2020 krw

Turning on various scsi drivers' *DEBUG options reveals that this has
rarely (if ever) been done.

Fix many printf format errors to calm clang and gcc on amd64, i386,
hppa. Missing #include, complaints if 'option <blah>DEBUG' is used in
config files, etc. All in debug code.


# 1.57 20-Jul-2020 krw

Move remaining scsi bus initialization info from "prototype scsi link"
fields to struct scsibus_attach_args. Nuke the struct scsi_link *
(saa_sc_link) in scaibus_attach_args.

Explicitly initialize each field in scsibus_attach_args variables.


# 1.56 19-Jul-2020 krw

Move the adapter related items (luns, adapter, adapter_target,
adapter_buswidth, adapter_softc) from struct scsi_link to struct
scsibus_attach_args.

Additional compile tests by jmatthew@ (sparc64) and aoyam@ (luna88k).


# 1.55 16-Jul-2020 krw

Access adapter softc via link->bus->sb_adapter_softc.

In sparc64 autoconf access 'luns' via sb_luns and 'adapter_buswidth'
via sb_adapter_buswidth.

Removes last post-config uses of the copies of bus related
information in scsi_link.


# 1.54 27-Jun-2020 krw

Nuke trailing whitespace.


# 1.53 27-Jun-2020 krw

No need to bzero()/memset() 'struct scsibus_attach_args' variables
immediately before initializing the only field in the struct.


# 1.52 24-Jun-2020 krw

Use SDEV_NO_ADAPTER_TARGET instead of the value that is being
aassigned to adapter_buswidth to indicate the adapter is not a target
on the bus.

ok dlg@ as part of a larger diff.


Revision tags: OPENBSD_6_7_BASE
# 1.51 15-Feb-2020 krw

*_minphys() functions that cap i/o sizes at a value larger than the
value minphys() uses (MAXPHYS) are pointless since minphys() is always
called after the *_minphys() function.

MAXPHYS (64 * 1024) == 16 * 4096. 4096 is the smallest PAGE_SIZE we
have. So a *_minphys() function that caps the i/o size at N *
PAGE_SIZE where N is > 16 is just wasting cycles.

Nuke adv_minphys (40 * PAGE_SIZE), adw_minphys (254 * PAGE_SIZE),
ahc_minphys (128 * PAGE_SIZE), ahd_minphys (128 * PAGE_SIZE),
ami_minphys (26 * PAGE_SIZE), cac_minphys (65535 (!!!) * 512),
iha_minphsy (32 * PAGE_SIZE), trm_minphys (31 * PAGE_SIZE),
twe_minphys (62 * PAGE_SIZE). uha_minphys (32 * PAGE_SIZE),


# 1.50 26-Jan-2020 krw

Shuffle some names around to make reading the code less headache
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.


# 1.49 25-Jan-2020 krw

Drivers that implement their own *minphys() don't need to call the
system minphys(). scsi_minphys() will do that and cd/sd/st will call
scsi_minphys().

ok jmatthew@ as part of larger diff


# 1.48 23-Jan-2020 krw

Use a consistant idiom/format when declaring scsi_adapter structures
in drivers. Terse one liners, NULLs instead of 0's, explicitly specify
all members, etc.

Nuke #ifdef notyet blocks related to the scsi_adapter in aic.

No intentional functional change.

ok tedu@


# 1.47 31-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok kn@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.46 22-Jan-2016 jsg

remove a surplus splbio
ok deraadt@ krw@


Revision tags: OPENBSD_5_8_BASE
# 1.45 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.44 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.43 18-Nov-2013 deraadt

format string


# 1.42 18-Nov-2013 deraadt

simplify kthread_create(). no more stdarg
ok matthew guenther mikeb


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.41 17-Jul-2011 matthew

Backout a bunch of my SCSI commits from c2k11. At least one of these
is causing problems when trying to boot sparc64 from an isp(4).

Verified to fix the sparc64/isp(4) regression by krw@; ok deraadt@


# 1.40 08-Jul-2011 matthew

First batch of converting SCSI HBAs from setting saa_targets and
saa_luns instead of adapter_buswidth and luns in the prototype link.

ok dlg@, miod@


# 1.39 03-Apr-2011 dlg

move twe over to iopools so we can get rid of another NO_CCB user. this
also cuts the aen drain over to using an iohandler so it can be made
reliable.

this compiles, but i havent got hardware to test with. its going in as a
way to force testing. if there's a problem with the code then let me know
or back it out.

"man up" k2k11


Revision tags: OPENBSD_4_9_BASE
# 1.38 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


Revision tags: OPENBSD_4_8_BASE
# 1.37 28-Jun-2010 krw

Remove all adapter-specific 'struct scsi_device's. They are never used. First
step in elminating 'struct scsi_device' entirely.

Spotted and initial diff from matthew@.

ok matthew@ dlg@ deraadt@ marco@ miod@


# 1.36 20-May-2010 krw

New scsi code seems to be stable. Pluck previously identified
low-hanging splbio/splx pairs that are no longer needed and see if
this reveals any hidden scsi flaws.

ok dlg@


# 1.35 29-Mar-2010 krw

Initialize various uninitialized variables. Found by jsg@ via Clang.

Feedback from miod@ and kettenis@.

ok beck@


# 1.34 23-Mar-2010 krw

Change the scsi_cmd function member of scsi_adapter from int to
void. Use XS_NO_CCB error in the scsi command (xs) to report the
NO_CCB condition. Eliminates all SUCCESSFULLY_QUEUED and COMPLETE
confusion and untangles the midlayer from the adapter a bit more.

Eyes and some fixes by miod@

There may be some compile issues on little used (i.e. I don't have
any) drivers but the change is mechanical and thus easy to remedy.

ok dlg@


Revision tags: OPENBSD_4_7_BASE
# 1.33 09-Jan-2010 krw

Zap all setting of ITSDONE in drivers that don't look at it. Nobody
else cares so it's just noise. Drivers that actually look at ITSDONE
are unchanged.

ok marco@ (for his files) dlg@ beck@


# 1.32 22-Nov-2009 krw

Bring last drivers fully into the NO_CCB world by replacing
TRY_AGAIN_LATER uses with equivalent NO_CCB. Eliminates confusion
between the two as was always intended. buf I/O's that can't be
started get pushed back onto the front of the queue and retried.
Others get sent back to originator as failures. No more epi-cycle
looping inside the SCSI midlayer hoping the problem goes away.

Various testers, no objection from miod@ as vs(4) was tested by
nick@.


# 1.31 03-Sep-2009 dlg

must call scsi_done before returning complete.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.30 16-Feb-2009 miod

Extend the scsi_adapter minphys() callback to take a struct scsi_link *
as additional argument. This will allow intermediate layers between
scsi devices such as sd and scsi host adapters to take appropriate
action if necessary.


Revision tags: OPENBSD_4_4_BASE
# 1.29 24-Jul-2008 thib

the softc sc_lock lockmgr lock is unused, so remove it.

ok krw@, dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.28 20-Oct-2007 krw

Call scsi_done() at SPLBIO. 'looks olright' says mickey.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.27 29-Dec-2006 pedro

Avoid void * arithmetic, okay deraadt@, suggestions from millert@


# 1.26 28-Nov-2006 dlg

give scsi controllers a real attach args to fill in when attaching scsibus.

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.25 03-Dec-2005 krw

The first thing done when XXX_scsi_cmd() returns TRY_AGAIN_LATER is
to set xs->error to XS_BUSY. So it is pointless and misleading to
set xs->error to XS_TIMEOUT, XS_DRIVER_STUFFUP or XS_BUSY just before
returning TRY_AGAIN_LATER.

No functional change.


# 1.24 15-Sep-2005 krw

Don't fake MODE SENSE page 4 info inside raid drivers, just let sd
fake a geometry. Page 4 info does not get used for size information.
Eliminate now unused union scsi_disk_pages.

ok marco@ mickey@ pre-lock.


Revision tags: OPENBSD_3_8_BASE
# 1.23 03-Jul-2005 krw

Fix data_length values in simulationed MODE SENSE page 4 responses so
that scsi_do_mode_sense() accepts them.

The data_length value does not include itself, and the pg_length value
in a mode page does not include itself or the page_code fields. We
were +1 on the former and -2 on the latter resulting in a data_length
value that was too small by one.

Eliminates 'mode sense page 5 not simulated' messages.

ok marco@


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.22 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


# 1.21 02-Jun-2003 mickey

kill the caluses three and four on some of my code


Revision tags: UBC_SYNC_A
# 1.20 27-Apr-2003 ho

strcpy/sprintf cleanup of sys/dev. miod@, deraadt@ says to commit.


# 1.19 09-Apr-2003 mickey

missing nl in the error msg and a return afterwards


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.18 17-Sep-2002 mickey

deal w/ the dma in a special thread to follow the busdma semantics. this fixes panics on unaligned physio; w/ help and testing from daniel@lucq.org


Revision tags: OPENBSD_3_1_BASE
# 1.17 14-Mar-2002 millert

First round of __P removal in sys


# 1.16 31-Jan-2002 mickey

scsi_done() is unsafe, rearrange locking to compensate


Revision tags: UBC_BASE
# 1.15 06-Dec-2001 mickey

branches: 1.15.2;
clear all inrterrupts separately and before enabling any.
this prevents stray interrupts and sometimes hangs,
caused by looping on stray unmapped interrupt.


# 1.14 05-Nov-2001 art

Switch everything to the new bus_dmamap_sync API.
Most work by Wilbern Cobb <vedge@csoft.org> with some fixes from me, mickey@
and drahn@.


Revision tags: OPENBSD_3_0_BASE
# 1.13 24-Sep-2001 mickey

get rid of kvtop, not that it matters that much


# 1.12 04-Jul-2001 espie

case labels without statements are not permitted by ANSI C... and gcc 3.0
warns about them.


# 1.11 18-May-2001 mickey

stupidous debug was left enabled


# 1.10 10-May-2001 mickey

branches: 1.10.2;
dmamem_unmap the memory before dmamem_freeig it.
only affects unaligned transfers (such as disklabel, fsck and dump).
we used to get away w/ this due to older pmap, uvm or both.
be more precise w/ double-buffer on command failure as well.
once at it, allow more than 1 segment for double-buffer to be allocated.
also fix a couple of endianesses and command timeouts.


Revision tags: OPENBSD_2_9_BASE
# 1.9 14-Mar-2001 mickey

branches: 1.9.2;
it seems sometimes it takes up to 35 seconds to init; from Chris Kuethe ckuethe@[[gecko.]math.]ualberta.ca


# 1.8 09-Mar-2001 mickey

missing twe_unlock for failed get_ccb() for i/o scsi cmd, which was impossible to trigger in twese case because of how maxcmds is calculated


# 1.7 19-Feb-2001 mickey

propoer dmaable memory allocations


# 1.6 07-Jan-2001 mickey

fix a few scsi_done() usages.
simplify locking a bit.
disable write cache if said so in the scsi_xfer.
a few more commands, from freebsd.


# 1.5 08-Nov-2000 mickey

oops, oops w/ no configured units


# 1.4 07-Nov-2000 mickey

estimate sc_link.openings on the number of configured units


Revision tags: OPENBSD_2_8_BASE
# 1.3 25-Sep-2000 mickey

do not do queue locking in get/put_ccb, since calling blocks
have gotten it already locked appropriately.
only try to satiate the command queue if there was a command interrupt,
it seems it's quite well-behaving this way.
dispose allocated resources if twe_attach() fails.


# 1.2 15-Sep-2000 mickey

forgot to turn off debugging


# 1.1 15-Sep-2000 mickey

3ware escalade ide raid controllers


# 1.57 20-Jul-2020 krw

Move remaining scsi bus initialization info from "prototype scsi link"
fields to struct scsibus_attach_args. Nuke the struct scsi_link *
(saa_sc_link) in scaibus_attach_args.

Explicitly initialize each field in scsibus_attach_args variables.


# 1.56 19-Jul-2020 krw

Move the adapter related items (luns, adapter, adapter_target,
adapter_buswidth, adapter_softc) from struct scsi_link to struct
scsibus_attach_args.

Additional compile tests by jmatthew@ (sparc64) and aoyam@ (luna88k).


# 1.55 16-Jul-2020 krw

Access adapter softc via link->bus->sb_adapter_softc.

In sparc64 autoconf access 'luns' via sb_luns and 'adapter_buswidth'
via sb_adapter_buswidth.

Removes last post-config uses of the copies of bus related
information in scsi_link.


# 1.54 27-Jun-2020 krw

Nuke trailing whitespace.


# 1.53 27-Jun-2020 krw

No need to bzero()/memset() 'struct scsibus_attach_args' variables
immediately before initializing the only field in the struct.


# 1.52 24-Jun-2020 krw

Use SDEV_NO_ADAPTER_TARGET instead of the value that is being
aassigned to adapter_buswidth to indicate the adapter is not a target
on the bus.

ok dlg@ as part of a larger diff.


Revision tags: OPENBSD_6_7_BASE
# 1.51 15-Feb-2020 krw

*_minphys() functions that cap i/o sizes at a value larger than the
value minphys() uses (MAXPHYS) are pointless since minphys() is always
called after the *_minphys() function.

MAXPHYS (64 * 1024) == 16 * 4096. 4096 is the smallest PAGE_SIZE we
have. So a *_minphys() function that caps the i/o size at N *
PAGE_SIZE where N is > 16 is just wasting cycles.

Nuke adv_minphys (40 * PAGE_SIZE), adw_minphys (254 * PAGE_SIZE),
ahc_minphys (128 * PAGE_SIZE), ahd_minphys (128 * PAGE_SIZE),
ami_minphys (26 * PAGE_SIZE), cac_minphys (65535 (!!!) * 512),
iha_minphsy (32 * PAGE_SIZE), trm_minphys (31 * PAGE_SIZE),
twe_minphys (62 * PAGE_SIZE). uha_minphys (32 * PAGE_SIZE),


# 1.50 26-Jan-2020 krw

Shuffle some names around to make reading the code less headache
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.


# 1.49 25-Jan-2020 krw

Drivers that implement their own *minphys() don't need to call the
system minphys(). scsi_minphys() will do that and cd/sd/st will call
scsi_minphys().

ok jmatthew@ as part of larger diff


# 1.48 23-Jan-2020 krw

Use a consistant idiom/format when declaring scsi_adapter structures
in drivers. Terse one liners, NULLs instead of 0's, explicitly specify
all members, etc.

Nuke #ifdef notyet blocks related to the scsi_adapter in aic.

No intentional functional change.

ok tedu@


# 1.47 31-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok kn@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.46 22-Jan-2016 jsg

remove a surplus splbio
ok deraadt@ krw@


Revision tags: OPENBSD_5_8_BASE
# 1.45 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.44 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.43 18-Nov-2013 deraadt

format string


# 1.42 18-Nov-2013 deraadt

simplify kthread_create(). no more stdarg
ok matthew guenther mikeb


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.41 17-Jul-2011 matthew

Backout a bunch of my SCSI commits from c2k11. At least one of these
is causing problems when trying to boot sparc64 from an isp(4).

Verified to fix the sparc64/isp(4) regression by krw@; ok deraadt@


# 1.40 08-Jul-2011 matthew

First batch of converting SCSI HBAs from setting saa_targets and
saa_luns instead of adapter_buswidth and luns in the prototype link.

ok dlg@, miod@


# 1.39 03-Apr-2011 dlg

move twe over to iopools so we can get rid of another NO_CCB user. this
also cuts the aen drain over to using an iohandler so it can be made
reliable.

this compiles, but i havent got hardware to test with. its going in as a
way to force testing. if there's a problem with the code then let me know
or back it out.

"man up" k2k11


Revision tags: OPENBSD_4_9_BASE
# 1.38 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


Revision tags: OPENBSD_4_8_BASE
# 1.37 28-Jun-2010 krw

Remove all adapter-specific 'struct scsi_device's. They are never used. First
step in elminating 'struct scsi_device' entirely.

Spotted and initial diff from matthew@.

ok matthew@ dlg@ deraadt@ marco@ miod@


# 1.36 20-May-2010 krw

New scsi code seems to be stable. Pluck previously identified
low-hanging splbio/splx pairs that are no longer needed and see if
this reveals any hidden scsi flaws.

ok dlg@


# 1.35 29-Mar-2010 krw

Initialize various uninitialized variables. Found by jsg@ via Clang.

Feedback from miod@ and kettenis@.

ok beck@


# 1.34 23-Mar-2010 krw

Change the scsi_cmd function member of scsi_adapter from int to
void. Use XS_NO_CCB error in the scsi command (xs) to report the
NO_CCB condition. Eliminates all SUCCESSFULLY_QUEUED and COMPLETE
confusion and untangles the midlayer from the adapter a bit more.

Eyes and some fixes by miod@

There may be some compile issues on little used (i.e. I don't have
any) drivers but the change is mechanical and thus easy to remedy.

ok dlg@


Revision tags: OPENBSD_4_7_BASE
# 1.33 09-Jan-2010 krw

Zap all setting of ITSDONE in drivers that don't look at it. Nobody
else cares so it's just noise. Drivers that actually look at ITSDONE
are unchanged.

ok marco@ (for his files) dlg@ beck@


# 1.32 22-Nov-2009 krw

Bring last drivers fully into the NO_CCB world by replacing
TRY_AGAIN_LATER uses with equivalent NO_CCB. Eliminates confusion
between the two as was always intended. buf I/O's that can't be
started get pushed back onto the front of the queue and retried.
Others get sent back to originator as failures. No more epi-cycle
looping inside the SCSI midlayer hoping the problem goes away.

Various testers, no objection from miod@ as vs(4) was tested by
nick@.


# 1.31 03-Sep-2009 dlg

must call scsi_done before returning complete.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.30 16-Feb-2009 miod

Extend the scsi_adapter minphys() callback to take a struct scsi_link *
as additional argument. This will allow intermediate layers between
scsi devices such as sd and scsi host adapters to take appropriate
action if necessary.


Revision tags: OPENBSD_4_4_BASE
# 1.29 24-Jul-2008 thib

the softc sc_lock lockmgr lock is unused, so remove it.

ok krw@, dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.28 20-Oct-2007 krw

Call scsi_done() at SPLBIO. 'looks olright' says mickey.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.27 29-Dec-2006 pedro

Avoid void * arithmetic, okay deraadt@, suggestions from millert@


# 1.26 28-Nov-2006 dlg

give scsi controllers a real attach args to fill in when attaching scsibus.

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.25 03-Dec-2005 krw

The first thing done when XXX_scsi_cmd() returns TRY_AGAIN_LATER is
to set xs->error to XS_BUSY. So it is pointless and misleading to
set xs->error to XS_TIMEOUT, XS_DRIVER_STUFFUP or XS_BUSY just before
returning TRY_AGAIN_LATER.

No functional change.


# 1.24 15-Sep-2005 krw

Don't fake MODE SENSE page 4 info inside raid drivers, just let sd
fake a geometry. Page 4 info does not get used for size information.
Eliminate now unused union scsi_disk_pages.

ok marco@ mickey@ pre-lock.


Revision tags: OPENBSD_3_8_BASE
# 1.23 03-Jul-2005 krw

Fix data_length values in simulationed MODE SENSE page 4 responses so
that scsi_do_mode_sense() accepts them.

The data_length value does not include itself, and the pg_length value
in a mode page does not include itself or the page_code fields. We
were +1 on the former and -2 on the latter resulting in a data_length
value that was too small by one.

Eliminates 'mode sense page 5 not simulated' messages.

ok marco@


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.22 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


# 1.21 02-Jun-2003 mickey

kill the caluses three and four on some of my code


Revision tags: UBC_SYNC_A
# 1.20 27-Apr-2003 ho

strcpy/sprintf cleanup of sys/dev. miod@, deraadt@ says to commit.


# 1.19 09-Apr-2003 mickey

missing nl in the error msg and a return afterwards


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.18 17-Sep-2002 mickey

deal w/ the dma in a special thread to follow the busdma semantics. this fixes panics on unaligned physio; w/ help and testing from daniel@lucq.org


Revision tags: OPENBSD_3_1_BASE
# 1.17 14-Mar-2002 millert

First round of __P removal in sys


# 1.16 31-Jan-2002 mickey

scsi_done() is unsafe, rearrange locking to compensate


Revision tags: UBC_BASE
# 1.15 06-Dec-2001 mickey

branches: 1.15.2;
clear all inrterrupts separately and before enabling any.
this prevents stray interrupts and sometimes hangs,
caused by looping on stray unmapped interrupt.


# 1.14 05-Nov-2001 art

Switch everything to the new bus_dmamap_sync API.
Most work by Wilbern Cobb <vedge@csoft.org> with some fixes from me, mickey@
and drahn@.


Revision tags: OPENBSD_3_0_BASE
# 1.13 24-Sep-2001 mickey

get rid of kvtop, not that it matters that much


# 1.12 04-Jul-2001 espie

case labels without statements are not permitted by ANSI C... and gcc 3.0
warns about them.


# 1.11 18-May-2001 mickey

stupidous debug was left enabled


# 1.10 10-May-2001 mickey

branches: 1.10.2;
dmamem_unmap the memory before dmamem_freeig it.
only affects unaligned transfers (such as disklabel, fsck and dump).
we used to get away w/ this due to older pmap, uvm or both.
be more precise w/ double-buffer on command failure as well.
once at it, allow more than 1 segment for double-buffer to be allocated.
also fix a couple of endianesses and command timeouts.


Revision tags: OPENBSD_2_9_BASE
# 1.9 14-Mar-2001 mickey

branches: 1.9.2;
it seems sometimes it takes up to 35 seconds to init; from Chris Kuethe ckuethe@[[gecko.]math.]ualberta.ca


# 1.8 09-Mar-2001 mickey

missing twe_unlock for failed get_ccb() for i/o scsi cmd, which was impossible to trigger in twese case because of how maxcmds is calculated


# 1.7 19-Feb-2001 mickey

propoer dmaable memory allocations


# 1.6 07-Jan-2001 mickey

fix a few scsi_done() usages.
simplify locking a bit.
disable write cache if said so in the scsi_xfer.
a few more commands, from freebsd.


# 1.5 08-Nov-2000 mickey

oops, oops w/ no configured units


# 1.4 07-Nov-2000 mickey

estimate sc_link.openings on the number of configured units


Revision tags: OPENBSD_2_8_BASE
# 1.3 25-Sep-2000 mickey

do not do queue locking in get/put_ccb, since calling blocks
have gotten it already locked appropriately.
only try to satiate the command queue if there was a command interrupt,
it seems it's quite well-behaving this way.
dispose allocated resources if twe_attach() fails.


# 1.2 15-Sep-2000 mickey

forgot to turn off debugging


# 1.1 15-Sep-2000 mickey

3ware escalade ide raid controllers


# 1.55 16-Jul-2020 krw

Access adapter softc via link->bus->sb_adapter_softc.

In sparc64 autoconf access 'luns' via sb_luns and 'adapter_buswidth'
via sb_adapter_buswidth.

Removes last post-config uses of the copies of bus related
information in scsi_link.


# 1.54 27-Jun-2020 krw

Nuke trailing whitespace.


# 1.53 27-Jun-2020 krw

No need to bzero()/memset() 'struct scsibus_attach_args' variables
immediately before initializing the only field in the struct.


# 1.52 24-Jun-2020 krw

Use SDEV_NO_ADAPTER_TARGET instead of the value that is being
aassigned to adapter_buswidth to indicate the adapter is not a target
on the bus.

ok dlg@ as part of a larger diff.


Revision tags: OPENBSD_6_7_BASE
# 1.51 15-Feb-2020 krw

*_minphys() functions that cap i/o sizes at a value larger than the
value minphys() uses (MAXPHYS) are pointless since minphys() is always
called after the *_minphys() function.

MAXPHYS (64 * 1024) == 16 * 4096. 4096 is the smallest PAGE_SIZE we
have. So a *_minphys() function that caps the i/o size at N *
PAGE_SIZE where N is > 16 is just wasting cycles.

Nuke adv_minphys (40 * PAGE_SIZE), adw_minphys (254 * PAGE_SIZE),
ahc_minphys (128 * PAGE_SIZE), ahd_minphys (128 * PAGE_SIZE),
ami_minphys (26 * PAGE_SIZE), cac_minphys (65535 (!!!) * 512),
iha_minphsy (32 * PAGE_SIZE), trm_minphys (31 * PAGE_SIZE),
twe_minphys (62 * PAGE_SIZE). uha_minphys (32 * PAGE_SIZE),


# 1.50 26-Jan-2020 krw

Shuffle some names around to make reading the code less headache
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.


# 1.49 25-Jan-2020 krw

Drivers that implement their own *minphys() don't need to call the
system minphys(). scsi_minphys() will do that and cd/sd/st will call
scsi_minphys().

ok jmatthew@ as part of larger diff


# 1.48 23-Jan-2020 krw

Use a consistant idiom/format when declaring scsi_adapter structures
in drivers. Terse one liners, NULLs instead of 0's, explicitly specify
all members, etc.

Nuke #ifdef notyet blocks related to the scsi_adapter in aic.

No intentional functional change.

ok tedu@


# 1.47 31-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok kn@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.46 22-Jan-2016 jsg

remove a surplus splbio
ok deraadt@ krw@


Revision tags: OPENBSD_5_8_BASE
# 1.45 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.44 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.43 18-Nov-2013 deraadt

format string


# 1.42 18-Nov-2013 deraadt

simplify kthread_create(). no more stdarg
ok matthew guenther mikeb


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.41 17-Jul-2011 matthew

Backout a bunch of my SCSI commits from c2k11. At least one of these
is causing problems when trying to boot sparc64 from an isp(4).

Verified to fix the sparc64/isp(4) regression by krw@; ok deraadt@


# 1.40 08-Jul-2011 matthew

First batch of converting SCSI HBAs from setting saa_targets and
saa_luns instead of adapter_buswidth and luns in the prototype link.

ok dlg@, miod@


# 1.39 03-Apr-2011 dlg

move twe over to iopools so we can get rid of another NO_CCB user. this
also cuts the aen drain over to using an iohandler so it can be made
reliable.

this compiles, but i havent got hardware to test with. its going in as a
way to force testing. if there's a problem with the code then let me know
or back it out.

"man up" k2k11


Revision tags: OPENBSD_4_9_BASE
# 1.38 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


Revision tags: OPENBSD_4_8_BASE
# 1.37 28-Jun-2010 krw

Remove all adapter-specific 'struct scsi_device's. They are never used. First
step in elminating 'struct scsi_device' entirely.

Spotted and initial diff from matthew@.

ok matthew@ dlg@ deraadt@ marco@ miod@


# 1.36 20-May-2010 krw

New scsi code seems to be stable. Pluck previously identified
low-hanging splbio/splx pairs that are no longer needed and see if
this reveals any hidden scsi flaws.

ok dlg@


# 1.35 29-Mar-2010 krw

Initialize various uninitialized variables. Found by jsg@ via Clang.

Feedback from miod@ and kettenis@.

ok beck@


# 1.34 23-Mar-2010 krw

Change the scsi_cmd function member of scsi_adapter from int to
void. Use XS_NO_CCB error in the scsi command (xs) to report the
NO_CCB condition. Eliminates all SUCCESSFULLY_QUEUED and COMPLETE
confusion and untangles the midlayer from the adapter a bit more.

Eyes and some fixes by miod@

There may be some compile issues on little used (i.e. I don't have
any) drivers but the change is mechanical and thus easy to remedy.

ok dlg@


Revision tags: OPENBSD_4_7_BASE
# 1.33 09-Jan-2010 krw

Zap all setting of ITSDONE in drivers that don't look at it. Nobody
else cares so it's just noise. Drivers that actually look at ITSDONE
are unchanged.

ok marco@ (for his files) dlg@ beck@


# 1.32 22-Nov-2009 krw

Bring last drivers fully into the NO_CCB world by replacing
TRY_AGAIN_LATER uses with equivalent NO_CCB. Eliminates confusion
between the two as was always intended. buf I/O's that can't be
started get pushed back onto the front of the queue and retried.
Others get sent back to originator as failures. No more epi-cycle
looping inside the SCSI midlayer hoping the problem goes away.

Various testers, no objection from miod@ as vs(4) was tested by
nick@.


# 1.31 03-Sep-2009 dlg

must call scsi_done before returning complete.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.30 16-Feb-2009 miod

Extend the scsi_adapter minphys() callback to take a struct scsi_link *
as additional argument. This will allow intermediate layers between
scsi devices such as sd and scsi host adapters to take appropriate
action if necessary.


Revision tags: OPENBSD_4_4_BASE
# 1.29 24-Jul-2008 thib

the softc sc_lock lockmgr lock is unused, so remove it.

ok krw@, dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.28 20-Oct-2007 krw

Call scsi_done() at SPLBIO. 'looks olright' says mickey.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.27 29-Dec-2006 pedro

Avoid void * arithmetic, okay deraadt@, suggestions from millert@


# 1.26 28-Nov-2006 dlg

give scsi controllers a real attach args to fill in when attaching scsibus.

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.25 03-Dec-2005 krw

The first thing done when XXX_scsi_cmd() returns TRY_AGAIN_LATER is
to set xs->error to XS_BUSY. So it is pointless and misleading to
set xs->error to XS_TIMEOUT, XS_DRIVER_STUFFUP or XS_BUSY just before
returning TRY_AGAIN_LATER.

No functional change.


# 1.24 15-Sep-2005 krw

Don't fake MODE SENSE page 4 info inside raid drivers, just let sd
fake a geometry. Page 4 info does not get used for size information.
Eliminate now unused union scsi_disk_pages.

ok marco@ mickey@ pre-lock.


Revision tags: OPENBSD_3_8_BASE
# 1.23 03-Jul-2005 krw

Fix data_length values in simulationed MODE SENSE page 4 responses so
that scsi_do_mode_sense() accepts them.

The data_length value does not include itself, and the pg_length value
in a mode page does not include itself or the page_code fields. We
were +1 on the former and -2 on the latter resulting in a data_length
value that was too small by one.

Eliminates 'mode sense page 5 not simulated' messages.

ok marco@


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.22 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


# 1.21 02-Jun-2003 mickey

kill the caluses three and four on some of my code


Revision tags: UBC_SYNC_A
# 1.20 27-Apr-2003 ho

strcpy/sprintf cleanup of sys/dev. miod@, deraadt@ says to commit.


# 1.19 09-Apr-2003 mickey

missing nl in the error msg and a return afterwards


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.18 17-Sep-2002 mickey

deal w/ the dma in a special thread to follow the busdma semantics. this fixes panics on unaligned physio; w/ help and testing from daniel@lucq.org


Revision tags: OPENBSD_3_1_BASE
# 1.17 14-Mar-2002 millert

First round of __P removal in sys


# 1.16 31-Jan-2002 mickey

scsi_done() is unsafe, rearrange locking to compensate


Revision tags: UBC_BASE
# 1.15 06-Dec-2001 mickey

branches: 1.15.2;
clear all inrterrupts separately and before enabling any.
this prevents stray interrupts and sometimes hangs,
caused by looping on stray unmapped interrupt.


# 1.14 05-Nov-2001 art

Switch everything to the new bus_dmamap_sync API.
Most work by Wilbern Cobb <vedge@csoft.org> with some fixes from me, mickey@
and drahn@.


Revision tags: OPENBSD_3_0_BASE
# 1.13 24-Sep-2001 mickey

get rid of kvtop, not that it matters that much


# 1.12 04-Jul-2001 espie

case labels without statements are not permitted by ANSI C... and gcc 3.0
warns about them.


# 1.11 18-May-2001 mickey

stupidous debug was left enabled


# 1.10 10-May-2001 mickey

branches: 1.10.2;
dmamem_unmap the memory before dmamem_freeig it.
only affects unaligned transfers (such as disklabel, fsck and dump).
we used to get away w/ this due to older pmap, uvm or both.
be more precise w/ double-buffer on command failure as well.
once at it, allow more than 1 segment for double-buffer to be allocated.
also fix a couple of endianesses and command timeouts.


Revision tags: OPENBSD_2_9_BASE
# 1.9 14-Mar-2001 mickey

branches: 1.9.2;
it seems sometimes it takes up to 35 seconds to init; from Chris Kuethe ckuethe@[[gecko.]math.]ualberta.ca


# 1.8 09-Mar-2001 mickey

missing twe_unlock for failed get_ccb() for i/o scsi cmd, which was impossible to trigger in twese case because of how maxcmds is calculated


# 1.7 19-Feb-2001 mickey

propoer dmaable memory allocations


# 1.6 07-Jan-2001 mickey

fix a few scsi_done() usages.
simplify locking a bit.
disable write cache if said so in the scsi_xfer.
a few more commands, from freebsd.


# 1.5 08-Nov-2000 mickey

oops, oops w/ no configured units


# 1.4 07-Nov-2000 mickey

estimate sc_link.openings on the number of configured units


Revision tags: OPENBSD_2_8_BASE
# 1.3 25-Sep-2000 mickey

do not do queue locking in get/put_ccb, since calling blocks
have gotten it already locked appropriately.
only try to satiate the command queue if there was a command interrupt,
it seems it's quite well-behaving this way.
dispose allocated resources if twe_attach() fails.


# 1.2 15-Sep-2000 mickey

forgot to turn off debugging


# 1.1 15-Sep-2000 mickey

3ware escalade ide raid controllers


# 1.54 27-Jun-2020 krw

Nuke trailing whitespace.


# 1.53 27-Jun-2020 krw

No need to bzero()/memset() 'struct scsibus_attach_args' variables
immediately before initializing the only field in the struct.


# 1.52 24-Jun-2020 krw

Use SDEV_NO_ADAPTER_TARGET instead of the value that is being
aassigned to adapter_buswidth to indicate the adapter is not a target
on the bus.

ok dlg@ as part of a larger diff.


Revision tags: OPENBSD_6_7_BASE
# 1.51 15-Feb-2020 krw

*_minphys() functions that cap i/o sizes at a value larger than the
value minphys() uses (MAXPHYS) are pointless since minphys() is always
called after the *_minphys() function.

MAXPHYS (64 * 1024) == 16 * 4096. 4096 is the smallest PAGE_SIZE we
have. So a *_minphys() function that caps the i/o size at N *
PAGE_SIZE where N is > 16 is just wasting cycles.

Nuke adv_minphys (40 * PAGE_SIZE), adw_minphys (254 * PAGE_SIZE),
ahc_minphys (128 * PAGE_SIZE), ahd_minphys (128 * PAGE_SIZE),
ami_minphys (26 * PAGE_SIZE), cac_minphys (65535 (!!!) * 512),
iha_minphsy (32 * PAGE_SIZE), trm_minphys (31 * PAGE_SIZE),
twe_minphys (62 * PAGE_SIZE). uha_minphys (32 * PAGE_SIZE),


# 1.50 26-Jan-2020 krw

Shuffle some names around to make reading the code less headache
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.


# 1.49 25-Jan-2020 krw

Drivers that implement their own *minphys() don't need to call the
system minphys(). scsi_minphys() will do that and cd/sd/st will call
scsi_minphys().

ok jmatthew@ as part of larger diff


# 1.48 23-Jan-2020 krw

Use a consistant idiom/format when declaring scsi_adapter structures
in drivers. Terse one liners, NULLs instead of 0's, explicitly specify
all members, etc.

Nuke #ifdef notyet blocks related to the scsi_adapter in aic.

No intentional functional change.

ok tedu@


# 1.47 31-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok kn@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.46 22-Jan-2016 jsg

remove a surplus splbio
ok deraadt@ krw@


Revision tags: OPENBSD_5_8_BASE
# 1.45 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.44 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.43 18-Nov-2013 deraadt

format string


# 1.42 18-Nov-2013 deraadt

simplify kthread_create(). no more stdarg
ok matthew guenther mikeb


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.41 17-Jul-2011 matthew

Backout a bunch of my SCSI commits from c2k11. At least one of these
is causing problems when trying to boot sparc64 from an isp(4).

Verified to fix the sparc64/isp(4) regression by krw@; ok deraadt@


# 1.40 08-Jul-2011 matthew

First batch of converting SCSI HBAs from setting saa_targets and
saa_luns instead of adapter_buswidth and luns in the prototype link.

ok dlg@, miod@


# 1.39 03-Apr-2011 dlg

move twe over to iopools so we can get rid of another NO_CCB user. this
also cuts the aen drain over to using an iohandler so it can be made
reliable.

this compiles, but i havent got hardware to test with. its going in as a
way to force testing. if there's a problem with the code then let me know
or back it out.

"man up" k2k11


Revision tags: OPENBSD_4_9_BASE
# 1.38 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


Revision tags: OPENBSD_4_8_BASE
# 1.37 28-Jun-2010 krw

Remove all adapter-specific 'struct scsi_device's. They are never used. First
step in elminating 'struct scsi_device' entirely.

Spotted and initial diff from matthew@.

ok matthew@ dlg@ deraadt@ marco@ miod@


# 1.36 20-May-2010 krw

New scsi code seems to be stable. Pluck previously identified
low-hanging splbio/splx pairs that are no longer needed and see if
this reveals any hidden scsi flaws.

ok dlg@


# 1.35 29-Mar-2010 krw

Initialize various uninitialized variables. Found by jsg@ via Clang.

Feedback from miod@ and kettenis@.

ok beck@


# 1.34 23-Mar-2010 krw

Change the scsi_cmd function member of scsi_adapter from int to
void. Use XS_NO_CCB error in the scsi command (xs) to report the
NO_CCB condition. Eliminates all SUCCESSFULLY_QUEUED and COMPLETE
confusion and untangles the midlayer from the adapter a bit more.

Eyes and some fixes by miod@

There may be some compile issues on little used (i.e. I don't have
any) drivers but the change is mechanical and thus easy to remedy.

ok dlg@


Revision tags: OPENBSD_4_7_BASE
# 1.33 09-Jan-2010 krw

Zap all setting of ITSDONE in drivers that don't look at it. Nobody
else cares so it's just noise. Drivers that actually look at ITSDONE
are unchanged.

ok marco@ (for his files) dlg@ beck@


# 1.32 22-Nov-2009 krw

Bring last drivers fully into the NO_CCB world by replacing
TRY_AGAIN_LATER uses with equivalent NO_CCB. Eliminates confusion
between the two as was always intended. buf I/O's that can't be
started get pushed back onto the front of the queue and retried.
Others get sent back to originator as failures. No more epi-cycle
looping inside the SCSI midlayer hoping the problem goes away.

Various testers, no objection from miod@ as vs(4) was tested by
nick@.


# 1.31 03-Sep-2009 dlg

must call scsi_done before returning complete.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.30 16-Feb-2009 miod

Extend the scsi_adapter minphys() callback to take a struct scsi_link *
as additional argument. This will allow intermediate layers between
scsi devices such as sd and scsi host adapters to take appropriate
action if necessary.


Revision tags: OPENBSD_4_4_BASE
# 1.29 24-Jul-2008 thib

the softc sc_lock lockmgr lock is unused, so remove it.

ok krw@, dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.28 20-Oct-2007 krw

Call scsi_done() at SPLBIO. 'looks olright' says mickey.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.27 29-Dec-2006 pedro

Avoid void * arithmetic, okay deraadt@, suggestions from millert@


# 1.26 28-Nov-2006 dlg

give scsi controllers a real attach args to fill in when attaching scsibus.

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.25 03-Dec-2005 krw

The first thing done when XXX_scsi_cmd() returns TRY_AGAIN_LATER is
to set xs->error to XS_BUSY. So it is pointless and misleading to
set xs->error to XS_TIMEOUT, XS_DRIVER_STUFFUP or XS_BUSY just before
returning TRY_AGAIN_LATER.

No functional change.


# 1.24 15-Sep-2005 krw

Don't fake MODE SENSE page 4 info inside raid drivers, just let sd
fake a geometry. Page 4 info does not get used for size information.
Eliminate now unused union scsi_disk_pages.

ok marco@ mickey@ pre-lock.


Revision tags: OPENBSD_3_8_BASE
# 1.23 03-Jul-2005 krw

Fix data_length values in simulationed MODE SENSE page 4 responses so
that scsi_do_mode_sense() accepts them.

The data_length value does not include itself, and the pg_length value
in a mode page does not include itself or the page_code fields. We
were +1 on the former and -2 on the latter resulting in a data_length
value that was too small by one.

Eliminates 'mode sense page 5 not simulated' messages.

ok marco@


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.22 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


# 1.21 02-Jun-2003 mickey

kill the caluses three and four on some of my code


Revision tags: UBC_SYNC_A
# 1.20 27-Apr-2003 ho

strcpy/sprintf cleanup of sys/dev. miod@, deraadt@ says to commit.


# 1.19 09-Apr-2003 mickey

missing nl in the error msg and a return afterwards


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.18 17-Sep-2002 mickey

deal w/ the dma in a special thread to follow the busdma semantics. this fixes panics on unaligned physio; w/ help and testing from daniel@lucq.org


Revision tags: OPENBSD_3_1_BASE
# 1.17 14-Mar-2002 millert

First round of __P removal in sys


# 1.16 31-Jan-2002 mickey

scsi_done() is unsafe, rearrange locking to compensate


Revision tags: UBC_BASE
# 1.15 06-Dec-2001 mickey

branches: 1.15.2;
clear all inrterrupts separately and before enabling any.
this prevents stray interrupts and sometimes hangs,
caused by looping on stray unmapped interrupt.


# 1.14 05-Nov-2001 art

Switch everything to the new bus_dmamap_sync API.
Most work by Wilbern Cobb <vedge@csoft.org> with some fixes from me, mickey@
and drahn@.


Revision tags: OPENBSD_3_0_BASE
# 1.13 24-Sep-2001 mickey

get rid of kvtop, not that it matters that much


# 1.12 04-Jul-2001 espie

case labels without statements are not permitted by ANSI C... and gcc 3.0
warns about them.


# 1.11 18-May-2001 mickey

stupidous debug was left enabled


# 1.10 10-May-2001 mickey

branches: 1.10.2;
dmamem_unmap the memory before dmamem_freeig it.
only affects unaligned transfers (such as disklabel, fsck and dump).
we used to get away w/ this due to older pmap, uvm or both.
be more precise w/ double-buffer on command failure as well.
once at it, allow more than 1 segment for double-buffer to be allocated.
also fix a couple of endianesses and command timeouts.


Revision tags: OPENBSD_2_9_BASE
# 1.9 14-Mar-2001 mickey

branches: 1.9.2;
it seems sometimes it takes up to 35 seconds to init; from Chris Kuethe ckuethe@[[gecko.]math.]ualberta.ca


# 1.8 09-Mar-2001 mickey

missing twe_unlock for failed get_ccb() for i/o scsi cmd, which was impossible to trigger in twese case because of how maxcmds is calculated


# 1.7 19-Feb-2001 mickey

propoer dmaable memory allocations


# 1.6 07-Jan-2001 mickey

fix a few scsi_done() usages.
simplify locking a bit.
disable write cache if said so in the scsi_xfer.
a few more commands, from freebsd.


# 1.5 08-Nov-2000 mickey

oops, oops w/ no configured units


# 1.4 07-Nov-2000 mickey

estimate sc_link.openings on the number of configured units


Revision tags: OPENBSD_2_8_BASE
# 1.3 25-Sep-2000 mickey

do not do queue locking in get/put_ccb, since calling blocks
have gotten it already locked appropriately.
only try to satiate the command queue if there was a command interrupt,
it seems it's quite well-behaving this way.
dispose allocated resources if twe_attach() fails.


# 1.2 15-Sep-2000 mickey

forgot to turn off debugging


# 1.1 15-Sep-2000 mickey

3ware escalade ide raid controllers


# 1.52 24-Jun-2020 krw

Use SDEV_NO_ADAPTER_TARGET instead of the value that is being
aassigned to adapter_buswidth to indicate the adapter is not a target
on the bus.

ok dlg@ as part of a larger diff.


Revision tags: OPENBSD_6_7_BASE
# 1.51 15-Feb-2020 krw

*_minphys() functions that cap i/o sizes at a value larger than the
value minphys() uses (MAXPHYS) are pointless since minphys() is always
called after the *_minphys() function.

MAXPHYS (64 * 1024) == 16 * 4096. 4096 is the smallest PAGE_SIZE we
have. So a *_minphys() function that caps the i/o size at N *
PAGE_SIZE where N is > 16 is just wasting cycles.

Nuke adv_minphys (40 * PAGE_SIZE), adw_minphys (254 * PAGE_SIZE),
ahc_minphys (128 * PAGE_SIZE), ahd_minphys (128 * PAGE_SIZE),
ami_minphys (26 * PAGE_SIZE), cac_minphys (65535 (!!!) * 512),
iha_minphsy (32 * PAGE_SIZE), trm_minphys (31 * PAGE_SIZE),
twe_minphys (62 * PAGE_SIZE). uha_minphys (32 * PAGE_SIZE),


# 1.50 26-Jan-2020 krw

Shuffle some names around to make reading the code less headache
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.


# 1.49 25-Jan-2020 krw

Drivers that implement their own *minphys() don't need to call the
system minphys(). scsi_minphys() will do that and cd/sd/st will call
scsi_minphys().

ok jmatthew@ as part of larger diff


# 1.48 23-Jan-2020 krw

Use a consistant idiom/format when declaring scsi_adapter structures
in drivers. Terse one liners, NULLs instead of 0's, explicitly specify
all members, etc.

Nuke #ifdef notyet blocks related to the scsi_adapter in aic.

No intentional functional change.

ok tedu@


# 1.47 31-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok kn@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.46 22-Jan-2016 jsg

remove a surplus splbio
ok deraadt@ krw@


Revision tags: OPENBSD_5_8_BASE
# 1.45 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.44 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.43 18-Nov-2013 deraadt

format string


# 1.42 18-Nov-2013 deraadt

simplify kthread_create(). no more stdarg
ok matthew guenther mikeb


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.41 17-Jul-2011 matthew

Backout a bunch of my SCSI commits from c2k11. At least one of these
is causing problems when trying to boot sparc64 from an isp(4).

Verified to fix the sparc64/isp(4) regression by krw@; ok deraadt@


# 1.40 08-Jul-2011 matthew

First batch of converting SCSI HBAs from setting saa_targets and
saa_luns instead of adapter_buswidth and luns in the prototype link.

ok dlg@, miod@


# 1.39 03-Apr-2011 dlg

move twe over to iopools so we can get rid of another NO_CCB user. this
also cuts the aen drain over to using an iohandler so it can be made
reliable.

this compiles, but i havent got hardware to test with. its going in as a
way to force testing. if there's a problem with the code then let me know
or back it out.

"man up" k2k11


Revision tags: OPENBSD_4_9_BASE
# 1.38 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


Revision tags: OPENBSD_4_8_BASE
# 1.37 28-Jun-2010 krw

Remove all adapter-specific 'struct scsi_device's. They are never used. First
step in elminating 'struct scsi_device' entirely.

Spotted and initial diff from matthew@.

ok matthew@ dlg@ deraadt@ marco@ miod@


# 1.36 20-May-2010 krw

New scsi code seems to be stable. Pluck previously identified
low-hanging splbio/splx pairs that are no longer needed and see if
this reveals any hidden scsi flaws.

ok dlg@


# 1.35 29-Mar-2010 krw

Initialize various uninitialized variables. Found by jsg@ via Clang.

Feedback from miod@ and kettenis@.

ok beck@


# 1.34 23-Mar-2010 krw

Change the scsi_cmd function member of scsi_adapter from int to
void. Use XS_NO_CCB error in the scsi command (xs) to report the
NO_CCB condition. Eliminates all SUCCESSFULLY_QUEUED and COMPLETE
confusion and untangles the midlayer from the adapter a bit more.

Eyes and some fixes by miod@

There may be some compile issues on little used (i.e. I don't have
any) drivers but the change is mechanical and thus easy to remedy.

ok dlg@


Revision tags: OPENBSD_4_7_BASE
# 1.33 09-Jan-2010 krw

Zap all setting of ITSDONE in drivers that don't look at it. Nobody
else cares so it's just noise. Drivers that actually look at ITSDONE
are unchanged.

ok marco@ (for his files) dlg@ beck@


# 1.32 22-Nov-2009 krw

Bring last drivers fully into the NO_CCB world by replacing
TRY_AGAIN_LATER uses with equivalent NO_CCB. Eliminates confusion
between the two as was always intended. buf I/O's that can't be
started get pushed back onto the front of the queue and retried.
Others get sent back to originator as failures. No more epi-cycle
looping inside the SCSI midlayer hoping the problem goes away.

Various testers, no objection from miod@ as vs(4) was tested by
nick@.


# 1.31 03-Sep-2009 dlg

must call scsi_done before returning complete.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.30 16-Feb-2009 miod

Extend the scsi_adapter minphys() callback to take a struct scsi_link *
as additional argument. This will allow intermediate layers between
scsi devices such as sd and scsi host adapters to take appropriate
action if necessary.


Revision tags: OPENBSD_4_4_BASE
# 1.29 24-Jul-2008 thib

the softc sc_lock lockmgr lock is unused, so remove it.

ok krw@, dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.28 20-Oct-2007 krw

Call scsi_done() at SPLBIO. 'looks olright' says mickey.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.27 29-Dec-2006 pedro

Avoid void * arithmetic, okay deraadt@, suggestions from millert@


# 1.26 28-Nov-2006 dlg

give scsi controllers a real attach args to fill in when attaching scsibus.

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.25 03-Dec-2005 krw

The first thing done when XXX_scsi_cmd() returns TRY_AGAIN_LATER is
to set xs->error to XS_BUSY. So it is pointless and misleading to
set xs->error to XS_TIMEOUT, XS_DRIVER_STUFFUP or XS_BUSY just before
returning TRY_AGAIN_LATER.

No functional change.


# 1.24 15-Sep-2005 krw

Don't fake MODE SENSE page 4 info inside raid drivers, just let sd
fake a geometry. Page 4 info does not get used for size information.
Eliminate now unused union scsi_disk_pages.

ok marco@ mickey@ pre-lock.


Revision tags: OPENBSD_3_8_BASE
# 1.23 03-Jul-2005 krw

Fix data_length values in simulationed MODE SENSE page 4 responses so
that scsi_do_mode_sense() accepts them.

The data_length value does not include itself, and the pg_length value
in a mode page does not include itself or the page_code fields. We
were +1 on the former and -2 on the latter resulting in a data_length
value that was too small by one.

Eliminates 'mode sense page 5 not simulated' messages.

ok marco@


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.22 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


# 1.21 02-Jun-2003 mickey

kill the caluses three and four on some of my code


Revision tags: UBC_SYNC_A
# 1.20 27-Apr-2003 ho

strcpy/sprintf cleanup of sys/dev. miod@, deraadt@ says to commit.


# 1.19 09-Apr-2003 mickey

missing nl in the error msg and a return afterwards


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.18 17-Sep-2002 mickey

deal w/ the dma in a special thread to follow the busdma semantics. this fixes panics on unaligned physio; w/ help and testing from daniel@lucq.org


Revision tags: OPENBSD_3_1_BASE
# 1.17 14-Mar-2002 millert

First round of __P removal in sys


# 1.16 31-Jan-2002 mickey

scsi_done() is unsafe, rearrange locking to compensate


Revision tags: UBC_BASE
# 1.15 06-Dec-2001 mickey

branches: 1.15.2;
clear all inrterrupts separately and before enabling any.
this prevents stray interrupts and sometimes hangs,
caused by looping on stray unmapped interrupt.


# 1.14 05-Nov-2001 art

Switch everything to the new bus_dmamap_sync API.
Most work by Wilbern Cobb <vedge@csoft.org> with some fixes from me, mickey@
and drahn@.


Revision tags: OPENBSD_3_0_BASE
# 1.13 24-Sep-2001 mickey

get rid of kvtop, not that it matters that much


# 1.12 04-Jul-2001 espie

case labels without statements are not permitted by ANSI C... and gcc 3.0
warns about them.


# 1.11 18-May-2001 mickey

stupidous debug was left enabled


# 1.10 10-May-2001 mickey

branches: 1.10.2;
dmamem_unmap the memory before dmamem_freeig it.
only affects unaligned transfers (such as disklabel, fsck and dump).
we used to get away w/ this due to older pmap, uvm or both.
be more precise w/ double-buffer on command failure as well.
once at it, allow more than 1 segment for double-buffer to be allocated.
also fix a couple of endianesses and command timeouts.


Revision tags: OPENBSD_2_9_BASE
# 1.9 14-Mar-2001 mickey

branches: 1.9.2;
it seems sometimes it takes up to 35 seconds to init; from Chris Kuethe ckuethe@[[gecko.]math.]ualberta.ca


# 1.8 09-Mar-2001 mickey

missing twe_unlock for failed get_ccb() for i/o scsi cmd, which was impossible to trigger in twese case because of how maxcmds is calculated


# 1.7 19-Feb-2001 mickey

propoer dmaable memory allocations


# 1.6 07-Jan-2001 mickey

fix a few scsi_done() usages.
simplify locking a bit.
disable write cache if said so in the scsi_xfer.
a few more commands, from freebsd.


# 1.5 08-Nov-2000 mickey

oops, oops w/ no configured units


# 1.4 07-Nov-2000 mickey

estimate sc_link.openings on the number of configured units


Revision tags: OPENBSD_2_8_BASE
# 1.3 25-Sep-2000 mickey

do not do queue locking in get/put_ccb, since calling blocks
have gotten it already locked appropriately.
only try to satiate the command queue if there was a command interrupt,
it seems it's quite well-behaving this way.
dispose allocated resources if twe_attach() fails.


# 1.2 15-Sep-2000 mickey

forgot to turn off debugging


# 1.1 15-Sep-2000 mickey

3ware escalade ide raid controllers


# 1.51 15-Feb-2020 krw

*_minphys() functions that cap i/o sizes at a value larger than the
value minphys() uses (MAXPHYS) are pointless since minphys() is always
called after the *_minphys() function.

MAXPHYS (64 * 1024) == 16 * 4096. 4096 is the smallest PAGE_SIZE we
have. So a *_minphys() function that caps the i/o size at N *
PAGE_SIZE where N is > 16 is just wasting cycles.

Nuke adv_minphys (40 * PAGE_SIZE), adw_minphys (254 * PAGE_SIZE),
ahc_minphys (128 * PAGE_SIZE), ahd_minphys (128 * PAGE_SIZE),
ami_minphys (26 * PAGE_SIZE), cac_minphys (65535 (!!!) * 512),
iha_minphsy (32 * PAGE_SIZE), trm_minphys (31 * PAGE_SIZE),
twe_minphys (62 * PAGE_SIZE). uha_minphys (32 * PAGE_SIZE),


# 1.50 26-Jan-2020 krw

Shuffle some names around to make reading the code less headache
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.


# 1.49 25-Jan-2020 krw

Drivers that implement their own *minphys() don't need to call the
system minphys(). scsi_minphys() will do that and cd/sd/st will call
scsi_minphys().

ok jmatthew@ as part of larger diff


# 1.48 23-Jan-2020 krw

Use a consistant idiom/format when declaring scsi_adapter structures
in drivers. Terse one liners, NULLs instead of 0's, explicitly specify
all members, etc.

Nuke #ifdef notyet blocks related to the scsi_adapter in aic.

No intentional functional change.

ok tedu@


# 1.47 31-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok kn@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.46 22-Jan-2016 jsg

remove a surplus splbio
ok deraadt@ krw@


Revision tags: OPENBSD_5_8_BASE
# 1.45 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.44 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.43 18-Nov-2013 deraadt

format string


# 1.42 18-Nov-2013 deraadt

simplify kthread_create(). no more stdarg
ok matthew guenther mikeb


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.41 17-Jul-2011 matthew

Backout a bunch of my SCSI commits from c2k11. At least one of these
is causing problems when trying to boot sparc64 from an isp(4).

Verified to fix the sparc64/isp(4) regression by krw@; ok deraadt@


# 1.40 08-Jul-2011 matthew

First batch of converting SCSI HBAs from setting saa_targets and
saa_luns instead of adapter_buswidth and luns in the prototype link.

ok dlg@, miod@


# 1.39 03-Apr-2011 dlg

move twe over to iopools so we can get rid of another NO_CCB user. this
also cuts the aen drain over to using an iohandler so it can be made
reliable.

this compiles, but i havent got hardware to test with. its going in as a
way to force testing. if there's a problem with the code then let me know
or back it out.

"man up" k2k11


Revision tags: OPENBSD_4_9_BASE
# 1.38 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


Revision tags: OPENBSD_4_8_BASE
# 1.37 28-Jun-2010 krw

Remove all adapter-specific 'struct scsi_device's. They are never used. First
step in elminating 'struct scsi_device' entirely.

Spotted and initial diff from matthew@.

ok matthew@ dlg@ deraadt@ marco@ miod@


# 1.36 20-May-2010 krw

New scsi code seems to be stable. Pluck previously identified
low-hanging splbio/splx pairs that are no longer needed and see if
this reveals any hidden scsi flaws.

ok dlg@


# 1.35 29-Mar-2010 krw

Initialize various uninitialized variables. Found by jsg@ via Clang.

Feedback from miod@ and kettenis@.

ok beck@


# 1.34 23-Mar-2010 krw

Change the scsi_cmd function member of scsi_adapter from int to
void. Use XS_NO_CCB error in the scsi command (xs) to report the
NO_CCB condition. Eliminates all SUCCESSFULLY_QUEUED and COMPLETE
confusion and untangles the midlayer from the adapter a bit more.

Eyes and some fixes by miod@

There may be some compile issues on little used (i.e. I don't have
any) drivers but the change is mechanical and thus easy to remedy.

ok dlg@


Revision tags: OPENBSD_4_7_BASE
# 1.33 09-Jan-2010 krw

Zap all setting of ITSDONE in drivers that don't look at it. Nobody
else cares so it's just noise. Drivers that actually look at ITSDONE
are unchanged.

ok marco@ (for his files) dlg@ beck@


# 1.32 22-Nov-2009 krw

Bring last drivers fully into the NO_CCB world by replacing
TRY_AGAIN_LATER uses with equivalent NO_CCB. Eliminates confusion
between the two as was always intended. buf I/O's that can't be
started get pushed back onto the front of the queue and retried.
Others get sent back to originator as failures. No more epi-cycle
looping inside the SCSI midlayer hoping the problem goes away.

Various testers, no objection from miod@ as vs(4) was tested by
nick@.


# 1.31 03-Sep-2009 dlg

must call scsi_done before returning complete.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.30 16-Feb-2009 miod

Extend the scsi_adapter minphys() callback to take a struct scsi_link *
as additional argument. This will allow intermediate layers between
scsi devices such as sd and scsi host adapters to take appropriate
action if necessary.


Revision tags: OPENBSD_4_4_BASE
# 1.29 24-Jul-2008 thib

the softc sc_lock lockmgr lock is unused, so remove it.

ok krw@, dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.28 20-Oct-2007 krw

Call scsi_done() at SPLBIO. 'looks olright' says mickey.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.27 29-Dec-2006 pedro

Avoid void * arithmetic, okay deraadt@, suggestions from millert@


# 1.26 28-Nov-2006 dlg

give scsi controllers a real attach args to fill in when attaching scsibus.

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.25 03-Dec-2005 krw

The first thing done when XXX_scsi_cmd() returns TRY_AGAIN_LATER is
to set xs->error to XS_BUSY. So it is pointless and misleading to
set xs->error to XS_TIMEOUT, XS_DRIVER_STUFFUP or XS_BUSY just before
returning TRY_AGAIN_LATER.

No functional change.


# 1.24 15-Sep-2005 krw

Don't fake MODE SENSE page 4 info inside raid drivers, just let sd
fake a geometry. Page 4 info does not get used for size information.
Eliminate now unused union scsi_disk_pages.

ok marco@ mickey@ pre-lock.


Revision tags: OPENBSD_3_8_BASE
# 1.23 03-Jul-2005 krw

Fix data_length values in simulationed MODE SENSE page 4 responses so
that scsi_do_mode_sense() accepts them.

The data_length value does not include itself, and the pg_length value
in a mode page does not include itself or the page_code fields. We
were +1 on the former and -2 on the latter resulting in a data_length
value that was too small by one.

Eliminates 'mode sense page 5 not simulated' messages.

ok marco@


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.22 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


# 1.21 02-Jun-2003 mickey

kill the caluses three and four on some of my code


Revision tags: UBC_SYNC_A
# 1.20 27-Apr-2003 ho

strcpy/sprintf cleanup of sys/dev. miod@, deraadt@ says to commit.


# 1.19 09-Apr-2003 mickey

missing nl in the error msg and a return afterwards


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.18 17-Sep-2002 mickey

deal w/ the dma in a special thread to follow the busdma semantics. this fixes panics on unaligned physio; w/ help and testing from daniel@lucq.org


Revision tags: OPENBSD_3_1_BASE
# 1.17 14-Mar-2002 millert

First round of __P removal in sys


# 1.16 31-Jan-2002 mickey

scsi_done() is unsafe, rearrange locking to compensate


Revision tags: UBC_BASE
# 1.15 06-Dec-2001 mickey

branches: 1.15.2;
clear all inrterrupts separately and before enabling any.
this prevents stray interrupts and sometimes hangs,
caused by looping on stray unmapped interrupt.


# 1.14 05-Nov-2001 art

Switch everything to the new bus_dmamap_sync API.
Most work by Wilbern Cobb <vedge@csoft.org> with some fixes from me, mickey@
and drahn@.


Revision tags: OPENBSD_3_0_BASE
# 1.13 24-Sep-2001 mickey

get rid of kvtop, not that it matters that much


# 1.12 04-Jul-2001 espie

case labels without statements are not permitted by ANSI C... and gcc 3.0
warns about them.


# 1.11 18-May-2001 mickey

stupidous debug was left enabled


# 1.10 10-May-2001 mickey

branches: 1.10.2;
dmamem_unmap the memory before dmamem_freeig it.
only affects unaligned transfers (such as disklabel, fsck and dump).
we used to get away w/ this due to older pmap, uvm or both.
be more precise w/ double-buffer on command failure as well.
once at it, allow more than 1 segment for double-buffer to be allocated.
also fix a couple of endianesses and command timeouts.


Revision tags: OPENBSD_2_9_BASE
# 1.9 14-Mar-2001 mickey

branches: 1.9.2;
it seems sometimes it takes up to 35 seconds to init; from Chris Kuethe ckuethe@[[gecko.]math.]ualberta.ca


# 1.8 09-Mar-2001 mickey

missing twe_unlock for failed get_ccb() for i/o scsi cmd, which was impossible to trigger in twese case because of how maxcmds is calculated


# 1.7 19-Feb-2001 mickey

propoer dmaable memory allocations


# 1.6 07-Jan-2001 mickey

fix a few scsi_done() usages.
simplify locking a bit.
disable write cache if said so in the scsi_xfer.
a few more commands, from freebsd.


# 1.5 08-Nov-2000 mickey

oops, oops w/ no configured units


# 1.4 07-Nov-2000 mickey

estimate sc_link.openings on the number of configured units


Revision tags: OPENBSD_2_8_BASE
# 1.3 25-Sep-2000 mickey

do not do queue locking in get/put_ccb, since calling blocks
have gotten it already locked appropriately.
only try to satiate the command queue if there was a command interrupt,
it seems it's quite well-behaving this way.
dispose allocated resources if twe_attach() fails.


# 1.2 15-Sep-2000 mickey

forgot to turn off debugging


# 1.1 15-Sep-2000 mickey

3ware escalade ide raid controllers


# 1.50 26-Jan-2020 krw

Shuffle some names around to make reading the code less headache
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.


# 1.49 25-Jan-2020 krw

Drivers that implement their own *minphys() don't need to call the
system minphys(). scsi_minphys() will do that and cd/sd/st will call
scsi_minphys().

ok jmatthew@ as part of larger diff


# 1.48 23-Jan-2020 krw

Use a consistant idiom/format when declaring scsi_adapter structures
in drivers. Terse one liners, NULLs instead of 0's, explicitly specify
all members, etc.

Nuke #ifdef notyet blocks related to the scsi_adapter in aic.

No intentional functional change.

ok tedu@


# 1.47 31-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok kn@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.46 22-Jan-2016 jsg

remove a surplus splbio
ok deraadt@ krw@


Revision tags: OPENBSD_5_8_BASE
# 1.45 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.44 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.43 18-Nov-2013 deraadt

format string


# 1.42 18-Nov-2013 deraadt

simplify kthread_create(). no more stdarg
ok matthew guenther mikeb


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.41 17-Jul-2011 matthew

Backout a bunch of my SCSI commits from c2k11. At least one of these
is causing problems when trying to boot sparc64 from an isp(4).

Verified to fix the sparc64/isp(4) regression by krw@; ok deraadt@


# 1.40 08-Jul-2011 matthew

First batch of converting SCSI HBAs from setting saa_targets and
saa_luns instead of adapter_buswidth and luns in the prototype link.

ok dlg@, miod@


# 1.39 03-Apr-2011 dlg

move twe over to iopools so we can get rid of another NO_CCB user. this
also cuts the aen drain over to using an iohandler so it can be made
reliable.

this compiles, but i havent got hardware to test with. its going in as a
way to force testing. if there's a problem with the code then let me know
or back it out.

"man up" k2k11


Revision tags: OPENBSD_4_9_BASE
# 1.38 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


Revision tags: OPENBSD_4_8_BASE
# 1.37 28-Jun-2010 krw

Remove all adapter-specific 'struct scsi_device's. They are never used. First
step in elminating 'struct scsi_device' entirely.

Spotted and initial diff from matthew@.

ok matthew@ dlg@ deraadt@ marco@ miod@


# 1.36 20-May-2010 krw

New scsi code seems to be stable. Pluck previously identified
low-hanging splbio/splx pairs that are no longer needed and see if
this reveals any hidden scsi flaws.

ok dlg@


# 1.35 29-Mar-2010 krw

Initialize various uninitialized variables. Found by jsg@ via Clang.

Feedback from miod@ and kettenis@.

ok beck@


# 1.34 23-Mar-2010 krw

Change the scsi_cmd function member of scsi_adapter from int to
void. Use XS_NO_CCB error in the scsi command (xs) to report the
NO_CCB condition. Eliminates all SUCCESSFULLY_QUEUED and COMPLETE
confusion and untangles the midlayer from the adapter a bit more.

Eyes and some fixes by miod@

There may be some compile issues on little used (i.e. I don't have
any) drivers but the change is mechanical and thus easy to remedy.

ok dlg@


Revision tags: OPENBSD_4_7_BASE
# 1.33 09-Jan-2010 krw

Zap all setting of ITSDONE in drivers that don't look at it. Nobody
else cares so it's just noise. Drivers that actually look at ITSDONE
are unchanged.

ok marco@ (for his files) dlg@ beck@


# 1.32 22-Nov-2009 krw

Bring last drivers fully into the NO_CCB world by replacing
TRY_AGAIN_LATER uses with equivalent NO_CCB. Eliminates confusion
between the two as was always intended. buf I/O's that can't be
started get pushed back onto the front of the queue and retried.
Others get sent back to originator as failures. No more epi-cycle
looping inside the SCSI midlayer hoping the problem goes away.

Various testers, no objection from miod@ as vs(4) was tested by
nick@.


# 1.31 03-Sep-2009 dlg

must call scsi_done before returning complete.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.30 16-Feb-2009 miod

Extend the scsi_adapter minphys() callback to take a struct scsi_link *
as additional argument. This will allow intermediate layers between
scsi devices such as sd and scsi host adapters to take appropriate
action if necessary.


Revision tags: OPENBSD_4_4_BASE
# 1.29 24-Jul-2008 thib

the softc sc_lock lockmgr lock is unused, so remove it.

ok krw@, dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.28 20-Oct-2007 krw

Call scsi_done() at SPLBIO. 'looks olright' says mickey.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.27 29-Dec-2006 pedro

Avoid void * arithmetic, okay deraadt@, suggestions from millert@


# 1.26 28-Nov-2006 dlg

give scsi controllers a real attach args to fill in when attaching scsibus.

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.25 03-Dec-2005 krw

The first thing done when XXX_scsi_cmd() returns TRY_AGAIN_LATER is
to set xs->error to XS_BUSY. So it is pointless and misleading to
set xs->error to XS_TIMEOUT, XS_DRIVER_STUFFUP or XS_BUSY just before
returning TRY_AGAIN_LATER.

No functional change.


# 1.24 15-Sep-2005 krw

Don't fake MODE SENSE page 4 info inside raid drivers, just let sd
fake a geometry. Page 4 info does not get used for size information.
Eliminate now unused union scsi_disk_pages.

ok marco@ mickey@ pre-lock.


Revision tags: OPENBSD_3_8_BASE
# 1.23 03-Jul-2005 krw

Fix data_length values in simulationed MODE SENSE page 4 responses so
that scsi_do_mode_sense() accepts them.

The data_length value does not include itself, and the pg_length value
in a mode page does not include itself or the page_code fields. We
were +1 on the former and -2 on the latter resulting in a data_length
value that was too small by one.

Eliminates 'mode sense page 5 not simulated' messages.

ok marco@


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.22 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


# 1.21 02-Jun-2003 mickey

kill the caluses three and four on some of my code


Revision tags: UBC_SYNC_A
# 1.20 27-Apr-2003 ho

strcpy/sprintf cleanup of sys/dev. miod@, deraadt@ says to commit.


# 1.19 09-Apr-2003 mickey

missing nl in the error msg and a return afterwards


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.18 17-Sep-2002 mickey

deal w/ the dma in a special thread to follow the busdma semantics. this fixes panics on unaligned physio; w/ help and testing from daniel@lucq.org


Revision tags: OPENBSD_3_1_BASE
# 1.17 14-Mar-2002 millert

First round of __P removal in sys


# 1.16 31-Jan-2002 mickey

scsi_done() is unsafe, rearrange locking to compensate


Revision tags: UBC_BASE
# 1.15 06-Dec-2001 mickey

branches: 1.15.2;
clear all inrterrupts separately and before enabling any.
this prevents stray interrupts and sometimes hangs,
caused by looping on stray unmapped interrupt.


# 1.14 05-Nov-2001 art

Switch everything to the new bus_dmamap_sync API.
Most work by Wilbern Cobb <vedge@csoft.org> with some fixes from me, mickey@
and drahn@.


Revision tags: OPENBSD_3_0_BASE
# 1.13 24-Sep-2001 mickey

get rid of kvtop, not that it matters that much


# 1.12 04-Jul-2001 espie

case labels without statements are not permitted by ANSI C... and gcc 3.0
warns about them.


# 1.11 18-May-2001 mickey

stupidous debug was left enabled


# 1.10 10-May-2001 mickey

branches: 1.10.2;
dmamem_unmap the memory before dmamem_freeig it.
only affects unaligned transfers (such as disklabel, fsck and dump).
we used to get away w/ this due to older pmap, uvm or both.
be more precise w/ double-buffer on command failure as well.
once at it, allow more than 1 segment for double-buffer to be allocated.
also fix a couple of endianesses and command timeouts.


Revision tags: OPENBSD_2_9_BASE
# 1.9 14-Mar-2001 mickey

branches: 1.9.2;
it seems sometimes it takes up to 35 seconds to init; from Chris Kuethe ckuethe@[[gecko.]math.]ualberta.ca


# 1.8 09-Mar-2001 mickey

missing twe_unlock for failed get_ccb() for i/o scsi cmd, which was impossible to trigger in twese case because of how maxcmds is calculated


# 1.7 19-Feb-2001 mickey

propoer dmaable memory allocations


# 1.6 07-Jan-2001 mickey

fix a few scsi_done() usages.
simplify locking a bit.
disable write cache if said so in the scsi_xfer.
a few more commands, from freebsd.


# 1.5 08-Nov-2000 mickey

oops, oops w/ no configured units


# 1.4 07-Nov-2000 mickey

estimate sc_link.openings on the number of configured units


Revision tags: OPENBSD_2_8_BASE
# 1.3 25-Sep-2000 mickey

do not do queue locking in get/put_ccb, since calling blocks
have gotten it already locked appropriately.
only try to satiate the command queue if there was a command interrupt,
it seems it's quite well-behaving this way.
dispose allocated resources if twe_attach() fails.


# 1.2 15-Sep-2000 mickey

forgot to turn off debugging


# 1.1 15-Sep-2000 mickey

3ware escalade ide raid controllers


# 1.48 23-Jan-2020 krw

Use a consistant idiom/format when declaring scsi_adapter structures
in drivers. Terse one liners, NULLs instead of 0's, explicitly specify
all members, etc.

Nuke #ifdef notyet blocks related to the scsi_adapter in aic.

No intentional functional change.

ok tedu@


# 1.47 31-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok kn@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.46 22-Jan-2016 jsg

remove a surplus splbio
ok deraadt@ krw@


Revision tags: OPENBSD_5_8_BASE
# 1.45 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.44 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.43 18-Nov-2013 deraadt

format string


# 1.42 18-Nov-2013 deraadt

simplify kthread_create(). no more stdarg
ok matthew guenther mikeb


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.41 17-Jul-2011 matthew

Backout a bunch of my SCSI commits from c2k11. At least one of these
is causing problems when trying to boot sparc64 from an isp(4).

Verified to fix the sparc64/isp(4) regression by krw@; ok deraadt@


# 1.40 08-Jul-2011 matthew

First batch of converting SCSI HBAs from setting saa_targets and
saa_luns instead of adapter_buswidth and luns in the prototype link.

ok dlg@, miod@


# 1.39 03-Apr-2011 dlg

move twe over to iopools so we can get rid of another NO_CCB user. this
also cuts the aen drain over to using an iohandler so it can be made
reliable.

this compiles, but i havent got hardware to test with. its going in as a
way to force testing. if there's a problem with the code then let me know
or back it out.

"man up" k2k11


Revision tags: OPENBSD_4_9_BASE
# 1.38 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


Revision tags: OPENBSD_4_8_BASE
# 1.37 28-Jun-2010 krw

Remove all adapter-specific 'struct scsi_device's. They are never used. First
step in elminating 'struct scsi_device' entirely.

Spotted and initial diff from matthew@.

ok matthew@ dlg@ deraadt@ marco@ miod@


# 1.36 20-May-2010 krw

New scsi code seems to be stable. Pluck previously identified
low-hanging splbio/splx pairs that are no longer needed and see if
this reveals any hidden scsi flaws.

ok dlg@


# 1.35 29-Mar-2010 krw

Initialize various uninitialized variables. Found by jsg@ via Clang.

Feedback from miod@ and kettenis@.

ok beck@


# 1.34 23-Mar-2010 krw

Change the scsi_cmd function member of scsi_adapter from int to
void. Use XS_NO_CCB error in the scsi command (xs) to report the
NO_CCB condition. Eliminates all SUCCESSFULLY_QUEUED and COMPLETE
confusion and untangles the midlayer from the adapter a bit more.

Eyes and some fixes by miod@

There may be some compile issues on little used (i.e. I don't have
any) drivers but the change is mechanical and thus easy to remedy.

ok dlg@


Revision tags: OPENBSD_4_7_BASE
# 1.33 09-Jan-2010 krw

Zap all setting of ITSDONE in drivers that don't look at it. Nobody
else cares so it's just noise. Drivers that actually look at ITSDONE
are unchanged.

ok marco@ (for his files) dlg@ beck@


# 1.32 22-Nov-2009 krw

Bring last drivers fully into the NO_CCB world by replacing
TRY_AGAIN_LATER uses with equivalent NO_CCB. Eliminates confusion
between the two as was always intended. buf I/O's that can't be
started get pushed back onto the front of the queue and retried.
Others get sent back to originator as failures. No more epi-cycle
looping inside the SCSI midlayer hoping the problem goes away.

Various testers, no objection from miod@ as vs(4) was tested by
nick@.


# 1.31 03-Sep-2009 dlg

must call scsi_done before returning complete.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.30 16-Feb-2009 miod

Extend the scsi_adapter minphys() callback to take a struct scsi_link *
as additional argument. This will allow intermediate layers between
scsi devices such as sd and scsi host adapters to take appropriate
action if necessary.


Revision tags: OPENBSD_4_4_BASE
# 1.29 24-Jul-2008 thib

the softc sc_lock lockmgr lock is unused, so remove it.

ok krw@, dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.28 20-Oct-2007 krw

Call scsi_done() at SPLBIO. 'looks olright' says mickey.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.27 29-Dec-2006 pedro

Avoid void * arithmetic, okay deraadt@, suggestions from millert@


# 1.26 28-Nov-2006 dlg

give scsi controllers a real attach args to fill in when attaching scsibus.

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.25 03-Dec-2005 krw

The first thing done when XXX_scsi_cmd() returns TRY_AGAIN_LATER is
to set xs->error to XS_BUSY. So it is pointless and misleading to
set xs->error to XS_TIMEOUT, XS_DRIVER_STUFFUP or XS_BUSY just before
returning TRY_AGAIN_LATER.

No functional change.


# 1.24 15-Sep-2005 krw

Don't fake MODE SENSE page 4 info inside raid drivers, just let sd
fake a geometry. Page 4 info does not get used for size information.
Eliminate now unused union scsi_disk_pages.

ok marco@ mickey@ pre-lock.


Revision tags: OPENBSD_3_8_BASE
# 1.23 03-Jul-2005 krw

Fix data_length values in simulationed MODE SENSE page 4 responses so
that scsi_do_mode_sense() accepts them.

The data_length value does not include itself, and the pg_length value
in a mode page does not include itself or the page_code fields. We
were +1 on the former and -2 on the latter resulting in a data_length
value that was too small by one.

Eliminates 'mode sense page 5 not simulated' messages.

ok marco@


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.22 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


# 1.21 02-Jun-2003 mickey

kill the caluses three and four on some of my code


Revision tags: UBC_SYNC_A
# 1.20 27-Apr-2003 ho

strcpy/sprintf cleanup of sys/dev. miod@, deraadt@ says to commit.


# 1.19 09-Apr-2003 mickey

missing nl in the error msg and a return afterwards


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.18 17-Sep-2002 mickey

deal w/ the dma in a special thread to follow the busdma semantics. this fixes panics on unaligned physio; w/ help and testing from daniel@lucq.org


Revision tags: OPENBSD_3_1_BASE
# 1.17 14-Mar-2002 millert

First round of __P removal in sys


# 1.16 31-Jan-2002 mickey

scsi_done() is unsafe, rearrange locking to compensate


Revision tags: UBC_BASE
# 1.15 06-Dec-2001 mickey

branches: 1.15.2;
clear all inrterrupts separately and before enabling any.
this prevents stray interrupts and sometimes hangs,
caused by looping on stray unmapped interrupt.


# 1.14 05-Nov-2001 art

Switch everything to the new bus_dmamap_sync API.
Most work by Wilbern Cobb <vedge@csoft.org> with some fixes from me, mickey@
and drahn@.


Revision tags: OPENBSD_3_0_BASE
# 1.13 24-Sep-2001 mickey

get rid of kvtop, not that it matters that much


# 1.12 04-Jul-2001 espie

case labels without statements are not permitted by ANSI C... and gcc 3.0
warns about them.


# 1.11 18-May-2001 mickey

stupidous debug was left enabled


# 1.10 10-May-2001 mickey

branches: 1.10.2;
dmamem_unmap the memory before dmamem_freeig it.
only affects unaligned transfers (such as disklabel, fsck and dump).
we used to get away w/ this due to older pmap, uvm or both.
be more precise w/ double-buffer on command failure as well.
once at it, allow more than 1 segment for double-buffer to be allocated.
also fix a couple of endianesses and command timeouts.


Revision tags: OPENBSD_2_9_BASE
# 1.9 14-Mar-2001 mickey

branches: 1.9.2;
it seems sometimes it takes up to 35 seconds to init; from Chris Kuethe ckuethe@[[gecko.]math.]ualberta.ca


# 1.8 09-Mar-2001 mickey

missing twe_unlock for failed get_ccb() for i/o scsi cmd, which was impossible to trigger in twese case because of how maxcmds is calculated


# 1.7 19-Feb-2001 mickey

propoer dmaable memory allocations


# 1.6 07-Jan-2001 mickey

fix a few scsi_done() usages.
simplify locking a bit.
disable write cache if said so in the scsi_xfer.
a few more commands, from freebsd.


# 1.5 08-Nov-2000 mickey

oops, oops w/ no configured units


# 1.4 07-Nov-2000 mickey

estimate sc_link.openings on the number of configured units


Revision tags: OPENBSD_2_8_BASE
# 1.3 25-Sep-2000 mickey

do not do queue locking in get/put_ccb, since calling blocks
have gotten it already locked appropriately.
only try to satiate the command queue if there was a command interrupt,
it seems it's quite well-behaving this way.
dispose allocated resources if twe_attach() fails.


# 1.2 15-Sep-2000 mickey

forgot to turn off debugging


# 1.1 15-Sep-2000 mickey

3ware escalade ide raid controllers


# 1.47 31-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok kn@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.46 22-Jan-2016 jsg

remove a surplus splbio
ok deraadt@ krw@


Revision tags: OPENBSD_5_8_BASE
# 1.45 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.44 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.43 18-Nov-2013 deraadt

format string


# 1.42 18-Nov-2013 deraadt

simplify kthread_create(). no more stdarg
ok matthew guenther mikeb


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.41 17-Jul-2011 matthew

Backout a bunch of my SCSI commits from c2k11. At least one of these
is causing problems when trying to boot sparc64 from an isp(4).

Verified to fix the sparc64/isp(4) regression by krw@; ok deraadt@


# 1.40 08-Jul-2011 matthew

First batch of converting SCSI HBAs from setting saa_targets and
saa_luns instead of adapter_buswidth and luns in the prototype link.

ok dlg@, miod@


# 1.39 03-Apr-2011 dlg

move twe over to iopools so we can get rid of another NO_CCB user. this
also cuts the aen drain over to using an iohandler so it can be made
reliable.

this compiles, but i havent got hardware to test with. its going in as a
way to force testing. if there's a problem with the code then let me know
or back it out.

"man up" k2k11


Revision tags: OPENBSD_4_9_BASE
# 1.38 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


Revision tags: OPENBSD_4_8_BASE
# 1.37 28-Jun-2010 krw

Remove all adapter-specific 'struct scsi_device's. They are never used. First
step in elminating 'struct scsi_device' entirely.

Spotted and initial diff from matthew@.

ok matthew@ dlg@ deraadt@ marco@ miod@


# 1.36 20-May-2010 krw

New scsi code seems to be stable. Pluck previously identified
low-hanging splbio/splx pairs that are no longer needed and see if
this reveals any hidden scsi flaws.

ok dlg@


# 1.35 29-Mar-2010 krw

Initialize various uninitialized variables. Found by jsg@ via Clang.

Feedback from miod@ and kettenis@.

ok beck@


# 1.34 23-Mar-2010 krw

Change the scsi_cmd function member of scsi_adapter from int to
void. Use XS_NO_CCB error in the scsi command (xs) to report the
NO_CCB condition. Eliminates all SUCCESSFULLY_QUEUED and COMPLETE
confusion and untangles the midlayer from the adapter a bit more.

Eyes and some fixes by miod@

There may be some compile issues on little used (i.e. I don't have
any) drivers but the change is mechanical and thus easy to remedy.

ok dlg@


Revision tags: OPENBSD_4_7_BASE
# 1.33 09-Jan-2010 krw

Zap all setting of ITSDONE in drivers that don't look at it. Nobody
else cares so it's just noise. Drivers that actually look at ITSDONE
are unchanged.

ok marco@ (for his files) dlg@ beck@


# 1.32 22-Nov-2009 krw

Bring last drivers fully into the NO_CCB world by replacing
TRY_AGAIN_LATER uses with equivalent NO_CCB. Eliminates confusion
between the two as was always intended. buf I/O's that can't be
started get pushed back onto the front of the queue and retried.
Others get sent back to originator as failures. No more epi-cycle
looping inside the SCSI midlayer hoping the problem goes away.

Various testers, no objection from miod@ as vs(4) was tested by
nick@.


# 1.31 03-Sep-2009 dlg

must call scsi_done before returning complete.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.30 16-Feb-2009 miod

Extend the scsi_adapter minphys() callback to take a struct scsi_link *
as additional argument. This will allow intermediate layers between
scsi devices such as sd and scsi host adapters to take appropriate
action if necessary.


Revision tags: OPENBSD_4_4_BASE
# 1.29 24-Jul-2008 thib

the softc sc_lock lockmgr lock is unused, so remove it.

ok krw@, dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.28 20-Oct-2007 krw

Call scsi_done() at SPLBIO. 'looks olright' says mickey.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.27 29-Dec-2006 pedro

Avoid void * arithmetic, okay deraadt@, suggestions from millert@


# 1.26 28-Nov-2006 dlg

give scsi controllers a real attach args to fill in when attaching scsibus.

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.25 03-Dec-2005 krw

The first thing done when XXX_scsi_cmd() returns TRY_AGAIN_LATER is
to set xs->error to XS_BUSY. So it is pointless and misleading to
set xs->error to XS_TIMEOUT, XS_DRIVER_STUFFUP or XS_BUSY just before
returning TRY_AGAIN_LATER.

No functional change.


# 1.24 15-Sep-2005 krw

Don't fake MODE SENSE page 4 info inside raid drivers, just let sd
fake a geometry. Page 4 info does not get used for size information.
Eliminate now unused union scsi_disk_pages.

ok marco@ mickey@ pre-lock.


Revision tags: OPENBSD_3_8_BASE
# 1.23 03-Jul-2005 krw

Fix data_length values in simulationed MODE SENSE page 4 responses so
that scsi_do_mode_sense() accepts them.

The data_length value does not include itself, and the pg_length value
in a mode page does not include itself or the page_code fields. We
were +1 on the former and -2 on the latter resulting in a data_length
value that was too small by one.

Eliminates 'mode sense page 5 not simulated' messages.

ok marco@


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.22 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


# 1.21 02-Jun-2003 mickey

kill the caluses three and four on some of my code


Revision tags: UBC_SYNC_A
# 1.20 27-Apr-2003 ho

strcpy/sprintf cleanup of sys/dev. miod@, deraadt@ says to commit.


# 1.19 09-Apr-2003 mickey

missing nl in the error msg and a return afterwards


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.18 17-Sep-2002 mickey

deal w/ the dma in a special thread to follow the busdma semantics. this fixes panics on unaligned physio; w/ help and testing from daniel@lucq.org


Revision tags: OPENBSD_3_1_BASE
# 1.17 14-Mar-2002 millert

First round of __P removal in sys


# 1.16 31-Jan-2002 mickey

scsi_done() is unsafe, rearrange locking to compensate


Revision tags: UBC_BASE
# 1.15 06-Dec-2001 mickey

branches: 1.15.2;
clear all inrterrupts separately and before enabling any.
this prevents stray interrupts and sometimes hangs,
caused by looping on stray unmapped interrupt.


# 1.14 05-Nov-2001 art

Switch everything to the new bus_dmamap_sync API.
Most work by Wilbern Cobb <vedge@csoft.org> with some fixes from me, mickey@
and drahn@.


Revision tags: OPENBSD_3_0_BASE
# 1.13 24-Sep-2001 mickey

get rid of kvtop, not that it matters that much


# 1.12 04-Jul-2001 espie

case labels without statements are not permitted by ANSI C... and gcc 3.0
warns about them.


# 1.11 18-May-2001 mickey

stupidous debug was left enabled


# 1.10 10-May-2001 mickey

branches: 1.10.2;
dmamem_unmap the memory before dmamem_freeig it.
only affects unaligned transfers (such as disklabel, fsck and dump).
we used to get away w/ this due to older pmap, uvm or both.
be more precise w/ double-buffer on command failure as well.
once at it, allow more than 1 segment for double-buffer to be allocated.
also fix a couple of endianesses and command timeouts.


Revision tags: OPENBSD_2_9_BASE
# 1.9 14-Mar-2001 mickey

branches: 1.9.2;
it seems sometimes it takes up to 35 seconds to init; from Chris Kuethe ckuethe@[[gecko.]math.]ualberta.ca


# 1.8 09-Mar-2001 mickey

missing twe_unlock for failed get_ccb() for i/o scsi cmd, which was impossible to trigger in twese case because of how maxcmds is calculated


# 1.7 19-Feb-2001 mickey

propoer dmaable memory allocations


# 1.6 07-Jan-2001 mickey

fix a few scsi_done() usages.
simplify locking a bit.
disable write cache if said so in the scsi_xfer.
a few more commands, from freebsd.


# 1.5 08-Nov-2000 mickey

oops, oops w/ no configured units


# 1.4 07-Nov-2000 mickey

estimate sc_link.openings on the number of configured units


Revision tags: OPENBSD_2_8_BASE
# 1.3 25-Sep-2000 mickey

do not do queue locking in get/put_ccb, since calling blocks
have gotten it already locked appropriately.
only try to satiate the command queue if there was a command interrupt,
it seems it's quite well-behaving this way.
dispose allocated resources if twe_attach() fails.


# 1.2 15-Sep-2000 mickey

forgot to turn off debugging


# 1.1 15-Sep-2000 mickey

3ware escalade ide raid controllers


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.46 22-Jan-2016 jsg

remove a surplus splbio
ok deraadt@ krw@


Revision tags: OPENBSD_5_8_BASE
# 1.45 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.44 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.43 18-Nov-2013 deraadt

format string


# 1.42 18-Nov-2013 deraadt

simplify kthread_create(). no more stdarg
ok matthew guenther mikeb


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.41 17-Jul-2011 matthew

Backout a bunch of my SCSI commits from c2k11. At least one of these
is causing problems when trying to boot sparc64 from an isp(4).

Verified to fix the sparc64/isp(4) regression by krw@; ok deraadt@


# 1.40 08-Jul-2011 matthew

First batch of converting SCSI HBAs from setting saa_targets and
saa_luns instead of adapter_buswidth and luns in the prototype link.

ok dlg@, miod@


# 1.39 03-Apr-2011 dlg

move twe over to iopools so we can get rid of another NO_CCB user. this
also cuts the aen drain over to using an iohandler so it can be made
reliable.

this compiles, but i havent got hardware to test with. its going in as a
way to force testing. if there's a problem with the code then let me know
or back it out.

"man up" k2k11


Revision tags: OPENBSD_4_9_BASE
# 1.38 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


Revision tags: OPENBSD_4_8_BASE
# 1.37 28-Jun-2010 krw

Remove all adapter-specific 'struct scsi_device's. They are never used. First
step in elminating 'struct scsi_device' entirely.

Spotted and initial diff from matthew@.

ok matthew@ dlg@ deraadt@ marco@ miod@


# 1.36 20-May-2010 krw

New scsi code seems to be stable. Pluck previously identified
low-hanging splbio/splx pairs that are no longer needed and see if
this reveals any hidden scsi flaws.

ok dlg@


# 1.35 29-Mar-2010 krw

Initialize various uninitialized variables. Found by jsg@ via Clang.

Feedback from miod@ and kettenis@.

ok beck@


# 1.34 23-Mar-2010 krw

Change the scsi_cmd function member of scsi_adapter from int to
void. Use XS_NO_CCB error in the scsi command (xs) to report the
NO_CCB condition. Eliminates all SUCCESSFULLY_QUEUED and COMPLETE
confusion and untangles the midlayer from the adapter a bit more.

Eyes and some fixes by miod@

There may be some compile issues on little used (i.e. I don't have
any) drivers but the change is mechanical and thus easy to remedy.

ok dlg@


Revision tags: OPENBSD_4_7_BASE
# 1.33 09-Jan-2010 krw

Zap all setting of ITSDONE in drivers that don't look at it. Nobody
else cares so it's just noise. Drivers that actually look at ITSDONE
are unchanged.

ok marco@ (for his files) dlg@ beck@


# 1.32 22-Nov-2009 krw

Bring last drivers fully into the NO_CCB world by replacing
TRY_AGAIN_LATER uses with equivalent NO_CCB. Eliminates confusion
between the two as was always intended. buf I/O's that can't be
started get pushed back onto the front of the queue and retried.
Others get sent back to originator as failures. No more epi-cycle
looping inside the SCSI midlayer hoping the problem goes away.

Various testers, no objection from miod@ as vs(4) was tested by
nick@.


# 1.31 03-Sep-2009 dlg

must call scsi_done before returning complete.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.30 16-Feb-2009 miod

Extend the scsi_adapter minphys() callback to take a struct scsi_link *
as additional argument. This will allow intermediate layers between
scsi devices such as sd and scsi host adapters to take appropriate
action if necessary.


Revision tags: OPENBSD_4_4_BASE
# 1.29 24-Jul-2008 thib

the softc sc_lock lockmgr lock is unused, so remove it.

ok krw@, dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.28 20-Oct-2007 krw

Call scsi_done() at SPLBIO. 'looks olright' says mickey.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.27 29-Dec-2006 pedro

Avoid void * arithmetic, okay deraadt@, suggestions from millert@


# 1.26 28-Nov-2006 dlg

give scsi controllers a real attach args to fill in when attaching scsibus.

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.25 03-Dec-2005 krw

The first thing done when XXX_scsi_cmd() returns TRY_AGAIN_LATER is
to set xs->error to XS_BUSY. So it is pointless and misleading to
set xs->error to XS_TIMEOUT, XS_DRIVER_STUFFUP or XS_BUSY just before
returning TRY_AGAIN_LATER.

No functional change.


# 1.24 15-Sep-2005 krw

Don't fake MODE SENSE page 4 info inside raid drivers, just let sd
fake a geometry. Page 4 info does not get used for size information.
Eliminate now unused union scsi_disk_pages.

ok marco@ mickey@ pre-lock.


Revision tags: OPENBSD_3_8_BASE
# 1.23 03-Jul-2005 krw

Fix data_length values in simulationed MODE SENSE page 4 responses so
that scsi_do_mode_sense() accepts them.

The data_length value does not include itself, and the pg_length value
in a mode page does not include itself or the page_code fields. We
were +1 on the former and -2 on the latter resulting in a data_length
value that was too small by one.

Eliminates 'mode sense page 5 not simulated' messages.

ok marco@


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.22 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


# 1.21 02-Jun-2003 mickey

kill the caluses three and four on some of my code


Revision tags: UBC_SYNC_A
# 1.20 27-Apr-2003 ho

strcpy/sprintf cleanup of sys/dev. miod@, deraadt@ says to commit.


# 1.19 09-Apr-2003 mickey

missing nl in the error msg and a return afterwards


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.18 17-Sep-2002 mickey

deal w/ the dma in a special thread to follow the busdma semantics. this fixes panics on unaligned physio; w/ help and testing from daniel@lucq.org


Revision tags: OPENBSD_3_1_BASE
# 1.17 14-Mar-2002 millert

First round of __P removal in sys


# 1.16 31-Jan-2002 mickey

scsi_done() is unsafe, rearrange locking to compensate


Revision tags: UBC_BASE
# 1.15 06-Dec-2001 mickey

branches: 1.15.2;
clear all inrterrupts separately and before enabling any.
this prevents stray interrupts and sometimes hangs,
caused by looping on stray unmapped interrupt.


# 1.14 05-Nov-2001 art

Switch everything to the new bus_dmamap_sync API.
Most work by Wilbern Cobb <vedge@csoft.org> with some fixes from me, mickey@
and drahn@.


Revision tags: OPENBSD_3_0_BASE
# 1.13 24-Sep-2001 mickey

get rid of kvtop, not that it matters that much


# 1.12 04-Jul-2001 espie

case labels without statements are not permitted by ANSI C... and gcc 3.0
warns about them.


# 1.11 18-May-2001 mickey

stupidous debug was left enabled


# 1.10 10-May-2001 mickey

branches: 1.10.2;
dmamem_unmap the memory before dmamem_freeig it.
only affects unaligned transfers (such as disklabel, fsck and dump).
we used to get away w/ this due to older pmap, uvm or both.
be more precise w/ double-buffer on command failure as well.
once at it, allow more than 1 segment for double-buffer to be allocated.
also fix a couple of endianesses and command timeouts.


Revision tags: OPENBSD_2_9_BASE
# 1.9 14-Mar-2001 mickey

branches: 1.9.2;
it seems sometimes it takes up to 35 seconds to init; from Chris Kuethe ckuethe@[[gecko.]math.]ualberta.ca


# 1.8 09-Mar-2001 mickey

missing twe_unlock for failed get_ccb() for i/o scsi cmd, which was impossible to trigger in twese case because of how maxcmds is calculated


# 1.7 19-Feb-2001 mickey

propoer dmaable memory allocations


# 1.6 07-Jan-2001 mickey

fix a few scsi_done() usages.
simplify locking a bit.
disable write cache if said so in the scsi_xfer.
a few more commands, from freebsd.


# 1.5 08-Nov-2000 mickey

oops, oops w/ no configured units


# 1.4 07-Nov-2000 mickey

estimate sc_link.openings on the number of configured units


Revision tags: OPENBSD_2_8_BASE
# 1.3 25-Sep-2000 mickey

do not do queue locking in get/put_ccb, since calling blocks
have gotten it already locked appropriately.
only try to satiate the command queue if there was a command interrupt,
it seems it's quite well-behaving this way.
dispose allocated resources if twe_attach() fails.


# 1.2 15-Sep-2000 mickey

forgot to turn off debugging


# 1.1 15-Sep-2000 mickey

3ware escalade ide raid controllers