Skip to contentSkip to conversation

mmc: Add HW Command Queuing Support

RFC PATCH In review Ritesh Harjani 4 participants 26 messages Jun 27, 2016 – Nov 22, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover mmc: Add HW Command Queuing Support

Hi All,

This patch series refreshes the older patch series sent a while ago by Asutosh Das[1].

Current set of patch series is only introducing the basic CMDQ driver to get more review comments. Based on the reviews, will add other features as well to the patch list.

Below paras describes about the CMDQ feature and a brief implementaion details of HW CMDQ :-

In this patch series, we propose a method to add support for Command Queueing(CQ) feature added to eMMC-5.1 specification. This feature includes new commands for issuing tasks to the device and orders the execution of tasks to the device. It also has task management functions.

Working of CQ with HW CQ support :-
Both card and controller(HC) maintains a queue where tasks can be queued for execution. SW pulls the requests from block layer, prepares request's task/transfer descriptors and issues (by ringing the doorbell) it to CMDQ HC. CMDQ HC then queues this task to the card queue (can queue while data transfer is in progress) by preparing and sending CMD44 followed by CMD45.

While SW driver can issues the tasks asynchronously to CMDQ HC, until the queue is full, HC can in parallel, send SQS (send queue status) to card to read QSR (queue status register), to know which tasks are ready for execution in card. Based on the QSR, HC can send CMD46/47 (read/write) for the task which was ready for execution in card.

Main advantage of CQ comes for Random requests and thus we see that in below performance table that it's mainly the random requests that gets most of the benefit.

Brief on implementation details :-
The initialization of CQ is decided based on the underlying driver capability and the capability advertised by the card through ext_csd.

In order to support queueing of multiple requests, we have added a new issue function to mmc-queue. This selectively pulls the requests and prepares and issues it to the underlying driver. We have used the inherent tagging mechanism of kernel block layer to keep track and map tags to the slots of underlying driver. The current design doesn't block for the request to complete. We have separated the issuing and completion path of the request and tracking is done using the tag assigned to the request.

We have introduced a number of APIs to mmc block layer to facilitate servicing of requests.

The completion of requests is handled in a softirq registered with the kernel block layer during initialization.

A new layer has been introduced to serve the CQ compliant drivers. This layer (cq_hci) has all the standard functionality implemented. It also has necessary hooks for convenience of platform drivers.

Performance Data :-

|------------------------------------
|Androbench	| CQ	|  Legacy  |
|---------------|-------|----------|
|Seq Read(MBps)	| 227.41|  216.97  |	
|---------------|-------|----------|
|Seq Write(MBps)| 56.6	|  56.44   |
|---------------|-------|----------|
|Rand.Read(IOPs)| 7144	|  4554    |
|---------------|-------|----------|
|Rand.Write(IOPS| 2374  |  1629	   |
|----------------------------------|

Patch Description in brief:-
Patch 1/10 - Reads ext_csd to know whether the card supports CMDQ or not.

Patch 2/10 - Adds support for a seperate queue and mmc_cmdq_thread for pulling and issuing the requests. Since this patch series adds a seperate queue for HW CMDQ support, this should not conflict with SW CMDQ series, except in places where we are (initializing/enabling? and) defining CMDQ definitions for card.

Patch 3/10 - Adds initialization and enabling of CMDQ in card and controller if both supports it.

Patch 4-5,8,9/10 - Add read/write/flush/halt support to CMDQ

Patch 6/10 - This change does not relate to CMDQ in general, but only w.r.t. SDMA & ADMA.

Patch 7/10 - Add CMDQ_HCI file for host controllers that support CMDQ.

Patch 10/10 - Add CQ support to sdhci.

[1]:- http://www.spinics.net/lists/linux-arm-msm/msg12692.html

Changes in RFCv2:
- Addressed comments from Shawn.

Asutosh Das (7):
mmc: core: Add support to read command queue parameters
mmc: queue: initialization of command queue
mmc: core: Add command queue initialzation support
mmc: core: add flush request support to command queue
mmc: core: Add halt support
mmc: cmdq-host: add halt support to command queue host
mmc: sdhci: add command queue support to sdhci

Subhash Jadavani (1):
mmc: host: sdhci: don't set SDMA buffer boundary in ADMA mode

Venkat Gopalakrishnan (2):
mmc: card: add read/write support in command queue mode
mmc: cmdq: support for command queue enabled host

 drivers/mmc/card/block.c    | 315 ++++++++++++++++++++-
 drivers/mmc/card/queue.c    | 188 ++++++++++++-
 drivers/mmc/card/queue.h    |  10 +-
 drivers/mmc/core/core.c     |  98 +++++++
 drivers/mmc/core/mmc.c      |  65 +++++
 drivers/mmc/core/mmc_ops.c  |  47 +++-
 drivers/mmc/host/Kconfig    |  13 +
 drivers/mmc/host/Makefile   |   1 +
 drivers/mmc/host/cmdq_hci.c | 671 ++++++++++++++++++++++++++++++++++++++++++++
 drivers/mmc/host/cmdq_hci.h | 207 ++++++++++++++
 drivers/mmc/host/sdhci.c    | 169 ++++++++++-
 drivers/mmc/host/sdhci.h    |   6 +
 include/linux/mmc/card.h    |  11 +-
 include/linux/mmc/core.h    |  13 +
 include/linux/mmc/host.h    |  75 +++++
 include/linux/mmc/mmc.h     |   3 +
 16 files changed, 1868 insertions(+), 24 deletions(-)
 create mode 100644 drivers/mmc/host/cmdq_hci.c
 create mode 100644 drivers/mmc/host/cmdq_hci.h
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
a Linux Foundation Collaborative Project.
#1 lore raw

RFC PATCH v2 1/10 mmc: core: Add support to read command queue parameters

From: Asutosh Das <[email protected]>

eMMC cards with EXT_CSD version >= 8, optionally support command queuing feature as defined by JEDEC eMMC5.1. Add support for probing command queue feature for such type of cards.

---
 drivers/mmc/core/mmc.c   | 15 +++++++++++++++
 include/linux/mmc/card.h |  2 ++
 include/linux/mmc/mmc.h  |  2 ++
 3 files changed, 19 insertions(+)
drivers/mmc/core/mmc.c +15 -0
index 5d438ad..77734c8 100644
@@ -585,6 +585,21 @@ static int mmc_decode_ext_csd(struct mmc_card *card, u8 *ext_csd)
 		card->ext_csd.data_sector_size = 512;
 	}
 
+	if (card->ext_csd.rev >= 8) {
+		card->ext_csd.cmdq_support = ext_csd[EXT_CSD_CMDQ_SUPPORT];
+		if (card->ext_csd.cmdq_support) {
+			/*
+			 * Queue Depth = N + 1,
+			 * see JEDEC JESD84-B51 section 7.4.19
+			 */
+			card->ext_csd.cmdq_depth =
+				ext_csd[EXT_CSD_CMDQ_DEPTH] + 1;
+			pr_debug("%s: CMDQ supported: depth: %d\n",
+				mmc_hostname(card->host),
+				card->ext_csd.cmdq_depth);
+		}
+	}
+
 	/* eMMC v5 or later */
 	if (card->ext_csd.rev >= 7) {
 		memcpy(card->ext_csd.fwrev, &ext_csd[EXT_CSD_FIRMWARE_VERSION],
include/linux/mmc/card.h +2 -0
index eb0151b..f74db84 100644
@@ -118,6 +118,8 @@ struct mmc_ext_csd {
 	u8			raw_pwr_cl_ddr_200_360;	/* 253 */
 	u8			raw_bkops_status;	/* 246 */
 	u8			raw_sectors[4];		/* 212 - 4 bytes */
+	u8			cmdq_depth;		/* 307 */
+	u8			cmdq_support;		/* 308 */
 
 	unsigned int            feature_support;
 #define MMC_DISCARD_FEATURE	BIT(0)                  /* CMD38 feature */
include/linux/mmc/mmc.h +2 -0
index 15f2c4a..694c189 100644
@@ -330,6 +330,8 @@ struct _mmc_csd {
 #define EXT_CSD_CACHE_SIZE		249	/* RO, 4 bytes */
 #define EXT_CSD_PWR_CL_DDR_200_360	253	/* RO */
 #define EXT_CSD_FIRMWARE_VERSION	254	/* RO, 8 bytes */
+#define EXT_CSD_CMDQ_DEPTH		307	/* RO */
+#define EXT_CSD_CMDQ_SUPPORT		308	/* RO */
 #define EXT_CSD_SUPPORTED_MODE		493	/* RO */
 #define EXT_CSD_TAG_UNIT_SIZE		498	/* RO */
 #define EXT_CSD_DATA_TAG_SUPPORT	499	/* RO */
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
a Linux Foundation Collaborative Project.
#8 lore raw

RFC PATCH v2 2/10 mmc: queue: initialization of command queue

In reply to Ritesh Harjani

From: Asutosh Das <[email protected]>

Command Queueing (CQ) feature is introduced to eMMC standard in revision 5.1. CQ includes new commands for issuing tasks to the device, for ordering the execution of previously issued tasks and for additional task management functions.

The idea is to keep the legacy and CQ code as discrete as possible. Hence, a separate queue is created for CQ. The issuing path is non-blocking since several requests (max. 32) can be queued at a time.

[[email protected]: fixed trivial merge conflicts & compilation error]

---
 drivers/mmc/card/block.c |   2 +-
 drivers/mmc/card/queue.c | 186 ++++++++++++++++++++++++++++++++++++++++++++++-
 drivers/mmc/card/queue.h |   9 ++-
 include/linux/mmc/host.h |  17 +++++
 4 files changed, 210 insertions(+), 4 deletions(-)
drivers/mmc/card/block.c +1 -1
index e62fde3..ec99f57 100644
@@ -2257,7 +2257,7 @@ again:
 	INIT_LIST_HEAD(&md->part);
 	md->usage = 1;
 
-	ret = mmc_init_queue(&md->queue, card, &md->lock, subname);
+	ret = mmc_init_queue(&md->queue, card, &md->lock, subname, area_type);
 	if (ret)
 		goto err_putdisk;
 
drivers/mmc/card/queue.c +185 -1

222 lines not on this page · raw message

drivers/mmc/card/queue.h +7 -2
index 36cddab..6420896 100644
@@ -52,16 +52,20 @@ struct mmc_queue {
 #define MMC_QUEUE_SUSPENDED	(1 << 0)
 #define MMC_QUEUE_NEW_REQUEST	(1 << 1)
 
-	int			(*issue_fn)(struct mmc_queue *, struct request *);
+	int (*issue_fn)(struct mmc_queue *, struct request *);
+	int (*cmdq_issue_fn)(struct mmc_queue *,
+			     struct request *);
+	void (*cmdq_complete_fn)(struct request *);
 	void			*data;
 	struct request_queue	*queue;
 	struct mmc_queue_req	mqrq[2];
 	struct mmc_queue_req	*mqrq_cur;
 	struct mmc_queue_req	*mqrq_prev;
+	struct mmc_queue_req	*mqrq_cmdq;
 };
 
 extern int mmc_init_queue(struct mmc_queue *, struct mmc_card *, spinlock_t *,
-			  const char *);
+			  const char *, int);
 extern void mmc_cleanup_queue(struct mmc_queue *);
 extern void mmc_queue_suspend(struct mmc_queue *);
 extern void mmc_queue_resume(struct mmc_queue *);
@@ -76,4 +80,5 @@ extern void mmc_packed_clean(struct mmc_queue *);
 
 extern int mmc_access_rpmb(struct mmc_queue *);
 
+extern void mmc_cmdq_clean(struct mmc_queue *mq, struct mmc_card *card);
 #endif
include/linux/mmc/host.h +17 -0
index 45cde8c..3842208 100644
@@ -187,6 +187,21 @@ struct mmc_slot {
 };
 
 /**
+ * mmc_cmdq_context_info - describes the contexts of cmdq
+ * @active_reqs		requests being processed
+ * @curr_state		state of cmdq engine
+ * @req_starved		completion should invoke the request_fn since
+ *			no tags were available
+ */
+struct mmc_cmdq_context_info {
+	unsigned long	active_reqs; /* in-flight requests */
+	unsigned long	curr_state;
+#define	CMDQ_STATE_ERR 0
+	/* no free tag available */
+	unsigned long	req_starved;
+};
+
+/**
  * mmc_context_info - synchronization details for mmc context
  * @is_done_rcv		wake up reason was done request
  * @is_new_req		wake up reason was new request
@@ -302,6 +317,7 @@ struct mmc_host {
 #define MMC_CAP2_SDIO_IRQ_NOTHREAD (1 << 17)
 #define MMC_CAP2_NO_WRITE_PROTECT (1 << 18)	/* No physical write protect pin, assume that card is always read-write */
 #define MMC_CAP2_NO_SDIO	(1 << 19)	/* Do not send SDIO commands during initialization */
+#define MMC_CAP2_CMD_QUEUE	(1 << 20)	/* support eMMC command queue */
 
 	mmc_pm_flag_t		pm_caps;	/* supported pm features */
 
@@ -384,6 +400,7 @@ struct mmc_host {
 	int			dsr_req;	/* DSR value is valid */
 	u32			dsr;	/* optional driver stage (DSR) value */
 
+	struct mmc_cmdq_context_info	cmdq_ctx;
 	unsigned long		private[0] ____cacheline_aligned;
 };
 
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
a Linux Foundation Collaborative Project.
#9 lore raw

RFC PATCH v2 3/10 mmc: core: Add command queue initialzation support

In reply to Ritesh Harjani

From: Asutosh Das <[email protected]>

Command Queueing (CQ) feature is introduced to eMMC standard in revision 5.1. CQ includes new commands for issuing tasks to the device, for ordering the execution of previously issued tasks and for additional task management functions.

This patch adds initialization and enabling of command queue in the card and controller. If the card and the controller support CQ, then it is enabled.

[[email protected]: fixed trivial merge conflicts]
[[email protected]: fixed trivial merge conflicts]
---
 drivers/mmc/core/mmc.c   | 50 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/mmc/card.h |  6 ++++++
 include/linux/mmc/host.h |  6 ++++++
 include/linux/mmc/mmc.h  |  1 +
 4 files changed, 63 insertions(+)
drivers/mmc/core/mmc.c +50 -0
index 77734c8..e0432b0 100644
@@ -1371,6 +1371,43 @@ static int mmc_hs200_tuning(struct mmc_card *card)
 	return mmc_execute_tuning(card);
 }
 
+static int mmc_select_cmdq(struct mmc_card *card)
+{
+	struct mmc_host *host = card->host;
+	int ret = 0;
+
+	if (!host->cmdq_ops) {
+		pr_err("%s: host controller doesn't support CMDQ\n",
+		       mmc_hostname(host));
+		return 0;
+	}
+
+	ret = mmc_set_blocklen(card, MMC_CARD_CMDQ_BLK_SIZE);
+	if (ret)
+		goto out;
+
+	ret = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_CMDQ, 1,
+			 card->ext_csd.generic_cmd6_time);
+	if (ret)
+		goto out;
+
+	mmc_card_set_cmdq(card);
+	ret = host->cmdq_ops->enable(card->host);
+	if (ret) {
+		pr_err("%s: failed (%d) enabling CMDQ on host\n",
+			mmc_hostname(host), ret);
+		mmc_card_clr_cmdq(card);
+		ret = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_CMDQ, 0,
+				 card->ext_csd.generic_cmd6_time);
+		if (ret)
+			goto out;
+	}
+
+	pr_debug("%s: CMDQ enabled on card\n", mmc_hostname(host));
+out:
+	return ret;
+}
+
 /*
  * Handle the detection and initialisation of a card.
  *
@@ -1399,6 +1436,7 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
 	 * respond.
 	 * mmc_go_idle is needed for eMMC that are asleep
 	 */
+reinit:
 	mmc_go_idle(host);
 
 	/* The extra bit indicates that we support high capacity */
@@ -1677,6 +1715,18 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
 	if (!oldcard)
 		host->card = card;
 
+	if (card->ext_csd.cmdq_support && (card->host->caps2 &
+					   MMC_CAP2_CMD_QUEUE)) {
+		err = mmc_select_cmdq(card);
+		if (err) {
+			pr_err("%s: selecting CMDQ mode: failed: %d\n",
+					   mmc_hostname(card->host), err);
+			card->ext_csd.cmdq_support = 0;
+			oldcard = card;
+			goto reinit;
+		}
+	}
+
 	return 0;
 
 free_card:
include/linux/mmc/card.h +6 -0
index f74db84..85a0d8d 100644
@@ -14,6 +14,8 @@
 #include <linux/mmc/core.h>
 #include <linux/mod_devicetable.h>
 
