From patchwork Thu Nov 6 15:42:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Shchislowski X-Patchwork-Id: 5244781 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 6B6F5C11AC for ; Thu, 6 Nov 2014 16:16:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 16B922011D for ; Thu, 6 Nov 2014 16:16:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B68442010C for ; Thu, 6 Nov 2014 16:16:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751322AbaKFQQN (ORCPT ); Thu, 6 Nov 2014 11:16:13 -0500 Received: from mail-by2on0068.outbound.protection.outlook.com ([207.46.100.68]:58331 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751054AbaKFQQK convert rfc822-to-8bit (ORCPT ); Thu, 6 Nov 2014 11:16:10 -0500 X-Greylist: delayed 2053 seconds by postgrey-1.27 at vger.kernel.org; Thu, 06 Nov 2014 11:16:10 EST Received: from BLUPR02CA062.namprd02.prod.outlook.com (25.160.23.180) by CO1PR02MB126.namprd02.prod.outlook.com (10.242.163.152) with Microsoft SMTP Server (TLS) id 15.1.16.15; Thu, 6 Nov 2014 15:42:43 +0000 Received: from BY2FFO11FD022.protection.gbl (2a01:111:f400:7c0c::186) by BLUPR02CA062.outlook.office365.com (2a01:111:e400:8ad::52) with Microsoft SMTP Server (TLS) id 15.1.16.15 via Frontend Transport; Thu, 6 Nov 2014 15:42:42 +0000 Received: from sacsmgep11.sandisk.com (74.221.232.162) by BY2FFO11FD022.mail.protection.outlook.com (10.1.15.211) with Microsoft SMTP Server id 15.1.6.13 via Frontend Transport; Thu, 6 Nov 2014 15:42:41 +0000 X-AuditID: ac1c210e-f79a26d000002892-9b-545b96f13f79 Received: from SACHUBIP01.sdcorp.global.sandisk.com ( [172.28.1.254]) by sacsmgep11.sandisk.com (Symantec Messaging Gateway) with SMTP id AC.B2.10386.1F69B545; Thu, 6 Nov 2014 07:42:41 -0800 (PST) Received: from SACMBXIP02.sdcorp.global.sandisk.com ([fe80::6420:780c:fa4c:c1e7]) by SACHUBIP01.sdcorp.global.sandisk.com ([10.181.10.103]) with mapi id 14.03.0195.001; Thu, 6 Nov 2014 07:42:41 -0800 From: Avi Shchislowski To: "linux-mmc@vger.kernel.org" , "'cjb@laptop.org'" CC: Alex Lemberg , Gwendal Grignou Subject: [PATCH 2/3]mmc: Support-FFU-for-eMMC-v5.0 Thread-Topic: [PATCH 2/3]mmc: Support-FFU-for-eMMC-v5.0 Thread-Index: Ac/52EfcrHrBXbrKTpOxl7acD0vUTQ== Date: Thu, 6 Nov 2014 15:42:41 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.181.8.64] MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrGLMWRmVeSWpSXmKPExsWyRobxn+7HadEhBn8W61psf72RzeLuzgmM Fkf+9zM6MHss2FTqcejKWkaPz5vkApijuGxSUnMyy1KL9O0SuDKefTnOWnDTueLPnFfsDYz7 zLsYOTkkBEwkunpfMULYYhIX7q1n62Lk4hASOM4o8XvTayYI5zSjxOHeSewgVWwCphLrvj8B SnBwiAgkSZy/EwISZhYIlti+cBrYIGEBY4mN51czg9giAhYSH6bOYIMo15M4/9MXxGQRUJHo +yELUsErEC2x99lZFhCbEeiE76fWMEFMFJe49WQ+E8RpAhJL9pxnhrBFJV4+/scKMkZCQF7i +mk7iHIdiQW7P7FB2NoSyxa+ZoYYLyhxcuYTlgmMIrOQTJ2FpGUWkpZZSFoWMLKsYhQrTkwu zk1PLTA01CtOzEvJLM7WS87P3cQIjg1Fvh2M+6aYH2IU4GBU4uEVOBEVIsSaWFZcmXuIUYKD WUmEt7onOkSINyWxsiq1KD++qDQntfgQozQHi5I471K3WcFCAumJJanZqakFqUUwWSYOTqkG xvQk/oMKXVZNU7gmPvu19feVY9Omf3fVar6h7d3UfDFv6jklnpds7+0vtTg1FBUHL7tkY8V7 YbNjKN/hMvXQj+wGp100r3ulPXcOFpusEjB7o8zv28tXCH8U7FJ8nnT0gUDApXdsJzRWKIXs Pd1yk03nO0u0XbJT4/ka+SCXGe/+yJ6Y+Id9nRJLcUaioRZzUXEiAP+QvC+JAgAA X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:74.221.232.162; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(438002)(189002)(199003)(46406003)(21056001)(55846006)(77156002)(54356999)(77096003)(33656002)(120916001)(99396003)(229853001)(20776003)(4396001)(23726002)(107046002)(97756001)(62966003)(47776003)(64706001)(50986999)(81156004)(84676001)(106466001)(31966008)(16796002)(92726001)(92566001)(575784001)(95666004)(86362001)(50466002)(44976005)(19580395003)(19580405001)(69596002)(68736004)(87936001)(46102003)(2656002)(97736003)(230783001)(7099017)(491001); DIR:OUT; SFP:1101; SCL:1; SRVR:CO1PR02MB126; H:sacsmgep11.sandisk.com; FPR:; MLV:ovrnspm; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Antispam: UriScan:; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:CO1PR02MB126; X-Exchange-Antispam-Report-Test: UriScan:; X-Forefront-PRVS: 0387D64A71 Received-SPF: Pass (protection.outlook.com: domain of sandisk.com designates 74.221.232.162 as permitted sender) receiver=protection.outlook.com; client-ip=74.221.232.162; helo=sacsmgep11.sandisk.com; Authentication-Results: spf=pass (sender IP is 74.221.232.162) smtp.mailfrom=Avi.Shchislowski@sandisk.com; X-OriginatorOrg: sandisk.com Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP eMMC5.0 FFU is using some of pre-existing mmc_test.c functionality. In order to prevent code duplication, some code of mmc_test.c was moved to core.c and modified. Signed-off-by: Avi Shchislowski Signed-off-by: Alex Lemberg +mmc_check_result(struct mmc_request *mrq); extern int +mmc_simple_transfer(struct mmc_card *card, + struct scatterlist *sg, unsigned sg_len, unsigned dev_addr, + unsigned blocks, unsigned blksz, int write); /** * mmc_claim_host - exclusively claim a host --- 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/mmc_test.c b/drivers/mmc/card/mmc_test.c index 0c0fc52..e6ee0a8 100644 --- a/drivers/mmc/card/mmc_test.c +++ b/drivers/mmc/card/mmc_test.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -189,43 +190,8 @@ static void mmc_test_prepare_mrq(struct mmc_test_card *test, struct mmc_request *mrq, struct scatterlist *sg, unsigned sg_len, unsigned dev_addr, unsigned blocks, unsigned blksz, int write) { - BUG_ON(!mrq || !mrq->cmd || !mrq->data || !mrq->stop); - - if (blocks > 1) { - mrq->cmd->opcode = write ? - MMC_WRITE_MULTIPLE_BLOCK : MMC_READ_MULTIPLE_BLOCK; - } else { - mrq->cmd->opcode = write ? - MMC_WRITE_BLOCK : MMC_READ_SINGLE_BLOCK; - } - - mrq->cmd->arg = dev_addr; - if (!mmc_card_blockaddr(test->card)) - mrq->cmd->arg <<= 9; - - mrq->cmd->flags = MMC_RSP_R1 | MMC_CMD_ADTC; - - if (blocks == 1) - mrq->stop = NULL; - else { - mrq->stop->opcode = MMC_STOP_TRANSMISSION; - mrq->stop->arg = 0; - mrq->stop->flags = MMC_RSP_R1B | MMC_CMD_AC; - } - - mrq->data->blksz = blksz; - mrq->data->blocks = blocks; - mrq->data->flags = write ? MMC_DATA_WRITE : MMC_DATA_READ; - mrq->data->sg = sg; - mrq->data->sg_len = sg_len; - - mmc_set_data_timeout(mrq->data, test->card); -} - -static int mmc_test_busy(struct mmc_command *cmd) -{ - return !(cmd->resp[0] & R1_READY_FOR_DATA) || - (R1_CURRENT_STATE(cmd->resp[0]) == R1_STATE_PRG); + mmc_prepare_mrq(test->card, mrq, sg, sg_len, + dev_addr, blocks, blksz, write); } /* @@ -233,30 +199,9 @@ static int mmc_test_busy(struct mmc_command *cmd) */ static int mmc_test_wait_busy(struct mmc_test_card *test) { - int ret, busy; - struct mmc_command cmd = {0}; - - busy = 0; - do { - memset(&cmd, 0, sizeof(struct mmc_command)); - - cmd.opcode = MMC_SEND_STATUS; - cmd.arg = test->card->rca << 16; - cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; - - ret = mmc_wait_for_cmd(test->card->host, &cmd, 0); - if (ret) - break; - - if (!busy && mmc_test_busy(&cmd)) { - busy = 1; - if (test->card->host->caps & MMC_CAP_WAIT_WHILE_BUSY) - pr_info("%s: Warning: Host did not " - "wait for busy state to end.\n", - mmc_hostname(test->card->host)); - } - } while (mmc_test_busy(&cmd)); + int ret; + ret = mmc_wait_busy(test->card); return ret; } @@ -693,19 +638,9 @@ static int mmc_test_check_result(struct mmc_test_card *test, { int ret; - BUG_ON(!mrq || !mrq->cmd || !mrq->data); - ret = 0; - if (!ret && mrq->cmd->error) - ret = mrq->cmd->error; - if (!ret && mrq->data->error) - ret = mrq->data->error; - if (!ret && mrq->stop && mrq->stop->error) - ret = mrq->stop->error; - if (!ret && mrq->data->bytes_xfered != - mrq->data->blocks * mrq->data->blksz) - ret = RESULT_FAIL; + ret = mmc_check_result(mrq); if (ret == -EINVAL) ret = RESULT_UNSUP_HOST; @@ -844,23 +779,13 @@ static int mmc_test_simple_transfer(struct mmc_test_card *test, struct scatterlist *sg, unsigned sg_len, unsigned dev_addr, unsigned blocks, unsigned blksz, int write) { - struct mmc_request mrq = {0}; - struct mmc_command cmd = {0}; - struct mmc_command stop = {0}; - struct mmc_data data = {0}; - - mrq.cmd = &cmd; - mrq.data = &data; - mrq.stop = &stop; + int ret; - mmc_test_prepare_mrq(test, &mrq, sg, sg_len, dev_addr, + ret = mmc_simple_transfer(test->card, sg, sg_len, dev_addr, blocks, blksz, write); - - mmc_wait_for_req(test->card->host, &mrq); - - mmc_test_wait_busy(test); - - return mmc_test_check_result(test, &mrq); + if (ret == -EINVAL) + ret = RESULT_UNSUP_HOST; + return ret; } /* diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index d03a080..132da0c 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -2658,6 +2658,134 @@ int mmc_pm_notify(struct notifier_block *notify_block, return 0; } #endif +/* + * Fill in the mmc_request structure given a set of transfer parameters. + */ +void mmc_prepare_mrq(struct mmc_card *card, + struct mmc_request *mrq, struct scatterlist *sg, unsigned sg_len, + unsigned dev_addr, unsigned blocks, unsigned blksz, int write) { + BUG_ON(!mrq || !mrq->cmd || !mrq->data || !mrq->stop); + + if (blocks > 1) { + mrq->cmd->opcode = write ? + MMC_WRITE_MULTIPLE_BLOCK : MMC_READ_MULTIPLE_BLOCK; + } else { + mrq->cmd->opcode = write ? + MMC_WRITE_BLOCK : MMC_READ_SINGLE_BLOCK; + } + + mrq->cmd->arg = dev_addr; + if (!mmc_card_blockaddr(card)) + mrq->cmd->arg <<= 9; + + mrq->cmd->flags = MMC_RSP_R1 | MMC_CMD_ADTC; + + if (blocks == 1) + mrq->stop = NULL; + else { + mrq->stop->opcode = MMC_STOP_TRANSMISSION; + mrq->stop->arg = 0; + mrq->stop->flags = MMC_RSP_R1B | MMC_CMD_AC; + } + + mrq->data->blksz = blksz; + mrq->data->blocks = blocks; + mrq->data->flags = write ? MMC_DATA_WRITE : MMC_DATA_READ; + mrq->data->sg = sg; + mrq->data->sg_len = sg_len; + + mmc_set_data_timeout(mrq->data, card); } +EXPORT_SYMBOL(mmc_prepare_mrq); + +static int mmc_busy(struct mmc_command *cmd) { + return !(cmd->resp[0] & R1_READY_FOR_DATA) || + (R1_CURRENT_STATE(cmd->resp[0]) == R1_STATE_PRG); } + +/* + * Wait for the card to finish the busy state */ int +mmc_wait_busy(struct mmc_card *card) { + int ret, busy = 0; + struct mmc_command cmd = {0}; + + memset(&cmd, 0, sizeof(struct mmc_command)); + cmd.opcode = MMC_SEND_STATUS; + cmd.arg = card->rca << 16; + cmd.flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_AC; + + do { + ret = mmc_wait_for_cmd(card->host, &cmd, 0); + if (ret) + break; + + if (!busy && mmc_busy(&cmd)) { + busy = 1; + if (card->host->caps & MMC_CAP_WAIT_WHILE_BUSY) { + pr_warn("%s: Warning: Host did not " + "wait for busy state to end.\n", + mmc_hostname(card->host)); + } + } + + } while (mmc_busy(&cmd)); + + return ret; +} +EXPORT_SYMBOL(mmc_wait_busy); + +int mmc_check_result(struct mmc_request *mrq) { + int ret; + + BUG_ON(!mrq || !mrq->cmd || !mrq->data); + + ret = 0; + + if (!ret && mrq->cmd->error) + ret = mrq->cmd->error; + if (!ret && mrq->data->error) + ret = mrq->data->error; + if (!ret && mrq->stop && mrq->stop->error) + ret = mrq->stop->error; + if (!ret && mrq->data->bytes_xfered != + mrq->data->blocks * mrq->data->blksz) + ret = -EPERM; + + return ret; +} +EXPORT_SYMBOL(mmc_check_result); + +/* ++ * transfer with certain parameters + */ +int mmc_simple_transfer(struct mmc_card *card, + struct scatterlist *sg, unsigned sg_len, unsigned dev_addr, + unsigned blocks, unsigned blksz, int write) { + struct mmc_request mrq = {0}; + struct mmc_command cmd = {0}; + struct mmc_command stop = {0}; + struct mmc_data data = {0}; + + mrq.cmd = &cmd; + mrq.data = &data; + mrq.stop = &stop; + + mmc_prepare_mrq(card, &mrq, sg, sg_len, dev_addr, + blocks, blksz, write); + + mmc_wait_for_req(card->host, &mrq); + + mmc_wait_busy(card); + + return mmc_check_result(&mrq); +} +EXPORT_SYMBOL(mmc_simple_transfer); /** * mmc_init_context_info() - init synchronization context diff --git a/include/linux/mmc/core.h b/include/linux/mmc/core.h index f206e29..92540d0 100644 --- a/include/linux/mmc/core.h +++ b/include/linux/mmc/core.h @@ -196,6 +196,14 @@ extern void mmc_put_card(struct mmc_card *card); extern int mmc_flush_cache(struct mmc_card *); extern int mmc_detect_card_removed(struct mmc_host *host); +extern void mmc_prepare_mrq(struct mmc_card *card, + struct mmc_request *mrq, struct scatterlist *sg, unsigned sg_len, + unsigned dev_addr, unsigned blocks, unsigned blksz, int write); extern +int mmc_wait_busy(struct mmc_card *card); extern int