CVS commit: [netbsd-8] src/sys/dev/sdmmc

2020-08-05 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Aug  5 16:14:25 UTC 2020

Modified Files:
src/sys/dev/sdmmc [netbsd-8]: sdhc.c sdhcreg.h

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.100.4.1 -r1.100.4.2 src/sys/dev/sdmmc/sdhc.c
cvs rdiff -u -r1.18.10.1 -r1.18.10.2 src/sys/dev/sdmmc/sdhcreg.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/sdmmc/sdhc.c
diff -u src/sys/dev/sdmmc/sdhc.c:1.100.4.1 src/sys/dev/sdmmc/sdhc.c:1.100.4.2
--- src/sys/dev/sdmmc/sdhc.c:1.100.4.1	Sun Jan  7 09:24:59 2018
+++ src/sys/dev/sdmmc/sdhc.c	Wed Aug  5 16:14:25 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sdhc.c,v 1.100.4.1 2018/01/07 09:24:59 snj Exp $	*/
+/*	$NetBSD: sdhc.c,v 1.100.4.2 2020/08/05 16:14:25 martin Exp $	*/
 /*	$OpenBSD: sdhc.c,v 1.25 2009/01/13 19:44:20 grange Exp $	*/
 
 /*
@@ -23,7 +23,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sdhc.c,v 1.100.4.1 2018/01/07 09:24:59 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sdhc.c,v 1.100.4.2 2020/08/05 16:14:25 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_sdmmc.h"
@@ -316,6 +316,12 @@ sdhc_host_found(struct sdhc_softc *sc, b
 	case SDHC_SPEC_VERS_400:
 		aprint_normal("4.0");
 		break;
+	case SDHC_SPEC_VERS_410:
+		aprint_normal("4.1");
+		break;
+	case SDHC_SPEC_VERS_420:
+		aprint_normal("4.2");
+		break;
 	case SDHC_SPEC_NOVERS:
 		hp->specver = -1;
 		aprint_normal("NO-VERS");

Index: src/sys/dev/sdmmc/sdhcreg.h
diff -u src/sys/dev/sdmmc/sdhcreg.h:1.18.10.1 src/sys/dev/sdmmc/sdhcreg.h:1.18.10.2
--- src/sys/dev/sdmmc/sdhcreg.h:1.18.10.1	Sun Jan  7 09:24:59 2018
+++ src/sys/dev/sdmmc/sdhcreg.h	Wed Aug  5 16:14:25 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sdhcreg.h,v 1.18.10.1 2018/01/07 09:24:59 snj Exp $	*/
+/*	$NetBSD: sdhcreg.h,v 1.18.10.2 2020/08/05 16:14:25 martin Exp $	*/
 /*	$OpenBSD: sdhcreg.h,v 1.4 2006/07/30 17:20:40 fgsch Exp $	*/
 
 /*
@@ -246,6 +246,8 @@
 #define SDHC_SPEC_VERS_200		0x01
 #define SDHC_SPEC_VERS_300		0x02
 #define SDHC_SPEC_VERS_400		0x03
+#define SDHC_SPEC_VERS_410		0x04
+#define SDHC_SPEC_VERS_420		0x05
 #define SDHC_SPEC_NOVERS		0xff	/* dummy */
 
 /* SDHC_CAPABILITIES decoding */



CVS commit: [netbsd-8] src/sys/dev/sdmmc

2018-02-11 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Sun Feb 11 21:29:18 UTC 2018