+#define MMC_CARD_CMDQ_BLK_SIZE 512
+
 struct mmc_cid {
 	unsigned int		manfid;
 	char			prod_name[8];
@@ -265,6 +267,7 @@ struct mmc_card {
 #define MMC_CARD_REMOVED	(1<<4)		/* card has been removed */
 #define MMC_STATE_DOING_BKOPS	(1<<5)		/* card is doing BKOPS */
 #define MMC_STATE_SUSPENDED	(1<<6)		/* card is suspended */
+#define MMC_STATE_CMDQ		(1<<12)         /* card is in cmd queue mode */
 	unsigned int		quirks; 	/* card quirks */
 #define MMC_QUIRK_LENIENT_FN0	(1<<0)		/* allow SDIO FN0 writes outside of the VS CCCR range */
 #define MMC_QUIRK_BLKSZ_FOR_BYTE_MODE (1<<1)	/* use func->cur_blksize */
@@ -433,6 +436,7 @@ static inline void __maybe_unused remove_quirk(struct mmc_card *card, int data)
 #define mmc_card_removed(c)	((c) && ((c)->state & MMC_CARD_REMOVED))
 #define mmc_card_doing_bkops(c)	((c)->state & MMC_STATE_DOING_BKOPS)
 #define mmc_card_suspended(c)	((c)->state & MMC_STATE_SUSPENDED)
+#define mmc_card_cmdq(c)       ((c)->state & MMC_STATE_CMDQ)
 
 #define mmc_card_set_present(c)	((c)->state |= MMC_STATE_PRESENT)
 #define mmc_card_set_readonly(c) ((c)->state |= MMC_STATE_READONLY)
@@ -443,6 +447,8 @@ static inline void __maybe_unused remove_quirk(struct mmc_card *card, int data)
 #define mmc_card_clr_doing_bkops(c)	((c)->state &= ~MMC_STATE_DOING_BKOPS)
 #define mmc_card_set_suspended(c) ((c)->state |= MMC_STATE_SUSPENDED)
 #define mmc_card_clr_suspended(c) ((c)->state &= ~MMC_STATE_SUSPENDED)
+#define mmc_card_set_cmdq(c)           ((c)->state |= MMC_STATE_CMDQ)
+#define mmc_card_clr_cmdq(c)           ((c)->state &= ~MMC_STATE_CMDQ)
 
 /*
  * Quirk add/remove for MMC products.
include/linux/mmc/host.h +6 -0
index 3842208..3c4a569 100644
@@ -79,6 +79,11 @@ struct mmc_ios {
 #define MMC_SET_DRIVER_TYPE_D	3
 };
 
+struct mmc_cmdq_host_ops {
+	int (*enable)(struct mmc_host *host);
+	void (*disable)(struct mmc_host *host, bool soft);
+};
+
 struct mmc_host_ops {
 	/*
 	 * It is optional for the host to implement pre_req and post_req in
@@ -230,6 +235,7 @@ struct mmc_host {
 	struct device		class_dev;
 	int			index;
 	const struct mmc_host_ops *ops;
+	const struct mmc_cmdq_host_ops *cmdq_ops;
 	struct mmc_pwrseq	*pwrseq;
 	unsigned int		f_min;
 	unsigned int		f_max;
include/linux/mmc/mmc.h +1 -0
index 694c189..55913d9 100644
@@ -272,6 +272,7 @@ struct _mmc_csd {
  * EXT_CSD fields
  */
 
+#define EXT_CSD_CMDQ			15	/* R/W */
 #define EXT_CSD_FLUSH_CACHE		32      /* W */
 #define EXT_CSD_CACHE_CTRL		33      /* R/W */
 #define EXT_CSD_POWER_OFF_NOTIFICATION	34	/* R/W */
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
a Linux Foundation Collaborative Project.
#10 lore raw

RFC PATCH v2 4/10 mmc: card: add read/write support in command queue mode

In reply to Ritesh Harjani

From: Venkat Gopalakrishnan <[email protected]>

Command queueing is defined in eMMC-5.1. It is designed for higher performance by ensuring upto 32 requests to be serviced at a time.

Adds read/write support for CMDQ enabled devices.

---
 drivers/mmc/card/block.c | 242 ++++++++++++++++++++++++++++++++++++++++++++++-
 drivers/mmc/card/queue.h |   1 +
 drivers/mmc/core/core.c  |  57 +++++++++++
 include/linux/mmc/card.h |   3 +-
 include/linux/mmc/core.h |   8 ++
 include/linux/mmc/host.h |  22 +++++
 6 files changed, 330 insertions(+), 3 deletions(-)
drivers/mmc/card/block.c +240 -2
index ec99f57..57563a5 100644
@@ -36,6 +36,7 @@
 #include <linux/compat.h>
 #include <linux/pm_runtime.h>
 #include <linux/idr.h>
+#include <linux/ioprio.h>
 
 #include <linux/mmc/ioctl.h>
 #include <linux/mmc/card.h>
@@ -101,6 +102,7 @@ struct mmc_blk_data {
 #define MMC_BLK_CMD23	(1 << 0)	/* Can do SET_BLOCK_COUNT for multiblock */
 #define MMC_BLK_REL_WR	(1 << 1)	/* MMC Reliable write support */
 #define MMC_BLK_PACKED_CMD	(1 << 2)	/* MMC packed command support */
+#define MMC_BLK_CMD_QUEUE	(1 << 3) /* MMC command queue support */
 
 	unsigned int	usage;
 	unsigned int	read_only;
@@ -136,6 +138,8 @@ MODULE_PARM_DESC(perdev_minors, "Minors numbers to allocate per device");
 static inline int mmc_blk_part_switch(struct mmc_card *card,
 				      struct mmc_blk_data *md);
 static int get_card_status(struct mmc_card *card, u32 *status, int retries);
+static int mmc_blk_cmdq_switch(struct mmc_card *card,
+			       struct mmc_blk_data *md, bool enable);
 
 static inline void mmc_blk_clear_packed(struct mmc_queue_req *mqrq)
 {
@@ -744,6 +748,44 @@ static const struct block_device_operations mmc_bdops = {
 #endif
 };
 
+static int mmc_blk_cmdq_switch(struct mmc_card *card,
+			       struct mmc_blk_data *md, bool enable)
+{
+	int ret = 0;
+	bool cmdq_mode = !!mmc_card_cmdq(card);
+
+	if (!(card->host->caps2 & MMC_CAP2_CMD_QUEUE) ||
+	    !card->ext_csd.cmdq_support ||
+	    (enable && !(md->flags & MMC_BLK_CMD_QUEUE)) ||
+	    (cmdq_mode == enable))
+		return 0;
+
+	if (enable) {
+		ret = mmc_set_blocklen(card, MMC_CARD_CMDQ_BLK_SIZE);
+		if (ret) {
+			pr_err("%s: failed (%d) to set block-size to %d\n",
+			       __func__, ret, MMC_CARD_CMDQ_BLK_SIZE);
+			goto out;
+		}
+	}
+
+	ret = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
+			 EXT_CSD_CMDQ, enable,
+			 card->ext_csd.generic_cmd6_time);
+	if (ret) {
+		pr_err("%s: cmdq mode %sable failed %d\n",
+		       md->disk->disk_name, enable ? "en" : "dis", ret);
+		goto out;
+	}
+
+	if (enable)
+		mmc_card_set_cmdq(card);
+	else
+		mmc_card_clr_cmdq(card);
+out:
+	return ret;
+}
+
 static inline int mmc_blk_part_switch(struct mmc_card *card,
 				      struct mmc_blk_data *md)
 {
@@ -759,6 +801,13 @@ static inline int mmc_blk_part_switch(struct mmc_card *card,
 		if (md->part_type == EXT_CSD_PART_CONFIG_ACC_RPMB)
 			mmc_retune_pause(card->host);
 
+		if (md->part_type) {
+			/* disable CQ mode for non-user data partitions */
+			ret = mmc_blk_cmdq_switch(card, md, false);
+			if (ret)
+				return ret;
+		}
+
 		part_config &= ~EXT_CSD_PART_CONFIG_ACC_MASK;
 		part_config |= md->part_type;
 
@@ -1949,6 +1998,165 @@ static void mmc_blk_revert_packed_req(struct mmc_queue *mq,
 	mmc_blk_clear_packed(mq_rq);
 }
 
+static int mmc_blk_cmdq_start_req(struct mmc_host *host,
+				  struct mmc_cmdq_req *cmdq_req)
+{
+	struct mmc_request *mrq = &cmdq_req->mrq;
+
+	mrq->done = mmc_blk_cmdq_req_done;
+	return mmc_cmdq_start_req(host, cmdq_req);
+}
+
+#define IS_RT_CLASS_REQ(x)     \
+	(IOPRIO_PRIO_CLASS(req_get_ioprio(x)) == IOPRIO_CLASS_RT)
+
+static struct mmc_cmdq_req *mmc_blk_cmdq_rw_prep(
+		struct mmc_queue_req *mqrq, struct mmc_queue *mq)
+{
+	struct mmc_card *card = mq->card;
+	struct request *req = mqrq->req;
+	struct mmc_blk_data *md = mq->data;
+	bool do_rel_wr = mmc_req_rel_wr(req) && (md->flags & MMC_BLK_REL_WR);
+	bool do_data_tag;
+	bool read_dir = (rq_data_dir(req) == READ);
+	bool prio = IS_RT_CLASS_REQ(req);
+	struct mmc_cmdq_req *cmdq_rq = &mqrq->cmdq_req;
+
+	memset(&mqrq->cmdq_req, 0, sizeof(struct mmc_cmdq_req));
+
+	cmdq_rq->tag = req->tag;
+	if (read_dir) {
+		cmdq_rq->cmdq_req_flags |= DIR;
+		cmdq_rq->data.flags = MMC_DATA_READ;
+	} else {
+		cmdq_rq->data.flags = MMC_DATA_WRITE;
+	}
+	if (prio)
+		cmdq_rq->cmdq_req_flags |= PRIO;
+
+	if (do_rel_wr)
+		cmdq_rq->cmdq_req_flags |= REL_WR;
+
+	cmdq_rq->data.blocks = blk_rq_sectors(req);
+	cmdq_rq->blk_addr = blk_rq_pos(req);
+	cmdq_rq->data.blksz = MMC_CARD_CMDQ_BLK_SIZE;
+
+	mmc_set_data_timeout(&cmdq_rq->data, card);
+
+	do_data_tag = (card->ext_csd.data_tag_unit_size) &&
+		(req->cmd_flags & REQ_META) &&
+		(rq_data_dir(req) == WRITE) &&
+		((cmdq_rq->data.blocks * cmdq_rq->data.blksz) >=
+		 card->ext_csd.data_tag_unit_size);
+	if (do_data_tag)
+		cmdq_rq->cmdq_req_flags |= DAT_TAG;
+	cmdq_rq->data.sg = mqrq->sg;
+	cmdq_rq->data.sg_len = mmc_queue_map_sg(mq, mqrq);
+
+	/*
+	 * Adjust the sg list so it is the same size as the
+	 * request.
+	 */
+	if (cmdq_rq->data.blocks > card->host->max_blk_count)
+		cmdq_rq->data.blocks = card->host->max_blk_count;
+
+	if (cmdq_rq->data.blocks != blk_rq_sectors(req)) {
+		int i, data_size = cmdq_rq->data.blocks << 9;
+		struct scatterlist *sg;
+
+		for_each_sg(cmdq_rq->data.sg, sg, cmdq_rq->data.sg_len, i) {
+			data_size -= sg->length;
+			if (data_size <= 0) {
+				sg->length += data_size;
+				i++;
+				break;
+			}
+		}
+		cmdq_rq->data.sg_len = i;
+	}
+
+	mqrq->cmdq_req.cmd_flags = req->cmd_flags;
+	mqrq->cmdq_req.mrq.req = mqrq->req;
+	mqrq->cmdq_req.mrq.cmdq_req = &mqrq->cmdq_req;
+	mqrq->cmdq_req.mrq.data = &mqrq->cmdq_req.data;
+	mqrq->req->special = mqrq;
+
+	pr_debug("%s: %s: mrq: 0x%p req: 0x%p mqrq: 0x%p bytes to xf: %d mmc_cmdq_req: 0x%p card-addr: 0x%08x dir(r-1/w-0): %d\n",
+		 mmc_hostname(card->host), __func__, &mqrq->cmdq_req.mrq,
+		 mqrq->req, mqrq, (cmdq_rq->data.blocks * cmdq_rq->data.blksz),
+		 cmdq_rq, cmdq_rq->blk_addr,
+		 (cmdq_rq->cmdq_req_flags & DIR) ? 1 : 0);
+
+	return &mqrq->cmdq_req;
+}
+
+static int mmc_blk_cmdq_issue_rw_rq(struct mmc_queue *mq, struct request *req)
+{
+	struct mmc_queue_req *active_mqrq;
+	struct mmc_card *card = mq->card;
+	struct mmc_host *host = card->host;
+	struct mmc_cmdq_req *mc_rq;
+	int ret = 0;
+
+	BUG_ON((req->tag < 0) || (req->tag > card->ext_csd.cmdq_depth));
+	BUG_ON(test_and_set_bit(req->tag, &host->cmdq_ctx.active_reqs));
+
+	active_mqrq = &mq->mqrq_cmdq[req->tag];
+	active_mqrq->req = req;
+
+	mc_rq = mmc_blk_cmdq_rw_prep(active_mqrq, mq);
+
+	ret = mmc_blk_cmdq_start_req(card->host, mc_rq);
+	return ret;
+}
+
+/* invoked by block layer in softirq context */
+void mmc_blk_cmdq_complete_rq(struct request *rq)
+{
+	struct mmc_queue_req *mq_rq = rq->special;
+	struct mmc_request *mrq = &mq_rq->cmdq_req.mrq;
+	struct mmc_host *host = mrq->host;
+	struct mmc_cmdq_context_info *ctx_info = &host->cmdq_ctx;
+	struct mmc_cmdq_req *cmdq_req = &mq_rq->cmdq_req;
+	struct mmc_queue *mq = (struct mmc_queue *)rq->q->queuedata;
+	int err = 0;
+
+	if (mrq->cmd && mrq->cmd->error)
+		err = mrq->cmd->error;
+	else if (mrq->data && mrq->data->error)
+		err = mrq->data->error;
+
+	mmc_cmdq_post_req(host, mrq, err);
+	if (err) {
+		pr_err("%s: %s: txfr error: %d\n", mmc_hostname(mrq->host),
+		       __func__, err);
+		set_bit(CMDQ_STATE_ERR, &ctx_info->curr_state);
+		WARN_ON(1);
+	}
+
+	BUG_ON(!test_and_clear_bit(cmdq_req->tag,
+				   &ctx_info->active_reqs));
+
+	blk_end_request(rq, err, cmdq_req->data.bytes_xfered);
+
+	if (test_and_clear_bit(0, &ctx_info->req_starved))
+		blk_run_queue(mq->queue);
+
+	mmc_release_host(host);
+}
+
+/*
+ * Complete reqs from block layer softirq context
+ * Invoked in irq context
+ */
+void mmc_blk_cmdq_req_done(struct mmc_request *mrq)
+{
+	struct request *req = mrq->req;
+
+	blk_complete_request(req);
+}
+EXPORT_SYMBOL(mmc_blk_cmdq_req_done);
+
 static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
 {
 	struct mmc_blk_data *md = mq->data;
@@ -2141,6 +2349,28 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
 	return 0;
 }
 
+static int mmc_blk_cmdq_issue_rq(struct mmc_queue *mq, struct request *req)
+{
+	int ret;
+	struct mmc_blk_data *md = mq->data;
+	struct mmc_card *card = md->queue.card;
+
+	mmc_claim_host(card->host);
+	ret = mmc_blk_part_switch(card, md);
+	if (ret) {
+		pr_err("%s: %s: partition switch failed %d\n",
+				md->disk->disk_name, __func__, ret);
+		blk_end_request_all(req, ret);
+		mmc_release_host(card->host);
+		goto switch_failure;
+	}
+
+	ret = mmc_blk_cmdq_issue_rw_rq(mq, req);
+
+switch_failure:
+	return ret;
+}
+
 static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
 {
 	int ret;
@@ -2308,12 +2538,18 @@ again:
 	if (mmc_card_mmc(card) &&
 	    md->flags & MMC_BLK_CMD23 &&
 	    ((card->ext_csd.rel_param & EXT_CSD_WR_REL_PARAM_EN) ||
-	     card->ext_csd.rel_sectors)) {
+	     card->ext_csd.rel_sectors) && !card->cmdq_init) {
 		md->flags |= MMC_BLK_REL_WR;
 		blk_queue_write_cache(md->queue.queue, true, true);
 	}
 
-	if (mmc_card_mmc(card) &&
+	if (card->cmdq_init) {
+		md->flags |= MMC_BLK_CMD_QUEUE;
+		md->queue.cmdq_complete_fn = mmc_blk_cmdq_complete_rq;
+		md->queue.cmdq_issue_fn = mmc_blk_cmdq_issue_rq;
+	}
+
+	if (mmc_card_mmc(card) && !card->cmdq_init &&
 	    (area_type == MMC_BLK_DATA_AREA_MAIN) &&
 	    (md->flags & MMC_BLK_CMD23) &&
 	    card->ext_csd.packed_event_en) {
@@ -2426,6 +2662,8 @@ static void mmc_blk_remove_req(struct mmc_blk_data *md)
 		mmc_cleanup_queue(&md->queue);
 		if (md->flags & MMC_BLK_PACKED_CMD)
 			mmc_packed_clean(&md->queue);
+		if (md->flags & MMC_BLK_CMD_QUEUE)
+			mmc_cmdq_clean(&md->queue, card);
 		if (md->disk->flags & GENHD_FL_UP) {
 			device_remove_file(disk_to_dev(md->disk), &md->force_ro);
 			if ((md->area_type & MMC_BLK_DATA_AREA_BOOT) &&
drivers/mmc/card/queue.h +1 -0
index 6420896..34d7800 100644
@@ -42,6 +42,7 @@ struct mmc_queue_req {
 	struct mmc_async_req	mmc_active;
 	enum mmc_packed_type	cmd_type;
 	struct mmc_packed	*packed;
+	struct mmc_cmdq_req	cmdq_req;
 };
 
 struct mmc_queue {
drivers/mmc/core/core.c +57 -0

69 lines not on this page · raw message

include/linux/mmc/card.h +2 -1
index 85a0d8d..8bf1742 100644
@@ -318,6 +318,7 @@ struct mmc_card {
 	struct dentry		*debugfs_root;
 	struct mmc_part	part[MMC_NUM_PHY_PARTITION]; /* physical partitions */
 	unsigned int    nr_parts;
+	bool cmdq_init;
 };
 
 /*
@@ -539,5 +540,5 @@ extern void mmc_unregister_driver(struct mmc_driver *);
 
 extern void mmc_fixup_device(struct mmc_card *card,
 			     const struct mmc_fixup *table);
-
+extern void mmc_blk_cmdq_req_done(struct mmc_request *mrq);
 #endif /* LINUX_MMC_CARD_H */
include/linux/mmc/core.h +8 -0
index b01e77d..a93e6f8 100644
@@ -135,10 +135,18 @@ struct mmc_request {
 	struct completion	completion;
 	void			(*done)(struct mmc_request *);/* completion function */
 	struct mmc_host		*host;
+	struct mmc_cmdq_req	*cmdq_req;
+	struct request		*req;		/* associated block request */
 };
 
 struct mmc_card;
 struct mmc_async_req;
+struct mmc_cmdq_req;
+
+extern void mmc_cmdq_post_req(struct mmc_host *host, struct mmc_request *mrq,
+			      int err);
+extern int mmc_cmdq_start_req(struct mmc_host *host,
+			      struct mmc_cmdq_req *cmdq_req);
 
 extern int mmc_stop_bkops(struct mmc_card *);
 extern int mmc_read_bkops_status(struct mmc_card *);
include/linux/mmc/host.h +22 -0
index 3c4a569..319501e 100644
@@ -82,6 +82,9 @@ struct mmc_ios {
 struct mmc_cmdq_host_ops {
 	int (*enable)(struct mmc_host *host);
 	void (*disable)(struct mmc_host *host, bool soft);
+	int (*request)(struct mmc_host *host, struct mmc_request *mrq);
+	void (*post_req)(struct mmc_host *host, struct mmc_request *mrq,
+			 int err);
 };
 
 struct mmc_host_ops {
@@ -165,6 +168,25 @@ struct mmc_host_ops {
 struct mmc_card;
 struct device;
 
+struct mmc_cmdq_req {
+	unsigned int cmd_flags;
+	u32 blk_addr;
+	/* active mmc request */
+	struct mmc_request	mrq;
+	struct mmc_data		data;
+	struct mmc_command	cmd;
+#define DCMD		(1 << 0)
+#define QBR		(1 << 1)
+#define DIR		(1 << 2)
+#define PRIO		(1 << 3)
+#define REL_WR		(1 << 4)
+#define DAT_TAG	(1 << 5)
+#define FORCED_PRG	(1 << 6)
+	unsigned int		cmdq_req_flags;
+	int			tag; /* used for command queuing */
+	u8			ctx_id;
+};
+
 struct mmc_async_req {
 	/* active mmc request */
 	struct mmc_request	*mrq;
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
a Linux Foundation Collaborative Project.
#11 lore raw

RFC PATCH v2 5/10 mmc: core: add flush request support to command queue

In reply to Ritesh Harjani

From: Asutosh Das <[email protected]>

Adds flush request support to command-queue. This uses DCMD feature of the controller for sending commands in command-queue mode. DCMD is a direct command feature that uses a pre-configured slot for sending commands other than Class 11.

---
 drivers/mmc/card/block.c   | 81 +++++++++++++++++++++++++++++++++++++++++++---
 drivers/mmc/card/queue.c   |  3 +-
 drivers/mmc/core/core.c    |  8 +++++
 drivers/mmc/core/mmc_ops.c | 47 +++++++++++++++++++++++----
 include/linux/mmc/core.h   |  4 +++
 include/linux/mmc/host.h   |  1 +
 6 files changed, 133 insertions(+), 11 deletions(-)
drivers/mmc/card/block.c +77 -4
index 57563a5..51c640b 100644
@@ -2007,6 +2007,26 @@ static int mmc_blk_cmdq_start_req(struct mmc_host *host,
 	return mmc_cmdq_start_req(host, cmdq_req);
 }
 
+/* prepare for non-data commands */
+static struct mmc_cmdq_req *mmc_cmdq_prep_dcmd(
+		struct mmc_queue_req *mqrq, struct mmc_queue *mq)
+{
+	struct request *req = mqrq->req;
+	struct mmc_cmdq_req *cmdq_req = &mqrq->cmdq_req;
+
+	memset(&mqrq->cmdq_req, 0, sizeof(struct mmc_cmdq_req));
+
+	cmdq_req->mrq.data = NULL;
+	cmdq_req->cmd_flags = req->cmd_flags;
+	cmdq_req->mrq.req = mqrq->req;
+	req->special = mqrq;
+	cmdq_req->cmdq_req_flags |= DCMD;
+	cmdq_req->mrq.cmdq_req = cmdq_req;
+
+	return &mqrq->cmdq_req;
+}
+
+
 #define IS_RT_CLASS_REQ(x)     \
 	(IOPRIO_PRIO_CLASS(req_get_ioprio(x)) == IOPRIO_CLASS_RT)
 
@@ -2110,6 +2130,47 @@ static int mmc_blk_cmdq_issue_rw_rq(struct mmc_queue *mq, struct request *req)
 	return ret;
 }
 
+/*
+ * Issues a flush (dcmd) request
+ */
+int mmc_blk_cmdq_issue_flush_rq(struct mmc_queue *mq, struct request *req)
+{
+	int err;
+	struct mmc_queue_req *active_mqrq;
+	struct mmc_card *card = mq->card;
+	struct mmc_host *host;
+	struct mmc_cmdq_req *cmdq_req;
+	struct mmc_cmdq_context_info *ctx_info;
+
+	BUG_ON(!card);
+	host = card->host;
+	BUG_ON(!host);
+	BUG_ON(req->tag > card->ext_csd.cmdq_depth);
+	BUG_ON(test_and_set_bit(req->tag, &host->cmdq_ctx.active_reqs));
+
+	ctx_info = &host->cmdq_ctx;
+
+	set_bit(CMDQ_STATE_DCMD_ACTIVE, &ctx_info->curr_state);
+
+	active_mqrq = &mq->mqrq_cmdq[req->tag];
+	active_mqrq->req = req;
+
+	cmdq_req = mmc_cmdq_prep_dcmd(active_mqrq, mq);
+	cmdq_req->cmdq_req_flags |= QBR;
+	cmdq_req->mrq.cmd = &cmdq_req->cmd;
+	cmdq_req->tag = req->tag;
+
+	err = mmc_cmdq_prepare_flush(cmdq_req->mrq.cmd);
+	if (err) {
+		pr_err("%s: failed (%d) preparing flush req\n",
+		       mmc_hostname(host), err);
+		return err;
+	}
+	err = mmc_blk_cmdq_start_req(card->host, cmdq_req);
+	return err;
+}
+EXPORT_SYMBOL(mmc_blk_cmdq_issue_flush_rq);
+
 /* invoked by block layer in softirq context */
 void mmc_blk_cmdq_complete_rq(struct request *rq)
 {
@@ -2136,12 +2197,17 @@ void mmc_blk_cmdq_complete_rq(struct request *rq)
 
 	BUG_ON(!test_and_clear_bit(cmdq_req->tag,
 				   &ctx_info->active_reqs));
+	if (cmdq_req->cmdq_req_flags & DCMD) {
+		clear_bit(CMDQ_STATE_DCMD_ACTIVE, &ctx_info->curr_state);
+		blk_end_request_all(rq, 0);
+		goto out;
+	}
 
 	blk_end_request(rq, err, cmdq_req->data.bytes_xfered);
 
+out:
 	if (test_and_clear_bit(0, &ctx_info->req_starved))
 		blk_run_queue(mq->queue);
-
 	mmc_release_host(host);
 }
 
@@ -2354,18 +2420,25 @@ static int mmc_blk_cmdq_issue_rq(struct mmc_queue *mq, struct request *req)
 	int ret;
 	struct mmc_blk_data *md = mq->data;
 	struct mmc_card *card = md->queue.card;
+	unsigned int cmd_flags = req ? req->cmd_flags : 0;
 
 	mmc_claim_host(card->host);
 	ret = mmc_blk_part_switch(card, md);
 	if (ret) {
 		pr_err("%s: %s: partition switch failed %d\n",
 				md->disk->disk_name, __func__, ret);
-		blk_end_request_all(req, ret);
+		if (req)
+			blk_end_request_all(req, ret);
 		mmc_release_host(card->host);
 		goto switch_failure;
 	}
 
-	ret = mmc_blk_cmdq_issue_rw_rq(mq, req);
+	if (req) {
+		if (cmd_flags & REQ_FLUSH)
+			ret = mmc_blk_cmdq_issue_flush_rq(mq, req);
+		else
+			ret = mmc_blk_cmdq_issue_rw_rq(mq, req);
+	}
 
 switch_failure:
 	return ret;
@@ -2538,7 +2611,7 @@ again:
 	if (mmc_card_mmc(card) &&
 	    md->flags & MMC_BLK_CMD23 &&
 	    ((card->ext_csd.rel_param & EXT_CSD_WR_REL_PARAM_EN) ||
-	     card->ext_csd.rel_sectors) && !card->cmdq_init) {
+	     card->ext_csd.rel_sectors)) {
 		md->flags |= MMC_BLK_REL_WR;
 		blk_queue_write_cache(md->queue.queue, true, true);
 	}
drivers/mmc/card/queue.c +2 -1
index bb885f4..2697529 100644
@@ -49,7 +49,8 @@ static int mmc_prep_request(struct request_queue *q, struct request *req)
 static inline bool mmc_cmdq_should_pull_reqs(struct mmc_host *host,
 					struct mmc_cmdq_context_info *ctx)
 {
-	if (test_bit(CMDQ_STATE_ERR, &ctx->curr_state)) {
+	if (test_bit(CMDQ_STATE_DCMD_ACTIVE, &ctx->curr_state) ||
+		test_bit(CMDQ_STATE_ERR, &ctx->curr_state)) {
 		pr_debug("%s: %s: skip pulling reqs: state: %lu\n",
 			 mmc_hostname(host), __func__, ctx->curr_state);
 		return false;
drivers/mmc/core/core.c +8 -0
index 32b6790..fdb24cc 100644
@@ -617,6 +617,14 @@ int mmc_cmdq_start_req(struct mmc_host *host, struct mmc_cmdq_req *cmdq_req)
 }
 EXPORT_SYMBOL(mmc_cmdq_start_req);
 
+int mmc_cmdq_prepare_flush(struct mmc_command *cmd)
+{
+	return   __mmc_switch_cmdq_mode(cmd, EXT_CSD_CMD_SET_NORMAL,
+				     EXT_CSD_FLUSH_CACHE, 1,
+				     0, true, true);
+}
+EXPORT_SYMBOL(mmc_cmdq_prepare_flush);
+
 /**
  *	mmc_start_req - start a non-blocking request
  *	@host: MMC host to start command
drivers/mmc/core/mmc_ops.c +41 -6

59 lines not on this page · raw message

include/linux/mmc/core.h +4 -0
index a93e6f8..7b3a60c 100644
@@ -147,6 +147,7 @@ extern void mmc_cmdq_post_req(struct mmc_host *host, struct mmc_request *mrq,
 			      int err);
 extern int mmc_cmdq_start_req(struct mmc_host *host,
 			      struct mmc_cmdq_req *cmdq_req);
+extern int mmc_cmdq_prepare_flush(struct mmc_command *cmd);
 
 extern int mmc_stop_bkops(struct mmc_card *);
 extern int mmc_read_bkops_status(struct mmc_card *);
@@ -160,6 +161,9 @@ extern int mmc_wait_for_app_cmd(struct mmc_host *, struct mmc_card *,
 	struct mmc_command *, int);
 extern void mmc_start_bkops(struct mmc_card *card, bool from_exception);
 extern int mmc_switch(struct mmc_card *, u8, u8, u8, unsigned int);
+extern int __mmc_switch_cmdq_mode(struct mmc_command *cmd, u8 set, u8 index,
+				  u8 value, unsigned int timeout_ms,
+				  bool use_busy_signal, bool ignore_timeout);
 extern int mmc_send_tuning(struct mmc_host *host, u32 opcode, int *cmd_error);
 extern int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd);
 
include/linux/mmc/host.h +1 -0
index 319501e..c73cf27 100644
@@ -224,6 +224,7 @@ struct mmc_cmdq_context_info {
 	unsigned long	active_reqs; /* in-flight requests */
 	unsigned long	curr_state;
 #define	CMDQ_STATE_ERR 0
+#define	CMDQ_STATE_DCMD_ACTIVE 1
 	/* no free tag available */
 	unsigned long	req_starved;
 };
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
a Linux Foundation Collaborative Project.
#12 lore raw

RFC PATCH v2 6/10 mmc: host: sdhci: don't set SDMA buffer boundary in ADMA mode

In reply to Ritesh Harjani

From: Subhash Jadavani <[email protected]>

SDMA buffer boundary size parameter in block size register should only be programmed if host controller DMA is operating in SDMA mode otherwise its better not to set this parameter to avoid any side effect when DMA is operating in ADMA mode operation.

---
 drivers/mmc/host/sdhci.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
drivers/mmc/host/sdhci.c +15 -8
index 0e3d7c0..9f5cdaa 100644
@@ -742,6 +742,17 @@ static void sdhci_set_timeout(struct sdhci_host *host, struct mmc_command *cmd)
 	}
 }
 
+static void sdhci_set_blk_size_reg(struct sdhci_host *host, unsigned int blksz,
+				   unsigned int sdma_boundary)
+{
+	if (host->flags & SDHCI_USE_ADMA)
+		sdhci_writew(host, SDHCI_MAKE_BLKSZ(0, blksz),
+			     SDHCI_BLOCK_SIZE);
+	else
+		sdhci_writew(host, SDHCI_MAKE_BLKSZ(sdma_boundary, blksz),
+			     SDHCI_BLOCK_SIZE);
+}
+
 static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_command *cmd)
 {
 	u8 ctrl;
@@ -874,8 +885,7 @@ static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_command *cmd)
 	sdhci_set_transfer_irqs(host);
 
 	/* Set the DMA boundary value and block size */
-	sdhci_writew(host, SDHCI_MAKE_BLKSZ(SDHCI_DEFAULT_BOUNDARY_ARG,
-		data->blksz), SDHCI_BLOCK_SIZE);
+	sdhci_set_blk_size_reg(host, data->blksz, SDHCI_DEFAULT_BOUNDARY_ARG);
 	sdhci_writew(host, data->blocks, SDHCI_BLOCK_COUNT);
 }
 
@@ -1935,14 +1945,11 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
 		 */
 		if (cmd.opcode == MMC_SEND_TUNING_BLOCK_HS200) {
 			if (mmc->ios.bus_width == MMC_BUS_WIDTH_8)
-				sdhci_writew(host, SDHCI_MAKE_BLKSZ(7, 128),
-					     SDHCI_BLOCK_SIZE);
+				sdhci_set_blk_size_reg(host, 128, 7);
 			else if (mmc->ios.bus_width == MMC_BUS_WIDTH_4)
-				sdhci_writew(host, SDHCI_MAKE_BLKSZ(7, 64),
-					     SDHCI_BLOCK_SIZE);
+				sdhci_set_blk_size_reg(host, 64, 7);
 		} else {
-			sdhci_writew(host, SDHCI_MAKE_BLKSZ(7, 64),
-				     SDHCI_BLOCK_SIZE);
+			sdhci_set_blk_size_reg(host, 64, 7);
 		}
 
 		/*
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
a Linux Foundation Collaborative Project.
#15 lore raw

RFC PATCH v2 7/10 mmc: cmdq: support for command queue enabled host

In reply to Ritesh Harjani

From: Venkat Gopalakrishnan <[email protected]>

This patch adds CMDQ support for command-queue compatible hosts.

Command queue is added in eMMC-5.1 specification. This enables the controller to process upto 32 requests at a time.

---
 drivers/mmc/host/Kconfig    |  13 +
 drivers/mmc/host/Makefile   |   1 +
 drivers/mmc/host/cmdq_hci.c | 636 ++++++++++++++++++++++++++++++++++++++++++++
 drivers/mmc/host/cmdq_hci.h | 207 ++++++++++++++
 include/linux/mmc/host.h    |  12 +
 5 files changed, 869 insertions(+)
 create mode 100644 drivers/mmc/host/cmdq_hci.c
 create mode 100644 drivers/mmc/host/cmdq_hci.h
drivers/mmc/host/Kconfig +13 -0
index 0aa484c..0381389 100644
@@ -774,6 +774,19 @@ config MMC_SUNXI
 	  This selects support for the SD/MMC Host Controller on
 	  Allwinner sunxi SoCs.
 
+config MMC_CQ_HCI
+	tristate "Command Queue Support"
+	depends on HAS_DMA
+	help
+	  This selects the Command Queue Host Controller Interface (CQHCI)
+	  support present in host controllers of Qualcomm Technologies, Inc
+	  amongst others.
+	  This controller supports eMMC devices with command queue support.
+
+	  If you have a controller with this interface, say Y or M here.
+
+	  If unsure, say N.
+
 config MMC_TOSHIBA_PCI
 	tristate "Toshiba Type A SD/MMC Card Interface Driver"
 	depends on PCI
drivers/mmc/host/Makefile +1 -0
index af918d2..3715f73 100644
@@ -76,6 +76,7 @@ obj-$(CONFIG_MMC_SDHCI_IPROC)		+= sdhci-iproc.o
 obj-$(CONFIG_MMC_SDHCI_MSM)		+= sdhci-msm.o
 obj-$(CONFIG_MMC_SDHCI_ST)		+= sdhci-st.o
 obj-$(CONFIG_MMC_SDHCI_MICROCHIP_PIC32)	+= sdhci-pic32.o
+obj-$(CONFIG_MMC_CQ_HCI)		+= cmdq_hci.o
 
 ifeq ($(CONFIG_CB710_DEBUG),y)
 	CFLAGS-cb710-mmc	+= -DDEBUG
drivers/mmc/host/cmdq_hci.c new file +636 -0

636 lines not on this page · raw message

drivers/mmc/host/cmdq_hci.h new file +207 -0

207 lines not on this page · raw message

include/linux/mmc/host.h +12 -0
index c73cf27..41b4e25 100644
@@ -430,6 +430,13 @@ struct mmc_host {
 	u32			dsr;	/* optional driver stage (DSR) value */
 
 	struct mmc_cmdq_context_info	cmdq_ctx;
+	/*
+	 * several cmdq supporting host controllers are extensions
+	 * of legacy controllers. This variable can be used to store
+	 * a reference to the cmdq extension of the existing host
+	 * controller.
+	 */
+	void *cmdq_private;
 	unsigned long		private[0] ____cacheline_aligned;
 };
 
@@ -444,6 +451,11 @@ static inline void *mmc_priv(struct mmc_host *host)
 	return (void *)host->private;
 }
 
+static inline void *mmc_cmdq_private(struct mmc_host *host)
+{
+	return host->cmdq_private;
+}
+
 #define mmc_host_is_spi(host)	((host)->caps & MMC_CAP_SPI)
 
 #define mmc_dev(x)	((x)->parent)
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
a Linux Foundation Collaborative Project.
#16 lore raw

RFC PATCH v2 8/10 mmc: core: Add halt support

In reply to Ritesh Harjani

From: Asutosh Das <[email protected]>

Halt is a controller feature that can change the controller mode from command-queue to legacy. This feature is very helpful in error cases.

---
 drivers/mmc/card/queue.c |  1 +
 drivers/mmc/core/core.c  | 33 +++++++++++++++++++++++++++++++++
 include/linux/mmc/core.h |  1 +
 include/linux/mmc/host.h | 17 +++++++++++++++++
 4 files changed, 52 insertions(+)
drivers/mmc/card/queue.c +1 -0
index 2697529..054a0b3 100644
@@ -50,6 +50,7 @@ static inline bool mmc_cmdq_should_pull_reqs(struct mmc_host *host,
 					struct mmc_cmdq_context_info *ctx)
 {
 	if (test_bit(CMDQ_STATE_DCMD_ACTIVE, &ctx->curr_state) ||
+		mmc_host_halt(host) ||
 		test_bit(CMDQ_STATE_ERR, &ctx->curr_state)) {
 		pr_debug("%s: %s: skip pulling reqs: state: %lu\n",
 			 mmc_hostname(host), __func__, ctx->curr_state);
drivers/mmc/core/core.c +33 -0
index fdb24cc..ab7f7fa 100644
@@ -603,6 +603,39 @@ void mmc_cmdq_post_req(struct mmc_host *host, struct mmc_request *mrq, int err)
 }
 EXPORT_SYMBOL(mmc_cmdq_post_req);
 
+/**
+ *	mmc_cmdq_halt - halt/un-halt the command queue engine
+ *	@host: host instance
+ *	@halt: true - halt, un-halt otherwise
+ *
+ *	Host halts the command queue engine. It should complete
+ *	the ongoing transfer and release the bus.
+ *	All legacy commands can be sent upon successful
+ *	completion of this function.
+ *	Returns 0 on success, negative otherwise
+ */
+int mmc_cmdq_halt(struct mmc_host *host, bool halt)
+{
+	int err = 0;
+
+	if ((halt && mmc_host_halt(host)) ||
+	    (!halt && !mmc_host_halt(host)))
+		return -EINVAL;
+
+	if (host->cmdq_ops->halt) {
+		err = host->cmdq_ops->halt(host, halt);
+		if (!err && halt)
+			mmc_host_set_halt(host);
+		else if (!err && !halt)
+			mmc_host_clr_halt(host);
+	} else {
+		err = -ENOSYS;
+	}
+
+	return err;
+}
+EXPORT_SYMBOL(mmc_cmdq_halt);
+
 int mmc_cmdq_start_req(struct mmc_host *host, struct mmc_cmdq_req *cmdq_req)
 {
 	struct mmc_request *mrq = &cmdq_req->mrq;
include/linux/mmc/core.h +1 -0
index 7b3a60c..92aa8cc 100644
@@ -143,6 +143,7 @@ struct mmc_card;
 struct mmc_async_req;
 struct mmc_cmdq_req;
 
+extern int mmc_cmdq_halt(struct mmc_host *host, bool enable);
 extern void mmc_cmdq_post_req(struct mmc_host *host, struct mmc_request *mrq,
 			      int err);
 extern int mmc_cmdq_start_req(struct mmc_host *host,
include/linux/mmc/host.h +17 -0
index 41b4e25..7f2ae52 100644
@@ -85,6 +85,7 @@ struct mmc_cmdq_host_ops {
 	int (*request)(struct mmc_host *host, struct mmc_request *mrq);
 	void (*post_req)(struct mmc_host *host, struct mmc_request *mrq,
 			 int err);
+	int (*halt)(struct mmc_host *host, bool halt);
 };
 
 struct mmc_host_ops {
@@ -225,6 +226,7 @@ struct mmc_cmdq_context_info {
 	unsigned long	curr_state;
 #define	CMDQ_STATE_ERR 0
 #define	CMDQ_STATE_DCMD_ACTIVE 1
+#define	CMDQ_STATE_HALT 2
 	/* no free tag available */
 	unsigned long	req_starved;
 };
@@ -544,6 +546,21 @@ static inline int mmc_host_packed_wr(struct mmc_host *host)
 	return host->caps2 & MMC_CAP2_PACKED_WR;
 }
 
+static inline void mmc_host_set_halt(struct mmc_host *host)
+{
+	set_bit(CMDQ_STATE_HALT, &host->cmdq_ctx.curr_state);
+}
+
+static inline void mmc_host_clr_halt(struct mmc_host *host)
+{
+	clear_bit(CMDQ_STATE_HALT, &host->cmdq_ctx.curr_state);
+}
+
+static inline int mmc_host_halt(struct mmc_host *host)
+{
+	return test_bit(CMDQ_STATE_HALT, &host->cmdq_ctx.curr_state);
+}
+
 static inline int mmc_card_hs(struct mmc_card *card)
 {
 	return card->host->ios.timing == MMC_TIMING_SD_HS ||
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
a Linux Foundation Collaborative Project.
#17 lore raw

RFC PATCH v2 9/10 mmc: cmdq-host: add halt support to command queue host

In reply to Ritesh Harjani

From: Asutosh Das <[email protected]>

Halt can be used in error cases to get control of the bus. This is used to remove a task from device queue and/or other recovery mechanisms.

---
 drivers/mmc/host/cmdq_hci.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
drivers/mmc/host/cmdq_hci.c +35 -0
index 322b77c..33c860b 100644
@@ -29,6 +29,9 @@
 #define DCMD_SLOT 31
 #define NUM_SLOTS 32
 
+/* 1 sec */
+#define HALT_TIMEOUT_MS 1000
+
 static inline u8 *get_desc(struct cmdq_host *cq_host, u8 tag)
 {
 	return cq_host->desc_base + (tag * cq_host->slot_sz);
@@ -552,11 +555,42 @@ irqreturn_t cmdq_irq(struct mmc_host *mmc, u32 intmask)
 		cmdq_dumpregs(cq_host);
 	}
 
+	if (status & CQIS_HAC) {
+		/* halt is completed, wakeup waiting thread */
+		complete(&cq_host->halt_comp);
+	}
+
 out:
 	return IRQ_HANDLED;
 }
 EXPORT_SYMBOL(cmdq_irq);
 
+/* May sleep */
+static int cmdq_halt(struct mmc_host *mmc, bool halt)
+{
+	struct cmdq_host *cq_host = (struct cmdq_host *)mmc_cmdq_private(mmc);
+	u32 val = 0;
+
+	if (halt) {
+		cmdq_writel(cq_host, cmdq_readl(cq_host, CQCTL) | HALT,
+			    CQCTL);
+		val = wait_for_completion_timeout(&cq_host->halt_comp,
+					  msecs_to_jiffies(HALT_TIMEOUT_MS));
+		/* halt done: re-enable legacy interrupts */
+		if (cq_host->ops->clear_set_irqs)
+			cq_host->ops->clear_set_irqs(mmc, false);
+
+		val = val ? 0 : -ETIMEDOUT;
+	} else {
+		if (cq_host->ops->clear_set_irqs)
+			cq_host->ops->clear_set_irqs(mmc, true);
+		cmdq_writel(cq_host, cmdq_readl(cq_host, CQCTL) & ~HALT,
+			    CQCTL);
+	}
+
+	return val;
+}
+
 static void cmdq_post_req(struct mmc_host *host, struct mmc_request *mrq,
 			  int err)
 {
@@ -579,6 +613,7 @@ static const struct mmc_cmdq_host_ops cmdq_host_ops = {
 	.disable = cmdq_disable,
 	.request = cmdq_request,
 	.post_req = cmdq_post_req,
+	.halt = cmdq_halt,
 };
 
 struct cmdq_host *cmdq_pltfm_init(struct platform_device *pdev)
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
a Linux Foundation Collaborative Project.
#18 lore raw

RFC PATCH v2 10/10 mmc: sdhci: add command queue support to sdhci

In reply to Ritesh Harjani

From: Asutosh Das <[email protected]>

Adds command-queue support to SDHCi compliant drivers.

[[email protected]: fixed trivial merge conflicts and compilation error]

---
 drivers/mmc/host/sdhci.c | 146 +++++++++++++++++++++++++++++++++++++++++++++--
 drivers/mmc/host/sdhci.h |   6 ++
 2 files changed, 148 insertions(+), 4 deletions(-)
drivers/mmc/host/sdhci.c +142 -4
index 9f5cdaa..0ed9c45 100644
@@ -32,6 +32,7 @@
 #include <linux/mmc/slot-gpio.h>
 
 #include "sdhci.h"
+#include "cmdq_hci.h"
 
 #define DRIVER_NAME "sdhci"
 
@@ -2474,6 +2475,20 @@ static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
 	}
 }
 
+#ifdef CONFIG_MMC_CQ_HCI
+static irqreturn_t sdhci_cmdq_irq(struct mmc_host *mmc, u32 intmask)
+{
+	return cmdq_irq(mmc, intmask);
+}
+
+#else
+static irqreturn_t sdhci_cmdq_irq(struct mmc_host *mmc, u32 intmask)
+{
+	pr_err("%s: rxd cmdq-irq when disabled !!!!\n", mmc_hostname(mmc));
+	return IRQ_NONE;
+}
+#endif
+
 static irqreturn_t sdhci_irq(int irq, void *dev_id)
 {
 	irqreturn_t result = IRQ_NONE;
@@ -2495,6 +2510,15 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
 	}
 
 	do {
+		if (host->mmc->card && mmc_card_cmdq(host->mmc->card) &&
+		    !mmc_host_halt(host->mmc)) {
+			pr_debug("*** %s: cmdq intr: 0x%08x\n",
+					mmc_hostname(host->mmc),
+					intmask);
+			result = sdhci_cmdq_irq(host->mmc, intmask);
+			goto out;
+		}
+
 		/* Clear selected interrupts. */
 		mask = intmask & (SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK |
 				  SDHCI_INT_BUS_POWER);
@@ -2823,6 +2847,106 @@ static int sdhci_set_dma_mask(struct sdhci_host *host)
 	return ret;
 }
 
+#ifdef CONFIG_MMC_CQ_HCI
+static void sdhci_cmdq_clear_set_irqs(struct mmc_host *mmc, bool clear)
+{
+	struct sdhci_host *host = mmc_priv(mmc);
+	u32 ier = 0;
+
+	ier &= ~SDHCI_INT_ALL_MASK;
+
+	if (clear) {
+		ier = SDHCI_INT_CMDQ_EN | SDHCI_INT_ERROR_MASK;
+		sdhci_writel(host, ier, SDHCI_INT_ENABLE);
+		sdhci_writel(host, ier, SDHCI_SIGNAL_ENABLE);
+	} else {
+		ier = SDHCI_INT_BUS_POWER | SDHCI_INT_DATA_END_BIT |
+			     SDHCI_INT_DATA_CRC | SDHCI_INT_DATA_TIMEOUT |
+			     SDHCI_INT_INDEX | SDHCI_INT_END_BIT |
+			     SDHCI_INT_CRC | SDHCI_INT_TIMEOUT |
+			     SDHCI_INT_DATA_END | SDHCI_INT_RESPONSE |
+			     SDHCI_INT_ACMD12ERR;
+		sdhci_writel(host, ier, SDHCI_INT_ENABLE);
+		sdhci_writel(host, ier, SDHCI_SIGNAL_ENABLE);
+	}
+}
+
+static void sdhci_cmdq_set_data_timeout(struct mmc_host *mmc, u32 val)
+{
+	struct sdhci_host *host = mmc_priv(mmc);
+
+	sdhci_writeb(host, val, SDHCI_TIMEOUT_CONTROL);
+}
+
+static void sdhci_cmdq_dump_vendor_regs(struct mmc_host *mmc)
+{
+	struct sdhci_host *host = mmc_priv(mmc);
+
+	sdhci_dumpregs(host);
+}
+
+static int sdhci_cmdq_init(struct sdhci_host *host, struct mmc_host *mmc,
+			   bool dma64)
+{
+	return cmdq_init(host->cq_host, mmc, dma64);
+}
+
+static void sdhci_cmdq_set_block_size(struct mmc_host *mmc)
+{
+	struct sdhci_host *host = mmc_priv(mmc);
+
+	sdhci_set_blk_size_reg(host, 512, 0);
+}
+
+static void sdhci_cmdq_clear_set_dumpregs(struct mmc_host *mmc, bool set)
+{
+	struct sdhci_host *host = mmc_priv(mmc);
+
+	if (host->ops->clear_set_dumpregs)
+		host->ops->clear_set_dumpregs(host, set);
+}
+#else
+static void sdhci_cmdq_clear_set_irqs(struct mmc_host *mmc, bool clear)
+{
+
+}
+
+static void sdhci_cmdq_set_data_timeout(struct mmc_host *mmc, u32 val)
+{
+
+}
+
+static void sdhci_cmdq_dump_vendor_regs(struct mmc_host *mmc)
+{
+
+}
+
+static int sdhci_cmdq_init(struct sdhci_host *host, struct mmc_host *mmc,
+			   bool dma64)
+{
+	return -ENOSYS;
+}
+
+static void sdhci_cmdq_set_block_size(struct mmc_host *mmc)
+{
+
+}
+
+static void sdhci_cmdq_clear_set_dumpregs(struct mmc_host *mmc, bool set)
+{
+
+}
+
+#endif
+
+static const struct cmdq_host_ops sdhci_cmdq_ops = {
+	.clear_set_irqs = sdhci_cmdq_clear_set_irqs,
+	.set_data_timeout = sdhci_cmdq_set_data_timeout,
+	.dump_vendor_regs = sdhci_cmdq_dump_vendor_regs,
+	.set_block_size = sdhci_cmdq_set_block_size,
+	.clear_set_dumpregs = sdhci_cmdq_clear_set_dumpregs,
+};
+
 int sdhci_add_host(struct sdhci_host *host)
 {
 	struct mmc_host *mmc;
@@ -3341,11 +3465,25 @@ int sdhci_add_host(struct sdhci_host *host)
 	if (ret)
 		goto unled;
 
-	pr_info("%s: SDHCI controller on %s [%s] using %s\n",
-		mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)),
+	if (mmc->caps2 &  MMC_CAP2_CMD_QUEUE) {
+		bool dma64 = (host->flags & SDHCI_USE_ADMA_64BIT) ?
+			true : false;
+		ret = sdhci_cmdq_init(host, mmc, dma64);
+		if (ret)
+			pr_err("%s: CMDQ init: failed (%d)\n",
+			       mmc_hostname(host->mmc), ret);
+		else
+			host->cq_host->ops = &sdhci_cmdq_ops;
+	}
+
+	pr_info("%s: SDHCI controller on %s [%s] using %s in %s mode\n",
+	mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)),
 		(host->flags & SDHCI_USE_ADMA) ?
-		(host->flags & SDHCI_USE_64_BIT_DMA) ? "ADMA 64-bit" : "ADMA" :
-		(host->flags & SDHCI_USE_SDMA) ? "DMA" : "PIO");
+		((host->flags & SDHCI_USE_ADMA_64BIT) ?
+		"64-bit ADMA" : "32-bit ADMA") :
+		((host->flags & SDHCI_USE_SDMA) ? "DMA" : "PIO"),
+		((mmc->caps2 &  MMC_CAP2_CMD_QUEUE) && !ret) ?
+		"CMDQ" : "legacy");
 
 	sdhci_enable_card_detection(host);
 
drivers/mmc/host/sdhci.h +6 -0
index 609f87c..fccc750 100644
@@ -150,6 +150,8 @@
 		SDHCI_INT_DATA_TIMEOUT | SDHCI_INT_DATA_CRC | \
 		SDHCI_INT_DATA_END_BIT | SDHCI_INT_ADMA_ERROR | \
 		SDHCI_INT_BLK_GAP)
+
+#define SDHCI_INT_CMDQ_EN	(0x1 << 14)
 #define SDHCI_INT_ALL_MASK	((unsigned int)-1)
 
 #define SDHCI_ACMD12_ERR	0x3C
@@ -446,6 +448,7 @@ struct sdhci_host {
 #define SDHCI_PV_ENABLED	(1<<8)	/* Preset value enabled */
 #define SDHCI_SDIO_IRQ_ENABLED	(1<<9)	/* SDIO irq enabled */
 #define SDHCI_USE_64_BIT_DMA	(1<<12)	/* Use 64-bit DMA */
+#define SDHCI_USE_ADMA_64BIT	(1<<12)	/* Host is 64-bit ADMA capable */
 #define SDHCI_HS400_TUNING	(1<<13)	/* Tuning for HS400 */
 
 	unsigned int version;	/* SDHCI spec. version */
@@ -509,6 +512,8 @@ struct sdhci_host {
 	unsigned int		tuning_mode;	/* Re-tuning mode supported by host */
 #define SDHCI_TUNING_MODE_1	0
 
+	struct cmdq_host *cq_host;
+
 	unsigned long private[0] ____cacheline_aligned;
 };
 
@@ -544,6 +549,7 @@ struct sdhci_ops {
 	void    (*adma_workaround)(struct sdhci_host *host, u32 intmask);
 	void	(*platform_init)(struct sdhci_host *host);
 	void    (*card_event)(struct sdhci_host *host);
+	void	(*clear_set_dumpregs)(struct sdhci_host *host, bool set);
 	void	(*voltage_switch)(struct sdhci_host *host);
 	int	(*select_drive_strength)(struct sdhci_host *host,
 					 struct mmc_card *card,
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
a Linux Foundation Collaborative Project.
maintainer
#13 lore raw

Re: [PATCH RFCv2 06/10] mmc: host: sdhci: don't set SDMA buffer boundary in ADMA mode

In reply to Ritesh Harjani
Quoted 6 lines · Ritesh Harjani

From: Subhash Jadavani <[email protected]>

SDMA buffer boundary size parameter in block size register should only be programmed if host controller DMA is operating in SDMA mode otherwise its better not to set this parameter to avoid any side effect when DMA is operating in ADMA mode operation.

Pedantically, the SDHCI specification does not say the SDMA Buffer Boundary should not be set in ADMA mode. All it says is that ADMA does not use it. In fact it is impossible to avoid writing to it because it is part of the Block Size register. Unfortunately the value 0 does not mean "not used" but instead means the boundary is 4K whereas the value presently being written (7 which is the highest) means 512K.

Given that we have always been writing 7 to it, I don't see any reason to change. Murphy's law says if we do change it, someone else's driver will break.

However I presume you have hardware where value 7 doesn't work. Can you clarify that?

Quoted 59 lines
---
 drivers/mmc/host/sdhci.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
drivers/mmc/host/sdhci.c +15 -8
index 0e3d7c0..9f5cdaa 100644
@@ -742,6 +742,17 @@ static void sdhci_set_timeout(struct sdhci_host *host, struct mmc_command *cmd)
 	}
 }
 
+static void sdhci_set_blk_size_reg(struct sdhci_host *host, unsigned int blksz,
+				   unsigned int sdma_boundary)
+{
+	if (host->flags & SDHCI_USE_ADMA)
+		sdhci_writew(host, SDHCI_MAKE_BLKSZ(0, blksz),
+			     SDHCI_BLOCK_SIZE);
+	else
+		sdhci_writew(host, SDHCI_MAKE_BLKSZ(sdma_boundary, blksz),
+			     SDHCI_BLOCK_SIZE);
+}
+
 static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_command *cmd)
 {
 	u8 ctrl;
@@ -874,8 +885,7 @@ static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_command *cmd)
 	sdhci_set_transfer_irqs(host);
 
 	/* Set the DMA boundary value and block size */
-	sdhci_writew(host, SDHCI_MAKE_BLKSZ(SDHCI_DEFAULT_BOUNDARY_ARG,
-		data->blksz), SDHCI_BLOCK_SIZE);
+	sdhci_set_blk_size_reg(host, data->blksz, SDHCI_DEFAULT_BOUNDARY_ARG);
 	sdhci_writew(host, data->blocks, SDHCI_BLOCK_COUNT);
 }
 
@@ -1935,14 +1945,11 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
 		 */
 		if (cmd.opcode == MMC_SEND_TUNING_BLOCK_HS200) {
 			if (mmc->ios.bus_width == MMC_BUS_WIDTH_8)
-				sdhci_writew(host, SDHCI_MAKE_BLKSZ(7, 128),
-					     SDHCI_BLOCK_SIZE);
+				sdhci_set_blk_size_reg(host, 128, 7);
 			else if (mmc->ios.bus_width == MMC_BUS_WIDTH_4)
-				sdhci_writew(host, SDHCI_MAKE_BLKSZ(7, 64),
-					     SDHCI_BLOCK_SIZE);
+				sdhci_set_blk_size_reg(host, 64, 7);
 		} else {
-			sdhci_writew(host, SDHCI_MAKE_BLKSZ(7, 64),
-				     SDHCI_BLOCK_SIZE);
+			sdhci_set_blk_size_reg(host, 64, 7);
 		}
 
 		/*
#14 lore raw

Re: [PATCH RFCv2 06/10] mmc: host: sdhci: don't set SDMA buffer boundary in ADMA mode

Hi Adrian,

Quoted 8 lines · Adrian Hunter
Quoted 6 lines · Ritesh Harjani

From: Subhash Jadavani <[email protected]>

SDMA buffer boundary size parameter in block size register should only be programmed if host controller DMA is operating in SDMA mode otherwise its better not to set this parameter to avoid any side effect when DMA is operating in ADMA mode operation.

Quoted 6 lines

Pedantically, the SDHCI specification does not say the SDMA Buffer Boundary should not be set in ADMA mode. All it says is that ADMA does not use it. In fact it is impossible to avoid writing to it because it is part of the Block Size register. Unfortunately the value 0 does not mean "not used" but instead means the boundary is 4K whereas the value presently being written (7 which is the highest) means 512K.

Ok.

Quoted 6 lines

Given that we have always been writing 7 to it, I don't see any reason to change. Murphy's law says if we do change it, someone else's driver will break.

However I presume you have hardware where value 7 doesn't work. Can you clarify that?

I think this was good to have patch, since SDHCI spec does not explicitly mention about this for ADMA. But agree with what you have mentioned. I will drop this patch then.

Quoted 61 lines
Quoted 60 lines
---
 drivers/mmc/host/sdhci.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
drivers/mmc/host/sdhci.c +15 -8
index 0e3d7c0..9f5cdaa 100644
@@ -742,6 +742,17 @@ static void sdhci_set_timeout(struct sdhci_host *host, struct mmc_command *cmd)
 	}
 }
 
+static void sdhci_set_blk_size_reg(struct sdhci_host *host, unsigned int blksz,
+				   unsigned int sdma_boundary)
+{
+	if (host->flags & SDHCI_USE_ADMA)
+		sdhci_writew(host, SDHCI_MAKE_BLKSZ(0, blksz),
+			     SDHCI_BLOCK_SIZE);
+	else
+		sdhci_writew(host, SDHCI_MAKE_BLKSZ(sdma_boundary, blksz),
+			     SDHCI_BLOCK_SIZE);
+}
+
 static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_command *cmd)
 {
 	u8 ctrl;
@@ -874,8 +885,7 @@ static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_command *cmd)
 	sdhci_set_transfer_irqs(host);
 
 	/* Set the DMA boundary value and block size */
-	sdhci_writew(host, SDHCI_MAKE_BLKSZ(SDHCI_DEFAULT_BOUNDARY_ARG,
-		data->blksz), SDHCI_BLOCK_SIZE);
+	sdhci_set_blk_size_reg(host, data->blksz, SDHCI_DEFAULT_BOUNDARY_ARG);
 	sdhci_writew(host, data->blocks, SDHCI_BLOCK_COUNT);
 }
 
@@ -1935,14 +1945,11 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
 		 */
 		if (cmd.opcode == MMC_SEND_TUNING_BLOCK_HS200) {
 			if (mmc->ios.bus_width == MMC_BUS_WIDTH_8)
-				sdhci_writew(host, SDHCI_MAKE_BLKSZ(7, 128),
-					     SDHCI_BLOCK_SIZE);
+				sdhci_set_blk_size_reg(host, 128, 7);
 			else if (mmc->ios.bus_width == MMC_BUS_WIDTH_4)
-				sdhci_writew(host, SDHCI_MAKE_BLKSZ(7, 64),
-					     SDHCI_BLOCK_SIZE);
+				sdhci_set_blk_size_reg(host, 64, 7);
 		} else {
-			sdhci_writew(host, SDHCI_MAKE_BLKSZ(7, 64),
-				     SDHCI_BLOCK_SIZE);
+			sdhci_set_blk_size_reg(host, 64, 7);
 		}
 
 		/*
maintainer
#19 lore raw

Re: [PATCH RFCv2 10/10] mmc: sdhci: add command queue support to sdhci

In reply to Ritesh Harjani
Quoted 3 lines · Ritesh Harjani

From: Asutosh Das <[email protected]>

Adds command-queue support to SDHCi compliant drivers.

CQHCI is not recognized in the SDHCI specification, and SDHCI should facilitate any CQE driver implementation not just CQHCI. That means there are 2 options:

1. Provide minimal support to allow individual host drivers to deal with CQHCI directly.

2. Create explicit support for a CQE companion driver and use that to provide common support for CQHCI.

I started looking at option 2 and concluded that it was taking SDHCI in the wrong direction because it made drivers more dependent on SDHCI and gave them less flexibility, and it seemed inconsistent with the aim of making SDHCI more like a library.

Consequently, I suggest the following:

1. Individual drivers are responsible for initializing and setting up CQHCI and its callbacks, and shutting it down.

2. SDHCI provides a new callback so that individual drivers can process interrupts and pass them to CQHCI.

3. SDHCI provides and exports any common helper functions that do not depend directly on CQHCI. For example the functions to set interrupts, timeout, blocks size and dump registers.

Quoted 19 lines

[[email protected]: fixed trivial merge conflicts and compilation error]

---
 drivers/mmc/host/sdhci.c | 146 +++++++++++++++++++++++++++++++++++++++++++++--
 drivers/mmc/host/sdhci.h |   6 ++
 2 files changed, 148 insertions(+), 4 deletions(-)
drivers/mmc/host/sdhci.c +0 -0
index 9f5cdaa..0ed9c45 100644

drivers/mmc/host/sdhci.c line 35

Quoted 4 lines
drivers/mmc/host/sdhci.c +1 -0
@@ -32,6 +32,7 @@
 #include <linux/mmc/slot-gpio.h>
 
 #include "sdhci.h"
+#include "cmdq_hci.h"

As discussed above, SDHCI should not have any references to CQHCI

drivers/mmc/host/sdhci.c static void sdhci_data_irq(struct sdhci_host *host, u32 intmask) · line 2478

Quoted 8 lines
drivers/mmc/host/sdhci.c +1 -0
 #define DRIVER_NAME "sdhci"
 
@@ -2474,6 +2475,20 @@ static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
 	}
 }
 
+#ifdef CONFIG_MMC_CQ_HCI

This won't work if CQHCI is a module. If you fix the dependencies then you can use:

#if IS_ENABLED(CONFIG_MMC_CQ_HCI)

Or if you select CONFIG_MMC_CQ_HCI in Kconfig then you don't need ifdef at all.

drivers/mmc/host/sdhci.c static void sdhci_data_irq(struct sdhci_host *host, u32 intmask) · line 2481

Quoted 3 lines
drivers/mmc/host/sdhci.c +3 -0
+static irqreturn_t sdhci_cmdq_irq(struct mmc_host *mmc, u32 intmask)
+{
+	return cmdq_irq(mmc, intmask);

This will give a linker error if the driver is built-in but CQHCI is a module. Probably drivers that use CQHCI should just select it in Kconfig.

Another issue is that CQHCI won't be able to interpret SDHCI interrupt bits.
I suggest you define a generic set of bit flags not dependent on SDHCI or
CQHCI and then we can create a function to convert the SDHCI interrupt status.

Quoted 16 lines
drivers/mmc/host/sdhci.c +10 -0
+}
+
+#else
+static irqreturn_t sdhci_cmdq_irq(struct mmc_host *mmc, u32 intmask)
+{
+	pr_err("%s: rxd cmdq-irq when disabled !!!!\n", mmc_hostname(mmc));
+	return IRQ_NONE;
+}
+#endif
+
 static irqreturn_t sdhci_irq(int irq, void *dev_id)
 {
 	irqreturn_t result = IRQ_NONE;
@@ -2495,6 +2510,15 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
 	}
 

drivers/mmc/host/sdhci.c static irqreturn_t sdhci_irq(int irq, void *dev_id) · line 2521

Quoted 10 lines
drivers/mmc/host/sdhci.c +9 -0
 	do {
+		if (host->mmc->card && mmc_card_cmdq(host->mmc->card) &&
+		    !mmc_host_halt(host->mmc)) {
+			pr_debug("*** %s: cmdq intr: 0x%08x\n",
+					mmc_hostname(host->mmc),
+					intmask);
+			result = sdhci_cmdq_irq(host->mmc, intmask);
+			goto out;
+		}
+

We need to create a new SDHCI host op to enable individual drivers to handle the IRQ if they choose. Then it is up to individual drivers to call into CQHCI.

Quoted 7 lines
drivers/mmc/host/sdhci.c +0 -0
 		/* Clear selected interrupts. */
 		mask = intmask & (SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK |
 				  SDHCI_INT_BUS_POWER);
@@ -2823,6 +2847,106 @@ static int sdhci_set_dma_mask(struct sdhci_host *host)
 	return ret;
 }
 

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host *host) · line 2859

Quoted 10 lines
drivers/mmc/host/sdhci.c +10 -0
+#ifdef CONFIG_MMC_CQ_HCI
+static void sdhci_cmdq_clear_set_irqs(struct mmc_host *mmc, bool clear)
+{
+	struct sdhci_host *host = mmc_priv(mmc);
+	u32 ier = 0;
+
+	ier &= ~SDHCI_INT_ALL_MASK;
+
+	if (clear) {
+		ier = SDHCI_INT_CMDQ_EN | SDHCI_INT_ERROR_MASK;

SDHCI_INT_ERROR_MASK is not ideal here. I would expect to set only the bits we know and want.

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host *host) · line 2868

Quoted 9 lines
drivers/mmc/host/sdhci.c +9 -0
+		sdhci_writel(host, ier, SDHCI_INT_ENABLE);
+		sdhci_writel(host, ier, SDHCI_SIGNAL_ENABLE);
+	} else {
+		ier = SDHCI_INT_BUS_POWER | SDHCI_INT_DATA_END_BIT |
+			     SDHCI_INT_DATA_CRC | SDHCI_INT_DATA_TIMEOUT |
+			     SDHCI_INT_INDEX | SDHCI_INT_END_BIT |
+			     SDHCI_INT_CRC | SDHCI_INT_TIMEOUT |
+			     SDHCI_INT_DATA_END | SDHCI_INT_RESPONSE |
+			     SDHCI_INT_ACMD12ERR;

We ought to have the default interrupts defined, so that the same ones are set here.

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host *host) · line 2874

Quoted 6 lines
drivers/mmc/host/sdhci.c +6 -0
+		sdhci_writel(host, ier, SDHCI_INT_ENABLE);
+		sdhci_writel(host, ier, SDHCI_SIGNAL_ENABLE);
+	}
+}
+
+static void sdhci_cmdq_set_data_timeout(struct mmc_host *mmc, u32 val)

