Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp133297rwi; Wed, 12 Oct 2022 17:20:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4WpCFE00n+rZ1QFGgK/hmTg2DwQgSHH0tbmy8HO0WVwfGoCoioT/Ap5SzwyF7VeZ35N5KX X-Received: by 2002:a17:907:2d8a:b0:78d:4448:e96c with SMTP id gt10-20020a1709072d8a00b0078d4448e96cmr24136211ejc.199.1665620401131; Wed, 12 Oct 2022 17:20:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665620401; cv=none; d=google.com; s=arc-20160816; b=iuW2Cv6fIsB1okIkwVEI2RR6uEK/SIYoNbMIS4njT+mXT6nmMfc5Uxd36cPrNy1mBH ZLTVQABRRcTj9zByTLBqABbAaawzy/PfH+6hG4enxdmb2/zFWUJqrDJKjWNolDZq5WDj aA0CuBs5VmicDtit/gSr9n0tE6MMVUnjWzjsEfbe4UjwDwOBXistuVUOIF6TV+qwoRgz OwpU9CNKwRhKG8sIQjjqkTHpakthv9ioSdsJ/4XsoogmMHmDS6R1ws3/PNY//NNhy+NF 0vkc80wdwMweXTq4k9BWr4Popc9xqzNHuxriegPpvnZgdP9YKE8EIIUdITV7NOm3VEfu tIgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=iGWVMjzuvGo5lj1+uXc7eAKNp3H0ETUNtDk9fSJTgWk=; b=E1NMZeCGmTHHssMkbT2sZW+u91bBTd50TH3d9iDxqYZXXb8+Ot4gUrsrn+2T/Io2Uz T6zJAHZa5JI26d9aA3NGgwf8YuEb86D4bd1GqEZBDPGtdx9xyFr4iQmA6nqKssiw0cSK Tqk5tNZXrIgaLVvUDdM2E9JTiqYUU9LBVdwovtj53VAPXB60lajTasZy356P8CJLVJmH Wh2rAgdRBfYryDzxzrQYw8vPjeFP/CkgID34Tx8mPMhggRamaSPq9OXSYVcKLqrR5qgz H8IhMRbvONZ5PuSd+7pl1mqdtvhIgtdoAxoN1iCOHz8iVhwy1gKBnNDXTLaM9aA53ZAU jnLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nL+Rp3ys; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j14-20020a50ed0e000000b00458b71488bdsi14530332eds.388.2022.10.12.17.19.35; Wed, 12 Oct 2022 17:20:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nL+Rp3ys; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S229879AbiJMARK (ORCPT + 99 others); Wed, 12 Oct 2022 20:17:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229843AbiJMAQp (ORCPT ); Wed, 12 Oct 2022 20:16:45 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A49E150492; Wed, 12 Oct 2022 17:16:21 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id C13EDB81CC2; Thu, 13 Oct 2022 00:16:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB0DDC43144; Thu, 13 Oct 2022 00:16:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665620178; bh=M+GQYKj7W9Q9eqQVTrqZvdk+oerpuJZZbVXvQ6MtdVg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nL+Rp3ysGAZgg0ZTSi6yJzyXGRTkgJ+vLhdBgwJZDRsKl7dtejo9PUmws+UGoqfaD i7jVEQZnpoGs4Q+OGPyoIFcu/bINVf7txcAjuXIo0YKWGWK4hFXUGQPjh8ft4M6OH7 ijBIDeR9QJ+Q5wBokF9uhbV11bJGTgZpSk6Wp1lQGsu30H4aEUz9VmeU0lDebasX9b FB8fQJ0D2wA3CPnn5DMEoyIgSrOjdMEzNssd02plGCF6nAy3MT3NyITZKy2YLLaLOE jghHu9Z+VGK+on5PB6WNhvUydEd5SkmXoVZeU/DJwiZkVWLYM3tBOhK3uDYKpugPO9 ET02XdYufPrcA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Vaishnav Achath , Peter Ujfalusi , Vinod Koul , Sasha Levin , dmaengine@vger.kernel.org Subject: [PATCH AUTOSEL 6.0 10/67] dmaengine: ti: k3-udma: Reset UDMA_CHAN_RT byte counters to prevent overflow Date: Wed, 12 Oct 2022 20:14:51 -0400 Message-Id: <20221013001554.1892206-10-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221013001554.1892206-1-sashal@kernel.org> References: <20221013001554.1892206-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vaishnav Achath [ Upstream commit 7c94dcfa8fcff2dba53915f1dabfee49a3df8b88 ] UDMA_CHAN_RT_*BCNT_REG stores the real-time channel bytecount statistics. These registers are 32-bit hardware counters and the driver uses these counters to monitor the operational progress status for a channel, when transferring more than 4GB of data it was observed that these counters overflow and completion calculation of a operation gets affected and the transfer hangs indefinitely. This commit adds changes to decrease the byte count for every complete transaction so that these registers never overflow and the proper byte count statistics is maintained for ongoing transaction by the RT counters. Earlier uc->bcnt used to maintain a count of the completed bytes at driver side, since the RT counters maintain the statistics of current transaction now, the maintenance of uc->bcnt is not necessary. Signed-off-by: Vaishnav Achath Acked-by: Peter Ujfalusi Link: https://lore.kernel.org/r/20220802054835.19482-1-vaishnav.a@ti.com Signed-off-by: Vinod Koul Signed-off-by: Sasha Levin --- drivers/dma/ti/k3-udma.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/drivers/dma/ti/k3-udma.c b/drivers/dma/ti/k3-udma.c index 2f0d2c68c93c..fcfcde947b30 100644 --- a/drivers/dma/ti/k3-udma.c +++ b/drivers/dma/ti/k3-udma.c @@ -300,8 +300,6 @@ struct udma_chan { struct udma_tx_drain tx_drain; - u32 bcnt; /* number of bytes completed since the start of the channel */ - /* Channel configuration parameters */ struct udma_chan_config config; @@ -757,6 +755,20 @@ static void udma_reset_rings(struct udma_chan *uc) } } +static void udma_decrement_byte_counters(struct udma_chan *uc, u32 val) +{ + if (uc->desc->dir == DMA_DEV_TO_MEM) { + udma_rchanrt_write(uc, UDMA_CHAN_RT_BCNT_REG, val); + udma_rchanrt_write(uc, UDMA_CHAN_RT_SBCNT_REG, val); + udma_rchanrt_write(uc, UDMA_CHAN_RT_PEER_BCNT_REG, val); + } else { + udma_tchanrt_write(uc, UDMA_CHAN_RT_BCNT_REG, val); + udma_tchanrt_write(uc, UDMA_CHAN_RT_SBCNT_REG, val); + if (!uc->bchan) + udma_tchanrt_write(uc, UDMA_CHAN_RT_PEER_BCNT_REG, val); + } +} + static void udma_reset_counters(struct udma_chan *uc) { u32 val; @@ -790,8 +802,6 @@ static void udma_reset_counters(struct udma_chan *uc) val = udma_rchanrt_read(uc, UDMA_CHAN_RT_PEER_BCNT_REG); udma_rchanrt_write(uc, UDMA_CHAN_RT_PEER_BCNT_REG, val); } - - uc->bcnt = 0; } static int udma_reset_chan(struct udma_chan *uc, bool hard) @@ -1115,7 +1125,7 @@ static void udma_check_tx_completion(struct work_struct *work) if (uc->desc) { struct udma_desc *d = uc->desc; - uc->bcnt += d->residue; + udma_decrement_byte_counters(uc, d->residue); udma_start(uc); vchan_cookie_complete(&d->vd); break; @@ -1168,7 +1178,7 @@ static irqreturn_t udma_ring_irq_handler(int irq, void *data) vchan_cyclic_callback(&d->vd); } else { if (udma_is_desc_really_done(uc, d)) { - uc->bcnt += d->residue; + udma_decrement_byte_counters(uc, d->residue); udma_start(uc); vchan_cookie_complete(&d->vd); } else { @@ -1204,7 +1214,7 @@ static irqreturn_t udma_udma_irq_handler(int irq, void *data) vchan_cyclic_callback(&d->vd); } else { /* TODO: figure out the real amount of data */ - uc->bcnt += d->residue; + udma_decrement_byte_counters(uc, d->residue); udma_start(uc); vchan_cookie_complete(&d->vd); } @@ -3809,7 +3819,6 @@ static enum dma_status udma_tx_status(struct dma_chan *chan, bcnt = udma_tchanrt_read(uc, UDMA_CHAN_RT_BCNT_REG); } - bcnt -= uc->bcnt; if (bcnt && !(bcnt % uc->desc->residue)) residue = 0; else -- 2.35.1