git: c1a9422b9962 - stable/13 - rtsx: Display error if rtsx_read()/rtsx_write() fail.

From: Alexander Motin <mav_at_FreeBSD.org>
Date: Thu, 31 Mar 2022 01:49:15 UTC
The branch stable/13 has been updated by mav:

URL: https://cgit.FreeBSD.org/src/commit/?id=c1a9422b99623e3d8024d2c739ebc75954ef2e86

commit c1a9422b99623e3d8024d2c739ebc75954ef2e86
Author:     Henri Hennebert <hlh@restart.be>
AuthorDate: 2022-03-24 01:01:00 +0000
Commit:     Alexander Motin <mav@FreeBSD.org>
CommitDate: 2022-03-31 01:48:24 +0000

    rtsx: Display error if rtsx_read()/rtsx_write() fail.
    
    MFC after:      1 week
    
    (cherry picked from commit 9b261d2e0a4490e436936c5f9209f7cc100b4787)
---
 sys/dev/rtsx/rtsx.c | 34 ++++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/sys/dev/rtsx/rtsx.c b/sys/dev/rtsx/rtsx.c
index a8e0e4adeba1..5664be67181f 100644
--- a/sys/dev/rtsx/rtsx.c
+++ b/sys/dev/rtsx/rtsx.c
@@ -99,7 +99,6 @@ struct rtsx_softc {
 
 	int		rtsx_res_id;		/* bus memory resource id */
 	struct resource *rtsx_res;		/* bus memory resource */
-	int		rtsx_res_type;		/* bus memory resource type */
 	bus_space_tag_t	rtsx_btag;		/* host register set tag */
 	bus_space_handle_t rtsx_bhandle;	/* host register set handle */
 
@@ -173,7 +172,7 @@ struct rtsx_softc {
 #define	RTSX_RTL8411		0x5289
 #define	RTSX_RTL8411B		0x5287
 
-#define	RTSX_VERSION		"2.1e"
+#define	RTSX_VERSION		"2.1f"
 
 static const struct rtsx_device {
 	uint16_t	vendor_id;
@@ -1320,10 +1319,11 @@ static int
 rtsx_read(struct rtsx_softc *sc, uint16_t addr, uint8_t *val)
 {
 	int	 tries = 1024;
+	uint32_t arg;
 	uint32_t reg;
 
-	WRITE4(sc, RTSX_HAIMR, RTSX_HAIMR_BUSY |
-	    (uint32_t)((addr & 0x3FFF) << 16));
+	arg = RTSX_HAIMR_BUSY | (uint32_t)((addr & 0x3FFF) << 16);
+	WRITE4(sc, RTSX_HAIMR, arg);
 
 	while (tries--) {
 		reg = READ4(sc, RTSX_HAIMR);
@@ -1332,7 +1332,12 @@ rtsx_read(struct rtsx_softc *sc, uint16_t addr, uint8_t *val)
 	}
 	*val = (reg & 0xff);
 
-	return ((tries == 0) ? ETIMEDOUT : 0);
+	if (tries > 0) {
+		return (0);
+	} else {
+		device_printf(sc->rtsx_dev, "rtsx_read(0x%x) timeout\n", arg);
+		return (ETIMEDOUT);
+	}
 }
 
 static int
@@ -1368,21 +1373,25 @@ static int
 rtsx_write(struct rtsx_softc *sc, uint16_t addr, uint8_t mask, uint8_t val)
 {
 	int 	 tries = 1024;
+	uint32_t arg;
 	uint32_t reg;
 
-	WRITE4(sc, RTSX_HAIMR,
-	    RTSX_HAIMR_BUSY | RTSX_HAIMR_WRITE |
-	    (uint32_t)(((addr & 0x3FFF) << 16) |
-	    (mask << 8) | val));
+	arg = RTSX_HAIMR_BUSY | RTSX_HAIMR_WRITE |
+		(uint32_t)(((addr & 0x3FFF) << 16) |
+			   (mask << 8) | val);
+	WRITE4(sc, RTSX_HAIMR, arg);
 
 	while (tries--) {
 		reg = READ4(sc, RTSX_HAIMR);
 		if (!(reg & RTSX_HAIMR_BUSY)) {
-			if (val != (reg & 0xff))
+			if (val != (reg & 0xff)) {
+				device_printf(sc->rtsx_dev, "rtsx_write(0x%x) error reg=0x%x\n", arg, reg);
 				return (EIO);
+			}
 			return (0);
 		}
 	}
+	device_printf(sc->rtsx_dev, "rtsx_write(0x%x) timeout\n", arg);
 
 	return (ETIMEDOUT);
 }
@@ -3692,8 +3701,9 @@ rtsx_attach(device_t dev)
 #endif /* MMCCAM */
 
 	/* Initialize device. */
-	if (rtsx_init(sc)) {
-		device_printf(dev, "Error during rtsx_init()\n");
+	error = rtsx_init(sc);
+	if (error) {
+		device_printf(dev, "Error %d during rtsx_init()\n", error);
 		goto destroy_rtsx_irq;
 	}