Modified Files:
src/sys/dev/sdmmc [netbsd-8]: sdmmc_mem.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.56.4.4 -r1.56.4.5 src/sys/dev/sdmmc/sdmmc_mem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/sdmmc/sdmmc_mem.c
diff -u src/sys/dev/sdmmc/sdmmc_mem.c:1.56.4.4 src/sys/dev/sdmmc/sdmmc_mem.c:1.56.4.5
--- src/sys/dev/sdmmc/sdmmc_mem.c:1.56.4.4	Fri Sep  1 09:59:10 2017
+++ src/sys/dev/sdmmc/sdmmc_mem.c	Sun Feb 11 21:29:18 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: sdmmc_mem.c,v 1.56.4.4 2017/09/01 09:59:10 martin Exp $	*/
+/*	$NetBSD: sdmmc_mem.c,v 1.56.4.5 2018/02/11 21:29:18 snj Exp $	*/
 /*	$OpenBSD: sdmmc_mem.c,v 1.10 2009/01/09 10:55:22 jsg Exp $	*/
 
 /*
@@ -45,7 +45,7 @@
 /* Routines for SD/MMC memory cards. */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sdmmc_mem.c,v 1.56.4.4 2017/09/01 09:59:10 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sdmmc_mem.c,v 1.56.4.5 2018/02/11 21:29:18 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_sdmmc.h"
@@ -644,10 +644,14 @@ sdmmc_mem_send_op_cond(struct sdmmc_soft
 		error = ETIMEDOUT;
 		sdmmc_delay(1);
 	}
-	if (error == 0 &&
-	ocrp != NULL &&
-	!ISSET(sc->sc_caps, SMC_CAPS_SPI_MODE))
-		*ocrp = MMC_R3(cmd.c_resp);
+	if (ocrp != NULL) {
+		if (error == 0 &&
+		!ISSET(sc->sc_caps, SMC_CAPS_SPI_MODE)) {
+			*ocrp = MMC_R3(cmd.c_resp);
+		} else {
+			*ocrp = ocr;
+		}
+	}
 	DPRINTF(("%s: sdmmc_mem_send_op_cond: error=%d, ocr=%#x\n",
 	SDMMCDEVNAME(sc), error, MMC_R3(cmd.c_resp)));
 	return error;



CVS commit: [netbsd-8] src/sys/dev/sdmmc

2018-01-07 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Sun Jan  7 09:24:59 UTC 2018