Do we really need different callbacks for ->clear_set_irqs(), ->set_data_timeout(), ->set_block_size() and ->clear_set_dumpregs()? It looks like we could consolidate them all into just 2 i.e. to start and stop CQ mode.

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host *host) · line 2879

Quoted 5 lines
drivers/mmc/host/sdhci.c +5 -0
+{
+	struct sdhci_host *host = mmc_priv(mmc);
+
+	sdhci_writeb(host, val, SDHCI_TIMEOUT_CONTROL);
+}

We can't expect CQHCI to provide the SDHCI register value. Ideally we don't want to set the highest value but instead calculate the value based on the maximum sized transfer.

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host *host) · line 2886

Quoted 7 lines
drivers/mmc/host/sdhci.c +7 -0
+
+static void sdhci_cmdq_dump_vendor_regs(struct mmc_host *mmc)
+{
+	struct sdhci_host *host = mmc_priv(mmc);
+
+	sdhci_dumpregs(host);
+}

Instead you should export sdhci_dumpregs() and let the individual drivers connect it to CQHCI.

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host *host) · line 2892

Quoted 6 lines
drivers/mmc/host/sdhci.c +6 -0
+
+static int sdhci_cmdq_init(struct sdhci_host *host, struct mmc_host *mmc,
+			   bool dma64)
+{
+	return cmdq_init(host->cq_host, mmc, dma64);
+}

