Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1349940pxb; Sun, 21 Feb 2021 22:26:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJzPEMKH3hoxItIzYXPGQW/5PZcpV8nIJdYws38C9LQL4tdzfFXiwwqxXaQoUjwHRQn3Xs5o X-Received: by 2002:aa7:cd06:: with SMTP id b6mr14648381edw.105.1613975218820; Sun, 21 Feb 2021 22:26:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613975218; cv=none; d=google.com; s=arc-20160816; b=rH+pb5fMC69bi2B0Arm5hBh8rIbx+8lcSMOIeK0ONvQ/MheSf9nFmGQvPebIwx26PN Vy/+SXSRRFYc851QQimZQ6UfG/ackFxKPxZatVGT4snul1fMAF3eWj/OqD4+IX4YuN4N wKO8g7rPwAH/BAmAzfxuuLHGELYgspyeeOEFp/uViCaeoFSfgBfewkbuVx6Lncr6TeYH dFlOXBhG3wiRFTCmYRQQFO6LzQokMLv2fKj7pF79PZeigx2KfaEYvKsSIePFwUWJUGzl kfQj3ljmY0V4ivdIavSvlqyo7cDE6C/NaUPoEHKLq+8XODqTNHzJkWlnTogOrFlt160S G/oQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=eufTMyIiNPHZxdvCzdH4K8WxNH/O/9NjrasSCHQSLHk=; b=s9b3kDidfH7/o5l3raqVotZlo18XUrYGw+IQNk2oDjCllOMu2QZxOErpCbn+3OMxzS An1xl5KIeDv+ozgYqJO+qgU+2S32sSlmM4RX+PSfOxh8IRcaEFB6ny6K+g3weo1y4KGq uYeItGQSmAuAc/ge6DM0n/BfZdUXKkJCE4vVaMvK83HnFw8BtUD0Cc2Ce4ubqYj5NnoL CG1yxxYPznjsPdbijWBGRqzA+GTbW9JFAKV3Nb82S6BRNovmBrDbtYMkubevHLWDSfPE AIziQsWkYMACNgMDeG3cYP2uR3hzGTP4xGTtsFBYGKLI4mhkjv4WA85BZvIEeIPPXmGi wCVA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l3si10750071edk.141.2021.02.21.22.26.35; Sun, 21 Feb 2021 22:26:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229903AbhBVG0J (ORCPT + 99 others); Mon, 22 Feb 2021 01:26:09 -0500 Received: from alexa-out.qualcomm.com ([129.46.98.28]:32942 "EHLO alexa-out.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229748AbhBVG0A (ORCPT ); Mon, 22 Feb 2021 01:26:00 -0500 Received: from ironmsg09-lv.qualcomm.com ([10.47.202.153]) by alexa-out.qualcomm.com with ESMTP; 21 Feb 2021 22:25:18 -0800 X-QCInternal: smtphost Received: from ironmsg02-blr.qualcomm.com ([10.86.208.131]) by ironmsg09-lv.qualcomm.com with ESMTP/TLS/AES256-SHA; 21 Feb 2021 22:25:17 -0800 X-QCInternal: smtphost Received: from mdalam-linux.qualcomm.com ([10.201.2.71]) by ironmsg02-blr.qualcomm.com with ESMTP; 22 Feb 2021 11:54:57 +0530 Received: by mdalam-linux.qualcomm.com (Postfix, from userid 466583) id 7B1E221107; Mon, 22 Feb 2021 11:54:57 +0530 (IST) From: Md Sadre Alam To: miquel.raynal@bootlin.com, mani@kernel.org, boris.brezillon@collabora.com, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Cc: mdalam@codeaurora.org, sricharan@codeaurora.org Subject: [PATCH] mtd: rawnand: qcom: Add helper to check last code word Date: Mon, 22 Feb 2021 11:54:55 +0530 Message-Id: <1613975095-15550-1-git-send-email-mdalam@codeaurora.org> X-Mailer: git-send-email 2.7.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This change will add helper qcom_nandc_is_last_cw() which will check for last code word and return true for last code word and false for other code word. Signed-off-by: Md Sadre Alam --- drivers/mtd/nand/raw/qcom_nandc.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/mtd/nand/raw/qcom_nandc.c b/drivers/mtd/nand/raw/qcom_nandc.c index ae8870ec..4189a7f 100644 --- a/drivers/mtd/nand/raw/qcom_nandc.c +++ b/drivers/mtd/nand/raw/qcom_nandc.c @@ -661,6 +661,12 @@ static void nandc_set_reg(struct qcom_nand_controller *nandc, int offset, *reg = cpu_to_le32(val); } +/* Helper to check the code word, whether it is last cw or not */ +static bool qcom_nandc_is_last_cw(struct nand_ecc_ctrl *ecc, int cw) +{ + return cw == (ecc->steps - 1); +} + /* helper to configure address register values */ static void set_address(struct qcom_nand_host *host, u16 column, int page) { @@ -1632,7 +1638,7 @@ qcom_nandc_read_cw_raw(struct mtd_info *mtd, struct nand_chip *chip, data_size1 = mtd->writesize - host->cw_size * (ecc->steps - 1); oob_size1 = host->bbm_size; - if (cw == (ecc->steps - 1)) { + if (qcom_nandc_is_last_cw(ecc, cw)) { data_size2 = ecc->size - data_size1 - ((ecc->steps - 1) * 4); oob_size2 = (ecc->steps * 4) + host->ecc_bytes_hw + @@ -1713,7 +1719,7 @@ check_for_erased_page(struct qcom_nand_host *host, u8 *data_buf, } for_each_set_bit(cw, &uncorrectable_cws, ecc->steps) { - if (cw == (ecc->steps - 1)) { + if (qcom_nandc_is_last_cw(ecc, cw)) { data_size = ecc->size - ((ecc->steps - 1) * 4); oob_size = (ecc->steps * 4) + host->ecc_bytes_hw; } else { @@ -1773,7 +1779,7 @@ static int parse_read_errors(struct qcom_nand_host *host, u8 *data_buf, u32 flash, buffer, erased_cw; int data_len, oob_len; - if (i == (ecc->steps - 1)) { + if (qcom_nandc_is_last_cw(ecc, i)) { data_len = ecc->size - ((ecc->steps - 1) << 2); oob_len = ecc->steps << 2; } else { @@ -1872,7 +1878,7 @@ static int read_page_ecc(struct qcom_nand_host *host, u8 *data_buf, for (i = 0; i < ecc->steps; i++) { int data_size, oob_size; - if (i == (ecc->steps - 1)) { + if (qcom_nandc_is_last_cw(ecc, i)) { data_size = ecc->size - ((ecc->steps - 1) << 2); oob_size = (ecc->steps << 2) + host->ecc_bytes_hw + host->spare_bytes; @@ -2051,7 +2057,7 @@ static int qcom_nandc_write_page(struct nand_chip *chip, const uint8_t *buf, for (i = 0; i < ecc->steps; i++) { int data_size, oob_size; - if (i == (ecc->steps - 1)) { + if (qcom_nandc_is_last_cw(ecc, i)) { data_size = ecc->size - ((ecc->steps - 1) << 2); oob_size = (ecc->steps << 2) + host->ecc_bytes_hw + host->spare_bytes; @@ -2068,10 +2074,10 @@ static int qcom_nandc_write_page(struct nand_chip *chip, const uint8_t *buf, * when ECC is enabled, we don't really need to write anything * to oob for the first n - 1 codewords since these oob regions * just contain ECC bytes that's written by the controller - * itself. For the last codeword, we skip the bbm positions and - * write to the free oob area. + * itself. For the last codeword, we skip the bbm positions and write + * to the free oob area. */ - if (i == (ecc->steps - 1)) { + if (qcom_nandc_is_last_cw(ecc, i)) { oob_buf += host->bbm_size; write_data_dma(nandc, FLASH_BUF_ACC + data_size, @@ -2126,7 +2132,7 @@ static int qcom_nandc_write_page_raw(struct nand_chip *chip, data_size1 = mtd->writesize - host->cw_size * (ecc->steps - 1); oob_size1 = host->bbm_size; - if (i == (ecc->steps - 1)) { + if (qcom_nandc_is_last_cw(ecc, i)) { data_size2 = ecc->size - data_size1 - ((ecc->steps - 1) << 2); oob_size2 = (ecc->steps << 2) + host->ecc_bytes_hw + -- 2.7.4