Modified Files:
src/sys/dev/sdmmc [netbsd-8]: sdhc.c sdhcreg.h

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.100.4.1 src/sys/dev/sdmmc/sdhc.c
cvs rdiff -u -r1.18 -r1.18.10.1 src/sys/dev/sdmmc/sdhcreg.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/sdmmc/sdhc.c
diff -u src/sys/dev/sdmmc/sdhc.c:1.100 src/sys/dev/sdmmc/sdhc.c:1.100.4.1
--- src/sys/dev/sdmmc/sdhc.c:1.100	Sat Apr 22 21:49:41 2017
+++ src/sys/dev/sdmmc/sdhc.c	Sun Jan  7 09:24:59 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: sdhc.c,v 1.100 2017/04/22 21:49:41 jmcneill Exp $	*/
+/*	$NetBSD: sdhc.c,v 1.100.4.1 2018/01/07 09:24:59 snj Exp $	*/
 /*	$OpenBSD: sdhc.c,v 1.25 2009/01/13 19:44:20 grange Exp $	*/
 
 /*
@@ -23,7 +23,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sdhc.c,v 1.100 2017/04/22 21:49:41 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sdhc.c,v 1.100.4.1 2018/01/07 09:24:59 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_sdmmc.h"
@@ -292,42 +292,41 @@ sdhc_host_found(struct sdhc_softc *sc, b
 	callout_init(>tuning_timer, CALLOUT_MPSAFE);
 	callout_setfunc(>tuning_timer, sdhc_tuning_timer, hp);
 
-	if (iosize <= SDHC_HOST_CTL_VERSION) {
-		aprint_normal_dev(sc->sc_dev, "SDHC NO-VERS");
-		hp->specver = -1;
+	if (ISSET(hp->sc->sc_flags, SDHC_FLAG_USDHC)) {
+		sdhcver = SDHC_SPEC_VERS_300 << SDHC_SPEC_VERS_SHIFT;
+	} else if (ISSET(hp->sc->sc_flags, SDHC_FLAG_ENHANCED)) {
+		sdhcver = HREAD4(hp, SDHC_ESDHC_HOST_CTL_VERSION);
+	} else if (iosize <= SDHC_HOST_CTL_VERSION) {
+		sdhcver = SDHC_SPEC_NOVERS << SDHC_SPEC_VERS_SHIFT;
 	} else {
-		if (ISSET(hp->sc->sc_flags, SDHC_FLAG_USDHC)) {
-			sdhcver = SDHC_SPEC_VERS_300 << SDHC_SPEC_VERS_SHIFT;
-		} else if (ISSET(hp->sc->sc_flags, SDHC_FLAG_ENHANCED)) {
-			sdhcver = HREAD4(hp, SDHC_ESDHC_HOST_CTL_VERSION);
-		} else
-			sdhcver = HREAD2(hp, SDHC_HOST_CTL_VERSION);
-		aprint_normal_dev(sc->sc_dev, "SDHC ");
-		hp->specver = SDHC_SPEC_VERSION(sdhcver);
-		switch (SDHC_SPEC_VERSION(sdhcver)) {
-		case SDHC_SPEC_VERS_100:
-			aprint_normal("1.0");
-			break;
-
-		case SDHC_SPEC_VERS_200:
-			aprint_normal("2.0");
-			break;
-
-		case SDHC_SPEC_VERS_300:
-			aprint_normal("3.0");
-			break;
-
-		case SDHC_SPEC_VERS_400:
-			aprint_normal("4.0");
-			break;
-
-		default:
-			aprint_normal("unknown version(0x%x)",
-			SDHC_SPEC_VERSION(sdhcver));
-			break;
-		}
-		aprint_normal(", rev %u", SDHC_VENDOR_VERSION(sdhcver));
+		sdhcver = HREAD2(hp, SDHC_HOST_CTL_VERSION);
+	}
+	aprint_normal_dev(sc->sc_dev, "SDHC ");
+	hp->specver = SDHC_SPEC_VERSION(sdhcver);
+	switch (SDHC_SPEC_VERSION(sdhcver)) {
+	case SDHC_SPEC_VERS_100:
+		aprint_normal("1.0");
+		break;
+	case SDHC_SPEC_VERS_200:
+		aprint_normal("2.0");
+		break;
+	case SDHC_SPEC_VERS_300:
+		aprint_normal("3.0");
+		break;
+	case SDHC_SPEC_VERS_400:
+		aprint_normal("4.0");
+		break;
+	case SDHC_SPEC_NOVERS:
+		hp->specver = -1;
+		aprint_normal("NO-VERS");
+		break;
+	default:
+		aprint_normal("unknown version(0x%x)",
+		SDHC_SPEC_VERSION(sdhcver));
+		break;
 	}
+	if (SDHC_SPEC_VERSION(sdhcver) != SDHC_SPEC_NOVERS)
+		aprint_normal(", rev %u", SDHC_VENDOR_VERSION(sdhcver));
 
 	/*
 	 * Reset the host controller and enable interrupts.

Index: src/sys/dev/sdmmc/sdhcreg.h
diff -u src/sys/dev/sdmmc/sdhcreg.h:1.18 src/sys/dev/sdmmc/sdhcreg.h:1.18.10.1
--- src/sys/dev/sdmmc/sdhcreg.h:1.18	Thu Dec 31 11:53:19 2015
+++ src/sys/dev/sdmmc/sdhcreg.h	Sun Jan  7 09:24:59 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: sdhcreg.h,v 1.18 2015/12/31 11:53:19 ryo Exp $	*/
+/*	$NetBSD: sdhcreg.h,v 1.18.10.1 2018/01/07 09:24:59 snj Exp $	*/
 /*	$OpenBSD: sdhcreg.h,v 1.4 2006/07/30 17:20:40 fgsch Exp $	*/
 
 /*
@@ -246,6 +246,7 @@
 #define SDHC_SPEC_VERS_200		0x01
 #define SDHC_SPEC_VERS_300		0x02
 #define SDHC_SPEC_VERS_400		0x03
+#define SDHC_SPEC_NOVERS		0xff	/* dummy */
 
 /* SDHC_CAPABILITIES decoding */
 #define SDHC_BASE_V3_FREQ_KHZ(cap)	\



