Home | History | Annotate | only in /src/sys/dev/sdmmc
History log of /src/sys/dev/sdmmc
RevisionDateAuthorComments
 1.1 21-Apr-2009  nonaka branches: 1.1.2; 1.1.4; 1.1.6; 1.1.8; 1.1.14;
Added SD/MMC support from OpenBSD.
tested on i386, amd64 at current-users ML by pgoyette@.
tested on zaurus by myself.
 1.1.14.2 21-Apr-2010  matt sync to netbsd-5
 1.1.14.1 21-Apr-2009  matt file Makefile.sdmmcdevs was added on branch matt-nb5-mips64 on 2010-04-21 00:27:52 +0000
 1.1.8.2 07-Oct-2009  sborrill Pull up the following revisions(s) (requested by jmcneill in ticket #1044):
distrib/sets/lists/man/mi: patch
share/man/man4/Makefile: patch
sys/arch/amd64/conf/files.amd64: 1.67
sys/arch/i386/conf/files.i386: 1.349
sys/conf/files 1.945
share/man/man4/sdmmc.4: 1.1-1.4
sys/dev/sdmmc/Makefile.sdmmcdevs 1.1
sys/dev/sdmmc/devlist2h.awk 1.1
sys/dev/sdmmc/files.sdmmc 1.1-1.2
sys/dev/sdmmc/ld_sdmmc.c 1.1-1.3
sys/dev/sdmmc/sbt.c 1.1-1.2
sys/dev/sdmmc/sdhc.c 1.1-1.3
sys/dev/sdmmc/sdhcreg.h 1.1
sys/dev/sdmmc/sdhcvar.h 1.1
sys/dev/sdmmc/sdmmc.c 1.1
sys/dev/sdmmc/sdmmc_cis.c 1.1
sys/dev/sdmmc/sdmmc_io.c 1.1
sys/dev/sdmmc/sdmmc_ioreg.h 1.1
sys/dev/sdmmc/sdmmc_mem.c 1.1-1.2
sys/dev/sdmmc/sdmmcchip.h 1.1
sys/dev/sdmmc/sdmmcdevs 1.1
sys/dev/sdmmc/sdmmcdevs.h 1.1-1.2
sys/dev/sdmmc/sdmmcreg.h 1.1-1.3
sys/dev/sdmmc/sdmmcvar.h 1.1

Add sdmmc framework
 1.1.8.1 21-Apr-2009  sborrill file Makefile.sdmmcdevs was added on branch netbsd-5 on 2009-10-07 15:41:13 +0000
 1.1.6.2 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.1.6.1 21-Apr-2009  jym file Makefile.sdmmcdevs was added on branch jym-xensuspend on 2009-05-13 17:21:29 +0000
 1.1.4.2 04-May-2009  yamt sync with head.
 1.1.4.1 21-Apr-2009  yamt file Makefile.sdmmcdevs was added on branch yamt-nfs-mp on 2009-05-04 08:13:18 +0000
 1.1.2.2 28-Apr-2009  skrll Sync with HEAD.
 1.1.2.1 21-Apr-2009  skrll file Makefile.sdmmcdevs was added on branch nick-hppapmap on 2009-04-28 07:36:33 +0000
 1.3 02-Dec-2019  christos drop my name from the advertising clause.
 1.2 03-Jun-2017  christos branches: 1.2.10;
remove my copyright.
 1.1 21-Apr-2009  nonaka branches: 1.1.2; 1.1.4; 1.1.6; 1.1.8; 1.1.14; 1.1.32; 1.1.50;
Added SD/MMC support from OpenBSD.
tested on i386, amd64 at current-users ML by pgoyette@.
tested on zaurus by myself.
 1.1.50.1 28-Aug-2017  skrll Sync with HEAD
 1.1.32.1 03-Dec-2017  jdolecek update from HEAD
 1.1.14.2 21-Apr-2010  matt sync to netbsd-5
 1.1.14.1 21-Apr-2009  matt file devlist2h.awk was added on branch matt-nb5-mips64 on 2010-04-21 00:27:52 +0000
 1.1.8.2 07-Oct-2009  sborrill Pull up the following revisions(s) (requested by jmcneill in ticket #1044):
distrib/sets/lists/man/mi: patch
share/man/man4/Makefile: patch
sys/arch/amd64/conf/files.amd64: 1.67
sys/arch/i386/conf/files.i386: 1.349
sys/conf/files 1.945
share/man/man4/sdmmc.4: 1.1-1.4
sys/dev/sdmmc/Makefile.sdmmcdevs 1.1
sys/dev/sdmmc/devlist2h.awk 1.1
sys/dev/sdmmc/files.sdmmc 1.1-1.2
sys/dev/sdmmc/ld_sdmmc.c 1.1-1.3
sys/dev/sdmmc/sbt.c 1.1-1.2
sys/dev/sdmmc/sdhc.c 1.1-1.3
sys/dev/sdmmc/sdhcreg.h 1.1
sys/dev/sdmmc/sdhcvar.h 1.1
sys/dev/sdmmc/sdmmc.c 1.1
sys/dev/sdmmc/sdmmc_cis.c 1.1
sys/dev/sdmmc/sdmmc_io.c 1.1
sys/dev/sdmmc/sdmmc_ioreg.h 1.1
sys/dev/sdmmc/sdmmc_mem.c 1.1-1.2
sys/dev/sdmmc/sdmmcchip.h 1.1
sys/dev/sdmmc/sdmmcdevs 1.1
sys/dev/sdmmc/sdmmcdevs.h 1.1-1.2
sys/dev/sdmmc/sdmmcreg.h 1.1-1.3
sys/dev/sdmmc/sdmmcvar.h 1.1

Add sdmmc framework
 1.1.8.1 21-Apr-2009  sborrill file devlist2h.awk was added on branch netbsd-5 on 2009-10-07 15:41:13 +0000
 1.1.6.2 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.1.6.1 21-Apr-2009  jym file devlist2h.awk was added on branch jym-xensuspend on 2009-05-13 17:21:29 +0000
 1.1.4.2 04-May-2009  yamt sync with head.
 1.1.4.1 21-Apr-2009  yamt file devlist2h.awk was added on branch yamt-nfs-mp on 2009-05-04 08:13:18 +0000
 1.1.2.2 28-Apr-2009  skrll Sync with HEAD.
 1.1.2.1 21-Apr-2009  skrll file devlist2h.awk was added on branch nick-hppapmap on 2009-04-28 07:36:33 +0000
 1.2.10.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.6 19-Jan-2025  jmcneill bwi(4): Add support for Nintendo Wii WLAN.

Adapt the bwi(4) driver to support SDIO attachment and driving TX/RX using
PIO instead of DMA since the latter is not supported on SDIO busses.
 1.5 07-Nov-2017  khorben branches: 1.5.36; 1.5.42;
Add driver for Broadcom 802.11a/b/g/n/ac SDIO wireless devices, based on
the OpenBSD bwfm(4) driver.

I could not test this on any hardware yet, as it does not attach as-is on
my Raspberry PI 3.
 1.4 02-Oct-2014  jmcneill debug ld_sdmmc with LD_SDMMC_DEBUG instead of SDMMC_DEBUG
 1.3 01-Feb-2012  matt branches: 1.3.6;
Use "opt_sdmmc.h" for SDMMC_DEBUG, etc.
 1.2 28-Jun-2009  hubertf branches: 1.2.2; 1.2.8; 1.2.16; 1.2.20;
Remove trailing whitespace,
from KIYOHARA Takashi on current-users@
 1.1 21-Apr-2009  nonaka branches: 1.1.2; 1.1.4; 1.1.6;
Added SD/MMC support from OpenBSD.
tested on i386, amd64 at current-users ML by pgoyette@.
tested on zaurus by myself.
 1.1.6.3 23-Jul-2009  jym Sync with HEAD.
 1.1.6.2 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.1.6.1 21-Apr-2009  jym file files.sdmmc was added on branch jym-xensuspend on 2009-05-13 17:21:29 +0000
 1.1.4.3 18-Jul-2009  yamt sync with head.
 1.1.4.2 04-May-2009  yamt sync with head.
 1.1.4.1 21-Apr-2009  yamt file files.sdmmc was added on branch yamt-nfs-mp on 2009-05-04 08:13:18 +0000
 1.1.2.2 28-Apr-2009  skrll Sync with HEAD.
 1.1.2.1 21-Apr-2009  skrll file files.sdmmc was added on branch nick-hppapmap on 2009-04-28 07:36:33 +0000
 1.2.20.1 18-Feb-2012  mrg merge to -current.
 1.2.16.1 17-Apr-2012  yamt sync with head
 1.2.8.2 21-Apr-2010  matt sync to netbsd-5
 1.2.8.1 28-Jun-2009  matt file files.sdmmc was added on branch matt-nb5-mips64 on 2010-04-21 00:27:52 +0000
 1.2.2.2 07-Oct-2009  sborrill Pull up the following revisions(s) (requested by jmcneill in ticket #1044):
distrib/sets/lists/man/mi: patch
share/man/man4/Makefile: patch
sys/arch/amd64/conf/files.amd64: 1.67
sys/arch/i386/conf/files.i386: 1.349
sys/conf/files 1.945
share/man/man4/sdmmc.4: 1.1-1.4
sys/dev/sdmmc/Makefile.sdmmcdevs 1.1
sys/dev/sdmmc/devlist2h.awk 1.1
sys/dev/sdmmc/files.sdmmc 1.1-1.2
sys/dev/sdmmc/ld_sdmmc.c 1.1-1.3
sys/dev/sdmmc/sbt.c 1.1-1.2
sys/dev/sdmmc/sdhc.c 1.1-1.3
sys/dev/sdmmc/sdhcreg.h 1.1
sys/dev/sdmmc/sdhcvar.h 1.1
sys/dev/sdmmc/sdmmc.c 1.1
sys/dev/sdmmc/sdmmc_cis.c 1.1
sys/dev/sdmmc/sdmmc_io.c 1.1
sys/dev/sdmmc/sdmmc_ioreg.h 1.1
sys/dev/sdmmc/sdmmc_mem.c 1.1-1.2
sys/dev/sdmmc/sdmmcchip.h 1.1
sys/dev/sdmmc/sdmmcdevs 1.1
sys/dev/sdmmc/sdmmcdevs.h 1.1-1.2
sys/dev/sdmmc/sdmmcreg.h 1.1-1.3
sys/dev/sdmmc/sdmmcvar.h 1.1

Add sdmmc framework
 1.2.2.1 28-Jun-2009  sborrill file files.sdmmc was added on branch netbsd-5 on 2009-10-07 15:41:13 +0000
 1.3.6.1 03-Dec-2017  jdolecek update from HEAD
 1.5.42.1 02-Aug-2025  perseant Sync with HEAD
 1.5.36.1 02-Feb-2025  martin Pull up following revision(s) (requested by jmcneill in ticket #1041):

sys/dev/ic/bwi.c: revision 1.40
share/man/man4/bwi.4: revision 1.15
sys/dev/sdmmc/if_bwi_sdio.c: revision 1.1
sys/dev/ic/bwi.c: revision 1.41
sys/dev/sdmmc/sdmmcvar.h: revision 1.38
sys/dev/ic/bwireg.h: revision 1.5
sys/dev/ic/bwi.c: revision 1.39
sys/dev/ic/bwivar.h: revision 1.11
sys/dev/sdmmc/sdmmc_cis.c: revision 1.10
sys/dev/sdmmc/files.sdmmc: revision 1.6
sys/arch/evbppc/conf/WII: revision 1.7

bwi: Remove unnecessary pcivar.h include

sdmmc: Capture lan_nid and expose sdmmc_cisptr
LAN NID contains the MAC address for networking adapters.
Device drivers may want to processor vendor specific tuple codes, so
expose sdmmc_cisptr to help this.

bwi(4): Add support for Nintendo Wii WLAN.

Adapt the bwi(4) driver to support SDIO attachment and driving TX/RX using
PIO instead of DMA since the latter is not supported on SDIO busses.

fix uninitialized
 1.31 04-Oct-2025  thorpej Use device-path, not fdt-path.
 1.30 03-Dec-2022  mlelstv Fix bug in protocol parser that often caused fatal 'checksum error'.
Defer power save setting to interface start.
More verbose on errors.
Allow build without FDT.
 1.29 18-Jun-2022  skrll Trailing whitespace
 1.28 14-Mar-2022  mlelstv Add OpenBSD to code to optionally load CLM (Country Locale Matrix) files.
 1.27 08-Aug-2021  jmcneill Use SMBIOS system product instead of the string "netbsd,generic-acpi"
for firmware loading on ACPI systems.
 1.26 21-Jun-2021  christos fix proplib deprecation
 1.25 27-Jan-2021  thorpej branches: 1.25.4;
Rename of_match_compat_data() to of_compatible_match(). Similarly,
rename of_search_compatible() to of_compatible_lookup().

Standardize on of_compatible_match() for driver matching, and adapt
all call sites.
 1.24 03-Nov-2020  mlelstv Continue parsing frames after empty payload.
Add diagnostic messages.
 1.23 22-Jul-2020  riastradh branches: 1.23.2;
Sort includes. Nix trailing whitespace.

No functional change intended.
 1.22 22-Jul-2020  riastradh Need <sys/kmem.h> for kmem_*.

Currently accidentally side-loaded by <sys/pcq.h>.
 1.21 20-Jul-2020  mrg clear all interrupts, not just those we expect from the hostintmask.

this removes the final hard hang i have seen in pinebookpro wifi,
though one may still need to 'ifconfig bwfm0 down up' occasionally,
so we still have bugs to fix here (the hang is usually associated
with 'checksum error' from bwfm/sdio.)
 1.20 20-Jul-2020  mrg only ask for SDPCMD_INTSTATUS_HMB_SW_MASK and SDPCMD_INTSTATUS_CHIPACTIVE
interrupts, not all of them. we only ack these ones.

mostly fixes pinebookpro wifi hard hangs. still is problematic and can
trigger interrupt storm that appears as a hard hang without NET_MPSAFE,
and a follow up, less clearly right, change will reduce that to a soft
hang of the interface that can be cleared with 'ifconfig bwfm0 down up',
and even often recovers itself now.
 1.19 23-Jun-2020  martin Make this work on big endian machines
 1.18 30-May-2020  jdolecek discussed with thorpej@, and it seems it's better to allocate the bss
alignment buffer statically (as part of softc) just to be sure to not
affect performance
 1.17 30-May-2020  jdolecek constify, and make static where possible
 1.16 24-May-2020  riastradh Fix races in sdmmc tasks and teach ld@sdmmc to abort xfers on detach.

- Teach sdmmc_add_task to queue it only if not already queued.
- Remove now-redundant logic to avoid repeated queueing elsewhere.
- Teach sdmmc_del_task to wait until task has completed.
- Call sdmmc_del_task in various needful places.
- Replace abuse of pcq by a lock and a tailq.
(pcq is multi-producer, _single_-consumer, but there are potentially
multiple consumers here and really only one producer.)
- Teach ld_sdmmc to abort xfers on detach.
(Mechanism is kinda kludgey but it'll do for now; any effort one is
tempted to spend overhauling this should be spent overhauling sdmmc
to support proper asynchronous commands.)
- Make sure ld_sdmmc_discard either returns failure or eventually calls
ldenddiscard.

XXX Currently ld_sdmmc_detach aborts xfers _before_ ldbegindetach has
has committed to detaching or not. This is currently necessary to
avoid a deadlock because ldbegindetach waits for xfers to drain --
which strikes me as wrong; ldbegindetach shouldn't wait for anything,
and should only make the decision to commit to detaching or not so
the caller can decide whether to abort xfers before we actually wait
for them in ldenddetach.

XXX pullup -- although this changes some kernel symbols (sdmmc_add_task
and sdmmc_del_task), it shouldn't affect any existing modules; the only
module that uses sdmmc is ld_sdmmc.kmod, which is `.if 0' in the build
so there shouldn't be any of them floating around.
 1.15 07-May-2020  macallan add entry for BCM43362, found on Cubietruck
ok jmcneill@
 1.14 25-Mar-2020  thorpej - Refactor the firmware loading code into a set of common routines in the
core driver that understand how to find model-specific files before the
generic files. This greatly simplifies the firmware loading procedure
in each of the bus front ends. Adding additional firmware file types
(such as CLM files) much simpler.
- Make firmware image selection table-driven rather than a set of switch()
and if() statements.
- Add several additional firmware image entries.
 1.13 29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.12 04-Jan-2020  mlelstv branches: 1.12.2;
size check was backwards.
 1.11 01-Jan-2020  jmcneill Use correct firmware for BCM43456
 1.10 30-Dec-2019  mlelstv Follow the Linux driver an use the FDT "compatible" property to build a
filename for the nvram config file, fall back to the standard filename.

E.g.

# ofctl -p /
[Caching 123 nodes and 1093 properties]
#address-cells 00000001 ........ ........ ........ 1
#size-cells 00000001 ........ ........ ........ 1
compatible 73696e6f 766f6970 2c627069 2d6d322d "sinovoip,bpi-m2-
0010: 7a65726f 00...... ........ ........ zero"
0015: 616c6c77 696e6e65 722c7375 6e38692d "allwinner,sun8i-
0025: 68322d70 6c757300 ........ ........ h2-plus"
interrupt-parent 00000001 ........ ........ ........ ....
model 42616e61 6e612050 69204250 492d4d32 "Banana Pi BPI-M2
0010: 2d5a6572 6f00.... ........ ........ -Zero"
name 00...... ........ ........ ........ ""
serial-number 30326330 30303432 65636431 36376566 02c00042ecd167ef
0010: 00...... ........ ........ ........ .


-rw-r--r-- 1 root wheel 875 Nov 2 12:06 brcmfmac43430-sdio.AP6212.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 16:19 brcmfmac43430-sdio.sinovoip,bpi-m2-zero.txt -> brcmfmac43430-sdio.AP6212.txt
-rw-r--r-- 1 root wheel 874 Jun 30 2019 brcmfmac43430-sdio.raspberrypi,3-model-b.txt
-rw-r--r-- 1 root wheel 1864 Jun 30 2019 brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 11:24 brcmfmac43455-sdio.raspberrypi,4-model-b-plus.txt -> brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
 1.9 28-Oct-2019  mlelstv More code from OpenBSD
no need to splnet() when enqueing packets
explicit structure padding
make internal functions static

also prepare for GPIO interrupts.
 1.8 28-Oct-2019  mlelstv Simplyfy sdmmc_io_set_blocklen function signature by dropping the
extra softc pointer. Aligns with OpenBSD.
 1.7 27-Oct-2019  bad white space police.
 1.6 25-Sep-2019  mlelstv Use correct function to verify if a task has been queued. Avoids race
that can corrupt the task queue.
 1.5 13-Sep-2019  mlelstv Don't pass empty mbufs to the network stack.
 1.4 01-Sep-2019  mlelstv From OpenBSD:
- All the missing pieces (firmware load, chip setup, protocol handling)
TX queue and interrupt handling via sdmmc_task.
Fix locking.
Fix packet parsing.
Add parser for original firmware config files.
 1.3 11-May-2018  maya branches: 1.3.2; 1.3.8;
sync with openbsd bwfm to some extent.

add a txcheck
set chip active/passive for more kinds of chips
add wrapper around setting active/passive
detect chip RAM
make bwfm_rx take an mbuf
 1.2 11-Mar-2018  khorben Outsource setting the backplane window into a specific function so it
can be called and reused in different places.

From OpenBSD.
 1.1 07-Nov-2017  khorben branches: 1.1.2; 1.1.4;
Add driver for Broadcom 802.11a/b/g/n/ac SDIO wireless devices, based on
the OpenBSD bwfm(4) driver.

I could not test this on any hardware yet, as it does not attach as-is on
my Raspberry PI 3.
 1.1.4.2 21-May-2018  pgoyette Sync with HEAD
 1.1.4.1 15-Mar-2018  pgoyette Synch with HEAD
 1.1.2.2 03-Dec-2017  jdolecek update from HEAD
 1.1.2.1 07-Nov-2017  jdolecek file if_bwfm_sdio.c was added on branch tls-maxphys on 2017-12-03 11:37:32 +0000
 1.3.8.4 17-Aug-2020  martin Pull up following revision(s) (requested by mrg in ticket #1052):

sys/dev/ic/bwfm.c: revision 1.28
sys/dev/ic/bwfm.c: revision 1.29
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.22
sys/dev/ic/bwfmreg.h: revision 1.7
sys/dev/ic/bwfmvar.h: revision 1.11
sys/dev/ic/bwfmvar.h: revision 1.12
(all via patch)

Add include guards and appropriate includes to bwfmreg.h, bwfmvar.h.

No functional change intended.

Need <sys/kmem.h> for kmem_*.

Currently accidentally side-loaded by <sys/pcq.h>.

bwfm: Switch from pcq to pool_cache.
pcq_get is required to be serialized, but it's far from clear that it
is serialized here.
 1.3.8.3 09-Aug-2020  martin Pull up following revision(s) (requested by mrg in ticket #1042):

sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.19
sys/dev/sdmmc/ld_sdmmc.c: revision 1.38
sys/dev/sdmmc/sdmmcvar.h: revision 1.35
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.5
sys/dev/ic/bwfm.c: revision 1.26
sys/dev/ic/bwfm.c: revision 1.27
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.20
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.21
sys/dev/sdmmc/sdmmc_io.c: revision 1.20
sys/dev/sdmmc/sdmmc_mem.c: revision 1.72
sys/dev/sdmmc/sdmmc.c: revision 1.40
sys/dev/sdmmc/sdmmc_ioreg.h: revision 1.6
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.16

Don't pass empty mbufs to the network stack.

Avoid changing signedness bit with << in sdmmc_ioreg.h
Reported by <prlw1>

If the controller doesn't support switch func (opcode 6) then skip
setting this but continue with other settings. This allows us to use
a card, albeit at a lower speed.

Fix races in sdmmc tasks and teach ld@sdmmc to abort xfers on detach.
- Teach sdmmc_add_task to queue it only if not already queued.
- Remove now-redundant logic to avoid repeated queueing elsewhere.
- Teach sdmmc_del_task to wait until task has completed.
- Call sdmmc_del_task in various needful places.
- Replace abuse of pcq by a lock and a tailq.
(pcq is multi-producer, _single_-consumer, but there are potentially
multiple consumers here and really only one producer.)
- Teach ld_sdmmc to abort xfers on detach.
(Mechanism is kinda kludgey but it'll do for now; any effort one is
tempted to spend overhauling this should be spent overhauling sdmmc
to support proper asynchronous commands.)
- Make sure ld_sdmmc_discard either returns failure or eventually calls
ldenddiscard.

XXX Currently ld_sdmmc_detach aborts xfers _before_ ldbegindetach has
has committed to detaching or not. This is currently necessary to
avoid a deadlock because ldbegindetach waits for xfers to drain --
which strikes me as wrong; ldbegindetach shouldn't wait for anything,
and should only make the decision to commit to detaching or not so
the caller can decide whether to abort xfers before we actually wait
for them in ldenddetach.

XXX pullup -- although this changes some kernel symbols (sdmmc_add_task
and sdmmc_del_task), it shouldn't affect any existing modules; the only
module that uses sdmmc is ld_sdmmc.kmod, which is `.if 0' in the build
so there shouldn't be any of them floating around.

Make this work on big endian machines

move some of the patching of callbacks and other data after
ieee80211_ifattach() but before if_deferred_start_init().
may fix panic i saw in after restarting wpa_supplicant.
from mlelstv.

only ask for SDPCMD_INTSTATUS_HMB_SW_MASK and SDPCMD_INTSTATUS_CHIPACTIVE
interrupts, not all of them. we only ack these ones.
mostly fixes pinebookpro wifi hard hangs. still is problematic and can
trigger interrupt storm that appears as a hard hang without NET_MPSAFE,
and a follow up, less clearly right, change will reduce that to a soft
hang of the interface that can be cleared with 'ifconfig bwfm0 down up',
and even often recovers itself now.

clear all interrupts, not just those we expect from the hostintmask.
this removes the final hard hang i have seen in pinebookpro wifi,
though one may still need to 'ifconfig bwfm0 down up' occasionally,
so we still have bugs to fix here (the hang is usually associated
with 'checksum error' from bwfm/sdio.)

Sort #includes. Nix trailing whitespace.
No functional change intended.
 1.3.8.2 07-May-2020  martin Pull up following revision(s) (requested by macallan in ticket #892):

sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.15

add entry for BCM43362, found on Cubietruck
ok jmcneill@
 1.3.8.1 25-Feb-2020  martin Pull up following revision(s) (requested by mrg in ticket #717):

sys/dev/fdt/dwcmmc_fdt.c 1.11
sys/dev/ic/bwfm.c 1.15-1.18
sys/dev/ic/bwfmreg.h 1.4-1.6
sys/dev/ic/bwfmvar.h 1.4,1.5
sys/dev/ic/dwc_mmc.c 1.21,1.22
sys/dev/ic/dwc_mmc_reg.h 1.8,1.9,1.12,1.13
sys/dev/pcmcia/pcmciareg.h 1.11
sys/dev/sdmmc/if_bwfm_sdio.c 1.4,1.6-1.12
sys/dev/sdmmc/if_bwfm_sdio.h 1.1,1.2
sys/dev/sdmmc/sdhc.c 1.105,1.106
sys/dev/sdmmc/sdmmc.c 1.37,1.39
sys/dev/sdmmc/sdmmc_cis.c 1.6,1.8
sys/dev/sdmmc/sdmmc_io.c 1.15-1.19
sys/dev/sdmmc/sdmmc_ioreg.h 1.4,1.5
sys/dev/sdmmc/sdmmc_mem.c 1.69-1.71
sys/dev/sdmmc/sdmmcdevs 1.5-1.8
sys/dev/sdmmc/sdmmcvar.h 1.31,1.33,1.34
sys/net/if_media.h 1.66

Add Broadcom devices
-
Fix typo
-
add PCMCIA_CISTPL_SDIO definition.
-
From OpenBSD:
- move event handling to workqueue
- check for save/restore capability
-
Tag work queue as MPsafe and increase length.
-
Juse use bpf_mtap(), the 802.11 encapsulation is handled by firmware.
-
From OpenBSD:
- support block length per function
- add functions to read/write regions
-
Decode (but not use) SDIO tuple in CIS.
-
Fix locking.
-
Add more SDIO defines (partially from version 3.0).
-
From OpenBSD:
- All the missing pieces (firmware load, chip setup, protocol handling)
TX queue and interrupt handling via sdmmc_task.
-
Fix locking.
-
Fix packet parsing.
-
Add parser for original firmware config files.
-
tagging work queue as MPSAFE was premature. Revert.
-
SD_IO_RW_EXTENDED is a data transfer command, so set ADTC flag instead of AC
Use correct function to verify if a task has been queued. Avoids race
that can corrupt the task queue.
-
More register definitions.
-
Add IFM_IEEE80211_VHT subtype, IFM_IEEE80211_11AC operating mode, and missing descriptions
-
If firmware is connected in HT or VHT mode, report it to SIOCGIFMEDIA
-
white space police.

Skip setting power when the voltage doesn't change.
Also increase some timeouts.
-
Add and use sdmmc_pause to avoid long-term busy waits.
-
Add sdio abort function.
-
Additional error messages.
-
Print parameters for SDIO devices.
-
Minor cosmetics.
-
Simplyfy sdmmc_io_set_blocklen function signature by dropping the
extra softc pointer. Aligns with OpenBSD.
-
Missing commit for sdio abort function.
-
More code from OpenBSD
-
no need to splnet() when enqueing packets
-
explicit structure padding
-
make internal functions static
-
also prepare for GPIO interrupts.
-
Avoid warnings for tautological shifts as sole conditional.
-
Follow the Linux driver an use the FDT "compatible" property to build a
filename for the nvram config file, fall back to the standard filename.
E.g.
[Caching 123 nodes and 1093 properties]
compatible 73696e6f 766f6970 2c627069 2d6d322d "sinovoip,bpi-m2-
0010: 7a65726f 00...... ........ ........ zero"
0015: 616c6c77 696e6e65 722c7375 6e38692d "allwinner,sun8i-
0025: 68322d70 6c757300 ........ ........ h2-plus"
interrupt-parent 00000001 ........ ........ ........ ....
model 42616e61 6e612050 69204250 492d4d32 "Banana Pi BPI-M2
0010: 2d5a6572 6f00.... ........ ........ -Zero"
name 00...... ........ ........ ........ ""
serial-number 30326330 30303432 65636431 36376566 02c00042ecd167ef
0010: 00...... ........ ........ ........ .
-rw-r--r-- 1 root wheel 875 Nov 2 12:06 brcmfmac43430-sdio.AP6212.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 16:19 brcmfmac43430-sdio.sinovoip,bpi-m2-zero.txt -> brcmfmac43430-sdio.AP6212.txt
-rw-r--r-- 1 root wheel 874 Jun 30 2019 brcmfmac43430-sdio.raspberrypi,3-model-b.txt
-rw-r--r-- 1 root wheel 1864 Jun 30 2019 brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 11:24 brcmfmac43455-sdio.raspberrypi,4-model-b-plus.txt -> brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
-
Add product ID for Broadcom BCM43455
-
Use correct firmware for BCM43456
-
size check was backwards.
-
Be less noisy for some commands.
-
Fix DWC_MMC_INT_SDIO_INT bit
-
dwc_mmc fixes:
- Rockchip uses a different SDIO int bit, so take this into consideration
- Avoid unnecessary resets and always wait for resets to complete
- kpause instead of delay while holding spinlock
- Do not attempt autostop for SD_IO_RW_EXTENDED commands
- Allow for sub-blklen byte counts for single block transfers
-
More SDIO stability and performance fixes
 1.3.2.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.12.2.1 29-Feb-2020  ad Sync with head.
 1.23.2.2 03-Apr-2021  thorpej Sync with HEAD.
 1.23.2.1 14-Dec-2020  thorpej Sync w/ HEAD.
 1.25.4.1 01-Aug-2021  thorpej Sync with HEAD.
 1.3 08-Aug-2021  jmcneill Fixup bwfm(4) register bit regarding SDIO device suspend/resume.

From OpenBSD if_bwfm_sdio.h r1.3
 1.2 03-Oct-2019  mlelstv branches: 1.2.4; 1.2.10;
More register definitions.
 1.1 01-Sep-2019  mlelstv From OpenBSD:
- All the missing pieces (firmware load, chip setup, protocol handling)
TX queue and interrupt handling via sdmmc_task.
Fix locking.
Fix packet parsing.
Add parser for original firmware config files.
 1.2.10.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.2.10.1 03-Oct-2019  martin file if_bwfm_sdio.h was added on branch phil-wifi on 2020-04-13 08:04:48 +0000
 1.2.4.2 25-Feb-2020  martin Pull up following revision(s) (requested by mrg in ticket #717):

sys/dev/fdt/dwcmmc_fdt.c 1.11
sys/dev/ic/bwfm.c 1.15-1.18
sys/dev/ic/bwfmreg.h 1.4-1.6
sys/dev/ic/bwfmvar.h 1.4,1.5
sys/dev/ic/dwc_mmc.c 1.21,1.22
sys/dev/ic/dwc_mmc_reg.h 1.8,1.9,1.12,1.13
sys/dev/pcmcia/pcmciareg.h 1.11
sys/dev/sdmmc/if_bwfm_sdio.c 1.4,1.6-1.12
sys/dev/sdmmc/if_bwfm_sdio.h 1.1,1.2
sys/dev/sdmmc/sdhc.c 1.105,1.106
sys/dev/sdmmc/sdmmc.c 1.37,1.39
sys/dev/sdmmc/sdmmc_cis.c 1.6,1.8
sys/dev/sdmmc/sdmmc_io.c 1.15-1.19
sys/dev/sdmmc/sdmmc_ioreg.h 1.4,1.5
sys/dev/sdmmc/sdmmc_mem.c 1.69-1.71
sys/dev/sdmmc/sdmmcdevs 1.5-1.8
sys/dev/sdmmc/sdmmcvar.h 1.31,1.33,1.34
sys/net/if_media.h 1.66

Add Broadcom devices
-
Fix typo
-
add PCMCIA_CISTPL_SDIO definition.
-
From OpenBSD:
- move event handling to workqueue
- check for save/restore capability
-
Tag work queue as MPsafe and increase length.
-
Juse use bpf_mtap(), the 802.11 encapsulation is handled by firmware.
-
From OpenBSD:
- support block length per function
- add functions to read/write regions
-
Decode (but not use) SDIO tuple in CIS.
-
Fix locking.
-
Add more SDIO defines (partially from version 3.0).
-
From OpenBSD:
- All the missing pieces (firmware load, chip setup, protocol handling)
TX queue and interrupt handling via sdmmc_task.
-
Fix locking.
-
Fix packet parsing.
-
Add parser for original firmware config files.
-
tagging work queue as MPSAFE was premature. Revert.
-
SD_IO_RW_EXTENDED is a data transfer command, so set ADTC flag instead of AC
Use correct function to verify if a task has been queued. Avoids race
that can corrupt the task queue.
-
More register definitions.
-
Add IFM_IEEE80211_VHT subtype, IFM_IEEE80211_11AC operating mode, and missing descriptions
-
If firmware is connected in HT or VHT mode, report it to SIOCGIFMEDIA
-
white space police.

Skip setting power when the voltage doesn't change.
Also increase some timeouts.
-
Add and use sdmmc_pause to avoid long-term busy waits.
-
Add sdio abort function.
-
Additional error messages.
-
Print parameters for SDIO devices.
-
Minor cosmetics.
-
Simplyfy sdmmc_io_set_blocklen function signature by dropping the
extra softc pointer. Aligns with OpenBSD.
-
Missing commit for sdio abort function.
-
More code from OpenBSD
-
no need to splnet() when enqueing packets
-
explicit structure padding
-
make internal functions static
-
also prepare for GPIO interrupts.
-
Avoid warnings for tautological shifts as sole conditional.
-
Follow the Linux driver an use the FDT "compatible" property to build a
filename for the nvram config file, fall back to the standard filename.
E.g.
[Caching 123 nodes and 1093 properties]
compatible 73696e6f 766f6970 2c627069 2d6d322d "sinovoip,bpi-m2-
0010: 7a65726f 00...... ........ ........ zero"
0015: 616c6c77 696e6e65 722c7375 6e38692d "allwinner,sun8i-
0025: 68322d70 6c757300 ........ ........ h2-plus"
interrupt-parent 00000001 ........ ........ ........ ....
model 42616e61 6e612050 69204250 492d4d32 "Banana Pi BPI-M2
0010: 2d5a6572 6f00.... ........ ........ -Zero"
name 00...... ........ ........ ........ ""
serial-number 30326330 30303432 65636431 36376566 02c00042ecd167ef
0010: 00...... ........ ........ ........ .
-rw-r--r-- 1 root wheel 875 Nov 2 12:06 brcmfmac43430-sdio.AP6212.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 16:19 brcmfmac43430-sdio.sinovoip,bpi-m2-zero.txt -> brcmfmac43430-sdio.AP6212.txt
-rw-r--r-- 1 root wheel 874 Jun 30 2019 brcmfmac43430-sdio.raspberrypi,3-model-b.txt
-rw-r--r-- 1 root wheel 1864 Jun 30 2019 brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 11:24 brcmfmac43455-sdio.raspberrypi,4-model-b-plus.txt -> brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
-
Add product ID for Broadcom BCM43455
-
Use correct firmware for BCM43456
-
size check was backwards.
-
Be less noisy for some commands.
-
Fix DWC_MMC_INT_SDIO_INT bit
-
dwc_mmc fixes:
- Rockchip uses a different SDIO int bit, so take this into consideration
- Avoid unnecessary resets and always wait for resets to complete
- kpause instead of delay while holding spinlock
- Do not attempt autostop for SD_IO_RW_EXTENDED commands
- Allow for sub-blklen byte counts for single block transfers
-
More SDIO stability and performance fixes
 1.2.4.1 03-Oct-2019  martin file if_bwfm_sdio.h was added on branch netbsd-9 on 2020-02-25 18:40:43 +0000
 1.1 19-Jan-2025  jmcneill branches: 1.1.2; 1.1.6;
bwi(4): Add support for Nintendo Wii WLAN.

Adapt the bwi(4) driver to support SDIO attachment and driving TX/RX using
PIO instead of DMA since the latter is not supported on SDIO busses.
 1.1.6.2 02-Aug-2025  perseant Sync with HEAD
 1.1.6.1 19-Jan-2025  perseant file if_bwi_sdio.c was added on branch perseant-exfatfs on 2025-08-02 05:57:03 +0000
 1.1.2.2 02-Feb-2025  martin Pull up following revision(s) (requested by jmcneill in ticket #1041):

sys/dev/ic/bwi.c: revision 1.40
share/man/man4/bwi.4: revision 1.15
sys/dev/sdmmc/if_bwi_sdio.c: revision 1.1
sys/dev/ic/bwi.c: revision 1.41
sys/dev/sdmmc/sdmmcvar.h: revision 1.38
sys/dev/ic/bwireg.h: revision 1.5
sys/dev/ic/bwi.c: revision 1.39
sys/dev/ic/bwivar.h: revision 1.11
sys/dev/sdmmc/sdmmc_cis.c: revision 1.10
sys/dev/sdmmc/files.sdmmc: revision 1.6
sys/arch/evbppc/conf/WII: revision 1.7

bwi: Remove unnecessary pcivar.h include

sdmmc: Capture lan_nid and expose sdmmc_cisptr
LAN NID contains the MAC address for networking adapters.
Device drivers may want to processor vendor specific tuple codes, so
expose sdmmc_cisptr to help this.

bwi(4): Add support for Nintendo Wii WLAN.

Adapt the bwi(4) driver to support SDIO attachment and driving TX/RX using
PIO instead of DMA since the latter is not supported on SDIO busses.

fix uninitialized
 1.1.2.1 19-Jan-2025  martin file if_bwi_sdio.c was added on branch netbsd-10 on 2025-02-02 14:29:59 +0000
 1.45 13-Apr-2025  rin ld(4): Convert blkno argument for sc_dump() to daddr_t

PR kern/59153

(1) For backends that accept 64-bit block address, i.e.,
nvme(4), virtio(4), aac(4), iop(4), and mainbus(usermode/4),
this should enable to dump beyond 2Gi blocks.

(2) sdmmc(4) backend allows to dump up to the last block.

(3) For other backends, block address is handled as `int`.
Some of them may support blocks up to 4Gi, but I do not have
enough time to examine datasheets. So, continue to reject >2Gi
blocks as before.

XXX
This is KABI change, and cannot be pulled up into netbsd-{10,9}.

XXX
Compile-test only (for amd64/ALL) due to lack of large SSDs ;)

Thanks mlelstv@ for discussion and careful review!!
 1.44 18-Oct-2024  jmcneill sdmmc: Add support for SD card caches.

SD physical 6.0 specification introduced Application Performance Class 2
(A2), which adds support for drive caches and command queueing.

Add support for enabling and flushing the cache when this feature is
present.
 1.43 23-Jan-2024  riastradh branches: 1.43.2;
ld@sdmmc(4): Hack around deadlock in cache sync on detach.

Yanking a card triggers the sdmmc discovery task, which runs in the
sdmmc task thread, to detach any attached child devices.

Detaching ld@sdmmc triggers a cache flush (via ldbegindetach ->
disk_begindetach -> ld_lastclose -> ld_flush -> ioctl DIOCCACHESYNC),
which is implemented by scheduling a task to do sdmmc_mem_flush_cache
and then waiting for it to complete.

The sdmmc_mem_cache_flush is done by an sdmmc task so it happens
after all previously scheduled I/O operations -- that way the cache
flush doesn't complete until the previously scheduled I/O operations
are complete.

However, when the cache flush task is issued from the discovery task,
this doesn't work, because the cache flush task can't start until the
discovery task has returned -- but the discovery task won't return
until the cache flush task has completed.

To work around this deadlock, which usually happens only when the
device has been yanked anyway so further I/O would be lost anyway,
just do the cache flush synchronously in DIOCCACHESYNC if we're
running in the task thread.

This isn't quite right -- implementation details of the task thread
shouldn't bleed into ld@sdmmc, and running the cache sync _before_
any subsequently scheduled I/O tasks is asking for trouble -- but it
should serve to avoid the deadlock in PR kern/57870 until we can fix
a host of concurrency bugs in sdmmc by fixing the locking scheme and
running discovery in a separate thread from tasks.

XXX pullup-10
 1.42 16-May-2022  jmcneill branches: 1.42.4;
sdmmc: ld: Include the card type (SD card, MMC) in the disk description.
 1.41 02-Aug-2020  riastradh Remove unnecessary wait in ldbegindetach.

Like disk_begindetach, ldbegindetach only commits to detaching but
doesn't wait for existing xfers to drain; it is up to the driver to
abort them, once we are committed, and then ldenddetach to wait for
them to drain.
 1.40 22-Jul-2020  riastradh Sort #includes. Nix trailing whitespace.

No functional change intended.
 1.39 22-Jul-2020  riastradh Omit needless <sys/pcq.h>.
 1.38 24-May-2020  riastradh Fix races in sdmmc tasks and teach ld@sdmmc to abort xfers on detach.

- Teach sdmmc_add_task to queue it only if not already queued.
- Remove now-redundant logic to avoid repeated queueing elsewhere.
- Teach sdmmc_del_task to wait until task has completed.
- Call sdmmc_del_task in various needful places.
- Replace abuse of pcq by a lock and a tailq.
(pcq is multi-producer, _single_-consumer, but there are potentially
multiple consumers here and really only one producer.)
- Teach ld_sdmmc to abort xfers on detach.
(Mechanism is kinda kludgey but it'll do for now; any effort one is
tempted to spend overhauling this should be spent overhauling sdmmc
to support proper asynchronous commands.)
- Make sure ld_sdmmc_discard either returns failure or eventually calls
ldenddiscard.

XXX Currently ld_sdmmc_detach aborts xfers _before_ ldbegindetach has
has committed to detaching or not. This is currently necessary to
avoid a deadlock because ldbegindetach waits for xfers to drain --
which strikes me as wrong; ldbegindetach shouldn't wait for anything,
and should only make the decision to commit to detaching or not so
the caller can decide whether to abort xfers before we actually wait
for them in ldenddetach.

XXX pullup -- although this changes some kernel symbols (sdmmc_add_task
and sdmmc_del_task), it shouldn't affect any existing modules; the only
module that uses sdmmc is ld_sdmmc.kmod, which is `.if 0' in the build
so there shouldn't be any of them floating around.
 1.37 28-Oct-2019  mlelstv Whitespace police
 1.36 19-Mar-2019  mlelstv branches: 1.36.4;
Provide CID data (manufacturer/product id/product name) as disk type.
 1.35 09-Nov-2018  jmcneill Defer DIOCCACHESYNC to the sdmmc task queue so they are serialized with other requests.
 1.34 20-Aug-2017  mlelstv branches: 1.34.2; 1.34.4;
make the sc_discard interface for the ld backend asynchronous and
signal completion through new callback lddiscardend. Use a standard
struct buf to pass disk address and range instead of two off_t values.

make lddiscard synchronous again. This is a requirement of the current
ffs discard code.
 1.33 11-Aug-2017  jmcneill Defer sdmmc discard operations to the sdmmc task queue. Fixes a panic
introduced by ld.c r1.102.
 1.32 09-Aug-2017  mlelstv While ld(4) is MP safe, many backends are not.

Add a flag for backends that are MP safe. Take KERNEL_LOCK when calling
into a backend that doesn't have the flag set. Do the same for the
discard routine.

Fixes PR 52462.
 1.31 16-Jul-2017  jmcneill branches: 1.31.2;
Add support for eMMC 4.5's optional cache feature. If a cache is present,
and the host controller reports the SMC_CAPS_POLLING capability (needed
to flush cache at shutdown), it will be automatically enabled and used.
 1.30 10-Jul-2017  mlelstv Decrypt comment about the attach thread. No functional change.
 1.29 08-Jul-2017  jmcneill The config_* APIs are not MPSAFE, so make sure the deferred attach
thread holds KERNEL_LOCK.
 1.28 24-Jun-2017  jmcneill Add discard support to ld@sdmmc using the ERASE (CMD38) command.
 1.27 06-Jun-2017  jmcneill Fix a race between ld_sdmmc_start and ld_sdmmc_dobio that could result in
tasks getting lost from the task queue. The symptom of this is a NULL
deref in ld_sdmmc_start since the code assumes that a task will always be
available from the pool.

This changes the code to use pcq(9) instead of a TAILQ to manage the free
task list.
 1.26 22-Apr-2017  jmcneill branches: 1.26.4;
Ensure that the task is returned to the free task list in an error branch.
 1.25 07-Jan-2017  martin Add missing includes
 1.24 07-Jan-2017  kiyohara Support retry when error. like wd(4).
 1.23 27-Sep-2016  pgoyette Modularize the ld driver and all of its attachments. Ensure that all
parents are capable of rescan (or otherwise provide a means of attaching
children post-initialization).
 1.22 16-Sep-2016  jdolecek modify ldattach() to have default strategy as a parameter
 1.21 28-Aug-2015  mlelstv branches: 1.21.2;
remove unused include sys/rndsource.h
 1.20 09-Aug-2015  mlelstv Add small command queue to reduce latency between ld driver and
sdmmc I/O thread.
 1.19 03-Aug-2015  jmcneill Print the selected transfer mode if known.
 1.18 03-Aug-2015  mlelstv use mutex locking for MP safety.
 1.17 27-Jul-2015  skrll Don't timeout waiting for ld_sdmmc_dobio in the IO thread to start.

XXX why does it take >1s to get scheduled?
 1.16 20-May-2015  jmcneill need to call lddone with splbio and kernel lock held
 1.15 13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.14 02-Oct-2014  jmcneill branches: 1.14.2;
debug ld_sdmmc with LD_SDMMC_DEBUG instead of SDMMC_DEBUG
 1.13 02-Oct-2014  mlelstv Be a bit more verbose about errors, also pass through error code
from lower layer like other drivers.
 1.12 12-Oct-2013  christos branches: 1.12.4;
Pass the device name in, so we can debug what deferred drivers did not work.
 1.11 14-Dec-2012  jakllsch branches: 1.11.2;
Display the whole CID register upon attach as "<MID:OID:PNM:PRV:PSN:MDT>"
instead of just "<PNM>". Probably should figure out a way to stuff this
into the device properties database too, but not everything has
pseudo-device drvctl enabled.

Also, drop trailing whitespace.
 1.10 02-Feb-2012  tls branches: 1.10.6;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

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

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

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

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

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.9 01-Feb-2012  matt Use "opt_sdmmc.h" for SDMMC_DEBUG, etc.
 1.8 27-Jan-2012  tsutsui Protect ldattach ops with config_pending_intr(9)/config_pending_decr(9)
so that "boot device: ld0" detection works properly even on slower zaurus.
 1.7 13-Nov-2010  uebayasi branches: 1.7.8; 1.7.12;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.6 23-Sep-2010  kiyohara Print bus width and clock for feature(High speed support).
 1.5 20-Sep-2010  kiyohara Print product name. like sd(4), wd(4) and etc...
 1.4 28-Nov-2009  nonaka branches: 1.4.2; 1.4.4; 1.4.6;
Always sector size is treated as 512 bytes.
 1.3 29-May-2009  nonaka branches: 1.3.2;
It is avoided that the error occurs when the card attaches it,
when wedge is supported.
 1.2 06-May-2009  cegger branches: 1.2.2;
struct cfdata * -> cfdata_t, no functional changes intended.
 1.1 21-Apr-2009  nonaka branches: 1.1.2; 1.1.4;
Added SD/MMC support from OpenBSD.
tested on i386, amd64 at current-users ML by pgoyette@.
tested on zaurus by myself.
 1.1.4.6 09-Oct-2010  yamt sync with head
 1.1.4.5 11-Mar-2010  yamt sync with head
 1.1.4.4 20-Jun-2009  yamt sync with head
 1.1.4.3 16-May-2009  yamt sync with head
 1.1.4.2 04-May-2009  yamt sync with head.
 1.1.4.1 21-Apr-2009  yamt file ld_sdmmc.c was added on branch yamt-nfs-mp on 2009-05-04 08:13:18 +0000
 1.1.2.2 28-Apr-2009  skrll Sync with HEAD.
 1.1.2.1 21-Apr-2009  skrll file ld_sdmmc.c was added on branch nick-hppapmap on 2009-04-28 07:36:33 +0000
 1.2.2.3 23-Jul-2009  jym Sync with HEAD.
 1.2.2.2 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.2.2.1 06-May-2009  jym file ld_sdmmc.c was added on branch jym-xensuspend on 2009-05-13 17:21:29 +0000
 1.3.2.3 02-Dec-2009  sborrill Pull up the following revisions(s) (requested by nonaka in ticket #1167):
sys/dev/sdmmc/ld_sdmmc.c: revision 1.4
sys/dev/sdmmc/sdmmc_mem.c: revision 1.3
sys/dev/sdmmc/sdmmcvar.h: revision 1.2

Always treat sector size as 512 bytes.
 1.3.2.2 07-Oct-2009  sborrill Pull up the following revisions(s) (requested by jmcneill in ticket #1044):
distrib/sets/lists/man/mi: patch
share/man/man4/Makefile: patch
sys/arch/amd64/conf/files.amd64: 1.67
sys/arch/i386/conf/files.i386: 1.349
sys/conf/files 1.945
share/man/man4/sdmmc.4: 1.1-1.4
sys/dev/sdmmc/Makefile.sdmmcdevs 1.1
sys/dev/sdmmc/devlist2h.awk 1.1
sys/dev/sdmmc/files.sdmmc 1.1-1.2
sys/dev/sdmmc/ld_sdmmc.c 1.1-1.3
sys/dev/sdmmc/sbt.c 1.1-1.2
sys/dev/sdmmc/sdhc.c 1.1-1.3
sys/dev/sdmmc/sdhcreg.h 1.1
sys/dev/sdmmc/sdhcvar.h 1.1
sys/dev/sdmmc/sdmmc.c 1.1
sys/dev/sdmmc/sdmmc_cis.c 1.1
sys/dev/sdmmc/sdmmc_io.c 1.1
sys/dev/sdmmc/sdmmc_ioreg.h 1.1
sys/dev/sdmmc/sdmmc_mem.c 1.1-1.2
sys/dev/sdmmc/sdmmcchip.h 1.1
sys/dev/sdmmc/sdmmcdevs 1.1
sys/dev/sdmmc/sdmmcdevs.h 1.1-1.2
sys/dev/sdmmc/sdmmcreg.h 1.1-1.3
sys/dev/sdmmc/sdmmcvar.h 1.1

Add sdmmc framework
 1.3.2.1 29-May-2009  sborrill file ld_sdmmc.c was added on branch netbsd-5 on 2009-10-07 15:41:13 +0000
 1.4.6.2 21-Apr-2010  matt sync to netbsd-5
 1.4.6.1 28-Nov-2009  matt file ld_sdmmc.c was added on branch matt-nb5-mips64 on 2010-04-21 00:27:52 +0000
 1.4.4.1 05-Mar-2011  rmind sync with head
 1.4.2.1 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.7.12.1 18-Feb-2012  mrg merge to -current.
 1.7.8.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.7.8.2 23-Jan-2013  yamt sync with head
 1.7.8.1 17-Apr-2012  yamt sync with head
 1.10.6.3 03-Dec-2017  jdolecek update from HEAD
 1.10.6.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.10.6.1 25-Feb-2013  tls resync with head
 1.11.2.1 18-May-2014  rmind sync with head
 1.12.4.2 23-Jul-2017  snj Pull up following revision(s) (requested by jmcneill in ticket #1447):
sys/dev/sdmmc/ld_sdmmc.c: revision 1.29
The config_* APIs are not MPSAFE, so make sure the deferred attach
thread holds KERNEL_LOCK.
 1.12.4.1 26-May-2015  msaitoh Pull up following revision(s) (requested by jmcneill in ticket #794):
sys/dev/sdmmc/sdmmc.c: revision 1.25
sys/dev/sdmmc/sdmmc.c: revision 1.26
sys/dev/sdmmc/ld_sdmmc.c: revision 1.13
sys/dev/sdmmc/ld_sdmmc.c: revision 1.16
- Be a bit more verbose about errors, also pass through error code
from lower layer like other drivers.
- need to call lddone with splbio and kernel lock held
- sdmmc_task_thread isn't MPSAFE so instead of just wrapping the callback
in KERNEL_LOCK/KERNEL_UNLOCK_ONE, remove KTHREAD_MPSAFE. While here, use
PRI_BIO instead of PRI_NONE for the task thread priority. Since this is
how all transfers are queued, and we have a 1 second timeout on the task
being picked up off the queue (!), better not to rely on a PRI_NONE thread.
 1.14.2.5 28-Aug-2017  skrll Sync with HEAD
 1.14.2.4 05-Feb-2017  skrll Sync with HEAD
 1.14.2.3 05-Oct-2016  skrll Sync with HEAD
 1.14.2.2 22-Sep-2015  skrll Sync with HEAD
 1.14.2.1 06-Jun-2015  skrll Sync with HEAD
 1.21.2.3 26-Apr-2017  pgoyette Sync with HEAD
 1.21.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.21.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.26.4.5 01-Sep-2017  martin Pull up following revision(s) (requested by mlelstv in ticket #261):
sys/dev/sdmmc/ld_sdmmc.c: revision 1.32
sys/dev/sdmmc/ld_sdmmc.c: revision 1.33
sys/dev/sdmmc/ld_sdmmc.c: revision 1.34
sys/dev/sdmmc/sdmmc_mem.c: revision 1.62
sys/dev/i2o/ld_iop.c: revision 1.39
sys/dev/ld.c: revision 1.102
sys/dev/ld.c: revision 1.103
sys/dev/dksubr.c: revision 1.98
sys/dev/dksubr.c: revision 1.99
sys/dev/sdmmc/sdmmcvar.h: revision 1.29
sys/dev/ic/ld_nvme.c: revision 1.17
sys/dev/ldvar.h: revision 1.31
sys/dev/ldvar.h: revision 1.32
sys/dev/ic/ld_cac.c: revision 1.31
sys/dev/pci/ld_virtio.c: revision 1.16
While ld(4) is MP safe, many backends are not.
Add a flag for backends that are MP safe. Take KERNEL_LOCK when calling
into a backend that doesn't have the flag set. Do the same for the
discard routine.
Fixes PR 52462.
Defer sdmmc discard operations to the sdmmc task queue. Fixes a panic
introduced by ld.c r1.102.
validate length for discard operation and split operation when byte length
doesn't fit into 'int'.
make the sc_discard interface for the ld backend asynchronous and
signal completion through new callback lddiscardend. Use a standard
struct buf to pass disk address and range instead of two off_t values.
make lddiscard synchronous again. This is a requirement of the current
ffs discard code.
Initialize error also in the case where len=0, which just succeeds.
while here, assert that the len is indeed non-negative. this is already
confirmed by sys_fdiscard, but let's be sure.
reported by: GCC, but with different compile flags
 1.26.4.4 25-Jul-2017  snj Pull up following revision(s) (requested by jmcneill in ticket #139):
sys/arch/arm/sunxi/sunxi_mmc.c: revision 1.2
sys/dev/sdmmc/ld_sdmmc.c: revision 1.31
sys/dev/sdmmc/sdmmc_mem.c: revision 1.61
sys/dev/sdmmc/sdmmcreg.h: revision 1.32
sys/dev/sdmmc/sdmmcvar.h: revision 1.28
Add support for eMMC 4.5's optional cache feature. If a cache is present,
and the host controller reports the SMC_CAPS_POLLING capability (needed
to flush cache at shutdown), it will be automatically enabled and used.
--
Add SMC_CAPS_POLLING support.
 1.26.4.3 10-Jul-2017  martin Pull up following revision(s) (requested by jmcneill in ticket #111):
sys/dev/sdmmc/ld_sdmmc.c: revision 1.29
The config_* APIs are not MPSAFE, so make sure the deferred attach
thread holds KERNEL_LOCK.
 1.26.4.2 01-Jul-2017  snj Pull up following revision(s) (requested by jmcneill in ticket #67):
sys/dev/sdmmc/ld_sdmmc.c: 1.28
sys/dev/sdmmc/sdmmc_mem.c: 1.58-1.60
sys/dev/sdmmc/sdmmcreg.h: 1.30, 1.31
sys/dev/sdmmc/sdmmcvar.h: 1.25-1.27
Add discard support to ld@sdmmc using the ERASE (CMD38) command.
--
Read SD status register and print card status when a new SD card is found:
sdmmc0: SD card status: 4-bit, C10, U1, V10
If the SD status register reports discard support, set the DISCARD arg to
the ERASE operation to let the card know that the host doesn't care if the
erase is performed.
--
Revert part of previous; the SD card spec recommends not to issue a DISCARD
command to the file system area.
 1.26.4.1 09-Jun-2017  snj Pull up following revision(s) (requested by jmcneill in ticket #14):
sys/dev/sdmmc/ld_sdmmc.c: revision 1.27
Fix a race between ld_sdmmc_start and ld_sdmmc_dobio that could result in
tasks getting lost from the task queue. The symptom of this is a NULL
deref in ld_sdmmc_start since the code assumes that a task will always be
available from the pool.
This changes the code to use pcq(9) instead of a TAILQ to manage the free
task list.
 1.31.2.2 16-Jul-2017  jmcneill 2978427
 1.31.2.1 16-Jul-2017  jmcneill file ld_sdmmc.c was added on branch perseant-stdc-iso10646 on 2017-07-16 17:11:47 +0000
 1.34.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.34.4.1 10-Jun-2019  christos Sync with HEAD
 1.34.2.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.36.4.2 03-Feb-2024  martin Pull up following revision(s) (requested by riastradh in ticket #1793):

sys/dev/sdmmc/ld_sdmmc.c: revision 1.43

ld@sdmmc(4): Hack around deadlock in cache sync on detach.

Yanking a card triggers the sdmmc discovery task, which runs in the
sdmmc task thread, to detach any attached child devices.

Detaching ld@sdmmc triggers a cache flush (via ldbegindetach ->
disk_begindetach -> ld_lastclose -> ld_flush -> ioctl DIOCCACHESYNC),
which is implemented by scheduling a task to do sdmmc_mem_flush_cache
and then waiting for it to complete.

The sdmmc_mem_cache_flush is done by an sdmmc task so it happens
after all previously scheduled I/O operations -- that way the cache
flush doesn't complete until the previously scheduled I/O operations
are complete.

However, when the cache flush task is issued from the discovery task,
this doesn't work, because the cache flush task can't start until the
discovery task has returned -- but the discovery task won't return
until the cache flush task has completed.

To work around this deadlock, which usually happens only when the
device has been yanked anyway so further I/O would be lost anyway,
just do the cache flush synchronously in DIOCCACHESYNC if we're
running in the task thread.

This isn't quite right -- implementation details of the task thread
shouldn't bleed into ld@sdmmc, and running the cache sync _before_
any subsequently scheduled I/O tasks is asking for trouble -- but it
should serve to avoid the deadlock in PR kern/57870 until we can fix
a host of concurrency bugs in sdmmc by fixing the locking scheme and
running discovery in a separate thread from tasks.
 1.36.4.1 09-Aug-2020  martin Pull up following revision(s) (requested by mrg in ticket #1042):

sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.19
sys/dev/sdmmc/ld_sdmmc.c: revision 1.38
sys/dev/sdmmc/sdmmcvar.h: revision 1.35
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.5
sys/dev/ic/bwfm.c: revision 1.26
sys/dev/ic/bwfm.c: revision 1.27
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.20
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.21
sys/dev/sdmmc/sdmmc_io.c: revision 1.20
sys/dev/sdmmc/sdmmc_mem.c: revision 1.72
sys/dev/sdmmc/sdmmc.c: revision 1.40
sys/dev/sdmmc/sdmmc_ioreg.h: revision 1.6
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.16

Don't pass empty mbufs to the network stack.

Avoid changing signedness bit with << in sdmmc_ioreg.h
Reported by <prlw1>

If the controller doesn't support switch func (opcode 6) then skip
setting this but continue with other settings. This allows us to use
a card, albeit at a lower speed.

Fix races in sdmmc tasks and teach ld@sdmmc to abort xfers on detach.
- Teach sdmmc_add_task to queue it only if not already queued.
- Remove now-redundant logic to avoid repeated queueing elsewhere.
- Teach sdmmc_del_task to wait until task has completed.
- Call sdmmc_del_task in various needful places.
- Replace abuse of pcq by a lock and a tailq.
(pcq is multi-producer, _single_-consumer, but there are potentially
multiple consumers here and really only one producer.)
- Teach ld_sdmmc to abort xfers on detach.
(Mechanism is kinda kludgey but it'll do for now; any effort one is
tempted to spend overhauling this should be spent overhauling sdmmc
to support proper asynchronous commands.)
- Make sure ld_sdmmc_discard either returns failure or eventually calls
ldenddiscard.

XXX Currently ld_sdmmc_detach aborts xfers _before_ ldbegindetach has
has committed to detaching or not. This is currently necessary to
avoid a deadlock because ldbegindetach waits for xfers to drain --
which strikes me as wrong; ldbegindetach shouldn't wait for anything,
and should only make the decision to commit to detaching or not so
the caller can decide whether to abort xfers before we actually wait
for them in ldenddetach.

XXX pullup -- although this changes some kernel symbols (sdmmc_add_task
and sdmmc_del_task), it shouldn't affect any existing modules; the only
module that uses sdmmc is ld_sdmmc.kmod, which is `.if 0' in the build
so there shouldn't be any of them floating around.

Make this work on big endian machines

move some of the patching of callbacks and other data after
ieee80211_ifattach() but before if_deferred_start_init().
may fix panic i saw in after restarting wpa_supplicant.
from mlelstv.

only ask for SDPCMD_INTSTATUS_HMB_SW_MASK and SDPCMD_INTSTATUS_CHIPACTIVE
interrupts, not all of them. we only ack these ones.
mostly fixes pinebookpro wifi hard hangs. still is problematic and can
trigger interrupt storm that appears as a hard hang without NET_MPSAFE,
and a follow up, less clearly right, change will reduce that to a soft
hang of the interface that can be cleared with 'ifconfig bwfm0 down up',
and even often recovers itself now.

clear all interrupts, not just those we expect from the hostintmask.
this removes the final hard hang i have seen in pinebookpro wifi,
though one may still need to 'ifconfig bwfm0 down up' occasionally,
so we still have bugs to fix here (the hang is usually associated
with 'checksum error' from bwfm/sdio.)

Sort #includes. Nix trailing whitespace.
No functional change intended.
 1.42.4.2 26-Oct-2024  martin Pull up following revision(s) (requested by jmcneill in ticket #985):

sys/dev/sdmmc/sdmmcvar.h: revision 1.37
sys/dev/sdmmc/sdmmcreg.h: revision 1.35
sys/dev/sdmmc/ld_sdmmc.c: revision 1.44
sys/dev/sdmmc/sdmmc_mem.c: revision 1.76

sdmmc: Add support for SD card caches.

SD physical 6.0 specification introduced Application Performance Class 2
(A2), which adds support for drive caches and command queueing.

Add support for enabling and flushing the cache when this feature is
present.
 1.42.4.1 03-Feb-2024  martin Pull up following revision(s) (requested by riastradh in ticket #566):

sys/dev/sdmmc/ld_sdmmc.c: revision 1.43

ld@sdmmc(4): Hack around deadlock in cache sync on detach.

Yanking a card triggers the sdmmc discovery task, which runs in the
sdmmc task thread, to detach any attached child devices.

Detaching ld@sdmmc triggers a cache flush (via ldbegindetach ->
disk_begindetach -> ld_lastclose -> ld_flush -> ioctl DIOCCACHESYNC),
which is implemented by scheduling a task to do sdmmc_mem_flush_cache
and then waiting for it to complete.

The sdmmc_mem_cache_flush is done by an sdmmc task so it happens
after all previously scheduled I/O operations -- that way the cache
flush doesn't complete until the previously scheduled I/O operations
are complete.

However, when the cache flush task is issued from the discovery task,
this doesn't work, because the cache flush task can't start until the
discovery task has returned -- but the discovery task won't return
until the cache flush task has completed.

To work around this deadlock, which usually happens only when the
device has been yanked anyway so further I/O would be lost anyway,
just do the cache flush synchronously in DIOCCACHESYNC if we're
running in the task thread.

This isn't quite right -- implementation details of the task thread
shouldn't bleed into ld@sdmmc, and running the cache sync _before_
any subsequently scheduled I/O tasks is asking for trouble -- but it
should serve to avoid the deadlock in PR kern/57870 until we can fix
a host of concurrency bugs in sdmmc by fixing the locking scheme and
running discovery in a separate thread from tasks.
 1.43.2.1 02-Aug-2025  perseant Sync with HEAD
 1.9 05-Jul-2024  rin sys: Drop redundant NULL check before m_freem(9)

m_freem(9) safely has accepted NULL argument at least since 4.2BSD:
https://www.tuhs.org/cgi-bin/utree.pl?file=4.2BSD/usr/src/sys/sys/uipc_mbuf.c

Compile-tested on amd64/ALL.

Suggested by knakahara@
 1.8 10-Nov-2019  chs branches: 1.8.32;
in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.7 14-Oct-2018  jdolecek remove M_CANFAIL flag for malloc(9) - it was completely ignored, so had
actually no effect
 1.6 18-Apr-2018  maxv branches: 1.6.2;
m_free -> m_freem, m_copyback could have added mbufs in the chain
 1.5 14-Jul-2016  msaitoh branches: 1.5.10; 1.5.16;
- Use aprint*() instead of printf() in xxx_attach().
- Add missing aprint_naive("\n");
- KNF
 1.4 20-May-2014  rmind branches: 1.4.4;
netbt: rename some attach/detach functions to have _pcb suffix, so
we could use standard attach/detach naming for pr_usrreq functions.
No functional change.
 1.3 27-Oct-2012  chs branches: 1.3.10;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.2 06-May-2009  cegger branches: 1.2.2; 1.2.4; 1.2.10; 1.2.18; 1.2.28;
struct cfdata * -> cfdata_t, no functional changes intended.
 1.1 21-Apr-2009  nonaka branches: 1.1.2; 1.1.4;
Added SD/MMC support from OpenBSD.
tested on i386, amd64 at current-users ML by pgoyette@.
tested on zaurus by myself.
 1.1.4.3 16-May-2009  yamt sync with head
 1.1.4.2 04-May-2009  yamt sync with head.
 1.1.4.1 21-Apr-2009  yamt file sbt.c was added on branch yamt-nfs-mp on 2009-05-04 08:13:18 +0000
 1.1.2.2 28-Apr-2009  skrll Sync with HEAD.
 1.1.2.1 21-Apr-2009  skrll file sbt.c was added on branch nick-hppapmap on 2009-04-28 07:36:33 +0000
 1.2.28.3 03-Dec-2017  jdolecek update from HEAD
 1.2.28.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.28.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.2.18.1 30-Oct-2012  yamt sync with head
 1.2.10.2 21-Apr-2010  matt sync to netbsd-5
 1.2.10.1 06-May-2009  matt file sbt.c was added on branch matt-nb5-mips64 on 2010-04-21 00:27:52 +0000
 1.2.4.2 07-Oct-2009  sborrill Pull up the following revisions(s) (requested by jmcneill in ticket #1044):
distrib/sets/lists/man/mi: patch
share/man/man4/Makefile: patch
sys/arch/amd64/conf/files.amd64: 1.67
sys/arch/i386/conf/files.i386: 1.349
sys/conf/files 1.945
share/man/man4/sdmmc.4: 1.1-1.4
sys/dev/sdmmc/Makefile.sdmmcdevs 1.1
sys/dev/sdmmc/devlist2h.awk 1.1
sys/dev/sdmmc/files.sdmmc 1.1-1.2
sys/dev/sdmmc/ld_sdmmc.c 1.1-1.3
sys/dev/sdmmc/sbt.c 1.1-1.2
sys/dev/sdmmc/sdhc.c 1.1-1.3
sys/dev/sdmmc/sdhcreg.h 1.1
sys/dev/sdmmc/sdhcvar.h 1.1
sys/dev/sdmmc/sdmmc.c 1.1
sys/dev/sdmmc/sdmmc_cis.c 1.1
sys/dev/sdmmc/sdmmc_io.c 1.1
sys/dev/sdmmc/sdmmc_ioreg.h 1.1
sys/dev/sdmmc/sdmmc_mem.c 1.1-1.2
sys/dev/sdmmc/sdmmcchip.h 1.1
sys/dev/sdmmc/sdmmcdevs 1.1
sys/dev/sdmmc/sdmmcdevs.h 1.1-1.2
sys/dev/sdmmc/sdmmcreg.h 1.1-1.3
sys/dev/sdmmc/sdmmcvar.h 1.1

Add sdmmc framework
 1.2.4.1 06-May-2009  sborrill file sbt.c was added on branch netbsd-5 on 2009-10-07 15:41:13 +0000
 1.2.2.2 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.2.2.1 06-May-2009  jym file sbt.c was added on branch jym-xensuspend on 2009-05-13 17:21:29 +0000
 1.3.10.1 10-Aug-2014  tls Rebase.
 1.4.4.1 05-Oct-2016  skrll Sync with HEAD
 1.5.16.2 20-Oct-2018  pgoyette Sync with head
 1.5.16.1 22-Apr-2018  pgoyette Sync with HEAD
 1.5.10.1 06-Nov-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #1429):

sys/dev/usb/ubt.c: revision 1.61
sys/dev/sdmmc/sbt.c: revision 1.6

m_free -> m_freem, m_copyback could have added mbufs in the chain
 1.6.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.6.2.1 10-Jun-2019  christos Sync with HEAD
 1.8.32.1 02-Aug-2025  perseant Sync with HEAD
 1.122 02-Sep-2025  jmcneill sdhc: Disable bus power for 32-bit register accesses.

SDHC_FLAG_32BIT_ACCESS shouldn't prohibit clearing the SD Bus Power bit in
the Power Control Register, that's what SDHC_FLAG_NO_PWR0 is for.

Should help with card initialization issues at boot on controllers that
set the 32-bit access flag.
 1.121 16-Feb-2025  jmcneill sdhc: Remove delay in sdhc_wait_state

Replace the 10us delay loop in sdhc_wait_state with a microuptime based
timeout test.
 1.120 16-Feb-2025  jmcneill sdhc: Remove now unused sc_write_delay
 1.119 09-May-2024  dyoung branches: 1.119.2;
If the ACPI flag "non-removable" is present and true for an SD/MMC
slot, then set a new flag on that slot to indicate that the media
is non-removable. Make sdhc_card_detect always return true for a
slot if its non-removable media flag is set.

This change lets the kernel automatically configure the
permanently-installed MMC slot on the NXP LX2160-based HoneyComb
LX2 board.
 1.118 20-Jan-2024  jmcneill sdmmc: add support for optional delay after register write
 1.117 02-Nov-2022  jmcneill branches: 1.117.2;
Select DMA mode after programming the ADMA base address register(s).

The Arasan SDHCI 8.9a found in the Xilinx Zynq-7000 SoC requires this
sequence to avoid sporadic transfer errors.
 1.116 14-Oct-2022  jmcneill Disable ADMA2 on Ricoh SDHCI controllers.

PR# 57015
 1.115 06-Feb-2022  jmcneill sdhc: Retire SDHC_FLAG_USE_ADMA2 flag.

ADMA2 support in sdhc is mature now, so no need for it to be opt-in.
 1.114 17-Jan-2022  mrg sdhc: avoid taking adaptive mutex while holding spin mutex

the clock_bus pre- and post- callbacks used in sdhc_bus_clock_ddr()
are called with a spin mutex held, and the new sdhc@acpi ends up
calling into (sleeping) ACPI code, triggering lockdebug assertion.

introduce an adaptive mutex that is held around these callbacks,
and reduce the spin mutex held time in sdhc_bus_clock_ddr().
 1.113 15-Jan-2022  jmcneill sdhc: High speed support capability flag applies to eMMC too.
 1.112 10-Nov-2021  msaitoh s/suport/support/ in comment.
 1.111 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.110 13-May-2021  msaitoh branches: 1.110.4;
Use unsigned to avoid undefined behavior in hwrite[12](). Found by kUBSan.
 1.109 24-Apr-2021  thorpej branches: 1.109.2; 1.109.4;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.108 13-Mar-2021  mlelstv branches: 1.108.2;
Enable block count only for count > 0.
Don't enable autostop when command sets new flag SCF_NO_STOP.
 1.107 15-Jul-2020  msaitoh branches: 1.107.2;
Identify SDHC 4.1 and 4.2. From {DragonFly,Free}BSD.
 1.106 28-Oct-2019  joerg Avoid warnings for tautological shifts as sole conditional.
 1.105 28-Oct-2019  mlelstv Skip setting power when the voltage doesn't change.
Also increase some timeouts.
 1.104 23-Oct-2019  hkenken Add SDHC flags.

+ SDHC_FLAG_BROKEN_ADMA2_ZEROLEN
Broken ADMA2 Zero length descriptor.
Can't 64K Byte data transfer.
+ SDHC_FLAG_NO_1_8_V
Support no 1.8V Supply.
Disable UHS-I bus speed mode (SDR50, DDR50, SDR104).
 1.103 03-Jul-2019  jmcneill branches: 1.103.2;
If switching to fixed sampling clock, do not return an error to the sdmmc layer.
 1.102 13-Mar-2019  jmcneill Add vendor callback for post-bus clock ops and add SDHC_FLAG_STOP_WITH_TC flag
 1.101 23-Jun-2017  ryo branches: 1.101.6;
fix problem for ESDHC/USDHC due to change of r1.96

on ESDHC/USDHC, even if the iosize is less than SDHC_HOST_CTL_VERSION,
specver must be an appropriate value.
 1.100 22-Apr-2017  jmcneill branches: 1.100.4;
Add a vendor callback for setting signal voltage.
 1.99 17-Feb-2017  nonaka sdhc(4): hardware reset support for Intel eMMC controller
 1.98 17-Feb-2017  nonaka sdhc(4), sdmmc(4): Added MMC HS DDR52 support.
 1.97 07-Jan-2017  kiyohara branches: 1.97.2;
Add flags SDHC_FLAG_NO_AUTO_STOP and SDHC_FLAG_NO_BUSY_INTR.
 1.96 07-Jan-2017  kiyohara Don't access SDHC_HOST_CTL_VERSION, if iosize less than this.
 1.95 10-Aug-2016  nonaka Use 1.65-1.95 voltage window for 1.8V support.
 1.94 03-Jul-2016  kiyohara branches: 1.94.2;
Please more delay, if timeout in sdhc_wait_intr().
 1.93 31-Dec-2015  ryo add support iMX6 uSDHC
- some UHS-I/SDR104 card are not stable
- eMMC doesn't work yet
 1.92 28-Dec-2015  ryo fix typo. use pmask for SDHC_PRESENT_STATE.
 1.91 03-Nov-2015  mlelstv Also wait for DAT when sending RSP_BSY commands. Fixes PR 50388.
 1.90 03-Nov-2015  mlelstv fix timeout path in soft reset when building with SDHC_DEBUG
 1.89 02-Nov-2015  jmcneill allow vendor specific code to hook into bus width changes
 1.88 06-Oct-2015  mlelstv support hiding command timeout messages with a new command flag and use this
when probing for cards. Should fix PR 50302.
 1.87 09-Sep-2015  mlelstv The iMX uSDHC controller doesn't have an interrupt error status flag,
the bit position is reserved and reads as value 0.
- Fake the flag if any of the error bits is set.
- uSDHC supports the 32bit access, the 16bit path doesn't need that quirk.
 1.86 09-Sep-2015  mlelstv Don't test flags from error value in status value. Instead test the
error interrupt status.
 1.85 09-Sep-2015  mlelstv fix DPRINTF parameters
 1.84 09-Aug-2015  mlelstv Ignore data inhibit for commands that do not use the DAT line.
Do a soft reset when the inhibit condition persists for better
error recovery.

Simplify interrupt handling and print errors reported by the controller.

Add more specific debug messages for timeout errors.
 1.83 09-Aug-2015  mlelstv Protect the whole tuning operation including the register setup.
 1.82 09-Aug-2015  mlelstv Add a quirk for Ricoh 5U823 controller. Operation with a 100MHz
bus clock for SDR50 seems to be unstable, reduce frequency one notch
(effectively down to 66MHz with divisor = 3).
 1.81 06-Aug-2015  jmcneill don't hold intr_lock while calling sdhc_execute_tuning
 1.80 05-Aug-2015  jmcneill support re-tuning modes 1 and 2
 1.79 05-Aug-2015  jmcneill Implement SDHC sampling clock tuning procedure.
 1.78 05-Aug-2015  mlelstv lock more hardware accesses
 1.77 03-Aug-2015  jmcneill Add SDHC_FLAG_POLL_CARD_DET flag which lets the bus glue request polling
instead of standard SDHC card insert / detach events.
 1.76 03-Aug-2015  jmcneill Add support for DDR50 transfer modes.
 1.75 03-Aug-2015  mlelstv better error message
 1.74 03-Aug-2015  jmcneill don't select SDR12 mode if we are <= 400 kHz
 1.73 03-Aug-2015  jmcneill dont confuse signaling voltage and bus voltage
 1.72 02-Aug-2015  jmcneill let SDHC_FLAG_HOSTCAPS override SDHC_CAPABILITIES2 as well
 1.71 02-Aug-2015  jmcneill add support for UHS-I modes on capable 3.0+ controllers
 1.70 02-Aug-2015  jmcneill bus_dma_segment_t ds_addr is bus_addr_t not paddr_t (another case of it)
 1.69 02-Aug-2015  jmcneill bus_dma_segment_t ds_addr is bus_addr_t not paddr_t
 1.68 02-Aug-2015  mlelstv Be more verbose about error conditions.
 1.67 02-Aug-2015  mlelstv correct (the commented out) calculation of bus frequency.
 1.66 02-Aug-2015  jmcneill return MMC_OCR_HCS bit from host_ocr if the controller supports high-speed mode
 1.65 31-Jul-2015  jmcneill Simplify sdhc(4) locking
 1.64 30-Jul-2015  jmcneill print "platform DMA" instead of "SDMA" when using external DMA engine
 1.63 29-Jul-2015  jmcneill Add ADMA2 support, which enables scatter gather DMA for data transfers on
controllers that support it.
 1.62 28-Jul-2015  skrll Remove unnecessary #include
 1.61 23-Jul-2015  jmcneill Add a SDHC_FLAG_NO_TIMEOUT quirk to handle spurious timeouts on Tegra K1
during data transfers. While here, increase the soft timeout for DMA
transfers from 1s to 3s.
 1.60 22-Jul-2015  skrll Use C99 designated initializers.

No functional change.
 1.59 30-May-2015  jmcneill support 8-bit mode for SDHC 3.0+ controllers
 1.58 03-May-2015  jmcneill print some useful information at attach time
 1.57 03-May-2015  jmcneill Add SDHC_FLAG_SINGLE_POWER_WRITE flag, that tells the driver to update
the SDHC_POWER_CTL register with a single write rather than in multiple
steps. Required for Tegra K1 SDHC.
 1.56 02-May-2015  jmcneill support SDHC 4.0, allow for overriding clk base frequency
 1.55 14-Apr-2015  bouyer Add a new SDHC_FLAG, SDHC_FLAG_EXTDMA_DMAEN, which request that the
SDHC_DMA_ENABLE bit be set in the command, even if we're using an
external DMA engine. Needed by the upcoming DMA support for AM335x
(beaglebone).
 1.54 27-Feb-2015  nonaka eSDHC has no DMA_BOUNDARY in BLOCK_SIZE register.
So clear multi segment DMA transfer support bit.
 1.53 27-Feb-2015  nonaka Don't clear other bits. pq3sdhc is set more bits.
 1.52 26-Jan-2015  nonaka eSDHC has non standard Host Controller Version Register offset.
 1.51 04-Oct-2014  jmcneill branches: 1.51.2;
pass sdhc_softc instead of sdhc_host to sc_vendor_transfer_data_dma, since the vendor specific code has no visibility into struct sdhc_host and can easily do device_private(sdhc_softc->sc_dev)
 1.50 02-Oct-2014  mlelstv Fix divisor calculation for SDHC 3.0.
1/1 -> 0
1/2 -> 1
1/4 -> 2
...
1/2*N -> N
 1.49 01-Oct-2014  jmcneill correct clk div calculation for SD 3.0 controllers
 1.48 01-Oct-2014  jmcneill Don't check slot type for pre-3.0 controllers, the bits were reserved at
the time. If an older controller advertises 1.8V support, just use it.
This fixes high-speed mode support for me on BeagleBone Black.
 1.47 14-Sep-2014  skrll When doing vendor dma transfer wait for SDHC_TRANSFER_COMPLETE.

From jmcneill@ with some layout changes from me.
 1.46 12-Sep-2014  jakllsch Avoid NULL deref when sdhc(4) attaches via config_interrupts().
 1.45 12-Sep-2014  jakllsch Allow sdhc(4) to use a non-integrated DMA engine.
 1.44 24-May-2014  hkenken branches: 1.44.2;
eSDHC Controller doesn't have "Host SDMA Buffer Boundary" bit field
 1.43 10-Jan-2013  jmcneill branches: 1.43.10;
add SDHC_FLAG_NO_HS_BIT flag to prevent sdhc driver from setting the SDHC_HIGH_SPEED bit in SDHC_HOST_CTL, required to get many high speed cards working on rpi
 1.42 08-Jan-2013  jakllsch If the command protocol calls for a trailing busy signal,
wait (up to 10 seconds) for it to be released.
 1.41 07-Jan-2013  jakllsch Find correct slot index in sdhc_cfprint().
 1.40 24-Dec-2012  jakllsch SDHC_VOLTAGE_SUPP_1_8V is only valid in the presence of SDHC_EMBEDDED_SLOT.
Fixes probing of full-size 1GB Toshiba card made in 2008 that fails to
respond with a 1.8V supply. (JMB389 (in TS-RDF1) host claims
SDHC_VOLTAGE_SUPP_1_8V but does not claim SDHC_EMBEDDED_SLOT.)
 1.39 23-Dec-2012  jakllsch SMC_CAPS_DMA without SMC_CAPS_MULTI_SEG_DMA means we as a host driver only
can support one segment per operation. This is not the case with SDHCI SDMA,
the only SDHCI DMA mechanism we currently support in sdhc(4). Should fix
corrupt data on DMA-enabled SDHCI controllers claiming conformance to a SDHCI
Specification other than 1.0.
 1.38 22-Dec-2012  jakllsch Add support for SDHCI 3.0 bus clock generation, which unlike 1.0 and 2.0
has support for non-power-of-two divisors from 1 to 1023. Additionally
restore finding the correct power-of-two divisor for standard-compliant
pre-3.0 SDHCI parts. Also, calculate minimum divided clock for the
clkmsk-quirk parts correctly.

XXX Will future standard-compliant SDHCI versions have a SDHCI 3.0
backwards-compatible clock generator, or just SDHCI 1.0/2.0?
 1.37 20-Dec-2012  jakllsch If we get a SDMA boundary-crossing interrupt at the end of the final
segment, the transfer is not implicitly complete; we still need to wait
for the transfer complete interrupt so that we can issue new commands
successfully.

This fixes the problem my Ricoh R5C822 was having where all writes after
a larger (64KiB) write were failing because we attempted to issue CMD13
(to check the status of the aformentioned write) too soon afterwards.

I suspect this fix to apply to other Ricoh SDHCI controllers I've heard
people have had trouble with. Sorry I didn't look at this sooner.
 1.36 20-Dec-2012  jakllsch Change sdhc_detach so that it detaches all host controllers at once.
This should make multiple slot controllers, for example those with
a controller on more than one PCI/CardBus BAR, detach with fewer bugs.
Tested with as-of-yet-uncommited sdhc_pci changes on a single-host
ExpressCard JMicron JMB38[89].
 1.35 13-Dec-2012  riastradh Implement TI AM335x's SDHC reset quirk. Beaglebone SDHC works now!

On the AM335x, we first must wait for the controller to acknowledge
the reset; then we can wait for the reset to complete.

I believe this quirk also applies to the OMAP4 ES, but I don't have
one of those to test and we don't seem to have an obvious conditional
for it anyway.

This quirk may work for controllers that don't require it too, but I
am nervous about doing it by default because if we miss the reset
acknowledgement, then we'll just time out even though everything is
really hunky-dory.

Also, for all sdhc, don't bother writing 0 in sdhc_soft_reset while
waiting for the reset to complete; there is no need.

ok matt
 1.34 12-Dec-2012  matt Add sc_vendor_bus_clock hook
From jmcneill.
 1.33 12-Dec-2012  riastradh Avoid the 16-bit read in sdhc_host_found for 32-bit-only devices.

This change makes sdhc_host_found allocate hp up front before showing
the identification, in order to avoid having to open-code a copy of
HREAD2 before hp is available.
 1.32 29-Oct-2012  kiyohara Support omap3 SDHC driver. tested on OVERO only.
 1.31 13-Sep-2012  joerg Don't use const foo const as type, one const is enough.
 1.30 31-Aug-2012  matt branches: 1.30.2;
Support deciphering SDHCv3 clock rates.
 1.29 30-Jul-2012  matt Make PIO on normal SDHC devices work correctly on big-endian machines.
Add locking around interrupt manipulation (it should now be MP safe).
 1.28 28-Jul-2012  matt Only SDHC 1.0 controllers can do that fucky MULTI_SEG stuff.
 1.27 28-Jul-2012  jakllsch sdhc(4) currently only implements support for the SDHC 1.0 DMA mechanism, so
only enable in that case.
 1.26 26-Jul-2012  matt MULTI_SEG does not for ESDHC. (Don't know how it works at all on any SDHC
but ...)
 1.25 23-Jul-2012  matt Responses are actually in host order (except SCR which is return in
big endian so that's convert to host order).
 1.24 21-Jul-2012  skrll Provide a method for attachments to specify capabilites.
 1.23 20-Jul-2012  matt Add use of watermark register when PIO to an ESDHC. After every kill or
drain of watermask words, pause a bit to give time for the fifo to recover.
Always the command response in BE byteorder. Rewrite __bitfield to deal
with this.
 1.22 17-Jul-2012  matt If there was an error in 32-bit mode, just set ERROR_INTERRUPT otherwise
see if matched anything we care about.
 1.21 17-Jul-2012  skrll Handle interrupt acknowledgement in the SDHC_FLAG_32BIT_ACCESS case in
the same way as non-SDHC_FLAG_32BIT_ACCESS case.
 1.20 12-Jul-2012  jakllsch bus_space_*_stream_N() functions are not universally available.
Provite alternate implementation for when they are unavailable.
 1.19 12-Jul-2012  jakllsch Completely rework (and enable) SDHC 1.0 DMA data transfer.

While without a large physically-contiguous buffer the performance
suffers severly, this should still be better than PIO.
 1.18 12-Jul-2012  jakllsch No need to panic on failure to find a divisor.
Additionally, add commented out calculation of actual clock frequency.
 1.17 12-Jul-2012  jakllsch SDHC can have multiple slots, note which slot a specific sdmmc(4) attaches to.
 1.16 12-Jul-2012  jakllsch SDHCI byte swaps the BE response on the wire into LE registers.
As we always want response data in LE, use bus_space_read_stream.
Additonally, read response data in 1 or 4 4-byte chunks, instead of
one 4-byte chunk or 15 1-byte chunks.
 1.15 12-Jul-2012  jakllsch Always enable and set block count register. We never do infinite transfers.
The old way seemed to be causing issues on a R5C822, at least with DMA enabled.
 1.14 12-Jul-2012  matt Add a flag for the lack of LED_ON in HOST_CTL (ti omap3 doesn't do that).
 1.13 15-Mar-2012  bouyer Do not read past array end, found by gcc -O3.
This could cause to HWRITE4() a bad value, but maybe last 2 bytes are
probably ignored by hardware anyway.
 1.12 02-Mar-2012  nonaka Added Ricoh 5U822/5U823 SD/MMC Controller support.
 1.11 23-Feb-2012  matt Support 32-bit only access to the SDHC registers.
Add support for FreeScale "Enhanced" SDHC port.
Add support for CGM mode (XLP and BCM2835 (Arason)).
 1.10 02-Feb-2012  nonaka branches: 1.10.2;
Use "opt_sdmmc.h" for SDHC_DEBUG.
 1.9 29-Jun-2011  matt branches: 1.9.2; 1.9.6;
Add some inital changes for the Freescale eSDHC.
 1.8 07-Oct-2010  kiyohara Support change Open-drain/Push-pull by bus_rod().
 1.7 27-Mar-2010  nonaka branches: 1.7.2;
Added sdhc at cardbus support.
 1.6 24-Feb-2010  dyoung branches: 1.6.2;
A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.
 1.5 12-Jan-2010  uebayasi branches: 1.5.2;
According to SD Host Controller Simplified Specification Version 2.00, 2.2.10.
Host Control Register (Offset 028h), the "Data Transfer Width" bit is in Host
Control Register (Offset 028h), not Power Control Register (Offset 029h).
 1.4 08-Jan-2010  dyoung Expand PMF_FN_* macros.
 1.3 02-Oct-2009  uebayasi branches: 1.3.2;
Typo in comment.
 1.2 17-May-2009  cegger fix crash with LOCKDEBUG+DIAGNOSTIC kernels:

sdhc_bus_clock() calls mutex_enter().
then in DIAGNOSTIC section, sdhc_bus_clock() calls sdhc_card_detect().
sdhc_card_detect() calls mutex_enter() on the same mutex again.
when LOCKDEBUG is enabled, you get

Mutex error: lockdebug_wantlock: locking against myself
 1.1 21-Apr-2009  nonaka branches: 1.1.2; 1.1.4; 1.1.6;
Added SD/MMC support from OpenBSD.
tested on i386, amd64 at current-users ML by pgoyette@.
tested on zaurus by myself.
 1.1.6.3 23-Jul-2009  jym Sync with HEAD.
 1.1.6.2 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.1.6.1 21-Apr-2009  jym file sdhc.c was added on branch jym-xensuspend on 2009-05-13 17:21:29 +0000
 1.1.4.6 09-Oct-2010  yamt sync with head
 1.1.4.5 11-Aug-2010  yamt sync with head.
 1.1.4.4 11-Mar-2010  yamt sync with head
 1.1.4.3 20-Jun-2009  yamt sync with head
 1.1.4.2 04-May-2009  yamt sync with head.
 1.1.4.1 21-Apr-2009  yamt file sdhc.c was added on branch yamt-nfs-mp on 2009-05-04 08:13:18 +0000
 1.1.2.2 28-Apr-2009  skrll Sync with HEAD.
 1.1.2.1 21-Apr-2009  skrll file sdhc.c was added on branch nick-hppapmap on 2009-04-28 07:36:33 +0000
 1.3.2.2 07-Oct-2009  sborrill branches: 1.3.2.2.4;
Pull up the following revisions(s) (requested by jmcneill in ticket #1044):
distrib/sets/lists/man/mi: patch
share/man/man4/Makefile: patch
sys/arch/amd64/conf/files.amd64: 1.67
sys/arch/i386/conf/files.i386: 1.349
sys/conf/files 1.945
share/man/man4/sdmmc.4: 1.1-1.4
sys/dev/sdmmc/Makefile.sdmmcdevs 1.1
sys/dev/sdmmc/devlist2h.awk 1.1
sys/dev/sdmmc/files.sdmmc 1.1-1.2
sys/dev/sdmmc/ld_sdmmc.c 1.1-1.3
sys/dev/sdmmc/sbt.c 1.1-1.2
sys/dev/sdmmc/sdhc.c 1.1-1.3
sys/dev/sdmmc/sdhcreg.h 1.1
sys/dev/sdmmc/sdhcvar.h 1.1
sys/dev/sdmmc/sdmmc.c 1.1
sys/dev/sdmmc/sdmmc_cis.c 1.1
sys/dev/sdmmc/sdmmc_io.c 1.1
sys/dev/sdmmc/sdmmc_ioreg.h 1.1
sys/dev/sdmmc/sdmmc_mem.c 1.1-1.2
sys/dev/sdmmc/sdmmcchip.h 1.1
sys/dev/sdmmc/sdmmcdevs 1.1
sys/dev/sdmmc/sdmmcdevs.h 1.1-1.2
sys/dev/sdmmc/sdmmcreg.h 1.1-1.3
sys/dev/sdmmc/sdmmcvar.h 1.1

Add sdmmc framework
 1.3.2.1 02-Oct-2009  sborrill file sdhc.c was added on branch netbsd-5 on 2009-10-07 15:41:13 +0000
 1.3.2.2.4.1 26-Jul-2011  matt Backport flash/nand/nor subsystem from -HEAD.
 1.5.2.2 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.5.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.6.2.2 05-Mar-2011  rmind sync with head
 1.6.2.1 30-May-2010  rmind sync with head
 1.7.2.6 15-Feb-2014  matt HAS_CGM -> HAVE_CGM (like current)
Add 32BIT_ACCESS
 1.7.2.5 05-Nov-2013  matt turn off debug
 1.7.2.4 27-Dec-2011  matt Sync/merge with changes from matt-nb5-pq3
 1.7.2.3 24-Dec-2011  matt Add support for >63MHZ speeds.
Add support for extended clock division via CGM.
 1.7.2.2 21-Apr-2010  matt sync to netbsd-5
 1.7.2.1 27-Mar-2010  matt file sdhc.c was added on branch matt-nb5-mips64 on 2010-04-21 00:27:52 +0000
 1.9.6.6 05-Apr-2012  mrg sync to latest -current.
 1.9.6.5 06-Mar-2012  mrg sync to -current
 1.9.6.4 06-Mar-2012  mrg sync to -current
 1.9.6.3 04-Mar-2012  mrg sync to latest -current.
 1.9.6.2 24-Feb-2012  mrg sync to -current.
 1.9.6.1 18-Feb-2012  mrg merge to -current.
 1.9.2.4 23-Jan-2013  yamt sync with head
 1.9.2.3 16-Jan-2013  yamt sync with (a bit old) head
 1.9.2.2 30-Oct-2012  yamt sync with head
 1.9.2.1 17-Apr-2012  yamt sync with head
 1.10.2.5 13-Feb-2013  riz Pull up following revision(s) (requested by skrll in ticket #813):

etc/MAKEDEV.tmpl 1.160
etc/etc.evbarm/MAKEDEV.conf 1.9
external/broadcom/rpi-firmware/dist/LICENCE.broadcom 1.1
external/broadcom/rpi-firmware/dist/bootcode.bin 1.1
external/broadcom/rpi-firmware/dist/bootcode.bin 1.2
external/broadcom/rpi-firmware/dist/fixup.dat 1.1
external/broadcom/rpi-firmware/dist/fixup.dat 1.2
external/broadcom/rpi-firmware/dist/fixup_cd.dat 1.1
external/broadcom/rpi-firmware/dist/fixup_cd.dat 1.2
external/broadcom/rpi-firmware/dist/start.elf 1.1
external/broadcom/rpi-firmware/dist/start.elf 1.2
external/broadcom/rpi-firmware/dist/start_cd.elf 1.1
external/broadcom/rpi-firmware/dist/start_cd.elf 1.2
sys/arch/arm/broadcom/bcm2835_bsc.c 1.1 via patch
sys/arch/arm/broadcom/bcm2835_bscreg.h 1.1 via patch
sys/arch/arm/broadcom/bcm2835_dotg.c 1.1 via patch
sys/arch/arm/broadcom/bcm2835_emmc.c 1.7 via patch
sys/arch/arm/broadcom/bcm2835_genfb.c 1.4 via patch
sys/arch/arm/broadcom/bcm2835_gpio_subr.c 1.2 via patch
sys/arch/arm/broadcom/bcm2835_gpio_subr.h 1.1 via patch
sys/arch/arm/broadcom/bcm2835_gpioreg.h 1.1 via patch
sys/arch/arm/broadcom/bcm2835_intr.c 1.3 via patch
sys/arch/arm/broadcom/bcm2835_mbox.c 1.5 via patch
sys/arch/arm/broadcom/bcm2835_mbox.h 1.4 via patch
sys/arch/arm/broadcom/bcm2835_obio.c 1.17 via patch
sys/arch/arm/broadcom/bcm2835_pm.c 1.2 via patch
sys/arch/arm/broadcom/bcm2835_rng.c 1.3 via patch
sys/arch/arm/broadcom/bcm2835_space.c 1.5 via patch
sys/arch/arm/broadcom/bcm2835_spi.c 1.1 via patch
sys/arch/arm/broadcom/bcm2835_spireg.h 1.1 via patch
sys/arch/arm/broadcom/bcm2835_tmr.c 1.3 via patch
sys/arch/arm/broadcom/bcm2835reg.h 1.10 via patch
sys/arch/arm/broadcom/files.bcm2835 1.14 via patch
sys/arch/evbarm/conf/RPI 1.23 via patch
sys/arch/evbarm/conf/files.rpi 1.3 via patch
sys/arch/evbarm/conf/mk.rpi 1.2 via patch
sys/arch/evbarm/conf/std.rpi 1.4 via patch
sys/arch/evbarm/rpi/rpi_machdep.c 1.34 via patch
sys/arch/evbarm/rpi/rpi_start.S 1.7 via patch
sys/arch/evbarm/rpi/rpi_vcmbox.c 1.2 via patch
sys/arch/evbarm/rpi/vcio.h 1.1 via patch
sys/arch/evbarm/rpi/vcprop.h 1.7 via patch
sys/conf/files patch
sys/dev/sdmmc/sdhc.c 1.43
sys/dev/sdmmc/sdhcvar.h 1.13
sys/dev/usb/dwc_otg.c 1.45 via patch
sys/dev/usb/dwc_otgreg.h 1.5 via patch
sys/dev/usb/dwc_otgvar.h 1.11 via patch
sys/dev/usb/files.usb 1.126 via patch
sys/dev/usb/if_smsc.c 1.7 via patch
sys/dev/usb/if_smscreg.h 1.1 via patch
sys/dev/usb/if_smscvar.h 1.1 via patch
sys/dev/usb/usbdevices.config patch
sys/dev/usb/usbdevs 1.633 via patch
sys/dev/usb/usbdevs.h regen
sys/dev/usb/usbdevs_data.h regen
sys/dev/wscons/wsconsio.h 1.105,1.107 via patch
sys/dev/wscons/wsdisplayvar.h 1.50
sys/dev/wscons/wsdisplay_util.c 1.2
sys/dev/videomode/edid.c 1.12 via patch

Greatly improved Raspberry Pi support. USB and onboard
Ethernet should work.
[skrll, ticket #813]
 1.10.2.4 02-Jan-2013  riz sys/dev/sdmmc/sdhc.c patch
sys/dev/sdmmc/sdhcreg.h patch

Support SDHC version 3 clocks.
[skrll, ticket #759]
 1.10.2.3 09-Aug-2012  jdc Pull up revisions:
src/sys/arch/evbarm/dev/plcomreg.h revisions 1.2,1.3,1.4
src/sys/arch/evbarm/conf/INTEGRATOR revision 1.65
src/sys/arch/evbarm/dev/plcom.c revisions 1.34,1.35,1.36,1.37,1.38,1.39,1.40
src/sys/arch/evbarm/ifpga/plcom_ifpga.c revisions 1.12,1.13,1.14
src/sys/arch/evbarm/dev/plcomvar.h revisions 1.9,1.10,1.11
src/sys/arch/evbarm/ifpga/plcom_ifpgavar.h revision 1.2
src/sys/arch/arm/arm/cpufunc.c revisions 1.105,1.108
src/sys/arch/arm/arm32/cpu.c revision 1.79
src/sys/arch/arm/include/armreg.h revisions 1.49,1.54
src/sys/arch/arm/arm32/pmap.c revision 1.229
src/sys/arch/arm/arm32/arm32_machdep.c revision 1.77
src/sys/arch/arm/include/cpu.h revision 1.64
src/sys/arch/arm/arm/cpufunc_asm_arm1136.S revision 1.3
src/sys/arch/arm/arm/cpufunc_asm_arm11x6.S revision 1.1
src/sys/arch/arm/conf/files.arm revision 1.106
src/sys/arch/arm/include/cpufunc.h revision 1.57
src/sys/dev/sdmmc/sdhc.c revisions 1.14,1.24
src/sys/dev/sdmmc/sdhcvar.h revisions 1.7,1.8
src/sys/arch/evbarm/ifpga/ifpgareg.h revision 1.4
src/sys/arch/evbarm/integrator/integrator_machdep.c revision 1.69
src/sys/arch/arm/broadcom/bcm2835_dma.c revision 1.1
src/sys/arch/arm/broadcom/bcm2835_emmc.c revision 1.1
src/sys/arch/arm/broadcom/bcm2835_intr.c revision 1.1
src/sys/arch/arm/broadcom/bcm2835_intr.h revision 1.1
src/sys/arch/arm/broadcom/bcm2835_obio.c revision 1.1
src/sys/arch/arm/broadcom/bcm2835_plcom.c revision 1.1
src/sys/arch/arm/broadcom/bcm2835_pm.c revision 1.1
src/sys/arch/arm/broadcom/bcm2835_pmvar.h revision 1.1
src/sys/arch/arm/broadcom/bcm2835_space.c revision 1.1
src/sys/arch/arm/broadcom/bcm2835_tmr.c revision 1.1
src/sys/arch/arm/broadcom/bcm2835reg.h revision 1.1
src/sys/arch/arm/broadcom/bcm2835var.h revision 1.1
src/sys/arch/arm/broadcom/bcm_amba.h revision 1.1
src/sys/arch/arm/broadcom/files.bcm2835 revision 1.1
src/sys/arch/evbarm/Makefile revision 1.9
src/sys/arch/evbarm/conf/RPI revision 1.1
src/sys/arch/evbarm/conf/files.rpi revision 1.1
src/sys/arch/evbarm/conf/mk.rpi revision 1.1
src/sys/arch/evbarm/conf/std.rpi revision 1.1
src/sys/arch/evbarm/rpi/genassym.cf revision 1.1
src/sys/arch/evbarm/rpi/rpi.h revision 1.1
src/sys/arch/evbarm/rpi/rpi_machdep.c revision 1.1
src/sys/arch/evbarm/rpi/rpi_start.S revision 1.1,1.2
src/etc/etc.evbarm/Makefile.inc revision 1.28
(requested by skrll in ticket #454).

don't mix #define<TAB> and #define<SPACE> in a file.

avoid warning with options PLCOM_DEBUG for INTEGRATOR.

Rename register values. No functional change - same code before and after.

Existing names are prefixed with PL01X_ where they're common between the
PL010 and the PL011. The PL010_/PL011_ prefixes are added where they're
found only on the respective chips.

Replace the simple_lock with a kmutex_t. Update the locking to match
com(4) in the few places it didn't already.

DOH. Replace a line that got accidently deleted in the last commit.

device_t/softc split
struct device * -> device_t
struct cfdata * -> cfdata_t

Add the 'Z' to the 1176 cpu product name.

ok matt@

Fix locking botch introduced in 1.36.

Fix a KASSERT. From/OK'ed by matt@

Fix racy softint dispatch that lead to KASSERT(si->si_active) in
softint_execute

Discussed with matt@. "Looks good to me"

Add the documented ARM11[37]6 Auxiliary control register defines.

Add support for the ARM1176JZS

Add a flag for the lack of LED_ON in HOST_CTL (ti omap3 doesn't do that).

Provide a method for attachments to specify capabilites.

Add support for the PL011 to plcom. Pull across a bunch of fixes from
com(4) while I'm here and do some other tidyup.

Tested on a RaspberryPi.

PL010 not tested.

Initial commit of support for the RaspberryPI (www.raspberrypi.org)

This is enough for serial console via the gpio header pins and to get to
multiuser.

A huge thank you to Matt Thomas for all his help.

Add RPI to KERNEL_SETS

Remove #if 0 code.
 1.10.2.2 08-Aug-2012  jdc Pull up revisions:
src/sys/dev/sdmmc/sdhc.c revisions 1.16,1.20,1.21,1.22,1.23 via patch,1.25
src/sys/dev/sdmmc/sdhcreg.h revision 1.8
src/sys/dev/sdmmc/sdmmc_mem.c revisions 1.21,1.22
src/sys/dev/sdmmc/sdmmcreg.h revisions 1.10,1.11,1.12
(requested by matt in ticket 441).

SDHCI byte swaps the BE response on the wire into LE registers.
As we always want response data in LE, use bus_space_read_stream.
Additonally, read response data in 1 or 4 4-byte chunks, instead of
one 4-byte chunk or 15 1-byte chunks.

bus_space_*_stream_N() functions are not universally available.
Provite alternate implementation for when they are unavailable.

Handle interrupt acknowledgement in the SDHC_FLAG_32BIT_ACCESS case in
the same way as non-SDHC_FLAG_32BIT_ACCESS case.

If there was an error in 32-bit mode, just set ERROR_INTERRUPT otherwise
see if matched anything we care about.

Add use of watermark register when PIO to an ESDHC. After every kill or
drain of watermask words, pause a bit to give time for the fifo to recover.
Always the command response in BE byteorder. Rewrite __bitfield to deal
with this.

Responses are actually in host order (except SCR which is return in
big endian so that's convert to host order).

Fix comments about __bitfield.
 1.10.2.1 11-Jun-2012  riz Pull up following revision(s) (requested by matt in ticket #254):
sys/arch/powerpc/booke/dev/pq3sdhc.c: revision 1.4
sys/dev/sdmmc/sdhc.c: revision 1.11
sys/dev/sdmmc/sdhc.c: revision 1.13
Use the new 32-bit and ESDHC support in sdhc.c
Support 32-bit only access to the SDHC registers.
Add support for FreeScale &quot;Enhanced&quot; SDHC port.
Add support for CGM mode (XLP and BCM2835 (Arason)).
Do not read past array end, found by gcc -O3.
This could cause to HWRITE4() a bad value, but maybe last 2 bytes are
probably ignored by hardware anyway.
 1.30.2.4 03-Dec-2017  jdolecek update from HEAD
 1.30.2.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.30.2.2 25-Feb-2013  tls resync with head
 1.30.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.43.10.1 10-Aug-2014  tls Rebase.
 1.44.2.9 08-Nov-2015  riz Pull up following revision(s) (requested by jmcneill in ticket #1022):
sys/dev/sdmmc/sdhc.c: revision 1.89
sys/arch/arm/omap/omap3_sdhc.c: revision 1.19
sys/dev/sdmmc/sdhcvar.h: revision 1.25
sys/arch/evbarm/beagle/beagle_machdep.c: revision 1.62
allow vendor specific code to hook into bus width changes
Support 8-bit eMMC for TI AM335x. On my BeagleBone Black,
Before: 134217728 bytes transferred in 9.410 secs (14263307 bytes/sec)
After: 134217728 bytes transferred in 7.518 secs (17852850 bytes/sec)
enable 8-bit mode on AM335X SDMMC2
 1.44.2.8 19-Apr-2015  msaitoh Pull up following revision(s) (requested by bouyer in ticket #703):
sys/dev/sdmmc/sdhcvar.h: revision 1.16
sys/dev/sdmmc/sdhc.c: revision 1.55
Add a new SDHC_FLAG, SDHC_FLAG_EXTDMA_DMAEN, which request that the
SDHC_DMA_ENABLE bit be set in the command, even if we're using an
external DMA engine. Needed by the upcoming DMA support for AM335x
(beaglebone).
 1.44.2.7 09-Mar-2015  snj Pull up following revision(s) (requested by nonaka in ticket #577):
sys/arch/powerpc/booke/dev/pq3sdhc.c: revision 1.6
sys/dev/sdmmc/sdhc.c: revision 1.54
sys/dev/sdmmc/sdmmc.c: revision 1.24
eSDHC has no DMA_BOUNDARY in BLOCK_SIZE register.
So clear multi segment DMA transfer support bit.
--
fix to simulate multi-segment dma transfer for pq3sdhc(4).
--
pq3sdhc: Enable DMA transfer.
 1.44.2.6 27-Jan-2015  martin Pull up following revision(s) (requested by nonaka in ticket #460):
sys/dev/sdmmc/sdhcreg.h: revision 1.12
sys/dev/sdmmc/sdhc.c: revision 1.52
eSDHC has non standard Host Controller Version Register offset.
 1.44.2.5 05-Oct-2014  martin Pull up following revision(s) (requested by skrll in ticket #129):
sys/dev/sdmmc/sdhcvar.h: revision 1.15
sys/dev/sdmmc/sdhc.c: revision 1.51
sys/arch/arm/broadcom/bcm2835_emmc.c: revision 1.19
Pass sdhc_softc instead of sdhc_host to sc_vendor_transfer_data_dma,
since the vendor specific code has no access to it otherwise,
but can easily do device_private(sdhc_softc->sc_dev).
 1.44.2.4 04-Oct-2014  martin Pull up following revision(s) (requested by skrll in ticket #127):
sys/dev/sdmmc/sdhc.c: revision 1.50
Fix divisor calculation for SDHC 3.0.
 1.44.2.3 03-Oct-2014  martin Pull up following revision(s) (requested by skrll in ticket #126):
sys/arch/evbarm/rpi/rpi_machdep.c: revision 1.47
sys/arch/arm/broadcom/bcm2835reg.h: revision 1.12
sys/arch/evbarm/conf/RPI: revision 1.52
sys/arch/evbarm/conf/RPI: revision 1.53
sys/arch/evbarm/conf/RPI: revision 1.54
sys/arch/arm/broadcom/bcm2835_emmc.c: revision 1.10
sys/arch/arm/broadcom/bcm2835_emmc.c: revision 1.11
sys/arch/arm/broadcom/bcm2835_emmc.c: revision 1.12
sys/arch/arm/broadcom/bcm2835_emmc.c: revision 1.13
sys/arch/arm/broadcom/bcm2835_emmc.c: revision 1.14
sys/arch/arm/broadcom/bcm2835_emmc.c: revision 1.15
sys/arch/arm/broadcom/bcm2835_dmac.c: revision 1.3
sys/arch/arm/broadcom/bcm2835_dmac.c: revision 1.4
sys/arch/arm/broadcom/bcm2835_dmac.h: revision 1.2
sys/arch/arm/broadcom/bcm2835_dmac.c: revision 1.5
sys/arch/arm/broadcom/bcm2835_emmc.c: revision 1.18
sys/arch/arm/broadcom/bcm2835_dmac.h: revision 1.3
sys/arch/arm/broadcom/bcm2835_dmac.c: revision 1.6
sys/arch/arm/broadcom/bcm2835_dmac.c: revision 1.7
sys/arch/arm/broadcom/bcm2835_dmac.c: revision 1.8
sys/arch/arm/broadcom/bcm2835_dmac.c: revision 1.9
sys/arch/arm/broadcom/files.bcm2835: revision 1.23
sys/dev/sdmmc/sdhc.c: revision 1.45
sys/dev/sdmmc/sdhc.c: revision 1.46
sys/dev/sdmmc/sdhc.c: revision 1.47
sys/dev/sdmmc/sdhcvar.h: revision 1.14
Various RPI DMAC and sdhc improvements.
 1.44.2.2 02-Oct-2014  martin Pull up following revision(s) (requested by jmcneill in ticket #124):
sys/dev/sdmmc/sdhc.c: revision 1.49
Correct clk div calculation for SD 3.0 controllers.
 1.44.2.1 01-Oct-2014  martin Pull up following revision(s) (requested by jmcneill in ticket #123):
sys/dev/sdmmc/sdhc.c: revision 1.48
Don't check slot type for pre-3.0 controllers, the bits were reserved at
the time. If an older controller advertises 1.8V support, just use it.
This fixes high-speed mode support for me on BeagleBone Black.
 1.51.2.9 28-Aug-2017  skrll Sync with HEAD
 1.51.2.8 05-Feb-2017  skrll Sync with HEAD
 1.51.2.7 05-Oct-2016  skrll Sync with HEAD
 1.51.2.6 09-Jul-2016  skrll Sync with HEAD
 1.51.2.5 19-Mar-2016  skrll Sync with HEAD
 1.51.2.4 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.51.2.3 22-Sep-2015  skrll Sync with HEAD
 1.51.2.2 06-Jun-2015  skrll Sync with HEAD
 1.51.2.1 06-Apr-2015  skrll Sync with HEAD
 1.94.2.2 26-Apr-2017  pgoyette Sync with HEAD
 1.94.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.97.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.100.4.3 03-Dec-2021  martin Pull up the following revisions (all via patch), requested by msaitoh
in ticket #1713:

sys/dev/sdmmc/sdhc.c 1.110, 1.112
sys/dev/sdmmc/sdmmc_mem.c 1.74
sys/dev/pci/sdhc_pci.c 1.18

- Support 64bit BAR.
- Use unsigned to avoid undefined behavior in hwrite[12]() and
sdmmc_mem_sd_switch().
- Fix typo in comment.
 1.100.4.2 05-Aug-2020  martin Pull up following revision(s) (requested by msaitoh in ticket #1592):

sys/dev/sdmmc/sdhc.c: revision 1.107
sys/dev/sdmmc/sdhcreg.h: revision 1.21

Identify SDHC 4.1 and 4.2. From {DragonFly,Free}BSD.
 1.100.4.1 07-Jan-2018  snj Pull up following revision(s) (requested by ryo in ticket #468):
sys/dev/sdmmc/sdhcreg.h: revision 1.19
sys/dev/sdmmc/sdhc.c: revision 1.101
fix problem for ESDHC/USDHC due to change of r1.96
on ESDHC/USDHC, even if the iosize is less than SDHC_HOST_CTL_VERSION,
specver must be an appropriate value.
 1.101.6.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.101.6.1 10-Jun-2019  christos Sync with HEAD
 1.103.2.3 03-Dec-2021  martin Pull up the followin revisions (all via patch), requested by msaitoh
in ticket #1383:

sys/dev/sdmmc/sdhc.c 1.110, 1.112
sys/dev/sdmmc/sdmmc_mem.c 1.74
sys/dev/pci/sdhc_pci.c 1.18

- Support 64bit BAR.
- Use unsigned to avoid undefined behavior in hwrite[12]() and
sdmmc_mem_sd_switch().
- Fix typo in comment.
 1.103.2.2 20-Jul-2020  martin Pull up following revision(s) (requested by msaitoh in ticket #1021):

sys/dev/sdmmc/sdhc.c: revision 1.107
sys/dev/sdmmc/sdhcreg.h: revision 1.21

Identify SDHC 4.1 and 4.2. From {DragonFly,Free}BSD.
 1.103.2.1 25-Feb-2020  martin Pull up following revision(s) (requested by mrg in ticket #717):

sys/dev/fdt/dwcmmc_fdt.c 1.11
sys/dev/ic/bwfm.c 1.15-1.18
sys/dev/ic/bwfmreg.h 1.4-1.6
sys/dev/ic/bwfmvar.h 1.4,1.5
sys/dev/ic/dwc_mmc.c 1.21,1.22
sys/dev/ic/dwc_mmc_reg.h 1.8,1.9,1.12,1.13
sys/dev/pcmcia/pcmciareg.h 1.11
sys/dev/sdmmc/if_bwfm_sdio.c 1.4,1.6-1.12
sys/dev/sdmmc/if_bwfm_sdio.h 1.1,1.2
sys/dev/sdmmc/sdhc.c 1.105,1.106
sys/dev/sdmmc/sdmmc.c 1.37,1.39
sys/dev/sdmmc/sdmmc_cis.c 1.6,1.8
sys/dev/sdmmc/sdmmc_io.c 1.15-1.19
sys/dev/sdmmc/sdmmc_ioreg.h 1.4,1.5
sys/dev/sdmmc/sdmmc_mem.c 1.69-1.71
sys/dev/sdmmc/sdmmcdevs 1.5-1.8
sys/dev/sdmmc/sdmmcvar.h 1.31,1.33,1.34
sys/net/if_media.h 1.66

Add Broadcom devices
-
Fix typo
-
add PCMCIA_CISTPL_SDIO definition.
-
From OpenBSD:
- move event handling to workqueue
- check for save/restore capability
-
Tag work queue as MPsafe and increase length.
-
Juse use bpf_mtap(), the 802.11 encapsulation is handled by firmware.
-
From OpenBSD:
- support block length per function
- add functions to read/write regions
-
Decode (but not use) SDIO tuple in CIS.
-
Fix locking.
-
Add more SDIO defines (partially from version 3.0).
-
From OpenBSD:
- All the missing pieces (firmware load, chip setup, protocol handling)
TX queue and interrupt handling via sdmmc_task.
-
Fix locking.
-
Fix packet parsing.
-
Add parser for original firmware config files.
-
tagging work queue as MPSAFE was premature. Revert.
-
SD_IO_RW_EXTENDED is a data transfer command, so set ADTC flag instead of AC
Use correct function to verify if a task has been queued. Avoids race
that can corrupt the task queue.
-
More register definitions.
-
Add IFM_IEEE80211_VHT subtype, IFM_IEEE80211_11AC operating mode, and missing descriptions
-
If firmware is connected in HT or VHT mode, report it to SIOCGIFMEDIA
-
white space police.

Skip setting power when the voltage doesn't change.
Also increase some timeouts.
-
Add and use sdmmc_pause to avoid long-term busy waits.
-
Add sdio abort function.
-
Additional error messages.
-
Print parameters for SDIO devices.
-
Minor cosmetics.
-
Simplyfy sdmmc_io_set_blocklen function signature by dropping the
extra softc pointer. Aligns with OpenBSD.
-
Missing commit for sdio abort function.
-
More code from OpenBSD
-
no need to splnet() when enqueing packets
-
explicit structure padding
-
make internal functions static
-
also prepare for GPIO interrupts.
-
Avoid warnings for tautological shifts as sole conditional.
-
Follow the Linux driver an use the FDT "compatible" property to build a
filename for the nvram config file, fall back to the standard filename.
E.g.
[Caching 123 nodes and 1093 properties]
compatible 73696e6f 766f6970 2c627069 2d6d322d "sinovoip,bpi-m2-
0010: 7a65726f 00...... ........ ........ zero"
0015: 616c6c77 696e6e65 722c7375 6e38692d "allwinner,sun8i-
0025: 68322d70 6c757300 ........ ........ h2-plus"
interrupt-parent 00000001 ........ ........ ........ ....
model 42616e61 6e612050 69204250 492d4d32 "Banana Pi BPI-M2
0010: 2d5a6572 6f00.... ........ ........ -Zero"
name 00...... ........ ........ ........ ""
serial-number 30326330 30303432 65636431 36376566 02c00042ecd167ef
0010: 00...... ........ ........ ........ .
-rw-r--r-- 1 root wheel 875 Nov 2 12:06 brcmfmac43430-sdio.AP6212.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 16:19 brcmfmac43430-sdio.sinovoip,bpi-m2-zero.txt -> brcmfmac43430-sdio.AP6212.txt
-rw-r--r-- 1 root wheel 874 Jun 30 2019 brcmfmac43430-sdio.raspberrypi,3-model-b.txt
-rw-r--r-- 1 root wheel 1864 Jun 30 2019 brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 11:24 brcmfmac43455-sdio.raspberrypi,4-model-b-plus.txt -> brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
-
Add product ID for Broadcom BCM43455
-
Use correct firmware for BCM43456
-
size check was backwards.
-
Be less noisy for some commands.
-
Fix DWC_MMC_INT_SDIO_INT bit
-
dwc_mmc fixes:
- Rockchip uses a different SDIO int bit, so take this into consideration
- Avoid unnecessary resets and always wait for resets to complete
- kpause instead of delay while holding spinlock
- Do not attempt autostop for SD_IO_RW_EXTENDED commands
- Allow for sub-blklen byte counts for single block transfers
-
More SDIO stability and performance fixes
 1.107.2.1 03-Apr-2021  thorpej Sync with HEAD.
 1.108.2.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.109.4.1 31-May-2021  cjep sync with head
 1.109.2.1 17-Jun-2021  thorpej Sync w/ HEAD.
 1.110.4.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.117.2.2 22-Feb-2025  martin Pull up following revision(s) (requested by jmcneill in ticket #1063):

sys/dev/sdmmc/sdhcvar.h: revision 1.36
sys/dev/sdmmc/sdhc.c: revision 1.120
sys/dev/sdmmc/sdhc.c: revision 1.121

sdhc: Remove now unused sc_write_delay

sdhc: Remove delay in sdhc_wait_state

Replace the 10us delay loop in sdhc_wait_state with a microuptime based
timeout test.
 1.117.2.1 03-Feb-2024  martin Pull up following revision(s) (requested by jmcneill in ticket #561):

etc/etc.evbppc/Makefile.inc: revision 1.15
sys/arch/evbppc/wii/dev/wiifb.c: revision 1.1
sys/arch/evbppc/wii/dev/wiifb.c: revision 1.2
sys/arch/evbppc/wii/dev/bwdsp.c: revision 1.1
sys/arch/evbppc/wii/dev/wiifb.c: revision 1.3
sys/arch/evbppc/wii/dev/bwdsp.c: revision 1.2
distrib/utils/embedded/files/evbppc_wii_icon.png: revision 1.1
usr.sbin/sysinst/arch/evbppc/md.h: revision 1.4
sys/arch/evbppc/wii/dev/wiifb.c: revision 1.4
sys/arch/evbppc/wii/dev/viio.h: revision 1.1
sys/arch/evbppc/wii/dev/wiifb.c: revision 1.5
sys/arch/evbppc/wii/dev/mainbus.h: revision 1.1
distrib/utils/embedded/conf/wii.conf: revision 1.1
distrib/utils/embedded/conf/wii.conf: revision 1.2
distrib/utils/embedded/conf/wii.conf: revision 1.3
sys/dev/sdmmc/sdhcvar.h: revision 1.34
sys/dev/sdmmc/sdhc.c: revision 1.118
sys/arch/evbppc/wii/dev/resetbtn.c: revision 1.1
distrib/utils/embedded/conf/evbppc.conf: revision 1.1
sys/dev/wsfb/genfb.c: revision 1.91
sys/arch/evbppc/wii/dev/resetbtn.c: revision 1.2
sys/dev/wscons/wsconsio.h: revision 1.127
sys/arch/powerpc/oea/oea_machdep.c: revision 1.85
sys/arch/evbppc/wii/dev/hollywood.h: revision 1.1
sys/arch/evbppc/conf/std.wii: revision 1.1
sys/arch/evbppc/wii/dev/hollywood.h: revision 1.2
sys/arch/evbppc/wii/dev/hollywood.c: revision 1.1
sys/arch/evbppc/conf/std.wii: revision 1.2
sys/arch/evbppc/wii/dev/hollywood.c: revision 1.2
sys/arch/evbppc/conf/std.wii: revision 1.3
sys/arch/powerpc/oea/cpu_subr.c: revision 1.109
sys/arch/evbppc/wii/wii_mmuinit.S: revision 1.1
sys/dev/usb/usb.h: revision 1.124
sys/arch/evbppc/wii/machdep.c: revision 1.1
sys/arch/evbppc/wii/dev/rtcsram.c: revision 1.1
sys/arch/powerpc/include/oea/hid.h: revision 1.14
sys/arch/evbppc/wii/mainbus.c: revision 1.1
sys/arch/evbppc/wii/machdep.c: revision 1.2
sys/arch/evbppc/wii/dev/ehci_hollywood.c: revision 1.1
sys/arch/evbppc/wii/mainbus.c: revision 1.2
sys/arch/evbppc/wii/machdep.c: revision 1.3
sys/arch/evbppc/wii/dev/ehci_hollywood.c: revision 1.2
sys/arch/evbppc/wii/mainbus.c: revision 1.3
sys/arch/evbppc/wii/machdep.c: revision 1.4
sys/arch/evbppc/wii/dev/hwgpio.c: revision 1.1
sys/arch/evbppc/wii/dev/sdhc_hollywood.c: revision 1.1
sys/arch/evbppc/wii/dev/sdhc_hollywood.c: revision 1.2
sys/arch/evbppc/wii/wii_locore.S: revision 1.1
sys/arch/evbppc/conf/files.wii: revision 1.1
sys/arch/evbppc/wii/wii_locore.S: revision 1.2
sys/arch/evbppc/include/wii.h: revision 1.1
sys/arch/evbppc/conf/files.wii: revision 1.2
sys/arch/evbppc/wii/dev/exi.c: revision 1.1
sys/arch/evbppc/include/wii.h: revision 1.2
sys/arch/evbppc/conf/files.wii: revision 1.3
sys/arch/powerpc/powerpc/clock.c: revision 1.18
sys/arch/evbppc/include/wii.h: revision 1.3
sys/arch/evbppc/conf/files.wii: revision 1.4
sys/arch/evbppc/include/wii.h: revision 1.4
sys/arch/evbppc/wii/dev/exi.h: revision 1.1
sys/arch/evbppc/wii/dev/avenc.c: revision 1.1
sys/arch/evbppc/include/wii.h: revision 1.5
sys/arch/evbppc/include/wii.h: revision 1.6
sys/arch/evbppc/include/wii.h: revision 1.7
sys/arch/evbppc/wii/dev/avenc.h: revision 1.1
distrib/utils/embedded/mkimage: revision 1.79
sys/arch/evbppc/conf/WII: revision 1.1
sys/arch/evbppc/conf/INSTALL_WII: revision 1.1
distrib/utils/embedded/files/evbppc_wii_meta.xml: revision 1.1
sys/arch/evbppc/wii/dev/vireg.h: revision 1.1
sys/arch/evbppc/conf/WII: revision 1.2
distrib/utils/embedded/files/evbppc_wii_meta.xml: revision 1.2
sys/arch/evbppc/wii/dev/vireg.h: revision 1.2
sys/arch/evbppc/conf/WII: revision 1.3
sys/arch/evbppc/conf/WII: revision 1.4
usr.sbin/sysinst/arch/evbppc/md.c: revision 1.11
sys/arch/evbppc/wii/dev/ohci_hollywood.c: revision 1.1
sys/dev/usb/ehcivar.h: revision 1.52
sys/arch/evbppc/wii/pic_pi.c: revision 1.1
sys/arch/evbppc/wii/dev/ohci_hollywood.c: revision 1.2
etc/etc.evbppc/ttys: revision 1.8
sys/arch/evbppc/wii/dev/bwai.c: revision 1.1
sys/arch/evbppc/wii/dev/bwai.c: revision 1.2
sys/arch/evbppc/wii/dev/bwai.c: revision 1.3
sys/arch/evbppc/wii/autoconf.c: revision 1.1
sys/arch/evbppc/conf/Makefile.wii.inc: revision 1.1
sys/arch/evbppc/wii/dev/bwai.h: revision 1.1
sys/arch/evbppc/wii/autoconf.c: revision 1.2
sys/arch/evbppc/conf/Makefile.wii.inc: revision 1.2

powerpc: oea: Fix prefetchable mappings
Prefetchable mappings need PMAP_NOCACHE to get write-combine semantics.
powerpc: oea: Decode IBM750CL L2 cache information.
sdmmc: add support for optional delay after register write
wscons: Add HOLLYWOOD display and YUY2 pixel format types
wsfb: add support for optional "devcmap" property
A hardware driver can supply a pointer to a 16x 32-bit array to override
the default rasops device colour map in the "devcmap" property.
ehci: add EHCIF_32BIT_ACCESS flag to force 32-bit MMIO
fix comments: HID0 ICFI/DCFI are "flash invalidate", not "flush invalidate"
powerpc: fix delay for large (> ~5sec) values
When calculating the target timebase, promote '1000' on the RHS to ULL
to force 64-bit calculation, otherwise 'n * 1000' will overflow.
usb: increase USB_PORT_RESET_RECOVERY from 10ms to 20ms
I changed this from 250ms to 10ms back in 2021 based on a similar FreeBSD
change, but it seems to be a bit too aggressive for some platforms.
evbppc: Add initial support for the Nintendo Wii
wii: support RB_POWERDOWN
build fix: use dd with count=1 for compat with NetBSD dd(1)
wii: Add NTSC 480p support.
In addition to this, add VIIO_{GET,SET}REGS ioctl support to allow for
poking at video interface registers from userland. This is helpful for
debugging display issues.
wii: Add 128x48 icon to SD card image
wii: Fix a comment
wii: Add drivers for Broadway DSP and Audio interface.
0: [*] audio0 @ bwdsp0: Broadway DSP
playback: 16, 2ch, 48000Hz
record: unavailable
(P-) slinear_be 16/16, 2ch, { 48000 }
wii: Add screenblank support.
wii: Use screen dimming register for screen blanking.
wii: Add GPIO, I2C, and basic A/V encoder driver.
wii: Use A/V encoder volume controls instead of using a software filter.
wii: Simply DSP driver - no interrupt handler required.
wii: provide device names to intr_establish
wii$ intrctl list
interrupt id CPU0 device name(s)
pi irq 14 64769* hollywood0
hollywood irq 36 5872* ehci0
hollywood irq 39 58907* sdhc0
hollywood irq 40 4* sdhc1
hollywood irq 49 0* resetbtn0
pi irq 5 0* bwai0
wii: Add support for passing boot options to the kernel.
wii: Add External interface bus and RTC support
wii: Remove objcopy after kernel build.
HBC will do the right thing.
Add wsvt25 entries (off by default) for ttyE0-ttyE3.
Add support for "PAL" (576i) mode on Wii.
 1.119.2.1 02-Aug-2025  perseant Sync with HEAD
 1.21 15-Jul-2020  msaitoh Identify SDHC 4.1 and 4.2. From {DragonFly,Free}BSD.
 1.20 23-Oct-2019  hkenken Add SDHC flags.

+ SDHC_FLAG_BROKEN_ADMA2_ZEROLEN
Broken ADMA2 Zero length descriptor.
Can't 64K Byte data transfer.
+ SDHC_FLAG_NO_1_8_V
Support no 1.8V Supply.
Disable UHS-I bus speed mode (SDR50, DDR50, SDR104).
 1.19 23-Jun-2017  ryo branches: 1.19.6; 1.19.12;
fix problem for ESDHC/USDHC due to change of r1.96

on ESDHC/USDHC, even if the iosize is less than SDHC_HOST_CTL_VERSION,
specver must be an appropriate value.
 1.18 31-Dec-2015  ryo branches: 1.18.10;
add support iMX6 uSDHC
- some UHS-I/SDR104 card are not stable
- eMMC doesn't work yet
 1.17 05-Aug-2015  jmcneill support re-tuning modes 1 and 2
 1.16 05-Aug-2015  jmcneill Implement SDHC sampling clock tuning procedure.
 1.15 02-Aug-2015  jmcneill add support for UHS-I modes on capable 3.0+ controllers
 1.14 29-Jul-2015  jmcneill Add ADMA2 support, which enables scatter gather DMA for data transfers on
controllers that support it.
 1.13 02-May-2015  jmcneill support SDHC 4.0, allow for overriding clk base frequency
 1.12 26-Jan-2015  nonaka eSDHC has non standard Host Controller Version Register offset.
 1.11 24-Dec-2012  jakllsch branches: 1.11.12; 1.11.14;
Add a few more register bits from SDHCI 3.0.
Also, add comment to denote an ESDHC bit.
 1.10 15-Oct-2012  jakllsch Make whitespace following preprocessor keywords consistent
with the predominating form in this file (that is, a space).
 1.9 31-Aug-2012  matt branches: 1.9.2;
Support deciphering SDHCv3 clock rates.
 1.8 20-Jul-2012  matt Add use of watermark register when PIO to an ESDHC. After every kill or
drain of watermask words, pause a bit to give time for the fifo to recover.
Always the command response in BE byteorder. Rewrite __bitfield to deal
with this.
 1.7 12-Jul-2012  jakllsch Add DMA boundary field shift and mask.
 1.6 02-Mar-2012  nonaka Added Ricoh 5U822/5U823 SD/MMC Controller support.
 1.5 01-Feb-2012  matt branches: 1.5.2;
Add XLP specific CGM mode for SDHC_CLOCK_CTL.
 1.4 01-Feb-2012  matt Add some more FreeScale ESDHC defintions.
 1.3 29-Jun-2011  matt branches: 1.3.2; 1.3.6;
Add some inital changes for the Freescale eSDHC.
 1.2 17-Mar-2011  matt Add stuff that the Freescale PowerQUICC3 ESDHC controllers have.
 1.1 21-Apr-2009  nonaka branches: 1.1.2; 1.1.4; 1.1.6; 1.1.8; 1.1.12; 1.1.14; 1.1.16;
Added SD/MMC support from OpenBSD.
tested on i386, amd64 at current-users ML by pgoyette@.
tested on zaurus by myself.
 1.1.16.1 06-Jun-2011  jruoho Sync with HEAD.
 1.1.14.4 27-Dec-2011  matt Sync/merge with changes from matt-nb5-pq3
 1.1.14.3 24-Dec-2011  matt Add support for >63MHZ speeds.
Add support for extended clock division via CGM.
 1.1.14.2 21-Apr-2010  matt sync to netbsd-5
 1.1.14.1 21-Apr-2009  matt file sdhcreg.h was added on branch matt-nb5-mips64 on 2010-04-21 00:27:52 +0000
 1.1.12.1 21-Apr-2011  rmind sync with head
 1.1.8.2 07-Oct-2009  sborrill branches: 1.1.8.2.4;
Pull up the following revisions(s) (requested by jmcneill in ticket #1044):
distrib/sets/lists/man/mi: patch
share/man/man4/Makefile: patch
sys/arch/amd64/conf/files.amd64: 1.67
sys/arch/i386/conf/files.i386: 1.349
sys/conf/files 1.945
share/man/man4/sdmmc.4: 1.1-1.4
sys/dev/sdmmc/Makefile.sdmmcdevs 1.1
sys/dev/sdmmc/devlist2h.awk 1.1
sys/dev/sdmmc/files.sdmmc 1.1-1.2
sys/dev/sdmmc/ld_sdmmc.c 1.1-1.3
sys/dev/sdmmc/sbt.c 1.1-1.2
sys/dev/sdmmc/sdhc.c 1.1-1.3
sys/dev/sdmmc/sdhcreg.h 1.1
sys/dev/sdmmc/sdhcvar.h 1.1
sys/dev/sdmmc/sdmmc.c 1.1
sys/dev/sdmmc/sdmmc_cis.c 1.1
sys/dev/sdmmc/sdmmc_io.c 1.1
sys/dev/sdmmc/sdmmc_ioreg.h 1.1
sys/dev/sdmmc/sdmmc_mem.c 1.1-1.2
sys/dev/sdmmc/sdmmcchip.h 1.1
sys/dev/sdmmc/sdmmcdevs 1.1
sys/dev/sdmmc/sdmmcdevs.h 1.1-1.2
sys/dev/sdmmc/sdmmcreg.h 1.1-1.3
sys/dev/sdmmc/sdmmcvar.h 1.1

Add sdmmc framework
 1.1.8.1 21-Apr-2009  sborrill file sdhcreg.h was added on branch netbsd-5 on 2009-10-07 15:41:13 +0000
 1.1.8.2.4.1 26-Jul-2011  matt Backport flash/nand/nor subsystem from -HEAD.
 1.1.6.2 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.1.6.1 21-Apr-2009  jym file sdhcreg.h was added on branch jym-xensuspend on 2009-05-13 17:21:29 +0000
 1.1.4.2 04-May-2009  yamt sync with head.
 1.1.4.1 21-Apr-2009  yamt file sdhcreg.h was added on branch yamt-nfs-mp on 2009-05-04 08:13:18 +0000
 1.1.2.2 28-Apr-2009  skrll Sync with HEAD.
 1.1.2.1 21-Apr-2009  skrll file sdhcreg.h was added on branch nick-hppapmap on 2009-04-28 07:36:33 +0000
 1.3.6.4 06-Mar-2012  mrg sync to -current
 1.3.6.3 06-Mar-2012  mrg sync to -current
 1.3.6.2 04-Mar-2012  mrg sync to latest -current.
 1.3.6.1 18-Feb-2012  mrg merge to -current.
 1.3.2.3 23-Jan-2013  yamt sync with head
 1.3.2.2 30-Oct-2012  yamt sync with head
 1.3.2.1 17-Apr-2012  yamt sync with head
 1.5.2.2 02-Jan-2013  riz sys/dev/sdmmc/sdhc.c patch
sys/dev/sdmmc/sdhcreg.h patch

Support SDHC version 3 clocks.
[skrll, ticket #759]
 1.5.2.1 08-Aug-2012  jdc Pull up revisions:
src/sys/dev/sdmmc/sdhc.c revisions 1.16,1.20,1.21,1.22,1.23 via patch,1.25
src/sys/dev/sdmmc/sdhcreg.h revision 1.8
src/sys/dev/sdmmc/sdmmc_mem.c revisions 1.21,1.22
src/sys/dev/sdmmc/sdmmcreg.h revisions 1.10,1.11,1.12
(requested by matt in ticket 441).

SDHCI byte swaps the BE response on the wire into LE registers.
As we always want response data in LE, use bus_space_read_stream.
Additonally, read response data in 1 or 4 4-byte chunks, instead of
one 4-byte chunk or 15 1-byte chunks.

bus_space_*_stream_N() functions are not universally available.
Provite alternate implementation for when they are unavailable.

Handle interrupt acknowledgement in the SDHC_FLAG_32BIT_ACCESS case in
the same way as non-SDHC_FLAG_32BIT_ACCESS case.

If there was an error in 32-bit mode, just set ERROR_INTERRUPT otherwise
see if matched anything we care about.

Add use of watermark register when PIO to an ESDHC. After every kill or
drain of watermask words, pause a bit to give time for the fifo to recover.
Always the command response in BE byteorder. Rewrite __bitfield to deal
with this.

Responses are actually in host order (except SCR which is return in
big endian so that's convert to host order).

Fix comments about __bitfield.
 1.9.2.3 03-Dec-2017  jdolecek update from HEAD
 1.9.2.2 25-Feb-2013  tls resync with head
 1.9.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.11.14.5 28-Aug-2017  skrll Sync with HEAD
 1.11.14.4 19-Mar-2016  skrll Sync with HEAD
 1.11.14.3 22-Sep-2015  skrll Sync with HEAD
 1.11.14.2 06-Jun-2015  skrll Sync with HEAD
 1.11.14.1 06-Apr-2015  skrll Sync with HEAD
 1.11.12.1 27-Jan-2015  martin Pull up following revision(s) (requested by nonaka in ticket #460):
sys/dev/sdmmc/sdhcreg.h: revision 1.12
sys/dev/sdmmc/sdhc.c: revision 1.52
eSDHC has non standard Host Controller Version Register offset.
 1.18.10.2 05-Aug-2020  martin Pull up following revision(s) (requested by msaitoh in ticket #1592):

sys/dev/sdmmc/sdhc.c: revision 1.107
sys/dev/sdmmc/sdhcreg.h: revision 1.21

Identify SDHC 4.1 and 4.2. From {DragonFly,Free}BSD.
 1.18.10.1 07-Jan-2018  snj Pull up following revision(s) (requested by ryo in ticket #468):
sys/dev/sdmmc/sdhcreg.h: revision 1.19
sys/dev/sdmmc/sdhc.c: revision 1.101
fix problem for ESDHC/USDHC due to change of r1.96
on ESDHC/USDHC, even if the iosize is less than SDHC_HOST_CTL_VERSION,
specver must be an appropriate value.
 1.19.12.1 20-Jul-2020  martin Pull up following revision(s) (requested by msaitoh in ticket #1021):

sys/dev/sdmmc/sdhc.c: revision 1.107
sys/dev/sdmmc/sdhcreg.h: revision 1.21

Identify SDHC 4.1 and 4.2. From {DragonFly,Free}BSD.
 1.19.6.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.36 16-Feb-2025  jmcneill sdhc: Remove now unused sc_write_delay
 1.35 09-May-2024  dyoung branches: 1.35.2;
If the ACPI flag "non-removable" is present and true for an SD/MMC
slot, then set a new flag on that slot to indicate that the media
is non-removable. Make sdhc_card_detect always return true for a
slot if its non-removable media flag is set.

This change lets the kernel automatically configure the
permanently-installed MMC slot on the NXP LX2160-based HoneyComb
LX2 board.
 1.34 20-Jan-2024  jmcneill sdmmc: add support for optional delay after register write
 1.33 14-Oct-2022  jmcneill branches: 1.33.2;
Disable ADMA2 on Ricoh SDHCI controllers.

PR# 57015
 1.32 06-Feb-2022  jmcneill sdhc: Retire SDHC_FLAG_USE_ADMA2 flag.

ADMA2 support in sdhc is mature now, so no need for it to be opt-in.
 1.31 23-Oct-2019  hkenken Add SDHC flags.

+ SDHC_FLAG_BROKEN_ADMA2_ZEROLEN
Broken ADMA2 Zero length descriptor.
Can't 64K Byte data transfer.
+ SDHC_FLAG_NO_1_8_V
Support no 1.8V Supply.
Disable UHS-I bus speed mode (SDR50, DDR50, SDR104).
 1.30 13-Mar-2019  jmcneill Add vendor callback for post-bus clock ops and add SDHC_FLAG_STOP_WITH_TC flag
 1.29 22-Apr-2017  jmcneill branches: 1.29.12;
Add a vendor callback for setting signal voltage.
 1.28 17-Feb-2017  nonaka sdhc(4): hardware reset support for Intel eMMC controller
 1.27 07-Jan-2017  kiyohara branches: 1.27.2;
Add flags SDHC_FLAG_NO_AUTO_STOP and SDHC_FLAG_NO_BUSY_INTR.
 1.26 31-Dec-2015  ryo branches: 1.26.2;
add support iMX6 uSDHC
- some UHS-I/SDR104 card are not stable
- eMMC doesn't work yet
 1.25 02-Nov-2015  jmcneill allow vendor specific code to hook into bus width changes
 1.24 09-Aug-2015  mlelstv Add a quirk for Ricoh 5U823 controller. Operation with a 100MHz
bus clock for SDR50 seems to be unstable, reduce frequency one notch
(effectively down to 66MHz with divisor = 3).
 1.23 03-Aug-2015  jmcneill Add SDHC_FLAG_POLL_CARD_DET flag which lets the bus glue request polling
instead of standard SDHC card insert / detach events.
 1.22 02-Aug-2015  jmcneill let SDHC_FLAG_HOSTCAPS override SDHC_CAPABILITIES2 as well
 1.21 31-Jul-2015  jmcneill Simplify sdhc(4) locking
 1.20 29-Jul-2015  jmcneill Add ADMA2 support, which enables scatter gather DMA for data transfers on
controllers that support it.
 1.19 23-Jul-2015  jmcneill Add a SDHC_FLAG_NO_TIMEOUT quirk to handle spurious timeouts on Tegra K1
during data transfers. While here, increase the soft timeout for DMA
transfers from 1s to 3s.
 1.18 03-May-2015  jmcneill Add SDHC_FLAG_SINGLE_POWER_WRITE flag, that tells the driver to update
the SDHC_POWER_CTL register with a single write rather than in multiple
steps. Required for Tegra K1 SDHC.
 1.17 02-May-2015  jmcneill support SDHC 4.0, allow for overriding clk base frequency
 1.16 14-Apr-2015  bouyer Add a new SDHC_FLAG, SDHC_FLAG_EXTDMA_DMAEN, which request that the
SDHC_DMA_ENABLE bit be set in the command, even if we're using an
external DMA engine. Needed by the upcoming DMA support for AM335x
(beaglebone).
 1.15 04-Oct-2014  jmcneill branches: 1.15.2;
pass sdhc_softc instead of sdhc_host to sc_vendor_transfer_data_dma, since the vendor specific code has no visibility into struct sdhc_host and can easily do device_private(sdhc_softc->sc_dev)
 1.14 12-Sep-2014  jakllsch Allow sdhc(4) to use a non-integrated DMA engine.
 1.13 10-Jan-2013  jmcneill branches: 1.13.12;
add SDHC_FLAG_NO_HS_BIT flag to prevent sdhc driver from setting the SDHC_HIGH_SPEED bit in SDHC_HOST_CTL, required to get many high speed cards working on rpi
 1.12 20-Dec-2012  jakllsch Change sdhc_detach so that it detaches all host controllers at once.
This should make multiple slot controllers, for example those with
a controller on more than one PCI/CardBus BAR, detach with fewer bugs.
Tested with as-of-yet-uncommited sdhc_pci changes on a single-host
ExpressCard JMicron JMB38[89].
 1.11 13-Dec-2012  riastradh Implement TI AM335x's SDHC reset quirk. Beaglebone SDHC works now!

On the AM335x, we first must wait for the controller to acknowledge
the reset; then we can wait for the reset to complete.

I believe this quirk also applies to the OMAP4 ES, but I don't have
one of those to test and we don't seem to have an obvious conditional
for it anyway.

This quirk may work for controllers that don't require it too, but I
am nervous about doing it by default because if we miss the reset
acknowledgement, then we'll just time out even though everything is
really hunky-dory.

Also, for all sdhc, don't bother writing 0 in sdhc_soft_reset while
waiting for the reset to complete; there is no need.

ok matt
 1.10 12-Dec-2012  matt Add sc_vendor_bus_clock hook
From jmcneill.
 1.9 29-Oct-2012  kiyohara Support omap3 SDHC driver. tested on OVERO only.
 1.8 21-Jul-2012  skrll branches: 1.8.2;
Provide a method for attachments to specify capabilites.
 1.7 12-Jul-2012  matt Add a flag for the lack of LED_ON in HOST_CTL (ti omap3 doesn't do that).
 1.6 01-Feb-2012  matt branches: 1.6.2;
Add more FLAGS
 1.5 29-Jun-2011  matt branches: 1.5.2; 1.5.6;
Add some inital changes for the Freescale eSDHC.
 1.4 27-Mar-2010  nonaka branches: 1.4.2;
Added sdhc at cardbus support.
 1.3 24-Feb-2010  dyoung branches: 1.3.2;
A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.
 1.2 08-Jan-2010  dyoung branches: 1.2.2;
Expand PMF_FN_* macros.
 1.1 21-Apr-2009  nonaka branches: 1.1.2; 1.1.4; 1.1.6; 1.1.8;
Added SD/MMC support from OpenBSD.
tested on i386, amd64 at current-users ML by pgoyette@.
tested on zaurus by myself.
 1.1.8.2 07-Oct-2009  sborrill branches: 1.1.8.2.4;
Pull up the following revisions(s) (requested by jmcneill in ticket #1044):
distrib/sets/lists/man/mi: patch
share/man/man4/Makefile: patch
sys/arch/amd64/conf/files.amd64: 1.67
sys/arch/i386/conf/files.i386: 1.349
sys/conf/files 1.945
share/man/man4/sdmmc.4: 1.1-1.4
sys/dev/sdmmc/Makefile.sdmmcdevs 1.1
sys/dev/sdmmc/devlist2h.awk 1.1
sys/dev/sdmmc/files.sdmmc 1.1-1.2
sys/dev/sdmmc/ld_sdmmc.c 1.1-1.3
sys/dev/sdmmc/sbt.c 1.1-1.2
sys/dev/sdmmc/sdhc.c 1.1-1.3
sys/dev/sdmmc/sdhcreg.h 1.1
sys/dev/sdmmc/sdhcvar.h 1.1
sys/dev/sdmmc/sdmmc.c 1.1
sys/dev/sdmmc/sdmmc_cis.c 1.1
sys/dev/sdmmc/sdmmc_io.c 1.1
sys/dev/sdmmc/sdmmc_ioreg.h 1.1
sys/dev/sdmmc/sdmmc_mem.c 1.1-1.2
sys/dev/sdmmc/sdmmcchip.h 1.1
sys/dev/sdmmc/sdmmcdevs 1.1
sys/dev/sdmmc/sdmmcdevs.h 1.1-1.2
sys/dev/sdmmc/sdmmcreg.h 1.1-1.3
sys/dev/sdmmc/sdmmcvar.h 1.1

Add sdmmc framework
 1.1.8.1 21-Apr-2009  sborrill file sdhcvar.h was added on branch netbsd-5 on 2009-10-07 15:41:13 +0000
 1.1.8.2.4.1 26-Jul-2011  matt Backport flash/nand/nor subsystem from -HEAD.
 1.1.6.2 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.1.6.1 21-Apr-2009  jym file sdhcvar.h was added on branch jym-xensuspend on 2009-05-13 17:21:29 +0000
 1.1.4.4 11-Aug-2010  yamt sync with head.
 1.1.4.3 11-Mar-2010  yamt sync with head
 1.1.4.2 04-May-2009  yamt sync with head.
 1.1.4.1 21-Apr-2009  yamt file sdhcvar.h was added on branch yamt-nfs-mp on 2009-05-04 08:13:18 +0000
 1.1.2.2 28-Apr-2009  skrll Sync with HEAD.
 1.1.2.1 21-Apr-2009  skrll file sdhcvar.h was added on branch nick-hppapmap on 2009-04-28 07:36:33 +0000
 1.2.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.3.2.1 30-May-2010  rmind sync with head
 1.4.2.5 15-Feb-2014  matt HAS_CGM -> HAVE_CGM (like current)
Add 32BIT_ACCESS
 1.4.2.4 27-Dec-2011  matt Sync/merge with changes from matt-nb5-pq3
 1.4.2.3 24-Dec-2011  matt Add support for >63MHZ speeds.
Add support for extended clock division via CGM.
 1.4.2.2 21-Apr-2010  matt sync to netbsd-5
 1.4.2.1 27-Mar-2010  matt file sdhcvar.h was added on branch matt-nb5-mips64 on 2010-04-21 00:27:52 +0000
 1.5.6.1 18-Feb-2012  mrg merge to -current.
 1.5.2.4 23-Jan-2013  yamt sync with head
 1.5.2.3 16-Jan-2013  yamt sync with (a bit old) head
 1.5.2.2 30-Oct-2012  yamt sync with head
 1.5.2.1 17-Apr-2012  yamt sync with head
 1.6.2.2 13-Feb-2013  riz Pull up following revision(s) (requested by skrll in ticket #813):

etc/MAKEDEV.tmpl 1.160
etc/etc.evbarm/MAKEDEV.conf 1.9
external/broadcom/rpi-firmware/dist/LICENCE.broadcom 1.1
external/broadcom/rpi-firmware/dist/bootcode.bin 1.1
external/broadcom/rpi-firmware/dist/bootcode.bin 1.2
external/broadcom/rpi-firmware/dist/fixup.dat 1.1
external/broadcom/rpi-firmware/dist/fixup.dat 1.2
external/broadcom/rpi-firmware/dist/fixup_cd.dat 1.1
external/broadcom/rpi-firmware/dist/fixup_cd.dat 1.2
external/broadcom/rpi-firmware/dist/start.elf 1.1
external/broadcom/rpi-firmware/dist/start.elf 1.2
external/broadcom/rpi-firmware/dist/start_cd.elf 1.1
external/broadcom/rpi-firmware/dist/start_cd.elf 1.2
sys/arch/arm/broadcom/bcm2835_bsc.c 1.1 via patch
sys/arch/arm/broadcom/bcm2835_bscreg.h 1.1 via patch
sys/arch/arm/broadcom/bcm2835_dotg.c 1.1 via patch
sys/arch/arm/broadcom/bcm2835_emmc.c 1.7 via patch
sys/arch/arm/broadcom/bcm2835_genfb.c 1.4 via patch
sys/arch/arm/broadcom/bcm2835_gpio_subr.c 1.2 via patch
sys/arch/arm/broadcom/bcm2835_gpio_subr.h 1.1 via patch
sys/arch/arm/broadcom/bcm2835_gpioreg.h 1.1 via patch
sys/arch/arm/broadcom/bcm2835_intr.c 1.3 via patch
sys/arch/arm/broadcom/bcm2835_mbox.c 1.5 via patch
sys/arch/arm/broadcom/bcm2835_mbox.h 1.4 via patch
sys/arch/arm/broadcom/bcm2835_obio.c 1.17 via patch
sys/arch/arm/broadcom/bcm2835_pm.c 1.2 via patch
sys/arch/arm/broadcom/bcm2835_rng.c 1.3 via patch
sys/arch/arm/broadcom/bcm2835_space.c 1.5 via patch
sys/arch/arm/broadcom/bcm2835_spi.c 1.1 via patch
sys/arch/arm/broadcom/bcm2835_spireg.h 1.1 via patch
sys/arch/arm/broadcom/bcm2835_tmr.c 1.3 via patch
sys/arch/arm/broadcom/bcm2835reg.h 1.10 via patch
sys/arch/arm/broadcom/files.bcm2835 1.14 via patch
sys/arch/evbarm/conf/RPI 1.23 via patch
sys/arch/evbarm/conf/files.rpi 1.3 via patch
sys/arch/evbarm/conf/mk.rpi 1.2 via patch
sys/arch/evbarm/conf/std.rpi 1.4 via patch
sys/arch/evbarm/rpi/rpi_machdep.c 1.34 via patch
sys/arch/evbarm/rpi/rpi_start.S 1.7 via patch
sys/arch/evbarm/rpi/rpi_vcmbox.c 1.2 via patch
sys/arch/evbarm/rpi/vcio.h 1.1 via patch
sys/arch/evbarm/rpi/vcprop.h 1.7 via patch
sys/conf/files patch
sys/dev/sdmmc/sdhc.c 1.43
sys/dev/sdmmc/sdhcvar.h 1.13
sys/dev/usb/dwc_otg.c 1.45 via patch
sys/dev/usb/dwc_otgreg.h 1.5 via patch
sys/dev/usb/dwc_otgvar.h 1.11 via patch
sys/dev/usb/files.usb 1.126 via patch
sys/dev/usb/if_smsc.c 1.7 via patch
sys/dev/usb/if_smscreg.h 1.1 via patch
sys/dev/usb/if_smscvar.h 1.1 via patch
sys/dev/usb/usbdevices.config patch
sys/dev/usb/usbdevs 1.633 via patch
sys/dev/usb/usbdevs.h regen
sys/dev/usb/usbdevs_data.h regen
sys/dev/wscons/wsconsio.h 1.105,1.107 via patch
sys/dev/wscons/wsdisplayvar.h 1.50
sys/dev/wscons/wsdisplay_util.c 1.2
sys/dev/videomode/edid.c 1.12 via patch

Greatly improved Raspberry Pi support. USB and onboard
Ethernet should work.
[skrll, ticket #813]
 1.6.2.1 09-Aug-2012  jdc Pull up revisions:
src/sys/arch/evbarm/dev/plcomreg.h revisions 1.2,1.3,1.4
src/sys/arch/evbarm/conf/INTEGRATOR revision 1.65
src/sys/arch/evbarm/dev/plcom.c revisions 1.34,1.35,1.36,1.37,1.38,1.39,1.40
src/sys/arch/evbarm/ifpga/plcom_ifpga.c revisions 1.12,1.13,1.14
src/sys/arch/evbarm/dev/plcomvar.h revisions 1.9,1.10,1.11
src/sys/arch/evbarm/ifpga/plcom_ifpgavar.h revision 1.2
src/sys/arch/arm/arm/cpufunc.c revisions 1.105,1.108
src/sys/arch/arm/arm32/cpu.c revision 1.79
src/sys/arch/arm/include/armreg.h revisions 1.49,1.54
src/sys/arch/arm/arm32/pmap.c revision 1.229
src/sys/arch/arm/arm32/arm32_machdep.c revision 1.77
src/sys/arch/arm/include/cpu.h revision 1.64
src/sys/arch/arm/arm/cpufunc_asm_arm1136.S revision 1.3
src/sys/arch/arm/arm/cpufunc_asm_arm11x6.S revision 1.1
src/sys/arch/arm/conf/files.arm revision 1.106
src/sys/arch/arm/include/cpufunc.h revision 1.57
src/sys/dev/sdmmc/sdhc.c revisions 1.14,1.24
src/sys/dev/sdmmc/sdhcvar.h revisions 1.7,1.8
src/sys/arch/evbarm/ifpga/ifpgareg.h revision 1.4
src/sys/arch/evbarm/integrator/integrator_machdep.c revision 1.69
src/sys/arch/arm/broadcom/bcm2835_dma.c revision 1.1
src/sys/arch/arm/broadcom/bcm2835_emmc.c revision 1.1
src/sys/arch/arm/broadcom/bcm2835_intr.c revision 1.1
src/sys/arch/arm/broadcom/bcm2835_intr.h revision 1.1
src/sys/arch/arm/broadcom/bcm2835_obio.c revision 1.1
src/sys/arch/arm/broadcom/bcm2835_plcom.c revision 1.1
src/sys/arch/arm/broadcom/bcm2835_pm.c revision 1.1
src/sys/arch/arm/broadcom/bcm2835_pmvar.h revision 1.1
src/sys/arch/arm/broadcom/bcm2835_space.c revision 1.1
src/sys/arch/arm/broadcom/bcm2835_tmr.c revision 1.1
src/sys/arch/arm/broadcom/bcm2835reg.h revision 1.1
src/sys/arch/arm/broadcom/bcm2835var.h revision 1.1
src/sys/arch/arm/broadcom/bcm_amba.h revision 1.1
src/sys/arch/arm/broadcom/files.bcm2835 revision 1.1
src/sys/arch/evbarm/Makefile revision 1.9
src/sys/arch/evbarm/conf/RPI revision 1.1
src/sys/arch/evbarm/conf/files.rpi revision 1.1
src/sys/arch/evbarm/conf/mk.rpi revision 1.1
src/sys/arch/evbarm/conf/std.rpi revision 1.1
src/sys/arch/evbarm/rpi/genassym.cf revision 1.1
src/sys/arch/evbarm/rpi/rpi.h revision 1.1
src/sys/arch/evbarm/rpi/rpi_machdep.c revision 1.1
src/sys/arch/evbarm/rpi/rpi_start.S revision 1.1,1.2
src/etc/etc.evbarm/Makefile.inc revision 1.28
(requested by skrll in ticket #454).

don't mix #define<TAB> and #define<SPACE> in a file.

avoid warning with options PLCOM_DEBUG for INTEGRATOR.

Rename register values. No functional change - same code before and after.

Existing names are prefixed with PL01X_ where they're common between the
PL010 and the PL011. The PL010_/PL011_ prefixes are added where they're
found only on the respective chips.

Replace the simple_lock with a kmutex_t. Update the locking to match
com(4) in the few places it didn't already.

DOH. Replace a line that got accidently deleted in the last commit.

device_t/softc split
struct device * -> device_t
struct cfdata * -> cfdata_t

Add the 'Z' to the 1176 cpu product name.

ok matt@

Fix locking botch introduced in 1.36.

Fix a KASSERT. From/OK'ed by matt@

Fix racy softint dispatch that lead to KASSERT(si->si_active) in
softint_execute

Discussed with matt@. "Looks good to me"

Add the documented ARM11[37]6 Auxiliary control register defines.

Add support for the ARM1176JZS

Add a flag for the lack of LED_ON in HOST_CTL (ti omap3 doesn't do that).

Provide a method for attachments to specify capabilites.

Add support for the PL011 to plcom. Pull across a bunch of fixes from
com(4) while I'm here and do some other tidyup.

Tested on a RaspberryPi.

PL010 not tested.

Initial commit of support for the RaspberryPI (www.raspberrypi.org)

This is enough for serial console via the gpio header pins and to get to
multiuser.

A huge thank you to Matt Thomas for all his help.

Add RPI to KERNEL_SETS

Remove #if 0 code.
 1.8.2.3 03-Dec-2017  jdolecek update from HEAD
 1.8.2.2 25-Feb-2013  tls resync with head
 1.8.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.13.12.4 08-Nov-2015  riz Pull up following revision(s) (requested by jmcneill in ticket #1022):
sys/dev/sdmmc/sdhc.c: revision 1.89
sys/arch/arm/omap/omap3_sdhc.c: revision 1.19
sys/dev/sdmmc/sdhcvar.h: revision 1.25
sys/arch/evbarm/beagle/beagle_machdep.c: revision 1.62
allow vendor specific code to hook into bus width changes
Support 8-bit eMMC for TI AM335x. On my BeagleBone Black,
Before: 134217728 bytes transferred in 9.410 secs (14263307 bytes/sec)
After: 134217728 bytes transferred in 7.518 secs (17852850 bytes/sec)
enable 8-bit mode on AM335X SDMMC2
 1.13.12.3 19-Apr-2015  msaitoh Pull up following revision(s) (requested by bouyer in ticket #703):
sys/dev/sdmmc/sdhcvar.h: revision 1.16
sys/dev/sdmmc/sdhc.c: revision 1.55
Add a new SDHC_FLAG, SDHC_FLAG_EXTDMA_DMAEN, which request that the
SDHC_DMA_ENABLE bit be set in the command, even if we're using an
external DMA engine. Needed by the upcoming DMA support for AM335x
(beaglebone).
 1.13.12.2 05-Oct-2014  martin Pull up following revision(s) (requested by skrll in ticket #129):
sys/dev/sdmmc/sdhcvar.h: revision 1.15
sys/dev/sdmmc/sdhc.c: revision 1.51
sys/arch/arm/broadcom/bcm2835_emmc.c: revision 1.19
Pass sdhc_softc instead of sdhc_host to sc_vendor_transfer_data_dma,
since the vendor specific code has no access to it otherwise,
but can easily do device_private(sdhc_softc->sc_dev).
 1.13.12.1 03-Oct-2014  martin Pull up following revision(s) (requested by skrll in ticket #126):
sys/arch/evbarm/rpi/rpi_machdep.c: revision 1.47
sys/arch/arm/broadcom/bcm2835reg.h: revision 1.12
sys/arch/evbarm/conf/RPI: revision 1.52
sys/arch/evbarm/conf/RPI: revision 1.53
sys/arch/evbarm/conf/RPI: revision 1.54
sys/arch/arm/broadcom/bcm2835_emmc.c: revision 1.10
sys/arch/arm/broadcom/bcm2835_emmc.c: revision 1.11
sys/arch/arm/broadcom/bcm2835_emmc.c: revision 1.12
sys/arch/arm/broadcom/bcm2835_emmc.c: revision 1.13
sys/arch/arm/broadcom/bcm2835_emmc.c: revision 1.14
sys/arch/arm/broadcom/bcm2835_emmc.c: revision 1.15
sys/arch/arm/broadcom/bcm2835_dmac.c: revision 1.3
sys/arch/arm/broadcom/bcm2835_dmac.c: revision 1.4
sys/arch/arm/broadcom/bcm2835_dmac.h: revision 1.2
sys/arch/arm/broadcom/bcm2835_dmac.c: revision 1.5
sys/arch/arm/broadcom/bcm2835_emmc.c: revision 1.18
sys/arch/arm/broadcom/bcm2835_dmac.h: revision 1.3
sys/arch/arm/broadcom/bcm2835_dmac.c: revision 1.6
sys/arch/arm/broadcom/bcm2835_dmac.c: revision 1.7
sys/arch/arm/broadcom/bcm2835_dmac.c: revision 1.8
sys/arch/arm/broadcom/bcm2835_dmac.c: revision 1.9
sys/arch/arm/broadcom/files.bcm2835: revision 1.23
sys/dev/sdmmc/sdhc.c: revision 1.45
sys/dev/sdmmc/sdhc.c: revision 1.46
sys/dev/sdmmc/sdhc.c: revision 1.47
sys/dev/sdmmc/sdhcvar.h: revision 1.14
Various RPI DMAC and sdhc improvements.
 1.15.2.6 28-Aug-2017  skrll Sync with HEAD
 1.15.2.5 05-Feb-2017  skrll Sync with HEAD
 1.15.2.4 19-Mar-2016  skrll Sync with HEAD
 1.15.2.3 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.15.2.2 22-Sep-2015  skrll Sync with HEAD
 1.15.2.1 06-Jun-2015  skrll Sync with HEAD
 1.26.2.2 26-Apr-2017  pgoyette Sync with HEAD
 1.26.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.27.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.29.12.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.29.12.1 10-Jun-2019  christos Sync with HEAD
 1.33.2.2 22-Feb-2025  martin Pull up following revision(s) (requested by jmcneill in ticket #1063):

sys/dev/sdmmc/sdhcvar.h: revision 1.36
sys/dev/sdmmc/sdhc.c: revision 1.120
sys/dev/sdmmc/sdhc.c: revision 1.121

sdhc: Remove now unused sc_write_delay

sdhc: Remove delay in sdhc_wait_state

Replace the 10us delay loop in sdhc_wait_state with a microuptime based
timeout test.
 1.33.2.1 03-Feb-2024  martin Pull up following revision(s) (requested by jmcneill in ticket #561):

etc/etc.evbppc/Makefile.inc: revision 1.15
sys/arch/evbppc/wii/dev/wiifb.c: revision 1.1
sys/arch/evbppc/wii/dev/wiifb.c: revision 1.2
sys/arch/evbppc/wii/dev/bwdsp.c: revision 1.1
sys/arch/evbppc/wii/dev/wiifb.c: revision 1.3
sys/arch/evbppc/wii/dev/bwdsp.c: revision 1.2
distrib/utils/embedded/files/evbppc_wii_icon.png: revision 1.1
usr.sbin/sysinst/arch/evbppc/md.h: revision 1.4
sys/arch/evbppc/wii/dev/wiifb.c: revision 1.4
sys/arch/evbppc/wii/dev/viio.h: revision 1.1
sys/arch/evbppc/wii/dev/wiifb.c: revision 1.5
sys/arch/evbppc/wii/dev/mainbus.h: revision 1.1
distrib/utils/embedded/conf/wii.conf: revision 1.1
distrib/utils/embedded/conf/wii.conf: revision 1.2
distrib/utils/embedded/conf/wii.conf: revision 1.3
sys/dev/sdmmc/sdhcvar.h: revision 1.34
sys/dev/sdmmc/sdhc.c: revision 1.118
sys/arch/evbppc/wii/dev/resetbtn.c: revision 1.1
distrib/utils/embedded/conf/evbppc.conf: revision 1.1
sys/dev/wsfb/genfb.c: revision 1.91
sys/arch/evbppc/wii/dev/resetbtn.c: revision 1.2
sys/dev/wscons/wsconsio.h: revision 1.127
sys/arch/powerpc/oea/oea_machdep.c: revision 1.85
sys/arch/evbppc/wii/dev/hollywood.h: revision 1.1
sys/arch/evbppc/conf/std.wii: revision 1.1
sys/arch/evbppc/wii/dev/hollywood.h: revision 1.2
sys/arch/evbppc/wii/dev/hollywood.c: revision 1.1
sys/arch/evbppc/conf/std.wii: revision 1.2
sys/arch/evbppc/wii/dev/hollywood.c: revision 1.2
sys/arch/evbppc/conf/std.wii: revision 1.3
sys/arch/powerpc/oea/cpu_subr.c: revision 1.109
sys/arch/evbppc/wii/wii_mmuinit.S: revision 1.1
sys/dev/usb/usb.h: revision 1.124
sys/arch/evbppc/wii/machdep.c: revision 1.1
sys/arch/evbppc/wii/dev/rtcsram.c: revision 1.1
sys/arch/powerpc/include/oea/hid.h: revision 1.14
sys/arch/evbppc/wii/mainbus.c: revision 1.1
sys/arch/evbppc/wii/machdep.c: revision 1.2
sys/arch/evbppc/wii/dev/ehci_hollywood.c: revision 1.1
sys/arch/evbppc/wii/mainbus.c: revision 1.2
sys/arch/evbppc/wii/machdep.c: revision 1.3
sys/arch/evbppc/wii/dev/ehci_hollywood.c: revision 1.2
sys/arch/evbppc/wii/mainbus.c: revision 1.3
sys/arch/evbppc/wii/machdep.c: revision 1.4
sys/arch/evbppc/wii/dev/hwgpio.c: revision 1.1
sys/arch/evbppc/wii/dev/sdhc_hollywood.c: revision 1.1
sys/arch/evbppc/wii/dev/sdhc_hollywood.c: revision 1.2
sys/arch/evbppc/wii/wii_locore.S: revision 1.1
sys/arch/evbppc/conf/files.wii: revision 1.1
sys/arch/evbppc/wii/wii_locore.S: revision 1.2
sys/arch/evbppc/include/wii.h: revision 1.1
sys/arch/evbppc/conf/files.wii: revision 1.2
sys/arch/evbppc/wii/dev/exi.c: revision 1.1
sys/arch/evbppc/include/wii.h: revision 1.2
sys/arch/evbppc/conf/files.wii: revision 1.3
sys/arch/powerpc/powerpc/clock.c: revision 1.18
sys/arch/evbppc/include/wii.h: revision 1.3
sys/arch/evbppc/conf/files.wii: revision 1.4
sys/arch/evbppc/include/wii.h: revision 1.4
sys/arch/evbppc/wii/dev/exi.h: revision 1.1
sys/arch/evbppc/wii/dev/avenc.c: revision 1.1
sys/arch/evbppc/include/wii.h: revision 1.5
sys/arch/evbppc/include/wii.h: revision 1.6
sys/arch/evbppc/include/wii.h: revision 1.7
sys/arch/evbppc/wii/dev/avenc.h: revision 1.1
distrib/utils/embedded/mkimage: revision 1.79
sys/arch/evbppc/conf/WII: revision 1.1
sys/arch/evbppc/conf/INSTALL_WII: revision 1.1
distrib/utils/embedded/files/evbppc_wii_meta.xml: revision 1.1
sys/arch/evbppc/wii/dev/vireg.h: revision 1.1
sys/arch/evbppc/conf/WII: revision 1.2
distrib/utils/embedded/files/evbppc_wii_meta.xml: revision 1.2
sys/arch/evbppc/wii/dev/vireg.h: revision 1.2
sys/arch/evbppc/conf/WII: revision 1.3
sys/arch/evbppc/conf/WII: revision 1.4
usr.sbin/sysinst/arch/evbppc/md.c: revision 1.11
sys/arch/evbppc/wii/dev/ohci_hollywood.c: revision 1.1
sys/dev/usb/ehcivar.h: revision 1.52
sys/arch/evbppc/wii/pic_pi.c: revision 1.1
sys/arch/evbppc/wii/dev/ohci_hollywood.c: revision 1.2
etc/etc.evbppc/ttys: revision 1.8
sys/arch/evbppc/wii/dev/bwai.c: revision 1.1
sys/arch/evbppc/wii/dev/bwai.c: revision 1.2
sys/arch/evbppc/wii/dev/bwai.c: revision 1.3
sys/arch/evbppc/wii/autoconf.c: revision 1.1
sys/arch/evbppc/conf/Makefile.wii.inc: revision 1.1
sys/arch/evbppc/wii/dev/bwai.h: revision 1.1
sys/arch/evbppc/wii/autoconf.c: revision 1.2
sys/arch/evbppc/conf/Makefile.wii.inc: revision 1.2

powerpc: oea: Fix prefetchable mappings
Prefetchable mappings need PMAP_NOCACHE to get write-combine semantics.
powerpc: oea: Decode IBM750CL L2 cache information.
sdmmc: add support for optional delay after register write
wscons: Add HOLLYWOOD display and YUY2 pixel format types
wsfb: add support for optional "devcmap" property
A hardware driver can supply a pointer to a 16x 32-bit array to override
the default rasops device colour map in the "devcmap" property.
ehci: add EHCIF_32BIT_ACCESS flag to force 32-bit MMIO
fix comments: HID0 ICFI/DCFI are "flash invalidate", not "flush invalidate"
powerpc: fix delay for large (> ~5sec) values
When calculating the target timebase, promote '1000' on the RHS to ULL
to force 64-bit calculation, otherwise 'n * 1000' will overflow.
usb: increase USB_PORT_RESET_RECOVERY from 10ms to 20ms
I changed this from 250ms to 10ms back in 2021 based on a similar FreeBSD
change, but it seems to be a bit too aggressive for some platforms.
evbppc: Add initial support for the Nintendo Wii
wii: support RB_POWERDOWN
build fix: use dd with count=1 for compat with NetBSD dd(1)
wii: Add NTSC 480p support.
In addition to this, add VIIO_{GET,SET}REGS ioctl support to allow for
poking at video interface registers from userland. This is helpful for
debugging display issues.
wii: Add 128x48 icon to SD card image
wii: Fix a comment
wii: Add drivers for Broadway DSP and Audio interface.
0: [*] audio0 @ bwdsp0: Broadway DSP
playback: 16, 2ch, 48000Hz
record: unavailable
(P-) slinear_be 16/16, 2ch, { 48000 }
wii: Add screenblank support.
wii: Use screen dimming register for screen blanking.
wii: Add GPIO, I2C, and basic A/V encoder driver.
wii: Use A/V encoder volume controls instead of using a software filter.
wii: Simply DSP driver - no interrupt handler required.
wii: provide device names to intr_establish
wii$ intrctl list
interrupt id CPU0 device name(s)
pi irq 14 64769* hollywood0
hollywood irq 36 5872* ehci0
hollywood irq 39 58907* sdhc0
hollywood irq 40 4* sdhc1
hollywood irq 49 0* resetbtn0
pi irq 5 0* bwai0
wii: Add support for passing boot options to the kernel.
wii: Add External interface bus and RTC support
wii: Remove objcopy after kernel build.
HBC will do the right thing.
Add wsvt25 entries (off by default) for ttyE0-ttyE3.
Add support for "PAL" (576i) mode on Wii.
 1.35.2.1 02-Aug-2025  perseant Sync with HEAD
 1.44 24-Jun-2025  gutteridge sdmmc.c: add missing newlines to several device_printf(9) calls
 1.43 07-Aug-2021  thorpej branches: 1.43.12;
Merge thorpej-cfargs2.
 1.42 13-Jun-2021  mlelstv branches: 1.42.2;
Don't crash on detach where interlock == NULL.
 1.41 24-Apr-2021  thorpej branches: 1.41.2;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.40 24-May-2020  riastradh branches: 1.40.4;
Fix races in sdmmc tasks and teach ld@sdmmc to abort xfers on detach.

- Teach sdmmc_add_task to queue it only if not already queued.
- Remove now-redundant logic to avoid repeated queueing elsewhere.
- Teach sdmmc_del_task to wait until task has completed.
- Call sdmmc_del_task in various needful places.
- Replace abuse of pcq by a lock and a tailq.
(pcq is multi-producer, _single_-consumer, but there are potentially
multiple consumers here and really only one producer.)
- Teach ld_sdmmc to abort xfers on detach.
(Mechanism is kinda kludgey but it'll do for now; any effort one is
tempted to spend overhauling this should be spent overhauling sdmmc
to support proper asynchronous commands.)
- Make sure ld_sdmmc_discard either returns failure or eventually calls
ldenddiscard.

XXX Currently ld_sdmmc_detach aborts xfers _before_ ldbegindetach has
has committed to detaching or not. This is currently necessary to
avoid a deadlock because ldbegindetach waits for xfers to drain --
which strikes me as wrong; ldbegindetach shouldn't wait for anything,
and should only make the decision to commit to detaching or not so
the caller can decide whether to abort xfers before we actually wait
for them in ldenddetach.

XXX pullup -- although this changes some kernel symbols (sdmmc_add_task
and sdmmc_del_task), it shouldn't affect any existing modules; the only
module that uses sdmmc is ld_sdmmc.kmod, which is `.if 0' in the build
so there shouldn't be any of them floating around.
 1.39 28-Oct-2019  mlelstv Add and use sdmmc_pause to avoid long-term busy waits.
Add sdio abort function.
Additional error messages.
Print parameters for SDIO devices.
Minor cosmetics.
 1.38 23-Oct-2019  hkenken Add SDHC flags.

+ SDHC_FLAG_BROKEN_ADMA2_ZEROLEN
Broken ADMA2 Zero length descriptor.
Can't 64K Byte data transfer.
+ SDHC_FLAG_NO_1_8_V
Support no 1.8V Supply.
Disable UHS-I bus speed mode (SDR50, DDR50, SDR104).
 1.37 01-Sep-2019  mlelstv From OpenBSD:
- support block length per function
- add functions to read/write regions
Decode (but not use) SDIO tuple in CIS.
Fix locking.
Add more SDIO defines (partially from version 3.0).
 1.36 06-Nov-2018  jmcneill branches: 1.36.4;
Increase kthread priority to PRI_SOFTBIO.
 1.35 06-Mar-2018  mlelstv branches: 1.35.2;
correct whitespace in attach message
 1.34 17-Feb-2017  nonaka branches: 1.34.12;
sdhc(4): hardware reset support for Intel eMMC controller
 1.33 22-Dec-2015  mlelstv branches: 1.33.2; 1.33.4;
ignore timeouts for APP_CMD prefix as for the application command itself.
 1.32 29-Nov-2015  jmcneill Add some event counters to track transfer sizes.
 1.31 09-Aug-2015  mlelstv Send an explicit CMD12 (stop transmission) when there was an error
in multi-sector I/O.

The SDHC spec has a complex flowchart describing when an explicit
CMD12 is necessary, so we probably use it too often.
 1.30 09-Aug-2015  mlelstv protect card detection with mutex.
 1.29 03-Aug-2015  jmcneill Add support for DDR50 transfer modes.
 1.28 03-Aug-2015  mlelstv use mutex locking for MP safety.
 1.27 28-Jul-2015  mlelstv Be more verbose about errors.
 1.26 21-May-2015  jmcneill sdmmc_task_thread isn't MPSAFE so instead of just wrapping the callback
in KERNEL_LOCK/KERNEL_UNLOCK_ONE, remove KTHREAD_MPSAFE. While here, use
PRI_BIO instead of PRI_NONE for the task thread priority. Since this is
how all transfers are queued, and we have a 1 second timeout on the task
being picked up off the queue (!), better not to rely on a PRI_NONE thread.
 1.25 20-May-2015  jmcneill need to call lddone with splbio and kernel lock held
 1.24 27-Feb-2015  nonaka fix to simulate multi-segment dma transfer for pq3sdhc(4).
 1.23 16-Nov-2014  ozaki-r branches: 1.23.2;
Replace callout_stop with callout_halt

In order to call callout_destroy for a callout safely, we have to ensure
the function of the callout is not running and pending. To do so, we should
use callout_halt, not callout_stop.

Discussed with martin@ and riastradh@.
 1.22 19-Mar-2014  nonaka branches: 1.22.4;
Add a driver for Realtek RTS5209/RTS5229 Card Reader.
Ported from OpenBSD.
 1.21 12-Oct-2013  christos Pass the device name in, so we can debug what deferred drivers did not work.
 1.20 22-Dec-2012  jakllsch branches: 1.20.2;
We can't block our interrupt while sdmmc_detach_card is called, as
it can issue commands, and some host drivers have interrupt-driven
command completion. Prevents assertion (or deadlock) upon detach
of sdhc(4) with inserted card.
 1.19 22-Dec-2012  jakllsch Revert sdmmc.c r1.18 (previous commit to this file).
It seems to have caused regressions to detaching drivers from cards at
the appropriate time.

DETACH_FORCE to sdmmc_card_detach really means the SD/SDIO card is gone,
and can not be abused to mean that the host controller disappered.
 1.18 20-Dec-2012  jakllsch Only use DETACH_FORCE as flags argument to sdmmc_card_detach when the
host controller has disappeared or is detaching.
XXX should pass flags from sdmmc_detach through to the task thread ending
to differentiate host controller disappearance from mere detachment.
 1.17 15-Dec-2012  jakllsch It's also useful to compile-test before committing.
 1.16 15-Dec-2012  jakllsch When debugging, it's useful to know what exactly failed.
 1.15 04-Aug-2012  kiyohara branches: 1.15.2;
Print 'Standard Function Interface Code" in sdmmc_print(), if not SD_IO_SFIC_NO_STANDARD.
 1.14 17-Jul-2012  skrll Whitespace.
 1.13 12-Jul-2012  jakllsch If necessary, unload and destroy dmamap upon detach.
 1.12 01-Feb-2012  matt Use "opt_sdmmc.h" for SDMMC_DEBUG, etc.
 1.11 26-Jan-2012  matt Print error if couldn't enable card.
 1.10 21-Jan-2012  nonaka fix my license notice.
 1.9 20-Mar-2011  nonaka branches: 1.9.4; 1.9.8;
if poll card detect is enabled, don't show "couldn't enable card".
 1.8 13-Feb-2011  nonaka - Don't switch MMC high-speed timing, if host controller isn't supported.
- Only check EXT_CSD STRUCTURE version when CSD version is 3.
- initialize width at sdmmc_function_alloc().
 1.7 05-Feb-2011  nonaka Don't switch SD high-speed timing, if host controller isn't supported.
 1.6 07-Oct-2010  kiyohara branches: 1.6.2; 1.6.4;
Fix read CIS. And pass to attach args the standard function interface code.
 1.5 07-Oct-2010  kiyohara Support High-Speed mode.
 1.4 01-Oct-2010  kiyohara Use DMA bounce buffer, if DMA buffer is making by multiple segments. A lot
of host controllers do not support to two or more segments.
 1.3 20-Sep-2010  kiyohara Clear SMF_CARD_PRESENT, if failed to attach.
 1.2 06-Apr-2010  nonaka branches: 1.2.2;
- mention MMC SPI mode.
- support SD 4bit bus width mode.
 1.1 21-Apr-2009  nonaka branches: 1.1.2; 1.1.4; 1.1.6; 1.1.8; 1.1.10; 1.1.12;
Added SD/MMC support from OpenBSD.
tested on i386, amd64 at current-users ML by pgoyette@.
tested on zaurus by myself.
 1.1.12.3 21-Apr-2011  rmind sync with head
 1.1.12.2 05-Mar-2011  rmind sync with head
 1.1.12.1 30-May-2010  rmind sync with head
 1.1.10.2 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.1.10.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.1.8.2 07-Oct-2009  sborrill Pull up the following revisions(s) (requested by jmcneill in ticket #1044):
distrib/sets/lists/man/mi: patch
share/man/man4/Makefile: patch
sys/arch/amd64/conf/files.amd64: 1.67
sys/arch/i386/conf/files.i386: 1.349
sys/conf/files 1.945
share/man/man4/sdmmc.4: 1.1-1.4
sys/dev/sdmmc/Makefile.sdmmcdevs 1.1
sys/dev/sdmmc/devlist2h.awk 1.1
sys/dev/sdmmc/files.sdmmc 1.1-1.2
sys/dev/sdmmc/ld_sdmmc.c 1.1-1.3
sys/dev/sdmmc/sbt.c 1.1-1.2
sys/dev/sdmmc/sdhc.c 1.1-1.3
sys/dev/sdmmc/sdhcreg.h 1.1
sys/dev/sdmmc/sdhcvar.h 1.1
sys/dev/sdmmc/sdmmc.c 1.1
sys/dev/sdmmc/sdmmc_cis.c 1.1
sys/dev/sdmmc/sdmmc_io.c 1.1
sys/dev/sdmmc/sdmmc_ioreg.h 1.1
sys/dev/sdmmc/sdmmc_mem.c 1.1-1.2
sys/dev/sdmmc/sdmmcchip.h 1.1
sys/dev/sdmmc/sdmmcdevs 1.1
sys/dev/sdmmc/sdmmcdevs.h 1.1-1.2
sys/dev/sdmmc/sdmmcreg.h 1.1-1.3
sys/dev/sdmmc/sdmmcvar.h 1.1

Add sdmmc framework
 1.1.8.1 21-Apr-2009  sborrill file sdmmc.c was added on branch netbsd-5 on 2009-10-07 15:41:13 +0000
 1.1.6.2 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.1.6.1 21-Apr-2009  jym file sdmmc.c was added on branch jym-xensuspend on 2009-05-13 17:21:29 +0000
 1.1.4.4 09-Oct-2010  yamt sync with head
 1.1.4.3 11-Aug-2010  yamt sync with head.
 1.1.4.2 04-May-2009  yamt sync with head.
 1.1.4.1 21-Apr-2009  yamt file sdmmc.c was added on branch yamt-nfs-mp on 2009-05-04 08:13:18 +0000
 1.1.2.2 28-Apr-2009  skrll Sync with HEAD.
 1.1.2.1 21-Apr-2009  skrll file sdmmc.c was added on branch nick-hppapmap on 2009-04-28 07:36:33 +0000
 1.2.2.2 21-Apr-2010  matt sync to netbsd-5
 1.2.2.1 06-Apr-2010  matt file sdmmc.c was added on branch matt-nb5-mips64 on 2010-04-21 00:27:52 +0000
 1.6.4.2 17-Feb-2011  bouyer Sync with HEAD
 1.6.4.1 08-Feb-2011  bouyer Sync with HEAD
 1.6.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.9.8.1 18-Feb-2012  mrg merge to -current.
 1.9.4.4 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.9.4.3 23-Jan-2013  yamt sync with head
 1.9.4.2 30-Oct-2012  yamt sync with head
 1.9.4.1 17-Apr-2012  yamt sync with head
 1.15.2.3 03-Dec-2017  jdolecek update from HEAD
 1.15.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.15.2.1 25-Feb-2013  tls resync with head
 1.20.2.1 18-May-2014  rmind sync with head
 1.22.4.3 26-May-2015  msaitoh Pull up following revision(s) (requested by jmcneill in ticket #794):
sys/dev/sdmmc/sdmmc.c: revision 1.25
sys/dev/sdmmc/sdmmc.c: revision 1.26
sys/dev/sdmmc/ld_sdmmc.c: revision 1.13
sys/dev/sdmmc/ld_sdmmc.c: revision 1.16
- Be a bit more verbose about errors, also pass through error code
from lower layer like other drivers.
- need to call lddone with splbio and kernel lock held
- sdmmc_task_thread isn't MPSAFE so instead of just wrapping the callback
in KERNEL_LOCK/KERNEL_UNLOCK_ONE, remove KTHREAD_MPSAFE. While here, use
PRI_BIO instead of PRI_NONE for the task thread priority. Since this is
how all transfers are queued, and we have a 1 second timeout on the task
being picked up off the queue (!), better not to rely on a PRI_NONE thread.
 1.22.4.2 09-Mar-2015  snj Pull up following revision(s) (requested by nonaka in ticket #577):
sys/arch/powerpc/booke/dev/pq3sdhc.c: revision 1.6
sys/dev/sdmmc/sdhc.c: revision 1.54
sys/dev/sdmmc/sdmmc.c: revision 1.24
eSDHC has no DMA_BOUNDARY in BLOCK_SIZE register.
So clear multi segment DMA transfer support bit.
--
fix to simulate multi-segment dma transfer for pq3sdhc(4).
--
pq3sdhc: Enable DMA transfer.
 1.22.4.1 01-Dec-2014  martin Pull up following revision(s) (requested by ozaki-r in ticket #279):
sys/kern/kern_ktrace.c: revision 1.166
sys/dev/isa/aps.c: revision 1.16
sys/dev/sysmon/sysmonvar.h: revision 1.45
sys/dev/ir/irframe_tty.c: revision 1.60
sys/dev/sysmon/sysmon_envsys_events.c: revision 1.111
sys/dev/sysmon/sysmon_envsys_events.c: revision 1.112
sys/dev/pci/pccbb.c: revision 1.207
sys/dev/wscons/wskbd.c: revision 1.135
sys/dev/usb/ohci.c: revision 1.254
sys/net/if_ecosubr.c: revision 1.41
sys/dev/pcmcia/btbc.c: revision 1.17
sys/arch/x86/x86/via_padlock.c: revision 1.23
sys/dev/sdmmc/sdmmc.c: revision 1.23
sys/dev/bluetooth/btkbd.c: revision 1.17
sys/dev/bluetooth/bcsp.c: revision 1.25
sys/arch/x86/pci/fwhrng.c: revision 1.8
sys/dev/ic/nslm7x.c: revision 1.61
share/man/man9/callout.9: revision 1.28
Replace callout_stop with callout_halt
In order to call callout_destroy for a callout safely, we have to ensure
the function of the callout is not running and pending. To do so, we should
use callout_halt, not callout_stop.
Discussed with martin@ and riastradh@.
Make it clear that we should use not callout_stop but callout_halt
before callout_destroy
Replace callout_stop with callout_halt
In order to call callout_destroy for a callout safely, we have to ensure
the function of the callout is not running and pending. To do so, we should
use callout_halt, not callout_stop.
In this case, we need to pass an interlock to callout_halt to wait for
the callout complete.
Reviewed by riastradh@.
Kill sme_callout_mtx and use sme_mtx instead
We can use sme_mtx for the callout as well. Actually we should do so
because sme_events_list and some other data that are touched in the
callout should be protected by sme_mtx, not sme_callout_mtx.
Discussed with riastradh@ in
http://mail-index.netbsd.org/tech-kern/2014/11/11/msg017956.html
Replace callout_stop with callout_halt
In order to call callout_destroy for a callout safely, we have to ensure
the function of the callout is not running and pending. To do so, we should
use callout_halt, not callout_stop.
In this case, we need to pass an interlock to callout_halt to wait for
the callout complete. And also we make sure that SME_CALLOUT_INITIALIZED
is unset before calling callout_halt to prevent the callout from calling
callout_schedule. This is the same as what we did in sys/netinet6/mld6.c@1.61.
Reviewed by riastradh@.
 1.23.2.5 28-Aug-2017  skrll Sync with HEAD
 1.23.2.4 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.23.2.3 22-Sep-2015  skrll Sync with HEAD
 1.23.2.2 06-Jun-2015  skrll Sync with HEAD
 1.23.2.1 06-Apr-2015  skrll Sync with HEAD
 1.33.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.33.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.34.12.2 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.34.12.1 15-Mar-2018  pgoyette Synch with HEAD
 1.35.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.35.2.1 10-Jun-2019  christos Sync with HEAD
 1.36.4.2 09-Aug-2020  martin Pull up following revision(s) (requested by mrg in ticket #1042):

sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.19
sys/dev/sdmmc/ld_sdmmc.c: revision 1.38
sys/dev/sdmmc/sdmmcvar.h: revision 1.35
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.5
sys/dev/ic/bwfm.c: revision 1.26
sys/dev/ic/bwfm.c: revision 1.27
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.20
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.21
sys/dev/sdmmc/sdmmc_io.c: revision 1.20
sys/dev/sdmmc/sdmmc_mem.c: revision 1.72
sys/dev/sdmmc/sdmmc.c: revision 1.40
sys/dev/sdmmc/sdmmc_ioreg.h: revision 1.6
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.16

Don't pass empty mbufs to the network stack.

Avoid changing signedness bit with << in sdmmc_ioreg.h
Reported by <prlw1>

If the controller doesn't support switch func (opcode 6) then skip
setting this but continue with other settings. This allows us to use
a card, albeit at a lower speed.

Fix races in sdmmc tasks and teach ld@sdmmc to abort xfers on detach.
- Teach sdmmc_add_task to queue it only if not already queued.
- Remove now-redundant logic to avoid repeated queueing elsewhere.
- Teach sdmmc_del_task to wait until task has completed.
- Call sdmmc_del_task in various needful places.
- Replace abuse of pcq by a lock and a tailq.
(pcq is multi-producer, _single_-consumer, but there are potentially
multiple consumers here and really only one producer.)
- Teach ld_sdmmc to abort xfers on detach.
(Mechanism is kinda kludgey but it'll do for now; any effort one is
tempted to spend overhauling this should be spent overhauling sdmmc
to support proper asynchronous commands.)
- Make sure ld_sdmmc_discard either returns failure or eventually calls
ldenddiscard.

XXX Currently ld_sdmmc_detach aborts xfers _before_ ldbegindetach has
has committed to detaching or not. This is currently necessary to
avoid a deadlock because ldbegindetach waits for xfers to drain --
which strikes me as wrong; ldbegindetach shouldn't wait for anything,
and should only make the decision to commit to detaching or not so
the caller can decide whether to abort xfers before we actually wait
for them in ldenddetach.

XXX pullup -- although this changes some kernel symbols (sdmmc_add_task
and sdmmc_del_task), it shouldn't affect any existing modules; the only
module that uses sdmmc is ld_sdmmc.kmod, which is `.if 0' in the build
so there shouldn't be any of them floating around.

Make this work on big endian machines

move some of the patching of callbacks and other data after
ieee80211_ifattach() but before if_deferred_start_init().
may fix panic i saw in after restarting wpa_supplicant.
from mlelstv.

only ask for SDPCMD_INTSTATUS_HMB_SW_MASK and SDPCMD_INTSTATUS_CHIPACTIVE
interrupts, not all of them. we only ack these ones.
mostly fixes pinebookpro wifi hard hangs. still is problematic and can
trigger interrupt storm that appears as a hard hang without NET_MPSAFE,
and a follow up, less clearly right, change will reduce that to a soft
hang of the interface that can be cleared with 'ifconfig bwfm0 down up',
and even often recovers itself now.

clear all interrupts, not just those we expect from the hostintmask.
this removes the final hard hang i have seen in pinebookpro wifi,
though one may still need to 'ifconfig bwfm0 down up' occasionally,
so we still have bugs to fix here (the hang is usually associated
with 'checksum error' from bwfm/sdio.)

Sort #includes. Nix trailing whitespace.
No functional change intended.
 1.36.4.1 25-Feb-2020  martin Pull up following revision(s) (requested by mrg in ticket #717):

sys/dev/fdt/dwcmmc_fdt.c 1.11
sys/dev/ic/bwfm.c 1.15-1.18
sys/dev/ic/bwfmreg.h 1.4-1.6
sys/dev/ic/bwfmvar.h 1.4,1.5
sys/dev/ic/dwc_mmc.c 1.21,1.22
sys/dev/ic/dwc_mmc_reg.h 1.8,1.9,1.12,1.13
sys/dev/pcmcia/pcmciareg.h 1.11
sys/dev/sdmmc/if_bwfm_sdio.c 1.4,1.6-1.12
sys/dev/sdmmc/if_bwfm_sdio.h 1.1,1.2
sys/dev/sdmmc/sdhc.c 1.105,1.106
sys/dev/sdmmc/sdmmc.c 1.37,1.39
sys/dev/sdmmc/sdmmc_cis.c 1.6,1.8
sys/dev/sdmmc/sdmmc_io.c 1.15-1.19
sys/dev/sdmmc/sdmmc_ioreg.h 1.4,1.5
sys/dev/sdmmc/sdmmc_mem.c 1.69-1.71
sys/dev/sdmmc/sdmmcdevs 1.5-1.8
sys/dev/sdmmc/sdmmcvar.h 1.31,1.33,1.34
sys/net/if_media.h 1.66

Add Broadcom devices
-
Fix typo
-
add PCMCIA_CISTPL_SDIO definition.
-
From OpenBSD:
- move event handling to workqueue
- check for save/restore capability
-
Tag work queue as MPsafe and increase length.
-
Juse use bpf_mtap(), the 802.11 encapsulation is handled by firmware.
-
From OpenBSD:
- support block length per function
- add functions to read/write regions
-
Decode (but not use) SDIO tuple in CIS.
-
Fix locking.
-
Add more SDIO defines (partially from version 3.0).
-
From OpenBSD:
- All the missing pieces (firmware load, chip setup, protocol handling)
TX queue and interrupt handling via sdmmc_task.
-
Fix locking.
-
Fix packet parsing.
-
Add parser for original firmware config files.
-
tagging work queue as MPSAFE was premature. Revert.
-
SD_IO_RW_EXTENDED is a data transfer command, so set ADTC flag instead of AC
Use correct function to verify if a task has been queued. Avoids race
that can corrupt the task queue.
-
More register definitions.
-
Add IFM_IEEE80211_VHT subtype, IFM_IEEE80211_11AC operating mode, and missing descriptions
-
If firmware is connected in HT or VHT mode, report it to SIOCGIFMEDIA
-
white space police.

Skip setting power when the voltage doesn't change.
Also increase some timeouts.
-
Add and use sdmmc_pause to avoid long-term busy waits.
-
Add sdio abort function.
-
Additional error messages.
-
Print parameters for SDIO devices.
-
Minor cosmetics.
-
Simplyfy sdmmc_io_set_blocklen function signature by dropping the
extra softc pointer. Aligns with OpenBSD.
-
Missing commit for sdio abort function.
-
More code from OpenBSD
-
no need to splnet() when enqueing packets
-
explicit structure padding
-
make internal functions static
-
also prepare for GPIO interrupts.
-
Avoid warnings for tautological shifts as sole conditional.
-
Follow the Linux driver an use the FDT "compatible" property to build a
filename for the nvram config file, fall back to the standard filename.
E.g.
[Caching 123 nodes and 1093 properties]
compatible 73696e6f 766f6970 2c627069 2d6d322d "sinovoip,bpi-m2-
0010: 7a65726f 00...... ........ ........ zero"
0015: 616c6c77 696e6e65 722c7375 6e38692d "allwinner,sun8i-
0025: 68322d70 6c757300 ........ ........ h2-plus"
interrupt-parent 00000001 ........ ........ ........ ....
model 42616e61 6e612050 69204250 492d4d32 "Banana Pi BPI-M2
0010: 2d5a6572 6f00.... ........ ........ -Zero"
name 00...... ........ ........ ........ ""
serial-number 30326330 30303432 65636431 36376566 02c00042ecd167ef
0010: 00...... ........ ........ ........ .
-rw-r--r-- 1 root wheel 875 Nov 2 12:06 brcmfmac43430-sdio.AP6212.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 16:19 brcmfmac43430-sdio.sinovoip,bpi-m2-zero.txt -> brcmfmac43430-sdio.AP6212.txt
-rw-r--r-- 1 root wheel 874 Jun 30 2019 brcmfmac43430-sdio.raspberrypi,3-model-b.txt
-rw-r--r-- 1 root wheel 1864 Jun 30 2019 brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 11:24 brcmfmac43455-sdio.raspberrypi,4-model-b-plus.txt -> brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
-
Add product ID for Broadcom BCM43455
-
Use correct firmware for BCM43456
-
size check was backwards.
-
Be less noisy for some commands.
-
Fix DWC_MMC_INT_SDIO_INT bit
-
dwc_mmc fixes:
- Rockchip uses a different SDIO int bit, so take this into consideration
- Avoid unnecessary resets and always wait for resets to complete
- kpause instead of delay while holding spinlock
- Do not attempt autostop for SD_IO_RW_EXTENDED commands
- Allow for sub-blklen byte counts for single block transfers
-
More SDIO stability and performance fixes
 1.40.4.1 23-Mar-2021  thorpej Convert config_found_ia() call sites where the device only carries
a single interface attribute to bare config_found() calls.
 1.41.2.1 17-Jun-2021  thorpej Sync w/ HEAD.
 1.42.2.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.43.12.1 02-Aug-2025  perseant Sync with HEAD
 1.10 17-Jan-2025  jmcneill sdmmc: Capture lan_nid and expose sdmmc_cisptr

LAN NID contains the MAC address for networking adapters.

Device drivers may want to processor vendor specific tuple codes, so
expose sdmmc_cisptr to help this.
 1.9 13-Oct-2024  jmcneill sdmmc: Decode CISTPL_FUNCE of type PCMCIA_TPLFE_TYPE_LAN_NID
 1.8 28-Oct-2019  mlelstv branches: 1.8.26; 1.8.32;
Whitespace police
 1.7 24-Sep-2019  mlelstv Remove debug printf.
 1.6 01-Sep-2019  mlelstv From OpenBSD:
- support block length per function
- add functions to read/write regions
Decode (but not use) SDIO tuple in CIS.
Fix locking.
Add more SDIO defines (partially from version 3.0).
 1.5 28-Jan-2018  jmcneill branches: 1.5.4; 1.5.10;
Don't print an error when we find a CIS tuple code in the vendor-unique
range (80h-8Fh).
 1.4 01-Feb-2012  matt Use "opt_sdmmc.h" for SDMMC_DEBUG, etc.
 1.3 07-Oct-2010  kiyohara branches: 1.3.8; 1.3.12;
Fix build failure. s/const static/static const/.
 1.2 07-Oct-2010  kiyohara Fix read CIS. And pass to attach args the standard function interface code.
 1.1 21-Apr-2009  nonaka branches: 1.1.2; 1.1.4; 1.1.6; 1.1.8; 1.1.10; 1.1.12; 1.1.14;
Added SD/MMC support from OpenBSD.
tested on i386, amd64 at current-users ML by pgoyette@.
tested on zaurus by myself.
 1.1.14.2 21-Apr-2010  matt sync to netbsd-5
 1.1.14.1 21-Apr-2009  matt file sdmmc_cis.c was added on branch matt-nb5-mips64 on 2010-04-21 00:27:52 +0000
 1.1.12.1 05-Mar-2011  rmind sync with head
 1.1.10.1 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.1.8.2 07-Oct-2009  sborrill Pull up the following revisions(s) (requested by jmcneill in ticket #1044):
distrib/sets/lists/man/mi: patch
share/man/man4/Makefile: patch
sys/arch/amd64/conf/files.amd64: 1.67
sys/arch/i386/conf/files.i386: 1.349
sys/conf/files 1.945
share/man/man4/sdmmc.4: 1.1-1.4
sys/dev/sdmmc/Makefile.sdmmcdevs 1.1
sys/dev/sdmmc/devlist2h.awk 1.1
sys/dev/sdmmc/files.sdmmc 1.1-1.2
sys/dev/sdmmc/ld_sdmmc.c 1.1-1.3
sys/dev/sdmmc/sbt.c 1.1-1.2
sys/dev/sdmmc/sdhc.c 1.1-1.3
sys/dev/sdmmc/sdhcreg.h 1.1
sys/dev/sdmmc/sdhcvar.h 1.1
sys/dev/sdmmc/sdmmc.c 1.1
sys/dev/sdmmc/sdmmc_cis.c 1.1
sys/dev/sdmmc/sdmmc_io.c 1.1
sys/dev/sdmmc/sdmmc_ioreg.h 1.1
sys/dev/sdmmc/sdmmc_mem.c 1.1-1.2
sys/dev/sdmmc/sdmmcchip.h 1.1
sys/dev/sdmmc/sdmmcdevs 1.1
sys/dev/sdmmc/sdmmcdevs.h 1.1-1.2
sys/dev/sdmmc/sdmmcreg.h 1.1-1.3
sys/dev/sdmmc/sdmmcvar.h 1.1

Add sdmmc framework
 1.1.8.1 21-Apr-2009  sborrill file sdmmc_cis.c was added on branch netbsd-5 on 2009-10-07 15:41:13 +0000
 1.1.6.2 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.1.6.1 21-Apr-2009  jym file sdmmc_cis.c was added on branch jym-xensuspend on 2009-05-13 17:21:29 +0000
 1.1.4.3 09-Oct-2010  yamt sync with head
 1.1.4.2 04-May-2009  yamt sync with head.
 1.1.4.1 21-Apr-2009  yamt file sdmmc_cis.c was added on branch yamt-nfs-mp on 2009-05-04 08:13:18 +0000
 1.1.2.2 28-Apr-2009  skrll Sync with HEAD.
 1.1.2.1 21-Apr-2009  skrll file sdmmc_cis.c was added on branch nick-hppapmap on 2009-04-28 07:36:33 +0000
 1.3.12.1 18-Feb-2012  mrg merge to -current.
 1.3.8.1 17-Apr-2012  yamt sync with head
 1.5.10.1 25-Feb-2020  martin Pull up following revision(s) (requested by mrg in ticket #717):

sys/dev/fdt/dwcmmc_fdt.c 1.11
sys/dev/ic/bwfm.c 1.15-1.18
sys/dev/ic/bwfmreg.h 1.4-1.6
sys/dev/ic/bwfmvar.h 1.4,1.5
sys/dev/ic/dwc_mmc.c 1.21,1.22
sys/dev/ic/dwc_mmc_reg.h 1.8,1.9,1.12,1.13
sys/dev/pcmcia/pcmciareg.h 1.11
sys/dev/sdmmc/if_bwfm_sdio.c 1.4,1.6-1.12
sys/dev/sdmmc/if_bwfm_sdio.h 1.1,1.2
sys/dev/sdmmc/sdhc.c 1.105,1.106
sys/dev/sdmmc/sdmmc.c 1.37,1.39
sys/dev/sdmmc/sdmmc_cis.c 1.6,1.8
sys/dev/sdmmc/sdmmc_io.c 1.15-1.19
sys/dev/sdmmc/sdmmc_ioreg.h 1.4,1.5
sys/dev/sdmmc/sdmmc_mem.c 1.69-1.71
sys/dev/sdmmc/sdmmcdevs 1.5-1.8
sys/dev/sdmmc/sdmmcvar.h 1.31,1.33,1.34
sys/net/if_media.h 1.66

Add Broadcom devices
-
Fix typo
-
add PCMCIA_CISTPL_SDIO definition.
-
From OpenBSD:
- move event handling to workqueue
- check for save/restore capability
-
Tag work queue as MPsafe and increase length.
-
Juse use bpf_mtap(), the 802.11 encapsulation is handled by firmware.
-
From OpenBSD:
- support block length per function
- add functions to read/write regions
-
Decode (but not use) SDIO tuple in CIS.
-
Fix locking.
-
Add more SDIO defines (partially from version 3.0).
-
From OpenBSD:
- All the missing pieces (firmware load, chip setup, protocol handling)
TX queue and interrupt handling via sdmmc_task.
-
Fix locking.
-
Fix packet parsing.
-
Add parser for original firmware config files.
-
tagging work queue as MPSAFE was premature. Revert.
-
SD_IO_RW_EXTENDED is a data transfer command, so set ADTC flag instead of AC
Use correct function to verify if a task has been queued. Avoids race
that can corrupt the task queue.
-
More register definitions.
-
Add IFM_IEEE80211_VHT subtype, IFM_IEEE80211_11AC operating mode, and missing descriptions
-
If firmware is connected in HT or VHT mode, report it to SIOCGIFMEDIA
-
white space police.

Skip setting power when the voltage doesn't change.
Also increase some timeouts.
-
Add and use sdmmc_pause to avoid long-term busy waits.
-
Add sdio abort function.
-
Additional error messages.
-
Print parameters for SDIO devices.
-
Minor cosmetics.
-
Simplyfy sdmmc_io_set_blocklen function signature by dropping the
extra softc pointer. Aligns with OpenBSD.
-
Missing commit for sdio abort function.
-
More code from OpenBSD
-
no need to splnet() when enqueing packets
-
explicit structure padding
-
make internal functions static
-
also prepare for GPIO interrupts.
-
Avoid warnings for tautological shifts as sole conditional.
-
Follow the Linux driver an use the FDT "compatible" property to build a
filename for the nvram config file, fall back to the standard filename.
E.g.
[Caching 123 nodes and 1093 properties]
compatible 73696e6f 766f6970 2c627069 2d6d322d "sinovoip,bpi-m2-
0010: 7a65726f 00...... ........ ........ zero"
0015: 616c6c77 696e6e65 722c7375 6e38692d "allwinner,sun8i-
0025: 68322d70 6c757300 ........ ........ h2-plus"
interrupt-parent 00000001 ........ ........ ........ ....
model 42616e61 6e612050 69204250 492d4d32 "Banana Pi BPI-M2
0010: 2d5a6572 6f00.... ........ ........ -Zero"
name 00...... ........ ........ ........ ""
serial-number 30326330 30303432 65636431 36376566 02c00042ecd167ef
0010: 00...... ........ ........ ........ .
-rw-r--r-- 1 root wheel 875 Nov 2 12:06 brcmfmac43430-sdio.AP6212.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 16:19 brcmfmac43430-sdio.sinovoip,bpi-m2-zero.txt -> brcmfmac43430-sdio.AP6212.txt
-rw-r--r-- 1 root wheel 874 Jun 30 2019 brcmfmac43430-sdio.raspberrypi,3-model-b.txt
-rw-r--r-- 1 root wheel 1864 Jun 30 2019 brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 11:24 brcmfmac43455-sdio.raspberrypi,4-model-b-plus.txt -> brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
-
Add product ID for Broadcom BCM43455
-
Use correct firmware for BCM43456
-
size check was backwards.
-
Be less noisy for some commands.
-
Fix DWC_MMC_INT_SDIO_INT bit
-
dwc_mmc fixes:
- Rockchip uses a different SDIO int bit, so take this into consideration
- Avoid unnecessary resets and always wait for resets to complete
- kpause instead of delay while holding spinlock
- Do not attempt autostop for SD_IO_RW_EXTENDED commands
- Allow for sub-blklen byte counts for single block transfers
-
More SDIO stability and performance fixes
 1.5.4.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.8.32.1 02-Aug-2025  perseant Sync with HEAD
 1.8.26.2 02-Feb-2025  martin Pull up following revision(s) (requested by jmcneill in ticket #1041):

sys/dev/ic/bwi.c: revision 1.40
share/man/man4/bwi.4: revision 1.15
sys/dev/sdmmc/if_bwi_sdio.c: revision 1.1
sys/dev/ic/bwi.c: revision 1.41
sys/dev/sdmmc/sdmmcvar.h: revision 1.38
sys/dev/ic/bwireg.h: revision 1.5
sys/dev/ic/bwi.c: revision 1.39
sys/dev/ic/bwivar.h: revision 1.11
sys/dev/sdmmc/sdmmc_cis.c: revision 1.10
sys/dev/sdmmc/files.sdmmc: revision 1.6
sys/arch/evbppc/conf/WII: revision 1.7

bwi: Remove unnecessary pcivar.h include

sdmmc: Capture lan_nid and expose sdmmc_cisptr
LAN NID contains the MAC address for networking adapters.
Device drivers may want to processor vendor specific tuple codes, so
expose sdmmc_cisptr to help this.

bwi(4): Add support for Nintendo Wii WLAN.

Adapt the bwi(4) driver to support SDIO attachment and driving TX/RX using
PIO instead of DMA since the latter is not supported on SDIO busses.

fix uninitialized
 1.8.26.1 14-Oct-2024  martin Pull up following revision(s) (requested by jmcneill in ticket #977):

sys/dev/sdmmc/sdmmc_cis.c: revision 1.9

sdmmc: Decode CISTPL_FUNCE of type PCMCIA_TPLFE_TYPE_LAN_NID
 1.21 17-Oct-2020  mlelstv Fix error message. No functional change, both commands use the same
bit to select read or write mode.
 1.20 24-May-2020  riastradh Fix races in sdmmc tasks and teach ld@sdmmc to abort xfers on detach.

- Teach sdmmc_add_task to queue it only if not already queued.
- Remove now-redundant logic to avoid repeated queueing elsewhere.
- Teach sdmmc_del_task to wait until task has completed.
- Call sdmmc_del_task in various needful places.
- Replace abuse of pcq by a lock and a tailq.
(pcq is multi-producer, _single_-consumer, but there are potentially
multiple consumers here and really only one producer.)
- Teach ld_sdmmc to abort xfers on detach.
(Mechanism is kinda kludgey but it'll do for now; any effort one is
tempted to spend overhauling this should be spent overhauling sdmmc
to support proper asynchronous commands.)
- Make sure ld_sdmmc_discard either returns failure or eventually calls
ldenddiscard.

XXX Currently ld_sdmmc_detach aborts xfers _before_ ldbegindetach has
has committed to detaching or not. This is currently necessary to
avoid a deadlock because ldbegindetach waits for xfers to drain --
which strikes me as wrong; ldbegindetach shouldn't wait for anything,
and should only make the decision to commit to detaching or not so
the caller can decide whether to abort xfers before we actually wait
for them in ldenddetach.

XXX pullup -- although this changes some kernel symbols (sdmmc_add_task
and sdmmc_del_task), it shouldn't affect any existing modules; the only
module that uses sdmmc is ld_sdmmc.kmod, which is `.if 0' in the build
so there shouldn't be any of them floating around.
 1.19 04-Jan-2020  mlelstv Be less noisy for some commands.
 1.18 28-Oct-2019  mlelstv Simplyfy sdmmc_io_set_blocklen function signature by dropping the
extra softc pointer. Aligns with OpenBSD.
 1.17 28-Oct-2019  mlelstv Add and use sdmmc_pause to avoid long-term busy waits.
Add sdio abort function.
Additional error messages.
Print parameters for SDIO devices.
Minor cosmetics.
 1.16 02-Sep-2019  jmcneill SD_IO_RW_EXTENDED is a data transfer command, so set ADTC flag instead of AC
 1.15 01-Sep-2019  mlelstv From OpenBSD:
- support block length per function
- add functions to read/write regions
Decode (but not use) SDIO tuple in CIS.
Fix locking.
Add more SDIO defines (partially from version 3.0).
 1.14 14-Oct-2018  jdolecek branches: 1.14.4;
remove M_CANFAIL flag for malloc(9) - it was completely ignored, so had
actually no effect
 1.13 23-Oct-2017  jmcneill branches: 1.13.2; 1.13.4;
- Get SDIO reset working (from OpenBSD).
- After switching bus width, notify the host controller of the change.
 1.12 06-Oct-2015  mlelstv support hiding command timeout messages with a new command flag and use this
when probing for cards. Should fix PR 50302.
 1.11 05-Aug-2015  mlelstv lock around interrupt registration.
don't release lock around interrupt handlers, the code cannot
handle an unstable handler list.
 1.10 03-Aug-2015  jmcneill Add support for DDR50 transfer modes.
 1.9 03-Aug-2015  mlelstv use mutex locking for MP safety.
 1.8 28-Jul-2015  mlelstv cosmetic change only.
 1.7 01-Feb-2012  matt branches: 1.7.6; 1.7.24;
Use "opt_sdmmc.h" for SDMMC_DEBUG, etc.
 1.6 13-Feb-2011  nonaka branches: 1.6.4; 1.6.8;
- Don't switch MMC high-speed timing, if host controller isn't supported.
- Only check EXT_CSD STRUCTURE version when CSD version is 3.
- initialize width at sdmmc_function_alloc().
 1.5 07-Oct-2010  kiyohara branches: 1.5.2; 1.5.4;
Fix read CIS. And pass to attach args the standard function interface code.
 1.4 07-Oct-2010  kiyohara Remove unnecessary Tab.
 1.3 07-Oct-2010  kiyohara Support High-Speed mode.
 1.2 05-Dec-2009  pooka branches: 1.2.2; 1.2.4; 1.2.6;
Convert tsleep(&lbolt) to kpause(). Make ltsleep/mtsleep on lbolt
illegal. I examined all places where lbolt is referenced to make
sure there were pointer aliases of it passed to tsleep, but put a
KASSERT in m/ltsleep() just to be sure.
 1.1 21-Apr-2009  nonaka branches: 1.1.2; 1.1.4; 1.1.6; 1.1.8;
Added SD/MMC support from OpenBSD.
tested on i386, amd64 at current-users ML by pgoyette@.
tested on zaurus by myself.
 1.1.8.2 07-Oct-2009  sborrill Pull up the following revisions(s) (requested by jmcneill in ticket #1044):
distrib/sets/lists/man/mi: patch
share/man/man4/Makefile: patch
sys/arch/amd64/conf/files.amd64: 1.67
sys/arch/i386/conf/files.i386: 1.349
sys/conf/files 1.945
share/man/man4/sdmmc.4: 1.1-1.4
sys/dev/sdmmc/Makefile.sdmmcdevs 1.1
sys/dev/sdmmc/devlist2h.awk 1.1
sys/dev/sdmmc/files.sdmmc 1.1-1.2
sys/dev/sdmmc/ld_sdmmc.c 1.1-1.3
sys/dev/sdmmc/sbt.c 1.1-1.2
sys/dev/sdmmc/sdhc.c 1.1-1.3
sys/dev/sdmmc/sdhcreg.h 1.1
sys/dev/sdmmc/sdhcvar.h 1.1
sys/dev/sdmmc/sdmmc.c 1.1
sys/dev/sdmmc/sdmmc_cis.c 1.1
sys/dev/sdmmc/sdmmc_io.c 1.1
sys/dev/sdmmc/sdmmc_ioreg.h 1.1
sys/dev/sdmmc/sdmmc_mem.c 1.1-1.2
sys/dev/sdmmc/sdmmcchip.h 1.1
sys/dev/sdmmc/sdmmcdevs 1.1
sys/dev/sdmmc/sdmmcdevs.h 1.1-1.2
sys/dev/sdmmc/sdmmcreg.h 1.1-1.3
sys/dev/sdmmc/sdmmcvar.h 1.1

Add sdmmc framework
 1.1.8.1 21-Apr-2009  sborrill file sdmmc_io.c was added on branch netbsd-5 on 2009-10-07 15:41:13 +0000
 1.1.6.2 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.1.6.1 21-Apr-2009  jym file sdmmc_io.c was added on branch jym-xensuspend on 2009-05-13 17:21:29 +0000
 1.1.4.4 09-Oct-2010  yamt sync with head
 1.1.4.3 11-Mar-2010  yamt sync with head
 1.1.4.2 04-May-2009  yamt sync with head.
 1.1.4.1 21-Apr-2009  yamt file sdmmc_io.c was added on branch yamt-nfs-mp on 2009-05-04 08:13:18 +0000
 1.1.2.2 28-Apr-2009  skrll Sync with HEAD.
 1.1.2.1 21-Apr-2009  skrll file sdmmc_io.c was added on branch nick-hppapmap on 2009-04-28 07:36:33 +0000
 1.2.6.2 21-Apr-2010  matt sync to netbsd-5
 1.2.6.1 05-Dec-2009  matt file sdmmc_io.c was added on branch matt-nb5-mips64 on 2010-04-21 00:27:52 +0000
 1.2.4.1 05-Mar-2011  rmind sync with head
 1.2.2.1 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.5.4.1 17-Feb-2011  bouyer Sync with HEAD
 1.5.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.6.8.1 18-Feb-2012  mrg merge to -current.
 1.6.4.1 17-Apr-2012  yamt sync with head
 1.7.24.2 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.7.24.1 22-Sep-2015  skrll Sync with HEAD
 1.7.6.1 03-Dec-2017  jdolecek update from HEAD
 1.13.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.13.4.1 10-Jun-2019  christos Sync with HEAD
 1.13.2.1 20-Oct-2018  pgoyette Sync with head
 1.14.4.2 09-Aug-2020  martin Pull up following revision(s) (requested by mrg in ticket #1042):

sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.19
sys/dev/sdmmc/ld_sdmmc.c: revision 1.38
sys/dev/sdmmc/sdmmcvar.h: revision 1.35
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.5
sys/dev/ic/bwfm.c: revision 1.26
sys/dev/ic/bwfm.c: revision 1.27
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.20
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.21
sys/dev/sdmmc/sdmmc_io.c: revision 1.20
sys/dev/sdmmc/sdmmc_mem.c: revision 1.72
sys/dev/sdmmc/sdmmc.c: revision 1.40
sys/dev/sdmmc/sdmmc_ioreg.h: revision 1.6
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.16

Don't pass empty mbufs to the network stack.

Avoid changing signedness bit with << in sdmmc_ioreg.h
Reported by <prlw1>

If the controller doesn't support switch func (opcode 6) then skip
setting this but continue with other settings. This allows us to use
a card, albeit at a lower speed.

Fix races in sdmmc tasks and teach ld@sdmmc to abort xfers on detach.
- Teach sdmmc_add_task to queue it only if not already queued.
- Remove now-redundant logic to avoid repeated queueing elsewhere.
- Teach sdmmc_del_task to wait until task has completed.
- Call sdmmc_del_task in various needful places.
- Replace abuse of pcq by a lock and a tailq.
(pcq is multi-producer, _single_-consumer, but there are potentially
multiple consumers here and really only one producer.)
- Teach ld_sdmmc to abort xfers on detach.
(Mechanism is kinda kludgey but it'll do for now; any effort one is
tempted to spend overhauling this should be spent overhauling sdmmc
to support proper asynchronous commands.)
- Make sure ld_sdmmc_discard either returns failure or eventually calls
ldenddiscard.

XXX Currently ld_sdmmc_detach aborts xfers _before_ ldbegindetach has
has committed to detaching or not. This is currently necessary to
avoid a deadlock because ldbegindetach waits for xfers to drain --
which strikes me as wrong; ldbegindetach shouldn't wait for anything,
and should only make the decision to commit to detaching or not so
the caller can decide whether to abort xfers before we actually wait
for them in ldenddetach.

XXX pullup -- although this changes some kernel symbols (sdmmc_add_task
and sdmmc_del_task), it shouldn't affect any existing modules; the only
module that uses sdmmc is ld_sdmmc.kmod, which is `.if 0' in the build
so there shouldn't be any of them floating around.

Make this work on big endian machines

move some of the patching of callbacks and other data after
ieee80211_ifattach() but before if_deferred_start_init().
may fix panic i saw in after restarting wpa_supplicant.
from mlelstv.

only ask for SDPCMD_INTSTATUS_HMB_SW_MASK and SDPCMD_INTSTATUS_CHIPACTIVE
interrupts, not all of them. we only ack these ones.
mostly fixes pinebookpro wifi hard hangs. still is problematic and can
trigger interrupt storm that appears as a hard hang without NET_MPSAFE,
and a follow up, less clearly right, change will reduce that to a soft
hang of the interface that can be cleared with 'ifconfig bwfm0 down up',
and even often recovers itself now.

clear all interrupts, not just those we expect from the hostintmask.
this removes the final hard hang i have seen in pinebookpro wifi,
though one may still need to 'ifconfig bwfm0 down up' occasionally,
so we still have bugs to fix here (the hang is usually associated
with 'checksum error' from bwfm/sdio.)

Sort #includes. Nix trailing whitespace.
No functional change intended.
 1.14.4.1 25-Feb-2020  martin Pull up following revision(s) (requested by mrg in ticket #717):

sys/dev/fdt/dwcmmc_fdt.c 1.11
sys/dev/ic/bwfm.c 1.15-1.18
sys/dev/ic/bwfmreg.h 1.4-1.6
sys/dev/ic/bwfmvar.h 1.4,1.5
sys/dev/ic/dwc_mmc.c 1.21,1.22
sys/dev/ic/dwc_mmc_reg.h 1.8,1.9,1.12,1.13
sys/dev/pcmcia/pcmciareg.h 1.11
sys/dev/sdmmc/if_bwfm_sdio.c 1.4,1.6-1.12
sys/dev/sdmmc/if_bwfm_sdio.h 1.1,1.2
sys/dev/sdmmc/sdhc.c 1.105,1.106
sys/dev/sdmmc/sdmmc.c 1.37,1.39
sys/dev/sdmmc/sdmmc_cis.c 1.6,1.8
sys/dev/sdmmc/sdmmc_io.c 1.15-1.19
sys/dev/sdmmc/sdmmc_ioreg.h 1.4,1.5
sys/dev/sdmmc/sdmmc_mem.c 1.69-1.71
sys/dev/sdmmc/sdmmcdevs 1.5-1.8
sys/dev/sdmmc/sdmmcvar.h 1.31,1.33,1.34
sys/net/if_media.h 1.66

Add Broadcom devices
-
Fix typo
-
add PCMCIA_CISTPL_SDIO definition.
-
From OpenBSD:
- move event handling to workqueue
- check for save/restore capability
-
Tag work queue as MPsafe and increase length.
-
Juse use bpf_mtap(), the 802.11 encapsulation is handled by firmware.
-
From OpenBSD:
- support block length per function
- add functions to read/write regions
-
Decode (but not use) SDIO tuple in CIS.
-
Fix locking.
-
Add more SDIO defines (partially from version 3.0).
-
From OpenBSD:
- All the missing pieces (firmware load, chip setup, protocol handling)
TX queue and interrupt handling via sdmmc_task.
-
Fix locking.
-
Fix packet parsing.
-
Add parser for original firmware config files.
-
tagging work queue as MPSAFE was premature. Revert.
-
SD_IO_RW_EXTENDED is a data transfer command, so set ADTC flag instead of AC
Use correct function to verify if a task has been queued. Avoids race
that can corrupt the task queue.
-
More register definitions.
-
Add IFM_IEEE80211_VHT subtype, IFM_IEEE80211_11AC operating mode, and missing descriptions
-
If firmware is connected in HT or VHT mode, report it to SIOCGIFMEDIA
-
white space police.

Skip setting power when the voltage doesn't change.
Also increase some timeouts.
-
Add and use sdmmc_pause to avoid long-term busy waits.
-
Add sdio abort function.
-
Additional error messages.
-
Print parameters for SDIO devices.
-
Minor cosmetics.
-
Simplyfy sdmmc_io_set_blocklen function signature by dropping the
extra softc pointer. Aligns with OpenBSD.
-
Missing commit for sdio abort function.
-
More code from OpenBSD
-
no need to splnet() when enqueing packets
-
explicit structure padding
-
make internal functions static
-
also prepare for GPIO interrupts.
-
Avoid warnings for tautological shifts as sole conditional.
-
Follow the Linux driver an use the FDT "compatible" property to build a
filename for the nvram config file, fall back to the standard filename.
E.g.
[Caching 123 nodes and 1093 properties]
compatible 73696e6f 766f6970 2c627069 2d6d322d "sinovoip,bpi-m2-
0010: 7a65726f 00...... ........ ........ zero"
0015: 616c6c77 696e6e65 722c7375 6e38692d "allwinner,sun8i-
0025: 68322d70 6c757300 ........ ........ h2-plus"
interrupt-parent 00000001 ........ ........ ........ ....
model 42616e61 6e612050 69204250 492d4d32 "Banana Pi BPI-M2
0010: 2d5a6572 6f00.... ........ ........ -Zero"
name 00...... ........ ........ ........ ""
serial-number 30326330 30303432 65636431 36376566 02c00042ecd167ef
0010: 00...... ........ ........ ........ .
-rw-r--r-- 1 root wheel 875 Nov 2 12:06 brcmfmac43430-sdio.AP6212.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 16:19 brcmfmac43430-sdio.sinovoip,bpi-m2-zero.txt -> brcmfmac43430-sdio.AP6212.txt
-rw-r--r-- 1 root wheel 874 Jun 30 2019 brcmfmac43430-sdio.raspberrypi,3-model-b.txt
-rw-r--r-- 1 root wheel 1864 Jun 30 2019 brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 11:24 brcmfmac43455-sdio.raspberrypi,4-model-b-plus.txt -> brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
-
Add product ID for Broadcom BCM43455
-
Use correct firmware for BCM43456
-
size check was backwards.
-
Be less noisy for some commands.
-
Fix DWC_MMC_INT_SDIO_INT bit
-
dwc_mmc fixes:
- Rockchip uses a different SDIO int bit, so take this into consideration
- Avoid unnecessary resets and always wait for resets to complete
- kpause instead of delay while holding spinlock
- Do not attempt autostop for SD_IO_RW_EXTENDED commands
- Allow for sub-blklen byte counts for single block transfers
-
More SDIO stability and performance fixes
 1.6 19-Dec-2019  kamil Avoid changing signedness bit with << in sdmmc_ioreg.h

Reported by <prlw1>
 1.5 28-Oct-2019  mlelstv Missing commit for sdio abort function.
 1.4 01-Sep-2019  mlelstv From OpenBSD:
- support block length per function
- add functions to read/write regions
Decode (but not use) SDIO tuple in CIS.
Fix locking.
Add more SDIO defines (partially from version 3.0).
 1.3 24-Jul-2019  msaitoh branches: 1.3.2;
Define SD_ARG_CMD52_WRITE macro correctly. Found by KUBSan. This macro is
used in sdmmc_io_write_1() and sdmmc_io_reset.
 1.2 07-Oct-2010  kiyohara branches: 1.2.60;
Fix read CIS. And pass to attach args the standard function interface code.
 1.1 21-Apr-2009  nonaka branches: 1.1.2; 1.1.4; 1.1.6; 1.1.8; 1.1.10; 1.1.12; 1.1.14;
Added SD/MMC support from OpenBSD.
tested on i386, amd64 at current-users ML by pgoyette@.
tested on zaurus by myself.
 1.1.14.2 21-Apr-2010  matt sync to netbsd-5
 1.1.14.1 21-Apr-2009  matt file sdmmc_ioreg.h was added on branch matt-nb5-mips64 on 2010-04-21 00:27:52 +0000
 1.1.12.1 05-Mar-2011  rmind sync with head
 1.1.10.1 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.1.8.2 07-Oct-2009  sborrill Pull up the following revisions(s) (requested by jmcneill in ticket #1044):
distrib/sets/lists/man/mi: patch
share/man/man4/Makefile: patch
sys/arch/amd64/conf/files.amd64: 1.67
sys/arch/i386/conf/files.i386: 1.349
sys/conf/files 1.945
share/man/man4/sdmmc.4: 1.1-1.4
sys/dev/sdmmc/Makefile.sdmmcdevs 1.1
sys/dev/sdmmc/devlist2h.awk 1.1
sys/dev/sdmmc/files.sdmmc 1.1-1.2
sys/dev/sdmmc/ld_sdmmc.c 1.1-1.3
sys/dev/sdmmc/sbt.c 1.1-1.2
sys/dev/sdmmc/sdhc.c 1.1-1.3
sys/dev/sdmmc/sdhcreg.h 1.1
sys/dev/sdmmc/sdhcvar.h 1.1
sys/dev/sdmmc/sdmmc.c 1.1
sys/dev/sdmmc/sdmmc_cis.c 1.1
sys/dev/sdmmc/sdmmc_io.c 1.1
sys/dev/sdmmc/sdmmc_ioreg.h 1.1
sys/dev/sdmmc/sdmmc_mem.c 1.1-1.2
sys/dev/sdmmc/sdmmcchip.h 1.1
sys/dev/sdmmc/sdmmcdevs 1.1
sys/dev/sdmmc/sdmmcdevs.h 1.1-1.2
sys/dev/sdmmc/sdmmcreg.h 1.1-1.3
sys/dev/sdmmc/sdmmcvar.h 1.1

Add sdmmc framework
 1.1.8.1 21-Apr-2009  sborrill file sdmmc_ioreg.h was added on branch netbsd-5 on 2009-10-07 15:41:13 +0000
 1.1.6.2 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.1.6.1 21-Apr-2009  jym file sdmmc_ioreg.h was added on branch jym-xensuspend on 2009-05-13 17:21:29 +0000
 1.1.4.3 09-Oct-2010  yamt sync with head
 1.1.4.2 04-May-2009  yamt sync with head.
 1.1.4.1 21-Apr-2009  yamt file sdmmc_ioreg.h was added on branch yamt-nfs-mp on 2009-05-04 08:13:18 +0000
 1.1.2.2 28-Apr-2009  skrll Sync with HEAD.
 1.1.2.1 21-Apr-2009  skrll file sdmmc_ioreg.h was added on branch nick-hppapmap on 2009-04-28 07:36:33 +0000
 1.2.60.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.2.60.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.3.2.2 09-Aug-2020  martin Pull up following revision(s) (requested by mrg in ticket #1042):

sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.19
sys/dev/sdmmc/ld_sdmmc.c: revision 1.38
sys/dev/sdmmc/sdmmcvar.h: revision 1.35
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.5
sys/dev/ic/bwfm.c: revision 1.26
sys/dev/ic/bwfm.c: revision 1.27
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.20
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.21
sys/dev/sdmmc/sdmmc_io.c: revision 1.20
sys/dev/sdmmc/sdmmc_mem.c: revision 1.72
sys/dev/sdmmc/sdmmc.c: revision 1.40
sys/dev/sdmmc/sdmmc_ioreg.h: revision 1.6
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.16

Don't pass empty mbufs to the network stack.

Avoid changing signedness bit with << in sdmmc_ioreg.h
Reported by <prlw1>

If the controller doesn't support switch func (opcode 6) then skip
setting this but continue with other settings. This allows us to use
a card, albeit at a lower speed.

Fix races in sdmmc tasks and teach ld@sdmmc to abort xfers on detach.
- Teach sdmmc_add_task to queue it only if not already queued.
- Remove now-redundant logic to avoid repeated queueing elsewhere.
- Teach sdmmc_del_task to wait until task has completed.
- Call sdmmc_del_task in various needful places.
- Replace abuse of pcq by a lock and a tailq.
(pcq is multi-producer, _single_-consumer, but there are potentially
multiple consumers here and really only one producer.)
- Teach ld_sdmmc to abort xfers on detach.
(Mechanism is kinda kludgey but it'll do for now; any effort one is
tempted to spend overhauling this should be spent overhauling sdmmc
to support proper asynchronous commands.)
- Make sure ld_sdmmc_discard either returns failure or eventually calls
ldenddiscard.

XXX Currently ld_sdmmc_detach aborts xfers _before_ ldbegindetach has
has committed to detaching or not. This is currently necessary to
avoid a deadlock because ldbegindetach waits for xfers to drain --
which strikes me as wrong; ldbegindetach shouldn't wait for anything,
and should only make the decision to commit to detaching or not so
the caller can decide whether to abort xfers before we actually wait
for them in ldenddetach.

XXX pullup -- although this changes some kernel symbols (sdmmc_add_task
and sdmmc_del_task), it shouldn't affect any existing modules; the only
module that uses sdmmc is ld_sdmmc.kmod, which is `.if 0' in the build
so there shouldn't be any of them floating around.

Make this work on big endian machines

move some of the patching of callbacks and other data after
ieee80211_ifattach() but before if_deferred_start_init().
may fix panic i saw in after restarting wpa_supplicant.
from mlelstv.

only ask for SDPCMD_INTSTATUS_HMB_SW_MASK and SDPCMD_INTSTATUS_CHIPACTIVE
interrupts, not all of them. we only ack these ones.
mostly fixes pinebookpro wifi hard hangs. still is problematic and can
trigger interrupt storm that appears as a hard hang without NET_MPSAFE,
and a follow up, less clearly right, change will reduce that to a soft
hang of the interface that can be cleared with 'ifconfig bwfm0 down up',
and even often recovers itself now.

clear all interrupts, not just those we expect from the hostintmask.
this removes the final hard hang i have seen in pinebookpro wifi,
though one may still need to 'ifconfig bwfm0 down up' occasionally,
so we still have bugs to fix here (the hang is usually associated
with 'checksum error' from bwfm/sdio.)

Sort #includes. Nix trailing whitespace.
No functional change intended.
 1.3.2.1 25-Feb-2020  martin Pull up following revision(s) (requested by mrg in ticket #717):

sys/dev/fdt/dwcmmc_fdt.c 1.11
sys/dev/ic/bwfm.c 1.15-1.18
sys/dev/ic/bwfmreg.h 1.4-1.6
sys/dev/ic/bwfmvar.h 1.4,1.5
sys/dev/ic/dwc_mmc.c 1.21,1.22
sys/dev/ic/dwc_mmc_reg.h 1.8,1.9,1.12,1.13
sys/dev/pcmcia/pcmciareg.h 1.11
sys/dev/sdmmc/if_bwfm_sdio.c 1.4,1.6-1.12
sys/dev/sdmmc/if_bwfm_sdio.h 1.1,1.2
sys/dev/sdmmc/sdhc.c 1.105,1.106
sys/dev/sdmmc/sdmmc.c 1.37,1.39
sys/dev/sdmmc/sdmmc_cis.c 1.6,1.8
sys/dev/sdmmc/sdmmc_io.c 1.15-1.19
sys/dev/sdmmc/sdmmc_ioreg.h 1.4,1.5
sys/dev/sdmmc/sdmmc_mem.c 1.69-1.71
sys/dev/sdmmc/sdmmcdevs 1.5-1.8
sys/dev/sdmmc/sdmmcvar.h 1.31,1.33,1.34
sys/net/if_media.h 1.66

Add Broadcom devices
-
Fix typo
-
add PCMCIA_CISTPL_SDIO definition.
-
From OpenBSD:
- move event handling to workqueue
- check for save/restore capability
-
Tag work queue as MPsafe and increase length.
-
Juse use bpf_mtap(), the 802.11 encapsulation is handled by firmware.
-
From OpenBSD:
- support block length per function
- add functions to read/write regions
-
Decode (but not use) SDIO tuple in CIS.
-
Fix locking.
-
Add more SDIO defines (partially from version 3.0).
-
From OpenBSD:
- All the missing pieces (firmware load, chip setup, protocol handling)
TX queue and interrupt handling via sdmmc_task.
-
Fix locking.
-
Fix packet parsing.
-
Add parser for original firmware config files.
-
tagging work queue as MPSAFE was premature. Revert.
-
SD_IO_RW_EXTENDED is a data transfer command, so set ADTC flag instead of AC
Use correct function to verify if a task has been queued. Avoids race
that can corrupt the task queue.
-
More register definitions.
-
Add IFM_IEEE80211_VHT subtype, IFM_IEEE80211_11AC operating mode, and missing descriptions
-
If firmware is connected in HT or VHT mode, report it to SIOCGIFMEDIA
-
white space police.

Skip setting power when the voltage doesn't change.
Also increase some timeouts.
-
Add and use sdmmc_pause to avoid long-term busy waits.
-
Add sdio abort function.
-
Additional error messages.
-
Print parameters for SDIO devices.
-
Minor cosmetics.
-
Simplyfy sdmmc_io_set_blocklen function signature by dropping the
extra softc pointer. Aligns with OpenBSD.
-
Missing commit for sdio abort function.
-
More code from OpenBSD
-
no need to splnet() when enqueing packets
-
explicit structure padding
-
make internal functions static
-
also prepare for GPIO interrupts.
-
Avoid warnings for tautological shifts as sole conditional.
-
Follow the Linux driver an use the FDT "compatible" property to build a
filename for the nvram config file, fall back to the standard filename.
E.g.
[Caching 123 nodes and 1093 properties]
compatible 73696e6f 766f6970 2c627069 2d6d322d "sinovoip,bpi-m2-
0010: 7a65726f 00...... ........ ........ zero"
0015: 616c6c77 696e6e65 722c7375 6e38692d "allwinner,sun8i-
0025: 68322d70 6c757300 ........ ........ h2-plus"
interrupt-parent 00000001 ........ ........ ........ ....
model 42616e61 6e612050 69204250 492d4d32 "Banana Pi BPI-M2
0010: 2d5a6572 6f00.... ........ ........ -Zero"
name 00...... ........ ........ ........ ""
serial-number 30326330 30303432 65636431 36376566 02c00042ecd167ef
0010: 00...... ........ ........ ........ .
-rw-r--r-- 1 root wheel 875 Nov 2 12:06 brcmfmac43430-sdio.AP6212.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 16:19 brcmfmac43430-sdio.sinovoip,bpi-m2-zero.txt -> brcmfmac43430-sdio.AP6212.txt
-rw-r--r-- 1 root wheel 874 Jun 30 2019 brcmfmac43430-sdio.raspberrypi,3-model-b.txt
-rw-r--r-- 1 root wheel 1864 Jun 30 2019 brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 11:24 brcmfmac43455-sdio.raspberrypi,4-model-b-plus.txt -> brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
-
Add product ID for Broadcom BCM43455
-
Use correct firmware for BCM43456
-
size check was backwards.
-
Be less noisy for some commands.
-
Fix DWC_MMC_INT_SDIO_INT bit
-
dwc_mmc fixes:
- Rockchip uses a different SDIO int bit, so take this into consideration
- Avoid unnecessary resets and always wait for resets to complete
- kpause instead of delay while holding spinlock
- Do not attempt autostop for SD_IO_RW_EXTENDED commands
- Allow for sub-blklen byte counts for single block transfers
-
More SDIO stability and performance fixes
 1.77 24-Oct-2024  skrll Don't stop sd card initialization early when bus clock is already set
to the target rate.

From jmnceill@ and tested by me on beagle-v.
 1.76 18-Oct-2024  jmcneill sdmmc: Add support for SD card caches.

SD physical 6.0 specification introduced Application Performance Class 2
(A2), which adds support for drive caches and command queueing.

Add support for enabling and flushing the cache when this feature is
present.
 1.75 29-Apr-2023  jmcneill branches: 1.75.6;
sdmmc: Only check chipset WP status for SD cards.

The sdmmc_chip_write_protect callback returns the write protect switch
status from the controller (SDWP#). This signal does not exist for eMMC;
instead, write protect is signaled using card registers (CSD). So lets
skip asking the chipset for WP status on eMMC cards for each write
request.
 1.74 03-Aug-2021  msaitoh branches: 1.74.8;
Use unsigned to avoid undefined behavior in sdmmc_mem_sd_switch().
Found by kUBSan.
 1.73 13-Jun-2021  mlelstv Be less verbose normally and more when debugging.
 1.72 11-May-2020  jdc branches: 1.72.6;
If the controller doesn't support switch func (opcode 6) then skip
setting this but continue with other settings. This allows us to use
a card, albeit at a lower speed.
 1.71 04-Jan-2020  mlelstv Be less noisy for some commands.
 1.70 28-Oct-2019  mlelstv Whitespace police
 1.69 28-Oct-2019  mlelstv Add and use sdmmc_pause to avoid long-term busy waits.
Add sdio abort function.
Additional error messages.
Print parameters for SDIO devices.
Minor cosmetics.
 1.68 06-Jun-2019  jmcneill branches: 1.68.2;
If setting HS_TIMING fails, keep trying slower speeds instead of bailing
out.
 1.67 28-May-2019  jmcneill If a mem function fails to initialize, set the error flag so sdmmc doesn't try to use it anyway.
 1.66 09-Nov-2018  jmcneill Wait for data ready after eMMC flush cache commands
 1.65 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

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

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

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

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

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

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

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.64 07-Feb-2018  bouyer branches: 1.64.2; 1.64.4;
Fix uninitialized variable use:
if there is an error, or if we are using a SPI controller,
sdmmc_mem_send_op_cond() doens't assign a value to *ocrp,
but it is used unconditionally in sdmmc_mem_enable() to see if we can switch
to low voltage.

In sdmmc_mem_send_op_cond(), if the new ocr is not returned by the
card for whatever reason, set *ocrp to the orig value.
 1.63 12-Sep-2017  jmcneill For SD cards, send the SET_WR_BLK_ERASE_COUNT app command before a
multi-block write to improve write performance.
 1.62 20-Aug-2017  mlelstv make the sc_discard interface for the ld backend asynchronous and
signal completion through new callback lddiscardend. Use a standard
struct buf to pass disk address and range instead of two off_t values.

make lddiscard synchronous again. This is a requirement of the current
ffs discard code.
 1.61 16-Jul-2017  jmcneill branches: 1.61.2;
Add support for eMMC 4.5's optional cache feature. If a cache is present,
and the host controller reports the SMC_CAPS_POLLING capability (needed
to flush cache at shutdown), it will be automatically enabled and used.
 1.60 24-Jun-2017  jmcneill Revert part of previous; the SD card spec recommends not to issue a DISCARD
command to the file system area.
 1.59 24-Jun-2017  jmcneill Read SD status register and print card status when a new SD card is found:

sdmmc0: SD card status: 4-bit, C10, U1, V10

If the SD status register reports discard support, set the DISCARD arg to
the ERASE operation to let the card know that the host doesn't care if the
erase is performed.
 1.58 24-Jun-2017  jmcneill Add discard support to ld@sdmmc using the ERASE (CMD38) command.
 1.57 04-Jun-2017  jmcneill Give a hint to controllers in the command flags if we are performing a
transfer with an SDHC capable card. If the controller needs to adjust
command args, it can use this hint to understand how it is encoded.
 1.56 11-Apr-2017  jmcneill branches: 1.56.4;
Remove a test that prevents tuning from happening on eMMC devices.
 1.55 17-Feb-2017  nonaka sdhc(4): hardware reset support for Intel eMMC controller
 1.54 17-Feb-2017  nonaka sdhc(4), sdmmc(4): Added MMC HS DDR52 support.
 1.53 17-Feb-2017  nonaka sdmmc(4): Use EXT_CSD[HS_TIMING] definitions.
 1.52 11-Aug-2016  nonaka branches: 1.52.2;
Fix incorrect sector counts with MMC.
 1.51 13-Mar-2016  tsutsui branches: 1.51.2;
Call the second sdmmc_mem_send_if_cond() only where it's necessary.

This makes SMC_CAPS_SPI_MODE devices (currently evbsh3 only) work again.
"Maybe ok" from nonaka@.
 1.50 22-Dec-2015  mlelstv Be graceful about command timeouts when probing.
 1.49 29-Nov-2015  jmcneill Add some event counters to track transfer sizes.
 1.48 29-Oct-2015  jmcneill After setting HS_TIMING value for HS200 or later, send repeated SEND_STATUS
command until the device is no longer busy or the SWITCH_ERROR bit is set.
 1.47 06-Oct-2015  mlelstv support hiding command timeout messages with a new command flag and use this
when probing for cards. Should fix PR 50302.
 1.46 08-Aug-2015  jmcneill eMMC fixes
 1.45 05-Aug-2015  jmcneill Add support for sampling clock tuning, required for some UHS modes and
MMC HS200.
 1.44 04-Aug-2015  jmcneill ODROID-C1 has a bug where the card is not power-cycled when the board is
reset. If you had previously switched to 1.8V signaling level, upon reboot
the card will still be in 1.8V mode and you cannot detect it with an S18R
request.

A card in 1.8V mode will report UHS modes though, so if the card reports
SDR50, DDR50, or SDR104 capabilities, and the previous S18R request failed
to switch, use this as an opportunity to re-enable UHS support in the
subsystem and host controller drivers.
 1.43 04-Aug-2015  jmcneill instead of trying to handle cards already in 1.8V mode, request host controller to switch to 3.3V signaling before starting the init sequence
 1.42 03-Aug-2015  jmcneill Handle cards that are already in low voltage (1.8V) mode. Test correct
bit when determining the best SD transfer mode.
 1.41 03-Aug-2015  jmcneill clear SMF_UHS_MODE flag before enabling card
 1.40 03-Aug-2015  jmcneill fix SDMMC_DEBUG build
 1.39 03-Aug-2015  jmcneill Add support for DDR50 transfer modes.
 1.38 03-Aug-2015  mlelstv use mutex locking for MP safety.
 1.37 03-Aug-2015  mlelstv more debug output
 1.36 02-Aug-2015  jmcneill Add support for eMMC 5.0 HS200 timings.
 1.35 02-Aug-2015  jmcneill Add basic UHS-I support. SDR50 and SDR104 are supported, but not DDR50.
 1.34 27-Feb-2015  nonaka fix to simulate multi-segment dma transfer for pq3sdhc(4).
 1.33 07-Feb-2015  christos Return an actual error. Reported by:
http://www.m00nbsd.net/ae123a9bae03f7dde5c6d654412daf5a.html#Report-4
 1.32 07-Dec-2014  jmcneill Fix high capacity (> 2GB) eMMC support, from OpenBSD.
 1.31 19-Mar-2014  nonaka branches: 1.31.4; 1.31.6;
Add a driver for Realtek RTS5209/RTS5229 Card Reader.
Ported from OpenBSD.
 1.30 25-Oct-2013  martin Turn a few __unused into __diagused
 1.29 03-May-2013  matt branches: 1.29.4;
Add support for the valid card types in eMMC v4.4 (needed by beaglebone
black).
 1.28 03-May-2013  matt Fix typo.
 1.27 20-Dec-2012  jakllsch fix off-by-one in switch function argument validation.
 1.26 15-Dec-2012  jakllsch Correctly read the 512-bit-wide big-endian Switch Function Status register.
Some of this could/will also be useful for the SD Status register.
 1.25 14-Dec-2012  jakllsch The Card Command Class (CCC) field is valid in both SD_CSD_CSDVER_1_0
and SD_CSD_CSDVER_2_0.
 1.24 13-Oct-2012  kiyohara Fix variable name for message of printf.
 1.23 26-Jul-2012  matt branches: 1.23.2;
Fix a delay to a correct value.
 1.22 23-Jul-2012  matt Responses are actually in host order (except SCR which is return in
big endian so that's convert to host order).
 1.21 20-Jul-2012  matt Add use of watermark register when PIO to an ESDHC. After every kill or
drain of watermask words, pause a bit to give time for the fifo to recover.
Always the command response in BE byteorder. Rewrite __bitfield to deal
with this.
 1.20 01-Feb-2012  matt branches: 1.20.2;
Use "opt_sdmmc.h" for SDMMC_DEBUG, etc.
 1.19 27-Jan-2012  matt Fix sdmmmc_mem_decode_scr for BE machines.
 1.18 21-Jan-2012  nonaka fix my license notice.
 1.17 13-Feb-2011  nonaka branches: 1.17.4; 1.17.8;
use MMC_CSD_CSDVER_EXT_CSD.
 1.16 13-Feb-2011  nonaka - Don't switch MMC high-speed timing, if host controller isn't supported.
- Only check EXT_CSD STRUCTURE version when CSD version is 3.
- initialize width at sdmmc_function_alloc().
 1.15 05-Feb-2011  nonaka Don't switch SD high-speed timing, if host controller isn't supported.
 1.14 13-Nov-2010  uebayasi branches: 1.14.2; 1.14.4;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.13 07-Oct-2010  kiyohara Support High-Speed mode.
 1.12 01-Oct-2010  kiyohara Use DMA bounce buffer, if DMA buffer is making by multiple segments. A lot
of host controllers do not support to two or more segments.
 1.11 23-Sep-2010  kiyohara Print bus width and clock for feature(High speed support).
 1.10 21-Sep-2010  kiyohara Fix build failure.
A new variable width and value had been forgotten since r1.7.
 1.9 20-Sep-2010  kiyohara Clean up return/error in sdmem_mem_send_scr().
 1.8 20-Sep-2010  kiyohara Fix SCR data.
 1.7 20-Sep-2010  kiyohara Support MMC 4,8-bit mode.
It tested only 4bit on Marvell Sheevaplug.
 1.6 20-Sep-2010  kiyohara Sync with POSTREAD before memcpy.
 1.5 01-May-2010  reinoud Initialise error variable to zero. If all the if's fail it exists the function
sdmmc_init returning the then still uninitialised variable.

gcc can't know if one of the if's is bound to happen.

Detected with -DDEBUG -DDIAGNOSTIC -DKGDB - ...
 1.4 06-Apr-2010  nonaka branches: 1.4.2;
- mention MMC SPI mode.
- support SD 4bit bus width mode.
 1.3 28-Nov-2009  nonaka branches: 1.3.2; 1.3.4;
Always sector size is treated as 512 bytes.
 1.2 24-May-2009  nonaka branches: 1.2.2;
SDHC card was able to be used.
 1.1 21-Apr-2009  nonaka branches: 1.1.2; 1.1.4; 1.1.6;
Added SD/MMC support from OpenBSD.
tested on i386, amd64 at current-users ML by pgoyette@.
tested on zaurus by myself.
 1.1.6.3 23-Jul-2009  jym Sync with HEAD.
 1.1.6.2 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.1.6.1 21-Apr-2009  jym file sdmmc_mem.c was added on branch jym-xensuspend on 2009-05-13 17:21:29 +0000
 1.1.4.6 09-Oct-2010  yamt sync with head
 1.1.4.5 11-Aug-2010  yamt sync with head.
 1.1.4.4 11-Mar-2010  yamt sync with head
 1.1.4.3 20-Jun-2009  yamt sync with head
 1.1.4.2 04-May-2009  yamt sync with head.
 1.1.4.1 21-Apr-2009  yamt file sdmmc_mem.c was added on branch yamt-nfs-mp on 2009-05-04 08:13:18 +0000
 1.1.2.2 28-Apr-2009  skrll Sync with HEAD.
 1.1.2.1 21-Apr-2009  skrll file sdmmc_mem.c was added on branch nick-hppapmap on 2009-04-28 07:36:33 +0000
 1.2.2.3 02-Dec-2009  sborrill Pull up the following revisions(s) (requested by nonaka in ticket #1167):
sys/dev/sdmmc/ld_sdmmc.c: revision 1.4
sys/dev/sdmmc/sdmmc_mem.c: revision 1.3
sys/dev/sdmmc/sdmmcvar.h: revision 1.2

Always treat sector size as 512 bytes.
 1.2.2.2 07-Oct-2009  sborrill Pull up the following revisions(s) (requested by jmcneill in ticket #1044):
distrib/sets/lists/man/mi: patch
share/man/man4/Makefile: patch
sys/arch/amd64/conf/files.amd64: 1.67
sys/arch/i386/conf/files.i386: 1.349
sys/conf/files 1.945
share/man/man4/sdmmc.4: 1.1-1.4
sys/dev/sdmmc/Makefile.sdmmcdevs 1.1
sys/dev/sdmmc/devlist2h.awk 1.1
sys/dev/sdmmc/files.sdmmc 1.1-1.2
sys/dev/sdmmc/ld_sdmmc.c 1.1-1.3
sys/dev/sdmmc/sbt.c 1.1-1.2
sys/dev/sdmmc/sdhc.c 1.1-1.3
sys/dev/sdmmc/sdhcreg.h 1.1
sys/dev/sdmmc/sdhcvar.h 1.1
sys/dev/sdmmc/sdmmc.c 1.1
sys/dev/sdmmc/sdmmc_cis.c 1.1
sys/dev/sdmmc/sdmmc_io.c 1.1
sys/dev/sdmmc/sdmmc_ioreg.h 1.1
sys/dev/sdmmc/sdmmc_mem.c 1.1-1.2
sys/dev/sdmmc/sdmmcchip.h 1.1
sys/dev/sdmmc/sdmmcdevs 1.1
sys/dev/sdmmc/sdmmcdevs.h 1.1-1.2
sys/dev/sdmmc/sdmmcreg.h 1.1-1.3
sys/dev/sdmmc/sdmmcvar.h 1.1

Add sdmmc framework
 1.2.2.1 24-May-2009  sborrill file sdmmc_mem.c was added on branch netbsd-5 on 2009-10-07 15:41:13 +0000
 1.3.4.2 05-Mar-2011  rmind sync with head
 1.3.4.1 30-May-2010  rmind sync with head
 1.3.2.3 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.3.2.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.3.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.4.2.2 21-Apr-2010  matt sync to netbsd-5
 1.4.2.1 06-Apr-2010  matt file sdmmc_mem.c was added on branch matt-nb5-mips64 on 2010-04-21 00:27:52 +0000
 1.14.4.2 17-Feb-2011  bouyer Sync with HEAD
 1.14.4.1 08-Feb-2011  bouyer Sync with HEAD
 1.14.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.17.8.1 18-Feb-2012  mrg merge to -current.
 1.17.4.4 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.17.4.3 23-Jan-2013  yamt sync with head
 1.17.4.2 30-Oct-2012  yamt sync with head
 1.17.4.1 17-Apr-2012  yamt sync with head
 1.20.2.1 08-Aug-2012  jdc Pull up revisions:
src/sys/dev/sdmmc/sdhc.c revisions 1.16,1.20,1.21,1.22,1.23 via patch,1.25
src/sys/dev/sdmmc/sdhcreg.h revision 1.8
src/sys/dev/sdmmc/sdmmc_mem.c revisions 1.21,1.22
src/sys/dev/sdmmc/sdmmcreg.h revisions 1.10,1.11,1.12
(requested by matt in ticket 441).

SDHCI byte swaps the BE response on the wire into LE registers.
As we always want response data in LE, use bus_space_read_stream.
Additonally, read response data in 1 or 4 4-byte chunks, instead of
one 4-byte chunk or 15 1-byte chunks.

bus_space_*_stream_N() functions are not universally available.
Provite alternate implementation for when they are unavailable.

Handle interrupt acknowledgement in the SDHC_FLAG_32BIT_ACCESS case in
the same way as non-SDHC_FLAG_32BIT_ACCESS case.

If there was an error in 32-bit mode, just set ERROR_INTERRUPT otherwise
see if matched anything we care about.

Add use of watermark register when PIO to an ESDHC. After every kill or
drain of watermask words, pause a bit to give time for the fifo to recover.
Always the command response in BE byteorder. Rewrite __bitfield to deal
with this.

Responses are actually in host order (except SCR which is return in
big endian so that's convert to host order).

Fix comments about __bitfield.
 1.23.2.5 03-Dec-2017  jdolecek update from HEAD
 1.23.2.4 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.23.2.3 23-Jun-2013  tls resync from head
 1.23.2.2 25-Feb-2013  tls resync with head
 1.23.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.29.4.1 18-May-2014  rmind sync with head
 1.31.6.6 28-Aug-2017  skrll Sync with HEAD
 1.31.6.5 05-Oct-2016  skrll Sync with HEAD
 1.31.6.4 19-Mar-2016  skrll Sync with HEAD
 1.31.6.3 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.31.6.2 22-Sep-2015  skrll Sync with HEAD
 1.31.6.1 06-Apr-2015  skrll Sync with HEAD
 1.31.4.2 09-Mar-2015  snj Pull up following revision(s) (requested by nonaka in ticket #577):
sys/dev/sdmmc/sdmmc_mem.c: revision 1.34
sys/dev/sdmmc/sdmmcvar.h: revision 1.16
fix to simulate multi-segment dma transfer for pq3sdhc(4).
 1.31.4.1 16-Feb-2015  martin Pull up following revision(s) (requested by maxv in ticket #520):
sys/ufs/chfs/ebh.c: revision 1.6
sys/dev/sdmmc/sdmmc_mem.c: revision 1.33
sys/dev/ic/aic7xxx.c: revision 1.132
sys/fs/nfs/common/krpc_subr.c: revision 1.2
sys/modules/lua/lua.c: revision 1.16
sys/fs/udf/udf_subr.c: revision 1.128
sys/ufs/chfs/chfs_scan.c: revision 1.6
sys/dev/ic/an.c: revision 1.62

Fix six memory leaks and two inconsistencies.
 1.51.2.2 26-Apr-2017  pgoyette Sync with HEAD
 1.51.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.52.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.56.4.6 03-Dec-2021  martin Pull up the following revisions (all via patch), requested by msaitoh
in ticket #1713:

sys/dev/sdmmc/sdhc.c 1.110, 1.112
sys/dev/sdmmc/sdmmc_mem.c 1.74
sys/dev/pci/sdhc_pci.c 1.18

- Support 64bit BAR.
- Use unsigned to avoid undefined behavior in hwrite[12]() and
sdmmc_mem_sd_switch().
- Fix typo in comment.
 1.56.4.5 11-Feb-2018  snj Pull up following revision(s) (requested by bouyer in ticket #537):
sys/dev/sdmmc/sdmmc_mem.c: revision 1.64
Fix uninitialized variable use:
if there is an error, or if we are using a SPI controller,
sdmmc_mem_send_op_cond() doens't assign a value to *ocrp,
but it is used unconditionally in sdmmc_mem_enable() to see if we can switch
to low voltage.
In sdmmc_mem_send_op_cond(), if the new ocr is not returned by the
card for whatever reason, set *ocrp to the orig value.
 1.56.4.4 01-Sep-2017  martin Pull up following revision(s) (requested by mlelstv in ticket #261):
sys/dev/sdmmc/ld_sdmmc.c: revision 1.32
sys/dev/sdmmc/ld_sdmmc.c: revision 1.33
sys/dev/sdmmc/ld_sdmmc.c: revision 1.34
sys/dev/sdmmc/sdmmc_mem.c: revision 1.62
sys/dev/i2o/ld_iop.c: revision 1.39
sys/dev/ld.c: revision 1.102
sys/dev/ld.c: revision 1.103
sys/dev/dksubr.c: revision 1.98
sys/dev/dksubr.c: revision 1.99
sys/dev/sdmmc/sdmmcvar.h: revision 1.29
sys/dev/ic/ld_nvme.c: revision 1.17
sys/dev/ldvar.h: revision 1.31
sys/dev/ldvar.h: revision 1.32
sys/dev/ic/ld_cac.c: revision 1.31
sys/dev/pci/ld_virtio.c: revision 1.16
While ld(4) is MP safe, many backends are not.
Add a flag for backends that are MP safe. Take KERNEL_LOCK when calling
into a backend that doesn't have the flag set. Do the same for the
discard routine.
Fixes PR 52462.
Defer sdmmc discard operations to the sdmmc task queue. Fixes a panic
introduced by ld.c r1.102.
validate length for discard operation and split operation when byte length
doesn't fit into 'int'.
make the sc_discard interface for the ld backend asynchronous and
signal completion through new callback lddiscardend. Use a standard
struct buf to pass disk address and range instead of two off_t values.
make lddiscard synchronous again. This is a requirement of the current
ffs discard code.
Initialize error also in the case where len=0, which just succeeds.
while here, assert that the len is indeed non-negative. this is already
confirmed by sys_fdiscard, but let's be sure.
reported by: GCC, but with different compile flags
 1.56.4.3 25-Jul-2017  snj Pull up following revision(s) (requested by jmcneill in ticket #139):
sys/arch/arm/sunxi/sunxi_mmc.c: revision 1.2
sys/dev/sdmmc/ld_sdmmc.c: revision 1.31
sys/dev/sdmmc/sdmmc_mem.c: revision 1.61
sys/dev/sdmmc/sdmmcreg.h: revision 1.32
sys/dev/sdmmc/sdmmcvar.h: revision 1.28
Add support for eMMC 4.5's optional cache feature. If a cache is present,
and the host controller reports the SMC_CAPS_POLLING capability (needed
to flush cache at shutdown), it will be automatically enabled and used.
--
Add SMC_CAPS_POLLING support.
 1.56.4.2 01-Jul-2017  snj Pull up following revision(s) (requested by jmcneill in ticket #67):
sys/dev/sdmmc/ld_sdmmc.c: 1.28
sys/dev/sdmmc/sdmmc_mem.c: 1.58-1.60
sys/dev/sdmmc/sdmmcreg.h: 1.30, 1.31
sys/dev/sdmmc/sdmmcvar.h: 1.25-1.27
Add discard support to ld@sdmmc using the ERASE (CMD38) command.
--
Read SD status register and print card status when a new SD card is found:
sdmmc0: SD card status: 4-bit, C10, U1, V10
If the SD status register reports discard support, set the DISCARD arg to
the ERASE operation to let the card know that the host doesn't care if the
erase is performed.
--
Revert part of previous; the SD card spec recommends not to issue a DISCARD
command to the file system area.
 1.56.4.1 04-Jun-2017  bouyer Pull up following revision(s) (requested by jmcneill in ticket #3):
sys/dev/sdmmc/sdmmcvar.h: revision 1.24
sys/dev/sdmmc/sdmmc_mem.c: revision 1.57
sys/dev/ic/pl181.c: revision 1.4
Give a hint to controllers in the command flags if we are performing a
transfer with an SDHC capable card. If the controller needs to adjust
command args, it can use this hint to understand how it is encoded.
Re-introduce support for multi-block transfers and split transfers to fit
within the 65535-byte limit.
 1.61.2.2 16-Jul-2017  jmcneill 2978427
 1.61.2.1 16-Jul-2017  jmcneill file sdmmc_mem.c was added on branch perseant-stdc-iso10646 on 2017-07-16 17:11:47 +0000
 1.64.4.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.64.4.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.64.4.1 10-Jun-2019  christos Sync with HEAD
 1.64.2.2 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.64.2.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.68.2.3 03-Dec-2021  martin Pull up the followin revisions (all via patch), requested by msaitoh
in ticket #1383:

sys/dev/sdmmc/sdhc.c 1.110, 1.112
sys/dev/sdmmc/sdmmc_mem.c 1.74
sys/dev/pci/sdhc_pci.c 1.18

- Support 64bit BAR.
- Use unsigned to avoid undefined behavior in hwrite[12]() and
sdmmc_mem_sd_switch().
- Fix typo in comment.
 1.68.2.2 09-Aug-2020  martin Pull up following revision(s) (requested by mrg in ticket #1042):

sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.19
sys/dev/sdmmc/ld_sdmmc.c: revision 1.38
sys/dev/sdmmc/sdmmcvar.h: revision 1.35
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.5
sys/dev/ic/bwfm.c: revision 1.26
sys/dev/ic/bwfm.c: revision 1.27
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.20
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.21
sys/dev/sdmmc/sdmmc_io.c: revision 1.20
sys/dev/sdmmc/sdmmc_mem.c: revision 1.72
sys/dev/sdmmc/sdmmc.c: revision 1.40
sys/dev/sdmmc/sdmmc_ioreg.h: revision 1.6
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.16

Don't pass empty mbufs to the network stack.

Avoid changing signedness bit with << in sdmmc_ioreg.h
Reported by <prlw1>

If the controller doesn't support switch func (opcode 6) then skip
setting this but continue with other settings. This allows us to use
a card, albeit at a lower speed.

Fix races in sdmmc tasks and teach ld@sdmmc to abort xfers on detach.
- Teach sdmmc_add_task to queue it only if not already queued.
- Remove now-redundant logic to avoid repeated queueing elsewhere.
- Teach sdmmc_del_task to wait until task has completed.
- Call sdmmc_del_task in various needful places.
- Replace abuse of pcq by a lock and a tailq.
(pcq is multi-producer, _single_-consumer, but there are potentially
multiple consumers here and really only one producer.)
- Teach ld_sdmmc to abort xfers on detach.
(Mechanism is kinda kludgey but it'll do for now; any effort one is
tempted to spend overhauling this should be spent overhauling sdmmc
to support proper asynchronous commands.)
- Make sure ld_sdmmc_discard either returns failure or eventually calls
ldenddiscard.

XXX Currently ld_sdmmc_detach aborts xfers _before_ ldbegindetach has
has committed to detaching or not. This is currently necessary to
avoid a deadlock because ldbegindetach waits for xfers to drain --
which strikes me as wrong; ldbegindetach shouldn't wait for anything,
and should only make the decision to commit to detaching or not so
the caller can decide whether to abort xfers before we actually wait
for them in ldenddetach.

XXX pullup -- although this changes some kernel symbols (sdmmc_add_task
and sdmmc_del_task), it shouldn't affect any existing modules; the only
module that uses sdmmc is ld_sdmmc.kmod, which is `.if 0' in the build
so there shouldn't be any of them floating around.

Make this work on big endian machines

move some of the patching of callbacks and other data after
ieee80211_ifattach() but before if_deferred_start_init().
may fix panic i saw in after restarting wpa_supplicant.
from mlelstv.

only ask for SDPCMD_INTSTATUS_HMB_SW_MASK and SDPCMD_INTSTATUS_CHIPACTIVE
interrupts, not all of them. we only ack these ones.
mostly fixes pinebookpro wifi hard hangs. still is problematic and can
trigger interrupt storm that appears as a hard hang without NET_MPSAFE,
and a follow up, less clearly right, change will reduce that to a soft
hang of the interface that can be cleared with 'ifconfig bwfm0 down up',
and even often recovers itself now.

clear all interrupts, not just those we expect from the hostintmask.
this removes the final hard hang i have seen in pinebookpro wifi,
though one may still need to 'ifconfig bwfm0 down up' occasionally,
so we still have bugs to fix here (the hang is usually associated
with 'checksum error' from bwfm/sdio.)

Sort #includes. Nix trailing whitespace.
No functional change intended.
 1.68.2.1 25-Feb-2020  martin Pull up following revision(s) (requested by mrg in ticket #717):

sys/dev/fdt/dwcmmc_fdt.c 1.11
sys/dev/ic/bwfm.c 1.15-1.18
sys/dev/ic/bwfmreg.h 1.4-1.6
sys/dev/ic/bwfmvar.h 1.4,1.5
sys/dev/ic/dwc_mmc.c 1.21,1.22
sys/dev/ic/dwc_mmc_reg.h 1.8,1.9,1.12,1.13
sys/dev/pcmcia/pcmciareg.h 1.11
sys/dev/sdmmc/if_bwfm_sdio.c 1.4,1.6-1.12
sys/dev/sdmmc/if_bwfm_sdio.h 1.1,1.2
sys/dev/sdmmc/sdhc.c 1.105,1.106
sys/dev/sdmmc/sdmmc.c 1.37,1.39
sys/dev/sdmmc/sdmmc_cis.c 1.6,1.8
sys/dev/sdmmc/sdmmc_io.c 1.15-1.19
sys/dev/sdmmc/sdmmc_ioreg.h 1.4,1.5
sys/dev/sdmmc/sdmmc_mem.c 1.69-1.71
sys/dev/sdmmc/sdmmcdevs 1.5-1.8
sys/dev/sdmmc/sdmmcvar.h 1.31,1.33,1.34
sys/net/if_media.h 1.66

Add Broadcom devices
-
Fix typo
-
add PCMCIA_CISTPL_SDIO definition.
-
From OpenBSD:
- move event handling to workqueue
- check for save/restore capability
-
Tag work queue as MPsafe and increase length.
-
Juse use bpf_mtap(), the 802.11 encapsulation is handled by firmware.
-
From OpenBSD:
- support block length per function
- add functions to read/write regions
-
Decode (but not use) SDIO tuple in CIS.
-
Fix locking.
-
Add more SDIO defines (partially from version 3.0).
-
From OpenBSD:
- All the missing pieces (firmware load, chip setup, protocol handling)
TX queue and interrupt handling via sdmmc_task.
-
Fix locking.
-
Fix packet parsing.
-
Add parser for original firmware config files.
-
tagging work queue as MPSAFE was premature. Revert.
-
SD_IO_RW_EXTENDED is a data transfer command, so set ADTC flag instead of AC
Use correct function to verify if a task has been queued. Avoids race
that can corrupt the task queue.
-
More register definitions.
-
Add IFM_IEEE80211_VHT subtype, IFM_IEEE80211_11AC operating mode, and missing descriptions
-
If firmware is connected in HT or VHT mode, report it to SIOCGIFMEDIA
-
white space police.

Skip setting power when the voltage doesn't change.
Also increase some timeouts.
-
Add and use sdmmc_pause to avoid long-term busy waits.
-
Add sdio abort function.
-
Additional error messages.
-
Print parameters for SDIO devices.
-
Minor cosmetics.
-
Simplyfy sdmmc_io_set_blocklen function signature by dropping the
extra softc pointer. Aligns with OpenBSD.
-
Missing commit for sdio abort function.
-
More code from OpenBSD
-
no need to splnet() when enqueing packets
-
explicit structure padding
-
make internal functions static
-
also prepare for GPIO interrupts.
-
Avoid warnings for tautological shifts as sole conditional.
-
Follow the Linux driver an use the FDT "compatible" property to build a
filename for the nvram config file, fall back to the standard filename.
E.g.
[Caching 123 nodes and 1093 properties]
compatible 73696e6f 766f6970 2c627069 2d6d322d "sinovoip,bpi-m2-
0010: 7a65726f 00...... ........ ........ zero"
0015: 616c6c77 696e6e65 722c7375 6e38692d "allwinner,sun8i-
0025: 68322d70 6c757300 ........ ........ h2-plus"
interrupt-parent 00000001 ........ ........ ........ ....
model 42616e61 6e612050 69204250 492d4d32 "Banana Pi BPI-M2
0010: 2d5a6572 6f00.... ........ ........ -Zero"
name 00...... ........ ........ ........ ""
serial-number 30326330 30303432 65636431 36376566 02c00042ecd167ef
0010: 00...... ........ ........ ........ .
-rw-r--r-- 1 root wheel 875 Nov 2 12:06 brcmfmac43430-sdio.AP6212.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 16:19 brcmfmac43430-sdio.sinovoip,bpi-m2-zero.txt -> brcmfmac43430-sdio.AP6212.txt
-rw-r--r-- 1 root wheel 874 Jun 30 2019 brcmfmac43430-sdio.raspberrypi,3-model-b.txt
-rw-r--r-- 1 root wheel 1864 Jun 30 2019 brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 11:24 brcmfmac43455-sdio.raspberrypi,4-model-b-plus.txt -> brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
-
Add product ID for Broadcom BCM43455
-
Use correct firmware for BCM43456
-
size check was backwards.
-
Be less noisy for some commands.
-
Fix DWC_MMC_INT_SDIO_INT bit
-
dwc_mmc fixes:
- Rockchip uses a different SDIO int bit, so take this into consideration
- Avoid unnecessary resets and always wait for resets to complete
- kpause instead of delay while holding spinlock
- Do not attempt autostop for SD_IO_RW_EXTENDED commands
- Allow for sub-blklen byte counts for single block transfers
-
More SDIO stability and performance fixes
 1.72.6.1 17-Jun-2021  thorpej Sync w/ HEAD.
 1.74.8.2 26-Oct-2024  martin Pull up following revision(s) (requested by jmcneill in ticket #985):

sys/dev/sdmmc/sdmmcvar.h: revision 1.37
sys/dev/sdmmc/sdmmcreg.h: revision 1.35
sys/dev/sdmmc/ld_sdmmc.c: revision 1.44
sys/dev/sdmmc/sdmmc_mem.c: revision 1.76

sdmmc: Add support for SD card caches.

SD physical 6.0 specification introduced Application Performance Class 2
(A2), which adds support for drive caches and command queueing.

Add support for enabling and flushing the cache when this feature is
present.
 1.74.8.1 30-Apr-2023  martin Pull up following revision(s) (requested by jmcneill in ticket #151):

sys/dev/sdmmc/sdmmc_mem.c: revision 1.75

sdmmc: Only check chipset WP status for SD cards.

The sdmmc_chip_write_protect callback returns the write protect switch
status from the controller (SDWP#). This signal does not exist for eMMC;
instead, write protect is signaled using card registers (CSD). So lets
skip asking the chipset for WP status on eMMC cards for each write
request.
 1.75.6.1 02-Aug-2025  perseant Sync with HEAD
 1.10 23-Oct-2019  hkenken Add SDHC flags.

+ SDHC_FLAG_BROKEN_ADMA2_ZEROLEN
Broken ADMA2 Zero length descriptor.
Can't 64K Byte data transfer.
+ SDHC_FLAG_NO_1_8_V
Support no 1.8V Supply.
Disable UHS-I bus speed mode (SDR50, DDR50, SDR104).
 1.9 17-Feb-2017  nonaka branches: 1.9.14;
sdhc(4): hardware reset support for Intel eMMC controller
 1.8 17-Feb-2017  nonaka sdhc(4), sdmmc(4): Added MMC HS DDR52 support.
 1.7 05-Aug-2015  jmcneill branches: 1.7.2; 1.7.4;
Add support for sampling clock tuning, required for some UHS modes and
MMC HS200.
 1.6 03-Aug-2015  jmcneill Add support for DDR50 transfer modes.
 1.5 02-Aug-2015  jmcneill Add basic UHS-I support. SDR50 and SDR104 are supported, but not DDR50.
 1.4 18-May-2011  dyoung branches: 1.4.14; 1.4.32;
#include <sys/bus.h>, not <machine/bus.h>.
 1.3 07-Oct-2010  kiyohara branches: 1.3.2;
Add bus_rod. It use to change to Data Transfer mode.
 1.2 06-Apr-2010  nonaka branches: 1.2.2;
- mention MMC SPI mode.
- support SD 4bit bus width mode.
 1.1 21-Apr-2009  nonaka branches: 1.1.2; 1.1.4; 1.1.6; 1.1.8; 1.1.10; 1.1.12;
Added SD/MMC support from OpenBSD.
tested on i386, amd64 at current-users ML by pgoyette@.
tested on zaurus by myself.
 1.1.12.3 31-May-2011  rmind sync with head
 1.1.12.2 05-Mar-2011  rmind sync with head
 1.1.12.1 30-May-2010  rmind sync with head
 1.1.10.2 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.1.10.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.1.8.2 07-Oct-2009  sborrill Pull up the following revisions(s) (requested by jmcneill in ticket #1044):
distrib/sets/lists/man/mi: patch
share/man/man4/Makefile: patch
sys/arch/amd64/conf/files.amd64: 1.67
sys/arch/i386/conf/files.i386: 1.349
sys/conf/files 1.945
share/man/man4/sdmmc.4: 1.1-1.4
sys/dev/sdmmc/Makefile.sdmmcdevs 1.1
sys/dev/sdmmc/devlist2h.awk 1.1
sys/dev/sdmmc/files.sdmmc 1.1-1.2
sys/dev/sdmmc/ld_sdmmc.c 1.1-1.3
sys/dev/sdmmc/sbt.c 1.1-1.2
sys/dev/sdmmc/sdhc.c 1.1-1.3
sys/dev/sdmmc/sdhcreg.h 1.1
sys/dev/sdmmc/sdhcvar.h 1.1
sys/dev/sdmmc/sdmmc.c 1.1
sys/dev/sdmmc/sdmmc_cis.c 1.1
sys/dev/sdmmc/sdmmc_io.c 1.1
sys/dev/sdmmc/sdmmc_ioreg.h 1.1
sys/dev/sdmmc/sdmmc_mem.c 1.1-1.2
sys/dev/sdmmc/sdmmcchip.h 1.1
sys/dev/sdmmc/sdmmcdevs 1.1
sys/dev/sdmmc/sdmmcdevs.h 1.1-1.2
sys/dev/sdmmc/sdmmcreg.h 1.1-1.3
sys/dev/sdmmc/sdmmcvar.h 1.1

Add sdmmc framework
 1.1.8.1 21-Apr-2009  sborrill file sdmmcchip.h was added on branch netbsd-5 on 2009-10-07 15:41:13 +0000
 1.1.6.2 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.1.6.1 21-Apr-2009  jym file sdmmcchip.h was added on branch jym-xensuspend on 2009-05-13 17:21:29 +0000
 1.1.4.4 09-Oct-2010  yamt sync with head
 1.1.4.3 11-Aug-2010  yamt sync with head.
 1.1.4.2 04-May-2009  yamt sync with head.
 1.1.4.1 21-Apr-2009  yamt file sdmmcchip.h was added on branch yamt-nfs-mp on 2009-05-04 08:13:18 +0000
 1.1.2.2 28-Apr-2009  skrll Sync with HEAD.
 1.1.2.1 21-Apr-2009  skrll file sdmmcchip.h was added on branch nick-hppapmap on 2009-04-28 07:36:33 +0000
 1.2.2.2 21-Apr-2010  matt sync to netbsd-5
 1.2.2.1 06-Apr-2010  matt file sdmmcchip.h was added on branch matt-nb5-mips64 on 2010-04-21 00:27:52 +0000
 1.3.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.4.32.2 28-Aug-2017  skrll Sync with HEAD
 1.4.32.1 22-Sep-2015  skrll Sync with HEAD
 1.4.14.1 03-Dec-2017  jdolecek update from HEAD
 1.7.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.7.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.9.14.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.9 17-Jan-2025  jmcneill sdmmc: Add Nintendo Wii WLAN device ID
 1.8 01-Jan-2020  jmcneill branches: 1.8.26; 1.8.32;
Add product ID for Broadcom BCM43455
 1.7 28-Oct-2019  mlelstv Whitespace police
 1.6 24-Aug-2019  mlelstv Fix typo
 1.5 18-Aug-2019  mlelstv Add Broadcom devices
 1.4 29-Dec-2018  thorpej branches: 1.4.4;
Add ReakTek RTL8189FTV SDIO 802.11 interface.
 1.3 28-Jun-2018  jmcneill branches: 1.3.2;
Add vendor REALTEK and product RTL8703BS
 1.2 19-Oct-2013  mlelstv branches: 1.2.28;
add Ricoh MMC reader
 1.1 21-Apr-2009  nonaka branches: 1.1.2; 1.1.4; 1.1.6; 1.1.8; 1.1.14; 1.1.22; 1.1.32; 1.1.36;
Added SD/MMC support from OpenBSD.
tested on i386, amd64 at current-users ML by pgoyette@.
tested on zaurus by myself.
 1.1.36.1 18-May-2014  rmind sync with head
 1.1.32.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.22.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.14.2 21-Apr-2010  matt sync to netbsd-5
 1.1.14.1 21-Apr-2009  matt file sdmmcdevs was added on branch matt-nb5-mips64 on 2010-04-21 00:27:52 +0000
 1.1.8.2 07-Oct-2009  sborrill Pull up the following revisions(s) (requested by jmcneill in ticket #1044):
distrib/sets/lists/man/mi: patch
share/man/man4/Makefile: patch
sys/arch/amd64/conf/files.amd64: 1.67
sys/arch/i386/conf/files.i386: 1.349
sys/conf/files 1.945
share/man/man4/sdmmc.4: 1.1-1.4
sys/dev/sdmmc/Makefile.sdmmcdevs 1.1
sys/dev/sdmmc/devlist2h.awk 1.1
sys/dev/sdmmc/files.sdmmc 1.1-1.2
sys/dev/sdmmc/ld_sdmmc.c 1.1-1.3
sys/dev/sdmmc/sbt.c 1.1-1.2
sys/dev/sdmmc/sdhc.c 1.1-1.3
sys/dev/sdmmc/sdhcreg.h 1.1
sys/dev/sdmmc/sdhcvar.h 1.1
sys/dev/sdmmc/sdmmc.c 1.1
sys/dev/sdmmc/sdmmc_cis.c 1.1
sys/dev/sdmmc/sdmmc_io.c 1.1
sys/dev/sdmmc/sdmmc_ioreg.h 1.1
sys/dev/sdmmc/sdmmc_mem.c 1.1-1.2
sys/dev/sdmmc/sdmmcchip.h 1.1
sys/dev/sdmmc/sdmmcdevs 1.1
sys/dev/sdmmc/sdmmcdevs.h 1.1-1.2
sys/dev/sdmmc/sdmmcreg.h 1.1-1.3
sys/dev/sdmmc/sdmmcvar.h 1.1

Add sdmmc framework
 1.1.8.1 21-Apr-2009  sborrill file sdmmcdevs was added on branch netbsd-5 on 2009-10-07 15:41:13 +0000
 1.1.6.2 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.1.6.1 21-Apr-2009  jym file sdmmcdevs was added on branch jym-xensuspend on 2009-05-13 17:21:29 +0000
 1.1.4.2 04-May-2009  yamt sync with head.
 1.1.4.1 21-Apr-2009  yamt file sdmmcdevs was added on branch yamt-nfs-mp on 2009-05-04 08:13:18 +0000
 1.1.2.2 28-Apr-2009  skrll Sync with HEAD.
 1.1.2.1 21-Apr-2009  skrll file sdmmcdevs was added on branch nick-hppapmap on 2009-04-28 07:36:33 +0000
 1.2.28.2 18-Jan-2019  pgoyette Synch with HEAD
 1.2.28.1 28-Jul-2018  pgoyette Sync with HEAD
 1.3.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.3.2.1 10-Jun-2019  christos Sync with HEAD
 1.4.4.1 25-Feb-2020  martin Pull up following revision(s) (requested by mrg in ticket #717):

sys/dev/fdt/dwcmmc_fdt.c 1.11
sys/dev/ic/bwfm.c 1.15-1.18
sys/dev/ic/bwfmreg.h 1.4-1.6
sys/dev/ic/bwfmvar.h 1.4,1.5
sys/dev/ic/dwc_mmc.c 1.21,1.22
sys/dev/ic/dwc_mmc_reg.h 1.8,1.9,1.12,1.13
sys/dev/pcmcia/pcmciareg.h 1.11
sys/dev/sdmmc/if_bwfm_sdio.c 1.4,1.6-1.12
sys/dev/sdmmc/if_bwfm_sdio.h 1.1,1.2
sys/dev/sdmmc/sdhc.c 1.105,1.106
sys/dev/sdmmc/sdmmc.c 1.37,1.39
sys/dev/sdmmc/sdmmc_cis.c 1.6,1.8
sys/dev/sdmmc/sdmmc_io.c 1.15-1.19
sys/dev/sdmmc/sdmmc_ioreg.h 1.4,1.5
sys/dev/sdmmc/sdmmc_mem.c 1.69-1.71
sys/dev/sdmmc/sdmmcdevs 1.5-1.8
sys/dev/sdmmc/sdmmcvar.h 1.31,1.33,1.34
sys/net/if_media.h 1.66

Add Broadcom devices
-
Fix typo
-
add PCMCIA_CISTPL_SDIO definition.
-
From OpenBSD:
- move event handling to workqueue
- check for save/restore capability
-
Tag work queue as MPsafe and increase length.
-
Juse use bpf_mtap(), the 802.11 encapsulation is handled by firmware.
-
From OpenBSD:
- support block length per function
- add functions to read/write regions
-
Decode (but not use) SDIO tuple in CIS.
-
Fix locking.
-
Add more SDIO defines (partially from version 3.0).
-
From OpenBSD:
- All the missing pieces (firmware load, chip setup, protocol handling)
TX queue and interrupt handling via sdmmc_task.
-
Fix locking.
-
Fix packet parsing.
-
Add parser for original firmware config files.
-
tagging work queue as MPSAFE was premature. Revert.
-
SD_IO_RW_EXTENDED is a data transfer command, so set ADTC flag instead of AC
Use correct function to verify if a task has been queued. Avoids race
that can corrupt the task queue.
-
More register definitions.
-
Add IFM_IEEE80211_VHT subtype, IFM_IEEE80211_11AC operating mode, and missing descriptions
-
If firmware is connected in HT or VHT mode, report it to SIOCGIFMEDIA
-
white space police.

Skip setting power when the voltage doesn't change.
Also increase some timeouts.
-
Add and use sdmmc_pause to avoid long-term busy waits.
-
Add sdio abort function.
-
Additional error messages.
-
Print parameters for SDIO devices.
-
Minor cosmetics.
-
Simplyfy sdmmc_io_set_blocklen function signature by dropping the
extra softc pointer. Aligns with OpenBSD.
-
Missing commit for sdio abort function.
-
More code from OpenBSD
-
no need to splnet() when enqueing packets
-
explicit structure padding
-
make internal functions static
-
also prepare for GPIO interrupts.
-
Avoid warnings for tautological shifts as sole conditional.
-
Follow the Linux driver an use the FDT "compatible" property to build a
filename for the nvram config file, fall back to the standard filename.
E.g.
[Caching 123 nodes and 1093 properties]
compatible 73696e6f 766f6970 2c627069 2d6d322d "sinovoip,bpi-m2-
0010: 7a65726f 00...... ........ ........ zero"
0015: 616c6c77 696e6e65 722c7375 6e38692d "allwinner,sun8i-
0025: 68322d70 6c757300 ........ ........ h2-plus"
interrupt-parent 00000001 ........ ........ ........ ....
model 42616e61 6e612050 69204250 492d4d32 "Banana Pi BPI-M2
0010: 2d5a6572 6f00.... ........ ........ -Zero"
name 00...... ........ ........ ........ ""
serial-number 30326330 30303432 65636431 36376566 02c00042ecd167ef
0010: 00...... ........ ........ ........ .
-rw-r--r-- 1 root wheel 875 Nov 2 12:06 brcmfmac43430-sdio.AP6212.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 16:19 brcmfmac43430-sdio.sinovoip,bpi-m2-zero.txt -> brcmfmac43430-sdio.AP6212.txt
-rw-r--r-- 1 root wheel 874 Jun 30 2019 brcmfmac43430-sdio.raspberrypi,3-model-b.txt
-rw-r--r-- 1 root wheel 1864 Jun 30 2019 brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 11:24 brcmfmac43455-sdio.raspberrypi,4-model-b-plus.txt -> brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
-
Add product ID for Broadcom BCM43455
-
Use correct firmware for BCM43456
-
size check was backwards.
-
Be less noisy for some commands.
-
Fix DWC_MMC_INT_SDIO_INT bit
-
dwc_mmc fixes:
- Rockchip uses a different SDIO int bit, so take this into consideration
- Avoid unnecessary resets and always wait for resets to complete
- kpause instead of delay while holding spinlock
- Do not attempt autostop for SD_IO_RW_EXTENDED commands
- Allow for sub-blklen byte counts for single block transfers
-
More SDIO stability and performance fixes
 1.8.32.1 02-Aug-2025  perseant Sync with HEAD
 1.8.26.1 02-Feb-2025  martin Pull up following revision(s) (requested by jmcneill in ticket #1041):

sys/dev/sdmmc/sdmmcdevs: revision 1.9

sdmmc: Add Nintendo Wii WLAN device ID
 1.9 17-Jan-2025  jmcneill sdmmc: regen sdmmcdevs.h
 1.8 01-Jan-2020  jmcneill branches: 1.8.26; 1.8.32;
regen
 1.7 28-Oct-2019  mlelstv regen
 1.6 24-Aug-2019  mlelstv regen
 1.5 18-Aug-2019  mlelstv regen
 1.4 29-Dec-2018  thorpej branches: 1.4.4;
Regen.
 1.3 28-Jun-2018  jmcneill branches: 1.3.2;
Regen
 1.2 21-Apr-2009  nonaka branches: 1.2.2; 1.2.4; 1.2.6; 1.2.8; 1.2.14; 1.2.72;
regen
 1.1 21-Apr-2009  nonaka Added SD/MMC support from OpenBSD.
tested on i386, amd64 at current-users ML by pgoyette@.
tested on zaurus by myself.
 1.2.72.2 18-Jan-2019  pgoyette Synch with HEAD
 1.2.72.1 28-Jul-2018  pgoyette Sync with HEAD
 1.2.14.2 21-Apr-2010  matt sync to netbsd-5
 1.2.14.1 21-Apr-2009  matt file sdmmcdevs.h was added on branch matt-nb5-mips64 on 2010-04-21 00:27:52 +0000
 1.2.8.2 07-Oct-2009  sborrill Pull up the following revisions(s) (requested by jmcneill in ticket #1044):
distrib/sets/lists/man/mi: patch
share/man/man4/Makefile: patch
sys/arch/amd64/conf/files.amd64: 1.67
sys/arch/i386/conf/files.i386: 1.349
sys/conf/files 1.945
share/man/man4/sdmmc.4: 1.1-1.4
sys/dev/sdmmc/Makefile.sdmmcdevs 1.1
sys/dev/sdmmc/devlist2h.awk 1.1
sys/dev/sdmmc/files.sdmmc 1.1-1.2
sys/dev/sdmmc/ld_sdmmc.c 1.1-1.3
sys/dev/sdmmc/sbt.c 1.1-1.2
sys/dev/sdmmc/sdhc.c 1.1-1.3
sys/dev/sdmmc/sdhcreg.h 1.1
sys/dev/sdmmc/sdhcvar.h 1.1
sys/dev/sdmmc/sdmmc.c 1.1
sys/dev/sdmmc/sdmmc_cis.c 1.1
sys/dev/sdmmc/sdmmc_io.c 1.1
sys/dev/sdmmc/sdmmc_ioreg.h 1.1
sys/dev/sdmmc/sdmmc_mem.c 1.1-1.2
sys/dev/sdmmc/sdmmcchip.h 1.1
sys/dev/sdmmc/sdmmcdevs 1.1
sys/dev/sdmmc/sdmmcdevs.h 1.1-1.2
sys/dev/sdmmc/sdmmcreg.h 1.1-1.3
sys/dev/sdmmc/sdmmcvar.h 1.1

Add sdmmc framework
 1.2.8.1 21-Apr-2009  sborrill file sdmmcdevs.h was added on branch netbsd-5 on 2009-10-07 15:41:13 +0000
 1.2.6.2 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.2.6.1 21-Apr-2009  jym file sdmmcdevs.h was added on branch jym-xensuspend on 2009-05-13 17:21:29 +0000
 1.2.4.2 04-May-2009  yamt sync with head.
 1.2.4.1 21-Apr-2009  yamt file sdmmcdevs.h was added on branch yamt-nfs-mp on 2009-05-04 08:13:18 +0000
 1.2.2.2 28-Apr-2009  skrll Sync with HEAD.
 1.2.2.1 21-Apr-2009  skrll file sdmmcdevs.h was added on branch nick-hppapmap on 2009-04-28 07:36:33 +0000
 1.3.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.3.2.1 10-Jun-2019  christos Sync with HEAD
 1.4.4.1 25-Feb-2020  martin Regen (for ticket #717)
 1.8.32.1 02-Aug-2025  perseant Sync with HEAD
 1.8.26.1 02-Feb-2025  martin regen for ticket 1041 (Add Nintendo Wii WLAN device ID)
 1.35 18-Oct-2024  jmcneill sdmmc: Add support for SD card caches.

SD physical 6.0 specification introduced Application Performance Class 2
(A2), which adds support for drive caches and command queueing.

Add support for enabling and flushing the cache when this feature is
present.
 1.34 19-Apr-2018  christos branches: 1.34.34; 1.34.40;
s/static inline/static __inline/g for consistency.
 1.33 12-Sep-2017  jmcneill branches: 1.33.2;
For SD cards, send the SET_WR_BLK_ERASE_COUNT app command before a
multi-block write to improve write performance.
 1.32 16-Jul-2017  jmcneill branches: 1.32.2;
Add support for eMMC 4.5's optional cache feature. If a cache is present,
and the host controller reports the SMC_CAPS_POLLING capability (needed
to flush cache at shutdown), it will be automatically enabled and used.
 1.31 24-Jun-2017  jmcneill Read SD status register and print card status when a new SD card is found:

sdmmc0: SD card status: 4-bit, C10, U1, V10

If the SD status register reports discard support, set the DISCARD arg to
the ERASE operation to let the card know that the host doesn't care if the
erase is performed.
 1.30 24-Jun-2017  jmcneill Add discard support to ld@sdmmc using the ERASE (CMD38) command.
 1.29 17-Feb-2017  nonaka branches: 1.29.6;
sdhc(4): hardware reset support for Intel eMMC controller
 1.28 17-Feb-2017  nonaka sdmmc(4): Added EXT_CSD[HS_TIMING] definitions.
 1.27 17-Feb-2017  nonaka sdmmc(4): Change EXT_CSD[CARD_TYPE] HS DDR 52 MHz definition.

Because it has been difficult to understand from the definition is DDR.
 1.26 17-Feb-2017  nonaka sdmmc(4): Remove unused EXT_CSD[CARD_TYPE] definitions.
 1.25 17-Feb-2017  nonaka sdmmc(4): Added comments at EXT_CSD[CARD_TYPE] definitions.
 1.24 17-Feb-2017  nonaka sdmmc(4): Added 4 and 8 bit mode DDR definitions at EXT_CSD[BUS_WIDTH].
 1.23 17-Feb-2017  nonaka sdmmc(4): Fix cell type in comments.

From JEDEC Standard No.84-B51, 7.4. Extended CSD register.
 1.22 10-Aug-2016  nonaka branches: 1.22.2;
Use 1.65-1.95 voltage window for 1.8V support.
 1.21 29-Oct-2015  jmcneill branches: 1.21.2;
After setting HS_TIMING value for HS200 or later, send repeated SEND_STATUS
command until the device is no longer busy or the SWITCH_ERROR bit is set.
 1.20 08-Aug-2015  jmcneill eMMC fixes
 1.19 05-Aug-2015  jmcneill Add support for sampling clock tuning, required for some UHS modes and
MMC HS200.
 1.18 03-Aug-2015  jmcneill Add support for DDR50 transfer modes.
 1.17 02-Aug-2015  jmcneill Add support for eMMC 5.0 HS200 timings.
 1.16 02-Aug-2015  jmcneill Add basic UHS-I support. SDR50 and SDR104 are supported, but not DDR50.
 1.15 07-Dec-2014  jmcneill Fix high capacity (> 2GB) eMMC support, from OpenBSD.
 1.14 03-May-2013  matt branches: 1.14.12;
Add support for the valid card types in eMMC v4.4 (needed by beaglebone
black).
 1.13 15-Dec-2012  jakllsch Correctly read the 512-bit-wide big-endian Switch Function Status register.
Some of this could/will also be useful for the SD Status register.
 1.12 28-Jul-2012  matt branches: 1.12.2;
Fix comments about __bitfield.
 1.11 23-Jul-2012  matt Responses are actually in host order (except SCR which is return in
big endian so that's convert to host order).
 1.10 20-Jul-2012  matt Add use of watermark register when PIO to an ESDHC. After every kill or
drain of watermask words, pause a bit to give time for the fifo to recover.
Always the command response in BE byteorder. Rewrite __bitfield to deal
with this.
 1.9 12-Jul-2012  jakllsch Add SD_STATUS (ACMD13) opcode.
 1.8 27-Jan-2012  matt branches: 1.8.2;
Remove suplurfious ++
 1.7 13-Feb-2011  nonaka branches: 1.7.4; 1.7.8;
use MMC_CSD_CSDVER_EXT_CSD.
 1.6 13-Feb-2011  nonaka - Don't switch MMC high-speed timing, if host controller isn't supported.
- Only check EXT_CSD STRUCTURE version when CSD version is 3.
- initialize width at sdmmc_function_alloc().
 1.5 07-Oct-2010  kiyohara branches: 1.5.2; 1.5.4;
Support High-Speed mode.
 1.4 06-Apr-2010  nonaka branches: 1.4.2;
- mention MMC SPI mode.
- support SD 4bit bus width mode.
 1.3 26-Apr-2009  nonaka branches: 1.3.2; 1.3.4; 1.3.6; 1.3.8; 1.3.10; 1.3.12;
fix build broken.
Pointed by Takeshi Nakayama.
 1.2 26-Apr-2009  nonaka Added some command definitions.
 1.1 21-Apr-2009  nonaka Added SD/MMC support from OpenBSD.
tested on i386, amd64 at current-users ML by pgoyette@.
tested on zaurus by myself.
 1.3.12.2 05-Mar-2011  rmind sync with head
 1.3.12.1 30-May-2010  rmind sync with head
 1.3.10.2 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.3.10.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.3.8.2 07-Oct-2009  sborrill Pull up the following revisions(s) (requested by jmcneill in ticket #1044):
distrib/sets/lists/man/mi: patch
share/man/man4/Makefile: patch
sys/arch/amd64/conf/files.amd64: 1.67
sys/arch/i386/conf/files.i386: 1.349
sys/conf/files 1.945
share/man/man4/sdmmc.4: 1.1-1.4
sys/dev/sdmmc/Makefile.sdmmcdevs 1.1
sys/dev/sdmmc/devlist2h.awk 1.1
sys/dev/sdmmc/files.sdmmc 1.1-1.2
sys/dev/sdmmc/ld_sdmmc.c 1.1-1.3
sys/dev/sdmmc/sbt.c 1.1-1.2
sys/dev/sdmmc/sdhc.c 1.1-1.3
sys/dev/sdmmc/sdhcreg.h 1.1
sys/dev/sdmmc/sdhcvar.h 1.1
sys/dev/sdmmc/sdmmc.c 1.1
sys/dev/sdmmc/sdmmc_cis.c 1.1
sys/dev/sdmmc/sdmmc_io.c 1.1
sys/dev/sdmmc/sdmmc_ioreg.h 1.1
sys/dev/sdmmc/sdmmc_mem.c 1.1-1.2
sys/dev/sdmmc/sdmmcchip.h 1.1
sys/dev/sdmmc/sdmmcdevs 1.1
sys/dev/sdmmc/sdmmcdevs.h 1.1-1.2
sys/dev/sdmmc/sdmmcreg.h 1.1-1.3
sys/dev/sdmmc/sdmmcvar.h 1.1

Add sdmmc framework
 1.3.8.1 26-Apr-2009  sborrill file sdmmcreg.h was added on branch netbsd-5 on 2009-10-07 15:41:13 +0000
 1.3.6.2 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.3.6.1 26-Apr-2009  jym file sdmmcreg.h was added on branch jym-xensuspend on 2009-05-13 17:21:29 +0000
 1.3.4.4 09-Oct-2010  yamt sync with head
 1.3.4.3 11-Aug-2010  yamt sync with head.
 1.3.4.2 04-May-2009  yamt sync with head.
 1.3.4.1 26-Apr-2009  yamt file sdmmcreg.h was added on branch yamt-nfs-mp on 2009-05-04 08:13:18 +0000
 1.3.2.2 28-Apr-2009  skrll Sync with HEAD.
 1.3.2.1 26-Apr-2009  skrll file sdmmcreg.h was added on branch nick-hppapmap on 2009-04-28 07:36:34 +0000
 1.4.2.2 21-Apr-2010  matt sync to netbsd-5
 1.4.2.1 06-Apr-2010  matt file sdmmcreg.h was added on branch matt-nb5-mips64 on 2010-04-21 00:27:52 +0000
 1.5.4.1 17-Feb-2011  bouyer Sync with HEAD
 1.5.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.7.8.1 18-Feb-2012  mrg merge to -current.
 1.7.4.4 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.7.4.3 23-Jan-2013  yamt sync with head
 1.7.4.2 30-Oct-2012  yamt sync with head
 1.7.4.1 17-Apr-2012  yamt sync with head
 1.8.2.1 08-Aug-2012  jdc Pull up revisions:
src/sys/dev/sdmmc/sdhc.c revisions 1.16,1.20,1.21,1.22,1.23 via patch,1.25
src/sys/dev/sdmmc/sdhcreg.h revision 1.8
src/sys/dev/sdmmc/sdmmc_mem.c revisions 1.21,1.22
src/sys/dev/sdmmc/sdmmcreg.h revisions 1.10,1.11,1.12
(requested by matt in ticket 441).

SDHCI byte swaps the BE response on the wire into LE registers.
As we always want response data in LE, use bus_space_read_stream.
Additonally, read response data in 1 or 4 4-byte chunks, instead of
one 4-byte chunk or 15 1-byte chunks.

bus_space_*_stream_N() functions are not universally available.
Provite alternate implementation for when they are unavailable.

Handle interrupt acknowledgement in the SDHC_FLAG_32BIT_ACCESS case in
the same way as non-SDHC_FLAG_32BIT_ACCESS case.

If there was an error in 32-bit mode, just set ERROR_INTERRUPT otherwise
see if matched anything we care about.

Add use of watermark register when PIO to an ESDHC. After every kill or
drain of watermask words, pause a bit to give time for the fifo to recover.
Always the command response in BE byteorder. Rewrite __bitfield to deal
with this.

Responses are actually in host order (except SCR which is return in
big endian so that's convert to host order).

Fix comments about __bitfield.
 1.12.2.3 03-Dec-2017  jdolecek update from HEAD
 1.12.2.2 23-Jun-2013  tls resync from head
 1.12.2.1 25-Feb-2013  tls resync with head
 1.14.12.5 28-Aug-2017  skrll Sync with HEAD
 1.14.12.4 05-Oct-2016  skrll Sync with HEAD
 1.14.12.3 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.14.12.2 22-Sep-2015  skrll Sync with HEAD
 1.14.12.1 06-Apr-2015  skrll Sync with HEAD
 1.21.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.22.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.29.6.2 25-Jul-2017  snj Pull up following revision(s) (requested by jmcneill in ticket #139):
sys/arch/arm/sunxi/sunxi_mmc.c: revision 1.2
sys/dev/sdmmc/ld_sdmmc.c: revision 1.31
sys/dev/sdmmc/sdmmc_mem.c: revision 1.61
sys/dev/sdmmc/sdmmcreg.h: revision 1.32
sys/dev/sdmmc/sdmmcvar.h: revision 1.28
Add support for eMMC 4.5's optional cache feature. If a cache is present,
and the host controller reports the SMC_CAPS_POLLING capability (needed
to flush cache at shutdown), it will be automatically enabled and used.
--
Add SMC_CAPS_POLLING support.
 1.29.6.1 01-Jul-2017  snj Pull up following revision(s) (requested by jmcneill in ticket #67):
sys/dev/sdmmc/ld_sdmmc.c: 1.28
sys/dev/sdmmc/sdmmc_mem.c: 1.58-1.60
sys/dev/sdmmc/sdmmcreg.h: 1.30, 1.31
sys/dev/sdmmc/sdmmcvar.h: 1.25-1.27
Add discard support to ld@sdmmc using the ERASE (CMD38) command.
--
Read SD status register and print card status when a new SD card is found:
sdmmc0: SD card status: 4-bit, C10, U1, V10
If the SD status register reports discard support, set the DISCARD arg to
the ERASE operation to let the card know that the host doesn't care if the
erase is performed.
--
Revert part of previous; the SD card spec recommends not to issue a DISCARD
command to the file system area.
 1.32.2.2 16-Jul-2017  jmcneill 2978427
 1.32.2.1 16-Jul-2017  jmcneill file sdmmcreg.h was added on branch perseant-stdc-iso10646 on 2017-07-16 17:11:47 +0000
 1.33.2.1 22-Apr-2018  pgoyette Sync with HEAD
 1.34.40.1 02-Aug-2025  perseant Sync with HEAD
 1.34.34.1 26-Oct-2024  martin Pull up following revision(s) (requested by jmcneill in ticket #985):

sys/dev/sdmmc/sdmmcvar.h: revision 1.37
sys/dev/sdmmc/sdmmcreg.h: revision 1.35
sys/dev/sdmmc/ld_sdmmc.c: revision 1.44
sys/dev/sdmmc/sdmmc_mem.c: revision 1.76

sdmmc: Add support for SD card caches.

SD physical 6.0 specification introduced Application Performance Class 2
(A2), which adds support for drive caches and command queueing.

Add support for enabling and flushing the cache when this feature is
present.
 1.38 17-Jan-2025  jmcneill sdmmc: Capture lan_nid and expose sdmmc_cisptr

LAN NID contains the MAC address for networking adapters.

Device drivers may want to processor vendor specific tuple codes, so
expose sdmmc_cisptr to help this.
 1.37 18-Oct-2024  jmcneill sdmmc: Add support for SD card caches.

SD physical 6.0 specification introduced Application Performance Class 2
(A2), which adds support for drive caches and command queueing.

Add support for enabling and flushing the cache when this feature is
present.
 1.36 13-Mar-2021  mlelstv branches: 1.36.18; 1.36.24;
define NO_STOP flag
 1.35 24-May-2020  riastradh branches: 1.35.2;
Fix races in sdmmc tasks and teach ld@sdmmc to abort xfers on detach.

- Teach sdmmc_add_task to queue it only if not already queued.
- Remove now-redundant logic to avoid repeated queueing elsewhere.
- Teach sdmmc_del_task to wait until task has completed.
- Call sdmmc_del_task in various needful places.
- Replace abuse of pcq by a lock and a tailq.
(pcq is multi-producer, _single_-consumer, but there are potentially
multiple consumers here and really only one producer.)
- Teach ld_sdmmc to abort xfers on detach.
(Mechanism is kinda kludgey but it'll do for now; any effort one is
tempted to spend overhauling this should be spent overhauling sdmmc
to support proper asynchronous commands.)
- Make sure ld_sdmmc_discard either returns failure or eventually calls
ldenddiscard.

XXX Currently ld_sdmmc_detach aborts xfers _before_ ldbegindetach has
has committed to detaching or not. This is currently necessary to
avoid a deadlock because ldbegindetach waits for xfers to drain --
which strikes me as wrong; ldbegindetach shouldn't wait for anything,
and should only make the decision to commit to detaching or not so
the caller can decide whether to abort xfers before we actually wait
for them in ldenddetach.

XXX pullup -- although this changes some kernel symbols (sdmmc_add_task
and sdmmc_del_task), it shouldn't affect any existing modules; the only
module that uses sdmmc is ld_sdmmc.kmod, which is `.if 0' in the build
so there shouldn't be any of them floating around.
 1.34 28-Oct-2019  mlelstv Simplyfy sdmmc_io_set_blocklen function signature by dropping the
extra softc pointer. Aligns with OpenBSD.
 1.33 28-Oct-2019  mlelstv Add and use sdmmc_pause to avoid long-term busy waits.
Add sdio abort function.
Additional error messages.
Print parameters for SDIO devices.
Minor cosmetics.
 1.32 23-Oct-2019  hkenken Add SDHC flags.

+ SDHC_FLAG_BROKEN_ADMA2_ZEROLEN
Broken ADMA2 Zero length descriptor.
Can't 64K Byte data transfer.
+ SDHC_FLAG_NO_1_8_V
Support no 1.8V Supply.
Disable UHS-I bus speed mode (SDR50, DDR50, SDR104).
 1.31 01-Sep-2019  mlelstv From OpenBSD:
- support block length per function
- add functions to read/write regions
Decode (but not use) SDIO tuple in CIS.
Fix locking.
Add more SDIO defines (partially from version 3.0).
 1.30 25-Feb-2019  jmcneill branches: 1.30.4;
Add SCF_NEED_BOUNCE command flag. Can be used by a driver to keep track of
which command(s) need data transfers to go through DMA bounce buffers.
 1.29 20-Aug-2017  mlelstv branches: 1.29.4;
make the sc_discard interface for the ld backend asynchronous and
signal completion through new callback lddiscardend. Use a standard
struct buf to pass disk address and range instead of two off_t values.

make lddiscard synchronous again. This is a requirement of the current
ffs discard code.
 1.28 16-Jul-2017  jmcneill branches: 1.28.2;
Add support for eMMC 4.5's optional cache feature. If a cache is present,
and the host controller reports the SMC_CAPS_POLLING capability (needed
to flush cache at shutdown), it will be automatically enabled and used.
 1.27 24-Jun-2017  jmcneill Revert part of previous; the SD card spec recommends not to issue a DISCARD
command to the file system area.
 1.26 24-Jun-2017  jmcneill Read SD status register and print card status when a new SD card is found:

sdmmc0: SD card status: 4-bit, C10, U1, V10

If the SD status register reports discard support, set the DISCARD arg to
the ERASE operation to let the card know that the host doesn't care if the
erase is performed.
 1.25 24-Jun-2017  jmcneill Add discard support to ld@sdmmc using the ERASE (CMD38) command.
 1.24 04-Jun-2017  jmcneill Give a hint to controllers in the command flags if we are performing a
transfer with an SDHC capable card. If the controller needs to adjust
command args, it can use this hint to understand how it is encoded.
 1.23 17-Feb-2017  nonaka branches: 1.23.6;
sdhc(4): hardware reset support for Intel eMMC controller
 1.22 17-Feb-2017  nonaka sdmmc(4): Add MMC HS DDR52 timing support bit and use __BIT() macro.
 1.21 29-Nov-2015  jmcneill branches: 1.21.2; 1.21.4;
Add some event counters to track transfer sizes.
 1.20 06-Oct-2015  mlelstv support hiding command timeout messages with a new command flag and use this
when probing for cards. Should fix PR 50302.
 1.19 09-Aug-2015  mlelstv Send an explicit CMD12 (stop transmission) when there was an error
in multi-sector I/O.

The SDHC spec has a complex flowchart describing when an explicit
CMD12 is necessary, so we probably use it too often.
 1.18 03-Aug-2015  jmcneill Add support for DDR50 transfer modes.
 1.17 02-Aug-2015  jmcneill Add basic UHS-I support. SDR50 and SDR104 are supported, but not DDR50.
 1.16 27-Feb-2015  nonaka fix to simulate multi-segment dma transfer for pq3sdhc(4).
 1.15 19-Mar-2014  nonaka branches: 1.15.4; 1.15.6;
Add a driver for Realtek RTS5209/RTS5229 Card Reader.
Ported from OpenBSD.
 1.14 12-Jul-2012  jakllsch branches: 1.14.2; 1.14.4;
Replace integer constant SDMMC_MAXNSEGS with the formula said value was
calculated from.
 1.13 11-Jul-2012  jakllsch Fix transposition typo in comment.
 1.12 01-Feb-2012  matt Use "opt_sdmmc.h" for SDMMC_DEBUG, etc.
 1.11 18-May-2011  dyoung branches: 1.11.4; 1.11.8;
#include <sys/bus.h>, not <machine/bus.h>.
 1.10 13-Feb-2011  nonaka - Don't switch MMC high-speed timing, if host controller isn't supported.
- Only check EXT_CSD STRUCTURE version when CSD version is 3.
- initialize width at sdmmc_function_alloc().
 1.9 05-Feb-2011  nonaka Don't switch SD high-speed timing, if host controller isn't supported.
 1.8 07-Oct-2010  kiyohara branches: 1.8.2; 1.8.4;
Support High-Speed mode.
 1.7 01-Oct-2010  kiyohara Use DMA bounce buffer, if DMA buffer is making by multiple segments. A lot
of host controllers do not support to two or more segments.
 1.6 23-Sep-2010  kiyohara Print bus width and clock for feature(High speed support).
 1.5 22-Sep-2010  kiyohara Back out previous change. "automagically" is NOT a typo.
 1.4 21-Sep-2010  kiyohara + Add macro SMC_CAPS_8BIT_MODE for 8bit mode support.
+ Typo. s/automagically/automatically/.
 1.3 06-Apr-2010  nonaka branches: 1.3.2;
- mention MMC SPI mode.
- support SD 4bit bus width mode.
 1.2 28-Nov-2009  nonaka branches: 1.2.2; 1.2.4;
Always sector size is treated as 512 bytes.
 1.1 21-Apr-2009  nonaka branches: 1.1.2; 1.1.4; 1.1.6; 1.1.8;
Added SD/MMC support from OpenBSD.
tested on i386, amd64 at current-users ML by pgoyette@.
tested on zaurus by myself.
 1.1.8.3 02-Dec-2009  sborrill Pull up the following revisions(s) (requested by nonaka in ticket #1167):
sys/dev/sdmmc/ld_sdmmc.c: revision 1.4
sys/dev/sdmmc/sdmmc_mem.c: revision 1.3
sys/dev/sdmmc/sdmmcvar.h: revision 1.2

Always treat sector size as 512 bytes.
 1.1.8.2 07-Oct-2009  sborrill Pull up the following revisions(s) (requested by jmcneill in ticket #1044):
distrib/sets/lists/man/mi: patch
share/man/man4/Makefile: patch
sys/arch/amd64/conf/files.amd64: 1.67
sys/arch/i386/conf/files.i386: 1.349
sys/conf/files 1.945
share/man/man4/sdmmc.4: 1.1-1.4
sys/dev/sdmmc/Makefile.sdmmcdevs 1.1
sys/dev/sdmmc/devlist2h.awk 1.1
sys/dev/sdmmc/files.sdmmc 1.1-1.2
sys/dev/sdmmc/ld_sdmmc.c 1.1-1.3
sys/dev/sdmmc/sbt.c 1.1-1.2
sys/dev/sdmmc/sdhc.c 1.1-1.3
sys/dev/sdmmc/sdhcreg.h 1.1
sys/dev/sdmmc/sdhcvar.h 1.1
sys/dev/sdmmc/sdmmc.c 1.1
sys/dev/sdmmc/sdmmc_cis.c 1.1
sys/dev/sdmmc/sdmmc_io.c 1.1
sys/dev/sdmmc/sdmmc_ioreg.h 1.1
sys/dev/sdmmc/sdmmc_mem.c 1.1-1.2
sys/dev/sdmmc/sdmmcchip.h 1.1
sys/dev/sdmmc/sdmmcdevs 1.1
sys/dev/sdmmc/sdmmcdevs.h 1.1-1.2
sys/dev/sdmmc/sdmmcreg.h 1.1-1.3
sys/dev/sdmmc/sdmmcvar.h 1.1

Add sdmmc framework
 1.1.8.1 21-Apr-2009  sborrill file sdmmcvar.h was added on branch netbsd-5 on 2009-10-07 15:41:13 +0000
 1.1.6.2 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.1.6.1 21-Apr-2009  jym file sdmmcvar.h was added on branch jym-xensuspend on 2009-05-13 17:21:29 +0000
 1.1.4.5 09-Oct-2010  yamt sync with head
 1.1.4.4 11-Aug-2010  yamt sync with head.
 1.1.4.3 11-Mar-2010  yamt sync with head
 1.1.4.2 04-May-2009  yamt sync with head.
 1.1.4.1 21-Apr-2009  yamt file sdmmcvar.h was added on branch yamt-nfs-mp on 2009-05-04 08:13:18 +0000
 1.1.2.2 28-Apr-2009  skrll Sync with HEAD.
 1.1.2.1 21-Apr-2009  skrll file sdmmcvar.h was added on branch nick-hppapmap on 2009-04-28 07:36:34 +0000
 1.2.4.3 31-May-2011  rmind sync with head
 1.2.4.2 05-Mar-2011  rmind sync with head
 1.2.4.1 30-May-2010  rmind sync with head
 1.2.2.2 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.2.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.3.2.2 21-Apr-2010  matt sync to netbsd-5
 1.3.2.1 06-Apr-2010  matt file sdmmcvar.h was added on branch matt-nb5-mips64 on 2010-04-21 00:27:52 +0000
 1.8.4.2 17-Feb-2011  bouyer Sync with HEAD
 1.8.4.1 08-Feb-2011  bouyer Sync with HEAD
 1.8.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.11.8.1 18-Feb-2012  mrg merge to -current.
 1.11.4.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.11.4.2 30-Oct-2012  yamt sync with head
 1.11.4.1 17-Apr-2012  yamt sync with head
 1.14.4.1 18-May-2014  rmind sync with head
 1.14.2.2 03-Dec-2017  jdolecek update from HEAD
 1.14.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.15.6.4 28-Aug-2017  skrll Sync with HEAD
 1.15.6.3 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.15.6.2 22-Sep-2015  skrll Sync with HEAD
 1.15.6.1 06-Apr-2015  skrll Sync with HEAD
 1.15.4.1 09-Mar-2015  snj Pull up following revision(s) (requested by nonaka in ticket #577):
sys/dev/sdmmc/sdmmc_mem.c: revision 1.34
sys/dev/sdmmc/sdmmcvar.h: revision 1.16
fix to simulate multi-segment dma transfer for pq3sdhc(4).
 1.21.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.21.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.23.6.4 01-Sep-2017  martin Pull up following revision(s) (requested by mlelstv in ticket #261):
sys/dev/sdmmc/ld_sdmmc.c: revision 1.32
sys/dev/sdmmc/ld_sdmmc.c: revision 1.33
sys/dev/sdmmc/ld_sdmmc.c: revision 1.34
sys/dev/sdmmc/sdmmc_mem.c: revision 1.62
sys/dev/i2o/ld_iop.c: revision 1.39
sys/dev/ld.c: revision 1.102
sys/dev/ld.c: revision 1.103
sys/dev/dksubr.c: revision 1.98
sys/dev/dksubr.c: revision 1.99
sys/dev/sdmmc/sdmmcvar.h: revision 1.29
sys/dev/ic/ld_nvme.c: revision 1.17
sys/dev/ldvar.h: revision 1.31
sys/dev/ldvar.h: revision 1.32
sys/dev/ic/ld_cac.c: revision 1.31
sys/dev/pci/ld_virtio.c: revision 1.16
While ld(4) is MP safe, many backends are not.
Add a flag for backends that are MP safe. Take KERNEL_LOCK when calling
into a backend that doesn't have the flag set. Do the same for the
discard routine.
Fixes PR 52462.
Defer sdmmc discard operations to the sdmmc task queue. Fixes a panic
introduced by ld.c r1.102.
validate length for discard operation and split operation when byte length
doesn't fit into 'int'.
make the sc_discard interface for the ld backend asynchronous and
signal completion through new callback lddiscardend. Use a standard
struct buf to pass disk address and range instead of two off_t values.
make lddiscard synchronous again. This is a requirement of the current
ffs discard code.
Initialize error also in the case where len=0, which just succeeds.
while here, assert that the len is indeed non-negative. this is already
confirmed by sys_fdiscard, but let's be sure.
reported by: GCC, but with different compile flags
 1.23.6.3 25-Jul-2017  snj Pull up following revision(s) (requested by jmcneill in ticket #139):
sys/arch/arm/sunxi/sunxi_mmc.c: revision 1.2
sys/dev/sdmmc/ld_sdmmc.c: revision 1.31
sys/dev/sdmmc/sdmmc_mem.c: revision 1.61
sys/dev/sdmmc/sdmmcreg.h: revision 1.32
sys/dev/sdmmc/sdmmcvar.h: revision 1.28
Add support for eMMC 4.5's optional cache feature. If a cache is present,
and the host controller reports the SMC_CAPS_POLLING capability (needed
to flush cache at shutdown), it will be automatically enabled and used.
--
Add SMC_CAPS_POLLING support.
 1.23.6.2 01-Jul-2017  snj Pull up following revision(s) (requested by jmcneill in ticket #67):
sys/dev/sdmmc/ld_sdmmc.c: 1.28
sys/dev/sdmmc/sdmmc_mem.c: 1.58-1.60
sys/dev/sdmmc/sdmmcreg.h: 1.30, 1.31
sys/dev/sdmmc/sdmmcvar.h: 1.25-1.27
Add discard support to ld@sdmmc using the ERASE (CMD38) command.
--
Read SD status register and print card status when a new SD card is found:
sdmmc0: SD card status: 4-bit, C10, U1, V10
If the SD status register reports discard support, set the DISCARD arg to
the ERASE operation to let the card know that the host doesn't care if the
erase is performed.
--
Revert part of previous; the SD card spec recommends not to issue a DISCARD
command to the file system area.
 1.23.6.1 04-Jun-2017  bouyer Pull up following revision(s) (requested by jmcneill in ticket #3):
sys/dev/sdmmc/sdmmcvar.h: revision 1.24
sys/dev/sdmmc/sdmmc_mem.c: revision 1.57
sys/dev/ic/pl181.c: revision 1.4
Give a hint to controllers in the command flags if we are performing a
transfer with an SDHC capable card. If the controller needs to adjust
command args, it can use this hint to understand how it is encoded.
Re-introduce support for multi-block transfers and split transfers to fit
within the 65535-byte limit.
 1.28.2.2 16-Jul-2017  jmcneill 2978427
 1.28.2.1 16-Jul-2017  jmcneill file sdmmcvar.h was added on branch perseant-stdc-iso10646 on 2017-07-16 17:11:47 +0000
 1.29.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.29.4.1 10-Jun-2019  christos Sync with HEAD
 1.30.4.2 09-Aug-2020  martin Pull up following revision(s) (requested by mrg in ticket #1042):

sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.19
sys/dev/sdmmc/ld_sdmmc.c: revision 1.38
sys/dev/sdmmc/sdmmcvar.h: revision 1.35
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.5
sys/dev/ic/bwfm.c: revision 1.26
sys/dev/ic/bwfm.c: revision 1.27
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.20
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.21
sys/dev/sdmmc/sdmmc_io.c: revision 1.20
sys/dev/sdmmc/sdmmc_mem.c: revision 1.72
sys/dev/sdmmc/sdmmc.c: revision 1.40
sys/dev/sdmmc/sdmmc_ioreg.h: revision 1.6
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.16

Don't pass empty mbufs to the network stack.

Avoid changing signedness bit with << in sdmmc_ioreg.h
Reported by <prlw1>

If the controller doesn't support switch func (opcode 6) then skip
setting this but continue with other settings. This allows us to use
a card, albeit at a lower speed.

Fix races in sdmmc tasks and teach ld@sdmmc to abort xfers on detach.
- Teach sdmmc_add_task to queue it only if not already queued.
- Remove now-redundant logic to avoid repeated queueing elsewhere.
- Teach sdmmc_del_task to wait until task has completed.
- Call sdmmc_del_task in various needful places.
- Replace abuse of pcq by a lock and a tailq.
(pcq is multi-producer, _single_-consumer, but there are potentially
multiple consumers here and really only one producer.)
- Teach ld_sdmmc to abort xfers on detach.
(Mechanism is kinda kludgey but it'll do for now; any effort one is
tempted to spend overhauling this should be spent overhauling sdmmc
to support proper asynchronous commands.)
- Make sure ld_sdmmc_discard either returns failure or eventually calls
ldenddiscard.

XXX Currently ld_sdmmc_detach aborts xfers _before_ ldbegindetach has
has committed to detaching or not. This is currently necessary to
avoid a deadlock because ldbegindetach waits for xfers to drain --
which strikes me as wrong; ldbegindetach shouldn't wait for anything,
and should only make the decision to commit to detaching or not so
the caller can decide whether to abort xfers before we actually wait
for them in ldenddetach.

XXX pullup -- although this changes some kernel symbols (sdmmc_add_task
and sdmmc_del_task), it shouldn't affect any existing modules; the only
module that uses sdmmc is ld_sdmmc.kmod, which is `.if 0' in the build
so there shouldn't be any of them floating around.

Make this work on big endian machines

move some of the patching of callbacks and other data after
ieee80211_ifattach() but before if_deferred_start_init().
may fix panic i saw in after restarting wpa_supplicant.
from mlelstv.

only ask for SDPCMD_INTSTATUS_HMB_SW_MASK and SDPCMD_INTSTATUS_CHIPACTIVE
interrupts, not all of them. we only ack these ones.
mostly fixes pinebookpro wifi hard hangs. still is problematic and can
trigger interrupt storm that appears as a hard hang without NET_MPSAFE,
and a follow up, less clearly right, change will reduce that to a soft
hang of the interface that can be cleared with 'ifconfig bwfm0 down up',
and even often recovers itself now.

clear all interrupts, not just those we expect from the hostintmask.
this removes the final hard hang i have seen in pinebookpro wifi,
though one may still need to 'ifconfig bwfm0 down up' occasionally,
so we still have bugs to fix here (the hang is usually associated
with 'checksum error' from bwfm/sdio.)

Sort #includes. Nix trailing whitespace.
No functional change intended.
 1.30.4.1 25-Feb-2020  martin Pull up following revision(s) (requested by mrg in ticket #717):

sys/dev/fdt/dwcmmc_fdt.c 1.11
sys/dev/ic/bwfm.c 1.15-1.18
sys/dev/ic/bwfmreg.h 1.4-1.6
sys/dev/ic/bwfmvar.h 1.4,1.5
sys/dev/ic/dwc_mmc.c 1.21,1.22
sys/dev/ic/dwc_mmc_reg.h 1.8,1.9,1.12,1.13
sys/dev/pcmcia/pcmciareg.h 1.11
sys/dev/sdmmc/if_bwfm_sdio.c 1.4,1.6-1.12
sys/dev/sdmmc/if_bwfm_sdio.h 1.1,1.2
sys/dev/sdmmc/sdhc.c 1.105,1.106
sys/dev/sdmmc/sdmmc.c 1.37,1.39
sys/dev/sdmmc/sdmmc_cis.c 1.6,1.8
sys/dev/sdmmc/sdmmc_io.c 1.15-1.19
sys/dev/sdmmc/sdmmc_ioreg.h 1.4,1.5
sys/dev/sdmmc/sdmmc_mem.c 1.69-1.71
sys/dev/sdmmc/sdmmcdevs 1.5-1.8
sys/dev/sdmmc/sdmmcvar.h 1.31,1.33,1.34
sys/net/if_media.h 1.66

Add Broadcom devices
-
Fix typo
-
add PCMCIA_CISTPL_SDIO definition.
-
From OpenBSD:
- move event handling to workqueue
- check for save/restore capability
-
Tag work queue as MPsafe and increase length.
-
Juse use bpf_mtap(), the 802.11 encapsulation is handled by firmware.
-
From OpenBSD:
- support block length per function
- add functions to read/write regions
-
Decode (but not use) SDIO tuple in CIS.
-
Fix locking.
-
Add more SDIO defines (partially from version 3.0).
-
From OpenBSD:
- All the missing pieces (firmware load, chip setup, protocol handling)
TX queue and interrupt handling via sdmmc_task.
-
Fix locking.
-
Fix packet parsing.
-
Add parser for original firmware config files.
-
tagging work queue as MPSAFE was premature. Revert.
-
SD_IO_RW_EXTENDED is a data transfer command, so set ADTC flag instead of AC
Use correct function to verify if a task has been queued. Avoids race
that can corrupt the task queue.
-
More register definitions.
-
Add IFM_IEEE80211_VHT subtype, IFM_IEEE80211_11AC operating mode, and missing descriptions
-
If firmware is connected in HT or VHT mode, report it to SIOCGIFMEDIA
-
white space police.

Skip setting power when the voltage doesn't change.
Also increase some timeouts.
-
Add and use sdmmc_pause to avoid long-term busy waits.
-
Add sdio abort function.
-
Additional error messages.
-
Print parameters for SDIO devices.
-
Minor cosmetics.
-
Simplyfy sdmmc_io_set_blocklen function signature by dropping the
extra softc pointer. Aligns with OpenBSD.
-
Missing commit for sdio abort function.
-
More code from OpenBSD
-
no need to splnet() when enqueing packets
-
explicit structure padding
-
make internal functions static
-
also prepare for GPIO interrupts.
-
Avoid warnings for tautological shifts as sole conditional.
-
Follow the Linux driver an use the FDT "compatible" property to build a
filename for the nvram config file, fall back to the standard filename.
E.g.
[Caching 123 nodes and 1093 properties]
compatible 73696e6f 766f6970 2c627069 2d6d322d "sinovoip,bpi-m2-
0010: 7a65726f 00...... ........ ........ zero"
0015: 616c6c77 696e6e65 722c7375 6e38692d "allwinner,sun8i-
0025: 68322d70 6c757300 ........ ........ h2-plus"
interrupt-parent 00000001 ........ ........ ........ ....
model 42616e61 6e612050 69204250 492d4d32 "Banana Pi BPI-M2
0010: 2d5a6572 6f00.... ........ ........ -Zero"
name 00...... ........ ........ ........ ""
serial-number 30326330 30303432 65636431 36376566 02c00042ecd167ef
0010: 00...... ........ ........ ........ .
-rw-r--r-- 1 root wheel 875 Nov 2 12:06 brcmfmac43430-sdio.AP6212.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 16:19 brcmfmac43430-sdio.sinovoip,bpi-m2-zero.txt -> brcmfmac43430-sdio.AP6212.txt
-rw-r--r-- 1 root wheel 874 Jun 30 2019 brcmfmac43430-sdio.raspberrypi,3-model-b.txt
-rw-r--r-- 1 root wheel 1864 Jun 30 2019 brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 11:24 brcmfmac43455-sdio.raspberrypi,4-model-b-plus.txt -> brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
-
Add product ID for Broadcom BCM43455
-
Use correct firmware for BCM43456
-
size check was backwards.
-
Be less noisy for some commands.
-
Fix DWC_MMC_INT_SDIO_INT bit
-
dwc_mmc fixes:
- Rockchip uses a different SDIO int bit, so take this into consideration
- Avoid unnecessary resets and always wait for resets to complete
- kpause instead of delay while holding spinlock
- Do not attempt autostop for SD_IO_RW_EXTENDED commands
- Allow for sub-blklen byte counts for single block transfers
-
More SDIO stability and performance fixes
 1.35.2.1 03-Apr-2021  thorpej Sync with HEAD.
 1.36.24.1 02-Aug-2025  perseant Sync with HEAD
 1.36.18.2 02-Feb-2025  martin Pull up following revision(s) (requested by jmcneill in ticket #1041):

sys/dev/ic/bwi.c: revision 1.40
share/man/man4/bwi.4: revision 1.15
sys/dev/sdmmc/if_bwi_sdio.c: revision 1.1
sys/dev/ic/bwi.c: revision 1.41
sys/dev/sdmmc/sdmmcvar.h: revision 1.38
sys/dev/ic/bwireg.h: revision 1.5
sys/dev/ic/bwi.c: revision 1.39
sys/dev/ic/bwivar.h: revision 1.11
sys/dev/sdmmc/sdmmc_cis.c: revision 1.10
sys/dev/sdmmc/files.sdmmc: revision 1.6
sys/arch/evbppc/conf/WII: revision 1.7

bwi: Remove unnecessary pcivar.h include

sdmmc: Capture lan_nid and expose sdmmc_cisptr
LAN NID contains the MAC address for networking adapters.
Device drivers may want to processor vendor specific tuple codes, so
expose sdmmc_cisptr to help this.

bwi(4): Add support for Nintendo Wii WLAN.

Adapt the bwi(4) driver to support SDIO attachment and driving TX/RX using
PIO instead of DMA since the latter is not supported on SDIO busses.

fix uninitialized
 1.36.18.1 26-Oct-2024  martin Pull up following revision(s) (requested by jmcneill in ticket #985):

sys/dev/sdmmc/sdmmcvar.h: revision 1.37
sys/dev/sdmmc/sdmmcreg.h: revision 1.35
sys/dev/sdmmc/ld_sdmmc.c: revision 1.44
sys/dev/sdmmc/sdmmc_mem.c: revision 1.76

sdmmc: Add support for SD card caches.

SD physical 6.0 specification introduced Application Performance Class 2
(A2), which adds support for drive caches and command queueing.

Add support for enabling and flushing the cache when this feature is
present.

RSS XML Feed