From b4828cc1dda89713d9262cca25dfd81fb206140a Mon Sep 17 00:00:00 2001
From: John Baldwin <jhb@FreeBSD.org>
Date: Thu, 5 Oct 2006 15:35:11 +0000
Subject: [PATCH] Add detailed debugging printf's for SMIC under SMIC_DEBUG.

---
 sys/dev/ipmi/ipmi_smic.c | 52 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 50 insertions(+), 2 deletions(-)

diff --git a/sys/dev/ipmi/ipmi_smic.c b/sys/dev/ipmi/ipmi_smic.c
index a0cf6b269b1a..facb8b32488d 100644
--- a/sys/dev/ipmi/ipmi_smic.c
+++ b/sys/dev/ipmi/ipmi_smic.c
@@ -247,28 +247,52 @@ smic_polled_request(struct ipmi_softc *sc, struct ipmi_request *req)
 	/* First, start the message with the address. */
 	if (!smic_start_write(sc, req->ir_addr))
 		return (0);
+#ifdef SMIC_DEBUG
+	device_printf(sc->ipmi_dev, "SMIC: WRITE_START address: %02x\n",
+	    req->ir_addr);
+#endif
 
 	if (req->ir_requestlen == 0) {
 		/* Send the command as the last byte. */
 		if (!smic_write_last(sc, req->ir_command))
 			return (0);
+#ifdef SMIC_DEBUG
+		device_printf(sc->ipmi_dev, "SMIC: Wrote command: %02x\n",
+		    req->ir_command);
+#endif
 	} else {
 		/* Send the command. */
 		if (!smic_write_next(sc, req->ir_command))
 			return (0);
+#ifdef SMIC_DEBUG
+		device_printf(sc->ipmi_dev, "SMIC: Wrote command: %02x\n",
+		    req->ir_command);
+#endif
 
 		/* Send the payload. */
 		cp = req->ir_request;
-		for (i = 0; i < req->ir_requestlen - 1; i++)
+		for (i = 0; i < req->ir_requestlen - 1; i++) {
 			if (!smic_write_next(sc, *cp++))
 				return (0);
+#ifdef SMIC_DEBUG
+			device_printf(sc->ipmi_dev, "SMIC: Wrote data: %02x\n",
+			    cp[-1]);
+#endif
+		}
 		if (!smic_write_last(sc, *cp))
 			return (0);
+#ifdef SMIC_DEBUG
+		device_printf(sc->ipmi_dev, "SMIC: Write last data: %02x\n",
+		    *cp);
+#endif
 	}
 
 	/* Start the read phase by reading the NetFn/LUN. */
 	if (smic_start_read(sc, &data) != 1)
 		return (0);
+#ifdef SMIC_DEBUG
+	device_printf(sc->ipmi_dev, "SMIC: Read address: %02x\n", data);
+#endif
 	if (data != IPMI_REPLY_ADDR(req->ir_addr)) {
 		device_printf(sc->ipmi_dev, "SMIC: Reply address mismatch\n");
 		return (0);
@@ -277,6 +301,9 @@ smic_polled_request(struct ipmi_softc *sc, struct ipmi_request *req)
 	/* Read the command. */
 	if (smic_read_byte(sc, &data) != 1)
 		return (0);
+#ifdef SMIC_DEBUG
+	device_printf(sc->ipmi_dev, "SMIC: Read command: %02x\n", data);
+#endif
 	if (data != req->ir_command) {
 		device_printf(sc->ipmi_dev, "SMIC: Command mismatch\n");
 		return (0);
@@ -286,6 +313,10 @@ smic_polled_request(struct ipmi_softc *sc, struct ipmi_request *req)
 	state = smic_read_byte(sc, &req->ir_compcode);
 	if (state == 0)
 		return (0);
+#ifdef SMIC_DEBUG
+	device_printf(sc->ipmi_dev, "SMIC: Read completion code: %02x\n",
+	    req->ir_compcode);
+#endif
 
 	/* Finally, read the reply from the BMC. */
 	i = 0;
@@ -293,8 +324,16 @@ smic_polled_request(struct ipmi_softc *sc, struct ipmi_request *req)
 		state = smic_read_byte(sc, &data);
 		if (state == 0)
 			return (0);
-		if (i < req->ir_replybuflen)
+		if (i < req->ir_replybuflen) {
 			req->ir_reply[i] = data;
+#ifdef SMIC_DEBUG
+			device_printf(sc->ipmi_dev, "SMIC: Read data: %02x\n",
+			    data);
+		} else {
+			device_printf(sc->ipmi_dev,
+			    "SMIC: Read short %02x byte %d\n", data, i + 1);
+#endif
+		}
 		i++;
 	}
 
@@ -302,7 +341,12 @@ smic_polled_request(struct ipmi_softc *sc, struct ipmi_request *req)
 	if (!smic_read_end(sc))
 		return (0);
 	req->ir_replylen = i;
+#ifdef SMIC_DEBUG
+	device_printf(sc->ipmi_dev, "SMIC: READ finished (%d bytes)\n", i);
+	if (req->ir_replybuflen < i)
+#else
 	if (req->ir_replybuflen < i && req->ir_replybuflen != 0)
+#endif
 		device_printf(sc->ipmi_dev,
 		    "SMIC: Read short: %zd buffer, %d actual\n",
 		    req->ir_replybuflen, i);
@@ -355,5 +399,9 @@ ipmi_smic_attach(struct ipmi_softc *sc)
 		return (ENXIO);
 	}
 
+#ifdef SMIC_DEBUG
+	device_printf(sc->ipmi_dev, "SMIC: initial state: %02x\n", flags);
+#endif
+
 	return (0);
 }