From patchwork Mon Jun 10 01:11:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 802938 Delivered-To: patch@linaro.org Received: by 2002:adf:f147:0:b0:35b:5a80:51b4 with SMTP id y7csp1734374wro; Sun, 9 Jun 2024 18:13:52 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVBpvpjxqE8R+KakdKOiDgu4JbSkJKeMk1lq3W5niD/cl+Csb6i8PTxHtjPyXVuYLQDH9XPSLmS3AuUNwhDKL+6 X-Google-Smtp-Source: AGHT+IEBIqvZGO53x1rJ4PSN2aVhG+sHCAnkQmmz0M+huhLrjw/emJmIy2hlpAsrnj5G9SyrlEtk X-Received: by 2002:a17:907:7d8f:b0:a6f:d7a:d650 with SMTP id a640c23a62f3a-a6f0d7ad8fcmr308829666b.50.1717982032179; Sun, 09 Jun 2024 18:13:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717982032; cv=none; d=google.com; s=arc-20160816; b=GbX8g/rUkkSgdoYxiu3W5EAmdgoNdtBAKPd8uqNtkOm1whTD+rpGibLKmfrZu/iN28 6VFPsNAPYZf95O7mGyoWiRGTumWBDO0JnkusFHPLlzVuROGCJiR94sRvlB2l8PBQdkS7 nwdMM0T/jEVbI3gdQTH3CwHYVDSpMyzOdyblUVHZ4IHjFm61djy56QFOetxIR9yNA0LM uUJNveXQg7OUp5rtgi4BwaD59vE3Si4sx6wLNWBbdJrkQrYYrbhjus5PnMxHA0Z3AZZJ 25a+9Lr+DEvui/Y3AM5qJ+N4ooPEBYkA4AARkpqV5B1jQQAaSaX4Y0CjAX823JL+Yogh QdVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=lPGi4Kzt/yp52MxH8jri7SB79TNuMSqNI79PcYdBi/w=; fh=oec11W2mHoSa6+JgXEENYFmdVsC8aCF3GP6KQHjqJlA=; b=lNhQDb5ZGQLAPoKDuTPa38Ost44KX9eUUCdGccCnFgYgONOwB2AAAKCw9rd50tR3Yv hefDgqXgfP4l3wa3RTLMWAfRFd9XAl8aihE9eanbcQcHfsBjr5Y/SEuQH9FZc7ucYo+e BnU7BPXgYHUMhRb3pHw8f4J4cAYO4nwema4l2R5W0GwQfNjkE8TdcbX5Lb+AMO0pmNh7 9gYPbOXpPRSzQF6QY59bHghEUt1jtvOek+38Cdn+Z974g6AZc3qOvr1KqtUnlnleOVIK hDScSHUtuoc1P7T82m1NdshdE0Zh3wo7uJtUe1FgzmqlmKi2PIICJFWdKI/Iam6MAKlj lD5g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vn+Q7w4g; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id a640c23a62f3a-a6ef7c5ded7si239015766b.278.2024.06.09.18.13.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jun 2024 18:13:52 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vn+Q7w4g; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0C0E1884BA; Mon, 10 Jun 2024 03:12:39 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="vn+Q7w4g"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4500488468; Mon, 10 Jun 2024 03:12:35 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ot1-x32c.google.com (mail-ot1-x32c.google.com [IPv6:2607:f8b0:4864:20::32c]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 157E488433 for ; Mon, 10 Jun 2024 03:12:33 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=semen.protsenko@linaro.org Received: by mail-ot1-x32c.google.com with SMTP id 46e09a7af769-6f9611fc320so1026268a34.2 for ; Sun, 09 Jun 2024 18:12:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717981952; x=1718586752; darn=lists.denx.de; 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=lPGi4Kzt/yp52MxH8jri7SB79TNuMSqNI79PcYdBi/w=; b=vn+Q7w4gyfxjgUc2ArK8cz0osZ+zNT6SbSQp0QcG7jM+a/EfB5lNzrxCYxb1Pe/mQC bfYJw7XlFZKr8hDkgVxStK7PUC2r++B9zaJrweC+xQddkZFAsxwvInWpRACiDCttiRME ZNmkhk8k8qQ2QSfThEjyAwI4yzbnU05qBMbFHeDGivQxmD/27NBbX+BqhquzUxPSM8ns rVrX4hbgLle7X2m+Dw0s7vlxl0ZxV5BH1+h3ah5kty9TrGpex02mVaUrQmg106sW9aLc 6XPju9AEu4XosC6maY1i+8Bb2b5IaA9r8GRaGF4f/hOAP24b5souAPnVEvjW10/DO5Ow vwng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717981952; x=1718586752; 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=lPGi4Kzt/yp52MxH8jri7SB79TNuMSqNI79PcYdBi/w=; b=wn+p5jVwrSWD9GknPurgrleoJ7ieXhKr/+QI8R5VDhtHWkpowZ3l5u+mFoEnleLF5o fEB5Yx9V6oac3EhUuAvzCcCeym08WTPQP10K9chqS21JyRwVW+11LAlVVsujw1DkLFe5 i/ZpY9DrfHZLwMJnMn81ObtVW5f8gncp9gTeyRDseLyvWHhQ5upAbUtgNcFiHbkK59N/ prVFTTdfBxBEN4SWrZ7Uy2fNFCdiAfstWLL+zCJQ4Ebt2emMrAL6ZtKmMlZiVQdI1Ktg p6sH6mhmEDwjXXehJXwAt0mCpBs1m5rIzoMqKe6eZWhZbCbW8ezQ2q0W+/efWJfa2CNI bg5A== X-Forwarded-Encrypted: i=1; AJvYcCXJu27G9sk3EIgEivNBKjwg3YaEQklljL0wOSXT8TcI6fN+f7iPZbmoNHWd9KNuLWCMDytanjfrzDFXnAsPfi89ZFZAqg== X-Gm-Message-State: AOJu0YzXKPLcFXL3IViqLvYWN5VogkS7xQBzIuF9pEA42Q80YmDR3ids JcwEJ2Ndcs5tnGv4ftS+IkSv1QI8kbwOf/39vVrgUstkbBl90qa5yiMLAQ5idwQ= X-Received: by 2002:a9d:7dda:0:b0:6f9:a9f6:55e8 with SMTP id 46e09a7af769-6f9a9f6572bmr2438555a34.29.1717981951827; Sun, 09 Jun 2024 18:12:31 -0700 (PDT) Received: from localhost ([136.62.192.75]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-6f9c7f4572csm80855a34.10.2024.06.09.18.12.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jun 2024 18:12:31 -0700 (PDT) From: Sam Protsenko To: Tom Rini , Minkyu Kang , Peng Fan , Jaehoon Chung , Simon Glass Cc: Quentin Schulz , Philipp Tomsich , Kever Yang , Eugeniy Paltsev , Peter Robinson , Jonas Karlman , Yang Xiwen , Ferass El Hafidi , Sean Anderson , u-boot@lists.denx.de, uboot-snps-arc@synopsys.com Subject: [PATCH v2 07/40] mmc: dw_mmc: Extract FIFO data transfer into a separate routine Date: Sun, 9 Jun 2024 20:11:53 -0500 Message-Id: <20240610011226.4050-8-semen.protsenko@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240610011226.4050-1-semen.protsenko@linaro.org> References: <20240610011226.4050-1-semen.protsenko@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean FIFO data transfer is implemented as quite a massive chunk of code. Extract it into a dedicated function to make dwmci_data_transfer() easier to read and reduce the indentation level of the code. No functional change. Signed-off-by: Sam Protsenko --- drivers/mmc/dw_mmc.c | 107 +++++++++++++++++++++---------------------- 1 file changed, 53 insertions(+), 54 deletions(-) diff --git a/drivers/mmc/dw_mmc.c b/drivers/mmc/dw_mmc.c index 7bf3279ee9ec..37a1125fba4f 100644 --- a/drivers/mmc/dw_mmc.c +++ b/drivers/mmc/dw_mmc.c @@ -140,25 +140,67 @@ static unsigned int dwmci_get_timeout(struct mmc *mmc, const unsigned int size) return timeout; } -static int dwmci_data_transfer(struct dwmci_host *host, struct mmc_data *data) +static int dwmci_data_transfer_fifo(struct dwmci_host *host, + struct mmc_data *data, u32 mask) { - struct mmc *mmc = host->mmc; + const u32 fifo_depth = (((host->fifoth_val & RX_WMARK_MASK) >> + RX_WMARK_SHIFT) + 1) * 2; + const u32 int_rx = mask & (DWMCI_INTMSK_RXDR | DWMCI_INTMSK_DTO); + const u32 int_tx = mask & DWMCI_INTMSK_TXDR; int ret = 0; - u32 timeout, mask, size, i, len = 0; - u32 *buf = NULL; - ulong start = get_timer(0); - u32 fifo_depth = (((host->fifoth_val & RX_WMARK_MASK) >> - RX_WMARK_SHIFT) + 1) * 2; + u32 len = 0, size, i; + u32 *buf; + + size = (data->blocksize * data->blocks) / 4; + if (!host->fifo_mode || !size) + return 0; - size = data->blocksize * data->blocks; if (data->flags == MMC_DATA_READ) buf = (unsigned int *)data->dest; else buf = (unsigned int *)data->src; - timeout = dwmci_get_timeout(mmc, size); + if (data->flags == MMC_DATA_READ && int_rx) { + dwmci_writel(host, DWMCI_RINTSTS, int_rx); + while (size) { + ret = dwmci_fifo_ready(host, DWMCI_FIFO_EMPTY, &len); + if (ret < 0) + break; + + len = (len >> DWMCI_FIFO_SHIFT) & DWMCI_FIFO_MASK; + len = min(size, len); + for (i = 0; i < len; i++) + *buf++ = dwmci_readl(host, DWMCI_DATA); + size = size > len ? (size - len) : 0; + } + } else if (data->flags == MMC_DATA_WRITE && int_tx) { + while (size) { + ret = dwmci_fifo_ready(host, DWMCI_FIFO_FULL, &len); + if (ret < 0) + break; + + len = fifo_depth - ((len >> DWMCI_FIFO_SHIFT) & + DWMCI_FIFO_MASK); + len = min(size, len); + for (i = 0; i < len; i++) + dwmci_writel(host, DWMCI_DATA, *buf++); + size = size > len ? (size - len) : 0; + } + dwmci_writel(host, DWMCI_RINTSTS, DWMCI_INTMSK_TXDR); + } - size /= 4; + return ret; +} + +static int dwmci_data_transfer(struct dwmci_host *host, struct mmc_data *data) +{ + struct mmc *mmc = host->mmc; + int ret = 0; + u32 timeout, mask, size; + ulong start = get_timer(0); + + size = data->blocksize * data->blocks; + timeout = dwmci_get_timeout(mmc, size); for (;;) { mask = dwmci_readl(host, DWMCI_RINTSTS); @@ -169,50 +211,7 @@ static int dwmci_data_transfer(struct dwmci_host *host, struct mmc_data *data) break; } - if (host->fifo_mode && size) { - len = 0; - if (data->flags == MMC_DATA_READ && - (mask & (DWMCI_INTMSK_RXDR | DWMCI_INTMSK_DTO))) { - dwmci_writel(host, DWMCI_RINTSTS, - mask & (DWMCI_INTMSK_RXDR | - DWMCI_INTMSK_DTO)); - while (size) { - ret = dwmci_fifo_ready(host, - DWMCI_FIFO_EMPTY, - &len); - if (ret < 0) - break; - - len = (len >> DWMCI_FIFO_SHIFT) & - DWMCI_FIFO_MASK; - len = min(size, len); - for (i = 0; i < len; i++) - *buf++ = - dwmci_readl(host, DWMCI_DATA); - size = size > len ? (size - len) : 0; - } - } else if (data->flags == MMC_DATA_WRITE && - (mask & DWMCI_INTMSK_TXDR)) { - while (size) { - ret = dwmci_fifo_ready(host, - DWMCI_FIFO_FULL, - &len); - if (ret < 0) - break; - - len = fifo_depth - ((len >> - DWMCI_FIFO_SHIFT) & - DWMCI_FIFO_MASK); - len = min(size, len); - for (i = 0; i < len; i++) - dwmci_writel(host, DWMCI_DATA, - *buf++); - size = size > len ? (size - len) : 0; - } - dwmci_writel(host, DWMCI_RINTSTS, - DWMCI_INTMSK_TXDR); - } - } + ret = dwmci_data_transfer_fifo(host, data, mask); /* Data arrived correctly. */ if (mask & DWMCI_INTMSK_DTO) {