CVS commit: [netbsd-8] src/sys/dev/sdmmc

2017-07-10 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Jul 10 12:29:47 UTC 2017

Modified Files:
src/sys/dev/sdmmc [netbsd-8]: ld_sdmmc.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.26.4.2 -r1.26.4.3 src/sys/dev/sdmmc/ld_sdmmc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/sdmmc/ld_sdmmc.c
diff -u src/sys/dev/sdmmc/ld_sdmmc.c:1.26.4.2 src/sys/dev/sdmmc/ld_sdmmc.c:1.26.4.3
--- src/sys/dev/sdmmc/ld_sdmmc.c:1.26.4.2	Sat Jul  1 08:45:03 2017
+++ src/sys/dev/sdmmc/ld_sdmmc.c	Mon Jul 10 12:29:47 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ld_sdmmc.c,v 1.26.4.2 2017/07/01 08:45:03 snj Exp $	*/
+/*	$NetBSD: ld_sdmmc.c,v 1.26.4.3 2017/07/10 12:29:47 martin Exp $	*/
 
 /*
  * Copyright (c) 2008 KIYOHARA Takashi
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ld_sdmmc.c,v 1.26.4.2 2017/07/01 08:45:03 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld_sdmmc.c,v 1.26.4.3 2017/07/10 12:29:47 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_sdmmc.h"
@@ -157,7 +157,7 @@ ld_sdmmc_attach(device_t parent, device_
 	 * when wedge is supported.
 	 */
 	config_pending_incr(self);
