From patchwork Mon Aug 22 22:56:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 74478 Delivered-To: patches@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1802590qga; Mon, 22 Aug 2016 15:57:08 -0700 (PDT) X-Received: by 10.66.79.138 with SMTP id j10mr47232376pax.60.1471906623076; Mon, 22 Aug 2016 15:57:03 -0700 (PDT) Return-Path: Received: from mail-pa0-x22b.google.com (mail-pa0-x22b.google.com. [2607:f8b0:400e:c03::22b]) by mx.google.com with ESMTPS id d28si339713pfb.283.2016.08.22.15.57.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Aug 2016 15:57:03 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c03::22b as permitted sender) client-ip=2607:f8b0:400e:c03::22b; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c03::22b as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by mail-pa0-x22b.google.com with SMTP id ti13so41656253pac.0 for ; Mon, 22 Aug 2016 15:57:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=NjtbKJ1+LY5X69XPzHe8osWtJYHGnDgz3dacrTivms4=; b=Ey6LgBHzxsXuXqJV2JYum/vCHGRDQLiBVk0EeAP3u7f7bZzBLq8/c7vW1JrqbC0USS 1e9i29hSn0nFM5CwDqbw+vRJyUxN8FLqSzrobbETqbcxgJ9mbWylYnD0wAZSxRNnPqs8 uNleSYxS1GnUZBGsxq1Wxz+DMFi8TxoY/QWSA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=NjtbKJ1+LY5X69XPzHe8osWtJYHGnDgz3dacrTivms4=; b=SOLHR4v532L0r3/Ts1JTxn1lLbtwaK/eRecMB1UffSoC9Bq/ERMGEJlpr4CuCF2PKg 8m4sPsbOuuT53Oy4o1PWUrokSUM0hHXygSrWXPVccP3iFfGlr6FSVm4aYlGLppOzhmOu u/q/WwBs4Pthj/wJKwu4+0aWSpC5hHhamrMev0Yl+lkGBpB3qKxUhWnQCWhTDSoOyk+j 6WYlDj5SRqVC0hr8/ncYhpInoeYZ/vm8MnnXch7g9zR/TcYNsaDITkmXb7FYX6bcMExZ uJoRp23AEQGbzyGWioSkWDZOaft1ehF3jL0M+YJnSkUdr6Vqu0Bmt0XKp2koLQm63i8d 7h/A== X-Gm-Message-State: AEkooutudPiVsxHgC3aWB5HzC3KZian0YATmNWyWuIq4hD0qazCLzQyGNFZVaWfP46VDqTL+2z0= X-Received: by 10.66.155.129 with SMTP id vw1mr46548830pab.148.1471906622783; Mon, 22 Aug 2016 15:57:02 -0700 (PDT) Return-Path: Received: from localhost.localdomain (c-73-67-244-238.hsd1.or.comcast.net. [73.67.244.238]) by smtp.gmail.com with ESMTPSA id bx9sm215851pab.17.2016.08.22.15.57.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 22 Aug 2016 15:57:02 -0700 (PDT) From: John Stultz To: lkml Cc: John Stultz , Zhangfei Gao , Krzysztof Kozlowski , Maxime Ripard , Vinod Koul , Dan Williams , Mark Brown , Andy Green Subject: [RESEND][PATCH 5/7 v4] k3dma: Fix occasional DMA ERR issue by using proper dma api Date: Mon, 22 Aug 2016 15:56:46 -0700 Message-Id: <1471906608-12418-6-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1471906608-12418-1-git-send-email-john.stultz@linaro.org> References: <1471906608-12418-1-git-send-email-john.stultz@linaro.org> After lots of debugging on an occasional DMA ERR issue, I realized that the desc structures which we point the dma hardware are being allocated out of regular memory. This means when we fill the desc structures, that data doesn't always get flushed out to memory by the time we start the dma transfer, resulting in the dma engine getting some null values, resulting in a DMA ERR on the first irq. Thus, this patch adopts mechanism similar to the zx296702_dma of allocating the desc structures from a dma pool, so the memory caching rules are properly set to avoid this issue. Cc: Zhangfei Gao Cc: Krzysztof Kozlowski Cc: Maxime Ripard Cc: Vinod Koul Cc: Dan Williams Cc: Mark Brown Cc: Andy Green Acked-by: Zhangfei Gao Signed-off-by: John Stutlz --- drivers/dma/k3dma.c | 53 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 8 deletions(-) -- 1.9.1 diff --git a/drivers/dma/k3dma.c b/drivers/dma/k3dma.c index f46b9b8..9d96c95 100644 --- a/drivers/dma/k3dma.c +++ b/drivers/dma/k3dma.c @@ -8,6 +8,8 @@ */ #include #include +#include +#include #include #include #include @@ -25,6 +27,7 @@ #define DRIVER_NAME "k3-dma" #define DMA_MAX_SIZE 0x1ffc +#define LLI_BLOCK_SIZE (4 * PAGE_SIZE) #define INT_STAT 0x00 #define INT_TC1 0x04 @@ -68,7 +71,7 @@ struct k3_dma_desc_sw { dma_addr_t desc_hw_lli; size_t desc_num; size_t size; - struct k3_desc_hw desc_hw[0]; + struct k3_desc_hw *desc_hw; }; struct k3_dma_phy; @@ -100,6 +103,7 @@ struct k3_dma_dev { struct k3_dma_phy *phy; struct k3_dma_chan *chans; struct clk *clk; + struct dma_pool *pool; u32 dma_channels; u32 dma_requests; unsigned int irq; @@ -414,6 +418,35 @@ static void k3_dma_fill_desc(struct k3_dma_desc_sw *ds, dma_addr_t dst, ds->desc_hw[num].config = ccfg; } +static struct k3_dma_desc_sw *k3_dma_alloc_desc_resource(int num, + struct dma_chan *chan) +{ + struct k3_dma_chan *c = to_k3_chan(chan); + struct k3_dma_desc_sw *ds; + struct k3_dma_dev *d = to_k3_dma(chan->device); + int lli_limit = LLI_BLOCK_SIZE / sizeof(struct k3_desc_hw); + + if (num > lli_limit) { + dev_dbg(chan->device->dev, "vch %p: sg num %d exceed max %d\n", + &c->vc, num, lli_limit); + return NULL; + } + + ds = kzalloc(sizeof(*ds), GFP_NOWAIT); + if (!ds) + return NULL; + + ds->desc_hw = dma_pool_alloc(d->pool, GFP_NOWAIT, &ds->desc_hw_lli); + if (!ds->desc_hw) { + dev_dbg(chan->device->dev, "vch %p: dma alloc fail\n", &c->vc); + kfree(ds); + return NULL; + } + memset(ds->desc_hw, 0, sizeof(struct k3_desc_hw) * num); + ds->desc_num = num; + return ds; +} + static struct dma_async_tx_descriptor *k3_dma_prep_memcpy( struct dma_chan *chan, dma_addr_t dst, dma_addr_t src, size_t len, unsigned long flags) @@ -427,13 +460,12 @@ static struct dma_async_tx_descriptor *k3_dma_prep_memcpy( return NULL; num = DIV_ROUND_UP(len, DMA_MAX_SIZE); - ds = kzalloc(sizeof(*ds) + num * sizeof(ds->desc_hw[0]), GFP_ATOMIC); + + ds = k3_dma_alloc_desc_resource(num, chan); if (!ds) return NULL; - ds->desc_hw_lli = __virt_to_phys((unsigned long)&ds->desc_hw[0]); ds->size = len; - ds->desc_num = num; num = 0; if (!c->ccfg) { @@ -482,12 +514,9 @@ static struct dma_async_tx_descriptor *k3_dma_prep_slave_sg( num += DIV_ROUND_UP(avail, DMA_MAX_SIZE) - 1; } - ds = kzalloc(sizeof(*ds) + num * sizeof(ds->desc_hw[0]), GFP_ATOMIC); + ds = k3_dma_alloc_desc_resource(num, chan); if (!ds) return NULL; - - ds->desc_hw_lli = __virt_to_phys((unsigned long)&ds->desc_hw[0]); - ds->desc_num = num; num = 0; for_each_sg(sgl, sg, sglen, i) { @@ -645,7 +674,9 @@ static void k3_dma_free_desc(struct virt_dma_desc *vd) { struct k3_dma_desc_sw *ds = container_of(vd, struct k3_dma_desc_sw, vd); + struct k3_dma_dev *d = to_k3_dma(vd->tx.chan->device); + dma_pool_free(d->pool, ds->desc_hw, ds->desc_hw_lli); kfree(ds); } @@ -708,6 +739,12 @@ static int k3_dma_probe(struct platform_device *op) d->irq = irq; + /* A DMA memory pool for LLIs, align on 32-byte boundary */ + d->pool = dmam_pool_create(DRIVER_NAME, &op->dev, + LLI_BLOCK_SIZE, 32, 0); + if (!d->pool) + return -ENOMEM; + /* init phy channel */ d->phy = devm_kzalloc(&op->dev, d->dma_channels * sizeof(struct k3_dma_phy), GFP_KERNEL);