From patchwork Fri Oct 12 09:44:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Dooks X-Patchwork-Id: 982954 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=codethink.co.uk Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42Wjcd3Np6z9sB7 for ; Fri, 12 Oct 2018 20:45:21 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728451AbeJLRQn (ORCPT ); Fri, 12 Oct 2018 13:16:43 -0400 Received: from imap1.codethink.co.uk ([176.9.8.82]:50561 "EHLO imap1.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728443AbeJLRQm (ORCPT ); Fri, 12 Oct 2018 13:16:42 -0400 Received: from [148.252.241.226] (helo=rainbowdash) by imap1.codethink.co.uk with esmtpsa (Exim 4.84_2 #1 (Debian)) id 1gAu09-00083X-GO; Fri, 12 Oct 2018 10:44:57 +0100 Received: from ben by rainbowdash with local (Exim 4.91) (envelope-from ) id 1gAu09-0005xh-3U; Fri, 12 Oct 2018 10:44:57 +0100 From: Ben Dooks To: dan.j.williams@intel.co, vkoul@kernel.org Cc: ldewangan@nvidia.com, dmaengine@vger.kernel.org, linux-tegra@vger.kernel.org, Ben Dooks Subject: [PATCH 1/6] dma: tegra: avoid overflow of byte tracking Date: Fri, 12 Oct 2018 10:44:49 +0100 Message-Id: <20181012094454.22841-2-ben.dooks@codethink.co.uk> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181012094454.22841-1-ben.dooks@codethink.co.uk> References: <20181012094454.22841-1-ben.dooks@codethink.co.uk> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The dma_desc->bytes_transferred counter tracks the number of bytes moved by the DMA channel. This is then used to calculate the information passed back in the in the tegra_dma_tx_status callback, which is usually fine. When the DMA channel is configured as continous, then the bytes_transferred counter will increase over time and eventually overflow to become negative so the residue count will become invalid and the ALSA sound-dma code will report invalid hardware pointer values to the application. This results in some users becoming confused about the playout position and putting audio data in the wrong place. To fix this issue, always ensure the bytes_transferred field is modulo the size of the request. We only do this for the case of the cyclic transfer done ISR as anyone attempting to move 2GiB of DMA data in one transfer is unlikely. Note, we don't fix the issue that we should /never/ transfer a negative number of bytes so we could make those fields unsigned. Signed-off-by: Ben Dooks --- drivers/dma/tegra20-apb-dma.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/dma/tegra20-apb-dma.c b/drivers/dma/tegra20-apb-dma.c index 9a558e30c461..8219ab88a507 100644 --- a/drivers/dma/tegra20-apb-dma.c +++ b/drivers/dma/tegra20-apb-dma.c @@ -636,7 +636,10 @@ static void handle_cont_sngl_cycle_dma_done(struct tegra_dma_channel *tdc, sgreq = list_first_entry(&tdc->pending_sg_req, typeof(*sgreq), node); dma_desc = sgreq->dma_desc; - dma_desc->bytes_transferred += sgreq->req_len; + /* if we dma for long enough the transfer count will wrap */ + dma_desc->bytes_transferred = + (dma_desc->bytes_transferred + sgreq->req_len) % + dma_desc->bytes_requested; /* Callback need to be call */ if (!dma_desc->cb_count) From patchwork Fri Oct 12 09:44:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Dooks X-Patchwork-Id: 982949 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=codethink.co.uk Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42WjcL0tnzz9s9N for ; Fri, 12 Oct 2018 20:45:06 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728439AbeJLRQj (ORCPT ); Fri, 12 Oct 2018 13:16:39 -0400 Received: from imap1.codethink.co.uk ([176.9.8.82]:50556 "EHLO imap1.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728416AbeJLRQj (ORCPT ); Fri, 12 Oct 2018 13:16:39 -0400 Received: from [148.252.241.226] (helo=rainbowdash) by imap1.codethink.co.uk with esmtpsa (Exim 4.84_2 #1 (Debian)) id 1gAu09-00083Y-Hw; Fri, 12 Oct 2018 10:44:57 +0100 Received: from ben by rainbowdash with local (Exim 4.91) (envelope-from ) id 1gAu09-0005xj-4R; Fri, 12 Oct 2018 10:44:57 +0100 From: Ben Dooks To: dan.j.williams@intel.co, vkoul@kernel.org Cc: ldewangan@nvidia.com, dmaengine@vger.kernel.org, linux-tegra@vger.kernel.org, Ben Dooks Subject: [PATCH 2/6] dma: tegra: make byte counters unsigned int Date: Fri, 12 Oct 2018 10:44:50 +0100 Message-Id: <20181012094454.22841-3-ben.dooks@codethink.co.uk> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181012094454.22841-1-ben.dooks@codethink.co.uk> References: <20181012094454.22841-1-ben.dooks@codethink.co.uk> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The buffer byte request length and counter are declared as signed integers but the values should never be below zero, so make these unsigned integers instead. Signed-off-by: Ben Dooks --- drivers/dma/tegra20-apb-dma.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/dma/tegra20-apb-dma.c b/drivers/dma/tegra20-apb-dma.c index 8219ab88a507..adfd918baedc 100644 --- a/drivers/dma/tegra20-apb-dma.c +++ b/drivers/dma/tegra20-apb-dma.c @@ -155,7 +155,7 @@ struct tegra_dma_channel_regs { */ struct tegra_dma_sg_req { struct tegra_dma_channel_regs ch_regs; - int req_len; + unsigned int req_len; bool configured; bool last_sg; struct list_head node; @@ -169,8 +169,8 @@ struct tegra_dma_sg_req { */ struct tegra_dma_desc { struct dma_async_tx_descriptor txd; - int bytes_requested; - int bytes_transferred; + unsigned int bytes_requested; + unsigned int bytes_transferred; enum dma_status dma_status; struct list_head node; struct list_head tx_list; From patchwork Fri Oct 12 09:44:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Dooks X-Patchwork-Id: 982951 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=codethink.co.uk Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42WjcP3GBlz9s3l for ; Fri, 12 Oct 2018 20:45:09 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728435AbeJLRQm (ORCPT ); Fri, 12 Oct 2018 13:16:42 -0400 Received: from imap1.codethink.co.uk ([176.9.8.82]:50558 "EHLO imap1.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728418AbeJLRQk (ORCPT ); Fri, 12 Oct 2018 13:16:40 -0400 Received: from [148.252.241.226] (helo=rainbowdash) by imap1.codethink.co.uk with esmtpsa (Exim 4.84_2 #1 (Debian)) id 1gAu09-00083Z-TB; Fri, 12 Oct 2018 10:44:58 +0100 Received: from ben by rainbowdash with local (Exim 4.91) (envelope-from ) id 1gAu09-0005xn-5F; Fri, 12 Oct 2018 10:44:57 +0100 From: Ben Dooks To: dan.j.williams@intel.co, vkoul@kernel.org Cc: ldewangan@nvidia.com, dmaengine@vger.kernel.org, linux-tegra@vger.kernel.org, Ben Dooks Subject: [PATCH 3/6] dma: tegra: fix incorrect case of DMA Date: Fri, 12 Oct 2018 10:44:51 +0100 Message-Id: <20181012094454.22841-4-ben.dooks@codethink.co.uk> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181012094454.22841-1-ben.dooks@codethink.co.uk> References: <20181012094454.22841-1-ben.dooks@codethink.co.uk> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The use of Dma is annoying, since it is an acronym so should be all upper case. Fix this throughout the driver. Signed-off-by: Ben Dooks --- drivers/dma/tegra20-apb-dma.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/dma/tegra20-apb-dma.c b/drivers/dma/tegra20-apb-dma.c index adfd918baedc..4f7d1e576d03 100644 --- a/drivers/dma/tegra20-apb-dma.c +++ b/drivers/dma/tegra20-apb-dma.c @@ -146,7 +146,7 @@ struct tegra_dma_channel_regs { }; /* - * tegra_dma_sg_req: Dma request details to configure hardware. This + * tegra_dma_sg_req: DMA request details to configure hardware. This * contains the details for one transfer to configure DMA hw. * The client's request for data transfer can be broken into multiple * sub-transfer as per requester details and hw support. @@ -574,7 +574,7 @@ static bool handle_continuous_head_request(struct tegra_dma_channel *tdc, struct tegra_dma_sg_req *hsgreq = NULL; if (list_empty(&tdc->pending_sg_req)) { - dev_err(tdc2dev(tdc), "Dma is running without req\n"); + dev_err(tdc2dev(tdc), "DMA is running without req\n"); tegra_dma_stop(tdc); return false; } @@ -922,7 +922,7 @@ static int get_transfer_param(struct tegra_dma_channel *tdc, return 0; default: - dev_err(tdc2dev(tdc), "Dma direction is not supported\n"); + dev_err(tdc2dev(tdc), "DMA direction is not supported\n"); return -EINVAL; } return -EINVAL; @@ -988,7 +988,7 @@ static struct dma_async_tx_descriptor *tegra_dma_prep_slave_sg( dma_desc = tegra_dma_desc_get(tdc); if (!dma_desc) { - dev_err(tdc2dev(tdc), "Dma descriptors not available\n"); + dev_err(tdc2dev(tdc), "DMA descriptors not available\n"); return NULL; } INIT_LIST_HEAD(&dma_desc->tx_list); @@ -1008,14 +1008,14 @@ static struct dma_async_tx_descriptor *tegra_dma_prep_slave_sg( if ((len & 3) || (mem & 3) || (len > tdc->tdma->chip_data->max_dma_count)) { dev_err(tdc2dev(tdc), - "Dma length/memory address is not supported\n"); + "DMA length/memory address is not supported\n"); tegra_dma_desc_put(tdc, dma_desc); return NULL; } sg_req = tegra_dma_sg_req_get(tdc); if (!sg_req) { - dev_err(tdc2dev(tdc), "Dma sg-req not available\n"); + dev_err(tdc2dev(tdc), "DMA sg-req not available\n"); tegra_dma_desc_put(tdc, dma_desc); return NULL; } @@ -1147,7 +1147,7 @@ static struct dma_async_tx_descriptor *tegra_dma_prep_dma_cyclic( while (remain_len) { sg_req = tegra_dma_sg_req_get(tdc); if (!sg_req) { - dev_err(tdc2dev(tdc), "Dma sg-req not available\n"); + dev_err(tdc2dev(tdc), "DMA sg-req not available\n"); tegra_dma_desc_put(tdc, dma_desc); return NULL; } From patchwork Fri Oct 12 09:44:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Dooks X-Patchwork-Id: 982952 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=codethink.co.uk Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42WjcQ1fBFz9s4Z for ; Fri, 12 Oct 2018 20:45:10 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728447AbeJLRQl (ORCPT ); Fri, 12 Oct 2018 13:16:41 -0400 Received: from imap1.codethink.co.uk ([176.9.8.82]:50559 "EHLO imap1.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728435AbeJLRQk (ORCPT ); Fri, 12 Oct 2018 13:16:40 -0400 Received: from [148.252.241.226] (helo=rainbowdash) by imap1.codethink.co.uk with esmtpsa (Exim 4.84_2 #1 (Debian)) id 1gAu09-00083a-MH; Fri, 12 Oct 2018 10:44:57 +0100 Received: from ben by rainbowdash with local (Exim 4.91) (envelope-from ) id 1gAu09-0005xq-6N; Fri, 12 Oct 2018 10:44:57 +0100 From: Ben Dooks To: dan.j.williams@intel.co, vkoul@kernel.org Cc: ldewangan@nvidia.com, dmaengine@vger.kernel.org, linux-tegra@vger.kernel.org, Ben Dooks Subject: [PATCH 4/6] dma: tegra: add accurate reporting of dma state Date: Fri, 12 Oct 2018 10:44:52 +0100 Message-Id: <20181012094454.22841-5-ben.dooks@codethink.co.uk> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181012094454.22841-1-ben.dooks@codethink.co.uk> References: <20181012094454.22841-1-ben.dooks@codethink.co.uk> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The tx_status callback does not report the state of the transfer beyond complete segments. This causes problems with users such as ALSA when applications want to know accurately how much data has been moved. This patch addes a function tegra_dma_update_residual() to query the hardware and modify the residual information accordinly. It takes into account any hardware issues when trying to read the state, such as delays between finishing a buffer and signalling the interrupt. Signed-off-by: Ben Dooks --- drivers/dma/tegra20-apb-dma.c | 92 ++++++++++++++++++++++++++++++++--- 1 file changed, 86 insertions(+), 6 deletions(-) diff --git a/drivers/dma/tegra20-apb-dma.c b/drivers/dma/tegra20-apb-dma.c index 4f7d1e576d03..ce2888f67254 100644 --- a/drivers/dma/tegra20-apb-dma.c +++ b/drivers/dma/tegra20-apb-dma.c @@ -802,6 +802,90 @@ static int tegra_dma_terminate_all(struct dma_chan *dc) return 0; } +static unsigned int tegra_dma_update_residual(struct tegra_dma_channel *tdc, + struct tegra_dma_sg_req *sg_req, + struct tegra_dma_desc *dma_desc, + unsigned int residual) +{ + unsigned long status = 0x0; + unsigned long wcount; + unsigned long ahbptr; + unsigned long tmp = 0x0; + unsigned int result; + int retries = TEGRA_APBDMA_BURST_COMPLETE_TIME * 10; + int done; + + /* if we're not the current request, then don't alter the residual */ + if (sg_req != list_first_entry(&tdc->pending_sg_req, + struct tegra_dma_sg_req, node)) { + result = residual; + ahbptr = 0xffffffff; + goto done; + } + + /* loop until we have a reliable result for residual */ + do { + ahbptr = tdc_read(tdc, TEGRA_APBDMA_CHAN_AHBPTR); + status = tdc_read(tdc, TEGRA_APBDMA_CHAN_STATUS); + tmp = tdc_read(tdc, 0x08); /* total count for debug */ + + /* check status, if channel isn't busy then skip */ + if (!(status & TEGRA_APBDMA_STATUS_BUSY)) { + result = residual; + break; + } + + /* if we've got an interrupt pending on the channel, don't + * try and deal with the residue as the hardware has likely + * moved on to the next buffer. return all data moved. + */ + if (status & TEGRA_APBDMA_STATUS_ISE_EOC) { + result = residual - sg_req->req_len; + break; + } + + if (tdc->tdma->chip_data->support_separate_wcount_reg) + wcount = tdc_read(tdc, TEGRA_APBDMA_CHAN_WORD_TRANSFER); + else + wcount = status; + + /* If the request is at the full point, then there is a + * chance that we have read the status register in the + * middle of the hardware reloading the next buffer. + * + * The sequence seems to be at the end of the buffer, to + * load the new word count before raising the EOC flag (or + * changing the ping-pong flag which could have also been + * used to determine a new buffer). This means there is a + * small window where we cannot determine zero-done for the + * current buffer, or moved to next buffer. + * + * If done shows 0, then retry the load, as it may hit the + * above hardware race. We will either get a new value which + * is from the first buffer, or we get an EOC (new buffer) + * or both a new value and an EOC... + */ + done = get_current_xferred_count(tdc, sg_req, wcount); + if (done != 0) { + result = residual - done; + break; + } + + ndelay(100); + } while (--retries > 0); + + if (retries <= 0) { + dev_err(tdc2dev(tdc), "timeout waiting for dma load\n"); + result = residual; + } + +done: + dev_dbg(tdc2dev(tdc), "residual: req %08lx, ahb@%08lx, wcount %08lx, done %d\n", + sg_req->ch_regs.ahb_ptr, ahbptr, wcount, done); + + return result; +} + static enum dma_status tegra_dma_tx_status(struct dma_chan *dc, dma_cookie_t cookie, struct dma_tx_state *txstate) { @@ -843,6 +927,7 @@ static enum dma_status tegra_dma_tx_status(struct dma_chan *dc, residual = dma_desc->bytes_requested - (dma_desc->bytes_transferred % dma_desc->bytes_requested); + residual = tegra_dma_update_residual(tdc, sg_req, dma_desc, residual); dma_set_residue(txstate, residual); } @@ -1436,12 +1521,7 @@ static int tegra_dma_probe(struct platform_device *pdev) BIT(DMA_SLAVE_BUSWIDTH_4_BYTES) | BIT(DMA_SLAVE_BUSWIDTH_8_BYTES); tdma->dma_dev.directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV); - /* - * XXX The hardware appears to support - * DMA_RESIDUE_GRANULARITY_BURST-level reporting, but it's - * only used by this driver during tegra_dma_terminate_all() - */ - tdma->dma_dev.residue_granularity = DMA_RESIDUE_GRANULARITY_SEGMENT; + tdma->dma_dev.residue_granularity = DMA_RESIDUE_GRANULARITY_BURST; tdma->dma_dev.device_config = tegra_dma_slave_config; tdma->dma_dev.device_terminate_all = tegra_dma_terminate_all; tdma->dma_dev.device_tx_status = tegra_dma_tx_status; From patchwork Fri Oct 12 09:44:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Dooks X-Patchwork-Id: 982950 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=codethink.co.uk Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42WjcN4l4sz9s9J for ; Fri, 12 Oct 2018 20:45:08 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728442AbeJLRQk (ORCPT ); Fri, 12 Oct 2018 13:16:40 -0400 Received: from imap1.codethink.co.uk ([176.9.8.82]:50557 "EHLO imap1.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728417AbeJLRQk (ORCPT ); Fri, 12 Oct 2018 13:16:40 -0400 Received: from [148.252.241.226] (helo=rainbowdash) by imap1.codethink.co.uk with esmtpsa (Exim 4.84_2 #1 (Debian)) id 1gAu09-00083c-N7; Fri, 12 Oct 2018 10:44:57 +0100 Received: from ben by rainbowdash with local (Exim 4.91) (envelope-from ) id 1gAu09-0005xt-7h; Fri, 12 Oct 2018 10:44:57 +0100 From: Ben Dooks To: dan.j.williams@intel.co, vkoul@kernel.org Cc: ldewangan@nvidia.com, dmaengine@vger.kernel.org, linux-tegra@vger.kernel.org, Ben Dooks , Ingo Molnar , Steven Rostedt Subject: [PATCH 5/6] dma: tegra: add tracepoints to driver Date: Fri, 12 Oct 2018 10:44:53 +0100 Message-Id: <20181012094454.22841-6-ben.dooks@codethink.co.uk> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181012094454.22841-1-ben.dooks@codethink.co.uk> References: <20181012094454.22841-1-ben.dooks@codethink.co.uk> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Add some trace-points to the driver to allow for debuging via the trace pipe. Signed-off-by: Ben Dooks --- Cc: Ingo Molnar (maintainer:TRACING) Cc: Steven Rostedt (maintainer:TRACING) --- drivers/dma/tegra20-apb-dma.c | 8 ++++ include/trace/events/tegra_apb_dma.h | 63 ++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 include/trace/events/tegra_apb_dma.h diff --git a/drivers/dma/tegra20-apb-dma.c b/drivers/dma/tegra20-apb-dma.c index ce2888f67254..96095a3b7edd 100644 --- a/drivers/dma/tegra20-apb-dma.c +++ b/drivers/dma/tegra20-apb-dma.c @@ -38,6 +38,9 @@ #include "dmaengine.h" +#define CREATE_TRACE_POINTS +#include + #define TEGRA_APBDMA_GENERAL 0x0 #define TEGRA_APBDMA_GENERAL_ENABLE BIT(31) @@ -672,6 +675,8 @@ static void tegra_dma_tasklet(unsigned long data) dmaengine_desc_get_callback(&dma_desc->txd, &cb); cb_count = dma_desc->cb_count; dma_desc->cb_count = 0; + trace_tegra_dma_complete_cb(&tdc->dma_chan, cb_count, + cb.callback); spin_unlock_irqrestore(&tdc->lock, flags); while (cb_count--) dmaengine_desc_callback_invoke(&cb, NULL); @@ -688,6 +693,7 @@ static irqreturn_t tegra_dma_isr(int irq, void *dev_id) spin_lock_irqsave(&tdc->lock, flags); + trace_tegra_dma_isr(&tdc->dma_chan, irq); status = tdc_read(tdc, TEGRA_APBDMA_CHAN_STATUS); if (status & TEGRA_APBDMA_STATUS_ISE_EOC) { tdc_write(tdc, TEGRA_APBDMA_CHAN_STATUS, status); @@ -931,6 +937,8 @@ static enum dma_status tegra_dma_tx_status(struct dma_chan *dc, dma_set_residue(txstate, residual); } + trace_tegra_dma_tx_status(&tdc->dma_chan, cookie, + txstate ? txstate->residue : -1); spin_unlock_irqrestore(&tdc->lock, flags); return ret; } diff --git a/include/trace/events/tegra_apb_dma.h b/include/trace/events/tegra_apb_dma.h new file mode 100644 index 000000000000..80d6f0cf4c36 --- /dev/null +++ b/include/trace/events/tegra_apb_dma.h @@ -0,0 +1,63 @@ +#if !defined(_TRACE_TEGRA_APB_DMA_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_TEGRA_APM_DMA_H + +#include +#include + +#undef TRACE_SYSTEM +#define TRACE_SYSTEM tegra_apb_dma + +TRACE_EVENT(tegra_dma_tx_status, + TP_PROTO(struct dma_chan *dc, s32 cookie, u32 residue), + TP_ARGS(dc, cookie, residue), + TP_STRUCT__entry( + __field(struct dma_chan *, dc) + __field(__s32, cookie) + __field(__u32, residue) + ), + TP_fast_assign( + __entry->dc = dc; + __entry->cookie = cookie; + __entry->residue = residue; + ), + TP_printk("channel %s: dma cookie %d, residue %u", + dev_name(&__entry->dc->dev->device), + __entry->cookie, __entry->residue) +); + +TRACE_EVENT(tegra_dma_complete_cb, + TP_PROTO(struct dma_chan *dc, int count, void *ptr), + TP_ARGS(dc, count, ptr), + TP_STRUCT__entry( + __field(struct dma_chan *, dc) + __field(int, count) + __field(void *, ptr) + ), + TP_fast_assign( + __entry->dc = dc; + __entry->count = count; + __entry->ptr = ptr; + ), + TP_printk("channel %s: done %d, ptr %p", + dev_name(&__entry->dc->dev->device), + __entry->count, __entry->ptr) +); + +TRACE_EVENT(tegra_dma_isr, + TP_PROTO(struct dma_chan *dc, int irq), + TP_ARGS(dc, irq), + TP_STRUCT__entry( + __field(struct dma_chan *, dc) + __field(int, irq) + ), + TP_fast_assign( + __entry->dc = dc; + __entry->irq = irq; + ), + TP_printk("%s: irq %d\n", dev_name(&__entry->dc->dev->device), + __entry->irq)); + +#endif /* _TRACE_TEGRADMA_H */ + +/* This part must be outside protection */ +#include From patchwork Fri Oct 12 09:44:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Dooks X-Patchwork-Id: 982953 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=codethink.co.uk Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42Wjcc09ypz9s9J for ; Fri, 12 Oct 2018 20:45:20 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728418AbeJLRQn (ORCPT ); Fri, 12 Oct 2018 13:16:43 -0400 Received: from imap1.codethink.co.uk ([176.9.8.82]:50563 "EHLO imap1.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728417AbeJLRQm (ORCPT ); Fri, 12 Oct 2018 13:16:42 -0400 Received: from [148.252.241.226] (helo=rainbowdash) by imap1.codethink.co.uk with esmtpsa (Exim 4.84_2 #1 (Debian)) id 1gAu09-00083e-Np; Fri, 12 Oct 2018 10:44:57 +0100 Received: from ben by rainbowdash with local (Exim 4.91) (envelope-from ) id 1gAu09-0005xw-8q; Fri, 12 Oct 2018 10:44:57 +0100 From: Ben Dooks To: dan.j.williams@intel.co, vkoul@kernel.org Cc: ldewangan@nvidia.com, dmaengine@vger.kernel.org, linux-tegra@vger.kernel.org, Ben Dooks , Ingo Molnar , Steven Rostedt Subject: [PATCH 6/6] dma: tegra: add tracepoint for residual update Date: Fri, 12 Oct 2018 10:44:54 +0100 Message-Id: <20181012094454.22841-7-ben.dooks@codethink.co.uk> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181012094454.22841-1-ben.dooks@codethink.co.uk> References: <20181012094454.22841-1-ben.dooks@codethink.co.uk> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Add a tracepoint in the residual update instead of using dev_dbg() to allow debugging via the trace pipe. Signed-off-by: Ben Dooks --- Cc: Ingo Molnar (maintainer:TRACING) Cc: Steven Rostedt (maintainer:TRACING) --- drivers/dma/tegra20-apb-dma.c | 5 ++--- include/trace/events/tegra_apb_dma.h | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/drivers/dma/tegra20-apb-dma.c b/drivers/dma/tegra20-apb-dma.c index 96095a3b7edd..495cda6c21b9 100644 --- a/drivers/dma/tegra20-apb-dma.c +++ b/drivers/dma/tegra20-apb-dma.c @@ -886,9 +886,8 @@ static unsigned int tegra_dma_update_residual(struct tegra_dma_channel *tdc, } done: - dev_dbg(tdc2dev(tdc), "residual: req %08lx, ahb@%08lx, wcount %08lx, done %d\n", - sg_req->ch_regs.ahb_ptr, ahbptr, wcount, done); - + trace_tegra_dma_tx_state(&tdc->dma_chan, ahbptr, status, result, + tmp, residual); return result; } diff --git a/include/trace/events/tegra_apb_dma.h b/include/trace/events/tegra_apb_dma.h index 80d6f0cf4c36..a686f98a9c8b 100644 --- a/include/trace/events/tegra_apb_dma.h +++ b/include/trace/events/tegra_apb_dma.h @@ -43,6 +43,33 @@ TRACE_EVENT(tegra_dma_complete_cb, __entry->count, __entry->ptr) ); +TRACE_EVENT(tegra_dma_tx_state, + TP_PROTO(struct dma_chan *dc, unsigned long ahb, + unsigned long wc, unsigned int done, + unsigned long byte_count, unsigned int residual), + TP_ARGS(dc, ahb, wc, done, byte_count, residual), + TP_STRUCT__entry( + __field(struct dma_chan *, dc) + __field(unsigned long, ahb) + __field(unsigned long, wc) + __field(unsigned long, done) + __field(unsigned int, residual) + __field(unsigned long, byte_count) + ), + TP_fast_assign( + __entry->dc = dc; + __entry->ahb = ahb; + __entry->wc = wc; + __entry->done = done; + __entry->residual = residual; + __entry->byte_count = byte_count; + ), + TP_printk("%s: txresidual: ahb %08lx wc %08lx => done %lu bc %lu residual %u", + dev_name(&__entry->dc->dev->device), + __entry->ahb, __entry->wc, __entry->done, + __entry->byte_count, __entry->residual) +); + TRACE_EVENT(tegra_dma_isr, TP_PROTO(struct dma_chan *dc, int irq), TP_ARGS(dc, irq),