Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 14 Oct 2015 23:41:41 +0000 (UTC)
From:      Ian Lepore <ian@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r289339 - stable/10/sys/dev/mmc
Message-ID:  <201510142341.t9ENffmn050023@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ian
Date: Wed Oct 14 23:41:41 2015
New Revision: 289339
URL: https://svnweb.freebsd.org/changeset/base/289339

Log:
  MFC r261994, r275905, r275951, r276106, r283128, r285678: MMC driver fixes...
  
    If no compatible cards were found after probing the bus, say so.
  
    Don't deselect the card too soon. To set the block size or switch the
    function parameters, the card has to be in transfer state. If it is in
    the idle state, the commands are ignored. This caused us not to set
    the proper parameters that we later assume to be present, leading to
    downstream failures of the card / interface as our state machine
    mismatches the card's.
  
    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.
  
    Always select the card before we do the 4.x specific stuff and
    deselect it after setting the block size. This is a similar bug that
    was fixed elsewhere, but not here. This makes sure that we leave the
    card deselected at the end of the loop, and we don't send any commands
    to the card without it selected.
  
    Re-select the SD card before getting the SD status. On a couple Atmel
    boards, this prevents some error messages during enumeration and also
    gives us the correct erase block size. They appear to be harmless
    elsewhere.
  
    Deselect the sd card before re-selecting it when working around a problem
    with some cards that causes them to become deselected after probing for
    switch capabilities.  The old workaround fixes the behavior with some cards,
    but causes problems with the cards the behave correctly and don't become
    deselected.  Forcing a deselect then reselect appears to work correctly
    with all cards in initial testing.

Modified:
  stable/10/sys/dev/mmc/mmc.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/dev/mmc/mmc.c
==============================================================================
--- stable/10/sys/dev/mmc/mmc.c	Wed Oct 14 23:29:19 2015	(r289338)
+++ stable/10/sys/dev/mmc/mmc.c	Wed Oct 14 23:41:41 2015	(r289339)
@@ -1379,6 +1379,21 @@ mmc_discover_cards(struct mmc_softc *sc)
 					ivar->hs_tran_speed = SD_MAX_HS;
 				}
 			}
+
+			/*
+			 * We deselect then reselect the card here.  Some cards
+			 * become unselected and timeout with the above two
+			 * commands, although the state tables / diagrams in the
+			 * standard suggest they go back to the transfer state.
+			 * Other cards don't become deselected, and if we
+			 * atttempt to blindly re-select them, we get timeout
+			 * errors from some controllers.  So we deselect then
+			 * reselect to handle all situations.  The only thing we
+			 * use from the sd_status is the erase sector size, but
+			 * it is still nice to get that right.
+			 */
+			mmc_select_card(sc, 0);
+			mmc_select_card(sc, ivar->rca);
 			mmc_app_sd_status(sc, ivar->rca, ivar->raw_sd_status);
 			mmc_app_decode_sd_status(ivar->raw_sd_status,
 			    &ivar->sd_status);
@@ -1386,7 +1401,6 @@ mmc_discover_cards(struct mmc_softc *sc)
 				ivar->erase_sector =
 				    16 << ivar->sd_status.au_size;
 			}
-			mmc_select_card(sc, 0);
 			/* Find max supported bus width. */
 			if ((mmcbr_get_caps(sc->dev) & MMC_CAP_4_BIT_DATA) &&
 			    (ivar->scr.bus_widths & SD_SCR_BUS_WIDTH_4))
@@ -1414,6 +1428,7 @@ mmc_discover_cards(struct mmc_softc *sc)
 				child = device_add_child(sc->dev, NULL, -1);
 				device_set_ivars(child, ivar);
 			}
+			mmc_select_card(sc, 0);
 			return;
 		}
 		mmc_decode_cid_mmc(ivar->raw_cid, &ivar->cid);
@@ -1446,10 +1461,10 @@ mmc_discover_cards(struct mmc_softc *sc)
 			break;
 		}
 
+		mmc_select_card(sc, ivar->rca);
+
 		/* Only MMC >= 4.x cards support EXT_CSD. */
 		if (ivar->csd.spec_vers >= 4) {
-			/* Card must be selected to fetch EXT_CSD. */
-			mmc_select_card(sc, ivar->rca);
 			mmc_send_ext_csd(sc, ivar->raw_ext_csd);
 			/* Handle extended capacity from EXT_CSD */
 			sec_count = ivar->raw_ext_csd[EXT_CSD_SEC_CNT] +
@@ -1472,7 +1487,6 @@ mmc_discover_cards(struct mmc_softc *sc)
 				ivar->hs_tran_speed = ivar->tran_speed;
 			/* Find max supported bus width. */
 			ivar->bus_width = mmc_test_bus_width(sc);
-			mmc_select_card(sc, 0);
 			/* Handle HC erase sector size. */
 			if (ivar->raw_ext_csd[EXT_CSD_ERASE_GRP_SIZE] != 0) {
 				ivar->erase_sector = 1024 *
@@ -1506,6 +1520,7 @@ mmc_discover_cards(struct mmc_softc *sc)
 			child = device_add_child(sc->dev, NULL, -1);
 			device_set_ivars(child, ivar);
 		}
+		mmc_select_card(sc, 0);
 	}
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201510142341.t9ENffmn050023>