Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2347677imm; Wed, 3 Oct 2018 02:23:03 -0700 (PDT) X-Google-Smtp-Source: ACcGV61o+oH/6VkoQbyLjTo51jYBrmYhD8JWbY66kdNl9NPutcrHUemV3TXLgzRfYtYY6MkhxwDS X-Received: by 2002:a17:902:ac89:: with SMTP id h9-v6mr656045plr.174.1538558583177; Wed, 03 Oct 2018 02:23:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538558583; cv=none; d=google.com; s=arc-20160816; b=UQkT0lUvA5VqM1NHfAocEhO6KCsJRwylCg5at/IIFxOJ0SBmwWGqMSqs7sUNvcLNje 9pNinNd+/2stX88MZBLfzMGnSnawp6KljFIVS/7fQkavyKrbWUI+/4HbcTLWNEIGJUDr bxfZ3N3avU0Yn9oME3DtkSUtL470nji/iZgma1u/0dRxjO3s9ihAFdcY9UMMzmvxL/4v 6TExLEFh0g1IldH2H30iDw7pm6eEsCfgZuoTGrmNNmGdu2jWkX3EEcS+S6LsbYzPzY9L oNLNah/+x7FYg3sMSbg9oXs6vKBkroGVhtBHh0HUq1c+JUDPHWDgdALBCT1O83l/QBaV lVKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature; bh=73gtWI23d9vY3kaW6V4yMmFD4cqrBcxbooxZyxe25rc=; b=UfepELxGxPLRsf0qiP2MbMn0WKAlTQ62DDUcQgbv7tzpcmhn+g9k3EFOwCfnn5TU+5 YbWVFyIjQDDp9DmwyN25qHVZcc7HQ5vbSWL6X+XPTDgkhDcxi+Y1Tfp02DB3XXv3MBtA OkNEYCu50JaMWpSLtJlRX/+10RYMIGZYJtyn5opTHSc3wMiJ5vxr9Gg8q6eVdhc9aWf2 iwKQRjDvGnu29bhZmW+RlTc2JesXdbfejacUmeA9/4XlTt7hDZHyPNBzQDlPQGOvUQEM bumP4VNdGooqa0LXNtFP2mRP2mL2GAMg81iHmtTO9GlOxiBodskC2LJHsv7UTwbx579T Zi1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kBaOCR6p; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q10-v6si1112399pli.202.2018.10.03.02.22.47; Wed, 03 Oct 2018 02:23:03 -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=@linaro.org header.s=google header.b=kBaOCR6p; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727256AbeJCQKO (ORCPT + 99 others); Wed, 3 Oct 2018 12:10:14 -0400 Received: from mail-it1-f195.google.com ([209.85.166.195]:37371 "EHLO mail-it1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726216AbeJCQKO (ORCPT ); Wed, 3 Oct 2018 12:10:14 -0400 Received: by mail-it1-f195.google.com with SMTP id m9-v6so7841374ita.2 for ; Wed, 03 Oct 2018 02:22:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=73gtWI23d9vY3kaW6V4yMmFD4cqrBcxbooxZyxe25rc=; b=kBaOCR6pbNCf1GlMcGaTOlQVh13yuFN9ueBQ0DcAAqQ018iCAQm674PvtDZJVREVNI Ma+14Z8iJRkD9wOw3idsVlTbn6JZQssaKiWXmQE3NrI5jT0gBiDuHAIoUuTyPpfP70z1 Lh86vuUe9Rtxu1aU7KKC1UBZGQepKMGUj/+OU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=73gtWI23d9vY3kaW6V4yMmFD4cqrBcxbooxZyxe25rc=; b=TKhblBmMZH5+uh6qQQSUTM+0aXWhf/He7ABfdUJP/zlHZUEWgzyXKAXL++Uu1pMtSr MOOfVNZEG0W4d57/a4K79IB6PEUpTX5Vtt9UkkmVHomzktn1nEz99N8YdcrpO2rSvCsI Y8eJtOFouCoxr3XUK9wUWUju3ZZBZsluCEC8qUXXSI10dfwvDUSBOAqumSCcFWvfu6lc YX+pXjxud2rIBJFUuxb4l0aAku0ZVFzvCZ1lmK8QQ+z0jeb/wUkSi2sai7coi0uCf0CS KoNNUxBg/DBVEzjCrJIw1VVXoAUWfrTN0ypPd3wcfU4BAubU6MX5SZhPOUB3EMrWPwOu lhtA== X-Gm-Message-State: ABuFfogS2j8H0gAucvhurCmb2eqTFYSOnLMto5/Ukj9KRCR5qgWuRk1e S7Gm+D6TS7rTjFlstEworMQKpTeCax6LDtWXcclP1A== X-Received: by 2002:a02:c881:: with SMTP id m1-v6mr384906jao.43.1538558560769; Wed, 03 Oct 2018 02:22:40 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a02:3941:0:0:0:0:0 with HTTP; Wed, 3 Oct 2018 02:22:00 -0700 (PDT) In-Reply-To: <1538482167-13819-3-git-send-email-ludovic.Barre@st.com> References: <1538482167-13819-1-git-send-email-ludovic.Barre@st.com> <1538482167-13819-3-git-send-email-ludovic.Barre@st.com> From: Ulf Hansson Date: Wed, 3 Oct 2018 11:22:00 +0200 Message-ID: Subject: Re: [PATCH V4 02/25] mmc: mmci: create generic mmci_dma_setup To: Ludovic Barre Cc: Srinivas Kandagatla , Rob Herring , Maxime Coquelin , Alexandre Torgue , Benjamin Gaignard , Gerald Baeza , Loic Pallardy , Linux ARM , Linux Kernel Mailing List , DTML , "linux-mmc@vger.kernel.org" , linux-stm32@st-md-mailman.stormreply.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org + Srinivas [...] > #ifdef CONFIG_DMA_ENGINE > -static void mmci_dma_setup(struct mmci_host *host) > +static inline void mmci_dma_release(struct mmci_host *host); > + > +int mmci_dmae_setup(struct mmci_host *host) > { > const char *rxname, *txname; > > @@ -464,8 +485,12 @@ static void mmci_dma_setup(struct mmci_host *host) > host->mmc->max_seg_size = max_seg_size; > } > > - if (host->ops && host->ops->dma_setup) > - host->ops->dma_setup(host); > + if (!host->dma_tx_channel || !host->dma_rx_channel) { > + mmci_dma_release(host); This doesn't look right to me. The existing code allows a tx channel to be used, even if an rx channel could not be setup. It seems reasonable to still allow that. > + return -EINVAL; > + } > + > + return 0; > } > > /* > @@ -496,7 +521,7 @@ static void mmci_dma_unmap(struct mmci_host *host, struct mmc_data *data) > > static void mmci_dma_data_error(struct mmci_host *host) > { > - if (!dma_inprogress(host)) > + if (!host->use_dma || !dma_inprogress(host)) Adding the check for use_dma here seems like an unnecessary check, unless there is a reason for it due to following changes on top. In such case, please make it a part of the patch(es) where it's actually needed. > return; > > dev_err(mmc_dev(host->mmc), "error during DMA transfer!\n"); > @@ -514,7 +539,7 @@ static void mmci_dma_finalize(struct mmci_host *host, struct mmc_data *data) > u32 status; > int i; > > - if (!dma_inprogress(host)) > + if (!host->use_dma || !dma_inprogress(host)) Ditto. > return; > > /* Wait up to 1ms for the DMA to complete */ > @@ -546,6 +571,7 @@ static void mmci_dma_finalize(struct mmci_host *host, struct mmc_data *data) > if (status & MCI_RXDATAAVLBLMASK) { > dev_err(mmc_dev(host->mmc), "buggy DMA detected. Taking evasive action.\n"); > mmci_dma_release(host); > + host->use_dma = false; > } > > host->dma_in_progress = false; > @@ -640,6 +666,9 @@ static int mmci_dma_start_data(struct mmci_host *host, unsigned int datactrl) > int ret; > struct mmc_data *data = host->data; > > + if (!host->use_dma) > + return -EINVAL; > + > ret = mmci_dma_prep_data(host, host->data); > if (ret) > return ret; > @@ -674,6 +703,9 @@ static void mmci_get_next_data(struct mmci_host *host, struct mmc_data *data) > { > struct mmci_host_next *next = &host->next_data; > > + if (!host->use_dma) > + return; > + > WARN_ON(data->host_cookie && data->host_cookie != next->cookie); > WARN_ON(!data->host_cookie && (next->dma_desc || next->dma_chan)); > > @@ -689,7 +721,7 @@ static void mmci_pre_request(struct mmc_host *mmc, struct mmc_request *mrq) > struct mmc_data *data = mrq->data; > struct mmci_host_next *nd = &host->next_data; > > - if (!data) > + if (!host->use_dma || !data) > return; > > BUG_ON(data->host_cookie); > @@ -707,7 +739,7 @@ static void mmci_post_request(struct mmc_host *mmc, struct mmc_request *mrq, > struct mmci_host *host = mmc_priv(mmc); > struct mmc_data *data = mrq->data; > > - if (!data || !data->host_cookie) > + if (!host->use_dma || !data || !data->host_cookie) Ditto. > return; > > mmci_dma_unmap(host, data); > @@ -735,14 +767,14 @@ static void mmci_post_request(struct mmc_host *mmc, struct mmc_request *mrq, > } > } > > +static struct mmci_host_ops mmci_variant_ops = { > + .dma_setup = mmci_dmae_setup, > +}; > #else > /* Blank functions if the DMA engine is not available */ > static void mmci_get_next_data(struct mmci_host *host, struct mmc_data *data) > { > } > -static inline void mmci_dma_setup(struct mmci_host *host) > -{ > -} > > static inline void mmci_dma_release(struct mmci_host *host) > { > @@ -765,8 +797,14 @@ static inline int mmci_dma_start_data(struct mmci_host *host, unsigned int datac > #define mmci_pre_request NULL > #define mmci_post_request NULL > > +static struct mmci_host_ops mmci_variant_ops = {}; This seems a bit unnecessary. See more about why, below. > #endif > > +void mmci_variant_init(struct mmci_host *host) Looks like you should make mmci_variant_init() internal to mmci.c, thus covert it to static. Moreover, I suggest you define a "static inline void mmci_variant_init()", when CONFIG_DMA_ENGINE is unset. In that way you don't need to assign host->ops at all for this case. > +{ > + host->ops = &mmci_variant_ops; > +} > + > static void mmci_start_data(struct mmci_host *host, struct mmc_data *data) > { > struct variant_data *variant = host->variant; > diff --git a/drivers/mmc/host/mmci.h b/drivers/mmc/host/mmci.h > index 01e6c6b..f7fe80f 100644 > --- a/drivers/mmc/host/mmci.h > +++ b/drivers/mmc/host/mmci.h > @@ -273,7 +273,7 @@ struct variant_data { > > /* mmci variant callbacks */ > struct mmci_host_ops { > - void (*dma_setup)(struct mmci_host *host); > + int (*dma_setup)(struct mmci_host *host); > }; > > struct mmci_host_next { > @@ -323,6 +323,7 @@ struct mmci_host { > unsigned int size; > int (*get_rx_fifocnt)(struct mmci_host *h, u32 status, int remain); > > + u8 use_dma:1; > #ifdef CONFIG_DMA_ENGINE > /* DMA stuff */ > struct dma_chan *dma_current; > @@ -336,3 +337,7 @@ struct mmci_host { > #endif > }; > > +void mmci_variant_init(struct mmci_host *host); > + > +int mmci_dmae_setup(struct mmci_host *host); > + > diff --git a/drivers/mmc/host/mmci_qcom_dml.c b/drivers/mmc/host/mmci_qcom_dml.c > index be3fab5..c8d7592 100644 > --- a/drivers/mmc/host/mmci_qcom_dml.c > +++ b/drivers/mmc/host/mmci_qcom_dml.c > @@ -119,19 +119,22 @@ static int of_get_dml_pipe_index(struct device_node *np, const char *name) > } > > /* Initialize the dml hardware connected to SD Card controller */ > -static void qcom_dma_setup(struct mmci_host *host) > +static int qcom_dma_setup(struct mmci_host *host) > { > u32 config; > void __iomem *base; > int consumer_id, producer_id; > struct device_node *np = host->mmc->parent->of_node; > > + if (mmci_dmae_setup(host)) > + return -EINVAL; > + > consumer_id = of_get_dml_pipe_index(np, "tx"); > producer_id = of_get_dml_pipe_index(np, "rx"); > > if (producer_id < 0 || consumer_id < 0) { > host->variant->qcom_dml = false; > - return; > + return -EINVAL; Seems like you need to call a corresponding dma release function here, before returning the error code. Probably an "mmci_dmae_release()" needs to be implemented as a part of this change - and then also called from here. This is according to Srinivas recommendations, which means falling back to pio. As a matter of fact this also needs to be clearly stated in the changelog, as you are really also improving the behavior for the Qcom variant. Unfortunate, I am not able to test this as I don't have the HW (which I thought I had). Perhaps Srinivas can help, once we have something ready for him to test. > } > > base = host->base + DML_OFFSET; > @@ -175,6 +178,8 @@ static void qcom_dma_setup(struct mmci_host *host) > > /* Make sure dml initialization is finished */ > mb(); > + > + return 0; > } > > static struct mmci_host_ops qcom_variant_ops = { > -- > 2.7.4 > Kind regards Uffe