History log of /openbsd-current/sys/dev/sdmmc/sdmmc_scsi.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.63 19-Apr-2023 dlg

dont advertise non-removable sdmmc devices as removable to the scsi layer.

this is cosmetic more than anything cos it gets rid of "removable"
in dmesg output when sd attaches.


# 1.62 19-Apr-2023 dlg

handle some more manufacturer ids.


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

constify SCSI adapter entry points

ok krw@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.60 27-Mar-2021 kn

Fix SDMMC_DEBUG build

- Replace undefined SDMMCDEVNAME macro with usual DEVNAME from sdmmcvar.h
- typofix struct member name


# 1.59 15-Oct-2020 krw

Replace simple one-line bcopy()/memcpy() of faked data into scsi_xfer with call
to scsi_copy_internal_data(). Thus getting xs->resid properly set and adding the
usual uio/size sanity checks.


Revision tags: OPENBSD_6_8_BASE
# 1.58 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.57 05-Sep-2020 krw

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


# 1.56 03-Sep-2020 krw

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


# 1.55 02-Sep-2020 krw

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


# 1.54 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.53 25-Jul-2020 krw

No need for a bzero(), just init saa.sf to NULL. All the saa.saa
fields are explicitly initialized.


# 1.52 22-Jul-2020 krw

Nuke unused struct scsi_link members of adapter softc's where the
driver successfully compiles on one or more of amd64, i386, hppa.


# 1.51 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.50 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.49 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.48 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.47 03-Jul-2020 krw

Pass the expected 'scsibus_attach_args *' to scsibus_attach() via
config_found(), not a 'scsi_link *'. Part of matthew@'s 2010 work.


Revision tags: OPENBSD_6_7_BASE
# 1.46 20-Feb-2020 krw

Relax the grip the dead hand of QBUS (a.k.a. MAXPHYS) has on the
throat of physio().

Allows individual devices to eventually be modified to support larger
physio() (a.k.a. 'raw') i/o's if they prove capable of them.

No immediate functional change.

Tested for many weeks by and ok robert@.


# 1.45 12-Feb-2020 krw

Bring a few stragglers into line with the idiom used by the other 40+
scsi drivers. i.e. eliminate the struct scsi_adapter member in the
softc and rely on the pointer to a static scsi_adapter in the struct
scsi_link member.


# 1.44 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.43 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


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.42 30-Mar-2018 jmatthew

Add some sensible error checking in the hibernate io path, helpfully
suggested by coverity (via daniel@)


Revision tags: OPENBSD_6_3_BASE
# 1.41 20-Mar-2018 jmatthew

Add hibernate IO path for sdmmc(4). This requires some help from the
sdmmc chipset driver, currently only implemented in sdhc(4), but
mostly uses the regular path. sdhc(4) also needed the ability to
perform IO while cold.

ok deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.40 06-Apr-2017 deraadt

Sizes for the remaining free() calls, and use mallocarray()
ok visa


# 1.39 06-Apr-2017 deraadt

add sizes to free() calls
ok dhill


Revision tags: OPENBSD_6_1_BASE
# 1.38 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


# 1.37 20-Jan-2017 deraadt

sdmmc sd(4) devices should be marked SID_REMOVABLE, so that eject(1) can
succeed. No downside in the bottom part of the driver.
ok dlg krw


Revision tags: OPENBSD_6_0_BASE
# 1.36 05-May-2016 kettenis

Populate SCSI inquiry data with information from SD and MMC cards.
Code is slightly more convoluted to avoid using strncpy(9).

ok jsg@, millert@, deraadt@


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.35 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.34 09-Dec-2014 doug

More malloc() -> mallocarray() in the kernel.

ok deraadt@ tedu@


# 1.33 01-Nov-2014 jsg

fix the build when SDMMC_DEBUG is defined


# 1.32 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.31 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.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.30 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.29 09-Jul-2011 matthew

Simplify sdmmc_scsi by using SCSI_NO_ADAPTER_TARGET.

Tested by drahn@


# 1.28 09-Jul-2011 matthew

Kludge around sdmmc(4)'s poor design: replace "struct scsi_link *"
with "struct scsibus_attach_args" in sdmmc_attach_args.

ok krw@


# 1.27 16-Jun-2011 dlg

dont respond to VPD inquiries with standard inquiry data. add a
check to make sure cmdlen is correct while there.

ok miod@


Revision tags: OPENBSD_4_9_BASE
# 1.26 25-Oct-2010 krw

Iopoolification. Tested by mcbride@, dlg@, and Gabriel Kihlman on tech@.

ok dlg@


# 1.25 24-Aug-2010 blambert

lockmgr -> rwlock conversion

and with this, my adventure in sdmmc-land is over
bikeshed is still banana-shaped

ok oga@


# 1.24 19-Aug-2010 jasper

- fold several occurences of DEVNAME() into one located in sdmmcvar.h.
making DEVNAME() usage a lot more consistent.

ok krw@


Revision tags: OPENBSD_4_8_BASE
# 1.23 20-Jun-2010 mk

Don't use and maintain a function pointer that is only ever set to one
function. Just call the function where needed.

ok krw dlg


# 1.22 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.21 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.20 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.19 03-Oct-2009 kettenis

Add missing <sys/device.h>.

ok deraadt@, miod@


# 1.18 05-Sep-2009 dlg

scsi_done before COMPLETE


Revision tags: OPENBSD_4_6_BASE
# 1.17 07-Apr-2009 blambert

Remove recursion from the sdmmc locking regime.

In snaps for a while.

Originally hacked on phessler@'s couch.
Testing by many, input from jsg@

"I'm tired of seeing the Ms" deraadt@


# 1.16 24-Mar-2009 kettenis

Remove redundant casts.


Revision tags: OPENBSD_4_5_BASE
# 1.15 20-Feb-2009 miod

Let the sdmmc adapters tell the sdmmc layer how much sectors they can
transfer with one command. Build on this and the recent minphys() changes
in the sdmmc layer to crank transfers at the maximum possible size instead
of a sad DEV_BSIZE.

Depending on your controller, this can speed up sdmmc I/O up to 2.5 times.


# 1.14 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.13 06-Feb-2009 grange

Fix crash on zaurus when sd memory card plugged by providing an attachment
structure that slave devices like sbt expect.


# 1.12 21-Jan-2009 grange

Replace timeout_add(msecs * hz / 1000) with timeout_add_msec(msecs).
No functional changes.

ok krw@ miod@


# 1.11 02-Dec-2008 deraadt

backout: would have been nice if this had been tested, to see that it
crashes the moment a card is plugged in.


# 1.10 24-Nov-2008 blambert

Rework sdmmc locking to remove recursion
Add SDMMC_ASSERT_LOCKED(), replacing many locking calls, and sprinkling
the assertion to make sure that future changes don't catch us out

"please commit" uwe@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.9 11-Sep-2007 gilles

KNF

prompted and "much better" by marco@, ok pyr@


# 1.8 10-Sep-2007 gilles

more MALLOC/FREE -> malloc/free and M_ZERO changes

ok pyr@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.7 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


# 1.6 17-Oct-2006 dlg

dont pass a copy of sdmmcs scsi_link struct on the stack to the midlayer.
it triggered a panic on detach of the scsibus when it tried to use the
adapters scsi_link struct that was no longer there.

issue found by and this fix tested by pedro@
ok krw@ looks right deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.5 23-Aug-2006 pedro

