From patchwork Thu Jul 6 18:29:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Zhang X-Patchwork-Id: 116815 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp2756541vqx; Thu, 6 Jul 2023 11:32:17 -0700 (PDT) X-Google-Smtp-Source: APBJJlElR38SkvKSMgbk/tYBCtyff3I/EVcqAFD+QZF15KfkvZRd+iMvLOHQJ73Xhp+lxG5Z4Txh X-Received: by 2002:a92:db45:0:b0:33e:7c8d:3cc with SMTP id w5-20020a92db45000000b0033e7c8d03ccmr2626934ilq.22.1688668337338; Thu, 06 Jul 2023 11:32:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688668337; cv=none; d=google.com; s=arc-20160816; b=eoDKhM78E5fshPBXojPePU3//+PLo1U/VJIHDaQLxfAbb+0MB/oHz5vGZOtOaA1Vy4 KRskdIUABOO326I6ENm4iyhfHVni/2wGH2nk9X451bIPKbOe1vYvMQTySYhEVrdgxWlb y5FmphPiDO20g7nGyM5lCcH7/zHrc8M7CDMO0Pl/d4FQelpURuz4c4/AXmf1HypsUdG2 AoPQmwPTmMJk64+sL3byhQqWE/S6vRRyjTLdpGTvA8aveZhKJDrZgYARYaQDWAHvym8s WYKUlRENBHCMZBRycJfOt+nGTpLiiIAfQv4AuiRIeET8r2sGGWD1mBrbRg+AoReobw9p dl7g== 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=j9gx9gtWQG17bITJPaSQX1DW1aPQRO9lN+pwis8si+8=; fh=VN1x6xxxs5OTEv2xMnlCQQEixEkVW/90Wb6HY6LnVL8=; b=bJlbhbkWmRksCIjwBWcOSMTCNmYhIk/cwcuAU9vOCYXvNxAPLGqqxEMAhSPj9a03CR HI3HCgiZokRVV0sK+L9RBRC9AADu48ePQFXTYR3VoxpCvnYCH2tGfa9JaTKXvtlEsfU/ 2Ne9dmhjBl18INH2kP6Wcstk4uaT4LZmgbNo5yekuN6WdJQwT/6ewmgrG8KqQPvQEh6C gFR4KqyOL4jXPaNF/spU6dz9aL5vfHl9IdKrgxA/V7J1bL9CiAK4kBxNuLU9/jSER/n5 cK9GbyMQ1hWIDlRXf0Pk+y22rNzwenadzjXvskC0aUCaWd3ogjomXpkZ0QhSQD5MmgsC lwDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=P65PhZnd; 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 l65-20020a639144000000b005133c334fe9si2026055pge.847.2023.07.06.11.32.03; Thu, 06 Jul 2023 11:32:16 -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=P65PhZnd; 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 S232163AbjGFS3g (ORCPT + 99 others); Thu, 6 Jul 2023 14:29:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232068AbjGFS3d (ORCPT ); Thu, 6 Jul 2023 14:29:33 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B04771BF3 for ; Thu, 6 Jul 2023 11:29:32 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-668704a5b5bso838051b3a.0 for ; Thu, 06 Jul 2023 11:29:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1688668172; x=1691260172; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=j9gx9gtWQG17bITJPaSQX1DW1aPQRO9lN+pwis8si+8=; b=P65PhZndeCPsnBvFcnO8CzzWjX3j29Bukb4sbpVkPhyCLc/2sznDZKw7SaM5eP4jq+ ij+bvwEpDhQHUBgGKxHAAalB+uWcZ90BK3E6+Nts9wbeU7jTmDXFbjRC0dbuPYX2jhgk W+UFbhI82CrV2se6KffgLlYFYaexYnmjnucaY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688668172; x=1691260172; 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=j9gx9gtWQG17bITJPaSQX1DW1aPQRO9lN+pwis8si+8=; b=ShU8b9LML4u/Wwk2EPsAaNm+rJudnqjwc3KuAaxsP6hrmQTk/q8zK/ooPmyDhluq+C poYKkBaP7HpTCljBZzrMIOIp3l6GNd6MS4RbwtCVba0r82ZJjBN2dv3N5DCzd4Q5OwQU bLHCbhYqBXQM0PNrohQZh9oWT0WbDZuv3+BZybaf1bvMO7QRv3HoiZ0hLsrtrSAzbTSA lGR+6qMJagxaP5yC0LqJllgKQPAUKVhvanTqWUuzy9w2drmstKvL40FbUUTEFCZ4c4iJ eYxlUMLDu1EKXR2hcDPB8j9wUafsJlvd79btgrlnrGx4YuTUnVQu7UL3NcJ/2mWGw0zH 5dQA== X-Gm-Message-State: ABy/qLaVjLS99K9xzLH90YyCp56VjrPYQHVfZCXdq2eT9IXVhtFYkkSw zP3RFFCQ+uWD/U1uwuGGEsgSVw== X-Received: by 2002:a05:6a00:2d20:b0:67a:a906:9edb with SMTP id fa32-20020a056a002d2000b0067aa9069edbmr3425198pfb.30.1688668171981; Thu, 06 Jul 2023 11:29:31 -0700 (PDT) Received: from ubuntu-22.localdomain ([192.19.222.250]) by smtp.gmail.com with ESMTPSA id y13-20020aa7804d000000b006826c9e4397sm1580871pfm.48.2023.07.06.11.29.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jul 2023 11:29:31 -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 , stable@vger.kernel.org, Rob Herring , linux-kernel@vger.kernel.org, Vignesh Raghavendra , Miquel Raynal , Richard Weinberger , Boris Brezillon , Kamal Dasu Subject: [PATCH v4 1/5] mtd: rawnand: brcmnand: Fix ECC level field setting for v7.2 controller Date: Thu, 6 Jul 2023 11:29:05 -0700 Message-Id: <20230706182909.79151-2-william.zhang@broadcom.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230706182909.79151-1-william.zhang@broadcom.com> References: <20230706182909.79151-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 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?1770697090555374488?= X-GMAIL-MSGID: =?utf-8?q?1770697090555374488?= 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 Cc: stable@vger.kernel.org --- Changes in v4: - Move ACC_CONTROL_ECC*_SHIFT definitions out of the enum definition - Add cc stable tag 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..9ea96911d16b 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), +}; + +#define ACC_CONTROL_ECC_SHIFT 16 +/* Only for v7.2 */ +#define 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 Thu Jul 6 18:29:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Zhang X-Patchwork-Id: 116819 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp2761911vqx; Thu, 6 Jul 2023 11:43:22 -0700 (PDT) X-Google-Smtp-Source: APBJJlGa2ns3DaJLTdb0xcP8Jux3+XDBZae/e4WYX3ii1OYpwcGIntMdlFkzyJqWG0BHW+cxv3b6 X-Received: by 2002:a17:902:7fc4:b0:1b8:865e:44e7 with SMTP id t4-20020a1709027fc400b001b8865e44e7mr6289515plb.20.1688669001788; Thu, 06 Jul 2023 11:43:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688669001; cv=none; d=google.com; s=arc-20160816; b=T0t2DVtpECgdupmHdLMtRPUvmwU6zSNx873oIYDyqKxqClZeaU8+YnHPwtqqtG2b3y qINpUacjjIW4XsAC/dfpb85JNeXpBRrZfE7bqyGHVlB4GHuavPxi6uYNgQpWctTN8NM4 9CkY4iiE4wVKB0kKl6/SQBDPxx55Sd9qsbDtBCQO+ccTabJMT6kfNytkloqsDwKPrZlW 7deGowj8SiZSbp7C9JkoEqwgnp4fXHfuxPvNPMwjH5vZyC+aRBV6m5zIp6WxTvl6B5cF U7UJQNXBp3cp5DGECrpo9wvI63YGPTtxhw9QrIUHNSA5hT4/DJU4tb5oWbrcZDF6SIuv fIvg== 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=M9jUpwDvuvmyT1XyvE0e45XyYXLWotDr9wT7gxrJDuU=; fh=ORNSF113G4WA1axyJjwSKo0Uw8ZG2/ZPZL9fP0p05MA=; b=Wi4OvgyK5qxaD3Im9VHY1SsIE5mNNNRYsDls8E39T0F4paNSy9191voc+9j8GBdmKu ID6YQbNMbYBbds3dn+NQg4CN98ePCiwEIjHH1XgMs7jYBQ2f8Z7UJOVW+qjVCrz/W823 sQbuZCTeKPt2XRMsZqsZ1sKbexlUi8T0FMD4XXaJ0YhOhJ1MG3nhANKOLU4w/lfXuHvV c2AlJ9DOpQ/H/3d+3TAN9cLhpE3uRsEztSbNhKIEnWSX33Css8n6fMqLzcJRHot8Erkw qTPv5qMq7xIzJt7Rzy2TUTCumwVphJVpDDwyY5yuJbF9fYJ36+kimj8MaPeKBLz0W27q 7Rug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=eR3vlrEv; 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 o13-20020a170902d4cd00b001b8c4168e20si1783402plg.58.2023.07.06.11.43.08; Thu, 06 Jul 2023 11:43:21 -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=eR3vlrEv; 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 S232347AbjGFS3l (ORCPT + 99 others); Thu, 6 Jul 2023 14:29:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232134AbjGFS3f (ORCPT ); Thu, 6 Jul 2023 14:29:35 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABA271BF3 for ; Thu, 6 Jul 2023 11:29:34 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-668711086f4so727617b3a.1 for ; Thu, 06 Jul 2023 11:29:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1688668174; x=1691260174; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=M9jUpwDvuvmyT1XyvE0e45XyYXLWotDr9wT7gxrJDuU=; b=eR3vlrEvD7GcbM/HM3wwB5wQkrx8/LUkQeu3S0bS3UGsPWAsc1BrIb1gBQo66mkwj0 zEBrQ+9LJ/K8DOU6WwUP+qvhksW0zK0ApY7JDxWEUY+HvXVu32DxgPtHXHqV3odRGPjN o0udKlnuB99rzZH5qMkFDLVGEdJQIUNSRdKo4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688668174; x=1691260174; 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=M9jUpwDvuvmyT1XyvE0e45XyYXLWotDr9wT7gxrJDuU=; b=FVPkWsUf/34DskPd7qYynG/cETRsUjFHf84hzng12pVYdSnXUtuK3fK+M6+drFEEom Xl9/nWoki/AbYglwSZm/FQUZZEGDoSx2CAFLcmluXaqdv8YpptRREGPiCWGPuXFqGEAc dOujKLB8I6WE0I7FynD+ID0z1SXSjsynY9q5v5aNP7vfo8SefOVG66LS5c4DO6T/DRYx CCzuQ7gprJKwAQjQKO57FhGf/dMb3WMrE7uKm2WNz0eaVxmxkUv6i/Mcy7kU0kKrUtA8 oFm0pw8rAg8Bzy4G1wZg7CZZoitoh4v5t2oTqvBenD2qoAkMT5zM3nNb0O5fU9nx8irm rMZA== X-Gm-Message-State: ABy/qLZoa4M5sM5MHvSE0hR4HL3IhlZbouNrSXpRvIv8T5PJJ6SWywYO 3Z/S6D3mp6rXR+tX/im6yevaOg== X-Received: by 2002:a05:6a00:d5d:b0:668:93e7:6800 with SMTP id n29-20020a056a000d5d00b0066893e76800mr7712593pfv.14.1688668174067; Thu, 06 Jul 2023 11:29:34 -0700 (PDT) Received: from ubuntu-22.localdomain ([192.19.222.250]) by smtp.gmail.com with ESMTPSA id y13-20020aa7804d000000b006826c9e4397sm1580871pfm.48.2023.07.06.11.29.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jul 2023 11:29:33 -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 , stable@vger.kernel.org, Miquel Raynal , linux-kernel@vger.kernel.org, Vignesh Raghavendra , Richard Weinberger , Boris Brezillon , Kamal Dasu Subject: [PATCH v4 2/5] mtd: rawnand: brcmnand: Fix potential false time out warning Date: Thu, 6 Jul 2023 11:29:06 -0700 Message-Id: <20230706182909.79151-3-william.zhang@broadcom.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230706182909.79151-1-william.zhang@broadcom.com> References: <20230706182909.79151-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 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?1770697787412027183?= X-GMAIL-MSGID: =?utf-8?q?1770697787412027183?= 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 Cc: stable@vger.kernel.org --- Changes in v4: - Update comment in the polling status function - Add cc stable tag 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 9ea96911d16b..9a373a10304d 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 the CPU was busy and the driver + * did not get enough time to perform the polling to avoid false alarms + */ + 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 Thu Jul 6 18:29:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Zhang X-Patchwork-Id: 116818 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp2761182vqx; Thu, 6 Jul 2023 11:41:49 -0700 (PDT) X-Google-Smtp-Source: APBJJlH25MS+BtstJIKf8MFCLw5KTda+/TxzZDRfVeFRB4CwbB5LtgjXT2SxlXzg1sEYpvW+iSgA X-Received: by 2002:a17:903:32ce:b0:1b8:b4e5:15c2 with SMTP id i14-20020a17090332ce00b001b8b4e515c2mr2899348plr.22.1688668908633; Thu, 06 Jul 2023 11:41:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688668908; cv=none; d=google.com; s=arc-20160816; b=B3QbqLYtAppwFQntAn9BlU/MzrekgrD+CV3UYBQBVbChdM5cQFx3gUmDom+Lf4uuqv 3XpqOOQyjvgmhGQb7pNxCEHjWJ8lhaLWMg2s7MVnCxMPluda0dDDSXSgfd8Gl0uObW36 J6D2nmU2WVvWK/UJ9gpG9DfVbBw+xb9BuHMolGpGlZ23ZBAaG9j3R34Ye12NPNL9pTxe OZwn2CRCiMJsyRkeeCn6c/hzWQKTHxEaZlujfENIn0R1WPKngNma42VFUxyJrUsMo+Mn HwItbjFU04vGqUduRfrz8dphsG3edcOf9Ni+S3TKUKBdPq2cPggqDgkp9cDQoII3Tgwz 0hNA== 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=D0cu2lwsj8lZsvKlL7iIsn2njGLUHuLcymfkJT5BpYk=; fh=m13O91RIJpWLA1E3t3OF4PWkN6piDivoH4+ccEA0NUM=; b=ndOzXLalO/mXVu3gLLfefj5ZNd65zBpUNfvsbbSOXqNIB6u4P0vLAPG5OY+AepBGQS b3t5b2G/Yw1vW05NEneC0dz3gv9c55TQCTP3npUiV+1Sn4EslHku6/fq6OfE6haYV+gk coPLtoANoPY8dV3LgFcS6vpKTas8OoGgm3eyOU8s6kAD9b2exwmUt8X4SHXL0nq5BssA qMDspEBePdP8Xe0e/nQmQdphDq7k8JgAxLj+zxvRCbnYxeyByTegiSuKaP9uErET33I/ 4Umbue66Pa9xhUFcRhg4gI2GgrmC+arjyC/j7XITnx8oNwsywgNSAa81u+27wm/g/qwk +srw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=YbNtEpUA; 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 h8-20020a170902680800b001b9075dbda2si467851plk.199.2023.07.06.11.41.31; Thu, 06 Jul 2023 11:41:48 -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=YbNtEpUA; 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 S232160AbjGFS3n (ORCPT + 99 others); Thu, 6 Jul 2023 14:29:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230036AbjGFS3h (ORCPT ); Thu, 6 Jul 2023 14:29:37 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B27A31BFC for ; Thu, 6 Jul 2023 11:29:36 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-666e3b15370so690112b3a.0 for ; Thu, 06 Jul 2023 11:29:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1688668176; x=1691260176; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=D0cu2lwsj8lZsvKlL7iIsn2njGLUHuLcymfkJT5BpYk=; b=YbNtEpUANR2TRTbcsFQ7k0zPPS9nd8WrCAYB1M6s13r0Go1H2SayophwDMv+oew+1Y ps5o7ePa6db7TtfhyMgimps8sjiL0xyNbFCU0EFi0ef+8tCol95GGFi4Ym2hUcgaJtMS b5mTLBKpOAuaLoda+kMmuifxBnoelM/HlUPss= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688668176; x=1691260176; 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=D0cu2lwsj8lZsvKlL7iIsn2njGLUHuLcymfkJT5BpYk=; b=NbNxPvri25JhoL8WMKhIxNx7GJiGZZ0wdyyJN/fPf49CfbQZRYjmpK9fVJ5kJ3VDsP +siDbNakcqyI/x5S6We/BRyXseobBakd53hIQwxNL3BaNPTYPpBIOEo/7P5Yu1ttQH/Q LZI0FgGQp7pok4ILf9wPUKTWafR3akY4gJs/mkRH+nuUZtxlmfpkkzJihlVAhQJtCr+r tIk08cugTZQ9DoImr5BH+YnY7guNespsn1O/ds/6taNUxFxRjlxgS6EllF2j/pnPNvB4 2E+tdMqS0GJYwN3lOg/yIHpU1Q1jM+lgT3fk4/gnXmef6Joe1h/Vvqq02rSqDjMeKWZ2 ITXw== X-Gm-Message-State: ABy/qLbJlzgGv7JNNbLPB6SP+w07OFCG0TOsJ587avdf9gy1Pjp3gk3r 09zWx5p/wIEhVzfTrKIBiw173g== X-Received: by 2002:a05:6a00:139b:b0:679:bc89:e5b with SMTP id t27-20020a056a00139b00b00679bc890e5bmr2741416pfg.19.1688668176150; Thu, 06 Jul 2023 11:29:36 -0700 (PDT) Received: from ubuntu-22.localdomain ([192.19.222.250]) by smtp.gmail.com with ESMTPSA id y13-20020aa7804d000000b006826c9e4397sm1580871pfm.48.2023.07.06.11.29.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jul 2023 11:29:35 -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 , stable@vger.kernel.org, Miquel Raynal , linux-kernel@vger.kernel.org, Vignesh Raghavendra , Richard Weinberger , Kamal Dasu Subject: [PATCH v4 3/5] mtd: rawnand: brcmnand: Fix crash during the panic_write Date: Thu, 6 Jul 2023 11:29:07 -0700 Message-Id: <20230706182909.79151-4-william.zhang@broadcom.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230706182909.79151-1-william.zhang@broadcom.com> References: <20230706182909.79151-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 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?1770697689657717195?= X-GMAIL-MSGID: =?utf-8?q?1770697689657717195?= When executing a NAND command within the panic write path, wait for any pending command instead of calling BUG_ON to avoid crashing while already 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 Cc: stable@vger.kernel.org --- Changes in v4: - Update commit message - Add cc stable tag 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 9a373a10304d..b2c6396060db 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 Thu Jul 6 18:29:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Zhang X-Patchwork-Id: 116821 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp2762515vqx; Thu, 6 Jul 2023 11:44:44 -0700 (PDT) X-Google-Smtp-Source: APBJJlG0XoCQ9k16JzXqepbJs7JK/Y+wpEVBpoH31Y9dIoMlkvSfauD5w8Dj+aHI9apfEgO9/H8U X-Received: by 2002:a17:902:c3d5:b0:1b8:41d4:89f with SMTP id j21-20020a170902c3d500b001b841d4089fmr2254238plj.4.1688669083845; Thu, 06 Jul 2023 11:44:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688669083; cv=none; d=google.com; s=arc-20160816; b=sZYTOWFwlGpD6CgB91ZOLnVj5DxdZuK2m2fT5OBSXca1GUM0ORGjOgTH8RfvzVr2Z2 joPvS6H2bL+Bds7Cxf73uUkt1YtvNiY11NMpteZPqtpAq91pGP17auMjm+jDB3OPfRTc NtVzRsoJunkP1BgUYDKkol1FLiVINiMTy2QVLMo4c7w2QUF+eg2cYrz/v9CKIU/6H3td wexLbUNyUjwJEolmZsaeaTCPE9sgJAHhG1ber/P48xsXhuUgm+6VxshT5ATLV17+sh2x Vu+8xX4ZsxbKZnaSj07I6BrueBkZ1/7dneucapzwWnKLYRn/WXzyGerdZ8czSuguNLKY usVQ== 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=aa+nUjBlOMfq0WnrVZHm27tMCu9V72ZfvnaM6ufPeMI=; fh=m13O91RIJpWLA1E3t3OF4PWkN6piDivoH4+ccEA0NUM=; b=ggSPm2ka+6vV29fVMAg0LsJEpPePslLD419OGGuZ+ZqtDAVjUuQYtOrKh+s2gMTglP DcOIG+/9kFRpjB7s4uJ8ufdGH108153N0gfYnHUeUHErY1Qaj8L4laZ4bWFW1Ls/SPAc l7t4nO2TPqBOlnjfo/aNGCw6M21GhvrC8IWiGWQuz3Kdad9fDoqXnqdV5JmIiOQlqvC4 72gWwilgDQHMwiVE95xlhNhbp5AtybB3f9ae+at2Xk3TWy33xBic/XhQWsmkErtKQ+e+ rhds0FmknXh/A/aMd0nYjfN6muS7VjGV5H8VBGUbpsygfO4V/daUZa2KhF/LARBprYbr VBLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b="A4I/K3Kx"; 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 o13-20020a170902d4cd00b001b8c4168e20si1783402plg.58.2023.07.06.11.44.30; Thu, 06 Jul 2023 11:44:43 -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="A4I/K3Kx"; 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 S232364AbjGFS3q (ORCPT + 99 others); Thu, 6 Jul 2023 14:29:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232304AbjGFS3k (ORCPT ); Thu, 6 Jul 2023 14:29:40 -0400 Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53DD41BF6 for ; Thu, 6 Jul 2023 11:29:39 -0700 (PDT) Received: by mail-oi1-x22e.google.com with SMTP id 5614622812f47-3a04e5baffcso987861b6e.3 for ; Thu, 06 Jul 2023 11:29:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1688668178; x=1691260178; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=aa+nUjBlOMfq0WnrVZHm27tMCu9V72ZfvnaM6ufPeMI=; b=A4I/K3KxZWmdzXHAwOpSMH18KTEhGc0FP9H3kZras3W48OCVW7WljY3ZuQC02NG6H0 KcwDdTe6OTtSUDqF3RmBNOpeie5CtvX0wKlngIvZp9iczJGEhHzHW0f1sY27iWeDMVQw yrdDufSuIaP8hJFkmFmRTYYUOe4xKALemiIPA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688668178; x=1691260178; 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=aa+nUjBlOMfq0WnrVZHm27tMCu9V72ZfvnaM6ufPeMI=; b=iVdFa+0mpgc1gpeKQWwK7y3zL+kfJDV+aqA7XJUCwZlHlb+6S6LtOlDa4ckKqsL3VX NpLTtq8vtLPOMfHgV13zVJrum7/J1vw+8bJzKSh1hcyiX2vt+HJDvrtGJmaf23It2lgC x+vJsQJRNH5NQ5TB2ZAT3lLVaGBgmqULWMTu2uO5eLKKP2eWYUyYFtRati282u/jkOuz lK7LmkBbEbeA6CIJhSGDV2TfBY9dP81INZ/Hu8LWTMx0pbMpN5XSslCx6jj7WlZ8SQp9 a4qrcl6e4Xm7YjUY/Mfe+WkyR981/tURKiACoFnUjnerCUfS/YknqWblbR7jn+lI91ft uG6g== X-Gm-Message-State: ABy/qLaorha8IR1Rqrgg3nk9r16DBCcC7JOSsdahD4QW1r0VS5VkLpYw ofCn5FkaJ4eqore3EyCRxaIdJg== X-Received: by 2002:a05:6808:1789:b0:3a3:7228:8c98 with SMTP id bg9-20020a056808178900b003a372288c98mr4043821oib.2.1688668178327; Thu, 06 Jul 2023 11:29:38 -0700 (PDT) Received: from ubuntu-22.localdomain ([192.19.222.250]) by smtp.gmail.com with ESMTPSA id y13-20020aa7804d000000b006826c9e4397sm1580871pfm.48.2023.07.06.11.29.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jul 2023 11:29:37 -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 , stable@vger.kernel.org, Miquel Raynal , linux-kernel@vger.kernel.org, Vignesh Raghavendra , Richard Weinberger , Kamal Dasu Subject: [PATCH v4 4/5] mtd: rawnand: brcmnand: Fix potential out-of-bounds access in oob write Date: Thu, 6 Jul 2023 11:29:08 -0700 Message-Id: <20230706182909.79151-5-william.zhang@broadcom.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230706182909.79151-1-william.zhang@broadcom.com> References: <20230706182909.79151-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 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?1770697873506701952?= X-GMAIL-MSGID: =?utf-8?q?1770697873506701952?= 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 Cc: stable@vger.kernel.org --- Changes in v4: - Add comments in the write_oob_to_regs function - Add cc stable tag 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 | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c index b2c6396060db..71d0ba652bee 100644 --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c @@ -1477,19 +1477,33 @@ 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) + /* + * tbytes may not be multiple of words. Make sure we don't read out of + * the boundary and stop at last word. + */ + 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)); + + /* handle the remaing bytes */ + 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 Thu Jul 6 18:29:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Zhang X-Patchwork-Id: 116824 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp2767791vqx; Thu, 6 Jul 2023 11:56:01 -0700 (PDT) X-Google-Smtp-Source: APBJJlEZnsbcwXfBkILgWQxXyPMSBGtcOwvVYnUuKqxLdo/7AhWv7Ggy1nmh2IVWnNiHdqTyCRia X-Received: by 2002:a17:903:110c:b0:1b8:83a3:7db9 with SMTP id n12-20020a170903110c00b001b883a37db9mr2911644plh.23.1688669761184; Thu, 06 Jul 2023 11:56:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688669761; cv=none; d=google.com; s=arc-20160816; b=EtSsxBQCuo93hxNzAUNhSE/9RFH0JF6UlUQUhyXML4dVyaPOzboWOd+NxsOYMJ6I3B qncVyP3T7TNK1amOLzFN0bvNSK9tpoTUE6l9WV7ap0l6YMapMdDfrADfOI7Z1iPyI6T6 DvZs/EIT2KukLGwhft2KpWSnNlKYkEeHU0dgw0Vf9m6ZYTBSilnXfjj/fFmKmuwKM08b Q4tNMgiWDcfVPs+DW9QQNigBgR8aLHLAxorXb2+rBCRWdLXXpY0mQEZd53ZNgzhv5SwM YezKLSwe0wJuXy+a4KwVNwztMyoEbn9HgaL2C7A0pCr58pazrv+TfrttXw7FoNZbe7Vh YnhQ== 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=NsC+L4CHLTDTROKB8tT7c3nb8dVrzJsiNq7PJiTV4iE=; fh=H8oezWVA2uTcgG6ruQ58mVEepH0WZHbgl0y800aHJhs=; b=JdjeE3D4FwB33JSjOPMNzb720xYzgzpM5jSWWjdTM997wKVdpuRE7ifLKsWYdh4YpI 0jjzswXsnefqbFYwKD2i3WAAC2kxuIa2n4cydfh2JjI/SypF6IeqgVdCQMpKqxNat5dN zH6orWC/MpgEeKuAZc2ZvGDuIYM/j26IeRQSEnohWX6DZzNE5QMACPWOEdoFbEzRQ+Mh pe0FO+PvfpvmF2Wuth6O2wywKgNoZ1an5NOy4u+5vVk11gXSbMpv8CRXVY8IraQI0p4T DS1pJrNTykelNIHckDx4ae+7wzMmqTR2sbwt3onfWd1A2oAJcFDSTUnA+zIhmr+ZIF3v yZ1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b="CNpmsWd/"; 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 s12-20020a170903200c00b001b8946f3f95si1686657pla.312.2023.07.06.11.55.44; Thu, 06 Jul 2023 11:56:00 -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="CNpmsWd/"; 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 S232404AbjGFS3t (ORCPT + 99 others); Thu, 6 Jul 2023 14:29:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232068AbjGFS3n (ORCPT ); Thu, 6 Jul 2023 14:29:43 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E91C1FC6 for ; Thu, 6 Jul 2023 11:29:41 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-66f5faba829so672413b3a.3 for ; Thu, 06 Jul 2023 11:29:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1688668180; x=1691260180; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=NsC+L4CHLTDTROKB8tT7c3nb8dVrzJsiNq7PJiTV4iE=; b=CNpmsWd/o0JDbrA4opR9vlzZhTSFfLbeu6OhuSdnH4VyEDjQ8vFmGhj77PtZBkEY2b SLSklN0DQRzR7abFoss4upzpe8kbcm7DSzIlNrmP9Nu5MrAmozgBshPxdOFLccNVKPJw TUv/bjo0xpg9nouITPLXImMwuBMT3DiKs7qsQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688668180; x=1691260180; 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=NsC+L4CHLTDTROKB8tT7c3nb8dVrzJsiNq7PJiTV4iE=; b=Fn3Uufpe+ezKBk/DrnHpf9pzGXol8jQE3OI0nFX3OMCSvvMaOlO+nx3ASr8/hJc+m1 WCwu3hfCXZ01Qqh3OHS1Bm86a/QjebyDNMMGsIEA+/Wb5O/6EJdg3078Tft89JPBnxT2 Nz1XxUQHgqIhw11DA754FFgOnWrDLiuAQRkhcqBnO+osXzP8BhA4f2EFwwykWSKauATO J0Ky0utbkIdaE4us0BZQKSg66UMGZQHJitYXjG7DWIDIqKdwFX++cSwqUu/RRqSalh09 bq65tbiAE+yE2GCjVkQ0g0orxUM28XtoPMt2pR1uXsijHSjghJ8tWhF2roGUUuo4kLnQ MM8w== X-Gm-Message-State: ABy/qLbX3EQjgPlV0n08HL0MyRxc8vhEOvUMfH0a7X+ET23QkSoVuuCj 5yQz97k4ySoLqdtEQ8wfzJYuUQ== X-Received: by 2002:a05:6a00:1952:b0:679:9639:1f6a with SMTP id s18-20020a056a00195200b0067996391f6amr2572927pfk.14.1688668180394; Thu, 06 Jul 2023 11:29:40 -0700 (PDT) Received: from ubuntu-22.localdomain ([192.19.222.250]) by smtp.gmail.com with ESMTPSA id y13-20020aa7804d000000b006826c9e4397sm1580871pfm.48.2023.07.06.11.29.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jul 2023 11:29:39 -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 v4 5/5] mtd: rawnand: brcmnand: Fix mtd oobsize Date: Thu, 6 Jul 2023 11:29:09 -0700 Message-Id: <20230706182909.79151-6-william.zhang@broadcom.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230706182909.79151-1-william.zhang@broadcom.com> References: <20230706182909.79151-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 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?1770698583388894222?= X-GMAIL-MSGID: =?utf-8?q?1770698583388894222?= 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 v4: None 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 71d0ba652bee..39661e23d7d4 100644 --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c @@ -2652,6 +2652,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]; @@ -2673,10 +2675,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;