From patchwork Tue Jun 27 19:37:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Zhang X-Patchwork-Id: 113559 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8434098vqr; Tue, 27 Jun 2023 12:49:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6BxMOxtK8eheimtJ2urIWpRCQh27AJMdLGtMZDLM8JKUspeWqrzmOMWpa//XxkC681SZ8M X-Received: by 2002:aa7:d351:0:b0:51d:9737:5257 with SMTP id m17-20020aa7d351000000b0051d97375257mr4538153edr.40.1687895398439; Tue, 27 Jun 2023 12:49:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687895398; cv=none; d=google.com; s=arc-20160816; b=Dwbn4XEGCdfdP8uCggANq8Cap7YjwTyJTbff/omj40M/zlL3LQ6AY2dg6lWmPZGXGg PhKa8UmHC+HgWC1HQnugs0rtFvuyU+URd/7bcMqqkYd6Z5+qH6KDO5sLcC9cGmuvPRnc 4RS6bJRms6wUVZXxzxPbwgdTMub3a8G4Prs9zeQ6it5nwa6tGkyVnppvMd59Y8fcM2PX f61jDeJ9L7bcREleJUpdpJCVhMUGxwH9VCCXOemjLr/i3hoS1dV61x1wqIwmNzLEbG0k 0ri1ypIfqSmNjp8+tPcLx2pWDqbLXzMG9sp8upA3Ku8Lv4P/pdd+vjKZdDRc3PrUrz5U jOVw== 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=9sRDVdhVXF20t74m0nwGTpI6Lg1jpaS1EEnPgZIqnMk=; fh=8o8F3rZxqIR7uEOb7V/ca7Dc/uMDZkwCPWOeUWHuQlE=; b=dkBxyhZJbjfUAYDRBo40NHeuEUzQfmD5qOHyDl95PM1MPeGP8QgriCAyiLXLupSH0O cNwe++JEwyWoso2h7GrmWcNofBZf2oMxCIPdYXaAd3LJr1SeNPS+qKZ+eLMf9pTFzI4r 5hXRowiwW66sP4JYjbl0rvvUUHdLFUGMmPjV0kxoBdcblGAF4qEkTkyMSYvD+hcfHPXR i6ln4WuBaY6c8YNzW67RTPjUMYOhLk5WEDGiLcFvRqV3h1D/BbQ3aJzPc7fjnI+D6qdf uOZISVPuc4WuU1gUhr0ZE8ZDNkuTV5gG1V9eLdgD/3VH1mTB7Eyj1klrCho6QeNiaNrq lIsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b="Tv/EGcdk"; 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 g20-20020a50ee14000000b0051dab455837si1180105eds.310.2023.06.27.12.49.33; Tue, 27 Jun 2023 12:49:58 -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="Tv/EGcdk"; 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 S229495AbjF0TiX (ORCPT + 99 others); Tue, 27 Jun 2023 15:38:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230115AbjF0TiV (ORCPT ); Tue, 27 Jun 2023 15:38:21 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AB1426B7 for ; Tue, 27 Jun 2023 12:38:15 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1b7f68f1c9eso27430435ad.2 for ; Tue, 27 Jun 2023 12:38:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1687894695; x=1690486695; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=9sRDVdhVXF20t74m0nwGTpI6Lg1jpaS1EEnPgZIqnMk=; b=Tv/EGcdknpW6cm5v1J8docAsGHyhUgrPq6/xEmLSuFvAq4LFVq0LQvNH0AHlj7/NuR jKdGAIWGkYejR+434oyWgZMGJxfecbkXIODFQKESbAnQYul+8+gxsva/CItmusio76DR smlXympi9M6TC67AaAzqRHQSkXYGsPzkzf7b0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687894695; x=1690486695; 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=9sRDVdhVXF20t74m0nwGTpI6Lg1jpaS1EEnPgZIqnMk=; b=AoxDztgTQUfMGQw1ESuIrB4hhdgk9mq6p/0eX+eWKv5wJNw8P1t0CCObSkBkDEzdV7 GcE1/QBvzZcvwdxH9JyBMLivEuoBtlHTn446LZlfRhWRJYjxn+luy/0qtuo1YfDPmYdN WC7OuuJGWxluzaqdW+QJBLEPwi4egO/JQmx2GAWlxNJs7fkOEKV3Me+uOKTr+Rnv4ia7 0SqSxzPY8CzvCITrbEouLDV6KuHY6rAMOidDLDWxeauV5Lm/GGKoz8Zs/MG2tI3j3lQc nrqZFzTG2P3sIz3JAtAuOvtbMm0D6XKygKN72Q2opbBeyi8Rva1u1IgATPOnmN0oNUr9 8hGA== X-Gm-Message-State: AC+VfDx5AJ3Xb9BfxnkyL+BxHV+T55gu4cqlEMJOHhXYvkFo/gNT/L0Q aA9QF/GJ/ofFYaWpXyRSaZ5Xkw== X-Received: by 2002:a17:903:246:b0:1a6:d15f:3ce1 with SMTP id j6-20020a170903024600b001a6d15f3ce1mr14129693plh.34.1687894694663; Tue, 27 Jun 2023 12:38:14 -0700 (PDT) Received: from ubuntu-22.localdomain ([192.19.222.250]) by smtp.gmail.com with ESMTPSA id g7-20020a1709026b4700b001b7f40a8959sm4986919plt.76.2023.06.27.12.38.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 12:38:13 -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 , Florian Fainelli , Rob Herring , linux-kernel@vger.kernel.org, Vignesh Raghavendra , Miquel Raynal , Richard Weinberger , Boris Brezillon , Kamal Dasu Subject: [PATCH v3 1/5] mtd: rawnand: brcmnand: Fix ECC level field setting for v7.2 controller Date: Tue, 27 Jun 2023 12:37:34 -0700 Message-Id: <20230627193738.19596-2-william.zhang@broadcom.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230627193738.19596-1-william.zhang@broadcom.com> References: <20230627193738.19596-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?1769886605777753076?= X-GMAIL-MSGID: =?utf-8?q?1769886605777753076?= v7.2 controller has different ECC level field size and shift in the acc control register than its predecessor and successor controller. It needs to be set specifically. Fixes: decba6d47869 ("mtd: brcmnand: Add v7.2 controller support") Signed-off-by: William Zhang Reviewed-by: Florian Fainelli --- Changes in v3: None Changes in v2: - Use driver static data for ECC level shift drivers/mtd/nand/raw/brcmnand/brcmnand.c | 74 +++++++++++++----------- 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c index 2e9c2e2d9c9f..69709419516a 100644 --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c @@ -272,6 +272,7 @@ struct brcmnand_controller { const unsigned int *page_sizes; unsigned int page_size_shift; unsigned int max_oob; + u32 ecc_level_shift; u32 features; /* for low-power standby/resume only */ @@ -596,6 +597,34 @@ enum { INTFC_CTLR_READY = BIT(31), }; +/*********************************************************************** + * NAND ACC CONTROL bitfield + * + * Some bits have remained constant throughout hardware revision, while + * others have shifted around. + ***********************************************************************/ + +/* Constant for all versions (where supported) */ +enum { + /* See BRCMNAND_HAS_CACHE_MODE */ + ACC_CONTROL_CACHE_MODE = BIT(22), + + /* See BRCMNAND_HAS_PREFETCH */ + ACC_CONTROL_PREFETCH = BIT(23), + + ACC_CONTROL_PAGE_HIT = BIT(24), + ACC_CONTROL_WR_PREEMPT = BIT(25), + ACC_CONTROL_PARTIAL_PAGE = BIT(26), + ACC_CONTROL_RD_ERASED = BIT(27), + ACC_CONTROL_FAST_PGM_RDIN = BIT(28), + ACC_CONTROL_WR_ECC = BIT(30), + ACC_CONTROL_RD_ECC = BIT(31), + + ACC_CONTROL_ECC_SHIFT = 16, + /* Only for v7.2 */ + ACC_CONTROL_ECC_EXT_SHIFT = 13, +}; + static inline bool brcmnand_non_mmio_ops(struct brcmnand_controller *ctrl) { #if IS_ENABLED(CONFIG_MTD_NAND_BRCMNAND_BCMA) @@ -737,6 +766,12 @@ static int brcmnand_revision_init(struct brcmnand_controller *ctrl) else if (of_property_read_bool(ctrl->dev->of_node, "brcm,nand-has-wp")) ctrl->features |= BRCMNAND_HAS_WP; + /* v7.2 has different ecc level shift in the acc register */ + if (ctrl->nand_version == 0x0702) + ctrl->ecc_level_shift = ACC_CONTROL_ECC_EXT_SHIFT; + else + ctrl->ecc_level_shift = ACC_CONTROL_ECC_SHIFT; + return 0; } @@ -931,30 +966,6 @@ static inline int brcmnand_cmd_shift(struct brcmnand_controller *ctrl) return 0; } -/*********************************************************************** - * NAND ACC CONTROL bitfield - * - * Some bits have remained constant throughout hardware revision, while - * others have shifted around. - ***********************************************************************/ - -/* Constant for all versions (where supported) */ -enum { - /* See BRCMNAND_HAS_CACHE_MODE */ - ACC_CONTROL_CACHE_MODE = BIT(22), - - /* See BRCMNAND_HAS_PREFETCH */ - ACC_CONTROL_PREFETCH = BIT(23), - - ACC_CONTROL_PAGE_HIT = BIT(24), - ACC_CONTROL_WR_PREEMPT = BIT(25), - ACC_CONTROL_PARTIAL_PAGE = BIT(26), - ACC_CONTROL_RD_ERASED = BIT(27), - ACC_CONTROL_FAST_PGM_RDIN = BIT(28), - ACC_CONTROL_WR_ECC = BIT(30), - ACC_CONTROL_RD_ECC = BIT(31), -}; - static inline u32 brcmnand_spare_area_mask(struct brcmnand_controller *ctrl) { if (ctrl->nand_version == 0x0702) @@ -967,18 +978,15 @@ static inline u32 brcmnand_spare_area_mask(struct brcmnand_controller *ctrl) return GENMASK(4, 0); } -#define NAND_ACC_CONTROL_ECC_SHIFT 16 -#define NAND_ACC_CONTROL_ECC_EXT_SHIFT 13 - static inline u32 brcmnand_ecc_level_mask(struct brcmnand_controller *ctrl) { u32 mask = (ctrl->nand_version >= 0x0600) ? 0x1f : 0x0f; - mask <<= NAND_ACC_CONTROL_ECC_SHIFT; + mask <<= ACC_CONTROL_ECC_SHIFT; /* v7.2 includes additional ECC levels */ - if (ctrl->nand_version >= 0x0702) - mask |= 0x7 << NAND_ACC_CONTROL_ECC_EXT_SHIFT; + if (ctrl->nand_version == 0x0702) + mask |= 0x7 << ACC_CONTROL_ECC_EXT_SHIFT; return mask; } @@ -992,8 +1000,8 @@ static void brcmnand_set_ecc_enabled(struct brcmnand_host *host, int en) if (en) { acc_control |= ecc_flags; /* enable RD/WR ECC */ - acc_control |= host->hwcfg.ecc_level - << NAND_ACC_CONTROL_ECC_SHIFT; + acc_control &= ~brcmnand_ecc_level_mask(ctrl); + acc_control |= host->hwcfg.ecc_level << ctrl->ecc_level_shift; } else { acc_control &= ~ecc_flags; /* disable RD/WR ECC */ acc_control &= ~brcmnand_ecc_level_mask(ctrl); @@ -2561,7 +2569,7 @@ static int brcmnand_set_cfg(struct brcmnand_host *host, tmp &= ~brcmnand_ecc_level_mask(ctrl); tmp &= ~brcmnand_spare_area_mask(ctrl); if (ctrl->nand_version >= 0x0302) { - tmp |= cfg->ecc_level << NAND_ACC_CONTROL_ECC_SHIFT; + tmp |= cfg->ecc_level << ctrl->ecc_level_shift; tmp |= cfg->spare_area_size; } nand_writereg(ctrl, acc_control_offs, tmp); From patchwork Tue Jun 27 19:37:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Zhang X-Patchwork-Id: 113568 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8435841vqr; Tue, 27 Jun 2023 12:53:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6UQLDw0D49IwAn7kbsmYvhOWUES7m+lC23j5u4l+x3jC30dggvrsiS8sDN4++qJ5jYuQBF X-Received: by 2002:a05:6a20:7f99:b0:10e:d4fb:b031 with SMTP id d25-20020a056a207f9900b0010ed4fbb031mr25299981pzj.61.1687895637365; Tue, 27 Jun 2023 12:53:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687895637; cv=none; d=google.com; s=arc-20160816; b=HQWUsfpTe9jL8rtoH1hY3Ab3HYmt8ZcC/cHekICvZvr57Gh/iEr0+vR/P7GXak+WZK k8y21leozX7x3+WyfieDN5Aty64m9y9UNVzkgF/UnAZQ0+VIVAmzPu1r835/MX09tbgY yQCuP0V5XN1P0ZgP6LCoL2hZln1CvGgwy7HYVB22tgnZ0D55K+Ce+jqAbqVyQVCDLHRj BVADrmej9/Cc0gtt9kKMyjsd5cPOu1yQX9fnm9Hb4WBMHycoqsbD5LldRMojhuczXbFU 19aLjfho23qnCo67HROKikypH2xf+GPukEKtj0XH/AwSE0lMOkxScScY5chnzJvdailL uWUg== 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=raC0c8lD4uoqTKZzJVWvaIfqfutPouqXSyepzVVGY8A=; fh=I9qq4GK33V5F8z/ulbIoIJANM2w6qIjwqLIeYG6B9Xc=; b=hKepzLTmDT1AXQhkVwfIeniIgWrLSw9hf3845y5LK16l/Uxw6Jmr+LoJ7L+VceEJZy A98TkGAnD5JqE2P0u3CaFS3wYRIm0qeTLGG5ySLSzv5jOSdsmoGZL5ctprGy9qQ2Mb9p 2RWlGeEpim2AZf5OkPsI76nBYCj1XPpxZ1GTFjNP6zm/HD2krU9WDrRhq21NtGfZ9q/3 WW5OG8Z9ZD31WmZCzTZAc4vVPNPyGY41FRUqPos1h76xwr4otihMoMdEHjJCOXKAXBNY SEjJMANF2gv098hmlQKl1d19UghLHqI04LLQqFBRS+2fjraGJIZXTc3cUV7suUw+X38r c67w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=gqA+TP3Y; 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 x64-20020a638643000000b00553c6af75d5si7667496pgd.315.2023.06.27.12.53.43; Tue, 27 Jun 2023 12:53:56 -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=gqA+TP3Y; 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 S230283AbjF0Ti2 (ORCPT + 99 others); Tue, 27 Jun 2023 15:38:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230179AbjF0TiX (ORCPT ); Tue, 27 Jun 2023 15:38:23 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D54E26A3 for ; Tue, 27 Jun 2023 12:38:17 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1b7fef01fe4so16950235ad.0 for ; Tue, 27 Jun 2023 12:38:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1687894697; x=1690486697; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=raC0c8lD4uoqTKZzJVWvaIfqfutPouqXSyepzVVGY8A=; b=gqA+TP3YY8Bl42FSOl7N8s9551FBx53d9n7BcJB/NshVW6qKv3gzGsbr/Yvw9EhSn5 DShp2MgQHwsKElHNAi3yNl/U3ZEysBfM7dqpABSsiWrGBlLV/KpbB441dENxrryCjXCp ScHefLEQlZi8TYlHitKQlBMUf9RMKiZT3nR6A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687894697; x=1690486697; 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=raC0c8lD4uoqTKZzJVWvaIfqfutPouqXSyepzVVGY8A=; b=Jx3aQfUZsQ1zLFoNe7lk2SIfn+JNItmGMFCQGBMY9pxxRfJA/2AAjSEFI9CoxtWd0O jhB2VyjkwE5ZUXMdx3Xl4WNJYf15xnuAtfWCgfIbXnx8da2EQqnbkFKZJNFdEX2LOYp9 0/WiH4pTJLPKRXhPse1H+TEeAlHDOK5/o+kZ+WxZ+sCoFPM1xD0dgZFLP7g7XkZcozVP FICDtrXrS+C4cJVhnsffTJ9Fsxd7FaOwbMIqj5JU+oUDP8e9nKLN7RLeoUYoNIzSlcEZ ljKnBp7uyXKgn+CxEBTTjJwRX38vfv3IX4B9bZxt45z37sLOfoEi7G8zku91EBkF1OMe /tHQ== X-Gm-Message-State: AC+VfDwibxtzjGxqfAmsw8OeJK2nRTMDB5Z/7FBoEnWJwJQYOXUh1jUX 5a8h0VJhLOGO/vVRMimLQ8ksBQ== X-Received: by 2002:a17:902:c40d:b0:1b5:5bf2:b7e2 with SMTP id k13-20020a170902c40d00b001b55bf2b7e2mr8453541plk.6.1687894696915; Tue, 27 Jun 2023 12:38:16 -0700 (PDT) Received: from ubuntu-22.localdomain ([192.19.222.250]) by smtp.gmail.com with ESMTPSA id g7-20020a1709026b4700b001b7f40a8959sm4986919plt.76.2023.06.27.12.38.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 12:38:16 -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 , Florian Fainelli , Miquel Raynal , linux-kernel@vger.kernel.org, Vignesh Raghavendra , Richard Weinberger , Boris Brezillon , Kamal Dasu Subject: [PATCH v3 2/5] mtd: rawnand: brcmnand: Fix potential false time out warning Date: Tue, 27 Jun 2023 12:37:35 -0700 Message-Id: <20230627193738.19596-3-william.zhang@broadcom.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230627193738.19596-1-william.zhang@broadcom.com> References: <20230627193738.19596-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?1769886855692020534?= X-GMAIL-MSGID: =?utf-8?q?1769886855692020534?= If system is busy during the command status polling function, the driver may not get the chance to poll the status register till the end of time out and return the premature status. Do a final check after time out happens to ensure reading the correct status. Fixes: 9d2ee0a60b8b ("mtd: nand: brcmnand: Check flash #WP pin status before nand erase/program") Signed-off-by: William Zhang Reviewed-by: Florian Fainelli --- Changes in v3: None Changes in v2: None drivers/mtd/nand/raw/brcmnand/brcmnand.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c index 69709419516a..37c2c7cfa00e 100644 --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c @@ -1080,6 +1080,14 @@ static int bcmnand_ctrl_poll_status(struct brcmnand_controller *ctrl, cpu_relax(); } while (time_after(limit, jiffies)); + /* + * do a final check after time out in case CPU is busy and driver does + * not get the enough time to poll to avoid false alarm + */ + val = brcmnand_read_reg(ctrl, BRCMNAND_INTFC_STATUS); + if ((val & mask) == expected_val) + return 0; + dev_warn(ctrl->dev, "timeout on status poll (expected %x got %x)\n", expected_val, val & mask); From patchwork Tue Jun 27 19:37:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Zhang X-Patchwork-Id: 113561 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8434447vqr; Tue, 27 Jun 2023 12:50:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5stodIDURXb+94qJBGwjtqKinrkOVkdK7fTL8ksVSzUM3BZpRTHeqrPt5wuZ0j8KJZwmIw X-Received: by 2002:a17:907:970f:b0:990:27e2:7f81 with SMTP id jg15-20020a170907970f00b0099027e27f81mr7834570ejc.31.1687895449754; Tue, 27 Jun 2023 12:50:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687895449; cv=none; d=google.com; s=arc-20160816; b=V3XMCxMDauGcWUW7vXCCsehDqSo4/ZtvApbGFr6N5wX8sATpPGDhN14nCLAYPp/s1q MPefdRwLMhGOL0awMqb45G6cjueo7SSi08cOiLxoCo9bDL7V3H/QzXVwEvWIDUgz5czO w9FDX9CFhh4klMsJ4+rtbVwfTL9O3FHgYNQzQipTquA+0ty89fZoGMnQO5dml3xqtetK MMAN3xRadt3f4nFZRUv/ASYMYwzA94TNmdJ0W+gXvKkhs7+QWad6EJI9khxwKoSNbHDI JG0ffpUVuWvRafuV+nBgoKZgfCw380qrN6OhWjN+GwntRV10zZ5y5DQF1YiH2NSl2KaL MAOg== 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=U6jLGJe+JGGax79XpISkVnPfy+abCUUfWZOAyTcMVmw=; fh=V5lgikJFjYeJdRk3kd9fIKVcjyByg7w8p+LYJYgJQFE=; b=t9W/g0MwHp3F+Nil5fT8CSS9q6ghZhYs9c6FqT9gR6bX+pO7hGAicmjyuh+JqtGxiB Nmbr5qSZ9JCoV0hmCHkrdt6WLZVxpJ+5mvZayucaqtDANblLPTzo1D8Bh1mLf4QFUGL9 AsJ2aCDNrGKgkhY/nXWz/pnbQ7PuO+sTgCfgju3izs9qsJqQqLHQq+gbgp4RRhZX+fsh LUAjnwXQlKwgn1xIoOtvtKxDDL0uig2LYntzz4ZCANNgJJvZhh6ETpmetYfXpb8kTHdf 2sy38oPcD1ET217TQDSSAX8GyYLHKIkIli0PX47wNqYtJQWJLK05dQBdq8N2QKEVCASk T0kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=U99bkglA; 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 h15-20020a170906590f00b0098dcabba1f7si5061062ejq.452.2023.06.27.12.50.25; Tue, 27 Jun 2023 12:50:49 -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=U99bkglA; 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 S230326AbjF0Tie (ORCPT + 99 others); Tue, 27 Jun 2023 15:38:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230214AbjF0TiY (ORCPT ); Tue, 27 Jun 2023 15:38:24 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD6DF19B5 for ; Tue, 27 Jun 2023 12:38:19 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1b7ffab9454so16173675ad.3 for ; Tue, 27 Jun 2023 12:38:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1687894699; x=1690486699; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=U6jLGJe+JGGax79XpISkVnPfy+abCUUfWZOAyTcMVmw=; b=U99bkglAeCfTB8XBCbyv+1GpA24LQHN18Dr/1J1QVs2vNq+OalPPbftDGNGLRKnFhb wFQeGQhr6tDjGXSkdPSdMeR5jkEFB3KClqzzAevNOARbxhlhPATBSPGKQtHV5knQQiCw aJpYNbt44YRnA9BMz6hstAzsD71hEhFRPHFi0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687894699; x=1690486699; 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=U6jLGJe+JGGax79XpISkVnPfy+abCUUfWZOAyTcMVmw=; b=SV8TZtOxh3F+ZvCSfPV8TrXMGWgqhq8N/jm9Er6g/e/XWIa6vtPesuIgz9aiEJ9nZo QOeCbNkBR30EheQMdI/dQkNyWMQH82j98z4Ssn5ztUgrBcKQdXwtR4v22Civz78aNCJ6 n5LBpvxHqMvfHWsyNJPyTVBOU48MP89ddXqMN1lIX7QcAQNUdINlMqygj0Ggl7z467bQ NUR8EmYO1tY3S+v0/f+NLolXsdML8rK9Zrm9KXm+cZ0aqE7p7bnAy5RSD7i2UVfJpgSz XVZG/Ua98jxmZC+vN2HRpnVSphAa+1jT8hIvBkWy/Qt4h9q3jlgqxLBoeYH1WOMCiLMq Mfiw== X-Gm-Message-State: AC+VfDxhqNqMFaPhykDjqoeNoaC8SjSkvfndPb8zNAguoVF2p/n2qkwk n5owbXhw3lKeaq/px4Nfp86ZTQ== X-Received: by 2002:a17:902:dace:b0:1b6:7b75:60f with SMTP id q14-20020a170902dace00b001b67b75060fmr7687704plx.41.1687894699322; Tue, 27 Jun 2023 12:38:19 -0700 (PDT) Received: from ubuntu-22.localdomain ([192.19.222.250]) by smtp.gmail.com with ESMTPSA id g7-20020a1709026b4700b001b7f40a8959sm4986919plt.76.2023.06.27.12.38.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 12:38:18 -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 , Florian Fainelli , Miquel Raynal , linux-kernel@vger.kernel.org, Vignesh Raghavendra , Richard Weinberger , Kamal Dasu Subject: [PATCH v3 3/5] mtd: rawnand: brcmnand: Fix crash during the panic_write Date: Tue, 27 Jun 2023 12:37:36 -0700 Message-Id: <20230627193738.19596-4-william.zhang@broadcom.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230627193738.19596-1-william.zhang@broadcom.com> References: <20230627193738.19596-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?1769886659467841908?= X-GMAIL-MSGID: =?utf-8?q?1769886659467841908?= During the panic write path to execute another nand command, if there is a pending command, we should wait for the command instead of calling BUG_ON so we don't crash while crashing. Fixes: 27c5b17cd1b1 ("mtd: nand: add NAND driver "library" for Broadcom STB NAND controller") Signed-off-by: William Zhang Reviewed-by: Florian Fainelli Reviewed-by: Kursad Oney Reviewed-by: Kamal Dasu --- Changes in v3: None Changes in v2: None drivers/mtd/nand/raw/brcmnand/brcmnand.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c index 37c2c7cfa00e..ea03104692bf 100644 --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c @@ -1608,7 +1608,17 @@ static void brcmnand_send_cmd(struct brcmnand_host *host, int cmd) dev_dbg(ctrl->dev, "send native cmd %d addr 0x%llx\n", cmd, cmd_addr); - BUG_ON(ctrl->cmd_pending != 0); + /* + * If we came here through _panic_write and there is a pending + * command, try to wait for it. If it times out, rather than + * hitting BUG_ON, just return so we don't crash while crashing. + */ + if (oops_in_progress) { + if (ctrl->cmd_pending && + bcmnand_ctrl_poll_status(ctrl, NAND_CTRL_RDY, NAND_CTRL_RDY, 0)) + return; + } else + BUG_ON(ctrl->cmd_pending != 0); ctrl->cmd_pending = cmd; ret = bcmnand_ctrl_poll_status(ctrl, NAND_CTRL_RDY, NAND_CTRL_RDY, 0); From patchwork Tue Jun 27 19:37:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Zhang X-Patchwork-Id: 113571 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8436207vqr; Tue, 27 Jun 2023 12:54:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7STVlpDVbYghQKLaGOCmNF8Fk16u8IArUCWqiUFLrHyYX+71q0OyoBi1MgPBYOYG2VNtZP X-Received: by 2002:a05:6a20:4323:b0:105:6d0e:c046 with SMTP id h35-20020a056a20432300b001056d0ec046mr42197016pzk.26.1687895693107; Tue, 27 Jun 2023 12:54:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687895693; cv=none; d=google.com; s=arc-20160816; b=g7xNkZs/x80aI7AOFQwH2RwLvWkF9RxLJ5XoH6KIPTa7ry3mDVav1F/UjDHImygRxL sMsIWUGusfusDqAa+PH6zXjSvLS3dBi47m6JFM9uK4UYUi/WZJm8l40RFRTPWujy2U9f TJJrh6g7dTx+ZeI/HK54QhqN1w8OsY5hif1TsqgyHaFhjlzgD6suMqfUuMrjizseOyuu tEFTOuJpyWMYaW0B3Rxw8ItVPiytKS4+OSxDqtBZkoDtAZUIyWmh0oIrgrm8O+I5n+j/ 7t3IIN5vCkQ3P0MEnAas0PF35C84illYs41P2uPbmWZv7+xJUNjuJG1erP9Jd0Uf9HCp tlqA== 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=iaXp4mrMe/jXAKy0jRBzak4I8/V0aXguqJa0gdgX48g=; fh=V5lgikJFjYeJdRk3kd9fIKVcjyByg7w8p+LYJYgJQFE=; b=OiS8xERmQqLghZ52lqUq8FQsPNXIpvNKbmH3VWgGcfkldZdGwgWfmv/45TA8AiqA37 Cq9ARmc2LYgndNEZ8gNIB+aaelQg+PmYVkfo0k/rt/6GuGmNo7fdKJmddC7U8lR4FQ4Z zw8fyh4nuXnDp4jXjxwQFRxap26DGj289DI8dhTJhqkt2vJG5vPaBrn0xYyKOryqCf4a +S6OYK9SrMGVzUypCREWffZ3B/3LF7n+TkjYPV8SMq+SfVGjE8+popp191+JlmwNyiiw k0nJKUlpw6MwglhccLU7iyl2+12ZslHzf8Kuk529YPfBYRL1zKAo4pcS1kC2/YjMmR6M J+fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=bw6IbBSq; 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 j72-20020a638b4b000000b0052ca7192647si8038367pge.548.2023.06.27.12.54.39; Tue, 27 Jun 2023 12:54:52 -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=bw6IbBSq; 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 S230349AbjF0Tik (ORCPT + 99 others); Tue, 27 Jun 2023 15:38:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230195AbjF0TiZ (ORCPT ); Tue, 27 Jun 2023 15:38:25 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AB0D1FC1 for ; Tue, 27 Jun 2023 12:38:22 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1b7e66ff65fso30490535ad.0 for ; Tue, 27 Jun 2023 12:38:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1687894702; x=1690486702; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=iaXp4mrMe/jXAKy0jRBzak4I8/V0aXguqJa0gdgX48g=; b=bw6IbBSqh+nxxv8KlezHQ267LmMa24v0mn0cdGQp1HTA9Dsb8q0yr+M2UkaHihh+UN suwkhkrZokLrb22hsYzHIrNXvT/GU+8erOy0ofWdfufu1U2PkrTkTagKhYi6LDcemMYi SwJFK64t3YyOnt96w2w8Gif1yOCEx8nkYCY9M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687894702; x=1690486702; 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=iaXp4mrMe/jXAKy0jRBzak4I8/V0aXguqJa0gdgX48g=; b=LwM86npRTLd1Bp23EcKM7oVmcVXHflWy/9jBcKwTwrNzApnFB27HLTVmcDl+EWn9q/ 6kY38AtgJjk/KrCREXesnR24nbpqvPlwtZ+gwak1fFMdNmyP0JOWr40kuKC/CoRU3vl2 Bb4k93a2OkZRpBXm4x922WiMKaUzXBAeDfJOCQD9RmDLsxCOfcE2ORqfuFCHdWC877rv wOkxrBW7trjzR4aP/OYt/8/Ka9X8ZJY7s1g9r+DjVsaYXGfJk64/0VH7zjPFSNZL03F8 IeaIKVOC/SNVnUjMnlv+otZHCL5NCiFsMVqLHlncOKK/Wxcen89fiVEzmgUd7LQvnCvs 6/rg== X-Gm-Message-State: AC+VfDydB3wkWXzUhzqEPze0ci4xab5SS2Hh+Fndf9cIXa9JEt3O3HcL 2ZztAP7iQBKgj9wucOdQzpaRYA== X-Received: by 2002:a17:902:7c06:b0:1b3:a928:18e8 with SMTP id x6-20020a1709027c0600b001b3a92818e8mr9757938pll.52.1687894702074; Tue, 27 Jun 2023 12:38:22 -0700 (PDT) Received: from ubuntu-22.localdomain ([192.19.222.250]) by smtp.gmail.com with ESMTPSA id g7-20020a1709026b4700b001b7f40a8959sm4986919plt.76.2023.06.27.12.38.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 12:38:20 -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 , Florian Fainelli , Miquel Raynal , linux-kernel@vger.kernel.org, Vignesh Raghavendra , Richard Weinberger , Kamal Dasu Subject: [PATCH v3 4/5] mtd: rawnand: brcmnand: Fix potential out-of-bounds access in oob write Date: Tue, 27 Jun 2023 12:37:37 -0700 Message-Id: <20230627193738.19596-5-william.zhang@broadcom.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230627193738.19596-1-william.zhang@broadcom.com> References: <20230627193738.19596-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?1769886913996801767?= X-GMAIL-MSGID: =?utf-8?q?1769886913996801767?= When the oob buffer length is not in multiple of words, the oob write function does out-of-bounds read on the oob source buffer at the last iteration. Fix that by always checking length limit on the oob buffer read and fill with 0xff when reaching the end of the buffer to the oob registers. Fixes: 27c5b17cd1b1 ("mtd: nand: add NAND driver "library" for Broadcom STB NAND controller") Signed-off-by: William Zhang Reviewed-by: Florian Fainelli --- Changes in v3: - Fix kernel test robot sparse warning: drivers/mtd/nand/raw/brcmnand/brcmnand.c:1500:54: sparse: expected unsigned int [usertype] data drivers/mtd/nand/raw/brcmnand/brcmnand.c:1500:54: sparse: got restricted __be32 [usertype] Changes in v2: - Handle the remaining unaligned oob data after the oob data write loop drivers/mtd/nand/raw/brcmnand/brcmnand.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c index ea03104692bf..407bf79cbaf4 100644 --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c @@ -1477,19 +1477,28 @@ static int write_oob_to_regs(struct brcmnand_controller *ctrl, int i, const u8 *oob, int sas, int sector_1k) { int tbytes = sas << sector_1k; - int j; + int j, k = 0; + u32 last = 0xffffffff; + u8 *plast = (u8 *)&last; /* Adjust OOB values for 1K sector size */ if (sector_1k && (i & 0x01)) tbytes = max(0, tbytes - (int)ctrl->max_oob); tbytes = min_t(int, tbytes, ctrl->max_oob); - for (j = 0; j < tbytes; j += 4) + for (j = 0; (j + 3) < tbytes; j += 4) oob_reg_write(ctrl, j, (oob[j + 0] << 24) | (oob[j + 1] << 16) | (oob[j + 2] << 8) | (oob[j + 3] << 0)); + + while (j < tbytes) + plast[k++] = oob[j++]; + + if (tbytes & 0x3) + oob_reg_write(ctrl, (tbytes & ~0x3), (__force u32)cpu_to_be32(last)); + return tbytes; } From patchwork Tue Jun 27 19:37:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Zhang X-Patchwork-Id: 113579 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8443268vqr; Tue, 27 Jun 2023 13:08:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7PzMFxSscB3+wdA0z6p0weVUD0MFGIpaR1ZFZbhVr47+DRvlVsqJV1vseWAdy7dnxpTt04 X-Received: by 2002:a17:906:3084:b0:98d:696a:531c with SMTP id 4-20020a170906308400b0098d696a531cmr11365703ejv.40.1687896485296; Tue, 27 Jun 2023 13:08:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687896485; cv=none; d=google.com; s=arc-20160816; b=QTpzZiBXuGfLQfxQbj+KbMwvrW8xpT70oxRPSUTlS1FaNs5PVOiXVnOMGp95QVyoNc 4M5tYailHIOR/2HuRXuDmmUo/RX4QjlHnrAyNWqDgn6zOotZ5VCSnWHq1mmGSN2tzJqM mvwaS9yIzwqGlw0o4SsS7qM5yK+CUEYCNMj2XMwll5pNIsvvW4lqvxKz4o2T7/JTCx6x Xj+v/tiC9KHF0NfuuBkJoYNgvdv2M14Y+xLlDydD/rJqvoKmx4jgDaSSg0O7lPAjtqUD TRqJ0UdC1xUxfRmaQSaycFgSs6km+yuMonHCJEp5cP56HvXTn7/jf+XXcvjD4aVERF9+ aqLA== 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=BLy/S1TCUO82bkfGypenKdq41570tFEwyfGTcR0MAxc=; fh=BrMeb02/O0wx3t8cxe1CDXp3kC0urhfYBekjZ3wN7WI=; b=POGDIYCWLqaLtoo1RDIb/Bring6e6Qm2aiPCDsDLnWbir8hKPRb/NE3yZTdSt/jas1 DXpDoyeSmxtEJxpAKGAg6cM0UEqoOPbIHcsFbIGiOSWUDFdJOR0g9HAXjfO3D05BZ7S7 iCaPKWmPQZ7s0esZMqLhdPNDsCRgWYm9ELzpV+Mdqu6Q7OPU0QlvNumuW8pPP2G1f/3N bQz7BfS5TGYI0MV9FZ/TMNc9GuDpUd4tkXtOHLEqpGG1v6Z/Tdff/hVX8fdAb10G2L3E AEG6zkaJ3SAzxnksDDflAQu0yn9GHHMipMqULTM+PlGYwUqXvzFVqeI+DyAFzz+z/qR9 Bh7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=JZUovjWB; 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 v23-20020a17090606d700b0098e4e1279fesi3247105ejb.859.2023.06.27.13.07.41; Tue, 27 Jun 2023 13:08:04 -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=JZUovjWB; 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 S230195AbjF0Tiz (ORCPT + 99 others); Tue, 27 Jun 2023 15:38:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230229AbjF0Tib (ORCPT ); Tue, 27 Jun 2023 15:38:31 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A02871BCF for ; Tue, 27 Jun 2023 12:38:24 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1b8303cd32aso3961735ad.2 for ; Tue, 27 Jun 2023 12:38:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1687894704; x=1690486704; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=BLy/S1TCUO82bkfGypenKdq41570tFEwyfGTcR0MAxc=; b=JZUovjWBiQ2SVPIpGIXWD01ZDby8Me+6iwhRx/KDHJvLfOBaXC3Ybpfn+wK92wiqwP O5laFY4/dfv7G+n5V6uIs9F+XjyCDtSf0YWHXuZ4bw89bFaGW5gGgPHRhgjlJGIhhDxX dbIRMW5hK0SnhMoqW6g72vOYcJWFTiANpjAm4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687894704; x=1690486704; 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=BLy/S1TCUO82bkfGypenKdq41570tFEwyfGTcR0MAxc=; b=kOY/n/nFVDcRNiafQIkjvAlqfUSPaqzVJjaO03U5/Zw4xIEae+8PpQlxR/n/TTV+U5 6tnQU5r0lDzvskI96IfvPYS3SsApXdCjRo61p0hN2UznfmzUSmrH+sTWsYe0aYbRYcqk WK1glYO2yPM6SbfXsTJiS0s6dIf2c01DrOue7GHXs3EIr9FJrszNe0AbPphIn14iWlea tAH2d0RQtQpT+Byl6sfWqNQ4ktrFWOwpw+wlcV8SsGEkwHHtXJGecM5yzdGGKCv+6zUC RAX+ZrkYKZJqfeuPWujhQ/U5tH31ayJ1KNDHjKMfw70J02I/dYmnSLG03xh1vfpU54iy fvrA== X-Gm-Message-State: AC+VfDx/tADk8qwSXiGm1f05uwq5imKpqTRRdGUcCl3yc1V0Tbkg6Na2 UCSn4Bq6QnoTOI6xHyzEcXFLjg== X-Received: by 2002:a17:903:41c2:b0:1b7:c629:f110 with SMTP id u2-20020a17090341c200b001b7c629f110mr13071912ple.63.1687894704162; Tue, 27 Jun 2023 12:38:24 -0700 (PDT) Received: from ubuntu-22.localdomain ([192.19.222.250]) by smtp.gmail.com with ESMTPSA id g7-20020a1709026b4700b001b7f40a8959sm4986919plt.76.2023.06.27.12.38.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 12:38:23 -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 , Frieder Schrempf , Miquel Raynal , linux-kernel@vger.kernel.org, Vignesh Raghavendra , Richard Weinberger , Boris Brezillon , Kamal Dasu Subject: [PATCH v3 5/5] mtd: rawnand: brcmnand: Fix mtd oobsize Date: Tue, 27 Jun 2023 12:37:38 -0700 Message-Id: <20230627193738.19596-6-william.zhang@broadcom.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230627193738.19596-1-william.zhang@broadcom.com> References: <20230627193738.19596-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?1769887744587595401?= X-GMAIL-MSGID: =?utf-8?q?1769887744587595401?= brcmnand controller can only access the flash spare area up to certain bytes based on the ECC level. It can be less than the actual flash spare area size. For example, for many NAND chip supporting ECC BCH-8, it has 226 bytes spare area. But controller can only uses 218 bytes. So brcmand driver overrides the mtd oobsize with the controller's accessible spare area size. When the nand base driver utilizes the nand_device object, it resets the oobsize back to the actual flash spare aprea size from nand_memory_organization structure and controller may not able to access all the oob area as mtd advises. This change fixes the issue by overriding the oobsize in the nand_memory_organization structure to the controller's accessible spare area size. Fixes: a7ab085d7c16 ("mtd: rawnand: Initialize the nand_device object") Signed-off-by: William Zhang --- Changes in v3: None Changes in v2: None drivers/mtd/nand/raw/brcmnand/brcmnand.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c index 407bf79cbaf4..39c7f547db1f 100644 --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c @@ -2647,6 +2647,8 @@ static int brcmnand_setup_dev(struct brcmnand_host *host) struct nand_chip *chip = &host->chip; const struct nand_ecc_props *requirements = nanddev_get_ecc_requirements(&chip->base); + struct nand_memory_organization *memorg = + nanddev_get_memorg(&chip->base); struct brcmnand_controller *ctrl = host->ctrl; struct brcmnand_cfg *cfg = &host->hwcfg; char msg[128]; @@ -2668,10 +2670,11 @@ static int brcmnand_setup_dev(struct brcmnand_host *host) if (cfg->spare_area_size > ctrl->max_oob) cfg->spare_area_size = ctrl->max_oob; /* - * Set oobsize to be consistent with controller's spare_area_size, as - * the rest is inaccessible. + * Set mtd and memorg oobsize to be consistent with controller's + * spare_area_size, as the rest is inaccessible. */ mtd->oobsize = cfg->spare_area_size * (mtd->writesize >> FC_SHIFT); + memorg->oobsize = mtd->oobsize; cfg->device_size = mtd->size; cfg->block_size = mtd->erasesize;