Protect scsi_done() with splbio(), discussed with and okay dlg@, marco@
and fgsch@, uwe@ time-out :(


# 1.4 18-Jul-2006 uwe

First and foremost, avoid an obious race between two or more processes
trying to get MMC commands through to the SD/MMC host controller via the
emulated SCSI layer. This is achieved by ensuring exclusive access to
the host controller for one process during any MMC command and during a
sequence of commands at the sdmmc(4) layer.

While at it, the command processing thread has been moved to sdmmc(4),
so as to simplify the implementation of future host controller drivers.
This should also pave the way for further cleanup of the code and for
new drivers.

Minor cleanups are included in this commit, as well.


# 1.3 01-Jun-2006 uwe

SDIO card identification


# 1.2 28-May-2006 uwe

don't #undef SDMMC_DEBUG


# 1.1 28-May-2006 uwe

Support for standard SD host controllers like the Ricoh 5C822, a small
generic bus layer, and SCSI emulation for SD/MMC memory cards.


# 1.61 16-Apr-2022 naddy

constify SCSI adapter entry points

ok krw@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.60 27-Mar-2021 kn

Fix SDMMC_DEBUG build

- Replace undefined SDMMCDEVNAME macro with usual DEVNAME from sdmmcvar.h
- typofix struct member name


# 1.59 15-Oct-2020 krw

Replace simple one-line bcopy()/memcpy() of faked data into scsi_xfer with call
to scsi_copy_internal_data(). Thus getting xs->resid properly set and adding the
usual uio/size sanity checks.


Revision tags: OPENBSD_6_8_BASE
# 1.58 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.57 05-Sep-2020 krw

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


# 1.56 03-Sep-2020 krw

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


# 1.55 02-Sep-2020 krw

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


# 1.54 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.53 25-Jul-2020 krw

No need for a bzero(), just init saa.sf to NULL. All the saa.saa
fields are explicitly initialized.


# 1.52 22-Jul-2020 krw

Nuke unused struct scsi_link members of adapter softc's where the
driver successfully compiles on one or more of amd64, i386, hppa.


# 1.51 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.50 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.49 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.48 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.47 03-Jul-2020 krw

Pass the expected 'scsibus_attach_args *' to scsibus_attach() via
config_found(), not a 'scsi_link *'. Part of matthew@'s 2010 work.


Revision tags: OPENBSD_6_7_BASE
# 1.46 20-Feb-2020 krw

Relax the grip the dead hand of QBUS (a.k.a. MAXPHYS) has on the
throat of physio().

Allows individual devices to eventually be modified to support larger
physio() (a.k.a. 'raw') i/o's if they prove capable of them.

No immediate functional change.

Tested for many weeks by and ok robert@.


# 1.45 12-Feb-2020 krw

Bring a few stragglers into line with the idiom used by the other 40+
scsi drivers. i.e. eliminate the struct scsi_adapter member in the
softc and rely on the pointer to a static scsi_adapter in the struct
scsi_link member.


# 1.44 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.43 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


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.42 30-Mar-2018 jmatthew

Add some sensible error checking in the hibernate io path, helpfully
suggested by coverity (via daniel@)


Revision tags: OPENBSD_6_3_BASE
# 1.41 20-Mar-2018 jmatthew

Add hibernate IO path for sdmmc(4). This requires some help from the
sdmmc chipset driver, currently only implemented in sdhc(4), but
mostly uses the regular path. sdhc(4) also needed the ability to
perform IO while cold.

ok deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.40 06-Apr-2017 deraadt

Sizes for the remaining free() calls, and use mallocarray()
ok visa


# 1.39 06-Apr-2017 deraadt

add sizes to free() calls
ok dhill


Revision tags: OPENBSD_6_1_BASE
# 1.38 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


# 1.37 20-Jan-2017 deraadt

sdmmc sd(4) devices should be marked SID_REMOVABLE, so that eject(1) can
succeed. No downside in the bottom part of the driver.
ok dlg krw


Revision tags: OPENBSD_6_0_BASE
# 1.36 05-May-2016 kettenis

Populate SCSI inquiry data with information from SD and MMC cards.
Code is slightly more convoluted to avoid using strncpy(9).

ok jsg@, millert@, deraadt@


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.35 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.34 09-Dec-2014 doug

More malloc() -> mallocarray() in the kernel.

ok deraadt@ tedu@


# 1.33 01-Nov-2014 jsg

fix the build when SDMMC_DEBUG is defined


# 1.32 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.31 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.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.30 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.29 09-Jul-2011 matthew

Simplify sdmmc_scsi by using SCSI_NO_ADAPTER_TARGET.

Tested by drahn@


# 1.28 09-Jul-2011 matthew

Kludge around sdmmc(4)'s poor design: replace "struct scsi_link *"
with "struct scsibus_attach_args" in sdmmc_attach_args.

ok krw@


# 1.27 16-Jun-2011 dlg

dont respond to VPD inquiries with standard inquiry data. add a
check to make sure cmdlen is correct while there.

ok miod@


Revision tags: OPENBSD_4_9_BASE
# 1.26 25-Oct-2010 krw

Iopoolification. Tested by mcbride@, dlg@, and Gabriel Kihlman on tech@.

ok dlg@


# 1.25 24-Aug-2010 blambert

lockmgr -> rwlock conversion

and with this, my adventure in sdmmc-land is over
bikeshed is still banana-shaped

ok oga@


# 1.24 19-Aug-2010 jasper

- fold several occurences of DEVNAME() into one located in sdmmcvar.h.
making DEVNAME() usage a lot more consistent.

ok krw@


Revision tags: OPENBSD_4_8_BASE
# 1.23 20-Jun-2010 mk

Don't use and maintain a function pointer that is only ever set to one
function. Just call the function where needed.

ok krw dlg


# 1.22 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.21 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.20 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.19 03-Oct-2009 kettenis

Add missing <sys/device.h>.

ok deraadt@, miod@


# 1.18 05-Sep-2009 dlg

scsi_done before COMPLETE


Revision tags: OPENBSD_4_6_BASE
# 1.17 07-Apr-2009 blambert

Remove recursion from the sdmmc locking regime.

In snaps for a while.

Originally hacked on phessler@'s couch.
Testing by many, input from jsg@

"I'm tired of seeing the Ms" deraadt@


# 1.16 24-Mar-2009 kettenis

Remove redundant casts.


Revision tags: OPENBSD_4_5_BASE
# 1.15 20-Feb-2009 miod

Let the sdmmc adapters tell the sdmmc layer how much sectors they can
transfer with one command. Build on this and the recent minphys() changes
in the sdmmc layer to crank transfers at the maximum possible size instead
of a sad DEV_BSIZE.

Depending on your controller, this can speed up sdmmc I/O up to 2.5 times.


# 1.14 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.13 06-Feb-2009 grange

Fix crash on zaurus when sd memory card plugged by providing an attachment
structure that slave devices like sbt expect.


# 1.12 21-Jan-2009 grange

Replace timeout_add(msecs * hz / 1000) with timeout_add_msec(msecs).
No functional changes.

ok krw@ miod@


# 1.11 02-Dec-2008 deraadt

backout: would have been nice if this had been tested, to see that it
crashes the moment a card is plugged in.


# 1.10 24-Nov-2008 blambert

Rework sdmmc locking to remove recursion
Add SDMMC_ASSERT_LOCKED(), replacing many locking calls, and sprinkling
the assertion to make sure that future changes don't catch us out

"please commit" uwe@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.9 11-Sep-2007 gilles

KNF

prompted and "much better" by marco@, ok pyr@


# 1.8 10-Sep-2007 gilles

more MALLOC/FREE -> malloc/free and M_ZERO changes

ok pyr@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.7 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


# 1.6 17-Oct-2006 dlg

dont pass a copy of sdmmcs scsi_link struct on the stack to the midlayer.
it triggered a panic on detach of the scsibus when it tried to use the
adapters scsi_link struct that was no longer there.

issue found by and this fix tested by pedro@
ok krw@ looks right deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.5 23-Aug-2006 pedro

Protect scsi_done() with splbio(), discussed with and okay dlg@, marco@
and fgsch@, uwe@ time-out :(


# 1.4 18-Jul-2006 uwe

First and foremost, avoid an obious race between two or more processes
trying to get MMC commands through to the SD/MMC host controller via the
emulated SCSI layer. This is achieved by ensuring exclusive access to
the host controller for one process during any MMC command and during a
sequence of commands at the sdmmc(4) layer.

While at it, the command processing thread has been moved to sdmmc(4),
so as to simplify the implementation of future host controller drivers.
This should also pave the way for further cleanup of the code and for
new drivers.

Minor cleanups are included in this commit, as well.


# 1.3 01-Jun-2006 uwe

SDIO card identification


# 1.2 28-May-2006 uwe

don't #undef SDMMC_DEBUG


# 1.1 28-May-2006 uwe

Support for standard SD host controllers like the Ricoh 5C822, a small
generic bus layer, and SCSI emulation for SD/MMC memory cards.


# 1.60 27-Mar-2021 kn

Fix SDMMC_DEBUG build

- Replace undefined SDMMCDEVNAME macro with usual DEVNAME from sdmmcvar.h
- typofix struct member name


# 1.59 15-Oct-2020 krw

Replace simple one-line bcopy()/memcpy() of faked data into scsi_xfer with call
to scsi_copy_internal_data(). Thus getting xs->resid properly set and adding the
usual uio/size sanity checks.


Revision tags: OPENBSD_6_8_BASE
# 1.58 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.57 05-Sep-2020 krw

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


# 1.56 03-Sep-2020 krw

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


# 1.55 02-Sep-2020 krw

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


# 1.54 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.53 25-Jul-2020 krw

No need for a bzero(), just init saa.sf to NULL. All the saa.saa
fields are explicitly initialized.


# 1.52 22-Jul-2020 krw

Nuke unused struct scsi_link members of adapter softc's where the
driver successfully compiles on one or more of amd64, i386, hppa.


# 1.51 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.50 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.49 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.48 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.47 03-Jul-2020 krw

Pass the expected 'scsibus_attach_args *' to scsibus_attach() via
config_found(), not a 'scsi_link *'. Part of matthew@'s 2010 work.


Revision tags: OPENBSD_6_7_BASE
# 1.46 20-Feb-2020 krw

Relax the grip the dead hand of QBUS (a.k.a. MAXPHYS) has on the
throat of physio().

Allows individual devices to eventually be modified to support larger
physio() (a.k.a. 'raw') i/o's if they prove capable of them.

No immediate functional change.

Tested for many weeks by and ok robert@.


# 1.45 12-Feb-2020 krw

Bring a few stragglers into line with the idiom used by the other 40+
scsi drivers. i.e. eliminate the struct scsi_adapter member in the
softc and rely on the pointer to a static scsi_adapter in the struct
scsi_link member.


# 1.44 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.43 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


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.42 30-Mar-2018 jmatthew

Add some sensible error checking in the hibernate io path, helpfully
suggested by coverity (via daniel@)


Revision tags: OPENBSD_6_3_BASE
# 1.41 20-Mar-2018 jmatthew

Add hibernate IO path for sdmmc(4). This requires some help from the
sdmmc chipset driver, currently only implemented in sdhc(4), but
mostly uses the regular path. sdhc(4) also needed the ability to
perform IO while cold.

ok deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.40 06-Apr-2017 deraadt

Sizes for the remaining free() calls, and use mallocarray()
ok visa


# 1.39 06-Apr-2017 deraadt

add sizes to free() calls
ok dhill


Revision tags: OPENBSD_6_1_BASE
# 1.38 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


# 1.37 20-Jan-2017 deraadt

sdmmc sd(4) devices should be marked SID_REMOVABLE, so that eject(1) can
succeed. No downside in the bottom part of the driver.
ok dlg krw


Revision tags: OPENBSD_6_0_BASE
# 1.36 05-May-2016 kettenis

Populate SCSI inquiry data with information from SD and MMC cards.
Code is slightly more convoluted to avoid using strncpy(9).

ok jsg@, millert@, deraadt@


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.35 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.34 09-Dec-2014 doug

More malloc() -> mallocarray() in the kernel.

ok deraadt@ tedu@


# 1.33 01-Nov-2014 jsg

fix the build when SDMMC_DEBUG is defined


# 1.32 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.31 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.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.30 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.29 09-Jul-2011 matthew

Simplify sdmmc_scsi by using SCSI_NO_ADAPTER_TARGET.

Tested by drahn@


# 1.28 09-Jul-2011 matthew

Kludge around sdmmc(4)'s poor design: replace "struct scsi_link *"
with "struct scsibus_attach_args" in sdmmc_attach_args.

ok krw@


# 1.27 16-Jun-2011 dlg

dont respond to VPD inquiries with standard inquiry data. add a
check to make sure cmdlen is correct while there.

ok miod@


Revision tags: OPENBSD_4_9_BASE
# 1.26 25-Oct-2010 krw

Iopoolification. Tested by mcbride@, dlg@, and Gabriel Kihlman on tech@.

ok dlg@


# 1.25 24-Aug-2010 blambert

lockmgr -> rwlock conversion

and with this, my adventure in sdmmc-land is over
bikeshed is still banana-shaped

ok oga@


# 1.24 19-Aug-2010 jasper

- fold several occurences of DEVNAME() into one located in sdmmcvar.h.
making DEVNAME() usage a lot more consistent.

ok krw@


Revision tags: OPENBSD_4_8_BASE
# 1.23 20-Jun-2010 mk

Don't use and maintain a function pointer that is only ever set to one
function. Just call the function where needed.

ok krw dlg


# 1.22 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.21 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.20 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.19 03-Oct-2009 kettenis

Add missing <sys/device.h>.

ok deraadt@, miod@


# 1.18 05-Sep-2009 dlg

scsi_done before COMPLETE


Revision tags: OPENBSD_4_6_BASE
# 1.17 07-Apr-2009 blambert

Remove recursion from the sdmmc locking regime.

In snaps for a while.

Originally hacked on phessler@'s couch.
Testing by many, input from jsg@

"I'm tired of seeing the Ms" deraadt@


# 1.16 24-Mar-2009 kettenis

Remove redundant casts.


Revision tags: OPENBSD_4_5_BASE
# 1.15 20-Feb-2009 miod

Let the sdmmc adapters tell the sdmmc layer how much sectors they can
transfer with one command. Build on this and the recent minphys() changes
in the sdmmc layer to crank transfers at the maximum possible size instead
of a sad DEV_BSIZE.

Depending on your controller, this can speed up sdmmc I/O up to 2.5 times.


# 1.14 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.13 06-Feb-2009 grange

Fix crash on zaurus when sd memory card plugged by providing an attachment
structure that slave devices like sbt expect.


# 1.12 21-Jan-2009 grange

Replace timeout_add(msecs * hz / 1000) with timeout_add_msec(msecs).
No functional changes.

ok krw@ miod@


# 1.11 02-Dec-2008 deraadt

backout: would have been nice if this had been tested, to see that it
crashes the moment a card is plugged in.


# 1.10 24-Nov-2008 blambert

Rework sdmmc locking to remove recursion
Add SDMMC_ASSERT_LOCKED(), replacing many locking calls, and sprinkling
the assertion to make sure that future changes don't catch us out

"please commit" uwe@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.9 11-Sep-2007 gilles

KNF

prompted and "much better" by marco@, ok pyr@


# 1.8 10-Sep-2007 gilles

more MALLOC/FREE -> malloc/free and M_ZERO changes

ok pyr@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.7 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


# 1.6 17-Oct-2006 dlg

dont pass a copy of sdmmcs scsi_link struct on the stack to the midlayer.
it triggered a panic on detach of the scsibus when it tried to use the
adapters scsi_link struct that was no longer there.

issue found by and this fix tested by pedro@
ok krw@ looks right deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.5 23-Aug-2006 pedro

Protect scsi_done() with splbio(), discussed with and okay dlg@, marco@
and fgsch@, uwe@ time-out :(


# 1.4 18-Jul-2006 uwe

First and foremost, avoid an obious race between two or more processes
trying to get MMC commands through to the SD/MMC host controller via the
emulated SCSI layer. This is achieved by ensuring exclusive access to
the host controller for one process during any MMC command and during a
sequence of commands at the sdmmc(4) layer.

While at it, the command processing thread has been moved to sdmmc(4),
so as to simplify the implementation of future host controller drivers.
This should also pave the way for further cleanup of the code and for
new drivers.

Minor cleanups are included in this commit, as well.


# 1.3 01-Jun-2006 uwe

SDIO card identification


# 1.2 28-May-2006 uwe

don't #undef SDMMC_DEBUG


# 1.1 28-May-2006 uwe

Support for standard SD host controllers like the Ricoh 5C822, a small
generic bus layer, and SCSI emulation for SD/MMC memory cards.


# 1.59 15-Oct-2020 krw

Replace simple one-line bcopy()/memcpy() of faked data into scsi_xfer with call
to scsi_copy_internal_data(). Thus getting xs->resid properly set and adding the
usual uio/size sanity checks.


Revision tags: OPENBSD_6_8_BASE
# 1.58 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.57 05-Sep-2020 krw

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


# 1.56 03-Sep-2020 krw

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


# 1.55 02-Sep-2020 krw

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


# 1.54 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.53 25-Jul-2020 krw

No need for a bzero(), just init saa.sf to NULL. All the saa.saa
fields are explicitly initialized.


# 1.52 22-Jul-2020 krw

Nuke unused struct scsi_link members of adapter softc's where the
driver successfully compiles on one or more of amd64, i386, hppa.


# 1.51 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.50 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.49 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.48 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.47 03-Jul-2020 krw

Pass the expected 'scsibus_attach_args *' to scsibus_attach() via
config_found(), not a 'scsi_link *'. Part of matthew@'s 2010 work.


Revision tags: OPENBSD_6_7_BASE
# 1.46 20-Feb-2020 krw

Relax the grip the dead hand of QBUS (a.k.a. MAXPHYS) has on the
throat of physio().

Allows individual devices to eventually be modified to support larger
physio() (a.k.a. 'raw') i/o's if they prove capable of them.

No immediate functional change.

Tested for many weeks by and ok robert@.


# 1.45 12-Feb-2020 krw

Bring a few stragglers into line with the idiom used by the other 40+
scsi drivers. i.e. eliminate the struct scsi_adapter member in the
softc and rely on the pointer to a static scsi_adapter in the struct
scsi_link member.


# 1.44 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.43 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


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.42 30-Mar-2018 jmatthew

Add some sensible error checking in the hibernate io path, helpfully
suggested by coverity (via daniel@)


Revision tags: OPENBSD_6_3_BASE
# 1.41 20-Mar-2018 jmatthew

Add hibernate IO path for sdmmc(4). This requires some help from the
sdmmc chipset driver, currently only implemented in sdhc(4), but
mostly uses the regular path. sdhc(4) also needed the ability to
perform IO while cold.

ok deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.40 06-Apr-2017 deraadt

Sizes for the remaining free() calls, and use mallocarray()
ok visa


# 1.39 06-Apr-2017 deraadt

add sizes to free() calls
ok dhill


Revision tags: OPENBSD_6_1_BASE
# 1.38 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


# 1.37 20-Jan-2017 deraadt

sdmmc sd(4) devices should be marked SID_REMOVABLE, so that eject(1) can
succeed. No downside in the bottom part of the driver.
ok dlg krw


Revision tags: OPENBSD_6_0_BASE
# 1.36 05-May-2016 kettenis

Populate SCSI inquiry data with information from SD and MMC cards.
Code is slightly more convoluted to avoid using strncpy(9).

ok jsg@, millert@, deraadt@


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.35 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.34 09-Dec-2014 doug

More malloc() -> mallocarray() in the kernel.

ok deraadt@ tedu@


# 1.33 01-Nov-2014 jsg

fix the build when SDMMC_DEBUG is defined


# 1.32 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.31 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.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.30 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.29 09-Jul-2011 matthew

Simplify sdmmc_scsi by using SCSI_NO_ADAPTER_TARGET.

Tested by drahn@


# 1.28 09-Jul-2011 matthew

Kludge around sdmmc(4)'s poor design: replace "struct scsi_link *"
with "struct scsibus_attach_args" in sdmmc_attach_args.

ok krw@


# 1.27 16-Jun-2011 dlg

dont respond to VPD inquiries with standard inquiry data. add a
check to make sure cmdlen is correct while there.

ok miod@


Revision tags: OPENBSD_4_9_BASE
# 1.26 25-Oct-2010 krw

Iopoolification. Tested by mcbride@, dlg@, and Gabriel Kihlman on tech@.

ok dlg@


# 1.25 24-Aug-2010 blambert

lockmgr -> rwlock conversion

and with this, my adventure in sdmmc-land is over
bikeshed is still banana-shaped

ok oga@


# 1.24 19-Aug-2010 jasper

- fold several occurences of DEVNAME() into one located in sdmmcvar.h.
making DEVNAME() usage a lot more consistent.

ok krw@


Revision tags: OPENBSD_4_8_BASE
# 1.23 20-Jun-2010 mk

Don't use and maintain a function pointer that is only ever set to one
function. Just call the function where needed.

ok krw dlg


# 1.22 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.21 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.20 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.19 03-Oct-2009 kettenis

Add missing <sys/device.h>.

ok deraadt@, miod@


# 1.18 05-Sep-2009 dlg

scsi_done before COMPLETE


Revision tags: OPENBSD_4_6_BASE
# 1.17 07-Apr-2009 blambert

Remove recursion from the sdmmc locking regime.

In snaps for a while.

Originally hacked on phessler@'s couch.
Testing by many, input from jsg@

"I'm tired of seeing the Ms" deraadt@


# 1.16 24-Mar-2009 kettenis

Remove redundant casts.


Revision tags: OPENBSD_4_5_BASE
# 1.15 20-Feb-2009 miod

Let the sdmmc adapters tell the sdmmc layer how much sectors they can
transfer with one command. Build on this and the recent minphys() changes
in the sdmmc layer to crank transfers at the maximum possible size instead
of a sad DEV_BSIZE.

Depending on your controller, this can speed up sdmmc I/O up to 2.5 times.


# 1.14 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.13 06-Feb-2009 grange

Fix crash on zaurus when sd memory card plugged by providing an attachment
structure that slave devices like sbt expect.


# 1.12 21-Jan-2009 grange

Replace timeout_add(msecs * hz / 1000) with timeout_add_msec(msecs).
No functional changes.

ok krw@ miod@


# 1.11 02-Dec-2008 deraadt

backout: would have been nice if this had been tested, to see that it
crashes the moment a card is plugged in.


# 1.10 24-Nov-2008 blambert

Rework sdmmc locking to remove recursion
Add SDMMC_ASSERT_LOCKED(), replacing many locking calls, and sprinkling
the assertion to make sure that future changes don't catch us out

"please commit" uwe@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.9 11-Sep-2007 gilles

KNF

prompted and "much better" by marco@, ok pyr@


# 1.8 10-Sep-2007 gilles

more MALLOC/FREE -> malloc/free and M_ZERO changes

ok pyr@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.7 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


# 1.6 17-Oct-2006 dlg

dont pass a copy of sdmmcs scsi_link struct on the stack to the midlayer.
it triggered a panic on detach of the scsibus when it tried to use the
adapters scsi_link struct that was no longer there.

issue found by and this fix tested by pedro@
ok krw@ looks right deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.5 23-Aug-2006 pedro

Protect scsi_done() with splbio(), discussed with and okay dlg@, marco@
and fgsch@, uwe@ time-out :(


# 1.4 18-Jul-2006 uwe

First and foremost, avoid an obious race between two or more processes
trying to get MMC commands through to the SD/MMC host controller via the
emulated SCSI layer. This is achieved by ensuring exclusive access to
the host controller for one process during any MMC command and during a
sequence of commands at the sdmmc(4) layer.

While at it, the command processing thread has been moved to sdmmc(4),
so as to simplify the implementation of future host controller drivers.
This should also pave the way for further cleanup of the code and for
new drivers.

Minor cleanups are included in this commit, as well.


# 1.3 01-Jun-2006 uwe

SDIO card identification


# 1.2 28-May-2006 uwe

don't #undef SDMMC_DEBUG


# 1.1 28-May-2006 uwe

Support for standard SD host controllers like the Ricoh 5C822, a small
generic bus layer, and SCSI emulation for SD/MMC memory cards.


# 1.58 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.57 05-Sep-2020 krw

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


# 1.56 03-Sep-2020 krw

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


# 1.55 02-Sep-2020 krw

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


# 1.54 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.53 25-Jul-2020 krw

No need for a bzero(), just init saa.sf to NULL. All the saa.saa
fields are explicitly initialized.


# 1.52 22-Jul-2020 krw

Nuke unused struct scsi_link members of adapter softc's where the
driver successfully compiles on one or more of amd64, i386, hppa.


# 1.51 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.50 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.49 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.48 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.47 03-Jul-2020 krw

Pass the expected 'scsibus_attach_args *' to scsibus_attach() via
config_found(), not a 'scsi_link *'. Part of matthew@'s 2010 work.


Revision tags: OPENBSD_6_7_BASE
# 1.46 20-Feb-2020 krw

Relax the grip the dead hand of QBUS (a.k.a. MAXPHYS) has on the
throat of physio().

Allows individual devices to eventually be modified to support larger
physio() (a.k.a. 'raw') i/o's if they prove capable of them.

No immediate functional change.

Tested for many weeks by and ok robert@.


# 1.45 12-Feb-2020 krw

Bring a few stragglers into line with the idiom used by the other 40+
scsi drivers. i.e. eliminate the struct scsi_adapter member in the
softc and rely on the pointer to a static scsi_adapter in the struct
scsi_link member.


# 1.44 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.43 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


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.42 30-Mar-2018 jmatthew

Add some sensible error checking in the hibernate io path, helpfully
suggested by coverity (via daniel@)


Revision tags: OPENBSD_6_3_BASE
# 1.41 20-Mar-2018 jmatthew

Add hibernate IO path for sdmmc(4). This requires some help from the
sdmmc chipset driver, currently only implemented in sdhc(4), but
mostly uses the regular path. sdhc(4) also needed the ability to
perform IO while cold.

ok deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.40 06-Apr-2017 deraadt

Sizes for the remaining free() calls, and use mallocarray()
ok visa


# 1.39 06-Apr-2017 deraadt

add sizes to free() calls
ok dhill


Revision tags: OPENBSD_6_1_BASE
# 1.38 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


# 1.37 20-Jan-2017 deraadt

sdmmc sd(4) devices should be marked SID_REMOVABLE, so that eject(1) can
succeed. No downside in the bottom part of the driver.
ok dlg krw


Revision tags: OPENBSD_6_0_BASE
# 1.36 05-May-2016 kettenis

Populate SCSI inquiry data with information from SD and MMC cards.
Code is slightly more convoluted to avoid using strncpy(9).

ok jsg@, millert@, deraadt@


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.35 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.34 09-Dec-2014 doug

More malloc() -> mallocarray() in the kernel.

ok deraadt@ tedu@


# 1.33 01-Nov-2014 jsg

fix the build when SDMMC_DEBUG is defined


# 1.32 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.31 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.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.30 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.29 09-Jul-2011 matthew

Simplify sdmmc_scsi by using SCSI_NO_ADAPTER_TARGET.

Tested by drahn@


# 1.28 09-Jul-2011 matthew

Kludge around sdmmc(4)'s poor design: replace "struct scsi_link *"
with "struct scsibus_attach_args" in sdmmc_attach_args.

ok krw@


# 1.27 16-Jun-2011 dlg

dont respond to VPD inquiries with standard inquiry data. add a
check to make sure cmdlen is correct while there.

ok miod@


Revision tags: OPENBSD_4_9_BASE
# 1.26 25-Oct-2010 krw

Iopoolification. Tested by mcbride@, dlg@, and Gabriel Kihlman on tech@.

ok dlg@


# 1.25 24-Aug-2010 blambert

lockmgr -> rwlock conversion

and with this, my adventure in sdmmc-land is over
bikeshed is still banana-shaped

ok oga@


# 1.24 19-Aug-2010 jasper

- fold several occurences of DEVNAME() into one located in sdmmcvar.h.
making DEVNAME() usage a lot more consistent.

ok krw@


Revision tags: OPENBSD_4_8_BASE
# 1.23 20-Jun-2010 mk

Don't use and maintain a function pointer that is only ever set to one
function. Just call the function where needed.

ok krw dlg


# 1.22 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.21 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.20 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.19 03-Oct-2009 kettenis

Add missing <sys/device.h>.

ok deraadt@, miod@


# 1.18 05-Sep-2009 dlg

scsi_done before COMPLETE


Revision tags: OPENBSD_4_6_BASE
# 1.17 07-Apr-2009 blambert

Remove recursion from the sdmmc locking regime.

In snaps for a while.

Originally hacked on phessler@'s couch.
Testing by many, input from jsg@

"I'm tired of seeing the Ms" deraadt@


# 1.16 24-Mar-2009 kettenis

Remove redundant casts.


Revision tags: OPENBSD_4_5_BASE
# 1.15 20-Feb-2009 miod

Let the sdmmc adapters tell the sdmmc layer how much sectors they can
transfer with one command. Build on this and the recent minphys() changes
in the sdmmc layer to crank transfers at the maximum possible size instead
of a sad DEV_BSIZE.

Depending on your controller, this can speed up sdmmc I/O up to 2.5 times.


# 1.14 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.13 06-Feb-2009 grange

Fix crash on zaurus when sd memory card plugged by providing an attachment
structure that slave devices like sbt expect.


# 1.12 21-Jan-2009 grange

Replace timeout_add(msecs * hz / 1000) with timeout_add_msec(msecs).
No functional changes.

ok krw@ miod@


# 1.11 02-Dec-2008 deraadt

backout: would have been nice if this had been tested, to see that it
crashes the moment a card is plugged in.


# 1.10 24-Nov-2008 blambert

Rework sdmmc locking to remove recursion
Add SDMMC_ASSERT_LOCKED(), replacing many locking calls, and sprinkling
the assertion to make sure that future changes don't catch us out

"please commit" uwe@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.9 11-Sep-2007 gilles

KNF

prompted and "much better" by marco@, ok pyr@


# 1.8 10-Sep-2007 gilles

more MALLOC/FREE -> malloc/free and M_ZERO changes

ok pyr@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.7 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


# 1.6 17-Oct-2006 dlg

dont pass a copy of sdmmcs scsi_link struct on the stack to the midlayer.
it triggered a panic on detach of the scsibus when it tried to use the
adapters scsi_link struct that was no longer there.

issue found by and this fix tested by pedro@
ok krw@ looks right deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.5 23-Aug-2006 pedro

Protect scsi_done() with splbio(), discussed with and okay dlg@, marco@
and fgsch@, uwe@ time-out :(


# 1.4 18-Jul-2006 uwe

First and foremost, avoid an obious race between two or more processes
trying to get MMC commands through to the SD/MMC host controller via the
emulated SCSI layer. This is achieved by ensuring exclusive access to
the host controller for one process during any MMC command and during a
sequence of commands at the sdmmc(4) layer.

While at it, the command processing thread has been moved to sdmmc(4),
so as to simplify the implementation of future host controller drivers.
This should also pave the way for further cleanup of the code and for
new drivers.

Minor cleanups are included in this commit, as well.


# 1.3 01-Jun-2006 uwe

SDIO card identification


# 1.2 28-May-2006 uwe

don't #undef SDMMC_DEBUG


# 1.1 28-May-2006 uwe

Support for standard SD host controllers like the Ricoh 5C822, a small
generic bus layer, and SCSI emulation for SD/MMC memory cards.


# 1.57 05-Sep-2020 krw

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


# 1.56 03-Sep-2020 krw

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


# 1.55 02-Sep-2020 krw

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


# 1.54 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.53 25-Jul-2020 krw

No need for a bzero(), just init saa.sf to NULL. All the saa.saa
fields are explicitly initialized.


# 1.52 22-Jul-2020 krw

Nuke unused struct scsi_link members of adapter softc's where the
driver successfully compiles on one or more of amd64, i386, hppa.


# 1.51 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.50 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.49 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.48 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.47 03-Jul-2020 krw

Pass the expected 'scsibus_attach_args *' to scsibus_attach() via
config_found(), not a 'scsi_link *'. Part of matthew@'s 2010 work.


Revision tags: OPENBSD_6_7_BASE
# 1.46 20-Feb-2020 krw

Relax the grip the dead hand of QBUS (a.k.a. MAXPHYS) has on the
throat of physio().

Allows individual devices to eventually be modified to support larger
physio() (a.k.a. 'raw') i/o's if they prove capable of them.

No immediate functional change.

Tested for many weeks by and ok robert@.


# 1.45 12-Feb-2020 krw

Bring a few stragglers into line with the idiom used by the other 40+
scsi drivers. i.e. eliminate the struct scsi_adapter member in the
softc and rely on the pointer to a static scsi_adapter in the struct
scsi_link member.


# 1.44 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.43 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


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.42 30-Mar-2018 jmatthew

Add some sensible error checking in the hibernate io path, helpfully
suggested by coverity (via daniel@)


Revision tags: OPENBSD_6_3_BASE
# 1.41 20-Mar-2018 jmatthew

Add hibernate IO path for sdmmc(4). This requires some help from the
sdmmc chipset driver, currently only implemented in sdhc(4), but
mostly uses the regular path. sdhc(4) also needed the ability to
perform IO while cold.

ok deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.40 06-Apr-2017 deraadt

Sizes for the remaining free() calls, and use mallocarray()
ok visa


# 1.39 06-Apr-2017 deraadt

add sizes to free() calls
ok dhill


Revision tags: OPENBSD_6_1_BASE
# 1.38 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


# 1.37 20-Jan-2017 deraadt

sdmmc sd(4) devices should be marked SID_REMOVABLE, so that eject(1) can
succeed. No downside in the bottom part of the driver.
ok dlg krw


Revision tags: OPENBSD_6_0_BASE
# 1.36 05-May-2016 kettenis

Populate SCSI inquiry data with information from SD and MMC cards.
Code is slightly more convoluted to avoid using strncpy(9).

ok jsg@, millert@, deraadt@


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.35 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.34 09-Dec-2014 doug

More malloc() -> mallocarray() in the kernel.

ok deraadt@ tedu@


# 1.33 01-Nov-2014 jsg

fix the build when SDMMC_DEBUG is defined


# 1.32 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.31 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.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.30 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.29 09-Jul-2011 matthew

Simplify sdmmc_scsi by using SCSI_NO_ADAPTER_TARGET.

Tested by drahn@


# 1.28 09-Jul-2011 matthew

Kludge around sdmmc(4)'s poor design: replace "struct scsi_link *"
with "struct scsibus_attach_args" in sdmmc_attach_args.

ok krw@


# 1.27 16-Jun-2011 dlg

dont respond to VPD inquiries with standard inquiry data. add a
check to make sure cmdlen is correct while there.

ok miod@


Revision tags: OPENBSD_4_9_BASE
# 1.26 25-Oct-2010 krw

Iopoolification. Tested by mcbride@, dlg@, and Gabriel Kihlman on tech@.

ok dlg@


# 1.25 24-Aug-2010 blambert

lockmgr -> rwlock conversion

and with this, my adventure in sdmmc-land is over
bikeshed is still banana-shaped

ok oga@


# 1.24 19-Aug-2010 jasper

- fold several occurences of DEVNAME() into one located in sdmmcvar.h.
making DEVNAME() usage a lot more consistent.

ok krw@


Revision tags: OPENBSD_4_8_BASE
# 1.23 20-Jun-2010 mk

Don't use and maintain a function pointer that is only ever set to one
function. Just call the function where needed.

ok krw dlg


# 1.22 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.21 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.20 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.19 03-Oct-2009 kettenis

Add missing <sys/device.h>.

ok deraadt@, miod@


# 1.18 05-Sep-2009 dlg

scsi_done before COMPLETE


Revision tags: OPENBSD_4_6_BASE
# 1.17 07-Apr-2009 blambert

Remove recursion from the sdmmc locking regime.

In snaps for a while.

Originally hacked on phessler@'s couch.
Testing by many, input from jsg@

"I'm tired of seeing the Ms" deraadt@


# 1.16 24-Mar-2009 kettenis

Remove redundant casts.


Revision tags: OPENBSD_4_5_BASE
# 1.15 20-Feb-2009 miod

Let the sdmmc adapters tell the sdmmc layer how much sectors they can
transfer with one command. Build on this and the recent minphys() changes
in the sdmmc layer to crank transfers at the maximum possible size instead
of a sad DEV_BSIZE.

Depending on your controller, this can speed up sdmmc I/O up to 2.5 times.


# 1.14 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.13 06-Feb-2009 grange

Fix crash on zaurus when sd memory card plugged by providing an attachment
structure that slave devices like sbt expect.


# 1.12 21-Jan-2009 grange

Replace timeout_add(msecs * hz / 1000) with timeout_add_msec(msecs).
No functional changes.

ok krw@ miod@


# 1.11 02-Dec-2008 deraadt

backout: would have been nice if this had been tested, to see that it
crashes the moment a card is plugged in.


# 1.10 24-Nov-2008 blambert

Rework sdmmc locking to remove recursion
Add SDMMC_ASSERT_LOCKED(), replacing many locking calls, and sprinkling
the assertion to make sure that future changes don't catch us out

"please commit" uwe@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.9 11-Sep-2007 gilles

KNF

prompted and "much better" by marco@, ok pyr@


# 1.8 10-Sep-2007 gilles

more MALLOC/FREE -> malloc/free and M_ZERO changes

ok pyr@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.7 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


# 1.6 17-Oct-2006 dlg

dont pass a copy of sdmmcs scsi_link struct on the stack to the midlayer.
it triggered a panic on detach of the scsibus when it tried to use the
adapters scsi_link struct that was no longer there.

issue found by and this fix tested by pedro@
ok krw@ looks right deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.5 23-Aug-2006 pedro

Protect scsi_done() with splbio(), discussed with and okay dlg@, marco@
and fgsch@, uwe@ time-out :(


# 1.4 18-Jul-2006 uwe

First and foremost, avoid an obious race between two or more processes
trying to get MMC commands through to the SD/MMC host controller via the
emulated SCSI layer. This is achieved by ensuring exclusive access to
the host controller for one process during any MMC command and during a
sequence of commands at the sdmmc(4) layer.

While at it, the command processing thread has been moved to sdmmc(4),
so as to simplify the implementation of future host controller drivers.
This should also pave the way for further cleanup of the code and for
new drivers.

Minor cleanups are included in this commit, as well.


# 1.3 01-Jun-2006 uwe

SDIO card identification


# 1.2 28-May-2006 uwe

don't #undef SDMMC_DEBUG


# 1.1 28-May-2006 uwe

Support for standard SD host controllers like the Ricoh 5C822, a small
generic bus layer, and SCSI emulation for SD/MMC memory cards.


# 1.56 03-Sep-2020 krw

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


# 1.55 02-Sep-2020 krw

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


# 1.54 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.53 25-Jul-2020 krw

No need for a bzero(), just init saa.sf to NULL. All the saa.saa
fields are explicitly initialized.


# 1.52 22-Jul-2020 krw

Nuke unused struct scsi_link members of adapter softc's where the
driver successfully compiles on one or more of amd64, i386, hppa.


# 1.51 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.50 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.49 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.48 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.47 03-Jul-2020 krw

Pass the expected 'scsibus_attach_args *' to scsibus_attach() via
config_found(), not a 'scsi_link *'. Part of matthew@'s 2010 work.


Revision tags: OPENBSD_6_7_BASE
# 1.46 20-Feb-2020 krw

Relax the grip the dead hand of QBUS (a.k.a. MAXPHYS) has on the
throat of physio().

Allows individual devices to eventually be modified to support larger
physio() (a.k.a. 'raw') i/o's if they prove capable of them.

No immediate functional change.

Tested for many weeks by and ok robert@.


# 1.45 12-Feb-2020 krw

Bring a few stragglers into line with the idiom used by the other 40+
scsi drivers. i.e. eliminate the struct scsi_adapter member in the
softc and rely on the pointer to a static scsi_adapter in the struct
scsi_link member.


# 1.44 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.43 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


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.42 30-Mar-2018 jmatthew

Add some sensible error checking in the hibernate io path, helpfully
suggested by coverity (via daniel@)


Revision tags: OPENBSD_6_3_BASE
# 1.41 20-Mar-2018 jmatthew

Add hibernate IO path for sdmmc(4). This requires some help from the
sdmmc chipset driver, currently only implemented in sdhc(4), but
mostly uses the regular path. sdhc(4) also needed the ability to
perform IO while cold.

ok deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.40 06-Apr-2017 deraadt

Sizes for the remaining free() calls, and use mallocarray()
ok visa


# 1.39 06-Apr-2017 deraadt

add sizes to free() calls
ok dhill


Revision tags: OPENBSD_6_1_BASE
# 1.38 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


# 1.37 20-Jan-2017 deraadt

sdmmc sd(4) devices should be marked SID_REMOVABLE, so that eject(1) can
succeed. No downside in the bottom part of the driver.
ok dlg krw


Revision tags: OPENBSD_6_0_BASE
# 1.36 05-May-2016 kettenis

Populate SCSI inquiry data with information from SD and MMC cards.
Code is slightly more convoluted to avoid using strncpy(9).

ok jsg@, millert@, deraadt@


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.35 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.34 09-Dec-2014 doug

More malloc() -> mallocarray() in the kernel.

ok deraadt@ tedu@


# 1.33 01-Nov-2014 jsg

fix the build when SDMMC_DEBUG is defined


# 1.32 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.31 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.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.30 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.29 09-Jul-2011 matthew

Simplify sdmmc_scsi by using SCSI_NO_ADAPTER_TARGET.

Tested by drahn@


# 1.28 09-Jul-2011 matthew

Kludge around sdmmc(4)'s poor design: replace "struct scsi_link *"
with "struct scsibus_attach_args" in sdmmc_attach_args.

ok krw@


# 1.27 16-Jun-2011 dlg

dont respond to VPD inquiries with standard inquiry data. add a
check to make sure cmdlen is correct while there.

ok miod@


Revision tags: OPENBSD_4_9_BASE
# 1.26 25-Oct-2010 krw

Iopoolification. Tested by mcbride@, dlg@, and Gabriel Kihlman on tech@.

ok dlg@


# 1.25 24-Aug-2010 blambert

lockmgr -> rwlock conversion

and with this, my adventure in sdmmc-land is over
bikeshed is still banana-shaped

ok oga@


# 1.24 19-Aug-2010 jasper

- fold several occurences of DEVNAME() into one located in sdmmcvar.h.
making DEVNAME() usage a lot more consistent.

ok krw@


Revision tags: OPENBSD_4_8_BASE
# 1.23 20-Jun-2010 mk

Don't use and maintain a function pointer that is only ever set to one
function. Just call the function where needed.

ok krw dlg


# 1.22 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.21 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.20 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.19 03-Oct-2009 kettenis

Add missing <sys/device.h>.

ok deraadt@, miod@


# 1.18 05-Sep-2009 dlg

scsi_done before COMPLETE


Revision tags: OPENBSD_4_6_BASE
# 1.17 07-Apr-2009 blambert

Remove recursion from the sdmmc locking regime.

In snaps for a while.

Originally hacked on phessler@'s couch.
Testing by many, input from jsg@

"I'm tired of seeing the Ms" deraadt@


# 1.16 24-Mar-2009 kettenis

Remove redundant casts.


Revision tags: OPENBSD_4_5_BASE
# 1.15 20-Feb-2009 miod

Let the sdmmc adapters tell the sdmmc layer how much sectors they can
transfer with one command. Build on this and the recent minphys() changes
in the sdmmc layer to crank transfers at the maximum possible size instead
of a sad DEV_BSIZE.

Depending on your controller, this can speed up sdmmc I/O up to 2.5 times.


# 1.14 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.13 06-Feb-2009 grange

Fix crash on zaurus when sd memory card plugged by providing an attachment
structure that slave devices like sbt expect.


# 1.12 21-Jan-2009 grange

Replace timeout_add(msecs * hz / 1000) with timeout_add_msec(msecs).
No functional changes.

ok krw@ miod@


# 1.11 02-Dec-2008 deraadt

backout: would have been nice if this had been tested, to see that it
crashes the moment a card is plugged in.


# 1.10 24-Nov-2008 blambert

Rework sdmmc locking to remove recursion
Add SDMMC_ASSERT_LOCKED(), replacing many locking calls, and sprinkling
the assertion to make sure that future changes don't catch us out

"please commit" uwe@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.9 11-Sep-2007 gilles

KNF

prompted and "much better" by marco@, ok pyr@


# 1.8 10-Sep-2007 gilles

more MALLOC/FREE -> malloc/free and M_ZERO changes

ok pyr@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.7 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


# 1.6 17-Oct-2006 dlg

dont pass a copy of sdmmcs scsi_link struct on the stack to the midlayer.
it triggered a panic on detach of the scsibus when it tried to use the
adapters scsi_link struct that was no longer there.

issue found by and this fix tested by pedro@
ok krw@ looks right deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.5 23-Aug-2006 pedro

Protect scsi_done() with splbio(), discussed with and okay dlg@, marco@
and fgsch@, uwe@ time-out :(


# 1.4 18-Jul-2006 uwe

First and foremost, avoid an obious race between two or more processes
trying to get MMC commands through to the SD/MMC host controller via the
emulated SCSI layer. This is achieved by ensuring exclusive access to
the host controller for one process during any MMC command and during a
sequence of commands at the sdmmc(4) layer.

While at it, the command processing thread has been moved to sdmmc(4),
so as to simplify the implementation of future host controller drivers.
This should also pave the way for further cleanup of the code and for
new drivers.

Minor cleanups are included in this commit, as well.


# 1.3 01-Jun-2006 uwe

SDIO card identification


# 1.2 28-May-2006 uwe

don't #undef SDMMC_DEBUG


# 1.1 28-May-2006 uwe

Support for standard SD host controllers like the Ricoh 5C822, a small
generic bus layer, and SCSI emulation for SD/MMC memory cards.


# 1.56 03-Sep-2020 krw

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


# 1.55 02-Sep-2020 krw

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


# 1.54 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.53 25-Jul-2020 krw

No need for a bzero(), just init saa.sf to NULL. All the saa.saa
fields are explicitly initialized.


# 1.52 22-Jul-2020 krw

Nuke unused struct scsi_link members of adapter softc's where the
driver successfully compiles on one or more of amd64, i386, hppa.


# 1.51 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.50 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.49 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.48 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.47 03-Jul-2020 krw

Pass the expected 'scsibus_attach_args *' to scsibus_attach() via
config_found(), not a 'scsi_link *'. Part of matthew@'s 2010 work.


Revision tags: OPENBSD_6_7_BASE
# 1.46 20-Feb-2020 krw

Relax the grip the dead hand of QBUS (a.k.a. MAXPHYS) has on the
throat of physio().

Allows individual devices to eventually be modified to support larger
physio() (a.k.a. 'raw') i/o's if they prove capable of them.

No immediate functional change.

Tested for many weeks by and ok robert@.


# 1.45 12-Feb-2020 krw

Bring a few stragglers into line with the idiom used by the other 40+
scsi drivers. i.e. eliminate the struct scsi_adapter member in the
softc and rely on the pointer to a static scsi_adapter in the struct
scsi_link member.


# 1.44 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.43 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


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.42 30-Mar-2018 jmatthew

Add some sensible error checking in the hibernate io path, helpfully
suggested by coverity (via daniel@)


Revision tags: OPENBSD_6_3_BASE
# 1.41 20-Mar-2018 jmatthew

Add hibernate IO path for sdmmc(4). This requires some help from the
sdmmc chipset driver, currently only implemented in sdhc(4), but
mostly uses the regular path. sdhc(4) also needed the ability to
perform IO while cold.

ok deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.40 06-Apr-2017 deraadt

Sizes for the remaining free() calls, and use mallocarray()
ok visa


# 1.39 06-Apr-2017 deraadt

add sizes to free() calls
ok dhill


Revision tags: OPENBSD_6_1_BASE
# 1.38 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


# 1.37 20-Jan-2017 deraadt

sdmmc sd(4) devices should be marked SID_REMOVABLE, so that eject(1) can
succeed. No downside in the bottom part of the driver.
ok dlg krw


Revision tags: OPENBSD_6_0_BASE
# 1.36 05-May-2016 kettenis

Populate SCSI inquiry data with information from SD and MMC cards.
Code is slightly more convoluted to avoid using strncpy(9).

ok jsg@, millert@, deraadt@


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.35 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.34 09-Dec-2014 doug

More malloc() -> mallocarray() in the kernel.

ok deraadt@ tedu@


# 1.33 01-Nov-2014 jsg

fix the build when SDMMC_DEBUG is defined


# 1.32 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.31 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.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.30 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.29 09-Jul-2011 matthew

Simplify sdmmc_scsi by using SCSI_NO_ADAPTER_TARGET.

Tested by drahn@


# 1.28 09-Jul-2011 matthew

Kludge around sdmmc(4)'s poor design: replace "struct scsi_link *"
with "struct scsibus_attach_args" in sdmmc_attach_args.

ok krw@


# 1.27 16-Jun-2011 dlg

dont respond to VPD inquiries with standard inquiry data. add a
check to make sure cmdlen is correct while there.

ok miod@


Revision tags: OPENBSD_4_9_BASE
# 1.26 25-Oct-2010 krw

Iopoolification. Tested by mcbride@, dlg@, and Gabriel Kihlman on tech@.

ok dlg@


# 1.25 24-Aug-2010 blambert

lockmgr -> rwlock conversion

and with this, my adventure in sdmmc-land is over
bikeshed is still banana-shaped

ok oga@


# 1.24 19-Aug-2010 jasper

- fold several occurences of DEVNAME() into one located in sdmmcvar.h.
making DEVNAME() usage a lot more consistent.

ok krw@


Revision tags: OPENBSD_4_8_BASE
# 1.23 20-Jun-2010 mk

Don't use and maintain a function pointer that is only ever set to one
function. Just call the function where needed.

ok krw dlg


# 1.22 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.21 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.20 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.19 03-Oct-2009 kettenis

Add missing <sys/device.h>.

ok deraadt@, miod@


# 1.18 05-Sep-2009 dlg

scsi_done before COMPLETE


Revision tags: OPENBSD_4_6_BASE
# 1.17 07-Apr-2009 blambert

Remove recursion from the sdmmc locking regime.

In snaps for a while.

Originally hacked on phessler@'s couch.
Testing by many, input from jsg@

"I'm tired of seeing the Ms" deraadt@


# 1.16 24-Mar-2009 kettenis

Remove redundant casts.


Revision tags: OPENBSD_4_5_BASE
# 1.15 20-Feb-2009 miod

Let the sdmmc adapters tell the sdmmc layer how much sectors they can
transfer with one command. Build on this and the recent minphys() changes
in the sdmmc layer to crank transfers at the maximum possible size instead
of a sad DEV_BSIZE.

Depending on your controller, this can speed up sdmmc I/O up to 2.5 times.


# 1.14 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.13 06-Feb-2009 grange

Fix crash on zaurus when sd memory card plugged by providing an attachment
structure that slave devices like sbt expect.


# 1.12 21-Jan-2009 grange

Replace timeout_add(msecs * hz / 1000) with timeout_add_msec(msecs).
No functional changes.

ok krw@ miod@


# 1.11 02-Dec-2008 deraadt

backout: would have been nice if this had been tested, to see that it
crashes the moment a card is plugged in.


# 1.10 24-Nov-2008 blambert

Rework sdmmc locking to remove recursion
Add SDMMC_ASSERT_LOCKED(), replacing many locking calls, and sprinkling
the assertion to make sure that future changes don't catch us out

"please commit" uwe@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.9 11-Sep-2007 gilles

KNF

prompted and "much better" by marco@, ok pyr@


# 1.8 10-Sep-2007 gilles

more MALLOC/FREE -> malloc/free and M_ZERO changes

ok pyr@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.7 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


# 1.6 17-Oct-2006 dlg

dont pass a copy of sdmmcs scsi_link struct on the stack to the midlayer.
it triggered a panic on detach of the scsibus when it tried to use the
adapters scsi_link struct that was no longer there.

issue found by and this fix tested by pedro@
ok krw@ looks right deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.5 23-Aug-2006 pedro

Protect scsi_done() with splbio(), discussed with and okay dlg@, marco@
and fgsch@, uwe@ time-out :(


# 1.4 18-Jul-2006 uwe

First and foremost, avoid an obious race between two or more processes
trying to get MMC commands through to the SD/MMC host controller via the
emulated SCSI layer. This is achieved by ensuring exclusive access to
the host controller for one process during any MMC command and during a
sequence of commands at the sdmmc(4) layer.

While at it, the command processing thread has been moved to sdmmc(4),
so as to simplify the implementation of future host controller drivers.
This should also pave the way for further cleanup of the code and for
new drivers.

Minor cleanups are included in this commit, as well.


# 1.3 01-Jun-2006 uwe

SDIO card identification


# 1.2 28-May-2006 uwe

don't #undef SDMMC_DEBUG


# 1.1 28-May-2006 uwe

Support for standard SD host controllers like the Ricoh 5C822, a small
generic bus layer, and SCSI emulation for SD/MMC memory cards.


# 1.54 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.53 25-Jul-2020 krw

No need for a bzero(), just init saa.sf to NULL. All the saa.saa
fields are explicitly initialized.


# 1.52 22-Jul-2020 krw

Nuke unused struct scsi_link members of adapter softc's where the
driver successfully compiles on one or more of amd64, i386, hppa.


# 1.51 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.50 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.49 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.48 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.47 03-Jul-2020 krw

Pass the expected 'scsibus_attach_args *' to scsibus_attach() via
config_found(), not a 'scsi_link *'. Part of matthew@'s 2010 work.


Revision tags: OPENBSD_6_7_BASE
# 1.46 20-Feb-2020 krw

Relax the grip the dead hand of QBUS (a.k.a. MAXPHYS) has on the
throat of physio().

Allows individual devices to eventually be modified to support larger
physio() (a.k.a. 'raw') i/o's if they prove capable of them.

No immediate functional change.

Tested for many weeks by and ok robert@.


# 1.45 12-Feb-2020 krw

Bring a few stragglers into line with the idiom used by the other 40+
scsi drivers. i.e. eliminate the struct scsi_adapter member in the
softc and rely on the pointer to a static scsi_adapter in the struct
scsi_link member.


# 1.44 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.43 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


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.42 30-Mar-2018 jmatthew

Add some sensible error checking in the hibernate io path, helpfully
suggested by coverity (via daniel@)


Revision tags: OPENBSD_6_3_BASE
# 1.41 20-Mar-2018 jmatthew

Add hibernate IO path for sdmmc(4). This requires some help from the
sdmmc chipset driver, currently only implemented in sdhc(4), but
mostly uses the regular path. sdhc(4) also needed the ability to
perform IO while cold.

ok deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.40 06-Apr-2017 deraadt

Sizes for the remaining free() calls, and use mallocarray()
ok visa


# 1.39 06-Apr-2017 deraadt

add sizes to free() calls
ok dhill


Revision tags: OPENBSD_6_1_BASE
# 1.38 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


# 1.37 20-Jan-2017 deraadt

sdmmc sd(4) devices should be marked SID_REMOVABLE, so that eject(1) can
succeed. No downside in the bottom part of the driver.
ok dlg krw


Revision tags: OPENBSD_6_0_BASE
# 1.36 05-May-2016 kettenis

Populate SCSI inquiry data with information from SD and MMC cards.
Code is slightly more convoluted to avoid using strncpy(9).

ok jsg@, millert@, deraadt@


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.35 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.34 09-Dec-2014 doug

More malloc() -> mallocarray() in the kernel.

ok deraadt@ tedu@


# 1.33 01-Nov-2014 jsg

fix the build when SDMMC_DEBUG is defined


# 1.32 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.31 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.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.30 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.29 09-Jul-2011 matthew

Simplify sdmmc_scsi by using SCSI_NO_ADAPTER_TARGET.

Tested by drahn@


# 1.28 09-Jul-2011 matthew

Kludge around sdmmc(4)'s poor design: replace "struct scsi_link *"
with "struct scsibus_attach_args" in sdmmc_attach_args.

ok krw@


# 1.27 16-Jun-2011 dlg

dont respond to VPD inquiries with standard inquiry data. add a
check to make sure cmdlen is correct while there.

ok miod@


Revision tags: OPENBSD_4_9_BASE
# 1.26 25-Oct-2010 krw

Iopoolification. Tested by mcbride@, dlg@, and Gabriel Kihlman on tech@.

ok dlg@


# 1.25 24-Aug-2010 blambert

lockmgr -> rwlock conversion

and with this, my adventure in sdmmc-land is over
bikeshed is still banana-shaped

ok oga@


# 1.24 19-Aug-2010 jasper

- fold several occurences of DEVNAME() into one located in sdmmcvar.h.
making DEVNAME() usage a lot more consistent.

ok krw@


Revision tags: OPENBSD_4_8_BASE
# 1.23 20-Jun-2010 mk

Don't use and maintain a function pointer that is only ever set to one
function. Just call the function where needed.

ok krw dlg


# 1.22 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.21 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.20 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.19 03-Oct-2009 kettenis

Add missing <sys/device.h>.

ok deraadt@, miod@


# 1.18 05-Sep-2009 dlg

scsi_done before COMPLETE


Revision tags: OPENBSD_4_6_BASE
# 1.17 07-Apr-2009 blambert

Remove recursion from the sdmmc locking regime.

In snaps for a while.

Originally hacked on phessler@'s couch.
Testing by many, input from jsg@

"I'm tired of seeing the Ms" deraadt@


# 1.16 24-Mar-2009 kettenis

Remove redundant casts.


Revision tags: OPENBSD_4_5_BASE
# 1.15 20-Feb-2009 miod

Let the sdmmc adapters tell the sdmmc layer how much sectors they can
transfer with one command. Build on this and the recent minphys() changes
in the sdmmc layer to crank transfers at the maximum possible size instead
of a sad DEV_BSIZE.

Depending on your controller, this can speed up sdmmc I/O up to 2.5 times.


# 1.14 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.13 06-Feb-2009 grange

Fix crash on zaurus when sd memory card plugged by providing an attachment
structure that slave devices like sbt expect.


# 1.12 21-Jan-2009 grange

Replace timeout_add(msecs * hz / 1000) with timeout_add_msec(msecs).
No functional changes.

ok krw@ miod@


# 1.11 02-Dec-2008 deraadt

backout: would have been nice if this had been tested, to see that it
crashes the moment a card is plugged in.


# 1.10 24-Nov-2008 blambert

Rework sdmmc locking to remove recursion
Add SDMMC_ASSERT_LOCKED(), replacing many locking calls, and sprinkling
the assertion to make sure that future changes don't catch us out

"please commit" uwe@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.9 11-Sep-2007 gilles

KNF

prompted and "much better" by marco@, ok pyr@


# 1.8 10-Sep-2007 gilles

more MALLOC/FREE -> malloc/free and M_ZERO changes

ok pyr@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.7 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


# 1.6 17-Oct-2006 dlg

dont pass a copy of sdmmcs scsi_link struct on the stack to the midlayer.
it triggered a panic on detach of the scsibus when it tried to use the
adapters scsi_link struct that was no longer there.

issue found by and this fix tested by pedro@
ok krw@ looks right deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.5 23-Aug-2006 pedro

Protect scsi_done() with splbio(), discussed with and okay dlg@, marco@
and fgsch@, uwe@ time-out :(


# 1.4 18-Jul-2006 uwe

First and foremost, avoid an obious race between two or more processes
trying to get MMC commands through to the SD/MMC host controller via the
emulated SCSI layer. This is achieved by ensuring exclusive access to
the host controller for one process during any MMC command and during a
sequence of commands at the sdmmc(4) layer.

While at it, the command processing thread has been moved to sdmmc(4),
so as to simplify the implementation of future host controller drivers.
This should also pave the way for further cleanup of the code and for
new drivers.

Minor cleanups are included in this commit, as well.


# 1.3 01-Jun-2006 uwe

SDIO card identification


# 1.2 28-May-2006 uwe

don't #undef SDMMC_DEBUG


# 1.1 28-May-2006 uwe

Support for standard SD host controllers like the Ricoh 5C822, a small
generic bus layer, and SCSI emulation for SD/MMC memory cards.


# 1.53 25-Jul-2020 krw

No need for a bzero(), just init saa.sf to NULL. All the saa.saa
fields are explicitly initialized.


# 1.52 22-Jul-2020 krw

Nuke unused struct scsi_link members of adapter softc's where the
driver successfully compiles on one or more of amd64, i386, hppa.


# 1.51 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.50 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.49 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.48 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.47 03-Jul-2020 krw

Pass the expected 'scsibus_attach_args *' to scsibus_attach() via
config_found(), not a 'scsi_link *'. Part of matthew@'s 2010 work.


Revision tags: OPENBSD_6_7_BASE
# 1.46 20-Feb-2020 krw

Relax the grip the dead hand of QBUS (a.k.a. MAXPHYS) has on the
throat of physio().

Allows individual devices to eventually be modified to support larger
physio() (a.k.a. 'raw') i/o's if they prove capable of them.

No immediate functional change.

Tested for many weeks by and ok robert@.


# 1.45 12-Feb-2020 krw

Bring a few stragglers into line with the idiom used by the other 40+
scsi drivers. i.e. eliminate the struct scsi_adapter member in the
softc and rely on the pointer to a static scsi_adapter in the struct
scsi_link member.


# 1.44 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.43 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


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.42 30-Mar-2018 jmatthew

Add some sensible error checking in the hibernate io path, helpfully
suggested by coverity (via daniel@)


Revision tags: OPENBSD_6_3_BASE
# 1.41 20-Mar-2018 jmatthew

Add hibernate IO path for sdmmc(4). This requires some help from the
sdmmc chipset driver, currently only implemented in sdhc(4), but
mostly uses the regular path. sdhc(4) also needed the ability to
perform IO while cold.

ok deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.40 06-Apr-2017 deraadt

Sizes for the remaining free() calls, and use mallocarray()
ok visa


# 1.39 06-Apr-2017 deraadt

add sizes to free() calls
ok dhill


Revision tags: OPENBSD_6_1_BASE
# 1.38 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


# 1.37 20-Jan-2017 deraadt

sdmmc sd(4) devices should be marked SID_REMOVABLE, so that eject(1) can
succeed. No downside in the bottom part of the driver.
ok dlg krw


Revision tags: OPENBSD_6_0_BASE
# 1.36 05-May-2016 kettenis

Populate SCSI inquiry data with information from SD and MMC cards.
Code is slightly more convoluted to avoid using strncpy(9).

ok jsg@, millert@, deraadt@


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.35 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.34 09-Dec-2014 doug

More malloc() -> mallocarray() in the kernel.

ok deraadt@ tedu@


# 1.33 01-Nov-2014 jsg

fix the build when SDMMC_DEBUG is defined


# 1.32 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.31 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.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.30 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.29 09-Jul-2011 matthew

Simplify sdmmc_scsi by using SCSI_NO_ADAPTER_TARGET.

Tested by drahn@


# 1.28 09-Jul-2011 matthew

Kludge around sdmmc(4)'s poor design: replace "struct scsi_link *"
with "struct scsibus_attach_args" in sdmmc_attach_args.

ok krw@


# 1.27 16-Jun-2011 dlg

dont respond to VPD inquiries with standard inquiry data. add a
check to make sure cmdlen is correct while there.

ok miod@


Revision tags: OPENBSD_4_9_BASE
# 1.26 25-Oct-2010 krw

Iopoolification. Tested by mcbride@, dlg@, and Gabriel Kihlman on tech@.

ok dlg@


# 1.25 24-Aug-2010 blambert

lockmgr -> rwlock conversion

and with this, my adventure in sdmmc-land is over
bikeshed is still banana-shaped

ok oga@


# 1.24 19-Aug-2010 jasper

- fold several occurences of DEVNAME() into one located in sdmmcvar.h.
making DEVNAME() usage a lot more consistent.

ok krw@


Revision tags: OPENBSD_4_8_BASE
# 1.23 20-Jun-2010 mk

Don't use and maintain a function pointer that is only ever set to one
function. Just call the function where needed.

ok krw dlg


# 1.22 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.21 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.20 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.19 03-Oct-2009 kettenis

Add missing <sys/device.h>.

ok deraadt@, miod@


# 1.18 05-Sep-2009 dlg

scsi_done before COMPLETE


Revision tags: OPENBSD_4_6_BASE
# 1.17 07-Apr-2009 blambert

Remove recursion from the sdmmc locking regime.

In snaps for a while.

Originally hacked on phessler@'s couch.
Testing by many, input from jsg@

"I'm tired of seeing the Ms" deraadt@


# 1.16 24-Mar-2009 kettenis

Remove redundant casts.


Revision tags: OPENBSD_4_5_BASE
# 1.15 20-Feb-2009 miod

Let the sdmmc adapters tell the sdmmc layer how much sectors they can
transfer with one command. Build on this and the recent minphys() changes
in the sdmmc layer to crank transfers at the maximum possible size instead
of a sad DEV_BSIZE.

Depending on your controller, this can speed up sdmmc I/O up to 2.5 times.


# 1.14 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.13 06-Feb-2009 grange

Fix crash on zaurus when sd memory card plugged by providing an attachment
structure that slave devices like sbt expect.


# 1.12 21-Jan-2009 grange

Replace timeout_add(msecs * hz / 1000) with timeout_add_msec(msecs).
No functional changes.

ok krw@ miod@


# 1.11 02-Dec-2008 deraadt

backout: would have been nice if this had been tested, to see that it
crashes the moment a card is plugged in.


# 1.10 24-Nov-2008 blambert

Rework sdmmc locking to remove recursion
Add SDMMC_ASSERT_LOCKED(), replacing many locking calls, and sprinkling
the assertion to make sure that future changes don't catch us out

"please commit" uwe@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.9 11-Sep-2007 gilles

KNF

prompted and "much better" by marco@, ok pyr@


# 1.8 10-Sep-2007 gilles

more MALLOC/FREE -> malloc/free and M_ZERO changes

ok pyr@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.7 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


# 1.6 17-Oct-2006 dlg

dont pass a copy of sdmmcs scsi_link struct on the stack to the midlayer.
it triggered a panic on detach of the scsibus when it tried to use the
adapters scsi_link struct that was no longer there.

issue found by and this fix tested by pedro@
ok krw@ looks right deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.5 23-Aug-2006 pedro

Protect scsi_done() with splbio(), discussed with and okay dlg@, marco@
and fgsch@, uwe@ time-out :(


# 1.4 18-Jul-2006 uwe

First and foremost, avoid an obious race between two or more processes
trying to get MMC commands through to the SD/MMC host controller via the
emulated SCSI layer. This is achieved by ensuring exclusive access to
the host controller for one process during any MMC command and during a
sequence of commands at the sdmmc(4) layer.

While at it, the command processing thread has been moved to sdmmc(4),
so as to simplify the implementation of future host controller drivers.
This should also pave the way for further cleanup of the code and for
new drivers.

Minor cleanups are included in this commit, as well.


# 1.3 01-Jun-2006 uwe

SDIO card identification


# 1.2 28-May-2006 uwe

don't #undef SDMMC_DEBUG


# 1.1 28-May-2006 uwe

Support for standard SD host controllers like the Ricoh 5C822, a small
generic bus layer, and SCSI emulation for SD/MMC memory cards.


# 1.52 22-Jul-2020 krw

Nuke unused struct scsi_link members of adapter softc's where the
driver successfully compiles on one or more of amd64, i386, hppa.


# 1.51 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.50 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.49 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.48 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.47 03-Jul-2020 krw

Pass the expected 'scsibus_attach_args *' to scsibus_attach() via
config_found(), not a 'scsi_link *'. Part of matthew@'s 2010 work.


Revision tags: OPENBSD_6_7_BASE
# 1.46 20-Feb-2020 krw

Relax the grip the dead hand of QBUS (a.k.a. MAXPHYS) has on the
throat of physio().

Allows individual devices to eventually be modified to support larger
physio() (a.k.a. 'raw') i/o's if they prove capable of them.

No immediate functional change.

Tested for many weeks by and ok robert@.


# 1.45 12-Feb-2020 krw

Bring a few stragglers into line with the idiom used by the other 40+
scsi drivers. i.e. eliminate the struct scsi_adapter member in the
softc and rely on the pointer to a static scsi_adapter in the struct
scsi_link member.


# 1.44 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.43 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


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.42 30-Mar-2018 jmatthew

Add some sensible error checking in the hibernate io path, helpfully
suggested by coverity (via daniel@)


Revision tags: OPENBSD_6_3_BASE
# 1.41 20-Mar-2018 jmatthew

Add hibernate IO path for sdmmc(4). This requires some help from the
sdmmc chipset driver, currently only implemented in sdhc(4), but
mostly uses the regular path. sdhc(4) also needed the ability to
perform IO while cold.

ok deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.40 06-Apr-2017 deraadt

Sizes for the remaining free() calls, and use mallocarray()
ok visa


# 1.39 06-Apr-2017 deraadt

add sizes to free() calls
ok dhill


Revision tags: OPENBSD_6_1_BASE
# 1.38 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


# 1.37 20-Jan-2017 deraadt

sdmmc sd(4) devices should be marked SID_REMOVABLE, so that eject(1) can
succeed. No downside in the bottom part of the driver.
ok dlg krw


Revision tags: OPENBSD_6_0_BASE
# 1.36 05-May-2016 kettenis

Populate SCSI inquiry data with information from SD and MMC cards.
Code is slightly more convoluted to avoid using strncpy(9).

ok jsg@, millert@, deraadt@


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.35 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.34 09-Dec-2014 doug

More malloc() -> mallocarray() in the kernel.

ok deraadt@ tedu@


# 1.33 01-Nov-2014 jsg

fix the build when SDMMC_DEBUG is defined


# 1.32 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.31 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.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.30 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.29 09-Jul-2011 matthew

Simplify sdmmc_scsi by using SCSI_NO_ADAPTER_TARGET.

Tested by drahn@


# 1.28 09-Jul-2011 matthew

Kludge around sdmmc(4)'s poor design: replace "struct scsi_link *"
with "struct scsibus_attach_args" in sdmmc_attach_args.

ok krw@


# 1.27 16-Jun-2011 dlg

dont respond to VPD inquiries with standard inquiry data. add a
check to make sure cmdlen is correct while there.

ok miod@


Revision tags: OPENBSD_4_9_BASE
# 1.26 25-Oct-2010 krw

Iopoolification. Tested by mcbride@, dlg@, and Gabriel Kihlman on tech@.

ok dlg@


# 1.25 24-Aug-2010 blambert

lockmgr -> rwlock conversion

and with this, my adventure in sdmmc-land is over
bikeshed is still banana-shaped

ok oga@


# 1.24 19-Aug-2010 jasper

- fold several occurences of DEVNAME() into one located in sdmmcvar.h.
making DEVNAME() usage a lot more consistent.

ok krw@


Revision tags: OPENBSD_4_8_BASE
# 1.23 20-Jun-2010 mk

Don't use and maintain a function pointer that is only ever set to one
function. Just call the function where needed.

ok krw dlg


# 1.22 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.21 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.20 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.19 03-Oct-2009 kettenis

Add missing <sys/device.h>.

ok deraadt@, miod@


# 1.18 05-Sep-2009 dlg

scsi_done before COMPLETE


Revision tags: OPENBSD_4_6_BASE
# 1.17 07-Apr-2009 blambert

Remove recursion from the sdmmc locking regime.

In snaps for a while.

Originally hacked on phessler@'s couch.
Testing by many, input from jsg@

"I'm tired of seeing the Ms" deraadt@


# 1.16 24-Mar-2009 kettenis

Remove redundant casts.


Revision tags: OPENBSD_4_5_BASE
# 1.15 20-Feb-2009 miod

Let the sdmmc adapters tell the sdmmc layer how much sectors they can
transfer with one command. Build on this and the recent minphys() changes
in the sdmmc layer to crank transfers at the maximum possible size instead
of a sad DEV_BSIZE.

Depending on your controller, this can speed up sdmmc I/O up to 2.5 times.


# 1.14 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.13 06-Feb-2009 grange

Fix crash on zaurus when sd memory card plugged by providing an attachment
structure that slave devices like sbt expect.


# 1.12 21-Jan-2009 grange

Replace timeout_add(msecs * hz / 1000) with timeout_add_msec(msecs).
No functional changes.

ok krw@ miod@


# 1.11 02-Dec-2008 deraadt

backout: would have been nice if this had been tested, to see that it
crashes the moment a card is plugged in.


# 1.10 24-Nov-2008 blambert

Rework sdmmc locking to remove recursion
Add SDMMC_ASSERT_LOCKED(), replacing many locking calls, and sprinkling
the assertion to make sure that future changes don't catch us out

"please commit" uwe@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.9 11-Sep-2007 gilles

KNF

prompted and "much better" by marco@, ok pyr@


# 1.8 10-Sep-2007 gilles

more MALLOC/FREE -> malloc/free and M_ZERO changes

ok pyr@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.7 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


# 1.6 17-Oct-2006 dlg

dont pass a copy of sdmmcs scsi_link struct on the stack to the midlayer.
it triggered a panic on detach of the scsibus when it tried to use the
adapters scsi_link struct that was no longer there.

issue found by and this fix tested by pedro@
ok krw@ looks right deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.5 23-Aug-2006 pedro

Protect scsi_done() with splbio(), discussed with and okay dlg@, marco@
and fgsch@, uwe@ time-out :(


# 1.4 18-Jul-2006 uwe

First and foremost, avoid an obious race between two or more processes
trying to get MMC commands through to the SD/MMC host controller via the
emulated SCSI layer. This is achieved by ensuring exclusive access to
the host controller for one process during any MMC command and during a
sequence of commands at the sdmmc(4) layer.

While at it, the command processing thread has been moved to sdmmc(4),
so as to simplify the implementation of future host controller drivers.
This should also pave the way for further cleanup of the code and for
new drivers.

Minor cleanups are included in this commit, as well.


# 1.3 01-Jun-2006 uwe

SDIO card identification


# 1.2 28-May-2006 uwe

don't #undef SDMMC_DEBUG


# 1.1 28-May-2006 uwe

Support for standard SD host controllers like the Ricoh 5C822, a small
generic bus layer, and SCSI emulation for SD/MMC memory cards.


# 1.52 22-Jul-2020 krw

Nuke unused struct scsi_link members of adapter softc's where the
driver successfully compiles on one or more of amd64, i386, hppa.


# 1.51 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.50 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.49 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.48 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.47 03-Jul-2020 krw

Pass the expected 'scsibus_attach_args *' to scsibus_attach() via
config_found(), not a 'scsi_link *'. Part of matthew@'s 2010 work.


Revision tags: OPENBSD_6_7_BASE
# 1.46 20-Feb-2020 krw

Relax the grip the dead hand of QBUS (a.k.a. MAXPHYS) has on the
throat of physio().

Allows individual devices to eventually be modified to support larger
physio() (a.k.a. 'raw') i/o's if they prove capable of them.

No immediate functional change.

Tested for many weeks by and ok robert@.


# 1.45 12-Feb-2020 krw

Bring a few stragglers into line with the idiom used by the other 40+
scsi drivers. i.e. eliminate the struct scsi_adapter member in the
softc and rely on the pointer to a static scsi_adapter in the struct
scsi_link member.


# 1.44 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.43 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


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.42 30-Mar-2018 jmatthew

Add some sensible error checking in the hibernate io path, helpfully
suggested by coverity (via daniel@)


Revision tags: OPENBSD_6_3_BASE
# 1.41 20-Mar-2018 jmatthew

Add hibernate IO path for sdmmc(4). This requires some help from the
sdmmc chipset driver, currently only implemented in sdhc(4), but
mostly uses the regular path. sdhc(4) also needed the ability to
perform IO while cold.

ok deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.40 06-Apr-2017 deraadt

Sizes for the remaining free() calls, and use mallocarray()
ok visa


# 1.39 06-Apr-2017 deraadt

add sizes to free() calls
ok dhill


Revision tags: OPENBSD_6_1_BASE
# 1.38 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


# 1.37 20-Jan-2017 deraadt

sdmmc sd(4) devices should be marked SID_REMOVABLE, so that eject(1) can
succeed. No downside in the bottom part of the driver.
ok dlg krw


Revision tags: OPENBSD_6_0_BASE
# 1.36 05-May-2016 kettenis

Populate SCSI inquiry data with information from SD and MMC cards.
Code is slightly more convoluted to avoid using strncpy(9).

ok jsg@, millert@, deraadt@


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.35 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.34 09-Dec-2014 doug

More malloc() -> mallocarray() in the kernel.

ok deraadt@ tedu@


# 1.33 01-Nov-2014 jsg

fix the build when SDMMC_DEBUG is defined


# 1.32 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.31 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.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.30 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.29 09-Jul-2011 matthew

Simplify sdmmc_scsi by using SCSI_NO_ADAPTER_TARGET.

Tested by drahn@


# 1.28 09-Jul-2011 matthew

Kludge around sdmmc(4)'s poor design: replace "struct scsi_link *"
with "struct scsibus_attach_args" in sdmmc_attach_args.

ok krw@


# 1.27 16-Jun-2011 dlg

dont respond to VPD inquiries with standard inquiry data. add a
check to make sure cmdlen is correct while there.

ok miod@


Revision tags: OPENBSD_4_9_BASE
# 1.26 25-Oct-2010 krw

Iopoolification. Tested by mcbride@, dlg@, and Gabriel Kihlman on tech@.

ok dlg@


# 1.25 24-Aug-2010 blambert

lockmgr -> rwlock conversion

and with this, my adventure in sdmmc-land is over
bikeshed is still banana-shaped

ok oga@


# 1.24 19-Aug-2010 jasper

- fold several occurences of DEVNAME() into one located in sdmmcvar.h.
making DEVNAME() usage a lot more consistent.

ok krw@


Revision tags: OPENBSD_4_8_BASE
# 1.23 20-Jun-2010 mk

Don't use and maintain a function pointer that is only ever set to one
function. Just call the function where needed.

ok krw dlg


# 1.22 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.21 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.20 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.19 03-Oct-2009 kettenis

Add missing <sys/device.h>.

ok deraadt@, miod@


# 1.18 05-Sep-2009 dlg

scsi_done before COMPLETE


Revision tags: OPENBSD_4_6_BASE
# 1.17 07-Apr-2009 blambert

Remove recursion from the sdmmc locking regime.

In snaps for a while.

Originally hacked on phessler@'s couch.
Testing by many, input from jsg@

"I'm tired of seeing the Ms" deraadt@


# 1.16 24-Mar-2009 kettenis

Remove redundant casts.


Revision tags: OPENBSD_4_5_BASE
# 1.15 20-Feb-2009 miod

Let the sdmmc adapters tell the sdmmc layer how much sectors they can
transfer with one command. Build on this and the recent minphys() changes
in the sdmmc layer to crank transfers at the maximum possible size instead
of a sad DEV_BSIZE.

Depending on your controller, this can speed up sdmmc I/O up to 2.5 times.


# 1.14 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.13 06-Feb-2009 grange

Fix crash on zaurus when sd memory card plugged by providing an attachment
structure that slave devices like sbt expect.


# 1.12 21-Jan-2009 grange

Replace timeout_add(msecs * hz / 1000) with timeout_add_msec(msecs).
No functional changes.

ok krw@ miod@


# 1.11 02-Dec-2008 deraadt

backout: would have been nice if this had been tested, to see that it
crashes the moment a card is plugged in.


# 1.10 24-Nov-2008 blambert

Rework sdmmc locking to remove recursion
Add SDMMC_ASSERT_LOCKED(), replacing many locking calls, and sprinkling
the assertion to make sure that future changes don't catch us out

"please commit" uwe@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.9 11-Sep-2007 gilles

KNF

prompted and "much better" by marco@, ok pyr@


# 1.8 10-Sep-2007 gilles

more MALLOC/FREE -> malloc/free and M_ZERO changes

ok pyr@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.7 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


# 1.6 17-Oct-2006 dlg

dont pass a copy of sdmmcs scsi_link struct on the stack to the midlayer.
it triggered a panic on detach of the scsibus when it tried to use the
adapters scsi_link struct that was no longer there.

issue found by and this fix tested by pedro@
ok krw@ looks right deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.5 23-Aug-2006 pedro

Protect scsi_done() with splbio(), discussed with and okay dlg@, marco@
and fgsch@, uwe@ time-out :(


# 1.4 18-Jul-2006 uwe

First and foremost, avoid an obious race between two or more processes
trying to get MMC commands through to the SD/MMC host controller via the
emulated SCSI layer. This is achieved by ensuring exclusive access to
the host controller for one process during any MMC command and during a
sequence of commands at the sdmmc(4) layer.

While at it, the command processing thread has been moved to sdmmc(4),
so as to simplify the implementation of future host controller drivers.
This should also pave the way for further cleanup of the code and for
new drivers.

Minor cleanups are included in this commit, as well.


# 1.3 01-Jun-2006 uwe

SDIO card identification


# 1.2 28-May-2006 uwe

don't #undef SDMMC_DEBUG


# 1.1 28-May-2006 uwe

Support for standard SD host controllers like the Ricoh 5C822, a small
generic bus layer, and SCSI emulation for SD/MMC memory cards.


# 1.49 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.48 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.47 03-Jul-2020 krw

Pass the expected 'scsibus_attach_args *' to scsibus_attach() via
config_found(), not a 'scsi_link *'. Part of matthew@'s 2010 work.


Revision tags: OPENBSD_6_7_BASE
# 1.46 20-Feb-2020 krw

Relax the grip the dead hand of QBUS (a.k.a. MAXPHYS) has on the
throat of physio().

Allows individual devices to eventually be modified to support larger
physio() (a.k.a. 'raw') i/o's if they prove capable of them.

No immediate functional change.

Tested for many weeks by and ok robert@.


# 1.45 12-Feb-2020 krw

Bring a few stragglers into line with the idiom used by the other 40+
scsi drivers. i.e. eliminate the struct scsi_adapter member in the
softc and rely on the pointer to a static scsi_adapter in the struct
scsi_link member.


# 1.44 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.43 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


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.42 30-Mar-2018 jmatthew

Add some sensible error checking in the hibernate io path, helpfully
suggested by coverity (via daniel@)


Revision tags: OPENBSD_6_3_BASE
# 1.41 20-Mar-2018 jmatthew

Add hibernate IO path for sdmmc(4). This requires some help from the
sdmmc chipset driver, currently only implemented in sdhc(4), but
mostly uses the regular path. sdhc(4) also needed the ability to
perform IO while cold.

ok deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.40 06-Apr-2017 deraadt

Sizes for the remaining free() calls, and use mallocarray()
ok visa


# 1.39 06-Apr-2017 deraadt

add sizes to free() calls
ok dhill


Revision tags: OPENBSD_6_1_BASE
# 1.38 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


# 1.37 20-Jan-2017 deraadt

sdmmc sd(4) devices should be marked SID_REMOVABLE, so that eject(1) can
succeed. No downside in the bottom part of the driver.
ok dlg krw


Revision tags: OPENBSD_6_0_BASE
# 1.36 05-May-2016 kettenis

Populate SCSI inquiry data with information from SD and MMC cards.
Code is slightly more convoluted to avoid using strncpy(9).

ok jsg@, millert@, deraadt@


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.35 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.34 09-Dec-2014 doug

More malloc() -> mallocarray() in the kernel.

ok deraadt@ tedu@


# 1.33 01-Nov-2014 jsg

fix the build when SDMMC_DEBUG is defined


# 1.32 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.31 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.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.30 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.29 09-Jul-2011 matthew

Simplify sdmmc_scsi by using SCSI_NO_ADAPTER_TARGET.

Tested by drahn@


# 1.28 09-Jul-2011 matthew

Kludge around sdmmc(4)'s poor design: replace "struct scsi_link *"
with "struct scsibus_attach_args" in sdmmc_attach_args.

ok krw@


# 1.27 16-Jun-2011 dlg

dont respond to VPD inquiries with standard inquiry data. add a
check to make sure cmdlen is correct while there.

ok miod@


Revision tags: OPENBSD_4_9_BASE
# 1.26 25-Oct-2010 krw

Iopoolification. Tested by mcbride@, dlg@, and Gabriel Kihlman on tech@.

ok dlg@


# 1.25 24-Aug-2010 blambert

lockmgr -> rwlock conversion

and with this, my adventure in sdmmc-land is over
bikeshed is still banana-shaped

ok oga@


# 1.24 19-Aug-2010 jasper

- fold several occurences of DEVNAME() into one located in sdmmcvar.h.
making DEVNAME() usage a lot more consistent.

ok krw@


Revision tags: OPENBSD_4_8_BASE
# 1.23 20-Jun-2010 mk

Don't use and maintain a function pointer that is only ever set to one
function. Just call the function where needed.

ok krw dlg


# 1.22 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.21 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.20 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.19 03-Oct-2009 kettenis

Add missing <sys/device.h>.

ok deraadt@, miod@


# 1.18 05-Sep-2009 dlg

scsi_done before COMPLETE


Revision tags: OPENBSD_4_6_BASE
# 1.17 07-Apr-2009 blambert

Remove recursion from the sdmmc locking regime.

In snaps for a while.

Originally hacked on phessler@'s couch.
Testing by many, input from jsg@

"I'm tired of seeing the Ms" deraadt@


# 1.16 24-Mar-2009 kettenis

Remove redundant casts.


Revision tags: OPENBSD_4_5_BASE
# 1.15 20-Feb-2009 miod

Let the sdmmc adapters tell the sdmmc layer how much sectors they can
transfer with one command. Build on this and the recent minphys() changes
in the sdmmc layer to crank transfers at the maximum possible size instead
of a sad DEV_BSIZE.

Depending on your controller, this can speed up sdmmc I/O up to 2.5 times.


# 1.14 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.13 06-Feb-2009 grange

Fix crash on zaurus when sd memory card plugged by providing an attachment
structure that slave devices like sbt expect.


# 1.12 21-Jan-2009 grange

Replace timeout_add(msecs * hz / 1000) with timeout_add_msec(msecs).
No functional changes.

ok krw@ miod@


# 1.11 02-Dec-2008 deraadt

backout: would have been nice if this had been tested, to see that it
crashes the moment a card is plugged in.


# 1.10 24-Nov-2008 blambert

Rework sdmmc locking to remove recursion
Add SDMMC_ASSERT_LOCKED(), replacing many locking calls, and sprinkling
the assertion to make sure that future changes don't catch us out

"please commit" uwe@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.9 11-Sep-2007 gilles

KNF

prompted and "much better" by marco@, ok pyr@


# 1.8 10-Sep-2007 gilles

more MALLOC/FREE -> malloc/free and M_ZERO changes

ok pyr@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.7 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


# 1.6 17-Oct-2006 dlg

dont pass a copy of sdmmcs scsi_link struct on the stack to the midlayer.
it triggered a panic on detach of the scsibus when it tried to use the
adapters scsi_link struct that was no longer there.

issue found by and this fix tested by pedro@
ok krw@ looks right deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.5 23-Aug-2006 pedro

Protect scsi_done() with splbio(), discussed with and okay dlg@, marco@
and fgsch@, uwe@ time-out :(


# 1.4 18-Jul-2006 uwe

First and foremost, avoid an obious race between two or more processes
trying to get MMC commands through to the SD/MMC host controller via the
emulated SCSI layer. This is achieved by ensuring exclusive access to
the host controller for one process during any MMC command and during a
sequence of commands at the sdmmc(4) layer.

While at it, the command processing thread has been moved to sdmmc(4),
so as to simplify the implementation of future host controller drivers.
This should also pave the way for further cleanup of the code and for
new drivers.

Minor cleanups are included in this commit, as well.


# 1.3 01-Jun-2006 uwe

SDIO card identification


# 1.2 28-May-2006 uwe

don't #undef SDMMC_DEBUG


# 1.1 28-May-2006 uwe

Support for standard SD host controllers like the Ricoh 5C822, a small
generic bus layer, and SCSI emulation for SD/MMC memory cards.


# 1.48 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.47 03-Jul-2020 krw

Pass the expected 'scsibus_attach_args *' to scsibus_attach() via
config_found(), not a 'scsi_link *'. Part of matthew@'s 2010 work.


Revision tags: OPENBSD_6_7_BASE
# 1.46 20-Feb-2020 krw

Relax the grip the dead hand of QBUS (a.k.a. MAXPHYS) has on the
throat of physio().

Allows individual devices to eventually be modified to support larger
physio() (a.k.a. 'raw') i/o's if they prove capable of them.

No immediate functional change.

Tested for many weeks by and ok robert@.


# 1.45 12-Feb-2020 krw

Bring a few stragglers into line with the idiom used by the other 40+
scsi drivers. i.e. eliminate the struct scsi_adapter member in the
softc and rely on the pointer to a static scsi_adapter in the struct
scsi_link member.


# 1.44 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.43 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


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.42 30-Mar-2018 jmatthew

Add some sensible error checking in the hibernate io path, helpfully
suggested by coverity (via daniel@)


Revision tags: OPENBSD_6_3_BASE
# 1.41 20-Mar-2018 jmatthew

Add hibernate IO path for sdmmc(4). This requires some help from the
sdmmc chipset driver, currently only implemented in sdhc(4), but
mostly uses the regular path. sdhc(4) also needed the ability to
perform IO while cold.

ok deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.40 06-Apr-2017 deraadt

Sizes for the remaining free() calls, and use mallocarray()
ok visa


# 1.39 06-Apr-2017 deraadt

add sizes to free() calls
ok dhill


Revision tags: OPENBSD_6_1_BASE
# 1.38 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


# 1.37 20-Jan-2017 deraadt

sdmmc sd(4) devices should be marked SID_REMOVABLE, so that eject(1) can
succeed. No downside in the bottom part of the driver.
ok dlg krw


Revision tags: OPENBSD_6_0_BASE
# 1.36 05-May-2016 kettenis

Populate SCSI inquiry data with information from SD and MMC cards.
Code is slightly more convoluted to avoid using strncpy(9).

ok jsg@, millert@, deraadt@


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.35 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.34 09-Dec-2014 doug

More malloc() -> mallocarray() in the kernel.

ok deraadt@ tedu@


# 1.33 01-Nov-2014 jsg

fix the build when SDMMC_DEBUG is defined


# 1.32 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.31 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.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.30 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.29 09-Jul-2011 matthew

Simplify sdmmc_scsi by using SCSI_NO_ADAPTER_TARGET.

Tested by drahn@


# 1.28 09-Jul-2011 matthew

Kludge around sdmmc(4)'s poor design: replace "struct scsi_link *"
with "struct scsibus_attach_args" in sdmmc_attach_args.

ok krw@


# 1.27 16-Jun-2011 dlg

dont respond to VPD inquiries with standard inquiry data. add a
check to make sure cmdlen is correct while there.

ok miod@


Revision tags: OPENBSD_4_9_BASE
# 1.26 25-Oct-2010 krw

Iopoolification. Tested by mcbride@, dlg@, and Gabriel Kihlman on tech@.

ok dlg@


# 1.25 24-Aug-2010 blambert

lockmgr -> rwlock conversion

and with this, my adventure in sdmmc-land is over
bikeshed is still banana-shaped

ok oga@


# 1.24 19-Aug-2010 jasper

- fold several occurences of DEVNAME() into one located in sdmmcvar.h.
making DEVNAME() usage a lot more consistent.

ok krw@


Revision tags: OPENBSD_4_8_BASE
# 1.23 20-Jun-2010 mk

Don't use and maintain a function pointer that is only ever set to one
function. Just call the function where needed.

ok krw dlg


# 1.22 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.21 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.20 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.19 03-Oct-2009 kettenis

Add missing <sys/device.h>.

ok deraadt@, miod@


# 1.18 05-Sep-2009 dlg

scsi_done before COMPLETE


Revision tags: OPENBSD_4_6_BASE
# 1.17 07-Apr-2009 blambert

Remove recursion from the sdmmc locking regime.

In snaps for a while.

Originally hacked on phessler@'s couch.
Testing by many, input from jsg@

"I'm tired of seeing the Ms" deraadt@


# 1.16 24-Mar-2009 kettenis

Remove redundant casts.


Revision tags: OPENBSD_4_5_BASE
# 1.15 20-Feb-2009 miod

Let the sdmmc adapters tell the sdmmc layer how much sectors they can
transfer with one command. Build on this and the recent minphys() changes
in the sdmmc layer to crank transfers at the maximum possible size instead
of a sad DEV_BSIZE.

Depending on your controller, this can speed up sdmmc I/O up to 2.5 times.


# 1.14 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.13 06-Feb-2009 grange

Fix crash on zaurus when sd memory card plugged by providing an attachment
structure that slave devices like sbt expect.


# 1.12 21-Jan-2009 grange

Replace timeout_add(msecs * hz / 1000) with timeout_add_msec(msecs).
No functional changes.

ok krw@ miod@


# 1.11 02-Dec-2008 deraadt

backout: would have been nice if this had been tested, to see that it
crashes the moment a card is plugged in.


# 1.10 24-Nov-2008 blambert

Rework sdmmc locking to remove recursion
Add SDMMC_ASSERT_LOCKED(), replacing many locking calls, and sprinkling
the assertion to make sure that future changes don't catch us out

"please commit" uwe@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.9 11-Sep-2007 gilles

KNF

prompted and "much better" by marco@, ok pyr@


# 1.8 10-Sep-2007 gilles

more MALLOC/FREE -> malloc/free and M_ZERO changes

ok pyr@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.7 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


# 1.6 17-Oct-2006 dlg

dont pass a copy of sdmmcs scsi_link struct on the stack to the midlayer.
it triggered a panic on detach of the scsibus when it tried to use the
adapters scsi_link struct that was no longer there.

issue found by and this fix tested by pedro@
ok krw@ looks right deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.5 23-Aug-2006 pedro

Protect scsi_done() with splbio(), discussed with and okay dlg@, marco@
and fgsch@, uwe@ time-out :(


# 1.4 18-Jul-2006 uwe

First and foremost, avoid an obious race between two or more processes
trying to get MMC commands through to the SD/MMC host controller via the
emulated SCSI layer. This is achieved by ensuring exclusive access to
the host controller for one process during any MMC command and during a
sequence of commands at the sdmmc(4) layer.

While at it, the command processing thread has been moved to sdmmc(4),
so as to simplify the implementation of future host controller drivers.
This should also pave the way for further cleanup of the code and for
new drivers.

Minor cleanups are included in this commit, as well.


# 1.3 01-Jun-2006 uwe

SDIO card identification


# 1.2 28-May-2006 uwe

don't #undef SDMMC_DEBUG


# 1.1 28-May-2006 uwe

Support for standard SD host controllers like the Ricoh 5C822, a small
generic bus layer, and SCSI emulation for SD/MMC memory cards.


# 1.47 03-Jul-2020 krw

Pass the expected 'scsibus_attach_args *' to scsibus_attach() via
config_found(), not a 'scsi_link *'. Part of matthew@'s 2010 work.


Revision tags: OPENBSD_6_7_BASE
# 1.46 20-Feb-2020 krw

Relax the grip the dead hand of QBUS (a.k.a. MAXPHYS) has on the
throat of physio().

Allows individual devices to eventually be modified to support larger
physio() (a.k.a. 'raw') i/o's if they prove capable of them.

No immediate functional change.

Tested for many weeks by and ok robert@.


# 1.45 12-Feb-2020 krw

Bring a few stragglers into line with the idiom used by the other 40+
scsi drivers. i.e. eliminate the struct scsi_adapter member in the
softc and rely on the pointer to a static scsi_adapter in the struct
scsi_link member.


# 1.44 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.43 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


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.42 30-Mar-2018 jmatthew

Add some sensible error checking in the hibernate io path, helpfully
suggested by coverity (via daniel@)


Revision tags: OPENBSD_6_3_BASE
# 1.41 20-Mar-2018 jmatthew

Add hibernate IO path for sdmmc(4). This requires some help from the
sdmmc chipset driver, currently only implemented in sdhc(4), but
mostly uses the regular path. sdhc(4) also needed the ability to
perform IO while cold.

ok deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.40 06-Apr-2017 deraadt

Sizes for the remaining free() calls, and use mallocarray()
ok visa


# 1.39 06-Apr-2017 deraadt

add sizes to free() calls
ok dhill


Revision tags: OPENBSD_6_1_BASE
# 1.38 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


# 1.37 20-Jan-2017 deraadt

sdmmc sd(4) devices should be marked SID_REMOVABLE, so that eject(1) can
succeed. No downside in the bottom part of the driver.
ok dlg krw


Revision tags: OPENBSD_6_0_BASE
# 1.36 05-May-2016 kettenis

Populate SCSI inquiry data with information from SD and MMC cards.
Code is slightly more convoluted to avoid using strncpy(9).

ok jsg@, millert@, deraadt@


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.35 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.34 09-Dec-2014 doug

More malloc() -> mallocarray() in the kernel.

ok deraadt@ tedu@


# 1.33 01-Nov-2014 jsg

fix the build when SDMMC_DEBUG is defined


# 1.32 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.31 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.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.30 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.29 09-Jul-2011 matthew

Simplify sdmmc_scsi by using SCSI_NO_ADAPTER_TARGET.

Tested by drahn@


# 1.28 09-Jul-2011 matthew

Kludge around sdmmc(4)'s poor design: replace "struct scsi_link *"
with "struct scsibus_attach_args" in sdmmc_attach_args.

ok krw@


# 1.27 16-Jun-2011 dlg

dont respond to VPD inquiries with standard inquiry data. add a
check to make sure cmdlen is correct while there.

ok miod@


Revision tags: OPENBSD_4_9_BASE
# 1.26 25-Oct-2010 krw

Iopoolification. Tested by mcbride@, dlg@, and Gabriel Kihlman on tech@.

ok dlg@


# 1.25 24-Aug-2010 blambert

lockmgr -> rwlock conversion

and with this, my adventure in sdmmc-land is over
bikeshed is still banana-shaped

ok oga@


# 1.24 19-Aug-2010 jasper

- fold several occurences of DEVNAME() into one located in sdmmcvar.h.
making DEVNAME() usage a lot more consistent.

ok krw@


Revision tags: OPENBSD_4_8_BASE
# 1.23 20-Jun-2010 mk

Don't use and maintain a function pointer that is only ever set to one
function. Just call the function where needed.

ok krw dlg


# 1.22 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.21 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.20 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.19 03-Oct-2009 kettenis

Add missing <sys/device.h>.

ok deraadt@, miod@


# 1.18 05-Sep-2009 dlg

scsi_done before COMPLETE


Revision tags: OPENBSD_4_6_BASE
# 1.17 07-Apr-2009 blambert

Remove recursion from the sdmmc locking regime.

In snaps for a while.

Originally hacked on phessler@'s couch.
Testing by many, input from jsg@

"I'm tired of seeing the Ms" deraadt@


# 1.16 24-Mar-2009 kettenis

Remove redundant casts.


Revision tags: OPENBSD_4_5_BASE
# 1.15 20-Feb-2009 miod

Let the sdmmc adapters tell the sdmmc layer how much sectors they can
transfer with one command. Build on this and the recent minphys() changes
in the sdmmc layer to crank transfers at the maximum possible size instead
of a sad DEV_BSIZE.

Depending on your controller, this can speed up sdmmc I/O up to 2.5 times.


# 1.14 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.13 06-Feb-2009 grange

Fix crash on zaurus when sd memory card plugged by providing an attachment
structure that slave devices like sbt expect.


# 1.12 21-Jan-2009 grange

Replace timeout_add(msecs * hz / 1000) with timeout_add_msec(msecs).
No functional changes.

ok krw@ miod@


# 1.11 02-Dec-2008 deraadt

backout: would have been nice if this had been tested, to see that it
crashes the moment a card is plugged in.


# 1.10 24-Nov-2008 blambert

Rework sdmmc locking to remove recursion
Add SDMMC_ASSERT_LOCKED(), replacing many locking calls, and sprinkling
the assertion to make sure that future changes don't catch us out

"please commit" uwe@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.9 11-Sep-2007 gilles

KNF

prompted and "much better" by marco@, ok pyr@


# 1.8 10-Sep-2007 gilles

more MALLOC/FREE -> malloc/free and M_ZERO changes

ok pyr@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.7 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


# 1.6 17-Oct-2006 dlg

dont pass a copy of sdmmcs scsi_link struct on the stack to the midlayer.
it triggered a panic on detach of the scsibus when it tried to use the
adapters scsi_link struct that was no longer there.

issue found by and this fix tested by pedro@
ok krw@ looks right deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.5 23-Aug-2006 pedro

Protect scsi_done() with splbio(), discussed with and okay dlg@, marco@
and fgsch@, uwe@ time-out :(


# 1.4 18-Jul-2006 uwe

First and foremost, avoid an obious race between two or more processes
trying to get MMC commands through to the SD/MMC host controller via the
emulated SCSI layer. This is achieved by ensuring exclusive access to
the host controller for one process during any MMC command and during a
sequence of commands at the sdmmc(4) layer.

While at it, the command processing thread has been moved to sdmmc(4),
so as to simplify the implementation of future host controller drivers.
This should also pave the way for further cleanup of the code and for
new drivers.

Minor cleanups are included in this commit, as well.


# 1.3 01-Jun-2006 uwe

SDIO card identification


# 1.2 28-May-2006 uwe

don't #undef SDMMC_DEBUG


# 1.1 28-May-2006 uwe

Support for standard SD host controllers like the Ricoh 5C822, a small
generic bus layer, and SCSI emulation for SD/MMC memory cards.


# 1.46 20-Feb-2020 krw

Relax the grip the dead hand of QBUS (a.k.a. MAXPHYS) has on the
throat of physio().

Allows individual devices to eventually be modified to support larger
physio() (a.k.a. 'raw') i/o's if they prove capable of them.

No immediate functional change.

Tested for many weeks by and ok robert@.


# 1.45 12-Feb-2020 krw

Bring a few stragglers into line with the idiom used by the other 40+
scsi drivers. i.e. eliminate the struct scsi_adapter member in the
softc and rely on the pointer to a static scsi_adapter in the struct
scsi_link member.


# 1.44 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.43 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


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.42 30-Mar-2018 jmatthew

Add some sensible error checking in the hibernate io path, helpfully
suggested by coverity (via daniel@)


Revision tags: OPENBSD_6_3_BASE
# 1.41 20-Mar-2018 jmatthew

Add hibernate IO path for sdmmc(4). This requires some help from the
sdmmc chipset driver, currently only implemented in sdhc(4), but
mostly uses the regular path. sdhc(4) also needed the ability to
perform IO while cold.

ok deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.40 06-Apr-2017 deraadt

Sizes for the remaining free() calls, and use mallocarray()
ok visa


# 1.39 06-Apr-2017 deraadt

add sizes to free() calls
ok dhill


Revision tags: OPENBSD_6_1_BASE
# 1.38 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


# 1.37 20-Jan-2017 deraadt

sdmmc sd(4) devices should be marked SID_REMOVABLE, so that eject(1) can
succeed. No downside in the bottom part of the driver.
ok dlg krw


Revision tags: OPENBSD_6_0_BASE
# 1.36 05-May-2016 kettenis

Populate SCSI inquiry data with information from SD and MMC cards.
Code is slightly more convoluted to avoid using strncpy(9).

ok jsg@, millert@, deraadt@


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.35 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.34 09-Dec-2014 doug

More malloc() -> mallocarray() in the kernel.

ok deraadt@ tedu@


# 1.33 01-Nov-2014 jsg

fix the build when SDMMC_DEBUG is defined


# 1.32 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.31 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.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.30 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.29 09-Jul-2011 matthew

Simplify sdmmc_scsi by using SCSI_NO_ADAPTER_TARGET.

Tested by drahn@


# 1.28 09-Jul-2011 matthew

Kludge around sdmmc(4)'s poor design: replace "struct scsi_link *"
with "struct scsibus_attach_args" in sdmmc_attach_args.

ok krw@


# 1.27 16-Jun-2011 dlg

dont respond to VPD inquiries with standard inquiry data. add a
check to make sure cmdlen is correct while there.

ok miod@


Revision tags: OPENBSD_4_9_BASE
# 1.26 25-Oct-2010 krw

Iopoolification. Tested by mcbride@, dlg@, and Gabriel Kihlman on tech@.

ok dlg@


# 1.25 24-Aug-2010 blambert

lockmgr -> rwlock conversion

and with this, my adventure in sdmmc-land is over
bikeshed is still banana-shaped

ok oga@


# 1.24 19-Aug-2010 jasper

- fold several occurences of DEVNAME() into one located in sdmmcvar.h.
making DEVNAME() usage a lot more consistent.

ok krw@


Revision tags: OPENBSD_4_8_BASE
# 1.23 20-Jun-2010 mk

Don't use and maintain a function pointer that is only ever set to one
function. Just call the function where needed.

ok krw dlg


# 1.22 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.21 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.20 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.19 03-Oct-2009 kettenis

Add missing <sys/device.h>.

ok deraadt@, miod@


# 1.18 05-Sep-2009 dlg

scsi_done before COMPLETE


Revision tags: OPENBSD_4_6_BASE
# 1.17 07-Apr-2009 blambert

Remove recursion from the sdmmc locking regime.

In snaps for a while.

Originally hacked on phessler@'s couch.
Testing by many, input from jsg@

"I'm tired of seeing the Ms" deraadt@


# 1.16 24-Mar-2009 kettenis

Remove redundant casts.


Revision tags: OPENBSD_4_5_BASE
# 1.15 20-Feb-2009 miod

Let the sdmmc adapters tell the sdmmc layer how much sectors they can
transfer with one command. Build on this and the recent minphys() changes
in the sdmmc layer to crank transfers at the maximum possible size instead
of a sad DEV_BSIZE.

Depending on your controller, this can speed up sdmmc I/O up to 2.5 times.


# 1.14 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.13 06-Feb-2009 grange

Fix crash on zaurus when sd memory card plugged by providing an attachment
structure that slave devices like sbt expect.


# 1.12 21-Jan-2009 grange

Replace timeout_add(msecs * hz / 1000) with timeout_add_msec(msecs).
No functional changes.

ok krw@ miod@


# 1.11 02-Dec-2008 deraadt

backout: would have been nice if this had been tested, to see that it
crashes the moment a card is plugged in.


# 1.10 24-Nov-2008 blambert

Rework sdmmc locking to remove recursion
Add SDMMC_ASSERT_LOCKED(), replacing many locking calls, and sprinkling
the assertion to make sure that future changes don't catch us out

"please commit" uwe@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.9 11-Sep-2007 gilles

KNF

prompted and "much better" by marco@, ok pyr@


# 1.8 10-Sep-2007 gilles

more MALLOC/FREE -> malloc/free and M_ZERO changes

ok pyr@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.7 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


# 1.6 17-Oct-2006 dlg

dont pass a copy of sdmmcs scsi_link struct on the stack to the midlayer.
it triggered a panic on detach of the scsibus when it tried to use the
adapters scsi_link struct that was no longer there.

issue found by and this fix tested by pedro@
ok krw@ looks right deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.5 23-Aug-2006 pedro

Protect scsi_done() with splbio(), discussed with and okay dlg@, marco@
and fgsch@, uwe@ time-out :(


# 1.4 18-Jul-2006 uwe

First and foremost, avoid an obious race between two or more processes
trying to get MMC commands through to the SD/MMC host controller via the
emulated SCSI layer. This is achieved by ensuring exclusive access to
the host controller for one process during any MMC command and during a
sequence of commands at the sdmmc(4) layer.

While at it, the command processing thread has been moved to sdmmc(4),
so as to simplify the implementation of future host controller drivers.
This should also pave the way for further cleanup of the code and for
new drivers.

Minor cleanups are included in this commit, as well.


# 1.3 01-Jun-2006 uwe

SDIO card identification


# 1.2 28-May-2006 uwe

don't #undef SDMMC_DEBUG


# 1.1 28-May-2006 uwe

Support for standard SD host controllers like the Ricoh 5C822, a small
generic bus layer, and SCSI emulation for SD/MMC memory cards.


# 1.45 12-Feb-2020 krw

Bring a few stragglers into line with the idiom used by the other 40+
scsi drivers. i.e. eliminate the struct scsi_adapter member in the
softc and rely on the pointer to a static scsi_adapter in the struct
scsi_link member.


# 1.44 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.43 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


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.42 30-Mar-2018 jmatthew

Add some sensible error checking in the hibernate io path, helpfully
suggested by coverity (via daniel@)


Revision tags: OPENBSD_6_3_BASE
# 1.41 20-Mar-2018 jmatthew

Add hibernate IO path for sdmmc(4). This requires some help from the
sdmmc chipset driver, currently only implemented in sdhc(4), but
mostly uses the regular path. sdhc(4) also needed the ability to
perform IO while cold.

ok deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.40 06-Apr-2017 deraadt

Sizes for the remaining free() calls, and use mallocarray()
ok visa


# 1.39 06-Apr-2017 deraadt

add sizes to free() calls
ok dhill


Revision tags: OPENBSD_6_1_BASE
# 1.38 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


# 1.37 20-Jan-2017 deraadt

sdmmc sd(4) devices should be marked SID_REMOVABLE, so that eject(1) can
succeed. No downside in the bottom part of the driver.
ok dlg krw


Revision tags: OPENBSD_6_0_BASE
# 1.36 05-May-2016 kettenis

Populate SCSI inquiry data with information from SD and MMC cards.
Code is slightly more convoluted to avoid using strncpy(9).

ok jsg@, millert@, deraadt@


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.35 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.34 09-Dec-2014 doug

More malloc() -> mallocarray() in the kernel.

ok deraadt@ tedu@


# 1.33 01-Nov-2014 jsg

fix the build when SDMMC_DEBUG is defined


# 1.32 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.31 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.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.30 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.29 09-Jul-2011 matthew

Simplify sdmmc_scsi by using SCSI_NO_ADAPTER_TARGET.

Tested by drahn@


# 1.28 09-Jul-2011 matthew

Kludge around sdmmc(4)'s poor design: replace "struct scsi_link *"
with "struct scsibus_attach_args" in sdmmc_attach_args.

ok krw@


# 1.27 16-Jun-2011 dlg

dont respond to VPD inquiries with standard inquiry data. add a
check to make sure cmdlen is correct while there.

ok miod@


Revision tags: OPENBSD_4_9_BASE
# 1.26 25-Oct-2010 krw

Iopoolification. Tested by mcbride@, dlg@, and Gabriel Kihlman on tech@.

ok dlg@


# 1.25 24-Aug-2010 blambert

lockmgr -> rwlock conversion

and with this, my adventure in sdmmc-land is over
bikeshed is still banana-shaped

ok oga@


# 1.24 19-Aug-2010 jasper

- fold several occurences of DEVNAME() into one located in sdmmcvar.h.
making DEVNAME() usage a lot more consistent.

ok krw@


Revision tags: OPENBSD_4_8_BASE
# 1.23 20-Jun-2010 mk

Don't use and maintain a function pointer that is only ever set to one
function. Just call the function where needed.

ok krw dlg


# 1.22 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.21 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.20 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.19 03-Oct-2009 kettenis

Add missing <sys/device.h>.

ok deraadt@, miod@


# 1.18 05-Sep-2009 dlg

scsi_done before COMPLETE


Revision tags: OPENBSD_4_6_BASE
# 1.17 07-Apr-2009 blambert

Remove recursion from the sdmmc locking regime.

In snaps for a while.

Originally hacked on phessler@'s couch.
Testing by many, input from jsg@

"I'm tired of seeing the Ms" deraadt@


# 1.16 24-Mar-2009 kettenis

Remove redundant casts.


Revision tags: OPENBSD_4_5_BASE
# 1.15 20-Feb-2009 miod

Let the sdmmc adapters tell the sdmmc layer how much sectors they can
transfer with one command. Build on this and the recent minphys() changes
in the sdmmc layer to crank transfers at the maximum possible size instead
of a sad DEV_BSIZE.

Depending on your controller, this can speed up sdmmc I/O up to 2.5 times.


# 1.14 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.13 06-Feb-2009 grange

Fix crash on zaurus when sd memory card plugged by providing an attachment
structure that slave devices like sbt expect.


# 1.12 21-Jan-2009 grange

Replace timeout_add(msecs * hz / 1000) with timeout_add_msec(msecs).
No functional changes.

ok krw@ miod@


# 1.11 02-Dec-2008 deraadt

backout: would have been nice if this had been tested, to see that it
crashes the moment a card is plugged in.


# 1.10 24-Nov-2008 blambert

Rework sdmmc locking to remove recursion
Add SDMMC_ASSERT_LOCKED(), replacing many locking calls, and sprinkling
the assertion to make sure that future changes don't catch us out

"please commit" uwe@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.9 11-Sep-2007 gilles

KNF

prompted and "much better" by marco@, ok pyr@


# 1.8 10-Sep-2007 gilles

more MALLOC/FREE -> malloc/free and M_ZERO changes

ok pyr@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.7 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


# 1.6 17-Oct-2006 dlg

dont pass a copy of sdmmcs scsi_link struct on the stack to the midlayer.
it triggered a panic on detach of the scsibus when it tried to use the
adapters scsi_link struct that was no longer there.

issue found by and this fix tested by pedro@
ok krw@ looks right deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.5 23-Aug-2006 pedro

Protect scsi_done() with splbio(), discussed with and okay dlg@, marco@
and fgsch@, uwe@ time-out :(


# 1.4 18-Jul-2006 uwe

First and foremost, avoid an obious race between two or more processes
trying to get MMC commands through to the SD/MMC host controller via the
emulated SCSI layer. This is achieved by ensuring exclusive access to
the host controller for one process during any MMC command and during a
sequence of commands at the sdmmc(4) layer.

While at it, the command processing thread has been moved to sdmmc(4),
so as to simplify the implementation of future host controller drivers.
This should also pave the way for further cleanup of the code and for
new drivers.

Minor cleanups are included in this commit, as well.


# 1.3 01-Jun-2006 uwe

SDIO card identification


# 1.2 28-May-2006 uwe

don't #undef SDMMC_DEBUG


# 1.1 28-May-2006 uwe

Support for standard SD host controllers like the Ricoh 5C822, a small
generic bus layer, and SCSI emulation for SD/MMC memory cards.


# 1.44 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.43 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


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.42 30-Mar-2018 jmatthew

Add some sensible error checking in the hibernate io path, helpfully
suggested by coverity (via daniel@)


Revision tags: OPENBSD_6_3_BASE
# 1.41 20-Mar-2018 jmatthew

Add hibernate IO path for sdmmc(4). This requires some help from the
sdmmc chipset driver, currently only implemented in sdhc(4), but
mostly uses the regular path. sdhc(4) also needed the ability to
perform IO while cold.

ok deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.40 06-Apr-2017 deraadt

Sizes for the remaining free() calls, and use mallocarray()
ok visa


# 1.39 06-Apr-2017 deraadt

add sizes to free() calls
ok dhill


Revision tags: OPENBSD_6_1_BASE
# 1.38 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


# 1.37 20-Jan-2017 deraadt

sdmmc sd(4) devices should be marked SID_REMOVABLE, so that eject(1) can
succeed. No downside in the bottom part of the driver.
ok dlg krw


Revision tags: OPENBSD_6_0_BASE
# 1.36 05-May-2016 kettenis

Populate SCSI inquiry data with information from SD and MMC cards.
Code is slightly more convoluted to avoid using strncpy(9).

ok jsg@, millert@, deraadt@


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.35 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.34 09-Dec-2014 doug

More malloc() -> mallocarray() in the kernel.

ok deraadt@ tedu@


# 1.33 01-Nov-2014 jsg

fix the build when SDMMC_DEBUG is defined


# 1.32 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.31 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.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.30 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.29 09-Jul-2011 matthew

Simplify sdmmc_scsi by using SCSI_NO_ADAPTER_TARGET.

Tested by drahn@


# 1.28 09-Jul-2011 matthew

Kludge around sdmmc(4)'s poor design: replace "struct scsi_link *"
with "struct scsibus_attach_args" in sdmmc_attach_args.

ok krw@


# 1.27 16-Jun-2011 dlg

dont respond to VPD inquiries with standard inquiry data. add a
check to make sure cmdlen is correct while there.

ok miod@


Revision tags: OPENBSD_4_9_BASE
# 1.26 25-Oct-2010 krw

Iopoolification. Tested by mcbride@, dlg@, and Gabriel Kihlman on tech@.

ok dlg@


# 1.25 24-Aug-2010 blambert

lockmgr -> rwlock conversion

and with this, my adventure in sdmmc-land is over
bikeshed is still banana-shaped

ok oga@


# 1.24 19-Aug-2010 jasper

- fold several occurences of DEVNAME() into one located in sdmmcvar.h.
making DEVNAME() usage a lot more consistent.

ok krw@


Revision tags: OPENBSD_4_8_BASE
# 1.23 20-Jun-2010 mk

Don't use and maintain a function pointer that is only ever set to one
function. Just call the function where needed.

ok krw dlg


# 1.22 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.21 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.20 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.19 03-Oct-2009 kettenis

Add missing <sys/device.h>.

ok deraadt@, miod@


# 1.18 05-Sep-2009 dlg

scsi_done before COMPLETE


Revision tags: OPENBSD_4_6_BASE
# 1.17 07-Apr-2009 blambert

Remove recursion from the sdmmc locking regime.

In snaps for a while.

Originally hacked on phessler@'s couch.
Testing by many, input from jsg@

"I'm tired of seeing the Ms" deraadt@


# 1.16 24-Mar-2009 kettenis

Remove redundant casts.


Revision tags: OPENBSD_4_5_BASE
# 1.15 20-Feb-2009 miod

Let the sdmmc adapters tell the sdmmc layer how much sectors they can
transfer with one command. Build on this and the recent minphys() changes
in the sdmmc layer to crank transfers at the maximum possible size instead
of a sad DEV_BSIZE.

Depending on your controller, this can speed up sdmmc I/O up to 2.5 times.


# 1.14 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.13 06-Feb-2009 grange

Fix crash on zaurus when sd memory card plugged by providing an attachment
structure that slave devices like sbt expect.


# 1.12 21-Jan-2009 grange

Replace timeout_add(msecs * hz / 1000) with timeout_add_msec(msecs).
No functional changes.

ok krw@ miod@


# 1.11 02-Dec-2008 deraadt

backout: would have been nice if this had been tested, to see that it
crashes the moment a card is plugged in.


# 1.10 24-Nov-2008 blambert

Rework sdmmc locking to remove recursion
Add SDMMC_ASSERT_LOCKED(), replacing many locking calls, and sprinkling
the assertion to make sure that future changes don't catch us out

"please commit" uwe@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.9 11-Sep-2007 gilles

KNF

prompted and "much better" by marco@, ok pyr@


# 1.8 10-Sep-2007 gilles

more MALLOC/FREE -> malloc/free and M_ZERO changes

ok pyr@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.7 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


# 1.6 17-Oct-2006 dlg

dont pass a copy of sdmmcs scsi_link struct on the stack to the midlayer.
it triggered a panic on detach of the scsibus when it tried to use the
adapters scsi_link struct that was no longer there.

issue found by and this fix tested by pedro@
ok krw@ looks right deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.5 23-Aug-2006 pedro

Protect scsi_done() with splbio(), discussed with and okay dlg@, marco@
and fgsch@, uwe@ time-out :(


# 1.4 18-Jul-2006 uwe

First and foremost, avoid an obious race between two or more processes
trying to get MMC commands through to the SD/MMC host controller via the
emulated SCSI layer. This is achieved by ensuring exclusive access to
the host controller for one process during any MMC command and during a
sequence of commands at the sdmmc(4) layer.

While at it, the command processing thread has been moved to sdmmc(4),
so as to simplify the implementation of future host controller drivers.
This should also pave the way for further cleanup of the code and for
new drivers.

Minor cleanups are included in this commit, as well.


# 1.3 01-Jun-2006 uwe

SDIO card identification


# 1.2 28-May-2006 uwe

don't #undef SDMMC_DEBUG


# 1.1 28-May-2006 uwe

Support for standard SD host controllers like the Ricoh 5C822, a small
generic bus layer, and SCSI emulation for SD/MMC memory cards.


# 1.42 30-Mar-2018 jmatthew

Add some sensible error checking in the hibernate io path, helpfully
suggested by coverity (via daniel@)


Revision tags: OPENBSD_6_3_BASE
# 1.41 20-Mar-2018 jmatthew

Add hibernate IO path for sdmmc(4). This requires some help from the
sdmmc chipset driver, currently only implemented in sdhc(4), but
mostly uses the regular path. sdhc(4) also needed the ability to
perform IO while cold.

ok deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.40 06-Apr-2017 deraadt

Sizes for the remaining free() calls, and use mallocarray()
ok visa


# 1.39 06-Apr-2017 deraadt

add sizes to free() calls
ok dhill


Revision tags: OPENBSD_6_1_BASE
# 1.38 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


# 1.37 20-Jan-2017 deraadt

sdmmc sd(4) devices should be marked SID_REMOVABLE, so that eject(1) can
succeed. No downside in the bottom part of the driver.
ok dlg krw


Revision tags: OPENBSD_6_0_BASE
# 1.36 05-May-2016 kettenis

Populate SCSI inquiry data with information from SD and MMC cards.
Code is slightly more convoluted to avoid using strncpy(9).

ok jsg@, millert@, deraadt@


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.35 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.34 09-Dec-2014 doug

More malloc() -> mallocarray() in the kernel.

ok deraadt@ tedu@


# 1.33 01-Nov-2014 jsg

fix the build when SDMMC_DEBUG is defined


# 1.32 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.31 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.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.30 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.29 09-Jul-2011 matthew

Simplify sdmmc_scsi by using SCSI_NO_ADAPTER_TARGET.

Tested by drahn@


# 1.28 09-Jul-2011 matthew

Kludge around sdmmc(4)'s poor design: replace "struct scsi_link *"
with "struct scsibus_attach_args" in sdmmc_attach_args.

ok krw@


# 1.27 16-Jun-2011 dlg

dont respond to VPD inquiries with standard inquiry data. add a
check to make sure cmdlen is correct while there.

ok miod@


Revision tags: OPENBSD_4_9_BASE
# 1.26 25-Oct-2010 krw

Iopoolification. Tested by mcbride@, dlg@, and Gabriel Kihlman on tech@.

ok dlg@


# 1.25 24-Aug-2010 blambert

lockmgr -> rwlock conversion

and with this, my adventure in sdmmc-land is over
bikeshed is still banana-shaped

ok oga@


# 1.24 19-Aug-2010 jasper

- fold several occurences of DEVNAME() into one located in sdmmcvar.h.
making DEVNAME() usage a lot more consistent.

ok krw@


Revision tags: OPENBSD_4_8_BASE
# 1.23 20-Jun-2010 mk

Don't use and maintain a function pointer that is only ever set to one
function. Just call the function where needed.

ok krw dlg


# 1.22 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.21 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.20 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.19 03-Oct-2009 kettenis

Add missing <sys/device.h>.

ok deraadt@, miod@


# 1.18 05-Sep-2009 dlg

scsi_done before COMPLETE


Revision tags: OPENBSD_4_6_BASE
# 1.17 07-Apr-2009 blambert

Remove recursion from the sdmmc locking regime.

In snaps for a while.

Originally hacked on phessler@'s couch.
Testing by many, input from jsg@

"I'm tired of seeing the Ms" deraadt@


# 1.16 24-Mar-2009 kettenis

Remove redundant casts.


Revision tags: OPENBSD_4_5_BASE
# 1.15 20-Feb-2009 miod

Let the sdmmc adapters tell the sdmmc layer how much sectors they can
transfer with one command. Build on this and the recent minphys() changes
in the sdmmc layer to crank transfers at the maximum possible size instead
of a sad DEV_BSIZE.

Depending on your controller, this can speed up sdmmc I/O up to 2.5 times.


# 1.14 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.13 06-Feb-2009 grange

Fix crash on zaurus when sd memory card plugged by providing an attachment
structure that slave devices like sbt expect.


# 1.12 21-Jan-2009 grange

Replace timeout_add(msecs * hz / 1000) with timeout_add_msec(msecs).
No functional changes.

ok krw@ miod@


# 1.11 02-Dec-2008 deraadt

backout: would have been nice if this had been tested, to see that it
crashes the moment a card is plugged in.


# 1.10 24-Nov-2008 blambert

Rework sdmmc locking to remove recursion
Add SDMMC_ASSERT_LOCKED(), replacing many locking calls, and sprinkling
the assertion to make sure that future changes don't catch us out

"please commit" uwe@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.9 11-Sep-2007 gilles

KNF

prompted and "much better" by marco@, ok pyr@


# 1.8 10-Sep-2007 gilles

more MALLOC/FREE -> malloc/free and M_ZERO changes

ok pyr@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.7 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


# 1.6 17-Oct-2006 dlg

dont pass a copy of sdmmcs scsi_link struct on the stack to the midlayer.
it triggered a panic on detach of the scsibus when it tried to use the
adapters scsi_link struct that was no longer there.

issue found by and this fix tested by pedro@
ok krw@ looks right deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.5 23-Aug-2006 pedro

Protect scsi_done() with splbio(), discussed with and okay dlg@, marco@
and fgsch@, uwe@ time-out :(


# 1.4 18-Jul-2006 uwe

First and foremost, avoid an obious race between two or more processes
trying to get MMC commands through to the SD/MMC host controller via the
emulated SCSI layer. This is achieved by ensuring exclusive access to
the host controller for one process during any MMC command and during a
sequence of commands at the sdmmc(4) layer.

While at it, the command processing thread has been moved to sdmmc(4),
so as to simplify the implementation of future host controller drivers.
This should also pave the way for further cleanup of the code and for
new drivers.

Minor cleanups are included in this commit, as well.


# 1.3 01-Jun-2006 uwe

SDIO card identification


# 1.2 28-May-2006 uwe

don't #undef SDMMC_DEBUG


# 1.1 28-May-2006 uwe

Support for standard SD host controllers like the Ricoh 5C822, a small
generic bus layer, and SCSI emulation for SD/MMC memory cards.


Revision tags: OPENBSD_6_2_BASE
# 1.40 06-Apr-2017 deraadt

Sizes for the remaining free() calls, and use mallocarray()
ok visa


# 1.39 06-Apr-2017 deraadt

add sizes to free() calls
ok dhill


Revision tags: OPENBSD_6_1_BASE
# 1.38 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


# 1.37 20-Jan-2017 deraadt

sdmmc sd(4) devices should be marked SID_REMOVABLE, so that eject(1) can
succeed. No downside in the bottom part of the driver.
ok dlg krw


Revision tags: OPENBSD_6_0_BASE
# 1.36 05-May-2016 kettenis

Populate SCSI inquiry data with information from SD and MMC cards.
Code is slightly more convoluted to avoid using strncpy(9).

ok jsg@, millert@, deraadt@


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.35 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.34 09-Dec-2014 doug

More malloc() -> mallocarray() in the kernel.

ok deraadt@ tedu@


# 1.33 01-Nov-2014 jsg

fix the build when SDMMC_DEBUG is defined


# 1.32 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.31 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.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.30 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.29 09-Jul-2011 matthew

Simplify sdmmc_scsi by using SCSI_NO_ADAPTER_TARGET.

Tested by drahn@


# 1.28 09-Jul-2011 matthew

Kludge around sdmmc(4)'s poor design: replace "struct scsi_link *"
with "struct scsibus_attach_args" in sdmmc_attach_args.

ok krw@


# 1.27 16-Jun-2011 dlg

dont respond to VPD inquiries with standard inquiry data. add a
check to make sure cmdlen is correct while there.

ok miod@


Revision tags: OPENBSD_4_9_BASE
# 1.26 25-Oct-2010 krw

Iopoolification. Tested by mcbride@, dlg@, and Gabriel Kihlman on tech@.

ok dlg@


# 1.25 24-Aug-2010 blambert

lockmgr -> rwlock conversion

and with this, my adventure in sdmmc-land is over
bikeshed is still banana-shaped

ok oga@


# 1.24 19-Aug-2010 jasper

- fold several occurences of DEVNAME() into one located in sdmmcvar.h.
making DEVNAME() usage a lot more consistent.

ok krw@


Revision tags: OPENBSD_4_8_BASE
# 1.23 20-Jun-2010 mk

Don't use and maintain a function pointer that is only ever set to one
function. Just call the function where needed.

ok krw dlg


# 1.22 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.21 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.20 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.19 03-Oct-2009 kettenis

Add missing <sys/device.h>.

ok deraadt@, miod@


# 1.18 05-Sep-2009 dlg

scsi_done before COMPLETE


Revision tags: OPENBSD_4_6_BASE
# 1.17 07-Apr-2009 blambert

Remove recursion from the sdmmc locking regime.

In snaps for a while.

Originally hacked on phessler@'s couch.
Testing by many, input from jsg@

"I'm tired of seeing the Ms" deraadt@


# 1.16 24-Mar-2009 kettenis

Remove redundant casts.


Revision tags: OPENBSD_4_5_BASE
# 1.15 20-Feb-2009 miod

Let the sdmmc adapters tell the sdmmc layer how much sectors they can
transfer with one command. Build on this and the recent minphys() changes
in the sdmmc layer to crank transfers at the maximum possible size instead
of a sad DEV_BSIZE.

Depending on your controller, this can speed up sdmmc I/O up to 2.5 times.


# 1.14 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.13 06-Feb-2009 grange

Fix crash on zaurus when sd memory card plugged by providing an attachment
structure that slave devices like sbt expect.


# 1.12 21-Jan-2009 grange

Replace timeout_add(msecs * hz / 1000) with timeout_add_msec(msecs).
No functional changes.

ok krw@ miod@


# 1.11 02-Dec-2008 deraadt

backout: would have been nice if this had been tested, to see that it
crashes the moment a card is plugged in.


# 1.10 24-Nov-2008 blambert

Rework sdmmc locking to remove recursion
Add SDMMC_ASSERT_LOCKED(), replacing many locking calls, and sprinkling
the assertion to make sure that future changes don't catch us out

"please commit" uwe@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.9 11-Sep-2007 gilles

KNF

prompted and "much better" by marco@, ok pyr@


# 1.8 10-Sep-2007 gilles

more MALLOC/FREE -> malloc/free and M_ZERO changes

ok pyr@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.7 28-Nov-2006 dlg

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

ok miod@ marco@ deraadt@


# 1.6 17-Oct-2006 dlg

dont pass a copy of sdmmcs scsi_link struct on the stack to the midlayer.
it triggered a panic on detach of the scsibus when it tried to use the
adapters scsi_link struct that was no longer there.

issue found by and this fix tested by pedro@
ok krw@ looks right deraadt@


Revision tags: OPENBSD_4_0_BASE
# 1.5 23-Aug-2006 pedro

Protect scsi_done() with splbio(), discussed with and okay dlg@, marco@
and fgsch@, uwe@ time-out :(


# 1.4 18-Jul-2006 uwe

First and foremost, avoid an obious race between two or more processes
trying to get MMC commands through to the SD/MMC host controller via the
emulated SCSI layer. This is achieved by ensuring exclusive access to
the host controller for one process during any MMC command and during a
sequence of commands at the sdmmc(4) layer.

While at it, the command processing thread has been moved to sdmmc(4),
so as to simplify the implementation of future host controller drivers.
This should also pave the way for further cleanup of the code and for
new drivers.

Minor cleanups are included in this commit, as well.


# 1.3 01-Jun-2006 uwe

SDIO card identification


# 1.2 28-May-2006 uwe

don't #undef SDMMC_DEBUG


# 1.1 28-May-2006 uwe

Support for standard SD host controllers like the Ricoh 5C822, a small
generic bus layer, and SCSI emulation for SD/MMC memory cards.