Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3872065ybi; Tue, 18 Jun 2019 07:50:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqxFYFpmHfsnz8CmNgkDFewLlTgeVW56Mg8XSSIVH1iAwZTCDATU5z3nZJ1kEbZ5HPFwnLOJ X-Received: by 2002:a63:514:: with SMTP id 20mr3015890pgf.272.1560869413973; Tue, 18 Jun 2019 07:50:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560869413; cv=none; d=google.com; s=arc-20160816; b=ADr1LcFVJAa6VMce9BJN682swPwYvvI7uFUIs+vl+gOtgUcSyCJDb1oaBAXIrL0+Qv Ngv1LkZguqpWPaDwM1cuiNamSxYEHjBKB6kEJejIlZkCNAfNy+XHQkjoDBFDAQ7S1oNl cZHafaMK2iBP3fxBgkiQ7lODGDEa4w0h8arSxtgtS0PVPARoPWB09yIO8YtO7Cmxhzgy jB843AZU1OWkiTFbxB/qlK5LeoqUdb/Jeire7VIUhdgR0f1kiMA1WTSbls+MZdeXRTuT 1S35LduA92lS8jp7/TeoCi1LimloJlknE8ghZW4srLHd0XzyPp0ulPDu5clqLgVMVD4G SmRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=Bw9Az1sDvYftv6OoenbcNn/WFNLrPeZPeUya6SiZhJE=; b=tTDHOi+f9g3aKrNU8w9sI8rTDM3EkswnFDsvwZAWr1tSZKYqoLpW6dVVP2UYGVUgdy clyCogyPM2Fs4wuNjgr40cyX2YsuQyx9UtOvnpMWHdtO/heyFHrust7HmBlkfHLtl6f3 g4KrEc5bAObR07LERN3859VYKrGZf1tJ++k9sIkbHz/J1e2YcGv07cGHwPabVgRIMxtl r3smGmHgAxqIUq0CvVe8rh2ElSzPEVF/4siiA9BPKQ3rzNGO3V+VKyZF+OyLIJf8wHFP CCZTWiS9yIBg2vRcy+7CoGC4hkqc5l963Cex437ee/aADsGqBMvYmyWlI4BbI68tO2ZJ SjwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=udv6A62f; 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 u69si382550pgc.531.2019.06.18.07.49.58; Tue, 18 Jun 2019 07:50:13 -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=udv6A62f; 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 S1729586AbfFROtx (ORCPT + 99 others); Tue, 18 Jun 2019 10:49:53 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:38091 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729406AbfFROtx (ORCPT ); Tue, 18 Jun 2019 10:49:53 -0400 Received: by mail-wm1-f66.google.com with SMTP id s15so3576502wmj.3 for ; Tue, 18 Jun 2019 07:49:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=Bw9Az1sDvYftv6OoenbcNn/WFNLrPeZPeUya6SiZhJE=; b=udv6A62ft/6+VkDzxa/PEOUwv3/ZITu7g/8w9iRR9ReSzG9lypxa62Pi4r9SN/Hhll FxiwNMpXKfogjWbeqkzE2jV1lTTjRsI5u2Ncn8o1StwJg3GwNsiQ0HTrn5K0u/7RXh8S e1Q4tcAQsalTh9bGi3YD4OfZYOGVt+uw3PnER43NYbFCThzlpqmKHcTqPQw3ZVPe9tWG PH1NVJSU5xUCVBCrz1s0Olr29daX709FTtmsAxJ+DWL2f1e3r2fWhIlvai+QmhWcokqz +sesl3yqFuJNNFqf70VfLr0azantLnGN1l0EabSUQ1F3+PVqxu2f2zGH9FeOGs9C6sdr aP+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Bw9Az1sDvYftv6OoenbcNn/WFNLrPeZPeUya6SiZhJE=; b=dTLwo/wZMTxMd1TxTYLhGokmpxYfsEWCliP9sPAyDBdbNNXL7kQIo82ylUPPSF7ay/ VmNmo5BqdbirJTlIomEjmY+c8WNO81trG2JUIeMYZW/6S1aRtSfIFd0FzuUkihCBhpDb d+fIr/n2O/IBfQWwZCptf4yixunBPtLf8BU/XyYfcoUxqMjdrU/pFNetjONinRqVRFFJ mIDS0GHc+SFhB/S2cKre1ggbSqML6DAqtEPgqo2AsZsTLTNipserr/VaO1hioe1tDIrT H4JmKQ+26KSlXlm/hWDD3W7LCxS1f+mus7AO1sUkn4pg+zHeEPXGuNX7aHZBvgzy/2U6 1aDw== X-Gm-Message-State: APjAAAW/YUaJw5hisylEzDLAE5dYIb579OddOuUfjV/Uan516llAPA0Q pGCbYBbdGsXqZUZiNUmmxxGdbg== X-Received: by 2002:a7b:c74a:: with SMTP id w10mr3834115wmk.99.1560869390770; Tue, 18 Jun 2019 07:49:50 -0700 (PDT) Received: from [192.168.86.34] (cpc89974-aztw32-2-0-cust43.18-1.cable.virginm.net. [86.30.250.44]) by smtp.googlemail.com with ESMTPSA id j189sm3881237wmb.48.2019.06.18.07.49.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Jun 2019 07:49:50 -0700 (PDT) Subject: Re: [PATCH] dmaengine: qcom-bam: fix circular buffer handling To: Sricharan R , vkoul@kernel.org Cc: dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org References: <20190614142012.31384-1-srinivas.kandagatla@linaro.org> From: Srinivas Kandagatla Message-ID: Date: Tue, 18 Jun 2019 15:49:49 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Sricharan, On 18/06/2019 08:13, Sricharan R wrote: > Hi Srini, > > On 6/14/2019 7:50 PM, Srinivas Kandagatla wrote: >> For some reason arguments to most of the circular buffers >> macros are used in reverse, tail is used for head and vice versa. >> >> This leads to bam thinking that there is an extra descriptor at the >> end and leading to retransmitting descriptor which was not scheduled >> by any driver. This happens after MAX_DESCRIPTORS (4096) are scheduled >> and done, so most of the drivers would not notice this, unless they are >> heavily using bam dma. Originally found this issue while testing >> SoundWire over SlimBus on DB845c which uses DMA very heavily for >> read/writes. >> >> Signed-off-by: Srinivas Kandagatla >> --- >> drivers/dma/qcom/bam_dma.c | 9 ++++----- >> 1 file changed, 4 insertions(+), 5 deletions(-) >> >> diff --git a/drivers/dma/qcom/bam_dma.c b/drivers/dma/qcom/bam_dma.c >> index cb860cb53c27..43d7b0a9713a 100644 >> --- a/drivers/dma/qcom/bam_dma.c >> +++ b/drivers/dma/qcom/bam_dma.c >> @@ -350,8 +350,8 @@ static const struct reg_offset_data bam_v1_7_reg_info[] = { >> #define BAM_DESC_FIFO_SIZE SZ_32K >> #define MAX_DESCRIPTORS (BAM_DESC_FIFO_SIZE / sizeof(struct bam_desc_hw) - 1) >> #define BAM_FIFO_SIZE (SZ_32K - 8) >> -#define IS_BUSY(chan) (CIRC_SPACE(bchan->tail, bchan->head,\ >> - MAX_DESCRIPTORS + 1) == 0) >> +#define IS_BUSY(chan) (CIRC_SPACE(bchan->head, bchan->tail,\ >> + MAX_DESCRIPTORS) == 0) >> >> struct bam_chan { >> struct virt_dma_chan vc; >> @@ -806,7 +806,7 @@ static u32 process_channel_irqs(struct bam_device *bdev) >> offset /= sizeof(struct bam_desc_hw); >> >> /* Number of bytes available to read */ >> - avail = CIRC_CNT(offset, bchan->head, MAX_DESCRIPTORS + 1); >> + avail = CIRC_CNT(bchan->head, offset, MAX_DESCRIPTORS); >> > one question, so MAX_DESCRIPTORS is already a mask, > #define MAX_DESCRIPTORS (BAM_DESC_FIFO_SIZE / sizeof(struct bam_desc_hw) - 1) > > CIRC_CNT/SPACE macros also does a size - 1, so would it not be a problem if we > just pass MAX_DESCRIPTORS ? Thanks for looking at this, TBH, usage of CIRC_* macros is only valid for power-of-2 buffers, In bam case MAX_DESCRIPTORS is 4095. Am really not sure why 8 bytes have been removed from fifo data buffer size. So basically usage of these macros is incorrect in bam case, this need to be fixed properly. Do you agree? Vinod, can you hold off with this patch, I will try to find some time this week to cook up a better patch removing the usage of these macros. thanks, srini > > Regards, > Sricharan > >> list_for_each_entry_safe(async_desc, tmp, >> &bchan->desc_list, desc_node) { >> @@ -997,8 +997,7 @@ static void bam_start_dma(struct bam_chan *bchan) >> bam_apply_new_config(bchan, async_desc->dir); >> >> desc = async_desc->curr_desc; >> - avail = CIRC_SPACE(bchan->tail, bchan->head, >> - MAX_DESCRIPTORS + 1); >> + avail = CIRC_SPACE(bchan->head, bchan->tail, MAX_DESCRIPTORS); >> >> if (async_desc->num_desc > avail) >> async_desc->xfer_len = avail; >> >