Individual drivers should initialize their CQE driver implementation. It is not necessarily CQHCI.

Quoted 5 lines
drivers/mmc/host/sdhci.c +5 -0
+
+static void sdhci_cmdq_set_block_size(struct mmc_host *mmc)
+{
+	struct sdhci_host *host = mmc_priv(mmc);
+

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host *host) · line 2907

Quoted 10 lines
drivers/mmc/host/sdhci.c +10 -0
+	sdhci_set_blk_size_reg(host, 512, 0);
+}
+
+static void sdhci_cmdq_clear_set_dumpregs(struct mmc_host *mmc, bool set)
+{
+	struct sdhci_host *host = mmc_priv(mmc);
+
+	if (host->ops->clear_set_dumpregs)
+		host->ops->clear_set_dumpregs(host, set);
+}

As questioned further below, what is this for?

Quoted 31 lines
drivers/mmc/host/sdhci.c +31 -0
+#else
+static void sdhci_cmdq_clear_set_irqs(struct mmc_host *mmc, bool clear)
+{
+
+}
+
+static void sdhci_cmdq_set_data_timeout(struct mmc_host *mmc, u32 val)
+{
+
+}
+
+static void sdhci_cmdq_dump_vendor_regs(struct mmc_host *mmc)
+{
+
+}
+
+static int sdhci_cmdq_init(struct sdhci_host *host, struct mmc_host *mmc,
+			   bool dma64)
+{
+	return -ENOSYS;
+}
+
+static void sdhci_cmdq_set_block_size(struct mmc_host *mmc)
+{
+
+}
+
+static void sdhci_cmdq_clear_set_dumpregs(struct mmc_host *mmc, bool set)
+{
+
+}

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host *host) · line 2948

