From patchwork Mon Aug 5 19:03:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tokunori Ikegami X-Patchwork-Id: 1142436 X-Patchwork-Delegate: vigneshr@ti.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=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="SRVJ6gVt"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="nHRMEFbk"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 462RyW40gyz9s7T for ; Tue, 6 Aug 2019 05:04:19 +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=XARoKtSntumTnSt2JlaaHaGqvQ3xf+LapfFlQ8IB/uM=; b=SRVJ6gVtCcNDGr0B+FE8CrpDD2 Bde3fVolw4Ml09k4dF6ZCKDL6miczQX0c/VoFIcV3yvBBOZOYr7uDNRw+v9Z10sNwuuMbvwEHvlrf ReHCOFdJkYuZqev1wTbJcE5waGUloQ592Z8AK2uDpsKbWcoxkGMpN9i0O1txURRr3NnXDqCKKCjZo mbpfXKLdHsnRTVgM1FnbnWbRNohduJ2fh04b6XlP2B9QTuR/Xv13q3lZ0DshCrb+5Vno9rgunk0Q0 zruzVeGyaRS+Z9wkLmD9cKpQcBpld8IJSi3Gm7qBD8q9OgLPR7I09ND0Dq4xVklchgk4TqeZxvG8e gVRP7gOQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1huiHJ-0003yH-EV; Mon, 05 Aug 2019 19:04:17 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1huiGq-0003MB-TS for linux-mtd@lists.infradead.org; Mon, 05 Aug 2019 19:03:50 +0000 Received: by mail-pg1-x541.google.com with SMTP id l21so40201734pgm.3 for ; Mon, 05 Aug 2019 12:03:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xuJr+cf3xJACYJRjDFlAmldKlorKm2FykMimPnIYDfQ=; b=nHRMEFbk+F1PVM1unmunzgXaRiH9aRxkIcaEEwDehhF9EWvPgQN59ZG04hUv4aNoGV sw0EBnG6poB87Z8HeYkw6F3n4ZHo9qnSVLL/PhkDTRSvPkRv8CwqJwiHoDBJmf2X0xxz /d472WnueJp0LYNdLs4VzzktmWDDhUT7S1bAIH3vCjtetzCp+gUCYYscS+T4g0NNvwnN hfa0cYeYPEK1ZvwfG1VbDW1IOh+azdte8EpUHPtl8EeB0jggi2GNfIqBfrBKZbsVCkw7 tkxxUDrBSckqlWpk4VwNPCsW0Kq7EXtP61RLwPLIVa46zragcsaeGBN+HCICdJMTCKTR WYjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xuJr+cf3xJACYJRjDFlAmldKlorKm2FykMimPnIYDfQ=; b=pg4pTplh0QBmlPxfEvAcuihhcYEleS0BEcGozo/ieT3NSnHL9lQuy4u9wNRbhZRJDz i/zW7sYyqy3N4NSdL6Q6b1Qd2G8OadCr7UNouz8jpcQpk6zONdFtcN0LWNESsSmMYdNZ qsVTRmkwAwozxRhYRyplwovPItqqWZY4960lFOCr3hqVjzpkt7QipqNch6btr/SU1hLL s0jo3kGx4P5RY/l1q6l+i54vm7RvFAJjYe+XzW6GtwuroE9KXAM532XJc1jC8WDrxR6I Lb0dTx7xxwdq67iQ7VdmcBPPZAVyxHJsTOCt2CWqhgrKUlMVCd5hyZZ/dm4hLOry48lD QN+Q== X-Gm-Message-State: APjAAAURlDaXlwgavN5PrmIPuMAdHj3sIqLereczrp58vhW41mpNtn+a oSBt189M/xKwqyKPIhiNypeT6nbM X-Google-Smtp-Source: APXvYqy9zpj8OjUwZqAxzLRtnQVXWAPrVHe/XzitN5oD5DZxQP0V+RW8F9mvqA2pzIC2mGPZxFX6Ng== X-Received: by 2002:a63:fb14:: with SMTP id o20mr124856639pgh.136.1565031827972; Mon, 05 Aug 2019 12:03:47 -0700 (PDT) Received: from localhost.localdomain (M106072039032.v4.enabler.ne.jp. [106.72.39.32]) by smtp.gmail.com with ESMTPSA id q198sm88045579pfq.155.2019.08.05.12.03.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Aug 2019 12:03:47 -0700 (PDT) From: Tokunori Ikegami To: Vignesh Raghavendra Subject: [PATCH v8 3/9] mtd: cfi_cmdset_0002: Split do_write_oneword() to reduce function size Date: Tue, 6 Aug 2019 04:03:20 +0900 Message-Id: <20190805190326.28772-4-ikegami.t@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190805190326.28772-1-ikegami.t@gmail.com> References: <20190805190326.28772-1-ikegami.t@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190805_120349_005987_6CF26857 X-CRM114-Status: GOOD ( 19.81 ) X-Spam-Score: 0.8 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.8 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:541 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (ikegami.t[at]gmail.com) -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_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 1.0 FREEMAIL_REPLY From and body contain different freemails X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tokunori Ikegami , linux-mtd@lists.infradead.org, Fabio Bettoni , Joakim Tjernlund MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Reduce the size of do_write_oneword() by extracting a helper function for the hardware access. Signed-off-by: Tokunori Ikegami Reviewed-by: Chris Packham Cc: Fabio Bettoni Co: Hauke Mehrtens Cc: Joakim Tjernlund Cc: linux-mtd@lists.infradead.org --- Changes since v7: - None. Changes since v6: - Removed the tag of Koen Vandeputte as same with the v7 1/9 patch. - Address the ./scripts/checkpatch.pl issues. Changes since v5: - Rebased on top of Liu Jian's fixes in master. - Change the email address of Tokunori Ikegami to ikegami.t@gmail.com. Changes since v4: - None. Changes since v3: - Drop the unnecessary comment and blank line. - Change the email address of Tokunori Ikegami to ikegami_to@yahoo.co.jp. Changes since v2: - Just update the commit message for the comment - Add Reviewed-by tag. Changes since v1: - Add the patch. drivers/mtd/chips/cfi_cmdset_0002.c | 90 ++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 40 deletions(-) diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c index c9fd35d1f3fe..b74b57e30904 100644 --- a/drivers/mtd/chips/cfi_cmdset_0002.c +++ b/drivers/mtd/chips/cfi_cmdset_0002.c @@ -1637,11 +1637,11 @@ static int cfi_amdstd_lock_user_prot_reg(struct mtd_info *mtd, loff_t from, do_otp_lock, 1); } -static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip, - unsigned long adr, map_word datum, - int mode) +static int __xipram do_write_oneword_once(struct map_info *map, + struct flchip *chip, + unsigned long adr, map_word datum, + int mode, struct cfi_private *cfi) { - struct cfi_private *cfi = map->fldrv_priv; unsigned long timeo = jiffies + HZ; /* * We use a 1ms + 1 jiffies generic timeout for writes (most devices @@ -1654,42 +1654,7 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip, */ unsigned long uWriteTimeout = (HZ / 1000) + 1; int ret = 0; - map_word oldd; - int retry_cnt = 0; - - adr += chip->start; - - mutex_lock(&chip->mutex); - ret = get_chip(map, chip, adr, mode); - if (ret) { - mutex_unlock(&chip->mutex); - return ret; - } - - pr_debug("MTD %s(): WRITE 0x%.8lx(0x%.8lx)\n", - __func__, adr, datum.x[0]); - - if (mode == FL_OTP_WRITE) - otp_enter(map, chip, adr, map_bankwidth(map)); - /* - * Check for a NOP for the case when the datum to write is already - * present - it saves time and works around buggy chips that corrupt - * data at other locations when 0xff is written to a location that - * already contains 0xff. - */ - oldd = map_read(map, adr); - if (map_word_equal(map, oldd, datum)) { - pr_debug("MTD %s(): NOP\n", - __func__); - goto op_done; - } - - XIP_INVAL_CACHED_RANGE(map, adr, map_bankwidth(map)); - ENABLE_VPP(map); - xip_disable(map, chip, adr); - - retry: cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL); cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi, cfi->device_type, NULL); cfi_send_gen_cmd(0xA0, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL); @@ -1736,7 +1701,52 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip, UDELAY(map, chip, adr, 1); } - /* Did we succeed? */ + return ret; +} + +static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip, + unsigned long adr, map_word datum, + int mode) +{ + struct cfi_private *cfi = map->fldrv_priv; + int ret = 0; + map_word oldd; + int retry_cnt = 0; + + adr += chip->start; + + mutex_lock(&chip->mutex); + ret = get_chip(map, chip, adr, mode); + if (ret) { + mutex_unlock(&chip->mutex); + return ret; + } + + pr_debug("MTD %s(): WRITE 0x%.8lx(0x%.8lx)\n", + __func__, adr, datum.x[0]); + + if (mode == FL_OTP_WRITE) + otp_enter(map, chip, adr, map_bankwidth(map)); + + /* + * Check for a NOP for the case when the datum to write is already + * present - it saves time and works around buggy chips that corrupt + * data at other locations when 0xff is written to a location that + * already contains 0xff. + */ + oldd = map_read(map, adr); + if (map_word_equal(map, oldd, datum)) { + pr_debug("MTD %s(): NOP\n", + __func__); + goto op_done; + } + + XIP_INVAL_CACHED_RANGE(map, adr, map_bankwidth(map)); + ENABLE_VPP(map); + xip_disable(map, chip, adr); + + retry: + ret = do_write_oneword_once(map, chip, adr, datum, mode, cfi); if (ret) { /* reset on all failures. */ cfi_check_err_status(map, chip, adr);