From patchwork Fri Jul 6 07:51:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abhishek Sahu X-Patchwork-Id: 940310 X-Patchwork-Delegate: miquel.raynal@bootlin.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="RfMTDWsB"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=codeaurora.org header.i=@codeaurora.org header.b="EvCpASqV"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=codeaurora.org header.i=@codeaurora.org header.b="H92PoadK"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41MRmV1L3Fz9s4r for ; Fri, 6 Jul 2018 17:53:14 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=cTPrObulIqiFZc0ZnNnJKY6uWfcMAzd1jmiMIvyIkgc=; b=RfMTDWsB1ldLI3vmTzRUkjAqG8 9A+q3olIj8tU8EgONq3uMs1Y1DAITEbGZwXDIQ3CJMFyhgwPUR1SrbkR6Xxqo/jJMOWOox25o1mmC iU0LDzHTYTbCNewbBONmVRTtBXoAWO/FPhyct9ZLpXZHPTmWTpXymH5KGLCjwtWNR4iVZZG05HFxc asVGkR18GXKJsTAtXoh5Tm8fcUvp0cUNfA6cbHSWkA53JXS/hNva/cjZPExh1OEf0yV8zTNfa7IHJ OmVghzYG6gpYJe/Ht3ykmwKPeWPufR9YnvQKDbJWAm0kWYkiHfvVFR4k3RwmAkqvJaVPxVGacVwCI NXGmfB2w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fbLYD-0004xZ-FF; Fri, 06 Jul 2018 07:53:09 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fbLXT-00041D-DE for linux-mtd@lists.infradead.org; Fri, 06 Jul 2018 07:52:26 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 2943C60B23; Fri, 6 Jul 2018 07:52:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1530863536; bh=w5H2e0pBPABQrAVbQkSHQ12xHME0j5Xr9WI+mupqGM4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EvCpASqVWlrEqt8GY7qAnYNhvvQuE9+L8LNaioTubJcOqKDvmzLZhoAOwuOPX0AbQ m2VIrOA3c/HHCYEq4anJQFZerzNC/RsciieDlFFXFrbh4oFZtCBfJ/9Dv2DcbumUps efzEBl44WrHeg+i57QKuYSsyFOGTSpUt0CfYYuVI= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED, T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from absahu-linux.qualcomm.com (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: absahu@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id ADB5D60B26; Fri, 6 Jul 2018 07:52:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1530863534; bh=w5H2e0pBPABQrAVbQkSHQ12xHME0j5Xr9WI+mupqGM4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H92PoadK0znD1dJnk/IEbkGwi6FhL77AKuFY8wCcS/bmealI5iyBehgwBXu+dbeuM SR8hkzyX1XWUOyGew70bx4AdGAcCkEVeUiYFNVCtIingBIQLJ4scWXBs2QYSEl45RK 6nlvTp84slQDYfcnHpTijnMYO/Y3dagcuNBbhuh8= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org ADB5D60B26 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=absahu@codeaurora.org From: Abhishek Sahu To: Boris Brezillon , Miquel Raynal Subject: [PATCH 2/5] mtd: rawnand: qcom: remove driver specific block_markbad function Date: Fri, 6 Jul 2018 13:21:56 +0530 Message-Id: <1530863519-5564-3-git-send-email-absahu@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1530863519-5564-1-git-send-email-absahu@codeaurora.org> References: <1530863519-5564-1-git-send-email-absahu@codeaurora.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180706_005223_611264_5A084E33 X-CRM114-Status: GOOD ( 21.93 ) X-Spam-Score: -2.4 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.4 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [198.145.29.96 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Marek Vasut , Abhishek Sahu , linux-mtd@lists.infradead.org, Richard Weinberger , Andy Gross , Brian Norris , David Woodhouse MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The NAND base layer calls write_oob() by setting bytes at chip->badblockpos with value non 0xFF for updating bad block status. The QCOM NAND controller skips the bad block bytes while doing normal write with ECC enabled. When initial support for this driver was added, the driver specific function was added temporarily for block_markbad() with assumption to change for raw read in NAND base layer. Moving to raw read for block_markbad() seems to take more time so this patch removes driver specific block_markbad() function by using following HACK in write_oob() function. Check for BBM bytes in OOB and accordingly do raw write for updating BBM bytes in NAND flash or normal write for updating available OOB bytes. Signed-off-by: Abhishek Sahu --- drivers/mtd/nand/raw/qcom_nandc.c | 103 +++++++++++++++----------------------- 1 file changed, 40 insertions(+), 63 deletions(-) diff --git a/drivers/mtd/nand/raw/qcom_nandc.c b/drivers/mtd/nand/raw/qcom_nandc.c index ea253ac..df12cf3 100644 --- a/drivers/mtd/nand/raw/qcom_nandc.c +++ b/drivers/mtd/nand/raw/qcom_nandc.c @@ -2138,28 +2138,57 @@ static int qcom_nandc_write_oob(struct mtd_info *mtd, struct nand_chip *chip, struct qcom_nand_host *host = to_qcom_nand_host(chip); struct qcom_nand_controller *nandc = get_qcom_nand_controller(chip); struct nand_ecc_ctrl *ecc = &chip->ecc; - u8 *oob = chip->oob_poi; - int data_size, oob_size; + u8 *oob = chip->oob_poi, bbm_byte; + int data_size, oob_size, bbm_offset, write_size; int ret; - host->use_ecc = true; clear_bam_transaction(nandc); - /* calculate the data and oob size for the last codeword/step */ - data_size = ecc->size - ((ecc->steps - 1) << 2); - oob_size = mtd->oobavail; + /* + * The NAND base layer calls ecc->write_oob() by setting bytes at + * chip->badblockpos (chip->badblockpos will be 0 for QCOM NAND + * controller layout) in OOB buffer with value other that 0xFF + * for updating bad block status. QCOM NAND controller skips + * BBM bytes while writing with ECC, so following HACK has been + * added in this function for using generic block_markbad() function. + * + * Check for BBM bytes in OOB and accordingly do raw write for + * updating BBM bytes in NAND flash or normal write with ECC for + * updating available OOB bytes. + */ + bbm_byte = oob[0]; + if (chip->options & NAND_BUSWIDTH_16) + bbm_byte &= oob[1]; - memset(nandc->data_buffer, 0xff, host->cw_data); - /* override new oob content to last codeword */ - mtd_ooblayout_get_databytes(mtd, nandc->data_buffer + data_size, oob, - 0, mtd->oobavail); + /* Write BBM bytes by doing raw write. */ + if (bbm_byte != 0xff) { + host->use_ecc = false; + memset(nandc->data_buffer, 0xff, host->cw_size); + /* Determine the BBM bytes position and update the same */ + bbm_offset = mtd->writesize - host->cw_size * (ecc->steps - 1); + memcpy(nandc->data_buffer + bbm_offset, oob, host->bbm_size); + write_size = host->cw_size; + /* Write OOB bytes by doing normal write with ECC */ + } else { + host->use_ecc = true; + /* calculate the data and oob size for the last codeword/step */ + data_size = ecc->size - ((ecc->steps - 1) << 2); + oob_size = mtd->oobavail; + + memset(nandc->data_buffer, 0xff, host->cw_data); + /* override new oob content to last codeword */ + mtd_ooblayout_get_databytes(mtd, nandc->data_buffer + data_size, + oob, 0, mtd->oobavail); + + write_size = data_size + oob_size; + } set_address(host, host->cw_size * (ecc->steps - 1), page); update_rw_regs(host, 1, false); config_nand_page_write(nandc); write_data_dma(nandc, FLASH_BUF_ACC, - nandc->data_buffer, data_size + oob_size, 0); + nandc->data_buffer, write_size, 0); config_nand_cw_write(nandc); ret = submit_descs(nandc); @@ -2174,48 +2203,6 @@ static int qcom_nandc_write_oob(struct mtd_info *mtd, struct nand_chip *chip, return nand_prog_page_end_op(chip); } -static int qcom_nandc_block_markbad(struct mtd_info *mtd, loff_t ofs) -{ - struct nand_chip *chip = mtd_to_nand(mtd); - struct qcom_nand_host *host = to_qcom_nand_host(chip); - struct qcom_nand_controller *nandc = get_qcom_nand_controller(chip); - struct nand_ecc_ctrl *ecc = &chip->ecc; - int page, ret; - - clear_read_regs(nandc); - clear_bam_transaction(nandc); - - /* - * to mark the BBM as bad, we flash the entire last codeword with 0s. - * we don't care about the rest of the content in the codeword since - * we aren't going to use this block again - */ - memset(nandc->data_buffer, 0x00, host->cw_size); - - page = (int)(ofs >> chip->page_shift) & chip->pagemask; - - /* prepare write */ - host->use_ecc = false; - set_address(host, host->cw_size * (ecc->steps - 1), page); - update_rw_regs(host, 1, false); - - config_nand_page_write(nandc); - write_data_dma(nandc, FLASH_BUF_ACC, - nandc->data_buffer, host->cw_size, 0); - config_nand_cw_write(nandc); - - ret = submit_descs(nandc); - - free_descs(nandc); - - if (ret) { - dev_err(nandc->dev, "failure to update BBM\n"); - return -EIO; - } - - return nand_prog_page_end_op(chip); -} - /* * the three functions below implement chip->read_byte(), chip->read_buf() * and chip->write_buf() respectively. these aren't used for @@ -2757,16 +2744,6 @@ static int qcom_nand_host_init(struct qcom_nand_controller *nandc, chip->set_features = nand_get_set_features_notsupp; chip->get_features = nand_get_set_features_notsupp; - /* - * the bad block marker is writable only when we write the last codeword - * of a page with ECC disabled. currently, the nand_base and nand_bbt - * helpers don't allow us to write BB from a nand chip with ECC - * disabled (MTD_OPS_PLACE_OOB is set by default). use the block_markbad - * helpers until we permanently switch to using - * MTD_OPS_RAW for all drivers (with the help of badblockbits) - */ - chip->block_markbad = qcom_nandc_block_markbad; - chip->controller = &nandc->controller; chip->options |= NAND_NO_SUBPAGE_WRITE | NAND_USE_BOUNCE_BUFFER | NAND_SKIP_BBTSCAN;