Quoted 10 lines
drivers/mmc/host/sdhci.c +10 -0
+
+#endif
+
+static const struct cmdq_host_ops sdhci_cmdq_ops = {
+	.clear_set_irqs = sdhci_cmdq_clear_set_irqs,
+	.set_data_timeout = sdhci_cmdq_set_data_timeout,
+	.dump_vendor_regs = sdhci_cmdq_dump_vendor_regs,
+	.set_block_size = sdhci_cmdq_set_block_size,
+	.clear_set_dumpregs = sdhci_cmdq_clear_set_dumpregs,
+};

It would be up to individual drivers to provide CQHCI ops.

Quoted 5 lines
drivers/mmc/host/sdhci.c +1 -0
+
 int sdhci_add_host(struct sdhci_host *host)
 {
 	struct mmc_host *mmc;

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host *host) · line 3471

Quoted 9 lines
drivers/mmc/host/sdhci.c +4 -2
@@ -3341,11 +3465,25 @@ int sdhci_add_host(struct sdhci_host *host)
 	if (ret)
 		goto unled;
 
-	pr_info("%s: SDHCI controller on %s [%s] using %s\n",
-		mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)),
+	if (mmc->caps2 &  MMC_CAP2_CMD_QUEUE) {
+		bool dma64 = (host->flags & SDHCI_USE_ADMA_64BIT) ?
+			true : false;
+		ret = sdhci_cmdq_init(host, mmc, dma64);

You must initialize before mmc_add_host() because mmc_add_host() also starts the host. If you re-base on top of the SDHCI patches, then individual drivers can take advantage of the new sdhci_setup_host() / __sdhci_add_host() split.

Quoted 7 lines
drivers/mmc/host/sdhci.c +7 -0
+		if (ret)
+			pr_err("%s: CMDQ init: failed (%d)\n",
+			       mmc_hostname(host->mmc), ret);
+		else
+			host->cq_host->ops = &sdhci_cmdq_ops;
+	}
+

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host *host) · line 3486

Quoted 10 lines
drivers/mmc/host/sdhci.c +7 -2
+	pr_info("%s: SDHCI controller on %s [%s] using %s in %s mode\n",
+	mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)),
 		(host->flags & SDHCI_USE_ADMA) ?
-		(host->flags & SDHCI_USE_64_BIT_DMA) ? "ADMA 64-bit" : "ADMA" :
-		(host->flags & SDHCI_USE_SDMA) ? "DMA" : "PIO");
+		((host->flags & SDHCI_USE_ADMA_64BIT) ?
+		"64-bit ADMA" : "32-bit ADMA") :
+		((host->flags & SDHCI_USE_SDMA) ? "DMA" : "PIO"),
+		((mmc->caps2 &  MMC_CAP2_CMD_QUEUE) && !ret) ?
+		"CMDQ" : "legacy");

It is probably better if CQHCI prints its own info. That way it you get a consistent message irrespective of whether the driver uses SDHCI. Also you can print other CQHCI details such as the version.

drivers/mmc/host/sdhci.h line 154

Quoted 13 lines
drivers/mmc/host/sdhci.c +0 -0
 	sdhci_enable_card_detection(host);
 
drivers/mmc/host/sdhci.h +2 -0
index 609f87c..fccc750 100644
@@ -150,6 +150,8 @@
 		SDHCI_INT_DATA_TIMEOUT | SDHCI_INT_DATA_CRC | \
 		SDHCI_INT_DATA_END_BIT | SDHCI_INT_ADMA_ERROR | \
 		SDHCI_INT_BLK_GAP)
+
+#define SDHCI_INT_CMDQ_EN	(0x1 << 14)

We can define this bit for convenience but we need a comment to say that it is non-standard.

drivers/mmc/host/sdhci.h struct sdhci_host { · line 451

Quoted 8 lines
drivers/mmc/host/sdhci.h +1 -0
 #define SDHCI_INT_ALL_MASK	((unsigned int)-1)
 
 #define SDHCI_ACMD12_ERR	0x3C
@@ -446,6 +448,7 @@ struct sdhci_host {
 #define SDHCI_PV_ENABLED	(1<<8)	/* Preset value enabled */
 #define SDHCI_SDIO_IRQ_ENABLED	(1<<9)	/* SDIO irq enabled */
 #define SDHCI_USE_64_BIT_DMA	(1<<12)	/* Use 64-bit DMA */
+#define SDHCI_USE_ADMA_64BIT	(1<<12)	/* Host is 64-bit ADMA capable */

SDHCI_USE_ADMA_64BIT looks redundant.

drivers/mmc/host/sdhci.h struct sdhci_host { · line 516

Quoted 9 lines
drivers/mmc/host/sdhci.h +2 -0
 #define SDHCI_HS400_TUNING	(1<<13)	/* Tuning for HS400 */
 
 	unsigned int version;	/* SDHCI spec. version */
@@ -509,6 +512,8 @@ struct sdhci_host {
 	unsigned int		tuning_mode;	/* Re-tuning mode supported by host */
 #define SDHCI_TUNING_MODE_1	0
 
+	struct cmdq_host *cq_host;
+

The individual drivers will have to have their own reference to CQHCI.

drivers/mmc/host/sdhci.h struct sdhci_ops { · line 552

Quoted 8 lines
drivers/mmc/host/sdhci.h +1 -0
 	unsigned long private[0] ____cacheline_aligned;
 };
 
@@ -544,6 +549,7 @@ struct sdhci_ops {
 	void    (*adma_workaround)(struct sdhci_host *host, u32 intmask);
 	void	(*platform_init)(struct sdhci_host *host);
 	void    (*card_event)(struct sdhci_host *host);
+	void	(*clear_set_dumpregs)(struct sdhci_host *host, bool set);

What is this for?

Quoted 4 lines
drivers/mmc/host/sdhci.h +0 -0
 	void	(*voltage_switch)(struct sdhci_host *host);
 	int	(*select_drive_strength)(struct sdhci_host *host,
 					 struct mmc_card *card,
maintainer
#20 lore raw

Re: [PATCH RFCv2 10/10] mmc: sdhci: add command queue support to sdhci

Quoted 1 line · Adrian Hunter

On 27/06/16 16:22, Ritesh Harjani wrote:

<SNIP>

Quoted 9 lines

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host *host) · line 2879

Quoted 5 lines
drivers/mmc/host/sdhci.c +5 -0
+{
+	struct sdhci_host *host = mmc_priv(mmc);
+
+	sdhci_writeb(host, val, SDHCI_TIMEOUT_CONTROL);
+}

We can't expect CQHCI to provide the SDHCI register value. Ideally we don't want to set the highest value but instead calculate the value based on the maximum sized transfer.

Except cache flush doesn't have a timeout, so we will have to set the highest value if we issue cache flush via DCMD.

#21 lore raw

Re: [PATCH RFCv2 10/10] mmc: sdhci: add command queue support to sdhci

In reply to Adrian Hunter

Hi Adrian,

Sorry about this long delay, was pulled into some release. Will be more responsive from now.

We have gone through your comments. We had some queries and wanted to discuss more about your initial comments before going onto individual comments in the code. It would be great if you could help us understand more on your initial comments by answering to our queries.

Quoted 6 lines · Adrian Hunter
Quoted 3 lines · Ritesh Harjani

From: Asutosh Das <[email protected]>

Adds command-queue support to SDHCi compliant drivers.

CQHCI is not recognized in the SDHCI specification,

Yes. Not sure about future plan though.

Quoted 3 lines

and SDHCI should
facilitate any CQE driver implementation not just CQHCI. That means there are 2 options:

Are we aware of any other vendor specific implementation of CQHCI? Or do you foresee this coming through?
Actually CQ host controller interface(CQHCI) is what is proposed in emmc JEDEC5.1 which is mentioned as extension to HCI in block diagram. (Fig B.110 in emmc-5.1 JEDEC).

Quoted 12 lines

1. Provide minimal support to allow individual host drivers to deal with CQHCI directly.

2. Create explicit support for a CQE companion driver and use that to provide common support for CQHCI.

I started looking at option 2 and concluded that it was taking SDHCI in the wrong direction because it made drivers more dependent on SDHCI and gave them less flexibility, and it seemed inconsistent with the aim of making SDHCI more like a library.

Quoted 4 lines

Consequently, I suggest the following:

1. Individual drivers are responsible for initializing and setting up CQHCI and its callbacks, and shutting it down.

CQHCI callbacks is what the concern is. Currently the callbacks are placed in SDHCI, because these callbacks are doing nothing other than setting up SDHCI registers itself for CQHCI. There is nothing platform specific which is happening in these. So why do you think that these should be implemented in individual platform specific drivers?
Will that not result into same code duplication in all SDHCI compliant platform drivers?

Quoted 3 lines

2. SDHCI provides a new callback so that individual drivers can process interrupts and pass them to CQHCI.

This again will depend upon the initial ask on - do you foresee SDHCI facilitating other CQE implementations? Or if you are already aware of something else other than CQHCI?

Quoted 166 lines

3. SDHCI provides and exports any common helper functions that do not depend directly on CQHCI. For example the functions to set interrupts, timeout, blocks size and dump registers.

Quoted 19 lines

[[email protected]: fixed trivial merge conflicts and compilation error]

---
 drivers/mmc/host/sdhci.c | 146 +++++++++++++++++++++++++++++++++++++++++++++--
 drivers/mmc/host/sdhci.h |   6 ++
 2 files changed, 148 insertions(+), 4 deletions(-)
drivers/mmc/host/sdhci.c +0 -0
index 9f5cdaa..0ed9c45 100644

drivers/mmc/host/sdhci.c line 35

Quoted 4 lines
drivers/mmc/host/sdhci.c +1 -0
@@ -32,6 +32,7 @@
 #include <linux/mmc/slot-gpio.h>
 
 #include "sdhci.h"
+#include "cmdq_hci.h"

As discussed above, SDHCI should not have any references to CQHCI

drivers/mmc/host/sdhci.c static void sdhci_data_irq(struct sdhci_host *host, u32 intmask) · line 2478

Quoted 8 lines
drivers/mmc/host/sdhci.c +1 -0
 #define DRIVER_NAME "sdhci"
 
@@ -2474,6 +2475,20 @@ static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
 	}
 }
 
+#ifdef CONFIG_MMC_CQ_HCI

This won't work if CQHCI is a module. If you fix the dependencies then you can use:

#if IS_ENABLED(CONFIG_MMC_CQ_HCI)

Or if you select CONFIG_MMC_CQ_HCI in Kconfig then you don't need ifdef at all.

drivers/mmc/host/sdhci.c static void sdhci_data_irq(struct sdhci_host *host, u32 intmask) · line 2481

Quoted 3 lines
drivers/mmc/host/sdhci.c +3 -0
+static irqreturn_t sdhci_cmdq_irq(struct mmc_host *mmc, u32 intmask)
+{
+	return cmdq_irq(mmc, intmask);

This will give a linker error if the driver is built-in but CQHCI is a module. Probably drivers that use CQHCI should just select it in Kconfig.

Another issue is that CQHCI won't be able to interpret SDHCI interrupt bits.
I suggest you define a generic set of bit flags not dependent on SDHCI or
CQHCI and then we can create a function to convert the SDHCI interrupt status.

Quoted 16 lines
drivers/mmc/host/sdhci.c +10 -0
+}
+
+#else
+static irqreturn_t sdhci_cmdq_irq(struct mmc_host *mmc, u32 intmask)
+{
+	pr_err("%s: rxd cmdq-irq when disabled !!!!\n", mmc_hostname(mmc));
+	return IRQ_NONE;
+}
+#endif
+
 static irqreturn_t sdhci_irq(int irq, void *dev_id)
 {
 	irqreturn_t result = IRQ_NONE;
@@ -2495,6 +2510,15 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
 	}
 

drivers/mmc/host/sdhci.c static irqreturn_t sdhci_irq(int irq, void *dev_id) · line 2521

Quoted 10 lines
drivers/mmc/host/sdhci.c +9 -0
 	do {
+		if (host->mmc->card && mmc_card_cmdq(host->mmc->card) &&
+		    !mmc_host_halt(host->mmc)) {
+			pr_debug("*** %s: cmdq intr: 0x%08x\n",
+					mmc_hostname(host->mmc),
+					intmask);
+			result = sdhci_cmdq_irq(host->mmc, intmask);
+			goto out;
+		}
+

We need to create a new SDHCI host op to enable individual drivers to handle the IRQ if they choose. Then it is up to individual drivers to call into CQHCI.

Quoted 7 lines
drivers/mmc/host/sdhci.c +0 -0
 		/* Clear selected interrupts. */
 		mask = intmask & (SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK |
 				  SDHCI_INT_BUS_POWER);
@@ -2823,6 +2847,106 @@ static int sdhci_set_dma_mask(struct sdhci_host *host)
 	return ret;
 }
 

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host *host) · line 2859

Quoted 10 lines
drivers/mmc/host/sdhci.c +10 -0
+#ifdef CONFIG_MMC_CQ_HCI
+static void sdhci_cmdq_clear_set_irqs(struct mmc_host *mmc, bool clear)
+{
+	struct sdhci_host *host = mmc_priv(mmc);
+	u32 ier = 0;
+
+	ier &= ~SDHCI_INT_ALL_MASK;
+
+	if (clear) {
+		ier = SDHCI_INT_CMDQ_EN | SDHCI_INT_ERROR_MASK;

SDHCI_INT_ERROR_MASK is not ideal here. I would expect to set only the bits we know and want.

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host *host) · line 2868

Quoted 9 lines
drivers/mmc/host/sdhci.c +9 -0
+		sdhci_writel(host, ier, SDHCI_INT_ENABLE);
+		sdhci_writel(host, ier, SDHCI_SIGNAL_ENABLE);
+	} else {
+		ier = SDHCI_INT_BUS_POWER | SDHCI_INT_DATA_END_BIT |
+			     SDHCI_INT_DATA_CRC | SDHCI_INT_DATA_TIMEOUT |
+			     SDHCI_INT_INDEX | SDHCI_INT_END_BIT |
+			     SDHCI_INT_CRC | SDHCI_INT_TIMEOUT |
+			     SDHCI_INT_DATA_END | SDHCI_INT_RESPONSE |
+			     SDHCI_INT_ACMD12ERR;

We ought to have the default interrupts defined, so that the same ones are set here.

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host *host) · line 2874

Quoted 6 lines
drivers/mmc/host/sdhci.c +6 -0
+		sdhci_writel(host, ier, SDHCI_INT_ENABLE);
+		sdhci_writel(host, ier, SDHCI_SIGNAL_ENABLE);
+	}
+}
+
+static void sdhci_cmdq_set_data_timeout(struct mmc_host *mmc, u32 val)

