From patchwork Tue Feb 5 14:07:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tokunori Ikegami X-Patchwork-Id: 1036770 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=none (p=none dis=none) header.from=yahoo.co.jp Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="DsLJ+bOJ"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=yahoo.co.jp header.i=@yahoo.co.jp header.b="IdNpvFhH"; 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 43v6012RJTz9s4V for ; Wed, 6 Feb 2019 01:09:37 +1100 (AEDT) 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=qio+lBKBI0UBo0xvoPnQfPLCOm0QUXO0ZifmyjEuHuw=; b=DsLJ+bOJ+y75eeT2xuioV2OUVV CowHAxfJ7Xc5xhNZAYEWnSuZzk635/xsItA/TPbo9DwgkG1p3DkiVZioiN51zLUuXp3ZItARIOK1n GfMQhFGwE9viZOxTk3wB/G+18Q6IfUkEBRezRJPJ/+ah4dYRR9j9kkam5S0Rb37EwcPX1sgoONtcz zlCBxE/UVlg6+v/MqZmseAX5bta2dkZPKxFHNx5a+xJSegYu3+wv9qA/60MnwDo9yuP4mvRMWKuXW q7bORz+WvGwp/ScmyKRyvT4nq4gz4u22gwC8QAprP3hGg28DEah+cU4d3h/Xsfv/l/DsVHhZ/6Eaw gakRKyTg==; 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 1gr1Pn-0007D2-8Y; Tue, 05 Feb 2019 14:09:31 +0000 Received: from nh503-vm4.bullet.mail.kks.yahoo.co.jp ([183.79.56.190]) by bombadil.infradead.org with smtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gr1PI-0006lV-Ix for linux-mtd@lists.infradead.org; Tue, 05 Feb 2019 14:09:04 +0000 Received: from [183.79.100.140] by nh503.bullet.mail.kks.yahoo.co.jp with NNFMP; 05 Feb 2019 14:08:57 -0000 Received: from [183.79.101.120] by t503.bullet.mail.kks.yahoo.co.jp with NNFMP; 05 Feb 2019 14:08:57 -0000 Received: from [127.0.0.1] by omp507.mail.kks.yahoo.co.jp with NNFMP; 05 Feb 2019 14:08:57 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 408139.19935.bm@omp507.mail.kks.yahoo.co.jp Received: (qmail 45703 invoked by alias); 5 Feb 2019 14:08:57 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.jp; s=yj20110701; t=1549375737; bh=HjpJs3bdlyLLTPHWvab8XDGrkndoAnTeJGTuXQEwJLg=; h=Received:X-YMail-JAS:X-Apparently-From:X-YMail-OSG:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References; b=IdNpvFhHaLu4HhdBtk6GW+Q3s8E7z5RFNJ015UhNTmbmtHiHyL6AwLWjYzGOaammzz8i+FcC5ti1ip+p4cdoJdTaSJKZNu3a+z48kJN61Ly9ezxU6qyT2Kje3Aqae7v2MnkwI6nGsF2ckiVZ+UoF8KSKp6JpRoRs5QMP5VSpcL8= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=yj20110701; d=yahoo.co.jp; h=Received:X-YMail-JAS:X-Apparently-From:X-YMail-OSG:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References; b=J/yS1J8FAXIhVqUTwtToGhqXOSfegOebCP3Wd+vo8yMVnvjJtwlJeyLc1t/Npwj3OY0rwzytV2dg5Zg5G+6ABpL9SoxliLJOReJXAeybw0yGrxl4Ff3fn/98Kf8fCGMBCBip3l8Lsr1C+7wQqfwnPvPY8q83RKM1qSMVImPQSIU= ; Received: from unknown (HELO localhost.localdomain) (106.72.39.32 with login) by smtp5006.mail.kks.ynwp.yahoo.co.jp with SMTP; 5 Feb 2019 14:08:56 -0000 X-YMail-JAS: l80whe8VM1l4m9r5qx5kCZeD5W0fSKcGfG.dhbJvYEoxx5M5TDjy4PTZzYuuQ36PQGa9pDAUgD.LPw3OBcFelInD37GOK_LPQHGGsIMLHCy2iFV5oyKqty4wbDLg3GtMcRmKSARMYw-- X-Apparently-From: X-YMail-OSG: ZUd8DUUVM1l7JkrgkxsnQMeNMRbG3o7Hamm66vboRqkdQgH 4l6yx1DeiXQBGeAKL6PfAIiR2DxKcCTt_UWnkGkQchZSWGDKiikIVk4YbUmy DZFuyHH_JBtZocKYAJ2Y5PfIVi8yHUDvgDgK8lW_sMcaAAsnvFPVN4AY5fMY NMgd.p9ePyV7Rc7jm.JjMv0P.AEDPvJD8ENxMhM2aHDpe6uiQuhfN.yqYr0Q By9__aTMH26QN_3Tm28nDAs2tsOeJ2JBCyFqeB4Ppp7KOV15e9jdrW_EVex0 IKPlfS7EeXFujBdBxlMcu0kWWxoqZSgpTK431GYvLQD1S04W0kIP008jlc.h UsH6CX65umFc54tsKvLYsfsTtJwsXq5YQBSWGbBoVknVIAmJROfFSZ2l5Gcx wvrSA.XAqmnbPcpmyFB5oOZ3BrE3Bt1qg9IxyRy7fuSN1BPU_xxfv9cPNKWZ h9ble1MJKk8KzQiDkxDNeonwcVOYnjm6Hazg8Jw5eIl9tmIClGrFeH61OELU i_Yxepdnh.IZxty8cck913HVt3zMMRPkRBQJ2SBDc2I7jQ_T6R0.LqhKaAxU dak6AO0zbAJiVOcCw1RcOemkrnizmBaY6ULe1fywZ5psDI.4- From: Tokunori Ikegami To: Boris Brezillon Subject: [PATCH v5 05/11] mtd: cfi_cmdset_0002: Split do_write_oneword() to reduce function size Date: Tue, 5 Feb 2019 23:07:53 +0900 Message-Id: <20190205140759.2360-6-ikegami_to@yahoo.co.jp> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190205140759.2360-1-ikegami_to@yahoo.co.jp> References: <20190205140759.2360-1-ikegami_to@yahoo.co.jp> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190205_060900_950027_19097E5C X-CRM114-Status: GOOD ( 16.21 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [183.79.56.190 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (ikegami_to[at]yahoo.co.jp) -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 -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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: Joakim Tjernlund , Tokunori Ikegami , linux-mtd@lists.infradead.org, Fabio Bettoni 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 Co: Koen Vandeputte Cc: Joakim Tjernlund Cc: linux-mtd@lists.infradead.org --- 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 | 89 ++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 40 deletions(-) diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c index 92d3e82..6393af4 100755 --- a/drivers/mtd/chips/cfi_cmdset_0002.c +++ b/drivers/mtd/chips/cfi_cmdset_0002.c @@ -1547,11 +1547,10 @@ 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 @@ -1564,42 +1563,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); @@ -1642,7 +1606,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. */ map_write(map, CMD(0xF0), chip->start);