From patchwork Thu Nov 13 16:31:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Shchislowski X-Patchwork-Id: 5299141 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D8D489F2F1 for ; Thu, 13 Nov 2014 16:32:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AFC24201F5 for ; Thu, 13 Nov 2014 16:32:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 689BF201F4 for ; Thu, 13 Nov 2014 16:32:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932939AbaKMQcD (ORCPT ); Thu, 13 Nov 2014 11:32:03 -0500 Received: from mail-bn1on0057.outbound.protection.outlook.com ([157.56.110.57]:52672 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932752AbaKMQcB (ORCPT ); Thu, 13 Nov 2014 11:32:01 -0500 Received: from BN1PR02CA0050.namprd02.prod.outlook.com (10.141.56.50) by BLUPR02MB113.namprd02.prod.outlook.com (10.242.187.21) with Microsoft SMTP Server (TLS) id 15.1.16.15; Thu, 13 Nov 2014 16:31:44 +0000 Received: from BY2FFO11FD044.protection.gbl (2a01:111:f400:7c0c::116) by BN1PR02CA0050.outlook.office365.com (2a01:111:e400:2a::50) with Microsoft SMTP Server (TLS) id 15.1.16.15 via Frontend Transport; Thu, 13 Nov 2014 16:31:44 +0000 Received: from milsmgep12.sandisk.com (63.163.107.173) by BY2FFO11FD044.mail.protection.outlook.com (10.1.14.229) with Microsoft SMTP Server id 15.1.6.13 via Frontend Transport; Thu, 13 Nov 2014 16:31:43 +0000 Received: from MILHUBIP03.sdcorp.global.sandisk.com ( [172.22.12.162]) by milsmgep12.sandisk.com (Symantec Messaging Gateway) with SMTP id 07.F0.11368.FECD4645; Thu, 13 Nov 2014 08:31:43 -0800 (PST) Received: from milsmgip11.sandisk.com (10.177.8.100) by MILHUBIP03.sdcorp.global.sandisk.com (10.177.9.96) with Microsoft SMTP Server id 14.3.195.1; Thu, 13 Nov 2014 08:31:43 -0800 X-AuditID: ac160a69-f79066d000002c68-e0-5464dcef7651 Received: from KFAC110926.sdcorp.global.sandisk.com ( [10.177.8.100]) by milsmgip11.sandisk.com (Symantec Messaging Gateway) with SMTP id 21.01.10458.DECD4645; Thu, 13 Nov 2014 08:31:43 -0800 (PST) From: Avi Shchislowski To: CC: , , , Avi Shchislowski , Alex Lemberg Subject: [PATCH 2/3] mmc: move shared mmc_test and ffu functions to core.c Date: Thu, 13 Nov 2014 18:31:33 +0200 Message-ID: <1415896293-27947-1-git-send-email-avi.shchislowski@sandisk.com> X-Mailer: git-send-email 1.7.9.5 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrHLMWRmVeSWpSXmKPExsWyRoxnke77OykhBlN3WlhMuLyd0eLI/35G i+Nrwx2YPe5c28PmcePVQiaPz5vkApijuGxSUnMyy1KL9O0SuDJ+HPnDWtDrUvF2wWGWBsYt 5l2MnBwSAiYSj3YvYoewxSQu3FvP1sXIxSEkcIJRYv3tyewQzg5GiXlHf7LBdEy/9pYFInGS UWLxi11g7WwCphIz25YydTFycIgIyEg0HjAGqWEWWMsoMeFJLyNIjbCAl8SsFZOZQWpYBFQl rtzgAwnzCvhIHJp9hh0kLCGgIDFnkg1Iq4TANxaJizsamSBqBCVOznzCAmIzC0hIHHzxghnE FhLQlDi5cDnbBEbBWUjKZiEpW8DItIpRLDczpzg3PbXA0EivODEvJbM4Wy85P3cTIzhUuTJ3 MK6YZH6IUYCDUYmH9wVLSogQa2JZcWXuIUYJDmYlEV7vw0Ah3pTEyqrUovz4otKc1OJDjNIc LErivILTs/yFBNITS1KzU1MLUotgskwcnFINjLPTF83W2vxh99l/srIKS01fR9ncnJt0Z4ry W/9k/wPlamqWGtKc73Za1ZzpNS7snMW38JldosWVkg9nla++ybJaf79zo/41f991p9nOCVRM Dl4WKHRmyUrnFx/33LvizJ8kNbl+znZHkbnZUcm5/0ImfP81TVsga9vGN2vmsV9qfaDcXC0x yUmJpTgj0VCLuag4EQCQ2VhBUQIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprMJMWRmVeSWpSXmKPExsXCtZEjRff9nZQQg51b1C1uPvjBZrFz7zom iwmXtzNaHPnfz2hxfG24A6vHnWt72DxuvFrI5DFtzXkmj8+b5AJYorhsUlJzMstSi/TtErgy fhz5w1rQ61LxdsFhlgbGLeZdjJwcEgImEtOvvWWBsMUkLtxbz9bFyMUhJHCcUWLyzG9sIAk2 AVOJmW1LmUBsEQEpiZ6nzcwgRcwCqxkljizZwgySEBbwkpi1YjKQzcHBIqAqceUGH0iYV8BH 4lL7DRaQsISAgsScSTYTGLkWMDKsYhTLzcwpzk3PLDA01CtOzEvJLM7WS87P3cQI9jZn5A7G pxPNDzEycXBKNTAumG/PfLyie9NEG82JjlpzuZIX5XKdWb8g7PYdwcKoU2uWXmvb3vdy6ckc +e08zAX1CtPtIr7Pm6XtJL7q2zWOyASDq01aX1yX8U94UyZbZvd+VV70jJm8vmvV+l6V33/Y 7DP7x5Ilf5ac8N/pmJE8I2Db3luT7zl310o/avXMqnr2z0sqgMtXiaU4I9FQi7moOBEAZeSd waYBAAA= MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:63.163.107.173; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(438002)(189002)(199003)(46102003)(21056001)(44976005)(81156004)(87286001)(92726001)(84676001)(19580395003)(110136001)(87936001)(88136002)(89996001)(120916001)(86362001)(33646002)(50466002)(92566001)(48376002)(97736003)(93916002)(95666004)(69596002)(77156002)(62966003)(50986999)(50226001)(4396001)(104166001)(36756003)(2351001)(31966008)(19580405001)(229853001)(68736004)(106466001)(47776003)(102836001)(20776003)(107046002)(64706001)(99396003); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR02MB113; H:milsmgep12.sandisk.com; FPR:; MLV:sfv; PTR:ErrorRetry; MX:1; A:1; LANG:en; X-Microsoft-Antispam: UriScan:; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:BLUPR02MB113; X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:;SRVR:BLUPR02MB113; X-Forefront-PRVS: 0394259C80 Received-SPF: Pass (protection.outlook.com: domain of sandisk.com designates 63.163.107.173 as permitted sender) receiver=protection.outlook.com; client-ip=63.163.107.173; helo=milsmgep12.sandisk.com; Authentication-Results: spf=pass (sender IP is 63.163.107.173) smtp.mailfrom=Avi.Shchislowski@sandisk.com; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:;SRVR:BLUPR02MB113; 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.9 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 --- drivers/mmc/card/mmc_test.c | 97 ++++---------------------------- drivers/mmc/core/core.c | 128 +++++++++++++++++++++++++++++++++++++++++++ include/linux/mmc/core.h | 8 +++ 3 files changed, 147 insertions(+), 86 deletions(-) diff --git a/drivers/mmc/card/mmc_test.c b/drivers/mmc/card/mmc_test.c index 0a7430f..5ea7075 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 @@ -192,43 +193,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); } /* @@ -236,30 +202,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; } @@ -696,19 +641,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; @@ -847,23 +782,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 a32bea2..c30a4d0 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -2657,6 +2657,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 b11e43c..1740e6f 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 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