Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3415200imm; Fri, 25 May 2018 05:26:59 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoGjpIhlMSWsrMNG8sNdtUmskCwXTVMuilWxlXxExuao5WYo1UpAh3aqvasGpMvvk/yvXr+ X-Received: by 2002:a63:8c4f:: with SMTP id q15-v6mr1918225pgn.236.1527251219018; Fri, 25 May 2018 05:26:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527251218; cv=none; d=google.com; s=arc-20160816; b=XCg2/i+GRw/HMM9tHcypaq0HTRIq1dAkUVQTi6E4WbJvcFazXjMxPGYTJSo4hTKS0n 2Co5nGizNe+GGpg0YPOTDj91Ukt4LQlz6MCGHiSYjkyjjSqycj8zbzSus4SwP096EkX+ TsG0jrxikwwY8BV3bwjTxEdv3RTa5qPm7XPS54r+MHI3rPn2hHB2heYyDnShcrb/fqMb ykbyq2RC3Y1EIDNwdeQ+hgmBe7zEBti2cbTjl2K5JpD8qijQbsHyioXdraDTYtz0IJdq jLvm6Il9wTr+1/DuQ4aHRhwjlDDjHUJw1M5DlDZ42P5IB9+OviinbiE+U82UkAgW5mOy 0MtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=fRC10UhtOatXGULTx346MEU0oF+/YyHfxAfxdCHpQHU=; b=e/7BAf2FmPYIbPDzwS8qOFYAVs2JQn2l6ZsixVw3N970OvYSHdwQ/QMlEW/bzIrQpp 6BAuTVpvln8cPPRFTOxxQ1pRuYeCbAn6xsTFxLgX/OtoC4O0pTtV2lzwRZEbD6mCpYBt MONCf9MDw7YhJILFBuwdHTV30wycFpgCKF+TcuLc/9om2CfXkl3/BConafRF6l5EDZMU SvOHpYg9juHtCmb3omZKgdr7M2SWW5E3rvZGrQIi9gUFExfM0Zmq8TNkVG7Nq8uKRqQL UTldJ5zK4jq2b6045OQ016CVH/mgVJMif3p0L6erdn7yaWP5c+p4+AJ3jTbCJNO7r7tj BiDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=Dsxxu8+4; dkim=pass header.i=@codeaurora.org header.s=default header.b=jH420Fvx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p67-v6si22658041pfp.72.2018.05.25.05.26.44; Fri, 25 May 2018 05:26:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=Dsxxu8+4; dkim=pass header.i=@codeaurora.org header.s=default header.b=jH420Fvx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967113AbeEYMYr (ORCPT + 99 others); Fri, 25 May 2018 08:24:47 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:48346 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966967AbeEYMWb (ORCPT ); Fri, 25 May 2018 08:22:31 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 48AA76076C; Fri, 25 May 2018 12:22:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1527250951; bh=yarQqxk0ZLIeYIdFFL1n+AmG59QP1Ug8qg0heBPVoqs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Dsxxu8+4Vc3vRh2U1i9oEbwg3U9ClZmczvMgPEcEYro3fQJXBVEpWqC5fKzJy4ZJw lotw6hrRjbs6nh4D14px/KD+v5gsZU2AkfNbUiCy6r39qKcFRugniy6v+CN1i5Q2Kt AxSe8elTcdztC1b+pKGJY7tU/Dh/iUhXXxGUWjik= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from absahu-linux.qualcomm.com (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: absahu@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 90D0160AFB; Fri, 25 May 2018 12:22:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1527250949; bh=yarQqxk0ZLIeYIdFFL1n+AmG59QP1Ug8qg0heBPVoqs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jH420Fvxd3sQ6Vh49uvp7Tpj8cKZM8d4vxEM4GpIzgTar+lbOiQP3HpmI2/w4KYSB F9NkWfgtGsPnjM/Eb7gK3fQ5awabVIxnCJTIB+K/FNGpD8whPlPquYJHOhpgODyKhq LEH6foKgUWebo72+BKERH0s0gsAdHHOC1ppAAFGE= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 90D0160AFB Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=absahu@codeaurora.org From: Abhishek Sahu To: Boris Brezillon Cc: David Woodhouse , Brian Norris , Marek Vasut , Richard Weinberger , Cyrille Pitchen , Miquel Raynal , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, Andy Gross , Archit Taneja , Abhishek Sahu , stable@vger.kernel.org Subject: [PATCH v3 07/16] mtd: rawnand: qcom: wait for desc completion in all BAM channels Date: Fri, 25 May 2018 17:51:35 +0530 Message-Id: <1527250904-21988-8-git-send-email-absahu@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1527250904-21988-1-git-send-email-absahu@codeaurora.org> References: <1527250904-21988-1-git-send-email-absahu@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The BAM has 3 channels - tx, rx and command. command channel is used for register read/writes, tx channel for data writes and rx channel for data reads. Currently, the driver assumes the transfer completion once it gets all the command descriptors completed. Sometimes, there is race condition between data channel (tx/rx) and command channel completion. In these cases, the data present in buffer is not valid during small window between command descriptor completion and data descriptor completion. This patch generates NAND transfer completion when both (Data and Command) DMA channels have completed all its DMA descriptors. It assigns completion callback in last DMA descriptors of that channel and wait for completion. Fixes: 8d6b6d7e135e ("mtd: nand: qcom: support for command descriptor formation") Cc: stable@vger.kernel.org Signed-off-by: Abhishek Sahu --- * Changes from v2: 1. Changed commit message and comments slightly 2. Renamed wait_second_completion from first_chan_done and set it before submit desc 3. Mark for stable tree * Changes from v1: NONE drivers/mtd/nand/raw/qcom_nandc.c | 53 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/nand/raw/qcom_nandc.c b/drivers/mtd/nand/raw/qcom_nandc.c index 7377923..7f85ef8 100644 --- a/drivers/mtd/nand/raw/qcom_nandc.c +++ b/drivers/mtd/nand/raw/qcom_nandc.c @@ -213,6 +213,8 @@ #define QPIC_PER_CW_CMD_SGL 32 #define QPIC_PER_CW_DATA_SGL 8 +#define QPIC_NAND_COMPLETION_TIMEOUT msecs_to_jiffies(2000) + /* * Flags used in DMA descriptor preparation helper functions * (i.e. read_reg_dma/write_reg_dma/read_data_dma/write_data_dma) @@ -245,6 +247,11 @@ * @tx_sgl_start - start index in data sgl for tx. * @rx_sgl_pos - current index in data sgl for rx. * @rx_sgl_start - start index in data sgl for rx. + * @wait_second_completion - wait for second DMA desc completion before making + * the NAND transfer completion. + * @txn_done - completion for NAND transfer. + * @last_data_desc - last DMA desc in data channel (tx/rx). + * @last_cmd_desc - last DMA desc in command channel. */ struct bam_transaction { struct bam_cmd_element *bam_ce; @@ -258,6 +265,10 @@ struct bam_transaction { u32 tx_sgl_start; u32 rx_sgl_pos; u32 rx_sgl_start; + bool wait_second_completion; + struct completion txn_done; + struct dma_async_tx_descriptor *last_data_desc; + struct dma_async_tx_descriptor *last_cmd_desc; }; /* @@ -504,6 +515,8 @@ static void free_bam_transaction(struct qcom_nand_controller *nandc) bam_txn->data_sgl = bam_txn_buf; + init_completion(&bam_txn->txn_done); + return bam_txn; } @@ -523,11 +536,33 @@ static void clear_bam_transaction(struct qcom_nand_controller *nandc) bam_txn->tx_sgl_start = 0; bam_txn->rx_sgl_pos = 0; bam_txn->rx_sgl_start = 0; + bam_txn->last_data_desc = NULL; + bam_txn->wait_second_completion = false; sg_init_table(bam_txn->cmd_sgl, nandc->max_cwperpage * QPIC_PER_CW_CMD_SGL); sg_init_table(bam_txn->data_sgl, nandc->max_cwperpage * QPIC_PER_CW_DATA_SGL); + + reinit_completion(&bam_txn->txn_done); +} + +/* Callback for DMA descriptor completion */ +static void qpic_bam_dma_done(void *data) +{ + struct bam_transaction *bam_txn = data; + + /* + * In case of data transfer with NAND, 2 callbacks will be generated. + * One for command channel and another one for data channel. + * If current transaction has data descriptors + * (i.e. wait_second_completion is true), then set this to false + * and wait for second DMA descriptor completion. + */ + if (bam_txn->wait_second_completion) + bam_txn->wait_second_completion = false; + else + complete(&bam_txn->txn_done); } static inline struct qcom_nand_host *to_qcom_nand_host(struct nand_chip *chip) @@ -756,6 +791,12 @@ static int prepare_bam_async_desc(struct qcom_nand_controller *nandc, desc->dma_desc = dma_desc; + /* update last data/command descriptor */ + if (chan == nandc->cmd_chan) + bam_txn->last_cmd_desc = dma_desc; + else + bam_txn->last_data_desc = dma_desc; + list_add_tail(&desc->node, &nandc->desc_list); return 0; @@ -1273,10 +1314,20 @@ static int submit_descs(struct qcom_nand_controller *nandc) cookie = dmaengine_submit(desc->dma_desc); if (nandc->props->is_bam) { + bam_txn->last_cmd_desc->callback = qpic_bam_dma_done; + bam_txn->last_cmd_desc->callback_param = bam_txn; + if (bam_txn->last_data_desc) { + bam_txn->last_data_desc->callback = qpic_bam_dma_done; + bam_txn->last_data_desc->callback_param = bam_txn; + bam_txn->wait_second_completion = true; + } + dma_async_issue_pending(nandc->tx_chan); dma_async_issue_pending(nandc->rx_chan); + dma_async_issue_pending(nandc->cmd_chan); - if (dma_sync_wait(nandc->cmd_chan, cookie) != DMA_COMPLETE) + if (!wait_for_completion_timeout(&bam_txn->txn_done, + QPIC_NAND_COMPLETION_TIMEOUT)) return -ETIMEDOUT; } else { if (dma_sync_wait(nandc->chan, cookie) != DMA_COMPLETE) -- QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation