History log of /openbsd-current/sys/dev/ic/mfi.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.191 28-Nov-2023 jsg

correct spelling of FALLTHROUGH


Revision tags: OPENBSD_7_4_BASE
# 1.190 06-Jul-2023 visa

Use mtx_init() to initialize stack-based mutexes

mtx_init() ensures the mutex' lock_object has static storage duration.
This makes it safe to re-enable WITNESS with stack-based mutexes.

OK bluhm@ miod@


# 1.189 25-May-2023 kurt

Disable witness for mutexes created on the stack which allows
the ddb command 'show witness' to succeed without panicking.
Leaving witness enabled on these mutexes saves a pointer to
struct lock_type on the stack which gets clobbered resulting
in a panic in witness_ddb_display_descendants().

okay miod@


Revision tags: OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.188 16-Apr-2022 naddy

constify SCSI adapter entry points

ok krw@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.187 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.186 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.185 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.184 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.183 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.182 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.181 13-Jul-2020 krw

Where we have a pointer (sc) to the relevant adapter_softc, use
&sc->sc_dev to get a device pointer rather than using the void *
whence we obtained 'sc'.


# 1.180 13-Jul-2020 krw

Remove some pointless casting of void * when assigning one
(scsi_link.adapter_softc) to a pointer of a particular softc type.


# 1.179 27-Jun-2020 krw

Nuke trailing whitespace.


# 1.178 27-Jun-2020 krw

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


# 1.177 24-Jun-2020 krw

Use SDEV_NO_ADAPTER_TARGET instead of -1 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.176 21-Mar-2020 krw

Simplify some goto'ing that jumps a single line or
does nothing at all.

The first one spotted as CID 1452976.

Reads good to millert@

ok mpi@


# 1.175 13-Feb-2020 krw

Nuke *_minphys() functions that either simply apply MAXPHYS or do
nothing at all. MAXPHYS will be applied in minphys() and nothing at
all, well, doesn't do anything.

Also remove any '#define <blah> MAXPHYS' statements used solely to
disguise MAXPHYS in said functions.


# 1.174 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.173 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.172 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.171 31-Dec-2019 mpi

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

ok kn@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.170 05-Mar-2019 jmatthew

apply background init progress fix from r1.59 of mfii.c
(reverting most of r1.60 of mfi.c, oddly enough)

ok dlg@
tested on a SAS2008 (perc h310)


Revision tags: OPENBSD_6_4_BASE
# 1.169 14-Aug-2018 jmatthew

return ENOTTY rather than EINVAL to indicate an ioctl hasn't been handled

ok dlg@ deraadt@ kettenis@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.168 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.167 02-Feb-2017 dlg

copy the mbox into the dcmd struct, not the pointer to the mbox.

makes bioctl work on mfi(4) again.

while here memset a few mboxes before using them.

bioctl breakage reported by jason george


# 1.166 23-Jan-2017 dlg

represent the mbox layout with union instead of an array of bytes.

memcpying uint16_ts into inconsistently addressed offsets is hard
to read, and this makes future work easier to implement.

tested on mfi(4) and mfii(4)


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.165 09-Sep-2015 deraadt

sizes for free(); ok sthen


Revision tags: OPENBSD_5_8_BASE
# 1.164 29-May-2015 uebayasi

Initial addition of ``Patrol Read'' support in bio(4), biocto(8), and
mfi(4). Based on FreeBSD, but done without mfiutil(8).

OK deraadt@


# 1.163 18-May-2015 mikeb

Prevent splassert from firing during sd_flush which runs "cold"

While mfi(4) should pass SCSI transfer flags (e.g. SCSI_POLL and
SCSI_NOSLEEP) down to the management function, make it at least
use "cold" consistently for now.

ok dlg


# 1.162 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.161 08-Mar-2015 dlg

properly set sgl related flags on skinny controllers. this fixes
io against physical disks on my dell perc h310s. logical disks still
work fine.

ok deraadt@ yasuoka@


# 1.160 08-Feb-2015 yasuoka

Fix mfi ioctl to set drive state properly.
diff from Tsubai Masanari

test dlg jmatthew
ok dlg


# 1.159 09-Jan-2015 yasuoka

Add support DIOC{G,S}CACHE to mfi(4). Cache of disk on mfi(4) will
be enabled by default. Also if the controller doesn't have any RAM,
the cache on the physical disk will be enabled.

discuss with jsg tsubai
ok dlg


# 1.158 19-Dec-2014 deraadt

another handful of bcopy -> memcpy because there is no overlap


# 1.157 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.156 09-Sep-2014 dlg

mark the interrupt handler mpsafe, and give up biglock in the scsi cmd
submission paths. take biglock again when calling back into the scsi
stack.

tested on a variety of cards here, including the skinny mfis on the
firewall next to mpsafe myx.


# 1.155 15-Aug-2014 yasuoka

Create a function which loads sgd in the mfi_iop_ops struct so that skinny
adapters can use "IEEE sgl".

tested dlg yasuoka
ok dlg jsg


Revision tags: OPENBSD_5_6_BASE
# 1.154 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.153 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.152 04-May-2014 sf

format string fixes for bus_addr_t and bus_size_t

bus_addr_t and bus_size_t are u_long everywhere

ok kettenis@


Revision tags: OPENBSD_5_5_BASE
# 1.151 20-Feb-2014 kettenis

revert previous commit; didn't intend to commit those bits


# 1.150 20-Feb-2014 kettenis

Avoid printing the "nvram corrupt" message for onboard 2200s found on Sun
hardware.

ok dlg@, jmatthew@


# 1.149 04-Dec-2013 dlg

mfi_refresh_sensors calls mfi_ioctl_vol which calls mfi_bio_getitall, which
replaces pointers in the softc and all sorts of fun stuff. this protects
the call to bio_getitall with the sc_lock the ioctl path uses, so we dont
get panics like those reported on bugs@ recently.

ok deraadt@


# 1.148 23-Oct-2013 kettenis

Add support for displaying the cache write policy of RAID volumes to bioctl(8)
and make mfi(4) pass up the necessary information. Adding support for other
RAID controllers is left as an excercise to the reader.

ok deraadt@


# 1.147 09-Oct-2013 jmatthew

Include the 'state of health' field in the bbu ok sensor value.
The dell perc 6/i sets this to zero (meaning bad) when it
decides the battery doesn't have enough capacity for it to
allow write back mode, but doesn't set any of the other flags
to tell us why.

ok dlg@, tested by sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.146 18-May-2013 jmc

enw->new in comment;
spotted by krw, missed by jsg, and forwarded From: Alexey Suslikov


# 1.145 08-May-2013 jsg

fix some leaks in error paths
ok fgsch@ krw@ kettenis@


# 1.144 03-May-2013 dlg

break out the battery status into excruciating detail. makes it harder for
$VENDOR to complain about a lack of diagnostic material from their crappy
mgmt tools if you're not running an operating system they support.


# 1.143 02-May-2013 dlg

always attach the battery sensor if the adapter lets us query it.
newly replaced batteries dont show up immediately.


# 1.142 01-May-2013 dlg

provide a sensor for the battery backup unit (bbu) on mfi boards that
support it.

now i can tell (a bit better) why io might be slow on some of my boxes.


# 1.141 01-May-2013 dlg

dont need to walk alldevs during sensor creation looking for the logical
disk scsibus when we record that in mfi_attach.

also happens to get rid of a logic error that let it come out of the loop
on alldevs with a reference to something that wasnt the logical disk
scsibus and use that.


# 1.140 30-Apr-2013 dlg

use MR_DCMD consistently. some MD_DCMD was in there somehow.


# 1.139 07-Apr-2013 dlg

david imhoff points out that the error handling in mfi_init_ccb gets the
index to which ccb to free wrong.

this takes the logic from mpi/mpii/mfii which pulls the ready ccbs off
the free list rather than rely on the current index from the for loop
that we failed inside of.

thanks to david for finding this out.


Revision tags: OPENBSD_5_3_BASE
# 1.138 12-Sep-2012 haesbaert

Make sure we don't sleep on autoconf.

ok mikeb


# 1.137 17-Aug-2012 dlg

add support for "physical devices" on skinny controllers.

these controllers let you specify disks that should be accessed directly
rather than be part of logical volumes. apparently you can plug in things
like tape drives too.

anyway, physical devices are exposed via a separate scsibus attached to
mfi.

ok mikeb@


# 1.136 16-Aug-2012 dlg

fix mfi_poll by having it do delays between loops, and breaking on
timeouts. how embarrassment.

implement mfi_exec for doing sync executions of commands in process
contexts and cut mfi_mgmt over to it.


# 1.135 16-Aug-2012 dlg

rework mfi_poll so it will do all the completions on a ccb including
calling the done handler.

this makes it consistently complete scsi io with all the proper error
checking.


# 1.134 16-Aug-2012 dlg

stop passing mfi_softc around as a member of the ccb, consistently give it
as the first argument to functions. like mfii.


# 1.133 16-Aug-2012 dlg

scrub ccbs when we're about to use them, not when we put them back
on the free list. ccbs can be reused, so we dont want old state screwing up
new commands.


# 1.132 16-Aug-2012 dlg

move the dma syncs for the ccb data into ccb_done, so we can do it once
rather than put the code everywhere.


# 1.131 16-Aug-2012 dlg

fix up the dma sync for the command frame in mfi_done.


# 1.130 14-Aug-2012 dlg

use scsi_get_link to find out the name of a child device for bioctl rather
than snoop scsi commands and copy it in an io path.

no functional change, but the code has one less XXX now.


# 1.129 14-Aug-2012 dlg

expose the max number of logical volumes the hardware supports as the width
of its scsibus. only advertise 1 lun on logical volumes instead of letting
the midlayer fix it up to 8.

give every target on the bus max_cmds openings. iopools means they will
properly share access to them.

this in particular is useful on skinny controllers which only advertise 31
command slots. if you have 16 volumes, theyll only get 1 opening each with
the old maths. this way round the ones that are busy will share the slots.

tested on a perc5 with two volumes and hard workloads.


# 1.128 14-Aug-2012 dlg

print the boards name (eg, perc 5/i) according to the firmware like mfii.

ok deraadt@


# 1.127 14-Aug-2012 dlg

move knowledge of the location of the inbound doorbell out of code in
transition_firmware into a member of the iop structures.

ok mikeb@ haesbaert@


# 1.126 13-Aug-2012 dlg

get rid of the last foo_lo and foo_hi bits i could find in the hardware
structures and use htole64 instead of htole32(addr >> 32); htole32(addr);

gets rid of "handy" stack variables to get the dva to 64bits.

sprinkle some more byte swaps for things that should have it.

tested on a perc5 (xscale)


# 1.125 13-Aug-2012 dlg

do appropriate bus_dmamapy_syncs around the pcq/completion ring.

tested on a perc5 (xscale)


# 1.124 13-Aug-2012 dlg

replace uint32_ts for hi and lo addresses in the mfi_init_ hardware
descriptors with single uint64_ts. theyre not some weird middle
endian thing. this makes the code more readable.

add some missing htole32s to the code while here.

tested on a perc5 (xscale).


# 1.123 11-Aug-2012 dlg

the producer/consumer values are used by the device, which is little
endian. do appropriate byteswapping for when the host cpu uses them.

tested on a perc5 (xscale) in an amd64.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.122 12-Jan-2012 dlg

add support for skinny variants.

from Alexey Suslikov
reviewed by marco


Revision tags: OPENBSD_5_0_BASE
# 1.121 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.120 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.119 09-Apr-2011 marco

add all 64 bit dma plumbing but stick with 32 for now by default.

ok deraadt


# 1.118 09-Apr-2011 marco

make sure the upper 32 bits are always written to instead of assuming it
is 0.

ok deraadt.


# 1.117 08-Apr-2011 marco

kill some stray spaces


# 1.116 08-Apr-2011 marco

rename wiat channel to something less than 8 chars.

prompted by deraadt


# 1.115 08-Apr-2011 marco

use dma_alloc for transient management commands.

prodded and ok deraadt


Revision tags: OPENBSD_4_9_BASE
# 1.114 30-Dec-2010 dlg

cut mfi over to using iopools.

this gets rid of NO_CCB, provides better scheduling of io between busy
logical volumes on the same controller, and makes the ioctl and sensor
paths more reliable.

this is the least intrusive version of this change i could come up with. it
only took 4 or 5 goes...

ok marco@
deraadt@ says this is a good time for this change.


# 1.113 24-Sep-2010 dlg

no use setting cmd in mfi_ioctl_setstate if you never use it.


# 1.112 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


# 1.111 29-Aug-2010 dlg

the scsi completion code thinks that if you dont get MFI_STAT_OK
back from the chip on a command then the command completely failed.
MFI_STAT_SCSI_DONE_WITH_ERROR really means the command completed
fine, but there's some sense data too. this tweaks the handling to
be more appropriate, as per the linux and solaris drivers.

timed out waiting for beck@
putting this in cos its obviously more correct than the current code.


Revision tags: OPENBSD_4_8_BASE
# 1.110 22-Jul-2010 matthew

SCSI HBA drivers are supposed to get their SCSI CDBs from xs->cmd, not
xs->cmdstore.

ok krw@ a while back (contingent upon testing), and deraadt@ says this
has been in snapshots for weeks now.


# 1.109 01-Jul-2010 matthew

Change scsibus(4)'s scsi_link array to an SLIST to save memory on
sparsely populated buses.

ok dlg@, krw@


# 1.108 30-Jun-2010 mk

Use SLIST for the ccb free list.

ok krw, discontent grunts from marco.


# 1.107 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.106 15-Jun-2010 dlg

dont pass the dev_t from the scsi device drivers into the midlayer for
ioctl requests, and dont pass the proc pointers around for any ioctl
requests in scsi land at all. neither were used, so trim the fat.

ok krw@ marco@


# 1.105 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.104 16-May-2010 nicm

Use a temporary variable for now to sidestep -Wbounded checking when
copying vendor[8]/product[16]/revision[4] out of struct scsi_inquiry_data
together with one memcopy.

ok krw


# 1.103 22-Apr-2010 oga

use BUS_DMA_ZERO on alloc instead of bzeroing after.

ok dlg@, marco@


# 1.102 10-Apr-2010 marco

grrr var names in protos


# 1.101 10-Apr-2010 marco

sprinkle some bus_dmamap_sync around frame access.
prompted by oga


# 1.100 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.99 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.98 04-Jan-2010 dlg

rename ccb_xs to ccb_cookie and change its type from a scsi_xfer * to a
void *. this lets us pass things other than scsi_xfers to ccb completion
handlers.


# 1.97 04-Jan-2010 dlg

protect the ccb free queue with a mutex rather than splbio


# 1.96 03-Jan-2010 chl

change M_WAITOK --> M_WAITOK|M_CANFAIL

with input from marco@

ok marco@ krw@

this was ok looooooooong time ago but lost in my mailbox


Revision tags: OPENBSD_4_6_BASE
# 1.95 30-Apr-2009 marco

Add READ(16) & WRITE(16) commands.
ok krw


# 1.94 29-Apr-2009 marco

MFI_D_IOCTL should be commented out. No binary change.


# 1.93 04-Apr-2009 dlg

scrub more fields in the ccb when returning them to the free list after
theyve been used, in particular the mfi header flags which has a bit
that specifies if a command should be completed via the interrupt path.

if we use a ccb during boot we set that bit, but it isnt necessarily
cleared by things that use it later on. this means a ccb we expected to
complete via an interrupt never actually generates an interrupt or appears
in the reply queue. this obviously stalls the io.


# 1.92 29-Mar-2009 marco

spello


# 1.91 29-Mar-2009 dlg

when we steal the SYNC CACHE command in mfi_scsi_cmd we still have to
mark the xs as done and call scsi_done for it rather than just returning
COMPLETE.


# 1.90 29-Mar-2009 dlg

fix a small race in mfi_mgmt between the checking of a ccbs completion and
the sleep waiting for the completion. it is possible to get the interrupt
completing the command just before the tsleep, which will never get a
wakeup because the interrupt with the wakeup has already happened.


Revision tags: OPENBSD_4_5_BASE
# 1.89 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.


# 1.88 28-Jan-2009 marco

Add support for next generation megaraid sas raid controllers.
From Jim Giannoules <gortag@gmail.com>


# 1.87 31-Oct-2008 marco

Generalize function to obtain all details to do bio stuff. This is in
preparation to start showing unsused disks which will require all this
information to do the math.

While at it fix a size of hotspare volume bug.


# 1.86 30-Oct-2008 marco

Fix bug that when there are no volumes but there are hot spares it would
no show the hotspares.


# 1.85 28-Oct-2008 marco

Fix output when reporting on multivolume disk groups.

Reported by mitja@muzenic.net


# 1.84 27-Oct-2008 marco

Move some include stuff around


# 1.83 26-Oct-2008 marco

Space


# 1.82 23-Oct-2008 marco

Fix PR5645
ok dlg
tested beck and others


# 1.81 25-Sep-2008 krw

Initialize 'ssc' to NULL since we test it later. Shouldn't ever be
NULL at the point of test unless the device list is confused, but
be consistantly paranoid if we're going to be paranoid.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.80 16-Feb-2008 krw

Return NO_CCB and not TRY_AGAIN_LATER when running out of ccb's.
Eliminates 'not queued' errors reported on the mailing lists.

Tested by Michael (belenus at bsdmail dot de).

ok marco@


# 1.79 11-Feb-2008 dlg

add support for the mfi controllers with the ppc iops, aka, LSI SAS1078 or
Dell PERC6.

committed off a machine booting and rooting off a perc6. tested on a perc5
by marco@
ok marco@


# 1.78 26-Jan-2008 brad

Set the return value instead of returning right away so that the DMA
memory is actually synched.

ok dlg@


# 1.77 26-Jan-2008 dlg

sync dma mem back to the cpu on poll failure.

from mickey via pr5714


# 1.76 26-Jan-2008 dlg

despatch -> dispatch

disparate spellink fix from mickey


# 1.75 05-Nov-2007 krw

More scsi_done() at SPLBIO.


# 1.74 27-Sep-2007 chl

M_ZERO changes

ok dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.73 24-Jun-2007 dlg

rework sensor tasks to use the kernels generic workq rather than a special
kernel thread of its own. the api has changed (which will be fixed in the
manpage shortly) so all the users of sensor tasks that i can find have
been fixed too.

noone tested, so its going in to force people to run with it.
"put it in" deraadt@


# 1.72 29-May-2007 todd

sprinkle some SMALL_KERNEL to permit bio/softraid to run on boot media
ok marco@ then suggested deraadt@


# 1.71 22-Mar-2007 deraadt

split userland & kernel struct sensor/sensordev so that the addition
of new fields in the future is less disruptive. This is done similar
to how struct proc is handled for ps(1). ok jmc (man page changes)
tested fkr simon, and more suggestions from millert


Revision tags: OPENBSD_4_1_BASE
# 1.70 14-Feb-2007 dlg

bus_space does byte swapping to cope with host endianness for us, so remove
an unnecessary htole32().


# 1.69 13-Feb-2007 marco

Fix subtle x ? y : z bug when calling mfi_create_sgl. This worked because
during runtime the bug condition does not happen.

ok krw joris


# 1.68 08-Feb-2007 ray

Remove double semicolons.

From Pierre Riteau <pierre dot riteau at free dot fr>.

OK marco@.


# 1.67 23-Dec-2006 deraadt

adapt to new two-level sensor api; Constantine A. Murenin


# 1.66 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.65 31-Aug-2006 marco

Add sensor thread for individual sd devices.

tested dlg
ok dlg deraadt


# 1.64 30-Aug-2006 dlg

when determining the size of the volumes and disks we want how many
bytes each of them has, not the number of kilobytes. this solves the
"why am i dividing by 2" question. the answer is "you dont, you multiply
by 512".


# 1.63 28-Jul-2006 brad

make dmesg printing look a little bit nicer.


# 1.62 19-Jun-2006 marco

Factor for disk size is /2. Odd but tested on all mfis I have.


# 1.61 19-Jun-2006 miod

Everytime one forgets an argument in a printf-like function call, God kills
a kitten. Commiters, please think of the kittens when working on code.


# 1.60 19-Jun-2006 marco

Make a BGI (Back Ground Init) a scrub instead of rebuild.


# 1.59 19-Jun-2006 marco

Add hot spare support.


# 1.58 26-May-2006 marco

Add blinking for disks.


# 1.57 25-May-2006 marco

Move a int i; to top of function so that it compiles on non c99 compilers.
Pointed out by miod@

The enclosure id modifier didn't reflect reality so move it back to whatever
the raid card uses.


# 1.56 25-May-2006 marco

And add time and percentage to builds and check consistencies.


# 1.55 25-May-2006 marco

Add last bit of physcal disk stuff.
Remove bogus memset.
Hotspares still don't work.


# 1.54 25-May-2006 marco

Add physical device and read config structures.
Add initial part of BIOCDISK


# 1.53 23-May-2006 deraadt

commited with unused variable


# 1.52 23-May-2006 marco

Remove some debug cruft.


# 1.51 23-May-2006 marco

Add first half of physical disk data for bio.


# 1.50 22-May-2006 marco

Add support for raid 50 and 10 in bio.


# 1.49 22-May-2006 marco

Add mail box to mfi_mgmt to handle sub commands more gracefully.
Remove some debug crud that snuck in the TEST_UNIT_READY case.
Finish other half of BIOCVOL primitive.
Add several structures to fill out the BIOCVOL primitive.


# 1.48 22-May-2006 marco

Add first half of BIOCVOL primitive.


# 1.47 21-May-2006 marco

Do a giant flush of disk and raid-card memory when SYNCHONIZE_CACHE is called.


# 1.46 21-May-2006 marco

pretty up some debug statements.


# 1.45 21-May-2006 marco

Add bio alarm function.
Redo mfi_mgmt to deal with zero data commands.


# 1.44 21-May-2006 marco

Add generic management function.
Redo ccb_state flags so that we can actually sleep on it.
Redo mfi_get_info to use new mgmt function.
Add rw_locks for mgmt interface.
Make BIOCINQ dynamic.


# 1.43 21-May-2006 marco

Oops, helps to use the right structure field.
Use actual nr of physical disks present.


# 1.42 21-May-2006 marco

Add first BIOCINQ primitive.


# 1.41 18-May-2006 marco

Remove some debug cruft and pretty up some debug messages.


# 1.40 18-May-2006 marco

Kill splbio/splx in the interrupt handler.


# 1.39 18-May-2006 marco

And we have lift off! Was able to create a filesystem and write to the
filesystem.

Collapse both completion routines into one.
Fixup scsi error reporting in the completion routine.


# 1.38 17-May-2006 marco

Add completion routines.
Fix some bugs inside the interrupt handler.


# 1.37 17-May-2006 marco

Add mfi_get_info to obtain all kinds of fun information from the fw.
Print out whole info structure when debug is enabled.
Add a nice print with useful info during attach.


# 1.36 17-May-2006 marco

Refactor scsi path so that we can have a single sgl function for io and non-io
traffic.
Redo parameters on functions that were passing too many parameters around.


# 1.35 16-May-2006 marco

Nuke some { }


# 1.34 16-May-2006 marco

Move !xs->data case into mfi_start_xs.
Return proper sense data when a polling command fails.


# 1.33 16-May-2006 marco

Fix some more htole32 screw-ups.
Colapse all little SCSI functions into a single generic one.
Fix a bug in the SGE calculation.

This brings the driver up to post:
mfi0 at pci12 dev 14 function 0 "Dell PERC SAS" rev 0x00: Dell PERC 5/e irq 5
scsibus3 at mfi0: 2 targets
sd1 at scsibus3 targ 0 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd1: 237824MB, 237824 cyl, 64 head, 32 sec, 512 bytes/sec, 487063552 sec total
sd2 at scsibus3 targ 1 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd2: 34176MB, 34176 cyl, 64 head, 32 sec, 512 bytes/sec, 69992448 sec total


# 1.32 16-May-2006 marco

Fix some htole32 I missed.
Sprinkle more debug.


# 1.31 16-May-2006 marco

Add READ CAPACITY.


# 1.30 16-May-2006 marco

Oops PREREAD not PREWRITE.


# 1.29 16-May-2006 marco

Add TUR and make it send it directly to firmware.
Sprinkle some extra debug.


# 1.28 15-May-2006 marco

Clear all relevant ccb fields when mfi_put_ccb frees a ccb.


# 1.27 15-May-2006 marco

Oops don't send command twice to firmware when polling.


# 1.26 15-May-2006 marco

Add INQUIRY command.
Add sgl magic.


# 1.25 10-May-2006 marco

Add some airplane code.

add bio hooks.
add scsi entry point for io.


# 1.24 26-Apr-2006 marco

Fix some debug prints.


# 1.23 21-Apr-2006 marco

typo


# 1.22 21-Apr-2006 marco

Add mfi_poll and use the new shiny function to setup all the hardware queues.
Lots of ideas from the FreeBSD driver.


# 1.21 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.20 20-Apr-2006 dlg

marco hates typedefs as much as i do, so he asked me to clean mfi like i
just did with ami. this gets rid of the typedef for the ccb lists.

also uses TAILQ_FIRST to get ccbs off the freelist. this is a proactive
fix for a lint teary.


# 1.19 18-Apr-2006 marco

It helps to initialize a queue before usage.


# 1.18 18-Apr-2006 marco

Actually add ccbs to the queue.
Fix the error path for mfi_init_ccb.
Alter dmamap for io.


# 1.17 17-Apr-2006 marco

Sprinkle more debug. Remove 64 byte boundary; it doesn't seem to like it.
Hack around 64 byte boundary for the frames for now.


# 1.16 17-Apr-2006 marco

Setup ccbs and clean up ccb structure.


# 1.15 16-Apr-2006 marco

Oops, make mfi_allocmem always use 64 byte boundaries since frames have to
have that alignment. It doesn't matter for the other consumers of the
function.


# 1.14 16-Apr-2006 marco

Add frame memory and sglist allocation.


# 1.13 16-Apr-2006 marco

Make memory access use macro.


# 1.12 16-Apr-2006 marco

typo


# 1.11 16-Apr-2006 marco

Add get and put ccb functions. Shuffle some more definitions.


# 1.10 16-Apr-2006 marco

Nicer print when context is invalid.


# 1.9 16-Apr-2006 marco

Shuffle some #defines.
Fix comments.
Add human readable enable intrrupt #define.


# 1.8 16-Apr-2006 marco

Add interrupt handler. Idea borrowed from FreeBSD since it is much nicer
than the Linux one.


# 1.7 07-Apr-2006 marco

Replace bus_space functions with generic ones that do barriers.


# 1.6 07-Apr-2006 marco

Add memory allocator functions.


# 1.5 07-Apr-2006 marco

Print state in debug. Change return vales to 1 instead of ENXIO.


# 1.4 07-Apr-2006 marco

Make a better debug mechanism.


# 1.3 07-Apr-2006 marco

Enable mfi_transition_fw() original code from FreeBSD.


# 1.2 06-Apr-2006 marco

Add fw transition logic.


# 1.1 06-Apr-2006 marco

Add skeleton driver for MegaRAID SAS.


# 1.190 06-Jul-2023 visa

Use mtx_init() to initialize stack-based mutexes

mtx_init() ensures the mutex' lock_object has static storage duration.
This makes it safe to re-enable WITNESS with stack-based mutexes.

OK bluhm@ miod@


# 1.189 25-May-2023 kurt

Disable witness for mutexes created on the stack which allows
the ddb command 'show witness' to succeed without panicking.
Leaving witness enabled on these mutexes saves a pointer to
struct lock_type on the stack which gets clobbered resulting
in a panic in witness_ddb_display_descendants().

okay miod@


Revision tags: OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.188 16-Apr-2022 naddy

constify SCSI adapter entry points

ok krw@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.187 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.186 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.185 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.184 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.183 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.182 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.181 13-Jul-2020 krw

Where we have a pointer (sc) to the relevant adapter_softc, use
&sc->sc_dev to get a device pointer rather than using the void *
whence we obtained 'sc'.


# 1.180 13-Jul-2020 krw

Remove some pointless casting of void * when assigning one
(scsi_link.adapter_softc) to a pointer of a particular softc type.


# 1.179 27-Jun-2020 krw

Nuke trailing whitespace.


# 1.178 27-Jun-2020 krw

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


# 1.177 24-Jun-2020 krw

Use SDEV_NO_ADAPTER_TARGET instead of -1 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.176 21-Mar-2020 krw

Simplify some goto'ing that jumps a single line or
does nothing at all.

The first one spotted as CID 1452976.

Reads good to millert@

ok mpi@


# 1.175 13-Feb-2020 krw

Nuke *_minphys() functions that either simply apply MAXPHYS or do
nothing at all. MAXPHYS will be applied in minphys() and nothing at
all, well, doesn't do anything.

Also remove any '#define <blah> MAXPHYS' statements used solely to
disguise MAXPHYS in said functions.


# 1.174 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.173 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.172 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.171 31-Dec-2019 mpi

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

ok kn@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.170 05-Mar-2019 jmatthew

apply background init progress fix from r1.59 of mfii.c
(reverting most of r1.60 of mfi.c, oddly enough)

ok dlg@
tested on a SAS2008 (perc h310)


Revision tags: OPENBSD_6_4_BASE
# 1.169 14-Aug-2018 jmatthew

return ENOTTY rather than EINVAL to indicate an ioctl hasn't been handled

ok dlg@ deraadt@ kettenis@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.168 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.167 02-Feb-2017 dlg

copy the mbox into the dcmd struct, not the pointer to the mbox.

makes bioctl work on mfi(4) again.

while here memset a few mboxes before using them.

bioctl breakage reported by jason george


# 1.166 23-Jan-2017 dlg

represent the mbox layout with union instead of an array of bytes.

memcpying uint16_ts into inconsistently addressed offsets is hard
to read, and this makes future work easier to implement.

tested on mfi(4) and mfii(4)


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.165 09-Sep-2015 deraadt

sizes for free(); ok sthen


Revision tags: OPENBSD_5_8_BASE
# 1.164 29-May-2015 uebayasi

Initial addition of ``Patrol Read'' support in bio(4), biocto(8), and
mfi(4). Based on FreeBSD, but done without mfiutil(8).

OK deraadt@


# 1.163 18-May-2015 mikeb

Prevent splassert from firing during sd_flush which runs "cold"

While mfi(4) should pass SCSI transfer flags (e.g. SCSI_POLL and
SCSI_NOSLEEP) down to the management function, make it at least
use "cold" consistently for now.

ok dlg


# 1.162 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.161 08-Mar-2015 dlg

properly set sgl related flags on skinny controllers. this fixes
io against physical disks on my dell perc h310s. logical disks still
work fine.

ok deraadt@ yasuoka@


# 1.160 08-Feb-2015 yasuoka

Fix mfi ioctl to set drive state properly.
diff from Tsubai Masanari

test dlg jmatthew
ok dlg


# 1.159 09-Jan-2015 yasuoka

Add support DIOC{G,S}CACHE to mfi(4). Cache of disk on mfi(4) will
be enabled by default. Also if the controller doesn't have any RAM,
the cache on the physical disk will be enabled.

discuss with jsg tsubai
ok dlg


# 1.158 19-Dec-2014 deraadt

another handful of bcopy -> memcpy because there is no overlap


# 1.157 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.156 09-Sep-2014 dlg

mark the interrupt handler mpsafe, and give up biglock in the scsi cmd
submission paths. take biglock again when calling back into the scsi
stack.

tested on a variety of cards here, including the skinny mfis on the
firewall next to mpsafe myx.


# 1.155 15-Aug-2014 yasuoka

Create a function which loads sgd in the mfi_iop_ops struct so that skinny
adapters can use "IEEE sgl".

tested dlg yasuoka
ok dlg jsg


Revision tags: OPENBSD_5_6_BASE
# 1.154 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.153 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.152 04-May-2014 sf

format string fixes for bus_addr_t and bus_size_t

bus_addr_t and bus_size_t are u_long everywhere

ok kettenis@


Revision tags: OPENBSD_5_5_BASE
# 1.151 20-Feb-2014 kettenis

revert previous commit; didn't intend to commit those bits


# 1.150 20-Feb-2014 kettenis

Avoid printing the "nvram corrupt" message for onboard 2200s found on Sun
hardware.

ok dlg@, jmatthew@


# 1.149 04-Dec-2013 dlg

mfi_refresh_sensors calls mfi_ioctl_vol which calls mfi_bio_getitall, which
replaces pointers in the softc and all sorts of fun stuff. this protects
the call to bio_getitall with the sc_lock the ioctl path uses, so we dont
get panics like those reported on bugs@ recently.

ok deraadt@


# 1.148 23-Oct-2013 kettenis

Add support for displaying the cache write policy of RAID volumes to bioctl(8)
and make mfi(4) pass up the necessary information. Adding support for other
RAID controllers is left as an excercise to the reader.

ok deraadt@


# 1.147 09-Oct-2013 jmatthew

Include the 'state of health' field in the bbu ok sensor value.
The dell perc 6/i sets this to zero (meaning bad) when it
decides the battery doesn't have enough capacity for it to
allow write back mode, but doesn't set any of the other flags
to tell us why.

ok dlg@, tested by sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.146 18-May-2013 jmc

enw->new in comment;
spotted by krw, missed by jsg, and forwarded From: Alexey Suslikov


# 1.145 08-May-2013 jsg

fix some leaks in error paths
ok fgsch@ krw@ kettenis@


# 1.144 03-May-2013 dlg

break out the battery status into excruciating detail. makes it harder for
$VENDOR to complain about a lack of diagnostic material from their crappy
mgmt tools if you're not running an operating system they support.


# 1.143 02-May-2013 dlg

always attach the battery sensor if the adapter lets us query it.
newly replaced batteries dont show up immediately.


# 1.142 01-May-2013 dlg

provide a sensor for the battery backup unit (bbu) on mfi boards that
support it.

now i can tell (a bit better) why io might be slow on some of my boxes.


# 1.141 01-May-2013 dlg

dont need to walk alldevs during sensor creation looking for the logical
disk scsibus when we record that in mfi_attach.

also happens to get rid of a logic error that let it come out of the loop
on alldevs with a reference to something that wasnt the logical disk
scsibus and use that.


# 1.140 30-Apr-2013 dlg

use MR_DCMD consistently. some MD_DCMD was in there somehow.


# 1.139 07-Apr-2013 dlg

david imhoff points out that the error handling in mfi_init_ccb gets the
index to which ccb to free wrong.

this takes the logic from mpi/mpii/mfii which pulls the ready ccbs off
the free list rather than rely on the current index from the for loop
that we failed inside of.

thanks to david for finding this out.


Revision tags: OPENBSD_5_3_BASE
# 1.138 12-Sep-2012 haesbaert

Make sure we don't sleep on autoconf.

ok mikeb


# 1.137 17-Aug-2012 dlg

add support for "physical devices" on skinny controllers.

these controllers let you specify disks that should be accessed directly
rather than be part of logical volumes. apparently you can plug in things
like tape drives too.

anyway, physical devices are exposed via a separate scsibus attached to
mfi.

ok mikeb@


# 1.136 16-Aug-2012 dlg

fix mfi_poll by having it do delays between loops, and breaking on
timeouts. how embarrassment.

implement mfi_exec for doing sync executions of commands in process
contexts and cut mfi_mgmt over to it.


# 1.135 16-Aug-2012 dlg

rework mfi_poll so it will do all the completions on a ccb including
calling the done handler.

this makes it consistently complete scsi io with all the proper error
checking.


# 1.134 16-Aug-2012 dlg

stop passing mfi_softc around as a member of the ccb, consistently give it
as the first argument to functions. like mfii.


# 1.133 16-Aug-2012 dlg

scrub ccbs when we're about to use them, not when we put them back
on the free list. ccbs can be reused, so we dont want old state screwing up
new commands.


# 1.132 16-Aug-2012 dlg

move the dma syncs for the ccb data into ccb_done, so we can do it once
rather than put the code everywhere.


# 1.131 16-Aug-2012 dlg

fix up the dma sync for the command frame in mfi_done.


# 1.130 14-Aug-2012 dlg

use scsi_get_link to find out the name of a child device for bioctl rather
than snoop scsi commands and copy it in an io path.

no functional change, but the code has one less XXX now.


# 1.129 14-Aug-2012 dlg

expose the max number of logical volumes the hardware supports as the width
of its scsibus. only advertise 1 lun on logical volumes instead of letting
the midlayer fix it up to 8.

give every target on the bus max_cmds openings. iopools means they will
properly share access to them.

this in particular is useful on skinny controllers which only advertise 31
command slots. if you have 16 volumes, theyll only get 1 opening each with
the old maths. this way round the ones that are busy will share the slots.

tested on a perc5 with two volumes and hard workloads.


# 1.128 14-Aug-2012 dlg

print the boards name (eg, perc 5/i) according to the firmware like mfii.

ok deraadt@


# 1.127 14-Aug-2012 dlg

move knowledge of the location of the inbound doorbell out of code in
transition_firmware into a member of the iop structures.

ok mikeb@ haesbaert@


# 1.126 13-Aug-2012 dlg

get rid of the last foo_lo and foo_hi bits i could find in the hardware
structures and use htole64 instead of htole32(addr >> 32); htole32(addr);

gets rid of "handy" stack variables to get the dva to 64bits.

sprinkle some more byte swaps for things that should have it.

tested on a perc5 (xscale)


# 1.125 13-Aug-2012 dlg

do appropriate bus_dmamapy_syncs around the pcq/completion ring.

tested on a perc5 (xscale)


# 1.124 13-Aug-2012 dlg

replace uint32_ts for hi and lo addresses in the mfi_init_ hardware
descriptors with single uint64_ts. theyre not some weird middle
endian thing. this makes the code more readable.

add some missing htole32s to the code while here.

tested on a perc5 (xscale).


# 1.123 11-Aug-2012 dlg

the producer/consumer values are used by the device, which is little
endian. do appropriate byteswapping for when the host cpu uses them.

tested on a perc5 (xscale) in an amd64.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.122 12-Jan-2012 dlg

add support for skinny variants.

from Alexey Suslikov
reviewed by marco


Revision tags: OPENBSD_5_0_BASE
# 1.121 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.120 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.119 09-Apr-2011 marco

add all 64 bit dma plumbing but stick with 32 for now by default.

ok deraadt


# 1.118 09-Apr-2011 marco

make sure the upper 32 bits are always written to instead of assuming it
is 0.

ok deraadt.


# 1.117 08-Apr-2011 marco

kill some stray spaces


# 1.116 08-Apr-2011 marco

rename wiat channel to something less than 8 chars.

prompted by deraadt


# 1.115 08-Apr-2011 marco

use dma_alloc for transient management commands.

prodded and ok deraadt


Revision tags: OPENBSD_4_9_BASE
# 1.114 30-Dec-2010 dlg

cut mfi over to using iopools.

this gets rid of NO_CCB, provides better scheduling of io between busy
logical volumes on the same controller, and makes the ioctl and sensor
paths more reliable.

this is the least intrusive version of this change i could come up with. it
only took 4 or 5 goes...

ok marco@
deraadt@ says this is a good time for this change.


# 1.113 24-Sep-2010 dlg

no use setting cmd in mfi_ioctl_setstate if you never use it.


# 1.112 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


# 1.111 29-Aug-2010 dlg

the scsi completion code thinks that if you dont get MFI_STAT_OK
back from the chip on a command then the command completely failed.
MFI_STAT_SCSI_DONE_WITH_ERROR really means the command completed
fine, but there's some sense data too. this tweaks the handling to
be more appropriate, as per the linux and solaris drivers.

timed out waiting for beck@
putting this in cos its obviously more correct than the current code.


Revision tags: OPENBSD_4_8_BASE
# 1.110 22-Jul-2010 matthew

SCSI HBA drivers are supposed to get their SCSI CDBs from xs->cmd, not
xs->cmdstore.

ok krw@ a while back (contingent upon testing), and deraadt@ says this
has been in snapshots for weeks now.


# 1.109 01-Jul-2010 matthew

Change scsibus(4)'s scsi_link array to an SLIST to save memory on
sparsely populated buses.

ok dlg@, krw@


# 1.108 30-Jun-2010 mk

Use SLIST for the ccb free list.

ok krw, discontent grunts from marco.


# 1.107 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.106 15-Jun-2010 dlg

dont pass the dev_t from the scsi device drivers into the midlayer for
ioctl requests, and dont pass the proc pointers around for any ioctl
requests in scsi land at all. neither were used, so trim the fat.

ok krw@ marco@


# 1.105 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.104 16-May-2010 nicm

Use a temporary variable for now to sidestep -Wbounded checking when
copying vendor[8]/product[16]/revision[4] out of struct scsi_inquiry_data
together with one memcopy.

ok krw


# 1.103 22-Apr-2010 oga

use BUS_DMA_ZERO on alloc instead of bzeroing after.

ok dlg@, marco@


# 1.102 10-Apr-2010 marco

grrr var names in protos


# 1.101 10-Apr-2010 marco

sprinkle some bus_dmamap_sync around frame access.
prompted by oga


# 1.100 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.99 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.98 04-Jan-2010 dlg

rename ccb_xs to ccb_cookie and change its type from a scsi_xfer * to a
void *. this lets us pass things other than scsi_xfers to ccb completion
handlers.


# 1.97 04-Jan-2010 dlg

protect the ccb free queue with a mutex rather than splbio


# 1.96 03-Jan-2010 chl

change M_WAITOK --> M_WAITOK|M_CANFAIL

with input from marco@

ok marco@ krw@

this was ok looooooooong time ago but lost in my mailbox


Revision tags: OPENBSD_4_6_BASE
# 1.95 30-Apr-2009 marco

Add READ(16) & WRITE(16) commands.
ok krw


# 1.94 29-Apr-2009 marco

MFI_D_IOCTL should be commented out. No binary change.


# 1.93 04-Apr-2009 dlg

scrub more fields in the ccb when returning them to the free list after
theyve been used, in particular the mfi header flags which has a bit
that specifies if a command should be completed via the interrupt path.

if we use a ccb during boot we set that bit, but it isnt necessarily
cleared by things that use it later on. this means a ccb we expected to
complete via an interrupt never actually generates an interrupt or appears
in the reply queue. this obviously stalls the io.


# 1.92 29-Mar-2009 marco

spello


# 1.91 29-Mar-2009 dlg

when we steal the SYNC CACHE command in mfi_scsi_cmd we still have to
mark the xs as done and call scsi_done for it rather than just returning
COMPLETE.


# 1.90 29-Mar-2009 dlg

fix a small race in mfi_mgmt between the checking of a ccbs completion and
the sleep waiting for the completion. it is possible to get the interrupt
completing the command just before the tsleep, which will never get a
wakeup because the interrupt with the wakeup has already happened.


Revision tags: OPENBSD_4_5_BASE
# 1.89 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.


# 1.88 28-Jan-2009 marco

Add support for next generation megaraid sas raid controllers.
From Jim Giannoules <gortag@gmail.com>


# 1.87 31-Oct-2008 marco

Generalize function to obtain all details to do bio stuff. This is in
preparation to start showing unsused disks which will require all this
information to do the math.

While at it fix a size of hotspare volume bug.


# 1.86 30-Oct-2008 marco

Fix bug that when there are no volumes but there are hot spares it would
no show the hotspares.


# 1.85 28-Oct-2008 marco

Fix output when reporting on multivolume disk groups.

Reported by mitja@muzenic.net


# 1.84 27-Oct-2008 marco

Move some include stuff around


# 1.83 26-Oct-2008 marco

Space


# 1.82 23-Oct-2008 marco

Fix PR5645
ok dlg
tested beck and others


# 1.81 25-Sep-2008 krw

Initialize 'ssc' to NULL since we test it later. Shouldn't ever be
NULL at the point of test unless the device list is confused, but
be consistantly paranoid if we're going to be paranoid.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.80 16-Feb-2008 krw

Return NO_CCB and not TRY_AGAIN_LATER when running out of ccb's.
Eliminates 'not queued' errors reported on the mailing lists.

Tested by Michael (belenus at bsdmail dot de).

ok marco@


# 1.79 11-Feb-2008 dlg

add support for the mfi controllers with the ppc iops, aka, LSI SAS1078 or
Dell PERC6.

committed off a machine booting and rooting off a perc6. tested on a perc5
by marco@
ok marco@


# 1.78 26-Jan-2008 brad

Set the return value instead of returning right away so that the DMA
memory is actually synched.

ok dlg@


# 1.77 26-Jan-2008 dlg

sync dma mem back to the cpu on poll failure.

from mickey via pr5714


# 1.76 26-Jan-2008 dlg

despatch -> dispatch

disparate spellink fix from mickey


# 1.75 05-Nov-2007 krw

More scsi_done() at SPLBIO.


# 1.74 27-Sep-2007 chl

M_ZERO changes

ok dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.73 24-Jun-2007 dlg

rework sensor tasks to use the kernels generic workq rather than a special
kernel thread of its own. the api has changed (which will be fixed in the
manpage shortly) so all the users of sensor tasks that i can find have
been fixed too.

noone tested, so its going in to force people to run with it.
"put it in" deraadt@


# 1.72 29-May-2007 todd

sprinkle some SMALL_KERNEL to permit bio/softraid to run on boot media
ok marco@ then suggested deraadt@


# 1.71 22-Mar-2007 deraadt

split userland & kernel struct sensor/sensordev so that the addition
of new fields in the future is less disruptive. This is done similar
to how struct proc is handled for ps(1). ok jmc (man page changes)
tested fkr simon, and more suggestions from millert


Revision tags: OPENBSD_4_1_BASE
# 1.70 14-Feb-2007 dlg

bus_space does byte swapping to cope with host endianness for us, so remove
an unnecessary htole32().


# 1.69 13-Feb-2007 marco

Fix subtle x ? y : z bug when calling mfi_create_sgl. This worked because
during runtime the bug condition does not happen.

ok krw joris


# 1.68 08-Feb-2007 ray

Remove double semicolons.

From Pierre Riteau <pierre dot riteau at free dot fr>.

OK marco@.


# 1.67 23-Dec-2006 deraadt

adapt to new two-level sensor api; Constantine A. Murenin


# 1.66 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.65 31-Aug-2006 marco

Add sensor thread for individual sd devices.

tested dlg
ok dlg deraadt


# 1.64 30-Aug-2006 dlg

when determining the size of the volumes and disks we want how many
bytes each of them has, not the number of kilobytes. this solves the
"why am i dividing by 2" question. the answer is "you dont, you multiply
by 512".


# 1.63 28-Jul-2006 brad

make dmesg printing look a little bit nicer.


# 1.62 19-Jun-2006 marco

Factor for disk size is /2. Odd but tested on all mfis I have.


# 1.61 19-Jun-2006 miod

Everytime one forgets an argument in a printf-like function call, God kills
a kitten. Commiters, please think of the kittens when working on code.


# 1.60 19-Jun-2006 marco

Make a BGI (Back Ground Init) a scrub instead of rebuild.


# 1.59 19-Jun-2006 marco

Add hot spare support.


# 1.58 26-May-2006 marco

Add blinking for disks.


# 1.57 25-May-2006 marco

Move a int i; to top of function so that it compiles on non c99 compilers.
Pointed out by miod@

The enclosure id modifier didn't reflect reality so move it back to whatever
the raid card uses.


# 1.56 25-May-2006 marco

And add time and percentage to builds and check consistencies.


# 1.55 25-May-2006 marco

Add last bit of physcal disk stuff.
Remove bogus memset.
Hotspares still don't work.


# 1.54 25-May-2006 marco

Add physical device and read config structures.
Add initial part of BIOCDISK


# 1.53 23-May-2006 deraadt

commited with unused variable


# 1.52 23-May-2006 marco

Remove some debug cruft.


# 1.51 23-May-2006 marco

Add first half of physical disk data for bio.


# 1.50 22-May-2006 marco

Add support for raid 50 and 10 in bio.


# 1.49 22-May-2006 marco

Add mail box to mfi_mgmt to handle sub commands more gracefully.
Remove some debug crud that snuck in the TEST_UNIT_READY case.
Finish other half of BIOCVOL primitive.
Add several structures to fill out the BIOCVOL primitive.


# 1.48 22-May-2006 marco

Add first half of BIOCVOL primitive.


# 1.47 21-May-2006 marco

Do a giant flush of disk and raid-card memory when SYNCHONIZE_CACHE is called.


# 1.46 21-May-2006 marco

pretty up some debug statements.


# 1.45 21-May-2006 marco

Add bio alarm function.
Redo mfi_mgmt to deal with zero data commands.


# 1.44 21-May-2006 marco

Add generic management function.
Redo ccb_state flags so that we can actually sleep on it.
Redo mfi_get_info to use new mgmt function.
Add rw_locks for mgmt interface.
Make BIOCINQ dynamic.


# 1.43 21-May-2006 marco

Oops, helps to use the right structure field.
Use actual nr of physical disks present.


# 1.42 21-May-2006 marco

Add first BIOCINQ primitive.


# 1.41 18-May-2006 marco

Remove some debug cruft and pretty up some debug messages.


# 1.40 18-May-2006 marco

Kill splbio/splx in the interrupt handler.


# 1.39 18-May-2006 marco

And we have lift off! Was able to create a filesystem and write to the
filesystem.

Collapse both completion routines into one.
Fixup scsi error reporting in the completion routine.


# 1.38 17-May-2006 marco

Add completion routines.
Fix some bugs inside the interrupt handler.


# 1.37 17-May-2006 marco

Add mfi_get_info to obtain all kinds of fun information from the fw.
Print out whole info structure when debug is enabled.
Add a nice print with useful info during attach.


# 1.36 17-May-2006 marco

Refactor scsi path so that we can have a single sgl function for io and non-io
traffic.
Redo parameters on functions that were passing too many parameters around.


# 1.35 16-May-2006 marco

Nuke some { }


# 1.34 16-May-2006 marco

Move !xs->data case into mfi_start_xs.
Return proper sense data when a polling command fails.


# 1.33 16-May-2006 marco

Fix some more htole32 screw-ups.
Colapse all little SCSI functions into a single generic one.
Fix a bug in the SGE calculation.

This brings the driver up to post:
mfi0 at pci12 dev 14 function 0 "Dell PERC SAS" rev 0x00: Dell PERC 5/e irq 5
scsibus3 at mfi0: 2 targets
sd1 at scsibus3 targ 0 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd1: 237824MB, 237824 cyl, 64 head, 32 sec, 512 bytes/sec, 487063552 sec total
sd2 at scsibus3 targ 1 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd2: 34176MB, 34176 cyl, 64 head, 32 sec, 512 bytes/sec, 69992448 sec total


# 1.32 16-May-2006 marco

Fix some htole32 I missed.
Sprinkle more debug.


# 1.31 16-May-2006 marco

Add READ CAPACITY.


# 1.30 16-May-2006 marco

Oops PREREAD not PREWRITE.


# 1.29 16-May-2006 marco

Add TUR and make it send it directly to firmware.
Sprinkle some extra debug.


# 1.28 15-May-2006 marco

Clear all relevant ccb fields when mfi_put_ccb frees a ccb.


# 1.27 15-May-2006 marco

Oops don't send command twice to firmware when polling.


# 1.26 15-May-2006 marco

Add INQUIRY command.
Add sgl magic.


# 1.25 10-May-2006 marco

Add some airplane code.

add bio hooks.
add scsi entry point for io.


# 1.24 26-Apr-2006 marco

Fix some debug prints.


# 1.23 21-Apr-2006 marco

typo


# 1.22 21-Apr-2006 marco

Add mfi_poll and use the new shiny function to setup all the hardware queues.
Lots of ideas from the FreeBSD driver.


# 1.21 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.20 20-Apr-2006 dlg

marco hates typedefs as much as i do, so he asked me to clean mfi like i
just did with ami. this gets rid of the typedef for the ccb lists.

also uses TAILQ_FIRST to get ccbs off the freelist. this is a proactive
fix for a lint teary.


# 1.19 18-Apr-2006 marco

It helps to initialize a queue before usage.


# 1.18 18-Apr-2006 marco

Actually add ccbs to the queue.
Fix the error path for mfi_init_ccb.
Alter dmamap for io.


# 1.17 17-Apr-2006 marco

Sprinkle more debug. Remove 64 byte boundary; it doesn't seem to like it.
Hack around 64 byte boundary for the frames for now.


# 1.16 17-Apr-2006 marco

Setup ccbs and clean up ccb structure.


# 1.15 16-Apr-2006 marco

Oops, make mfi_allocmem always use 64 byte boundaries since frames have to
have that alignment. It doesn't matter for the other consumers of the
function.


# 1.14 16-Apr-2006 marco

Add frame memory and sglist allocation.


# 1.13 16-Apr-2006 marco

Make memory access use macro.


# 1.12 16-Apr-2006 marco

typo


# 1.11 16-Apr-2006 marco

Add get and put ccb functions. Shuffle some more definitions.


# 1.10 16-Apr-2006 marco

Nicer print when context is invalid.


# 1.9 16-Apr-2006 marco

Shuffle some #defines.
Fix comments.
Add human readable enable intrrupt #define.


# 1.8 16-Apr-2006 marco

Add interrupt handler. Idea borrowed from FreeBSD since it is much nicer
than the Linux one.


# 1.7 07-Apr-2006 marco

Replace bus_space functions with generic ones that do barriers.


# 1.6 07-Apr-2006 marco

Add memory allocator functions.


# 1.5 07-Apr-2006 marco

Print state in debug. Change return vales to 1 instead of ENXIO.


# 1.4 07-Apr-2006 marco

Make a better debug mechanism.


# 1.3 07-Apr-2006 marco

Enable mfi_transition_fw() original code from FreeBSD.


# 1.2 06-Apr-2006 marco

Add fw transition logic.


# 1.1 06-Apr-2006 marco

Add skeleton driver for MegaRAID SAS.


# 1.189 25-May-2023 kurt

Disable witness for mutexes created on the stack which allows
the ddb command 'show witness' to succeed without panicking.
Leaving witness enabled on these mutexes saves a pointer to
struct lock_type on the stack which gets clobbered resulting
in a panic in witness_ddb_display_descendants().

okay miod@


Revision tags: OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.188 16-Apr-2022 naddy

constify SCSI adapter entry points

ok krw@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.187 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.186 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.185 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.184 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.183 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.182 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.181 13-Jul-2020 krw

Where we have a pointer (sc) to the relevant adapter_softc, use
&sc->sc_dev to get a device pointer rather than using the void *
whence we obtained 'sc'.


# 1.180 13-Jul-2020 krw

Remove some pointless casting of void * when assigning one
(scsi_link.adapter_softc) to a pointer of a particular softc type.


# 1.179 27-Jun-2020 krw

Nuke trailing whitespace.


# 1.178 27-Jun-2020 krw

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


# 1.177 24-Jun-2020 krw

Use SDEV_NO_ADAPTER_TARGET instead of -1 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.176 21-Mar-2020 krw

Simplify some goto'ing that jumps a single line or
does nothing at all.

The first one spotted as CID 1452976.

Reads good to millert@

ok mpi@


# 1.175 13-Feb-2020 krw

Nuke *_minphys() functions that either simply apply MAXPHYS or do
nothing at all. MAXPHYS will be applied in minphys() and nothing at
all, well, doesn't do anything.

Also remove any '#define <blah> MAXPHYS' statements used solely to
disguise MAXPHYS in said functions.


# 1.174 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.173 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.172 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.171 31-Dec-2019 mpi

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

ok kn@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.170 05-Mar-2019 jmatthew

apply background init progress fix from r1.59 of mfii.c
(reverting most of r1.60 of mfi.c, oddly enough)

ok dlg@
tested on a SAS2008 (perc h310)


Revision tags: OPENBSD_6_4_BASE
# 1.169 14-Aug-2018 jmatthew

return ENOTTY rather than EINVAL to indicate an ioctl hasn't been handled

ok dlg@ deraadt@ kettenis@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.168 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.167 02-Feb-2017 dlg

copy the mbox into the dcmd struct, not the pointer to the mbox.

makes bioctl work on mfi(4) again.

while here memset a few mboxes before using them.

bioctl breakage reported by jason george


# 1.166 23-Jan-2017 dlg

represent the mbox layout with union instead of an array of bytes.

memcpying uint16_ts into inconsistently addressed offsets is hard
to read, and this makes future work easier to implement.

tested on mfi(4) and mfii(4)


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.165 09-Sep-2015 deraadt

sizes for free(); ok sthen


Revision tags: OPENBSD_5_8_BASE
# 1.164 29-May-2015 uebayasi

Initial addition of ``Patrol Read'' support in bio(4), biocto(8), and
mfi(4). Based on FreeBSD, but done without mfiutil(8).

OK deraadt@


# 1.163 18-May-2015 mikeb

Prevent splassert from firing during sd_flush which runs "cold"

While mfi(4) should pass SCSI transfer flags (e.g. SCSI_POLL and
SCSI_NOSLEEP) down to the management function, make it at least
use "cold" consistently for now.

ok dlg


# 1.162 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.161 08-Mar-2015 dlg

properly set sgl related flags on skinny controllers. this fixes
io against physical disks on my dell perc h310s. logical disks still
work fine.

ok deraadt@ yasuoka@


# 1.160 08-Feb-2015 yasuoka

Fix mfi ioctl to set drive state properly.
diff from Tsubai Masanari

test dlg jmatthew
ok dlg


# 1.159 09-Jan-2015 yasuoka

Add support DIOC{G,S}CACHE to mfi(4). Cache of disk on mfi(4) will
be enabled by default. Also if the controller doesn't have any RAM,
the cache on the physical disk will be enabled.

discuss with jsg tsubai
ok dlg


# 1.158 19-Dec-2014 deraadt

another handful of bcopy -> memcpy because there is no overlap


# 1.157 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.156 09-Sep-2014 dlg

mark the interrupt handler mpsafe, and give up biglock in the scsi cmd
submission paths. take biglock again when calling back into the scsi
stack.

tested on a variety of cards here, including the skinny mfis on the
firewall next to mpsafe myx.


# 1.155 15-Aug-2014 yasuoka

Create a function which loads sgd in the mfi_iop_ops struct so that skinny
adapters can use "IEEE sgl".

tested dlg yasuoka
ok dlg jsg


Revision tags: OPENBSD_5_6_BASE
# 1.154 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.153 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.152 04-May-2014 sf

format string fixes for bus_addr_t and bus_size_t

bus_addr_t and bus_size_t are u_long everywhere

ok kettenis@


Revision tags: OPENBSD_5_5_BASE
# 1.151 20-Feb-2014 kettenis

revert previous commit; didn't intend to commit those bits


# 1.150 20-Feb-2014 kettenis

Avoid printing the "nvram corrupt" message for onboard 2200s found on Sun
hardware.

ok dlg@, jmatthew@


# 1.149 04-Dec-2013 dlg

mfi_refresh_sensors calls mfi_ioctl_vol which calls mfi_bio_getitall, which
replaces pointers in the softc and all sorts of fun stuff. this protects
the call to bio_getitall with the sc_lock the ioctl path uses, so we dont
get panics like those reported on bugs@ recently.

ok deraadt@


# 1.148 23-Oct-2013 kettenis

Add support for displaying the cache write policy of RAID volumes to bioctl(8)
and make mfi(4) pass up the necessary information. Adding support for other
RAID controllers is left as an excercise to the reader.

ok deraadt@


# 1.147 09-Oct-2013 jmatthew

Include the 'state of health' field in the bbu ok sensor value.
The dell perc 6/i sets this to zero (meaning bad) when it
decides the battery doesn't have enough capacity for it to
allow write back mode, but doesn't set any of the other flags
to tell us why.

ok dlg@, tested by sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.146 18-May-2013 jmc

enw->new in comment;
spotted by krw, missed by jsg, and forwarded From: Alexey Suslikov


# 1.145 08-May-2013 jsg

fix some leaks in error paths
ok fgsch@ krw@ kettenis@


# 1.144 03-May-2013 dlg

break out the battery status into excruciating detail. makes it harder for
$VENDOR to complain about a lack of diagnostic material from their crappy
mgmt tools if you're not running an operating system they support.


# 1.143 02-May-2013 dlg

always attach the battery sensor if the adapter lets us query it.
newly replaced batteries dont show up immediately.


# 1.142 01-May-2013 dlg

provide a sensor for the battery backup unit (bbu) on mfi boards that
support it.

now i can tell (a bit better) why io might be slow on some of my boxes.


# 1.141 01-May-2013 dlg

dont need to walk alldevs during sensor creation looking for the logical
disk scsibus when we record that in mfi_attach.

also happens to get rid of a logic error that let it come out of the loop
on alldevs with a reference to something that wasnt the logical disk
scsibus and use that.


# 1.140 30-Apr-2013 dlg

use MR_DCMD consistently. some MD_DCMD was in there somehow.


# 1.139 07-Apr-2013 dlg

david imhoff points out that the error handling in mfi_init_ccb gets the
index to which ccb to free wrong.

this takes the logic from mpi/mpii/mfii which pulls the ready ccbs off
the free list rather than rely on the current index from the for loop
that we failed inside of.

thanks to david for finding this out.


Revision tags: OPENBSD_5_3_BASE
# 1.138 12-Sep-2012 haesbaert

Make sure we don't sleep on autoconf.

ok mikeb


# 1.137 17-Aug-2012 dlg

add support for "physical devices" on skinny controllers.

these controllers let you specify disks that should be accessed directly
rather than be part of logical volumes. apparently you can plug in things
like tape drives too.

anyway, physical devices are exposed via a separate scsibus attached to
mfi.

ok mikeb@


# 1.136 16-Aug-2012 dlg

fix mfi_poll by having it do delays between loops, and breaking on
timeouts. how embarrassment.

implement mfi_exec for doing sync executions of commands in process
contexts and cut mfi_mgmt over to it.


# 1.135 16-Aug-2012 dlg

rework mfi_poll so it will do all the completions on a ccb including
calling the done handler.

this makes it consistently complete scsi io with all the proper error
checking.


# 1.134 16-Aug-2012 dlg

stop passing mfi_softc around as a member of the ccb, consistently give it
as the first argument to functions. like mfii.


# 1.133 16-Aug-2012 dlg

scrub ccbs when we're about to use them, not when we put them back
on the free list. ccbs can be reused, so we dont want old state screwing up
new commands.


# 1.132 16-Aug-2012 dlg

move the dma syncs for the ccb data into ccb_done, so we can do it once
rather than put the code everywhere.


# 1.131 16-Aug-2012 dlg

fix up the dma sync for the command frame in mfi_done.


# 1.130 14-Aug-2012 dlg

use scsi_get_link to find out the name of a child device for bioctl rather
than snoop scsi commands and copy it in an io path.

no functional change, but the code has one less XXX now.


# 1.129 14-Aug-2012 dlg

expose the max number of logical volumes the hardware supports as the width
of its scsibus. only advertise 1 lun on logical volumes instead of letting
the midlayer fix it up to 8.

give every target on the bus max_cmds openings. iopools means they will
properly share access to them.

this in particular is useful on skinny controllers which only advertise 31
command slots. if you have 16 volumes, theyll only get 1 opening each with
the old maths. this way round the ones that are busy will share the slots.

tested on a perc5 with two volumes and hard workloads.


# 1.128 14-Aug-2012 dlg

print the boards name (eg, perc 5/i) according to the firmware like mfii.

ok deraadt@


# 1.127 14-Aug-2012 dlg

move knowledge of the location of the inbound doorbell out of code in
transition_firmware into a member of the iop structures.

ok mikeb@ haesbaert@


# 1.126 13-Aug-2012 dlg

get rid of the last foo_lo and foo_hi bits i could find in the hardware
structures and use htole64 instead of htole32(addr >> 32); htole32(addr);

gets rid of "handy" stack variables to get the dva to 64bits.

sprinkle some more byte swaps for things that should have it.

tested on a perc5 (xscale)


# 1.125 13-Aug-2012 dlg

do appropriate bus_dmamapy_syncs around the pcq/completion ring.

tested on a perc5 (xscale)


# 1.124 13-Aug-2012 dlg

replace uint32_ts for hi and lo addresses in the mfi_init_ hardware
descriptors with single uint64_ts. theyre not some weird middle
endian thing. this makes the code more readable.

add some missing htole32s to the code while here.

tested on a perc5 (xscale).


# 1.123 11-Aug-2012 dlg

the producer/consumer values are used by the device, which is little
endian. do appropriate byteswapping for when the host cpu uses them.

tested on a perc5 (xscale) in an amd64.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.122 12-Jan-2012 dlg

add support for skinny variants.

from Alexey Suslikov
reviewed by marco


Revision tags: OPENBSD_5_0_BASE
# 1.121 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.120 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.119 09-Apr-2011 marco

add all 64 bit dma plumbing but stick with 32 for now by default.

ok deraadt


# 1.118 09-Apr-2011 marco

make sure the upper 32 bits are always written to instead of assuming it
is 0.

ok deraadt.


# 1.117 08-Apr-2011 marco

kill some stray spaces


# 1.116 08-Apr-2011 marco

rename wiat channel to something less than 8 chars.

prompted by deraadt


# 1.115 08-Apr-2011 marco

use dma_alloc for transient management commands.

prodded and ok deraadt


Revision tags: OPENBSD_4_9_BASE
# 1.114 30-Dec-2010 dlg

cut mfi over to using iopools.

this gets rid of NO_CCB, provides better scheduling of io between busy
logical volumes on the same controller, and makes the ioctl and sensor
paths more reliable.

this is the least intrusive version of this change i could come up with. it
only took 4 or 5 goes...

ok marco@
deraadt@ says this is a good time for this change.


# 1.113 24-Sep-2010 dlg

no use setting cmd in mfi_ioctl_setstate if you never use it.


# 1.112 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


# 1.111 29-Aug-2010 dlg

the scsi completion code thinks that if you dont get MFI_STAT_OK
back from the chip on a command then the command completely failed.
MFI_STAT_SCSI_DONE_WITH_ERROR really means the command completed
fine, but there's some sense data too. this tweaks the handling to
be more appropriate, as per the linux and solaris drivers.

timed out waiting for beck@
putting this in cos its obviously more correct than the current code.


Revision tags: OPENBSD_4_8_BASE
# 1.110 22-Jul-2010 matthew

SCSI HBA drivers are supposed to get their SCSI CDBs from xs->cmd, not
xs->cmdstore.

ok krw@ a while back (contingent upon testing), and deraadt@ says this
has been in snapshots for weeks now.


# 1.109 01-Jul-2010 matthew

Change scsibus(4)'s scsi_link array to an SLIST to save memory on
sparsely populated buses.

ok dlg@, krw@


# 1.108 30-Jun-2010 mk

Use SLIST for the ccb free list.

ok krw, discontent grunts from marco.


# 1.107 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.106 15-Jun-2010 dlg

dont pass the dev_t from the scsi device drivers into the midlayer for
ioctl requests, and dont pass the proc pointers around for any ioctl
requests in scsi land at all. neither were used, so trim the fat.

ok krw@ marco@


# 1.105 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.104 16-May-2010 nicm

Use a temporary variable for now to sidestep -Wbounded checking when
copying vendor[8]/product[16]/revision[4] out of struct scsi_inquiry_data
together with one memcopy.

ok krw


# 1.103 22-Apr-2010 oga

use BUS_DMA_ZERO on alloc instead of bzeroing after.

ok dlg@, marco@


# 1.102 10-Apr-2010 marco

grrr var names in protos


# 1.101 10-Apr-2010 marco

sprinkle some bus_dmamap_sync around frame access.
prompted by oga


# 1.100 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.99 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.98 04-Jan-2010 dlg

rename ccb_xs to ccb_cookie and change its type from a scsi_xfer * to a
void *. this lets us pass things other than scsi_xfers to ccb completion
handlers.


# 1.97 04-Jan-2010 dlg

protect the ccb free queue with a mutex rather than splbio


# 1.96 03-Jan-2010 chl

change M_WAITOK --> M_WAITOK|M_CANFAIL

with input from marco@

ok marco@ krw@

this was ok looooooooong time ago but lost in my mailbox


Revision tags: OPENBSD_4_6_BASE
# 1.95 30-Apr-2009 marco

Add READ(16) & WRITE(16) commands.
ok krw


# 1.94 29-Apr-2009 marco

MFI_D_IOCTL should be commented out. No binary change.


# 1.93 04-Apr-2009 dlg

scrub more fields in the ccb when returning them to the free list after
theyve been used, in particular the mfi header flags which has a bit
that specifies if a command should be completed via the interrupt path.

if we use a ccb during boot we set that bit, but it isnt necessarily
cleared by things that use it later on. this means a ccb we expected to
complete via an interrupt never actually generates an interrupt or appears
in the reply queue. this obviously stalls the io.


# 1.92 29-Mar-2009 marco

spello


# 1.91 29-Mar-2009 dlg

when we steal the SYNC CACHE command in mfi_scsi_cmd we still have to
mark the xs as done and call scsi_done for it rather than just returning
COMPLETE.


# 1.90 29-Mar-2009 dlg

fix a small race in mfi_mgmt between the checking of a ccbs completion and
the sleep waiting for the completion. it is possible to get the interrupt
completing the command just before the tsleep, which will never get a
wakeup because the interrupt with the wakeup has already happened.


Revision tags: OPENBSD_4_5_BASE
# 1.89 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.


# 1.88 28-Jan-2009 marco

Add support for next generation megaraid sas raid controllers.
From Jim Giannoules <gortag@gmail.com>


# 1.87 31-Oct-2008 marco

Generalize function to obtain all details to do bio stuff. This is in
preparation to start showing unsused disks which will require all this
information to do the math.

While at it fix a size of hotspare volume bug.


# 1.86 30-Oct-2008 marco

Fix bug that when there are no volumes but there are hot spares it would
no show the hotspares.


# 1.85 28-Oct-2008 marco

Fix output when reporting on multivolume disk groups.

Reported by mitja@muzenic.net


# 1.84 27-Oct-2008 marco

Move some include stuff around


# 1.83 26-Oct-2008 marco

Space


# 1.82 23-Oct-2008 marco

Fix PR5645
ok dlg
tested beck and others


# 1.81 25-Sep-2008 krw

Initialize 'ssc' to NULL since we test it later. Shouldn't ever be
NULL at the point of test unless the device list is confused, but
be consistantly paranoid if we're going to be paranoid.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.80 16-Feb-2008 krw

Return NO_CCB and not TRY_AGAIN_LATER when running out of ccb's.
Eliminates 'not queued' errors reported on the mailing lists.

Tested by Michael (belenus at bsdmail dot de).

ok marco@


# 1.79 11-Feb-2008 dlg

add support for the mfi controllers with the ppc iops, aka, LSI SAS1078 or
Dell PERC6.

committed off a machine booting and rooting off a perc6. tested on a perc5
by marco@
ok marco@


# 1.78 26-Jan-2008 brad

Set the return value instead of returning right away so that the DMA
memory is actually synched.

ok dlg@


# 1.77 26-Jan-2008 dlg

sync dma mem back to the cpu on poll failure.

from mickey via pr5714


# 1.76 26-Jan-2008 dlg

despatch -> dispatch

disparate spellink fix from mickey


# 1.75 05-Nov-2007 krw

More scsi_done() at SPLBIO.


# 1.74 27-Sep-2007 chl

M_ZERO changes

ok dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.73 24-Jun-2007 dlg

rework sensor tasks to use the kernels generic workq rather than a special
kernel thread of its own. the api has changed (which will be fixed in the
manpage shortly) so all the users of sensor tasks that i can find have
been fixed too.

noone tested, so its going in to force people to run with it.
"put it in" deraadt@


# 1.72 29-May-2007 todd

sprinkle some SMALL_KERNEL to permit bio/softraid to run on boot media
ok marco@ then suggested deraadt@


# 1.71 22-Mar-2007 deraadt

split userland & kernel struct sensor/sensordev so that the addition
of new fields in the future is less disruptive. This is done similar
to how struct proc is handled for ps(1). ok jmc (man page changes)
tested fkr simon, and more suggestions from millert


Revision tags: OPENBSD_4_1_BASE
# 1.70 14-Feb-2007 dlg

bus_space does byte swapping to cope with host endianness for us, so remove
an unnecessary htole32().


# 1.69 13-Feb-2007 marco

Fix subtle x ? y : z bug when calling mfi_create_sgl. This worked because
during runtime the bug condition does not happen.

ok krw joris


# 1.68 08-Feb-2007 ray

Remove double semicolons.

From Pierre Riteau <pierre dot riteau at free dot fr>.

OK marco@.


# 1.67 23-Dec-2006 deraadt

adapt to new two-level sensor api; Constantine A. Murenin


# 1.66 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.65 31-Aug-2006 marco

Add sensor thread for individual sd devices.

tested dlg
ok dlg deraadt


# 1.64 30-Aug-2006 dlg

when determining the size of the volumes and disks we want how many
bytes each of them has, not the number of kilobytes. this solves the
"why am i dividing by 2" question. the answer is "you dont, you multiply
by 512".


# 1.63 28-Jul-2006 brad

make dmesg printing look a little bit nicer.


# 1.62 19-Jun-2006 marco

Factor for disk size is /2. Odd but tested on all mfis I have.


# 1.61 19-Jun-2006 miod

Everytime one forgets an argument in a printf-like function call, God kills
a kitten. Commiters, please think of the kittens when working on code.


# 1.60 19-Jun-2006 marco

Make a BGI (Back Ground Init) a scrub instead of rebuild.


# 1.59 19-Jun-2006 marco

Add hot spare support.


# 1.58 26-May-2006 marco

Add blinking for disks.


# 1.57 25-May-2006 marco

Move a int i; to top of function so that it compiles on non c99 compilers.
Pointed out by miod@

The enclosure id modifier didn't reflect reality so move it back to whatever
the raid card uses.


# 1.56 25-May-2006 marco

And add time and percentage to builds and check consistencies.


# 1.55 25-May-2006 marco

Add last bit of physcal disk stuff.
Remove bogus memset.
Hotspares still don't work.


# 1.54 25-May-2006 marco

Add physical device and read config structures.
Add initial part of BIOCDISK


# 1.53 23-May-2006 deraadt

commited with unused variable


# 1.52 23-May-2006 marco

Remove some debug cruft.


# 1.51 23-May-2006 marco

Add first half of physical disk data for bio.


# 1.50 22-May-2006 marco

Add support for raid 50 and 10 in bio.


# 1.49 22-May-2006 marco

Add mail box to mfi_mgmt to handle sub commands more gracefully.
Remove some debug crud that snuck in the TEST_UNIT_READY case.
Finish other half of BIOCVOL primitive.
Add several structures to fill out the BIOCVOL primitive.


# 1.48 22-May-2006 marco

Add first half of BIOCVOL primitive.


# 1.47 21-May-2006 marco

Do a giant flush of disk and raid-card memory when SYNCHONIZE_CACHE is called.


# 1.46 21-May-2006 marco

pretty up some debug statements.


# 1.45 21-May-2006 marco

Add bio alarm function.
Redo mfi_mgmt to deal with zero data commands.


# 1.44 21-May-2006 marco

Add generic management function.
Redo ccb_state flags so that we can actually sleep on it.
Redo mfi_get_info to use new mgmt function.
Add rw_locks for mgmt interface.
Make BIOCINQ dynamic.


# 1.43 21-May-2006 marco

Oops, helps to use the right structure field.
Use actual nr of physical disks present.


# 1.42 21-May-2006 marco

Add first BIOCINQ primitive.


# 1.41 18-May-2006 marco

Remove some debug cruft and pretty up some debug messages.


# 1.40 18-May-2006 marco

Kill splbio/splx in the interrupt handler.


# 1.39 18-May-2006 marco

And we have lift off! Was able to create a filesystem and write to the
filesystem.

Collapse both completion routines into one.
Fixup scsi error reporting in the completion routine.


# 1.38 17-May-2006 marco

Add completion routines.
Fix some bugs inside the interrupt handler.


# 1.37 17-May-2006 marco

Add mfi_get_info to obtain all kinds of fun information from the fw.
Print out whole info structure when debug is enabled.
Add a nice print with useful info during attach.


# 1.36 17-May-2006 marco

Refactor scsi path so that we can have a single sgl function for io and non-io
traffic.
Redo parameters on functions that were passing too many parameters around.


# 1.35 16-May-2006 marco

Nuke some { }


# 1.34 16-May-2006 marco

Move !xs->data case into mfi_start_xs.
Return proper sense data when a polling command fails.


# 1.33 16-May-2006 marco

Fix some more htole32 screw-ups.
Colapse all little SCSI functions into a single generic one.
Fix a bug in the SGE calculation.

This brings the driver up to post:
mfi0 at pci12 dev 14 function 0 "Dell PERC SAS" rev 0x00: Dell PERC 5/e irq 5
scsibus3 at mfi0: 2 targets
sd1 at scsibus3 targ 0 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd1: 237824MB, 237824 cyl, 64 head, 32 sec, 512 bytes/sec, 487063552 sec total
sd2 at scsibus3 targ 1 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd2: 34176MB, 34176 cyl, 64 head, 32 sec, 512 bytes/sec, 69992448 sec total


# 1.32 16-May-2006 marco

Fix some htole32 I missed.
Sprinkle more debug.


# 1.31 16-May-2006 marco

Add READ CAPACITY.


# 1.30 16-May-2006 marco

Oops PREREAD not PREWRITE.


# 1.29 16-May-2006 marco

Add TUR and make it send it directly to firmware.
Sprinkle some extra debug.


# 1.28 15-May-2006 marco

Clear all relevant ccb fields when mfi_put_ccb frees a ccb.


# 1.27 15-May-2006 marco

Oops don't send command twice to firmware when polling.


# 1.26 15-May-2006 marco

Add INQUIRY command.
Add sgl magic.


# 1.25 10-May-2006 marco

Add some airplane code.

add bio hooks.
add scsi entry point for io.


# 1.24 26-Apr-2006 marco

Fix some debug prints.


# 1.23 21-Apr-2006 marco

typo


# 1.22 21-Apr-2006 marco

Add mfi_poll and use the new shiny function to setup all the hardware queues.
Lots of ideas from the FreeBSD driver.


# 1.21 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.20 20-Apr-2006 dlg

marco hates typedefs as much as i do, so he asked me to clean mfi like i
just did with ami. this gets rid of the typedef for the ccb lists.

also uses TAILQ_FIRST to get ccbs off the freelist. this is a proactive
fix for a lint teary.


# 1.19 18-Apr-2006 marco

It helps to initialize a queue before usage.


# 1.18 18-Apr-2006 marco

Actually add ccbs to the queue.
Fix the error path for mfi_init_ccb.
Alter dmamap for io.


# 1.17 17-Apr-2006 marco

Sprinkle more debug. Remove 64 byte boundary; it doesn't seem to like it.
Hack around 64 byte boundary for the frames for now.


# 1.16 17-Apr-2006 marco

Setup ccbs and clean up ccb structure.


# 1.15 16-Apr-2006 marco

Oops, make mfi_allocmem always use 64 byte boundaries since frames have to
have that alignment. It doesn't matter for the other consumers of the
function.


# 1.14 16-Apr-2006 marco

Add frame memory and sglist allocation.


# 1.13 16-Apr-2006 marco

Make memory access use macro.


# 1.12 16-Apr-2006 marco

typo


# 1.11 16-Apr-2006 marco

Add get and put ccb functions. Shuffle some more definitions.


# 1.10 16-Apr-2006 marco

Nicer print when context is invalid.


# 1.9 16-Apr-2006 marco

Shuffle some #defines.
Fix comments.
Add human readable enable intrrupt #define.


# 1.8 16-Apr-2006 marco

Add interrupt handler. Idea borrowed from FreeBSD since it is much nicer
than the Linux one.


# 1.7 07-Apr-2006 marco

Replace bus_space functions with generic ones that do barriers.


# 1.6 07-Apr-2006 marco

Add memory allocator functions.


# 1.5 07-Apr-2006 marco

Print state in debug. Change return vales to 1 instead of ENXIO.


# 1.4 07-Apr-2006 marco

Make a better debug mechanism.


# 1.3 07-Apr-2006 marco

Enable mfi_transition_fw() original code from FreeBSD.


# 1.2 06-Apr-2006 marco

Add fw transition logic.


# 1.1 06-Apr-2006 marco

Add skeleton driver for MegaRAID SAS.


# 1.188 16-Apr-2022 naddy

constify SCSI adapter entry points

ok krw@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.187 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.186 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.185 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.184 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.183 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.182 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.181 13-Jul-2020 krw

Where we have a pointer (sc) to the relevant adapter_softc, use
&sc->sc_dev to get a device pointer rather than using the void *
whence we obtained 'sc'.


# 1.180 13-Jul-2020 krw

Remove some pointless casting of void * when assigning one
(scsi_link.adapter_softc) to a pointer of a particular softc type.


# 1.179 27-Jun-2020 krw

Nuke trailing whitespace.


# 1.178 27-Jun-2020 krw

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


# 1.177 24-Jun-2020 krw

Use SDEV_NO_ADAPTER_TARGET instead of -1 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.176 21-Mar-2020 krw

Simplify some goto'ing that jumps a single line or
does nothing at all.

The first one spotted as CID 1452976.

Reads good to millert@

ok mpi@


# 1.175 13-Feb-2020 krw

Nuke *_minphys() functions that either simply apply MAXPHYS or do
nothing at all. MAXPHYS will be applied in minphys() and nothing at
all, well, doesn't do anything.

Also remove any '#define <blah> MAXPHYS' statements used solely to
disguise MAXPHYS in said functions.


# 1.174 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.173 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.172 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.171 31-Dec-2019 mpi

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

ok kn@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.170 05-Mar-2019 jmatthew

apply background init progress fix from r1.59 of mfii.c
(reverting most of r1.60 of mfi.c, oddly enough)

ok dlg@
tested on a SAS2008 (perc h310)


Revision tags: OPENBSD_6_4_BASE
# 1.169 14-Aug-2018 jmatthew

return ENOTTY rather than EINVAL to indicate an ioctl hasn't been handled

ok dlg@ deraadt@ kettenis@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.168 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.167 02-Feb-2017 dlg

copy the mbox into the dcmd struct, not the pointer to the mbox.

makes bioctl work on mfi(4) again.

while here memset a few mboxes before using them.

bioctl breakage reported by jason george


# 1.166 23-Jan-2017 dlg

represent the mbox layout with union instead of an array of bytes.

memcpying uint16_ts into inconsistently addressed offsets is hard
to read, and this makes future work easier to implement.

tested on mfi(4) and mfii(4)


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.165 09-Sep-2015 deraadt

sizes for free(); ok sthen


Revision tags: OPENBSD_5_8_BASE
# 1.164 29-May-2015 uebayasi

Initial addition of ``Patrol Read'' support in bio(4), biocto(8), and
mfi(4). Based on FreeBSD, but done without mfiutil(8).

OK deraadt@


# 1.163 18-May-2015 mikeb

Prevent splassert from firing during sd_flush which runs "cold"

While mfi(4) should pass SCSI transfer flags (e.g. SCSI_POLL and
SCSI_NOSLEEP) down to the management function, make it at least
use "cold" consistently for now.

ok dlg


# 1.162 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.161 08-Mar-2015 dlg

properly set sgl related flags on skinny controllers. this fixes
io against physical disks on my dell perc h310s. logical disks still
work fine.

ok deraadt@ yasuoka@


# 1.160 08-Feb-2015 yasuoka

Fix mfi ioctl to set drive state properly.
diff from Tsubai Masanari

test dlg jmatthew
ok dlg


# 1.159 09-Jan-2015 yasuoka

Add support DIOC{G,S}CACHE to mfi(4). Cache of disk on mfi(4) will
be enabled by default. Also if the controller doesn't have any RAM,
the cache on the physical disk will be enabled.

discuss with jsg tsubai
ok dlg


# 1.158 19-Dec-2014 deraadt

another handful of bcopy -> memcpy because there is no overlap


# 1.157 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.156 09-Sep-2014 dlg

mark the interrupt handler mpsafe, and give up biglock in the scsi cmd
submission paths. take biglock again when calling back into the scsi
stack.

tested on a variety of cards here, including the skinny mfis on the
firewall next to mpsafe myx.


# 1.155 15-Aug-2014 yasuoka

Create a function which loads sgd in the mfi_iop_ops struct so that skinny
adapters can use "IEEE sgl".

tested dlg yasuoka
ok dlg jsg


Revision tags: OPENBSD_5_6_BASE
# 1.154 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.153 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.152 04-May-2014 sf

format string fixes for bus_addr_t and bus_size_t

bus_addr_t and bus_size_t are u_long everywhere

ok kettenis@


Revision tags: OPENBSD_5_5_BASE
# 1.151 20-Feb-2014 kettenis

revert previous commit; didn't intend to commit those bits


# 1.150 20-Feb-2014 kettenis

Avoid printing the "nvram corrupt" message for onboard 2200s found on Sun
hardware.

ok dlg@, jmatthew@


# 1.149 04-Dec-2013 dlg

mfi_refresh_sensors calls mfi_ioctl_vol which calls mfi_bio_getitall, which
replaces pointers in the softc and all sorts of fun stuff. this protects
the call to bio_getitall with the sc_lock the ioctl path uses, so we dont
get panics like those reported on bugs@ recently.

ok deraadt@


# 1.148 23-Oct-2013 kettenis

Add support for displaying the cache write policy of RAID volumes to bioctl(8)
and make mfi(4) pass up the necessary information. Adding support for other
RAID controllers is left as an excercise to the reader.

ok deraadt@


# 1.147 09-Oct-2013 jmatthew

Include the 'state of health' field in the bbu ok sensor value.
The dell perc 6/i sets this to zero (meaning bad) when it
decides the battery doesn't have enough capacity for it to
allow write back mode, but doesn't set any of the other flags
to tell us why.

ok dlg@, tested by sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.146 18-May-2013 jmc

enw->new in comment;
spotted by krw, missed by jsg, and forwarded From: Alexey Suslikov


# 1.145 08-May-2013 jsg

fix some leaks in error paths
ok fgsch@ krw@ kettenis@


# 1.144 03-May-2013 dlg

break out the battery status into excruciating detail. makes it harder for
$VENDOR to complain about a lack of diagnostic material from their crappy
mgmt tools if you're not running an operating system they support.


# 1.143 02-May-2013 dlg

always attach the battery sensor if the adapter lets us query it.
newly replaced batteries dont show up immediately.


# 1.142 01-May-2013 dlg

provide a sensor for the battery backup unit (bbu) on mfi boards that
support it.

now i can tell (a bit better) why io might be slow on some of my boxes.


# 1.141 01-May-2013 dlg

dont need to walk alldevs during sensor creation looking for the logical
disk scsibus when we record that in mfi_attach.

also happens to get rid of a logic error that let it come out of the loop
on alldevs with a reference to something that wasnt the logical disk
scsibus and use that.


# 1.140 30-Apr-2013 dlg

use MR_DCMD consistently. some MD_DCMD was in there somehow.


# 1.139 07-Apr-2013 dlg

david imhoff points out that the error handling in mfi_init_ccb gets the
index to which ccb to free wrong.

this takes the logic from mpi/mpii/mfii which pulls the ready ccbs off
the free list rather than rely on the current index from the for loop
that we failed inside of.

thanks to david for finding this out.


Revision tags: OPENBSD_5_3_BASE
# 1.138 12-Sep-2012 haesbaert

Make sure we don't sleep on autoconf.

ok mikeb


# 1.137 17-Aug-2012 dlg

add support for "physical devices" on skinny controllers.

these controllers let you specify disks that should be accessed directly
rather than be part of logical volumes. apparently you can plug in things
like tape drives too.

anyway, physical devices are exposed via a separate scsibus attached to
mfi.

ok mikeb@


# 1.136 16-Aug-2012 dlg

fix mfi_poll by having it do delays between loops, and breaking on
timeouts. how embarrassment.

implement mfi_exec for doing sync executions of commands in process
contexts and cut mfi_mgmt over to it.


# 1.135 16-Aug-2012 dlg

rework mfi_poll so it will do all the completions on a ccb including
calling the done handler.

this makes it consistently complete scsi io with all the proper error
checking.


# 1.134 16-Aug-2012 dlg

stop passing mfi_softc around as a member of the ccb, consistently give it
as the first argument to functions. like mfii.


# 1.133 16-Aug-2012 dlg

scrub ccbs when we're about to use them, not when we put them back
on the free list. ccbs can be reused, so we dont want old state screwing up
new commands.


# 1.132 16-Aug-2012 dlg

move the dma syncs for the ccb data into ccb_done, so we can do it once
rather than put the code everywhere.


# 1.131 16-Aug-2012 dlg

fix up the dma sync for the command frame in mfi_done.


# 1.130 14-Aug-2012 dlg

use scsi_get_link to find out the name of a child device for bioctl rather
than snoop scsi commands and copy it in an io path.

no functional change, but the code has one less XXX now.


# 1.129 14-Aug-2012 dlg

expose the max number of logical volumes the hardware supports as the width
of its scsibus. only advertise 1 lun on logical volumes instead of letting
the midlayer fix it up to 8.

give every target on the bus max_cmds openings. iopools means they will
properly share access to them.

this in particular is useful on skinny controllers which only advertise 31
command slots. if you have 16 volumes, theyll only get 1 opening each with
the old maths. this way round the ones that are busy will share the slots.

tested on a perc5 with two volumes and hard workloads.


# 1.128 14-Aug-2012 dlg

print the boards name (eg, perc 5/i) according to the firmware like mfii.

ok deraadt@


# 1.127 14-Aug-2012 dlg

move knowledge of the location of the inbound doorbell out of code in
transition_firmware into a member of the iop structures.

ok mikeb@ haesbaert@


# 1.126 13-Aug-2012 dlg

get rid of the last foo_lo and foo_hi bits i could find in the hardware
structures and use htole64 instead of htole32(addr >> 32); htole32(addr);

gets rid of "handy" stack variables to get the dva to 64bits.

sprinkle some more byte swaps for things that should have it.

tested on a perc5 (xscale)


# 1.125 13-Aug-2012 dlg

do appropriate bus_dmamapy_syncs around the pcq/completion ring.

tested on a perc5 (xscale)


# 1.124 13-Aug-2012 dlg

replace uint32_ts for hi and lo addresses in the mfi_init_ hardware
descriptors with single uint64_ts. theyre not some weird middle
endian thing. this makes the code more readable.

add some missing htole32s to the code while here.

tested on a perc5 (xscale).


# 1.123 11-Aug-2012 dlg

the producer/consumer values are used by the device, which is little
endian. do appropriate byteswapping for when the host cpu uses them.

tested on a perc5 (xscale) in an amd64.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.122 12-Jan-2012 dlg

add support for skinny variants.

from Alexey Suslikov
reviewed by marco


Revision tags: OPENBSD_5_0_BASE
# 1.121 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.120 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.119 09-Apr-2011 marco

add all 64 bit dma plumbing but stick with 32 for now by default.

ok deraadt


# 1.118 09-Apr-2011 marco

make sure the upper 32 bits are always written to instead of assuming it
is 0.

ok deraadt.


# 1.117 08-Apr-2011 marco

kill some stray spaces


# 1.116 08-Apr-2011 marco

rename wiat channel to something less than 8 chars.

prompted by deraadt


# 1.115 08-Apr-2011 marco

use dma_alloc for transient management commands.

prodded and ok deraadt


Revision tags: OPENBSD_4_9_BASE
# 1.114 30-Dec-2010 dlg

cut mfi over to using iopools.

this gets rid of NO_CCB, provides better scheduling of io between busy
logical volumes on the same controller, and makes the ioctl and sensor
paths more reliable.

this is the least intrusive version of this change i could come up with. it
only took 4 or 5 goes...

ok marco@
deraadt@ says this is a good time for this change.


# 1.113 24-Sep-2010 dlg

no use setting cmd in mfi_ioctl_setstate if you never use it.


# 1.112 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


# 1.111 29-Aug-2010 dlg

the scsi completion code thinks that if you dont get MFI_STAT_OK
back from the chip on a command then the command completely failed.
MFI_STAT_SCSI_DONE_WITH_ERROR really means the command completed
fine, but there's some sense data too. this tweaks the handling to
be more appropriate, as per the linux and solaris drivers.

timed out waiting for beck@
putting this in cos its obviously more correct than the current code.


Revision tags: OPENBSD_4_8_BASE
# 1.110 22-Jul-2010 matthew

SCSI HBA drivers are supposed to get their SCSI CDBs from xs->cmd, not
xs->cmdstore.

ok krw@ a while back (contingent upon testing), and deraadt@ says this
has been in snapshots for weeks now.


# 1.109 01-Jul-2010 matthew

Change scsibus(4)'s scsi_link array to an SLIST to save memory on
sparsely populated buses.

ok dlg@, krw@


# 1.108 30-Jun-2010 mk

Use SLIST for the ccb free list.

ok krw, discontent grunts from marco.


# 1.107 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.106 15-Jun-2010 dlg

dont pass the dev_t from the scsi device drivers into the midlayer for
ioctl requests, and dont pass the proc pointers around for any ioctl
requests in scsi land at all. neither were used, so trim the fat.

ok krw@ marco@


# 1.105 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.104 16-May-2010 nicm

Use a temporary variable for now to sidestep -Wbounded checking when
copying vendor[8]/product[16]/revision[4] out of struct scsi_inquiry_data
together with one memcopy.

ok krw


# 1.103 22-Apr-2010 oga

use BUS_DMA_ZERO on alloc instead of bzeroing after.

ok dlg@, marco@


# 1.102 10-Apr-2010 marco

grrr var names in protos


# 1.101 10-Apr-2010 marco

sprinkle some bus_dmamap_sync around frame access.
prompted by oga


# 1.100 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.99 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.98 04-Jan-2010 dlg

rename ccb_xs to ccb_cookie and change its type from a scsi_xfer * to a
void *. this lets us pass things other than scsi_xfers to ccb completion
handlers.


# 1.97 04-Jan-2010 dlg

protect the ccb free queue with a mutex rather than splbio


# 1.96 03-Jan-2010 chl

change M_WAITOK --> M_WAITOK|M_CANFAIL

with input from marco@

ok marco@ krw@

this was ok looooooooong time ago but lost in my mailbox


Revision tags: OPENBSD_4_6_BASE
# 1.95 30-Apr-2009 marco

Add READ(16) & WRITE(16) commands.
ok krw


# 1.94 29-Apr-2009 marco

MFI_D_IOCTL should be commented out. No binary change.


# 1.93 04-Apr-2009 dlg

scrub more fields in the ccb when returning them to the free list after
theyve been used, in particular the mfi header flags which has a bit
that specifies if a command should be completed via the interrupt path.

if we use a ccb during boot we set that bit, but it isnt necessarily
cleared by things that use it later on. this means a ccb we expected to
complete via an interrupt never actually generates an interrupt or appears
in the reply queue. this obviously stalls the io.


# 1.92 29-Mar-2009 marco

spello


# 1.91 29-Mar-2009 dlg

when we steal the SYNC CACHE command in mfi_scsi_cmd we still have to
mark the xs as done and call scsi_done for it rather than just returning
COMPLETE.


# 1.90 29-Mar-2009 dlg

fix a small race in mfi_mgmt between the checking of a ccbs completion and
the sleep waiting for the completion. it is possible to get the interrupt
completing the command just before the tsleep, which will never get a
wakeup because the interrupt with the wakeup has already happened.


Revision tags: OPENBSD_4_5_BASE
# 1.89 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.


# 1.88 28-Jan-2009 marco

Add support for next generation megaraid sas raid controllers.
From Jim Giannoules <gortag@gmail.com>


# 1.87 31-Oct-2008 marco

Generalize function to obtain all details to do bio stuff. This is in
preparation to start showing unsused disks which will require all this
information to do the math.

While at it fix a size of hotspare volume bug.


# 1.86 30-Oct-2008 marco

Fix bug that when there are no volumes but there are hot spares it would
no show the hotspares.


# 1.85 28-Oct-2008 marco

Fix output when reporting on multivolume disk groups.

Reported by mitja@muzenic.net


# 1.84 27-Oct-2008 marco

Move some include stuff around


# 1.83 26-Oct-2008 marco

Space


# 1.82 23-Oct-2008 marco

Fix PR5645
ok dlg
tested beck and others


# 1.81 25-Sep-2008 krw

Initialize 'ssc' to NULL since we test it later. Shouldn't ever be
NULL at the point of test unless the device list is confused, but
be consistantly paranoid if we're going to be paranoid.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.80 16-Feb-2008 krw

Return NO_CCB and not TRY_AGAIN_LATER when running out of ccb's.
Eliminates 'not queued' errors reported on the mailing lists.

Tested by Michael (belenus at bsdmail dot de).

ok marco@


# 1.79 11-Feb-2008 dlg

add support for the mfi controllers with the ppc iops, aka, LSI SAS1078 or
Dell PERC6.

committed off a machine booting and rooting off a perc6. tested on a perc5
by marco@
ok marco@


# 1.78 26-Jan-2008 brad

Set the return value instead of returning right away so that the DMA
memory is actually synched.

ok dlg@


# 1.77 26-Jan-2008 dlg

sync dma mem back to the cpu on poll failure.

from mickey via pr5714


# 1.76 26-Jan-2008 dlg

despatch -> dispatch

disparate spellink fix from mickey


# 1.75 05-Nov-2007 krw

More scsi_done() at SPLBIO.


# 1.74 27-Sep-2007 chl

M_ZERO changes

ok dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.73 24-Jun-2007 dlg

rework sensor tasks to use the kernels generic workq rather than a special
kernel thread of its own. the api has changed (which will be fixed in the
manpage shortly) so all the users of sensor tasks that i can find have
been fixed too.

noone tested, so its going in to force people to run with it.
"put it in" deraadt@


# 1.72 29-May-2007 todd

sprinkle some SMALL_KERNEL to permit bio/softraid to run on boot media
ok marco@ then suggested deraadt@


# 1.71 22-Mar-2007 deraadt

split userland & kernel struct sensor/sensordev so that the addition
of new fields in the future is less disruptive. This is done similar
to how struct proc is handled for ps(1). ok jmc (man page changes)
tested fkr simon, and more suggestions from millert


Revision tags: OPENBSD_4_1_BASE
# 1.70 14-Feb-2007 dlg

bus_space does byte swapping to cope with host endianness for us, so remove
an unnecessary htole32().


# 1.69 13-Feb-2007 marco

Fix subtle x ? y : z bug when calling mfi_create_sgl. This worked because
during runtime the bug condition does not happen.

ok krw joris


# 1.68 08-Feb-2007 ray

Remove double semicolons.

From Pierre Riteau <pierre dot riteau at free dot fr>.

OK marco@.


# 1.67 23-Dec-2006 deraadt

adapt to new two-level sensor api; Constantine A. Murenin


# 1.66 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.65 31-Aug-2006 marco

Add sensor thread for individual sd devices.

tested dlg
ok dlg deraadt


# 1.64 30-Aug-2006 dlg

when determining the size of the volumes and disks we want how many
bytes each of them has, not the number of kilobytes. this solves the
"why am i dividing by 2" question. the answer is "you dont, you multiply
by 512".


# 1.63 28-Jul-2006 brad

make dmesg printing look a little bit nicer.


# 1.62 19-Jun-2006 marco

Factor for disk size is /2. Odd but tested on all mfis I have.


# 1.61 19-Jun-2006 miod

Everytime one forgets an argument in a printf-like function call, God kills
a kitten. Commiters, please think of the kittens when working on code.


# 1.60 19-Jun-2006 marco

Make a BGI (Back Ground Init) a scrub instead of rebuild.


# 1.59 19-Jun-2006 marco

Add hot spare support.


# 1.58 26-May-2006 marco

Add blinking for disks.


# 1.57 25-May-2006 marco

Move a int i; to top of function so that it compiles on non c99 compilers.
Pointed out by miod@

The enclosure id modifier didn't reflect reality so move it back to whatever
the raid card uses.


# 1.56 25-May-2006 marco

And add time and percentage to builds and check consistencies.


# 1.55 25-May-2006 marco

Add last bit of physcal disk stuff.
Remove bogus memset.
Hotspares still don't work.


# 1.54 25-May-2006 marco

Add physical device and read config structures.
Add initial part of BIOCDISK


# 1.53 23-May-2006 deraadt

commited with unused variable


# 1.52 23-May-2006 marco

Remove some debug cruft.


# 1.51 23-May-2006 marco

Add first half of physical disk data for bio.


# 1.50 22-May-2006 marco

Add support for raid 50 and 10 in bio.


# 1.49 22-May-2006 marco

Add mail box to mfi_mgmt to handle sub commands more gracefully.
Remove some debug crud that snuck in the TEST_UNIT_READY case.
Finish other half of BIOCVOL primitive.
Add several structures to fill out the BIOCVOL primitive.


# 1.48 22-May-2006 marco

Add first half of BIOCVOL primitive.


# 1.47 21-May-2006 marco

Do a giant flush of disk and raid-card memory when SYNCHONIZE_CACHE is called.


# 1.46 21-May-2006 marco

pretty up some debug statements.


# 1.45 21-May-2006 marco

Add bio alarm function.
Redo mfi_mgmt to deal with zero data commands.


# 1.44 21-May-2006 marco

Add generic management function.
Redo ccb_state flags so that we can actually sleep on it.
Redo mfi_get_info to use new mgmt function.
Add rw_locks for mgmt interface.
Make BIOCINQ dynamic.


# 1.43 21-May-2006 marco

Oops, helps to use the right structure field.
Use actual nr of physical disks present.


# 1.42 21-May-2006 marco

Add first BIOCINQ primitive.


# 1.41 18-May-2006 marco

Remove some debug cruft and pretty up some debug messages.


# 1.40 18-May-2006 marco

Kill splbio/splx in the interrupt handler.


# 1.39 18-May-2006 marco

And we have lift off! Was able to create a filesystem and write to the
filesystem.

Collapse both completion routines into one.
Fixup scsi error reporting in the completion routine.


# 1.38 17-May-2006 marco

Add completion routines.
Fix some bugs inside the interrupt handler.


# 1.37 17-May-2006 marco

Add mfi_get_info to obtain all kinds of fun information from the fw.
Print out whole info structure when debug is enabled.
Add a nice print with useful info during attach.


# 1.36 17-May-2006 marco

Refactor scsi path so that we can have a single sgl function for io and non-io
traffic.
Redo parameters on functions that were passing too many parameters around.


# 1.35 16-May-2006 marco

Nuke some { }


# 1.34 16-May-2006 marco

Move !xs->data case into mfi_start_xs.
Return proper sense data when a polling command fails.


# 1.33 16-May-2006 marco

Fix some more htole32 screw-ups.
Colapse all little SCSI functions into a single generic one.
Fix a bug in the SGE calculation.

This brings the driver up to post:
mfi0 at pci12 dev 14 function 0 "Dell PERC SAS" rev 0x00: Dell PERC 5/e irq 5
scsibus3 at mfi0: 2 targets
sd1 at scsibus3 targ 0 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd1: 237824MB, 237824 cyl, 64 head, 32 sec, 512 bytes/sec, 487063552 sec total
sd2 at scsibus3 targ 1 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd2: 34176MB, 34176 cyl, 64 head, 32 sec, 512 bytes/sec, 69992448 sec total


# 1.32 16-May-2006 marco

Fix some htole32 I missed.
Sprinkle more debug.


# 1.31 16-May-2006 marco

Add READ CAPACITY.


# 1.30 16-May-2006 marco

Oops PREREAD not PREWRITE.


# 1.29 16-May-2006 marco

Add TUR and make it send it directly to firmware.
Sprinkle some extra debug.


# 1.28 15-May-2006 marco

Clear all relevant ccb fields when mfi_put_ccb frees a ccb.


# 1.27 15-May-2006 marco

Oops don't send command twice to firmware when polling.


# 1.26 15-May-2006 marco

Add INQUIRY command.
Add sgl magic.


# 1.25 10-May-2006 marco

Add some airplane code.

add bio hooks.
add scsi entry point for io.


# 1.24 26-Apr-2006 marco

Fix some debug prints.


# 1.23 21-Apr-2006 marco

typo


# 1.22 21-Apr-2006 marco

Add mfi_poll and use the new shiny function to setup all the hardware queues.
Lots of ideas from the FreeBSD driver.


# 1.21 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.20 20-Apr-2006 dlg

marco hates typedefs as much as i do, so he asked me to clean mfi like i
just did with ami. this gets rid of the typedef for the ccb lists.

also uses TAILQ_FIRST to get ccbs off the freelist. this is a proactive
fix for a lint teary.


# 1.19 18-Apr-2006 marco

It helps to initialize a queue before usage.


# 1.18 18-Apr-2006 marco

Actually add ccbs to the queue.
Fix the error path for mfi_init_ccb.
Alter dmamap for io.


# 1.17 17-Apr-2006 marco

Sprinkle more debug. Remove 64 byte boundary; it doesn't seem to like it.
Hack around 64 byte boundary for the frames for now.


# 1.16 17-Apr-2006 marco

Setup ccbs and clean up ccb structure.


# 1.15 16-Apr-2006 marco

Oops, make mfi_allocmem always use 64 byte boundaries since frames have to
have that alignment. It doesn't matter for the other consumers of the
function.


# 1.14 16-Apr-2006 marco

Add frame memory and sglist allocation.


# 1.13 16-Apr-2006 marco

Make memory access use macro.


# 1.12 16-Apr-2006 marco

typo


# 1.11 16-Apr-2006 marco

Add get and put ccb functions. Shuffle some more definitions.


# 1.10 16-Apr-2006 marco

Nicer print when context is invalid.


# 1.9 16-Apr-2006 marco

Shuffle some #defines.
Fix comments.
Add human readable enable intrrupt #define.


# 1.8 16-Apr-2006 marco

Add interrupt handler. Idea borrowed from FreeBSD since it is much nicer
than the Linux one.


# 1.7 07-Apr-2006 marco

Replace bus_space functions with generic ones that do barriers.


# 1.6 07-Apr-2006 marco

Add memory allocator functions.


# 1.5 07-Apr-2006 marco

Print state in debug. Change return vales to 1 instead of ENXIO.


# 1.4 07-Apr-2006 marco

Make a better debug mechanism.


# 1.3 07-Apr-2006 marco

Enable mfi_transition_fw() original code from FreeBSD.


# 1.2 06-Apr-2006 marco

Add fw transition logic.


# 1.1 06-Apr-2006 marco

Add skeleton driver for MegaRAID SAS.


# 1.187 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.186 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.185 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.184 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.183 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.182 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.181 13-Jul-2020 krw

Where we have a pointer (sc) to the relevant adapter_softc, use
&sc->sc_dev to get a device pointer rather than using the void *
whence we obtained 'sc'.


# 1.180 13-Jul-2020 krw

Remove some pointless casting of void * when assigning one
(scsi_link.adapter_softc) to a pointer of a particular softc type.


# 1.179 27-Jun-2020 krw

Nuke trailing whitespace.


# 1.178 27-Jun-2020 krw

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


# 1.177 24-Jun-2020 krw

Use SDEV_NO_ADAPTER_TARGET instead of -1 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.176 21-Mar-2020 krw

Simplify some goto'ing that jumps a single line or
does nothing at all.

The first one spotted as CID 1452976.

Reads good to millert@

ok mpi@


# 1.175 13-Feb-2020 krw

Nuke *_minphys() functions that either simply apply MAXPHYS or do
nothing at all. MAXPHYS will be applied in minphys() and nothing at
all, well, doesn't do anything.

Also remove any '#define <blah> MAXPHYS' statements used solely to
disguise MAXPHYS in said functions.


# 1.174 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.173 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.172 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.171 31-Dec-2019 mpi

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

ok kn@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.170 05-Mar-2019 jmatthew

apply background init progress fix from r1.59 of mfii.c
(reverting most of r1.60 of mfi.c, oddly enough)

ok dlg@
tested on a SAS2008 (perc h310)


Revision tags: OPENBSD_6_4_BASE
# 1.169 14-Aug-2018 jmatthew

return ENOTTY rather than EINVAL to indicate an ioctl hasn't been handled

ok dlg@ deraadt@ kettenis@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.168 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.167 02-Feb-2017 dlg

copy the mbox into the dcmd struct, not the pointer to the mbox.

makes bioctl work on mfi(4) again.

while here memset a few mboxes before using them.

bioctl breakage reported by jason george


# 1.166 23-Jan-2017 dlg

represent the mbox layout with union instead of an array of bytes.

memcpying uint16_ts into inconsistently addressed offsets is hard
to read, and this makes future work easier to implement.

tested on mfi(4) and mfii(4)


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.165 09-Sep-2015 deraadt

sizes for free(); ok sthen


Revision tags: OPENBSD_5_8_BASE
# 1.164 29-May-2015 uebayasi

Initial addition of ``Patrol Read'' support in bio(4), biocto(8), and
mfi(4). Based on FreeBSD, but done without mfiutil(8).

OK deraadt@


# 1.163 18-May-2015 mikeb

Prevent splassert from firing during sd_flush which runs "cold"

While mfi(4) should pass SCSI transfer flags (e.g. SCSI_POLL and
SCSI_NOSLEEP) down to the management function, make it at least
use "cold" consistently for now.

ok dlg


# 1.162 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.161 08-Mar-2015 dlg

properly set sgl related flags on skinny controllers. this fixes
io against physical disks on my dell perc h310s. logical disks still
work fine.

ok deraadt@ yasuoka@


# 1.160 08-Feb-2015 yasuoka

Fix mfi ioctl to set drive state properly.
diff from Tsubai Masanari

test dlg jmatthew
ok dlg


# 1.159 09-Jan-2015 yasuoka

Add support DIOC{G,S}CACHE to mfi(4). Cache of disk on mfi(4) will
be enabled by default. Also if the controller doesn't have any RAM,
the cache on the physical disk will be enabled.

discuss with jsg tsubai
ok dlg


# 1.158 19-Dec-2014 deraadt

another handful of bcopy -> memcpy because there is no overlap


# 1.157 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.156 09-Sep-2014 dlg

mark the interrupt handler mpsafe, and give up biglock in the scsi cmd
submission paths. take biglock again when calling back into the scsi
stack.

tested on a variety of cards here, including the skinny mfis on the
firewall next to mpsafe myx.


# 1.155 15-Aug-2014 yasuoka

Create a function which loads sgd in the mfi_iop_ops struct so that skinny
adapters can use "IEEE sgl".

tested dlg yasuoka
ok dlg jsg


Revision tags: OPENBSD_5_6_BASE
# 1.154 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.153 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.152 04-May-2014 sf

format string fixes for bus_addr_t and bus_size_t

bus_addr_t and bus_size_t are u_long everywhere

ok kettenis@


Revision tags: OPENBSD_5_5_BASE
# 1.151 20-Feb-2014 kettenis

revert previous commit; didn't intend to commit those bits


# 1.150 20-Feb-2014 kettenis

Avoid printing the "nvram corrupt" message for onboard 2200s found on Sun
hardware.

ok dlg@, jmatthew@


# 1.149 04-Dec-2013 dlg

mfi_refresh_sensors calls mfi_ioctl_vol which calls mfi_bio_getitall, which
replaces pointers in the softc and all sorts of fun stuff. this protects
the call to bio_getitall with the sc_lock the ioctl path uses, so we dont
get panics like those reported on bugs@ recently.

ok deraadt@


# 1.148 23-Oct-2013 kettenis

Add support for displaying the cache write policy of RAID volumes to bioctl(8)
and make mfi(4) pass up the necessary information. Adding support for other
RAID controllers is left as an excercise to the reader.

ok deraadt@


# 1.147 09-Oct-2013 jmatthew

Include the 'state of health' field in the bbu ok sensor value.
The dell perc 6/i sets this to zero (meaning bad) when it
decides the battery doesn't have enough capacity for it to
allow write back mode, but doesn't set any of the other flags
to tell us why.

ok dlg@, tested by sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.146 18-May-2013 jmc

enw->new in comment;
spotted by krw, missed by jsg, and forwarded From: Alexey Suslikov


# 1.145 08-May-2013 jsg

fix some leaks in error paths
ok fgsch@ krw@ kettenis@


# 1.144 03-May-2013 dlg

break out the battery status into excruciating detail. makes it harder for
$VENDOR to complain about a lack of diagnostic material from their crappy
mgmt tools if you're not running an operating system they support.


# 1.143 02-May-2013 dlg

always attach the battery sensor if the adapter lets us query it.
newly replaced batteries dont show up immediately.


# 1.142 01-May-2013 dlg

provide a sensor for the battery backup unit (bbu) on mfi boards that
support it.

now i can tell (a bit better) why io might be slow on some of my boxes.


# 1.141 01-May-2013 dlg

dont need to walk alldevs during sensor creation looking for the logical
disk scsibus when we record that in mfi_attach.

also happens to get rid of a logic error that let it come out of the loop
on alldevs with a reference to something that wasnt the logical disk
scsibus and use that.


# 1.140 30-Apr-2013 dlg

use MR_DCMD consistently. some MD_DCMD was in there somehow.


# 1.139 07-Apr-2013 dlg

david imhoff points out that the error handling in mfi_init_ccb gets the
index to which ccb to free wrong.

this takes the logic from mpi/mpii/mfii which pulls the ready ccbs off
the free list rather than rely on the current index from the for loop
that we failed inside of.

thanks to david for finding this out.


Revision tags: OPENBSD_5_3_BASE
# 1.138 12-Sep-2012 haesbaert

Make sure we don't sleep on autoconf.

ok mikeb


# 1.137 17-Aug-2012 dlg

add support for "physical devices" on skinny controllers.

these controllers let you specify disks that should be accessed directly
rather than be part of logical volumes. apparently you can plug in things
like tape drives too.

anyway, physical devices are exposed via a separate scsibus attached to
mfi.

ok mikeb@


# 1.136 16-Aug-2012 dlg

fix mfi_poll by having it do delays between loops, and breaking on
timeouts. how embarrassment.

implement mfi_exec for doing sync executions of commands in process
contexts and cut mfi_mgmt over to it.


# 1.135 16-Aug-2012 dlg

rework mfi_poll so it will do all the completions on a ccb including
calling the done handler.

this makes it consistently complete scsi io with all the proper error
checking.


# 1.134 16-Aug-2012 dlg

stop passing mfi_softc around as a member of the ccb, consistently give it
as the first argument to functions. like mfii.


# 1.133 16-Aug-2012 dlg

scrub ccbs when we're about to use them, not when we put them back
on the free list. ccbs can be reused, so we dont want old state screwing up
new commands.


# 1.132 16-Aug-2012 dlg

move the dma syncs for the ccb data into ccb_done, so we can do it once
rather than put the code everywhere.


# 1.131 16-Aug-2012 dlg

fix up the dma sync for the command frame in mfi_done.


# 1.130 14-Aug-2012 dlg

use scsi_get_link to find out the name of a child device for bioctl rather
than snoop scsi commands and copy it in an io path.

no functional change, but the code has one less XXX now.


# 1.129 14-Aug-2012 dlg

expose the max number of logical volumes the hardware supports as the width
of its scsibus. only advertise 1 lun on logical volumes instead of letting
the midlayer fix it up to 8.

give every target on the bus max_cmds openings. iopools means they will
properly share access to them.

this in particular is useful on skinny controllers which only advertise 31
command slots. if you have 16 volumes, theyll only get 1 opening each with
the old maths. this way round the ones that are busy will share the slots.

tested on a perc5 with two volumes and hard workloads.


# 1.128 14-Aug-2012 dlg

print the boards name (eg, perc 5/i) according to the firmware like mfii.

ok deraadt@


# 1.127 14-Aug-2012 dlg

move knowledge of the location of the inbound doorbell out of code in
transition_firmware into a member of the iop structures.

ok mikeb@ haesbaert@


# 1.126 13-Aug-2012 dlg

get rid of the last foo_lo and foo_hi bits i could find in the hardware
structures and use htole64 instead of htole32(addr >> 32); htole32(addr);

gets rid of "handy" stack variables to get the dva to 64bits.

sprinkle some more byte swaps for things that should have it.

tested on a perc5 (xscale)


# 1.125 13-Aug-2012 dlg

do appropriate bus_dmamapy_syncs around the pcq/completion ring.

tested on a perc5 (xscale)


# 1.124 13-Aug-2012 dlg

replace uint32_ts for hi and lo addresses in the mfi_init_ hardware
descriptors with single uint64_ts. theyre not some weird middle
endian thing. this makes the code more readable.

add some missing htole32s to the code while here.

tested on a perc5 (xscale).


# 1.123 11-Aug-2012 dlg

the producer/consumer values are used by the device, which is little
endian. do appropriate byteswapping for when the host cpu uses them.

tested on a perc5 (xscale) in an amd64.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.122 12-Jan-2012 dlg

add support for skinny variants.

from Alexey Suslikov
reviewed by marco


Revision tags: OPENBSD_5_0_BASE
# 1.121 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.120 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.119 09-Apr-2011 marco

add all 64 bit dma plumbing but stick with 32 for now by default.

ok deraadt


# 1.118 09-Apr-2011 marco

make sure the upper 32 bits are always written to instead of assuming it
is 0.

ok deraadt.


# 1.117 08-Apr-2011 marco

kill some stray spaces


# 1.116 08-Apr-2011 marco

rename wiat channel to something less than 8 chars.

prompted by deraadt


# 1.115 08-Apr-2011 marco

use dma_alloc for transient management commands.

prodded and ok deraadt


Revision tags: OPENBSD_4_9_BASE
# 1.114 30-Dec-2010 dlg

cut mfi over to using iopools.

this gets rid of NO_CCB, provides better scheduling of io between busy
logical volumes on the same controller, and makes the ioctl and sensor
paths more reliable.

this is the least intrusive version of this change i could come up with. it
only took 4 or 5 goes...

ok marco@
deraadt@ says this is a good time for this change.


# 1.113 24-Sep-2010 dlg

no use setting cmd in mfi_ioctl_setstate if you never use it.


# 1.112 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


# 1.111 29-Aug-2010 dlg

the scsi completion code thinks that if you dont get MFI_STAT_OK
back from the chip on a command then the command completely failed.
MFI_STAT_SCSI_DONE_WITH_ERROR really means the command completed
fine, but there's some sense data too. this tweaks the handling to
be more appropriate, as per the linux and solaris drivers.

timed out waiting for beck@
putting this in cos its obviously more correct than the current code.


Revision tags: OPENBSD_4_8_BASE
# 1.110 22-Jul-2010 matthew

SCSI HBA drivers are supposed to get their SCSI CDBs from xs->cmd, not
xs->cmdstore.

ok krw@ a while back (contingent upon testing), and deraadt@ says this
has been in snapshots for weeks now.


# 1.109 01-Jul-2010 matthew

Change scsibus(4)'s scsi_link array to an SLIST to save memory on
sparsely populated buses.

ok dlg@, krw@


# 1.108 30-Jun-2010 mk

Use SLIST for the ccb free list.

ok krw, discontent grunts from marco.


# 1.107 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.106 15-Jun-2010 dlg

dont pass the dev_t from the scsi device drivers into the midlayer for
ioctl requests, and dont pass the proc pointers around for any ioctl
requests in scsi land at all. neither were used, so trim the fat.

ok krw@ marco@


# 1.105 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.104 16-May-2010 nicm

Use a temporary variable for now to sidestep -Wbounded checking when
copying vendor[8]/product[16]/revision[4] out of struct scsi_inquiry_data
together with one memcopy.

ok krw


# 1.103 22-Apr-2010 oga

use BUS_DMA_ZERO on alloc instead of bzeroing after.

ok dlg@, marco@


# 1.102 10-Apr-2010 marco

grrr var names in protos


# 1.101 10-Apr-2010 marco

sprinkle some bus_dmamap_sync around frame access.
prompted by oga


# 1.100 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.99 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.98 04-Jan-2010 dlg

rename ccb_xs to ccb_cookie and change its type from a scsi_xfer * to a
void *. this lets us pass things other than scsi_xfers to ccb completion
handlers.


# 1.97 04-Jan-2010 dlg

protect the ccb free queue with a mutex rather than splbio


# 1.96 03-Jan-2010 chl

change M_WAITOK --> M_WAITOK|M_CANFAIL

with input from marco@

ok marco@ krw@

this was ok looooooooong time ago but lost in my mailbox


Revision tags: OPENBSD_4_6_BASE
# 1.95 30-Apr-2009 marco

Add READ(16) & WRITE(16) commands.
ok krw


# 1.94 29-Apr-2009 marco

MFI_D_IOCTL should be commented out. No binary change.


# 1.93 04-Apr-2009 dlg

scrub more fields in the ccb when returning them to the free list after
theyve been used, in particular the mfi header flags which has a bit
that specifies if a command should be completed via the interrupt path.

if we use a ccb during boot we set that bit, but it isnt necessarily
cleared by things that use it later on. this means a ccb we expected to
complete via an interrupt never actually generates an interrupt or appears
in the reply queue. this obviously stalls the io.


# 1.92 29-Mar-2009 marco

spello


# 1.91 29-Mar-2009 dlg

when we steal the SYNC CACHE command in mfi_scsi_cmd we still have to
mark the xs as done and call scsi_done for it rather than just returning
COMPLETE.


# 1.90 29-Mar-2009 dlg

fix a small race in mfi_mgmt between the checking of a ccbs completion and
the sleep waiting for the completion. it is possible to get the interrupt
completing the command just before the tsleep, which will never get a
wakeup because the interrupt with the wakeup has already happened.


Revision tags: OPENBSD_4_5_BASE
# 1.89 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.


# 1.88 28-Jan-2009 marco

Add support for next generation megaraid sas raid controllers.
From Jim Giannoules <gortag@gmail.com>


# 1.87 31-Oct-2008 marco

Generalize function to obtain all details to do bio stuff. This is in
preparation to start showing unsused disks which will require all this
information to do the math.

While at it fix a size of hotspare volume bug.


# 1.86 30-Oct-2008 marco

Fix bug that when there are no volumes but there are hot spares it would
no show the hotspares.


# 1.85 28-Oct-2008 marco

Fix output when reporting on multivolume disk groups.

Reported by mitja@muzenic.net


# 1.84 27-Oct-2008 marco

Move some include stuff around


# 1.83 26-Oct-2008 marco

Space


# 1.82 23-Oct-2008 marco

Fix PR5645
ok dlg
tested beck and others


# 1.81 25-Sep-2008 krw

Initialize 'ssc' to NULL since we test it later. Shouldn't ever be
NULL at the point of test unless the device list is confused, but
be consistantly paranoid if we're going to be paranoid.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.80 16-Feb-2008 krw

Return NO_CCB and not TRY_AGAIN_LATER when running out of ccb's.
Eliminates 'not queued' errors reported on the mailing lists.

Tested by Michael (belenus at bsdmail dot de).

ok marco@


# 1.79 11-Feb-2008 dlg

add support for the mfi controllers with the ppc iops, aka, LSI SAS1078 or
Dell PERC6.

committed off a machine booting and rooting off a perc6. tested on a perc5
by marco@
ok marco@


# 1.78 26-Jan-2008 brad

Set the return value instead of returning right away so that the DMA
memory is actually synched.

ok dlg@


# 1.77 26-Jan-2008 dlg

sync dma mem back to the cpu on poll failure.

from mickey via pr5714


# 1.76 26-Jan-2008 dlg

despatch -> dispatch

disparate spellink fix from mickey


# 1.75 05-Nov-2007 krw

More scsi_done() at SPLBIO.


# 1.74 27-Sep-2007 chl

M_ZERO changes

ok dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.73 24-Jun-2007 dlg

rework sensor tasks to use the kernels generic workq rather than a special
kernel thread of its own. the api has changed (which will be fixed in the
manpage shortly) so all the users of sensor tasks that i can find have
been fixed too.

noone tested, so its going in to force people to run with it.
"put it in" deraadt@


# 1.72 29-May-2007 todd

sprinkle some SMALL_KERNEL to permit bio/softraid to run on boot media
ok marco@ then suggested deraadt@


# 1.71 22-Mar-2007 deraadt

split userland & kernel struct sensor/sensordev so that the addition
of new fields in the future is less disruptive. This is done similar
to how struct proc is handled for ps(1). ok jmc (man page changes)
tested fkr simon, and more suggestions from millert


Revision tags: OPENBSD_4_1_BASE
# 1.70 14-Feb-2007 dlg

bus_space does byte swapping to cope with host endianness for us, so remove
an unnecessary htole32().


# 1.69 13-Feb-2007 marco

Fix subtle x ? y : z bug when calling mfi_create_sgl. This worked because
during runtime the bug condition does not happen.

ok krw joris


# 1.68 08-Feb-2007 ray

Remove double semicolons.

From Pierre Riteau <pierre dot riteau at free dot fr>.

OK marco@.


# 1.67 23-Dec-2006 deraadt

adapt to new two-level sensor api; Constantine A. Murenin


# 1.66 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.65 31-Aug-2006 marco

Add sensor thread for individual sd devices.

tested dlg
ok dlg deraadt


# 1.64 30-Aug-2006 dlg

when determining the size of the volumes and disks we want how many
bytes each of them has, not the number of kilobytes. this solves the
"why am i dividing by 2" question. the answer is "you dont, you multiply
by 512".


# 1.63 28-Jul-2006 brad

make dmesg printing look a little bit nicer.


# 1.62 19-Jun-2006 marco

Factor for disk size is /2. Odd but tested on all mfis I have.


# 1.61 19-Jun-2006 miod

Everytime one forgets an argument in a printf-like function call, God kills
a kitten. Commiters, please think of the kittens when working on code.


# 1.60 19-Jun-2006 marco

Make a BGI (Back Ground Init) a scrub instead of rebuild.


# 1.59 19-Jun-2006 marco

Add hot spare support.


# 1.58 26-May-2006 marco

Add blinking for disks.


# 1.57 25-May-2006 marco

Move a int i; to top of function so that it compiles on non c99 compilers.
Pointed out by miod@

The enclosure id modifier didn't reflect reality so move it back to whatever
the raid card uses.


# 1.56 25-May-2006 marco

And add time and percentage to builds and check consistencies.


# 1.55 25-May-2006 marco

Add last bit of physcal disk stuff.
Remove bogus memset.
Hotspares still don't work.


# 1.54 25-May-2006 marco

Add physical device and read config structures.
Add initial part of BIOCDISK


# 1.53 23-May-2006 deraadt

commited with unused variable


# 1.52 23-May-2006 marco

Remove some debug cruft.


# 1.51 23-May-2006 marco

Add first half of physical disk data for bio.


# 1.50 22-May-2006 marco

Add support for raid 50 and 10 in bio.


# 1.49 22-May-2006 marco

Add mail box to mfi_mgmt to handle sub commands more gracefully.
Remove some debug crud that snuck in the TEST_UNIT_READY case.
Finish other half of BIOCVOL primitive.
Add several structures to fill out the BIOCVOL primitive.


# 1.48 22-May-2006 marco

Add first half of BIOCVOL primitive.


# 1.47 21-May-2006 marco

Do a giant flush of disk and raid-card memory when SYNCHONIZE_CACHE is called.


# 1.46 21-May-2006 marco

pretty up some debug statements.


# 1.45 21-May-2006 marco

Add bio alarm function.
Redo mfi_mgmt to deal with zero data commands.


# 1.44 21-May-2006 marco

Add generic management function.
Redo ccb_state flags so that we can actually sleep on it.
Redo mfi_get_info to use new mgmt function.
Add rw_locks for mgmt interface.
Make BIOCINQ dynamic.


# 1.43 21-May-2006 marco

Oops, helps to use the right structure field.
Use actual nr of physical disks present.


# 1.42 21-May-2006 marco

Add first BIOCINQ primitive.


# 1.41 18-May-2006 marco

Remove some debug cruft and pretty up some debug messages.


# 1.40 18-May-2006 marco

Kill splbio/splx in the interrupt handler.


# 1.39 18-May-2006 marco

And we have lift off! Was able to create a filesystem and write to the
filesystem.

Collapse both completion routines into one.
Fixup scsi error reporting in the completion routine.


# 1.38 17-May-2006 marco

Add completion routines.
Fix some bugs inside the interrupt handler.


# 1.37 17-May-2006 marco

Add mfi_get_info to obtain all kinds of fun information from the fw.
Print out whole info structure when debug is enabled.
Add a nice print with useful info during attach.


# 1.36 17-May-2006 marco

Refactor scsi path so that we can have a single sgl function for io and non-io
traffic.
Redo parameters on functions that were passing too many parameters around.


# 1.35 16-May-2006 marco

Nuke some { }


# 1.34 16-May-2006 marco

Move !xs->data case into mfi_start_xs.
Return proper sense data when a polling command fails.


# 1.33 16-May-2006 marco

Fix some more htole32 screw-ups.
Colapse all little SCSI functions into a single generic one.
Fix a bug in the SGE calculation.

This brings the driver up to post:
mfi0 at pci12 dev 14 function 0 "Dell PERC SAS" rev 0x00: Dell PERC 5/e irq 5
scsibus3 at mfi0: 2 targets
sd1 at scsibus3 targ 0 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd1: 237824MB, 237824 cyl, 64 head, 32 sec, 512 bytes/sec, 487063552 sec total
sd2 at scsibus3 targ 1 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd2: 34176MB, 34176 cyl, 64 head, 32 sec, 512 bytes/sec, 69992448 sec total


# 1.32 16-May-2006 marco

Fix some htole32 I missed.
Sprinkle more debug.


# 1.31 16-May-2006 marco

Add READ CAPACITY.


# 1.30 16-May-2006 marco

Oops PREREAD not PREWRITE.


# 1.29 16-May-2006 marco

Add TUR and make it send it directly to firmware.
Sprinkle some extra debug.


# 1.28 15-May-2006 marco

Clear all relevant ccb fields when mfi_put_ccb frees a ccb.


# 1.27 15-May-2006 marco

Oops don't send command twice to firmware when polling.


# 1.26 15-May-2006 marco

Add INQUIRY command.
Add sgl magic.


# 1.25 10-May-2006 marco

Add some airplane code.

add bio hooks.
add scsi entry point for io.


# 1.24 26-Apr-2006 marco

Fix some debug prints.


# 1.23 21-Apr-2006 marco

typo


# 1.22 21-Apr-2006 marco

Add mfi_poll and use the new shiny function to setup all the hardware queues.
Lots of ideas from the FreeBSD driver.


# 1.21 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.20 20-Apr-2006 dlg

marco hates typedefs as much as i do, so he asked me to clean mfi like i
just did with ami. this gets rid of the typedef for the ccb lists.

also uses TAILQ_FIRST to get ccbs off the freelist. this is a proactive
fix for a lint teary.


# 1.19 18-Apr-2006 marco

It helps to initialize a queue before usage.


# 1.18 18-Apr-2006 marco

Actually add ccbs to the queue.
Fix the error path for mfi_init_ccb.
Alter dmamap for io.


# 1.17 17-Apr-2006 marco

Sprinkle more debug. Remove 64 byte boundary; it doesn't seem to like it.
Hack around 64 byte boundary for the frames for now.


# 1.16 17-Apr-2006 marco

Setup ccbs and clean up ccb structure.


# 1.15 16-Apr-2006 marco

Oops, make mfi_allocmem always use 64 byte boundaries since frames have to
have that alignment. It doesn't matter for the other consumers of the
function.


# 1.14 16-Apr-2006 marco

Add frame memory and sglist allocation.


# 1.13 16-Apr-2006 marco

Make memory access use macro.


# 1.12 16-Apr-2006 marco

typo


# 1.11 16-Apr-2006 marco

Add get and put ccb functions. Shuffle some more definitions.


# 1.10 16-Apr-2006 marco

Nicer print when context is invalid.


# 1.9 16-Apr-2006 marco

Shuffle some #defines.
Fix comments.
Add human readable enable intrrupt #define.


# 1.8 16-Apr-2006 marco

Add interrupt handler. Idea borrowed from FreeBSD since it is much nicer
than the Linux one.


# 1.7 07-Apr-2006 marco

Replace bus_space functions with generic ones that do barriers.


# 1.6 07-Apr-2006 marco

Add memory allocator functions.


# 1.5 07-Apr-2006 marco

Print state in debug. Change return vales to 1 instead of ENXIO.


# 1.4 07-Apr-2006 marco

Make a better debug mechanism.


# 1.3 07-Apr-2006 marco

Enable mfi_transition_fw() original code from FreeBSD.


# 1.2 06-Apr-2006 marco

Add fw transition logic.


# 1.1 06-Apr-2006 marco

Add skeleton driver for MegaRAID SAS.


# 1.186 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.185 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.184 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.183 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.182 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.181 13-Jul-2020 krw

Where we have a pointer (sc) to the relevant adapter_softc, use
&sc->sc_dev to get a device pointer rather than using the void *
whence we obtained 'sc'.


# 1.180 13-Jul-2020 krw

Remove some pointless casting of void * when assigning one
(scsi_link.adapter_softc) to a pointer of a particular softc type.


# 1.179 27-Jun-2020 krw

Nuke trailing whitespace.


# 1.178 27-Jun-2020 krw

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


# 1.177 24-Jun-2020 krw

Use SDEV_NO_ADAPTER_TARGET instead of -1 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.176 21-Mar-2020 krw

Simplify some goto'ing that jumps a single line or
does nothing at all.

The first one spotted as CID 1452976.

Reads good to millert@

ok mpi@


# 1.175 13-Feb-2020 krw

Nuke *_minphys() functions that either simply apply MAXPHYS or do
nothing at all. MAXPHYS will be applied in minphys() and nothing at
all, well, doesn't do anything.

Also remove any '#define <blah> MAXPHYS' statements used solely to
disguise MAXPHYS in said functions.


# 1.174 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.173 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.172 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.171 31-Dec-2019 mpi

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

ok kn@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.170 05-Mar-2019 jmatthew

apply background init progress fix from r1.59 of mfii.c
(reverting most of r1.60 of mfi.c, oddly enough)

ok dlg@
tested on a SAS2008 (perc h310)


Revision tags: OPENBSD_6_4_BASE
# 1.169 14-Aug-2018 jmatthew

return ENOTTY rather than EINVAL to indicate an ioctl hasn't been handled

ok dlg@ deraadt@ kettenis@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.168 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.167 02-Feb-2017 dlg

copy the mbox into the dcmd struct, not the pointer to the mbox.

makes bioctl work on mfi(4) again.

while here memset a few mboxes before using them.

bioctl breakage reported by jason george


# 1.166 23-Jan-2017 dlg

represent the mbox layout with union instead of an array of bytes.

memcpying uint16_ts into inconsistently addressed offsets is hard
to read, and this makes future work easier to implement.

tested on mfi(4) and mfii(4)


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.165 09-Sep-2015 deraadt

sizes for free(); ok sthen


Revision tags: OPENBSD_5_8_BASE
# 1.164 29-May-2015 uebayasi

Initial addition of ``Patrol Read'' support in bio(4), biocto(8), and
mfi(4). Based on FreeBSD, but done without mfiutil(8).

OK deraadt@


# 1.163 18-May-2015 mikeb

Prevent splassert from firing during sd_flush which runs "cold"

While mfi(4) should pass SCSI transfer flags (e.g. SCSI_POLL and
SCSI_NOSLEEP) down to the management function, make it at least
use "cold" consistently for now.

ok dlg


# 1.162 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.161 08-Mar-2015 dlg

properly set sgl related flags on skinny controllers. this fixes
io against physical disks on my dell perc h310s. logical disks still
work fine.

ok deraadt@ yasuoka@


# 1.160 08-Feb-2015 yasuoka

Fix mfi ioctl to set drive state properly.
diff from Tsubai Masanari

test dlg jmatthew
ok dlg


# 1.159 09-Jan-2015 yasuoka

Add support DIOC{G,S}CACHE to mfi(4). Cache of disk on mfi(4) will
be enabled by default. Also if the controller doesn't have any RAM,
the cache on the physical disk will be enabled.

discuss with jsg tsubai
ok dlg


# 1.158 19-Dec-2014 deraadt

another handful of bcopy -> memcpy because there is no overlap


# 1.157 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.156 09-Sep-2014 dlg

mark the interrupt handler mpsafe, and give up biglock in the scsi cmd
submission paths. take biglock again when calling back into the scsi
stack.

tested on a variety of cards here, including the skinny mfis on the
firewall next to mpsafe myx.


# 1.155 15-Aug-2014 yasuoka

Create a function which loads sgd in the mfi_iop_ops struct so that skinny
adapters can use "IEEE sgl".

tested dlg yasuoka
ok dlg jsg


Revision tags: OPENBSD_5_6_BASE
# 1.154 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.153 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.152 04-May-2014 sf

format string fixes for bus_addr_t and bus_size_t

bus_addr_t and bus_size_t are u_long everywhere

ok kettenis@


Revision tags: OPENBSD_5_5_BASE
# 1.151 20-Feb-2014 kettenis

revert previous commit; didn't intend to commit those bits


# 1.150 20-Feb-2014 kettenis

Avoid printing the "nvram corrupt" message for onboard 2200s found on Sun
hardware.

ok dlg@, jmatthew@


# 1.149 04-Dec-2013 dlg

mfi_refresh_sensors calls mfi_ioctl_vol which calls mfi_bio_getitall, which
replaces pointers in the softc and all sorts of fun stuff. this protects
the call to bio_getitall with the sc_lock the ioctl path uses, so we dont
get panics like those reported on bugs@ recently.

ok deraadt@


# 1.148 23-Oct-2013 kettenis

Add support for displaying the cache write policy of RAID volumes to bioctl(8)
and make mfi(4) pass up the necessary information. Adding support for other
RAID controllers is left as an excercise to the reader.

ok deraadt@


# 1.147 09-Oct-2013 jmatthew

Include the 'state of health' field in the bbu ok sensor value.
The dell perc 6/i sets this to zero (meaning bad) when it
decides the battery doesn't have enough capacity for it to
allow write back mode, but doesn't set any of the other flags
to tell us why.

ok dlg@, tested by sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.146 18-May-2013 jmc

enw->new in comment;
spotted by krw, missed by jsg, and forwarded From: Alexey Suslikov


# 1.145 08-May-2013 jsg

fix some leaks in error paths
ok fgsch@ krw@ kettenis@


# 1.144 03-May-2013 dlg

break out the battery status into excruciating detail. makes it harder for
$VENDOR to complain about a lack of diagnostic material from their crappy
mgmt tools if you're not running an operating system they support.


# 1.143 02-May-2013 dlg

always attach the battery sensor if the adapter lets us query it.
newly replaced batteries dont show up immediately.


# 1.142 01-May-2013 dlg

provide a sensor for the battery backup unit (bbu) on mfi boards that
support it.

now i can tell (a bit better) why io might be slow on some of my boxes.


# 1.141 01-May-2013 dlg

dont need to walk alldevs during sensor creation looking for the logical
disk scsibus when we record that in mfi_attach.

also happens to get rid of a logic error that let it come out of the loop
on alldevs with a reference to something that wasnt the logical disk
scsibus and use that.


# 1.140 30-Apr-2013 dlg

use MR_DCMD consistently. some MD_DCMD was in there somehow.


# 1.139 07-Apr-2013 dlg

david imhoff points out that the error handling in mfi_init_ccb gets the
index to which ccb to free wrong.

this takes the logic from mpi/mpii/mfii which pulls the ready ccbs off
the free list rather than rely on the current index from the for loop
that we failed inside of.

thanks to david for finding this out.


Revision tags: OPENBSD_5_3_BASE
# 1.138 12-Sep-2012 haesbaert

Make sure we don't sleep on autoconf.

ok mikeb


# 1.137 17-Aug-2012 dlg

add support for "physical devices" on skinny controllers.

these controllers let you specify disks that should be accessed directly
rather than be part of logical volumes. apparently you can plug in things
like tape drives too.

anyway, physical devices are exposed via a separate scsibus attached to
mfi.

ok mikeb@


# 1.136 16-Aug-2012 dlg

fix mfi_poll by having it do delays between loops, and breaking on
timeouts. how embarrassment.

implement mfi_exec for doing sync executions of commands in process
contexts and cut mfi_mgmt over to it.


# 1.135 16-Aug-2012 dlg

rework mfi_poll so it will do all the completions on a ccb including
calling the done handler.

this makes it consistently complete scsi io with all the proper error
checking.


# 1.134 16-Aug-2012 dlg

stop passing mfi_softc around as a member of the ccb, consistently give it
as the first argument to functions. like mfii.


# 1.133 16-Aug-2012 dlg

scrub ccbs when we're about to use them, not when we put them back
on the free list. ccbs can be reused, so we dont want old state screwing up
new commands.


# 1.132 16-Aug-2012 dlg

move the dma syncs for the ccb data into ccb_done, so we can do it once
rather than put the code everywhere.


# 1.131 16-Aug-2012 dlg

fix up the dma sync for the command frame in mfi_done.


# 1.130 14-Aug-2012 dlg

use scsi_get_link to find out the name of a child device for bioctl rather
than snoop scsi commands and copy it in an io path.

no functional change, but the code has one less XXX now.


# 1.129 14-Aug-2012 dlg

expose the max number of logical volumes the hardware supports as the width
of its scsibus. only advertise 1 lun on logical volumes instead of letting
the midlayer fix it up to 8.

give every target on the bus max_cmds openings. iopools means they will
properly share access to them.

this in particular is useful on skinny controllers which only advertise 31
command slots. if you have 16 volumes, theyll only get 1 opening each with
the old maths. this way round the ones that are busy will share the slots.

tested on a perc5 with two volumes and hard workloads.


# 1.128 14-Aug-2012 dlg

print the boards name (eg, perc 5/i) according to the firmware like mfii.

ok deraadt@


# 1.127 14-Aug-2012 dlg

move knowledge of the location of the inbound doorbell out of code in
transition_firmware into a member of the iop structures.

ok mikeb@ haesbaert@


# 1.126 13-Aug-2012 dlg

get rid of the last foo_lo and foo_hi bits i could find in the hardware
structures and use htole64 instead of htole32(addr >> 32); htole32(addr);

gets rid of "handy" stack variables to get the dva to 64bits.

sprinkle some more byte swaps for things that should have it.

tested on a perc5 (xscale)


# 1.125 13-Aug-2012 dlg

do appropriate bus_dmamapy_syncs around the pcq/completion ring.

tested on a perc5 (xscale)


# 1.124 13-Aug-2012 dlg

replace uint32_ts for hi and lo addresses in the mfi_init_ hardware
descriptors with single uint64_ts. theyre not some weird middle
endian thing. this makes the code more readable.

add some missing htole32s to the code while here.

tested on a perc5 (xscale).


# 1.123 11-Aug-2012 dlg

the producer/consumer values are used by the device, which is little
endian. do appropriate byteswapping for when the host cpu uses them.

tested on a perc5 (xscale) in an amd64.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.122 12-Jan-2012 dlg

add support for skinny variants.

from Alexey Suslikov
reviewed by marco


Revision tags: OPENBSD_5_0_BASE
# 1.121 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.120 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.119 09-Apr-2011 marco

add all 64 bit dma plumbing but stick with 32 for now by default.

ok deraadt


# 1.118 09-Apr-2011 marco

make sure the upper 32 bits are always written to instead of assuming it
is 0.

ok deraadt.


# 1.117 08-Apr-2011 marco

kill some stray spaces


# 1.116 08-Apr-2011 marco

rename wiat channel to something less than 8 chars.

prompted by deraadt


# 1.115 08-Apr-2011 marco

use dma_alloc for transient management commands.

prodded and ok deraadt


Revision tags: OPENBSD_4_9_BASE
# 1.114 30-Dec-2010 dlg

cut mfi over to using iopools.

this gets rid of NO_CCB, provides better scheduling of io between busy
logical volumes on the same controller, and makes the ioctl and sensor
paths more reliable.

this is the least intrusive version of this change i could come up with. it
only took 4 or 5 goes...

ok marco@
deraadt@ says this is a good time for this change.


# 1.113 24-Sep-2010 dlg

no use setting cmd in mfi_ioctl_setstate if you never use it.


# 1.112 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


# 1.111 29-Aug-2010 dlg

the scsi completion code thinks that if you dont get MFI_STAT_OK
back from the chip on a command then the command completely failed.
MFI_STAT_SCSI_DONE_WITH_ERROR really means the command completed
fine, but there's some sense data too. this tweaks the handling to
be more appropriate, as per the linux and solaris drivers.

timed out waiting for beck@
putting this in cos its obviously more correct than the current code.


Revision tags: OPENBSD_4_8_BASE
# 1.110 22-Jul-2010 matthew

SCSI HBA drivers are supposed to get their SCSI CDBs from xs->cmd, not
xs->cmdstore.

ok krw@ a while back (contingent upon testing), and deraadt@ says this
has been in snapshots for weeks now.


# 1.109 01-Jul-2010 matthew

Change scsibus(4)'s scsi_link array to an SLIST to save memory on
sparsely populated buses.

ok dlg@, krw@


# 1.108 30-Jun-2010 mk

Use SLIST for the ccb free list.

ok krw, discontent grunts from marco.


# 1.107 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.106 15-Jun-2010 dlg

dont pass the dev_t from the scsi device drivers into the midlayer for
ioctl requests, and dont pass the proc pointers around for any ioctl
requests in scsi land at all. neither were used, so trim the fat.

ok krw@ marco@


# 1.105 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.104 16-May-2010 nicm

Use a temporary variable for now to sidestep -Wbounded checking when
copying vendor[8]/product[16]/revision[4] out of struct scsi_inquiry_data
together with one memcopy.

ok krw


# 1.103 22-Apr-2010 oga

use BUS_DMA_ZERO on alloc instead of bzeroing after.

ok dlg@, marco@


# 1.102 10-Apr-2010 marco

grrr var names in protos


# 1.101 10-Apr-2010 marco

sprinkle some bus_dmamap_sync around frame access.
prompted by oga


# 1.100 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.99 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.98 04-Jan-2010 dlg

rename ccb_xs to ccb_cookie and change its type from a scsi_xfer * to a
void *. this lets us pass things other than scsi_xfers to ccb completion
handlers.


# 1.97 04-Jan-2010 dlg

protect the ccb free queue with a mutex rather than splbio


# 1.96 03-Jan-2010 chl

change M_WAITOK --> M_WAITOK|M_CANFAIL

with input from marco@

ok marco@ krw@

this was ok looooooooong time ago but lost in my mailbox


Revision tags: OPENBSD_4_6_BASE
# 1.95 30-Apr-2009 marco

Add READ(16) & WRITE(16) commands.
ok krw


# 1.94 29-Apr-2009 marco

MFI_D_IOCTL should be commented out. No binary change.


# 1.93 04-Apr-2009 dlg

scrub more fields in the ccb when returning them to the free list after
theyve been used, in particular the mfi header flags which has a bit
that specifies if a command should be completed via the interrupt path.

if we use a ccb during boot we set that bit, but it isnt necessarily
cleared by things that use it later on. this means a ccb we expected to
complete via an interrupt never actually generates an interrupt or appears
in the reply queue. this obviously stalls the io.


# 1.92 29-Mar-2009 marco

spello


# 1.91 29-Mar-2009 dlg

when we steal the SYNC CACHE command in mfi_scsi_cmd we still have to
mark the xs as done and call scsi_done for it rather than just returning
COMPLETE.


# 1.90 29-Mar-2009 dlg

fix a small race in mfi_mgmt between the checking of a ccbs completion and
the sleep waiting for the completion. it is possible to get the interrupt
completing the command just before the tsleep, which will never get a
wakeup because the interrupt with the wakeup has already happened.


Revision tags: OPENBSD_4_5_BASE
# 1.89 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.


# 1.88 28-Jan-2009 marco

Add support for next generation megaraid sas raid controllers.
From Jim Giannoules <gortag@gmail.com>


# 1.87 31-Oct-2008 marco

Generalize function to obtain all details to do bio stuff. This is in
preparation to start showing unsused disks which will require all this
information to do the math.

While at it fix a size of hotspare volume bug.


# 1.86 30-Oct-2008 marco

Fix bug that when there are no volumes but there are hot spares it would
no show the hotspares.


# 1.85 28-Oct-2008 marco

Fix output when reporting on multivolume disk groups.

Reported by mitja@muzenic.net


# 1.84 27-Oct-2008 marco

Move some include stuff around


# 1.83 26-Oct-2008 marco

Space


# 1.82 23-Oct-2008 marco

Fix PR5645
ok dlg
tested beck and others


# 1.81 25-Sep-2008 krw

Initialize 'ssc' to NULL since we test it later. Shouldn't ever be
NULL at the point of test unless the device list is confused, but
be consistantly paranoid if we're going to be paranoid.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.80 16-Feb-2008 krw

Return NO_CCB and not TRY_AGAIN_LATER when running out of ccb's.
Eliminates 'not queued' errors reported on the mailing lists.

Tested by Michael (belenus at bsdmail dot de).

ok marco@


# 1.79 11-Feb-2008 dlg

add support for the mfi controllers with the ppc iops, aka, LSI SAS1078 or
Dell PERC6.

committed off a machine booting and rooting off a perc6. tested on a perc5
by marco@
ok marco@


# 1.78 26-Jan-2008 brad

Set the return value instead of returning right away so that the DMA
memory is actually synched.

ok dlg@


# 1.77 26-Jan-2008 dlg

sync dma mem back to the cpu on poll failure.

from mickey via pr5714


# 1.76 26-Jan-2008 dlg

despatch -> dispatch

disparate spellink fix from mickey


# 1.75 05-Nov-2007 krw

More scsi_done() at SPLBIO.


# 1.74 27-Sep-2007 chl

M_ZERO changes

ok dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.73 24-Jun-2007 dlg

rework sensor tasks to use the kernels generic workq rather than a special
kernel thread of its own. the api has changed (which will be fixed in the
manpage shortly) so all the users of sensor tasks that i can find have
been fixed too.

noone tested, so its going in to force people to run with it.
"put it in" deraadt@


# 1.72 29-May-2007 todd

sprinkle some SMALL_KERNEL to permit bio/softraid to run on boot media
ok marco@ then suggested deraadt@


# 1.71 22-Mar-2007 deraadt

split userland & kernel struct sensor/sensordev so that the addition
of new fields in the future is less disruptive. This is done similar
to how struct proc is handled for ps(1). ok jmc (man page changes)
tested fkr simon, and more suggestions from millert


Revision tags: OPENBSD_4_1_BASE
# 1.70 14-Feb-2007 dlg

bus_space does byte swapping to cope with host endianness for us, so remove
an unnecessary htole32().


# 1.69 13-Feb-2007 marco

Fix subtle x ? y : z bug when calling mfi_create_sgl. This worked because
during runtime the bug condition does not happen.

ok krw joris


# 1.68 08-Feb-2007 ray

Remove double semicolons.

From Pierre Riteau <pierre dot riteau at free dot fr>.

OK marco@.


# 1.67 23-Dec-2006 deraadt

adapt to new two-level sensor api; Constantine A. Murenin


# 1.66 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.65 31-Aug-2006 marco

Add sensor thread for individual sd devices.

tested dlg
ok dlg deraadt


# 1.64 30-Aug-2006 dlg

when determining the size of the volumes and disks we want how many
bytes each of them has, not the number of kilobytes. this solves the
"why am i dividing by 2" question. the answer is "you dont, you multiply
by 512".


# 1.63 28-Jul-2006 brad

make dmesg printing look a little bit nicer.


# 1.62 19-Jun-2006 marco

Factor for disk size is /2. Odd but tested on all mfis I have.


# 1.61 19-Jun-2006 miod

Everytime one forgets an argument in a printf-like function call, God kills
a kitten. Commiters, please think of the kittens when working on code.


# 1.60 19-Jun-2006 marco

Make a BGI (Back Ground Init) a scrub instead of rebuild.


# 1.59 19-Jun-2006 marco

Add hot spare support.


# 1.58 26-May-2006 marco

Add blinking for disks.


# 1.57 25-May-2006 marco

Move a int i; to top of function so that it compiles on non c99 compilers.
Pointed out by miod@

The enclosure id modifier didn't reflect reality so move it back to whatever
the raid card uses.


# 1.56 25-May-2006 marco

And add time and percentage to builds and check consistencies.


# 1.55 25-May-2006 marco

Add last bit of physcal disk stuff.
Remove bogus memset.
Hotspares still don't work.


# 1.54 25-May-2006 marco

Add physical device and read config structures.
Add initial part of BIOCDISK


# 1.53 23-May-2006 deraadt

commited with unused variable


# 1.52 23-May-2006 marco

Remove some debug cruft.


# 1.51 23-May-2006 marco

Add first half of physical disk data for bio.


# 1.50 22-May-2006 marco

Add support for raid 50 and 10 in bio.


# 1.49 22-May-2006 marco

Add mail box to mfi_mgmt to handle sub commands more gracefully.
Remove some debug crud that snuck in the TEST_UNIT_READY case.
Finish other half of BIOCVOL primitive.
Add several structures to fill out the BIOCVOL primitive.


# 1.48 22-May-2006 marco

Add first half of BIOCVOL primitive.


# 1.47 21-May-2006 marco

Do a giant flush of disk and raid-card memory when SYNCHONIZE_CACHE is called.


# 1.46 21-May-2006 marco

pretty up some debug statements.


# 1.45 21-May-2006 marco

Add bio alarm function.
Redo mfi_mgmt to deal with zero data commands.


# 1.44 21-May-2006 marco

Add generic management function.
Redo ccb_state flags so that we can actually sleep on it.
Redo mfi_get_info to use new mgmt function.
Add rw_locks for mgmt interface.
Make BIOCINQ dynamic.


# 1.43 21-May-2006 marco

Oops, helps to use the right structure field.
Use actual nr of physical disks present.


# 1.42 21-May-2006 marco

Add first BIOCINQ primitive.


# 1.41 18-May-2006 marco

Remove some debug cruft and pretty up some debug messages.


# 1.40 18-May-2006 marco

Kill splbio/splx in the interrupt handler.


# 1.39 18-May-2006 marco

And we have lift off! Was able to create a filesystem and write to the
filesystem.

Collapse both completion routines into one.
Fixup scsi error reporting in the completion routine.


# 1.38 17-May-2006 marco

Add completion routines.
Fix some bugs inside the interrupt handler.


# 1.37 17-May-2006 marco

Add mfi_get_info to obtain all kinds of fun information from the fw.
Print out whole info structure when debug is enabled.
Add a nice print with useful info during attach.


# 1.36 17-May-2006 marco

Refactor scsi path so that we can have a single sgl function for io and non-io
traffic.
Redo parameters on functions that were passing too many parameters around.


# 1.35 16-May-2006 marco

Nuke some { }


# 1.34 16-May-2006 marco

Move !xs->data case into mfi_start_xs.
Return proper sense data when a polling command fails.


# 1.33 16-May-2006 marco

Fix some more htole32 screw-ups.
Colapse all little SCSI functions into a single generic one.
Fix a bug in the SGE calculation.

This brings the driver up to post:
mfi0 at pci12 dev 14 function 0 "Dell PERC SAS" rev 0x00: Dell PERC 5/e irq 5
scsibus3 at mfi0: 2 targets
sd1 at scsibus3 targ 0 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd1: 237824MB, 237824 cyl, 64 head, 32 sec, 512 bytes/sec, 487063552 sec total
sd2 at scsibus3 targ 1 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd2: 34176MB, 34176 cyl, 64 head, 32 sec, 512 bytes/sec, 69992448 sec total


# 1.32 16-May-2006 marco

Fix some htole32 I missed.
Sprinkle more debug.


# 1.31 16-May-2006 marco

Add READ CAPACITY.


# 1.30 16-May-2006 marco

Oops PREREAD not PREWRITE.


# 1.29 16-May-2006 marco

Add TUR and make it send it directly to firmware.
Sprinkle some extra debug.


# 1.28 15-May-2006 marco

Clear all relevant ccb fields when mfi_put_ccb frees a ccb.


# 1.27 15-May-2006 marco

Oops don't send command twice to firmware when polling.


# 1.26 15-May-2006 marco

Add INQUIRY command.
Add sgl magic.


# 1.25 10-May-2006 marco

Add some airplane code.

add bio hooks.
add scsi entry point for io.


# 1.24 26-Apr-2006 marco

Fix some debug prints.


# 1.23 21-Apr-2006 marco

typo


# 1.22 21-Apr-2006 marco

Add mfi_poll and use the new shiny function to setup all the hardware queues.
Lots of ideas from the FreeBSD driver.


# 1.21 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.20 20-Apr-2006 dlg

marco hates typedefs as much as i do, so he asked me to clean mfi like i
just did with ami. this gets rid of the typedef for the ccb lists.

also uses TAILQ_FIRST to get ccbs off the freelist. this is a proactive
fix for a lint teary.


# 1.19 18-Apr-2006 marco

It helps to initialize a queue before usage.


# 1.18 18-Apr-2006 marco

Actually add ccbs to the queue.
Fix the error path for mfi_init_ccb.
Alter dmamap for io.


# 1.17 17-Apr-2006 marco

Sprinkle more debug. Remove 64 byte boundary; it doesn't seem to like it.
Hack around 64 byte boundary for the frames for now.


# 1.16 17-Apr-2006 marco

Setup ccbs and clean up ccb structure.


# 1.15 16-Apr-2006 marco

Oops, make mfi_allocmem always use 64 byte boundaries since frames have to
have that alignment. It doesn't matter for the other consumers of the
function.


# 1.14 16-Apr-2006 marco

Add frame memory and sglist allocation.


# 1.13 16-Apr-2006 marco

Make memory access use macro.


# 1.12 16-Apr-2006 marco

typo


# 1.11 16-Apr-2006 marco

Add get and put ccb functions. Shuffle some more definitions.


# 1.10 16-Apr-2006 marco

Nicer print when context is invalid.


# 1.9 16-Apr-2006 marco

Shuffle some #defines.
Fix comments.
Add human readable enable intrrupt #define.


# 1.8 16-Apr-2006 marco

Add interrupt handler. Idea borrowed from FreeBSD since it is much nicer
than the Linux one.


# 1.7 07-Apr-2006 marco

Replace bus_space functions with generic ones that do barriers.


# 1.6 07-Apr-2006 marco

Add memory allocator functions.


# 1.5 07-Apr-2006 marco

Print state in debug. Change return vales to 1 instead of ENXIO.


# 1.4 07-Apr-2006 marco

Make a better debug mechanism.


# 1.3 07-Apr-2006 marco

Enable mfi_transition_fw() original code from FreeBSD.


# 1.2 06-Apr-2006 marco

Add fw transition logic.


# 1.1 06-Apr-2006 marco

Add skeleton driver for MegaRAID SAS.


# 1.185 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.184 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.183 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.182 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.181 13-Jul-2020 krw

Where we have a pointer (sc) to the relevant adapter_softc, use
&sc->sc_dev to get a device pointer rather than using the void *
whence we obtained 'sc'.


# 1.180 13-Jul-2020 krw

Remove some pointless casting of void * when assigning one
(scsi_link.adapter_softc) to a pointer of a particular softc type.


# 1.179 27-Jun-2020 krw

Nuke trailing whitespace.


# 1.178 27-Jun-2020 krw

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


# 1.177 24-Jun-2020 krw

Use SDEV_NO_ADAPTER_TARGET instead of -1 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.176 21-Mar-2020 krw

Simplify some goto'ing that jumps a single line or
does nothing at all.

The first one spotted as CID 1452976.

Reads good to millert@

ok mpi@


# 1.175 13-Feb-2020 krw

Nuke *_minphys() functions that either simply apply MAXPHYS or do
nothing at all. MAXPHYS will be applied in minphys() and nothing at
all, well, doesn't do anything.

Also remove any '#define <blah> MAXPHYS' statements used solely to
disguise MAXPHYS in said functions.


# 1.174 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.173 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.172 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.171 31-Dec-2019 mpi

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

ok kn@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.170 05-Mar-2019 jmatthew

apply background init progress fix from r1.59 of mfii.c
(reverting most of r1.60 of mfi.c, oddly enough)

ok dlg@
tested on a SAS2008 (perc h310)


Revision tags: OPENBSD_6_4_BASE
# 1.169 14-Aug-2018 jmatthew

return ENOTTY rather than EINVAL to indicate an ioctl hasn't been handled

ok dlg@ deraadt@ kettenis@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.168 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.167 02-Feb-2017 dlg

copy the mbox into the dcmd struct, not the pointer to the mbox.

makes bioctl work on mfi(4) again.

while here memset a few mboxes before using them.

bioctl breakage reported by jason george


# 1.166 23-Jan-2017 dlg

represent the mbox layout with union instead of an array of bytes.

memcpying uint16_ts into inconsistently addressed offsets is hard
to read, and this makes future work easier to implement.

tested on mfi(4) and mfii(4)


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.165 09-Sep-2015 deraadt

sizes for free(); ok sthen


Revision tags: OPENBSD_5_8_BASE
# 1.164 29-May-2015 uebayasi

Initial addition of ``Patrol Read'' support in bio(4), biocto(8), and
mfi(4). Based on FreeBSD, but done without mfiutil(8).

OK deraadt@


# 1.163 18-May-2015 mikeb

Prevent splassert from firing during sd_flush which runs "cold"

While mfi(4) should pass SCSI transfer flags (e.g. SCSI_POLL and
SCSI_NOSLEEP) down to the management function, make it at least
use "cold" consistently for now.

ok dlg


# 1.162 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.161 08-Mar-2015 dlg

properly set sgl related flags on skinny controllers. this fixes
io against physical disks on my dell perc h310s. logical disks still
work fine.

ok deraadt@ yasuoka@


# 1.160 08-Feb-2015 yasuoka

Fix mfi ioctl to set drive state properly.
diff from Tsubai Masanari

test dlg jmatthew
ok dlg


# 1.159 09-Jan-2015 yasuoka

Add support DIOC{G,S}CACHE to mfi(4). Cache of disk on mfi(4) will
be enabled by default. Also if the controller doesn't have any RAM,
the cache on the physical disk will be enabled.

discuss with jsg tsubai
ok dlg


# 1.158 19-Dec-2014 deraadt

another handful of bcopy -> memcpy because there is no overlap


# 1.157 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.156 09-Sep-2014 dlg

mark the interrupt handler mpsafe, and give up biglock in the scsi cmd
submission paths. take biglock again when calling back into the scsi
stack.

tested on a variety of cards here, including the skinny mfis on the
firewall next to mpsafe myx.


# 1.155 15-Aug-2014 yasuoka

Create a function which loads sgd in the mfi_iop_ops struct so that skinny
adapters can use "IEEE sgl".

tested dlg yasuoka
ok dlg jsg


Revision tags: OPENBSD_5_6_BASE
# 1.154 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.153 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.152 04-May-2014 sf

format string fixes for bus_addr_t and bus_size_t

bus_addr_t and bus_size_t are u_long everywhere

ok kettenis@


Revision tags: OPENBSD_5_5_BASE
# 1.151 20-Feb-2014 kettenis

revert previous commit; didn't intend to commit those bits


# 1.150 20-Feb-2014 kettenis

Avoid printing the "nvram corrupt" message for onboard 2200s found on Sun
hardware.

ok dlg@, jmatthew@


# 1.149 04-Dec-2013 dlg

mfi_refresh_sensors calls mfi_ioctl_vol which calls mfi_bio_getitall, which
replaces pointers in the softc and all sorts of fun stuff. this protects
the call to bio_getitall with the sc_lock the ioctl path uses, so we dont
get panics like those reported on bugs@ recently.

ok deraadt@


# 1.148 23-Oct-2013 kettenis

Add support for displaying the cache write policy of RAID volumes to bioctl(8)
and make mfi(4) pass up the necessary information. Adding support for other
RAID controllers is left as an excercise to the reader.

ok deraadt@


# 1.147 09-Oct-2013 jmatthew

Include the 'state of health' field in the bbu ok sensor value.
The dell perc 6/i sets this to zero (meaning bad) when it
decides the battery doesn't have enough capacity for it to
allow write back mode, but doesn't set any of the other flags
to tell us why.

ok dlg@, tested by sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.146 18-May-2013 jmc

enw->new in comment;
spotted by krw, missed by jsg, and forwarded From: Alexey Suslikov


# 1.145 08-May-2013 jsg

fix some leaks in error paths
ok fgsch@ krw@ kettenis@


# 1.144 03-May-2013 dlg

break out the battery status into excruciating detail. makes it harder for
$VENDOR to complain about a lack of diagnostic material from their crappy
mgmt tools if you're not running an operating system they support.


# 1.143 02-May-2013 dlg

always attach the battery sensor if the adapter lets us query it.
newly replaced batteries dont show up immediately.


# 1.142 01-May-2013 dlg

provide a sensor for the battery backup unit (bbu) on mfi boards that
support it.

now i can tell (a bit better) why io might be slow on some of my boxes.


# 1.141 01-May-2013 dlg

dont need to walk alldevs during sensor creation looking for the logical
disk scsibus when we record that in mfi_attach.

also happens to get rid of a logic error that let it come out of the loop
on alldevs with a reference to something that wasnt the logical disk
scsibus and use that.


# 1.140 30-Apr-2013 dlg

use MR_DCMD consistently. some MD_DCMD was in there somehow.


# 1.139 07-Apr-2013 dlg

david imhoff points out that the error handling in mfi_init_ccb gets the
index to which ccb to free wrong.

this takes the logic from mpi/mpii/mfii which pulls the ready ccbs off
the free list rather than rely on the current index from the for loop
that we failed inside of.

thanks to david for finding this out.


Revision tags: OPENBSD_5_3_BASE
# 1.138 12-Sep-2012 haesbaert

Make sure we don't sleep on autoconf.

ok mikeb


# 1.137 17-Aug-2012 dlg

add support for "physical devices" on skinny controllers.

these controllers let you specify disks that should be accessed directly
rather than be part of logical volumes. apparently you can plug in things
like tape drives too.

anyway, physical devices are exposed via a separate scsibus attached to
mfi.

ok mikeb@


# 1.136 16-Aug-2012 dlg

fix mfi_poll by having it do delays between loops, and breaking on
timeouts. how embarrassment.

implement mfi_exec for doing sync executions of commands in process
contexts and cut mfi_mgmt over to it.


# 1.135 16-Aug-2012 dlg

rework mfi_poll so it will do all the completions on a ccb including
calling the done handler.

this makes it consistently complete scsi io with all the proper error
checking.


# 1.134 16-Aug-2012 dlg

stop passing mfi_softc around as a member of the ccb, consistently give it
as the first argument to functions. like mfii.


# 1.133 16-Aug-2012 dlg

scrub ccbs when we're about to use them, not when we put them back
on the free list. ccbs can be reused, so we dont want old state screwing up
new commands.


# 1.132 16-Aug-2012 dlg

move the dma syncs for the ccb data into ccb_done, so we can do it once
rather than put the code everywhere.


# 1.131 16-Aug-2012 dlg

fix up the dma sync for the command frame in mfi_done.


# 1.130 14-Aug-2012 dlg

use scsi_get_link to find out the name of a child device for bioctl rather
than snoop scsi commands and copy it in an io path.

no functional change, but the code has one less XXX now.


# 1.129 14-Aug-2012 dlg

expose the max number of logical volumes the hardware supports as the width
of its scsibus. only advertise 1 lun on logical volumes instead of letting
the midlayer fix it up to 8.

give every target on the bus max_cmds openings. iopools means they will
properly share access to them.

this in particular is useful on skinny controllers which only advertise 31
command slots. if you have 16 volumes, theyll only get 1 opening each with
the old maths. this way round the ones that are busy will share the slots.

tested on a perc5 with two volumes and hard workloads.


# 1.128 14-Aug-2012 dlg

print the boards name (eg, perc 5/i) according to the firmware like mfii.

ok deraadt@


# 1.127 14-Aug-2012 dlg

move knowledge of the location of the inbound doorbell out of code in
transition_firmware into a member of the iop structures.

ok mikeb@ haesbaert@


# 1.126 13-Aug-2012 dlg

get rid of the last foo_lo and foo_hi bits i could find in the hardware
structures and use htole64 instead of htole32(addr >> 32); htole32(addr);

gets rid of "handy" stack variables to get the dva to 64bits.

sprinkle some more byte swaps for things that should have it.

tested on a perc5 (xscale)


# 1.125 13-Aug-2012 dlg

do appropriate bus_dmamapy_syncs around the pcq/completion ring.

tested on a perc5 (xscale)


# 1.124 13-Aug-2012 dlg

replace uint32_ts for hi and lo addresses in the mfi_init_ hardware
descriptors with single uint64_ts. theyre not some weird middle
endian thing. this makes the code more readable.

add some missing htole32s to the code while here.

tested on a perc5 (xscale).


# 1.123 11-Aug-2012 dlg

the producer/consumer values are used by the device, which is little
endian. do appropriate byteswapping for when the host cpu uses them.

tested on a perc5 (xscale) in an amd64.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.122 12-Jan-2012 dlg

add support for skinny variants.

from Alexey Suslikov
reviewed by marco


Revision tags: OPENBSD_5_0_BASE
# 1.121 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.120 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.119 09-Apr-2011 marco

add all 64 bit dma plumbing but stick with 32 for now by default.

ok deraadt


# 1.118 09-Apr-2011 marco

make sure the upper 32 bits are always written to instead of assuming it
is 0.

ok deraadt.


# 1.117 08-Apr-2011 marco

kill some stray spaces


# 1.116 08-Apr-2011 marco

rename wiat channel to something less than 8 chars.

prompted by deraadt


# 1.115 08-Apr-2011 marco

use dma_alloc for transient management commands.

prodded and ok deraadt


Revision tags: OPENBSD_4_9_BASE
# 1.114 30-Dec-2010 dlg

cut mfi over to using iopools.

this gets rid of NO_CCB, provides better scheduling of io between busy
logical volumes on the same controller, and makes the ioctl and sensor
paths more reliable.

this is the least intrusive version of this change i could come up with. it
only took 4 or 5 goes...

ok marco@
deraadt@ says this is a good time for this change.


# 1.113 24-Sep-2010 dlg

no use setting cmd in mfi_ioctl_setstate if you never use it.


# 1.112 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


# 1.111 29-Aug-2010 dlg

the scsi completion code thinks that if you dont get MFI_STAT_OK
back from the chip on a command then the command completely failed.
MFI_STAT_SCSI_DONE_WITH_ERROR really means the command completed
fine, but there's some sense data too. this tweaks the handling to
be more appropriate, as per the linux and solaris drivers.

timed out waiting for beck@
putting this in cos its obviously more correct than the current code.


Revision tags: OPENBSD_4_8_BASE
# 1.110 22-Jul-2010 matthew

SCSI HBA drivers are supposed to get their SCSI CDBs from xs->cmd, not
xs->cmdstore.

ok krw@ a while back (contingent upon testing), and deraadt@ says this
has been in snapshots for weeks now.


# 1.109 01-Jul-2010 matthew

Change scsibus(4)'s scsi_link array to an SLIST to save memory on
sparsely populated buses.

ok dlg@, krw@


# 1.108 30-Jun-2010 mk

Use SLIST for the ccb free list.

ok krw, discontent grunts from marco.


# 1.107 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.106 15-Jun-2010 dlg

dont pass the dev_t from the scsi device drivers into the midlayer for
ioctl requests, and dont pass the proc pointers around for any ioctl
requests in scsi land at all. neither were used, so trim the fat.

ok krw@ marco@


# 1.105 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.104 16-May-2010 nicm

Use a temporary variable for now to sidestep -Wbounded checking when
copying vendor[8]/product[16]/revision[4] out of struct scsi_inquiry_data
together with one memcopy.

ok krw


# 1.103 22-Apr-2010 oga

use BUS_DMA_ZERO on alloc instead of bzeroing after.

ok dlg@, marco@


# 1.102 10-Apr-2010 marco

grrr var names in protos


# 1.101 10-Apr-2010 marco

sprinkle some bus_dmamap_sync around frame access.
prompted by oga


# 1.100 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.99 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.98 04-Jan-2010 dlg

rename ccb_xs to ccb_cookie and change its type from a scsi_xfer * to a
void *. this lets us pass things other than scsi_xfers to ccb completion
handlers.


# 1.97 04-Jan-2010 dlg

protect the ccb free queue with a mutex rather than splbio


# 1.96 03-Jan-2010 chl

change M_WAITOK --> M_WAITOK|M_CANFAIL

with input from marco@

ok marco@ krw@

this was ok looooooooong time ago but lost in my mailbox


Revision tags: OPENBSD_4_6_BASE
# 1.95 30-Apr-2009 marco

Add READ(16) & WRITE(16) commands.
ok krw


# 1.94 29-Apr-2009 marco

MFI_D_IOCTL should be commented out. No binary change.


# 1.93 04-Apr-2009 dlg

scrub more fields in the ccb when returning them to the free list after
theyve been used, in particular the mfi header flags which has a bit
that specifies if a command should be completed via the interrupt path.

if we use a ccb during boot we set that bit, but it isnt necessarily
cleared by things that use it later on. this means a ccb we expected to
complete via an interrupt never actually generates an interrupt or appears
in the reply queue. this obviously stalls the io.


# 1.92 29-Mar-2009 marco

spello


# 1.91 29-Mar-2009 dlg

when we steal the SYNC CACHE command in mfi_scsi_cmd we still have to
mark the xs as done and call scsi_done for it rather than just returning
COMPLETE.


# 1.90 29-Mar-2009 dlg

fix a small race in mfi_mgmt between the checking of a ccbs completion and
the sleep waiting for the completion. it is possible to get the interrupt
completing the command just before the tsleep, which will never get a
wakeup because the interrupt with the wakeup has already happened.


Revision tags: OPENBSD_4_5_BASE
# 1.89 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.


# 1.88 28-Jan-2009 marco

Add support for next generation megaraid sas raid controllers.
From Jim Giannoules <gortag@gmail.com>


# 1.87 31-Oct-2008 marco

Generalize function to obtain all details to do bio stuff. This is in
preparation to start showing unsused disks which will require all this
information to do the math.

While at it fix a size of hotspare volume bug.


# 1.86 30-Oct-2008 marco

Fix bug that when there are no volumes but there are hot spares it would
no show the hotspares.


# 1.85 28-Oct-2008 marco

Fix output when reporting on multivolume disk groups.

Reported by mitja@muzenic.net


# 1.84 27-Oct-2008 marco

Move some include stuff around


# 1.83 26-Oct-2008 marco

Space


# 1.82 23-Oct-2008 marco

Fix PR5645
ok dlg
tested beck and others


# 1.81 25-Sep-2008 krw

Initialize 'ssc' to NULL since we test it later. Shouldn't ever be
NULL at the point of test unless the device list is confused, but
be consistantly paranoid if we're going to be paranoid.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.80 16-Feb-2008 krw

Return NO_CCB and not TRY_AGAIN_LATER when running out of ccb's.
Eliminates 'not queued' errors reported on the mailing lists.

Tested by Michael (belenus at bsdmail dot de).

ok marco@


# 1.79 11-Feb-2008 dlg

add support for the mfi controllers with the ppc iops, aka, LSI SAS1078 or
Dell PERC6.

committed off a machine booting and rooting off a perc6. tested on a perc5
by marco@
ok marco@


# 1.78 26-Jan-2008 brad

Set the return value instead of returning right away so that the DMA
memory is actually synched.

ok dlg@


# 1.77 26-Jan-2008 dlg

sync dma mem back to the cpu on poll failure.

from mickey via pr5714


# 1.76 26-Jan-2008 dlg

despatch -> dispatch

disparate spellink fix from mickey


# 1.75 05-Nov-2007 krw

More scsi_done() at SPLBIO.


# 1.74 27-Sep-2007 chl

M_ZERO changes

ok dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.73 24-Jun-2007 dlg

rework sensor tasks to use the kernels generic workq rather than a special
kernel thread of its own. the api has changed (which will be fixed in the
manpage shortly) so all the users of sensor tasks that i can find have
been fixed too.

noone tested, so its going in to force people to run with it.
"put it in" deraadt@


# 1.72 29-May-2007 todd

sprinkle some SMALL_KERNEL to permit bio/softraid to run on boot media
ok marco@ then suggested deraadt@


# 1.71 22-Mar-2007 deraadt

split userland & kernel struct sensor/sensordev so that the addition
of new fields in the future is less disruptive. This is done similar
to how struct proc is handled for ps(1). ok jmc (man page changes)
tested fkr simon, and more suggestions from millert


Revision tags: OPENBSD_4_1_BASE
# 1.70 14-Feb-2007 dlg

bus_space does byte swapping to cope with host endianness for us, so remove
an unnecessary htole32().


# 1.69 13-Feb-2007 marco

Fix subtle x ? y : z bug when calling mfi_create_sgl. This worked because
during runtime the bug condition does not happen.

ok krw joris


# 1.68 08-Feb-2007 ray

Remove double semicolons.

From Pierre Riteau <pierre dot riteau at free dot fr>.

OK marco@.


# 1.67 23-Dec-2006 deraadt

adapt to new two-level sensor api; Constantine A. Murenin


# 1.66 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.65 31-Aug-2006 marco

Add sensor thread for individual sd devices.

tested dlg
ok dlg deraadt


# 1.64 30-Aug-2006 dlg

when determining the size of the volumes and disks we want how many
bytes each of them has, not the number of kilobytes. this solves the
"why am i dividing by 2" question. the answer is "you dont, you multiply
by 512".


# 1.63 28-Jul-2006 brad

make dmesg printing look a little bit nicer.


# 1.62 19-Jun-2006 marco

Factor for disk size is /2. Odd but tested on all mfis I have.


# 1.61 19-Jun-2006 miod

Everytime one forgets an argument in a printf-like function call, God kills
a kitten. Commiters, please think of the kittens when working on code.


# 1.60 19-Jun-2006 marco

Make a BGI (Back Ground Init) a scrub instead of rebuild.


# 1.59 19-Jun-2006 marco

Add hot spare support.


# 1.58 26-May-2006 marco

Add blinking for disks.


# 1.57 25-May-2006 marco

Move a int i; to top of function so that it compiles on non c99 compilers.
Pointed out by miod@

The enclosure id modifier didn't reflect reality so move it back to whatever
the raid card uses.


# 1.56 25-May-2006 marco

And add time and percentage to builds and check consistencies.


# 1.55 25-May-2006 marco

Add last bit of physcal disk stuff.
Remove bogus memset.
Hotspares still don't work.


# 1.54 25-May-2006 marco

Add physical device and read config structures.
Add initial part of BIOCDISK


# 1.53 23-May-2006 deraadt

commited with unused variable


# 1.52 23-May-2006 marco

Remove some debug cruft.


# 1.51 23-May-2006 marco

Add first half of physical disk data for bio.


# 1.50 22-May-2006 marco

Add support for raid 50 and 10 in bio.


# 1.49 22-May-2006 marco

Add mail box to mfi_mgmt to handle sub commands more gracefully.
Remove some debug crud that snuck in the TEST_UNIT_READY case.
Finish other half of BIOCVOL primitive.
Add several structures to fill out the BIOCVOL primitive.


# 1.48 22-May-2006 marco

Add first half of BIOCVOL primitive.


# 1.47 21-May-2006 marco

Do a giant flush of disk and raid-card memory when SYNCHONIZE_CACHE is called.


# 1.46 21-May-2006 marco

pretty up some debug statements.


# 1.45 21-May-2006 marco

Add bio alarm function.
Redo mfi_mgmt to deal with zero data commands.


# 1.44 21-May-2006 marco

Add generic management function.
Redo ccb_state flags so that we can actually sleep on it.
Redo mfi_get_info to use new mgmt function.
Add rw_locks for mgmt interface.
Make BIOCINQ dynamic.


# 1.43 21-May-2006 marco

Oops, helps to use the right structure field.
Use actual nr of physical disks present.


# 1.42 21-May-2006 marco

Add first BIOCINQ primitive.


# 1.41 18-May-2006 marco

Remove some debug cruft and pretty up some debug messages.


# 1.40 18-May-2006 marco

Kill splbio/splx in the interrupt handler.


# 1.39 18-May-2006 marco

And we have lift off! Was able to create a filesystem and write to the
filesystem.

Collapse both completion routines into one.
Fixup scsi error reporting in the completion routine.


# 1.38 17-May-2006 marco

Add completion routines.
Fix some bugs inside the interrupt handler.


# 1.37 17-May-2006 marco

Add mfi_get_info to obtain all kinds of fun information from the fw.
Print out whole info structure when debug is enabled.
Add a nice print with useful info during attach.


# 1.36 17-May-2006 marco

Refactor scsi path so that we can have a single sgl function for io and non-io
traffic.
Redo parameters on functions that were passing too many parameters around.


# 1.35 16-May-2006 marco

Nuke some { }


# 1.34 16-May-2006 marco

Move !xs->data case into mfi_start_xs.
Return proper sense data when a polling command fails.


# 1.33 16-May-2006 marco

Fix some more htole32 screw-ups.
Colapse all little SCSI functions into a single generic one.
Fix a bug in the SGE calculation.

This brings the driver up to post:
mfi0 at pci12 dev 14 function 0 "Dell PERC SAS" rev 0x00: Dell PERC 5/e irq 5
scsibus3 at mfi0: 2 targets
sd1 at scsibus3 targ 0 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd1: 237824MB, 237824 cyl, 64 head, 32 sec, 512 bytes/sec, 487063552 sec total
sd2 at scsibus3 targ 1 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd2: 34176MB, 34176 cyl, 64 head, 32 sec, 512 bytes/sec, 69992448 sec total


# 1.32 16-May-2006 marco

Fix some htole32 I missed.
Sprinkle more debug.


# 1.31 16-May-2006 marco

Add READ CAPACITY.


# 1.30 16-May-2006 marco

Oops PREREAD not PREWRITE.


# 1.29 16-May-2006 marco

Add TUR and make it send it directly to firmware.
Sprinkle some extra debug.


# 1.28 15-May-2006 marco

Clear all relevant ccb fields when mfi_put_ccb frees a ccb.


# 1.27 15-May-2006 marco

Oops don't send command twice to firmware when polling.


# 1.26 15-May-2006 marco

Add INQUIRY command.
Add sgl magic.


# 1.25 10-May-2006 marco

Add some airplane code.

add bio hooks.
add scsi entry point for io.


# 1.24 26-Apr-2006 marco

Fix some debug prints.


# 1.23 21-Apr-2006 marco

typo


# 1.22 21-Apr-2006 marco

Add mfi_poll and use the new shiny function to setup all the hardware queues.
Lots of ideas from the FreeBSD driver.


# 1.21 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.20 20-Apr-2006 dlg

marco hates typedefs as much as i do, so he asked me to clean mfi like i
just did with ami. this gets rid of the typedef for the ccb lists.

also uses TAILQ_FIRST to get ccbs off the freelist. this is a proactive
fix for a lint teary.


# 1.19 18-Apr-2006 marco

It helps to initialize a queue before usage.


# 1.18 18-Apr-2006 marco

Actually add ccbs to the queue.
Fix the error path for mfi_init_ccb.
Alter dmamap for io.


# 1.17 17-Apr-2006 marco

Sprinkle more debug. Remove 64 byte boundary; it doesn't seem to like it.
Hack around 64 byte boundary for the frames for now.


# 1.16 17-Apr-2006 marco

Setup ccbs and clean up ccb structure.


# 1.15 16-Apr-2006 marco

Oops, make mfi_allocmem always use 64 byte boundaries since frames have to
have that alignment. It doesn't matter for the other consumers of the
function.


# 1.14 16-Apr-2006 marco

Add frame memory and sglist allocation.


# 1.13 16-Apr-2006 marco

Make memory access use macro.


# 1.12 16-Apr-2006 marco

typo


# 1.11 16-Apr-2006 marco

Add get and put ccb functions. Shuffle some more definitions.


# 1.10 16-Apr-2006 marco

Nicer print when context is invalid.


# 1.9 16-Apr-2006 marco

Shuffle some #defines.
Fix comments.
Add human readable enable intrrupt #define.


# 1.8 16-Apr-2006 marco

Add interrupt handler. Idea borrowed from FreeBSD since it is much nicer
than the Linux one.


# 1.7 07-Apr-2006 marco

Replace bus_space functions with generic ones that do barriers.


# 1.6 07-Apr-2006 marco

Add memory allocator functions.


# 1.5 07-Apr-2006 marco

Print state in debug. Change return vales to 1 instead of ENXIO.


# 1.4 07-Apr-2006 marco

Make a better debug mechanism.


# 1.3 07-Apr-2006 marco

Enable mfi_transition_fw() original code from FreeBSD.


# 1.2 06-Apr-2006 marco

Add fw transition logic.


# 1.1 06-Apr-2006 marco

Add skeleton driver for MegaRAID SAS.


# 1.184 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.183 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.182 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.181 13-Jul-2020 krw

Where we have a pointer (sc) to the relevant adapter_softc, use
&sc->sc_dev to get a device pointer rather than using the void *
whence we obtained 'sc'.


# 1.180 13-Jul-2020 krw

Remove some pointless casting of void * when assigning one
(scsi_link.adapter_softc) to a pointer of a particular softc type.


# 1.179 27-Jun-2020 krw

Nuke trailing whitespace.


# 1.178 27-Jun-2020 krw

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


# 1.177 24-Jun-2020 krw

Use SDEV_NO_ADAPTER_TARGET instead of -1 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.176 21-Mar-2020 krw

Simplify some goto'ing that jumps a single line or
does nothing at all.

The first one spotted as CID 1452976.

Reads good to millert@

ok mpi@


# 1.175 13-Feb-2020 krw

Nuke *_minphys() functions that either simply apply MAXPHYS or do
nothing at all. MAXPHYS will be applied in minphys() and nothing at
all, well, doesn't do anything.

Also remove any '#define <blah> MAXPHYS' statements used solely to
disguise MAXPHYS in said functions.


# 1.174 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.173 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.172 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.171 31-Dec-2019 mpi

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

ok kn@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.170 05-Mar-2019 jmatthew

apply background init progress fix from r1.59 of mfii.c
(reverting most of r1.60 of mfi.c, oddly enough)

ok dlg@
tested on a SAS2008 (perc h310)


Revision tags: OPENBSD_6_4_BASE
# 1.169 14-Aug-2018 jmatthew

return ENOTTY rather than EINVAL to indicate an ioctl hasn't been handled

ok dlg@ deraadt@ kettenis@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.168 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.167 02-Feb-2017 dlg

copy the mbox into the dcmd struct, not the pointer to the mbox.

makes bioctl work on mfi(4) again.

while here memset a few mboxes before using them.

bioctl breakage reported by jason george


# 1.166 23-Jan-2017 dlg

represent the mbox layout with union instead of an array of bytes.

memcpying uint16_ts into inconsistently addressed offsets is hard
to read, and this makes future work easier to implement.

tested on mfi(4) and mfii(4)


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.165 09-Sep-2015 deraadt

sizes for free(); ok sthen


Revision tags: OPENBSD_5_8_BASE
# 1.164 29-May-2015 uebayasi

Initial addition of ``Patrol Read'' support in bio(4), biocto(8), and
mfi(4). Based on FreeBSD, but done without mfiutil(8).

OK deraadt@


# 1.163 18-May-2015 mikeb

Prevent splassert from firing during sd_flush which runs "cold"

While mfi(4) should pass SCSI transfer flags (e.g. SCSI_POLL and
SCSI_NOSLEEP) down to the management function, make it at least
use "cold" consistently for now.

ok dlg


# 1.162 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.161 08-Mar-2015 dlg

properly set sgl related flags on skinny controllers. this fixes
io against physical disks on my dell perc h310s. logical disks still
work fine.

ok deraadt@ yasuoka@


# 1.160 08-Feb-2015 yasuoka

Fix mfi ioctl to set drive state properly.
diff from Tsubai Masanari

test dlg jmatthew
ok dlg


# 1.159 09-Jan-2015 yasuoka

Add support DIOC{G,S}CACHE to mfi(4). Cache of disk on mfi(4) will
be enabled by default. Also if the controller doesn't have any RAM,
the cache on the physical disk will be enabled.

discuss with jsg tsubai
ok dlg


# 1.158 19-Dec-2014 deraadt

another handful of bcopy -> memcpy because there is no overlap


# 1.157 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.156 09-Sep-2014 dlg

mark the interrupt handler mpsafe, and give up biglock in the scsi cmd
submission paths. take biglock again when calling back into the scsi
stack.

tested on a variety of cards here, including the skinny mfis on the
firewall next to mpsafe myx.


# 1.155 15-Aug-2014 yasuoka

Create a function which loads sgd in the mfi_iop_ops struct so that skinny
adapters can use "IEEE sgl".

tested dlg yasuoka
ok dlg jsg


Revision tags: OPENBSD_5_6_BASE
# 1.154 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.153 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.152 04-May-2014 sf

format string fixes for bus_addr_t and bus_size_t

bus_addr_t and bus_size_t are u_long everywhere

ok kettenis@


Revision tags: OPENBSD_5_5_BASE
# 1.151 20-Feb-2014 kettenis

revert previous commit; didn't intend to commit those bits


# 1.150 20-Feb-2014 kettenis

Avoid printing the "nvram corrupt" message for onboard 2200s found on Sun
hardware.

ok dlg@, jmatthew@


# 1.149 04-Dec-2013 dlg

mfi_refresh_sensors calls mfi_ioctl_vol which calls mfi_bio_getitall, which
replaces pointers in the softc and all sorts of fun stuff. this protects
the call to bio_getitall with the sc_lock the ioctl path uses, so we dont
get panics like those reported on bugs@ recently.

ok deraadt@


# 1.148 23-Oct-2013 kettenis

Add support for displaying the cache write policy of RAID volumes to bioctl(8)
and make mfi(4) pass up the necessary information. Adding support for other
RAID controllers is left as an excercise to the reader.

ok deraadt@


# 1.147 09-Oct-2013 jmatthew

Include the 'state of health' field in the bbu ok sensor value.
The dell perc 6/i sets this to zero (meaning bad) when it
decides the battery doesn't have enough capacity for it to
allow write back mode, but doesn't set any of the other flags
to tell us why.

ok dlg@, tested by sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.146 18-May-2013 jmc

enw->new in comment;
spotted by krw, missed by jsg, and forwarded From: Alexey Suslikov


# 1.145 08-May-2013 jsg

fix some leaks in error paths
ok fgsch@ krw@ kettenis@


# 1.144 03-May-2013 dlg

break out the battery status into excruciating detail. makes it harder for
$VENDOR to complain about a lack of diagnostic material from their crappy
mgmt tools if you're not running an operating system they support.


# 1.143 02-May-2013 dlg

always attach the battery sensor if the adapter lets us query it.
newly replaced batteries dont show up immediately.


# 1.142 01-May-2013 dlg

provide a sensor for the battery backup unit (bbu) on mfi boards that
support it.

now i can tell (a bit better) why io might be slow on some of my boxes.


# 1.141 01-May-2013 dlg

dont need to walk alldevs during sensor creation looking for the logical
disk scsibus when we record that in mfi_attach.

also happens to get rid of a logic error that let it come out of the loop
on alldevs with a reference to something that wasnt the logical disk
scsibus and use that.


# 1.140 30-Apr-2013 dlg

use MR_DCMD consistently. some MD_DCMD was in there somehow.


# 1.139 07-Apr-2013 dlg

david imhoff points out that the error handling in mfi_init_ccb gets the
index to which ccb to free wrong.

this takes the logic from mpi/mpii/mfii which pulls the ready ccbs off
the free list rather than rely on the current index from the for loop
that we failed inside of.

thanks to david for finding this out.


Revision tags: OPENBSD_5_3_BASE
# 1.138 12-Sep-2012 haesbaert

Make sure we don't sleep on autoconf.

ok mikeb


# 1.137 17-Aug-2012 dlg

add support for "physical devices" on skinny controllers.

these controllers let you specify disks that should be accessed directly
rather than be part of logical volumes. apparently you can plug in things
like tape drives too.

anyway, physical devices are exposed via a separate scsibus attached to
mfi.

ok mikeb@


# 1.136 16-Aug-2012 dlg

fix mfi_poll by having it do delays between loops, and breaking on
timeouts. how embarrassment.

implement mfi_exec for doing sync executions of commands in process
contexts and cut mfi_mgmt over to it.


# 1.135 16-Aug-2012 dlg

rework mfi_poll so it will do all the completions on a ccb including
calling the done handler.

this makes it consistently complete scsi io with all the proper error
checking.


# 1.134 16-Aug-2012 dlg

stop passing mfi_softc around as a member of the ccb, consistently give it
as the first argument to functions. like mfii.


# 1.133 16-Aug-2012 dlg

scrub ccbs when we're about to use them, not when we put them back
on the free list. ccbs can be reused, so we dont want old state screwing up
new commands.


# 1.132 16-Aug-2012 dlg

move the dma syncs for the ccb data into ccb_done, so we can do it once
rather than put the code everywhere.


# 1.131 16-Aug-2012 dlg

fix up the dma sync for the command frame in mfi_done.


# 1.130 14-Aug-2012 dlg

use scsi_get_link to find out the name of a child device for bioctl rather
than snoop scsi commands and copy it in an io path.

no functional change, but the code has one less XXX now.


# 1.129 14-Aug-2012 dlg

expose the max number of logical volumes the hardware supports as the width
of its scsibus. only advertise 1 lun on logical volumes instead of letting
the midlayer fix it up to 8.

give every target on the bus max_cmds openings. iopools means they will
properly share access to them.

this in particular is useful on skinny controllers which only advertise 31
command slots. if you have 16 volumes, theyll only get 1 opening each with
the old maths. this way round the ones that are busy will share the slots.

tested on a perc5 with two volumes and hard workloads.


# 1.128 14-Aug-2012 dlg

print the boards name (eg, perc 5/i) according to the firmware like mfii.

ok deraadt@


# 1.127 14-Aug-2012 dlg

move knowledge of the location of the inbound doorbell out of code in
transition_firmware into a member of the iop structures.

ok mikeb@ haesbaert@


# 1.126 13-Aug-2012 dlg

get rid of the last foo_lo and foo_hi bits i could find in the hardware
structures and use htole64 instead of htole32(addr >> 32); htole32(addr);

gets rid of "handy" stack variables to get the dva to 64bits.

sprinkle some more byte swaps for things that should have it.

tested on a perc5 (xscale)


# 1.125 13-Aug-2012 dlg

do appropriate bus_dmamapy_syncs around the pcq/completion ring.

tested on a perc5 (xscale)


# 1.124 13-Aug-2012 dlg

replace uint32_ts for hi and lo addresses in the mfi_init_ hardware
descriptors with single uint64_ts. theyre not some weird middle
endian thing. this makes the code more readable.

add some missing htole32s to the code while here.

tested on a perc5 (xscale).


# 1.123 11-Aug-2012 dlg

the producer/consumer values are used by the device, which is little
endian. do appropriate byteswapping for when the host cpu uses them.

tested on a perc5 (xscale) in an amd64.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.122 12-Jan-2012 dlg

add support for skinny variants.

from Alexey Suslikov
reviewed by marco


Revision tags: OPENBSD_5_0_BASE
# 1.121 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.120 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.119 09-Apr-2011 marco

add all 64 bit dma plumbing but stick with 32 for now by default.

ok deraadt


# 1.118 09-Apr-2011 marco

make sure the upper 32 bits are always written to instead of assuming it
is 0.

ok deraadt.


# 1.117 08-Apr-2011 marco

kill some stray spaces


# 1.116 08-Apr-2011 marco

rename wiat channel to something less than 8 chars.

prompted by deraadt


# 1.115 08-Apr-2011 marco

use dma_alloc for transient management commands.

prodded and ok deraadt


Revision tags: OPENBSD_4_9_BASE
# 1.114 30-Dec-2010 dlg

cut mfi over to using iopools.

this gets rid of NO_CCB, provides better scheduling of io between busy
logical volumes on the same controller, and makes the ioctl and sensor
paths more reliable.

this is the least intrusive version of this change i could come up with. it
only took 4 or 5 goes...

ok marco@
deraadt@ says this is a good time for this change.


# 1.113 24-Sep-2010 dlg

no use setting cmd in mfi_ioctl_setstate if you never use it.


# 1.112 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


# 1.111 29-Aug-2010 dlg

the scsi completion code thinks that if you dont get MFI_STAT_OK
back from the chip on a command then the command completely failed.
MFI_STAT_SCSI_DONE_WITH_ERROR really means the command completed
fine, but there's some sense data too. this tweaks the handling to
be more appropriate, as per the linux and solaris drivers.

timed out waiting for beck@
putting this in cos its obviously more correct than the current code.


Revision tags: OPENBSD_4_8_BASE
# 1.110 22-Jul-2010 matthew

SCSI HBA drivers are supposed to get their SCSI CDBs from xs->cmd, not
xs->cmdstore.

ok krw@ a while back (contingent upon testing), and deraadt@ says this
has been in snapshots for weeks now.


# 1.109 01-Jul-2010 matthew

Change scsibus(4)'s scsi_link array to an SLIST to save memory on
sparsely populated buses.

ok dlg@, krw@


# 1.108 30-Jun-2010 mk

Use SLIST for the ccb free list.

ok krw, discontent grunts from marco.


# 1.107 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.106 15-Jun-2010 dlg

dont pass the dev_t from the scsi device drivers into the midlayer for
ioctl requests, and dont pass the proc pointers around for any ioctl
requests in scsi land at all. neither were used, so trim the fat.

ok krw@ marco@


# 1.105 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.104 16-May-2010 nicm

Use a temporary variable for now to sidestep -Wbounded checking when
copying vendor[8]/product[16]/revision[4] out of struct scsi_inquiry_data
together with one memcopy.

ok krw


# 1.103 22-Apr-2010 oga

use BUS_DMA_ZERO on alloc instead of bzeroing after.

ok dlg@, marco@


# 1.102 10-Apr-2010 marco

grrr var names in protos


# 1.101 10-Apr-2010 marco

sprinkle some bus_dmamap_sync around frame access.
prompted by oga


# 1.100 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.99 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.98 04-Jan-2010 dlg

rename ccb_xs to ccb_cookie and change its type from a scsi_xfer * to a
void *. this lets us pass things other than scsi_xfers to ccb completion
handlers.


# 1.97 04-Jan-2010 dlg

protect the ccb free queue with a mutex rather than splbio


# 1.96 03-Jan-2010 chl

change M_WAITOK --> M_WAITOK|M_CANFAIL

with input from marco@

ok marco@ krw@

this was ok looooooooong time ago but lost in my mailbox


Revision tags: OPENBSD_4_6_BASE
# 1.95 30-Apr-2009 marco

Add READ(16) & WRITE(16) commands.
ok krw


# 1.94 29-Apr-2009 marco

MFI_D_IOCTL should be commented out. No binary change.


# 1.93 04-Apr-2009 dlg

scrub more fields in the ccb when returning them to the free list after
theyve been used, in particular the mfi header flags which has a bit
that specifies if a command should be completed via the interrupt path.

if we use a ccb during boot we set that bit, but it isnt necessarily
cleared by things that use it later on. this means a ccb we expected to
complete via an interrupt never actually generates an interrupt or appears
in the reply queue. this obviously stalls the io.


# 1.92 29-Mar-2009 marco

spello


# 1.91 29-Mar-2009 dlg

when we steal the SYNC CACHE command in mfi_scsi_cmd we still have to
mark the xs as done and call scsi_done for it rather than just returning
COMPLETE.


# 1.90 29-Mar-2009 dlg

fix a small race in mfi_mgmt between the checking of a ccbs completion and
the sleep waiting for the completion. it is possible to get the interrupt
completing the command just before the tsleep, which will never get a
wakeup because the interrupt with the wakeup has already happened.


Revision tags: OPENBSD_4_5_BASE
# 1.89 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.


# 1.88 28-Jan-2009 marco

Add support for next generation megaraid sas raid controllers.
From Jim Giannoules <gortag@gmail.com>


# 1.87 31-Oct-2008 marco

Generalize function to obtain all details to do bio stuff. This is in
preparation to start showing unsused disks which will require all this
information to do the math.

While at it fix a size of hotspare volume bug.


# 1.86 30-Oct-2008 marco

Fix bug that when there are no volumes but there are hot spares it would
no show the hotspares.


# 1.85 28-Oct-2008 marco

Fix output when reporting on multivolume disk groups.

Reported by mitja@muzenic.net


# 1.84 27-Oct-2008 marco

Move some include stuff around


# 1.83 26-Oct-2008 marco

Space


# 1.82 23-Oct-2008 marco

Fix PR5645
ok dlg
tested beck and others


# 1.81 25-Sep-2008 krw

Initialize 'ssc' to NULL since we test it later. Shouldn't ever be
NULL at the point of test unless the device list is confused, but
be consistantly paranoid if we're going to be paranoid.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.80 16-Feb-2008 krw

Return NO_CCB and not TRY_AGAIN_LATER when running out of ccb's.
Eliminates 'not queued' errors reported on the mailing lists.

Tested by Michael (belenus at bsdmail dot de).

ok marco@


# 1.79 11-Feb-2008 dlg

add support for the mfi controllers with the ppc iops, aka, LSI SAS1078 or
Dell PERC6.

committed off a machine booting and rooting off a perc6. tested on a perc5
by marco@
ok marco@


# 1.78 26-Jan-2008 brad

Set the return value instead of returning right away so that the DMA
memory is actually synched.

ok dlg@


# 1.77 26-Jan-2008 dlg

sync dma mem back to the cpu on poll failure.

from mickey via pr5714


# 1.76 26-Jan-2008 dlg

despatch -> dispatch

disparate spellink fix from mickey


# 1.75 05-Nov-2007 krw

More scsi_done() at SPLBIO.


# 1.74 27-Sep-2007 chl

M_ZERO changes

ok dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.73 24-Jun-2007 dlg

rework sensor tasks to use the kernels generic workq rather than a special
kernel thread of its own. the api has changed (which will be fixed in the
manpage shortly) so all the users of sensor tasks that i can find have
been fixed too.

noone tested, so its going in to force people to run with it.
"put it in" deraadt@


# 1.72 29-May-2007 todd

sprinkle some SMALL_KERNEL to permit bio/softraid to run on boot media
ok marco@ then suggested deraadt@


# 1.71 22-Mar-2007 deraadt

split userland & kernel struct sensor/sensordev so that the addition
of new fields in the future is less disruptive. This is done similar
to how struct proc is handled for ps(1). ok jmc (man page changes)
tested fkr simon, and more suggestions from millert


Revision tags: OPENBSD_4_1_BASE
# 1.70 14-Feb-2007 dlg

bus_space does byte swapping to cope with host endianness for us, so remove
an unnecessary htole32().


# 1.69 13-Feb-2007 marco

Fix subtle x ? y : z bug when calling mfi_create_sgl. This worked because
during runtime the bug condition does not happen.

ok krw joris


# 1.68 08-Feb-2007 ray

Remove double semicolons.

From Pierre Riteau <pierre dot riteau at free dot fr>.

OK marco@.


# 1.67 23-Dec-2006 deraadt

adapt to new two-level sensor api; Constantine A. Murenin


# 1.66 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.65 31-Aug-2006 marco

Add sensor thread for individual sd devices.

tested dlg
ok dlg deraadt


# 1.64 30-Aug-2006 dlg

when determining the size of the volumes and disks we want how many
bytes each of them has, not the number of kilobytes. this solves the
"why am i dividing by 2" question. the answer is "you dont, you multiply
by 512".


# 1.63 28-Jul-2006 brad

make dmesg printing look a little bit nicer.


# 1.62 19-Jun-2006 marco

Factor for disk size is /2. Odd but tested on all mfis I have.


# 1.61 19-Jun-2006 miod

Everytime one forgets an argument in a printf-like function call, God kills
a kitten. Commiters, please think of the kittens when working on code.


# 1.60 19-Jun-2006 marco

Make a BGI (Back Ground Init) a scrub instead of rebuild.


# 1.59 19-Jun-2006 marco

Add hot spare support.


# 1.58 26-May-2006 marco

Add blinking for disks.


# 1.57 25-May-2006 marco

Move a int i; to top of function so that it compiles on non c99 compilers.
Pointed out by miod@

The enclosure id modifier didn't reflect reality so move it back to whatever
the raid card uses.


# 1.56 25-May-2006 marco

And add time and percentage to builds and check consistencies.


# 1.55 25-May-2006 marco

Add last bit of physcal disk stuff.
Remove bogus memset.
Hotspares still don't work.


# 1.54 25-May-2006 marco

Add physical device and read config structures.
Add initial part of BIOCDISK


# 1.53 23-May-2006 deraadt

commited with unused variable


# 1.52 23-May-2006 marco

Remove some debug cruft.


# 1.51 23-May-2006 marco

Add first half of physical disk data for bio.


# 1.50 22-May-2006 marco

Add support for raid 50 and 10 in bio.


# 1.49 22-May-2006 marco

Add mail box to mfi_mgmt to handle sub commands more gracefully.
Remove some debug crud that snuck in the TEST_UNIT_READY case.
Finish other half of BIOCVOL primitive.
Add several structures to fill out the BIOCVOL primitive.


# 1.48 22-May-2006 marco

Add first half of BIOCVOL primitive.


# 1.47 21-May-2006 marco

Do a giant flush of disk and raid-card memory when SYNCHONIZE_CACHE is called.


# 1.46 21-May-2006 marco

pretty up some debug statements.


# 1.45 21-May-2006 marco

Add bio alarm function.
Redo mfi_mgmt to deal with zero data commands.


# 1.44 21-May-2006 marco

Add generic management function.
Redo ccb_state flags so that we can actually sleep on it.
Redo mfi_get_info to use new mgmt function.
Add rw_locks for mgmt interface.
Make BIOCINQ dynamic.


# 1.43 21-May-2006 marco

Oops, helps to use the right structure field.
Use actual nr of physical disks present.


# 1.42 21-May-2006 marco

Add first BIOCINQ primitive.


# 1.41 18-May-2006 marco

Remove some debug cruft and pretty up some debug messages.


# 1.40 18-May-2006 marco

Kill splbio/splx in the interrupt handler.


# 1.39 18-May-2006 marco

And we have lift off! Was able to create a filesystem and write to the
filesystem.

Collapse both completion routines into one.
Fixup scsi error reporting in the completion routine.


# 1.38 17-May-2006 marco

Add completion routines.
Fix some bugs inside the interrupt handler.


# 1.37 17-May-2006 marco

Add mfi_get_info to obtain all kinds of fun information from the fw.
Print out whole info structure when debug is enabled.
Add a nice print with useful info during attach.


# 1.36 17-May-2006 marco

Refactor scsi path so that we can have a single sgl function for io and non-io
traffic.
Redo parameters on functions that were passing too many parameters around.


# 1.35 16-May-2006 marco

Nuke some { }


# 1.34 16-May-2006 marco

Move !xs->data case into mfi_start_xs.
Return proper sense data when a polling command fails.


# 1.33 16-May-2006 marco

Fix some more htole32 screw-ups.
Colapse all little SCSI functions into a single generic one.
Fix a bug in the SGE calculation.

This brings the driver up to post:
mfi0 at pci12 dev 14 function 0 "Dell PERC SAS" rev 0x00: Dell PERC 5/e irq 5
scsibus3 at mfi0: 2 targets
sd1 at scsibus3 targ 0 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd1: 237824MB, 237824 cyl, 64 head, 32 sec, 512 bytes/sec, 487063552 sec total
sd2 at scsibus3 targ 1 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd2: 34176MB, 34176 cyl, 64 head, 32 sec, 512 bytes/sec, 69992448 sec total


# 1.32 16-May-2006 marco

Fix some htole32 I missed.
Sprinkle more debug.


# 1.31 16-May-2006 marco

Add READ CAPACITY.


# 1.30 16-May-2006 marco

Oops PREREAD not PREWRITE.


# 1.29 16-May-2006 marco

Add TUR and make it send it directly to firmware.
Sprinkle some extra debug.


# 1.28 15-May-2006 marco

Clear all relevant ccb fields when mfi_put_ccb frees a ccb.


# 1.27 15-May-2006 marco

Oops don't send command twice to firmware when polling.


# 1.26 15-May-2006 marco

Add INQUIRY command.
Add sgl magic.


# 1.25 10-May-2006 marco

Add some airplane code.

add bio hooks.
add scsi entry point for io.


# 1.24 26-Apr-2006 marco

Fix some debug prints.


# 1.23 21-Apr-2006 marco

typo


# 1.22 21-Apr-2006 marco

Add mfi_poll and use the new shiny function to setup all the hardware queues.
Lots of ideas from the FreeBSD driver.


# 1.21 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.20 20-Apr-2006 dlg

marco hates typedefs as much as i do, so he asked me to clean mfi like i
just did with ami. this gets rid of the typedef for the ccb lists.

also uses TAILQ_FIRST to get ccbs off the freelist. this is a proactive
fix for a lint teary.


# 1.19 18-Apr-2006 marco

It helps to initialize a queue before usage.


# 1.18 18-Apr-2006 marco

Actually add ccbs to the queue.
Fix the error path for mfi_init_ccb.
Alter dmamap for io.


# 1.17 17-Apr-2006 marco

Sprinkle more debug. Remove 64 byte boundary; it doesn't seem to like it.
Hack around 64 byte boundary for the frames for now.


# 1.16 17-Apr-2006 marco

Setup ccbs and clean up ccb structure.


# 1.15 16-Apr-2006 marco

Oops, make mfi_allocmem always use 64 byte boundaries since frames have to
have that alignment. It doesn't matter for the other consumers of the
function.


# 1.14 16-Apr-2006 marco

Add frame memory and sglist allocation.


# 1.13 16-Apr-2006 marco

Make memory access use macro.


# 1.12 16-Apr-2006 marco

typo


# 1.11 16-Apr-2006 marco

Add get and put ccb functions. Shuffle some more definitions.


# 1.10 16-Apr-2006 marco

Nicer print when context is invalid.


# 1.9 16-Apr-2006 marco

Shuffle some #defines.
Fix comments.
Add human readable enable intrrupt #define.


# 1.8 16-Apr-2006 marco

Add interrupt handler. Idea borrowed from FreeBSD since it is much nicer
than the Linux one.


# 1.7 07-Apr-2006 marco

Replace bus_space functions with generic ones that do barriers.


# 1.6 07-Apr-2006 marco

Add memory allocator functions.


# 1.5 07-Apr-2006 marco

Print state in debug. Change return vales to 1 instead of ENXIO.


# 1.4 07-Apr-2006 marco

Make a better debug mechanism.


# 1.3 07-Apr-2006 marco

Enable mfi_transition_fw() original code from FreeBSD.


# 1.2 06-Apr-2006 marco

Add fw transition logic.


# 1.1 06-Apr-2006 marco

Add skeleton driver for MegaRAID SAS.


# 1.182 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.181 13-Jul-2020 krw

Where we have a pointer (sc) to the relevant adapter_softc, use
&sc->sc_dev to get a device pointer rather than using the void *
whence we obtained 'sc'.


# 1.180 13-Jul-2020 krw

Remove some pointless casting of void * when assigning one
(scsi_link.adapter_softc) to a pointer of a particular softc type.


# 1.179 27-Jun-2020 krw

Nuke trailing whitespace.


# 1.178 27-Jun-2020 krw

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


# 1.177 24-Jun-2020 krw

Use SDEV_NO_ADAPTER_TARGET instead of -1 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.176 21-Mar-2020 krw

Simplify some goto'ing that jumps a single line or
does nothing at all.

The first one spotted as CID 1452976.

Reads good to millert@

ok mpi@


# 1.175 13-Feb-2020 krw

Nuke *_minphys() functions that either simply apply MAXPHYS or do
nothing at all. MAXPHYS will be applied in minphys() and nothing at
all, well, doesn't do anything.

Also remove any '#define <blah> MAXPHYS' statements used solely to
disguise MAXPHYS in said functions.


# 1.174 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.173 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.172 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.171 31-Dec-2019 mpi

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

ok kn@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.170 05-Mar-2019 jmatthew

apply background init progress fix from r1.59 of mfii.c
(reverting most of r1.60 of mfi.c, oddly enough)

ok dlg@
tested on a SAS2008 (perc h310)


Revision tags: OPENBSD_6_4_BASE
# 1.169 14-Aug-2018 jmatthew

return ENOTTY rather than EINVAL to indicate an ioctl hasn't been handled

ok dlg@ deraadt@ kettenis@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.168 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.167 02-Feb-2017 dlg

copy the mbox into the dcmd struct, not the pointer to the mbox.

makes bioctl work on mfi(4) again.

while here memset a few mboxes before using them.

bioctl breakage reported by jason george


# 1.166 23-Jan-2017 dlg

represent the mbox layout with union instead of an array of bytes.

memcpying uint16_ts into inconsistently addressed offsets is hard
to read, and this makes future work easier to implement.

tested on mfi(4) and mfii(4)


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.165 09-Sep-2015 deraadt

sizes for free(); ok sthen


Revision tags: OPENBSD_5_8_BASE
# 1.164 29-May-2015 uebayasi

Initial addition of ``Patrol Read'' support in bio(4), biocto(8), and
mfi(4). Based on FreeBSD, but done without mfiutil(8).

OK deraadt@


# 1.163 18-May-2015 mikeb

Prevent splassert from firing during sd_flush which runs "cold"

While mfi(4) should pass SCSI transfer flags (e.g. SCSI_POLL and
SCSI_NOSLEEP) down to the management function, make it at least
use "cold" consistently for now.

ok dlg


# 1.162 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.161 08-Mar-2015 dlg

properly set sgl related flags on skinny controllers. this fixes
io against physical disks on my dell perc h310s. logical disks still
work fine.

ok deraadt@ yasuoka@


# 1.160 08-Feb-2015 yasuoka

Fix mfi ioctl to set drive state properly.
diff from Tsubai Masanari

test dlg jmatthew
ok dlg


# 1.159 09-Jan-2015 yasuoka

Add support DIOC{G,S}CACHE to mfi(4). Cache of disk on mfi(4) will
be enabled by default. Also if the controller doesn't have any RAM,
the cache on the physical disk will be enabled.

discuss with jsg tsubai
ok dlg


# 1.158 19-Dec-2014 deraadt

another handful of bcopy -> memcpy because there is no overlap


# 1.157 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.156 09-Sep-2014 dlg

mark the interrupt handler mpsafe, and give up biglock in the scsi cmd
submission paths. take biglock again when calling back into the scsi
stack.

tested on a variety of cards here, including the skinny mfis on the
firewall next to mpsafe myx.


# 1.155 15-Aug-2014 yasuoka

Create a function which loads sgd in the mfi_iop_ops struct so that skinny
adapters can use "IEEE sgl".

tested dlg yasuoka
ok dlg jsg


Revision tags: OPENBSD_5_6_BASE
# 1.154 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.153 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.152 04-May-2014 sf

format string fixes for bus_addr_t and bus_size_t

bus_addr_t and bus_size_t are u_long everywhere

ok kettenis@


Revision tags: OPENBSD_5_5_BASE
# 1.151 20-Feb-2014 kettenis

revert previous commit; didn't intend to commit those bits


# 1.150 20-Feb-2014 kettenis

Avoid printing the "nvram corrupt" message for onboard 2200s found on Sun
hardware.

ok dlg@, jmatthew@


# 1.149 04-Dec-2013 dlg

mfi_refresh_sensors calls mfi_ioctl_vol which calls mfi_bio_getitall, which
replaces pointers in the softc and all sorts of fun stuff. this protects
the call to bio_getitall with the sc_lock the ioctl path uses, so we dont
get panics like those reported on bugs@ recently.

ok deraadt@


# 1.148 23-Oct-2013 kettenis

Add support for displaying the cache write policy of RAID volumes to bioctl(8)
and make mfi(4) pass up the necessary information. Adding support for other
RAID controllers is left as an excercise to the reader.

ok deraadt@


# 1.147 09-Oct-2013 jmatthew

Include the 'state of health' field in the bbu ok sensor value.
The dell perc 6/i sets this to zero (meaning bad) when it
decides the battery doesn't have enough capacity for it to
allow write back mode, but doesn't set any of the other flags
to tell us why.

ok dlg@, tested by sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.146 18-May-2013 jmc

enw->new in comment;
spotted by krw, missed by jsg, and forwarded From: Alexey Suslikov


# 1.145 08-May-2013 jsg

fix some leaks in error paths
ok fgsch@ krw@ kettenis@


# 1.144 03-May-2013 dlg

break out the battery status into excruciating detail. makes it harder for
$VENDOR to complain about a lack of diagnostic material from their crappy
mgmt tools if you're not running an operating system they support.


# 1.143 02-May-2013 dlg

always attach the battery sensor if the adapter lets us query it.
newly replaced batteries dont show up immediately.


# 1.142 01-May-2013 dlg

provide a sensor for the battery backup unit (bbu) on mfi boards that
support it.

now i can tell (a bit better) why io might be slow on some of my boxes.


# 1.141 01-May-2013 dlg

dont need to walk alldevs during sensor creation looking for the logical
disk scsibus when we record that in mfi_attach.

also happens to get rid of a logic error that let it come out of the loop
on alldevs with a reference to something that wasnt the logical disk
scsibus and use that.


# 1.140 30-Apr-2013 dlg

use MR_DCMD consistently. some MD_DCMD was in there somehow.


# 1.139 07-Apr-2013 dlg

david imhoff points out that the error handling in mfi_init_ccb gets the
index to which ccb to free wrong.

this takes the logic from mpi/mpii/mfii which pulls the ready ccbs off
the free list rather than rely on the current index from the for loop
that we failed inside of.

thanks to david for finding this out.


Revision tags: OPENBSD_5_3_BASE
# 1.138 12-Sep-2012 haesbaert

Make sure we don't sleep on autoconf.

ok mikeb


# 1.137 17-Aug-2012 dlg

add support for "physical devices" on skinny controllers.

these controllers let you specify disks that should be accessed directly
rather than be part of logical volumes. apparently you can plug in things
like tape drives too.

anyway, physical devices are exposed via a separate scsibus attached to
mfi.

ok mikeb@


# 1.136 16-Aug-2012 dlg

fix mfi_poll by having it do delays between loops, and breaking on
timeouts. how embarrassment.

implement mfi_exec for doing sync executions of commands in process
contexts and cut mfi_mgmt over to it.


# 1.135 16-Aug-2012 dlg

rework mfi_poll so it will do all the completions on a ccb including
calling the done handler.

this makes it consistently complete scsi io with all the proper error
checking.


# 1.134 16-Aug-2012 dlg

stop passing mfi_softc around as a member of the ccb, consistently give it
as the first argument to functions. like mfii.


# 1.133 16-Aug-2012 dlg

scrub ccbs when we're about to use them, not when we put them back
on the free list. ccbs can be reused, so we dont want old state screwing up
new commands.


# 1.132 16-Aug-2012 dlg

move the dma syncs for the ccb data into ccb_done, so we can do it once
rather than put the code everywhere.


# 1.131 16-Aug-2012 dlg

fix up the dma sync for the command frame in mfi_done.


# 1.130 14-Aug-2012 dlg

use scsi_get_link to find out the name of a child device for bioctl rather
than snoop scsi commands and copy it in an io path.

no functional change, but the code has one less XXX now.


# 1.129 14-Aug-2012 dlg

expose the max number of logical volumes the hardware supports as the width
of its scsibus. only advertise 1 lun on logical volumes instead of letting
the midlayer fix it up to 8.

give every target on the bus max_cmds openings. iopools means they will
properly share access to them.

this in particular is useful on skinny controllers which only advertise 31
command slots. if you have 16 volumes, theyll only get 1 opening each with
the old maths. this way round the ones that are busy will share the slots.

tested on a perc5 with two volumes and hard workloads.


# 1.128 14-Aug-2012 dlg

print the boards name (eg, perc 5/i) according to the firmware like mfii.

ok deraadt@


# 1.127 14-Aug-2012 dlg

move knowledge of the location of the inbound doorbell out of code in
transition_firmware into a member of the iop structures.

ok mikeb@ haesbaert@


# 1.126 13-Aug-2012 dlg

get rid of the last foo_lo and foo_hi bits i could find in the hardware
structures and use htole64 instead of htole32(addr >> 32); htole32(addr);

gets rid of "handy" stack variables to get the dva to 64bits.

sprinkle some more byte swaps for things that should have it.

tested on a perc5 (xscale)


# 1.125 13-Aug-2012 dlg

do appropriate bus_dmamapy_syncs around the pcq/completion ring.

tested on a perc5 (xscale)


# 1.124 13-Aug-2012 dlg

replace uint32_ts for hi and lo addresses in the mfi_init_ hardware
descriptors with single uint64_ts. theyre not some weird middle
endian thing. this makes the code more readable.

add some missing htole32s to the code while here.

tested on a perc5 (xscale).


# 1.123 11-Aug-2012 dlg

the producer/consumer values are used by the device, which is little
endian. do appropriate byteswapping for when the host cpu uses them.

tested on a perc5 (xscale) in an amd64.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.122 12-Jan-2012 dlg

add support for skinny variants.

from Alexey Suslikov
reviewed by marco


Revision tags: OPENBSD_5_0_BASE
# 1.121 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.120 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.119 09-Apr-2011 marco

add all 64 bit dma plumbing but stick with 32 for now by default.

ok deraadt


# 1.118 09-Apr-2011 marco

make sure the upper 32 bits are always written to instead of assuming it
is 0.

ok deraadt.


# 1.117 08-Apr-2011 marco

kill some stray spaces


# 1.116 08-Apr-2011 marco

rename wiat channel to something less than 8 chars.

prompted by deraadt


# 1.115 08-Apr-2011 marco

use dma_alloc for transient management commands.

prodded and ok deraadt


Revision tags: OPENBSD_4_9_BASE
# 1.114 30-Dec-2010 dlg

cut mfi over to using iopools.

this gets rid of NO_CCB, provides better scheduling of io between busy
logical volumes on the same controller, and makes the ioctl and sensor
paths more reliable.

this is the least intrusive version of this change i could come up with. it
only took 4 or 5 goes...

ok marco@
deraadt@ says this is a good time for this change.


# 1.113 24-Sep-2010 dlg

no use setting cmd in mfi_ioctl_setstate if you never use it.


# 1.112 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


# 1.111 29-Aug-2010 dlg

the scsi completion code thinks that if you dont get MFI_STAT_OK
back from the chip on a command then the command completely failed.
MFI_STAT_SCSI_DONE_WITH_ERROR really means the command completed
fine, but there's some sense data too. this tweaks the handling to
be more appropriate, as per the linux and solaris drivers.

timed out waiting for beck@
putting this in cos its obviously more correct than the current code.


Revision tags: OPENBSD_4_8_BASE
# 1.110 22-Jul-2010 matthew

SCSI HBA drivers are supposed to get their SCSI CDBs from xs->cmd, not
xs->cmdstore.

ok krw@ a while back (contingent upon testing), and deraadt@ says this
has been in snapshots for weeks now.


# 1.109 01-Jul-2010 matthew

Change scsibus(4)'s scsi_link array to an SLIST to save memory on
sparsely populated buses.

ok dlg@, krw@


# 1.108 30-Jun-2010 mk

Use SLIST for the ccb free list.

ok krw, discontent grunts from marco.


# 1.107 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.106 15-Jun-2010 dlg

dont pass the dev_t from the scsi device drivers into the midlayer for
ioctl requests, and dont pass the proc pointers around for any ioctl
requests in scsi land at all. neither were used, so trim the fat.

ok krw@ marco@


# 1.105 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.104 16-May-2010 nicm

Use a temporary variable for now to sidestep -Wbounded checking when
copying vendor[8]/product[16]/revision[4] out of struct scsi_inquiry_data
together with one memcopy.

ok krw


# 1.103 22-Apr-2010 oga

use BUS_DMA_ZERO on alloc instead of bzeroing after.

ok dlg@, marco@


# 1.102 10-Apr-2010 marco

grrr var names in protos


# 1.101 10-Apr-2010 marco

sprinkle some bus_dmamap_sync around frame access.
prompted by oga


# 1.100 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.99 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.98 04-Jan-2010 dlg

rename ccb_xs to ccb_cookie and change its type from a scsi_xfer * to a
void *. this lets us pass things other than scsi_xfers to ccb completion
handlers.


# 1.97 04-Jan-2010 dlg

protect the ccb free queue with a mutex rather than splbio


# 1.96 03-Jan-2010 chl

change M_WAITOK --> M_WAITOK|M_CANFAIL

with input from marco@

ok marco@ krw@

this was ok looooooooong time ago but lost in my mailbox


Revision tags: OPENBSD_4_6_BASE
# 1.95 30-Apr-2009 marco

Add READ(16) & WRITE(16) commands.
ok krw


# 1.94 29-Apr-2009 marco

MFI_D_IOCTL should be commented out. No binary change.


# 1.93 04-Apr-2009 dlg

scrub more fields in the ccb when returning them to the free list after
theyve been used, in particular the mfi header flags which has a bit
that specifies if a command should be completed via the interrupt path.

if we use a ccb during boot we set that bit, but it isnt necessarily
cleared by things that use it later on. this means a ccb we expected to
complete via an interrupt never actually generates an interrupt or appears
in the reply queue. this obviously stalls the io.


# 1.92 29-Mar-2009 marco

spello


# 1.91 29-Mar-2009 dlg

when we steal the SYNC CACHE command in mfi_scsi_cmd we still have to
mark the xs as done and call scsi_done for it rather than just returning
COMPLETE.


# 1.90 29-Mar-2009 dlg

fix a small race in mfi_mgmt between the checking of a ccbs completion and
the sleep waiting for the completion. it is possible to get the interrupt
completing the command just before the tsleep, which will never get a
wakeup because the interrupt with the wakeup has already happened.


Revision tags: OPENBSD_4_5_BASE
# 1.89 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.


# 1.88 28-Jan-2009 marco

Add support for next generation megaraid sas raid controllers.
From Jim Giannoules <gortag@gmail.com>


# 1.87 31-Oct-2008 marco

Generalize function to obtain all details to do bio stuff. This is in
preparation to start showing unsused disks which will require all this
information to do the math.

While at it fix a size of hotspare volume bug.


# 1.86 30-Oct-2008 marco

Fix bug that when there are no volumes but there are hot spares it would
no show the hotspares.


# 1.85 28-Oct-2008 marco

Fix output when reporting on multivolume disk groups.

Reported by mitja@muzenic.net


# 1.84 27-Oct-2008 marco

Move some include stuff around


# 1.83 26-Oct-2008 marco

Space


# 1.82 23-Oct-2008 marco

Fix PR5645
ok dlg
tested beck and others


# 1.81 25-Sep-2008 krw

Initialize 'ssc' to NULL since we test it later. Shouldn't ever be
NULL at the point of test unless the device list is confused, but
be consistantly paranoid if we're going to be paranoid.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.80 16-Feb-2008 krw

Return NO_CCB and not TRY_AGAIN_LATER when running out of ccb's.
Eliminates 'not queued' errors reported on the mailing lists.

Tested by Michael (belenus at bsdmail dot de).

ok marco@


# 1.79 11-Feb-2008 dlg

add support for the mfi controllers with the ppc iops, aka, LSI SAS1078 or
Dell PERC6.

committed off a machine booting and rooting off a perc6. tested on a perc5
by marco@
ok marco@


# 1.78 26-Jan-2008 brad

Set the return value instead of returning right away so that the DMA
memory is actually synched.

ok dlg@


# 1.77 26-Jan-2008 dlg

sync dma mem back to the cpu on poll failure.

from mickey via pr5714


# 1.76 26-Jan-2008 dlg

despatch -> dispatch

disparate spellink fix from mickey


# 1.75 05-Nov-2007 krw

More scsi_done() at SPLBIO.


# 1.74 27-Sep-2007 chl

M_ZERO changes

ok dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.73 24-Jun-2007 dlg

rework sensor tasks to use the kernels generic workq rather than a special
kernel thread of its own. the api has changed (which will be fixed in the
manpage shortly) so all the users of sensor tasks that i can find have
been fixed too.

noone tested, so its going in to force people to run with it.
"put it in" deraadt@


# 1.72 29-May-2007 todd

sprinkle some SMALL_KERNEL to permit bio/softraid to run on boot media
ok marco@ then suggested deraadt@


# 1.71 22-Mar-2007 deraadt

split userland & kernel struct sensor/sensordev so that the addition
of new fields in the future is less disruptive. This is done similar
to how struct proc is handled for ps(1). ok jmc (man page changes)
tested fkr simon, and more suggestions from millert


Revision tags: OPENBSD_4_1_BASE
# 1.70 14-Feb-2007 dlg

bus_space does byte swapping to cope with host endianness for us, so remove
an unnecessary htole32().


# 1.69 13-Feb-2007 marco

Fix subtle x ? y : z bug when calling mfi_create_sgl. This worked because
during runtime the bug condition does not happen.

ok krw joris


# 1.68 08-Feb-2007 ray

Remove double semicolons.

From Pierre Riteau <pierre dot riteau at free dot fr>.

OK marco@.


# 1.67 23-Dec-2006 deraadt

adapt to new two-level sensor api; Constantine A. Murenin


# 1.66 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.65 31-Aug-2006 marco

Add sensor thread for individual sd devices.

tested dlg
ok dlg deraadt


# 1.64 30-Aug-2006 dlg

when determining the size of the volumes and disks we want how many
bytes each of them has, not the number of kilobytes. this solves the
"why am i dividing by 2" question. the answer is "you dont, you multiply
by 512".


# 1.63 28-Jul-2006 brad

make dmesg printing look a little bit nicer.


# 1.62 19-Jun-2006 marco

Factor for disk size is /2. Odd but tested on all mfis I have.


# 1.61 19-Jun-2006 miod

Everytime one forgets an argument in a printf-like function call, God kills
a kitten. Commiters, please think of the kittens when working on code.


# 1.60 19-Jun-2006 marco

Make a BGI (Back Ground Init) a scrub instead of rebuild.


# 1.59 19-Jun-2006 marco

Add hot spare support.


# 1.58 26-May-2006 marco

Add blinking for disks.


# 1.57 25-May-2006 marco

Move a int i; to top of function so that it compiles on non c99 compilers.
Pointed out by miod@

The enclosure id modifier didn't reflect reality so move it back to whatever
the raid card uses.


# 1.56 25-May-2006 marco

And add time and percentage to builds and check consistencies.


# 1.55 25-May-2006 marco

Add last bit of physcal disk stuff.
Remove bogus memset.
Hotspares still don't work.


# 1.54 25-May-2006 marco

Add physical device and read config structures.
Add initial part of BIOCDISK


# 1.53 23-May-2006 deraadt

commited with unused variable


# 1.52 23-May-2006 marco

Remove some debug cruft.


# 1.51 23-May-2006 marco

Add first half of physical disk data for bio.


# 1.50 22-May-2006 marco

Add support for raid 50 and 10 in bio.


# 1.49 22-May-2006 marco

Add mail box to mfi_mgmt to handle sub commands more gracefully.
Remove some debug crud that snuck in the TEST_UNIT_READY case.
Finish other half of BIOCVOL primitive.
Add several structures to fill out the BIOCVOL primitive.


# 1.48 22-May-2006 marco

Add first half of BIOCVOL primitive.


# 1.47 21-May-2006 marco

Do a giant flush of disk and raid-card memory when SYNCHONIZE_CACHE is called.


# 1.46 21-May-2006 marco

pretty up some debug statements.


# 1.45 21-May-2006 marco

Add bio alarm function.
Redo mfi_mgmt to deal with zero data commands.


# 1.44 21-May-2006 marco

Add generic management function.
Redo ccb_state flags so that we can actually sleep on it.
Redo mfi_get_info to use new mgmt function.
Add rw_locks for mgmt interface.
Make BIOCINQ dynamic.


# 1.43 21-May-2006 marco

Oops, helps to use the right structure field.
Use actual nr of physical disks present.


# 1.42 21-May-2006 marco

Add first BIOCINQ primitive.


# 1.41 18-May-2006 marco

Remove some debug cruft and pretty up some debug messages.


# 1.40 18-May-2006 marco

Kill splbio/splx in the interrupt handler.


# 1.39 18-May-2006 marco

And we have lift off! Was able to create a filesystem and write to the
filesystem.

Collapse both completion routines into one.
Fixup scsi error reporting in the completion routine.


# 1.38 17-May-2006 marco

Add completion routines.
Fix some bugs inside the interrupt handler.


# 1.37 17-May-2006 marco

Add mfi_get_info to obtain all kinds of fun information from the fw.
Print out whole info structure when debug is enabled.
Add a nice print with useful info during attach.


# 1.36 17-May-2006 marco

Refactor scsi path so that we can have a single sgl function for io and non-io
traffic.
Redo parameters on functions that were passing too many parameters around.


# 1.35 16-May-2006 marco

Nuke some { }


# 1.34 16-May-2006 marco

Move !xs->data case into mfi_start_xs.
Return proper sense data when a polling command fails.


# 1.33 16-May-2006 marco

Fix some more htole32 screw-ups.
Colapse all little SCSI functions into a single generic one.
Fix a bug in the SGE calculation.

This brings the driver up to post:
mfi0 at pci12 dev 14 function 0 "Dell PERC SAS" rev 0x00: Dell PERC 5/e irq 5
scsibus3 at mfi0: 2 targets
sd1 at scsibus3 targ 0 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd1: 237824MB, 237824 cyl, 64 head, 32 sec, 512 bytes/sec, 487063552 sec total
sd2 at scsibus3 targ 1 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd2: 34176MB, 34176 cyl, 64 head, 32 sec, 512 bytes/sec, 69992448 sec total


# 1.32 16-May-2006 marco

Fix some htole32 I missed.
Sprinkle more debug.


# 1.31 16-May-2006 marco

Add READ CAPACITY.


# 1.30 16-May-2006 marco

Oops PREREAD not PREWRITE.


# 1.29 16-May-2006 marco

Add TUR and make it send it directly to firmware.
Sprinkle some extra debug.


# 1.28 15-May-2006 marco

Clear all relevant ccb fields when mfi_put_ccb frees a ccb.


# 1.27 15-May-2006 marco

Oops don't send command twice to firmware when polling.


# 1.26 15-May-2006 marco

Add INQUIRY command.
Add sgl magic.


# 1.25 10-May-2006 marco

Add some airplane code.

add bio hooks.
add scsi entry point for io.


# 1.24 26-Apr-2006 marco

Fix some debug prints.


# 1.23 21-Apr-2006 marco

typo


# 1.22 21-Apr-2006 marco

Add mfi_poll and use the new shiny function to setup all the hardware queues.
Lots of ideas from the FreeBSD driver.


# 1.21 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.20 20-Apr-2006 dlg

marco hates typedefs as much as i do, so he asked me to clean mfi like i
just did with ami. this gets rid of the typedef for the ccb lists.

also uses TAILQ_FIRST to get ccbs off the freelist. this is a proactive
fix for a lint teary.


# 1.19 18-Apr-2006 marco

It helps to initialize a queue before usage.


# 1.18 18-Apr-2006 marco

Actually add ccbs to the queue.
Fix the error path for mfi_init_ccb.
Alter dmamap for io.


# 1.17 17-Apr-2006 marco

Sprinkle more debug. Remove 64 byte boundary; it doesn't seem to like it.
Hack around 64 byte boundary for the frames for now.


# 1.16 17-Apr-2006 marco

Setup ccbs and clean up ccb structure.


# 1.15 16-Apr-2006 marco

Oops, make mfi_allocmem always use 64 byte boundaries since frames have to
have that alignment. It doesn't matter for the other consumers of the
function.


# 1.14 16-Apr-2006 marco

Add frame memory and sglist allocation.


# 1.13 16-Apr-2006 marco

Make memory access use macro.


# 1.12 16-Apr-2006 marco

typo


# 1.11 16-Apr-2006 marco

Add get and put ccb functions. Shuffle some more definitions.


# 1.10 16-Apr-2006 marco

Nicer print when context is invalid.


# 1.9 16-Apr-2006 marco

Shuffle some #defines.
Fix comments.
Add human readable enable intrrupt #define.


# 1.8 16-Apr-2006 marco

Add interrupt handler. Idea borrowed from FreeBSD since it is much nicer
than the Linux one.


# 1.7 07-Apr-2006 marco

Replace bus_space functions with generic ones that do barriers.


# 1.6 07-Apr-2006 marco

Add memory allocator functions.


# 1.5 07-Apr-2006 marco

Print state in debug. Change return vales to 1 instead of ENXIO.


# 1.4 07-Apr-2006 marco

Make a better debug mechanism.


# 1.3 07-Apr-2006 marco

Enable mfi_transition_fw() original code from FreeBSD.


# 1.2 06-Apr-2006 marco

Add fw transition logic.


# 1.1 06-Apr-2006 marco

Add skeleton driver for MegaRAID SAS.


# 1.181 13-Jul-2020 krw

Where we have a pointer (sc) to the relevant adapter_softc, use
&sc->sc_dev to get a device pointer rather than using the void *
whence we obtained 'sc'.


# 1.180 13-Jul-2020 krw

Remove some pointless casting of void * when assigning one
(scsi_link.adapter_softc) to a pointer of a particular softc type.


# 1.179 27-Jun-2020 krw

Nuke trailing whitespace.


# 1.178 27-Jun-2020 krw

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


# 1.177 24-Jun-2020 krw

Use SDEV_NO_ADAPTER_TARGET instead of -1 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.176 21-Mar-2020 krw

Simplify some goto'ing that jumps a single line or
does nothing at all.

The first one spotted as CID 1452976.

Reads good to millert@

ok mpi@


# 1.175 13-Feb-2020 krw

Nuke *_minphys() functions that either simply apply MAXPHYS or do
nothing at all. MAXPHYS will be applied in minphys() and nothing at
all, well, doesn't do anything.

Also remove any '#define <blah> MAXPHYS' statements used solely to
disguise MAXPHYS in said functions.


# 1.174 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.173 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.172 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.171 31-Dec-2019 mpi

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

ok kn@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.170 05-Mar-2019 jmatthew

apply background init progress fix from r1.59 of mfii.c
(reverting most of r1.60 of mfi.c, oddly enough)

ok dlg@
tested on a SAS2008 (perc h310)


Revision tags: OPENBSD_6_4_BASE
# 1.169 14-Aug-2018 jmatthew

return ENOTTY rather than EINVAL to indicate an ioctl hasn't been handled

ok dlg@ deraadt@ kettenis@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.168 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.167 02-Feb-2017 dlg

copy the mbox into the dcmd struct, not the pointer to the mbox.

makes bioctl work on mfi(4) again.

while here memset a few mboxes before using them.

bioctl breakage reported by jason george


# 1.166 23-Jan-2017 dlg

represent the mbox layout with union instead of an array of bytes.

memcpying uint16_ts into inconsistently addressed offsets is hard
to read, and this makes future work easier to implement.

tested on mfi(4) and mfii(4)


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.165 09-Sep-2015 deraadt

sizes for free(); ok sthen


Revision tags: OPENBSD_5_8_BASE
# 1.164 29-May-2015 uebayasi

Initial addition of ``Patrol Read'' support in bio(4), biocto(8), and
mfi(4). Based on FreeBSD, but done without mfiutil(8).

OK deraadt@


# 1.163 18-May-2015 mikeb

Prevent splassert from firing during sd_flush which runs "cold"

While mfi(4) should pass SCSI transfer flags (e.g. SCSI_POLL and
SCSI_NOSLEEP) down to the management function, make it at least
use "cold" consistently for now.

ok dlg


# 1.162 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.161 08-Mar-2015 dlg

properly set sgl related flags on skinny controllers. this fixes
io against physical disks on my dell perc h310s. logical disks still
work fine.

ok deraadt@ yasuoka@


# 1.160 08-Feb-2015 yasuoka

Fix mfi ioctl to set drive state properly.
diff from Tsubai Masanari

test dlg jmatthew
ok dlg


# 1.159 09-Jan-2015 yasuoka

Add support DIOC{G,S}CACHE to mfi(4). Cache of disk on mfi(4) will
be enabled by default. Also if the controller doesn't have any RAM,
the cache on the physical disk will be enabled.

discuss with jsg tsubai
ok dlg


# 1.158 19-Dec-2014 deraadt

another handful of bcopy -> memcpy because there is no overlap


# 1.157 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.156 09-Sep-2014 dlg

mark the interrupt handler mpsafe, and give up biglock in the scsi cmd
submission paths. take biglock again when calling back into the scsi
stack.

tested on a variety of cards here, including the skinny mfis on the
firewall next to mpsafe myx.


# 1.155 15-Aug-2014 yasuoka

Create a function which loads sgd in the mfi_iop_ops struct so that skinny
adapters can use "IEEE sgl".

tested dlg yasuoka
ok dlg jsg


Revision tags: OPENBSD_5_6_BASE
# 1.154 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.153 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.152 04-May-2014 sf

format string fixes for bus_addr_t and bus_size_t

bus_addr_t and bus_size_t are u_long everywhere

ok kettenis@


Revision tags: OPENBSD_5_5_BASE
# 1.151 20-Feb-2014 kettenis

revert previous commit; didn't intend to commit those bits


# 1.150 20-Feb-2014 kettenis

Avoid printing the "nvram corrupt" message for onboard 2200s found on Sun
hardware.

ok dlg@, jmatthew@


# 1.149 04-Dec-2013 dlg

mfi_refresh_sensors calls mfi_ioctl_vol which calls mfi_bio_getitall, which
replaces pointers in the softc and all sorts of fun stuff. this protects
the call to bio_getitall with the sc_lock the ioctl path uses, so we dont
get panics like those reported on bugs@ recently.

ok deraadt@


# 1.148 23-Oct-2013 kettenis

Add support for displaying the cache write policy of RAID volumes to bioctl(8)
and make mfi(4) pass up the necessary information. Adding support for other
RAID controllers is left as an excercise to the reader.

ok deraadt@


# 1.147 09-Oct-2013 jmatthew

Include the 'state of health' field in the bbu ok sensor value.
The dell perc 6/i sets this to zero (meaning bad) when it
decides the battery doesn't have enough capacity for it to
allow write back mode, but doesn't set any of the other flags
to tell us why.

ok dlg@, tested by sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.146 18-May-2013 jmc

enw->new in comment;
spotted by krw, missed by jsg, and forwarded From: Alexey Suslikov


# 1.145 08-May-2013 jsg

fix some leaks in error paths
ok fgsch@ krw@ kettenis@


# 1.144 03-May-2013 dlg

break out the battery status into excruciating detail. makes it harder for
$VENDOR to complain about a lack of diagnostic material from their crappy
mgmt tools if you're not running an operating system they support.


# 1.143 02-May-2013 dlg

always attach the battery sensor if the adapter lets us query it.
newly replaced batteries dont show up immediately.


# 1.142 01-May-2013 dlg

provide a sensor for the battery backup unit (bbu) on mfi boards that
support it.

now i can tell (a bit better) why io might be slow on some of my boxes.


# 1.141 01-May-2013 dlg

dont need to walk alldevs during sensor creation looking for the logical
disk scsibus when we record that in mfi_attach.

also happens to get rid of a logic error that let it come out of the loop
on alldevs with a reference to something that wasnt the logical disk
scsibus and use that.


# 1.140 30-Apr-2013 dlg

use MR_DCMD consistently. some MD_DCMD was in there somehow.


# 1.139 07-Apr-2013 dlg

david imhoff points out that the error handling in mfi_init_ccb gets the
index to which ccb to free wrong.

this takes the logic from mpi/mpii/mfii which pulls the ready ccbs off
the free list rather than rely on the current index from the for loop
that we failed inside of.

thanks to david for finding this out.


Revision tags: OPENBSD_5_3_BASE
# 1.138 12-Sep-2012 haesbaert

Make sure we don't sleep on autoconf.

ok mikeb


# 1.137 17-Aug-2012 dlg

add support for "physical devices" on skinny controllers.

these controllers let you specify disks that should be accessed directly
rather than be part of logical volumes. apparently you can plug in things
like tape drives too.

anyway, physical devices are exposed via a separate scsibus attached to
mfi.

ok mikeb@


# 1.136 16-Aug-2012 dlg

fix mfi_poll by having it do delays between loops, and breaking on
timeouts. how embarrassment.

implement mfi_exec for doing sync executions of commands in process
contexts and cut mfi_mgmt over to it.


# 1.135 16-Aug-2012 dlg

rework mfi_poll so it will do all the completions on a ccb including
calling the done handler.

this makes it consistently complete scsi io with all the proper error
checking.


# 1.134 16-Aug-2012 dlg

stop passing mfi_softc around as a member of the ccb, consistently give it
as the first argument to functions. like mfii.


# 1.133 16-Aug-2012 dlg

scrub ccbs when we're about to use them, not when we put them back
on the free list. ccbs can be reused, so we dont want old state screwing up
new commands.


# 1.132 16-Aug-2012 dlg

move the dma syncs for the ccb data into ccb_done, so we can do it once
rather than put the code everywhere.


# 1.131 16-Aug-2012 dlg

fix up the dma sync for the command frame in mfi_done.


# 1.130 14-Aug-2012 dlg

use scsi_get_link to find out the name of a child device for bioctl rather
than snoop scsi commands and copy it in an io path.

no functional change, but the code has one less XXX now.


# 1.129 14-Aug-2012 dlg

expose the max number of logical volumes the hardware supports as the width
of its scsibus. only advertise 1 lun on logical volumes instead of letting
the midlayer fix it up to 8.

give every target on the bus max_cmds openings. iopools means they will
properly share access to them.

this in particular is useful on skinny controllers which only advertise 31
command slots. if you have 16 volumes, theyll only get 1 opening each with
the old maths. this way round the ones that are busy will share the slots.

tested on a perc5 with two volumes and hard workloads.


# 1.128 14-Aug-2012 dlg

print the boards name (eg, perc 5/i) according to the firmware like mfii.

ok deraadt@


# 1.127 14-Aug-2012 dlg

move knowledge of the location of the inbound doorbell out of code in
transition_firmware into a member of the iop structures.

ok mikeb@ haesbaert@


# 1.126 13-Aug-2012 dlg

get rid of the last foo_lo and foo_hi bits i could find in the hardware
structures and use htole64 instead of htole32(addr >> 32); htole32(addr);

gets rid of "handy" stack variables to get the dva to 64bits.

sprinkle some more byte swaps for things that should have it.

tested on a perc5 (xscale)


# 1.125 13-Aug-2012 dlg

do appropriate bus_dmamapy_syncs around the pcq/completion ring.

tested on a perc5 (xscale)


# 1.124 13-Aug-2012 dlg

replace uint32_ts for hi and lo addresses in the mfi_init_ hardware
descriptors with single uint64_ts. theyre not some weird middle
endian thing. this makes the code more readable.

add some missing htole32s to the code while here.

tested on a perc5 (xscale).


# 1.123 11-Aug-2012 dlg

the producer/consumer values are used by the device, which is little
endian. do appropriate byteswapping for when the host cpu uses them.

tested on a perc5 (xscale) in an amd64.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.122 12-Jan-2012 dlg

add support for skinny variants.

from Alexey Suslikov
reviewed by marco


Revision tags: OPENBSD_5_0_BASE
# 1.121 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.120 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.119 09-Apr-2011 marco

add all 64 bit dma plumbing but stick with 32 for now by default.

ok deraadt


# 1.118 09-Apr-2011 marco

make sure the upper 32 bits are always written to instead of assuming it
is 0.

ok deraadt.


# 1.117 08-Apr-2011 marco

kill some stray spaces


# 1.116 08-Apr-2011 marco

rename wiat channel to something less than 8 chars.

prompted by deraadt


# 1.115 08-Apr-2011 marco

use dma_alloc for transient management commands.

prodded and ok deraadt


Revision tags: OPENBSD_4_9_BASE
# 1.114 30-Dec-2010 dlg

cut mfi over to using iopools.

this gets rid of NO_CCB, provides better scheduling of io between busy
logical volumes on the same controller, and makes the ioctl and sensor
paths more reliable.

this is the least intrusive version of this change i could come up with. it
only took 4 or 5 goes...

ok marco@
deraadt@ says this is a good time for this change.


# 1.113 24-Sep-2010 dlg

no use setting cmd in mfi_ioctl_setstate if you never use it.


# 1.112 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


# 1.111 29-Aug-2010 dlg

the scsi completion code thinks that if you dont get MFI_STAT_OK
back from the chip on a command then the command completely failed.
MFI_STAT_SCSI_DONE_WITH_ERROR really means the command completed
fine, but there's some sense data too. this tweaks the handling to
be more appropriate, as per the linux and solaris drivers.

timed out waiting for beck@
putting this in cos its obviously more correct than the current code.


Revision tags: OPENBSD_4_8_BASE
# 1.110 22-Jul-2010 matthew

SCSI HBA drivers are supposed to get their SCSI CDBs from xs->cmd, not
xs->cmdstore.

ok krw@ a while back (contingent upon testing), and deraadt@ says this
has been in snapshots for weeks now.


# 1.109 01-Jul-2010 matthew

Change scsibus(4)'s scsi_link array to an SLIST to save memory on
sparsely populated buses.

ok dlg@, krw@


# 1.108 30-Jun-2010 mk

Use SLIST for the ccb free list.

ok krw, discontent grunts from marco.


# 1.107 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.106 15-Jun-2010 dlg

dont pass the dev_t from the scsi device drivers into the midlayer for
ioctl requests, and dont pass the proc pointers around for any ioctl
requests in scsi land at all. neither were used, so trim the fat.

ok krw@ marco@


# 1.105 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.104 16-May-2010 nicm

Use a temporary variable for now to sidestep -Wbounded checking when
copying vendor[8]/product[16]/revision[4] out of struct scsi_inquiry_data
together with one memcopy.

ok krw


# 1.103 22-Apr-2010 oga

use BUS_DMA_ZERO on alloc instead of bzeroing after.

ok dlg@, marco@


# 1.102 10-Apr-2010 marco

grrr var names in protos


# 1.101 10-Apr-2010 marco

sprinkle some bus_dmamap_sync around frame access.
prompted by oga


# 1.100 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.99 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.98 04-Jan-2010 dlg

rename ccb_xs to ccb_cookie and change its type from a scsi_xfer * to a
void *. this lets us pass things other than scsi_xfers to ccb completion
handlers.


# 1.97 04-Jan-2010 dlg

protect the ccb free queue with a mutex rather than splbio


# 1.96 03-Jan-2010 chl

change M_WAITOK --> M_WAITOK|M_CANFAIL

with input from marco@

ok marco@ krw@

this was ok looooooooong time ago but lost in my mailbox


Revision tags: OPENBSD_4_6_BASE
# 1.95 30-Apr-2009 marco

Add READ(16) & WRITE(16) commands.
ok krw


# 1.94 29-Apr-2009 marco

MFI_D_IOCTL should be commented out. No binary change.


# 1.93 04-Apr-2009 dlg

scrub more fields in the ccb when returning them to the free list after
theyve been used, in particular the mfi header flags which has a bit
that specifies if a command should be completed via the interrupt path.

if we use a ccb during boot we set that bit, but it isnt necessarily
cleared by things that use it later on. this means a ccb we expected to
complete via an interrupt never actually generates an interrupt or appears
in the reply queue. this obviously stalls the io.


# 1.92 29-Mar-2009 marco

spello


# 1.91 29-Mar-2009 dlg

when we steal the SYNC CACHE command in mfi_scsi_cmd we still have to
mark the xs as done and call scsi_done for it rather than just returning
COMPLETE.


# 1.90 29-Mar-2009 dlg

fix a small race in mfi_mgmt between the checking of a ccbs completion and
the sleep waiting for the completion. it is possible to get the interrupt
completing the command just before the tsleep, which will never get a
wakeup because the interrupt with the wakeup has already happened.


Revision tags: OPENBSD_4_5_BASE
# 1.89 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.


# 1.88 28-Jan-2009 marco

Add support for next generation megaraid sas raid controllers.
From Jim Giannoules <gortag@gmail.com>


# 1.87 31-Oct-2008 marco

Generalize function to obtain all details to do bio stuff. This is in
preparation to start showing unsused disks which will require all this
information to do the math.

While at it fix a size of hotspare volume bug.


# 1.86 30-Oct-2008 marco

Fix bug that when there are no volumes but there are hot spares it would
no show the hotspares.


# 1.85 28-Oct-2008 marco

Fix output when reporting on multivolume disk groups.

Reported by mitja@muzenic.net


# 1.84 27-Oct-2008 marco

Move some include stuff around


# 1.83 26-Oct-2008 marco

Space


# 1.82 23-Oct-2008 marco

Fix PR5645
ok dlg
tested beck and others


# 1.81 25-Sep-2008 krw

Initialize 'ssc' to NULL since we test it later. Shouldn't ever be
NULL at the point of test unless the device list is confused, but
be consistantly paranoid if we're going to be paranoid.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.80 16-Feb-2008 krw

Return NO_CCB and not TRY_AGAIN_LATER when running out of ccb's.
Eliminates 'not queued' errors reported on the mailing lists.

Tested by Michael (belenus at bsdmail dot de).

ok marco@


# 1.79 11-Feb-2008 dlg

add support for the mfi controllers with the ppc iops, aka, LSI SAS1078 or
Dell PERC6.

committed off a machine booting and rooting off a perc6. tested on a perc5
by marco@
ok marco@


# 1.78 26-Jan-2008 brad

Set the return value instead of returning right away so that the DMA
memory is actually synched.

ok dlg@


# 1.77 26-Jan-2008 dlg

sync dma mem back to the cpu on poll failure.

from mickey via pr5714


# 1.76 26-Jan-2008 dlg

despatch -> dispatch

disparate spellink fix from mickey


# 1.75 05-Nov-2007 krw

More scsi_done() at SPLBIO.


# 1.74 27-Sep-2007 chl

M_ZERO changes

ok dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.73 24-Jun-2007 dlg

rework sensor tasks to use the kernels generic workq rather than a special
kernel thread of its own. the api has changed (which will be fixed in the
manpage shortly) so all the users of sensor tasks that i can find have
been fixed too.

noone tested, so its going in to force people to run with it.
"put it in" deraadt@


# 1.72 29-May-2007 todd

sprinkle some SMALL_KERNEL to permit bio/softraid to run on boot media
ok marco@ then suggested deraadt@


# 1.71 22-Mar-2007 deraadt

split userland & kernel struct sensor/sensordev so that the addition
of new fields in the future is less disruptive. This is done similar
to how struct proc is handled for ps(1). ok jmc (man page changes)
tested fkr simon, and more suggestions from millert


Revision tags: OPENBSD_4_1_BASE
# 1.70 14-Feb-2007 dlg

bus_space does byte swapping to cope with host endianness for us, so remove
an unnecessary htole32().


# 1.69 13-Feb-2007 marco

Fix subtle x ? y : z bug when calling mfi_create_sgl. This worked because
during runtime the bug condition does not happen.

ok krw joris


# 1.68 08-Feb-2007 ray

Remove double semicolons.

From Pierre Riteau <pierre dot riteau at free dot fr>.

OK marco@.


# 1.67 23-Dec-2006 deraadt

adapt to new two-level sensor api; Constantine A. Murenin


# 1.66 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.65 31-Aug-2006 marco

Add sensor thread for individual sd devices.

tested dlg
ok dlg deraadt


# 1.64 30-Aug-2006 dlg

when determining the size of the volumes and disks we want how many
bytes each of them has, not the number of kilobytes. this solves the
"why am i dividing by 2" question. the answer is "you dont, you multiply
by 512".


# 1.63 28-Jul-2006 brad

make dmesg printing look a little bit nicer.


# 1.62 19-Jun-2006 marco

Factor for disk size is /2. Odd but tested on all mfis I have.


# 1.61 19-Jun-2006 miod

Everytime one forgets an argument in a printf-like function call, God kills
a kitten. Commiters, please think of the kittens when working on code.


# 1.60 19-Jun-2006 marco

Make a BGI (Back Ground Init) a scrub instead of rebuild.


# 1.59 19-Jun-2006 marco

Add hot spare support.


# 1.58 26-May-2006 marco

Add blinking for disks.


# 1.57 25-May-2006 marco

Move a int i; to top of function so that it compiles on non c99 compilers.
Pointed out by miod@

The enclosure id modifier didn't reflect reality so move it back to whatever
the raid card uses.


# 1.56 25-May-2006 marco

And add time and percentage to builds and check consistencies.


# 1.55 25-May-2006 marco

Add last bit of physcal disk stuff.
Remove bogus memset.
Hotspares still don't work.


# 1.54 25-May-2006 marco

Add physical device and read config structures.
Add initial part of BIOCDISK


# 1.53 23-May-2006 deraadt

commited with unused variable


# 1.52 23-May-2006 marco

Remove some debug cruft.


# 1.51 23-May-2006 marco

Add first half of physical disk data for bio.


# 1.50 22-May-2006 marco

Add support for raid 50 and 10 in bio.


# 1.49 22-May-2006 marco

Add mail box to mfi_mgmt to handle sub commands more gracefully.
Remove some debug crud that snuck in the TEST_UNIT_READY case.
Finish other half of BIOCVOL primitive.
Add several structures to fill out the BIOCVOL primitive.


# 1.48 22-May-2006 marco

Add first half of BIOCVOL primitive.


# 1.47 21-May-2006 marco

Do a giant flush of disk and raid-card memory when SYNCHONIZE_CACHE is called.


# 1.46 21-May-2006 marco

pretty up some debug statements.


# 1.45 21-May-2006 marco

Add bio alarm function.
Redo mfi_mgmt to deal with zero data commands.


# 1.44 21-May-2006 marco

Add generic management function.
Redo ccb_state flags so that we can actually sleep on it.
Redo mfi_get_info to use new mgmt function.
Add rw_locks for mgmt interface.
Make BIOCINQ dynamic.


# 1.43 21-May-2006 marco

Oops, helps to use the right structure field.
Use actual nr of physical disks present.


# 1.42 21-May-2006 marco

Add first BIOCINQ primitive.


# 1.41 18-May-2006 marco

Remove some debug cruft and pretty up some debug messages.


# 1.40 18-May-2006 marco

Kill splbio/splx in the interrupt handler.


# 1.39 18-May-2006 marco

And we have lift off! Was able to create a filesystem and write to the
filesystem.

Collapse both completion routines into one.
Fixup scsi error reporting in the completion routine.


# 1.38 17-May-2006 marco

Add completion routines.
Fix some bugs inside the interrupt handler.


# 1.37 17-May-2006 marco

Add mfi_get_info to obtain all kinds of fun information from the fw.
Print out whole info structure when debug is enabled.
Add a nice print with useful info during attach.


# 1.36 17-May-2006 marco

Refactor scsi path so that we can have a single sgl function for io and non-io
traffic.
Redo parameters on functions that were passing too many parameters around.


# 1.35 16-May-2006 marco

Nuke some { }


# 1.34 16-May-2006 marco

Move !xs->data case into mfi_start_xs.
Return proper sense data when a polling command fails.


# 1.33 16-May-2006 marco

Fix some more htole32 screw-ups.
Colapse all little SCSI functions into a single generic one.
Fix a bug in the SGE calculation.

This brings the driver up to post:
mfi0 at pci12 dev 14 function 0 "Dell PERC SAS" rev 0x00: Dell PERC 5/e irq 5
scsibus3 at mfi0: 2 targets
sd1 at scsibus3 targ 0 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd1: 237824MB, 237824 cyl, 64 head, 32 sec, 512 bytes/sec, 487063552 sec total
sd2 at scsibus3 targ 1 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd2: 34176MB, 34176 cyl, 64 head, 32 sec, 512 bytes/sec, 69992448 sec total


# 1.32 16-May-2006 marco

Fix some htole32 I missed.
Sprinkle more debug.


# 1.31 16-May-2006 marco

Add READ CAPACITY.


# 1.30 16-May-2006 marco

Oops PREREAD not PREWRITE.


# 1.29 16-May-2006 marco

Add TUR and make it send it directly to firmware.
Sprinkle some extra debug.


# 1.28 15-May-2006 marco

Clear all relevant ccb fields when mfi_put_ccb frees a ccb.


# 1.27 15-May-2006 marco

Oops don't send command twice to firmware when polling.


# 1.26 15-May-2006 marco

Add INQUIRY command.
Add sgl magic.


# 1.25 10-May-2006 marco

Add some airplane code.

add bio hooks.
add scsi entry point for io.


# 1.24 26-Apr-2006 marco

Fix some debug prints.


# 1.23 21-Apr-2006 marco

typo


# 1.22 21-Apr-2006 marco

Add mfi_poll and use the new shiny function to setup all the hardware queues.
Lots of ideas from the FreeBSD driver.


# 1.21 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.20 20-Apr-2006 dlg

marco hates typedefs as much as i do, so he asked me to clean mfi like i
just did with ami. this gets rid of the typedef for the ccb lists.

also uses TAILQ_FIRST to get ccbs off the freelist. this is a proactive
fix for a lint teary.


# 1.19 18-Apr-2006 marco

It helps to initialize a queue before usage.


# 1.18 18-Apr-2006 marco

Actually add ccbs to the queue.
Fix the error path for mfi_init_ccb.
Alter dmamap for io.


# 1.17 17-Apr-2006 marco

Sprinkle more debug. Remove 64 byte boundary; it doesn't seem to like it.
Hack around 64 byte boundary for the frames for now.


# 1.16 17-Apr-2006 marco

Setup ccbs and clean up ccb structure.


# 1.15 16-Apr-2006 marco

Oops, make mfi_allocmem always use 64 byte boundaries since frames have to
have that alignment. It doesn't matter for the other consumers of the
function.


# 1.14 16-Apr-2006 marco

Add frame memory and sglist allocation.


# 1.13 16-Apr-2006 marco

Make memory access use macro.


# 1.12 16-Apr-2006 marco

typo


# 1.11 16-Apr-2006 marco

Add get and put ccb functions. Shuffle some more definitions.


# 1.10 16-Apr-2006 marco

Nicer print when context is invalid.


# 1.9 16-Apr-2006 marco

Shuffle some #defines.
Fix comments.
Add human readable enable intrrupt #define.


# 1.8 16-Apr-2006 marco

Add interrupt handler. Idea borrowed from FreeBSD since it is much nicer
than the Linux one.


# 1.7 07-Apr-2006 marco

Replace bus_space functions with generic ones that do barriers.


# 1.6 07-Apr-2006 marco

Add memory allocator functions.


# 1.5 07-Apr-2006 marco

Print state in debug. Change return vales to 1 instead of ENXIO.


# 1.4 07-Apr-2006 marco

Make a better debug mechanism.


# 1.3 07-Apr-2006 marco

Enable mfi_transition_fw() original code from FreeBSD.


# 1.2 06-Apr-2006 marco

Add fw transition logic.


# 1.1 06-Apr-2006 marco

Add skeleton driver for MegaRAID SAS.


# 1.179 27-Jun-2020 krw

Nuke trailing whitespace.


# 1.178 27-Jun-2020 krw

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


# 1.177 24-Jun-2020 krw

Use SDEV_NO_ADAPTER_TARGET instead of -1 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.176 21-Mar-2020 krw

Simplify some goto'ing that jumps a single line or
does nothing at all.

The first one spotted as CID 1452976.

Reads good to millert@

ok mpi@


# 1.175 13-Feb-2020 krw

Nuke *_minphys() functions that either simply apply MAXPHYS or do
nothing at all. MAXPHYS will be applied in minphys() and nothing at
all, well, doesn't do anything.

Also remove any '#define <blah> MAXPHYS' statements used solely to
disguise MAXPHYS in said functions.


# 1.174 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.173 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.172 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.171 31-Dec-2019 mpi

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

ok kn@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.170 05-Mar-2019 jmatthew

apply background init progress fix from r1.59 of mfii.c
(reverting most of r1.60 of mfi.c, oddly enough)

ok dlg@
tested on a SAS2008 (perc h310)


Revision tags: OPENBSD_6_4_BASE
# 1.169 14-Aug-2018 jmatthew

return ENOTTY rather than EINVAL to indicate an ioctl hasn't been handled

ok dlg@ deraadt@ kettenis@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.168 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.167 02-Feb-2017 dlg

copy the mbox into the dcmd struct, not the pointer to the mbox.

makes bioctl work on mfi(4) again.

while here memset a few mboxes before using them.

bioctl breakage reported by jason george


# 1.166 23-Jan-2017 dlg

represent the mbox layout with union instead of an array of bytes.

memcpying uint16_ts into inconsistently addressed offsets is hard
to read, and this makes future work easier to implement.

tested on mfi(4) and mfii(4)


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.165 09-Sep-2015 deraadt

sizes for free(); ok sthen


Revision tags: OPENBSD_5_8_BASE
# 1.164 29-May-2015 uebayasi

Initial addition of ``Patrol Read'' support in bio(4), biocto(8), and
mfi(4). Based on FreeBSD, but done without mfiutil(8).

OK deraadt@


# 1.163 18-May-2015 mikeb

Prevent splassert from firing during sd_flush which runs "cold"

While mfi(4) should pass SCSI transfer flags (e.g. SCSI_POLL and
SCSI_NOSLEEP) down to the management function, make it at least
use "cold" consistently for now.

ok dlg


# 1.162 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.161 08-Mar-2015 dlg

properly set sgl related flags on skinny controllers. this fixes
io against physical disks on my dell perc h310s. logical disks still
work fine.

ok deraadt@ yasuoka@


# 1.160 08-Feb-2015 yasuoka

Fix mfi ioctl to set drive state properly.
diff from Tsubai Masanari

test dlg jmatthew
ok dlg


# 1.159 09-Jan-2015 yasuoka

Add support DIOC{G,S}CACHE to mfi(4). Cache of disk on mfi(4) will
be enabled by default. Also if the controller doesn't have any RAM,
the cache on the physical disk will be enabled.

discuss with jsg tsubai
ok dlg


# 1.158 19-Dec-2014 deraadt

another handful of bcopy -> memcpy because there is no overlap


# 1.157 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.156 09-Sep-2014 dlg

mark the interrupt handler mpsafe, and give up biglock in the scsi cmd
submission paths. take biglock again when calling back into the scsi
stack.

tested on a variety of cards here, including the skinny mfis on the
firewall next to mpsafe myx.


# 1.155 15-Aug-2014 yasuoka

Create a function which loads sgd in the mfi_iop_ops struct so that skinny
adapters can use "IEEE sgl".

tested dlg yasuoka
ok dlg jsg


Revision tags: OPENBSD_5_6_BASE
# 1.154 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.153 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.152 04-May-2014 sf

format string fixes for bus_addr_t and bus_size_t

bus_addr_t and bus_size_t are u_long everywhere

ok kettenis@


Revision tags: OPENBSD_5_5_BASE
# 1.151 20-Feb-2014 kettenis

revert previous commit; didn't intend to commit those bits


# 1.150 20-Feb-2014 kettenis

Avoid printing the "nvram corrupt" message for onboard 2200s found on Sun
hardware.

ok dlg@, jmatthew@


# 1.149 04-Dec-2013 dlg

mfi_refresh_sensors calls mfi_ioctl_vol which calls mfi_bio_getitall, which
replaces pointers in the softc and all sorts of fun stuff. this protects
the call to bio_getitall with the sc_lock the ioctl path uses, so we dont
get panics like those reported on bugs@ recently.

ok deraadt@


# 1.148 23-Oct-2013 kettenis

Add support for displaying the cache write policy of RAID volumes to bioctl(8)
and make mfi(4) pass up the necessary information. Adding support for other
RAID controllers is left as an excercise to the reader.

ok deraadt@


# 1.147 09-Oct-2013 jmatthew

Include the 'state of health' field in the bbu ok sensor value.
The dell perc 6/i sets this to zero (meaning bad) when it
decides the battery doesn't have enough capacity for it to
allow write back mode, but doesn't set any of the other flags
to tell us why.

ok dlg@, tested by sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.146 18-May-2013 jmc

enw->new in comment;
spotted by krw, missed by jsg, and forwarded From: Alexey Suslikov


# 1.145 08-May-2013 jsg

fix some leaks in error paths
ok fgsch@ krw@ kettenis@


# 1.144 03-May-2013 dlg

break out the battery status into excruciating detail. makes it harder for
$VENDOR to complain about a lack of diagnostic material from their crappy
mgmt tools if you're not running an operating system they support.


# 1.143 02-May-2013 dlg

always attach the battery sensor if the adapter lets us query it.
newly replaced batteries dont show up immediately.


# 1.142 01-May-2013 dlg

provide a sensor for the battery backup unit (bbu) on mfi boards that
support it.

now i can tell (a bit better) why io might be slow on some of my boxes.


# 1.141 01-May-2013 dlg

dont need to walk alldevs during sensor creation looking for the logical
disk scsibus when we record that in mfi_attach.

also happens to get rid of a logic error that let it come out of the loop
on alldevs with a reference to something that wasnt the logical disk
scsibus and use that.


# 1.140 30-Apr-2013 dlg

use MR_DCMD consistently. some MD_DCMD was in there somehow.


# 1.139 07-Apr-2013 dlg

david imhoff points out that the error handling in mfi_init_ccb gets the
index to which ccb to free wrong.

this takes the logic from mpi/mpii/mfii which pulls the ready ccbs off
the free list rather than rely on the current index from the for loop
that we failed inside of.

thanks to david for finding this out.


Revision tags: OPENBSD_5_3_BASE
# 1.138 12-Sep-2012 haesbaert

Make sure we don't sleep on autoconf.

ok mikeb


# 1.137 17-Aug-2012 dlg

add support for "physical devices" on skinny controllers.

these controllers let you specify disks that should be accessed directly
rather than be part of logical volumes. apparently you can plug in things
like tape drives too.

anyway, physical devices are exposed via a separate scsibus attached to
mfi.

ok mikeb@


# 1.136 16-Aug-2012 dlg

fix mfi_poll by having it do delays between loops, and breaking on
timeouts. how embarrassment.

implement mfi_exec for doing sync executions of commands in process
contexts and cut mfi_mgmt over to it.


# 1.135 16-Aug-2012 dlg

rework mfi_poll so it will do all the completions on a ccb including
calling the done handler.

this makes it consistently complete scsi io with all the proper error
checking.


# 1.134 16-Aug-2012 dlg

stop passing mfi_softc around as a member of the ccb, consistently give it
as the first argument to functions. like mfii.


# 1.133 16-Aug-2012 dlg

scrub ccbs when we're about to use them, not when we put them back
on the free list. ccbs can be reused, so we dont want old state screwing up
new commands.


# 1.132 16-Aug-2012 dlg

move the dma syncs for the ccb data into ccb_done, so we can do it once
rather than put the code everywhere.


# 1.131 16-Aug-2012 dlg

fix up the dma sync for the command frame in mfi_done.


# 1.130 14-Aug-2012 dlg

use scsi_get_link to find out the name of a child device for bioctl rather
than snoop scsi commands and copy it in an io path.

no functional change, but the code has one less XXX now.


# 1.129 14-Aug-2012 dlg

expose the max number of logical volumes the hardware supports as the width
of its scsibus. only advertise 1 lun on logical volumes instead of letting
the midlayer fix it up to 8.

give every target on the bus max_cmds openings. iopools means they will
properly share access to them.

this in particular is useful on skinny controllers which only advertise 31
command slots. if you have 16 volumes, theyll only get 1 opening each with
the old maths. this way round the ones that are busy will share the slots.

tested on a perc5 with two volumes and hard workloads.


# 1.128 14-Aug-2012 dlg

print the boards name (eg, perc 5/i) according to the firmware like mfii.

ok deraadt@


# 1.127 14-Aug-2012 dlg

move knowledge of the location of the inbound doorbell out of code in
transition_firmware into a member of the iop structures.

ok mikeb@ haesbaert@


# 1.126 13-Aug-2012 dlg

get rid of the last foo_lo and foo_hi bits i could find in the hardware
structures and use htole64 instead of htole32(addr >> 32); htole32(addr);

gets rid of "handy" stack variables to get the dva to 64bits.

sprinkle some more byte swaps for things that should have it.

tested on a perc5 (xscale)


# 1.125 13-Aug-2012 dlg

do appropriate bus_dmamapy_syncs around the pcq/completion ring.

tested on a perc5 (xscale)


# 1.124 13-Aug-2012 dlg

replace uint32_ts for hi and lo addresses in the mfi_init_ hardware
descriptors with single uint64_ts. theyre not some weird middle
endian thing. this makes the code more readable.

add some missing htole32s to the code while here.

tested on a perc5 (xscale).


# 1.123 11-Aug-2012 dlg

the producer/consumer values are used by the device, which is little
endian. do appropriate byteswapping for when the host cpu uses them.

tested on a perc5 (xscale) in an amd64.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.122 12-Jan-2012 dlg

add support for skinny variants.

from Alexey Suslikov
reviewed by marco


Revision tags: OPENBSD_5_0_BASE
# 1.121 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.120 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.119 09-Apr-2011 marco

add all 64 bit dma plumbing but stick with 32 for now by default.

ok deraadt


# 1.118 09-Apr-2011 marco

make sure the upper 32 bits are always written to instead of assuming it
is 0.

ok deraadt.


# 1.117 08-Apr-2011 marco

kill some stray spaces


# 1.116 08-Apr-2011 marco

rename wiat channel to something less than 8 chars.

prompted by deraadt


# 1.115 08-Apr-2011 marco

use dma_alloc for transient management commands.

prodded and ok deraadt


Revision tags: OPENBSD_4_9_BASE
# 1.114 30-Dec-2010 dlg

cut mfi over to using iopools.

this gets rid of NO_CCB, provides better scheduling of io between busy
logical volumes on the same controller, and makes the ioctl and sensor
paths more reliable.

this is the least intrusive version of this change i could come up with. it
only took 4 or 5 goes...

ok marco@
deraadt@ says this is a good time for this change.


# 1.113 24-Sep-2010 dlg

no use setting cmd in mfi_ioctl_setstate if you never use it.


# 1.112 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


# 1.111 29-Aug-2010 dlg

the scsi completion code thinks that if you dont get MFI_STAT_OK
back from the chip on a command then the command completely failed.
MFI_STAT_SCSI_DONE_WITH_ERROR really means the command completed
fine, but there's some sense data too. this tweaks the handling to
be more appropriate, as per the linux and solaris drivers.

timed out waiting for beck@
putting this in cos its obviously more correct than the current code.


Revision tags: OPENBSD_4_8_BASE
# 1.110 22-Jul-2010 matthew

SCSI HBA drivers are supposed to get their SCSI CDBs from xs->cmd, not
xs->cmdstore.

ok krw@ a while back (contingent upon testing), and deraadt@ says this
has been in snapshots for weeks now.


# 1.109 01-Jul-2010 matthew

Change scsibus(4)'s scsi_link array to an SLIST to save memory on
sparsely populated buses.

ok dlg@, krw@


# 1.108 30-Jun-2010 mk

Use SLIST for the ccb free list.

ok krw, discontent grunts from marco.


# 1.107 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.106 15-Jun-2010 dlg

dont pass the dev_t from the scsi device drivers into the midlayer for
ioctl requests, and dont pass the proc pointers around for any ioctl
requests in scsi land at all. neither were used, so trim the fat.

ok krw@ marco@


# 1.105 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.104 16-May-2010 nicm

Use a temporary variable for now to sidestep -Wbounded checking when
copying vendor[8]/product[16]/revision[4] out of struct scsi_inquiry_data
together with one memcopy.

ok krw


# 1.103 22-Apr-2010 oga

use BUS_DMA_ZERO on alloc instead of bzeroing after.

ok dlg@, marco@


# 1.102 10-Apr-2010 marco

grrr var names in protos


# 1.101 10-Apr-2010 marco

sprinkle some bus_dmamap_sync around frame access.
prompted by oga


# 1.100 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.99 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.98 04-Jan-2010 dlg

rename ccb_xs to ccb_cookie and change its type from a scsi_xfer * to a
void *. this lets us pass things other than scsi_xfers to ccb completion
handlers.


# 1.97 04-Jan-2010 dlg

protect the ccb free queue with a mutex rather than splbio


# 1.96 03-Jan-2010 chl

change M_WAITOK --> M_WAITOK|M_CANFAIL

with input from marco@

ok marco@ krw@

this was ok looooooooong time ago but lost in my mailbox


Revision tags: OPENBSD_4_6_BASE
# 1.95 30-Apr-2009 marco

Add READ(16) & WRITE(16) commands.
ok krw


# 1.94 29-Apr-2009 marco

MFI_D_IOCTL should be commented out. No binary change.


# 1.93 04-Apr-2009 dlg

scrub more fields in the ccb when returning them to the free list after
theyve been used, in particular the mfi header flags which has a bit
that specifies if a command should be completed via the interrupt path.

if we use a ccb during boot we set that bit, but it isnt necessarily
cleared by things that use it later on. this means a ccb we expected to
complete via an interrupt never actually generates an interrupt or appears
in the reply queue. this obviously stalls the io.


# 1.92 29-Mar-2009 marco

spello


# 1.91 29-Mar-2009 dlg

when we steal the SYNC CACHE command in mfi_scsi_cmd we still have to
mark the xs as done and call scsi_done for it rather than just returning
COMPLETE.


# 1.90 29-Mar-2009 dlg

fix a small race in mfi_mgmt between the checking of a ccbs completion and
the sleep waiting for the completion. it is possible to get the interrupt
completing the command just before the tsleep, which will never get a
wakeup because the interrupt with the wakeup has already happened.


Revision tags: OPENBSD_4_5_BASE
# 1.89 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.


# 1.88 28-Jan-2009 marco

Add support for next generation megaraid sas raid controllers.
From Jim Giannoules <gortag@gmail.com>


# 1.87 31-Oct-2008 marco

Generalize function to obtain all details to do bio stuff. This is in
preparation to start showing unsused disks which will require all this
information to do the math.

While at it fix a size of hotspare volume bug.


# 1.86 30-Oct-2008 marco

Fix bug that when there are no volumes but there are hot spares it would
no show the hotspares.


# 1.85 28-Oct-2008 marco

Fix output when reporting on multivolume disk groups.

Reported by mitja@muzenic.net


# 1.84 27-Oct-2008 marco

Move some include stuff around


# 1.83 26-Oct-2008 marco

Space


# 1.82 23-Oct-2008 marco

Fix PR5645
ok dlg
tested beck and others


# 1.81 25-Sep-2008 krw

Initialize 'ssc' to NULL since we test it later. Shouldn't ever be
NULL at the point of test unless the device list is confused, but
be consistantly paranoid if we're going to be paranoid.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.80 16-Feb-2008 krw

Return NO_CCB and not TRY_AGAIN_LATER when running out of ccb's.
Eliminates 'not queued' errors reported on the mailing lists.

Tested by Michael (belenus at bsdmail dot de).

ok marco@


# 1.79 11-Feb-2008 dlg

add support for the mfi controllers with the ppc iops, aka, LSI SAS1078 or
Dell PERC6.

committed off a machine booting and rooting off a perc6. tested on a perc5
by marco@
ok marco@


# 1.78 26-Jan-2008 brad

Set the return value instead of returning right away so that the DMA
memory is actually synched.

ok dlg@


# 1.77 26-Jan-2008 dlg

sync dma mem back to the cpu on poll failure.

from mickey via pr5714


# 1.76 26-Jan-2008 dlg

despatch -> dispatch

disparate spellink fix from mickey


# 1.75 05-Nov-2007 krw

More scsi_done() at SPLBIO.


# 1.74 27-Sep-2007 chl

M_ZERO changes

ok dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.73 24-Jun-2007 dlg

rework sensor tasks to use the kernels generic workq rather than a special
kernel thread of its own. the api has changed (which will be fixed in the
manpage shortly) so all the users of sensor tasks that i can find have
been fixed too.

noone tested, so its going in to force people to run with it.
"put it in" deraadt@


# 1.72 29-May-2007 todd

sprinkle some SMALL_KERNEL to permit bio/softraid to run on boot media
ok marco@ then suggested deraadt@


# 1.71 22-Mar-2007 deraadt

split userland & kernel struct sensor/sensordev so that the addition
of new fields in the future is less disruptive. This is done similar
to how struct proc is handled for ps(1). ok jmc (man page changes)
tested fkr simon, and more suggestions from millert


Revision tags: OPENBSD_4_1_BASE
# 1.70 14-Feb-2007 dlg

bus_space does byte swapping to cope with host endianness for us, so remove
an unnecessary htole32().


# 1.69 13-Feb-2007 marco

Fix subtle x ? y : z bug when calling mfi_create_sgl. This worked because
during runtime the bug condition does not happen.

ok krw joris


# 1.68 08-Feb-2007 ray

Remove double semicolons.

From Pierre Riteau <pierre dot riteau at free dot fr>.

OK marco@.


# 1.67 23-Dec-2006 deraadt

adapt to new two-level sensor api; Constantine A. Murenin


# 1.66 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.65 31-Aug-2006 marco

Add sensor thread for individual sd devices.

tested dlg
ok dlg deraadt


# 1.64 30-Aug-2006 dlg

when determining the size of the volumes and disks we want how many
bytes each of them has, not the number of kilobytes. this solves the
"why am i dividing by 2" question. the answer is "you dont, you multiply
by 512".


# 1.63 28-Jul-2006 brad

make dmesg printing look a little bit nicer.


# 1.62 19-Jun-2006 marco

Factor for disk size is /2. Odd but tested on all mfis I have.


# 1.61 19-Jun-2006 miod

Everytime one forgets an argument in a printf-like function call, God kills
a kitten. Commiters, please think of the kittens when working on code.


# 1.60 19-Jun-2006 marco

Make a BGI (Back Ground Init) a scrub instead of rebuild.


# 1.59 19-Jun-2006 marco

Add hot spare support.


# 1.58 26-May-2006 marco

Add blinking for disks.


# 1.57 25-May-2006 marco

Move a int i; to top of function so that it compiles on non c99 compilers.
Pointed out by miod@

The enclosure id modifier didn't reflect reality so move it back to whatever
the raid card uses.


# 1.56 25-May-2006 marco

And add time and percentage to builds and check consistencies.


# 1.55 25-May-2006 marco

Add last bit of physcal disk stuff.
Remove bogus memset.
Hotspares still don't work.


# 1.54 25-May-2006 marco

Add physical device and read config structures.
Add initial part of BIOCDISK


# 1.53 23-May-2006 deraadt

commited with unused variable


# 1.52 23-May-2006 marco

Remove some debug cruft.


# 1.51 23-May-2006 marco

Add first half of physical disk data for bio.


# 1.50 22-May-2006 marco

Add support for raid 50 and 10 in bio.


# 1.49 22-May-2006 marco

Add mail box to mfi_mgmt to handle sub commands more gracefully.
Remove some debug crud that snuck in the TEST_UNIT_READY case.
Finish other half of BIOCVOL primitive.
Add several structures to fill out the BIOCVOL primitive.


# 1.48 22-May-2006 marco

Add first half of BIOCVOL primitive.


# 1.47 21-May-2006 marco

Do a giant flush of disk and raid-card memory when SYNCHONIZE_CACHE is called.


# 1.46 21-May-2006 marco

pretty up some debug statements.


# 1.45 21-May-2006 marco

Add bio alarm function.
Redo mfi_mgmt to deal with zero data commands.


# 1.44 21-May-2006 marco

Add generic management function.
Redo ccb_state flags so that we can actually sleep on it.
Redo mfi_get_info to use new mgmt function.
Add rw_locks for mgmt interface.
Make BIOCINQ dynamic.


# 1.43 21-May-2006 marco

Oops, helps to use the right structure field.
Use actual nr of physical disks present.


# 1.42 21-May-2006 marco

Add first BIOCINQ primitive.


# 1.41 18-May-2006 marco

Remove some debug cruft and pretty up some debug messages.


# 1.40 18-May-2006 marco

Kill splbio/splx in the interrupt handler.


# 1.39 18-May-2006 marco

And we have lift off! Was able to create a filesystem and write to the
filesystem.

Collapse both completion routines into one.
Fixup scsi error reporting in the completion routine.


# 1.38 17-May-2006 marco

Add completion routines.
Fix some bugs inside the interrupt handler.


# 1.37 17-May-2006 marco

Add mfi_get_info to obtain all kinds of fun information from the fw.
Print out whole info structure when debug is enabled.
Add a nice print with useful info during attach.


# 1.36 17-May-2006 marco

Refactor scsi path so that we can have a single sgl function for io and non-io
traffic.
Redo parameters on functions that were passing too many parameters around.


# 1.35 16-May-2006 marco

Nuke some { }


# 1.34 16-May-2006 marco

Move !xs->data case into mfi_start_xs.
Return proper sense data when a polling command fails.


# 1.33 16-May-2006 marco

Fix some more htole32 screw-ups.
Colapse all little SCSI functions into a single generic one.
Fix a bug in the SGE calculation.

This brings the driver up to post:
mfi0 at pci12 dev 14 function 0 "Dell PERC SAS" rev 0x00: Dell PERC 5/e irq 5
scsibus3 at mfi0: 2 targets
sd1 at scsibus3 targ 0 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd1: 237824MB, 237824 cyl, 64 head, 32 sec, 512 bytes/sec, 487063552 sec total
sd2 at scsibus3 targ 1 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd2: 34176MB, 34176 cyl, 64 head, 32 sec, 512 bytes/sec, 69992448 sec total


# 1.32 16-May-2006 marco

Fix some htole32 I missed.
Sprinkle more debug.


# 1.31 16-May-2006 marco

Add READ CAPACITY.


# 1.30 16-May-2006 marco

Oops PREREAD not PREWRITE.


# 1.29 16-May-2006 marco

Add TUR and make it send it directly to firmware.
Sprinkle some extra debug.


# 1.28 15-May-2006 marco

Clear all relevant ccb fields when mfi_put_ccb frees a ccb.


# 1.27 15-May-2006 marco

Oops don't send command twice to firmware when polling.


# 1.26 15-May-2006 marco

Add INQUIRY command.
Add sgl magic.


# 1.25 10-May-2006 marco

Add some airplane code.

add bio hooks.
add scsi entry point for io.


# 1.24 26-Apr-2006 marco

Fix some debug prints.


# 1.23 21-Apr-2006 marco

typo


# 1.22 21-Apr-2006 marco

Add mfi_poll and use the new shiny function to setup all the hardware queues.
Lots of ideas from the FreeBSD driver.


# 1.21 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.20 20-Apr-2006 dlg

marco hates typedefs as much as i do, so he asked me to clean mfi like i
just did with ami. this gets rid of the typedef for the ccb lists.

also uses TAILQ_FIRST to get ccbs off the freelist. this is a proactive
fix for a lint teary.


# 1.19 18-Apr-2006 marco

It helps to initialize a queue before usage.


# 1.18 18-Apr-2006 marco

Actually add ccbs to the queue.
Fix the error path for mfi_init_ccb.
Alter dmamap for io.


# 1.17 17-Apr-2006 marco

Sprinkle more debug. Remove 64 byte boundary; it doesn't seem to like it.
Hack around 64 byte boundary for the frames for now.


# 1.16 17-Apr-2006 marco

Setup ccbs and clean up ccb structure.


# 1.15 16-Apr-2006 marco

Oops, make mfi_allocmem always use 64 byte boundaries since frames have to
have that alignment. It doesn't matter for the other consumers of the
function.


# 1.14 16-Apr-2006 marco

Add frame memory and sglist allocation.


# 1.13 16-Apr-2006 marco

Make memory access use macro.


# 1.12 16-Apr-2006 marco

typo


# 1.11 16-Apr-2006 marco

Add get and put ccb functions. Shuffle some more definitions.


# 1.10 16-Apr-2006 marco

Nicer print when context is invalid.


# 1.9 16-Apr-2006 marco

Shuffle some #defines.
Fix comments.
Add human readable enable intrrupt #define.


# 1.8 16-Apr-2006 marco

Add interrupt handler. Idea borrowed from FreeBSD since it is much nicer
than the Linux one.


# 1.7 07-Apr-2006 marco

Replace bus_space functions with generic ones that do barriers.


# 1.6 07-Apr-2006 marco

Add memory allocator functions.


# 1.5 07-Apr-2006 marco

Print state in debug. Change return vales to 1 instead of ENXIO.


# 1.4 07-Apr-2006 marco

Make a better debug mechanism.


# 1.3 07-Apr-2006 marco

Enable mfi_transition_fw() original code from FreeBSD.


# 1.2 06-Apr-2006 marco

Add fw transition logic.


# 1.1 06-Apr-2006 marco

Add skeleton driver for MegaRAID SAS.


# 1.177 24-Jun-2020 krw

Use SDEV_NO_ADAPTER_TARGET instead of -1 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.176 21-Mar-2020 krw

Simplify some goto'ing that jumps a single line or
does nothing at all.

The first one spotted as CID 1452976.

Reads good to millert@

ok mpi@


# 1.175 13-Feb-2020 krw

Nuke *_minphys() functions that either simply apply MAXPHYS or do
nothing at all. MAXPHYS will be applied in minphys() and nothing at
all, well, doesn't do anything.

Also remove any '#define <blah> MAXPHYS' statements used solely to
disguise MAXPHYS in said functions.


# 1.174 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.173 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.172 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.171 31-Dec-2019 mpi

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

ok kn@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.170 05-Mar-2019 jmatthew

apply background init progress fix from r1.59 of mfii.c
(reverting most of r1.60 of mfi.c, oddly enough)

ok dlg@
tested on a SAS2008 (perc h310)


Revision tags: OPENBSD_6_4_BASE
# 1.169 14-Aug-2018 jmatthew

return ENOTTY rather than EINVAL to indicate an ioctl hasn't been handled

ok dlg@ deraadt@ kettenis@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.168 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.167 02-Feb-2017 dlg

copy the mbox into the dcmd struct, not the pointer to the mbox.

makes bioctl work on mfi(4) again.

while here memset a few mboxes before using them.

bioctl breakage reported by jason george


# 1.166 23-Jan-2017 dlg

represent the mbox layout with union instead of an array of bytes.

memcpying uint16_ts into inconsistently addressed offsets is hard
to read, and this makes future work easier to implement.

tested on mfi(4) and mfii(4)


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.165 09-Sep-2015 deraadt

sizes for free(); ok sthen


Revision tags: OPENBSD_5_8_BASE
# 1.164 29-May-2015 uebayasi

Initial addition of ``Patrol Read'' support in bio(4), biocto(8), and
mfi(4). Based on FreeBSD, but done without mfiutil(8).

OK deraadt@


# 1.163 18-May-2015 mikeb

Prevent splassert from firing during sd_flush which runs "cold"

While mfi(4) should pass SCSI transfer flags (e.g. SCSI_POLL and
SCSI_NOSLEEP) down to the management function, make it at least
use "cold" consistently for now.

ok dlg


# 1.162 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.161 08-Mar-2015 dlg

properly set sgl related flags on skinny controllers. this fixes
io against physical disks on my dell perc h310s. logical disks still
work fine.

ok deraadt@ yasuoka@


# 1.160 08-Feb-2015 yasuoka

Fix mfi ioctl to set drive state properly.
diff from Tsubai Masanari

test dlg jmatthew
ok dlg


# 1.159 09-Jan-2015 yasuoka

Add support DIOC{G,S}CACHE to mfi(4). Cache of disk on mfi(4) will
be enabled by default. Also if the controller doesn't have any RAM,
the cache on the physical disk will be enabled.

discuss with jsg tsubai
ok dlg


# 1.158 19-Dec-2014 deraadt

another handful of bcopy -> memcpy because there is no overlap


# 1.157 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.156 09-Sep-2014 dlg

mark the interrupt handler mpsafe, and give up biglock in the scsi cmd
submission paths. take biglock again when calling back into the scsi
stack.

tested on a variety of cards here, including the skinny mfis on the
firewall next to mpsafe myx.


# 1.155 15-Aug-2014 yasuoka

Create a function which loads sgd in the mfi_iop_ops struct so that skinny
adapters can use "IEEE sgl".

tested dlg yasuoka
ok dlg jsg


Revision tags: OPENBSD_5_6_BASE
# 1.154 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.153 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.152 04-May-2014 sf

format string fixes for bus_addr_t and bus_size_t

bus_addr_t and bus_size_t are u_long everywhere

ok kettenis@


Revision tags: OPENBSD_5_5_BASE
# 1.151 20-Feb-2014 kettenis

revert previous commit; didn't intend to commit those bits


# 1.150 20-Feb-2014 kettenis

Avoid printing the "nvram corrupt" message for onboard 2200s found on Sun
hardware.

ok dlg@, jmatthew@


# 1.149 04-Dec-2013 dlg

mfi_refresh_sensors calls mfi_ioctl_vol which calls mfi_bio_getitall, which
replaces pointers in the softc and all sorts of fun stuff. this protects
the call to bio_getitall with the sc_lock the ioctl path uses, so we dont
get panics like those reported on bugs@ recently.

ok deraadt@


# 1.148 23-Oct-2013 kettenis

Add support for displaying the cache write policy of RAID volumes to bioctl(8)
and make mfi(4) pass up the necessary information. Adding support for other
RAID controllers is left as an excercise to the reader.

ok deraadt@


# 1.147 09-Oct-2013 jmatthew

Include the 'state of health' field in the bbu ok sensor value.
The dell perc 6/i sets this to zero (meaning bad) when it
decides the battery doesn't have enough capacity for it to
allow write back mode, but doesn't set any of the other flags
to tell us why.

ok dlg@, tested by sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.146 18-May-2013 jmc

enw->new in comment;
spotted by krw, missed by jsg, and forwarded From: Alexey Suslikov


# 1.145 08-May-2013 jsg

fix some leaks in error paths
ok fgsch@ krw@ kettenis@


# 1.144 03-May-2013 dlg

break out the battery status into excruciating detail. makes it harder for
$VENDOR to complain about a lack of diagnostic material from their crappy
mgmt tools if you're not running an operating system they support.


# 1.143 02-May-2013 dlg

always attach the battery sensor if the adapter lets us query it.
newly replaced batteries dont show up immediately.


# 1.142 01-May-2013 dlg

provide a sensor for the battery backup unit (bbu) on mfi boards that
support it.

now i can tell (a bit better) why io might be slow on some of my boxes.


# 1.141 01-May-2013 dlg

dont need to walk alldevs during sensor creation looking for the logical
disk scsibus when we record that in mfi_attach.

also happens to get rid of a logic error that let it come out of the loop
on alldevs with a reference to something that wasnt the logical disk
scsibus and use that.


# 1.140 30-Apr-2013 dlg

use MR_DCMD consistently. some MD_DCMD was in there somehow.


# 1.139 07-Apr-2013 dlg

david imhoff points out that the error handling in mfi_init_ccb gets the
index to which ccb to free wrong.

this takes the logic from mpi/mpii/mfii which pulls the ready ccbs off
the free list rather than rely on the current index from the for loop
that we failed inside of.

thanks to david for finding this out.


Revision tags: OPENBSD_5_3_BASE
# 1.138 12-Sep-2012 haesbaert

Make sure we don't sleep on autoconf.

ok mikeb


# 1.137 17-Aug-2012 dlg

add support for "physical devices" on skinny controllers.

these controllers let you specify disks that should be accessed directly
rather than be part of logical volumes. apparently you can plug in things
like tape drives too.

anyway, physical devices are exposed via a separate scsibus attached to
mfi.

ok mikeb@


# 1.136 16-Aug-2012 dlg

fix mfi_poll by having it do delays between loops, and breaking on
timeouts. how embarrassment.

implement mfi_exec for doing sync executions of commands in process
contexts and cut mfi_mgmt over to it.


# 1.135 16-Aug-2012 dlg

rework mfi_poll so it will do all the completions on a ccb including
calling the done handler.

this makes it consistently complete scsi io with all the proper error
checking.


# 1.134 16-Aug-2012 dlg

stop passing mfi_softc around as a member of the ccb, consistently give it
as the first argument to functions. like mfii.


# 1.133 16-Aug-2012 dlg

scrub ccbs when we're about to use them, not when we put them back
on the free list. ccbs can be reused, so we dont want old state screwing up
new commands.


# 1.132 16-Aug-2012 dlg

move the dma syncs for the ccb data into ccb_done, so we can do it once
rather than put the code everywhere.


# 1.131 16-Aug-2012 dlg

fix up the dma sync for the command frame in mfi_done.


# 1.130 14-Aug-2012 dlg

use scsi_get_link to find out the name of a child device for bioctl rather
than snoop scsi commands and copy it in an io path.

no functional change, but the code has one less XXX now.


# 1.129 14-Aug-2012 dlg

expose the max number of logical volumes the hardware supports as the width
of its scsibus. only advertise 1 lun on logical volumes instead of letting
the midlayer fix it up to 8.

give every target on the bus max_cmds openings. iopools means they will
properly share access to them.

this in particular is useful on skinny controllers which only advertise 31
command slots. if you have 16 volumes, theyll only get 1 opening each with
the old maths. this way round the ones that are busy will share the slots.

tested on a perc5 with two volumes and hard workloads.


# 1.128 14-Aug-2012 dlg

print the boards name (eg, perc 5/i) according to the firmware like mfii.

ok deraadt@


# 1.127 14-Aug-2012 dlg

move knowledge of the location of the inbound doorbell out of code in
transition_firmware into a member of the iop structures.

ok mikeb@ haesbaert@


# 1.126 13-Aug-2012 dlg

get rid of the last foo_lo and foo_hi bits i could find in the hardware
structures and use htole64 instead of htole32(addr >> 32); htole32(addr);

gets rid of "handy" stack variables to get the dva to 64bits.

sprinkle some more byte swaps for things that should have it.

tested on a perc5 (xscale)


# 1.125 13-Aug-2012 dlg

do appropriate bus_dmamapy_syncs around the pcq/completion ring.

tested on a perc5 (xscale)


# 1.124 13-Aug-2012 dlg

replace uint32_ts for hi and lo addresses in the mfi_init_ hardware
descriptors with single uint64_ts. theyre not some weird middle
endian thing. this makes the code more readable.

add some missing htole32s to the code while here.

tested on a perc5 (xscale).


# 1.123 11-Aug-2012 dlg

the producer/consumer values are used by the device, which is little
endian. do appropriate byteswapping for when the host cpu uses them.

tested on a perc5 (xscale) in an amd64.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.122 12-Jan-2012 dlg

add support for skinny variants.

from Alexey Suslikov
reviewed by marco


Revision tags: OPENBSD_5_0_BASE
# 1.121 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.120 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.119 09-Apr-2011 marco

add all 64 bit dma plumbing but stick with 32 for now by default.

ok deraadt


# 1.118 09-Apr-2011 marco

make sure the upper 32 bits are always written to instead of assuming it
is 0.

ok deraadt.


# 1.117 08-Apr-2011 marco

kill some stray spaces


# 1.116 08-Apr-2011 marco

rename wiat channel to something less than 8 chars.

prompted by deraadt


# 1.115 08-Apr-2011 marco

use dma_alloc for transient management commands.

prodded and ok deraadt


Revision tags: OPENBSD_4_9_BASE
# 1.114 30-Dec-2010 dlg

cut mfi over to using iopools.

this gets rid of NO_CCB, provides better scheduling of io between busy
logical volumes on the same controller, and makes the ioctl and sensor
paths more reliable.

this is the least intrusive version of this change i could come up with. it
only took 4 or 5 goes...

ok marco@
deraadt@ says this is a good time for this change.


# 1.113 24-Sep-2010 dlg

no use setting cmd in mfi_ioctl_setstate if you never use it.


# 1.112 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


# 1.111 29-Aug-2010 dlg

the scsi completion code thinks that if you dont get MFI_STAT_OK
back from the chip on a command then the command completely failed.
MFI_STAT_SCSI_DONE_WITH_ERROR really means the command completed
fine, but there's some sense data too. this tweaks the handling to
be more appropriate, as per the linux and solaris drivers.

timed out waiting for beck@
putting this in cos its obviously more correct than the current code.


Revision tags: OPENBSD_4_8_BASE
# 1.110 22-Jul-2010 matthew

SCSI HBA drivers are supposed to get their SCSI CDBs from xs->cmd, not
xs->cmdstore.

ok krw@ a while back (contingent upon testing), and deraadt@ says this
has been in snapshots for weeks now.


# 1.109 01-Jul-2010 matthew

Change scsibus(4)'s scsi_link array to an SLIST to save memory on
sparsely populated buses.

ok dlg@, krw@


# 1.108 30-Jun-2010 mk

Use SLIST for the ccb free list.

ok krw, discontent grunts from marco.


# 1.107 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.106 15-Jun-2010 dlg

dont pass the dev_t from the scsi device drivers into the midlayer for
ioctl requests, and dont pass the proc pointers around for any ioctl
requests in scsi land at all. neither were used, so trim the fat.

ok krw@ marco@


# 1.105 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.104 16-May-2010 nicm

Use a temporary variable for now to sidestep -Wbounded checking when
copying vendor[8]/product[16]/revision[4] out of struct scsi_inquiry_data
together with one memcopy.

ok krw


# 1.103 22-Apr-2010 oga

use BUS_DMA_ZERO on alloc instead of bzeroing after.

ok dlg@, marco@


# 1.102 10-Apr-2010 marco

grrr var names in protos


# 1.101 10-Apr-2010 marco

sprinkle some bus_dmamap_sync around frame access.
prompted by oga


# 1.100 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.99 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.98 04-Jan-2010 dlg

rename ccb_xs to ccb_cookie and change its type from a scsi_xfer * to a
void *. this lets us pass things other than scsi_xfers to ccb completion
handlers.


# 1.97 04-Jan-2010 dlg

protect the ccb free queue with a mutex rather than splbio


# 1.96 03-Jan-2010 chl

change M_WAITOK --> M_WAITOK|M_CANFAIL

with input from marco@

ok marco@ krw@

this was ok looooooooong time ago but lost in my mailbox


Revision tags: OPENBSD_4_6_BASE
# 1.95 30-Apr-2009 marco

Add READ(16) & WRITE(16) commands.
ok krw


# 1.94 29-Apr-2009 marco

MFI_D_IOCTL should be commented out. No binary change.


# 1.93 04-Apr-2009 dlg

scrub more fields in the ccb when returning them to the free list after
theyve been used, in particular the mfi header flags which has a bit
that specifies if a command should be completed via the interrupt path.

if we use a ccb during boot we set that bit, but it isnt necessarily
cleared by things that use it later on. this means a ccb we expected to
complete via an interrupt never actually generates an interrupt or appears
in the reply queue. this obviously stalls the io.


# 1.92 29-Mar-2009 marco

spello


# 1.91 29-Mar-2009 dlg

when we steal the SYNC CACHE command in mfi_scsi_cmd we still have to
mark the xs as done and call scsi_done for it rather than just returning
COMPLETE.


# 1.90 29-Mar-2009 dlg

fix a small race in mfi_mgmt between the checking of a ccbs completion and
the sleep waiting for the completion. it is possible to get the interrupt
completing the command just before the tsleep, which will never get a
wakeup because the interrupt with the wakeup has already happened.


Revision tags: OPENBSD_4_5_BASE
# 1.89 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.


# 1.88 28-Jan-2009 marco

Add support for next generation megaraid sas raid controllers.
From Jim Giannoules <gortag@gmail.com>


# 1.87 31-Oct-2008 marco

Generalize function to obtain all details to do bio stuff. This is in
preparation to start showing unsused disks which will require all this
information to do the math.

While at it fix a size of hotspare volume bug.


# 1.86 30-Oct-2008 marco

Fix bug that when there are no volumes but there are hot spares it would
no show the hotspares.


# 1.85 28-Oct-2008 marco

Fix output when reporting on multivolume disk groups.

Reported by mitja@muzenic.net


# 1.84 27-Oct-2008 marco

Move some include stuff around


# 1.83 26-Oct-2008 marco

Space


# 1.82 23-Oct-2008 marco

Fix PR5645
ok dlg
tested beck and others


# 1.81 25-Sep-2008 krw

Initialize 'ssc' to NULL since we test it later. Shouldn't ever be
NULL at the point of test unless the device list is confused, but
be consistantly paranoid if we're going to be paranoid.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.80 16-Feb-2008 krw

Return NO_CCB and not TRY_AGAIN_LATER when running out of ccb's.
Eliminates 'not queued' errors reported on the mailing lists.

Tested by Michael (belenus at bsdmail dot de).

ok marco@


# 1.79 11-Feb-2008 dlg

add support for the mfi controllers with the ppc iops, aka, LSI SAS1078 or
Dell PERC6.

committed off a machine booting and rooting off a perc6. tested on a perc5
by marco@
ok marco@


# 1.78 26-Jan-2008 brad

Set the return value instead of returning right away so that the DMA
memory is actually synched.

ok dlg@


# 1.77 26-Jan-2008 dlg

sync dma mem back to the cpu on poll failure.

from mickey via pr5714


# 1.76 26-Jan-2008 dlg

despatch -> dispatch

disparate spellink fix from mickey


# 1.75 05-Nov-2007 krw

More scsi_done() at SPLBIO.


# 1.74 27-Sep-2007 chl

M_ZERO changes

ok dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.73 24-Jun-2007 dlg

rework sensor tasks to use the kernels generic workq rather than a special
kernel thread of its own. the api has changed (which will be fixed in the
manpage shortly) so all the users of sensor tasks that i can find have
been fixed too.

noone tested, so its going in to force people to run with it.
"put it in" deraadt@


# 1.72 29-May-2007 todd

sprinkle some SMALL_KERNEL to permit bio/softraid to run on boot media
ok marco@ then suggested deraadt@


# 1.71 22-Mar-2007 deraadt

split userland & kernel struct sensor/sensordev so that the addition
of new fields in the future is less disruptive. This is done similar
to how struct proc is handled for ps(1). ok jmc (man page changes)
tested fkr simon, and more suggestions from millert


Revision tags: OPENBSD_4_1_BASE
# 1.70 14-Feb-2007 dlg

bus_space does byte swapping to cope with host endianness for us, so remove
an unnecessary htole32().


# 1.69 13-Feb-2007 marco

Fix subtle x ? y : z bug when calling mfi_create_sgl. This worked because
during runtime the bug condition does not happen.

ok krw joris


# 1.68 08-Feb-2007 ray

Remove double semicolons.

From Pierre Riteau <pierre dot riteau at free dot fr>.

OK marco@.


# 1.67 23-Dec-2006 deraadt

adapt to new two-level sensor api; Constantine A. Murenin


# 1.66 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.65 31-Aug-2006 marco

Add sensor thread for individual sd devices.

tested dlg
ok dlg deraadt


# 1.64 30-Aug-2006 dlg

when determining the size of the volumes and disks we want how many
bytes each of them has, not the number of kilobytes. this solves the
"why am i dividing by 2" question. the answer is "you dont, you multiply
by 512".


# 1.63 28-Jul-2006 brad

make dmesg printing look a little bit nicer.


# 1.62 19-Jun-2006 marco

Factor for disk size is /2. Odd but tested on all mfis I have.


# 1.61 19-Jun-2006 miod

Everytime one forgets an argument in a printf-like function call, God kills
a kitten. Commiters, please think of the kittens when working on code.


# 1.60 19-Jun-2006 marco

Make a BGI (Back Ground Init) a scrub instead of rebuild.


# 1.59 19-Jun-2006 marco

Add hot spare support.


# 1.58 26-May-2006 marco

Add blinking for disks.


# 1.57 25-May-2006 marco

Move a int i; to top of function so that it compiles on non c99 compilers.
Pointed out by miod@

The enclosure id modifier didn't reflect reality so move it back to whatever
the raid card uses.


# 1.56 25-May-2006 marco

And add time and percentage to builds and check consistencies.


# 1.55 25-May-2006 marco

Add last bit of physcal disk stuff.
Remove bogus memset.
Hotspares still don't work.


# 1.54 25-May-2006 marco

Add physical device and read config structures.
Add initial part of BIOCDISK


# 1.53 23-May-2006 deraadt

commited with unused variable


# 1.52 23-May-2006 marco

Remove some debug cruft.


# 1.51 23-May-2006 marco

Add first half of physical disk data for bio.


# 1.50 22-May-2006 marco

Add support for raid 50 and 10 in bio.


# 1.49 22-May-2006 marco

Add mail box to mfi_mgmt to handle sub commands more gracefully.
Remove some debug crud that snuck in the TEST_UNIT_READY case.
Finish other half of BIOCVOL primitive.
Add several structures to fill out the BIOCVOL primitive.


# 1.48 22-May-2006 marco

Add first half of BIOCVOL primitive.


# 1.47 21-May-2006 marco

Do a giant flush of disk and raid-card memory when SYNCHONIZE_CACHE is called.


# 1.46 21-May-2006 marco

pretty up some debug statements.


# 1.45 21-May-2006 marco

Add bio alarm function.
Redo mfi_mgmt to deal with zero data commands.


# 1.44 21-May-2006 marco

Add generic management function.
Redo ccb_state flags so that we can actually sleep on it.
Redo mfi_get_info to use new mgmt function.
Add rw_locks for mgmt interface.
Make BIOCINQ dynamic.


# 1.43 21-May-2006 marco

Oops, helps to use the right structure field.
Use actual nr of physical disks present.


# 1.42 21-May-2006 marco

Add first BIOCINQ primitive.


# 1.41 18-May-2006 marco

Remove some debug cruft and pretty up some debug messages.


# 1.40 18-May-2006 marco

Kill splbio/splx in the interrupt handler.


# 1.39 18-May-2006 marco

And we have lift off! Was able to create a filesystem and write to the
filesystem.

Collapse both completion routines into one.
Fixup scsi error reporting in the completion routine.


# 1.38 17-May-2006 marco

Add completion routines.
Fix some bugs inside the interrupt handler.


# 1.37 17-May-2006 marco

Add mfi_get_info to obtain all kinds of fun information from the fw.
Print out whole info structure when debug is enabled.
Add a nice print with useful info during attach.


# 1.36 17-May-2006 marco

Refactor scsi path so that we can have a single sgl function for io and non-io
traffic.
Redo parameters on functions that were passing too many parameters around.


# 1.35 16-May-2006 marco

Nuke some { }


# 1.34 16-May-2006 marco

Move !xs->data case into mfi_start_xs.
Return proper sense data when a polling command fails.


# 1.33 16-May-2006 marco

Fix some more htole32 screw-ups.
Colapse all little SCSI functions into a single generic one.
Fix a bug in the SGE calculation.

This brings the driver up to post:
mfi0 at pci12 dev 14 function 0 "Dell PERC SAS" rev 0x00: Dell PERC 5/e irq 5
scsibus3 at mfi0: 2 targets
sd1 at scsibus3 targ 0 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd1: 237824MB, 237824 cyl, 64 head, 32 sec, 512 bytes/sec, 487063552 sec total
sd2 at scsibus3 targ 1 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd2: 34176MB, 34176 cyl, 64 head, 32 sec, 512 bytes/sec, 69992448 sec total


# 1.32 16-May-2006 marco

Fix some htole32 I missed.
Sprinkle more debug.


# 1.31 16-May-2006 marco

Add READ CAPACITY.


# 1.30 16-May-2006 marco

Oops PREREAD not PREWRITE.


# 1.29 16-May-2006 marco

Add TUR and make it send it directly to firmware.
Sprinkle some extra debug.


# 1.28 15-May-2006 marco

Clear all relevant ccb fields when mfi_put_ccb frees a ccb.


# 1.27 15-May-2006 marco

Oops don't send command twice to firmware when polling.


# 1.26 15-May-2006 marco

Add INQUIRY command.
Add sgl magic.


# 1.25 10-May-2006 marco

Add some airplane code.

add bio hooks.
add scsi entry point for io.


# 1.24 26-Apr-2006 marco

Fix some debug prints.


# 1.23 21-Apr-2006 marco

typo


# 1.22 21-Apr-2006 marco

Add mfi_poll and use the new shiny function to setup all the hardware queues.
Lots of ideas from the FreeBSD driver.


# 1.21 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.20 20-Apr-2006 dlg

marco hates typedefs as much as i do, so he asked me to clean mfi like i
just did with ami. this gets rid of the typedef for the ccb lists.

also uses TAILQ_FIRST to get ccbs off the freelist. this is a proactive
fix for a lint teary.


# 1.19 18-Apr-2006 marco

It helps to initialize a queue before usage.


# 1.18 18-Apr-2006 marco

Actually add ccbs to the queue.
Fix the error path for mfi_init_ccb.
Alter dmamap for io.


# 1.17 17-Apr-2006 marco

Sprinkle more debug. Remove 64 byte boundary; it doesn't seem to like it.
Hack around 64 byte boundary for the frames for now.


# 1.16 17-Apr-2006 marco

Setup ccbs and clean up ccb structure.


# 1.15 16-Apr-2006 marco

Oops, make mfi_allocmem always use 64 byte boundaries since frames have to
have that alignment. It doesn't matter for the other consumers of the
function.


# 1.14 16-Apr-2006 marco

Add frame memory and sglist allocation.


# 1.13 16-Apr-2006 marco

Make memory access use macro.


# 1.12 16-Apr-2006 marco

typo


# 1.11 16-Apr-2006 marco

Add get and put ccb functions. Shuffle some more definitions.


# 1.10 16-Apr-2006 marco

Nicer print when context is invalid.


# 1.9 16-Apr-2006 marco

Shuffle some #defines.
Fix comments.
Add human readable enable intrrupt #define.


# 1.8 16-Apr-2006 marco

Add interrupt handler. Idea borrowed from FreeBSD since it is much nicer
than the Linux one.


# 1.7 07-Apr-2006 marco

Replace bus_space functions with generic ones that do barriers.


# 1.6 07-Apr-2006 marco

Add memory allocator functions.


# 1.5 07-Apr-2006 marco

Print state in debug. Change return vales to 1 instead of ENXIO.


# 1.4 07-Apr-2006 marco

Make a better debug mechanism.


# 1.3 07-Apr-2006 marco

Enable mfi_transition_fw() original code from FreeBSD.


# 1.2 06-Apr-2006 marco

Add fw transition logic.


# 1.1 06-Apr-2006 marco

Add skeleton driver for MegaRAID SAS.


# 1.176 21-Mar-2020 krw

Simplify some goto'ing that jumps a single line or
does nothing at all.

The first one spotted as CID 1452976.

Reads good to millert@

ok mpi@


# 1.175 13-Feb-2020 krw

Nuke *_minphys() functions that either simply apply MAXPHYS or do
nothing at all. MAXPHYS will be applied in minphys() and nothing at
all, well, doesn't do anything.

Also remove any '#define <blah> MAXPHYS' statements used solely to
disguise MAXPHYS in said functions.


# 1.174 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.173 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.172 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.171 31-Dec-2019 mpi

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

ok kn@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.170 05-Mar-2019 jmatthew

apply background init progress fix from r1.59 of mfii.c
(reverting most of r1.60 of mfi.c, oddly enough)

ok dlg@
tested on a SAS2008 (perc h310)


Revision tags: OPENBSD_6_4_BASE
# 1.169 14-Aug-2018 jmatthew

return ENOTTY rather than EINVAL to indicate an ioctl hasn't been handled

ok dlg@ deraadt@ kettenis@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.168 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.167 02-Feb-2017 dlg

copy the mbox into the dcmd struct, not the pointer to the mbox.

makes bioctl work on mfi(4) again.

while here memset a few mboxes before using them.

bioctl breakage reported by jason george


# 1.166 23-Jan-2017 dlg

represent the mbox layout with union instead of an array of bytes.

memcpying uint16_ts into inconsistently addressed offsets is hard
to read, and this makes future work easier to implement.

tested on mfi(4) and mfii(4)


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.165 09-Sep-2015 deraadt

sizes for free(); ok sthen


Revision tags: OPENBSD_5_8_BASE
# 1.164 29-May-2015 uebayasi

Initial addition of ``Patrol Read'' support in bio(4), biocto(8), and
mfi(4). Based on FreeBSD, but done without mfiutil(8).

OK deraadt@


# 1.163 18-May-2015 mikeb

Prevent splassert from firing during sd_flush which runs "cold"

While mfi(4) should pass SCSI transfer flags (e.g. SCSI_POLL and
SCSI_NOSLEEP) down to the management function, make it at least
use "cold" consistently for now.

ok dlg


# 1.162 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.161 08-Mar-2015 dlg

properly set sgl related flags on skinny controllers. this fixes
io against physical disks on my dell perc h310s. logical disks still
work fine.

ok deraadt@ yasuoka@


# 1.160 08-Feb-2015 yasuoka

Fix mfi ioctl to set drive state properly.
diff from Tsubai Masanari

test dlg jmatthew
ok dlg


# 1.159 09-Jan-2015 yasuoka

Add support DIOC{G,S}CACHE to mfi(4). Cache of disk on mfi(4) will
be enabled by default. Also if the controller doesn't have any RAM,
the cache on the physical disk will be enabled.

discuss with jsg tsubai
ok dlg


# 1.158 19-Dec-2014 deraadt

another handful of bcopy -> memcpy because there is no overlap


# 1.157 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.156 09-Sep-2014 dlg

mark the interrupt handler mpsafe, and give up biglock in the scsi cmd
submission paths. take biglock again when calling back into the scsi
stack.

tested on a variety of cards here, including the skinny mfis on the
firewall next to mpsafe myx.


# 1.155 15-Aug-2014 yasuoka

Create a function which loads sgd in the mfi_iop_ops struct so that skinny
adapters can use "IEEE sgl".

tested dlg yasuoka
ok dlg jsg


Revision tags: OPENBSD_5_6_BASE
# 1.154 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.153 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.152 04-May-2014 sf

format string fixes for bus_addr_t and bus_size_t

bus_addr_t and bus_size_t are u_long everywhere

ok kettenis@


Revision tags: OPENBSD_5_5_BASE
# 1.151 20-Feb-2014 kettenis

revert previous commit; didn't intend to commit those bits


# 1.150 20-Feb-2014 kettenis

Avoid printing the "nvram corrupt" message for onboard 2200s found on Sun
hardware.

ok dlg@, jmatthew@


# 1.149 04-Dec-2013 dlg

mfi_refresh_sensors calls mfi_ioctl_vol which calls mfi_bio_getitall, which
replaces pointers in the softc and all sorts of fun stuff. this protects
the call to bio_getitall with the sc_lock the ioctl path uses, so we dont
get panics like those reported on bugs@ recently.

ok deraadt@


# 1.148 23-Oct-2013 kettenis

Add support for displaying the cache write policy of RAID volumes to bioctl(8)
and make mfi(4) pass up the necessary information. Adding support for other
RAID controllers is left as an excercise to the reader.

ok deraadt@


# 1.147 09-Oct-2013 jmatthew

Include the 'state of health' field in the bbu ok sensor value.
The dell perc 6/i sets this to zero (meaning bad) when it
decides the battery doesn't have enough capacity for it to
allow write back mode, but doesn't set any of the other flags
to tell us why.

ok dlg@, tested by sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.146 18-May-2013 jmc

enw->new in comment;
spotted by krw, missed by jsg, and forwarded From: Alexey Suslikov


# 1.145 08-May-2013 jsg

fix some leaks in error paths
ok fgsch@ krw@ kettenis@


# 1.144 03-May-2013 dlg

break out the battery status into excruciating detail. makes it harder for
$VENDOR to complain about a lack of diagnostic material from their crappy
mgmt tools if you're not running an operating system they support.


# 1.143 02-May-2013 dlg

always attach the battery sensor if the adapter lets us query it.
newly replaced batteries dont show up immediately.


# 1.142 01-May-2013 dlg

provide a sensor for the battery backup unit (bbu) on mfi boards that
support it.

now i can tell (a bit better) why io might be slow on some of my boxes.


# 1.141 01-May-2013 dlg

dont need to walk alldevs during sensor creation looking for the logical
disk scsibus when we record that in mfi_attach.

also happens to get rid of a logic error that let it come out of the loop
on alldevs with a reference to something that wasnt the logical disk
scsibus and use that.


# 1.140 30-Apr-2013 dlg

use MR_DCMD consistently. some MD_DCMD was in there somehow.


# 1.139 07-Apr-2013 dlg

david imhoff points out that the error handling in mfi_init_ccb gets the
index to which ccb to free wrong.

this takes the logic from mpi/mpii/mfii which pulls the ready ccbs off
the free list rather than rely on the current index from the for loop
that we failed inside of.

thanks to david for finding this out.


Revision tags: OPENBSD_5_3_BASE
# 1.138 12-Sep-2012 haesbaert

Make sure we don't sleep on autoconf.

ok mikeb


# 1.137 17-Aug-2012 dlg

add support for "physical devices" on skinny controllers.

these controllers let you specify disks that should be accessed directly
rather than be part of logical volumes. apparently you can plug in things
like tape drives too.

anyway, physical devices are exposed via a separate scsibus attached to
mfi.

ok mikeb@


# 1.136 16-Aug-2012 dlg

fix mfi_poll by having it do delays between loops, and breaking on
timeouts. how embarrassment.

implement mfi_exec for doing sync executions of commands in process
contexts and cut mfi_mgmt over to it.


# 1.135 16-Aug-2012 dlg

rework mfi_poll so it will do all the completions on a ccb including
calling the done handler.

this makes it consistently complete scsi io with all the proper error
checking.


# 1.134 16-Aug-2012 dlg

stop passing mfi_softc around as a member of the ccb, consistently give it
as the first argument to functions. like mfii.


# 1.133 16-Aug-2012 dlg

scrub ccbs when we're about to use them, not when we put them back
on the free list. ccbs can be reused, so we dont want old state screwing up
new commands.


# 1.132 16-Aug-2012 dlg

move the dma syncs for the ccb data into ccb_done, so we can do it once
rather than put the code everywhere.


# 1.131 16-Aug-2012 dlg

fix up the dma sync for the command frame in mfi_done.


# 1.130 14-Aug-2012 dlg

use scsi_get_link to find out the name of a child device for bioctl rather
than snoop scsi commands and copy it in an io path.

no functional change, but the code has one less XXX now.


# 1.129 14-Aug-2012 dlg

expose the max number of logical volumes the hardware supports as the width
of its scsibus. only advertise 1 lun on logical volumes instead of letting
the midlayer fix it up to 8.

give every target on the bus max_cmds openings. iopools means they will
properly share access to them.

this in particular is useful on skinny controllers which only advertise 31
command slots. if you have 16 volumes, theyll only get 1 opening each with
the old maths. this way round the ones that are busy will share the slots.

tested on a perc5 with two volumes and hard workloads.


# 1.128 14-Aug-2012 dlg

print the boards name (eg, perc 5/i) according to the firmware like mfii.

ok deraadt@


# 1.127 14-Aug-2012 dlg

move knowledge of the location of the inbound doorbell out of code in
transition_firmware into a member of the iop structures.

ok mikeb@ haesbaert@


# 1.126 13-Aug-2012 dlg

get rid of the last foo_lo and foo_hi bits i could find in the hardware
structures and use htole64 instead of htole32(addr >> 32); htole32(addr);

gets rid of "handy" stack variables to get the dva to 64bits.

sprinkle some more byte swaps for things that should have it.

tested on a perc5 (xscale)


# 1.125 13-Aug-2012 dlg

do appropriate bus_dmamapy_syncs around the pcq/completion ring.

tested on a perc5 (xscale)


# 1.124 13-Aug-2012 dlg

replace uint32_ts for hi and lo addresses in the mfi_init_ hardware
descriptors with single uint64_ts. theyre not some weird middle
endian thing. this makes the code more readable.

add some missing htole32s to the code while here.

tested on a perc5 (xscale).


# 1.123 11-Aug-2012 dlg

the producer/consumer values are used by the device, which is little
endian. do appropriate byteswapping for when the host cpu uses them.

tested on a perc5 (xscale) in an amd64.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.122 12-Jan-2012 dlg

add support for skinny variants.

from Alexey Suslikov
reviewed by marco


Revision tags: OPENBSD_5_0_BASE
# 1.121 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.120 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.119 09-Apr-2011 marco

add all 64 bit dma plumbing but stick with 32 for now by default.

ok deraadt


# 1.118 09-Apr-2011 marco

make sure the upper 32 bits are always written to instead of assuming it
is 0.

ok deraadt.


# 1.117 08-Apr-2011 marco

kill some stray spaces


# 1.116 08-Apr-2011 marco

rename wiat channel to something less than 8 chars.

prompted by deraadt


# 1.115 08-Apr-2011 marco

use dma_alloc for transient management commands.

prodded and ok deraadt


Revision tags: OPENBSD_4_9_BASE
# 1.114 30-Dec-2010 dlg

cut mfi over to using iopools.

this gets rid of NO_CCB, provides better scheduling of io between busy
logical volumes on the same controller, and makes the ioctl and sensor
paths more reliable.

this is the least intrusive version of this change i could come up with. it
only took 4 or 5 goes...

ok marco@
deraadt@ says this is a good time for this change.


# 1.113 24-Sep-2010 dlg

no use setting cmd in mfi_ioctl_setstate if you never use it.


# 1.112 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


# 1.111 29-Aug-2010 dlg

the scsi completion code thinks that if you dont get MFI_STAT_OK
back from the chip on a command then the command completely failed.
MFI_STAT_SCSI_DONE_WITH_ERROR really means the command completed
fine, but there's some sense data too. this tweaks the handling to
be more appropriate, as per the linux and solaris drivers.

timed out waiting for beck@
putting this in cos its obviously more correct than the current code.


Revision tags: OPENBSD_4_8_BASE
# 1.110 22-Jul-2010 matthew

SCSI HBA drivers are supposed to get their SCSI CDBs from xs->cmd, not
xs->cmdstore.

ok krw@ a while back (contingent upon testing), and deraadt@ says this
has been in snapshots for weeks now.


# 1.109 01-Jul-2010 matthew

Change scsibus(4)'s scsi_link array to an SLIST to save memory on
sparsely populated buses.

ok dlg@, krw@


# 1.108 30-Jun-2010 mk

Use SLIST for the ccb free list.

ok krw, discontent grunts from marco.


# 1.107 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.106 15-Jun-2010 dlg

dont pass the dev_t from the scsi device drivers into the midlayer for
ioctl requests, and dont pass the proc pointers around for any ioctl
requests in scsi land at all. neither were used, so trim the fat.

ok krw@ marco@


# 1.105 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.104 16-May-2010 nicm

Use a temporary variable for now to sidestep -Wbounded checking when
copying vendor[8]/product[16]/revision[4] out of struct scsi_inquiry_data
together with one memcopy.

ok krw


# 1.103 22-Apr-2010 oga

use BUS_DMA_ZERO on alloc instead of bzeroing after.

ok dlg@, marco@


# 1.102 10-Apr-2010 marco

grrr var names in protos


# 1.101 10-Apr-2010 marco

sprinkle some bus_dmamap_sync around frame access.
prompted by oga


# 1.100 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.99 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.98 04-Jan-2010 dlg

rename ccb_xs to ccb_cookie and change its type from a scsi_xfer * to a
void *. this lets us pass things other than scsi_xfers to ccb completion
handlers.


# 1.97 04-Jan-2010 dlg

protect the ccb free queue with a mutex rather than splbio


# 1.96 03-Jan-2010 chl

change M_WAITOK --> M_WAITOK|M_CANFAIL

with input from marco@

ok marco@ krw@

this was ok looooooooong time ago but lost in my mailbox


Revision tags: OPENBSD_4_6_BASE
# 1.95 30-Apr-2009 marco

Add READ(16) & WRITE(16) commands.
ok krw


# 1.94 29-Apr-2009 marco

MFI_D_IOCTL should be commented out. No binary change.


# 1.93 04-Apr-2009 dlg

scrub more fields in the ccb when returning them to the free list after
theyve been used, in particular the mfi header flags which has a bit
that specifies if a command should be completed via the interrupt path.

if we use a ccb during boot we set that bit, but it isnt necessarily
cleared by things that use it later on. this means a ccb we expected to
complete via an interrupt never actually generates an interrupt or appears
in the reply queue. this obviously stalls the io.


# 1.92 29-Mar-2009 marco

spello


# 1.91 29-Mar-2009 dlg

when we steal the SYNC CACHE command in mfi_scsi_cmd we still have to
mark the xs as done and call scsi_done for it rather than just returning
COMPLETE.


# 1.90 29-Mar-2009 dlg

fix a small race in mfi_mgmt between the checking of a ccbs completion and
the sleep waiting for the completion. it is possible to get the interrupt
completing the command just before the tsleep, which will never get a
wakeup because the interrupt with the wakeup has already happened.


Revision tags: OPENBSD_4_5_BASE
# 1.89 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.


# 1.88 28-Jan-2009 marco

Add support for next generation megaraid sas raid controllers.
From Jim Giannoules <gortag@gmail.com>


# 1.87 31-Oct-2008 marco

Generalize function to obtain all details to do bio stuff. This is in
preparation to start showing unsused disks which will require all this
information to do the math.

While at it fix a size of hotspare volume bug.


# 1.86 30-Oct-2008 marco

Fix bug that when there are no volumes but there are hot spares it would
no show the hotspares.


# 1.85 28-Oct-2008 marco

Fix output when reporting on multivolume disk groups.

Reported by mitja@muzenic.net


# 1.84 27-Oct-2008 marco

Move some include stuff around


# 1.83 26-Oct-2008 marco

Space


# 1.82 23-Oct-2008 marco

Fix PR5645
ok dlg
tested beck and others


# 1.81 25-Sep-2008 krw

Initialize 'ssc' to NULL since we test it later. Shouldn't ever be
NULL at the point of test unless the device list is confused, but
be consistantly paranoid if we're going to be paranoid.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.80 16-Feb-2008 krw

Return NO_CCB and not TRY_AGAIN_LATER when running out of ccb's.
Eliminates 'not queued' errors reported on the mailing lists.

Tested by Michael (belenus at bsdmail dot de).

ok marco@


# 1.79 11-Feb-2008 dlg

add support for the mfi controllers with the ppc iops, aka, LSI SAS1078 or
Dell PERC6.

committed off a machine booting and rooting off a perc6. tested on a perc5
by marco@
ok marco@


# 1.78 26-Jan-2008 brad

Set the return value instead of returning right away so that the DMA
memory is actually synched.

ok dlg@


# 1.77 26-Jan-2008 dlg

sync dma mem back to the cpu on poll failure.

from mickey via pr5714


# 1.76 26-Jan-2008 dlg

despatch -> dispatch

disparate spellink fix from mickey


# 1.75 05-Nov-2007 krw

More scsi_done() at SPLBIO.


# 1.74 27-Sep-2007 chl

M_ZERO changes

ok dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.73 24-Jun-2007 dlg

rework sensor tasks to use the kernels generic workq rather than a special
kernel thread of its own. the api has changed (which will be fixed in the
manpage shortly) so all the users of sensor tasks that i can find have
been fixed too.

noone tested, so its going in to force people to run with it.
"put it in" deraadt@


# 1.72 29-May-2007 todd

sprinkle some SMALL_KERNEL to permit bio/softraid to run on boot media
ok marco@ then suggested deraadt@


# 1.71 22-Mar-2007 deraadt

split userland & kernel struct sensor/sensordev so that the addition
of new fields in the future is less disruptive. This is done similar
to how struct proc is handled for ps(1). ok jmc (man page changes)
tested fkr simon, and more suggestions from millert


Revision tags: OPENBSD_4_1_BASE
# 1.70 14-Feb-2007 dlg

bus_space does byte swapping to cope with host endianness for us, so remove
an unnecessary htole32().


# 1.69 13-Feb-2007 marco

Fix subtle x ? y : z bug when calling mfi_create_sgl. This worked because
during runtime the bug condition does not happen.

ok krw joris


# 1.68 08-Feb-2007 ray

Remove double semicolons.

From Pierre Riteau <pierre dot riteau at free dot fr>.

OK marco@.


# 1.67 23-Dec-2006 deraadt

adapt to new two-level sensor api; Constantine A. Murenin


# 1.66 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.65 31-Aug-2006 marco

Add sensor thread for individual sd devices.

tested dlg
ok dlg deraadt


# 1.64 30-Aug-2006 dlg

when determining the size of the volumes and disks we want how many
bytes each of them has, not the number of kilobytes. this solves the
"why am i dividing by 2" question. the answer is "you dont, you multiply
by 512".


# 1.63 28-Jul-2006 brad

make dmesg printing look a little bit nicer.


# 1.62 19-Jun-2006 marco

Factor for disk size is /2. Odd but tested on all mfis I have.


# 1.61 19-Jun-2006 miod

Everytime one forgets an argument in a printf-like function call, God kills
a kitten. Commiters, please think of the kittens when working on code.


# 1.60 19-Jun-2006 marco

Make a BGI (Back Ground Init) a scrub instead of rebuild.


# 1.59 19-Jun-2006 marco

Add hot spare support.


# 1.58 26-May-2006 marco

Add blinking for disks.


# 1.57 25-May-2006 marco

Move a int i; to top of function so that it compiles on non c99 compilers.
Pointed out by miod@

The enclosure id modifier didn't reflect reality so move it back to whatever
the raid card uses.


# 1.56 25-May-2006 marco

And add time and percentage to builds and check consistencies.


# 1.55 25-May-2006 marco

Add last bit of physcal disk stuff.
Remove bogus memset.
Hotspares still don't work.


# 1.54 25-May-2006 marco

Add physical device and read config structures.
Add initial part of BIOCDISK


# 1.53 23-May-2006 deraadt

commited with unused variable


# 1.52 23-May-2006 marco

Remove some debug cruft.


# 1.51 23-May-2006 marco

Add first half of physical disk data for bio.


# 1.50 22-May-2006 marco

Add support for raid 50 and 10 in bio.


# 1.49 22-May-2006 marco

Add mail box to mfi_mgmt to handle sub commands more gracefully.
Remove some debug crud that snuck in the TEST_UNIT_READY case.
Finish other half of BIOCVOL primitive.
Add several structures to fill out the BIOCVOL primitive.


# 1.48 22-May-2006 marco

Add first half of BIOCVOL primitive.


# 1.47 21-May-2006 marco

Do a giant flush of disk and raid-card memory when SYNCHONIZE_CACHE is called.


# 1.46 21-May-2006 marco

pretty up some debug statements.


# 1.45 21-May-2006 marco

Add bio alarm function.
Redo mfi_mgmt to deal with zero data commands.


# 1.44 21-May-2006 marco

Add generic management function.
Redo ccb_state flags so that we can actually sleep on it.
Redo mfi_get_info to use new mgmt function.
Add rw_locks for mgmt interface.
Make BIOCINQ dynamic.


# 1.43 21-May-2006 marco

Oops, helps to use the right structure field.
Use actual nr of physical disks present.


# 1.42 21-May-2006 marco

Add first BIOCINQ primitive.


# 1.41 18-May-2006 marco

Remove some debug cruft and pretty up some debug messages.


# 1.40 18-May-2006 marco

Kill splbio/splx in the interrupt handler.


# 1.39 18-May-2006 marco

And we have lift off! Was able to create a filesystem and write to the
filesystem.

Collapse both completion routines into one.
Fixup scsi error reporting in the completion routine.


# 1.38 17-May-2006 marco

Add completion routines.
Fix some bugs inside the interrupt handler.


# 1.37 17-May-2006 marco

Add mfi_get_info to obtain all kinds of fun information from the fw.
Print out whole info structure when debug is enabled.
Add a nice print with useful info during attach.


# 1.36 17-May-2006 marco

Refactor scsi path so that we can have a single sgl function for io and non-io
traffic.
Redo parameters on functions that were passing too many parameters around.


# 1.35 16-May-2006 marco

Nuke some { }


# 1.34 16-May-2006 marco

Move !xs->data case into mfi_start_xs.
Return proper sense data when a polling command fails.


# 1.33 16-May-2006 marco

Fix some more htole32 screw-ups.
Colapse all little SCSI functions into a single generic one.
Fix a bug in the SGE calculation.

This brings the driver up to post:
mfi0 at pci12 dev 14 function 0 "Dell PERC SAS" rev 0x00: Dell PERC 5/e irq 5
scsibus3 at mfi0: 2 targets
sd1 at scsibus3 targ 0 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd1: 237824MB, 237824 cyl, 64 head, 32 sec, 512 bytes/sec, 487063552 sec total
sd2 at scsibus3 targ 1 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd2: 34176MB, 34176 cyl, 64 head, 32 sec, 512 bytes/sec, 69992448 sec total


# 1.32 16-May-2006 marco

Fix some htole32 I missed.
Sprinkle more debug.


# 1.31 16-May-2006 marco

Add READ CAPACITY.


# 1.30 16-May-2006 marco

Oops PREREAD not PREWRITE.


# 1.29 16-May-2006 marco

Add TUR and make it send it directly to firmware.
Sprinkle some extra debug.


# 1.28 15-May-2006 marco

Clear all relevant ccb fields when mfi_put_ccb frees a ccb.


# 1.27 15-May-2006 marco

Oops don't send command twice to firmware when polling.


# 1.26 15-May-2006 marco

Add INQUIRY command.
Add sgl magic.


# 1.25 10-May-2006 marco

Add some airplane code.

add bio hooks.
add scsi entry point for io.


# 1.24 26-Apr-2006 marco

Fix some debug prints.


# 1.23 21-Apr-2006 marco

typo


# 1.22 21-Apr-2006 marco

Add mfi_poll and use the new shiny function to setup all the hardware queues.
Lots of ideas from the FreeBSD driver.


# 1.21 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.20 20-Apr-2006 dlg

marco hates typedefs as much as i do, so he asked me to clean mfi like i
just did with ami. this gets rid of the typedef for the ccb lists.

also uses TAILQ_FIRST to get ccbs off the freelist. this is a proactive
fix for a lint teary.


# 1.19 18-Apr-2006 marco

It helps to initialize a queue before usage.


# 1.18 18-Apr-2006 marco

Actually add ccbs to the queue.
Fix the error path for mfi_init_ccb.
Alter dmamap for io.


# 1.17 17-Apr-2006 marco

Sprinkle more debug. Remove 64 byte boundary; it doesn't seem to like it.
Hack around 64 byte boundary for the frames for now.


# 1.16 17-Apr-2006 marco

Setup ccbs and clean up ccb structure.


# 1.15 16-Apr-2006 marco

Oops, make mfi_allocmem always use 64 byte boundaries since frames have to
have that alignment. It doesn't matter for the other consumers of the
function.


# 1.14 16-Apr-2006 marco

Add frame memory and sglist allocation.


# 1.13 16-Apr-2006 marco

Make memory access use macro.


# 1.12 16-Apr-2006 marco

typo


# 1.11 16-Apr-2006 marco

Add get and put ccb functions. Shuffle some more definitions.


# 1.10 16-Apr-2006 marco

Nicer print when context is invalid.


# 1.9 16-Apr-2006 marco

Shuffle some #defines.
Fix comments.
Add human readable enable intrrupt #define.


# 1.8 16-Apr-2006 marco

Add interrupt handler. Idea borrowed from FreeBSD since it is much nicer
than the Linux one.


# 1.7 07-Apr-2006 marco

Replace bus_space functions with generic ones that do barriers.


# 1.6 07-Apr-2006 marco

Add memory allocator functions.


# 1.5 07-Apr-2006 marco

Print state in debug. Change return vales to 1 instead of ENXIO.


# 1.4 07-Apr-2006 marco

Make a better debug mechanism.


# 1.3 07-Apr-2006 marco

Enable mfi_transition_fw() original code from FreeBSD.


# 1.2 06-Apr-2006 marco

Add fw transition logic.


# 1.1 06-Apr-2006 marco

Add skeleton driver for MegaRAID SAS.


# 1.175 13-Feb-2020 krw

Nuke *_minphys() functions that either simply apply MAXPHYS or do
nothing at all. MAXPHYS will be applied in minphys() and nothing at
all, well, doesn't do anything.

Also remove any '#define <blah> MAXPHYS' statements used solely to
disguise MAXPHYS in said functions.


# 1.174 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.173 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.172 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.171 31-Dec-2019 mpi

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

ok kn@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.170 05-Mar-2019 jmatthew

apply background init progress fix from r1.59 of mfii.c
(reverting most of r1.60 of mfi.c, oddly enough)

ok dlg@
tested on a SAS2008 (perc h310)


Revision tags: OPENBSD_6_4_BASE
# 1.169 14-Aug-2018 jmatthew

return ENOTTY rather than EINVAL to indicate an ioctl hasn't been handled

ok dlg@ deraadt@ kettenis@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.168 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.167 02-Feb-2017 dlg

copy the mbox into the dcmd struct, not the pointer to the mbox.

makes bioctl work on mfi(4) again.

while here memset a few mboxes before using them.

bioctl breakage reported by jason george


# 1.166 23-Jan-2017 dlg

represent the mbox layout with union instead of an array of bytes.

memcpying uint16_ts into inconsistently addressed offsets is hard
to read, and this makes future work easier to implement.

tested on mfi(4) and mfii(4)


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.165 09-Sep-2015 deraadt

sizes for free(); ok sthen


Revision tags: OPENBSD_5_8_BASE
# 1.164 29-May-2015 uebayasi

Initial addition of ``Patrol Read'' support in bio(4), biocto(8), and
mfi(4). Based on FreeBSD, but done without mfiutil(8).

OK deraadt@


# 1.163 18-May-2015 mikeb

Prevent splassert from firing during sd_flush which runs "cold"

While mfi(4) should pass SCSI transfer flags (e.g. SCSI_POLL and
SCSI_NOSLEEP) down to the management function, make it at least
use "cold" consistently for now.

ok dlg


# 1.162 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.161 08-Mar-2015 dlg

properly set sgl related flags on skinny controllers. this fixes
io against physical disks on my dell perc h310s. logical disks still
work fine.

ok deraadt@ yasuoka@


# 1.160 08-Feb-2015 yasuoka

Fix mfi ioctl to set drive state properly.
diff from Tsubai Masanari

test dlg jmatthew
ok dlg


# 1.159 09-Jan-2015 yasuoka

Add support DIOC{G,S}CACHE to mfi(4). Cache of disk on mfi(4) will
be enabled by default. Also if the controller doesn't have any RAM,
the cache on the physical disk will be enabled.

discuss with jsg tsubai
ok dlg


# 1.158 19-Dec-2014 deraadt

another handful of bcopy -> memcpy because there is no overlap


# 1.157 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.156 09-Sep-2014 dlg

mark the interrupt handler mpsafe, and give up biglock in the scsi cmd
submission paths. take biglock again when calling back into the scsi
stack.

tested on a variety of cards here, including the skinny mfis on the
firewall next to mpsafe myx.


# 1.155 15-Aug-2014 yasuoka

Create a function which loads sgd in the mfi_iop_ops struct so that skinny
adapters can use "IEEE sgl".

tested dlg yasuoka
ok dlg jsg


Revision tags: OPENBSD_5_6_BASE
# 1.154 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.153 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.152 04-May-2014 sf

format string fixes for bus_addr_t and bus_size_t

bus_addr_t and bus_size_t are u_long everywhere

ok kettenis@


Revision tags: OPENBSD_5_5_BASE
# 1.151 20-Feb-2014 kettenis

revert previous commit; didn't intend to commit those bits


# 1.150 20-Feb-2014 kettenis

Avoid printing the "nvram corrupt" message for onboard 2200s found on Sun
hardware.

ok dlg@, jmatthew@


# 1.149 04-Dec-2013 dlg

mfi_refresh_sensors calls mfi_ioctl_vol which calls mfi_bio_getitall, which
replaces pointers in the softc and all sorts of fun stuff. this protects
the call to bio_getitall with the sc_lock the ioctl path uses, so we dont
get panics like those reported on bugs@ recently.

ok deraadt@


# 1.148 23-Oct-2013 kettenis

Add support for displaying the cache write policy of RAID volumes to bioctl(8)
and make mfi(4) pass up the necessary information. Adding support for other
RAID controllers is left as an excercise to the reader.

ok deraadt@


# 1.147 09-Oct-2013 jmatthew

Include the 'state of health' field in the bbu ok sensor value.
The dell perc 6/i sets this to zero (meaning bad) when it
decides the battery doesn't have enough capacity for it to
allow write back mode, but doesn't set any of the other flags
to tell us why.

ok dlg@, tested by sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.146 18-May-2013 jmc

enw->new in comment;
spotted by krw, missed by jsg, and forwarded From: Alexey Suslikov


# 1.145 08-May-2013 jsg

fix some leaks in error paths
ok fgsch@ krw@ kettenis@


# 1.144 03-May-2013 dlg

break out the battery status into excruciating detail. makes it harder for
$VENDOR to complain about a lack of diagnostic material from their crappy
mgmt tools if you're not running an operating system they support.


# 1.143 02-May-2013 dlg

always attach the battery sensor if the adapter lets us query it.
newly replaced batteries dont show up immediately.


# 1.142 01-May-2013 dlg

provide a sensor for the battery backup unit (bbu) on mfi boards that
support it.

now i can tell (a bit better) why io might be slow on some of my boxes.


# 1.141 01-May-2013 dlg

dont need to walk alldevs during sensor creation looking for the logical
disk scsibus when we record that in mfi_attach.

also happens to get rid of a logic error that let it come out of the loop
on alldevs with a reference to something that wasnt the logical disk
scsibus and use that.


# 1.140 30-Apr-2013 dlg

use MR_DCMD consistently. some MD_DCMD was in there somehow.


# 1.139 07-Apr-2013 dlg

david imhoff points out that the error handling in mfi_init_ccb gets the
index to which ccb to free wrong.

this takes the logic from mpi/mpii/mfii which pulls the ready ccbs off
the free list rather than rely on the current index from the for loop
that we failed inside of.

thanks to david for finding this out.


Revision tags: OPENBSD_5_3_BASE
# 1.138 12-Sep-2012 haesbaert

Make sure we don't sleep on autoconf.

ok mikeb


# 1.137 17-Aug-2012 dlg

add support for "physical devices" on skinny controllers.

these controllers let you specify disks that should be accessed directly
rather than be part of logical volumes. apparently you can plug in things
like tape drives too.

anyway, physical devices are exposed via a separate scsibus attached to
mfi.

ok mikeb@


# 1.136 16-Aug-2012 dlg

fix mfi_poll by having it do delays between loops, and breaking on
timeouts. how embarrassment.

implement mfi_exec for doing sync executions of commands in process
contexts and cut mfi_mgmt over to it.


# 1.135 16-Aug-2012 dlg

rework mfi_poll so it will do all the completions on a ccb including
calling the done handler.

this makes it consistently complete scsi io with all the proper error
checking.


# 1.134 16-Aug-2012 dlg

stop passing mfi_softc around as a member of the ccb, consistently give it
as the first argument to functions. like mfii.


# 1.133 16-Aug-2012 dlg

scrub ccbs when we're about to use them, not when we put them back
on the free list. ccbs can be reused, so we dont want old state screwing up
new commands.


# 1.132 16-Aug-2012 dlg

move the dma syncs for the ccb data into ccb_done, so we can do it once
rather than put the code everywhere.


# 1.131 16-Aug-2012 dlg

fix up the dma sync for the command frame in mfi_done.


# 1.130 14-Aug-2012 dlg

use scsi_get_link to find out the name of a child device for bioctl rather
than snoop scsi commands and copy it in an io path.

no functional change, but the code has one less XXX now.


# 1.129 14-Aug-2012 dlg

expose the max number of logical volumes the hardware supports as the width
of its scsibus. only advertise 1 lun on logical volumes instead of letting
the midlayer fix it up to 8.

give every target on the bus max_cmds openings. iopools means they will
properly share access to them.

this in particular is useful on skinny controllers which only advertise 31
command slots. if you have 16 volumes, theyll only get 1 opening each with
the old maths. this way round the ones that are busy will share the slots.

tested on a perc5 with two volumes and hard workloads.


# 1.128 14-Aug-2012 dlg

print the boards name (eg, perc 5/i) according to the firmware like mfii.

ok deraadt@


# 1.127 14-Aug-2012 dlg

move knowledge of the location of the inbound doorbell out of code in
transition_firmware into a member of the iop structures.

ok mikeb@ haesbaert@


# 1.126 13-Aug-2012 dlg

get rid of the last foo_lo and foo_hi bits i could find in the hardware
structures and use htole64 instead of htole32(addr >> 32); htole32(addr);

gets rid of "handy" stack variables to get the dva to 64bits.

sprinkle some more byte swaps for things that should have it.

tested on a perc5 (xscale)


# 1.125 13-Aug-2012 dlg

do appropriate bus_dmamapy_syncs around the pcq/completion ring.

tested on a perc5 (xscale)


# 1.124 13-Aug-2012 dlg

replace uint32_ts for hi and lo addresses in the mfi_init_ hardware
descriptors with single uint64_ts. theyre not some weird middle
endian thing. this makes the code more readable.

add some missing htole32s to the code while here.

tested on a perc5 (xscale).


# 1.123 11-Aug-2012 dlg

the producer/consumer values are used by the device, which is little
endian. do appropriate byteswapping for when the host cpu uses them.

tested on a perc5 (xscale) in an amd64.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.122 12-Jan-2012 dlg

add support for skinny variants.

from Alexey Suslikov
reviewed by marco


Revision tags: OPENBSD_5_0_BASE
# 1.121 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.120 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.119 09-Apr-2011 marco

add all 64 bit dma plumbing but stick with 32 for now by default.

ok deraadt


# 1.118 09-Apr-2011 marco

make sure the upper 32 bits are always written to instead of assuming it
is 0.

ok deraadt.


# 1.117 08-Apr-2011 marco

kill some stray spaces


# 1.116 08-Apr-2011 marco

rename wiat channel to something less than 8 chars.

prompted by deraadt


# 1.115 08-Apr-2011 marco

use dma_alloc for transient management commands.

prodded and ok deraadt


Revision tags: OPENBSD_4_9_BASE
# 1.114 30-Dec-2010 dlg

cut mfi over to using iopools.

this gets rid of NO_CCB, provides better scheduling of io between busy
logical volumes on the same controller, and makes the ioctl and sensor
paths more reliable.

this is the least intrusive version of this change i could come up with. it
only took 4 or 5 goes...

ok marco@
deraadt@ says this is a good time for this change.


# 1.113 24-Sep-2010 dlg

no use setting cmd in mfi_ioctl_setstate if you never use it.


# 1.112 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


# 1.111 29-Aug-2010 dlg

the scsi completion code thinks that if you dont get MFI_STAT_OK
back from the chip on a command then the command completely failed.
MFI_STAT_SCSI_DONE_WITH_ERROR really means the command completed
fine, but there's some sense data too. this tweaks the handling to
be more appropriate, as per the linux and solaris drivers.

timed out waiting for beck@
putting this in cos its obviously more correct than the current code.


Revision tags: OPENBSD_4_8_BASE
# 1.110 22-Jul-2010 matthew

SCSI HBA drivers are supposed to get their SCSI CDBs from xs->cmd, not
xs->cmdstore.

ok krw@ a while back (contingent upon testing), and deraadt@ says this
has been in snapshots for weeks now.


# 1.109 01-Jul-2010 matthew

Change scsibus(4)'s scsi_link array to an SLIST to save memory on
sparsely populated buses.

ok dlg@, krw@


# 1.108 30-Jun-2010 mk

Use SLIST for the ccb free list.

ok krw, discontent grunts from marco.


# 1.107 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.106 15-Jun-2010 dlg

dont pass the dev_t from the scsi device drivers into the midlayer for
ioctl requests, and dont pass the proc pointers around for any ioctl
requests in scsi land at all. neither were used, so trim the fat.

ok krw@ marco@


# 1.105 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.104 16-May-2010 nicm

Use a temporary variable for now to sidestep -Wbounded checking when
copying vendor[8]/product[16]/revision[4] out of struct scsi_inquiry_data
together with one memcopy.

ok krw


# 1.103 22-Apr-2010 oga

use BUS_DMA_ZERO on alloc instead of bzeroing after.

ok dlg@, marco@


# 1.102 10-Apr-2010 marco

grrr var names in protos


# 1.101 10-Apr-2010 marco

sprinkle some bus_dmamap_sync around frame access.
prompted by oga


# 1.100 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.99 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.98 04-Jan-2010 dlg

rename ccb_xs to ccb_cookie and change its type from a scsi_xfer * to a
void *. this lets us pass things other than scsi_xfers to ccb completion
handlers.


# 1.97 04-Jan-2010 dlg

protect the ccb free queue with a mutex rather than splbio


# 1.96 03-Jan-2010 chl

change M_WAITOK --> M_WAITOK|M_CANFAIL

with input from marco@

ok marco@ krw@

this was ok looooooooong time ago but lost in my mailbox


Revision tags: OPENBSD_4_6_BASE
# 1.95 30-Apr-2009 marco

Add READ(16) & WRITE(16) commands.
ok krw


# 1.94 29-Apr-2009 marco

MFI_D_IOCTL should be commented out. No binary change.


# 1.93 04-Apr-2009 dlg

scrub more fields in the ccb when returning them to the free list after
theyve been used, in particular the mfi header flags which has a bit
that specifies if a command should be completed via the interrupt path.

if we use a ccb during boot we set that bit, but it isnt necessarily
cleared by things that use it later on. this means a ccb we expected to
complete via an interrupt never actually generates an interrupt or appears
in the reply queue. this obviously stalls the io.


# 1.92 29-Mar-2009 marco

spello


# 1.91 29-Mar-2009 dlg

when we steal the SYNC CACHE command in mfi_scsi_cmd we still have to
mark the xs as done and call scsi_done for it rather than just returning
COMPLETE.


# 1.90 29-Mar-2009 dlg

fix a small race in mfi_mgmt between the checking of a ccbs completion and
the sleep waiting for the completion. it is possible to get the interrupt
completing the command just before the tsleep, which will never get a
wakeup because the interrupt with the wakeup has already happened.


Revision tags: OPENBSD_4_5_BASE
# 1.89 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.


# 1.88 28-Jan-2009 marco

Add support for next generation megaraid sas raid controllers.
From Jim Giannoules <gortag@gmail.com>


# 1.87 31-Oct-2008 marco

Generalize function to obtain all details to do bio stuff. This is in
preparation to start showing unsused disks which will require all this
information to do the math.

While at it fix a size of hotspare volume bug.


# 1.86 30-Oct-2008 marco

Fix bug that when there are no volumes but there are hot spares it would
no show the hotspares.


# 1.85 28-Oct-2008 marco

Fix output when reporting on multivolume disk groups.

Reported by mitja@muzenic.net


# 1.84 27-Oct-2008 marco

Move some include stuff around


# 1.83 26-Oct-2008 marco

Space


# 1.82 23-Oct-2008 marco

Fix PR5645
ok dlg
tested beck and others


# 1.81 25-Sep-2008 krw

Initialize 'ssc' to NULL since we test it later. Shouldn't ever be
NULL at the point of test unless the device list is confused, but
be consistantly paranoid if we're going to be paranoid.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.80 16-Feb-2008 krw

Return NO_CCB and not TRY_AGAIN_LATER when running out of ccb's.
Eliminates 'not queued' errors reported on the mailing lists.

Tested by Michael (belenus at bsdmail dot de).

ok marco@


# 1.79 11-Feb-2008 dlg

add support for the mfi controllers with the ppc iops, aka, LSI SAS1078 or
Dell PERC6.

committed off a machine booting and rooting off a perc6. tested on a perc5
by marco@
ok marco@


# 1.78 26-Jan-2008 brad

Set the return value instead of returning right away so that the DMA
memory is actually synched.

ok dlg@


# 1.77 26-Jan-2008 dlg

sync dma mem back to the cpu on poll failure.

from mickey via pr5714


# 1.76 26-Jan-2008 dlg

despatch -> dispatch

disparate spellink fix from mickey


# 1.75 05-Nov-2007 krw

More scsi_done() at SPLBIO.


# 1.74 27-Sep-2007 chl

M_ZERO changes

ok dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.73 24-Jun-2007 dlg

rework sensor tasks to use the kernels generic workq rather than a special
kernel thread of its own. the api has changed (which will be fixed in the
manpage shortly) so all the users of sensor tasks that i can find have
been fixed too.

noone tested, so its going in to force people to run with it.
"put it in" deraadt@


# 1.72 29-May-2007 todd

sprinkle some SMALL_KERNEL to permit bio/softraid to run on boot media
ok marco@ then suggested deraadt@


# 1.71 22-Mar-2007 deraadt

split userland & kernel struct sensor/sensordev so that the addition
of new fields in the future is less disruptive. This is done similar
to how struct proc is handled for ps(1). ok jmc (man page changes)
tested fkr simon, and more suggestions from millert


Revision tags: OPENBSD_4_1_BASE
# 1.70 14-Feb-2007 dlg

bus_space does byte swapping to cope with host endianness for us, so remove
an unnecessary htole32().


# 1.69 13-Feb-2007 marco

Fix subtle x ? y : z bug when calling mfi_create_sgl. This worked because
during runtime the bug condition does not happen.

ok krw joris


# 1.68 08-Feb-2007 ray

Remove double semicolons.

From Pierre Riteau <pierre dot riteau at free dot fr>.

OK marco@.


# 1.67 23-Dec-2006 deraadt

adapt to new two-level sensor api; Constantine A. Murenin


# 1.66 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.65 31-Aug-2006 marco

Add sensor thread for individual sd devices.

tested dlg
ok dlg deraadt


# 1.64 30-Aug-2006 dlg

when determining the size of the volumes and disks we want how many
bytes each of them has, not the number of kilobytes. this solves the
"why am i dividing by 2" question. the answer is "you dont, you multiply
by 512".


# 1.63 28-Jul-2006 brad

make dmesg printing look a little bit nicer.


# 1.62 19-Jun-2006 marco

Factor for disk size is /2. Odd but tested on all mfis I have.


# 1.61 19-Jun-2006 miod

Everytime one forgets an argument in a printf-like function call, God kills
a kitten. Commiters, please think of the kittens when working on code.


# 1.60 19-Jun-2006 marco

Make a BGI (Back Ground Init) a scrub instead of rebuild.


# 1.59 19-Jun-2006 marco

Add hot spare support.


# 1.58 26-May-2006 marco

Add blinking for disks.


# 1.57 25-May-2006 marco

Move a int i; to top of function so that it compiles on non c99 compilers.
Pointed out by miod@

The enclosure id modifier didn't reflect reality so move it back to whatever
the raid card uses.


# 1.56 25-May-2006 marco

And add time and percentage to builds and check consistencies.


# 1.55 25-May-2006 marco

Add last bit of physcal disk stuff.
Remove bogus memset.
Hotspares still don't work.


# 1.54 25-May-2006 marco

Add physical device and read config structures.
Add initial part of BIOCDISK


# 1.53 23-May-2006 deraadt

commited with unused variable


# 1.52 23-May-2006 marco

Remove some debug cruft.


# 1.51 23-May-2006 marco

Add first half of physical disk data for bio.


# 1.50 22-May-2006 marco

Add support for raid 50 and 10 in bio.


# 1.49 22-May-2006 marco

Add mail box to mfi_mgmt to handle sub commands more gracefully.
Remove some debug crud that snuck in the TEST_UNIT_READY case.
Finish other half of BIOCVOL primitive.
Add several structures to fill out the BIOCVOL primitive.


# 1.48 22-May-2006 marco

Add first half of BIOCVOL primitive.


# 1.47 21-May-2006 marco

Do a giant flush of disk and raid-card memory when SYNCHONIZE_CACHE is called.


# 1.46 21-May-2006 marco

pretty up some debug statements.


# 1.45 21-May-2006 marco

Add bio alarm function.
Redo mfi_mgmt to deal with zero data commands.


# 1.44 21-May-2006 marco

Add generic management function.
Redo ccb_state flags so that we can actually sleep on it.
Redo mfi_get_info to use new mgmt function.
Add rw_locks for mgmt interface.
Make BIOCINQ dynamic.


# 1.43 21-May-2006 marco

Oops, helps to use the right structure field.
Use actual nr of physical disks present.


# 1.42 21-May-2006 marco

Add first BIOCINQ primitive.


# 1.41 18-May-2006 marco

Remove some debug cruft and pretty up some debug messages.


# 1.40 18-May-2006 marco

Kill splbio/splx in the interrupt handler.


# 1.39 18-May-2006 marco

And we have lift off! Was able to create a filesystem and write to the
filesystem.

Collapse both completion routines into one.
Fixup scsi error reporting in the completion routine.


# 1.38 17-May-2006 marco

Add completion routines.
Fix some bugs inside the interrupt handler.


# 1.37 17-May-2006 marco

Add mfi_get_info to obtain all kinds of fun information from the fw.
Print out whole info structure when debug is enabled.
Add a nice print with useful info during attach.


# 1.36 17-May-2006 marco

Refactor scsi path so that we can have a single sgl function for io and non-io
traffic.
Redo parameters on functions that were passing too many parameters around.


# 1.35 16-May-2006 marco

Nuke some { }


# 1.34 16-May-2006 marco

Move !xs->data case into mfi_start_xs.
Return proper sense data when a polling command fails.


# 1.33 16-May-2006 marco

Fix some more htole32 screw-ups.
Colapse all little SCSI functions into a single generic one.
Fix a bug in the SGE calculation.

This brings the driver up to post:
mfi0 at pci12 dev 14 function 0 "Dell PERC SAS" rev 0x00: Dell PERC 5/e irq 5
scsibus3 at mfi0: 2 targets
sd1 at scsibus3 targ 0 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd1: 237824MB, 237824 cyl, 64 head, 32 sec, 512 bytes/sec, 487063552 sec total
sd2 at scsibus3 targ 1 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd2: 34176MB, 34176 cyl, 64 head, 32 sec, 512 bytes/sec, 69992448 sec total


# 1.32 16-May-2006 marco

Fix some htole32 I missed.
Sprinkle more debug.


# 1.31 16-May-2006 marco

Add READ CAPACITY.


# 1.30 16-May-2006 marco

Oops PREREAD not PREWRITE.


# 1.29 16-May-2006 marco

Add TUR and make it send it directly to firmware.
Sprinkle some extra debug.


# 1.28 15-May-2006 marco

Clear all relevant ccb fields when mfi_put_ccb frees a ccb.


# 1.27 15-May-2006 marco

Oops don't send command twice to firmware when polling.


# 1.26 15-May-2006 marco

Add INQUIRY command.
Add sgl magic.


# 1.25 10-May-2006 marco

Add some airplane code.

add bio hooks.
add scsi entry point for io.


# 1.24 26-Apr-2006 marco

Fix some debug prints.


# 1.23 21-Apr-2006 marco

typo


# 1.22 21-Apr-2006 marco

Add mfi_poll and use the new shiny function to setup all the hardware queues.
Lots of ideas from the FreeBSD driver.


# 1.21 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.20 20-Apr-2006 dlg

marco hates typedefs as much as i do, so he asked me to clean mfi like i
just did with ami. this gets rid of the typedef for the ccb lists.

also uses TAILQ_FIRST to get ccbs off the freelist. this is a proactive
fix for a lint teary.


# 1.19 18-Apr-2006 marco

It helps to initialize a queue before usage.


# 1.18 18-Apr-2006 marco

Actually add ccbs to the queue.
Fix the error path for mfi_init_ccb.
Alter dmamap for io.


# 1.17 17-Apr-2006 marco

Sprinkle more debug. Remove 64 byte boundary; it doesn't seem to like it.
Hack around 64 byte boundary for the frames for now.


# 1.16 17-Apr-2006 marco

Setup ccbs and clean up ccb structure.


# 1.15 16-Apr-2006 marco

Oops, make mfi_allocmem always use 64 byte boundaries since frames have to
have that alignment. It doesn't matter for the other consumers of the
function.


# 1.14 16-Apr-2006 marco

Add frame memory and sglist allocation.


# 1.13 16-Apr-2006 marco

Make memory access use macro.


# 1.12 16-Apr-2006 marco

typo


# 1.11 16-Apr-2006 marco

Add get and put ccb functions. Shuffle some more definitions.


# 1.10 16-Apr-2006 marco

Nicer print when context is invalid.


# 1.9 16-Apr-2006 marco

Shuffle some #defines.
Fix comments.
Add human readable enable intrrupt #define.


# 1.8 16-Apr-2006 marco

Add interrupt handler. Idea borrowed from FreeBSD since it is much nicer
than the Linux one.


# 1.7 07-Apr-2006 marco

Replace bus_space functions with generic ones that do barriers.


# 1.6 07-Apr-2006 marco

Add memory allocator functions.


# 1.5 07-Apr-2006 marco

Print state in debug. Change return vales to 1 instead of ENXIO.


# 1.4 07-Apr-2006 marco

Make a better debug mechanism.


# 1.3 07-Apr-2006 marco

Enable mfi_transition_fw() original code from FreeBSD.


# 1.2 06-Apr-2006 marco

Add fw transition logic.


# 1.1 06-Apr-2006 marco

Add skeleton driver for MegaRAID SAS.


# 1.174 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.173 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.172 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.171 31-Dec-2019 mpi

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

ok kn@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.170 05-Mar-2019 jmatthew

apply background init progress fix from r1.59 of mfii.c
(reverting most of r1.60 of mfi.c, oddly enough)

ok dlg@
tested on a SAS2008 (perc h310)


Revision tags: OPENBSD_6_4_BASE
# 1.169 14-Aug-2018 jmatthew

return ENOTTY rather than EINVAL to indicate an ioctl hasn't been handled

ok dlg@ deraadt@ kettenis@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.168 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.167 02-Feb-2017 dlg

copy the mbox into the dcmd struct, not the pointer to the mbox.

makes bioctl work on mfi(4) again.

while here memset a few mboxes before using them.

bioctl breakage reported by jason george


# 1.166 23-Jan-2017 dlg

represent the mbox layout with union instead of an array of bytes.

memcpying uint16_ts into inconsistently addressed offsets is hard
to read, and this makes future work easier to implement.

tested on mfi(4) and mfii(4)


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.165 09-Sep-2015 deraadt

sizes for free(); ok sthen


Revision tags: OPENBSD_5_8_BASE
# 1.164 29-May-2015 uebayasi

Initial addition of ``Patrol Read'' support in bio(4), biocto(8), and
mfi(4). Based on FreeBSD, but done without mfiutil(8).

OK deraadt@


# 1.163 18-May-2015 mikeb

Prevent splassert from firing during sd_flush which runs "cold"

While mfi(4) should pass SCSI transfer flags (e.g. SCSI_POLL and
SCSI_NOSLEEP) down to the management function, make it at least
use "cold" consistently for now.

ok dlg


# 1.162 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.161 08-Mar-2015 dlg

properly set sgl related flags on skinny controllers. this fixes
io against physical disks on my dell perc h310s. logical disks still
work fine.

ok deraadt@ yasuoka@


# 1.160 08-Feb-2015 yasuoka

Fix mfi ioctl to set drive state properly.
diff from Tsubai Masanari

test dlg jmatthew
ok dlg


# 1.159 09-Jan-2015 yasuoka

Add support DIOC{G,S}CACHE to mfi(4). Cache of disk on mfi(4) will
be enabled by default. Also if the controller doesn't have any RAM,
the cache on the physical disk will be enabled.

discuss with jsg tsubai
ok dlg


# 1.158 19-Dec-2014 deraadt

another handful of bcopy -> memcpy because there is no overlap


# 1.157 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.156 09-Sep-2014 dlg

mark the interrupt handler mpsafe, and give up biglock in the scsi cmd
submission paths. take biglock again when calling back into the scsi
stack.

tested on a variety of cards here, including the skinny mfis on the
firewall next to mpsafe myx.


# 1.155 15-Aug-2014 yasuoka

Create a function which loads sgd in the mfi_iop_ops struct so that skinny
adapters can use "IEEE sgl".

tested dlg yasuoka
ok dlg jsg


Revision tags: OPENBSD_5_6_BASE
# 1.154 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.153 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.152 04-May-2014 sf

format string fixes for bus_addr_t and bus_size_t

bus_addr_t and bus_size_t are u_long everywhere

ok kettenis@


Revision tags: OPENBSD_5_5_BASE
# 1.151 20-Feb-2014 kettenis

revert previous commit; didn't intend to commit those bits


# 1.150 20-Feb-2014 kettenis

Avoid printing the "nvram corrupt" message for onboard 2200s found on Sun
hardware.

ok dlg@, jmatthew@


# 1.149 04-Dec-2013 dlg

mfi_refresh_sensors calls mfi_ioctl_vol which calls mfi_bio_getitall, which
replaces pointers in the softc and all sorts of fun stuff. this protects
the call to bio_getitall with the sc_lock the ioctl path uses, so we dont
get panics like those reported on bugs@ recently.

ok deraadt@


# 1.148 23-Oct-2013 kettenis

Add support for displaying the cache write policy of RAID volumes to bioctl(8)
and make mfi(4) pass up the necessary information. Adding support for other
RAID controllers is left as an excercise to the reader.

ok deraadt@


# 1.147 09-Oct-2013 jmatthew

Include the 'state of health' field in the bbu ok sensor value.
The dell perc 6/i sets this to zero (meaning bad) when it
decides the battery doesn't have enough capacity for it to
allow write back mode, but doesn't set any of the other flags
to tell us why.

ok dlg@, tested by sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.146 18-May-2013 jmc

enw->new in comment;
spotted by krw, missed by jsg, and forwarded From: Alexey Suslikov


# 1.145 08-May-2013 jsg

fix some leaks in error paths
ok fgsch@ krw@ kettenis@


# 1.144 03-May-2013 dlg

break out the battery status into excruciating detail. makes it harder for
$VENDOR to complain about a lack of diagnostic material from their crappy
mgmt tools if you're not running an operating system they support.


# 1.143 02-May-2013 dlg

always attach the battery sensor if the adapter lets us query it.
newly replaced batteries dont show up immediately.


# 1.142 01-May-2013 dlg

provide a sensor for the battery backup unit (bbu) on mfi boards that
support it.

now i can tell (a bit better) why io might be slow on some of my boxes.


# 1.141 01-May-2013 dlg

dont need to walk alldevs during sensor creation looking for the logical
disk scsibus when we record that in mfi_attach.

also happens to get rid of a logic error that let it come out of the loop
on alldevs with a reference to something that wasnt the logical disk
scsibus and use that.


# 1.140 30-Apr-2013 dlg

use MR_DCMD consistently. some MD_DCMD was in there somehow.


# 1.139 07-Apr-2013 dlg

david imhoff points out that the error handling in mfi_init_ccb gets the
index to which ccb to free wrong.

this takes the logic from mpi/mpii/mfii which pulls the ready ccbs off
the free list rather than rely on the current index from the for loop
that we failed inside of.

thanks to david for finding this out.


Revision tags: OPENBSD_5_3_BASE
# 1.138 12-Sep-2012 haesbaert

Make sure we don't sleep on autoconf.

ok mikeb


# 1.137 17-Aug-2012 dlg

add support for "physical devices" on skinny controllers.

these controllers let you specify disks that should be accessed directly
rather than be part of logical volumes. apparently you can plug in things
like tape drives too.

anyway, physical devices are exposed via a separate scsibus attached to
mfi.

ok mikeb@


# 1.136 16-Aug-2012 dlg

fix mfi_poll by having it do delays between loops, and breaking on
timeouts. how embarrassment.

implement mfi_exec for doing sync executions of commands in process
contexts and cut mfi_mgmt over to it.


# 1.135 16-Aug-2012 dlg

rework mfi_poll so it will do all the completions on a ccb including
calling the done handler.

this makes it consistently complete scsi io with all the proper error
checking.


# 1.134 16-Aug-2012 dlg

stop passing mfi_softc around as a member of the ccb, consistently give it
as the first argument to functions. like mfii.


# 1.133 16-Aug-2012 dlg

scrub ccbs when we're about to use them, not when we put them back
on the free list. ccbs can be reused, so we dont want old state screwing up
new commands.


# 1.132 16-Aug-2012 dlg

move the dma syncs for the ccb data into ccb_done, so we can do it once
rather than put the code everywhere.


# 1.131 16-Aug-2012 dlg

fix up the dma sync for the command frame in mfi_done.


# 1.130 14-Aug-2012 dlg

use scsi_get_link to find out the name of a child device for bioctl rather
than snoop scsi commands and copy it in an io path.

no functional change, but the code has one less XXX now.


# 1.129 14-Aug-2012 dlg

expose the max number of logical volumes the hardware supports as the width
of its scsibus. only advertise 1 lun on logical volumes instead of letting
the midlayer fix it up to 8.

give every target on the bus max_cmds openings. iopools means they will
properly share access to them.

this in particular is useful on skinny controllers which only advertise 31
command slots. if you have 16 volumes, theyll only get 1 opening each with
the old maths. this way round the ones that are busy will share the slots.

tested on a perc5 with two volumes and hard workloads.


# 1.128 14-Aug-2012 dlg

print the boards name (eg, perc 5/i) according to the firmware like mfii.

ok deraadt@


# 1.127 14-Aug-2012 dlg

move knowledge of the location of the inbound doorbell out of code in
transition_firmware into a member of the iop structures.

ok mikeb@ haesbaert@


# 1.126 13-Aug-2012 dlg

get rid of the last foo_lo and foo_hi bits i could find in the hardware
structures and use htole64 instead of htole32(addr >> 32); htole32(addr);

gets rid of "handy" stack variables to get the dva to 64bits.

sprinkle some more byte swaps for things that should have it.

tested on a perc5 (xscale)


# 1.125 13-Aug-2012 dlg

do appropriate bus_dmamapy_syncs around the pcq/completion ring.

tested on a perc5 (xscale)


# 1.124 13-Aug-2012 dlg

replace uint32_ts for hi and lo addresses in the mfi_init_ hardware
descriptors with single uint64_ts. theyre not some weird middle
endian thing. this makes the code more readable.

add some missing htole32s to the code while here.

tested on a perc5 (xscale).


# 1.123 11-Aug-2012 dlg

the producer/consumer values are used by the device, which is little
endian. do appropriate byteswapping for when the host cpu uses them.

tested on a perc5 (xscale) in an amd64.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.122 12-Jan-2012 dlg

add support for skinny variants.

from Alexey Suslikov
reviewed by marco


Revision tags: OPENBSD_5_0_BASE
# 1.121 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.120 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.119 09-Apr-2011 marco

add all 64 bit dma plumbing but stick with 32 for now by default.

ok deraadt


# 1.118 09-Apr-2011 marco

make sure the upper 32 bits are always written to instead of assuming it
is 0.

ok deraadt.


# 1.117 08-Apr-2011 marco

kill some stray spaces


# 1.116 08-Apr-2011 marco

rename wiat channel to something less than 8 chars.

prompted by deraadt


# 1.115 08-Apr-2011 marco

use dma_alloc for transient management commands.

prodded and ok deraadt


Revision tags: OPENBSD_4_9_BASE
# 1.114 30-Dec-2010 dlg

cut mfi over to using iopools.

this gets rid of NO_CCB, provides better scheduling of io between busy
logical volumes on the same controller, and makes the ioctl and sensor
paths more reliable.

this is the least intrusive version of this change i could come up with. it
only took 4 or 5 goes...

ok marco@
deraadt@ says this is a good time for this change.


# 1.113 24-Sep-2010 dlg

no use setting cmd in mfi_ioctl_setstate if you never use it.


# 1.112 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


# 1.111 29-Aug-2010 dlg

the scsi completion code thinks that if you dont get MFI_STAT_OK
back from the chip on a command then the command completely failed.
MFI_STAT_SCSI_DONE_WITH_ERROR really means the command completed
fine, but there's some sense data too. this tweaks the handling to
be more appropriate, as per the linux and solaris drivers.

timed out waiting for beck@
putting this in cos its obviously more correct than the current code.


Revision tags: OPENBSD_4_8_BASE
# 1.110 22-Jul-2010 matthew

SCSI HBA drivers are supposed to get their SCSI CDBs from xs->cmd, not
xs->cmdstore.

ok krw@ a while back (contingent upon testing), and deraadt@ says this
has been in snapshots for weeks now.


# 1.109 01-Jul-2010 matthew

Change scsibus(4)'s scsi_link array to an SLIST to save memory on
sparsely populated buses.

ok dlg@, krw@


# 1.108 30-Jun-2010 mk

Use SLIST for the ccb free list.

ok krw, discontent grunts from marco.


# 1.107 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.106 15-Jun-2010 dlg

dont pass the dev_t from the scsi device drivers into the midlayer for
ioctl requests, and dont pass the proc pointers around for any ioctl
requests in scsi land at all. neither were used, so trim the fat.

ok krw@ marco@


# 1.105 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.104 16-May-2010 nicm

Use a temporary variable for now to sidestep -Wbounded checking when
copying vendor[8]/product[16]/revision[4] out of struct scsi_inquiry_data
together with one memcopy.

ok krw


# 1.103 22-Apr-2010 oga

use BUS_DMA_ZERO on alloc instead of bzeroing after.

ok dlg@, marco@


# 1.102 10-Apr-2010 marco

grrr var names in protos


# 1.101 10-Apr-2010 marco

sprinkle some bus_dmamap_sync around frame access.
prompted by oga


# 1.100 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.99 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.98 04-Jan-2010 dlg

rename ccb_xs to ccb_cookie and change its type from a scsi_xfer * to a
void *. this lets us pass things other than scsi_xfers to ccb completion
handlers.


# 1.97 04-Jan-2010 dlg

protect the ccb free queue with a mutex rather than splbio


# 1.96 03-Jan-2010 chl

change M_WAITOK --> M_WAITOK|M_CANFAIL

with input from marco@

ok marco@ krw@

this was ok looooooooong time ago but lost in my mailbox


Revision tags: OPENBSD_4_6_BASE
# 1.95 30-Apr-2009 marco

Add READ(16) & WRITE(16) commands.
ok krw


# 1.94 29-Apr-2009 marco

MFI_D_IOCTL should be commented out. No binary change.


# 1.93 04-Apr-2009 dlg

scrub more fields in the ccb when returning them to the free list after
theyve been used, in particular the mfi header flags which has a bit
that specifies if a command should be completed via the interrupt path.

if we use a ccb during boot we set that bit, but it isnt necessarily
cleared by things that use it later on. this means a ccb we expected to
complete via an interrupt never actually generates an interrupt or appears
in the reply queue. this obviously stalls the io.


# 1.92 29-Mar-2009 marco

spello


# 1.91 29-Mar-2009 dlg

when we steal the SYNC CACHE command in mfi_scsi_cmd we still have to
mark the xs as done and call scsi_done for it rather than just returning
COMPLETE.


# 1.90 29-Mar-2009 dlg

fix a small race in mfi_mgmt between the checking of a ccbs completion and
the sleep waiting for the completion. it is possible to get the interrupt
completing the command just before the tsleep, which will never get a
wakeup because the interrupt with the wakeup has already happened.


Revision tags: OPENBSD_4_5_BASE
# 1.89 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.


# 1.88 28-Jan-2009 marco

Add support for next generation megaraid sas raid controllers.
From Jim Giannoules <gortag@gmail.com>


# 1.87 31-Oct-2008 marco

Generalize function to obtain all details to do bio stuff. This is in
preparation to start showing unsused disks which will require all this
information to do the math.

While at it fix a size of hotspare volume bug.


# 1.86 30-Oct-2008 marco

Fix bug that when there are no volumes but there are hot spares it would
no show the hotspares.


# 1.85 28-Oct-2008 marco

Fix output when reporting on multivolume disk groups.

Reported by mitja@muzenic.net


# 1.84 27-Oct-2008 marco

Move some include stuff around


# 1.83 26-Oct-2008 marco

Space


# 1.82 23-Oct-2008 marco

Fix PR5645
ok dlg
tested beck and others


# 1.81 25-Sep-2008 krw

Initialize 'ssc' to NULL since we test it later. Shouldn't ever be
NULL at the point of test unless the device list is confused, but
be consistantly paranoid if we're going to be paranoid.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.80 16-Feb-2008 krw

Return NO_CCB and not TRY_AGAIN_LATER when running out of ccb's.
Eliminates 'not queued' errors reported on the mailing lists.

Tested by Michael (belenus at bsdmail dot de).

ok marco@


# 1.79 11-Feb-2008 dlg

add support for the mfi controllers with the ppc iops, aka, LSI SAS1078 or
Dell PERC6.

committed off a machine booting and rooting off a perc6. tested on a perc5
by marco@
ok marco@


# 1.78 26-Jan-2008 brad

Set the return value instead of returning right away so that the DMA
memory is actually synched.

ok dlg@


# 1.77 26-Jan-2008 dlg

sync dma mem back to the cpu on poll failure.

from mickey via pr5714


# 1.76 26-Jan-2008 dlg

despatch -> dispatch

disparate spellink fix from mickey


# 1.75 05-Nov-2007 krw

More scsi_done() at SPLBIO.


# 1.74 27-Sep-2007 chl

M_ZERO changes

ok dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.73 24-Jun-2007 dlg

rework sensor tasks to use the kernels generic workq rather than a special
kernel thread of its own. the api has changed (which will be fixed in the
manpage shortly) so all the users of sensor tasks that i can find have
been fixed too.

noone tested, so its going in to force people to run with it.
"put it in" deraadt@


# 1.72 29-May-2007 todd

sprinkle some SMALL_KERNEL to permit bio/softraid to run on boot media
ok marco@ then suggested deraadt@


# 1.71 22-Mar-2007 deraadt

split userland & kernel struct sensor/sensordev so that the addition
of new fields in the future is less disruptive. This is done similar
to how struct proc is handled for ps(1). ok jmc (man page changes)
tested fkr simon, and more suggestions from millert


Revision tags: OPENBSD_4_1_BASE
# 1.70 14-Feb-2007 dlg

bus_space does byte swapping to cope with host endianness for us, so remove
an unnecessary htole32().


# 1.69 13-Feb-2007 marco

Fix subtle x ? y : z bug when calling mfi_create_sgl. This worked because
during runtime the bug condition does not happen.

ok krw joris


# 1.68 08-Feb-2007 ray

Remove double semicolons.

From Pierre Riteau <pierre dot riteau at free dot fr>.

OK marco@.


# 1.67 23-Dec-2006 deraadt

adapt to new two-level sensor api; Constantine A. Murenin


# 1.66 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.65 31-Aug-2006 marco

Add sensor thread for individual sd devices.

tested dlg
ok dlg deraadt


# 1.64 30-Aug-2006 dlg

when determining the size of the volumes and disks we want how many
bytes each of them has, not the number of kilobytes. this solves the
"why am i dividing by 2" question. the answer is "you dont, you multiply
by 512".


# 1.63 28-Jul-2006 brad

make dmesg printing look a little bit nicer.


# 1.62 19-Jun-2006 marco

Factor for disk size is /2. Odd but tested on all mfis I have.


# 1.61 19-Jun-2006 miod

Everytime one forgets an argument in a printf-like function call, God kills
a kitten. Commiters, please think of the kittens when working on code.


# 1.60 19-Jun-2006 marco

Make a BGI (Back Ground Init) a scrub instead of rebuild.


# 1.59 19-Jun-2006 marco

Add hot spare support.


# 1.58 26-May-2006 marco

Add blinking for disks.


# 1.57 25-May-2006 marco

Move a int i; to top of function so that it compiles on non c99 compilers.
Pointed out by miod@

The enclosure id modifier didn't reflect reality so move it back to whatever
the raid card uses.


# 1.56 25-May-2006 marco

And add time and percentage to builds and check consistencies.


# 1.55 25-May-2006 marco

Add last bit of physcal disk stuff.
Remove bogus memset.
Hotspares still don't work.


# 1.54 25-May-2006 marco

Add physical device and read config structures.
Add initial part of BIOCDISK


# 1.53 23-May-2006 deraadt

commited with unused variable


# 1.52 23-May-2006 marco

Remove some debug cruft.


# 1.51 23-May-2006 marco

Add first half of physical disk data for bio.


# 1.50 22-May-2006 marco

Add support for raid 50 and 10 in bio.


# 1.49 22-May-2006 marco

Add mail box to mfi_mgmt to handle sub commands more gracefully.
Remove some debug crud that snuck in the TEST_UNIT_READY case.
Finish other half of BIOCVOL primitive.
Add several structures to fill out the BIOCVOL primitive.


# 1.48 22-May-2006 marco

Add first half of BIOCVOL primitive.


# 1.47 21-May-2006 marco

Do a giant flush of disk and raid-card memory when SYNCHONIZE_CACHE is called.


# 1.46 21-May-2006 marco

pretty up some debug statements.


# 1.45 21-May-2006 marco

Add bio alarm function.
Redo mfi_mgmt to deal with zero data commands.


# 1.44 21-May-2006 marco

Add generic management function.
Redo ccb_state flags so that we can actually sleep on it.
Redo mfi_get_info to use new mgmt function.
Add rw_locks for mgmt interface.
Make BIOCINQ dynamic.


# 1.43 21-May-2006 marco

Oops, helps to use the right structure field.
Use actual nr of physical disks present.


# 1.42 21-May-2006 marco

Add first BIOCINQ primitive.


# 1.41 18-May-2006 marco

Remove some debug cruft and pretty up some debug messages.


# 1.40 18-May-2006 marco

Kill splbio/splx in the interrupt handler.


# 1.39 18-May-2006 marco

And we have lift off! Was able to create a filesystem and write to the
filesystem.

Collapse both completion routines into one.
Fixup scsi error reporting in the completion routine.


# 1.38 17-May-2006 marco

Add completion routines.
Fix some bugs inside the interrupt handler.


# 1.37 17-May-2006 marco

Add mfi_get_info to obtain all kinds of fun information from the fw.
Print out whole info structure when debug is enabled.
Add a nice print with useful info during attach.


# 1.36 17-May-2006 marco

Refactor scsi path so that we can have a single sgl function for io and non-io
traffic.
Redo parameters on functions that were passing too many parameters around.


# 1.35 16-May-2006 marco

Nuke some { }


# 1.34 16-May-2006 marco

Move !xs->data case into mfi_start_xs.
Return proper sense data when a polling command fails.


# 1.33 16-May-2006 marco

Fix some more htole32 screw-ups.
Colapse all little SCSI functions into a single generic one.
Fix a bug in the SGE calculation.

This brings the driver up to post:
mfi0 at pci12 dev 14 function 0 "Dell PERC SAS" rev 0x00: Dell PERC 5/e irq 5
scsibus3 at mfi0: 2 targets
sd1 at scsibus3 targ 0 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd1: 237824MB, 237824 cyl, 64 head, 32 sec, 512 bytes/sec, 487063552 sec total
sd2 at scsibus3 targ 1 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd2: 34176MB, 34176 cyl, 64 head, 32 sec, 512 bytes/sec, 69992448 sec total


# 1.32 16-May-2006 marco

Fix some htole32 I missed.
Sprinkle more debug.


# 1.31 16-May-2006 marco

Add READ CAPACITY.


# 1.30 16-May-2006 marco

Oops PREREAD not PREWRITE.


# 1.29 16-May-2006 marco

Add TUR and make it send it directly to firmware.
Sprinkle some extra debug.


# 1.28 15-May-2006 marco

Clear all relevant ccb fields when mfi_put_ccb frees a ccb.


# 1.27 15-May-2006 marco

Oops don't send command twice to firmware when polling.


# 1.26 15-May-2006 marco

Add INQUIRY command.
Add sgl magic.


# 1.25 10-May-2006 marco

Add some airplane code.

add bio hooks.
add scsi entry point for io.


# 1.24 26-Apr-2006 marco

Fix some debug prints.


# 1.23 21-Apr-2006 marco

typo


# 1.22 21-Apr-2006 marco

Add mfi_poll and use the new shiny function to setup all the hardware queues.
Lots of ideas from the FreeBSD driver.


# 1.21 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.20 20-Apr-2006 dlg

marco hates typedefs as much as i do, so he asked me to clean mfi like i
just did with ami. this gets rid of the typedef for the ccb lists.

also uses TAILQ_FIRST to get ccbs off the freelist. this is a proactive
fix for a lint teary.


# 1.19 18-Apr-2006 marco

It helps to initialize a queue before usage.


# 1.18 18-Apr-2006 marco

Actually add ccbs to the queue.
Fix the error path for mfi_init_ccb.
Alter dmamap for io.


# 1.17 17-Apr-2006 marco

Sprinkle more debug. Remove 64 byte boundary; it doesn't seem to like it.
Hack around 64 byte boundary for the frames for now.


# 1.16 17-Apr-2006 marco

Setup ccbs and clean up ccb structure.


# 1.15 16-Apr-2006 marco

Oops, make mfi_allocmem always use 64 byte boundaries since frames have to
have that alignment. It doesn't matter for the other consumers of the
function.


# 1.14 16-Apr-2006 marco

Add frame memory and sglist allocation.


# 1.13 16-Apr-2006 marco

Make memory access use macro.


# 1.12 16-Apr-2006 marco

typo


# 1.11 16-Apr-2006 marco

Add get and put ccb functions. Shuffle some more definitions.


# 1.10 16-Apr-2006 marco

Nicer print when context is invalid.


# 1.9 16-Apr-2006 marco

Shuffle some #defines.
Fix comments.
Add human readable enable intrrupt #define.


# 1.8 16-Apr-2006 marco

Add interrupt handler. Idea borrowed from FreeBSD since it is much nicer
than the Linux one.


# 1.7 07-Apr-2006 marco

Replace bus_space functions with generic ones that do barriers.


# 1.6 07-Apr-2006 marco

Add memory allocator functions.


# 1.5 07-Apr-2006 marco

Print state in debug. Change return vales to 1 instead of ENXIO.


# 1.4 07-Apr-2006 marco

Make a better debug mechanism.


# 1.3 07-Apr-2006 marco

Enable mfi_transition_fw() original code from FreeBSD.


# 1.2 06-Apr-2006 marco

Add fw transition logic.


# 1.1 06-Apr-2006 marco

Add skeleton driver for MegaRAID SAS.


# 1.172 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.171 31-Dec-2019 mpi

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

ok kn@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.170 05-Mar-2019 jmatthew

apply background init progress fix from r1.59 of mfii.c
(reverting most of r1.60 of mfi.c, oddly enough)

ok dlg@
tested on a SAS2008 (perc h310)


Revision tags: OPENBSD_6_4_BASE
# 1.169 14-Aug-2018 jmatthew

return ENOTTY rather than EINVAL to indicate an ioctl hasn't been handled

ok dlg@ deraadt@ kettenis@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.168 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.167 02-Feb-2017 dlg

copy the mbox into the dcmd struct, not the pointer to the mbox.

makes bioctl work on mfi(4) again.

while here memset a few mboxes before using them.

bioctl breakage reported by jason george


# 1.166 23-Jan-2017 dlg

represent the mbox layout with union instead of an array of bytes.

memcpying uint16_ts into inconsistently addressed offsets is hard
to read, and this makes future work easier to implement.

tested on mfi(4) and mfii(4)


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.165 09-Sep-2015 deraadt

sizes for free(); ok sthen


Revision tags: OPENBSD_5_8_BASE
# 1.164 29-May-2015 uebayasi

Initial addition of ``Patrol Read'' support in bio(4), biocto(8), and
mfi(4). Based on FreeBSD, but done without mfiutil(8).

OK deraadt@


# 1.163 18-May-2015 mikeb

Prevent splassert from firing during sd_flush which runs "cold"

While mfi(4) should pass SCSI transfer flags (e.g. SCSI_POLL and
SCSI_NOSLEEP) down to the management function, make it at least
use "cold" consistently for now.

ok dlg


# 1.162 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.161 08-Mar-2015 dlg

properly set sgl related flags on skinny controllers. this fixes
io against physical disks on my dell perc h310s. logical disks still
work fine.

ok deraadt@ yasuoka@


# 1.160 08-Feb-2015 yasuoka

Fix mfi ioctl to set drive state properly.
diff from Tsubai Masanari

test dlg jmatthew
ok dlg


# 1.159 09-Jan-2015 yasuoka

Add support DIOC{G,S}CACHE to mfi(4). Cache of disk on mfi(4) will
be enabled by default. Also if the controller doesn't have any RAM,
the cache on the physical disk will be enabled.

discuss with jsg tsubai
ok dlg


# 1.158 19-Dec-2014 deraadt

another handful of bcopy -> memcpy because there is no overlap


# 1.157 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.156 09-Sep-2014 dlg

mark the interrupt handler mpsafe, and give up biglock in the scsi cmd
submission paths. take biglock again when calling back into the scsi
stack.

tested on a variety of cards here, including the skinny mfis on the
firewall next to mpsafe myx.


# 1.155 15-Aug-2014 yasuoka

Create a function which loads sgd in the mfi_iop_ops struct so that skinny
adapters can use "IEEE sgl".

tested dlg yasuoka
ok dlg jsg


Revision tags: OPENBSD_5_6_BASE
# 1.154 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.153 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.152 04-May-2014 sf

format string fixes for bus_addr_t and bus_size_t

bus_addr_t and bus_size_t are u_long everywhere

ok kettenis@


Revision tags: OPENBSD_5_5_BASE
# 1.151 20-Feb-2014 kettenis

revert previous commit; didn't intend to commit those bits


# 1.150 20-Feb-2014 kettenis

Avoid printing the "nvram corrupt" message for onboard 2200s found on Sun
hardware.

ok dlg@, jmatthew@


# 1.149 04-Dec-2013 dlg

mfi_refresh_sensors calls mfi_ioctl_vol which calls mfi_bio_getitall, which
replaces pointers in the softc and all sorts of fun stuff. this protects
the call to bio_getitall with the sc_lock the ioctl path uses, so we dont
get panics like those reported on bugs@ recently.

ok deraadt@


# 1.148 23-Oct-2013 kettenis

Add support for displaying the cache write policy of RAID volumes to bioctl(8)
and make mfi(4) pass up the necessary information. Adding support for other
RAID controllers is left as an excercise to the reader.

ok deraadt@


# 1.147 09-Oct-2013 jmatthew

Include the 'state of health' field in the bbu ok sensor value.
The dell perc 6/i sets this to zero (meaning bad) when it
decides the battery doesn't have enough capacity for it to
allow write back mode, but doesn't set any of the other flags
to tell us why.

ok dlg@, tested by sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.146 18-May-2013 jmc

enw->new in comment;
spotted by krw, missed by jsg, and forwarded From: Alexey Suslikov


# 1.145 08-May-2013 jsg

fix some leaks in error paths
ok fgsch@ krw@ kettenis@


# 1.144 03-May-2013 dlg

break out the battery status into excruciating detail. makes it harder for
$VENDOR to complain about a lack of diagnostic material from their crappy
mgmt tools if you're not running an operating system they support.


# 1.143 02-May-2013 dlg

always attach the battery sensor if the adapter lets us query it.
newly replaced batteries dont show up immediately.


# 1.142 01-May-2013 dlg

provide a sensor for the battery backup unit (bbu) on mfi boards that
support it.

now i can tell (a bit better) why io might be slow on some of my boxes.


# 1.141 01-May-2013 dlg

dont need to walk alldevs during sensor creation looking for the logical
disk scsibus when we record that in mfi_attach.

also happens to get rid of a logic error that let it come out of the loop
on alldevs with a reference to something that wasnt the logical disk
scsibus and use that.


# 1.140 30-Apr-2013 dlg

use MR_DCMD consistently. some MD_DCMD was in there somehow.


# 1.139 07-Apr-2013 dlg

david imhoff points out that the error handling in mfi_init_ccb gets the
index to which ccb to free wrong.

this takes the logic from mpi/mpii/mfii which pulls the ready ccbs off
the free list rather than rely on the current index from the for loop
that we failed inside of.

thanks to david for finding this out.


Revision tags: OPENBSD_5_3_BASE
# 1.138 12-Sep-2012 haesbaert

Make sure we don't sleep on autoconf.

ok mikeb


# 1.137 17-Aug-2012 dlg

add support for "physical devices" on skinny controllers.

these controllers let you specify disks that should be accessed directly
rather than be part of logical volumes. apparently you can plug in things
like tape drives too.

anyway, physical devices are exposed via a separate scsibus attached to
mfi.

ok mikeb@


# 1.136 16-Aug-2012 dlg

fix mfi_poll by having it do delays between loops, and breaking on
timeouts. how embarrassment.

implement mfi_exec for doing sync executions of commands in process
contexts and cut mfi_mgmt over to it.


# 1.135 16-Aug-2012 dlg

rework mfi_poll so it will do all the completions on a ccb including
calling the done handler.

this makes it consistently complete scsi io with all the proper error
checking.


# 1.134 16-Aug-2012 dlg

stop passing mfi_softc around as a member of the ccb, consistently give it
as the first argument to functions. like mfii.


# 1.133 16-Aug-2012 dlg

scrub ccbs when we're about to use them, not when we put them back
on the free list. ccbs can be reused, so we dont want old state screwing up
new commands.


# 1.132 16-Aug-2012 dlg

move the dma syncs for the ccb data into ccb_done, so we can do it once
rather than put the code everywhere.


# 1.131 16-Aug-2012 dlg

fix up the dma sync for the command frame in mfi_done.


# 1.130 14-Aug-2012 dlg

use scsi_get_link to find out the name of a child device for bioctl rather
than snoop scsi commands and copy it in an io path.

no functional change, but the code has one less XXX now.


# 1.129 14-Aug-2012 dlg

expose the max number of logical volumes the hardware supports as the width
of its scsibus. only advertise 1 lun on logical volumes instead of letting
the midlayer fix it up to 8.

give every target on the bus max_cmds openings. iopools means they will
properly share access to them.

this in particular is useful on skinny controllers which only advertise 31
command slots. if you have 16 volumes, theyll only get 1 opening each with
the old maths. this way round the ones that are busy will share the slots.

tested on a perc5 with two volumes and hard workloads.


# 1.128 14-Aug-2012 dlg

print the boards name (eg, perc 5/i) according to the firmware like mfii.

ok deraadt@


# 1.127 14-Aug-2012 dlg

move knowledge of the location of the inbound doorbell out of code in
transition_firmware into a member of the iop structures.

ok mikeb@ haesbaert@


# 1.126 13-Aug-2012 dlg

get rid of the last foo_lo and foo_hi bits i could find in the hardware
structures and use htole64 instead of htole32(addr >> 32); htole32(addr);

gets rid of "handy" stack variables to get the dva to 64bits.

sprinkle some more byte swaps for things that should have it.

tested on a perc5 (xscale)


# 1.125 13-Aug-2012 dlg

do appropriate bus_dmamapy_syncs around the pcq/completion ring.

tested on a perc5 (xscale)


# 1.124 13-Aug-2012 dlg

replace uint32_ts for hi and lo addresses in the mfi_init_ hardware
descriptors with single uint64_ts. theyre not some weird middle
endian thing. this makes the code more readable.

add some missing htole32s to the code while here.

tested on a perc5 (xscale).


# 1.123 11-Aug-2012 dlg

the producer/consumer values are used by the device, which is little
endian. do appropriate byteswapping for when the host cpu uses them.

tested on a perc5 (xscale) in an amd64.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.122 12-Jan-2012 dlg

add support for skinny variants.

from Alexey Suslikov
reviewed by marco


Revision tags: OPENBSD_5_0_BASE
# 1.121 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.120 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.119 09-Apr-2011 marco

add all 64 bit dma plumbing but stick with 32 for now by default.

ok deraadt


# 1.118 09-Apr-2011 marco

make sure the upper 32 bits are always written to instead of assuming it
is 0.

ok deraadt.


# 1.117 08-Apr-2011 marco

kill some stray spaces


# 1.116 08-Apr-2011 marco

rename wiat channel to something less than 8 chars.

prompted by deraadt


# 1.115 08-Apr-2011 marco

use dma_alloc for transient management commands.

prodded and ok deraadt


Revision tags: OPENBSD_4_9_BASE
# 1.114 30-Dec-2010 dlg

cut mfi over to using iopools.

this gets rid of NO_CCB, provides better scheduling of io between busy
logical volumes on the same controller, and makes the ioctl and sensor
paths more reliable.

this is the least intrusive version of this change i could come up with. it
only took 4 or 5 goes...

ok marco@
deraadt@ says this is a good time for this change.


# 1.113 24-Sep-2010 dlg

no use setting cmd in mfi_ioctl_setstate if you never use it.


# 1.112 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


# 1.111 29-Aug-2010 dlg

the scsi completion code thinks that if you dont get MFI_STAT_OK
back from the chip on a command then the command completely failed.
MFI_STAT_SCSI_DONE_WITH_ERROR really means the command completed
fine, but there's some sense data too. this tweaks the handling to
be more appropriate, as per the linux and solaris drivers.

timed out waiting for beck@
putting this in cos its obviously more correct than the current code.


Revision tags: OPENBSD_4_8_BASE
# 1.110 22-Jul-2010 matthew

SCSI HBA drivers are supposed to get their SCSI CDBs from xs->cmd, not
xs->cmdstore.

ok krw@ a while back (contingent upon testing), and deraadt@ says this
has been in snapshots for weeks now.


# 1.109 01-Jul-2010 matthew

Change scsibus(4)'s scsi_link array to an SLIST to save memory on
sparsely populated buses.

ok dlg@, krw@


# 1.108 30-Jun-2010 mk

Use SLIST for the ccb free list.

ok krw, discontent grunts from marco.


# 1.107 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.106 15-Jun-2010 dlg

dont pass the dev_t from the scsi device drivers into the midlayer for
ioctl requests, and dont pass the proc pointers around for any ioctl
requests in scsi land at all. neither were used, so trim the fat.

ok krw@ marco@


# 1.105 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.104 16-May-2010 nicm

Use a temporary variable for now to sidestep -Wbounded checking when
copying vendor[8]/product[16]/revision[4] out of struct scsi_inquiry_data
together with one memcopy.

ok krw


# 1.103 22-Apr-2010 oga

use BUS_DMA_ZERO on alloc instead of bzeroing after.

ok dlg@, marco@


# 1.102 10-Apr-2010 marco

grrr var names in protos


# 1.101 10-Apr-2010 marco

sprinkle some bus_dmamap_sync around frame access.
prompted by oga


# 1.100 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.99 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.98 04-Jan-2010 dlg

rename ccb_xs to ccb_cookie and change its type from a scsi_xfer * to a
void *. this lets us pass things other than scsi_xfers to ccb completion
handlers.


# 1.97 04-Jan-2010 dlg

protect the ccb free queue with a mutex rather than splbio


# 1.96 03-Jan-2010 chl

change M_WAITOK --> M_WAITOK|M_CANFAIL

with input from marco@

ok marco@ krw@

this was ok looooooooong time ago but lost in my mailbox


Revision tags: OPENBSD_4_6_BASE
# 1.95 30-Apr-2009 marco

Add READ(16) & WRITE(16) commands.
ok krw


# 1.94 29-Apr-2009 marco

MFI_D_IOCTL should be commented out. No binary change.


# 1.93 04-Apr-2009 dlg

scrub more fields in the ccb when returning them to the free list after
theyve been used, in particular the mfi header flags which has a bit
that specifies if a command should be completed via the interrupt path.

if we use a ccb during boot we set that bit, but it isnt necessarily
cleared by things that use it later on. this means a ccb we expected to
complete via an interrupt never actually generates an interrupt or appears
in the reply queue. this obviously stalls the io.


# 1.92 29-Mar-2009 marco

spello


# 1.91 29-Mar-2009 dlg

when we steal the SYNC CACHE command in mfi_scsi_cmd we still have to
mark the xs as done and call scsi_done for it rather than just returning
COMPLETE.


# 1.90 29-Mar-2009 dlg

fix a small race in mfi_mgmt between the checking of a ccbs completion and
the sleep waiting for the completion. it is possible to get the interrupt
completing the command just before the tsleep, which will never get a
wakeup because the interrupt with the wakeup has already happened.


Revision tags: OPENBSD_4_5_BASE
# 1.89 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.


# 1.88 28-Jan-2009 marco

Add support for next generation megaraid sas raid controllers.
From Jim Giannoules <gortag@gmail.com>


# 1.87 31-Oct-2008 marco

Generalize function to obtain all details to do bio stuff. This is in
preparation to start showing unsused disks which will require all this
information to do the math.

While at it fix a size of hotspare volume bug.


# 1.86 30-Oct-2008 marco

Fix bug that when there are no volumes but there are hot spares it would
no show the hotspares.


# 1.85 28-Oct-2008 marco

Fix output when reporting on multivolume disk groups.

Reported by mitja@muzenic.net


# 1.84 27-Oct-2008 marco

Move some include stuff around


# 1.83 26-Oct-2008 marco

Space


# 1.82 23-Oct-2008 marco

Fix PR5645
ok dlg
tested beck and others


# 1.81 25-Sep-2008 krw

Initialize 'ssc' to NULL since we test it later. Shouldn't ever be
NULL at the point of test unless the device list is confused, but
be consistantly paranoid if we're going to be paranoid.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.80 16-Feb-2008 krw

Return NO_CCB and not TRY_AGAIN_LATER when running out of ccb's.
Eliminates 'not queued' errors reported on the mailing lists.

Tested by Michael (belenus at bsdmail dot de).

ok marco@


# 1.79 11-Feb-2008 dlg

add support for the mfi controllers with the ppc iops, aka, LSI SAS1078 or
Dell PERC6.

committed off a machine booting and rooting off a perc6. tested on a perc5
by marco@
ok marco@


# 1.78 26-Jan-2008 brad

Set the return value instead of returning right away so that the DMA
memory is actually synched.

ok dlg@


# 1.77 26-Jan-2008 dlg

sync dma mem back to the cpu on poll failure.

from mickey via pr5714


# 1.76 26-Jan-2008 dlg

despatch -> dispatch

disparate spellink fix from mickey


# 1.75 05-Nov-2007 krw

More scsi_done() at SPLBIO.


# 1.74 27-Sep-2007 chl

M_ZERO changes

ok dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.73 24-Jun-2007 dlg

rework sensor tasks to use the kernels generic workq rather than a special
kernel thread of its own. the api has changed (which will be fixed in the
manpage shortly) so all the users of sensor tasks that i can find have
been fixed too.

noone tested, so its going in to force people to run with it.
"put it in" deraadt@


# 1.72 29-May-2007 todd

sprinkle some SMALL_KERNEL to permit bio/softraid to run on boot media
ok marco@ then suggested deraadt@


# 1.71 22-Mar-2007 deraadt

split userland & kernel struct sensor/sensordev so that the addition
of new fields in the future is less disruptive. This is done similar
to how struct proc is handled for ps(1). ok jmc (man page changes)
tested fkr simon, and more suggestions from millert


Revision tags: OPENBSD_4_1_BASE
# 1.70 14-Feb-2007 dlg

bus_space does byte swapping to cope with host endianness for us, so remove
an unnecessary htole32().


# 1.69 13-Feb-2007 marco

Fix subtle x ? y : z bug when calling mfi_create_sgl. This worked because
during runtime the bug condition does not happen.

ok krw joris


# 1.68 08-Feb-2007 ray

Remove double semicolons.

From Pierre Riteau <pierre dot riteau at free dot fr>.

OK marco@.


# 1.67 23-Dec-2006 deraadt

adapt to new two-level sensor api; Constantine A. Murenin


# 1.66 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.65 31-Aug-2006 marco

Add sensor thread for individual sd devices.

tested dlg
ok dlg deraadt


# 1.64 30-Aug-2006 dlg

when determining the size of the volumes and disks we want how many
bytes each of them has, not the number of kilobytes. this solves the
"why am i dividing by 2" question. the answer is "you dont, you multiply
by 512".


# 1.63 28-Jul-2006 brad

make dmesg printing look a little bit nicer.


# 1.62 19-Jun-2006 marco

Factor for disk size is /2. Odd but tested on all mfis I have.


# 1.61 19-Jun-2006 miod

Everytime one forgets an argument in a printf-like function call, God kills
a kitten. Commiters, please think of the kittens when working on code.


# 1.60 19-Jun-2006 marco

Make a BGI (Back Ground Init) a scrub instead of rebuild.


# 1.59 19-Jun-2006 marco

Add hot spare support.


# 1.58 26-May-2006 marco

Add blinking for disks.


# 1.57 25-May-2006 marco

Move a int i; to top of function so that it compiles on non c99 compilers.
Pointed out by miod@

The enclosure id modifier didn't reflect reality so move it back to whatever
the raid card uses.


# 1.56 25-May-2006 marco

And add time and percentage to builds and check consistencies.


# 1.55 25-May-2006 marco

Add last bit of physcal disk stuff.
Remove bogus memset.
Hotspares still don't work.


# 1.54 25-May-2006 marco

Add physical device and read config structures.
Add initial part of BIOCDISK


# 1.53 23-May-2006 deraadt

commited with unused variable


# 1.52 23-May-2006 marco

Remove some debug cruft.


# 1.51 23-May-2006 marco

Add first half of physical disk data for bio.


# 1.50 22-May-2006 marco

Add support for raid 50 and 10 in bio.


# 1.49 22-May-2006 marco

Add mail box to mfi_mgmt to handle sub commands more gracefully.
Remove some debug crud that snuck in the TEST_UNIT_READY case.
Finish other half of BIOCVOL primitive.
Add several structures to fill out the BIOCVOL primitive.


# 1.48 22-May-2006 marco

Add first half of BIOCVOL primitive.


# 1.47 21-May-2006 marco

Do a giant flush of disk and raid-card memory when SYNCHONIZE_CACHE is called.


# 1.46 21-May-2006 marco

pretty up some debug statements.


# 1.45 21-May-2006 marco

Add bio alarm function.
Redo mfi_mgmt to deal with zero data commands.


# 1.44 21-May-2006 marco

Add generic management function.
Redo ccb_state flags so that we can actually sleep on it.
Redo mfi_get_info to use new mgmt function.
Add rw_locks for mgmt interface.
Make BIOCINQ dynamic.


# 1.43 21-May-2006 marco

Oops, helps to use the right structure field.
Use actual nr of physical disks present.


# 1.42 21-May-2006 marco

Add first BIOCINQ primitive.


# 1.41 18-May-2006 marco

Remove some debug cruft and pretty up some debug messages.


# 1.40 18-May-2006 marco

Kill splbio/splx in the interrupt handler.


# 1.39 18-May-2006 marco

And we have lift off! Was able to create a filesystem and write to the
filesystem.

Collapse both completion routines into one.
Fixup scsi error reporting in the completion routine.


# 1.38 17-May-2006 marco

Add completion routines.
Fix some bugs inside the interrupt handler.


# 1.37 17-May-2006 marco

Add mfi_get_info to obtain all kinds of fun information from the fw.
Print out whole info structure when debug is enabled.
Add a nice print with useful info during attach.


# 1.36 17-May-2006 marco

Refactor scsi path so that we can have a single sgl function for io and non-io
traffic.
Redo parameters on functions that were passing too many parameters around.


# 1.35 16-May-2006 marco

Nuke some { }


# 1.34 16-May-2006 marco

Move !xs->data case into mfi_start_xs.
Return proper sense data when a polling command fails.


# 1.33 16-May-2006 marco

Fix some more htole32 screw-ups.
Colapse all little SCSI functions into a single generic one.
Fix a bug in the SGE calculation.

This brings the driver up to post:
mfi0 at pci12 dev 14 function 0 "Dell PERC SAS" rev 0x00: Dell PERC 5/e irq 5
scsibus3 at mfi0: 2 targets
sd1 at scsibus3 targ 0 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd1: 237824MB, 237824 cyl, 64 head, 32 sec, 512 bytes/sec, 487063552 sec total
sd2 at scsibus3 targ 1 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd2: 34176MB, 34176 cyl, 64 head, 32 sec, 512 bytes/sec, 69992448 sec total


# 1.32 16-May-2006 marco

Fix some htole32 I missed.
Sprinkle more debug.


# 1.31 16-May-2006 marco

Add READ CAPACITY.


# 1.30 16-May-2006 marco

Oops PREREAD not PREWRITE.


# 1.29 16-May-2006 marco

Add TUR and make it send it directly to firmware.
Sprinkle some extra debug.


# 1.28 15-May-2006 marco

Clear all relevant ccb fields when mfi_put_ccb frees a ccb.


# 1.27 15-May-2006 marco

Oops don't send command twice to firmware when polling.


# 1.26 15-May-2006 marco

Add INQUIRY command.
Add sgl magic.


# 1.25 10-May-2006 marco

Add some airplane code.

add bio hooks.
add scsi entry point for io.


# 1.24 26-Apr-2006 marco

Fix some debug prints.


# 1.23 21-Apr-2006 marco

typo


# 1.22 21-Apr-2006 marco

Add mfi_poll and use the new shiny function to setup all the hardware queues.
Lots of ideas from the FreeBSD driver.


# 1.21 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.20 20-Apr-2006 dlg

marco hates typedefs as much as i do, so he asked me to clean mfi like i
just did with ami. this gets rid of the typedef for the ccb lists.

also uses TAILQ_FIRST to get ccbs off the freelist. this is a proactive
fix for a lint teary.


# 1.19 18-Apr-2006 marco

It helps to initialize a queue before usage.


# 1.18 18-Apr-2006 marco

Actually add ccbs to the queue.
Fix the error path for mfi_init_ccb.
Alter dmamap for io.


# 1.17 17-Apr-2006 marco

Sprinkle more debug. Remove 64 byte boundary; it doesn't seem to like it.
Hack around 64 byte boundary for the frames for now.


# 1.16 17-Apr-2006 marco

Setup ccbs and clean up ccb structure.


# 1.15 16-Apr-2006 marco

Oops, make mfi_allocmem always use 64 byte boundaries since frames have to
have that alignment. It doesn't matter for the other consumers of the
function.


# 1.14 16-Apr-2006 marco

Add frame memory and sglist allocation.


# 1.13 16-Apr-2006 marco

Make memory access use macro.


# 1.12 16-Apr-2006 marco

typo


# 1.11 16-Apr-2006 marco

Add get and put ccb functions. Shuffle some more definitions.


# 1.10 16-Apr-2006 marco

Nicer print when context is invalid.


# 1.9 16-Apr-2006 marco

Shuffle some #defines.
Fix comments.
Add human readable enable intrrupt #define.


# 1.8 16-Apr-2006 marco

Add interrupt handler. Idea borrowed from FreeBSD since it is much nicer
than the Linux one.


# 1.7 07-Apr-2006 marco

Replace bus_space functions with generic ones that do barriers.


# 1.6 07-Apr-2006 marco

Add memory allocator functions.


# 1.5 07-Apr-2006 marco

Print state in debug. Change return vales to 1 instead of ENXIO.


# 1.4 07-Apr-2006 marco

Make a better debug mechanism.


# 1.3 07-Apr-2006 marco

Enable mfi_transition_fw() original code from FreeBSD.


# 1.2 06-Apr-2006 marco

Add fw transition logic.


# 1.1 06-Apr-2006 marco

Add skeleton driver for MegaRAID SAS.


# 1.171 31-Dec-2019 mpi

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

ok kn@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.170 05-Mar-2019 jmatthew

apply background init progress fix from r1.59 of mfii.c
(reverting most of r1.60 of mfi.c, oddly enough)

ok dlg@
tested on a SAS2008 (perc h310)


Revision tags: OPENBSD_6_4_BASE
# 1.169 14-Aug-2018 jmatthew

return ENOTTY rather than EINVAL to indicate an ioctl hasn't been handled

ok dlg@ deraadt@ kettenis@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.168 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.167 02-Feb-2017 dlg

copy the mbox into the dcmd struct, not the pointer to the mbox.

makes bioctl work on mfi(4) again.

while here memset a few mboxes before using them.

bioctl breakage reported by jason george


# 1.166 23-Jan-2017 dlg

represent the mbox layout with union instead of an array of bytes.

memcpying uint16_ts into inconsistently addressed offsets is hard
to read, and this makes future work easier to implement.

tested on mfi(4) and mfii(4)


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.165 09-Sep-2015 deraadt

sizes for free(); ok sthen


Revision tags: OPENBSD_5_8_BASE
# 1.164 29-May-2015 uebayasi

Initial addition of ``Patrol Read'' support in bio(4), biocto(8), and
mfi(4). Based on FreeBSD, but done without mfiutil(8).

OK deraadt@


# 1.163 18-May-2015 mikeb

Prevent splassert from firing during sd_flush which runs "cold"

While mfi(4) should pass SCSI transfer flags (e.g. SCSI_POLL and
SCSI_NOSLEEP) down to the management function, make it at least
use "cold" consistently for now.

ok dlg


# 1.162 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.161 08-Mar-2015 dlg

properly set sgl related flags on skinny controllers. this fixes
io against physical disks on my dell perc h310s. logical disks still
work fine.

ok deraadt@ yasuoka@


# 1.160 08-Feb-2015 yasuoka

Fix mfi ioctl to set drive state properly.
diff from Tsubai Masanari

test dlg jmatthew
ok dlg


# 1.159 09-Jan-2015 yasuoka

Add support DIOC{G,S}CACHE to mfi(4). Cache of disk on mfi(4) will
be enabled by default. Also if the controller doesn't have any RAM,
the cache on the physical disk will be enabled.

discuss with jsg tsubai
ok dlg


# 1.158 19-Dec-2014 deraadt

another handful of bcopy -> memcpy because there is no overlap


# 1.157 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.156 09-Sep-2014 dlg

mark the interrupt handler mpsafe, and give up biglock in the scsi cmd
submission paths. take biglock again when calling back into the scsi
stack.

tested on a variety of cards here, including the skinny mfis on the
firewall next to mpsafe myx.


# 1.155 15-Aug-2014 yasuoka

Create a function which loads sgd in the mfi_iop_ops struct so that skinny
adapters can use "IEEE sgl".

tested dlg yasuoka
ok dlg jsg


Revision tags: OPENBSD_5_6_BASE
# 1.154 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.153 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.152 04-May-2014 sf

format string fixes for bus_addr_t and bus_size_t

bus_addr_t and bus_size_t are u_long everywhere

ok kettenis@


Revision tags: OPENBSD_5_5_BASE
# 1.151 20-Feb-2014 kettenis

revert previous commit; didn't intend to commit those bits


# 1.150 20-Feb-2014 kettenis

Avoid printing the "nvram corrupt" message for onboard 2200s found on Sun
hardware.

ok dlg@, jmatthew@


# 1.149 04-Dec-2013 dlg

mfi_refresh_sensors calls mfi_ioctl_vol which calls mfi_bio_getitall, which
replaces pointers in the softc and all sorts of fun stuff. this protects
the call to bio_getitall with the sc_lock the ioctl path uses, so we dont
get panics like those reported on bugs@ recently.

ok deraadt@


# 1.148 23-Oct-2013 kettenis

Add support for displaying the cache write policy of RAID volumes to bioctl(8)
and make mfi(4) pass up the necessary information. Adding support for other
RAID controllers is left as an excercise to the reader.

ok deraadt@


# 1.147 09-Oct-2013 jmatthew

Include the 'state of health' field in the bbu ok sensor value.
The dell perc 6/i sets this to zero (meaning bad) when it
decides the battery doesn't have enough capacity for it to
allow write back mode, but doesn't set any of the other flags
to tell us why.

ok dlg@, tested by sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.146 18-May-2013 jmc

enw->new in comment;
spotted by krw, missed by jsg, and forwarded From: Alexey Suslikov


# 1.145 08-May-2013 jsg

fix some leaks in error paths
ok fgsch@ krw@ kettenis@


# 1.144 03-May-2013 dlg

break out the battery status into excruciating detail. makes it harder for
$VENDOR to complain about a lack of diagnostic material from their crappy
mgmt tools if you're not running an operating system they support.


# 1.143 02-May-2013 dlg

always attach the battery sensor if the adapter lets us query it.
newly replaced batteries dont show up immediately.


# 1.142 01-May-2013 dlg

provide a sensor for the battery backup unit (bbu) on mfi boards that
support it.

now i can tell (a bit better) why io might be slow on some of my boxes.


# 1.141 01-May-2013 dlg

dont need to walk alldevs during sensor creation looking for the logical
disk scsibus when we record that in mfi_attach.

also happens to get rid of a logic error that let it come out of the loop
on alldevs with a reference to something that wasnt the logical disk
scsibus and use that.


# 1.140 30-Apr-2013 dlg

use MR_DCMD consistently. some MD_DCMD was in there somehow.


# 1.139 07-Apr-2013 dlg

david imhoff points out that the error handling in mfi_init_ccb gets the
index to which ccb to free wrong.

this takes the logic from mpi/mpii/mfii which pulls the ready ccbs off
the free list rather than rely on the current index from the for loop
that we failed inside of.

thanks to david for finding this out.


Revision tags: OPENBSD_5_3_BASE
# 1.138 12-Sep-2012 haesbaert

Make sure we don't sleep on autoconf.

ok mikeb


# 1.137 17-Aug-2012 dlg

add support for "physical devices" on skinny controllers.

these controllers let you specify disks that should be accessed directly
rather than be part of logical volumes. apparently you can plug in things
like tape drives too.

anyway, physical devices are exposed via a separate scsibus attached to
mfi.

ok mikeb@


# 1.136 16-Aug-2012 dlg

fix mfi_poll by having it do delays between loops, and breaking on
timeouts. how embarrassment.

implement mfi_exec for doing sync executions of commands in process
contexts and cut mfi_mgmt over to it.


# 1.135 16-Aug-2012 dlg

rework mfi_poll so it will do all the completions on a ccb including
calling the done handler.

this makes it consistently complete scsi io with all the proper error
checking.


# 1.134 16-Aug-2012 dlg

stop passing mfi_softc around as a member of the ccb, consistently give it
as the first argument to functions. like mfii.


# 1.133 16-Aug-2012 dlg

scrub ccbs when we're about to use them, not when we put them back
on the free list. ccbs can be reused, so we dont want old state screwing up
new commands.


# 1.132 16-Aug-2012 dlg

move the dma syncs for the ccb data into ccb_done, so we can do it once
rather than put the code everywhere.


# 1.131 16-Aug-2012 dlg

fix up the dma sync for the command frame in mfi_done.


# 1.130 14-Aug-2012 dlg

use scsi_get_link to find out the name of a child device for bioctl rather
than snoop scsi commands and copy it in an io path.

no functional change, but the code has one less XXX now.


# 1.129 14-Aug-2012 dlg

expose the max number of logical volumes the hardware supports as the width
of its scsibus. only advertise 1 lun on logical volumes instead of letting
the midlayer fix it up to 8.

give every target on the bus max_cmds openings. iopools means they will
properly share access to them.

this in particular is useful on skinny controllers which only advertise 31
command slots. if you have 16 volumes, theyll only get 1 opening each with
the old maths. this way round the ones that are busy will share the slots.

tested on a perc5 with two volumes and hard workloads.


# 1.128 14-Aug-2012 dlg

print the boards name (eg, perc 5/i) according to the firmware like mfii.

ok deraadt@


# 1.127 14-Aug-2012 dlg

move knowledge of the location of the inbound doorbell out of code in
transition_firmware into a member of the iop structures.

ok mikeb@ haesbaert@


# 1.126 13-Aug-2012 dlg

get rid of the last foo_lo and foo_hi bits i could find in the hardware
structures and use htole64 instead of htole32(addr >> 32); htole32(addr);

gets rid of "handy" stack variables to get the dva to 64bits.

sprinkle some more byte swaps for things that should have it.

tested on a perc5 (xscale)


# 1.125 13-Aug-2012 dlg

do appropriate bus_dmamapy_syncs around the pcq/completion ring.

tested on a perc5 (xscale)


# 1.124 13-Aug-2012 dlg

replace uint32_ts for hi and lo addresses in the mfi_init_ hardware
descriptors with single uint64_ts. theyre not some weird middle
endian thing. this makes the code more readable.

add some missing htole32s to the code while here.

tested on a perc5 (xscale).


# 1.123 11-Aug-2012 dlg

the producer/consumer values are used by the device, which is little
endian. do appropriate byteswapping for when the host cpu uses them.

tested on a perc5 (xscale) in an amd64.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.122 12-Jan-2012 dlg

add support for skinny variants.

from Alexey Suslikov
reviewed by marco


Revision tags: OPENBSD_5_0_BASE
# 1.121 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.120 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.119 09-Apr-2011 marco

add all 64 bit dma plumbing but stick with 32 for now by default.

ok deraadt


# 1.118 09-Apr-2011 marco

make sure the upper 32 bits are always written to instead of assuming it
is 0.

ok deraadt.


# 1.117 08-Apr-2011 marco

kill some stray spaces


# 1.116 08-Apr-2011 marco

rename wiat channel to something less than 8 chars.

prompted by deraadt


# 1.115 08-Apr-2011 marco

use dma_alloc for transient management commands.

prodded and ok deraadt


Revision tags: OPENBSD_4_9_BASE
# 1.114 30-Dec-2010 dlg

cut mfi over to using iopools.

this gets rid of NO_CCB, provides better scheduling of io between busy
logical volumes on the same controller, and makes the ioctl and sensor
paths more reliable.

this is the least intrusive version of this change i could come up with. it
only took 4 or 5 goes...

ok marco@
deraadt@ says this is a good time for this change.


# 1.113 24-Sep-2010 dlg

no use setting cmd in mfi_ioctl_setstate if you never use it.


# 1.112 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


# 1.111 29-Aug-2010 dlg

the scsi completion code thinks that if you dont get MFI_STAT_OK
back from the chip on a command then the command completely failed.
MFI_STAT_SCSI_DONE_WITH_ERROR really means the command completed
fine, but there's some sense data too. this tweaks the handling to
be more appropriate, as per the linux and solaris drivers.

timed out waiting for beck@
putting this in cos its obviously more correct than the current code.


Revision tags: OPENBSD_4_8_BASE
# 1.110 22-Jul-2010 matthew

SCSI HBA drivers are supposed to get their SCSI CDBs from xs->cmd, not
xs->cmdstore.

ok krw@ a while back (contingent upon testing), and deraadt@ says this
has been in snapshots for weeks now.


# 1.109 01-Jul-2010 matthew

Change scsibus(4)'s scsi_link array to an SLIST to save memory on
sparsely populated buses.

ok dlg@, krw@


# 1.108 30-Jun-2010 mk

Use SLIST for the ccb free list.

ok krw, discontent grunts from marco.


# 1.107 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.106 15-Jun-2010 dlg

dont pass the dev_t from the scsi device drivers into the midlayer for
ioctl requests, and dont pass the proc pointers around for any ioctl
requests in scsi land at all. neither were used, so trim the fat.

ok krw@ marco@


# 1.105 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.104 16-May-2010 nicm

Use a temporary variable for now to sidestep -Wbounded checking when
copying vendor[8]/product[16]/revision[4] out of struct scsi_inquiry_data
together with one memcopy.

ok krw


# 1.103 22-Apr-2010 oga

use BUS_DMA_ZERO on alloc instead of bzeroing after.

ok dlg@, marco@


# 1.102 10-Apr-2010 marco

grrr var names in protos


# 1.101 10-Apr-2010 marco

sprinkle some bus_dmamap_sync around frame access.
prompted by oga


# 1.100 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.99 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.98 04-Jan-2010 dlg

rename ccb_xs to ccb_cookie and change its type from a scsi_xfer * to a
void *. this lets us pass things other than scsi_xfers to ccb completion
handlers.


# 1.97 04-Jan-2010 dlg

protect the ccb free queue with a mutex rather than splbio


# 1.96 03-Jan-2010 chl

change M_WAITOK --> M_WAITOK|M_CANFAIL

with input from marco@

ok marco@ krw@

this was ok looooooooong time ago but lost in my mailbox


Revision tags: OPENBSD_4_6_BASE
# 1.95 30-Apr-2009 marco

Add READ(16) & WRITE(16) commands.
ok krw


# 1.94 29-Apr-2009 marco

MFI_D_IOCTL should be commented out. No binary change.


# 1.93 04-Apr-2009 dlg

scrub more fields in the ccb when returning them to the free list after
theyve been used, in particular the mfi header flags which has a bit
that specifies if a command should be completed via the interrupt path.

if we use a ccb during boot we set that bit, but it isnt necessarily
cleared by things that use it later on. this means a ccb we expected to
complete via an interrupt never actually generates an interrupt or appears
in the reply queue. this obviously stalls the io.


# 1.92 29-Mar-2009 marco

spello


# 1.91 29-Mar-2009 dlg

when we steal the SYNC CACHE command in mfi_scsi_cmd we still have to
mark the xs as done and call scsi_done for it rather than just returning
COMPLETE.


# 1.90 29-Mar-2009 dlg

fix a small race in mfi_mgmt between the checking of a ccbs completion and
the sleep waiting for the completion. it is possible to get the interrupt
completing the command just before the tsleep, which will never get a
wakeup because the interrupt with the wakeup has already happened.


Revision tags: OPENBSD_4_5_BASE
# 1.89 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.


# 1.88 28-Jan-2009 marco

Add support for next generation megaraid sas raid controllers.
From Jim Giannoules <gortag@gmail.com>


# 1.87 31-Oct-2008 marco

Generalize function to obtain all details to do bio stuff. This is in
preparation to start showing unsused disks which will require all this
information to do the math.

While at it fix a size of hotspare volume bug.


# 1.86 30-Oct-2008 marco

Fix bug that when there are no volumes but there are hot spares it would
no show the hotspares.


# 1.85 28-Oct-2008 marco

Fix output when reporting on multivolume disk groups.

Reported by mitja@muzenic.net


# 1.84 27-Oct-2008 marco

Move some include stuff around


# 1.83 26-Oct-2008 marco

Space


# 1.82 23-Oct-2008 marco

Fix PR5645
ok dlg
tested beck and others


# 1.81 25-Sep-2008 krw

Initialize 'ssc' to NULL since we test it later. Shouldn't ever be
NULL at the point of test unless the device list is confused, but
be consistantly paranoid if we're going to be paranoid.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.80 16-Feb-2008 krw

Return NO_CCB and not TRY_AGAIN_LATER when running out of ccb's.
Eliminates 'not queued' errors reported on the mailing lists.

Tested by Michael (belenus at bsdmail dot de).

ok marco@


# 1.79 11-Feb-2008 dlg

add support for the mfi controllers with the ppc iops, aka, LSI SAS1078 or
Dell PERC6.

committed off a machine booting and rooting off a perc6. tested on a perc5
by marco@
ok marco@


# 1.78 26-Jan-2008 brad

Set the return value instead of returning right away so that the DMA
memory is actually synched.

ok dlg@


# 1.77 26-Jan-2008 dlg

sync dma mem back to the cpu on poll failure.

from mickey via pr5714


# 1.76 26-Jan-2008 dlg

despatch -> dispatch

disparate spellink fix from mickey


# 1.75 05-Nov-2007 krw

More scsi_done() at SPLBIO.


# 1.74 27-Sep-2007 chl

M_ZERO changes

ok dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.73 24-Jun-2007 dlg

rework sensor tasks to use the kernels generic workq rather than a special
kernel thread of its own. the api has changed (which will be fixed in the
manpage shortly) so all the users of sensor tasks that i can find have
been fixed too.

noone tested, so its going in to force people to run with it.
"put it in" deraadt@


# 1.72 29-May-2007 todd

sprinkle some SMALL_KERNEL to permit bio/softraid to run on boot media
ok marco@ then suggested deraadt@


# 1.71 22-Mar-2007 deraadt

split userland & kernel struct sensor/sensordev so that the addition
of new fields in the future is less disruptive. This is done similar
to how struct proc is handled for ps(1). ok jmc (man page changes)
tested fkr simon, and more suggestions from millert


Revision tags: OPENBSD_4_1_BASE
# 1.70 14-Feb-2007 dlg

bus_space does byte swapping to cope with host endianness for us, so remove
an unnecessary htole32().


# 1.69 13-Feb-2007 marco

Fix subtle x ? y : z bug when calling mfi_create_sgl. This worked because
during runtime the bug condition does not happen.

ok krw joris


# 1.68 08-Feb-2007 ray

Remove double semicolons.

From Pierre Riteau <pierre dot riteau at free dot fr>.

OK marco@.


# 1.67 23-Dec-2006 deraadt

adapt to new two-level sensor api; Constantine A. Murenin


# 1.66 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.65 31-Aug-2006 marco

Add sensor thread for individual sd devices.

tested dlg
ok dlg deraadt


# 1.64 30-Aug-2006 dlg

when determining the size of the volumes and disks we want how many
bytes each of them has, not the number of kilobytes. this solves the
"why am i dividing by 2" question. the answer is "you dont, you multiply
by 512".


# 1.63 28-Jul-2006 brad

make dmesg printing look a little bit nicer.


# 1.62 19-Jun-2006 marco

Factor for disk size is /2. Odd but tested on all mfis I have.


# 1.61 19-Jun-2006 miod

Everytime one forgets an argument in a printf-like function call, God kills
a kitten. Commiters, please think of the kittens when working on code.


# 1.60 19-Jun-2006 marco

Make a BGI (Back Ground Init) a scrub instead of rebuild.


# 1.59 19-Jun-2006 marco

Add hot spare support.


# 1.58 26-May-2006 marco

Add blinking for disks.


# 1.57 25-May-2006 marco

Move a int i; to top of function so that it compiles on non c99 compilers.
Pointed out by miod@

The enclosure id modifier didn't reflect reality so move it back to whatever
the raid card uses.


# 1.56 25-May-2006 marco

And add time and percentage to builds and check consistencies.


# 1.55 25-May-2006 marco

Add last bit of physcal disk stuff.
Remove bogus memset.
Hotspares still don't work.


# 1.54 25-May-2006 marco

Add physical device and read config structures.
Add initial part of BIOCDISK


# 1.53 23-May-2006 deraadt

commited with unused variable


# 1.52 23-May-2006 marco

Remove some debug cruft.


# 1.51 23-May-2006 marco

Add first half of physical disk data for bio.


# 1.50 22-May-2006 marco

Add support for raid 50 and 10 in bio.


# 1.49 22-May-2006 marco

Add mail box to mfi_mgmt to handle sub commands more gracefully.
Remove some debug crud that snuck in the TEST_UNIT_READY case.
Finish other half of BIOCVOL primitive.
Add several structures to fill out the BIOCVOL primitive.


# 1.48 22-May-2006 marco

Add first half of BIOCVOL primitive.


# 1.47 21-May-2006 marco

Do a giant flush of disk and raid-card memory when SYNCHONIZE_CACHE is called.


# 1.46 21-May-2006 marco

pretty up some debug statements.


# 1.45 21-May-2006 marco

Add bio alarm function.
Redo mfi_mgmt to deal with zero data commands.


# 1.44 21-May-2006 marco

Add generic management function.
Redo ccb_state flags so that we can actually sleep on it.
Redo mfi_get_info to use new mgmt function.
Add rw_locks for mgmt interface.
Make BIOCINQ dynamic.


# 1.43 21-May-2006 marco

Oops, helps to use the right structure field.
Use actual nr of physical disks present.


# 1.42 21-May-2006 marco

Add first BIOCINQ primitive.


# 1.41 18-May-2006 marco

Remove some debug cruft and pretty up some debug messages.


# 1.40 18-May-2006 marco

Kill splbio/splx in the interrupt handler.


# 1.39 18-May-2006 marco

And we have lift off! Was able to create a filesystem and write to the
filesystem.

Collapse both completion routines into one.
Fixup scsi error reporting in the completion routine.


# 1.38 17-May-2006 marco

Add completion routines.
Fix some bugs inside the interrupt handler.


# 1.37 17-May-2006 marco

Add mfi_get_info to obtain all kinds of fun information from the fw.
Print out whole info structure when debug is enabled.
Add a nice print with useful info during attach.


# 1.36 17-May-2006 marco

Refactor scsi path so that we can have a single sgl function for io and non-io
traffic.
Redo parameters on functions that were passing too many parameters around.


# 1.35 16-May-2006 marco

Nuke some { }


# 1.34 16-May-2006 marco

Move !xs->data case into mfi_start_xs.
Return proper sense data when a polling command fails.


# 1.33 16-May-2006 marco

Fix some more htole32 screw-ups.
Colapse all little SCSI functions into a single generic one.
Fix a bug in the SGE calculation.

This brings the driver up to post:
mfi0 at pci12 dev 14 function 0 "Dell PERC SAS" rev 0x00: Dell PERC 5/e irq 5
scsibus3 at mfi0: 2 targets
sd1 at scsibus3 targ 0 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd1: 237824MB, 237824 cyl, 64 head, 32 sec, 512 bytes/sec, 487063552 sec total
sd2 at scsibus3 targ 1 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd2: 34176MB, 34176 cyl, 64 head, 32 sec, 512 bytes/sec, 69992448 sec total


# 1.32 16-May-2006 marco

Fix some htole32 I missed.
Sprinkle more debug.


# 1.31 16-May-2006 marco

Add READ CAPACITY.


# 1.30 16-May-2006 marco

Oops PREREAD not PREWRITE.


# 1.29 16-May-2006 marco

Add TUR and make it send it directly to firmware.
Sprinkle some extra debug.


# 1.28 15-May-2006 marco

Clear all relevant ccb fields when mfi_put_ccb frees a ccb.


# 1.27 15-May-2006 marco

Oops don't send command twice to firmware when polling.


# 1.26 15-May-2006 marco

Add INQUIRY command.
Add sgl magic.


# 1.25 10-May-2006 marco

Add some airplane code.

add bio hooks.
add scsi entry point for io.


# 1.24 26-Apr-2006 marco

Fix some debug prints.


# 1.23 21-Apr-2006 marco

typo


# 1.22 21-Apr-2006 marco

Add mfi_poll and use the new shiny function to setup all the hardware queues.
Lots of ideas from the FreeBSD driver.


# 1.21 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.20 20-Apr-2006 dlg

marco hates typedefs as much as i do, so he asked me to clean mfi like i
just did with ami. this gets rid of the typedef for the ccb lists.

also uses TAILQ_FIRST to get ccbs off the freelist. this is a proactive
fix for a lint teary.


# 1.19 18-Apr-2006 marco

It helps to initialize a queue before usage.


# 1.18 18-Apr-2006 marco

Actually add ccbs to the queue.
Fix the error path for mfi_init_ccb.
Alter dmamap for io.


# 1.17 17-Apr-2006 marco

Sprinkle more debug. Remove 64 byte boundary; it doesn't seem to like it.
Hack around 64 byte boundary for the frames for now.


# 1.16 17-Apr-2006 marco

Setup ccbs and clean up ccb structure.


# 1.15 16-Apr-2006 marco

Oops, make mfi_allocmem always use 64 byte boundaries since frames have to
have that alignment. It doesn't matter for the other consumers of the
function.


# 1.14 16-Apr-2006 marco

Add frame memory and sglist allocation.


# 1.13 16-Apr-2006 marco

Make memory access use macro.


# 1.12 16-Apr-2006 marco

typo


# 1.11 16-Apr-2006 marco

Add get and put ccb functions. Shuffle some more definitions.


# 1.10 16-Apr-2006 marco

Nicer print when context is invalid.


# 1.9 16-Apr-2006 marco

Shuffle some #defines.
Fix comments.
Add human readable enable intrrupt #define.


# 1.8 16-Apr-2006 marco

Add interrupt handler. Idea borrowed from FreeBSD since it is much nicer
than the Linux one.


# 1.7 07-Apr-2006 marco

Replace bus_space functions with generic ones that do barriers.


# 1.6 07-Apr-2006 marco

Add memory allocator functions.


# 1.5 07-Apr-2006 marco

Print state in debug. Change return vales to 1 instead of ENXIO.


# 1.4 07-Apr-2006 marco

Make a better debug mechanism.


# 1.3 07-Apr-2006 marco

Enable mfi_transition_fw() original code from FreeBSD.


# 1.2 06-Apr-2006 marco

Add fw transition logic.


# 1.1 06-Apr-2006 marco

Add skeleton driver for MegaRAID SAS.


# 1.170 05-Mar-2019 jmatthew

apply background init progress fix from r1.59 of mfii.c
(reverting most of r1.60 of mfi.c, oddly enough)

ok dlg@
tested on a SAS2008 (perc h310)


Revision tags: OPENBSD_6_4_BASE
# 1.169 14-Aug-2018 jmatthew

return ENOTTY rather than EINVAL to indicate an ioctl hasn't been handled

ok dlg@ deraadt@ kettenis@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.168 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.167 02-Feb-2017 dlg

copy the mbox into the dcmd struct, not the pointer to the mbox.

makes bioctl work on mfi(4) again.

while here memset a few mboxes before using them.

bioctl breakage reported by jason george


# 1.166 23-Jan-2017 dlg

represent the mbox layout with union instead of an array of bytes.

memcpying uint16_ts into inconsistently addressed offsets is hard
to read, and this makes future work easier to implement.

tested on mfi(4) and mfii(4)


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.165 09-Sep-2015 deraadt

sizes for free(); ok sthen


Revision tags: OPENBSD_5_8_BASE
# 1.164 29-May-2015 uebayasi

Initial addition of ``Patrol Read'' support in bio(4), biocto(8), and
mfi(4). Based on FreeBSD, but done without mfiutil(8).

OK deraadt@


# 1.163 18-May-2015 mikeb

Prevent splassert from firing during sd_flush which runs "cold"

While mfi(4) should pass SCSI transfer flags (e.g. SCSI_POLL and
SCSI_NOSLEEP) down to the management function, make it at least
use "cold" consistently for now.

ok dlg


# 1.162 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.161 08-Mar-2015 dlg

properly set sgl related flags on skinny controllers. this fixes
io against physical disks on my dell perc h310s. logical disks still
work fine.

ok deraadt@ yasuoka@


# 1.160 08-Feb-2015 yasuoka

Fix mfi ioctl to set drive state properly.
diff from Tsubai Masanari

test dlg jmatthew
ok dlg


# 1.159 09-Jan-2015 yasuoka

Add support DIOC{G,S}CACHE to mfi(4). Cache of disk on mfi(4) will
be enabled by default. Also if the controller doesn't have any RAM,
the cache on the physical disk will be enabled.

discuss with jsg tsubai
ok dlg


# 1.158 19-Dec-2014 deraadt

another handful of bcopy -> memcpy because there is no overlap


# 1.157 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.156 09-Sep-2014 dlg

mark the interrupt handler mpsafe, and give up biglock in the scsi cmd
submission paths. take biglock again when calling back into the scsi
stack.

tested on a variety of cards here, including the skinny mfis on the
firewall next to mpsafe myx.


# 1.155 15-Aug-2014 yasuoka

Create a function which loads sgd in the mfi_iop_ops struct so that skinny
adapters can use "IEEE sgl".

tested dlg yasuoka
ok dlg jsg


Revision tags: OPENBSD_5_6_BASE
# 1.154 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.153 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.152 04-May-2014 sf

format string fixes for bus_addr_t and bus_size_t

bus_addr_t and bus_size_t are u_long everywhere

ok kettenis@


Revision tags: OPENBSD_5_5_BASE
# 1.151 20-Feb-2014 kettenis

revert previous commit; didn't intend to commit those bits


# 1.150 20-Feb-2014 kettenis

Avoid printing the "nvram corrupt" message for onboard 2200s found on Sun
hardware.

ok dlg@, jmatthew@


# 1.149 04-Dec-2013 dlg

mfi_refresh_sensors calls mfi_ioctl_vol which calls mfi_bio_getitall, which
replaces pointers in the softc and all sorts of fun stuff. this protects
the call to bio_getitall with the sc_lock the ioctl path uses, so we dont
get panics like those reported on bugs@ recently.

ok deraadt@


# 1.148 23-Oct-2013 kettenis

Add support for displaying the cache write policy of RAID volumes to bioctl(8)
and make mfi(4) pass up the necessary information. Adding support for other
RAID controllers is left as an excercise to the reader.

ok deraadt@


# 1.147 09-Oct-2013 jmatthew

Include the 'state of health' field in the bbu ok sensor value.
The dell perc 6/i sets this to zero (meaning bad) when it
decides the battery doesn't have enough capacity for it to
allow write back mode, but doesn't set any of the other flags
to tell us why.

ok dlg@, tested by sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.146 18-May-2013 jmc

enw->new in comment;
spotted by krw, missed by jsg, and forwarded From: Alexey Suslikov


# 1.145 08-May-2013 jsg

fix some leaks in error paths
ok fgsch@ krw@ kettenis@


# 1.144 03-May-2013 dlg

break out the battery status into excruciating detail. makes it harder for
$VENDOR to complain about a lack of diagnostic material from their crappy
mgmt tools if you're not running an operating system they support.


# 1.143 02-May-2013 dlg

always attach the battery sensor if the adapter lets us query it.
newly replaced batteries dont show up immediately.


# 1.142 01-May-2013 dlg

provide a sensor for the battery backup unit (bbu) on mfi boards that
support it.

now i can tell (a bit better) why io might be slow on some of my boxes.


# 1.141 01-May-2013 dlg

dont need to walk alldevs during sensor creation looking for the logical
disk scsibus when we record that in mfi_attach.

also happens to get rid of a logic error that let it come out of the loop
on alldevs with a reference to something that wasnt the logical disk
scsibus and use that.


# 1.140 30-Apr-2013 dlg

use MR_DCMD consistently. some MD_DCMD was in there somehow.


# 1.139 07-Apr-2013 dlg

david imhoff points out that the error handling in mfi_init_ccb gets the
index to which ccb to free wrong.

this takes the logic from mpi/mpii/mfii which pulls the ready ccbs off
the free list rather than rely on the current index from the for loop
that we failed inside of.

thanks to david for finding this out.


Revision tags: OPENBSD_5_3_BASE
# 1.138 12-Sep-2012 haesbaert

Make sure we don't sleep on autoconf.

ok mikeb


# 1.137 17-Aug-2012 dlg

add support for "physical devices" on skinny controllers.

these controllers let you specify disks that should be accessed directly
rather than be part of logical volumes. apparently you can plug in things
like tape drives too.

anyway, physical devices are exposed via a separate scsibus attached to
mfi.

ok mikeb@


# 1.136 16-Aug-2012 dlg

fix mfi_poll by having it do delays between loops, and breaking on
timeouts. how embarrassment.

implement mfi_exec for doing sync executions of commands in process
contexts and cut mfi_mgmt over to it.


# 1.135 16-Aug-2012 dlg

rework mfi_poll so it will do all the completions on a ccb including
calling the done handler.

this makes it consistently complete scsi io with all the proper error
checking.


# 1.134 16-Aug-2012 dlg

stop passing mfi_softc around as a member of the ccb, consistently give it
as the first argument to functions. like mfii.


# 1.133 16-Aug-2012 dlg

scrub ccbs when we're about to use them, not when we put them back
on the free list. ccbs can be reused, so we dont want old state screwing up
new commands.


# 1.132 16-Aug-2012 dlg

move the dma syncs for the ccb data into ccb_done, so we can do it once
rather than put the code everywhere.


# 1.131 16-Aug-2012 dlg

fix up the dma sync for the command frame in mfi_done.


# 1.130 14-Aug-2012 dlg

use scsi_get_link to find out the name of a child device for bioctl rather
than snoop scsi commands and copy it in an io path.

no functional change, but the code has one less XXX now.


# 1.129 14-Aug-2012 dlg

expose the max number of logical volumes the hardware supports as the width
of its scsibus. only advertise 1 lun on logical volumes instead of letting
the midlayer fix it up to 8.

give every target on the bus max_cmds openings. iopools means they will
properly share access to them.

this in particular is useful on skinny controllers which only advertise 31
command slots. if you have 16 volumes, theyll only get 1 opening each with
the old maths. this way round the ones that are busy will share the slots.

tested on a perc5 with two volumes and hard workloads.


# 1.128 14-Aug-2012 dlg

print the boards name (eg, perc 5/i) according to the firmware like mfii.

ok deraadt@


# 1.127 14-Aug-2012 dlg

move knowledge of the location of the inbound doorbell out of code in
transition_firmware into a member of the iop structures.

ok mikeb@ haesbaert@


# 1.126 13-Aug-2012 dlg

get rid of the last foo_lo and foo_hi bits i could find in the hardware
structures and use htole64 instead of htole32(addr >> 32); htole32(addr);

gets rid of "handy" stack variables to get the dva to 64bits.

sprinkle some more byte swaps for things that should have it.

tested on a perc5 (xscale)


# 1.125 13-Aug-2012 dlg

do appropriate bus_dmamapy_syncs around the pcq/completion ring.

tested on a perc5 (xscale)


# 1.124 13-Aug-2012 dlg

replace uint32_ts for hi and lo addresses in the mfi_init_ hardware
descriptors with single uint64_ts. theyre not some weird middle
endian thing. this makes the code more readable.

add some missing htole32s to the code while here.

tested on a perc5 (xscale).


# 1.123 11-Aug-2012 dlg

the producer/consumer values are used by the device, which is little
endian. do appropriate byteswapping for when the host cpu uses them.

tested on a perc5 (xscale) in an amd64.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.122 12-Jan-2012 dlg

add support for skinny variants.

from Alexey Suslikov
reviewed by marco


Revision tags: OPENBSD_5_0_BASE
# 1.121 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.120 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.119 09-Apr-2011 marco

add all 64 bit dma plumbing but stick with 32 for now by default.

ok deraadt


# 1.118 09-Apr-2011 marco

make sure the upper 32 bits are always written to instead of assuming it
is 0.

ok deraadt.


# 1.117 08-Apr-2011 marco

kill some stray spaces


# 1.116 08-Apr-2011 marco

rename wiat channel to something less than 8 chars.

prompted by deraadt


# 1.115 08-Apr-2011 marco

use dma_alloc for transient management commands.

prodded and ok deraadt


Revision tags: OPENBSD_4_9_BASE
# 1.114 30-Dec-2010 dlg

cut mfi over to using iopools.

this gets rid of NO_CCB, provides better scheduling of io between busy
logical volumes on the same controller, and makes the ioctl and sensor
paths more reliable.

this is the least intrusive version of this change i could come up with. it
only took 4 or 5 goes...

ok marco@
deraadt@ says this is a good time for this change.


# 1.113 24-Sep-2010 dlg

no use setting cmd in mfi_ioctl_setstate if you never use it.


# 1.112 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


# 1.111 29-Aug-2010 dlg

the scsi completion code thinks that if you dont get MFI_STAT_OK
back from the chip on a command then the command completely failed.
MFI_STAT_SCSI_DONE_WITH_ERROR really means the command completed
fine, but there's some sense data too. this tweaks the handling to
be more appropriate, as per the linux and solaris drivers.

timed out waiting for beck@
putting this in cos its obviously more correct than the current code.


Revision tags: OPENBSD_4_8_BASE
# 1.110 22-Jul-2010 matthew

SCSI HBA drivers are supposed to get their SCSI CDBs from xs->cmd, not
xs->cmdstore.

ok krw@ a while back (contingent upon testing), and deraadt@ says this
has been in snapshots for weeks now.


# 1.109 01-Jul-2010 matthew

Change scsibus(4)'s scsi_link array to an SLIST to save memory on
sparsely populated buses.

ok dlg@, krw@


# 1.108 30-Jun-2010 mk

Use SLIST for the ccb free list.

ok krw, discontent grunts from marco.


# 1.107 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.106 15-Jun-2010 dlg

dont pass the dev_t from the scsi device drivers into the midlayer for
ioctl requests, and dont pass the proc pointers around for any ioctl
requests in scsi land at all. neither were used, so trim the fat.

ok krw@ marco@


# 1.105 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.104 16-May-2010 nicm

Use a temporary variable for now to sidestep -Wbounded checking when
copying vendor[8]/product[16]/revision[4] out of struct scsi_inquiry_data
together with one memcopy.

ok krw


# 1.103 22-Apr-2010 oga

use BUS_DMA_ZERO on alloc instead of bzeroing after.

ok dlg@, marco@


# 1.102 10-Apr-2010 marco

grrr var names in protos


# 1.101 10-Apr-2010 marco

sprinkle some bus_dmamap_sync around frame access.
prompted by oga


# 1.100 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.99 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.98 04-Jan-2010 dlg

rename ccb_xs to ccb_cookie and change its type from a scsi_xfer * to a
void *. this lets us pass things other than scsi_xfers to ccb completion
handlers.


# 1.97 04-Jan-2010 dlg

protect the ccb free queue with a mutex rather than splbio


# 1.96 03-Jan-2010 chl

change M_WAITOK --> M_WAITOK|M_CANFAIL

with input from marco@

ok marco@ krw@

this was ok looooooooong time ago but lost in my mailbox


Revision tags: OPENBSD_4_6_BASE
# 1.95 30-Apr-2009 marco

Add READ(16) & WRITE(16) commands.
ok krw


# 1.94 29-Apr-2009 marco

MFI_D_IOCTL should be commented out. No binary change.


# 1.93 04-Apr-2009 dlg

scrub more fields in the ccb when returning them to the free list after
theyve been used, in particular the mfi header flags which has a bit
that specifies if a command should be completed via the interrupt path.

if we use a ccb during boot we set that bit, but it isnt necessarily
cleared by things that use it later on. this means a ccb we expected to
complete via an interrupt never actually generates an interrupt or appears
in the reply queue. this obviously stalls the io.


# 1.92 29-Mar-2009 marco

spello


# 1.91 29-Mar-2009 dlg

when we steal the SYNC CACHE command in mfi_scsi_cmd we still have to
mark the xs as done and call scsi_done for it rather than just returning
COMPLETE.


# 1.90 29-Mar-2009 dlg

fix a small race in mfi_mgmt between the checking of a ccbs completion and
the sleep waiting for the completion. it is possible to get the interrupt
completing the command just before the tsleep, which will never get a
wakeup because the interrupt with the wakeup has already happened.


Revision tags: OPENBSD_4_5_BASE
# 1.89 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.


# 1.88 28-Jan-2009 marco

Add support for next generation megaraid sas raid controllers.
From Jim Giannoules <gortag@gmail.com>


# 1.87 31-Oct-2008 marco

Generalize function to obtain all details to do bio stuff. This is in
preparation to start showing unsused disks which will require all this
information to do the math.

While at it fix a size of hotspare volume bug.


# 1.86 30-Oct-2008 marco

Fix bug that when there are no volumes but there are hot spares it would
no show the hotspares.


# 1.85 28-Oct-2008 marco

Fix output when reporting on multivolume disk groups.

Reported by mitja@muzenic.net


# 1.84 27-Oct-2008 marco

Move some include stuff around


# 1.83 26-Oct-2008 marco

Space


# 1.82 23-Oct-2008 marco

Fix PR5645
ok dlg
tested beck and others


# 1.81 25-Sep-2008 krw

Initialize 'ssc' to NULL since we test it later. Shouldn't ever be
NULL at the point of test unless the device list is confused, but
be consistantly paranoid if we're going to be paranoid.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.80 16-Feb-2008 krw

Return NO_CCB and not TRY_AGAIN_LATER when running out of ccb's.
Eliminates 'not queued' errors reported on the mailing lists.

Tested by Michael (belenus at bsdmail dot de).

ok marco@


# 1.79 11-Feb-2008 dlg

add support for the mfi controllers with the ppc iops, aka, LSI SAS1078 or
Dell PERC6.

committed off a machine booting and rooting off a perc6. tested on a perc5
by marco@
ok marco@


# 1.78 26-Jan-2008 brad

Set the return value instead of returning right away so that the DMA
memory is actually synched.

ok dlg@


# 1.77 26-Jan-2008 dlg

sync dma mem back to the cpu on poll failure.

from mickey via pr5714


# 1.76 26-Jan-2008 dlg

despatch -> dispatch

disparate spellink fix from mickey


# 1.75 05-Nov-2007 krw

More scsi_done() at SPLBIO.


# 1.74 27-Sep-2007 chl

M_ZERO changes

ok dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.73 24-Jun-2007 dlg

rework sensor tasks to use the kernels generic workq rather than a special
kernel thread of its own. the api has changed (which will be fixed in the
manpage shortly) so all the users of sensor tasks that i can find have
been fixed too.

noone tested, so its going in to force people to run with it.
"put it in" deraadt@


# 1.72 29-May-2007 todd

sprinkle some SMALL_KERNEL to permit bio/softraid to run on boot media
ok marco@ then suggested deraadt@


# 1.71 22-Mar-2007 deraadt

split userland & kernel struct sensor/sensordev so that the addition
of new fields in the future is less disruptive. This is done similar
to how struct proc is handled for ps(1). ok jmc (man page changes)
tested fkr simon, and more suggestions from millert


Revision tags: OPENBSD_4_1_BASE
# 1.70 14-Feb-2007 dlg

bus_space does byte swapping to cope with host endianness for us, so remove
an unnecessary htole32().


# 1.69 13-Feb-2007 marco

Fix subtle x ? y : z bug when calling mfi_create_sgl. This worked because
during runtime the bug condition does not happen.

ok krw joris


# 1.68 08-Feb-2007 ray

Remove double semicolons.

From Pierre Riteau <pierre dot riteau at free dot fr>.

OK marco@.


# 1.67 23-Dec-2006 deraadt

adapt to new two-level sensor api; Constantine A. Murenin


# 1.66 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.65 31-Aug-2006 marco

Add sensor thread for individual sd devices.

tested dlg
ok dlg deraadt


# 1.64 30-Aug-2006 dlg

when determining the size of the volumes and disks we want how many
bytes each of them has, not the number of kilobytes. this solves the
"why am i dividing by 2" question. the answer is "you dont, you multiply
by 512".


# 1.63 28-Jul-2006 brad

make dmesg printing look a little bit nicer.


# 1.62 19-Jun-2006 marco

Factor for disk size is /2. Odd but tested on all mfis I have.


# 1.61 19-Jun-2006 miod

Everytime one forgets an argument in a printf-like function call, God kills
a kitten. Commiters, please think of the kittens when working on code.


# 1.60 19-Jun-2006 marco

Make a BGI (Back Ground Init) a scrub instead of rebuild.


# 1.59 19-Jun-2006 marco

Add hot spare support.


# 1.58 26-May-2006 marco

Add blinking for disks.


# 1.57 25-May-2006 marco

Move a int i; to top of function so that it compiles on non c99 compilers.
Pointed out by miod@

The enclosure id modifier didn't reflect reality so move it back to whatever
the raid card uses.


# 1.56 25-May-2006 marco

And add time and percentage to builds and check consistencies.


# 1.55 25-May-2006 marco

Add last bit of physcal disk stuff.
Remove bogus memset.
Hotspares still don't work.


# 1.54 25-May-2006 marco

Add physical device and read config structures.
Add initial part of BIOCDISK


# 1.53 23-May-2006 deraadt

commited with unused variable


# 1.52 23-May-2006 marco

Remove some debug cruft.


# 1.51 23-May-2006 marco

Add first half of physical disk data for bio.


# 1.50 22-May-2006 marco

Add support for raid 50 and 10 in bio.


# 1.49 22-May-2006 marco

Add mail box to mfi_mgmt to handle sub commands more gracefully.
Remove some debug crud that snuck in the TEST_UNIT_READY case.
Finish other half of BIOCVOL primitive.
Add several structures to fill out the BIOCVOL primitive.


# 1.48 22-May-2006 marco

Add first half of BIOCVOL primitive.


# 1.47 21-May-2006 marco

Do a giant flush of disk and raid-card memory when SYNCHONIZE_CACHE is called.


# 1.46 21-May-2006 marco

pretty up some debug statements.


# 1.45 21-May-2006 marco

Add bio alarm function.
Redo mfi_mgmt to deal with zero data commands.


# 1.44 21-May-2006 marco

Add generic management function.
Redo ccb_state flags so that we can actually sleep on it.
Redo mfi_get_info to use new mgmt function.
Add rw_locks for mgmt interface.
Make BIOCINQ dynamic.


# 1.43 21-May-2006 marco

Oops, helps to use the right structure field.
Use actual nr of physical disks present.


# 1.42 21-May-2006 marco

Add first BIOCINQ primitive.


# 1.41 18-May-2006 marco

Remove some debug cruft and pretty up some debug messages.


# 1.40 18-May-2006 marco

Kill splbio/splx in the interrupt handler.


# 1.39 18-May-2006 marco

And we have lift off! Was able to create a filesystem and write to the
filesystem.

Collapse both completion routines into one.
Fixup scsi error reporting in the completion routine.


# 1.38 17-May-2006 marco

Add completion routines.
Fix some bugs inside the interrupt handler.


# 1.37 17-May-2006 marco

Add mfi_get_info to obtain all kinds of fun information from the fw.
Print out whole info structure when debug is enabled.
Add a nice print with useful info during attach.


# 1.36 17-May-2006 marco

Refactor scsi path so that we can have a single sgl function for io and non-io
traffic.
Redo parameters on functions that were passing too many parameters around.


# 1.35 16-May-2006 marco

Nuke some { }


# 1.34 16-May-2006 marco

Move !xs->data case into mfi_start_xs.
Return proper sense data when a polling command fails.


# 1.33 16-May-2006 marco

Fix some more htole32 screw-ups.
Colapse all little SCSI functions into a single generic one.
Fix a bug in the SGE calculation.

This brings the driver up to post:
mfi0 at pci12 dev 14 function 0 "Dell PERC SAS" rev 0x00: Dell PERC 5/e irq 5
scsibus3 at mfi0: 2 targets
sd1 at scsibus3 targ 0 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd1: 237824MB, 237824 cyl, 64 head, 32 sec, 512 bytes/sec, 487063552 sec total
sd2 at scsibus3 targ 1 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd2: 34176MB, 34176 cyl, 64 head, 32 sec, 512 bytes/sec, 69992448 sec total


# 1.32 16-May-2006 marco

Fix some htole32 I missed.
Sprinkle more debug.


# 1.31 16-May-2006 marco

Add READ CAPACITY.


# 1.30 16-May-2006 marco

Oops PREREAD not PREWRITE.


# 1.29 16-May-2006 marco

Add TUR and make it send it directly to firmware.
Sprinkle some extra debug.


# 1.28 15-May-2006 marco

Clear all relevant ccb fields when mfi_put_ccb frees a ccb.


# 1.27 15-May-2006 marco

Oops don't send command twice to firmware when polling.


# 1.26 15-May-2006 marco

Add INQUIRY command.
Add sgl magic.


# 1.25 10-May-2006 marco

Add some airplane code.

add bio hooks.
add scsi entry point for io.


# 1.24 26-Apr-2006 marco

Fix some debug prints.


# 1.23 21-Apr-2006 marco

typo


# 1.22 21-Apr-2006 marco

Add mfi_poll and use the new shiny function to setup all the hardware queues.
Lots of ideas from the FreeBSD driver.


# 1.21 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.20 20-Apr-2006 dlg

marco hates typedefs as much as i do, so he asked me to clean mfi like i
just did with ami. this gets rid of the typedef for the ccb lists.

also uses TAILQ_FIRST to get ccbs off the freelist. this is a proactive
fix for a lint teary.


# 1.19 18-Apr-2006 marco

It helps to initialize a queue before usage.


# 1.18 18-Apr-2006 marco

Actually add ccbs to the queue.
Fix the error path for mfi_init_ccb.
Alter dmamap for io.


# 1.17 17-Apr-2006 marco

Sprinkle more debug. Remove 64 byte boundary; it doesn't seem to like it.
Hack around 64 byte boundary for the frames for now.


# 1.16 17-Apr-2006 marco

Setup ccbs and clean up ccb structure.


# 1.15 16-Apr-2006 marco

Oops, make mfi_allocmem always use 64 byte boundaries since frames have to
have that alignment. It doesn't matter for the other consumers of the
function.


# 1.14 16-Apr-2006 marco

Add frame memory and sglist allocation.


# 1.13 16-Apr-2006 marco

Make memory access use macro.


# 1.12 16-Apr-2006 marco

typo


# 1.11 16-Apr-2006 marco

Add get and put ccb functions. Shuffle some more definitions.


# 1.10 16-Apr-2006 marco

Nicer print when context is invalid.


# 1.9 16-Apr-2006 marco

Shuffle some #defines.
Fix comments.
Add human readable enable intrrupt #define.


# 1.8 16-Apr-2006 marco

Add interrupt handler. Idea borrowed from FreeBSD since it is much nicer
than the Linux one.


# 1.7 07-Apr-2006 marco

Replace bus_space functions with generic ones that do barriers.


# 1.6 07-Apr-2006 marco

Add memory allocator functions.


# 1.5 07-Apr-2006 marco

Print state in debug. Change return vales to 1 instead of ENXIO.


# 1.4 07-Apr-2006 marco

Make a better debug mechanism.


# 1.3 07-Apr-2006 marco

Enable mfi_transition_fw() original code from FreeBSD.


# 1.2 06-Apr-2006 marco

Add fw transition logic.


# 1.1 06-Apr-2006 marco

Add skeleton driver for MegaRAID SAS.


# 1.169 14-Aug-2018 jmatthew

return ENOTTY rather than EINVAL to indicate an ioctl hasn't been handled

ok dlg@ deraadt@ kettenis@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.168 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.167 02-Feb-2017 dlg

copy the mbox into the dcmd struct, not the pointer to the mbox.

makes bioctl work on mfi(4) again.

while here memset a few mboxes before using them.

bioctl breakage reported by jason george


# 1.166 23-Jan-2017 dlg

represent the mbox layout with union instead of an array of bytes.

memcpying uint16_ts into inconsistently addressed offsets is hard
to read, and this makes future work easier to implement.

tested on mfi(4) and mfii(4)


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.165 09-Sep-2015 deraadt

sizes for free(); ok sthen


Revision tags: OPENBSD_5_8_BASE
# 1.164 29-May-2015 uebayasi

Initial addition of ``Patrol Read'' support in bio(4), biocto(8), and
mfi(4). Based on FreeBSD, but done without mfiutil(8).

OK deraadt@


# 1.163 18-May-2015 mikeb

Prevent splassert from firing during sd_flush which runs "cold"

While mfi(4) should pass SCSI transfer flags (e.g. SCSI_POLL and
SCSI_NOSLEEP) down to the management function, make it at least
use "cold" consistently for now.

ok dlg


# 1.162 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.161 08-Mar-2015 dlg

properly set sgl related flags on skinny controllers. this fixes
io against physical disks on my dell perc h310s. logical disks still
work fine.

ok deraadt@ yasuoka@


# 1.160 08-Feb-2015 yasuoka

Fix mfi ioctl to set drive state properly.
diff from Tsubai Masanari

test dlg jmatthew
ok dlg


# 1.159 09-Jan-2015 yasuoka

Add support DIOC{G,S}CACHE to mfi(4). Cache of disk on mfi(4) will
be enabled by default. Also if the controller doesn't have any RAM,
the cache on the physical disk will be enabled.

discuss with jsg tsubai
ok dlg


# 1.158 19-Dec-2014 deraadt

another handful of bcopy -> memcpy because there is no overlap


# 1.157 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.156 09-Sep-2014 dlg

mark the interrupt handler mpsafe, and give up biglock in the scsi cmd
submission paths. take biglock again when calling back into the scsi
stack.

tested on a variety of cards here, including the skinny mfis on the
firewall next to mpsafe myx.


# 1.155 15-Aug-2014 yasuoka

Create a function which loads sgd in the mfi_iop_ops struct so that skinny
adapters can use "IEEE sgl".

tested dlg yasuoka
ok dlg jsg


Revision tags: OPENBSD_5_6_BASE
# 1.154 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.153 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.152 04-May-2014 sf

format string fixes for bus_addr_t and bus_size_t

bus_addr_t and bus_size_t are u_long everywhere

ok kettenis@


Revision tags: OPENBSD_5_5_BASE
# 1.151 20-Feb-2014 kettenis

revert previous commit; didn't intend to commit those bits


# 1.150 20-Feb-2014 kettenis

Avoid printing the "nvram corrupt" message for onboard 2200s found on Sun
hardware.

ok dlg@, jmatthew@


# 1.149 04-Dec-2013 dlg

mfi_refresh_sensors calls mfi_ioctl_vol which calls mfi_bio_getitall, which
replaces pointers in the softc and all sorts of fun stuff. this protects
the call to bio_getitall with the sc_lock the ioctl path uses, so we dont
get panics like those reported on bugs@ recently.

ok deraadt@


# 1.148 23-Oct-2013 kettenis

Add support for displaying the cache write policy of RAID volumes to bioctl(8)
and make mfi(4) pass up the necessary information. Adding support for other
RAID controllers is left as an excercise to the reader.

ok deraadt@


# 1.147 09-Oct-2013 jmatthew

Include the 'state of health' field in the bbu ok sensor value.
The dell perc 6/i sets this to zero (meaning bad) when it
decides the battery doesn't have enough capacity for it to
allow write back mode, but doesn't set any of the other flags
to tell us why.

ok dlg@, tested by sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.146 18-May-2013 jmc

enw->new in comment;
spotted by krw, missed by jsg, and forwarded From: Alexey Suslikov


# 1.145 08-May-2013 jsg

fix some leaks in error paths
ok fgsch@ krw@ kettenis@


# 1.144 03-May-2013 dlg

break out the battery status into excruciating detail. makes it harder for
$VENDOR to complain about a lack of diagnostic material from their crappy
mgmt tools if you're not running an operating system they support.


# 1.143 02-May-2013 dlg

always attach the battery sensor if the adapter lets us query it.
newly replaced batteries dont show up immediately.


# 1.142 01-May-2013 dlg

provide a sensor for the battery backup unit (bbu) on mfi boards that
support it.

now i can tell (a bit better) why io might be slow on some of my boxes.


# 1.141 01-May-2013 dlg

dont need to walk alldevs during sensor creation looking for the logical
disk scsibus when we record that in mfi_attach.

also happens to get rid of a logic error that let it come out of the loop
on alldevs with a reference to something that wasnt the logical disk
scsibus and use that.


# 1.140 30-Apr-2013 dlg

use MR_DCMD consistently. some MD_DCMD was in there somehow.


# 1.139 07-Apr-2013 dlg

david imhoff points out that the error handling in mfi_init_ccb gets the
index to which ccb to free wrong.

this takes the logic from mpi/mpii/mfii which pulls the ready ccbs off
the free list rather than rely on the current index from the for loop
that we failed inside of.

thanks to david for finding this out.


Revision tags: OPENBSD_5_3_BASE
# 1.138 12-Sep-2012 haesbaert

Make sure we don't sleep on autoconf.

ok mikeb


# 1.137 17-Aug-2012 dlg

add support for "physical devices" on skinny controllers.

these controllers let you specify disks that should be accessed directly
rather than be part of logical volumes. apparently you can plug in things
like tape drives too.

anyway, physical devices are exposed via a separate scsibus attached to
mfi.

ok mikeb@


# 1.136 16-Aug-2012 dlg

fix mfi_poll by having it do delays between loops, and breaking on
timeouts. how embarrassment.

implement mfi_exec for doing sync executions of commands in process
contexts and cut mfi_mgmt over to it.


# 1.135 16-Aug-2012 dlg

rework mfi_poll so it will do all the completions on a ccb including
calling the done handler.

this makes it consistently complete scsi io with all the proper error
checking.


# 1.134 16-Aug-2012 dlg

stop passing mfi_softc around as a member of the ccb, consistently give it
as the first argument to functions. like mfii.


# 1.133 16-Aug-2012 dlg

scrub ccbs when we're about to use them, not when we put them back
on the free list. ccbs can be reused, so we dont want old state screwing up
new commands.


# 1.132 16-Aug-2012 dlg

move the dma syncs for the ccb data into ccb_done, so we can do it once
rather than put the code everywhere.


# 1.131 16-Aug-2012 dlg

fix up the dma sync for the command frame in mfi_done.


# 1.130 14-Aug-2012 dlg

use scsi_get_link to find out the name of a child device for bioctl rather
than snoop scsi commands and copy it in an io path.

no functional change, but the code has one less XXX now.


# 1.129 14-Aug-2012 dlg

expose the max number of logical volumes the hardware supports as the width
of its scsibus. only advertise 1 lun on logical volumes instead of letting
the midlayer fix it up to 8.

give every target on the bus max_cmds openings. iopools means they will
properly share access to them.

this in particular is useful on skinny controllers which only advertise 31
command slots. if you have 16 volumes, theyll only get 1 opening each with
the old maths. this way round the ones that are busy will share the slots.

tested on a perc5 with two volumes and hard workloads.


# 1.128 14-Aug-2012 dlg

print the boards name (eg, perc 5/i) according to the firmware like mfii.

ok deraadt@


# 1.127 14-Aug-2012 dlg

move knowledge of the location of the inbound doorbell out of code in
transition_firmware into a member of the iop structures.

ok mikeb@ haesbaert@


# 1.126 13-Aug-2012 dlg

get rid of the last foo_lo and foo_hi bits i could find in the hardware
structures and use htole64 instead of htole32(addr >> 32); htole32(addr);

gets rid of "handy" stack variables to get the dva to 64bits.

sprinkle some more byte swaps for things that should have it.

tested on a perc5 (xscale)


# 1.125 13-Aug-2012 dlg

do appropriate bus_dmamapy_syncs around the pcq/completion ring.

tested on a perc5 (xscale)


# 1.124 13-Aug-2012 dlg

replace uint32_ts for hi and lo addresses in the mfi_init_ hardware
descriptors with single uint64_ts. theyre not some weird middle
endian thing. this makes the code more readable.

add some missing htole32s to the code while here.

tested on a perc5 (xscale).


# 1.123 11-Aug-2012 dlg

the producer/consumer values are used by the device, which is little
endian. do appropriate byteswapping for when the host cpu uses them.

tested on a perc5 (xscale) in an amd64.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.122 12-Jan-2012 dlg

add support for skinny variants.

from Alexey Suslikov
reviewed by marco


Revision tags: OPENBSD_5_0_BASE
# 1.121 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.120 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.119 09-Apr-2011 marco

add all 64 bit dma plumbing but stick with 32 for now by default.

ok deraadt


# 1.118 09-Apr-2011 marco

make sure the upper 32 bits are always written to instead of assuming it
is 0.

ok deraadt.


# 1.117 08-Apr-2011 marco

kill some stray spaces


# 1.116 08-Apr-2011 marco

rename wiat channel to something less than 8 chars.

prompted by deraadt


# 1.115 08-Apr-2011 marco

use dma_alloc for transient management commands.

prodded and ok deraadt


Revision tags: OPENBSD_4_9_BASE
# 1.114 30-Dec-2010 dlg

cut mfi over to using iopools.

this gets rid of NO_CCB, provides better scheduling of io between busy
logical volumes on the same controller, and makes the ioctl and sensor
paths more reliable.

this is the least intrusive version of this change i could come up with. it
only took 4 or 5 goes...

ok marco@
deraadt@ says this is a good time for this change.


# 1.113 24-Sep-2010 dlg

no use setting cmd in mfi_ioctl_setstate if you never use it.


# 1.112 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


# 1.111 29-Aug-2010 dlg

the scsi completion code thinks that if you dont get MFI_STAT_OK
back from the chip on a command then the command completely failed.
MFI_STAT_SCSI_DONE_WITH_ERROR really means the command completed
fine, but there's some sense data too. this tweaks the handling to
be more appropriate, as per the linux and solaris drivers.

timed out waiting for beck@
putting this in cos its obviously more correct than the current code.


Revision tags: OPENBSD_4_8_BASE
# 1.110 22-Jul-2010 matthew

SCSI HBA drivers are supposed to get their SCSI CDBs from xs->cmd, not
xs->cmdstore.

ok krw@ a while back (contingent upon testing), and deraadt@ says this
has been in snapshots for weeks now.


# 1.109 01-Jul-2010 matthew

Change scsibus(4)'s scsi_link array to an SLIST to save memory on
sparsely populated buses.

ok dlg@, krw@


# 1.108 30-Jun-2010 mk

Use SLIST for the ccb free list.

ok krw, discontent grunts from marco.


# 1.107 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.106 15-Jun-2010 dlg

dont pass the dev_t from the scsi device drivers into the midlayer for
ioctl requests, and dont pass the proc pointers around for any ioctl
requests in scsi land at all. neither were used, so trim the fat.

ok krw@ marco@


# 1.105 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.104 16-May-2010 nicm

Use a temporary variable for now to sidestep -Wbounded checking when
copying vendor[8]/product[16]/revision[4] out of struct scsi_inquiry_data
together with one memcopy.

ok krw


# 1.103 22-Apr-2010 oga

use BUS_DMA_ZERO on alloc instead of bzeroing after.

ok dlg@, marco@


# 1.102 10-Apr-2010 marco

grrr var names in protos


# 1.101 10-Apr-2010 marco

sprinkle some bus_dmamap_sync around frame access.
prompted by oga


# 1.100 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.99 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.98 04-Jan-2010 dlg

rename ccb_xs to ccb_cookie and change its type from a scsi_xfer * to a
void *. this lets us pass things other than scsi_xfers to ccb completion
handlers.


# 1.97 04-Jan-2010 dlg

protect the ccb free queue with a mutex rather than splbio


# 1.96 03-Jan-2010 chl

change M_WAITOK --> M_WAITOK|M_CANFAIL

with input from marco@

ok marco@ krw@

this was ok looooooooong time ago but lost in my mailbox


Revision tags: OPENBSD_4_6_BASE
# 1.95 30-Apr-2009 marco

Add READ(16) & WRITE(16) commands.
ok krw


# 1.94 29-Apr-2009 marco

MFI_D_IOCTL should be commented out. No binary change.


# 1.93 04-Apr-2009 dlg

scrub more fields in the ccb when returning them to the free list after
theyve been used, in particular the mfi header flags which has a bit
that specifies if a command should be completed via the interrupt path.

if we use a ccb during boot we set that bit, but it isnt necessarily
cleared by things that use it later on. this means a ccb we expected to
complete via an interrupt never actually generates an interrupt or appears
in the reply queue. this obviously stalls the io.


# 1.92 29-Mar-2009 marco

spello


# 1.91 29-Mar-2009 dlg

when we steal the SYNC CACHE command in mfi_scsi_cmd we still have to
mark the xs as done and call scsi_done for it rather than just returning
COMPLETE.


# 1.90 29-Mar-2009 dlg

fix a small race in mfi_mgmt between the checking of a ccbs completion and
the sleep waiting for the completion. it is possible to get the interrupt
completing the command just before the tsleep, which will never get a
wakeup because the interrupt with the wakeup has already happened.


Revision tags: OPENBSD_4_5_BASE
# 1.89 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.


# 1.88 28-Jan-2009 marco

Add support for next generation megaraid sas raid controllers.
From Jim Giannoules <gortag@gmail.com>


# 1.87 31-Oct-2008 marco

Generalize function to obtain all details to do bio stuff. This is in
preparation to start showing unsused disks which will require all this
information to do the math.

While at it fix a size of hotspare volume bug.


# 1.86 30-Oct-2008 marco

Fix bug that when there are no volumes but there are hot spares it would
no show the hotspares.


# 1.85 28-Oct-2008 marco

Fix output when reporting on multivolume disk groups.

Reported by mitja@muzenic.net


# 1.84 27-Oct-2008 marco

Move some include stuff around


# 1.83 26-Oct-2008 marco

Space


# 1.82 23-Oct-2008 marco

Fix PR5645
ok dlg
tested beck and others


# 1.81 25-Sep-2008 krw

Initialize 'ssc' to NULL since we test it later. Shouldn't ever be
NULL at the point of test unless the device list is confused, but
be consistantly paranoid if we're going to be paranoid.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.80 16-Feb-2008 krw

Return NO_CCB and not TRY_AGAIN_LATER when running out of ccb's.
Eliminates 'not queued' errors reported on the mailing lists.

Tested by Michael (belenus at bsdmail dot de).

ok marco@


# 1.79 11-Feb-2008 dlg

add support for the mfi controllers with the ppc iops, aka, LSI SAS1078 or
Dell PERC6.

committed off a machine booting and rooting off a perc6. tested on a perc5
by marco@
ok marco@


# 1.78 26-Jan-2008 brad

Set the return value instead of returning right away so that the DMA
memory is actually synched.

ok dlg@


# 1.77 26-Jan-2008 dlg

sync dma mem back to the cpu on poll failure.

from mickey via pr5714


# 1.76 26-Jan-2008 dlg

despatch -> dispatch

disparate spellink fix from mickey


# 1.75 05-Nov-2007 krw

More scsi_done() at SPLBIO.


# 1.74 27-Sep-2007 chl

M_ZERO changes

ok dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.73 24-Jun-2007 dlg

rework sensor tasks to use the kernels generic workq rather than a special
kernel thread of its own. the api has changed (which will be fixed in the
manpage shortly) so all the users of sensor tasks that i can find have
been fixed too.

noone tested, so its going in to force people to run with it.
"put it in" deraadt@


# 1.72 29-May-2007 todd

sprinkle some SMALL_KERNEL to permit bio/softraid to run on boot media
ok marco@ then suggested deraadt@


# 1.71 22-Mar-2007 deraadt

split userland & kernel struct sensor/sensordev so that the addition
of new fields in the future is less disruptive. This is done similar
to how struct proc is handled for ps(1). ok jmc (man page changes)
tested fkr simon, and more suggestions from millert


Revision tags: OPENBSD_4_1_BASE
# 1.70 14-Feb-2007 dlg

bus_space does byte swapping to cope with host endianness for us, so remove
an unnecessary htole32().


# 1.69 13-Feb-2007 marco

Fix subtle x ? y : z bug when calling mfi_create_sgl. This worked because
during runtime the bug condition does not happen.

ok krw joris


# 1.68 08-Feb-2007 ray

Remove double semicolons.

From Pierre Riteau <pierre dot riteau at free dot fr>.

OK marco@.


# 1.67 23-Dec-2006 deraadt

adapt to new two-level sensor api; Constantine A. Murenin


# 1.66 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.65 31-Aug-2006 marco

Add sensor thread for individual sd devices.

tested dlg
ok dlg deraadt


# 1.64 30-Aug-2006 dlg

when determining the size of the volumes and disks we want how many
bytes each of them has, not the number of kilobytes. this solves the
"why am i dividing by 2" question. the answer is "you dont, you multiply
by 512".


# 1.63 28-Jul-2006 brad

make dmesg printing look a little bit nicer.


# 1.62 19-Jun-2006 marco

Factor for disk size is /2. Odd but tested on all mfis I have.


# 1.61 19-Jun-2006 miod

Everytime one forgets an argument in a printf-like function call, God kills
a kitten. Commiters, please think of the kittens when working on code.


# 1.60 19-Jun-2006 marco

Make a BGI (Back Ground Init) a scrub instead of rebuild.


# 1.59 19-Jun-2006 marco

Add hot spare support.


# 1.58 26-May-2006 marco

Add blinking for disks.


# 1.57 25-May-2006 marco

Move a int i; to top of function so that it compiles on non c99 compilers.
Pointed out by miod@

The enclosure id modifier didn't reflect reality so move it back to whatever
the raid card uses.


# 1.56 25-May-2006 marco

And add time and percentage to builds and check consistencies.


# 1.55 25-May-2006 marco

Add last bit of physcal disk stuff.
Remove bogus memset.
Hotspares still don't work.


# 1.54 25-May-2006 marco

Add physical device and read config structures.
Add initial part of BIOCDISK


# 1.53 23-May-2006 deraadt

commited with unused variable


# 1.52 23-May-2006 marco

Remove some debug cruft.


# 1.51 23-May-2006 marco

Add first half of physical disk data for bio.


# 1.50 22-May-2006 marco

Add support for raid 50 and 10 in bio.


# 1.49 22-May-2006 marco

Add mail box to mfi_mgmt to handle sub commands more gracefully.
Remove some debug crud that snuck in the TEST_UNIT_READY case.
Finish other half of BIOCVOL primitive.
Add several structures to fill out the BIOCVOL primitive.


# 1.48 22-May-2006 marco

Add first half of BIOCVOL primitive.


# 1.47 21-May-2006 marco

Do a giant flush of disk and raid-card memory when SYNCHONIZE_CACHE is called.


# 1.46 21-May-2006 marco

pretty up some debug statements.


# 1.45 21-May-2006 marco

Add bio alarm function.
Redo mfi_mgmt to deal with zero data commands.


# 1.44 21-May-2006 marco

Add generic management function.
Redo ccb_state flags so that we can actually sleep on it.
Redo mfi_get_info to use new mgmt function.
Add rw_locks for mgmt interface.
Make BIOCINQ dynamic.


# 1.43 21-May-2006 marco

Oops, helps to use the right structure field.
Use actual nr of physical disks present.


# 1.42 21-May-2006 marco

Add first BIOCINQ primitive.


# 1.41 18-May-2006 marco

Remove some debug cruft and pretty up some debug messages.


# 1.40 18-May-2006 marco

Kill splbio/splx in the interrupt handler.


# 1.39 18-May-2006 marco

And we have lift off! Was able to create a filesystem and write to the
filesystem.

Collapse both completion routines into one.
Fixup scsi error reporting in the completion routine.


# 1.38 17-May-2006 marco

Add completion routines.
Fix some bugs inside the interrupt handler.


# 1.37 17-May-2006 marco

Add mfi_get_info to obtain all kinds of fun information from the fw.
Print out whole info structure when debug is enabled.
Add a nice print with useful info during attach.


# 1.36 17-May-2006 marco

Refactor scsi path so that we can have a single sgl function for io and non-io
traffic.
Redo parameters on functions that were passing too many parameters around.


# 1.35 16-May-2006 marco

Nuke some { }


# 1.34 16-May-2006 marco

Move !xs->data case into mfi_start_xs.
Return proper sense data when a polling command fails.


# 1.33 16-May-2006 marco

Fix some more htole32 screw-ups.
Colapse all little SCSI functions into a single generic one.
Fix a bug in the SGE calculation.

This brings the driver up to post:
mfi0 at pci12 dev 14 function 0 "Dell PERC SAS" rev 0x00: Dell PERC 5/e irq 5
scsibus3 at mfi0: 2 targets
sd1 at scsibus3 targ 0 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd1: 237824MB, 237824 cyl, 64 head, 32 sec, 512 bytes/sec, 487063552 sec total
sd2 at scsibus3 targ 1 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd2: 34176MB, 34176 cyl, 64 head, 32 sec, 512 bytes/sec, 69992448 sec total


# 1.32 16-May-2006 marco

Fix some htole32 I missed.
Sprinkle more debug.


# 1.31 16-May-2006 marco

Add READ CAPACITY.


# 1.30 16-May-2006 marco

Oops PREREAD not PREWRITE.


# 1.29 16-May-2006 marco

Add TUR and make it send it directly to firmware.
Sprinkle some extra debug.


# 1.28 15-May-2006 marco

Clear all relevant ccb fields when mfi_put_ccb frees a ccb.


# 1.27 15-May-2006 marco

Oops don't send command twice to firmware when polling.


# 1.26 15-May-2006 marco

Add INQUIRY command.
Add sgl magic.


# 1.25 10-May-2006 marco

Add some airplane code.

add bio hooks.
add scsi entry point for io.


# 1.24 26-Apr-2006 marco

Fix some debug prints.


# 1.23 21-Apr-2006 marco

typo


# 1.22 21-Apr-2006 marco

Add mfi_poll and use the new shiny function to setup all the hardware queues.
Lots of ideas from the FreeBSD driver.


# 1.21 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.20 20-Apr-2006 dlg

marco hates typedefs as much as i do, so he asked me to clean mfi like i
just did with ami. this gets rid of the typedef for the ccb lists.

also uses TAILQ_FIRST to get ccbs off the freelist. this is a proactive
fix for a lint teary.


# 1.19 18-Apr-2006 marco

It helps to initialize a queue before usage.


# 1.18 18-Apr-2006 marco

Actually add ccbs to the queue.
Fix the error path for mfi_init_ccb.
Alter dmamap for io.


# 1.17 17-Apr-2006 marco

Sprinkle more debug. Remove 64 byte boundary; it doesn't seem to like it.
Hack around 64 byte boundary for the frames for now.


# 1.16 17-Apr-2006 marco

Setup ccbs and clean up ccb structure.


# 1.15 16-Apr-2006 marco

Oops, make mfi_allocmem always use 64 byte boundaries since frames have to
have that alignment. It doesn't matter for the other consumers of the
function.


# 1.14 16-Apr-2006 marco

Add frame memory and sglist allocation.


# 1.13 16-Apr-2006 marco

Make memory access use macro.


# 1.12 16-Apr-2006 marco

typo


# 1.11 16-Apr-2006 marco

Add get and put ccb functions. Shuffle some more definitions.


# 1.10 16-Apr-2006 marco

Nicer print when context is invalid.


# 1.9 16-Apr-2006 marco

Shuffle some #defines.
Fix comments.
Add human readable enable intrrupt #define.


# 1.8 16-Apr-2006 marco

Add interrupt handler. Idea borrowed from FreeBSD since it is much nicer
than the Linux one.


# 1.7 07-Apr-2006 marco

Replace bus_space functions with generic ones that do barriers.


# 1.6 07-Apr-2006 marco

Add memory allocator functions.


# 1.5 07-Apr-2006 marco

Print state in debug. Change return vales to 1 instead of ENXIO.


# 1.4 07-Apr-2006 marco

Make a better debug mechanism.


# 1.3 07-Apr-2006 marco

Enable mfi_transition_fw() original code from FreeBSD.


# 1.2 06-Apr-2006 marco

Add fw transition logic.


# 1.1 06-Apr-2006 marco

Add skeleton driver for MegaRAID SAS.


Revision tags: OPENBSD_6_2_BASE
# 1.168 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.167 02-Feb-2017 dlg

copy the mbox into the dcmd struct, not the pointer to the mbox.

makes bioctl work on mfi(4) again.

while here memset a few mboxes before using them.

bioctl breakage reported by jason george


# 1.166 23-Jan-2017 dlg

represent the mbox layout with union instead of an array of bytes.

memcpying uint16_ts into inconsistently addressed offsets is hard
to read, and this makes future work easier to implement.

tested on mfi(4) and mfii(4)


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.165 09-Sep-2015 deraadt

sizes for free(); ok sthen


Revision tags: OPENBSD_5_8_BASE
# 1.164 29-May-2015 uebayasi

Initial addition of ``Patrol Read'' support in bio(4), biocto(8), and
mfi(4). Based on FreeBSD, but done without mfiutil(8).

OK deraadt@


# 1.163 18-May-2015 mikeb

Prevent splassert from firing during sd_flush which runs "cold"

While mfi(4) should pass SCSI transfer flags (e.g. SCSI_POLL and
SCSI_NOSLEEP) down to the management function, make it at least
use "cold" consistently for now.

ok dlg


# 1.162 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.161 08-Mar-2015 dlg

properly set sgl related flags on skinny controllers. this fixes
io against physical disks on my dell perc h310s. logical disks still
work fine.

ok deraadt@ yasuoka@


# 1.160 08-Feb-2015 yasuoka

Fix mfi ioctl to set drive state properly.
diff from Tsubai Masanari

test dlg jmatthew
ok dlg


# 1.159 09-Jan-2015 yasuoka

Add support DIOC{G,S}CACHE to mfi(4). Cache of disk on mfi(4) will
be enabled by default. Also if the controller doesn't have any RAM,
the cache on the physical disk will be enabled.

discuss with jsg tsubai
ok dlg


# 1.158 19-Dec-2014 deraadt

another handful of bcopy -> memcpy because there is no overlap


# 1.157 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.156 09-Sep-2014 dlg

mark the interrupt handler mpsafe, and give up biglock in the scsi cmd
submission paths. take biglock again when calling back into the scsi
stack.

tested on a variety of cards here, including the skinny mfis on the
firewall next to mpsafe myx.


# 1.155 15-Aug-2014 yasuoka

Create a function which loads sgd in the mfi_iop_ops struct so that skinny
adapters can use "IEEE sgl".

tested dlg yasuoka
ok dlg jsg


Revision tags: OPENBSD_5_6_BASE
# 1.154 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.153 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.152 04-May-2014 sf

format string fixes for bus_addr_t and bus_size_t

bus_addr_t and bus_size_t are u_long everywhere

ok kettenis@


Revision tags: OPENBSD_5_5_BASE
# 1.151 20-Feb-2014 kettenis

revert previous commit; didn't intend to commit those bits


# 1.150 20-Feb-2014 kettenis

Avoid printing the "nvram corrupt" message for onboard 2200s found on Sun
hardware.

ok dlg@, jmatthew@


# 1.149 04-Dec-2013 dlg

mfi_refresh_sensors calls mfi_ioctl_vol which calls mfi_bio_getitall, which
replaces pointers in the softc and all sorts of fun stuff. this protects
the call to bio_getitall with the sc_lock the ioctl path uses, so we dont
get panics like those reported on bugs@ recently.

ok deraadt@


# 1.148 23-Oct-2013 kettenis

Add support for displaying the cache write policy of RAID volumes to bioctl(8)
and make mfi(4) pass up the necessary information. Adding support for other
RAID controllers is left as an excercise to the reader.

ok deraadt@


# 1.147 09-Oct-2013 jmatthew

Include the 'state of health' field in the bbu ok sensor value.
The dell perc 6/i sets this to zero (meaning bad) when it
decides the battery doesn't have enough capacity for it to
allow write back mode, but doesn't set any of the other flags
to tell us why.

ok dlg@, tested by sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.146 18-May-2013 jmc

enw->new in comment;
spotted by krw, missed by jsg, and forwarded From: Alexey Suslikov


# 1.145 08-May-2013 jsg

fix some leaks in error paths
ok fgsch@ krw@ kettenis@


# 1.144 03-May-2013 dlg

break out the battery status into excruciating detail. makes it harder for
$VENDOR to complain about a lack of diagnostic material from their crappy
mgmt tools if you're not running an operating system they support.


# 1.143 02-May-2013 dlg

always attach the battery sensor if the adapter lets us query it.
newly replaced batteries dont show up immediately.


# 1.142 01-May-2013 dlg

provide a sensor for the battery backup unit (bbu) on mfi boards that
support it.

now i can tell (a bit better) why io might be slow on some of my boxes.


# 1.141 01-May-2013 dlg

dont need to walk alldevs during sensor creation looking for the logical
disk scsibus when we record that in mfi_attach.

also happens to get rid of a logic error that let it come out of the loop
on alldevs with a reference to something that wasnt the logical disk
scsibus and use that.


# 1.140 30-Apr-2013 dlg

use MR_DCMD consistently. some MD_DCMD was in there somehow.


# 1.139 07-Apr-2013 dlg

david imhoff points out that the error handling in mfi_init_ccb gets the
index to which ccb to free wrong.

this takes the logic from mpi/mpii/mfii which pulls the ready ccbs off
the free list rather than rely on the current index from the for loop
that we failed inside of.

thanks to david for finding this out.


Revision tags: OPENBSD_5_3_BASE
# 1.138 12-Sep-2012 haesbaert

Make sure we don't sleep on autoconf.

ok mikeb


# 1.137 17-Aug-2012 dlg

add support for "physical devices" on skinny controllers.

these controllers let you specify disks that should be accessed directly
rather than be part of logical volumes. apparently you can plug in things
like tape drives too.

anyway, physical devices are exposed via a separate scsibus attached to
mfi.

ok mikeb@


# 1.136 16-Aug-2012 dlg

fix mfi_poll by having it do delays between loops, and breaking on
timeouts. how embarrassment.

implement mfi_exec for doing sync executions of commands in process
contexts and cut mfi_mgmt over to it.


# 1.135 16-Aug-2012 dlg

rework mfi_poll so it will do all the completions on a ccb including
calling the done handler.

this makes it consistently complete scsi io with all the proper error
checking.


# 1.134 16-Aug-2012 dlg

stop passing mfi_softc around as a member of the ccb, consistently give it
as the first argument to functions. like mfii.


# 1.133 16-Aug-2012 dlg

scrub ccbs when we're about to use them, not when we put them back
on the free list. ccbs can be reused, so we dont want old state screwing up
new commands.


# 1.132 16-Aug-2012 dlg

move the dma syncs for the ccb data into ccb_done, so we can do it once
rather than put the code everywhere.


# 1.131 16-Aug-2012 dlg

fix up the dma sync for the command frame in mfi_done.


# 1.130 14-Aug-2012 dlg

use scsi_get_link to find out the name of a child device for bioctl rather
than snoop scsi commands and copy it in an io path.

no functional change, but the code has one less XXX now.


# 1.129 14-Aug-2012 dlg

expose the max number of logical volumes the hardware supports as the width
of its scsibus. only advertise 1 lun on logical volumes instead of letting
the midlayer fix it up to 8.

give every target on the bus max_cmds openings. iopools means they will
properly share access to them.

this in particular is useful on skinny controllers which only advertise 31
command slots. if you have 16 volumes, theyll only get 1 opening each with
the old maths. this way round the ones that are busy will share the slots.

tested on a perc5 with two volumes and hard workloads.


# 1.128 14-Aug-2012 dlg

print the boards name (eg, perc 5/i) according to the firmware like mfii.

ok deraadt@


# 1.127 14-Aug-2012 dlg

move knowledge of the location of the inbound doorbell out of code in
transition_firmware into a member of the iop structures.

ok mikeb@ haesbaert@


# 1.126 13-Aug-2012 dlg

get rid of the last foo_lo and foo_hi bits i could find in the hardware
structures and use htole64 instead of htole32(addr >> 32); htole32(addr);

gets rid of "handy" stack variables to get the dva to 64bits.

sprinkle some more byte swaps for things that should have it.

tested on a perc5 (xscale)


# 1.125 13-Aug-2012 dlg

do appropriate bus_dmamapy_syncs around the pcq/completion ring.

tested on a perc5 (xscale)


# 1.124 13-Aug-2012 dlg

replace uint32_ts for hi and lo addresses in the mfi_init_ hardware
descriptors with single uint64_ts. theyre not some weird middle
endian thing. this makes the code more readable.

add some missing htole32s to the code while here.

tested on a perc5 (xscale).


# 1.123 11-Aug-2012 dlg

the producer/consumer values are used by the device, which is little
endian. do appropriate byteswapping for when the host cpu uses them.

tested on a perc5 (xscale) in an amd64.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.122 12-Jan-2012 dlg

add support for skinny variants.

from Alexey Suslikov
reviewed by marco


Revision tags: OPENBSD_5_0_BASE
# 1.121 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.120 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.119 09-Apr-2011 marco

add all 64 bit dma plumbing but stick with 32 for now by default.

ok deraadt


# 1.118 09-Apr-2011 marco

make sure the upper 32 bits are always written to instead of assuming it
is 0.

ok deraadt.


# 1.117 08-Apr-2011 marco

kill some stray spaces


# 1.116 08-Apr-2011 marco

rename wiat channel to something less than 8 chars.

prompted by deraadt


# 1.115 08-Apr-2011 marco

use dma_alloc for transient management commands.

prodded and ok deraadt


Revision tags: OPENBSD_4_9_BASE
# 1.114 30-Dec-2010 dlg

cut mfi over to using iopools.

this gets rid of NO_CCB, provides better scheduling of io between busy
logical volumes on the same controller, and makes the ioctl and sensor
paths more reliable.

this is the least intrusive version of this change i could come up with. it
only took 4 or 5 goes...

ok marco@
deraadt@ says this is a good time for this change.


# 1.113 24-Sep-2010 dlg

no use setting cmd in mfi_ioctl_setstate if you never use it.


# 1.112 20-Sep-2010 krw

Use SSD_ERRCODE_CURRENT instead of magic 0x70.

ok dlg@ matthew@


# 1.111 29-Aug-2010 dlg

the scsi completion code thinks that if you dont get MFI_STAT_OK
back from the chip on a command then the command completely failed.
MFI_STAT_SCSI_DONE_WITH_ERROR really means the command completed
fine, but there's some sense data too. this tweaks the handling to
be more appropriate, as per the linux and solaris drivers.

timed out waiting for beck@
putting this in cos its obviously more correct than the current code.


Revision tags: OPENBSD_4_8_BASE
# 1.110 22-Jul-2010 matthew

SCSI HBA drivers are supposed to get their SCSI CDBs from xs->cmd, not
xs->cmdstore.

ok krw@ a while back (contingent upon testing), and deraadt@ says this
has been in snapshots for weeks now.


# 1.109 01-Jul-2010 matthew

Change scsibus(4)'s scsi_link array to an SLIST to save memory on
sparsely populated buses.

ok dlg@, krw@


# 1.108 30-Jun-2010 mk

Use SLIST for the ccb free list.

ok krw, discontent grunts from marco.


# 1.107 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.106 15-Jun-2010 dlg

dont pass the dev_t from the scsi device drivers into the midlayer for
ioctl requests, and dont pass the proc pointers around for any ioctl
requests in scsi land at all. neither were used, so trim the fat.

ok krw@ marco@


# 1.105 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.104 16-May-2010 nicm

Use a temporary variable for now to sidestep -Wbounded checking when
copying vendor[8]/product[16]/revision[4] out of struct scsi_inquiry_data
together with one memcopy.

ok krw


# 1.103 22-Apr-2010 oga

use BUS_DMA_ZERO on alloc instead of bzeroing after.

ok dlg@, marco@


# 1.102 10-Apr-2010 marco

grrr var names in protos


# 1.101 10-Apr-2010 marco

sprinkle some bus_dmamap_sync around frame access.
prompted by oga


# 1.100 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.99 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.98 04-Jan-2010 dlg

rename ccb_xs to ccb_cookie and change its type from a scsi_xfer * to a
void *. this lets us pass things other than scsi_xfers to ccb completion
handlers.


# 1.97 04-Jan-2010 dlg

protect the ccb free queue with a mutex rather than splbio


# 1.96 03-Jan-2010 chl

change M_WAITOK --> M_WAITOK|M_CANFAIL

with input from marco@

ok marco@ krw@

this was ok looooooooong time ago but lost in my mailbox


Revision tags: OPENBSD_4_6_BASE
# 1.95 30-Apr-2009 marco

Add READ(16) & WRITE(16) commands.
ok krw


# 1.94 29-Apr-2009 marco

MFI_D_IOCTL should be commented out. No binary change.


# 1.93 04-Apr-2009 dlg

scrub more fields in the ccb when returning them to the free list after
theyve been used, in particular the mfi header flags which has a bit
that specifies if a command should be completed via the interrupt path.

if we use a ccb during boot we set that bit, but it isnt necessarily
cleared by things that use it later on. this means a ccb we expected to
complete via an interrupt never actually generates an interrupt or appears
in the reply queue. this obviously stalls the io.


# 1.92 29-Mar-2009 marco

spello


# 1.91 29-Mar-2009 dlg

when we steal the SYNC CACHE command in mfi_scsi_cmd we still have to
mark the xs as done and call scsi_done for it rather than just returning
COMPLETE.


# 1.90 29-Mar-2009 dlg

fix a small race in mfi_mgmt between the checking of a ccbs completion and
the sleep waiting for the completion. it is possible to get the interrupt
completing the command just before the tsleep, which will never get a
wakeup because the interrupt with the wakeup has already happened.


Revision tags: OPENBSD_4_5_BASE
# 1.89 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.


# 1.88 28-Jan-2009 marco

Add support for next generation megaraid sas raid controllers.
From Jim Giannoules <gortag@gmail.com>


# 1.87 31-Oct-2008 marco

Generalize function to obtain all details to do bio stuff. This is in
preparation to start showing unsused disks which will require all this
information to do the math.

While at it fix a size of hotspare volume bug.


# 1.86 30-Oct-2008 marco

Fix bug that when there are no volumes but there are hot spares it would
no show the hotspares.


# 1.85 28-Oct-2008 marco

Fix output when reporting on multivolume disk groups.

Reported by mitja@muzenic.net


# 1.84 27-Oct-2008 marco

Move some include stuff around


# 1.83 26-Oct-2008 marco

Space


# 1.82 23-Oct-2008 marco

Fix PR5645
ok dlg
tested beck and others


# 1.81 25-Sep-2008 krw

Initialize 'ssc' to NULL since we test it later. Shouldn't ever be
NULL at the point of test unless the device list is confused, but
be consistantly paranoid if we're going to be paranoid.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.80 16-Feb-2008 krw

Return NO_CCB and not TRY_AGAIN_LATER when running out of ccb's.
Eliminates 'not queued' errors reported on the mailing lists.

Tested by Michael (belenus at bsdmail dot de).

ok marco@


# 1.79 11-Feb-2008 dlg

add support for the mfi controllers with the ppc iops, aka, LSI SAS1078 or
Dell PERC6.

committed off a machine booting and rooting off a perc6. tested on a perc5
by marco@
ok marco@


# 1.78 26-Jan-2008 brad

Set the return value instead of returning right away so that the DMA
memory is actually synched.

ok dlg@


# 1.77 26-Jan-2008 dlg

sync dma mem back to the cpu on poll failure.

from mickey via pr5714


# 1.76 26-Jan-2008 dlg

despatch -> dispatch

disparate spellink fix from mickey


# 1.75 05-Nov-2007 krw

More scsi_done() at SPLBIO.


# 1.74 27-Sep-2007 chl

M_ZERO changes

ok dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.73 24-Jun-2007 dlg

rework sensor tasks to use the kernels generic workq rather than a special
kernel thread of its own. the api has changed (which will be fixed in the
manpage shortly) so all the users of sensor tasks that i can find have
been fixed too.

noone tested, so its going in to force people to run with it.
"put it in" deraadt@


# 1.72 29-May-2007 todd

sprinkle some SMALL_KERNEL to permit bio/softraid to run on boot media
ok marco@ then suggested deraadt@


# 1.71 22-Mar-2007 deraadt

split userland & kernel struct sensor/sensordev so that the addition
of new fields in the future is less disruptive. This is done similar
to how struct proc is handled for ps(1). ok jmc (man page changes)
tested fkr simon, and more suggestions from millert


Revision tags: OPENBSD_4_1_BASE
# 1.70 14-Feb-2007 dlg

bus_space does byte swapping to cope with host endianness for us, so remove
an unnecessary htole32().


# 1.69 13-Feb-2007 marco

Fix subtle x ? y : z bug when calling mfi_create_sgl. This worked because
during runtime the bug condition does not happen.

ok krw joris


# 1.68 08-Feb-2007 ray

Remove double semicolons.

From Pierre Riteau <pierre dot riteau at free dot fr>.

OK marco@.


# 1.67 23-Dec-2006 deraadt

adapt to new two-level sensor api; Constantine A. Murenin


# 1.66 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.65 31-Aug-2006 marco

Add sensor thread for individual sd devices.

tested dlg
ok dlg deraadt


# 1.64 30-Aug-2006 dlg

when determining the size of the volumes and disks we want how many
bytes each of them has, not the number of kilobytes. this solves the
"why am i dividing by 2" question. the answer is "you dont, you multiply
by 512".


# 1.63 28-Jul-2006 brad

make dmesg printing look a little bit nicer.


# 1.62 19-Jun-2006 marco

Factor for disk size is /2. Odd but tested on all mfis I have.


# 1.61 19-Jun-2006 miod

Everytime one forgets an argument in a printf-like function call, God kills
a kitten. Commiters, please think of the kittens when working on code.


# 1.60 19-Jun-2006 marco

Make a BGI (Back Ground Init) a scrub instead of rebuild.


# 1.59 19-Jun-2006 marco

Add hot spare support.


# 1.58 26-May-2006 marco

Add blinking for disks.


# 1.57 25-May-2006 marco

Move a int i; to top of function so that it compiles on non c99 compilers.
Pointed out by miod@

The enclosure id modifier didn't reflect reality so move it back to whatever
the raid card uses.


# 1.56 25-May-2006 marco

And add time and percentage to builds and check consistencies.


# 1.55 25-May-2006 marco

Add last bit of physcal disk stuff.
Remove bogus memset.
Hotspares still don't work.


# 1.54 25-May-2006 marco

Add physical device and read config structures.
Add initial part of BIOCDISK


# 1.53 23-May-2006 deraadt

commited with unused variable


# 1.52 23-May-2006 marco

Remove some debug cruft.


# 1.51 23-May-2006 marco

Add first half of physical disk data for bio.


# 1.50 22-May-2006 marco

Add support for raid 50 and 10 in bio.


# 1.49 22-May-2006 marco

Add mail box to mfi_mgmt to handle sub commands more gracefully.
Remove some debug crud that snuck in the TEST_UNIT_READY case.
Finish other half of BIOCVOL primitive.
Add several structures to fill out the BIOCVOL primitive.


# 1.48 22-May-2006 marco

Add first half of BIOCVOL primitive.


# 1.47 21-May-2006 marco

Do a giant flush of disk and raid-card memory when SYNCHONIZE_CACHE is called.


# 1.46 21-May-2006 marco

pretty up some debug statements.


# 1.45 21-May-2006 marco

Add bio alarm function.
Redo mfi_mgmt to deal with zero data commands.


# 1.44 21-May-2006 marco

Add generic management function.
Redo ccb_state flags so that we can actually sleep on it.
Redo mfi_get_info to use new mgmt function.
Add rw_locks for mgmt interface.
Make BIOCINQ dynamic.


# 1.43 21-May-2006 marco

Oops, helps to use the right structure field.
Use actual nr of physical disks present.


# 1.42 21-May-2006 marco

Add first BIOCINQ primitive.


# 1.41 18-May-2006 marco

Remove some debug cruft and pretty up some debug messages.


# 1.40 18-May-2006 marco

Kill splbio/splx in the interrupt handler.


# 1.39 18-May-2006 marco

And we have lift off! Was able to create a filesystem and write to the
filesystem.

Collapse both completion routines into one.
Fixup scsi error reporting in the completion routine.


# 1.38 17-May-2006 marco

Add completion routines.
Fix some bugs inside the interrupt handler.


# 1.37 17-May-2006 marco

Add mfi_get_info to obtain all kinds of fun information from the fw.
Print out whole info structure when debug is enabled.
Add a nice print with useful info during attach.


# 1.36 17-May-2006 marco

Refactor scsi path so that we can have a single sgl function for io and non-io
traffic.
Redo parameters on functions that were passing too many parameters around.


# 1.35 16-May-2006 marco

Nuke some { }


# 1.34 16-May-2006 marco

Move !xs->data case into mfi_start_xs.
Return proper sense data when a polling command fails.


# 1.33 16-May-2006 marco

Fix some more htole32 screw-ups.
Colapse all little SCSI functions into a single generic one.
Fix a bug in the SGE calculation.

This brings the driver up to post:
mfi0 at pci12 dev 14 function 0 "Dell PERC SAS" rev 0x00: Dell PERC 5/e irq 5
scsibus3 at mfi0: 2 targets
sd1 at scsibus3 targ 0 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd1: 237824MB, 237824 cyl, 64 head, 32 sec, 512 bytes/sec, 487063552 sec total
sd2 at scsibus3 targ 1 lun 0: <DELL, PERC 5/E Adapter, 1.00> SCSI5 0/direct fixed
sd2: 34176MB, 34176 cyl, 64 head, 32 sec, 512 bytes/sec, 69992448 sec total


# 1.32 16-May-2006 marco

Fix some htole32 I missed.
Sprinkle more debug.


# 1.31 16-May-2006 marco

Add READ CAPACITY.


# 1.30 16-May-2006 marco

Oops PREREAD not PREWRITE.


# 1.29 16-May-2006 marco

Add TUR and make it send it directly to firmware.
Sprinkle some extra debug.


# 1.28 15-May-2006 marco

Clear all relevant ccb fields when mfi_put_ccb frees a ccb.


# 1.27 15-May-2006 marco

Oops don't send command twice to firmware when polling.


# 1.26 15-May-2006 marco

Add INQUIRY command.
Add sgl magic.


# 1.25 10-May-2006 marco

Add some airplane code.

add bio hooks.
add scsi entry point for io.


# 1.24 26-Apr-2006 marco

Fix some debug prints.


# 1.23 21-Apr-2006 marco

typo


# 1.22 21-Apr-2006 marco

Add mfi_poll and use the new shiny function to setup all the hardware queues.
Lots of ideas from the FreeBSD driver.


# 1.21 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.20 20-Apr-2006 dlg

marco hates typedefs as much as i do, so he asked me to clean mfi like i
just did with ami. this gets rid of the typedef for the ccb lists.

also uses TAILQ_FIRST to get ccbs off the freelist. this is a proactive
fix for a lint teary.


# 1.19 18-Apr-2006 marco

It helps to initialize a queue before usage.


# 1.18 18-Apr-2006 marco

Actually add ccbs to the queue.
Fix the error path for mfi_init_ccb.
Alter dmamap for io.


# 1.17 17-Apr-2006 marco

Sprinkle more debug. Remove 64 byte boundary; it doesn't seem to like it.
Hack around 64 byte boundary for the frames for now.


# 1.16 17-Apr-2006 marco

Setup ccbs and clean up ccb structure.


# 1.15 16-Apr-2006 marco

Oops, make mfi_allocmem always use 64 byte boundaries since frames have to
have that alignment. It doesn't matter for the other consumers of the
function.


# 1.14 16-Apr-2006 marco

Add frame memory and sglist allocation.


# 1.13 16-Apr-2006 marco

Make memory access use macro.


# 1.12 16-Apr-2006 marco

typo


# 1.11 16-Apr-2006 marco

Add get and put ccb functions. Shuffle some more definitions.


# 1.10 16-Apr-2006 marco

Nicer print when context is invalid.


# 1.9 16-Apr-2006 marco

Shuffle some #defines.
Fix comments.
Add human readable enable intrrupt #define.


# 1.8 16-Apr-2006 marco

Add interrupt handler. Idea borrowed from FreeBSD since it is much nicer
than the Linux one.


# 1.7 07-Apr-2006 marco

Replace bus_space functions with generic ones that do barriers.


# 1.6 07-Apr-2006 marco

Add memory allocator functions.


# 1.5 07-Apr-2006 marco

Print state in debug. Change return vales to 1 instead of ENXIO.


# 1.4 07-Apr-2006 marco

Make a better debug mechanism.


# 1.3 07-Apr-2006 marco

Enable mfi_transition_fw() original code from FreeBSD.


# 1.2 06-Apr-2006 marco

Add fw transition logic.


# 1.1 06-Apr-2006 marco

Add skeleton driver for MegaRAID SAS.