Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3486463imu; Sun, 11 Nov 2018 16:11:31 -0800 (PST) X-Google-Smtp-Source: AJdET5doZOeF8mX3l3RbId5KY1G3tAIAHJENLjlcI3ggmG1oBgIkc8qvrQIIraHw5ockUGE9uC5h X-Received: by 2002:a62:f24f:: with SMTP id y15-v6mr17940067pfl.25.1541981491648; Sun, 11 Nov 2018 16:11:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541981491; cv=none; d=google.com; s=arc-20160816; b=XPed61z7wqbIHAWxcIXYQTG4+XawciB0jvr6uF95huRFSI1cJYddlSyKqVvj5rJT7u qwytevTxFPtQL9njBpKCvUV8CUqZgizwBcpGTpZpdPQ7L7pmQUcpb/eMwM+LXW7XrgCY bRyI47F9eaugX47mSk8spij+mNMlU4QpVRwH9ofXsNMjuyN1mujXBaMUQp9v9h6o3b6W W0lD5ao4knKrXUJ3WBc/lcMZP/9h+POzpErfHJi9e6lX4E2z5G/UmF/tQ44mH8wAamYz eLidGgqJzgReVuse/mPMyZrEfb+5Q+2BTy2NJTM2Q/0a+jiACteWsuzd3u9dypfv2I0h Jodw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TozeDqp5V/5+9BwXxWI7v1CvSjRrn4hqhnhpqYeyl54=; b=jEKIY86Z44JRfrofUe91qSl+BoSiQvccs14S2oJybzT3d1qe9TYu2PXHvCxQK3jxmt ObtrFWd+82xbMTxXn+73PEWj7p6T5V7Jfsgw5cg+x2mX2WEJPApdBC0Wd6+WX5ug8nCl wTSdl4Rd3TZGovJdqY22rVk4OpRaO47J6D1DkpZUPg3KZoylo+3+d3/USM54mFFdvhv5 9ynExP9fVKOu0jHkCYpqQhmDdHck97xGXhYNUaAsMb79m+dDNinYAve2SNVixtFy0IvI ufM0AKgTC+b8Tc4hcZy2DCCGSeEu1Zu/JRWO9fzP5b+nB99dYdWfhSLvVWk+GFXHP/sY avBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BD4dZqZV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a62-v6si17072443pfb.266.2018.11.11.16.11.16; Sun, 11 Nov 2018 16:11:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BD4dZqZV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731790AbeKLKBR (ORCPT + 99 others); Mon, 12 Nov 2018 05:01:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:60706 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730731AbeKLIRY (ORCPT ); Mon, 12 Nov 2018 03:17:24 -0500 Received: from localhost (unknown [206.108.79.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2674D214DB; Sun, 11 Nov 2018 22:27:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975248; bh=To9ZBeK/OgdizYlejYz0ynHrahyTLhiaYF06SCOxlOk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BD4dZqZVEcmfOGX4PKexw097JzSyPqMx1PQj/xF+dL+qvIJrV2XgwNPLIVP47Mtlv mChOhC4c764zJQqRpnMTuYyWGfH53QPytAhSsWoILukV3Qc2GD2Lm7/X25jgWvgvwG SpoF+0pJmhGhupIe3xlsa8sRmN1NAPx+2eeZrUCs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Masahiro Yamada , Boris Brezillon , Miquel Raynal , Sasha Levin Subject: [PATCH 4.19 072/361] mtd: rawnand: denali: set SPARE_AREA_SKIP_BYTES register to 8 if unset Date: Sun, 11 Nov 2018 14:16:59 -0800 Message-Id: <20181111221630.112167800@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Masahiro Yamada [ Upstream commit 0d55c668b218a1db68b5044bce4de74e1bd0f0c8 ] NAND devices need additional data area (OOB) for error correction, but it is also used for Bad Block Marker (BBM). In many cases, the first byte in OOB is used for BBM, but the location actually depends on chip vendors. The NAND controller should preserve the precious BBM to keep track of bad blocks. In Denali IP, the SPARE_AREA_SKIP_BYTES register is used to specify the number of bytes to skip from the start of OOB. The ECC engine will automatically skip the specified number of bytes when it gets access to OOB area. The same value for SPARE_AREA_SKIP_BYTES should be used between firmware and the operating system if you intend to use the NAND device across the control hand-off. In fact, the current denali.c code expects firmware to have already set the SPARE_AREA_SKIP_BYTES register, then reads the value out. If no firmware (or bootloader) has initialized the controller, the register value is zero, which is the default after power-on-reset. In other words, the Linux driver cannot initialize the controller by itself. Some possible solutions are: [1] Add a DT property to specify the skipped bytes in OOB [2] Associate the preferred value with compatible [3] Hard-code the default value in the driver My first attempt was [1], but in the review process, [3] was suggested as a counter-implementation. (https://lore.kernel.org/patchwork/patch/983055/) The default value 8 was chosen to match to the boot ROM of the UniPhier platform. The preferred value may vary by platform. If so, please trade up to a different solution. Signed-off-by: Masahiro Yamada Reviewed-by: Boris Brezillon Signed-off-by: Miquel Raynal Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/mtd/nand/raw/denali.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) --- a/drivers/mtd/nand/raw/denali.c +++ b/drivers/mtd/nand/raw/denali.c @@ -28,6 +28,7 @@ MODULE_LICENSE("GPL"); #define DENALI_NAND_NAME "denali-nand" +#define DENALI_DEFAULT_OOB_SKIP_BYTES 8 /* for Indexed Addressing */ #define DENALI_INDEXED_CTRL 0x00 @@ -1105,12 +1106,17 @@ static void denali_hw_init(struct denali denali->revision = swab16(ioread32(denali->reg + REVISION)); /* - * tell driver how many bit controller will skip before - * writing ECC code in OOB, this register may be already - * set by firmware. So we read this value out. - * if this value is 0, just let it be. + * Set how many bytes should be skipped before writing data in OOB. + * If a non-zero value has already been set (by firmware or something), + * just use it. Otherwise, set the driver default. */ denali->oob_skip_bytes = ioread32(denali->reg + SPARE_AREA_SKIP_BYTES); + if (!denali->oob_skip_bytes) { + denali->oob_skip_bytes = DENALI_DEFAULT_OOB_SKIP_BYTES; + iowrite32(denali->oob_skip_bytes, + denali->reg + SPARE_AREA_SKIP_BYTES); + } + denali_detect_max_banks(denali); iowrite32(0x0F, denali->reg + RB_PIN_ENABLED); iowrite32(CHIP_EN_DONT_CARE__FLAG, denali->reg + CHIP_ENABLE_DONT_CARE);