Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 19 Jun 2018 20:02:04 +0000 (UTC)
From:      Ilya Bakulin <kibab@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r335384 - head/sys/cam/mmc
Message-ID:  <201806192002.w5JK24Pp093893@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kibab
Date: Tue Jun 19 20:02:03 2018
New Revision: 335384
URL: https://svnweb.freebsd.org/changeset/base/335384

Log:
  Fix setting RCA for MMC cards
  
  Unlike SD cards, that publish RCA in response to CMD3,
  MMC cards expect the host to set RCA itself.
  
  Since we don't support multiple MMC cards on the bus,
  just assign a static RCA of 2 to the attached MMC card.
  
  Approved by:	imp (mentor)
  Differential Revision:	https://reviews.freebsd.org/D13063

Modified:
  head/sys/cam/mmc/mmc.h
  head/sys/cam/mmc/mmc_xpt.c

Modified: head/sys/cam/mmc/mmc.h
==============================================================================
--- head/sys/cam/mmc/mmc.h	Tue Jun 19 19:27:37 2018	(r335383)
+++ head/sys/cam/mmc/mmc.h	Tue Jun 19 20:02:03 2018	(r335384)
@@ -94,4 +94,12 @@ struct mmc_params {
         uint8_t sdio_func_count;
 } __packed;
 
+/*
+ * Only one MMC card on bus is supported now.
+ * If we ever want to support multiple MMC cards on the same bus,
+ * mmc_xpt needs to be extended to issue new RCAs based on number
+ * of already probed cards. Furthermore, retuning and high-speed
+ * settings should also take all cards into account.
+ */
+#define MMC_PROPOSED_RCA    2
 #endif

Modified: head/sys/cam/mmc/mmc_xpt.c
==============================================================================
--- head/sys/cam/mmc/mmc_xpt.c	Tue Jun 19 19:27:37 2018	(r335383)
+++ head/sys/cam/mmc/mmc_xpt.c	Tue Jun 19 20:02:03 2018	(r335384)
@@ -98,7 +98,8 @@ typedef enum {
         PROBE_GET_CID,
         PROBE_GET_CSD,
         PROBE_SEND_RELATIVE_ADDR,
-        PROBE_SELECT_CARD,
+	PROBE_MMC_SET_RELATIVE_ADDR,
+	PROBE_SELECT_CARD,
 	PROBE_DONE,
 	PROBE_INVALID
 } probe_action;
@@ -114,6 +115,7 @@ static char *probe_action_text[] = {
         "PROBE_GET_CID",
         "PROBE_GET_CSD",
         "PROBE_SEND_RELATIVE_ADDR",
+	"PROBE_MMC_SET_RELATIVE_ADDR",
         "PROBE_SELECT_CARD",
 	"PROBE_DONE",
 	"PROBE_INVALID"
@@ -702,7 +704,6 @@ mmcprobe_start(struct cam_periph *periph, union ccb *s
 		mmcio->cmd.flags = MMC_RSP_R2 | MMC_CMD_BCR;
 		mmcio->stop.opcode = 0;
 		break;
-
 	case PROBE_SEND_RELATIVE_ADDR:
 		init_standard_ccb(start_ccb, XPT_MMC_IO);
 		mmcio->cmd.opcode = SD_SEND_RELATIVE_ADDR;
@@ -710,6 +711,13 @@ mmcprobe_start(struct cam_periph *periph, union ccb *s
 		mmcio->cmd.flags = MMC_RSP_R6 | MMC_CMD_BCR;
 		mmcio->stop.opcode = 0;
 		break;
+	case PROBE_MMC_SET_RELATIVE_ADDR:
+		init_standard_ccb(start_ccb, XPT_MMC_IO);
+		mmcio->cmd.opcode = MMC_SET_RELATIVE_ADDR;
+		mmcio->cmd.arg = MMC_PROPOSED_RCA << 16;
+		mmcio->cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
+		mmcio->stop.opcode = 0;
+		break;
 	case PROBE_SELECT_CARD:
 		init_standard_ccb(start_ccb, XPT_MMC_IO);
 		mmcio->cmd.opcode = MMC_SELECT_CARD;
@@ -985,7 +993,10 @@ mmcprobe_done(struct cam_periph *periph, union ccb *do
                            mmcp->card_cid[1],
                            mmcp->card_cid[2],
                            mmcp->card_cid[3]));
-                PROBE_SET_ACTION(softc, PROBE_SEND_RELATIVE_ADDR);
+		if (mmcp->card_features & CARD_FEATURE_MMC)
+			PROBE_SET_ACTION(softc, PROBE_MMC_SET_RELATIVE_ADDR);
+		else
+			PROBE_SET_ACTION(softc, PROBE_SEND_RELATIVE_ADDR);
                 break;
         }
         case PROBE_SEND_RELATIVE_ADDR: {
@@ -1010,6 +1021,18 @@ mmcprobe_done(struct cam_periph *periph, union ccb *do
                         PROBE_SET_ACTION(softc, PROBE_SELECT_CARD);
 		break;
         }
+	case PROBE_MMC_SET_RELATIVE_ADDR:
+		mmcio = &done_ccb->mmcio;
+		err = mmcio->cmd.error;
+		if (err != MMC_ERR_NONE) {
+			CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_PROBE,
+			    ("PROBE_MMC_SET_RELATIVE_ADDR: error %d\n", err));
+			PROBE_SET_ACTION(softc, PROBE_INVALID);
+			break;
+		}
+		path->device->mmc_ident_data.card_rca = MMC_PROPOSED_RCA;
+		PROBE_SET_ACTION(softc, PROBE_GET_CSD);
+		break;
         case PROBE_GET_CSD: {
 		mmcio = &done_ccb->mmcio;
 		err = mmcio->cmd.error;



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