Do we really need different callbacks for ->clear_set_irqs(), ->set_data_timeout(), ->set_block_size() and ->clear_set_dumpregs()? It looks like we could consolidate them all into just 2 i.e. to start and stop CQ mode.

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host *host) · line 2879

Quoted 5 lines
drivers/mmc/host/sdhci.c +5 -0
+{
+	struct sdhci_host *host = mmc_priv(mmc);
+
+	sdhci_writeb(host, val, SDHCI_TIMEOUT_CONTROL);
+}

We can't expect CQHCI to provide the SDHCI register value. Ideally we don't want to set the highest value but instead calculate the value based on the maximum sized transfer.

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host *host) · line 2886

Quoted 7 lines
drivers/mmc/host/sdhci.c +7 -0
+
+static void sdhci_cmdq_dump_vendor_regs(struct mmc_host *mmc)
+{
+	struct sdhci_host *host = mmc_priv(mmc);
+
+	sdhci_dumpregs(host);
+}

Instead you should export sdhci_dumpregs() and let the individual drivers connect it to CQHCI.

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host *host) · line 2892

Quoted 6 lines
drivers/mmc/host/sdhci.c +6 -0
+
+static int sdhci_cmdq_init(struct sdhci_host *host, struct mmc_host *mmc,
+			   bool dma64)
+{
+	return cmdq_init(host->cq_host, mmc, dma64);
+}

Individual drivers should initialize their CQE driver implementation. It is not necessarily CQHCI.

Quoted 14 lines
Quoted 4 lines
drivers/mmc/host/sdhci.c +4 -0
+
+static void sdhci_cmdq_set_block_size(struct mmc_host *mmc)
+{
+	struct sdhci_host *host = mmc_priv(mmc);

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host *host) · line 2906

Quoted 10 lines
drivers/mmc/host/sdhci.c +10 -0
+
+	sdhci_set_blk_size_reg(host, 512, 0);
+}
+
+static void sdhci_cmdq_clear_set_dumpregs(struct mmc_host *mmc, bool set)
+{
+	struct sdhci_host *host = mmc_priv(mmc);
+
+	if (host->ops->clear_set_dumpregs)
+		host->ops->clear_set_dumpregs(host, set);

This is vendor specific callback for platform drivers to enable/disable (say some TEST bus) registers for debugging purposes.

Quoted 133 lines

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host *host) · line 2907

Quoted 1 line
drivers/mmc/host/sdhci.c +1 -0
+}

As questioned further below, what is this for?

Quoted 31 lines
drivers/mmc/host/sdhci.c +31 -0
+#else
+static void sdhci_cmdq_clear_set_irqs(struct mmc_host *mmc, bool clear)
+{
+
+}
+
+static void sdhci_cmdq_set_data_timeout(struct mmc_host *mmc, u32 val)
+{
+
+}
+
+static void sdhci_cmdq_dump_vendor_regs(struct mmc_host *mmc)
+{
+
+}
+
+static int sdhci_cmdq_init(struct sdhci_host *host, struct mmc_host *mmc,
+			   bool dma64)
+{
+	return -ENOSYS;
+}
+
+static void sdhci_cmdq_set_block_size(struct mmc_host *mmc)
+{
+
+}
+
+static void sdhci_cmdq_clear_set_dumpregs(struct mmc_host *mmc, bool set)
+{
+
+}

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host *host) · line 2948

Quoted 10 lines
drivers/mmc/host/sdhci.c +10 -0
+
+#endif
+
+static const struct cmdq_host_ops sdhci_cmdq_ops = {
+	.clear_set_irqs = sdhci_cmdq_clear_set_irqs,
+	.set_data_timeout = sdhci_cmdq_set_data_timeout,
+	.dump_vendor_regs = sdhci_cmdq_dump_vendor_regs,
+	.set_block_size = sdhci_cmdq_set_block_size,
+	.clear_set_dumpregs = sdhci_cmdq_clear_set_dumpregs,
+};

It would be up to individual drivers to provide CQHCI ops.

Quoted 5 lines
drivers/mmc/host/sdhci.c +1 -0
+
 int sdhci_add_host(struct sdhci_host *host)
 {
 	struct mmc_host *mmc;

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host *host) · line 3471

Quoted 9 lines
drivers/mmc/host/sdhci.c +4 -2
@@ -3341,11 +3465,25 @@ int sdhci_add_host(struct sdhci_host *host)
 	if (ret)
 		goto unled;
 
-	pr_info("%s: SDHCI controller on %s [%s] using %s\n",
-		mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)),
+	if (mmc->caps2 &  MMC_CAP2_CMD_QUEUE) {
+		bool dma64 = (host->flags & SDHCI_USE_ADMA_64BIT) ?
+			true : false;
+		ret = sdhci_cmdq_init(host, mmc, dma64);

You must initialize before mmc_add_host() because mmc_add_host() also starts the host. If you re-base on top of the SDHCI patches, then individual drivers can take advantage of the new sdhci_setup_host() / __sdhci_add_host() split.

Quoted 7 lines
drivers/mmc/host/sdhci.c +7 -0
+		if (ret)
+			pr_err("%s: CMDQ init: failed (%d)\n",
+			       mmc_hostname(host->mmc), ret);
+		else
+			host->cq_host->ops = &sdhci_cmdq_ops;
+	}
+

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host *host) · line 3486

Quoted 10 lines
drivers/mmc/host/sdhci.c +7 -2
+	pr_info("%s: SDHCI controller on %s [%s] using %s in %s mode\n",
+	mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)),
 		(host->flags & SDHCI_USE_ADMA) ?
-		(host->flags & SDHCI_USE_64_BIT_DMA) ? "ADMA 64-bit" : "ADMA" :
-		(host->flags & SDHCI_USE_SDMA) ? "DMA" : "PIO");
+		((host->flags & SDHCI_USE_ADMA_64BIT) ?
+		"64-bit ADMA" : "32-bit ADMA") :
+		((host->flags & SDHCI_USE_SDMA) ? "DMA" : "PIO"),
+		((mmc->caps2 &  MMC_CAP2_CMD_QUEUE) && !ret) ?
+		"CMDQ" : "legacy");

It is probably better if CQHCI prints its own info. That way it you get a consistent message irrespective of whether the driver uses SDHCI. Also you can print other CQHCI details such as the version.

drivers/mmc/host/sdhci.h line 154

Quoted 13 lines
drivers/mmc/host/sdhci.c +0 -0
 	sdhci_enable_card_detection(host);
 
drivers/mmc/host/sdhci.h +2 -0
index 609f87c..fccc750 100644
@@ -150,6 +150,8 @@
 		SDHCI_INT_DATA_TIMEOUT | SDHCI_INT_DATA_CRC | \
 		SDHCI_INT_DATA_END_BIT | SDHCI_INT_ADMA_ERROR | \
 		SDHCI_INT_BLK_GAP)
+
+#define SDHCI_INT_CMDQ_EN	(0x1 << 14)

We can define this bit for convenience but we need a comment to say that it is non-standard.

drivers/mmc/host/sdhci.h struct sdhci_host { · line 451

Quoted 8 lines
drivers/mmc/host/sdhci.h +1 -0
 #define SDHCI_INT_ALL_MASK	((unsigned int)-1)
 
 #define SDHCI_ACMD12_ERR	0x3C
@@ -446,6 +448,7 @@ struct sdhci_host {
 #define SDHCI_PV_ENABLED	(1<<8)	/* Preset value enabled */
 #define SDHCI_SDIO_IRQ_ENABLED	(1<<9)	/* SDIO irq enabled */
 #define SDHCI_USE_64_BIT_DMA	(1<<12)	/* Use 64-bit DMA */
+#define SDHCI_USE_ADMA_64BIT	(1<<12)	/* Host is 64-bit ADMA capable */

SDHCI_USE_ADMA_64BIT looks redundant.

drivers/mmc/host/sdhci.h struct sdhci_host { · line 516

Quoted 9 lines
drivers/mmc/host/sdhci.h +2 -0
 #define SDHCI_HS400_TUNING	(1<<13)	/* Tuning for HS400 */
 
 	unsigned int version;	/* SDHCI spec. version */
@@ -509,6 +512,8 @@ struct sdhci_host {
 	unsigned int		tuning_mode;	/* Re-tuning mode supported by host */
 #define SDHCI_TUNING_MODE_1	0
 
+	struct cmdq_host *cq_host;
+

The individual drivers will have to have their own reference to CQHCI.

Quoted 3 lines
drivers/mmc/host/sdhci.h +0 -0
 	unsigned long private[0] ____cacheline_aligned;
 };
 
Quoted 7 lines

drivers/mmc/host/sdhci.h struct sdhci_ops { · line 552

Quoted 5 lines
drivers/mmc/host/sdhci.h +1 -0
@@ -544,6 +549,7 @@ struct sdhci_ops {
 	void    (*adma_workaround)(struct sdhci_host *host, u32 intmask);
 	void	(*platform_init)(struct sdhci_host *host);
 	void    (*card_event)(struct sdhci_host *host);
+	void	(*clear_set_dumpregs)(struct sdhci_host *host, bool set);

What is this for?

This is vendor specific callback to enable/disable some TEST bus registers for debugging purposes.

Quoted 11 lines

drivers/mmc/host/sdhci.h struct sdhci_ops { · line 555

Quoted 5 lines
drivers/mmc/host/sdhci.h +0 -0
 	void	(*voltage_switch)(struct sdhci_host *host);
 	int	(*select_drive_strength)(struct sdhci_host *host,
 					 struct mmc_card *card,

--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#22 lore raw

Re: [PATCH RFCv2 10/10] mmc: sdhci: add command queue support to sdhci

Quoted 2 lines · Ritesh Harjani

Sorry about this long delay, was pulled into some release. Will be more responsive from now.

Well, I was away, so now it is my delay, sorry.

Quoted 6 lines

We have gone through your comments. We had some queries and wanted to discuss more about your initial comments before going onto individual comments in the code. It would be great if you could help us understand more on your initial comments by answering to our queries.

Quoted 8 lines
Quoted 6 lines · Adrian Hunter
Quoted 3 lines · Ritesh Harjani

From: Asutosh Das <[email protected]>

Adds command-queue support to SDHCi compliant drivers.

CQHCI is not recognized in the SDHCI specification,

Yes. Not sure about future plan though.

SD Association and JEDEC are different bodies and I have never seen a SD Association Spec. that mentions eMMC, so I would not expect the SDHCI spec. ever to recognize CQHCI.

Quoted 7 lines
Quoted 4 lines

and SDHCI should
facilitate any CQE driver implementation not just CQHCI. That means there are 2 options:

Are we aware of any other vendor specific implementation of CQHCI? Or do you foresee this coming through?

No

Quoted 22 lines

Actually CQ host controller interface(CQHCI) is what is proposed in emmc JEDEC5.1 which is mentioned as extension to HCI in block diagram. (Fig B.110 in emmc-5.1 JEDEC).

Quoted 12 lines

1. Provide minimal support to allow individual host drivers to deal with CQHCI directly.

2. Create explicit support for a CQE companion driver and use that to provide common support for CQHCI.

I started looking at option 2 and concluded that it was taking SDHCI in the wrong direction because it made drivers more dependent on SDHCI and gave them less flexibility, and it seemed inconsistent with the aim of making SDHCI more like a library.

Quoted 4 lines

Consequently, I suggest the following:

1. Individual drivers are responsible for initializing and setting up CQHCI and its callbacks, and shutting it down.

Quoted 8 lines

CQHCI callbacks is what the concern is. Currently the callbacks are placed in SDHCI, because these callbacks are doing nothing other than setting up SDHCI registers itself for CQHCI. There is nothing platform specific which is happening in these.
So why do you think that these should be implemented in individual platform specific drivers?
Will that not result into same code duplication in all SDHCI compliant platform drivers?

Common functions that do not need CQHCI definitions can still be in sdhci.c. Some amount of code duplication is the cost of allowing drivers to be able to do whatever the need to.

Linking CQHCI and SDHCI goes in the opposite direction of making SDHCI more like a library. It means more callbacks and more potential issues if drivers need to do anything differently.

Quoted 8 lines
Quoted 5 lines

2. SDHCI provides a new callback so that individual drivers can process interrupts and pass them to CQHCI.

This again will depend upon the initial ask on - do you foresee SDHCI facilitating other CQE implementations? Or if you are already aware of something else other than CQHCI?

No I don't know if there will ever be another implementation, however it is not impossible. Obviously it would be much messier for SDHCI to support different CQE implementations than for individual drivers to support just the one they use.

Quoted 352 lines
Quoted 173 lines

3. SDHCI provides and exports any common helper functions that do not depend directly on CQHCI. For example the functions to set interrupts, timeout, blocks size and dump registers.

Quoted 20 lines

[[email protected]: fixed trivial merge conflicts and compilation error]

---
 drivers/mmc/host/sdhci.c | 146
+++++++++++++++++++++++++++++++++++++++++++++--
 drivers/mmc/host/sdhci.h |   6 ++
 2 files changed, 148 insertions(+), 4 deletions(-)
drivers/mmc/host/sdhci.c +0 -0
index 9f5cdaa..0ed9c45 100644

drivers/mmc/host/sdhci.c line 35

Quoted 4 lines
drivers/mmc/host/sdhci.c +1 -0
@@ -32,6 +32,7 @@
 #include <linux/mmc/slot-gpio.h>
 
 #include "sdhci.h"
+#include "cmdq_hci.h"

As discussed above, SDHCI should not have any references to CQHCI

drivers/mmc/host/sdhci.c static void sdhci_data_irq(struct sdhci_host · line 2479

Quoted 9 lines
drivers/mmc/host/sdhci.c +1 -0
 #define DRIVER_NAME "sdhci"
 
@@ -2474,6 +2475,20 @@ static void sdhci_data_irq(struct sdhci_host
 *host, u32 intmask)
     }
 }
 
+#ifdef CONFIG_MMC_CQ_HCI

This won't work if CQHCI is a module. If you fix the dependencies then you can use:

#if IS_ENABLED(CONFIG_MMC_CQ_HCI)

Or if you select CONFIG_MMC_CQ_HCI in Kconfig then you don't need ifdef at all.

drivers/mmc/host/sdhci.c static void sdhci_data_irq(struct sdhci_host *host, u32 intmask) · line 2481

Quoted 3 lines
drivers/mmc/host/sdhci.c +3 -0
+static irqreturn_t sdhci_cmdq_irq(struct mmc_host *mmc, u32 intmask)
+{
+    return cmdq_irq(mmc, intmask);

This will give a linker error if the driver is built-in but CQHCI is a module. Probably drivers that use CQHCI should just select it in Kconfig.

Another issue is that CQHCI won't be able to interpret SDHCI interrupt bits.
I suggest you define a generic set of bit flags not dependent on SDHCI or
CQHCI and then we can create a function to convert the SDHCI interrupt status.

Quoted 16 lines
drivers/mmc/host/sdhci.c +10 -0
+}
+
+#else
+static irqreturn_t sdhci_cmdq_irq(struct mmc_host *mmc, u32 intmask)
+{
+    pr_err("%s: rxd cmdq-irq when disabled !!!!\n", mmc_hostname(mmc));
+    return IRQ_NONE;
+}
+#endif
+
 static irqreturn_t sdhci_irq(int irq, void *dev_id)
 {
     irqreturn_t result = IRQ_NONE;
drivers/mmc/host/sdhci.c +0 -0
@@ -2495,6 +2510,15 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
     }
 

drivers/mmc/host/sdhci.c static irqreturn_t sdhci_irq(int irq, void *dev_id) · line 2521

Quoted 10 lines
drivers/mmc/host/sdhci.c +9 -0
     do {
+        if (host->mmc->card && mmc_card_cmdq(host->mmc->card) &&
+            !mmc_host_halt(host->mmc)) {
+            pr_debug("*** %s: cmdq intr: 0x%08x\n",
+                    mmc_hostname(host->mmc),
+                    intmask);
+            result = sdhci_cmdq_irq(host->mmc, intmask);
+            goto out;
+        }
+

We need to create a new SDHCI host op to enable individual drivers to handle the IRQ if they choose. Then it is up to individual drivers to call into CQHCI.

Quoted 8 lines
drivers/mmc/host/sdhci.c +0 -0
         /* Clear selected interrupts. */
         mask = intmask & (SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK |
                   SDHCI_INT_BUS_POWER);
@@ -2823,6 +2847,106 @@ static int sdhci_set_dma_mask(struct sdhci_host
 *host)
     return ret;
 }
 

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host · line 2860

Quoted 10 lines
drivers/mmc/host/sdhci.c +10 -0
+#ifdef CONFIG_MMC_CQ_HCI
+static void sdhci_cmdq_clear_set_irqs(struct mmc_host *mmc, bool clear)
+{
+    struct sdhci_host *host = mmc_priv(mmc);
+    u32 ier = 0;
+
+    ier &= ~SDHCI_INT_ALL_MASK;
+
+    if (clear) {
+        ier = SDHCI_INT_CMDQ_EN | SDHCI_INT_ERROR_MASK;

SDHCI_INT_ERROR_MASK is not ideal here. I would expect to set only the bits we know and want.

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host *host) · line 2868

Quoted 9 lines
drivers/mmc/host/sdhci.c +9 -0
+        sdhci_writel(host, ier, SDHCI_INT_ENABLE);
+        sdhci_writel(host, ier, SDHCI_SIGNAL_ENABLE);
+    } else {
+        ier = SDHCI_INT_BUS_POWER | SDHCI_INT_DATA_END_BIT |
+                 SDHCI_INT_DATA_CRC | SDHCI_INT_DATA_TIMEOUT |
+                 SDHCI_INT_INDEX | SDHCI_INT_END_BIT |
+                 SDHCI_INT_CRC | SDHCI_INT_TIMEOUT |
+                 SDHCI_INT_DATA_END | SDHCI_INT_RESPONSE |
+                 SDHCI_INT_ACMD12ERR;

We ought to have the default interrupts defined, so that the same ones are set here.

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host *host) · line 2874

Quoted 6 lines
drivers/mmc/host/sdhci.c +6 -0
+        sdhci_writel(host, ier, SDHCI_INT_ENABLE);
+        sdhci_writel(host, ier, SDHCI_SIGNAL_ENABLE);
+    }
+}
+
+static void sdhci_cmdq_set_data_timeout(struct mmc_host *mmc, u32 val)

Do we really need different callbacks for ->clear_set_irqs(), ->set_data_timeout(), ->set_block_size() and ->clear_set_dumpregs()? It looks like we could consolidate them all into just 2 i.e. to start and stop CQ mode.

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host *host) · line 2879

Quoted 5 lines
drivers/mmc/host/sdhci.c +5 -0
+{
+    struct sdhci_host *host = mmc_priv(mmc);
+
+    sdhci_writeb(host, val, SDHCI_TIMEOUT_CONTROL);
+}

We can't expect CQHCI to provide the SDHCI register value. Ideally we don't want to set the highest value but instead calculate the value based on the maximum sized transfer.

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host *host) · line 2886

Quoted 7 lines
drivers/mmc/host/sdhci.c +7 -0
+
+static void sdhci_cmdq_dump_vendor_regs(struct mmc_host *mmc)
+{
+    struct sdhci_host *host = mmc_priv(mmc);
+
+    sdhci_dumpregs(host);
+}

Instead you should export sdhci_dumpregs() and let the individual drivers connect it to CQHCI.

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host *host) · line 2892

Quoted 6 lines
drivers/mmc/host/sdhci.c +6 -0
+
+static int sdhci_cmdq_init(struct sdhci_host *host, struct mmc_host *mmc,
+               bool dma64)
+{
+    return cmdq_init(host->cq_host, mmc, dma64);
+}

Individual drivers should initialize their CQE driver implementation. It is not necessarily CQHCI.

Quoted 14 lines
Quoted 4 lines
drivers/mmc/host/sdhci.c +4 -0
+
+static void sdhci_cmdq_set_block_size(struct mmc_host *mmc)
+{
+    struct sdhci_host *host = mmc_priv(mmc);

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host *host) · line 2906

Quoted 10 lines
drivers/mmc/host/sdhci.c +10 -0
+
+    sdhci_set_blk_size_reg(host, 512, 0);
+}
+
+static void sdhci_cmdq_clear_set_dumpregs(struct mmc_host *mmc, bool set)
+{
+    struct sdhci_host *host = mmc_priv(mmc);
+
+    if (host->ops->clear_set_dumpregs)
+        host->ops->clear_set_dumpregs(host, set);

This is vendor specific callback for platform drivers to enable/disable (say some TEST bus) registers for debugging purposes.

Quoted 135 lines

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host · line 2908

Quoted 1 line
drivers/mmc/host/sdhci.c +1 -0
+}

