From patchwork Fri Aug 12 11:14:41 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaehoon Chung X-Patchwork-Id: 1060802 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p7CBEPOL007998 for ; Fri, 12 Aug 2011 11:14:28 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751546Ab1HLLO2 (ORCPT ); Fri, 12 Aug 2011 07:14:28 -0400 Received: from mailout1.samsung.com ([203.254.224.24]:20169 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751471Ab1HLLO1 (ORCPT ); Fri, 12 Aug 2011 07:14:27 -0400 Received: from epcpsbgm1.samsung.com (mailout1.samsung.com [203.254.224.24]) by mailout1.samsung.com (Oracle Communications Messaging Exchange Server 7u4-19.01 64bit (built Sep 7 2010)) with ESMTP id <0LPT0010MB7V1ER0@mailout1.samsung.com> for linux-mmc@vger.kernel.org; Fri, 12 Aug 2011 20:14:26 +0900 (KST) X-AuditID: cbfee61a-b7cf0ae000006bc6-06-4e450b129e6d Received: from epmmp1 ( [203.254.227.16]) by epcpsbgm1.samsung.com (MMPCPMTA) with SMTP id AA.4D.27590.21B054E4; Fri, 12 Aug 2011 20:14:26 +0900 (KST) Received: from TNRNDGASPAPP1.tn.corp.samsungelectronics.net ([165.213.149.150]) by mmp1.samsung.com (iPlanet Messaging Server 5.2 Patch 2 (built Jul 14 2004)) with ESMTPA id <0LPT00FFQB824B@mmp1.samsung.com> for linux-mmc@vger.kernel.org; Fri, 12 Aug 2011 20:14:26 +0900 (KST) Received: from [165.213.219.108] ([165.213.219.108]) by TNRNDGASPAPP1.tn.corp.samsungelectronics.net with Microsoft SMTPSVC(6.0.3790.4675); Fri, 12 Aug 2011 20:15:00 +0900 Date: Fri, 12 Aug 2011 20:14:41 +0900 From: Jaehoon Chung Subject: [RFC PATCH] mmc: support background operation To: "linux-mmc@vger.kernel.org" Cc: Chris Ball , Kyungmin Park , Chuanxiao Dong , Hanumath Prasad Message-id: <4E450B21.8040502@samsung.com> MIME-version: 1.0 Content-type: text/plain; charset=ISO-8859-1 Content-transfer-encoding: 7BIT User-Agent: Thunderbird 2.0.0.24 (X11/20100623) X-OriginalArrivalTime: 12 Aug 2011 11:15:00.0823 (UTC) FILETIME=[13B22670:01CC58E1] X-Brightmail-Tracker: AAAAAA== Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Fri, 12 Aug 2011 11:14:28 +0000 (UTC) Hi mailing. This RFC patch is supported background operation(BKOPS). And if you want to test this patch, must apply "[PATCH v3] mmc: support HPI send command" This patch is based on Hanumath Prasad's patch "mmc: enable background operations for emmc4.41 with HPI support" Hanumath's patch is implemented before applied per forlin's patch "use nonblock mmc request...". This patch is based on 3.1.0-rc1 in mmc-next. Background operations is run when set the URGENT_BKOPS in response. if set the URGENT_BKOPS in response, we can notify that card need the BKOPS. (URGENT_BKOPS is used in eMMC4.41 spec, but in eMMC4.5 changed to EXCEPTION_EVENT bit. maybe, we need to change this point). And all request is done, then run background operation. if request read/write operation when running BKOPS, issue HPI interrupt This patch is just RFC patch (not to merge), because i want to use BKOPS in userspace. (using ioctl). I want to get mailing's review for this patch. Signed-off-by: Jaehoon Chung Signed-off-by: Kyungmin Park CC: Hanumath Prasad --- drivers/mmc/card/block.c | 4 ++++ drivers/mmc/card/queue.c | 10 ++++++++++ drivers/mmc/core/core.c | 35 +++++++++++++++++++++++++++++++++++ drivers/mmc/core/mmc.c | 28 ++++++++++++++++++++++++++++ drivers/mmc/core/mmc_ops.c | 3 +++ include/linux/mmc/card.h | 11 +++++++++++ include/linux/mmc/core.h | 1 + include/linux/mmc/mmc.h | 4 ++++ 8 files changed, 96 insertions(+), 0 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c index 1ff5486..ff72c4a 100644 --- a/drivers/mmc/card/block.c +++ b/drivers/mmc/card/block.c @@ -1078,6 +1078,10 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc) switch (status) { case MMC_BLK_SUCCESS: case MMC_BLK_PARTIAL: + if (mmc_card_mmc(card) && + (brq->cmd.resp[0] & R1_URGENT_BKOPS)) { + mmc_card_set_need_bkops(card); + } /* * A block was successfully transferred. */ diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c index 45fb362..52b1293 100644 --- a/drivers/mmc/card/queue.c +++ b/drivers/mmc/card/queue.c @@ -46,6 +46,8 @@ static int mmc_queue_thread(void *d) { struct mmc_queue *mq = d; struct request_queue *q = mq->queue; + struct mmc_card *card = mq->card; + unsigned long flags; current->flags |= PF_MEMALLOC; @@ -61,6 +63,13 @@ static int mmc_queue_thread(void *d) spin_unlock_irq(q->queue_lock); if (req || mq->mqrq_prev->req) { + if (mmc_card_doing_bkops(card)) { + mmc_interrupt_hpi(card); + spin_lock_irqsave(&card->host->lock, flags); + mmc_card_clr_doing_bkops(card); + spin_unlock_irqrestore(&card->host->lock, + flags); + } set_current_state(TASK_RUNNING); mq->issue_fn(mq, req); } else { @@ -68,6 +77,7 @@ static int mmc_queue_thread(void *d) set_current_state(TASK_RUNNING); break; } + mmc_start_bkops(mq->card); up(&mq->thread_sem); schedule(); down(&mq->thread_sem); diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 7c1ab06..b6de0e5 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -347,6 +347,41 @@ int mmc_wait_for_cmd(struct mmc_host *host, struct mmc_command *cmd, int retries EXPORT_SYMBOL(mmc_wait_for_cmd); +/* Start background operation */ +void mmc_start_bkops(struct mmc_card *card) +{ + int err; + unsigned long flags; + + BUG_ON(!card); + + if (!card->ext_csd.bkops_en) { + printk(KERN_INFO "Didn't set BKOPS enable bit!\n"); + return; + } + + if (mmc_card_doing_bkops(card) || + !mmc_card_need_bkops(card)) { + return; + } + + mmc_claim_host(card->host); + err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, + EXT_CSD_BKOPS_START, 1, 0); + if (err) { + mmc_card_clr_need_bkops(card); + goto out; + } + + spin_lock_irqsave(&card->host->lock, flags); + mmc_card_clr_need_bkops(card); + mmc_card_set_doing_bkops(card); + spin_unlock_irqrestore(&card->host->lock, flags); +out: + mmc_release_host(card->host); +} +EXPORT_SYMBOL(mmc_start_bkops); + /** * mmc_interrupt_hpi - Issue for High priority Interrupt * @card: the MMC card associated with the HPI transfer diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index ef10bfd..0372414 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -421,6 +421,17 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd) ext_csd[EXT_CSD_OUT_OF_INTERRUPT_TIME] * 10; } + /* + * check whether the eMMC card support BKOPS. + * if set BKOPS_SUPPORT bit, + * BKOPS_STATUS, BKOPS_EN,,BKOPS_START and + * URGENT_BKOPS are supported.(default) + */ + if (ext_csd[EXT_CSD_BKOPS_SUPPORT] & 0x1) { + card->ext_csd.bkops = 1; + card->ext_csd.bkops_en = ext_csd[EXT_CSD_BKOPS_EN]; + } + card->ext_csd.rel_param = ext_csd[EXT_CSD_WR_REL_PARAM]; } @@ -762,6 +773,23 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr, } /* + * Enable HPI feature (if supported) + */ + if (card->ext_csd.hpi) { + err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, + EXT_CSD_HPI_MGMT, 1, 0); + if (err && err != -EBADMSG) + goto free_card; + + if (err) { + printk(KERN_WARNING "%s: Enabling HPI failed\n", + mmc_hostname(card->host)); + err = 0; + } else + card->ext_csd.hpi_en = 1; + } + + /* * Compute bus speed. */ max_dtr = (unsigned int)-1; diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c index 4706400..2a54221 100644 --- a/drivers/mmc/core/mmc_ops.c +++ b/drivers/mmc/core/mmc_ops.c @@ -398,6 +398,9 @@ int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value, if (err) return err; + if (index == EXT_CSD_BKOPS_START) + return 0; + /* Must check status to be sure of no errors */ do { err = mmc_send_status(card, &status); diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h index 411054d..137887d 100644 --- a/include/linux/mmc/card.h +++ b/include/linux/mmc/card.h @@ -67,6 +67,8 @@ struct mmc_ext_csd { bool hpi_en; /* HPI enablebit */ bool hpi; /* HPI support bit */ unsigned int hpi_cmd; /* cmd used as HPI */ + bool bkops; /* BKOPS support bit */ + bool bkops_en; /* BKOPS enable bit */ u8 raw_partition_support; /* 160 */ u8 raw_erased_mem_count; /* 181 */ u8 raw_ext_csd_structure; /* 194 */ @@ -192,6 +194,8 @@ struct mmc_card { #define MMC_QUIRK_DISABLE_CD (1<<5) /* disconnect CD/DAT[3] resistor */ #define MMC_QUIRK_INAND_CMD38 (1<<6) /* iNAND devices have broken CMD38 */ #define MMC_QUIRK_BLK_NO_CMD23 (1<<7) /* Avoid CMD23 for regular multiblock */ +#define MMC_STATE_NEED_BKOPS (1<<7) /* Need background operation */ +#define MMC_STATE_DOING_BKOPS (1<<8) /* Do running background operation */ unsigned int erase_size; /* erase size in sectors */ unsigned int erase_shift; /* if erase unit is power 2 */ @@ -318,6 +322,8 @@ static inline void __maybe_unused remove_quirk(struct mmc_card *card, int data) #define mmc_card_ddr_mode(c) ((c)->state & MMC_STATE_HIGHSPEED_DDR) #define mmc_sd_card_uhs(c) ((c)->state & MMC_STATE_ULTRAHIGHSPEED) #define mmc_card_ext_capacity(c) ((c)->state & MMC_CARD_SDXC) +#define mmc_card_need_bkops(c) ((c)->state & MMC_STATE_NEED_BKOPS) +#define mmc_card_doing_bkops(c) ((c)->state & MMC_STATE_DOING_BKOPS) #define mmc_card_set_present(c) ((c)->state |= MMC_STATE_PRESENT) #define mmc_card_set_readonly(c) ((c)->state |= MMC_STATE_READONLY) @@ -326,6 +332,11 @@ static inline void __maybe_unused remove_quirk(struct mmc_card *card, int data) #define mmc_card_set_ddr_mode(c) ((c)->state |= MMC_STATE_HIGHSPEED_DDR) #define mmc_sd_card_set_uhs(c) ((c)->state |= MMC_STATE_ULTRAHIGHSPEED) #define mmc_card_set_ext_capacity(c) ((c)->state |= MMC_CARD_SDXC) +#define mmc_card_set_need_bkops(c) ((c)->state |= MMC_STATE_NEED_BKOPS) +#define mmc_card_set_doing_bkops(c) ((c)->state |= MMC_STATE_DOING_BKOPS) + +#define mmc_card_clr_need_bkops(c) ((c)->state &= ~MMC_STATE_NEED_BKOPS) +#define mmc_card_clr_doing_bkops(c) ((c)->state &= ~MMC_STATE_DOING_BKOPS) /* * Quirk add/remove for MMC products. diff --git a/include/linux/mmc/core.h b/include/linux/mmc/core.h index dca3c08..90f2e1c 100644 --- a/include/linux/mmc/core.h +++ b/include/linux/mmc/core.h @@ -162,6 +162,7 @@ extern int mmc_erase_group_aligned(struct mmc_card *card, unsigned int from, unsigned int nr); extern unsigned int mmc_calc_max_discard(struct mmc_card *card); +extern void mmc_start_bkops(struct mmc_card *card); extern int mmc_set_blocklen(struct mmc_card *card, unsigned int blocklen); extern void mmc_set_data_timeout(struct mmc_data *, const struct mmc_card *); diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h index e16c776..419a48e 100644 --- a/include/linux/mmc/mmc.h +++ b/include/linux/mmc/mmc.h @@ -139,6 +139,7 @@ static inline bool mmc_op_multi(u32 opcode) #define R1_READY_FOR_DATA (1 << 8) /* sx, a */ #define R1_SWITCH_ERROR (1 << 7) /* sx, c */ #define R1_APP_CMD (1 << 5) /* sr, c */ +#define R1_URGENT_BKOPS (1 << 6) /* sr, a */ #define R1_STATE_IDLE 0 #define R1_STATE_READY 1 @@ -273,6 +274,8 @@ struct _mmc_csd { #define EXT_CSD_PARTITION_ATTRIBUTE 156 /* R/W */ #define EXT_CSD_PARTITION_SUPPORT 160 /* RO */ #define EXT_CSD_HPI_MGMT 161 /* R/W */ +#define EXT_CSD_BKOPS_EN 163 /* R/W */ +#define EXT_CSD_BKOPS_START 164 /* R/W */ #define EXT_CSD_WR_REL_PARAM 166 /* RO */ #define EXT_CSD_ERASE_GROUP_DEF 175 /* R/W */ #define EXT_CSD_PART_CONFIG 179 /* R/W */ @@ -295,6 +298,7 @@ struct _mmc_csd { #define EXT_CSD_SEC_ERASE_MULT 230 /* RO */ #define EXT_CSD_SEC_FEATURE_SUPPORT 231 /* RO */ #define EXT_CSD_TRIM_MULT 232 /* RO */ +#define EXT_CSD_BKOPS_SUPPORT 502 /* RO */ #define EXT_CSD_HPI_FEATURES 503 /* RO */ /*