Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp817003imu; Fri, 4 Jan 2019 07:42:53 -0800 (PST) X-Google-Smtp-Source: AFSGD/Wfg70mXZfcDJre1E0XOdSH5VEC15t9jBBawmqeQPC1jaqUicvK6EGCjOcOfzMOsnr62+ze X-Received: by 2002:a62:c42:: with SMTP id u63mr51807523pfi.73.1546616452083; Fri, 04 Jan 2019 07:40:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546616452; cv=none; d=google.com; s=arc-20160816; b=cnG/2dquITkiDvZ6Ta3YcqEsgGXXtDedaN/rTth0ri1sUTyhSM7paFwxGo7ArzWxO4 tU8/V4+Y+jquVkPZI7ElJQWggzODpY8TGdDwugx+p4u+jUMdoYZdD1HmWpvFT3dwiifm FHJxofTDjLdnAteyJ5XC/ooLCDtVI7dXsILvUVgFYz5/pGZM8Sp6AjH1Lnl9JN9L3gYe CUZ7F+ZwnVvpLku14pGPMKwZlXrshGtQtDm+ZiHIMt58+3n0FKLmeVcAbwHwtQV64oOl 8RVa+D8KSA2qaKBqxHo25j9c/vynAjjKlCaSGM71ZZDAZSMDSobughU69Y7ri9J1Er5g w79Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=IjVVLCRQwETFoTVRDPAnMzGrVBPMrjvDFqVDthWSBsA=; b=M222FxCvykEPLG++H1GsqQxiJ0aiS39YzUYLxs1Ul+5tZPrO23JhUEGRBqBZNWliwT CWPNPyp3QgYiKduzwqhM71wSaXQq1pqSUXSjB4VScsrVOxX7ylFTB5JqtNbVJdklt2zO nhYlWotoecLc3IDC5Cc5gDvl0WVxxf05bR6BTbKj3DyqvQsf/56xynRyxQPePXUJIv2Q /kwt3lTjkriojEax2cJYCmi+thEtR4a2MhgerEFzVsrE4Mo+2bC6ypbl1gkbhizz8qHT betKujBXyUan7WTj4n8d34Q5hLz7VTQJwl+0kEWy0K+GSi+IliA32HNCKu/UiAVfc7FA Jmdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qVHBNgit; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s123si11405222pfb.274.2019.01.04.07.40.19; Fri, 04 Jan 2019 07:40:52 -0800 (PST) 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=@kernel.org header.s=default header.b=qVHBNgit; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726762AbfADMkQ (ORCPT + 99 others); Fri, 4 Jan 2019 07:40:16 -0500 Received: from mail.kernel.org ([198.145.29.99]:60982 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726296AbfADMkP (ORCPT ); Fri, 4 Jan 2019 07:40:15 -0500 Received: from localhost (unknown [171.76.109.220]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 698EA21871; Fri, 4 Jan 2019 12:40:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546605614; bh=hF2imHRmRVa4hohWZd0oeeeoZD7AkFa74s0AOUjVqHY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=qVHBNgit3oF3Pp1nAd3FQe2IN3pMtMaQdv8osfozcqtJ47dqquyGEig8FYRw42dgz 3d3lzosYYe7HrNJAaGo1G5Eli+69QPkoaFFn/58sd3Z9lj4hQssdWaPH9c8sYOclTq yQR1BOl4Xs3Yl6OL400KR/hrx7HoGfsj1mry/YHw= Date: Fri, 4 Jan 2019 18:08:36 +0530 From: Vinod Koul To: shun-chih.yu@mediatek.com Cc: Sean Wang , Rob Herring , Matthias Brugger , Dan Williams , dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, srv_wsdupstream@mediatek.com Subject: Re: [PATCH 2/2] dmaengine: mediatek: Add MediaTek Command-Queue DMA controller for MT6765 SoC Message-ID: <20190104123836.GB13372@vkoul-mobl.Dlink> References: <1545916258-18218-1-git-send-email-shun-chih.yu@mediatek.com> <1545916258-18218-3-git-send-email-shun-chih.yu@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1545916258-18218-3-git-send-email-shun-chih.yu@mediatek.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 27-12-18, 21:10, shun-chih.yu@mediatek.com wrote: > From: Shun-Chih Yu > This should be v4 of the patch series, why is it not tagged so? > MediaTek Command-Queue DMA controller (CQDMA) on MT6765 SoC is dedicated > to memory-to-memory transfer through queue based descriptor management. Have you tested this with dmatest, if so can you provide results of the test as well. > There are only 3 physical channels inside CQDMA, while the driver is > extended to support 32 virtual channels for multiple dma users to issue > dma requests onto the CQDMA simultaneously. > > Change-Id: I1e8d116c5ecbbc49190ffc925cb59a0d035d886b Please remove this from upstream, checkpatch would have warned that! > Signed-off-by: Shun-Chih Yu > Reviewed-by: Vinod Koul This is _WRONG_ I have never provided such tag, can you explain why this was added without my approval? > This controller provides the channels which is dedicated to > memory-to-memory transfer to offload from CPU through ring- > based descriptor management. > + > +config MTK_CQDMA > + tristate "MediaTek Command-Queue DMA controller support" Am not sure if I asked this earlier but, what is difference with HSDMA? > +/** > + * struct mtk_cqdma_pchan - The struct holding info describing physical > + * channel (PC) > + * @queue: Queue for the CVDs issued to this PC > + * @base: The mapped register I/O base of this PC > + * @irq: The IRQ that this PC are using > + * @refcnt: Track how many VCs are using this PC > + * @lock: Lock protect agaisting multiple VCs access PC Please maintain alignment! > + */ > +struct mtk_cqdma_pchan { > + struct list_head queue; > + void __iomem *base; > + u32 irq; > + refcount_t refcnt; > + > + /* lock to protect PC */ This is not required, you already have above ! > + spinlock_t lock; > +}; > + > +/** > + * struct mtk_cqdma_vchan - The struct holding info describing virtual > + * channel (VC) > + * @vc: An instance for struct virt_dma_chan > + * @pc: The pointer to the underlying PC > + * @issue_completion: The wait for all issued descriptors completited typo completited , am not sure why you need this > +static void mtk_dma_write(struct mtk_cqdma_pchan *pc, u32 reg, u32 val) > +{ > + writel_relaxed(val, pc->base + reg); Why is it relaxed one? > +static void mtk_cqdma_consume_work_queue(struct mtk_cqdma_pchan *pc) > +{ > + struct mtk_cqdma_vchan *cvc; > + struct mtk_cqdma_vdesc *cvd; > + size_t tlen; > + > + /* consume a CVD from PC's queue */ > + cvd = list_first_entry_or_null(&pc->queue, > + struct mtk_cqdma_vdesc, node); you can use vchan_next_desc() and also remove your own queue as virt-desc already implements that logic! > + if (unlikely(!cvd)) > + return; > + > + cvc = to_cqdma_vchan(cvd->ch); > + > + tlen = (cvd->len < MTK_CQDMA_MAX_LEN) ? cvd->len : MTK_CQDMA_MAX_LEN; > + cvd->len -= tlen; > + cvd->src += tlen; > + cvd->dest += tlen; > + > + /* check whether the CVD completed */ > + if (!cvd->len) { > + /* delete CVD from PC's queue */ > + list_del(&cvd->node); > + > + spin_lock(&cvc->vc.lock); > + > + /* add the VD into list desc_completed */ > + vchan_cookie_complete(&cvd->vd); > + > + /* setup completion if this VC is under synchronization */ > + if (cvc->issue_synchronize && !mtk_cqdma_is_vchan_active(cvc)) { > + complete(&cvc->issue_completion); > + cvc->issue_synchronize = false; > + } why do you need your own completion? > + > + spin_unlock(&cvc->vc.lock); > + } > + > + /* iterate on the next CVD if the current CVD completed */ > + if (!cvd->len) > + cvd = list_first_entry_or_null(&pc->queue, > + struct mtk_cqdma_vdesc, node); > + > + /* start the next transaction */ > + if (cvd) > + mtk_cqdma_start(pc, cvd); most of this logic looks reduandant to me. Virt-dma was designed to do exactly this, have N physical channels and share with M virt channels. Please reuse and remove code from this driver. > +static struct virt_dma_desc *mtk_cqdma_find_active_desc(struct dma_chan *c, > + dma_cookie_t cookie) > +{ > + struct mtk_cqdma_vchan *cvc = to_cqdma_vchan(c); > + struct virt_dma_desc *vd; > + unsigned long flags; > + > + spin_lock_irqsave(&cvc->pc->lock, flags); > + list_for_each_entry(vd, &cvc->pc->queue, node) > + if (vd->tx.cookie == cookie) { > + spin_unlock_irqrestore(&cvc->pc->lock, flags); > + return vd; > + } > + spin_unlock_irqrestore(&cvc->pc->lock, flags); > + > + list_for_each_entry(vd, &cvc->vc.desc_issued, node) > + if (vd->tx.cookie == cookie) > + return vd; vchan_find_desc() ?? > +static enum dma_status mtk_cqdma_tx_status(struct dma_chan *c, > + dma_cookie_t cookie, > + struct dma_tx_state *txstate) > +{ > + struct mtk_cqdma_vchan *cvc = to_cqdma_vchan(c); > + struct mtk_cqdma_vdesc *cvd; > + struct virt_dma_desc *vd; > + enum dma_status ret; > + unsigned long flags; > + size_t bytes = 0; > + > + ret = dma_cookie_status(c, cookie, txstate); > + if (ret == DMA_COMPLETE || !txstate) > + return ret; > + > + spin_lock_irqsave(&cvc->vc.lock, flags); > + vd = mtk_cqdma_find_active_desc(c, cookie); > + spin_unlock_irqrestore(&cvc->vc.lock, flags); > + > + if (vd) { > + cvd = to_cqdma_vdesc(vd); > + bytes = cvd->len; > + } > + > + dma_set_residue(txstate, bytes); Have you tested this and are able to report residue properly? > +static void mtk_cqdma_free_inactive_desc(struct dma_chan *c) > +{ > + struct virt_dma_chan *vc = to_virt_chan(c); > + unsigned long flags; > + LIST_HEAD(head); > + > + /* > + * set desc_allocated, desc_submitted, > + * and desc_issued as the candicates to be freed > + */ > + spin_lock_irqsave(&vc->lock, flags); > + list_splice_tail_init(&vc->desc_allocated, &head); > + list_splice_tail_init(&vc->desc_submitted, &head); > + list_splice_tail_init(&vc->desc_issued, &head); You missed completed and didnt use vchan_get_all_descriptors() ?? Looking at the driver, I feel things have been complicated a bit, you can reuse more code and routines in vchan layer and remove driver handling and make things with less bugs (used more tested generic code) and simpler to review .. Please do so in next rev and tag version properly! -- ~Vinod