From patchwork Tue Mar 29 12:57:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitkumar Karwar X-Patchwork-Id: 8686681 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C31359F44D for ; Tue, 29 Mar 2016 13:04:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4985A2026F for ; Tue, 29 Mar 2016 13:04:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 699EC202F2 for ; Tue, 29 Mar 2016 13:04:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752503AbcC2NEA (ORCPT ); Tue, 29 Mar 2016 09:04:00 -0400 Received: from mx0a-0016f401.pphosted.com ([67.231.148.174]:46426 "EHLO mx0a-0016f401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751826AbcC2ND6 (ORCPT ); Tue, 29 Mar 2016 09:03:58 -0400 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u2TD1fse010608; Tue, 29 Mar 2016 06:03:56 -0700 Received: from sc-exch02.marvell.com ([199.233.58.182]) by mx0a-0016f401.pphosted.com with ESMTP id 21ydsktj9p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Tue, 29 Mar 2016 06:03:56 -0700 Received: from SC-EXCH04.marvell.com (10.93.176.84) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1104.5; Tue, 29 Mar 2016 06:03:55 -0700 Received: from maili.marvell.com (10.93.176.43) by SC-EXCH04.marvell.com (10.93.176.84) with Microsoft SMTP Server id 15.0.1104.5 via Frontend Transport; Tue, 29 Mar 2016 06:03:55 -0700 Received: from pe-lt101 (unknown [10.31.130.27]) by maili.marvell.com (Postfix) with ESMTP id 4631A3F7040; Tue, 29 Mar 2016 06:03:55 -0700 (PDT) Received: from pe-lt101 (pe-lt077 [127.0.0.1]) by pe-lt101 (8.14.4/8.14.4) with ESMTP id u2TCvopG022522; Tue, 29 Mar 2016 05:57:51 -0700 Received: (from root@localhost) by pe-lt101 (8.14.4/8.14.4/Submit) id u2TCvoGK022520; Tue, 29 Mar 2016 05:57:50 -0700 From: Amitkumar Karwar To: CC: Nishant Sarmukadam , , , Cathy Luo , Bing Zhao , Xinming Hu , Amitkumar Karwar Subject: [PATCH] mmc: add API for data write using scatter gather DMA Date: Tue, 29 Mar 2016 05:57:41 -0700 Message-ID: <1459256261-22492-1-git-send-email-akarwar@marvell.com> X-Mailer: git-send-email 1.7.3.4 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-03-29_04:, , signatures=0 X-Proofpoint-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1601100000 definitions=main-1603290189 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@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=unavailable 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 From: Bing Zhao This patch adds new API for SDIO scatter gather. Existing mmc_io_rw_extended() API expects caller to pass single contiguous buffer. It will be split if it exceeds segment size, SG table is prepared and used it for reading/writing the data. Our intention for defining new API here is to facilitate caller to provide ready SG table(scattered buffer list). It will be useful for the drivers which intend to handle SDIO SG internally. Signed-off-by: Bing Zhao Signed-off-by: Xinming Hu Signed-off-by: Amitkumar Karwar --- drivers/mmc/core/sdio_ops.c | 64 +++++++++++++++++++++++++++++++++++++++++++ include/linux/mmc/sdio_func.h | 5 ++++ 2 files changed, 69 insertions(+) diff --git a/drivers/mmc/core/sdio_ops.c b/drivers/mmc/core/sdio_ops.c index 62508b4..6875980 100644 --- a/drivers/mmc/core/sdio_ops.c +++ b/drivers/mmc/core/sdio_ops.c @@ -204,6 +204,70 @@ int mmc_io_rw_extended(struct mmc_card *card, int write, unsigned fn, return 0; } +int mmc_io_rw_extended_sg(struct mmc_card *card, int write, unsigned fn, + unsigned addr, int incr_addr, + struct sg_table *sgt, unsigned blksz) +{ + struct mmc_request mrq = {NULL}; + struct mmc_command cmd = {0}; + struct mmc_data data = {0}; + struct scatterlist *sg_ptr; + unsigned blocks = 0; + int i; + + WARN_ON(!card || !card->host); + WARN_ON(fn > 7); + WARN_ON(blksz == 0); + for_each_sg(sgt->sgl, sg_ptr, sgt->nents, i) { + WARN_ON(sg_ptr->length > card->host->max_seg_size); + blocks += DIV_ROUND_UP(sg_ptr->length, blksz); + } + + /* sanity check */ + if (addr & ~0x1FFFF) + return -EINVAL; + + mrq.cmd = &cmd; + mrq.data = &data; + + cmd.opcode = SD_IO_RW_EXTENDED; + cmd.arg = write ? 0x80000000 : 0x00000000; + cmd.arg |= fn << 28; + cmd.arg |= incr_addr ? 0x04000000 : 0x00000000; + cmd.arg |= addr << 9; + cmd.arg |= 0x08000000 | blocks; + 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 = sgt->sgl; + data.sg_len = sgt->nents; + + mmc_set_data_timeout(&data, card); + mmc_wait_for_req(card->host, &mrq); + + if (cmd.error) + return cmd.error; + if (data.error) + return data.error; + + if (mmc_host_is_spi(card->host)) { + /* host driver already reported errors */ + } else { + if (cmd.resp[0] & R5_ERROR) + return -EIO; + if (cmd.resp[0] & R5_FUNCTION_NUMBER) + return -EINVAL; + if (cmd.resp[0] & R5_OUT_OF_RANGE) + return -ERANGE; + } + + return 0; +} +EXPORT_SYMBOL_GPL(mmc_io_rw_extended_sg); + int sdio_reset(struct mmc_host *host) { int ret; diff --git a/include/linux/mmc/sdio_func.h b/include/linux/mmc/sdio_func.h index aab032a..2107e91 100644 --- a/include/linux/mmc/sdio_func.h +++ b/include/linux/mmc/sdio_func.h @@ -14,6 +14,7 @@ #include #include +#include #include @@ -151,6 +152,10 @@ extern int sdio_memcpy_toio(struct sdio_func *func, unsigned int addr, extern int sdio_writesb(struct sdio_func *func, unsigned int addr, void *src, int count); +int mmc_io_rw_extended_sg(struct mmc_card *card, int write, unsigned fn, + unsigned addr, int incr_addr, + struct sg_table *sgt, unsigned blksz); + extern unsigned char sdio_f0_readb(struct sdio_func *func, unsigned int addr, int *err_ret); extern void sdio_f0_writeb(struct sdio_func *func, unsigned char b,