Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp88633lqb; Tue, 16 Apr 2024 09:30:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVzB5DfOOPbyARuTZg5eHLtkfrFB+p4J5jZpur79qVrP0HF0I3valuIbOAxWT+QPSGy7BMjyaywLVG6ijFRD55K+Bjwfv1DyePP7ebQNQ== X-Google-Smtp-Source: AGHT+IFsy1Z2XUHDE0OuYwlmHz5Rs2VELHXQP1X33gR46VZcQ9RaRTL36iDhDmQAH/2wUIc3DGhB X-Received: by 2002:a05:6a00:1302:b0:6eb:3c2d:76e0 with SMTP id j2-20020a056a00130200b006eb3c2d76e0mr16389924pfu.11.1713285029889; Tue, 16 Apr 2024 09:30:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713285029; cv=pass; d=google.com; s=arc-20160816; b=PJ13Q2MPgn5lIRz1aCbf8qqN5CArVbF/vLaMHKkqmnOcexUdmz1bVzf0VzUxSAyQ7D hHewHKgkHmClbiJ5Pz/vB1ZlHAm4hpORA4hdUF0ahKeIvZ40sJhe/R/tRahxWw4M+J6y HCeB7zlOtgQfdxLvQDJ9PeofsnS4EdPaJC9EO9d+5HZ+i3qqQa+hKJZ8VLWj7ZC9TCE+ psjd1BrC5HEma0TbL6K39L0yPEntATH15EvS99av1HQ9pZW/QleGwA3kgG54ruAYBm4F yluS4Gns/UEMqhNwew3D9I9/awizFT9RW71hyuSPS7NhdNxSr1fTglKw4t0+dFOUdRnx 4+cA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ERSdJnkxlnsAamkbGXEbd3rVP20U4VTq4AXaYwSzTK4=; fh=DbO8dvWGqlUiL9TYXB92Oev116a448kQNPura6mDM8U=; b=CN4cydHO5rdjFko45ApM5ZoA+ZP18Qz3UPR1VlcFBapvbJHFg0bY9y9jHtIOnOPyig ZlAZ8k6mA0EX9V3Lofua2nrgCilIewqP5MGo/pcy9hZeYRLKzo2RCjgW/Ku6rZ7WDzBu IMRckkXk4UrTZ+yKPshhOrIhNaeUN3NU+FADwjN5CsChf9YLfi04Y1loEYoQmFzLNz1M Z7GBkpS65kDK2jzKRYwr7/k1k4kK+bmReVkh4V7DfwdcHKzePLkD+SeL9LvlPdYtxeb3 bQ6WI2Dz8MTrIbKt+Nn73m6Fb9O1ziM1jvgSf80SE0lJVPGHnyqKcTvOD4mal/EVLh+a ay9w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=m5remeGD; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-147240-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147240-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id h5-20020a056a00170500b006eacbf31752si10345320pfc.184.2024.04.16.09.30.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 09:30:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-147240-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=m5remeGD; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-147240-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147240-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 894FA284824 for ; Tue, 16 Apr 2024 16:30:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DB44F13540C; Tue, 16 Apr 2024 16:29:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="m5remeGD" 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 D7E6D132C17; Tue, 16 Apr 2024 16:29:22 +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=1713284964; cv=none; b=u7G8jXeg2NqEeTwa1t5TPSYdFCDLgWxBuFqh7zMjjwP0WbAGtJW26d7sNJpAA5bnXwKjqsrkrKpk2BlfEZOxJ08cOhju8Bbp4F2skbl1zT/ttGin7fcRXe570hTtmOPs40Bx4+gSr1C1oHR+trSbq70ncnyDtkLS0lGuN0ieeRI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713284964; c=relaxed/simple; bh=2Kd3DIDnTnUy4CbLobJwZ9WXWWQcfVElxl61UbnfXBg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hQ33TBeL+3zUWVBsa5WFtp6tHzZogr7i1EJWsVBKNNdQFGcNoH6Mt3X133E1Zdsbm5vupU0y/Qo2JBt3l/ZMBF0Xtg1HGW1RbZq461y5WtoipmKkFyczmYB8FLAiTS7sAH4/cQauqEoVH3XOHI7QRqlCEb1ZvXT78JjSr+MkXMM= 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=m5remeGD; 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 Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-518c9ff3e29so3174801e87.0; Tue, 16 Apr 2024 09:29:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713284961; x=1713889761; 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=ERSdJnkxlnsAamkbGXEbd3rVP20U4VTq4AXaYwSzTK4=; b=m5remeGDhaa8m6vtpemN9IHJbNP48nVfOKmDYvADjaXCRlz6Xh+YnYkeMKNhWbz/WG YXe3PYSuemmN2TheJAXOz8f6eCMeBxqzu0nq4J7XmCDkHII6WGRfsEhAwsbQsgGayuF5 QxoSwY5Dhuj/r8jxz3lKhCkug47WQO7mmdv+YdfFqFPub3rz4qGwQONEbHENvjqeXvwT CkRglL/2dpxOr1LuxSWqdip8e7ydIbeXrFVokNRNKxilLvsNlayIsQ9WdImQBzJG2Z7w JwcIV9XPh4h+3pv+MFFDgR0u4NmHT0V42sgd1ZISWPxAc45rNzBqIiHobDTHH5y2GD1u c6dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713284961; x=1713889761; 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=ERSdJnkxlnsAamkbGXEbd3rVP20U4VTq4AXaYwSzTK4=; b=QGiMeNI1hxEFKNaPrefKMevhEjToBClU7tneANzmZx+ywqvzl1ZAHNrfQuXlnOFFzh wSEa7mgkeTld2M1rXARjYrf9GOMVt6az6iwQxEv+HLbjVSqT2/RNn3yYb5bMXv/mhw8Q qJgEo4Haz99SDuv+HQMgLL+aBMizgyjyZpmrgn2KH3XVnFClMClNFcyHPkV9e5VWxQBD pLUms3Bcc6QRMarEo1Uokl/cCkkMBQHXv0Ea/DGWY01Td11voJpVefW7hfZh7r1FQYvf Mg3QGkBLP1z9Z3DrgCLe+HPvCV3fWTKGYqUYVeGcUAEfHZGfMzSJEQAXcttx0vZG8N87 a5uw== X-Forwarded-Encrypted: i=1; AJvYcCXIzJw0q8Nl5rF4aKZWaIvRYPdks46bMN4NcnZw6/KAtfuEcYTSYcfmDx4Kas1X4D7QZnmneOKqcCyyOqWMAisLBHyOToAE5eBgTFAQK5q01L9b4iI6gH8qTrkAuzHGFZlJMsyApmFqPonaoPIWgap+qkEtOTq2tEOAN22BBZ5Hh+TdGvmF X-Gm-Message-State: AOJu0YzJVl48j/2oNBmakgcGBEGof5Gnbm2owpz5GsXWIWUfFpT2ItgR bDD3jShbYVY2EawdAd+taqU6LSrpo99vCE9HqGsWshR1xsRpSHVi X-Received: by 2002:a05:6512:10c5:b0:518:c371:2db4 with SMTP id k5-20020a05651210c500b00518c3712db4mr7803127lfg.10.1713284960779; Tue, 16 Apr 2024 09:29:20 -0700 (PDT) Received: from localhost (srv1.baikalchip.ru. [87.245.175.227]) by smtp.gmail.com with ESMTPSA id a11-20020a056512374b00b0051926db8fe7sm223971lfs.228.2024.04.16.09.29.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 09:29:20 -0700 (PDT) From: Serge Semin To: Viresh Kumar , Andy Shevchenko , Vinod Koul Cc: Serge Semin , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Greg Kroah-Hartman , Jiri Slaby , dmaengine@vger.kernel.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] dmaengine: dw: Simplify max-burst calculation procedure Date: Tue, 16 Apr 2024 19:28:58 +0300 Message-ID: <20240416162908.24180-5-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240416162908.24180-1-fancer.lancer@gmail.com> References: <20240416162908.24180-1-fancer.lancer@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In order to have a more coherent DW AHB DMA slave configuration method 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 DMA slave config method will turn to a set of the verification methods execution. 2. Since both the generic DW AHB DMA and Intel DMA32 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 value, 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 method will look more readable executing the verification functions one-by-one. Signed-off-by: Serge Semin --- drivers/dma/dw/core.c | 26 +++++++++++++++++--------- drivers/dma/dw/dw.c | 23 +++++++++++------------ drivers/dma/dw/idma32.c | 15 +++++++-------- drivers/dma/dw/regs.h | 1 - 4 files changed, 35 insertions(+), 30 deletions(-) diff --git a/drivers/dma/dw/core.c b/drivers/dma/dw/core.c index 61e026310dd8..8b4ecd137ae2 100644 --- a/drivers/dma/dw/core.c +++ b/drivers/dma/dw/core.c @@ -779,6 +779,21 @@ bool dw_dma_filter(struct dma_chan *chan, void *param) } EXPORT_SYMBOL_GPL(dw_dma_filter); +static void 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); +} + static int dwc_verify_p_buswidth(struct dma_chan *chan) { struct dw_dma_chan *dwc = to_dw_dma_chan(chan); @@ -828,7 +843,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); } @@ -839,15 +854,11 @@ 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 err; 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); + dwc_verify_maxburst(chan); err = dwc_verify_p_buswidth(chan); if (err) @@ -857,9 +868,6 @@ static int dwc_config(struct dma_chan *chan, struct dma_slave_config *sconfig) if (err) return err; - 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 c65438d1f1ff..c52333646edd 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 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. + */ + return 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; @@ -73,10 +82,10 @@ static u32 dw_dma_prepare_ctllo(struct dw_dma_chan *dwc) sms = dwc->dws.m_master; smsize = 0; 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; - smsize = sconfig->src_maxburst; + smsize = dw_dma_encode_maxburst(sconfig->src_maxburst); dms = dwc->dws.m_master; dmsize = 0; } else /* DMA_MEM_TO_MEM */ { @@ -91,15 +100,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); @@ -128,7 +128,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 3a1b12517655..428aba9fc2db 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 inline u32 idma32_encode_maxburst(u32 maxburst) +{ + return maxburst > 1 ? fls(maxburst) - 1 : 0; +} + static u32 idma32_prepare_ctllo(struct dw_dma_chan *dwc) { struct dma_slave_config *sconfig = &dwc->dma_sconfig; @@ -206,9 +211,9 @@ static u32 idma32_prepare_ctllo(struct dw_dma_chan *dwc) if (dwc->direction == DMA_MEM_TO_DEV) { smsize = 0; - 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); dmsize = 0; } else /* DMA_MEM_TO_MEM */ { smsize = 0; @@ -219,11 +224,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); @@ -280,7 +280,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); -- 2.43.0