From patchwork Tue Jun 6 23:12:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Zhang X-Patchwork-Id: 104150 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3738060vqr; Tue, 6 Jun 2023 16:38:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7nbEQjmCoO2I8UHm2a9BUN5aYLo2CJi8UrnJxC5g4J3To2W16o4TFoW3/JeCYeKdT7Wpkx X-Received: by 2002:a05:6a00:99b:b0:655:6bcf:208a with SMTP id u27-20020a056a00099b00b006556bcf208amr4328948pfg.6.1686094735273; Tue, 06 Jun 2023 16:38:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686094735; cv=none; d=google.com; s=arc-20160816; b=dYU5wqZcXl4FyrSLjUQaO3qB+38lmX/fvPh5H+hW0fYu/pIPAVBMECKFbqBeeW/iEY 4GIrThdWXYs14wUBQPf/Br+2VRO16PhJc2kCTFRb2amAXhDt3bgWUUl19HR+8u4r/wy8 +cT7nbeplJha9lor/N+N4qQqNgx1N1iju07wjgIuqKLiXzghUsyKWy01rFFw4Ue1Fqcn w64AmtFXFQxqbwAzBp08yuKmiuDxj/5nr0/cUC0e6RMWBlFORcidCVoyQr6fWAdHgg9e KSvrxnqsRGMlEWXMdYKHjcS7N8Tc8en11KqCnx9/s/OxZrSZx5YBlHIdUKRCB1nxfPC3 2hdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=U+Z84/AfzP1MYacvhjEamKy0f7DBRojW2nAeEre6Y5c=; b=Bzo0+58aftkitKLZ21QVp42DKeUPorzNVHgeR8kGmM+4n4JU7EZ3Aj8rc1jS9hek+r AH/o6OGNUz1NX4XC8AWoYe5rSSrcLpvRg2IqUa4yNlIbsH8TjuUiQMyNLUrSdn+HZEaW AWv3zkehoL10pTqAWk5Ei4jKlUfQcElkHSuJpgLQcqleb3XGD66Tnwty7taggOWHLd+A 2le2QgFOsa71/gtUSUlAjuQcX7g4J8HEnrmfh+FsZh7ohAWq+n20gYgXWP54iEb6Rkgi tz1JfL5u6A/51KhwLEzfXg+usqIfGJt7/1LffRBm0dlcLzbexz5CS7n3pzCZtKkR1AZR JAwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b="dWM/Zn8f"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y12-20020aa79aec000000b0064f44863407si6188383pfp.384.2023.06.06.16.38.41; Tue, 06 Jun 2023 16:38:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b="dWM/Zn8f"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240315AbjFFXPQ (ORCPT + 99 others); Tue, 6 Jun 2023 19:15:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240236AbjFFXOq (ORCPT ); Tue, 6 Jun 2023 19:14:46 -0400 Received: from mail-qv1-xf2a.google.com (mail-qv1-xf2a.google.com [IPv6:2607:f8b0:4864:20::f2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6CD81723 for ; Tue, 6 Jun 2023 16:14:45 -0700 (PDT) Received: by mail-qv1-xf2a.google.com with SMTP id 6a1803df08f44-62b699b88e1so4354076d6.1 for ; Tue, 06 Jun 2023 16:14:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1686093285; x=1688685285; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=U+Z84/AfzP1MYacvhjEamKy0f7DBRojW2nAeEre6Y5c=; b=dWM/Zn8fIv72Rap3CadIPAy7izpJgg1EUz+A4LqaCoNOfUTJEoOcevr97mTdfsPbvG JQmFoCXVqr8q5Ytlb0NroBv5KT8A4JF6IHlrY80YbZG5qivCGKKE3vu0I8iIhc9mO7Iq pKjxxELjXXcJXpGot5mMb+7Up+ZGf1OroYIyU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686093285; x=1688685285; h=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=U+Z84/AfzP1MYacvhjEamKy0f7DBRojW2nAeEre6Y5c=; b=NtQCysrmXSMcIKG3c/T5wRlRKe2Hqeq1uwXHNOPAqF9s7J6s48VoctjiQf71HVM+qD 6qVeBCYIYLBzMv1hBETfql4c+S9svjd9C87KzTb6OlryJZGjjJQ1YH7eydv81G+DUYRe lG4S3dPlFnysqVFCxRP9/ims3WpMtJOAujT09vlRqS6sL1ZAMzLCgu+7OpMdjIi8phnN G73FDQC/cWs/dQMKMeDBa7On2fIZ0oYTLfqNEwcLxNC5NUIQw8g4yXmQzzfT0OCDs/vm j1OQ01IrDCCsGz2ruheEKIuekOdQlkfhEhRnWyZgfK92P+F3LCol3KW18QCaykMozW+9 yEUw== X-Gm-Message-State: AC+VfDytWE30q/VkYDi7Uz/Ehy1Bd7RkfT5jKYCL0i3qXQIpXifgmKUV +Ao+w/cfeJ0oQqaBW51K86slYg== X-Received: by 2002:ad4:5c8e:0:b0:625:aa49:19f3 with SMTP id o14-20020ad45c8e000000b00625aa4919f3mr1208739qvh.64.1686093284715; Tue, 06 Jun 2023 16:14:44 -0700 (PDT) Received: from ubuntu-22.localdomain ([192.19.222.250]) by smtp.gmail.com with ESMTPSA id x9-20020ae9e909000000b0075b23e55640sm5221519qkf.123.2023.06.06.16.14.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jun 2023 16:14:44 -0700 (PDT) From: William Zhang To: Broadcom Kernel List , Linux MTD List Cc: f.fainelli@gmail.com, rafal@milecki.pl, kursad.oney@broadcom.com, joel.peshkin@broadcom.com, computersforpeace@gmail.com, anand.gore@broadcom.com, dregan@mail.com, kamal.dasu@broadcom.com, tomer.yacoby@broadcom.com, dan.beygelman@broadcom.com, William Zhang , Miquel Raynal , linux-kernel@vger.kernel.org, Vignesh Raghavendra , Richard Weinberger , Kamal Dasu , linux-arm-kernel@lists.infradead.org Subject: [PATCH 10/12] mtd: rawnand: brcmnand: Add BCMBCA read data bus interface Date: Tue, 6 Jun 2023 16:12:50 -0700 Message-Id: <20230606231252.94838-11-william.zhang@broadcom.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230606231252.94838-1-william.zhang@broadcom.com> References: <20230606231252.94838-1-william.zhang@broadcom.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767998472933372452?= X-GMAIL-MSGID: =?utf-8?q?1767998472933372452?= The BCMBCA broadband SoC integrates the NAND controller differently than STB, iProc and other SoCs. It has different endianness for NAND cache data and ONFI parameter 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 --- drivers/mtd/nand/raw/brcmnand/bcmbca_nand.c | 36 +++++++++++++++++ drivers/mtd/nand/raw/brcmnand/brcmnand.c | 44 ++++++++++++++------- drivers/mtd/nand/raw/brcmnand/brcmnand.h | 2 + 3 files changed, 68 insertions(+), 14 deletions(-) diff --git a/drivers/mtd/nand/raw/brcmnand/bcmbca_nand.c b/drivers/mtd/nand/raw/brcmnand/bcmbca_nand.c index 7e48b6a0bfa2..899103a62c98 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,29 @@ 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, bool is_param) +{ + int i; + + if (!is_param) { + /* + * memcpy can do unaligned aligned access depending on source + * and dest address, which is incompatible with nand cache. Fallback + * to the memcpy for io version + */ + if (bcmbca_nand_is_buf_aligned(flash_cache, buffer)) + memcpy((void *)buffer, (void *)flash_cache, fc_words * 4); + else + memcpy_fromio((void *)buffer, (void *)flash_cache, fc_words * 4); + } else { + /* Flash cache has same endian as the host for parameter pages */ + for (i = 0; i < fc_words; i++, buffer++) + *buffer = __raw_readl(flash_cache + i * 4); + } +} + static int bcmbca_nand_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -75,6 +110,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 d920e88c7f5b..656be4d73016 100644 --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c @@ -814,6 +814,30 @@ 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, bool is_param) +{ + struct brcmnand_soc *soc = ctrl->soc; + int i; + + if (soc->read_data_bus) { + soc->read_data_bus(soc, flash_cache, buffer, fc_words, is_param); + } else { + if (!is_param) { + for (i = 0; i < fc_words; i++, buffer++) + *buffer = brcmnand_read_fc(ctrl, i); + } else { + for (i = 0; i < fc_words; i++) + /* + * Flash cache is big endian for parameter pages, at + * least on STB SoCs + */ + buffer[i] = be32_to_cpu(brcmnand_read_fc(ctrl, i)); + } + } +} + static void brcmnand_clear_ecc_addr(struct brcmnand_controller *ctrl) { @@ -1811,20 +1835,11 @@ static void brcmnand_cmdfunc(struct nand_chip *chip, unsigned command, native_cmd == CMD_PARAMETER_CHANGE_COL) { /* Copy flash cache word-wise */ u32 *flash_cache = (u32 *)ctrl->flash_cache; - int i; brcmnand_soc_data_bus_prepare(ctrl->soc, true); - /* - * Must cache the FLASH_CACHE now, since changes in - * SECTOR_SIZE_1K may invalidate it - */ - for (i = 0; i < FC_WORDS; i++) - /* - * Flash cache is big endian for parameter pages, at - * least on STB SoCs - */ - flash_cache[i] = be32_to_cpu(brcmnand_read_fc(ctrl, i)); + brcmnand_read_data_bus(ctrl, ctrl->nand_fc, flash_cache, + FC_WORDS, true); brcmnand_soc_data_bus_unprepare(ctrl->soc, true); @@ -2137,7 +2152,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); @@ -2150,8 +2165,9 @@ 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, false); + 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 f1f93d85f50d..88819bc395f8 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, bool is_param); const struct brcmnand_io_ops *ops; };