From patchwork Wed Feb 7 20:22:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Zhang X-Patchwork-Id: 198129 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2566843dyb; Wed, 7 Feb 2024 15:29:18 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUaleBlcntFdJT63F6qoWJtjjI4mL5pTyJwONWiPw0qcYHLSX1WadWJNytiuroW9Ej/pV5K5ZDB0qtGmc3u2PvRRcdgEw== X-Google-Smtp-Source: AGHT+IE+bG26CX8TrbVuQ9ekqCG5c7THxA7KaKdgWZIWRAAmyYLhNiGsIdcNfv74Rvr+fnmotrbV X-Received: by 2002:a92:905:0:b0:363:bc94:7ea6 with SMTP id y5-20020a920905000000b00363bc947ea6mr6552666ilg.31.1707348558779; Wed, 07 Feb 2024 15:29:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707348558; cv=pass; d=google.com; s=arc-20160816; b=V3rneY32uE5gPZ5vnX35UhZVyWdi6RsFXxtsRYJsFBGKH0E2JOc9s0oPRNRVdLpJBL L+WjwFk2Dif/4QuhC7SyKayP9Q5CEJzqFJuZjihs8AIWbryC1JzuDikCDYUNIStl8iDN 8wpz7ryuQTinLIz4O737GLY9HBCbxKVq+EOdvPWspFqh6RJof539nHOBPJjpU3RvQ321 iv+N/GV+4wIaLjyfRv8s60UrRFFrDg/vXHeJGMv6geflKw589aKoVCm2h3IQylIlA2iF pJnpjVE8ohwZO8JAvGXi9OzLjkwqslchk5+vvyWrCvdakWvI03PpFCOO1J/LcwZyM51W yfmQ== 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:dkim-filter; bh=y/Nim1Tszu1HVYl8OsNhcwhgB3DIuIKi0TfwvLTnL/s=; fh=p9yBHZiVGzEwepG4hHjTul8Nnik7IO/v0i4K1d2yOAQ=; b=bdKm4PTQj504kthQihSsJ6Tuw11NcY1fLuML2JYNSO9zKh20Qo6XoECPNVNwb7FDUD uiSyeYwg/dIVBYzMRtcpLT46GquCCnFxqgYDi6oGj+5F805akOOOzzNDPI25E5KhA0mc gU8h5xOj7PjzyCtD7Tuu2bZAO007bxqeVAhThZ4bp94kPmbadt67+mQJeDv1FHWWfp9e 6yA3A+ZHWT4Fo8/H6LP1ywirL8ZOqRJydaZ8noX3ysleaw+XeTNtYX5Tfv12d5ir7EwQ 8DEU5/XugF3k0rLL12zM+eZBatMLu5q9t/4b6F8xYdvWhrz8lQW0UtmgtORjNhsnwMqx rPhg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@broadcom.com header.s=dkimrelay header.b=HMo4Y+GP; arc=pass (i=1 dkim=pass dkdomain=broadcom.com dmarc=pass fromdomain=broadcom.com); spf=pass (google.com: domain of linux-kernel+bounces-57019-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57019-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com X-Forwarded-Encrypted: i=2; AJvYcCWByCcweUWAKzf0LpHZ7ZsxUI+FRoBCbnDgeBh0MeL6r+Qn83Lrvsl5Z+cBI2FLBXMh6xQwcmxv/lKApqpa6Juw5IhiUw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id cl13-20020a056a02098d00b005ce3c33c303si2883815pgb.301.2024.02.07.15.29.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 15:29:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57019-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@broadcom.com header.s=dkimrelay header.b=HMo4Y+GP; arc=pass (i=1 dkim=pass dkdomain=broadcom.com dmarc=pass fromdomain=broadcom.com); spf=pass (google.com: domain of linux-kernel+bounces-57019-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57019-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.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 E626D28CD83 for ; Wed, 7 Feb 2024 20:25:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 92EE712C814; Wed, 7 Feb 2024 20:24:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="HMo4Y+GP" Received: from relay.smtp-ext.broadcom.com (unknown [192.19.166.228]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7AF012AAFE for ; Wed, 7 Feb 2024 20:24:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.19.166.228 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707337447; cv=none; b=mIUlnQCylRSQ3R0N2J9ruOn+CeunXavxSpf0aduy4mSUnGL23Ezcj0ZyTegOiu7tFWqm6utl3Q0UVBVY/RoMSWOp3eY6yi9nz52rUTJEWF2YAlEWy2aU0Q3IWoQUthEYqZTMLMlsxAFODn6FF+jca3q655LA2n/uV2/tWdl8XFs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707337447; c=relaxed/simple; bh=3KI+0H7nre5BBb1mmhtPwiG4aWlQO8hYYw+faxeJstM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=g2xFcSrTRyhOVsiMUVxvoMDCn7NY1Pg+wBQeQchgTC3415oivL7odF546q9+TOuyOirHWRocdoUu7XdPg27g9rNynhvI8+DmyhbTRPPw+F7BvAQRDRjGKeyuU1NQptjmBv78WDnyAxD3IdQVwwSH8bv2QHx81uOiqE2BZbs1Fj0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b=HMo4Y+GP; arc=none smtp.client-ip=192.19.166.228 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Received: from mail-lvn-it-01.lvn.broadcom.net (mail-lvn-it-01.lvn.broadcom.net [10.36.132.253]) by relay.smtp-ext.broadcom.com (Postfix) with ESMTP id 48939C0094CB; Wed, 7 Feb 2024 12:24:05 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 relay.smtp-ext.broadcom.com 48939C0094CB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=broadcom.com; s=dkimrelay; t=1707337445; bh=3KI+0H7nre5BBb1mmhtPwiG4aWlQO8hYYw+faxeJstM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HMo4Y+GPif6wR5z2grQbbEMwdkWpMt6TTdgkZKgxEbzxAEKH9OOSGthlH4YY3gakM Vq0N2FLp0VHRFwEArGVxUsGNzce8Li4YpULVCxEASOy1AKuA5bSf3R3MgokJ2rcyzj UWwFPIGCuHFJO4QSR/Fbnb/Sh8mk1p+6HC7ULOfo= Received: from bcacpedev-irv-3.lvn.broadcom.net (bcacpedev-irv-3.lvn.broadcom.net [10.173.232.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail-lvn-it-01.lvn.broadcom.net (Postfix) with ESMTPSA id D693A18041CAC4; Wed, 7 Feb 2024 12:24:03 -0800 (PST) From: William Zhang To: Linux MTD List , Linux ARM List , Broadcom Kernel List Cc: f.fainelli@gmail.com, kursad.oney@broadcom.com, joel.peshkin@broadcom.com, anand.gore@broadcom.com, dregan@mail.com, kamal.dasu@broadcom.com, tomer.yacoby@broadcom.com, dan.beygelman@broadcom.com, William Zhang , David Regan , Miquel Raynal , linux-kernel@vger.kernel.org, Vignesh Raghavendra , Brian Norris , Richard Weinberger , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Florian Fainelli Subject: [PATCH v5 08/12] mtd: rawnand: brcmnand: Add BCMBCA read data bus interface Date: Wed, 7 Feb 2024 12:22:53 -0800 Message-Id: <20240207202257.271784-9-william.zhang@broadcom.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20240207202257.271784-1-william.zhang@broadcom.com> References: <20240207202257.271784-1-william.zhang@broadcom.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790284722322061237 X-GMAIL-MSGID: 1790284722322061237 The BCMBCA broadband SoC integrates the NAND controller differently than STB, iProc and other SoCs. It has different endianness for NAND cache data. Add a SoC read data bus shim for BCMBCA to meet the specific SoC need and performance improvement using the optimized memcpy function on NAND cache memory. Signed-off-by: William Zhang Reviewed-by: David Regan --- Changes in v5: None Changes in v4: None Changes in v3: - Updated bcmbca_read_data_bus comment Changes in v2: - Drop the is_param argument to the read data bus function now that we have the exec_op API to read the parameter page and ONFI data - Remove be32_to_cpu from brcmnand_read_data_bus drivers/mtd/nand/raw/brcmnand/bcmbca_nand.c | 27 +++++++++++++++++++++ drivers/mtd/nand/raw/brcmnand/brcmnand.c | 20 ++++++++++++--- drivers/mtd/nand/raw/brcmnand/brcmnand.h | 2 ++ 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/nand/raw/brcmnand/bcmbca_nand.c b/drivers/mtd/nand/raw/brcmnand/bcmbca_nand.c index 3e2f3b79788d..7ad3e7a98f97 100644 --- a/drivers/mtd/nand/raw/brcmnand/bcmbca_nand.c +++ b/drivers/mtd/nand/raw/brcmnand/bcmbca_nand.c @@ -26,6 +26,18 @@ enum { BCMBCA_CTLRDY = BIT(4), }; +#if defined(CONFIG_ARM64) +#define ALIGN_REQ 8 +#else +#define ALIGN_REQ 4 +#endif + +static inline bool bcmbca_nand_is_buf_aligned(void *flash_cache, void *buffer) +{ + return IS_ALIGNED((uintptr_t)buffer, ALIGN_REQ) && + IS_ALIGNED((uintptr_t)flash_cache, ALIGN_REQ); +} + static bool bcmbca_nand_intc_ack(struct brcmnand_soc *soc) { struct bcmbca_nand_soc *priv = @@ -56,6 +68,20 @@ static void bcmbca_nand_intc_set(struct brcmnand_soc *soc, bool en) brcmnand_writel(val, mmio); } +static void bcmbca_read_data_bus(struct brcmnand_soc *soc, + void __iomem *flash_cache, u32 *buffer, int fc_words) +{ + /* + * memcpy can do unaligned aligned access depending on source + * and dest address, which is incompatible with nand cache. Fallback + * to the memcpy_fromio in such case + */ + if (bcmbca_nand_is_buf_aligned((void *)flash_cache, buffer)) + memcpy((void *)buffer, (void *)flash_cache, fc_words * 4); + else + memcpy_fromio((void *)buffer, flash_cache, fc_words * 4); +} + static int bcmbca_nand_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -73,6 +99,7 @@ static int bcmbca_nand_probe(struct platform_device *pdev) soc->ctlrdy_ack = bcmbca_nand_intc_ack; soc->ctlrdy_set_enabled = bcmbca_nand_intc_set; + soc->read_data_bus = bcmbca_read_data_bus; return brcmnand_probe(pdev, soc); } diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c index 8faca43ae1ff..73fdf7ce21aa 100644 --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c @@ -851,6 +851,20 @@ static inline u32 edu_readl(struct brcmnand_controller *ctrl, return brcmnand_readl(ctrl->edu_base + offs); } +static inline void brcmnand_read_data_bus(struct brcmnand_controller *ctrl, + void __iomem *flash_cache, u32 *buffer, int fc_words) +{ + struct brcmnand_soc *soc = ctrl->soc; + int i; + + if (soc->read_data_bus) { + soc->read_data_bus(soc, flash_cache, buffer, fc_words); + } else { + for (i = 0; i < fc_words; i++) + buffer[i] = brcmnand_read_fc(ctrl, i); + } +} + static void brcmnand_clear_ecc_addr(struct brcmnand_controller *ctrl) { @@ -1975,7 +1989,7 @@ static int brcmnand_read_by_pio(struct mtd_info *mtd, struct nand_chip *chip, { struct brcmnand_host *host = nand_get_controller_data(chip); struct brcmnand_controller *ctrl = host->ctrl; - int i, j, ret = 0; + int i, ret = 0; brcmnand_clear_ecc_addr(ctrl); @@ -1988,8 +2002,8 @@ static int brcmnand_read_by_pio(struct mtd_info *mtd, struct nand_chip *chip, if (likely(buf)) { brcmnand_soc_data_bus_prepare(ctrl->soc, false); - for (j = 0; j < FC_WORDS; j++, buf++) - *buf = brcmnand_read_fc(ctrl, j); + brcmnand_read_data_bus(ctrl, ctrl->nand_fc, buf, FC_WORDS); + buf += FC_WORDS; brcmnand_soc_data_bus_unprepare(ctrl->soc, false); } diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.h b/drivers/mtd/nand/raw/brcmnand/brcmnand.h index 928114c0be5e..7261a69989fe 100644 --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.h +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.h @@ -24,6 +24,8 @@ struct brcmnand_soc { void (*ctlrdy_set_enabled)(struct brcmnand_soc *soc, bool en); void (*prepare_data_bus)(struct brcmnand_soc *soc, bool prepare, bool is_param); + void (*read_data_bus)(struct brcmnand_soc *soc, void __iomem *flash_cache, + u32 *buffer, int fc_words); const struct brcmnand_io_ops *ops; };