-	if (kthread_create(PRI_NONE, KTHREAD_MPSAFE, NULL,
+	if (kthread_create(PRI_NONE, 0, NULL,
 	ld_sdmmc_doattach, sc, , "%sattach", device_xname(self))) {
 		aprint_error_dev(self, "couldn't create thread\n");
 	}



CVS commit: [netbsd-8] src/sys/dev/sdmmc

2017-07-01 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Sat Jul  1 08:45:03 UTC 2017

Modified Files:
src/sys/dev/sdmmc [netbsd-8]: ld_sdmmc.c sdmmc_mem.c sdmmcreg.h
sdmmcvar.h

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.26.4.1 -r1.26.4.2 src/sys/dev/sdmmc/ld_sdmmc.c
cvs rdiff -u -r1.56.4.1 -r1.56.4.2 src/sys/dev/sdmmc/sdmmc_mem.c
cvs rdiff -u -r1.29 -r1.29.6.1 src/sys/dev/sdmmc/sdmmcreg.h
cvs rdiff -u -r1.23.6.1 -r1.23.6.2 src/sys/dev/sdmmc/sdmmcvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/sdmmc/ld_sdmmc.c
diff -u src/sys/dev/sdmmc/ld_sdmmc.c:1.26.4.1 src/sys/dev/sdmmc/ld_sdmmc.c:1.26.4.2
--- src/sys/dev/sdmmc/ld_sdmmc.c:1.26.4.1	Fri Jun  9 16:52:10 2017
+++ src/sys/dev/sdmmc/ld_sdmmc.c	Sat Jul  1 08:45:03 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ld_sdmmc.c,v 1.26.4.1 2017/06/09 16:52:10 snj Exp $	*/
+/*	$NetBSD: ld_sdmmc.c,v 1.26.4.2 2017/07/01 08:45:03 snj Exp $	*/
 
 /*
  * Copyright (c) 2008 KIYOHARA Takashi
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ld_sdmmc.c,v 1.26.4.1 2017/06/09 16:52:10 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld_sdmmc.c,v 1.26.4.2 2017/07/01 08:45:03 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_sdmmc.h"
@@ -93,6 +93,7 @@ static int ld_sdmmc_detach(device_t, int
 static int ld_sdmmc_dump(struct ld_softc *, void *, int, int);
 static int ld_sdmmc_start(struct ld_softc *, struct buf *);
 static void ld_sdmmc_restart(void *);
+static int ld_sdmmc_discard(struct ld_softc *, off_t, off_t);
 
 static void ld_sdmmc_doattach(void *);
 static void ld_sdmmc_dobio(void *);
@@ -149,6 +150,7 @@ ld_sdmmc_attach(device_t parent, device_
 	ld->sc_maxqueuecnt = LD_SDMMC_MAXQUEUECNT;
 	ld->sc_dump = ld_sdmmc_dump;
 	ld->sc_start = ld_sdmmc_start;
+	ld->sc_discard = ld_sdmmc_discard;
 
 	/*
 	 * It is avoided that the error occurs when the card attaches it,
@@ -297,6 +299,14 @@ ld_sdmmc_dump(struct ld_softc *ld, void 
 	blkcnt * ld->sc_secsize);
 }
 
+static int
+ld_sdmmc_discard(struct ld_softc *ld, off_t pos, off_t len)
+{
+	struct ld_sdmmc_softc *sc = device_private(ld->sc_dv);
+
+	return sdmmc_mem_discard(sc->sc_sf, pos, len);
+}
+
 MODULE(MODULE_CLASS_DRIVER, ld_sdmmc, "ld");
 
 #ifdef _MODULE

Index: src/sys/dev/sdmmc/sdmmc_mem.c
diff -u src/sys/dev/sdmmc/sdmmc_mem.c:1.56.4.1 src/sys/dev/sdmmc/sdmmc_mem.c:1.56.4.2
--- src/sys/dev/sdmmc/sdmmc_mem.c:1.56.4.1	Sun Jun  4 20:45:54 2017
+++ src/sys/dev/sdmmc/sdmmc_mem.c	Sat Jul  1 08:45:03 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: sdmmc_mem.c,v 1.56.4.1 2017/06/04 20:45:54 bouyer Exp $	*/
+/*	$NetBSD: sdmmc_mem.c,v 1.56.4.2 2017/07/01 08:45:03 snj Exp $	*/
 /*	$OpenBSD: sdmmc_mem.c,v 1.10 2009/01/09 10:55:22 jsg Exp $	*/
 
 /*
@@ -45,7 +45,7 @@
 /* Routines for SD/MMC memory cards. */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sdmmc_mem.c,v 1.56.4.1 2017/06/04 20:45:54 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sdmmc_mem.c,v 1.56.4.2 2017/07/01 08:45:03 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_sdmmc.h"
@@ -79,6 +79,10 @@ static int sdmmc_mem_send_csd(struct sdm
 static int sdmmc_mem_send_scr(struct sdmmc_softc *, struct sdmmc_function *,
 uint32_t *scr);
 static int sdmmc_mem_decode_scr(struct sdmmc_softc *, struct sdmmc_function *);
+static int sdmmc_mem_send_ssr(struct sdmmc_softc *, struct sdmmc_function *,
+sdmmc_bitfield512_t *);
+static int sdmmc_mem_decode_ssr(struct sdmmc_softc *, struct sdmmc_function *,
+sdmmc_bitfield512_t *);
 static int sdmmc_mem_send_cxd_data(struct sdmmc_softc *, int, void *, size_t);
 static int sdmmc_set_bus_width(struct sdmmc_function *, int);
 static int sdmmc_mem_sd_switch(struct sdmmc_function *, int, int, int, sdmmc_bitfield512_t *);
@@ -778,7 +782,7 @@ static int
 sdmmc_mem_sd_init(struct sdmmc_softc *sc, struct sdmmc_function *sf)
 {
 	int support_func, best_func, bus_clock, error, i;
-	sdmmc_bitfield512_t status; /* Switch Function Status */
+	sdmmc_bitfield512_t status;
 	bool ddr = false;
 
 	/* change bus clock */
@@ -888,6 +892,15 @@ sdmmc_mem_sd_init(struct sdmmc_softc *sc
 	sc->sc_transfer_mode = switch_group0_functions[best_func].name;
 	sc->sc_busddr = ddr;
 
+	/* get card status */
+	error = 

CVS commit: [netbsd-8] src/sys/dev/sdmmc

2017-06-09 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Fri Jun  9 16:52:10 UTC 2017

Modified Files:
src/sys/dev/sdmmc [netbsd-8]: ld_sdmmc.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.26.4.1 src/sys/dev/sdmmc/ld_sdmmc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/sdmmc/ld_sdmmc.c
diff -u src/sys/dev/sdmmc/ld_sdmmc.c:1.26 src/sys/dev/sdmmc/ld_sdmmc.c:1.26.4.1
--- src/sys/dev/sdmmc/ld_sdmmc.c:1.26	Sat Apr 22 14:19:36 2017
+++ src/sys/dev/sdmmc/ld_sdmmc.c	Fri Jun  9 16:52:10 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ld_sdmmc.c,v 1.26 2017/04/22 14:19:36 jmcneill Exp $	*/
+/*	$NetBSD: ld_sdmmc.c,v 1.26.4.1 2017/06/09 16:52:10 snj Exp $	*/
 
 /*
  * Copyright (c) 2008 KIYOHARA Takashi
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ld_sdmmc.c,v 1.26 2017/04/22 14:19:36 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld_sdmmc.c,v 1.26.4.1 2017/06/09 16:52:10 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_sdmmc.h"
@@ -48,6 +48,7 @@ __KERNEL_RCSID(0, "$NetBSD: ld_sdmmc.c,v
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -82,7 +83,7 @@ struct ld_sdmmc_softc {
 	struct sdmmc_function *sc_sf;
 #define LD_SDMMC_MAXQUEUECNT 4
 	struct ld_sdmmc_task sc_task[LD_SDMMC_MAXQUEUECNT];
-	TAILQ_HEAD(, sdmmc_task) sc_freeq;
+	pcq_t *sc_freeq;
 };
 
 static int ld_sdmmc_match(device_t, cfdata_t, void *);
@@ -129,12 +130,13 @@ ld_sdmmc_attach(device_t parent, device_
 	sa->sf->cid.rev, sa->sf->cid.psn, sa->sf->cid.mdt);
 	aprint_naive("\n");
 
-	TAILQ_INIT(>sc_freeq);
-	for (i = 0; i < __arraycount(sc->sc_task); i++) {
+	const int ntask = __arraycount(sc->sc_task);
+	sc->sc_freeq = pcq_create(ntask, KM_SLEEP);
+	for (i = 0; i < ntask; i++) {
 		task = >sc_task[i];
 		task->task_sc = sc;
-		callout_init(>task_restart_ch, 0);
-		TAILQ_INSERT_TAIL(>sc_freeq, >task, next);
+		callout_init(>task_restart_ch, CALLOUT_MPSAFE);
+		pcq_put(sc->sc_freeq, task);
 	}
 
 	sc->sc_hwunit = 0;	/* always 0? */
@@ -193,6 +195,8 @@ ld_sdmmc_detach(device_t dev, int flags)
 	for (i = 0; i < __arraycount(sc->sc_task); i++)
 		callout_destroy(>sc_task[i].task_restart_ch);
 
+	pcq_destroy(sc->sc_freeq);
+
 	return 0;
 }
 
@@ -200,9 +204,10 @@ static int
 ld_sdmmc_start(struct ld_softc *ld, struct buf *bp)
 {
 	struct ld_sdmmc_softc *sc = device_private(ld->sc_dv);
-	struct ld_sdmmc_task *task = (void *)TAILQ_FIRST(>sc_freeq);
+	struct ld_sdmmc_task *task = pcq_get(sc->sc_freeq);
 
-	TAILQ_REMOVE(>sc_freeq, >task, next);
+	if (task == NULL)
+		return EAGAIN;
 
 	task->task_bp = bp;
 	task->task_retries = 0;
@@ -278,7 +283,7 @@ ld_sdmmc_dobio(void *arg)
 	}
 
 done:
-	TAILQ_INSERT_TAIL(>sc_freeq, >task, next);
+	pcq_put(sc->sc_freeq, task);
 
 	lddone(>sc_ld, bp);
 }