From patchwork Thu Jun 27 17:22:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 808095 Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0FA9C19A2A2; Thu, 27 Jun 2024 17:22:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719508967; cv=none; b=WeOSM8LXpbu9mT5uRGw+ih7z63wcBeL+DKTtdwJnU3KuI1XR7uUXiF7h9hMvS/NrwL55LrMtd+Fvt9DcIQQx75RYTB29Ko9VyNLlnMx+/ijDm8MttbwzDLwCpU9/lLYHbxMn5Gjnkp7EGGNrrxcK6e8EnFOmmHkr0av2io5yxYs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719508967; c=relaxed/simple; bh=HE/gBLYoq3YOFcYSah+Q4/Z07EhWJT3vDtkUn+oRy0U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IXajP8RLkA45eQ1QIIXA4k1Hv7e1JCtz0kxdyJ8e99D8pG4ThthXGwUm0xUIiBzE2flWgPCXgBluPRMhfFPxLbGwNk16ukh+fV/quBZ+lEsEjrof7ckfpm2E0Yix4PHMEYn+Pb4tnw6LJwI6spMNtkjoeX6ZROUhsXOFF0tbRWg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IVcuIahr; arc=none smtp.client-ip=209.85.208.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IVcuIahr" Received: by mail-lj1-f176.google.com with SMTP id 38308e7fff4ca-2ebe40673e8so92297121fa.3; Thu, 27 Jun 2024 10:22:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719508964; x=1720113764; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0lS5bTkP1B6ljd2Myp+Kpm68dJUaLMTKGqzv1HIMuo8=; b=IVcuIahrW5FysDwob8C3hqDFZxauvijI/uLRSeVKPfF32H587X3i28t3EduZyKqIaE 62JFHGciJrqPGDvjLhjD5sJ5xenniFI6uphySrhUrwwr66DB7Ne57AU+JUHkC6fX6e1g 2JviHeWQ6pDQW9yNzq/C2d7ukDOwXRPXl37/Lgo2T4u/GKLMJ1PFdjKKVUCesKt1y3Ka daejJlPTkX6gU/zI41I3jSAuDnlj+BbNg54JAW0Ff4xtgskxg/XSDd79JEaN9LGYaF8Y LtdSDi9wbl2TDPIzD6SCv4i6jKjB2V8kg5Rary72Fm/z3HN62Ck1J60Tj8W3/zLobcj7 epGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719508964; x=1720113764; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0lS5bTkP1B6ljd2Myp+Kpm68dJUaLMTKGqzv1HIMuo8=; b=QcEUC85jG65I8RXRxxgjzOlDbiFG2TF5Luc3ZvNATF7mQ/4gp79PkATsPMUwGHLgIy aB0Z5bYY+vR8n+KuLW8+2UXGkw/ZUrg6L1s8KQOUJHXMXUsv3kgSW4RCXC3/SdZwp8T0 CdyTalJcN34eCf7WBDbtiIyutP1Ub+u5DnIt+7CuCrPK/cNyl2jAQUpG48475kZD2avT KDCU6jBfv7xg36A1udGnrU3/V81Gm2jM/DD8KIJrrjtW2IlRUjbXsld99eIkqNkbGmjk zKF/jTL809eLEIhuBWhCb/QXAuPb8AnaTc4TGHNO7xV+kLWXmSG9oTo5jtEKq4cxYoXk fLAQ== X-Forwarded-Encrypted: i=1; AJvYcCW64ih6JJE7Q1QQ3If5RC53iHE4uvR78Vzb26CJJDfTsfdcX7r5s86nBV7h3YJ2X2VjRi3gd7Z9/p3zQ8qF47rGnkvJmFa+IhjMkAUFk386L5mZJDZMq/5rl/j3ZWM7z80RWtRT3JkDtvwizGSvdrtDhYw3kjbrByps0kHSmJsM5GChmnzJ X-Gm-Message-State: AOJu0Yzrnuhapu/jwMPvt9e3sERZrxWg2+50VJXBKUo9VvMkMgAL3jWy Jrl/Fg5x9f0X7ohce3JfRnRbxjmJUsKITiXPlh0unsnEJmD8cmNL X-Google-Smtp-Source: AGHT+IFNXyS68nJnNNwmjV8K/ycrg0Vr3BgzCcFhyV7FSPm9Lg+BaOc1kIvM/q279/yI5ycWn1cAew== X-Received: by 2002:a2e:90d0:0:b0:2ec:541b:4b4e with SMTP id 38308e7fff4ca-2ec5b3d47c0mr83087041fa.32.1719508963802; Thu, 27 Jun 2024 10:22:43 -0700 (PDT) Received: from localhost ([213.79.110.82]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2ee4a4bf077sm3182271fa.119.2024.06.27.10.22.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 10:22:42 -0700 (PDT) From: Serge Semin To: Viresh Kumar , Andy Shevchenko , Vinod Koul Cc: Serge Semin , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Greg Kroah-Hartman , Jiri Slaby , dmaengine@vger.kernel.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RESEND v3 1/6] dmaengine: dw: Add peripheral bus width verification Date: Thu, 27 Jun 2024 20:22:17 +0300 Message-ID: <20240627172231.24856-2-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240627172231.24856-1-fancer.lancer@gmail.com> References: <20240627172231.24856-1-fancer.lancer@gmail.com> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently the src_addr_width and dst_addr_width fields of the dma_slave_config structure are mapped to the CTLx.SRC_TR_WIDTH and CTLx.DST_TR_WIDTH fields of the peripheral bus side in order to have the properly aligned data passed to the target device. It's done just by converting the passed peripheral bus width to the encoded value using the __ffs() function. This implementation has several problematic sides: 1. __ffs() is undefined if no bit exist in the passed value. Thus if the specified addr-width is DMA_SLAVE_BUSWIDTH_UNDEFINED, __ffs() may return unexpected value depending on the platform-specific implementation. 2. DW AHB DMA-engine permits having the power-of-2 transfer width limited by the DMAH_Mk_HDATA_WIDTH IP-core synthesize parameter. Specifying bus-width out of that constraints scope will definitely cause unexpected result since the destination reg will be only partly touched than the client driver implied. Let's fix all of that by adding the peripheral bus width verification method and calling it in dwc_config() which is supposed to be executed before preparing any transfer. The new method will make sure that the passed source or destination address width is valid and if undefined then the driver will just fallback to the 1-byte width transfer. Fixes: 029a40e97d0d ("dmaengine: dw: provide DMA capabilities") Signed-off-by: Serge Semin --- Changelog v2: - Add a note to the commit message about having the verification method called in the dwc_config() function. (Andy) - Add hyphen to "1byte" in the in-situ comment. (Andy) - Convert "err" to "ret" variable. (Andy) --- drivers/dma/dw/core.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/drivers/dma/dw/core.c b/drivers/dma/dw/core.c index 5f7d690e3dba..11e269a31a09 100644 --- a/drivers/dma/dw/core.c +++ b/drivers/dma/dw/core.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -780,10 +781,43 @@ bool dw_dma_filter(struct dma_chan *chan, void *param) } EXPORT_SYMBOL_GPL(dw_dma_filter); +static int dwc_verify_p_buswidth(struct dma_chan *chan) +{ + struct dw_dma_chan *dwc = to_dw_dma_chan(chan); + struct dw_dma *dw = to_dw_dma(chan->device); + u32 reg_width, max_width; + + if (dwc->dma_sconfig.direction == DMA_MEM_TO_DEV) + reg_width = dwc->dma_sconfig.dst_addr_width; + else if (dwc->dma_sconfig.direction == DMA_DEV_TO_MEM) + reg_width = dwc->dma_sconfig.src_addr_width; + else /* DMA_MEM_TO_MEM */ + return 0; + + max_width = dw->pdata->data_width[dwc->dws.p_master]; + + /* Fall-back to 1-byte transfer width if undefined */ + if (reg_width == DMA_SLAVE_BUSWIDTH_UNDEFINED) + reg_width = DMA_SLAVE_BUSWIDTH_1_BYTE; + else if (!is_power_of_2(reg_width) || reg_width > max_width) + return -EINVAL; + else /* bus width is valid */ + return 0; + + /* Update undefined addr width value */ + if (dwc->dma_sconfig.direction == DMA_MEM_TO_DEV) + dwc->dma_sconfig.dst_addr_width = reg_width; + else /* DMA_DEV_TO_MEM */ + dwc->dma_sconfig.src_addr_width = reg_width; + + return 0; +} + static int dwc_config(struct dma_chan *chan, struct dma_slave_config *sconfig) { struct dw_dma_chan *dwc = to_dw_dma_chan(chan); struct dw_dma *dw = to_dw_dma(chan->device); + int ret; memcpy(&dwc->dma_sconfig, sconfig, sizeof(*sconfig)); @@ -792,6 +826,10 @@ static int dwc_config(struct dma_chan *chan, struct dma_slave_config *sconfig) dwc->dma_sconfig.dst_maxburst = clamp(dwc->dma_sconfig.dst_maxburst, 0U, dwc->max_burst); + ret = dwc_verify_p_buswidth(chan); + if (ret) + return ret; + dw->encode_maxburst(dwc, &dwc->dma_sconfig.src_maxburst); dw->encode_maxburst(dwc, &dwc->dma_sconfig.dst_maxburst); From patchwork Thu Jun 27 17:22:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 808479 Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE80519AA41; Thu, 27 Jun 2024 17:22:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719508969; cv=none; b=Ng2A81CAbgy5HVNTjgVi5Vw4luNq2jTmE+4wRZwUfZUszZV7cG84I4G0zg0GC4Nuuevja1D0rrsXicMMFLadNr7gS1fkhIyxXCnabmKYBgjI+vBv4BuHhQ1Y1MAtusW2SJAnqNyUPduwhrx6amNQiyjoet1rSA4JwOoq/WNmwQ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719508969; c=relaxed/simple; bh=fpQL+2Ui54/50vZusa3FnI4hmiiTnnsXAfE1S+7AyMw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eTKhPfAnejmP0G2FMxwzPCXwpYbZN1eLYcoI5p9Y7fC3UoLvi8U3vC39a/dwg572feRaJ2fq27c2BSEQc+Oc+5Q16fotce0jRfXcXfetHXhHnVInxAK1z+fyAUna9gFffo8DB5R0jOKc+a8Oc1ldb7yH/78nCg2MHJtTvSxtIDo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RtSv0QrV; arc=none smtp.client-ip=209.85.208.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RtSv0QrV" Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-2ec595d0acbso65157401fa.1; Thu, 27 Jun 2024 10:22:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719508966; x=1720113766; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qshpIny+GIJeG9aHZTifG+SU7u9xJlQ4LhmZoe7c33c=; b=RtSv0QrVJJtSD8r49B4/JTxiQdWF6yJCOuSESwtGHbrvSNXuWvR8Qbu/zGr/WxGgBU CLqMdpsQ0Wytk2h9+SDa1pGYoW3XgHT1qmL3B6+fAahgp9bfw8VThnI7tE8i1c2zFm7Z BSeblUmqIzMby52vtalSEtjBeE7Xr5rr8LKO+OJ0h9IpFXLqfg34GPevBc0+KZBQmYU6 PWw8c0mrYE+r7XpO5DAOs6I7a55xldvHiqlOKRlx0QLEhnfj7i7xDP8A2A6TUrt94Uby oUUf5miLXFzjqtY1fup1RxAolw2V8BVwE45eRk9WGAYiCWMxX1meLDUMz51UPm7OTmCo deFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719508966; x=1720113766; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qshpIny+GIJeG9aHZTifG+SU7u9xJlQ4LhmZoe7c33c=; b=nknLjfd5k066rBrGx3yVvZgc4N/Yv4P4+XWfiq/m+Zl+gObScxUoGY/hcXklxo5f46 2N7uw+5ygr5pvsShyYXzZHBSVJeFLHicCACTYpDiHQlOp0Cst4C0/4qodojGSbwpBQGm n7vRerI1l618cGqlSlpQ8IoslFCtaL13xK9nbnKwapANB/AXQcuxyUaVCe1E2prAsOM1 Yqd+c536SvY+44VqHr56+qARGUIUB6nj5rTtFCL0fdi0MwaPpeH65DVG2uXhZ0sPNRhC Y7MRyTmAbIH8CbApBtMWxtNO1GZAYLIRxQtFNzhmsonjiFTck3Pk8GCdgEQHtNiawVXh syow== X-Forwarded-Encrypted: i=1; AJvYcCXjgCibjoOsEVdH+KldWbA1cRb1mz7MCiesqDVSuw1sLdnFK/iO/3R0QKPukwsMQrd5+nR0aKCP4wDBG6u/75jN5hLfXoJ5JUDooDJh1vjoeyOoWTh/rifaMUijbwDUchlyRh1mTTZG5gnnqUp2ov+HT4bb4OTsv6E+Knboj5f/+ar0q7ck X-Gm-Message-State: AOJu0Yz8KfG+dD9fecGtlduA07lMhZ7cGys41nXyqJkAL6mQXo+rMQQd pUx7rwB5la8z5G67S0kveAAAdfMV4j+y/z0i/PZEiIap/WIk5mrd X-Google-Smtp-Source: AGHT+IHx46h+d8fbVwKoHa+U98hTA2A4hQgJw2PrEQQzJfYoKJ34aUUvdUmXcD1626dI7Ee3kJTb+A== X-Received: by 2002:a2e:9596:0:b0:2ec:55b5:ed50 with SMTP id 38308e7fff4ca-2ec5b2fd2d0mr101924481fa.5.1719508965834; Thu, 27 Jun 2024 10:22:45 -0700 (PDT) Received: from localhost ([213.79.110.82]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2ee4a34f67fsm3253931fa.31.2024.06.27.10.22.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 10:22:45 -0700 (PDT) From: Serge Semin To: Viresh Kumar , Andy Shevchenko , Vinod Koul Cc: Serge Semin , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Greg Kroah-Hartman , Jiri Slaby , dmaengine@vger.kernel.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Viresh Kumar Subject: [PATCH RESEND v3 2/6] dmaengine: dw: Add memory bus width verification Date: Thu, 27 Jun 2024 20:22:18 +0300 Message-ID: <20240627172231.24856-3-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240627172231.24856-1-fancer.lancer@gmail.com> References: <20240627172231.24856-1-fancer.lancer@gmail.com> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently in case of the DEV_TO_MEM or MEM_TO_DEV DMA transfers the memory data width (single transfer width) is determined based on the buffer length, buffer base address or DMA master-channel max address width capability. It isn't enough in case of the channel disabling prior the block transfer is finished. Here is what DW AHB DMA IP-core databook says regarding the port suspension (DMA-transfer pause) implementation in the controller: "When CTLx.SRC_TR_WIDTH < CTLx.DST_TR_WIDTH and the CFGx.CH_SUSP bit is high, the CFGx.FIFO_EMPTY is asserted once the contents of the FIFO do not permit a single word of CTLx.DST_TR_WIDTH to be formed. However, there may still be data in the channel FIFO, but not enough to form a single transfer of CTLx.DST_TR_WIDTH. In this scenario, once the channel is disabled, the remaining data in the channel FIFO is not transferred to the destination peripheral." So in case if the port gets to be suspended and then disabled it's possible to have the data silently discarded even though the controller reported that FIFO is empty and the CTLx.BLOCK_TS indicated the dropped data already received from the source device. This looks as if the data somehow got lost on a way from the peripheral device to memory and causes problems for instance in the DW APB UART driver, which pauses and disables the DMA-transfer as soon as the recv data timeout happens. Here is the way it looks: Memory <------- DMA FIFO <------ UART FIFO <---------------- UART DST_TR_WIDTH -+--------| | | | | | | No more data Current lvl -+--------| |---------+- DMA-burst lvl | | |---------+- Leftover data | | |---------+- SRC_TR_WIDTH -+--------+-------+---------+ In the example above: no more data is getting received over the UART port and BLOCK_TS is not even close to be fully received; some data is left in the UART FIFO, but not enough to perform a bursted DMA-xfer to the DMA FIFO; some data is left in the DMA FIFO, but not enough to be passed further to the system memory in a single transfer. In this situation the 8250 UART driver catches the recv timeout interrupt, pauses the DMA-transfer and terminates it completely, after which the IRQ handler manually fetches the leftover data from the UART FIFO into the recv-buffer. But since the DMA-channel has been disabled with the data left in the DMA FIFO, that data will be just discarded and the recv-buffer will have a gap of the "current lvl" size in the recv-buffer at the tail of the lately received data portion. So the data will be lost just due to the misconfigured DMA transfer. Note this is only relevant for the case of the transfer suspension and _disabling_. No problem will happen if the transfer will be re-enabled afterwards or the block transfer is fully completed. In the later case the "FIFO flush mode" will be executed at the transfer final stage in order to push out the data left in the DMA FIFO. In order to fix the denoted problem the DW AHB DMA-engine driver needs to make sure that the _bursted_ source transfer width is greater or equal to the single destination transfer (note the HW databook describes more strict constraint than actually required). Since the peripheral-device side is prescribed by the client driver logic, the memory-side can be only used for that. The solution can be easily implemented for the DEV_TO_MEM transfers just by adjusting the memory-channel address width. Sadly it's not that easy for the MEM_TO_DEV transfers since the mem-to-dma burst size is normally dynamically determined by the controller. So the only thing that can be done is to make sure that memory-side address width is greater than the peripheral device address width. Fixes: a09820043c9e ("dw_dmac: autoconfigure data_width or get it via platform data") Signed-off-by: Serge Semin --- Changelog v2: - Add a in-situ comment regarding why the memory-side bus width verification was required. (Andy) - Convert "err" to "ret" variable. (Andy) --- drivers/dma/dw/core.c | 51 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/drivers/dma/dw/core.c b/drivers/dma/dw/core.c index 11e269a31a09..b341a6f1b043 100644 --- a/drivers/dma/dw/core.c +++ b/drivers/dma/dw/core.c @@ -622,12 +622,10 @@ dwc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl, struct dw_desc *prev; struct dw_desc *first; u32 ctllo, ctlhi; - u8 m_master = dwc->dws.m_master; - u8 lms = DWC_LLP_LMS(m_master); + u8 lms = DWC_LLP_LMS(dwc->dws.m_master); dma_addr_t reg; unsigned int reg_width; unsigned int mem_width; - unsigned int data_width = dw->pdata->data_width[m_master]; unsigned int i; struct scatterlist *sg; size_t total_len = 0; @@ -661,7 +659,7 @@ dwc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl, mem = sg_dma_address(sg); len = sg_dma_len(sg); - mem_width = __ffs(data_width | mem | len); + mem_width = __ffs(sconfig->src_addr_width | mem | len); slave_sg_todev_fill_desc: desc = dwc_desc_get(dwc); @@ -721,7 +719,7 @@ dwc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl, lli_write(desc, sar, reg); lli_write(desc, dar, mem); lli_write(desc, ctlhi, ctlhi); - mem_width = __ffs(data_width | mem); + mem_width = __ffs(sconfig->dst_addr_width | mem); lli_write(desc, ctllo, ctllo | DWC_CTLL_DST_WIDTH(mem_width)); desc->len = dlen; @@ -813,6 +811,41 @@ static int dwc_verify_p_buswidth(struct dma_chan *chan) return 0; } +static int dwc_verify_m_buswidth(struct dma_chan *chan) +{ + struct dw_dma_chan *dwc = to_dw_dma_chan(chan); + struct dw_dma *dw = to_dw_dma(chan->device); + u32 reg_width, reg_burst, mem_width; + + mem_width = dw->pdata->data_width[dwc->dws.m_master]; + + /* + * It's possible to have a data portion locked in the DMA FIFO in case + * of the channel suspension. Subsequent channel disabling will cause + * that data silent loss. In order to prevent that maintain the src and + * dst transfer widths coherency by means of the relation: + * (CTLx.SRC_TR_WIDTH * CTLx.SRC_MSIZE >= CTLx.DST_TR_WIDTH) + * Look for the details in the commit message that brings this change. + * + * Note the DMA configs utilized in the calculations below must have + * been verified to have correct values by this method call. + */ + if (dwc->dma_sconfig.direction == DMA_MEM_TO_DEV) { + reg_width = dwc->dma_sconfig.dst_addr_width; + if (mem_width < reg_width) + return -EINVAL; + + dwc->dma_sconfig.src_addr_width = mem_width; + } else if (dwc->dma_sconfig.direction == DMA_DEV_TO_MEM) { + reg_width = dwc->dma_sconfig.src_addr_width; + reg_burst = rounddown_pow_of_two(dwc->dma_sconfig.src_maxburst); + + dwc->dma_sconfig.dst_addr_width = min(mem_width, reg_width * reg_burst); + } + + return 0; +} + static int dwc_config(struct dma_chan *chan, struct dma_slave_config *sconfig) { struct dw_dma_chan *dwc = to_dw_dma_chan(chan); @@ -822,14 +855,18 @@ static int dwc_config(struct dma_chan *chan, struct dma_slave_config *sconfig) memcpy(&dwc->dma_sconfig, sconfig, sizeof(*sconfig)); dwc->dma_sconfig.src_maxburst = - clamp(dwc->dma_sconfig.src_maxburst, 0U, dwc->max_burst); + clamp(dwc->dma_sconfig.src_maxburst, 1U, dwc->max_burst); dwc->dma_sconfig.dst_maxburst = - clamp(dwc->dma_sconfig.dst_maxburst, 0U, dwc->max_burst); + clamp(dwc->dma_sconfig.dst_maxburst, 1U, dwc->max_burst); ret = dwc_verify_p_buswidth(chan); if (ret) return ret; + ret = dwc_verify_m_buswidth(chan); + if (ret) + return ret; + dw->encode_maxburst(dwc, &dwc->dma_sconfig.src_maxburst); dw->encode_maxburst(dwc, &dwc->dma_sconfig.dst_maxburst); From patchwork Thu Jun 27 17:22:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 808094 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BBFC919AA70; Thu, 27 Jun 2024 17:22:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719508971; cv=none; b=bgvLo0hKwwCGc0MYLnWYUKxcvy8WkI8wAJTtpkg267ECQbSCjfCmbIaw3upQojrHehFdoLDd4Amzf13sEBQKrGWf1+Q9IWC1JrHteG7bL8dUlUBe8e+jLW1WM9ig+hTL3CM5nZThWLO4aduq8a+4ad++pDkJ6TY+XDHl3Z6mZvI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719508971; c=relaxed/simple; bh=klqYSawc9+NGO/zCAp0wyCL7LwvbZptI3bgjMK68bVs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c8SyQMRvbTPJ5nQgpq4SzT/WkG3KEVNQ8ys0hm2Q9YbBYC76Ut6rB/kw1DZmBaIeFBISZyaEYWy1AHohEdZOeGYdxgclUx006D+GDANad9UnDPhx8P93uxz3Odm08A8eXciL/s7rvOtTJSEPeEwTRCPQYP4meFPm6rSsrRWgtsw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=jrQXA5ac; arc=none smtp.client-ip=209.85.167.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jrQXA5ac" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-52ce674da85so5290543e87.2; Thu, 27 Jun 2024 10:22:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719508968; x=1720113768; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=siZ4YVoVvwl35AmLdBXelRcytxkQs25RUWuyPVhPzww=; b=jrQXA5achsyVcn5eE910YHsDuwnlBOtTKlYq9ffIYnn9CzBm3sfOYMbViRwWZ+lJeJ dFAcDIZP/qjfjdkZ+R+rCniRbzeTRU7x7AkhDb3hC20y9RALmHkQUC0if7dSTI7mQ1NA RV+c8wZdxHcG2c+22gAuMXfPjASruNRMGnbAXodI4+fqp1/q+QvH77Oaygo6RSF3WaYu jmpYfT3G7TVCthwPXe2smOpnIbnkbLwiJL0nm5C1gw/nu3RcBPDCFpIApdBMFKAtEdHd v75mgDIzlgYwLaySZ3St7s4DjiVp9uRpSnnqBqh9RwtllwT8pfrLZ3YBAMCXbVVVd2XD xqFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719508968; x=1720113768; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=siZ4YVoVvwl35AmLdBXelRcytxkQs25RUWuyPVhPzww=; b=Eup/PuRd5WBWr2yWcplocwaJXleRV5P07EnBbqGkIm2Lsc2k6zy+Jz36obZd8IJae7 eaU9HJuowvBY1kLLYUa7uXVaKONsS6tJhuHJLdeHcsYm+eaS7d0R7IY278oB2dVCcIis fNxuoiMVWxvto5+iABUwfQvPKLwpzFHuHyHAn0IbNTgob9GoJ++NE0CiioRgP6PeWlY/ E+uipx5jAHscR68FxnYhBQO2hJtRc8M2Bb43ScDnCdg8x4hNTQgXtkKAGmcawS57tawh iycusl2lWL1LDbsRfzsKiBQbj/ZwNM8LRyNfnEKOc8JNbRJQVWKUoEplLh/fGHqDqUER m2kQ== X-Forwarded-Encrypted: i=1; AJvYcCWHv2AHGIoH8fA5NQVoLvzgKWNHUTzDpj/IIng+cLSf0dOOMezH7Iv7C4c/YyixYo6psZl7nKQdX0LJb+FmG15TTIp1HzBoGg6VnetHKJzNUgGrEThb32Ipotc29QJ0u+k92ZL0/2keFNLaMqkyA+qfSTAVrItS1xeXE2VLSvsh/j+YJigE X-Gm-Message-State: AOJu0YzZmEWYATjILkginUg0NFdKKcNFTkPdnnmfgBuF/bjdL7JGAYqR 0c6y7XXkB5hm/bgK4cSuBCmEx7Z9wt3BA7lbv2/no0YreAsZQLIW X-Google-Smtp-Source: AGHT+IGh4XkamlP40fuEKOV4BaBgP/JJzsUdce1nGRPuSvsATQK0RszJNSwTndBnKq6e2kHeOW7/gg== X-Received: by 2002:a05:6512:acf:b0:52c:8c4d:f8d6 with SMTP id 2adb3069b0e04-52cf50fbcb7mr5778741e87.45.1719508967656; Thu, 27 Jun 2024 10:22:47 -0700 (PDT) Received: from localhost ([213.79.110.82]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52e71305d6esm267170e87.167.2024.06.27.10.22.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 10:22:47 -0700 (PDT) From: Serge Semin To: Viresh Kumar , Andy Shevchenko , Vinod Koul Cc: Serge Semin , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Greg Kroah-Hartman , Jiri Slaby , dmaengine@vger.kernel.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RESEND v3 3/6] dmaengine: dw: Simplify prepare CTL_LO methods Date: Thu, 27 Jun 2024 20:22:19 +0300 Message-ID: <20240627172231.24856-4-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240627172231.24856-1-fancer.lancer@gmail.com> References: <20240627172231.24856-1-fancer.lancer@gmail.com> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently the CTL LO fields are calculated on the platform-specific basis. It's implemented by means of the prepare_ctllo() callbacks using the ternary operator within the local variables init block at the beginning of the block scope. The functions code currently is relatively hard to comprehend and isn't that optimal since implies four conditional statements executed and two additional local variables defined. Let's simplify the DW AHB DMA prepare_ctllo() method by unrolling the ternary operators into the normal if-else statement, dropping redundant master-interface ID variables and initializing the local variables based on the singly evaluated DMA-transfer direction check. Thus the method will look much more readable since now the fields content can be easily inferred right from the if-else branch. Provide the same update in the Intel DMA32 core driver for the sake of the driver code unification. Note besides of the effects described above this update is basically a preparation before dropping the max burst encoding callback. The dropping will require to call the burst fields calculation methods right in the prepare_ctllo() callbacks. It would have made the later functions code even more complex should they were left in the original state. Signed-off-by: Serge Semin --- Changelog v2: - Group sms+dms and smsize+dmsize variables initializations up. (Andy) - Move the zero initializations out to the variables init block. (Andy) --- drivers/dma/dw/dw.c | 21 +++++++++++++++------ drivers/dma/dw/idma32.c | 8 ++++++-- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/drivers/dma/dw/dw.c b/drivers/dma/dw/dw.c index a4862263ff14..e3d2cc3ea68c 100644 --- a/drivers/dma/dw/dw.c +++ b/drivers/dma/dw/dw.c @@ -67,12 +67,21 @@ static size_t dw_dma_block2bytes(struct dw_dma_chan *dwc, u32 block, u32 width) static u32 dw_dma_prepare_ctllo(struct dw_dma_chan *dwc) { struct dma_slave_config *sconfig = &dwc->dma_sconfig; - u8 smsize = (dwc->direction == DMA_DEV_TO_MEM) ? sconfig->src_maxburst : 0; - u8 dmsize = (dwc->direction == DMA_MEM_TO_DEV) ? sconfig->dst_maxburst : 0; - u8 p_master = dwc->dws.p_master; - u8 m_master = dwc->dws.m_master; - u8 dms = (dwc->direction == DMA_MEM_TO_DEV) ? p_master : m_master; - u8 sms = (dwc->direction == DMA_DEV_TO_MEM) ? p_master : m_master; + u8 smsize = 0, dmsize = 0; + u8 sms, dms; + + if (dwc->direction == DMA_MEM_TO_DEV) { + sms = dwc->dws.m_master; + dms = dwc->dws.p_master; + dmsize = sconfig->dst_maxburst; + } else if (dwc->direction == DMA_DEV_TO_MEM) { + sms = dwc->dws.p_master; + dms = dwc->dws.m_master; + smsize = sconfig->src_maxburst; + } else /* DMA_MEM_TO_MEM */ { + sms = dwc->dws.m_master; + dms = dwc->dws.m_master; + } return DWC_CTLL_LLP_D_EN | DWC_CTLL_LLP_S_EN | DWC_CTLL_DST_MSIZE(dmsize) | DWC_CTLL_SRC_MSIZE(smsize) | diff --git a/drivers/dma/dw/idma32.c b/drivers/dma/dw/idma32.c index 58f4078d83fe..e0c31f77cd0f 100644 --- a/drivers/dma/dw/idma32.c +++ b/drivers/dma/dw/idma32.c @@ -202,8 +202,12 @@ static size_t idma32_block2bytes(struct dw_dma_chan *dwc, u32 block, u32 width) static u32 idma32_prepare_ctllo(struct dw_dma_chan *dwc) { struct dma_slave_config *sconfig = &dwc->dma_sconfig; - u8 smsize = (dwc->direction == DMA_DEV_TO_MEM) ? sconfig->src_maxburst : 0; - u8 dmsize = (dwc->direction == DMA_MEM_TO_DEV) ? sconfig->dst_maxburst : 0; + u8 smsize = 0, dmsize = 0; + + if (dwc->direction == DMA_MEM_TO_DEV) + dmsize = sconfig->dst_maxburst; + else if (dwc->direction == DMA_DEV_TO_MEM) + smsize = sconfig->src_maxburst; return DWC_CTLL_LLP_D_EN | DWC_CTLL_LLP_S_EN | DWC_CTLL_DST_MSIZE(dmsize) | DWC_CTLL_SRC_MSIZE(smsize); From patchwork Thu Jun 27 17:22:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 808478 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3F5C19AD63; Thu, 27 Jun 2024 17:22:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719508973; cv=none; b=liuCDZC1JLJt+7E/Vdg5nJj6O/LbYKMOW6yh1YNT2bbFdZI7ZXtN77W+KVnMyJDwjmMuhOj/QUCDHkr8DhF/7rBbfGm3UTInk6Y2BI0vTKgXmH4K3dT4c30fdfngkN3PrwnJBYiOS84hkB35PQ0Yk51DKJ4HFPQKz3h4UH/S48A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719508973; c=relaxed/simple; bh=fQPhAal9u/RtGJ6B755rdrjV8QGkzP6TRnf7LTNG+vU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T0VJVRGNByg9SJClH8XKK/zViXU3DndmXSHoAlDbq3wLIaXGXje6CQ/D11aaEjtFb3sG79rEgdA6hyxjVbhNg4jz/juNTzkGOahFAbLAy/1ncScuopCCaEIw1obaMvxp57Prf97CvjRJ3NkD6L3Tvk+M/pSh38pUhRLaGxHzQEw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MBGFKTo9; arc=none smtp.client-ip=209.85.167.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MBGFKTo9" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-52cdcd26d61so6536242e87.2; Thu, 27 Jun 2024 10:22:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719508970; x=1720113770; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pZfbnz/PwNgQkBbjrQGHnGTi9KvvR26owgXnJGMkSZg=; b=MBGFKTo9MQI333GodTY8pOYBIrWfwghQ1iFq8K8nhjg4tS7NcC2KXepGL1jqM9ez1V 3FDLbER1vRcypimbqOcq+UXUscHqYQmV1qRaLWskk+h/LirRH7lFhFhZk0+OJdadf5WG xrpdYT43WToof+jHx6vL41mQR/2e5VTMe0W10zvfYhaT1i5QeDauTAdKUOf663RxZVB2 mAx2PWcOqCWg4GP41mfekXgaT1QL8n7h+eV7MOr5boNODkHS1Wsyih8G0pCLMg1CF8/U gGPcjw3zXyBvfSC4IFT8sp//oGorInkFQGTCszpzxNaRou7E9qIby6zhaodnz5v9CEf7 12Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719508970; x=1720113770; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pZfbnz/PwNgQkBbjrQGHnGTi9KvvR26owgXnJGMkSZg=; b=OEX+WjdB9jRQWgi/jc3Xy5rO1p1IJm0eb2FJvyGIcXhzms7ljTEFc5lrsvgp/WmG6E P8i9baypx7eqp+39I0T1tO0oyfboH/7mfMYkgrTDT4uQrujLvt9pdre1rhNb3WisfbSN xfke2s1Hz0ZGqG00wZF8oukS+msgKNhTir4iIIPCeUlTtZxJp+Vg0tEMFBWPBTTDL6IO 3RFFawJV6Bfhjke6pxO/zbJNKFZlrcfAq5pw9N2RD+zqvqu8jSLDrN70U+dQ0+Y0AlT7 SDn6TpFLYO0h75t+mGvzS8yjDLyE8+9qJL5gvcbYej2fTBi3n4PqmTFRHEYEMPyX29Ya rBCg== X-Forwarded-Encrypted: i=1; AJvYcCU2qnl18Yb+UnDK8mhvSUvi++IRuWcdK2JwDgXHaEr5fRtLlbEFd3fW7cDYdD6SqsXnFC0/U+Cuz0neCAscT5yzdx6blWo35c4zAPKoTJJb2Q8vcXukhCglyvSjCDXFp3+/JhBQ+au13P4WERz0WrkygCFXDhCY47yxbJLDgeY4LqPLZzs2 X-Gm-Message-State: AOJu0YxkoMfYaw2AFp/wyllJAUO2zb0PqLS1bzVxiJVnxNW1lcK8Jb/V UUm7q6mf7IXIbzoEGkOK1zbGlr44V7Gciv9+4t2gLX9FC3tQYRI5 X-Google-Smtp-Source: AGHT+IH/skTxNTdJ77l9P9sERL7buslm8AqLFNbV1oIcAE/j5l1j3e9u138KdLde4k/rybo0E7eccA== X-Received: by 2002:a05:6512:ad5:b0:52e:7684:a385 with SMTP id 2adb3069b0e04-52e7684a554mr773311e87.52.1719508969473; Thu, 27 Jun 2024 10:22:49 -0700 (PDT) Received: from localhost ([213.79.110.82]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52e71319ce7sm274550e87.221.2024.06.27.10.22.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 10:22:49 -0700 (PDT) From: Serge Semin To: Viresh Kumar , Andy Shevchenko , Vinod Koul Cc: Serge Semin , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Greg Kroah-Hartman , Jiri Slaby , dmaengine@vger.kernel.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RESEND v3 4/6] dmaengine: dw: Define encode_maxburst() above prepare_ctllo() callbacks Date: Thu, 27 Jun 2024 20:22:20 +0300 Message-ID: <20240627172231.24856-5-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240627172231.24856-1-fancer.lancer@gmail.com> References: <20240627172231.24856-1-fancer.lancer@gmail.com> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 As a preparatory change before dropping the encode_maxburst() callbacks let's move dw_dma_encode_maxburst() and idma32_encode_maxburst() to being defined above the dw_dma_prepare_ctllo() and idma32_prepare_ctllo() methods respectively. That's required since the former methods will be called from the later ones directly. Signed-off-by: Serge Semin --- Changelog v2: - New patch created on v2 review stage. (Andy) --- drivers/dma/dw/dw.c | 18 +++++++++--------- drivers/dma/dw/idma32.c | 10 +++++----- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/dma/dw/dw.c b/drivers/dma/dw/dw.c index e3d2cc3ea68c..628ee1e77505 100644 --- a/drivers/dma/dw/dw.c +++ b/drivers/dma/dw/dw.c @@ -64,6 +64,15 @@ static size_t dw_dma_block2bytes(struct dw_dma_chan *dwc, u32 block, u32 width) return DWC_CTLH_BLOCK_TS(block) << width; } +static void dw_dma_encode_maxburst(struct dw_dma_chan *dwc, u32 *maxburst) +{ + /* + * Fix burst size according to dw_dmac. We need to convert them as: + * 1 -> 0, 4 -> 1, 8 -> 2, 16 -> 3. + */ + *maxburst = *maxburst > 1 ? fls(*maxburst) - 2 : 0; +} + static u32 dw_dma_prepare_ctllo(struct dw_dma_chan *dwc) { struct dma_slave_config *sconfig = &dwc->dma_sconfig; @@ -88,15 +97,6 @@ static u32 dw_dma_prepare_ctllo(struct dw_dma_chan *dwc) DWC_CTLL_DMS(dms) | DWC_CTLL_SMS(sms); } -static void dw_dma_encode_maxburst(struct dw_dma_chan *dwc, u32 *maxburst) -{ - /* - * Fix burst size according to dw_dmac. We need to convert them as: - * 1 -> 0, 4 -> 1, 8 -> 2, 16 -> 3. - */ - *maxburst = *maxburst > 1 ? fls(*maxburst) - 2 : 0; -} - static void dw_dma_set_device_name(struct dw_dma *dw, int id) { snprintf(dw->name, sizeof(dw->name), "dw:dmac%d", id); diff --git a/drivers/dma/dw/idma32.c b/drivers/dma/dw/idma32.c index e0c31f77cd0f..493fcbafa2b8 100644 --- a/drivers/dma/dw/idma32.c +++ b/drivers/dma/dw/idma32.c @@ -199,6 +199,11 @@ static size_t idma32_block2bytes(struct dw_dma_chan *dwc, u32 block, u32 width) return IDMA32C_CTLH_BLOCK_TS(block); } +static void idma32_encode_maxburst(struct dw_dma_chan *dwc, u32 *maxburst) +{ + *maxburst = *maxburst > 1 ? fls(*maxburst) - 1 : 0; +} + static u32 idma32_prepare_ctllo(struct dw_dma_chan *dwc) { struct dma_slave_config *sconfig = &dwc->dma_sconfig; @@ -213,11 +218,6 @@ static u32 idma32_prepare_ctllo(struct dw_dma_chan *dwc) DWC_CTLL_DST_MSIZE(dmsize) | DWC_CTLL_SRC_MSIZE(smsize); } -static void idma32_encode_maxburst(struct dw_dma_chan *dwc, u32 *maxburst) -{ - *maxburst = *maxburst > 1 ? fls(*maxburst) - 1 : 0; -} - static void idma32_set_device_name(struct dw_dma *dw, int id) { snprintf(dw->name, sizeof(dw->name), "idma32:dmac%d", id); From patchwork Thu Jun 27 17:22:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 808093 Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ADFAA19B3E3; Thu, 27 Jun 2024 17:22:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719508975; cv=none; b=Yp76jIGuQWwUgBdZzjXOzPEJLa5ciPCBO6lm6qe/9LGFtXtREs5DSqT1xF+2uR130SMt90VyGrg53lsY8CHIK+szYDnT+0iimzrwSPh+tun7DTd0gYKio0Gx4uH4VkAOwDmIHpIBN8qhW+2nsr48XSmdQYkebT0sGt2wcaQXHwo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719508975; c=relaxed/simple; bh=7c2a53YpQodmCF26TS5JXa9VgIKEr2auMGh9ugNAu2o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sVQJWoYDaw1uh9XJpj6Tsv2ToEsY87zcKvSAstsiSc/8Physi2lh1tX3s2K0a/vo5eJtha/dYKqmyvH1DumioSCEte5Sw/DILP1eI7wjpUDEPn1uV39PCmA/iubkQuAz/rJfqlszuOZS8QU0pDnj1TlLKb3slUgtzroabwBVWA4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bEv1jjkd; arc=none smtp.client-ip=209.85.167.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bEv1jjkd" Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-52e7145c63cso632639e87.0; Thu, 27 Jun 2024 10:22:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719508972; x=1720113772; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IeEWdCK+v3cFCGOt0s8SezCLp0oS2iOHSzMswWowNvs=; b=bEv1jjkdLroIsi0LoWtFoV3OBauBcCPpF44bj8x2rAJDwiI2dj7UUB2dVbKTerSOPW IgBzhaKnTd8oVEKqiib7MmrejcwLIpEvZH12j2obxVjD4BgkrYXs+1R0pq6W5FaJ+6pY 0JO7vwKBpq4jCn1gcwrDPOmK7hiRm70O8SvDJKovJK9NTpUCHY7hAzqzsh1ShCCPblB/ L5XvutMN2biP4k4ZoRs5YhbZJbDsLv/hzcxppMKHXBw+xGFvS9zZKG5583fzxUDy5B7Z /PdtQqZc3Bz24LgQAKCcBCSpBJfwoJYLRixxnsaVKZsJv7pE9QcPq5T52B+2l/QE+Pbi JjPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719508972; x=1720113772; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IeEWdCK+v3cFCGOt0s8SezCLp0oS2iOHSzMswWowNvs=; b=p2qX3gHT2BLI4fonzf7Bywo5uyop6VxES7XYUqm9wDz2KnOinVg1GZ+TlnobhCrHGi w1es75PRMOI4VKysMcyVemmymO3DDzArDxAgd34jL8beK38lOUVWOkXCQTZe7Fr3XZ9c u6tjRSMxedCaHMLVG6VgPgwcf/78FLqxq1WBxD9eGY7/faKIyfj8UWnHMVYHjhs32dg4 e1RNtFbVQQkw5Cpr/Jad5airuLHhb5VehpHUsBcM6F1wgJ2qH4e1wFVXAxDxnitJv6hr qTQBvNfq8o45ruTS4wPTCl47yFgQ9xeRd+chITUKx+Fy0mesNRcXziAWMhnMkjKuUu0u SBQA== X-Forwarded-Encrypted: i=1; AJvYcCWrHat4flyqvWjRugOnEB5vPtzs2z8MlVddvoqBL50iu3BvSmovcy1jdHUeDnh+MDftP1bQ5x+QkQoytbTdl4YloD8kmuZudbC1J5FyqjmY1CZeIGx5uTdDMKX1+3dPIwazNSthwzA7dkYPTy4mB9zGZSE2mpu6xQFPeTNa+tQdWFDffIL9 X-Gm-Message-State: AOJu0YyYYvF72LbXGOLr3Yti5DPr2pyeq8PPnhyKU2RlF/Jjq2Ls2S+M 6XW1oiQs+LbiEw0GJ+cVCo0cw+Ldbo2hqqMMfscS+Sz8rPnbCcBD X-Google-Smtp-Source: AGHT+IF/npTSsVNef8jboB8omMFAeMLmlrurRJdb6QuF8dkT7XBz+Cb8CK/50DdhfPoKialyLwtGnw== X-Received: by 2002:a05:6512:3996:b0:52c:8508:e851 with SMTP id 2adb3069b0e04-52e70384cadmr776161e87.14.1719508971731; Thu, 27 Jun 2024 10:22:51 -0700 (PDT) Received: from localhost ([213.79.110.82]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52e712a7401sm265353e87.5.2024.06.27.10.22.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 10:22:51 -0700 (PDT) From: Serge Semin To: Viresh Kumar , Andy Shevchenko , Vinod Koul Cc: Serge Semin , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Greg Kroah-Hartman , Jiri Slaby , dmaengine@vger.kernel.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RESEND v3 5/6] dmaengine: dw: Simplify max-burst calculation procedure Date: Thu, 27 Jun 2024 20:22:21 +0300 Message-ID: <20240627172231.24856-6-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240627172231.24856-1-fancer.lancer@gmail.com> References: <20240627172231.24856-1-fancer.lancer@gmail.com> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In order to have a more coherent DW AHB DMA slave configuration method - dwc_config() - let's simplify the source and destination channel max-burst calculation procedure: 1. Create the max-burst verification method as it has been just done for the memory and peripheral address widths. Thus the dwc_config() method will turn to a set of the verification methods execution. 2. Since both the generic DW AHB DMA and Intel iDMA 32-bit engines support the power-of-2 bursts only, then the specified by the client driver max-burst values can be converted to being power-of-2 right in the max-burst verification method. 3. Since max-burst encoded value is required on the CTL_LO fields calculation stage, the encode_maxburst() callback can be easily dropped from the dw_dma structure meanwhile the encoding procedure will be executed right in the CTL_LO register value calculation. Thus the update will provide the next positive effects: the internal DMA-slave config structure will contain only the real DMA-transfer config values, which will be encoded to the DMA-controller register fields only when it's required on the buffer mapping; the redundant encode_maxburst() callback will be dropped simplifying the internal HW-abstraction API; dwc_config() will look more readable executing the verification functions one-by-one. Signed-off-by: Serge Semin --- Changelog v2: - Refer to dwc_config() in the commit message. (Andy) - Convert dwc_verify_maxburst() to returning zero. (Andy) - Add a comment regarding the values utilized in the dwc_verify_p_buswidth() being verified before the method is called. (Andy, see patch 2) - Detach the dw_dma_encode_maxburst() and idma32_encode_maxburst() movement to a preparatory patch. (Andy) --- drivers/dma/dw/core.c | 30 +++++++++++++++++++++--------- drivers/dma/dw/dw.c | 9 ++++----- drivers/dma/dw/idma32.c | 9 ++++----- drivers/dma/dw/regs.h | 1 - 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/drivers/dma/dw/core.c b/drivers/dma/dw/core.c index b341a6f1b043..32a66f9effd9 100644 --- a/drivers/dma/dw/core.c +++ b/drivers/dma/dw/core.c @@ -779,6 +779,23 @@ bool dw_dma_filter(struct dma_chan *chan, void *param) } EXPORT_SYMBOL_GPL(dw_dma_filter); +static int dwc_verify_maxburst(struct dma_chan *chan) +{ + struct dw_dma_chan *dwc = to_dw_dma_chan(chan); + + dwc->dma_sconfig.src_maxburst = + clamp(dwc->dma_sconfig.src_maxburst, 1U, dwc->max_burst); + dwc->dma_sconfig.dst_maxburst = + clamp(dwc->dma_sconfig.dst_maxburst, 1U, dwc->max_burst); + + dwc->dma_sconfig.src_maxburst = + rounddown_pow_of_two(dwc->dma_sconfig.src_maxburst); + dwc->dma_sconfig.dst_maxburst = + rounddown_pow_of_two(dwc->dma_sconfig.dst_maxburst); + + return 0; +} + static int dwc_verify_p_buswidth(struct dma_chan *chan) { struct dw_dma_chan *dwc = to_dw_dma_chan(chan); @@ -838,7 +855,7 @@ static int dwc_verify_m_buswidth(struct dma_chan *chan) dwc->dma_sconfig.src_addr_width = mem_width; } else if (dwc->dma_sconfig.direction == DMA_DEV_TO_MEM) { reg_width = dwc->dma_sconfig.src_addr_width; - reg_burst = rounddown_pow_of_two(dwc->dma_sconfig.src_maxburst); + reg_burst = dwc->dma_sconfig.src_maxburst; dwc->dma_sconfig.dst_addr_width = min(mem_width, reg_width * reg_burst); } @@ -849,15 +866,13 @@ static int dwc_verify_m_buswidth(struct dma_chan *chan) static int dwc_config(struct dma_chan *chan, struct dma_slave_config *sconfig) { struct dw_dma_chan *dwc = to_dw_dma_chan(chan); - struct dw_dma *dw = to_dw_dma(chan->device); int ret; memcpy(&dwc->dma_sconfig, sconfig, sizeof(*sconfig)); - dwc->dma_sconfig.src_maxburst = - clamp(dwc->dma_sconfig.src_maxburst, 1U, dwc->max_burst); - dwc->dma_sconfig.dst_maxburst = - clamp(dwc->dma_sconfig.dst_maxburst, 1U, dwc->max_burst); + ret = dwc_verify_maxburst(chan); + if (ret) + return ret; ret = dwc_verify_p_buswidth(chan); if (ret) @@ -867,9 +882,6 @@ static int dwc_config(struct dma_chan *chan, struct dma_slave_config *sconfig) if (ret) return ret; - dw->encode_maxburst(dwc, &dwc->dma_sconfig.src_maxburst); - dw->encode_maxburst(dwc, &dwc->dma_sconfig.dst_maxburst); - return 0; } diff --git a/drivers/dma/dw/dw.c b/drivers/dma/dw/dw.c index 628ee1e77505..6766142884b6 100644 --- a/drivers/dma/dw/dw.c +++ b/drivers/dma/dw/dw.c @@ -64,13 +64,13 @@ static size_t dw_dma_block2bytes(struct dw_dma_chan *dwc, u32 block, u32 width) return DWC_CTLH_BLOCK_TS(block) << width; } -static void dw_dma_encode_maxburst(struct dw_dma_chan *dwc, u32 *maxburst) +static inline u8 dw_dma_encode_maxburst(u32 maxburst) { /* * Fix burst size according to dw_dmac. We need to convert them as: * 1 -> 0, 4 -> 1, 8 -> 2, 16 -> 3. */ - *maxburst = *maxburst > 1 ? fls(*maxburst) - 2 : 0; + return maxburst > 1 ? fls(maxburst) - 2 : 0; } static u32 dw_dma_prepare_ctllo(struct dw_dma_chan *dwc) @@ -82,11 +82,11 @@ static u32 dw_dma_prepare_ctllo(struct dw_dma_chan *dwc) if (dwc->direction == DMA_MEM_TO_DEV) { sms = dwc->dws.m_master; dms = dwc->dws.p_master; - dmsize = sconfig->dst_maxburst; + dmsize = dw_dma_encode_maxburst(sconfig->dst_maxburst); } else if (dwc->direction == DMA_DEV_TO_MEM) { sms = dwc->dws.p_master; dms = dwc->dws.m_master; - smsize = sconfig->src_maxburst; + smsize = dw_dma_encode_maxburst(sconfig->src_maxburst); } else /* DMA_MEM_TO_MEM */ { sms = dwc->dws.m_master; dms = dwc->dws.m_master; @@ -125,7 +125,6 @@ int dw_dma_probe(struct dw_dma_chip *chip) dw->suspend_chan = dw_dma_suspend_chan; dw->resume_chan = dw_dma_resume_chan; dw->prepare_ctllo = dw_dma_prepare_ctllo; - dw->encode_maxburst = dw_dma_encode_maxburst; dw->bytes2block = dw_dma_bytes2block; dw->block2bytes = dw_dma_block2bytes; diff --git a/drivers/dma/dw/idma32.c b/drivers/dma/dw/idma32.c index 493fcbafa2b8..dac617c183e6 100644 --- a/drivers/dma/dw/idma32.c +++ b/drivers/dma/dw/idma32.c @@ -199,9 +199,9 @@ static size_t idma32_block2bytes(struct dw_dma_chan *dwc, u32 block, u32 width) return IDMA32C_CTLH_BLOCK_TS(block); } -static void idma32_encode_maxburst(struct dw_dma_chan *dwc, u32 *maxburst) +static inline u8 idma32_encode_maxburst(u32 maxburst) { - *maxburst = *maxburst > 1 ? fls(*maxburst) - 1 : 0; + return maxburst > 1 ? fls(maxburst) - 1 : 0; } static u32 idma32_prepare_ctllo(struct dw_dma_chan *dwc) @@ -210,9 +210,9 @@ static u32 idma32_prepare_ctllo(struct dw_dma_chan *dwc) u8 smsize = 0, dmsize = 0; if (dwc->direction == DMA_MEM_TO_DEV) - dmsize = sconfig->dst_maxburst; + dmsize = idma32_encode_maxburst(sconfig->dst_maxburst); else if (dwc->direction == DMA_DEV_TO_MEM) - smsize = sconfig->src_maxburst; + smsize = idma32_encode_maxburst(sconfig->src_maxburst); return DWC_CTLL_LLP_D_EN | DWC_CTLL_LLP_S_EN | DWC_CTLL_DST_MSIZE(dmsize) | DWC_CTLL_SRC_MSIZE(smsize); @@ -274,7 +274,6 @@ int idma32_dma_probe(struct dw_dma_chip *chip) dw->suspend_chan = idma32_suspend_chan; dw->resume_chan = idma32_resume_chan; dw->prepare_ctllo = idma32_prepare_ctllo; - dw->encode_maxburst = idma32_encode_maxburst; dw->bytes2block = idma32_bytes2block; dw->block2bytes = idma32_block2bytes; diff --git a/drivers/dma/dw/regs.h b/drivers/dma/dw/regs.h index 76654bd13c1a..5969d9cc8d7a 100644 --- a/drivers/dma/dw/regs.h +++ b/drivers/dma/dw/regs.h @@ -327,7 +327,6 @@ struct dw_dma { void (*suspend_chan)(struct dw_dma_chan *dwc, bool drain); void (*resume_chan)(struct dw_dma_chan *dwc, bool drain); u32 (*prepare_ctllo)(struct dw_dma_chan *dwc); - void (*encode_maxburst)(struct dw_dma_chan *dwc, u32 *maxburst); u32 (*bytes2block)(struct dw_dma_chan *dwc, size_t bytes, unsigned int width, size_t *len); size_t (*block2bytes)(struct dw_dma_chan *dwc, u32 block, u32 width); From patchwork Thu Jun 27 17:22:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 808477 Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7ADBF19CD05; Thu, 27 Jun 2024 17:22:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719508977; cv=none; b=NralfEYFdtzv9KCKx4VWYFyMCFCxN0zOtOuwTMqSqbhxMbiyRf33UmLmra5BiS4gzD5HgjCUKoLkx+WcaYg9DggyexXGNEFORUkgpWdV50eWDw/KJs7PREl4vHf+PXW235WJELrFIV6GnNZb98NS1uIro3pBPUReyFQuSjvTcEg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719508977; c=relaxed/simple; bh=9trPxT7067agZJig5NFIevW79dFHtTF0XpemZk9R2eE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p7MfCPBitI0XGPMdtjFNoffL7MPSh2OK0jRvStevWVkPWlM59as5mC4tOuT7kIvYcT1TOsdOl5AF4fmUIJqAlNLSacZSO/sDUmE2riyDBew/VwOXIIZuLZ36aumeATryvWUr10f+ZC2T7yduzOucVH96qs1RND97dNTL5otY52M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=E7kjvhJu; arc=none smtp.client-ip=209.85.208.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="E7kjvhJu" Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-2ec58040f39so57325321fa.2; Thu, 27 Jun 2024 10:22:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719508974; x=1720113774; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Q8jv7DlUuWmwKBFAeDpE74984/WTEdS+lAt5ksO5mUc=; b=E7kjvhJuyxv7J5TBtvDvdiTVfOfGW9ylxHih3tHOngN7AF6OyyOlceH6Uy/V5d7aEL zxtU+TKYt7ICEKeT154ZSP7zeOlLXyD7zMnde33V7CCTd3rBqcx3CVgtuu38M9yRSF4X p6cOxJ5a69sKo8JJo4/FYqhpmNcTWAyQDIdX6Mj2OVcak4Hs37yA2nX2zl9lxr50IMZS wr2oy/IviUWe3ChX+HghgK7vS4p2adUdWi7PavQxuw38cl4AsES0UmJGShMGRDD87Hej HUMaJelB0NvkeC0tO9t1J+dy3gvIa8BBG1SviFCXOt319ZMAzjYR9I3Yj7j1gNu6Cccq qSlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719508974; x=1720113774; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Q8jv7DlUuWmwKBFAeDpE74984/WTEdS+lAt5ksO5mUc=; b=wqEtA/MNtRfsxm/rJ8zq/4T8LtmxyTgQPVGxubYv7kcQ5l06CIuz6sf9OBGg8SLz2Z ufmDyXnJo8ZHpi5XuOH0ZD8Pk2oyfv3eAuKJEcBBHCKMa0xVkU7tqX3/DE2U8NrkYsR0 rL081P32xtf9jekMzo7P5V0GJTalODbK0UpAb0N6YS/QVzN+5ssJd6df2V1uoUkbWM3U BsSIDepRRhHhivgzvw8MvirK6K3bqJrHA+FcJYJB2sPWrv8wr16hR9Pt43WBFcchmGgT mGjf/GQkIXyTt5G1enniVN56ZtxBzaR80yfFV/lwpLBTR+XDvYsXy575plJyAkNOl1C+ MsgQ== X-Forwarded-Encrypted: i=1; AJvYcCUYZBlRmgfneszwN3Z2GFQk5fX3Xdi56q2Om9vWWdtO+nPoNKyT+tIgs5br+YIgDiiuFhy4BJjHdIBk1i2Vekv6AHoAXhcSQsm8jp2uVW+UpmVj0bKMCWXQoXwcoBGU3Iy1DY2VMdWFMsEntxKU2NJ/T5/5dHxkvuGw4Q2uxewIL05j2ZlZ X-Gm-Message-State: AOJu0YxH0EmSNosTlbnWKFi2j3794Z6x31bbqR9u3Opegl1yZXE5V6UG 4gazJYLJYDlEDsxvNbUTp5RLe04UpjSWlFlRXzZ/zoAlc5EFZiFP X-Google-Smtp-Source: AGHT+IHGcnWVU3uZWrJira+2rU/QndOHq6hMw0pexfkmq6Vfs0ZRtEfHJDto+HPL5wXmLCqgkqqfrA== X-Received: by 2002:a2e:3a13:0:b0:2ec:5019:bec3 with SMTP id 38308e7fff4ca-2ec593e0cd9mr95407421fa.21.1719508973571; Thu, 27 Jun 2024 10:22:53 -0700 (PDT) Received: from localhost ([213.79.110.82]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2ee4a34447fsm3237781fa.11.2024.06.27.10.22.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 10:22:53 -0700 (PDT) From: Serge Semin To: Viresh Kumar , Andy Shevchenko , Vinod Koul Cc: Serge Semin , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Greg Kroah-Hartman , Jiri Slaby , dmaengine@vger.kernel.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RESEND v3 6/6] dmaengine: dw: Unify ret-val local variables naming Date: Thu, 27 Jun 2024 20:22:22 +0300 Message-ID: <20240627172231.24856-7-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240627172231.24856-1-fancer.lancer@gmail.com> References: <20240627172231.24856-1-fancer.lancer@gmail.com> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently there are two names utilized in the driver to keep the functions call status: ret and err. For the sake of unification convert to using the first version only. Signed-off-by: Serge Semin --- Changelog v2: - New patch created on v2 review stage. (Andy) --- drivers/dma/dw/core.c | 20 ++++++++++---------- drivers/dma/dw/platform.c | 20 ++++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/drivers/dma/dw/core.c b/drivers/dma/dw/core.c index 32a66f9effd9..dd75f97a33b3 100644 --- a/drivers/dma/dw/core.c +++ b/drivers/dma/dw/core.c @@ -1155,7 +1155,7 @@ int do_dma_probe(struct dw_dma_chip *chip) bool autocfg = false; unsigned int dw_params; unsigned int i; - int err; + int ret; dw->pdata = devm_kzalloc(chip->dev, sizeof(*dw->pdata), GFP_KERNEL); if (!dw->pdata) @@ -1171,7 +1171,7 @@ int do_dma_probe(struct dw_dma_chip *chip) autocfg = dw_params >> DW_PARAMS_EN & 1; if (!autocfg) { - err = -EINVAL; + ret = -EINVAL; goto err_pdata; } @@ -1191,7 +1191,7 @@ int do_dma_probe(struct dw_dma_chip *chip) pdata->chan_allocation_order = CHAN_ALLOCATION_ASCENDING; pdata->chan_priority = CHAN_PRIORITY_ASCENDING; } else if (chip->pdata->nr_channels > DW_DMA_MAX_NR_CHANNELS) { - err = -EINVAL; + ret = -EINVAL; goto err_pdata; } else { memcpy(dw->pdata, chip->pdata, sizeof(*dw->pdata)); @@ -1203,7 +1203,7 @@ int do_dma_probe(struct dw_dma_chip *chip) dw->chan = devm_kcalloc(chip->dev, pdata->nr_channels, sizeof(*dw->chan), GFP_KERNEL); if (!dw->chan) { - err = -ENOMEM; + ret = -ENOMEM; goto err_pdata; } @@ -1221,15 +1221,15 @@ int do_dma_probe(struct dw_dma_chip *chip) sizeof(struct dw_desc), 4, 0); if (!dw->desc_pool) { dev_err(chip->dev, "No memory for descriptors dma pool\n"); - err = -ENOMEM; + ret = -ENOMEM; goto err_pdata; } tasklet_setup(&dw->tasklet, dw_dma_tasklet); - err = request_irq(chip->irq, dw_dma_interrupt, IRQF_SHARED, + ret = request_irq(chip->irq, dw_dma_interrupt, IRQF_SHARED, dw->name, dw); - if (err) + if (ret) goto err_pdata; INIT_LIST_HEAD(&dw->dma.channels); @@ -1341,8 +1341,8 @@ int do_dma_probe(struct dw_dma_chip *chip) */ dma_set_max_seg_size(dw->dma.dev, dw->chan[0].block_size); - err = dma_async_device_register(&dw->dma); - if (err) + ret = dma_async_device_register(&dw->dma); + if (ret) goto err_dma_register; dev_info(chip->dev, "DesignWare DMA Controller, %d channels\n", @@ -1356,7 +1356,7 @@ int do_dma_probe(struct dw_dma_chip *chip) free_irq(chip->irq, dw); err_pdata: pm_runtime_put_sync_suspend(chip->dev); - return err; + return ret; } int do_dma_remove(struct dw_dma_chip *chip) diff --git a/drivers/dma/dw/platform.c b/drivers/dma/dw/platform.c index 7d9d4c951724..47c58ad468cb 100644 --- a/drivers/dma/dw/platform.c +++ b/drivers/dma/dw/platform.c @@ -29,7 +29,7 @@ static int dw_probe(struct platform_device *pdev) struct dw_dma_chip_pdata *data; struct dw_dma_chip *chip; struct device *dev = &pdev->dev; - int err; + int ret; match = device_get_match_data(dev); if (!match) @@ -51,9 +51,9 @@ static int dw_probe(struct platform_device *pdev) if (IS_ERR(chip->regs)) return PTR_ERR(chip->regs); - err = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); - if (err) - return err; + ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); + if (ret) + return ret; if (!data->pdata) data->pdata = dev_get_platdata(dev); @@ -69,14 +69,14 @@ static int dw_probe(struct platform_device *pdev) chip->clk = devm_clk_get_optional(chip->dev, "hclk"); if (IS_ERR(chip->clk)) return PTR_ERR(chip->clk); - err = clk_prepare_enable(chip->clk); - if (err) - return err; + ret = clk_prepare_enable(chip->clk); + if (ret) + return ret; pm_runtime_enable(&pdev->dev); - err = data->probe(chip); - if (err) + ret = data->probe(chip); + if (ret) goto err_dw_dma_probe; platform_set_drvdata(pdev, data); @@ -90,7 +90,7 @@ static int dw_probe(struct platform_device *pdev) err_dw_dma_probe: pm_runtime_disable(&pdev->dev); clk_disable_unprepare(chip->clk); - return err; + return ret; } static void dw_remove(struct platform_device *pdev)