From owner-svn-src-all@FreeBSD.ORG Sat Dec 20 04:24:41 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id BBC35F84; Sat, 20 Dec 2014 04:24:41 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A81A725D6; Sat, 20 Dec 2014 04:24:41 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id sBK4OfqC070367; Sat, 20 Dec 2014 04:24:41 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id sBK4OfhE070366; Sat, 20 Dec 2014 04:24:41 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201412200424.sBK4OfhE070366@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Sat, 20 Dec 2014 04:24:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r275951 - head/sys/dev/mmc X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Dec 2014 04:24:41 -0000 Author: ian Date: Sat Dec 20 04:24:40 2014 New Revision: 275951 URL: https://svnweb.freebsd.org/changeset/base/275951 Log: Log mmc and sd command failures. Reporting of routine expected errors, such as timeouts while probing a bus or testing for a feature, is squelched. Also, error reporting is limited to 5 events per second, because when an sdcard goes bad on a low-end embedded board, flooding the console at high speed isn't helpful. Original logging code contributed by Michal Meloun, but then I fancied it up with squelching and ppsratecheck. Modified: head/sys/dev/mmc/mmc.c Modified: head/sys/dev/mmc/mmc.c ============================================================================== --- head/sys/dev/mmc/mmc.c Sat Dec 20 01:13:13 2014 (r275950) +++ head/sys/dev/mmc/mmc.c Sat Dec 20 04:24:40 2014 (r275951) @@ -63,6 +63,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -76,8 +77,13 @@ struct mmc_softc { struct intr_config_hook config_intrhook; device_t owner; uint32_t last_rca; + int squelched; /* suppress reporting of (expected) errors */ + int log_count; + struct timeval log_time; }; +#define LOG_PPS 5 /* Log no more than 5 errors per second. */ + /* * Per-card data */ @@ -426,6 +432,13 @@ mmc_wait_for_cmd(struct mmc_softc *sc, s err = cmd->error; } while (err != MMC_ERR_NONE && retries-- > 0); + if (err != MMC_ERR_NONE && sc->squelched == 0) { + if (ppsratecheck(&sc->log_time, &sc->log_count, LOG_PPS)) { + device_printf(sc->dev, "CMD%d failed, RESULT: %d\n", + cmd->opcode, err); + } + } + return (err); } @@ -436,6 +449,8 @@ mmc_wait_for_app_cmd(struct mmc_softc *s struct mmc_command appcmd; int err; + /* Squelch error reporting at lower levels, we report below. */ + sc->squelched++; do { memset(&appcmd, 0, sizeof(appcmd)); appcmd.opcode = MMC_APP_CMD; @@ -455,6 +470,14 @@ mmc_wait_for_app_cmd(struct mmc_softc *s err = cmd->error; } } while (err != MMC_ERR_NONE && retries-- > 0); + sc->squelched--; + + if (err != MMC_ERR_NONE && sc->squelched == 0) { + if (ppsratecheck(&sc->log_time, &sc->log_count, LOG_PPS)) { + device_printf(sc->dev, "ACMD%d failed, RESULT: %d\n", + cmd->opcode, err); + } + } return (err); } @@ -760,6 +783,7 @@ mmc_test_bus_width(struct mmc_softc *sc) mmcbr_set_bus_width(sc->dev, bus_width_8); mmcbr_update_ios(sc->dev); + sc->squelched++; /* Errors are expected, squelch reporting. */ memset(&cmd, 0, sizeof(cmd)); memset(&data, 0, sizeof(data)); cmd.opcode = MMC_BUSTEST_W; @@ -783,6 +807,7 @@ mmc_test_bus_width(struct mmc_softc *sc) data.len = 8; data.flags = MMC_DATA_READ; err = mmc_wait_for_cmd(sc, &cmd, 0); + sc->squelched--; mmcbr_set_bus_width(sc->dev, bus_width_1); mmcbr_update_ios(sc->dev); @@ -795,6 +820,7 @@ mmc_test_bus_width(struct mmc_softc *sc) mmcbr_set_bus_width(sc->dev, bus_width_4); mmcbr_update_ios(sc->dev); + sc->squelched++; /* Errors are expected, squelch reporting. */ memset(&cmd, 0, sizeof(cmd)); memset(&data, 0, sizeof(data)); cmd.opcode = MMC_BUSTEST_W; @@ -818,6 +844,7 @@ mmc_test_bus_width(struct mmc_softc *sc) data.len = 4; data.flags = MMC_DATA_READ; err = mmc_wait_for_cmd(sc, &cmd, 0); + sc->squelched--; mmcbr_set_bus_width(sc->dev, bus_width_1); mmcbr_update_ios(sc->dev); @@ -1270,7 +1297,9 @@ mmc_discover_cards(struct mmc_softc *sc) if (bootverbose || mmc_debug) device_printf(sc->dev, "Probing cards\n"); while (1) { + sc->squelched++; /* Errors are expected, squelch reporting. */ err = mmc_all_send_cid(sc, raw_cid); + sc->squelched--; if (err == MMC_ERR_TIMEOUT) break; if (err != MMC_ERR_NONE) { @@ -1536,6 +1565,7 @@ mmc_go_discovery(struct mmc_softc *sc) /* * First, try SD modes */ + sc->squelched++; /* Errors are expected, squelch reporting. */ mmcbr_set_mode(dev, mode_sd); mmc_power_up(sc); mmcbr_set_bus_mode(dev, pushpull); @@ -1561,6 +1591,7 @@ mmc_go_discovery(struct mmc_softc *sc) "MMC probe: OK (OCR: 0x%08x)\n", ocr); } else if (bootverbose || mmc_debug) device_printf(sc->dev, "SD probe: OK (OCR: 0x%08x)\n", ocr); + sc->squelched--; mmcbr_set_ocr(dev, mmc_select_vdd(sc, ocr)); if (mmcbr_get_ocr(dev) != 0)