As questioned further below, what is this for?

Quoted 31 lines
drivers/mmc/host/sdhci.c +31 -0
+#else
+static void sdhci_cmdq_clear_set_irqs(struct mmc_host *mmc, bool clear)
+{
+
+}
+
+static void sdhci_cmdq_set_data_timeout(struct mmc_host *mmc, u32 val)
+{
+
+}
+
+static void sdhci_cmdq_dump_vendor_regs(struct mmc_host *mmc)
+{
+
+}
+
+static int sdhci_cmdq_init(struct sdhci_host *host, struct mmc_host *mmc,
+               bool dma64)
+{
+    return -ENOSYS;
+}
+
+static void sdhci_cmdq_set_block_size(struct mmc_host *mmc)
+{
+
+}
+
+static void sdhci_cmdq_clear_set_dumpregs(struct mmc_host *mmc, bool set)
+{
+
+}

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host *host) · line 2948

Quoted 10 lines
drivers/mmc/host/sdhci.c +10 -0
+
+#endif
+
+static const struct cmdq_host_ops sdhci_cmdq_ops = {
+    .clear_set_irqs = sdhci_cmdq_clear_set_irqs,
+    .set_data_timeout = sdhci_cmdq_set_data_timeout,
+    .dump_vendor_regs = sdhci_cmdq_dump_vendor_regs,
+    .set_block_size = sdhci_cmdq_set_block_size,
+    .clear_set_dumpregs = sdhci_cmdq_clear_set_dumpregs,
+};

It would be up to individual drivers to provide CQHCI ops.

Quoted 5 lines
drivers/mmc/host/sdhci.c +1 -0
+
 int sdhci_add_host(struct sdhci_host *host)
 {
     struct mmc_host *mmc;

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host *host) · line 3471

Quoted 9 lines
drivers/mmc/host/sdhci.c +4 -2
@@ -3341,11 +3465,25 @@ int sdhci_add_host(struct sdhci_host *host)
     if (ret)
         goto unled;
 
-    pr_info("%s: SDHCI controller on %s [%s] using %s\n",
-        mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)),
+    if (mmc->caps2 &  MMC_CAP2_CMD_QUEUE) {
+        bool dma64 = (host->flags & SDHCI_USE_ADMA_64BIT) ?
+            true : false;
+        ret = sdhci_cmdq_init(host, mmc, dma64);

You must initialize before mmc_add_host() because mmc_add_host() also starts the host. If you re-base on top of the SDHCI patches, then individual drivers can take advantage of the new sdhci_setup_host() / __sdhci_add_host() split.

Quoted 7 lines
drivers/mmc/host/sdhci.c +7 -0
+        if (ret)
+            pr_err("%s: CMDQ init: failed (%d)\n",
+                   mmc_hostname(host->mmc), ret);
+        else
+            host->cq_host->ops = &sdhci_cmdq_ops;
+    }
+

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host *host) · line 3486

Quoted 10 lines
drivers/mmc/host/sdhci.c +7 -2
+    pr_info("%s: SDHCI controller on %s [%s] using %s in %s mode\n",
+    mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)),
         (host->flags & SDHCI_USE_ADMA) ?
-        (host->flags & SDHCI_USE_64_BIT_DMA) ? "ADMA 64-bit" : "ADMA" :
-        (host->flags & SDHCI_USE_SDMA) ? "DMA" : "PIO");
+        ((host->flags & SDHCI_USE_ADMA_64BIT) ?
+        "64-bit ADMA" : "32-bit ADMA") :
+        ((host->flags & SDHCI_USE_SDMA) ? "DMA" : "PIO"),
+        ((mmc->caps2 &  MMC_CAP2_CMD_QUEUE) && !ret) ?
+        "CMDQ" : "legacy");

It is probably better if CQHCI prints its own info. That way it you get a consistent message irrespective of whether the driver uses SDHCI. Also you can print other CQHCI details such as the version.

drivers/mmc/host/sdhci.h line 154

Quoted 13 lines
drivers/mmc/host/sdhci.c +0 -0
     sdhci_enable_card_detection(host);
 
drivers/mmc/host/sdhci.h +2 -0
index 609f87c..fccc750 100644
@@ -150,6 +150,8 @@
         SDHCI_INT_DATA_TIMEOUT | SDHCI_INT_DATA_CRC | \
         SDHCI_INT_DATA_END_BIT | SDHCI_INT_ADMA_ERROR | \
         SDHCI_INT_BLK_GAP)
+
+#define SDHCI_INT_CMDQ_EN    (0x1 << 14)

We can define this bit for convenience but we need a comment to say that it is non-standard.

Quoted 9 lines
drivers/mmc/host/sdhci.h +1 -0
 #define SDHCI_INT_ALL_MASK    ((unsigned int)-1)
 
 #define SDHCI_ACMD12_ERR    0x3C
@@ -446,6 +448,7 @@ struct sdhci_host {
 #define SDHCI_PV_ENABLED    (1<<8)    /* Preset value enabled */
 #define SDHCI_SDIO_IRQ_ENABLED    (1<<9)    /* SDIO irq enabled */
 #define SDHCI_USE_64_BIT_DMA    (1<<12)    /* Use 64-bit DMA */
+#define SDHCI_USE_ADMA_64BIT    (1<<12)    /* Host is 64-bit ADMA

capable */

SDHCI_USE_ADMA_64BIT looks redundant.

drivers/mmc/host/sdhci.h struct sdhci_host { · line 516

Quoted 10 lines

#define SDHCI_HS400_TUNING (1<<13) /* Tuning for HS400 */

unsigned int version; /* SDHCI spec. version */

drivers/mmc/host/sdhci.h +0 -0
@@ -509,6 +512,8 @@ struct sdhci_host {
     unsigned int        tuning_mode;    /* Re-tuning mode supported by

host */
#define SDHCI_TUNING_MODE_1 0

drivers/mmc/host/sdhci.h +2 -0
+    struct cmdq_host *cq_host;
+

The individual drivers will have to have their own reference to CQHCI.

Quoted 3 lines
     unsigned long private[0] ____cacheline_aligned;

};

Quoted 7 lines

drivers/mmc/host/sdhci.h struct sdhci_ops { · line 552

Quoted 5 lines
drivers/mmc/host/sdhci.h +1 -0
@@ -544,6 +549,7 @@ struct sdhci_ops {
     void    (*adma_workaround)(struct sdhci_host *host, u32 intmask);
     void    (*platform_init)(struct sdhci_host *host);
     void    (*card_event)(struct sdhci_host *host);
+    void    (*clear_set_dumpregs)(struct sdhci_host *host, bool set);

What is this for?

This is vendor specific callback to enable/disable some TEST bus registers for debugging purposes.

Quoted 11 lines
Quoted 5 lines
drivers/mmc/host/sdhci.h +0 -0
     void    (*voltage_switch)(struct sdhci_host *host);
     int    (*select_drive_strength)(struct sdhci_host *host,
                      struct mmc_card *card,
Signature · 3 lines
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#23 lore raw

Re: [PATCH RFCv2 10/10] mmc: sdhci: add command queue support to sdhci

Hi Adrian,

Thanks for replying to queries.
I will work on your comments. Mostly after
http://www.spinics.net/lists/linux-mmc/msg38467.html

Regards
Ritesh

Quoted 446 lines · Adrian Hunter
Quoted 2 lines · Ritesh Harjani

Sorry about this long delay, was pulled into some release. Will be more responsive from now.

Well, I was away, so now it is my delay, sorry.

Quoted 6 lines

We have gone through your comments. We had some queries and wanted to discuss more about your initial comments before going onto individual comments in the code. It would be great if you could help us understand more on your initial comments by answering to our queries.

Quoted 8 lines
Quoted 6 lines · Adrian Hunter
Quoted 3 lines · Ritesh Harjani

From: Asutosh Das <[email protected]>

Adds command-queue support to SDHCi compliant drivers.

CQHCI is not recognized in the SDHCI specification,

Yes. Not sure about future plan though.

SD Association and JEDEC are different bodies and I have never seen a SD Association Spec. that mentions eMMC, so I would not expect the SDHCI spec. ever to recognize CQHCI.

Quoted 7 lines
Quoted 4 lines

and SDHCI should
facilitate any CQE driver implementation not just CQHCI. That means there are 2 options:

Are we aware of any other vendor specific implementation of CQHCI? Or do you foresee this coming through?

No

Quoted 22 lines

Actually CQ host controller interface(CQHCI) is what is proposed in emmc JEDEC5.1 which is mentioned as extension to HCI in block diagram. (Fig B.110 in emmc-5.1 JEDEC).

Quoted 12 lines

1. Provide minimal support to allow individual host drivers to deal with CQHCI directly.

2. Create explicit support for a CQE companion driver and use that to provide common support for CQHCI.

I started looking at option 2 and concluded that it was taking SDHCI in the wrong direction because it made drivers more dependent on SDHCI and gave them less flexibility, and it seemed inconsistent with the aim of making SDHCI more like a library.

Quoted 4 lines

Consequently, I suggest the following:

1. Individual drivers are responsible for initializing and setting up CQHCI and its callbacks, and shutting it down.

Quoted 8 lines

CQHCI callbacks is what the concern is. Currently the callbacks are placed in SDHCI, because these callbacks are doing nothing other than setting up SDHCI registers itself for CQHCI. There is nothing platform specific which is happening in these.
So why do you think that these should be implemented in individual platform specific drivers?
Will that not result into same code duplication in all SDHCI compliant platform drivers?

Common functions that do not need CQHCI definitions can still be in sdhci.c. Some amount of code duplication is the cost of allowing drivers to be able to do whatever the need to.

Linking CQHCI and SDHCI goes in the opposite direction of making SDHCI more like a library. It means more callbacks and more potential issues if drivers need to do anything differently.

Quoted 8 lines
Quoted 5 lines

2. SDHCI provides a new callback so that individual drivers can process interrupts and pass them to CQHCI.

This again will depend upon the initial ask on - do you foresee SDHCI facilitating other CQE implementations? Or if you are already aware of something else other than CQHCI?

No I don't know if there will ever be another implementation, however it is not impossible. Obviously it would be much messier for SDHCI to support different CQE implementations than for individual drivers to support just the one they use.

Quoted 334 lines
Quoted 173 lines

3. SDHCI provides and exports any common helper functions that do not depend directly on CQHCI. For example the functions to set interrupts, timeout, blocks size and dump registers.

Quoted 20 lines

[[email protected]: fixed trivial merge conflicts and compilation error]

---
 drivers/mmc/host/sdhci.c | 146
+++++++++++++++++++++++++++++++++++++++++++++--
 drivers/mmc/host/sdhci.h |   6 ++
 2 files changed, 148 insertions(+), 4 deletions(-)
drivers/mmc/host/sdhci.c +0 -0
index 9f5cdaa..0ed9c45 100644

drivers/mmc/host/sdhci.c line 35

Quoted 4 lines
drivers/mmc/host/sdhci.c +1 -0
@@ -32,6 +32,7 @@
 #include <linux/mmc/slot-gpio.h>
 
 #include "sdhci.h"
+#include "cmdq_hci.h"

As discussed above, SDHCI should not have any references to CQHCI

drivers/mmc/host/sdhci.c static void sdhci_data_irq(struct sdhci_host · line 2479

Quoted 9 lines
drivers/mmc/host/sdhci.c +1 -0
 #define DRIVER_NAME "sdhci"
 
@@ -2474,6 +2475,20 @@ static void sdhci_data_irq(struct sdhci_host
 *host, u32 intmask)
     }
 }
 
+#ifdef CONFIG_MMC_CQ_HCI

This won't work if CQHCI is a module. If you fix the dependencies then you can use:

#if IS_ENABLED(CONFIG_MMC_CQ_HCI)

Or if you select CONFIG_MMC_CQ_HCI in Kconfig then you don't need ifdef at all.

drivers/mmc/host/sdhci.c static void sdhci_data_irq(struct sdhci_host *host, u32 intmask) · line 2481

Quoted 3 lines
drivers/mmc/host/sdhci.c +3 -0
+static irqreturn_t sdhci_cmdq_irq(struct mmc_host *mmc, u32 intmask)
+{
+    return cmdq_irq(mmc, intmask);

This will give a linker error if the driver is built-in but CQHCI is a module. Probably drivers that use CQHCI should just select it in Kconfig.

Another issue is that CQHCI won't be able to interpret SDHCI interrupt bits.
I suggest you define a generic set of bit flags not dependent on SDHCI or
CQHCI and then we can create a function to convert the SDHCI interrupt status.

Quoted 16 lines
drivers/mmc/host/sdhci.c +10 -0
+}
+
+#else
+static irqreturn_t sdhci_cmdq_irq(struct mmc_host *mmc, u32 intmask)
+{
+    pr_err("%s: rxd cmdq-irq when disabled !!!!\n", mmc_hostname(mmc));
+    return IRQ_NONE;
+}
+#endif
+
 static irqreturn_t sdhci_irq(int irq, void *dev_id)
 {
     irqreturn_t result = IRQ_NONE;
drivers/mmc/host/sdhci.c +0 -0
@@ -2495,6 +2510,15 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
     }
 

drivers/mmc/host/sdhci.c static irqreturn_t sdhci_irq(int irq, void *dev_id) · line 2521

Quoted 10 lines
drivers/mmc/host/sdhci.c +9 -0
     do {
+        if (host->mmc->card && mmc_card_cmdq(host->mmc->card) &&
+            !mmc_host_halt(host->mmc)) {
+            pr_debug("*** %s: cmdq intr: 0x%08x\n",
+                    mmc_hostname(host->mmc),
+                    intmask);
+            result = sdhci_cmdq_irq(host->mmc, intmask);
+            goto out;
+        }
+

We need to create a new SDHCI host op to enable individual drivers to handle the IRQ if they choose. Then it is up to individual drivers to call into CQHCI.

Quoted 8 lines
drivers/mmc/host/sdhci.c +0 -0
         /* Clear selected interrupts. */
         mask = intmask & (SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK |
                   SDHCI_INT_BUS_POWER);
@@ -2823,6 +2847,106 @@ static int sdhci_set_dma_mask(struct sdhci_host
 *host)
     return ret;
 }
 

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host · line 2860

Quoted 10 lines
drivers/mmc/host/sdhci.c +10 -0
+#ifdef CONFIG_MMC_CQ_HCI
+static void sdhci_cmdq_clear_set_irqs(struct mmc_host *mmc, bool clear)
+{
+    struct sdhci_host *host = mmc_priv(mmc);
+    u32 ier = 0;
+
+    ier &= ~SDHCI_INT_ALL_MASK;
+
+    if (clear) {
+        ier = SDHCI_INT_CMDQ_EN | SDHCI_INT_ERROR_MASK;

SDHCI_INT_ERROR_MASK is not ideal here. I would expect to set only the bits we know and want.

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host *host) · line 2868

Quoted 9 lines
drivers/mmc/host/sdhci.c +9 -0
+        sdhci_writel(host, ier, SDHCI_INT_ENABLE);
+        sdhci_writel(host, ier, SDHCI_SIGNAL_ENABLE);
+    } else {
+        ier = SDHCI_INT_BUS_POWER | SDHCI_INT_DATA_END_BIT |
+                 SDHCI_INT_DATA_CRC | SDHCI_INT_DATA_TIMEOUT |
+                 SDHCI_INT_INDEX | SDHCI_INT_END_BIT |
+                 SDHCI_INT_CRC | SDHCI_INT_TIMEOUT |
+                 SDHCI_INT_DATA_END | SDHCI_INT_RESPONSE |
+                 SDHCI_INT_ACMD12ERR;

We ought to have the default interrupts defined, so that the same ones are set here.

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host *host) · line 2874

Quoted 6 lines
drivers/mmc/host/sdhci.c +6 -0
+        sdhci_writel(host, ier, SDHCI_INT_ENABLE);
+        sdhci_writel(host, ier, SDHCI_SIGNAL_ENABLE);
+    }
+}
+
+static void sdhci_cmdq_set_data_timeout(struct mmc_host *mmc, u32 val)

Do we really need different callbacks for ->clear_set_irqs(), ->set_data_timeout(), ->set_block_size() and ->clear_set_dumpregs()? It looks like we could consolidate them all into just 2 i.e. to start and stop CQ mode.

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host *host) · line 2879

Quoted 5 lines
drivers/mmc/host/sdhci.c +5 -0
+{
+    struct sdhci_host *host = mmc_priv(mmc);
+
+    sdhci_writeb(host, val, SDHCI_TIMEOUT_CONTROL);
+}

We can't expect CQHCI to provide the SDHCI register value. Ideally we don't want to set the highest value but instead calculate the value based on the maximum sized transfer.

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host *host) · line 2886

