Home | History | Annotate | Download | only in sdmmc
History log of /src/sys/dev/sdmmc/ld_sdmmc.c
RevisionDateAuthorComments
 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 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.

RSS XML Feed