Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp515894imm; Wed, 20 Jun 2018 02:03:58 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKI59iTKngT6/9N9sCN1FfJNtyD+RaCkTi1grLzcNdhU/d/awEduRDNNHig6owyCkJBQu65 X-Received: by 2002:a62:a054:: with SMTP id r81-v6mr21642022pfe.10.1529485438572; Wed, 20 Jun 2018 02:03:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529485438; cv=none; d=google.com; s=arc-20160816; b=MF7Dxvs1Nu9JxnvZukPn6vQmSvJZmoedVIvdxXfqptxpO+BT5JIMzS+lUyhcDPkGb1 mrVJAotMoOCTO0i4l25NNtGoqC81s+yXWp59Z7SM9xaV0e6Y2WxbHiNhDipbMLz8Fa+6 za4lODvns5SI88lYxyKMS8I+o8w23IXUMJV9rEOxedk9QaUyhdcWi53uyAo6yaK0mOXj 3x3YG6xSW/Idvhg5SWFD7h9EWy3K/sStQ3jPZ26CVH6j3EblBLI3+bmiOFNGEKw9QxyG Modt98pKi9Wo19aHrAkSHntgRrNrTzUw/QbjbibtUP+xOSIwXk5LUKCMCKRV6CGPaT47 aHzQ== 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=cDYti3Yg3Ku0VF0izEGp2ZdC+tepxPtTLW7VuJ0n5F0=; b=JdXJWwblDE9P5QljrS7mLERVut5cwIA7RCyjwsckP1lUEv4VEvJul8pWf5FuplCN89 x2wpswoEGYr2wNjNNSRtdwRW4qm9FJyPQY4LtzFQNqvkYpbLrQhcC141nFQOwqu8Kd9h otYlo1iBP9oKA1XpbIbyzh9AgmSNy0W4d6WHB4Jdkr1uf7X81TMoeGt6tsVNxTBGM9N6 W+6VwrHqsNjcV6+TFBwwxPp7je4TRqK7zQmNcqW9TxWThTRP7eKvdDIkimHEtB2FKvJ9 /VLyxBjHetQCYu4vVbuElqtvbA+R/tR7CHe7XPSVGxIf4Y2POszdfawc/kD+2Wtuc/Ze zjKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b="jqXdL/gC"; dkim=pass header.i=@codeaurora.org header.s=default header.b=a3iNlpg4; 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 m3-v6si2009709plt.71.2018.06.20.02.03.44; Wed, 20 Jun 2018 02:03: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="jqXdL/gC"; dkim=pass header.i=@codeaurora.org header.s=default header.b=a3iNlpg4; 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 S932686AbeFTI52 (ORCPT + 99 others); Wed, 20 Jun 2018 04:57:28 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:49610 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752792AbeFTIpD (ORCPT ); Wed, 20 Jun 2018 04:45:03 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 9164E60B74; Wed, 20 Jun 2018 07:28:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1529479698; bh=xRr6ihtnuxQbPnqLk2c4FGabgzxmW0+135vPXzAVX/g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jqXdL/gCdGAOA+JvGEA91I5x81Nl7cai6Pv8UJltGHE1dwT2SViC58MGmiHBazWYe mCcT4IAKgIcwiRCoK7bcibpfsmx6zBkJWQKA6QQ4kSW74kkCr76Yw0NpehJ0w7a04i X36KRj5YN13ItvzmOF90VT9wMOOYoZ+OtVJN5eec= 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 DDDB06085F; Wed, 20 Jun 2018 07:28:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1529479697; bh=xRr6ihtnuxQbPnqLk2c4FGabgzxmW0+135vPXzAVX/g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a3iNlpg4gLrQPaY2XJQ5TNGQPZaTXnB1NhFAA0h6mOlFMkHh48IeL+2hSXBSQs9ra CS4m1rMK19wSNFuodA7dq+i8Kq7MLLUn9R2HscL/OSpTV848azc87nk9996gcrsE4c 1ZETjSxoNXTR7zXOVBlbPjw8CBAhgLy7SpkjJlU8= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org DDDB06085F 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 , Miquel Raynal Cc: David Woodhouse , Brian Norris , Marek Vasut , Richard Weinberger , 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 v4 06/15] mtd: rawnand: qcom: wait for desc completion in all BAM channels Date: Wed, 20 Jun 2018 12:57:33 +0530 Message-Id: <1529479662-4026-7-git-send-email-absahu@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1529479662-4026-1-git-send-email-absahu@codeaurora.org> References: <1529479662-4026-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 Acked-by: Miquel Raynal Signed-off-by: Abhishek Sahu --- * Changes from v3: 1. NONE * 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 2375780..fc20149 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