Quoted 7 lines
drivers/mmc/host/sdhci.c +7 -0
+
+static void sdhci_cmdq_dump_vendor_regs(struct mmc_host *mmc)
+{
+    struct sdhci_host *host = mmc_priv(mmc);
+
+    sdhci_dumpregs(host);
+}

Instead you should export sdhci_dumpregs() and let the individual drivers connect it to CQHCI.

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host *host) · line 2892

Quoted 6 lines
drivers/mmc/host/sdhci.c +6 -0
+
+static int sdhci_cmdq_init(struct sdhci_host *host, struct mmc_host *mmc,
+               bool dma64)
+{
+    return cmdq_init(host->cq_host, mmc, dma64);
+}

Individual drivers should initialize their CQE driver implementation. It is not necessarily CQHCI.

Quoted 14 lines
Quoted 4 lines
drivers/mmc/host/sdhci.c +4 -0
+
+static void sdhci_cmdq_set_block_size(struct mmc_host *mmc)
+{
+    struct sdhci_host *host = mmc_priv(mmc);

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host *host) · line 2906

Quoted 10 lines
drivers/mmc/host/sdhci.c +10 -0
+
+    sdhci_set_blk_size_reg(host, 512, 0);
+}
+
+static void sdhci_cmdq_clear_set_dumpregs(struct mmc_host *mmc, bool set)
+{
+    struct sdhci_host *host = mmc_priv(mmc);
+
+    if (host->ops->clear_set_dumpregs)
+        host->ops->clear_set_dumpregs(host, set);

This is vendor specific callback for platform drivers to enable/disable (say some TEST bus) registers for debugging purposes.

Quoted 135 lines

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host · line 2908

Quoted 1 line
drivers/mmc/host/sdhci.c +1 -0
+}

As questioned further below, what is this for?

Quoted 31 lines
drivers/mmc/host/sdhci.c +31 -0
+#else
+static void sdhci_cmdq_clear_set_irqs(struct mmc_host *mmc, bool clear)
+{
+
+}
+
+static void sdhci_cmdq_set_data_timeout(struct mmc_host *mmc, u32 val)
+{
+
+}
+
+static void sdhci_cmdq_dump_vendor_regs(struct mmc_host *mmc)
+{
+
+}
+
+static int sdhci_cmdq_init(struct sdhci_host *host, struct mmc_host *mmc,
+               bool dma64)
+{
+    return -ENOSYS;
+}
+
+static void sdhci_cmdq_set_block_size(struct mmc_host *mmc)
+{
+
+}
+
+static void sdhci_cmdq_clear_set_dumpregs(struct mmc_host *mmc, bool set)
+{
+
+}

drivers/mmc/host/sdhci.c static int sdhci_set_dma_mask(struct sdhci_host *host) · line 2948

Quoted 10 lines
drivers/mmc/host/sdhci.c +10 -0
+
+#endif
+
+static const struct cmdq_host_ops sdhci_cmdq_ops = {
+    .clear_set_irqs = sdhci_cmdq_clear_set_irqs,
+    .set_data_timeout = sdhci_cmdq_set_data_timeout,
+    .dump_vendor_regs = sdhci_cmdq_dump_vendor_regs,
+    .set_block_size = sdhci_cmdq_set_block_size,
+    .clear_set_dumpregs = sdhci_cmdq_clear_set_dumpregs,
+};

It would be up to individual drivers to provide CQHCI ops.

Quoted 5 lines
drivers/mmc/host/sdhci.c +1 -0
+
 int sdhci_add_host(struct sdhci_host *host)
 {
     struct mmc_host *mmc;

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host *host) · line 3471

Quoted 9 lines
drivers/mmc/host/sdhci.c +4 -2
@@ -3341,11 +3465,25 @@ int sdhci_add_host(struct sdhci_host *host)
     if (ret)
         goto unled;
 
-    pr_info("%s: SDHCI controller on %s [%s] using %s\n",
-        mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)),
+    if (mmc->caps2 &  MMC_CAP2_CMD_QUEUE) {
+        bool dma64 = (host->flags & SDHCI_USE_ADMA_64BIT) ?
+            true : false;
+        ret = sdhci_cmdq_init(host, mmc, dma64);

You must initialize before mmc_add_host() because mmc_add_host() also starts the host. If you re-base on top of the SDHCI patches, then individual drivers can take advantage of the new sdhci_setup_host() / __sdhci_add_host() split.

Quoted 7 lines
drivers/mmc/host/sdhci.c +7 -0
+        if (ret)
+            pr_err("%s: CMDQ init: failed (%d)\n",
+                   mmc_hostname(host->mmc), ret);
+        else
+            host->cq_host->ops = &sdhci_cmdq_ops;
+    }
+

drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host *host) · line 3486

Quoted 10 lines
drivers/mmc/host/sdhci.c +7 -2
+    pr_info("%s: SDHCI controller on %s [%s] using %s in %s mode\n",
+    mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)),
         (host->flags & SDHCI_USE_ADMA) ?
-        (host->flags & SDHCI_USE_64_BIT_DMA) ? "ADMA 64-bit" : "ADMA" :
-        (host->flags & SDHCI_USE_SDMA) ? "DMA" : "PIO");
+        ((host->flags & SDHCI_USE_ADMA_64BIT) ?
+        "64-bit ADMA" : "32-bit ADMA") :
+        ((host->flags & SDHCI_USE_SDMA) ? "DMA" : "PIO"),
+        ((mmc->caps2 &  MMC_CAP2_CMD_QUEUE) && !ret) ?
+        "CMDQ" : "legacy");

It is probably better if CQHCI prints its own info. That way it you get a consistent message irrespective of whether the driver uses SDHCI. Also you can print other CQHCI details such as the version.

drivers/mmc/host/sdhci.h line 154

Quoted 13 lines
drivers/mmc/host/sdhci.c +0 -0
     sdhci_enable_card_detection(host);
 
drivers/mmc/host/sdhci.h +2 -0
index 609f87c..fccc750 100644
@@ -150,6 +150,8 @@
         SDHCI_INT_DATA_TIMEOUT | SDHCI_INT_DATA_CRC | \
         SDHCI_INT_DATA_END_BIT | SDHCI_INT_ADMA_ERROR | \
         SDHCI_INT_BLK_GAP)
+
+#define SDHCI_INT_CMDQ_EN    (0x1 << 14)

We can define this bit for convenience but we need a comment to say that it is non-standard.

Quoted 9 lines
drivers/mmc/host/sdhci.h +1 -0
 #define SDHCI_INT_ALL_MASK    ((unsigned int)-1)
 
 #define SDHCI_ACMD12_ERR    0x3C
@@ -446,6 +448,7 @@ struct sdhci_host {
 #define SDHCI_PV_ENABLED    (1<<8)    /* Preset value enabled */
 #define SDHCI_SDIO_IRQ_ENABLED    (1<<9)    /* SDIO irq enabled */
 #define SDHCI_USE_64_BIT_DMA    (1<<12)    /* Use 64-bit DMA */
+#define SDHCI_USE_ADMA_64BIT    (1<<12)    /* Host is 64-bit ADMA

capable */

SDHCI_USE_ADMA_64BIT looks redundant.

drivers/mmc/host/sdhci.h struct sdhci_host { · line 516

Quoted 10 lines

#define SDHCI_HS400_TUNING (1<<13) /* Tuning for HS400 */

unsigned int version; /* SDHCI spec. version */

drivers/mmc/host/sdhci.h +0 -0
@@ -509,6 +512,8 @@ struct sdhci_host {
     unsigned int        tuning_mode;    /* Re-tuning mode supported by

host */
#define SDHCI_TUNING_MODE_1 0

drivers/mmc/host/sdhci.h +2 -0
+    struct cmdq_host *cq_host;
+

The individual drivers will have to have their own reference to CQHCI.

Quoted 3 lines
     unsigned long private[0] ____cacheline_aligned;

};

Quoted 7 lines

drivers/mmc/host/sdhci.h struct sdhci_ops { · line 552

Quoted 5 lines
drivers/mmc/host/sdhci.h +1 -0
@@ -544,6 +549,7 @@ struct sdhci_ops {
     void    (*adma_workaround)(struct sdhci_host *host, u32 intmask);
     void    (*platform_init)(struct sdhci_host *host);
     void    (*card_event)(struct sdhci_host *host);
+    void    (*clear_set_dumpregs)(struct sdhci_host *host, bool set);

What is this for?

Quoted 18 lines

This is vendor specific callback to enable/disable some TEST bus registers for debugging purposes.

Quoted 11 lines

drivers/mmc/host/sdhci.h struct sdhci_ops { · line 555

Quoted 5 lines
drivers/mmc/host/sdhci.h +0 -0
     void    (*voltage_switch)(struct sdhci_host *host);
     int    (*select_drive_strength)(struct sdhci_host *host,
                      struct mmc_card *card,

--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Reviewed-by on v2 1/10
#2 lore raw

Re: [PATCH RFCv2 01/10] mmc: core: Add support to read command queue parameters

In reply to Ritesh Harjani
Quoted 6 lines · Ritesh Harjani

From: Asutosh Das <[email protected]>

eMMC cards with EXT_CSD version >= 8, optionally support command queuing feature as defined by JEDEC eMMC5.1. Add support for probing command queue feature for such type of cards.

Quoted 6 lines

Even if we don't merge the specific mechanism provided by the rest of the patches, this patch just make us know more about the capabilities of the hardware we're running on, which is good.

WIll it be reported properly by the lsmmc command too?

Yours,
Linus Walleij

#24 lore raw
In reply to Ritesh Harjani
Quoted 6 lines · Ritesh Harjani

This patch series refreshes the older patch series sent a while ago by Asutosh Das[1].

Current set of patch series is only introducing the basic CMDQ driver to get more review comments. Based on the reviews, will add other features as well to the patch list.

kthread is deprecated since the talks of the last kernel summit. You should prefer to use workqueues.

The queueing mechanism looks like a duplicate copy/paste solution built on the "old" processing queue.

Overall this is the problem with the whole patch set: instead of a "deep" integration by improving the existing request processing, a separate code path is bolted on the side.

What you should do is improve the existing infrastructure to accomodate for the new mechanism.

For example: a new processing thread is introduced instead of augmenting the existing one to handle this case, resulting in a big slew of duplicated code.

For example: this is not at all integrated with the other feature, packed command, which is *also* speculatively pulling out ever more stuff from the block layer, albeit in a totally different manner, actually integrated with the existing queue mechanism.

Needless to say: these two features (packed command and command queue) should use the *same codepath* just that the command queuing is more powerful, so that packed command is merely a subset of the command queueing.

Now: note that I sent a patch do delete packed command. I do not know if that will be accepted, but something deeply integrated is for sure needed, we need a elegant and compact core of code to maintain, not more copies of the already existing messy code.

Yours,
Linus Walleij

#25 lore raw
Quoted 11 lines · CET Linus Walleij
Quoted 6 lines · Ritesh Harjani

This patch series refreshes the older patch series sent a while ago by Asutosh Das[1].

Current set of patch series is only introducing the basic CMDQ driver to get more review comments. Based on the reviews, will add other features as well to the patch list.

kthread is deprecated since the talks of the last kernel summit. You should prefer to use workqueues.

It's the kthread freezer that is deprecated, not kthreads. It with blk_mq, we probably won't want to have this kthread, but that's a differennt issue, and using workqueues instead won't help.

Arnd

maintainer
#3 lore raw

Re: [PATCH RFCv2 01/10] mmc: core: Add support to read command queue parameters

In reply to Linus Walleij
Quoted 15 lines · Linus Walleij
Quoted 6 lines · Ritesh Harjani

From: Asutosh Das <[email protected]>

eMMC cards with EXT_CSD version >= 8, optionally support command queuing feature as defined by JEDEC eMMC5.1. Add support for probing command queue feature for such type of cards.

Quoted 6 lines
Quoted 5 lines

Even if we don't merge the specific mechanism provided by the rest of the patches, this patch just make us know more about the capabilities of the hardware we're running on, which is good.

I think SW CMDQ is a better starting point:

	https://marc.info/?l=linux-mmc&m=147729857722285

It cleans up the queue thread a bit:

	https://marc.info/?l=linux-mmc&m=147729857222281&w=2

And introduces queue semantics:

	https://marc.info/?l=linux-mmc&m=147729863322314&w=2
#4 lore raw

Re: [PATCH RFCv2 01/10] mmc: core: Add support to read command queue parameters

Quoted 16 lines · Adrian Hunter
Quoted 15 lines · Linus Walleij
Quoted 12 lines · Ritesh Harjani

From: Asutosh Das <[email protected]>

eMMC cards with EXT_CSD version >= 8, optionally support command queuing feature as defined by JEDEC eMMC5.1. Add support for probing command queue feature for such type of cards.

Quoted 7 lines
Quoted 5 lines

Even if we don't merge the specific mechanism provided by the rest of the patches, this patch just make us know more about the capabilities of the hardware we're running on, which is good.

I think SW CMDQ is a better starting point:

When I supplied the Reviewe-by, as stated below it I am not talking about the patch set as a whole. I am talking about *this* patch.

As you can see in my reply to 00/10 I have serious concerns about this patchset overall.

Yours,
Linus Walleij

maintainer
#5 lore raw

Re: [PATCH RFCv2 01/10] mmc: core: Add support to read command queue parameters

Quoted 19 lines · Linus Walleij
Quoted 18 lines · Adrian Hunter
Quoted 17 lines · Linus Walleij
Quoted 6 lines · Ritesh Harjani

From: Asutosh Das <[email protected]>

eMMC cards with EXT_CSD version >= 8, optionally support command queuing feature as defined by JEDEC eMMC5.1. Add support for probing command queue feature for such type of cards.

Quoted 6 lines
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Even if we don't merge the specific mechanism provided by the rest of the patches, this patch just make us know more about the capabilities of the hardware we're running on, which is good.

I think SW CMDQ is a better starting point:

When I supplied the Reviewe-by, as stated below it I am not talking about the patch set as a whole. I am talking about *this* patch.

I should have been more explicit. SW CMDQ covers some of the same ground and has basically the same patch:

	https://marc.info/?l=linux-mmc&m=147729859922297&w=2
Quoted 3 lines

As you can see in my reply to 00/10 I have serious concerns about this patchset overall.

I didn't mean to imply otherwise.

#6 lore raw

Re: [PATCH RFCv2 01/10] mmc: core: Add support to read command queue parameters

Quoted 26 lines · Adrian Hunter
Quoted 25 lines · Linus Walleij
Quoted 23 lines · Adrian Hunter
Quoted 15 lines · Linus Walleij
Quoted 6 lines · Ritesh Harjani

From: Asutosh Das <[email protected]>

eMMC cards with EXT_CSD version >= 8, optionally support command queuing feature as defined by JEDEC eMMC5.1. Add support for probing command queue feature for such type of cards.

Quoted 6 lines
Quoted 5 lines

Even if we don't merge the specific mechanism provided by the rest of the patches, this patch just make us know more about the capabilities of the hardware we're running on, which is good.

I think SW CMDQ is a better starting point:

Quoted 7 lines
Quoted 2 lines

When I supplied the Reviewe-by, as stated below it I am not talking about the patch set as a whole. I am talking about *this* patch.

I should have been more explicit. SW CMDQ covers some of the same ground and has basically the same patch:

        https://marc.info/?l=linux-mmc&m=147729859922297&w=2

OK it seems to define more of the constants, I'll go and review it.

Yours,
Linus Walleij

Reviewed-by
#7 lore raw

Re: [PATCH RFCv2 01/10] mmc: core: Add support to read command queue parameters

Quoted 8 lines · Linus Walleij
Quoted 4 lines · Adrian Hunter

I should have been more explicit. SW CMDQ covers some of the same ground and has basically the same patch:

        https://marc.info/?l=linux-mmc&m=147729859922297&w=2

OK it seems to define more of the constants, I'll go and review it.

Bah it's not in my INBOX for some reason, maybe I fell off the linux-mmc list at some point :( I review it here:

Leave out this:

+ cmdq_en Command Queue enabled: 1 => enabled, 0 => not enabled (...)
+MMC_DEV_ATTR(cmdq_en, "%d\n", card->ext_csd.cmdq_en); (...)
+ &dev_attr_cmdq_en.attr,
(...)
+ bool cmdq_en; /* Command Queue enabled */

Because that is about enabling the *use* of this mechnism rather than detecting its presence.

With the above removed it is superior to $SUBJECT so you can add:

Yours,
Linus Walleij