From patchwork Wed Sep 7 11:40:20 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Ferre X-Patchwork-Id: 1127852 Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p87Gqo9q001357 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 7 Sep 2011 16:53:10 GMT Received: from canuck.infradead.org ([2001:4978:20e::1]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1R1FcL-0001su-3j; Wed, 07 Sep 2011 10:44:29 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1R1FcK-0003Xb-KB; Wed, 07 Sep 2011 10:44:28 +0000 Received: from newsmtp5.atmel.com ([204.2.163.5] helo=sjogate2.atmel.com) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1R1FcG-0003Wm-VC for linux-arm-kernel@lists.infradead.org; Wed, 07 Sep 2011 10:44:26 +0000 Received: from meyreuil.atmel.fr ([10.159.254.132]) by sjogate2.atmel.com (8.13.6/8.13.6) with ESMTP id p87APKNQ016049; Wed, 7 Sep 2011 03:25:21 -0700 (PDT) Received: from bendor.rfo.atmel.com ([10.159.245.201]) by meyreuil.atmel.fr (8.11.7p1+Sun/8.11.7) with ESMTP id p87ASee12729; Wed, 7 Sep 2011 12:28:40 +0200 (MEST) From: Nicolas Ferre To: cjb@laptop.org, linux-mmc@vger.kernel.org Subject: [RFC PATCH] mmc: sdio: rw extended, use a sg entry for each block Date: Wed, 7 Sep 2011 13:40:20 +0200 Message-Id: <1315395620-22641-1-git-send-email-nicolas.ferre@atmel.com> X-Mailer: git-send-email 1.7.3 X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110907_064425_186525_6CD77E35 X-CRM114-Status: GOOD ( 11.61 ) X-Spam-Score: -0.5 (/) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (-0.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.5 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain Cc: Nicolas Ferre , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Wed, 07 Sep 2011 16:53:10 +0000 (UTC) While using io multiple blocks operations, change the way that sg is built: use one sg entry for each block instead of aggregating the whole buffer in a single sg entry. Using a single sg entry for a multiple block command may lead to misunderstanding between the sd/mmc and the DMA controllers. In fact, the knowledge of the block length will allow both controllers to optimize burst sizes on internal bus while dealing with those data. Use a sg table to store start addresses of blocks within the data buffer. Signed-off-by: Nicolas Ferre --- drivers/mmc/core/sdio_ops.c | 38 +++++++++++++++++++++++++++++--------- 1 files changed, 29 insertions(+), 9 deletions(-) diff --git a/drivers/mmc/core/sdio_ops.c b/drivers/mmc/core/sdio_ops.c index f087d87..aea6978 100644 --- a/drivers/mmc/core/sdio_ops.c +++ b/drivers/mmc/core/sdio_ops.c @@ -124,7 +124,7 @@ int mmc_io_rw_extended(struct mmc_card *card, int write, unsigned fn, struct mmc_request mrq = {0}; struct mmc_command cmd = {0}; struct mmc_data data = {0}; - struct scatterlist sg; + struct sg_table sgt; BUG_ON(!card); BUG_ON(fn > 7); @@ -144,24 +144,44 @@ int mmc_io_rw_extended(struct mmc_card *card, int write, unsigned fn, cmd.arg |= fn << 28; cmd.arg |= incr_addr ? 0x04000000 : 0x00000000; cmd.arg |= addr << 9; - if (blocks == 1 && blksz <= 512) - cmd.arg |= (blksz == 512) ? 0 : blksz; /* byte mode */ - else - cmd.arg |= 0x08000000 | blocks; /* block mode */ + if (blocks == 1 && blksz <= 512) { + /* byte mode */ + struct scatterlist sg; + + cmd.arg |= (blksz == 512) ? 0 : blksz; + sg_init_one(&sg, buf, blksz * blocks); + + data.sg = &sg; + data.sg_len = 1; + } else { + /* block mode */ + struct scatterlist *sg_ptr; + int i; + + cmd.arg |= 0x08000000 | blocks; + if (sg_alloc_table(&sgt, blocks, GFP_KERNEL)) + return -ENOMEM; + for_each_sg(sgt.sgl, sg_ptr, sgt.nents, i) { + sg_set_buf(sg_ptr, buf + i * blksz, blksz); + } + + data.sg = sgt.sgl; + data.sg_len = sgt.nents; + } + cmd.flags = MMC_RSP_SPI_R5 | MMC_RSP_R5 | MMC_CMD_ADTC; data.blksz = blksz; data.blocks = blocks; data.flags = write ? MMC_DATA_WRITE : MMC_DATA_READ; - data.sg = &sg; - data.sg_len = 1; - - sg_init_one(&sg, buf, blksz * blocks); mmc_set_data_timeout(&data, card); mmc_wait_for_req(card->host, &mrq); + if (blocks != 1 || blksz > 512) + sg_free_table(&sgt); + if (cmd.error) return cmd.error; if (data.error)