Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2682222pxb; Tue, 23 Feb 2021 12:55:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJzarZjksGOfV0VdrcrO8uHm1Y/ibid4Q/hsFmjh7HVOR6jQPhsG4N1X1BWWT5fdhzHJ50Ay X-Received: by 2002:a17:907:d86:: with SMTP id go6mr27044325ejc.337.1614113720722; Tue, 23 Feb 2021 12:55:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614113720; cv=none; d=google.com; s=arc-20160816; b=pzxeaeGTPx9Gkt9LQU6UzrbJinnGb4lOJBhP/qvpll53ytblshVkKFgE8C96mM7j5v EYyhfcy/YArWsZDeiEQOQaDRUswPhdjHG59p2SMV6CQZSmRgHWGZiM8aEgipCMPoaaU6 FnZvOtxml7C1fqFsQOJgf+uv3lklblOyUssu7OtkRs7aV8Wqix39jUn+DhMYUULJD8Ns i5Sf436+wodCQmFckHZSicw3obyUISlRAyXjB1ihi/8NyDJAyF/dcTdS++oQhEnoNs51 ZhRUm9npvLcg9Wkf4lisOWIUw5icdERXYolbqYiTYSGeqv3gO3dHplHf98grURP9oWF1 9xRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=MGdbAuwoFLXD+tAq8pWdNYgX/7ptP7NY7FrqT3cuBZE=; b=DuU5U1fBwJY1sZdUM12P7P94/MOx/BHVLMumw+TPoO1fJhVy+HhERKXQd7DTuzQcvD gnQca+v8VZwUSNdZ3TdnCA9oVeq446e5Ev/VxX6Gv4Xtzmiz/qz9gENI2AIEoOCg/ucD nBye3Fi0TY1QliwvpWpjSAmt3NYhMF0mqQftmJB7moxNE+k5ookx5RpJ2v0L3D4Cq2Ix krXYbQ4gnZc/4AQKMEoYQw5/YtBJ231xxKC++XQqNEPEiUTpuCZmhKjbu3hYfqkFZoyG DIJBQop9RbSs1LCyBG5pG0CwGDDYHFFfJ3CoGvuMobYgUFKEw0g7WQW6bCVrDjIPgQCA kh3w== 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 a3si16455535ejd.310.2021.02.23.12.54.51; Tue, 23 Feb 2021 12:55:20 -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 S233855AbhBWTlG (ORCPT + 99 others); Tue, 23 Feb 2021 14:41:06 -0500 Received: from alexa-out.qualcomm.com ([129.46.98.28]:29750 "EHLO alexa-out.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230330AbhBWTk4 (ORCPT ); Tue, 23 Feb 2021 14:40:56 -0500 Received: from ironmsg-lv-alpha.qualcomm.com ([10.47.202.13]) by alexa-out.qualcomm.com with ESMTP; 23 Feb 2021 11:39:28 -0800 X-QCInternal: smtphost Received: from ironmsg02-blr.qualcomm.com ([10.86.208.131]) by ironmsg-lv-alpha.qualcomm.com with ESMTP/TLS/AES256-SHA; 23 Feb 2021 11:39:27 -0800 X-QCInternal: smtphost Received: from mdalam-linux.qualcomm.com ([10.201.2.71]) by ironmsg02-blr.qualcomm.com with ESMTP; 24 Feb 2021 01:09:06 +0530 Received: by mdalam-linux.qualcomm.com (Postfix, from userid 466583) id 0340A20E1F; Wed, 24 Feb 2021 01:09:05 +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 2/5] mtd: rawnand: qcom: Add helper to check last code word Date: Wed, 24 Feb 2021 01:08:58 +0530 Message-Id: <1614109141-7531-2-git-send-email-mdalam@codeaurora.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1614109141-7531-1-git-send-email-mdalam@codeaurora.org> References: <1614109141-7531-1-git-send-email-mdalam@codeaurora.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add the qcom_nandc_is_last_cw() helper which checks if the input cw index is the last one or not. Signed-off-by: Md Sadre Alam --- drivers/mtd/nand/raw/qcom_nandc.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/mtd/nand/raw/qcom_nandc.c b/drivers/mtd/nand/raw/qcom_nandc.c index 4898d32..9a890ef 100644 --- a/drivers/mtd/nand/raw/qcom_nandc.c +++ b/drivers/mtd/nand/raw/qcom_nandc.c @@ -662,6 +662,12 @@ static void nandc_set_reg(struct nand_chip *chip, 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) { @@ -1629,7 +1635,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 + @@ -1710,7 +1716,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 { @@ -1770,7 +1776,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 { @@ -1869,7 +1875,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; @@ -2048,7 +2054,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,7 +2074,7 @@ static int qcom_nandc_write_page(struct nand_chip *chip, const uint8_t *buf, * 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, @@ -2123,7 +2129,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