From patchwork Mon Aug 12 20:08:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11090831 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 28E11112C for ; Mon, 12 Aug 2019 20:10:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A27F27F90 for ; Mon, 12 Aug 2019 20:10:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0EBA4283AD; Mon, 12 Aug 2019 20:10:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A84DE27F90 for ; Mon, 12 Aug 2019 20:10:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727297AbfHLUJV (ORCPT ); Mon, 12 Aug 2019 16:09:21 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:38511 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727163AbfHLUJV (ORCPT ); Mon, 12 Aug 2019 16:09:21 -0400 Received: by mail-pf1-f195.google.com with SMTP id o70so4902913pfg.5; Mon, 12 Aug 2019 13:09:20 -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 :mime-version:content-transfer-encoding; bh=TN+vbXoGtZXDyZZbwyRpwdE8T0Jxms0oeW+6+Yw5/RA=; b=X8o0fPWh9Bs/+AcOwAcBVoLh9JW4mMYIzkFTXSNwjaOoBCnq04hiL9ZO+9C7w6gH87 2bw00CDZGtx0+flu13GCj+Z5bpQ12MP4+YaTXGFVvR5IOSYcMlBDkOalCJTVCrtNa6hs XQ7Fjain/orZ/SxqhMS3cM8EySD/gmRT1jZ4DDZ09EGT7Q+en3PHbEne5C0L3+jUGiMg Sr9FgdrRLKKYZINxudYneHfvlgerJIcRFYX8/rQb0Gtoo4WUoO6F/hVXvHvua7q2Oaik gY/Rik4eCH5TPWm5FEg9+tVM3oCWF+WWTaWJxD8g4tofmSnziryJsISP87n9e5XVmFoo UHMQ== 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:mime-version:content-transfer-encoding; bh=TN+vbXoGtZXDyZZbwyRpwdE8T0Jxms0oeW+6+Yw5/RA=; b=rqGSP8YoA1GF5hiY+raALOzbF3FcyUniyedTkEbegbYrz90WWV4nfamlx8auaoLxUB pRl1uV/NSJcEFj5hz+apXWwsJsYgQmjrTQ+TvuC6raeqAK99fQBk5RIYqVLGoa/mmOaB vT4WoKmM3huLZIS61A8VoeCnJeWl5u8u3fikY6MPHeCx/HkBgY+RK9XlTBwypCtzNHxE /Dh743vcQOAFrtcwdmzRBUJcL4hCiznX1jXaBc2dYZdgC9EYqfFXkEY/d3b6tzifwCC0 QTH/K4s6g0QyTzvoF3bkYQ4JpgeqfaUXOGSOPvOk77E1fIJDSvl7NXZuwqZ0MAqGwIVV 8C0g== X-Gm-Message-State: APjAAAUf8QC7phusOKmL4LFyV/2NOQjX5ETlmPsLcdtILe0yyQwhk7ok h8cQ8m2dQVulqJ5+7BadS24R2Bvg X-Google-Smtp-Source: APXvYqzie7nch6IxxKkPdk2BZVQy+kChRyM+MLUh80vvOR4C7FaL03jEAWGlDEZmeFjSnU4ZFCdKyw== X-Received: by 2002:a62:63c7:: with SMTP id x190mr35856663pfb.181.1565640560251; Mon, 12 Aug 2019 13:09:20 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id n26sm110286451pfa.83.2019.08.12.13.09.18 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 12 Aug 2019 13:09:19 -0700 (PDT) From: Andrey Smirnov To: linux-watchdog@vger.kernel.org Cc: Andrey Smirnov , Guenter Roeck , Chris Healy , Rick Ramstetter , linux-kernel@vger.kernel.org Subject: [PATCH v2 01/22] watchdog: ziirave_wdt: Add missing newline Date: Mon, 12 Aug 2019 13:08:45 -0700 Message-Id: <20190812200906.31344-2-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190812200906.31344-1-andrew.smirnov@gmail.com> References: <20190812200906.31344-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add missing newline. Signed-off-by: Andrey Smirnov Reviewed-by: Guenter Roeck Cc: Chris Healy Cc: Guenter Roeck Cc: Rick Ramstetter Cc: linux-watchdog@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/watchdog/ziirave_wdt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/watchdog/ziirave_wdt.c b/drivers/watchdog/ziirave_wdt.c index dec660c509b3..6ec028fb2635 100644 --- a/drivers/watchdog/ziirave_wdt.c +++ b/drivers/watchdog/ziirave_wdt.c @@ -671,7 +671,7 @@ static int ziirave_wdt_probe(struct i2c_client *client, if (ret) return ret; - dev_info(&client->dev, "Timeout set to %ds.", + dev_info(&client->dev, "Timeout set to %ds\n", w_priv->wdd.timeout); } From patchwork Mon Aug 12 20:08:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11090829 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E46F5112C for ; Mon, 12 Aug 2019 20:10:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D663927F90 for ; Mon, 12 Aug 2019 20:10:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CAF75283AD; Mon, 12 Aug 2019 20:10:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 59C8128396 for ; Mon, 12 Aug 2019 20:10:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727664AbfHLUJX (ORCPT ); Mon, 12 Aug 2019 16:09:23 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:35010 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727657AbfHLUJW (ORCPT ); Mon, 12 Aug 2019 16:09:22 -0400 Received: by mail-pg1-f193.google.com with SMTP id n4so8302850pgv.2; Mon, 12 Aug 2019 13:09:22 -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 :mime-version:content-transfer-encoding; bh=DegDg2tvBAyXrJjc6gXX700jFAcfvGwUPaOS67cRtOc=; b=PXrJMfrzuS+VpWJ1SNAjz7a0dzCWasVv6vE2qk3HxkZIDuCI+f+v5gsHswxgmXeqwU 5dx9LOp3WK3Ap0y7cGrK6ds33EcDDCsUCp7iJXlGnVxsHRNBHVg/Jh+DWnDkySE741dr PMZCwrlmm/mZiw0g3cXrdQzaW32AdvjLD2Z+zjdbQTrK//tgip98z4fjY1IUqKsvXDEw nHxj7n9FzM65x6+f8dutqRbfft1YqJZO7I7gM4sSWfWrCaNgtA25+Ozn4UiiDFfZM6zS rlxhw2+DUbkhanqsZclkrnJNRyebEgQGGLFsMI8bXS+/gzALQcal5YX5xoKCWG3dvYB3 bqUg== 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:mime-version:content-transfer-encoding; bh=DegDg2tvBAyXrJjc6gXX700jFAcfvGwUPaOS67cRtOc=; b=guBeDO8vhwaXv3PfqgX3WUmZ9krDvdl0E5v4Q9OG7XByi7dbXq1obWmLVKuBnrJgCf 3YxbSAE4Thy/ga/gzvkfSCMsqQr4E9YenCk6McB6ZqevPhzNo3RKkY1J3SvoEfn17a2J FlIfQI53dUoBM2EfaWOwtFTv5WDIu7o6NosUgOT5gWPne4y0B7nkQ7U5snbXxLo6+5pO lYV1SU0CIEXkTSDLq8sDCUo8hpzCu/vjDS+XrK/34Vq5xV+P/xLWbQaylDQaPnNHARol EcM7tA9zwck/ckMjgFbYfYoIywlQVRF7YKjzq+jenLf3xc3BMg/5pgPD0Kzz0pU9GaDZ 6Q+Q== X-Gm-Message-State: APjAAAUuZ3OHQih2kWYZZaLizN57pvatjGm3fVzj+Rd+3F+hHULR/v7T fI72ZISJHYWtpA9vFQRfqAUMfqfk X-Google-Smtp-Source: APXvYqwu/2FETnuIiQWtNg4giB5vY0hRC4rBp7tpnJ5h5smm+tsnZVvPA+2y/KJDM7lBwR3TaNTkFQ== X-Received: by 2002:a17:90a:ad93:: with SMTP id s19mr955418pjq.36.1565640561479; Mon, 12 Aug 2019 13:09:21 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id n26sm110286451pfa.83.2019.08.12.13.09.20 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 12 Aug 2019 13:09:20 -0700 (PDT) From: Andrey Smirnov To: linux-watchdog@vger.kernel.org Cc: Andrey Smirnov , Guenter Roeck , Chris Healy , Rick Ramstetter , linux-kernel@vger.kernel.org Subject: [PATCH v2 02/22] watchdog: ziirave_wdt: Be verbose about errors in probe() Date: Mon, 12 Aug 2019 13:08:46 -0700 Message-Id: <20190812200906.31344-3-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190812200906.31344-1-andrew.smirnov@gmail.com> References: <20190812200906.31344-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The driver is quite silent in case of probe failure, which makes it more difficult to diagnose problem from the kernel log. Add logging to all of the silent error paths ziirave_wdt_probe() to improve that. Signed-off-by: Andrey Smirnov Reviewed-by: Guenter Roeck Cc: Chris Healy Cc: Guenter Roeck Cc: Rick Ramstetter Cc: linux-watchdog@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/watchdog/ziirave_wdt.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/drivers/watchdog/ziirave_wdt.c b/drivers/watchdog/ziirave_wdt.c index 6ec028fb2635..8c71341a9c1c 100644 --- a/drivers/watchdog/ziirave_wdt.c +++ b/drivers/watchdog/ziirave_wdt.c @@ -658,8 +658,10 @@ static int ziirave_wdt_probe(struct i2c_client *client, */ if (w_priv->wdd.timeout == 0) { val = i2c_smbus_read_byte_data(client, ZIIRAVE_WDT_TIMEOUT); - if (val < 0) + if (val < 0) { + dev_err(&client->dev, "Failed to read timeout\n"); return val; + } if (val < ZIIRAVE_TIMEOUT_MIN) return -ENODEV; @@ -668,8 +670,10 @@ static int ziirave_wdt_probe(struct i2c_client *client, } else { ret = ziirave_wdt_set_timeout(&w_priv->wdd, w_priv->wdd.timeout); - if (ret) + if (ret) { + dev_err(&client->dev, "Failed to set timeout\n"); return ret; + } dev_info(&client->dev, "Timeout set to %ds\n", w_priv->wdd.timeout); @@ -681,34 +685,46 @@ static int ziirave_wdt_probe(struct i2c_client *client, /* If in unconfigured state, set to stopped */ val = i2c_smbus_read_byte_data(client, ZIIRAVE_WDT_STATE); - if (val < 0) + if (val < 0) { + dev_err(&client->dev, "Failed to read state\n"); return val; + } if (val == ZIIRAVE_STATE_INITIAL) ziirave_wdt_stop(&w_priv->wdd); ret = ziirave_wdt_init_duration(client); - if (ret) + if (ret) { + dev_err(&client->dev, "Failed to init duration\n"); return ret; + } ret = ziirave_wdt_revision(client, &w_priv->firmware_rev, ZIIRAVE_WDT_FIRM_VER_MAJOR); - if (ret) + if (ret) { + dev_err(&client->dev, "Failed to read firmware version\n"); return ret; + } ret = ziirave_wdt_revision(client, &w_priv->bootloader_rev, ZIIRAVE_WDT_BOOT_VER_MAJOR); - if (ret) + if (ret) { + dev_err(&client->dev, "Failed to read bootloader version\n"); return ret; + } w_priv->reset_reason = i2c_smbus_read_byte_data(client, ZIIRAVE_WDT_RESET_REASON); - if (w_priv->reset_reason < 0) + if (w_priv->reset_reason < 0) { + dev_err(&client->dev, "Failed to read reset reason\n"); return w_priv->reset_reason; + } if (w_priv->reset_reason >= ARRAY_SIZE(ziirave_reasons) || - !ziirave_reasons[w_priv->reset_reason]) + !ziirave_reasons[w_priv->reset_reason]) { + dev_err(&client->dev, "Invalid reset reason\n"); return -ENODEV; + } ret = watchdog_register_device(&w_priv->wdd); From patchwork Mon Aug 12 20:08:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11090827 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A92911398 for ; Mon, 12 Aug 2019 20:10:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B3A227F90 for ; Mon, 12 Aug 2019 20:10:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8FA372845C; Mon, 12 Aug 2019 20:10:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A0CF27F90 for ; Mon, 12 Aug 2019 20:10:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727193AbfHLUKn (ORCPT ); Mon, 12 Aug 2019 16:10:43 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:36001 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727163AbfHLUJX (ORCPT ); Mon, 12 Aug 2019 16:09:23 -0400 Received: by mail-pg1-f194.google.com with SMTP id l21so50030450pgm.3; Mon, 12 Aug 2019 13:09:23 -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 :mime-version:content-transfer-encoding; bh=v5LhoIh9pEXsuxuOal6SQWOEU6dIDuk09/Lr+q8se7U=; b=m3tzM5Rjigj1YHXtE5lXE4sKYSMSgS8iLNxSaKt7AGhxG0BxGDK9ZOSakPs7RxdgMO 2VH4MAV64sIbrqBsqspOusRH6kVALTy75Yo2u1xDsLjCvxKdYJCLKZFCeZOjFOvGwkwJ aUyuf7uJqp20+fNgsUNWg4IZYKbdh+8Y5fxBhnb4natmsQhYmAe+APl3sGE19HXNzbmy nXLICEQ8th490qXxDShMh4F4XAEfhTXnLe34ehmO91GvN8vHFCnN9RvEuq1P6lEecPQH 7gTDYkgjXErCBYkF9W3Bas26Zp2qK7jJ0xLUnabG54+wufiWMTykWnGsT1AYrzCRHUPE aUWA== 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:mime-version:content-transfer-encoding; bh=v5LhoIh9pEXsuxuOal6SQWOEU6dIDuk09/Lr+q8se7U=; b=rKQM76pvNtEw6Ux+hAXzLi350m5zxsQcwuix2AgeotMYIiwUlxK80ylQ79GBX0ox/n D5xBD9O2ReZJxjl8AUNAGn1vBJO6AubKVIYCP3kLFb6EQ6BeUu+tCn4XXLg3zI/DAqUy PDbt2DWCuq3qqpRV8rpPOP+U0Ko1Jc9IdYFFXRTet3HuhGQZx0rr2XgQy43zrgFwv7vg RCujOUxC0qLfd59NAKah4J2pJfMy1UY+FHpTHhPqkKoFN9U2lCKqONw6mHg311eQGZuH UpeXE3TVwpNquYcFbXLBWhj7XhU6bRJzBIkHKMVRAmSVg7LbzwHnuO79cGzlsf6GBsYp hvlg== X-Gm-Message-State: APjAAAV8IACRtJ4VpyWVPIuplguZIMXsaF/81/576iLpRxFniMPQ2+6x MMYz/LykqXwUeSxxD8GYfaENNc3M X-Google-Smtp-Source: APXvYqxiNEuuYTdNk/z8R1E7J8+LLjiEFuarmkwBZF4IeYgn7FceZwWLd3s8ejncGYTYmTQmohIUDw== X-Received: by 2002:a62:1c93:: with SMTP id c141mr38374483pfc.9.1565640562519; Mon, 12 Aug 2019 13:09:22 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id n26sm110286451pfa.83.2019.08.12.13.09.21 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 12 Aug 2019 13:09:21 -0700 (PDT) From: Andrey Smirnov To: linux-watchdog@vger.kernel.org Cc: Andrey Smirnov , Guenter Roeck , Chris Healy , Rick Ramstetter , linux-kernel@vger.kernel.org Subject: [PATCH v2 03/22] watchdog: ziirave_wdt: Be more verbose during firmware update Date: Mon, 12 Aug 2019 13:08:47 -0700 Message-Id: <20190812200906.31344-4-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190812200906.31344-1-andrew.smirnov@gmail.com> References: <20190812200906.31344-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add more error logging to ziirave_firm_upload() for diagnostics. Signed-off-by: Andrey Smirnov Reviewed-by: Guenter Roeck Cc: Chris Healy Cc: Guenter Roeck Cc: Rick Ramstetter Cc: linux-watchdog@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/watchdog/ziirave_wdt.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/watchdog/ziirave_wdt.c b/drivers/watchdog/ziirave_wdt.c index 8c71341a9c1c..b3e255b40209 100644 --- a/drivers/watchdog/ziirave_wdt.c +++ b/drivers/watchdog/ziirave_wdt.c @@ -335,14 +335,18 @@ static int ziirave_firm_upload(struct watchdog_device *wdd, ret = ziirave_firm_write_byte(wdd, ZIIRAVE_CMD_JUMP_TO_BOOTLOADER, 1, false); - if (ret) + if (ret) { + dev_err(&client->dev, "Failed to jump to bootloader\n"); return ret; + } msleep(500); ret = ziirave_firm_write_byte(wdd, ZIIRAVE_CMD_DOWNLOAD_START, 1, true); - if (ret) + if (ret) { + dev_err(&client->dev, "Failed to start download\n"); return ret; + } msleep(500); @@ -438,14 +442,20 @@ static int ziirave_firm_upload(struct watchdog_device *wdd, /* End download operation */ ret = ziirave_firm_write_byte(wdd, ZIIRAVE_CMD_DOWNLOAD_END, 1, false); - if (ret) + if (ret) { + dev_err(&client->dev, + "Failed to end firmware download: %d\n", ret); return ret; + } /* Reset the processor */ ret = ziirave_firm_write_byte(wdd, ZIIRAVE_CMD_RESET_PROCESSOR, 1, false); - if (ret) + if (ret) { + dev_err(&client->dev, + "Failed to reset the watchdog: %d\n", ret); return ret; + } msleep(500); From patchwork Mon Aug 12 20:08:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11090789 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5F8461398 for ; Mon, 12 Aug 2019 20:09:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4EF9128569 for ; Mon, 12 Aug 2019 20:09:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 430CF2857B; Mon, 12 Aug 2019 20:09:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DEE8628569 for ; Mon, 12 Aug 2019 20:09:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727474AbfHLUJ0 (ORCPT ); Mon, 12 Aug 2019 16:09:26 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:43937 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727669AbfHLUJY (ORCPT ); Mon, 12 Aug 2019 16:09:24 -0400 Received: by mail-pl1-f193.google.com with SMTP id 4so41296708pld.10; Mon, 12 Aug 2019 13:09:24 -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 :mime-version:content-transfer-encoding; bh=FAkiHbs5735QnUwhI1DDee38S7XbX5mLL8p2xUkayFw=; b=SZpvUHcveQfGkXaOtrVybbHvnWzzlVW4o160Sr6vOMxVeMFvUXR6JAroTAfrrSBgiH k6bNrqEBT4Mc80xV+/nvoHDyWzt3pS1hbTJ+qv6nciV3ivhxYFUAtTwetCMeT6jMS7sc HS7su40a5Yjbs40OtSoiyVLvaWLssfM/dTDw7chLhopknhyHq7PGojGtaVy/u81nQUtg I/ZLwE21VU5keCgbXeZyJhDjyDTKggi9itx2W+W0P0A82mr/ryNWwE/d5jYuKo0cy45b YHZCi05qWvHgJf8FSYwbqGRaEkuywlMwGCdaiWZ03jLXFPQDtZFe3AuXKfZNPiXsqbuP TpAA== 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:mime-version:content-transfer-encoding; bh=FAkiHbs5735QnUwhI1DDee38S7XbX5mLL8p2xUkayFw=; b=tBwEQgBtL1kiAtvkSLJpzroCdG/GUq3Ss/Cd2dzfNXYlVV55gMUWPMVQU+znNVCfyd 9QNQCDyW23pw9B207YYyGAYkHUsbfdtdk+zf5ya8+gPaBXQKbsvHTT34MmPnVs3G5Vp4 yskFudiHr8NWeEeqj7Z0tBm5QZlCF/EHXmR8L8AwSQrozQFg8Nu6dofRn5du/nMAyp2+ iTgYZSGDgv1HBZByr1hJ3AQYWRI0IqR5D333fgXlfHnjaGhZ5CEMbo5a3LimE1S8XKpC zr/qfTqvDAM08Q9YU7611dFffQ98ovXzGELPmLb1cc/LcfGn2zphUveVmokmGca97x0g 8w6A== X-Gm-Message-State: APjAAAXutylM1xFUSjX3OUanMZylzakSve7qUTGYOPLEKHMGaWpBNKi+ in68ry1Cg5/PzqwOsRobZ1kD9EmF X-Google-Smtp-Source: APXvYqxq7rPFBorjef8bA9idco6czMcatBnBbTid+/C+psuskRBrCxEhNfhAQe1CeynF3R5sLRD/zQ== X-Received: by 2002:a17:902:2987:: with SMTP id h7mr34109726plb.37.1565640563524; Mon, 12 Aug 2019 13:09:23 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id n26sm110286451pfa.83.2019.08.12.13.09.22 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 12 Aug 2019 13:09:22 -0700 (PDT) From: Andrey Smirnov To: linux-watchdog@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Guenter Roeck , Rick Ramstetter , linux-kernel@vger.kernel.org Subject: [PATCH v2 04/22] watchdog: ziirave_wdt: Don't bail out on unexpected timeout value Date: Mon, 12 Aug 2019 13:08:48 -0700 Message-Id: <20190812200906.31344-5-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190812200906.31344-1-andrew.smirnov@gmail.com> References: <20190812200906.31344-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Reprogramming bootloader on watchdog MCU will result in reported default timeout value of "0". That in turn will be unnecessarily rejected by the driver as invalid device (-ENODEV). Simplify probe to read stored timeout value, set it to a sane default if it is bogus, and then program that value unconditionally. Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Guenter Roeck Cc: Rick Ramstetter Cc: linux-watchdog@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Guenter Roeck --- drivers/watchdog/ziirave_wdt.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/watchdog/ziirave_wdt.c b/drivers/watchdog/ziirave_wdt.c index b3e255b40209..a11b92383c5f 100644 --- a/drivers/watchdog/ziirave_wdt.c +++ b/drivers/watchdog/ziirave_wdt.c @@ -23,6 +23,7 @@ #define ZIIRAVE_TIMEOUT_MIN 3 #define ZIIRAVE_TIMEOUT_MAX 255 +#define ZIIRAVE_TIMEOUT_DEFAULT 30 #define ZIIRAVE_PING_VALUE 0x0 @@ -673,22 +674,21 @@ static int ziirave_wdt_probe(struct i2c_client *client, return val; } - if (val < ZIIRAVE_TIMEOUT_MIN) - return -ENODEV; + if (val > ZIIRAVE_TIMEOUT_MAX || + val < ZIIRAVE_TIMEOUT_MIN) + val = ZIIRAVE_TIMEOUT_DEFAULT; w_priv->wdd.timeout = val; - } else { - ret = ziirave_wdt_set_timeout(&w_priv->wdd, - w_priv->wdd.timeout); - if (ret) { - dev_err(&client->dev, "Failed to set timeout\n"); - return ret; - } + } - dev_info(&client->dev, "Timeout set to %ds\n", - w_priv->wdd.timeout); + ret = ziirave_wdt_set_timeout(&w_priv->wdd, w_priv->wdd.timeout); + if (ret) { + dev_err(&client->dev, "Failed to set timeout\n"); + return ret; } + dev_info(&client->dev, "Timeout set to %ds\n", w_priv->wdd.timeout); + watchdog_set_nowayout(&w_priv->wdd, nowayout); i2c_set_clientdata(client, w_priv); From patchwork Mon Aug 12 20:08:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11090825 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9E88A1398 for ; Mon, 12 Aug 2019 20:10:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8FDA527F90 for ; Mon, 12 Aug 2019 20:10:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 84145283AD; Mon, 12 Aug 2019 20:10:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 205AB27F90 for ; Mon, 12 Aug 2019 20:10:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727681AbfHLUJ0 (ORCPT ); Mon, 12 Aug 2019 16:09:26 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:46080 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727657AbfHLUJZ (ORCPT ); Mon, 12 Aug 2019 16:09:25 -0400 Received: by mail-pg1-f196.google.com with SMTP id w3so12829618pgt.13; Mon, 12 Aug 2019 13:09:25 -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 :mime-version:content-transfer-encoding; bh=jEZoU65CYKkhJ//nkcnVx5x5ywWiKoHTZZ29p5BWWTg=; b=iNVVNqeRFZBPxHGfQlmxfKGEZibrqHSwoQpnwvOErULZ9JhSdd09pQwUB+dpH3Klpa N4j7PExnKorc+tIyPlrrSq4VqAQSbTF/qd1AcnYDHT1H2iOer6Y/McYVdlRVe+/d7921 4GxxFakT3aH8glDMYIL6oqFoRumBHvyd+nYked6TcFZ9M5Bn3BXXburXDHE26HEQIPbc dpTc5MFWlONZQxrYihgZsM7d5GWFiyQ2C/2QbpVTYxuzaAzGWfz6qybE6bfJ8Ub7Bm4m MMPUBmeiZxTCM8VDvd6yQeEUI8kYm2pmTzD/AB9nNlcAutsK82hjKRGLcNNxwvhyLe60 rFeA== 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:mime-version:content-transfer-encoding; bh=jEZoU65CYKkhJ//nkcnVx5x5ywWiKoHTZZ29p5BWWTg=; b=gYe3hojme//FaUtb0y721Y9Y2zjV9IaET7NvYsH8FXnbcDp1w6D6Snaeb2fTWxe9vT S2iF/jTt0l7rCGJkS7wVDzjIXxRVPurO1l1wVCRmjElXAYuVz5uTDKXxESaSRt8Xk4K0 U7ACwXZhf3UtcK66CSaVV5zVbagxq16ju0n0JmTRGgSlB7bTipP5jJfxsJd5eQR/X7KK msFyZHIRp5YLFgvmS1EFeuuZb0q91MQLs6EPtxW+/93oYjQ7m95fG3mAldVIMUXiigtZ Y0CPvUHJ1kGsvJUkJk04o2dYEe6JTt7VOGSnatPZosdZIX5hkAbjYCmLksv0Z+ip/JbD q5nQ== X-Gm-Message-State: APjAAAWYVtu93vG7JBq/1Fzumuoq+t9PoRoDsnjhop21eL7zQa6ATBEu YSE8SGI3dYgfEu4cQxv8YcQHJ6Dl X-Google-Smtp-Source: APXvYqwZdZi1eqYARjIfbuKgRo4ipWyXBrI2oG+fTR9Z3SWJvIAFXrRt6Cg3uvvDLf6blZKBvCclTA== X-Received: by 2002:a62:1808:: with SMTP id 8mr11125738pfy.177.1565640564884; Mon, 12 Aug 2019 13:09:24 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id n26sm110286451pfa.83.2019.08.12.13.09.23 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 12 Aug 2019 13:09:24 -0700 (PDT) From: Andrey Smirnov To: linux-watchdog@vger.kernel.org Cc: Andrey Smirnov , Guenter Roeck , Chris Healy , Rick Ramstetter , linux-kernel@vger.kernel.org Subject: [PATCH v2 05/22] watchdog: ziirave_wdt: Log bootloader/firmware info during probe Date: Mon, 12 Aug 2019 13:08:49 -0700 Message-Id: <20190812200906.31344-6-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190812200906.31344-1-andrew.smirnov@gmail.com> References: <20190812200906.31344-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Log bootloader/firmware info during probe. This information is available via sysfs already, but it's really helpful to have this in kernel log during startup as well. Signed-off-by: Andrey Smirnov Reviewed-by: Guenter Roeck Cc: Chris Healy Cc: Guenter Roeck Cc: Rick Ramstetter Cc: linux-watchdog@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/watchdog/ziirave_wdt.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/watchdog/ziirave_wdt.c b/drivers/watchdog/ziirave_wdt.c index a11b92383c5f..75c066602c00 100644 --- a/drivers/watchdog/ziirave_wdt.c +++ b/drivers/watchdog/ziirave_wdt.c @@ -69,6 +69,9 @@ static char *ziirave_reasons[] = {"power cycle", "hw watchdog", NULL, NULL, #define ZIIRAVE_CMD_JUMP_TO_BOOTLOADER 0x0c #define ZIIRAVE_CMD_DOWNLOAD_PACKET 0x0e +#define ZIIRAVE_FW_VERSION_FMT "02.%02u.%02u" +#define ZIIRAVE_BL_VERSION_FMT "01.%02u.%02u" + struct ziirave_wdt_rev { unsigned char major; unsigned char minor; @@ -489,7 +492,7 @@ static ssize_t ziirave_wdt_sysfs_show_firm(struct device *dev, if (ret) return ret; - ret = sprintf(buf, "02.%02u.%02u", w_priv->firmware_rev.major, + ret = sprintf(buf, ZIIRAVE_FW_VERSION_FMT, w_priv->firmware_rev.major, w_priv->firmware_rev.minor); mutex_unlock(&w_priv->sysfs_mutex); @@ -512,7 +515,7 @@ static ssize_t ziirave_wdt_sysfs_show_boot(struct device *dev, if (ret) return ret; - ret = sprintf(buf, "01.%02u.%02u", w_priv->bootloader_rev.major, + ret = sprintf(buf, ZIIRAVE_BL_VERSION_FMT, w_priv->bootloader_rev.major, w_priv->bootloader_rev.minor); mutex_unlock(&w_priv->sysfs_mutex); @@ -579,7 +582,8 @@ static ssize_t ziirave_wdt_sysfs_store_firm(struct device *dev, goto unlock_mutex; } - dev_info(&client->dev, "Firmware updated to version 02.%02u.%02u\n", + dev_info(&client->dev, + "Firmware updated to version " ZIIRAVE_FW_VERSION_FMT "\n", w_priv->firmware_rev.major, w_priv->firmware_rev.minor); /* Restore the watchdog timeout */ @@ -716,6 +720,10 @@ static int ziirave_wdt_probe(struct i2c_client *client, return ret; } + dev_info(&client->dev, + "Firmware version: " ZIIRAVE_FW_VERSION_FMT "\n", + w_priv->firmware_rev.major, w_priv->firmware_rev.minor); + ret = ziirave_wdt_revision(client, &w_priv->bootloader_rev, ZIIRAVE_WDT_BOOT_VER_MAJOR); if (ret) { @@ -723,6 +731,10 @@ static int ziirave_wdt_probe(struct i2c_client *client, return ret; } + dev_info(&client->dev, + "Bootloader version: " ZIIRAVE_BL_VERSION_FMT "\n", + w_priv->bootloader_rev.major, w_priv->bootloader_rev.minor); + w_priv->reset_reason = i2c_smbus_read_byte_data(client, ZIIRAVE_WDT_RESET_REASON); if (w_priv->reset_reason < 0) { From patchwork Mon Aug 12 20:08:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11090823 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6F96A112C for ; Mon, 12 Aug 2019 20:10:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 603B727F90 for ; Mon, 12 Aug 2019 20:10:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 52D28283AD; Mon, 12 Aug 2019 20:10:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B0ECE27F90 for ; Mon, 12 Aug 2019 20:10:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727595AbfHLUKi (ORCPT ); Mon, 12 Aug 2019 16:10:38 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:43230 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727685AbfHLUJ1 (ORCPT ); Mon, 12 Aug 2019 16:09:27 -0400 Received: by mail-pg1-f195.google.com with SMTP id r26so14085447pgl.10; Mon, 12 Aug 2019 13:09:26 -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 :mime-version:content-transfer-encoding; bh=s01id/bOKqHbSZOwJqDeTGRrZOkCw7N0lkNR7ywaBCU=; b=bOm1smK3FIK/qm4nWXJQ3M+ZQ99uM0jxgqV7Q2SaY2u+bSx4syNKCD4U2Sdqy+60Je Uf16hlgCEouo117pVAp9X0Nm6ch9AEhIQzp+7+wtrKZ4wCcyNBBH5MhiHDkjZJ0czzgl kPRwVKAQrQmvvdlU7mpbA2WxNrWa+AUoWOwP7oFPvhclWkqBnd1nHnClzb6mwneOr6Se klg3yfVEFHbIZQKEsf0sum28+PBBfttsunme1LlOLTcAsnoYBPeKhwQ9RYuaMk70vyxv BttDGCROP1bTllyYwtaMNeRBAbmKxSsakIDPkzDJ3ldui/BPzdFytOiytUA9acuXC8b1 crXg== 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:mime-version:content-transfer-encoding; bh=s01id/bOKqHbSZOwJqDeTGRrZOkCw7N0lkNR7ywaBCU=; b=a8tjBH1HvBeIWFbb3VY3lVGZUe5AZrcHesMbACtruVPnMMVcqJyhyRktRgmEeJuMGg veSLJKxD/dVZWZI7jG5jPpkfzZDQE7E2unbSFYbNlRROtVYGaJRkRl3G1qgME/QywTUu UUtzCvfhJVmLCRLtHHGIrZ0UMHuWmIAcg+MwMl3OLcZ98rwHv86Ov/t5IwFm9PBu0R0T mXsdFtAvmlE04TOmOazuxuBLLHyosLsyQQYfUTFFrYJLzD+THTb7BNLrrsyS3InZTTBk 75f/sehhoAxh8Vt+8pVcDFffLlsL9RexIY6fIZ01FlejFtwnnZhbTeyZYBl64FyxcoJ1 XRBg== X-Gm-Message-State: APjAAAWzBKE1/Eyi7tjj4V0iR0aR2gwPzttrmEdzspakvFnnBHdPeixj jUf8fh6eIDLwIJAJ5oxvlBacoUFB X-Google-Smtp-Source: APXvYqwnOkLd8FQChENX81H6oxLjr0wNdj8grTifdhEXAM7laAo9vmVoeIvqe8bTpgjNhZO8F/MZfQ== X-Received: by 2002:a62:640c:: with SMTP id y12mr36702608pfb.166.1565640566249; Mon, 12 Aug 2019 13:09:26 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id n26sm110286451pfa.83.2019.08.12.13.09.25 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 12 Aug 2019 13:09:25 -0700 (PDT) From: Andrey Smirnov To: linux-watchdog@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Guenter Roeck , Rick Ramstetter , linux-kernel@vger.kernel.org Subject: [PATCH v2 06/22] watchdog: ziirave_wdt: Simplify ziirave_firm_write_pkt() Date: Mon, 12 Aug 2019 13:08:50 -0700 Message-Id: <20190812200906.31344-7-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190812200906.31344-1-andrew.smirnov@gmail.com> References: <20190812200906.31344-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There no reason why ziirave_firm_write_pkt() has to take firmware data via 'struct ihex_binrec' and it can just take address, data pointer and data length as individual arguments. Make this change to allow us to drastically simplify handling page crossing case by removing all of the extra code required to split 'struct ihex_binrec' into two. Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Guenter Roeck Cc: Rick Ramstetter Cc: linux-watchdog@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Guenter Roeck --- drivers/watchdog/ziirave_wdt.c | 116 +++++++++++++-------------------- 1 file changed, 44 insertions(+), 72 deletions(-) diff --git a/drivers/watchdog/ziirave_wdt.c b/drivers/watchdog/ziirave_wdt.c index 75c066602c00..b2d5ff0c22fe 100644 --- a/drivers/watchdog/ziirave_wdt.c +++ b/drivers/watchdog/ziirave_wdt.c @@ -51,6 +51,7 @@ static char *ziirave_reasons[] = {"power cycle", "hw watchdog", NULL, NULL, #define ZIIRAVE_FIRM_PKT_DATA_SIZE 16 #define ZIIRAVE_FIRM_FLASH_MEMORY_START 0x1600 #define ZIIRAVE_FIRM_FLASH_MEMORY_END 0x2bbf +#define ZIIRAVE_FIRM_PAGE_SIZE 128 /* Received and ready for next Download packet. */ #define ZIIRAVE_FIRM_DOWNLOAD_ACK 1 @@ -244,27 +245,26 @@ static int ziirave_firm_write_byte(struct watchdog_device *wdd, u8 command, * Data0 .. Data15: Array of 16 bytes of data. * Checksum: Checksum byte to verify data integrity. */ -static int ziirave_firm_write_pkt(struct watchdog_device *wdd, - const struct ihex_binrec *rec) +static int __ziirave_firm_write_pkt(struct watchdog_device *wdd, + u32 addr, const u8 *data, u8 len) { + const u16 addr16 = (u16)addr / 2; struct i2c_client *client = to_i2c_client(wdd->parent); u8 i, checksum = 0, packet[ZIIRAVE_FIRM_PKT_TOTAL_SIZE]; int ret; - u16 addr; memset(packet, 0, ARRAY_SIZE(packet)); /* Packet length */ - packet[0] = (u8)be16_to_cpu(rec->len); + packet[0] = len; /* Packet address */ - addr = (be32_to_cpu(rec->addr) & 0xffff) >> 1; - packet[1] = addr & 0xff; - packet[2] = (addr & 0xff00) >> 8; + packet[1] = addr16 & 0xff; + packet[2] = (addr16 & 0xff00) >> 8; /* Packet data */ - if (be16_to_cpu(rec->len) > ZIIRAVE_FIRM_PKT_DATA_SIZE) + if (len > ZIIRAVE_FIRM_PKT_DATA_SIZE) return -EMSGSIZE; - memcpy(packet + 3, rec->data, be16_to_cpu(rec->len)); + memcpy(packet + 3, data, len); /* Packet checksum */ for (i = 0; i < ZIIRAVE_FIRM_PKT_TOTAL_SIZE - 1; i++) @@ -276,11 +276,35 @@ static int ziirave_firm_write_pkt(struct watchdog_device *wdd, if (ret) dev_err(&client->dev, "Failed to write firmware packet at address 0x%04x: %d\n", - addr, ret); + addr16, ret); return ret; } +static int ziirave_firm_write_pkt(struct watchdog_device *wdd, + u32 addr, const u8 *data, u8 len) +{ + const u8 max_write_len = ZIIRAVE_FIRM_PAGE_SIZE - + (addr - ALIGN_DOWN(addr, ZIIRAVE_FIRM_PAGE_SIZE)); + int ret; + + if (len > max_write_len) { + /* + * If data crossed page boundary we need to split this + * write in two + */ + ret = __ziirave_firm_write_pkt(wdd, addr, data, max_write_len); + if (ret) + return ret; + + addr += max_write_len; + data += max_write_len; + len -= max_write_len; + } + + return __ziirave_firm_write_pkt(wdd, addr, data, len); +} + static int ziirave_firm_verify(struct watchdog_device *wdd, const struct firmware *fw) { @@ -333,9 +357,8 @@ static int ziirave_firm_upload(struct watchdog_device *wdd, const struct firmware *fw) { struct i2c_client *client = to_i2c_client(wdd->parent); - int ret, words_till_page_break; const struct ihex_binrec *rec; - struct ihex_binrec *rec_new; + int ret; ret = ziirave_firm_write_byte(wdd, ZIIRAVE_CMD_JUMP_TO_BOOTLOADER, 1, false); @@ -366,68 +389,17 @@ static int ziirave_firm_upload(struct watchdog_device *wdd, return -EMSGSIZE; } - /* Calculate words till page break */ - words_till_page_break = (64 - ((be32_to_cpu(rec->addr) >> 1) & - 0x3f)); - if ((be16_to_cpu(rec->len) >> 1) > words_till_page_break) { - /* - * Data in passes page boundary, so we need to split in - * two blocks of data. Create a packet with the first - * block of data. - */ - rec_new = kzalloc(sizeof(struct ihex_binrec) + - (words_till_page_break << 1), - GFP_KERNEL); - if (!rec_new) - return -ENOMEM; - - rec_new->len = cpu_to_be16(words_till_page_break << 1); - rec_new->addr = rec->addr; - memcpy(rec_new->data, rec->data, - be16_to_cpu(rec_new->len)); - - ret = ziirave_firm_write_pkt(wdd, rec_new); - kfree(rec_new); - if (ret) - return ret; - - /* Create a packet with the second block of data */ - rec_new = kzalloc(sizeof(struct ihex_binrec) + - be16_to_cpu(rec->len) - - (words_till_page_break << 1), - GFP_KERNEL); - if (!rec_new) - return -ENOMEM; - - /* Remaining bytes */ - rec_new->len = rec->len - - cpu_to_be16(words_till_page_break << 1); - - rec_new->addr = cpu_to_be32(be32_to_cpu(rec->addr) + - (words_till_page_break << 1)); - - memcpy(rec_new->data, - rec->data + (words_till_page_break << 1), - be16_to_cpu(rec_new->len)); - - ret = ziirave_firm_write_pkt(wdd, rec_new); - kfree(rec_new); - if (ret) - return ret; - } else { - ret = ziirave_firm_write_pkt(wdd, rec); - if (ret) - return ret; - } + ret = ziirave_firm_write_pkt(wdd, be32_to_cpu(rec->addr), + rec->data, be16_to_cpu(rec->len)); + if (ret) + return ret; } - /* For end of download, the length field will be set to 0 */ - rec_new = kzalloc(sizeof(struct ihex_binrec) + 1, GFP_KERNEL); - if (!rec_new) - return -ENOMEM; - - ret = ziirave_firm_write_pkt(wdd, rec_new); - kfree(rec_new); + /* + * Finish firmware download process by sending a zero length + * payload + */ + ret = ziirave_firm_write_pkt(wdd, 0, NULL, 0); if (ret) { dev_err(&client->dev, "Failed to send EMPTY packet: %d\n", ret); return ret; From patchwork Mon Aug 12 20:08:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11090821 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C288F1398 for ; Mon, 12 Aug 2019 20:10:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A553F27F90 for ; Mon, 12 Aug 2019 20:10:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9566E2856F; Mon, 12 Aug 2019 20:10:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7FC2B28569 for ; Mon, 12 Aug 2019 20:10:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727527AbfHLUKc (ORCPT ); Mon, 12 Aug 2019 16:10:32 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:46083 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727697AbfHLUJ2 (ORCPT ); Mon, 12 Aug 2019 16:09:28 -0400 Received: by mail-pg1-f193.google.com with SMTP id w3so12829668pgt.13; Mon, 12 Aug 2019 13:09:28 -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 :mime-version:content-transfer-encoding; bh=deC9bypm2a5woLMxu2BTX+DDzR5ih5b4fjPEyHG/r60=; b=rJ/4+68w9pWobiIUxhoShphAASwz6SsDyf/ZBZL4nHBmV4qE/qy+mqchknTmclQM7H VcOi2knmywYxtXMBkMPHF8CVbzlmkt/mR4nRthMXKsF5uWy588doaGGyL6iJO7olYvLt qKuwIc2wfdhUil3A9AdkbOYZ1TRiOuWypNoLsRSnKhQbVozN4hOCAsDmf/mtIbQc0VQL idxsP2InQSsjkEOuJhvYD3nJkwk/VFhMEjGOD1xprxNAdjFmY4f9mFmsKsZgXXzbjjfe /VYqcm6UwBDovx9NfhnNVe+u8luNP3Esrkjdy+iYaYGbws4yD1qwF8B5RAOoychYE1mh FIiw== 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:mime-version:content-transfer-encoding; bh=deC9bypm2a5woLMxu2BTX+DDzR5ih5b4fjPEyHG/r60=; b=cVDQ+EqaqPs+Bi2tuh0oErScElRBScdugvAthjvGceiV/PEISDCCt1gCa4on6Hp/N6 PFDyMnqPd+/F82FmrnmlX7JUEsExv47KFoucIGIcQr7RPq1GJtsUY2dL/rDJKkgRgcL7 Ce7EBfnqpFLr+2Y2FG1SlWq0gi/YZ0t/Ut7WgVK2jWurWyvd1rH1nTjtqUbKtN4wEPnS YDEbo2+x+uO8j3gVa3coNP816mHsgh3HpQtWuJElOafL5tOPuckhfkKQe4nWhAZZPy8J DAwBo87ERCfYuEnkOwOSb3DqxGiFKMThIWDn2yWag6e2I/ta8oIkKuPD4nriDOI2lKbB lBiQ== X-Gm-Message-State: APjAAAXgMZdsMfRfKaOTf7jmwQqsgwKiLnhLPGgEBWziXrgYkdoG06Ir Yi2A9nKSL8+ximetIjq59rPhlzJI X-Google-Smtp-Source: APXvYqzn5NmBzOWdjj+4sNQujP4hwHHL2qOiWfWaHXT7reQ8xRApvxZ0Fe+CCbKr5TknKgukuzdG7Q== X-Received: by 2002:a62:b615:: with SMTP id j21mr36345631pff.190.1565640567545; Mon, 12 Aug 2019 13:09:27 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id n26sm110286451pfa.83.2019.08.12.13.09.26 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 12 Aug 2019 13:09:26 -0700 (PDT) From: Andrey Smirnov To: linux-watchdog@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Guenter Roeck , Rick Ramstetter , linux-kernel@vger.kernel.org Subject: [PATCH v2 07/22] watchdog: ziirave_wdt: Check packet length only once Date: Mon, 12 Aug 2019 13:08:51 -0700 Message-Id: <20190812200906.31344-8-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190812200906.31344-1-andrew.smirnov@gmail.com> References: <20190812200906.31344-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We don't need to check for packet length more than once, so drop the extra check in ziirave_firm_upload(). While at it move the check at the very start of __ziirave_firm_write_pkt(), as to not waste any time preparing a packet we'll never use. Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Guenter Roeck Cc: Rick Ramstetter Cc: linux-watchdog@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Guenter Roeck --- drivers/watchdog/ziirave_wdt.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/drivers/watchdog/ziirave_wdt.c b/drivers/watchdog/ziirave_wdt.c index b2d5ff0c22fe..9d9c669b8b47 100644 --- a/drivers/watchdog/ziirave_wdt.c +++ b/drivers/watchdog/ziirave_wdt.c @@ -253,6 +253,13 @@ static int __ziirave_firm_write_pkt(struct watchdog_device *wdd, u8 i, checksum = 0, packet[ZIIRAVE_FIRM_PKT_TOTAL_SIZE]; int ret; + /* Check max data size */ + if (len > ZIIRAVE_FIRM_PKT_DATA_SIZE) { + dev_err(&client->dev, "Firmware packet too long (%d)\n", + len); + return -EMSGSIZE; + } + memset(packet, 0, ARRAY_SIZE(packet)); /* Packet length */ @@ -261,9 +268,6 @@ static int __ziirave_firm_write_pkt(struct watchdog_device *wdd, packet[1] = addr16 & 0xff; packet[2] = (addr16 & 0xff00) >> 8; - /* Packet data */ - if (len > ZIIRAVE_FIRM_PKT_DATA_SIZE) - return -EMSGSIZE; memcpy(packet + 3, data, len); /* Packet checksum */ @@ -382,13 +386,6 @@ static int ziirave_firm_upload(struct watchdog_device *wdd, if (!be16_to_cpu(rec->len)) break; - /* Check max data size */ - if (be16_to_cpu(rec->len) > ZIIRAVE_FIRM_PKT_DATA_SIZE) { - dev_err(&client->dev, "Firmware packet too long (%d)\n", - be16_to_cpu(rec->len)); - return -EMSGSIZE; - } - ret = ziirave_firm_write_pkt(wdd, be32_to_cpu(rec->addr), rec->data, be16_to_cpu(rec->len)); if (ret) From patchwork Mon Aug 12 20:08:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11090791 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 299C8112C for ; Mon, 12 Aug 2019 20:09:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B9E72856F for ; Mon, 12 Aug 2019 20:09:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0FF0B2857E; Mon, 12 Aug 2019 20:09:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DC1DC2857B for ; Mon, 12 Aug 2019 20:09:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727705AbfHLUJa (ORCPT ); Mon, 12 Aug 2019 16:09:30 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:34123 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727704AbfHLUJ3 (ORCPT ); Mon, 12 Aug 2019 16:09:29 -0400 Received: by mail-pg1-f193.google.com with SMTP id n9so43814246pgc.1; Mon, 12 Aug 2019 13:09:29 -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 :mime-version:content-transfer-encoding; bh=ijw8qW4YQwPJ65cSa1rqyHCWE36jFTySRyvLwWFgnQw=; b=tfJUFeWwhrmS4h1pq6sO+GDBArYE2TxoBPuPasju9ZIokfBWp+RqY7yiJpEonO763q BuwB3RdLjAkdnctdf7S+fVh8IIuGDTszipW+SA2J5TZRbwObD8KWt5uq00fXmC9ITrCE LWh5VGEQHgqOG+kNU8MFkQABga9OuxTk6ZSmvKm19rFz8nbzCa1j+x/hS6O0+S+hml3j 9xuo5kcLORk9U7/09L32nOwiIFKc/hkp0aRrTdjDpDaF4MRJwC78qRegrYpHHcUAXIw8 rK27jkx1uYtD5GAMe0l2ARB851cSlc+lkwAvl8HycMgXS2g3eoC/Zo1ekVCqV5WGFvwP LxFA== 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:mime-version:content-transfer-encoding; bh=ijw8qW4YQwPJ65cSa1rqyHCWE36jFTySRyvLwWFgnQw=; b=K00gghbCQG8GSckpZqb1+kncCZ323ykK0iGFYOkVipfZWbAEfc1yA5CDp45inzo/f3 kqpVI8pVdeI5ql0AQJDVp0vr0AuR14qhC+kw+U+W21HxXf0TM5EvCJI+m+67y4qpbnm7 bE/XqMgcV+C8Ofqcg7Vbd/ilNY6KjT0Xzz2QRkIosg103dhtZQ2o1vOHcA1EKxPjtG74 IsQmh2cvuV+3SY0JufPKinBGsTzAAsl4riRGtHsqMYum0SJcm3AnvM39dhUA0svPEWK2 PxxBvt5dN3vhmk9L3c0Lf2vYtgnbJzPhHbT0SsWpwrF5h/TkDdP+RbQSbUNVSnayim/J pBgQ== X-Gm-Message-State: APjAAAUibfBVaBdinp62CBm5VHF3dY8soPnbpBs+IqD7l/DhInruw2aD fN8Mdynk3DSB6dQKEcb2SQZR74JJ X-Google-Smtp-Source: APXvYqzpdprAf4PgfPstdReQJX4BUhcgUUiPmhjuiohTicqwFGMjLLlYEvn3FKN5Q5Xkz3s5c23+hA== X-Received: by 2002:aa7:91ca:: with SMTP id z10mr14091512pfa.30.1565640568726; Mon, 12 Aug 2019 13:09:28 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id n26sm110286451pfa.83.2019.08.12.13.09.27 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 12 Aug 2019 13:09:28 -0700 (PDT) From: Andrey Smirnov To: linux-watchdog@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Guenter Roeck , Rick Ramstetter , linux-kernel@vger.kernel.org Subject: [PATCH v2 08/22] watchdog: ziirave_wdt: Skip zeros when calculating checksum Date: Mon, 12 Aug 2019 13:08:52 -0700 Message-Id: <20190812200906.31344-9-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190812200906.31344-1-andrew.smirnov@gmail.com> References: <20190812200906.31344-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Zeros don't contribute anything to checksum value, so we can skip unused portion of the packet when calculating its checksum. Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Guenter Roeck Cc: Rick Ramstetter Cc: linux-watchdog@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Guenter Roeck --- drivers/watchdog/ziirave_wdt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/watchdog/ziirave_wdt.c b/drivers/watchdog/ziirave_wdt.c index 9d9c669b8b47..19da0910c2d1 100644 --- a/drivers/watchdog/ziirave_wdt.c +++ b/drivers/watchdog/ziirave_wdt.c @@ -271,7 +271,7 @@ static int __ziirave_firm_write_pkt(struct watchdog_device *wdd, memcpy(packet + 3, data, len); /* Packet checksum */ - for (i = 0; i < ZIIRAVE_FIRM_PKT_TOTAL_SIZE - 1; i++) + for (i = 0; i < len + 3; i++) checksum += packet[i]; packet[ZIIRAVE_FIRM_PKT_TOTAL_SIZE - 1] = checksum; From patchwork Mon Aug 12 20:08:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11090793 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2E9CD1398 for ; Mon, 12 Aug 2019 20:09:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 201EA2856B for ; Mon, 12 Aug 2019 20:09:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 136BC2857B; Mon, 12 Aug 2019 20:09:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD3D32856B for ; Mon, 12 Aug 2019 20:09:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727332AbfHLUJc (ORCPT ); Mon, 12 Aug 2019 16:09:32 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:43238 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727720AbfHLUJb (ORCPT ); Mon, 12 Aug 2019 16:09:31 -0400 Received: by mail-pg1-f194.google.com with SMTP id r26so14085547pgl.10; Mon, 12 Aug 2019 13:09:30 -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 :mime-version:content-transfer-encoding; bh=qfkrKfTu6aSEYz9nb94lbej06C22MD5/E3UVVvaQRvw=; b=X7ynJwHXLWXnsclNvpp6MSr3yn7hpr5XJvNYL3PdsVgBrHRLT90xekoaOw7u+ZC9KP cU3gP5+3HxV+brOntvuMx4s5TMBrhc6Mzq9szXdql7exFHJUjAszfQuXSMBsccbleBr0 lTkIfH/E361NiT9KtzSuFdYFdV3kKNNsRrWxzAolPLVD3yaFR0QoEMBYyKez/BxAgx29 mZt0aKr4XVb1K/+odxUhOATHDU7SYcLp5oRsxR4xzZ50oxIFIjUZPux750OUUTcjQ3fo X+qElcdV7b0KCYdZtdSXGtmJqsZRwLAntt90PDwWBekLYk+ZsUYQOxgbLySAMGovUvzg xPmA== 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:mime-version:content-transfer-encoding; bh=qfkrKfTu6aSEYz9nb94lbej06C22MD5/E3UVVvaQRvw=; b=hmFY9GYU8F3lzC/SJIuDVMp5Vv0ykhs93QFwpB5gx8r9fM9y8ovw7XuknIFyTMo6gj F02FbrakETQqFTJTc0WRJG0jAgKpsrwOZEQU0tsSirtnxczhSwQsHp3+MGFJmCOg8G47 Z2Va/dGCAV1f4FMlNpphaV9kZY7QfAQehHuMy9XMYNZgOCsihmVzwM011IOP3H48rrUC J4ty8wSIg32FMDP4MRPN1QBWjHXvje8DAeq2d0x1eCQ4LTllO9EA7J2NiONPe5QqfgZ6 XSzPuujDoCrEG9cJElzey/6FHRgDxEG3rZiGe9hQWv9q3lgQ0ssl90f/yhc2ud8kIOAE l/xQ== X-Gm-Message-State: APjAAAVHgzmI4SMNmd+jhs4DpnckQsNXkOS6bTDm+rNMnGPVimtDNChg tPhMyLisIw1M2hT5dniGYsSSger1 X-Google-Smtp-Source: APXvYqzS8KZrfyTODXNtdQmW4FVzEWk/QoBBIpScB769gk4FK+UcYCi9i7Gnk9op527ftr07QnSpiw== X-Received: by 2002:a65:458d:: with SMTP id o13mr31127428pgq.34.1565640570136; Mon, 12 Aug 2019 13:09:30 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id n26sm110286451pfa.83.2019.08.12.13.09.28 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 12 Aug 2019 13:09:29 -0700 (PDT) From: Andrey Smirnov To: linux-watchdog@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Guenter Roeck , Rick Ramstetter , linux-kernel@vger.kernel.org Subject: [PATCH v2 09/22] watchdog: ziirave_wdt: Fix incorrect use of ARRAY_SIZE Date: Mon, 12 Aug 2019 13:08:53 -0700 Message-Id: <20190812200906.31344-10-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190812200906.31344-1-andrew.smirnov@gmail.com> References: <20190812200906.31344-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Both memset() and ziirave_firm_write_block_data() expect length in bytes as an argument, not a number of elements in array. It just happens that in this particular case both values are equal. Modify the code to use sizeof() instead. Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Guenter Roeck Cc: Rick Ramstetter Cc: linux-watchdog@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Guenter Roeck --- drivers/watchdog/ziirave_wdt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/watchdog/ziirave_wdt.c b/drivers/watchdog/ziirave_wdt.c index 19da0910c2d1..e0f55cbdc603 100644 --- a/drivers/watchdog/ziirave_wdt.c +++ b/drivers/watchdog/ziirave_wdt.c @@ -203,7 +203,7 @@ static int ziirave_firm_set_read_addr(struct watchdog_device *wdd, u16 addr) return i2c_smbus_write_block_data(client, ZIIRAVE_CMD_DOWNLOAD_SET_READ_ADDR, - ARRAY_SIZE(address), address); + sizeof(address), address); } static int ziirave_firm_write_block_data(struct watchdog_device *wdd, @@ -260,7 +260,7 @@ static int __ziirave_firm_write_pkt(struct watchdog_device *wdd, return -EMSGSIZE; } - memset(packet, 0, ARRAY_SIZE(packet)); + memset(packet, 0, sizeof(packet)); /* Packet length */ packet[0] = len; @@ -276,7 +276,7 @@ static int __ziirave_firm_write_pkt(struct watchdog_device *wdd, packet[ZIIRAVE_FIRM_PKT_TOTAL_SIZE - 1] = checksum; ret = ziirave_firm_write_block_data(wdd, ZIIRAVE_CMD_DOWNLOAD_PACKET, - ARRAY_SIZE(packet), packet, true); + sizeof(packet), packet, true); if (ret) dev_err(&client->dev, "Failed to write firmware packet at address 0x%04x: %d\n", From patchwork Mon Aug 12 20:08:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11090819 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E88C01398 for ; Mon, 12 Aug 2019 20:10:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D9D5328569 for ; Mon, 12 Aug 2019 20:10:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE5932856F; Mon, 12 Aug 2019 20:10:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7DE7228569 for ; Mon, 12 Aug 2019 20:10:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727569AbfHLUK2 (ORCPT ); Mon, 12 Aug 2019 16:10:28 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:34136 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727330AbfHLUJc (ORCPT ); Mon, 12 Aug 2019 16:09:32 -0400 Received: by mail-pg1-f194.google.com with SMTP id n9so43814328pgc.1; Mon, 12 Aug 2019 13:09:32 -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 :mime-version:content-transfer-encoding; bh=s6xPb3Pi9HQl3OaPyWVe4AATOniA65kRVZILYWuETVg=; b=Tl5W5sCmCDdiZk0cvEElfwNZ8muz77OEpGZooh6sxP2+mjyOpyYqbUq9lXFAbvuJLc jqYjTc89PwWzm9Lk+wtDKOrB8lN6ek2lBL6PoK+oIs2dd6d7Os9VVSruHjG4hWSdCMU4 ZBN2e5ASSuJWF1YdWFl4GuvHqE9revKIbp3uGxGEWkpwiAGyZ+8FyxnfnERnGHP8Jz6q iMBGjb8RRcbMZnc7DbFA8yfdUfDzFuzkYS5s4UFs/azwJObr/DfZSBI/Z3VIPBSLGFKi P2oHDUHmvZE7OjAwQ9YAoQvUquTbSXf1u7nhy/qQjvFSFw7gcHwBCGU9BMFcG8eeal6h FRfg== 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:mime-version:content-transfer-encoding; bh=s6xPb3Pi9HQl3OaPyWVe4AATOniA65kRVZILYWuETVg=; b=nfphnRBXhOrUdLnhX3SEk74BV7Cd+nxK4Q2PhJ+Cv4tpTUTePCTaMZY4xdm7v+4g+Q uZeR6UOOl84afkayzr2DymV1I7DEGlQm2cGZgkhIDH61E7XOY/Ox12mZEy3LGD9OnZ6w Qy3RwXiBZ26g3XbEMOkGALW92tf+t9pB1eLpgyVRPXcn6t4rHFf/AESXgDUOemzzR0ic e+ilO1/Yd+azZKzpwUZUsNRtr04lnR7oM8Mi6yzRePLcwGnYZniWHgcKpX6WWImqcXXE LgJYi4IdzzMyaSeMNUOu+9/nHp8l9gw234o9uNSQ2Wgx/eK0KSJFCi4uwjJqW95RqiXR bKuA== X-Gm-Message-State: APjAAAUbsuV5c8XawHGwHB545/Ofkv/YJYo/tz5EYJRPq17m+a0hl9t5 VWarOwFzCL3YImNxHjs0GCpQ0wJs X-Google-Smtp-Source: APXvYqwGM/Yr0wf0FOouYw8R3GOXH4oT1nkm4wRNA+S5UsJlHqGQ+/tUp+XuUh8+IwQVFMuMFNPJAA== X-Received: by 2002:aa7:9254:: with SMTP id 20mr38477100pfp.212.1565640571617; Mon, 12 Aug 2019 13:09:31 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id n26sm110286451pfa.83.2019.08.12.13.09.30 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 12 Aug 2019 13:09:30 -0700 (PDT) From: Andrey Smirnov To: linux-watchdog@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Guenter Roeck , Rick Ramstetter , linux-kernel@vger.kernel.org Subject: [PATCH v2 10/22] watchdog: ziirave_wdt: Zero out only what's necessary Date: Mon, 12 Aug 2019 13:08:54 -0700 Message-Id: <20190812200906.31344-11-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190812200906.31344-1-andrew.smirnov@gmail.com> References: <20190812200906.31344-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of zeroing out all of the packet and then overwriting a significant portion of those zeros via memcpy(), zero out only a portion of the packet that is known to not contain any data. Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Guenter Roeck Cc: Rick Ramstetter Cc: linux-watchdog@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Guenter Roeck --- drivers/watchdog/ziirave_wdt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/watchdog/ziirave_wdt.c b/drivers/watchdog/ziirave_wdt.c index e0f55cbdc603..69694f2836d7 100644 --- a/drivers/watchdog/ziirave_wdt.c +++ b/drivers/watchdog/ziirave_wdt.c @@ -260,8 +260,6 @@ static int __ziirave_firm_write_pkt(struct watchdog_device *wdd, return -EMSGSIZE; } - memset(packet, 0, sizeof(packet)); - /* Packet length */ packet[0] = len; /* Packet address */ @@ -269,6 +267,7 @@ static int __ziirave_firm_write_pkt(struct watchdog_device *wdd, packet[2] = (addr16 & 0xff00) >> 8; memcpy(packet + 3, data, len); + memset(packet + 3 + len, 0, ZIIRAVE_FIRM_PKT_DATA_SIZE - len); /* Packet checksum */ for (i = 0; i < len + 3; i++) From patchwork Mon Aug 12 20:08:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11090811 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 46EB1112C for ; Mon, 12 Aug 2019 20:10:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 383382856F for ; Mon, 12 Aug 2019 20:10:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2CE9F2857E; Mon, 12 Aug 2019 20:10:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B7ABB2856F for ; Mon, 12 Aug 2019 20:10:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727742AbfHLUJe (ORCPT ); Mon, 12 Aug 2019 16:09:34 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:38535 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727731AbfHLUJe (ORCPT ); Mon, 12 Aug 2019 16:09:34 -0400 Received: by mail-pf1-f194.google.com with SMTP id o70so4903238pfg.5; Mon, 12 Aug 2019 13:09:33 -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 :mime-version:content-transfer-encoding; bh=Cfi8eGhAZL6laytKQF8w9HsoqEDugdT9/babz9jDHkc=; b=jvOueJScWyTv5hPktqL67tKU+G+nHHbssgO2NxwnM3Phte4m35xeEEbWvijGUANTaA X2CtR0mgFZP12VSVBGlwlApKm/S0hWKajypQUyNbgbNpbXRxBYq1f/MNEkL5w6rgEDxs gZy7qNMtNSEzV+WeknGAQ44Xh6/QxG5owPywb1rD3JzQu2nogCW4kUVua7viuQgEiVC2 zcQKqMk6WxmlEqbe1odWSHoQr5xjt0oFsPVWLCXTMcXILQEPDKVmKk3mMaAi1wbdV4HP dznNxEws1L9mN/NBdNAdqxe9hLw4qkbci5rir4ImWjqce9C3+lPAClfzcGxixBcFF1HF ralA== 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:mime-version:content-transfer-encoding; bh=Cfi8eGhAZL6laytKQF8w9HsoqEDugdT9/babz9jDHkc=; b=CRrTd7zAOnEHgJWM6dYcqxN9nE7lPxXby+272ImIFQgi/VAOkwAdF1nIyK2Ny/81AH auhNAf1ILMOiHpqSb9DO2snPHpROhpiFcqYbmFa/26U9Ac9EvlFVXeI4u2OLQe3OmmDp gjz510+08fhfSGDMuA8PF+wHGEKPr9FnbU7BgqtSOdAQjaNeFSA6rcT+52Ps/8DMQW7E 4ozUYnHyRRmDshpkHPc8eAsEFX3lErbdqRvNfvHPdbRddMu9FjvvqMNiKez0Lq+X425p yjP1u4uKBScw6b0/Yx5ZNwnknVvBrz5wclt5pMgNRR00bdpYAY5dj+UKjY5nTU9AF2B1 jYyA== X-Gm-Message-State: APjAAAVvqiCncxPziuFcW+DPgb6hEBoFoXGl0Y1kM7J+p2l8p+1h7aL3 o3Mj0/HSnPDsdyEpJo//lnemSSqM X-Google-Smtp-Source: APXvYqwKhD3zWqzaQMN4Z79u0WX4qY6wPt62R+zZK08bzjGifFhDRr8j8LzbZzVZe/F6zDNt6A6pyg== X-Received: by 2002:aa7:8585:: with SMTP id w5mr3468136pfn.1.1565640572742; Mon, 12 Aug 2019 13:09:32 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id n26sm110286451pfa.83.2019.08.12.13.09.31 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 12 Aug 2019 13:09:31 -0700 (PDT) From: Andrey Smirnov To: linux-watchdog@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Guenter Roeck , Rick Ramstetter , linux-kernel@vger.kernel.org Subject: [PATCH v2 11/22] watchdog: ziirave_wdt: Make use of put_unaligned_le16 Date: Mon, 12 Aug 2019 13:08:55 -0700 Message-Id: <20190812200906.31344-12-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190812200906.31344-1-andrew.smirnov@gmail.com> References: <20190812200906.31344-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of doing this explicitly use put_unaligned_le16() to place 16-bit address value into command payload. Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Guenter Roeck Cc: Rick Ramstetter Cc: linux-watchdog@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Guenter Roeck --- drivers/watchdog/ziirave_wdt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/watchdog/ziirave_wdt.c b/drivers/watchdog/ziirave_wdt.c index 69694f2836d7..38cf3ca329d7 100644 --- a/drivers/watchdog/ziirave_wdt.c +++ b/drivers/watchdog/ziirave_wdt.c @@ -21,6 +21,8 @@ #include #include +#include + #define ZIIRAVE_TIMEOUT_MIN 3 #define ZIIRAVE_TIMEOUT_MAX 255 #define ZIIRAVE_TIMEOUT_DEFAULT 30 @@ -198,8 +200,7 @@ static int ziirave_firm_set_read_addr(struct watchdog_device *wdd, u16 addr) struct i2c_client *client = to_i2c_client(wdd->parent); u8 address[2]; - address[0] = addr & 0xff; - address[1] = (addr >> 8) & 0xff; + put_unaligned_le16(addr, address); return i2c_smbus_write_block_data(client, ZIIRAVE_CMD_DOWNLOAD_SET_READ_ADDR, @@ -263,8 +264,7 @@ static int __ziirave_firm_write_pkt(struct watchdog_device *wdd, /* Packet length */ packet[0] = len; /* Packet address */ - packet[1] = addr16 & 0xff; - packet[2] = (addr16 & 0xff00) >> 8; + put_unaligned_le16(addr16, packet + 1); memcpy(packet + 3, data, len); memset(packet + 3 + len, 0, ZIIRAVE_FIRM_PKT_DATA_SIZE - len); From patchwork Mon Aug 12 20:08:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11090815 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CF39C112C for ; Mon, 12 Aug 2019 20:10:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C28832856B for ; Mon, 12 Aug 2019 20:10:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B72952857D; Mon, 12 Aug 2019 20:10:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6358E2856B for ; Mon, 12 Aug 2019 20:10:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727845AbfHLUKO (ORCPT ); Mon, 12 Aug 2019 16:10:14 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:46181 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727418AbfHLUJf (ORCPT ); Mon, 12 Aug 2019 16:09:35 -0400 Received: by mail-pf1-f194.google.com with SMTP id q139so1955589pfc.13; Mon, 12 Aug 2019 13:09:34 -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 :mime-version:content-transfer-encoding; bh=s7wEcXjgtIZl9U3KIuvRTDXiR5VgWVcjPVD+M9dp6i4=; b=E6ti69xyz0TK4JpVeWEr6CXyjvRhB07lnKL4/I45PFYaL3a8HiH+SZ57ZvpsAE+qtx 1A0eUT1sgFvu/N9tMAq13meaumNazIBpESQb1phcAdOVf1sEzZEysjR+7orD4+mEpF9w 1DHu5yOoA2re3ju7D8Rga/bDHj+u+OWCQaYjfZJPNWgysjGC45FfsTrZ5OgYPBWSx8iB bSpKrYb/F6vthPob3VSfrYIn6GJAITN+Kwcps9pwV8iiGE1LSq6ZuIA9CZ6djYxsJjCb bMcqClwv7yHmW42LjDJ6lHSG60ALKeCG8ntYzGvHX3D+W8y//gif/w6iZHkIBhkdUN4w OT/w== 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:mime-version:content-transfer-encoding; bh=s7wEcXjgtIZl9U3KIuvRTDXiR5VgWVcjPVD+M9dp6i4=; b=aZesWD8E4tyf+wJ2Qou8MUEOwiQ7ECKfQNXTNOvJbqFXr7wU47w8fltPqSvlxkPeEZ gKQcSvAL7toHba9AAWW+PsntlUJsiNbMEFBV3sJWoFxeOiRdf5PAm38R+kyMbjsk+/x6 b56f/2Hy3QQphv2ET46swmXAvBS4QkmqPDsed0sIOq/7PSSTZXu0QPJP17sgOV1qgOZf czSErxrYOpi4JyL6gDhe5e3i3XONI6H/Q0/B4nS/rdOw9DNnj2trNkXNat5KwRVdag/A KSL6XtDwMn468nNtICV3NjpyJk37H8luVMZ8DU360ssnqDNdWQtgmXtpkknPnM2JyyOi eIDw== X-Gm-Message-State: APjAAAWZddIO4yOgHUb2mMHRCc5Bn2ZDMn9dTKyPa2vfzYqCEZX6inDR kVNdbcA414VSeY2Hs+mztpvyWvfA X-Google-Smtp-Source: APXvYqzqlTRXEnxBDqMPh41b70/Q7WJSsI/vXqI7PIeCKV2dBUmlwQmAphyJFAthzMwA4cKfNlMwQA== X-Received: by 2002:aa7:8218:: with SMTP id k24mr35932001pfi.221.1565640574149; Mon, 12 Aug 2019 13:09:34 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id n26sm110286451pfa.83.2019.08.12.13.09.32 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 12 Aug 2019 13:09:33 -0700 (PDT) From: Andrey Smirnov To: linux-watchdog@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Guenter Roeck , Rick Ramstetter , linux-kernel@vger.kernel.org Subject: [PATCH v2 12/22] watchdog: ziirave_wdt: Don't check if ihex record length is zero Date: Mon, 12 Aug 2019 13:08:56 -0700 Message-Id: <20190812200906.31344-13-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190812200906.31344-1-andrew.smirnov@gmail.com> References: <20190812200906.31344-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Ihex_next_binrec() will return NULL if next record's 'len' is zero, so explicit checks for that in the driver are unnecessary. Drop them. Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Guenter Roeck Cc: Rick Ramstetter Cc: linux-watchdog@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Guenter Roeck --- drivers/watchdog/ziirave_wdt.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/drivers/watchdog/ziirave_wdt.c b/drivers/watchdog/ziirave_wdt.c index 38cf3ca329d7..4b95467bf239 100644 --- a/drivers/watchdog/ziirave_wdt.c +++ b/drivers/watchdog/ziirave_wdt.c @@ -318,10 +318,6 @@ static int ziirave_firm_verify(struct watchdog_device *wdd, u16 addr; for (rec = (void *)fw->data; rec; rec = ihex_next_binrec(rec)) { - /* Zero length marks end of records */ - if (!be16_to_cpu(rec->len)) - break; - addr = (be32_to_cpu(rec->addr) & 0xffff) >> 1; if (addr < ZIIRAVE_FIRM_FLASH_MEMORY_START || addr > ZIIRAVE_FIRM_FLASH_MEMORY_END) @@ -381,10 +377,6 @@ static int ziirave_firm_upload(struct watchdog_device *wdd, msleep(500); for (rec = (void *)fw->data; rec; rec = ihex_next_binrec(rec)) { - /* Zero length marks end of records */ - if (!be16_to_cpu(rec->len)) - break; - ret = ziirave_firm_write_pkt(wdd, be32_to_cpu(rec->addr), rec->data, be16_to_cpu(rec->len)); if (ret) From patchwork Mon Aug 12 20:08:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11090813 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C3E7413B1 for ; Mon, 12 Aug 2019 20:10:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B3E462856B for ; Mon, 12 Aug 2019 20:10:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A8B9D2857B; Mon, 12 Aug 2019 20:10:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8FEF32856B for ; Mon, 12 Aug 2019 20:10:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727757AbfHLUJi (ORCPT ); Mon, 12 Aug 2019 16:09:38 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:33791 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727442AbfHLUJg (ORCPT ); Mon, 12 Aug 2019 16:09:36 -0400 Received: by mail-pg1-f193.google.com with SMTP id n190so9224057pgn.0; Mon, 12 Aug 2019 13:09:36 -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 :mime-version:content-transfer-encoding; bh=Al/DgRidHVqo/g9YdSiEeqYKH6WNvd2YSDNAidLE1ZA=; b=nPY4ul+wXuULh52bDJnhEiH9sAiZvMb5ajFLmzcI1SOrnt0MlbILBY5UlE8F8l4Pkj 1/WFaz+82IrsMuFa2jkrfwUqcBpYZxrGOmg64k6soAh00ztHlUh1BkfQ/AlUrOrU7ul+ fie1PCYMslcj26JD9I9ayC2IX9+02aoKqVHQMZFvQfLaDQbgJKCtiJHf4BJVKGwAE99/ X0JPsyRSxb1zMeljN6jjmq4iCArrekt4CzcmNLVGh/RyJzcUs8JjUVzB+gQD+FV6JMhv kjSl9Bw9PdInwJMYO8ZTdGUyhPTDx66ooXlFegSFuXLEZSgfEZR8jXcYTFQF2liW12Te Wrxw== 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:mime-version:content-transfer-encoding; bh=Al/DgRidHVqo/g9YdSiEeqYKH6WNvd2YSDNAidLE1ZA=; b=IWYjyh6y2wIVH2i0fUiEVicTtigLhwTfM8dcEBQhFKlhyxLwsquUFfE7LAANIxfKwN Ckp3cSYeaAoOG6Cr5W9UcsOQ29uhlyHi76KV/RViw45Crw2B9olkYKHD5ARhs0I0GZm0 jD2VdPnlI5ziLkasny/phoWjf8seJBP0BlcPsvKGby7enCuUVIuGgydqvHjpzHBbqwTq TS9ERJNTy5huxaPsxmH/zGQhBOD+xXmy2DQXEmPuJfy5xnglHbNMIVWUeCyZ10tvuTox iD9XFdi45atDljyyjDS8nnE0k1QxSA6kutGhl+/nGp3NN4POagPkTGtpp6ZM8yDmRZrW Ir+Q== X-Gm-Message-State: APjAAAULfjXRVimfvYkpT71tZarAnW8mlWOs3eLR7a9oGQclvm1bf/HU LQbY+Xn/v5Bm1hQyLYDtRkRU0MVv X-Google-Smtp-Source: APXvYqwNWHDTLHBZCyyK/C6H2ACoxORIKQr5blSl8h7eNNs9y3QLOqiTZIrF52txfoftssM0xnLdQg== X-Received: by 2002:a63:2887:: with SMTP id o129mr25132359pgo.179.1565640575365; Mon, 12 Aug 2019 13:09:35 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id n26sm110286451pfa.83.2019.08.12.13.09.34 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 12 Aug 2019 13:09:34 -0700 (PDT) From: Andrey Smirnov To: linux-watchdog@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Guenter Roeck , Rick Ramstetter , linux-kernel@vger.kernel.org Subject: [PATCH v2 13/22] watchdog: ziirave_wdt: Don't read out more than 'len' firmware bytes Date: Mon, 12 Aug 2019 13:08:57 -0700 Message-Id: <20190812200906.31344-14-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190812200906.31344-1-andrew.smirnov@gmail.com> References: <20190812200906.31344-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We only compare first 'len' bytes of read firmware, so we don't need to read more that that. Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Guenter Roeck Cc: Rick Ramstetter Cc: linux-watchdog@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Guenter Roeck --- drivers/watchdog/ziirave_wdt.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/watchdog/ziirave_wdt.c b/drivers/watchdog/ziirave_wdt.c index 4b95467bf239..f05095b08016 100644 --- a/drivers/watchdog/ziirave_wdt.c +++ b/drivers/watchdog/ziirave_wdt.c @@ -318,6 +318,8 @@ static int ziirave_firm_verify(struct watchdog_device *wdd, u16 addr; for (rec = (void *)fw->data; rec; rec = ihex_next_binrec(rec)) { + const u16 len = be16_to_cpu(rec->len); + addr = (be32_to_cpu(rec->addr) & 0xffff) >> 1; if (addr < ZIIRAVE_FIRM_FLASH_MEMORY_START || addr > ZIIRAVE_FIRM_FLASH_MEMORY_END) @@ -331,7 +333,7 @@ static int ziirave_firm_verify(struct watchdog_device *wdd, return ret; } - for (i = 0; i < ARRAY_SIZE(data); i++) { + for (i = 0; i < len; i++) { ret = i2c_smbus_read_byte_data(client, ZIIRAVE_CMD_DOWNLOAD_READ_BYTE); if (ret < 0) { @@ -342,7 +344,7 @@ static int ziirave_firm_verify(struct watchdog_device *wdd, data[i] = ret; } - if (memcmp(data, rec->data, be16_to_cpu(rec->len))) { + if (memcmp(data, rec->data, len)) { dev_err(&client->dev, "Firmware mismatch at address 0x%04x\n", addr); return -EINVAL; From patchwork Mon Aug 12 20:08:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11090817 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2871F13B1 for ; Mon, 12 Aug 2019 20:10:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 19EB12856B for ; Mon, 12 Aug 2019 20:10:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0E7BD2857B; Mon, 12 Aug 2019 20:10:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 92B972856F for ; Mon, 12 Aug 2019 20:10:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727535AbfHLUKO (ORCPT ); Mon, 12 Aug 2019 16:10:14 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:44669 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727731AbfHLUJi (ORCPT ); Mon, 12 Aug 2019 16:09:38 -0400 Received: by mail-pf1-f196.google.com with SMTP id c81so1237350pfc.11; Mon, 12 Aug 2019 13:09:37 -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 :mime-version:content-transfer-encoding; bh=4xRnCXPOXDMuZQhnpqA+htuwTVhEEUcMOIJr19kWmsc=; b=FjXND/xQUqmA91G+FF/Jq1RGy1RXOfVBnb6Iydfjon9OnCBTWGXG+mpx7I9Wvken/P znGJeNu6doUGuE0HpbLpOroahAZJFCqB5XeplmWtHwZn0IZoGGaHMMnwgDz/KbLgW25b PgW0+Jp2kmlKRgiuiE7OON07VRLspfuL4z/ICSBdvWXgWCefaUgjMMB70Em4OvKNPDsU 9PznDL7TakghuMOhZYCF7gEbDYCWZ6NEK7Y1VmlF8twXe6v1YWrde98/iDnarbGVhjBk gP48B8GjbyxAZskzidoSJSc6QB7cDlhZV695BQhvOaF3cAN1tpkT99WHAWUXOWGDWgMw SJ8w== 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:mime-version:content-transfer-encoding; bh=4xRnCXPOXDMuZQhnpqA+htuwTVhEEUcMOIJr19kWmsc=; b=PCKamoEtqRW42OHJlYL4EcJD4BbX3dN802mG7mKKGvwbXJazt1MV5ZYt7CueblgiUR o0xomb0tqzg1j/FAUYUJujf5/npawzOmVyEo1hiy9z71EFeD22SLEquXzN1GEFDLBEfE a7vZ2d0uzUJrdnxfADS6OfXzhN8pbuGkMOqwlChizgVYCVBP7+4bDLAGcW9O6EBl6MFf t2sCUcgvo4byPCCfd4OA9XqGBk9RHQtU/Q04B0B+gLcQHtwWSG16YfeMT+fpSBAc5Rzk NlPCEQ+YP5zwBhqQUnp2NfMfk/a1H8hJJd+hN2XzYUdJcgO8CnBQet4TtqqLHqDOCocW mAIQ== X-Gm-Message-State: APjAAAU17qGS0SklKSyFu40Ho97JCEi/fnIBLSyE5ZYUPmrINB9tE2on QnCOYlGuHqHg8GbKKjQ5CloeNezl X-Google-Smtp-Source: APXvYqwt+H0sjUTZ6SSyeGRMxuVp1+16KAb2czF9wZ90mc42aXiUVIh6QYHQAKRgrf+pud+/cQiVUQ== X-Received: by 2002:a63:553:: with SMTP id 80mr32443475pgf.280.1565640576764; Mon, 12 Aug 2019 13:09:36 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id n26sm110286451pfa.83.2019.08.12.13.09.35 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 12 Aug 2019 13:09:36 -0700 (PDT) From: Andrey Smirnov To: linux-watchdog@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Guenter Roeck , Rick Ramstetter , linux-kernel@vger.kernel.org Subject: [PATCH v2 14/22] watchdog: ziirave_wdt: Don't try to program readonly flash Date: Mon, 12 Aug 2019 13:08:58 -0700 Message-Id: <20190812200906.31344-15-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190812200906.31344-1-andrew.smirnov@gmail.com> References: <20190812200906.31344-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Bootloader code will ignore any attempts to write data to any flash area outside of [ZIIRAVE_FIRM_FLASH_MEMORY_START; ZIIRAVE_FIRM_FLASH_MEMORY_END]. Firmware update code already have an appropriate check to skip those areas when validating updated firmware. Firmware programming code, OTOH, does not and will needlessly send no-op I2C traffic. Add an appropriate check to __ziirave_firm_write_pkt() so as to save all of that wasted effort. While at it, normalize all of the address handling code to use full 32-bit address in units of bytes and convert it to an appropriate value only in places where that is necessary. Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Guenter Roeck Cc: Rick Ramstetter Cc: linux-watchdog@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Guenter Roeck --- drivers/watchdog/ziirave_wdt.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/drivers/watchdog/ziirave_wdt.c b/drivers/watchdog/ziirave_wdt.c index f05095b08016..a3cc936858ad 100644 --- a/drivers/watchdog/ziirave_wdt.c +++ b/drivers/watchdog/ziirave_wdt.c @@ -51,8 +51,8 @@ static char *ziirave_reasons[] = {"power cycle", "hw watchdog", NULL, NULL, #define ZIIRAVE_FIRM_PKT_TOTAL_SIZE 20 #define ZIIRAVE_FIRM_PKT_DATA_SIZE 16 -#define ZIIRAVE_FIRM_FLASH_MEMORY_START 0x1600 -#define ZIIRAVE_FIRM_FLASH_MEMORY_END 0x2bbf +#define ZIIRAVE_FIRM_FLASH_MEMORY_START (2 * 0x1600) +#define ZIIRAVE_FIRM_FLASH_MEMORY_END (2 * 0x2bbf) #define ZIIRAVE_FIRM_PAGE_SIZE 128 /* Received and ready for next Download packet. */ @@ -195,12 +195,13 @@ static int ziirave_firm_wait_for_ack(struct watchdog_device *wdd) return ret == ZIIRAVE_FIRM_DOWNLOAD_ACK ? 0 : -EIO; } -static int ziirave_firm_set_read_addr(struct watchdog_device *wdd, u16 addr) +static int ziirave_firm_set_read_addr(struct watchdog_device *wdd, u32 addr) { struct i2c_client *client = to_i2c_client(wdd->parent); + const u16 addr16 = (u16)addr / 2; u8 address[2]; - put_unaligned_le16(addr, address); + put_unaligned_le16(addr16, address); return i2c_smbus_write_block_data(client, ZIIRAVE_CMD_DOWNLOAD_SET_READ_ADDR, @@ -234,6 +235,12 @@ static int ziirave_firm_write_byte(struct watchdog_device *wdd, u8 command, wait_for_ack); } +static bool ziirave_firm_addr_readonly(u32 addr) +{ + return addr < ZIIRAVE_FIRM_FLASH_MEMORY_START || + addr > ZIIRAVE_FIRM_FLASH_MEMORY_END; +} + /* * ziirave_firm_write_pkt() - Build and write a firmware packet * @@ -261,6 +268,16 @@ static int __ziirave_firm_write_pkt(struct watchdog_device *wdd, return -EMSGSIZE; } + /* + * Ignore packets that are targeting program memory outisde of + * app partition, since they will be ignored by the + * bootloader. At the same time, we need to make sure we'll + * allow zero length packet that will be sent as the last step + * of firmware update + */ + if (len && ziirave_firm_addr_readonly(addr)) + return 0; + /* Packet length */ packet[0] = len; /* Packet address */ @@ -279,7 +296,7 @@ static int __ziirave_firm_write_pkt(struct watchdog_device *wdd, if (ret) dev_err(&client->dev, "Failed to write firmware packet at address 0x%04x: %d\n", - addr16, ret); + addr, ret); return ret; } @@ -315,14 +332,12 @@ static int ziirave_firm_verify(struct watchdog_device *wdd, const struct ihex_binrec *rec; int i, ret; u8 data[ZIIRAVE_FIRM_PKT_DATA_SIZE]; - u16 addr; for (rec = (void *)fw->data; rec; rec = ihex_next_binrec(rec)) { const u16 len = be16_to_cpu(rec->len); + const u32 addr = be32_to_cpu(rec->addr); - addr = (be32_to_cpu(rec->addr) & 0xffff) >> 1; - if (addr < ZIIRAVE_FIRM_FLASH_MEMORY_START || - addr > ZIIRAVE_FIRM_FLASH_MEMORY_END) + if (ziirave_firm_addr_readonly(addr)) continue; ret = ziirave_firm_set_read_addr(wdd, addr); From patchwork Mon Aug 12 20:08:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11090809 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DCA11112C for ; Mon, 12 Aug 2019 20:10:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE5012856B for ; Mon, 12 Aug 2019 20:10:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C25CA2857B; Mon, 12 Aug 2019 20:10:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 72CAE2856B for ; Mon, 12 Aug 2019 20:10:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727771AbfHLUJj (ORCPT ); Mon, 12 Aug 2019 16:09:39 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:36900 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727758AbfHLUJj (ORCPT ); Mon, 12 Aug 2019 16:09:39 -0400 Received: by mail-pf1-f196.google.com with SMTP id 129so3332740pfa.4; Mon, 12 Aug 2019 13:09:38 -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 :mime-version:content-transfer-encoding; bh=fEQpbh35kmetbOwWrx+8yJXAYsmEnojnvAEv4480YIA=; b=X+pEynRi2mvcOZjNBWuJ/XWBTcZPw8Wnkx+NVbZtAK0OmaiCpAIqGzB0YIY+y6IkQf jNvFwvw7rdsXL/LEmf+t+HVeT4TfCAWukobpEV6BagJNiFZJ9v9W/pMAGuzXhd8zv6m/ UwW8NXVUEt3aWPkyU1lWpbqi+/4oq3dE+Ig74tTmgegA+ZM5IVHOcDRWJZR0xd/REMv7 OQiD33BmL1qYhoC8qiBSxCA6wnETr21KysxoLxfgb7YnTauNtOXtdvqQ8lhqVGsRCRzW dKdbiikmKcI6xLldRANuGsxhW66t5PNro+gI5S2ZVFbLCzUIkZjslOY/CXrx/LuYDjpc 3R3g== 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:mime-version:content-transfer-encoding; bh=fEQpbh35kmetbOwWrx+8yJXAYsmEnojnvAEv4480YIA=; b=owuaY8FljkmCYgx89D7oWNaLe4tB2rPu7AqupTKU3P5JQ6s+8MllNn03OryVO7S3GR PYQiWndL/5gXE4pBUC4Vbc8nfUXxGeBNQRCwQtlB+ELqQApwsgv213br+RVHh+Y3BhUW UQbHsHNfdmWY9urNHkXgmWxlGupyN87qNMS9bGnSsS9g8mZVf5El0xPdfitZFrupBMgF zbGj3BsD+QgJVLlyjT5j+XRdLvVDmeP6eyU2enLZiiGlPKSr52Jkg9OIygssCLYCY8NW kDaC+FYbglAR53GQTNo9igD0TuZaqrPrCh79qyNAp/KbmY4dXwSvBCvfABPHFkQKPeQE CJSg== X-Gm-Message-State: APjAAAVRJfRRyRCzCtvCIsJLqI414oW+s3IjCq2H1Nm/c9Fk2m0OZ0VQ oX/MR2cdockXDPkEABOHsZiL9xa6 X-Google-Smtp-Source: APXvYqxA1gL+MXZ4IG2JLjwA/6cNQ/lJsRKvitucNa0eGKGYQIz0jr8UIIEH2fzdQQ8BZKq2qLtrBQ== X-Received: by 2002:a65:6114:: with SMTP id z20mr32068911pgu.141.1565640577821; Mon, 12 Aug 2019 13:09:37 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id n26sm110286451pfa.83.2019.08.12.13.09.36 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 12 Aug 2019 13:09:37 -0700 (PDT) From: Andrey Smirnov To: linux-watchdog@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Guenter Roeck , Rick Ramstetter , linux-kernel@vger.kernel.org Subject: [PATCH v2 15/22] watchdog: ziirave_wdt: Fix misleading error message Date: Mon, 12 Aug 2019 13:08:59 -0700 Message-Id: <20190812200906.31344-16-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190812200906.31344-1-andrew.smirnov@gmail.com> References: <20190812200906.31344-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Fix misleading error message in ziirave_wdt_init_duration(). Saying "unable to set ..." implies that an attempt at communication with watchdog device has taken palce and was not successful. In this case, however, all it indicates is that no reset pulse duration was specified either via kernel parameter or Device Tree. Re-phase the log message to be more clear about benign nature of this event. Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Guenter Roeck Cc: Rick Ramstetter Cc: linux-watchdog@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Guenter Roeck --- drivers/watchdog/ziirave_wdt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/watchdog/ziirave_wdt.c b/drivers/watchdog/ziirave_wdt.c index a3cc936858ad..0c150f3cf408 100644 --- a/drivers/watchdog/ziirave_wdt.c +++ b/drivers/watchdog/ziirave_wdt.c @@ -603,7 +603,7 @@ static int ziirave_wdt_init_duration(struct i2c_client *client) &reset_duration); if (ret) { dev_info(&client->dev, - "Unable to set reset pulse duration, using default\n"); + "No reset pulse duration specified, using default\n"); return 0; } } From patchwork Mon Aug 12 20:09:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11090807 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7F3C81398 for ; Mon, 12 Aug 2019 20:10:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6EDFE2856F for ; Mon, 12 Aug 2019 20:10:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 636E42857D; Mon, 12 Aug 2019 20:10:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0CC3F2856B for ; Mon, 12 Aug 2019 20:10:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727785AbfHLUJl (ORCPT ); Mon, 12 Aug 2019 16:09:41 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:38636 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727781AbfHLUJk (ORCPT ); Mon, 12 Aug 2019 16:09:40 -0400 Received: by mail-pg1-f194.google.com with SMTP id z14so12804930pga.5; Mon, 12 Aug 2019 13:09:40 -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 :mime-version:content-transfer-encoding; bh=FmDMJc136Mrdy2NDd2zjpdm6i0On592v+7kBSJ6sTeQ=; b=NOensDYZhrWrJ1yAc8t/OFcxBoT+FNapnNx5u1G5mWmS119XygbjXUjAFlaDAFXhZV 5rxRNLfsW9Si3RzD4IyjAHJDEz1ab4gVjQ2OK+umb0ItmoA2l2u+UJ3PFb6SQQTMYohG /0XiRVDfmt6YO0XRqyjzt9dd46R/Tv+svLQ8duDJQ1lTLER6WXNPbJTsyeGnMkvfIzig mtLU9sm7iRg23g9vHQB2hafatdKUgrlJgryzQedIri55FYDX86qai6XaMyz25vPfcj/f fDR3IRyUNGO/OGVlwiy+XrwU0pshtCDq400lQAkPZZAPmWa7wQfO+CYgBIQ0VX6nI+kd 6UYw== 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:mime-version:content-transfer-encoding; bh=FmDMJc136Mrdy2NDd2zjpdm6i0On592v+7kBSJ6sTeQ=; b=ZhEBirlNG1KPYLIDchdw5ftiop0tXyZC/dlyqYThgvMsvwjmzbffmBuKtFugv2/Na5 Ev5lmspeTVrOLfYCUGX+v+woJ6QBoxh/djiafWaD/RLe7nENya5Hts58dYSkSMBhyl5p UsEsKaH5mT8R0SDJVMIFXV/XMhKW1mxa0tjE4bSkR1kQW+sUGZK3u0A5b0BNb6QdMYaT oWalj2tv7UPEWiQyfVct9ruuw8A5lCK06RZRfZYXmdgcQuj6FzCcItB+k1dbxggFSY/t eFac4XrsWNoeJ387wlm3t2AYB9NpAvqgl0ONExI+s/QOEHrnuVufi9I1FVvQ9tB/yc7x DQ1Q== X-Gm-Message-State: APjAAAUnrgR1NvGV/jp+S6UuVXNgHI4LxWZR24DNIZnFH7tCdQf8No9i aEXeZJ3IB9r8Ge2rAOXpDPFZ5K1P X-Google-Smtp-Source: APXvYqyYb64Ze15SAlKOdvZrc9MSzkB2laleMnJkUoX8zdWnG96d7BBoVf3jsJWlP6jdqqWifivBag== X-Received: by 2002:a63:b64:: with SMTP id a36mr32262590pgl.215.1565640579472; Mon, 12 Aug 2019 13:09:39 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id n26sm110286451pfa.83.2019.08.12.13.09.38 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 12 Aug 2019 13:09:38 -0700 (PDT) From: Andrey Smirnov To: linux-watchdog@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Guenter Roeck , Rick Ramstetter , linux-kernel@vger.kernel.org Subject: [PATCH v2 16/22] watchdog: ziirave_wdt: Fix JUMP_TO_BOOTLOADER payload Date: Mon, 12 Aug 2019 13:09:00 -0700 Message-Id: <20190812200906.31344-17-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190812200906.31344-1-andrew.smirnov@gmail.com> References: <20190812200906.31344-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Bootloader firmware expects the following traffic for JUMP_TO_BOOTLOADER: S Addr Wr [A] 0x0c [A] 0x01 [A] P using ziirave_firm_write_byte() will result in S Addr Wr [A] 0x0c [A] 0x01 [A] 0x01 [A] P which happens to work because firmware will ignore any extra bytes and expected magic value matches byte count sent by i2c_smbus_write_block_data(). Fix this by converting the code to use i2c_smbus_write_byte_data() instead. Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Guenter Roeck Cc: Rick Ramstetter Cc: linux-watchdog@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Guenter Roeck --- drivers/watchdog/ziirave_wdt.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/watchdog/ziirave_wdt.c b/drivers/watchdog/ziirave_wdt.c index 0c150f3cf408..0185b9175cc0 100644 --- a/drivers/watchdog/ziirave_wdt.c +++ b/drivers/watchdog/ziirave_wdt.c @@ -72,6 +72,8 @@ static char *ziirave_reasons[] = {"power cycle", "hw watchdog", NULL, NULL, #define ZIIRAVE_CMD_JUMP_TO_BOOTLOADER 0x0c #define ZIIRAVE_CMD_DOWNLOAD_PACKET 0x0e +#define ZIIRAVE_CMD_JUMP_TO_BOOTLOADER_MAGIC 1 + #define ZIIRAVE_FW_VERSION_FMT "02.%02u.%02u" #define ZIIRAVE_BL_VERSION_FMT "01.%02u.%02u" @@ -376,8 +378,9 @@ static int ziirave_firm_upload(struct watchdog_device *wdd, const struct ihex_binrec *rec; int ret; - ret = ziirave_firm_write_byte(wdd, ZIIRAVE_CMD_JUMP_TO_BOOTLOADER, 1, - false); + ret = i2c_smbus_write_byte_data(client, + ZIIRAVE_CMD_JUMP_TO_BOOTLOADER, + ZIIRAVE_CMD_JUMP_TO_BOOTLOADER_MAGIC); if (ret) { dev_err(&client->dev, "Failed to jump to bootloader\n"); return ret; From patchwork Mon Aug 12 20:09:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11090805 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6E26E1398 for ; Mon, 12 Aug 2019 20:10:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6001D2856B for ; Mon, 12 Aug 2019 20:10:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5488C2857B; Mon, 12 Aug 2019 20:10:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 073E02856B for ; Mon, 12 Aug 2019 20:10:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727797AbfHLUJm (ORCPT ); Mon, 12 Aug 2019 16:09:42 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:42784 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727786AbfHLUJl (ORCPT ); Mon, 12 Aug 2019 16:09:41 -0400 Received: by mail-pg1-f193.google.com with SMTP id t132so50030679pgb.9; Mon, 12 Aug 2019 13:09:41 -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 :mime-version:content-transfer-encoding; bh=nE0TrNNGtWudMia7gsErH53LkjK1StyH8J2lmMfA2xM=; b=c3BZKJAbmlHupqnBU0pxDFNcsXsA2PpQkQVQsSrvPZ+FJm3rvvEj5RdJoWmBQeSoHS TFhQuIvRYuogfbqAdG89OlP58zOHv3AaFrymDG9Eih99geEu0OGv7dOfvgT+uWXYWHky GE7H5aZ+a+yQFsE+DHAmMsBMgwkp1uykC1UPIC+noHhhmUNnpA4yIJfSU7ScejCTUvnT /jqgDJf/lU0N9qSKMgZW/8AXQtVNvezhZa2KHQ4AvtWHwR1w2SYXrn+uxUc6qfyVx0Kx 1RywUCd8rxsUyvPMStwCZjblPiLJwGCLCwLEM2DaSqw0elaVeKBImrPm6dtuN4xPHNdF lePw== 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:mime-version:content-transfer-encoding; bh=nE0TrNNGtWudMia7gsErH53LkjK1StyH8J2lmMfA2xM=; b=sUjzFr25X49JK3woSO19ueHLQBme4PIrf9jDpench8Ub95WX3Xl8LHCHpVr8nI2m5q EfZMpjFeAJZwGZEhcjKqPa1YoP+aSU8IIUCSd81lW/awe4DchN5lF2OikVKsgMkbMECt dF8A/dmH4xrYG8YQBHN1a6hsKjXWenHC8ZvYGYOEX7SoZnRhGEXIJxrRNtny1+ZFiO8W 7IpaQs0smfBfhsKj5ae+Mm68K7Xa3Y7rhFulGhpoKQg8JT6ycqdWcguxe1jKTWoZVZRR TUJ4zVFxe+i3PnJQ0GfOyaYntjJDabjKzNEGcrBlT+oUk0MEBz2zNpG8cabjeHqho3W7 /R5g== X-Gm-Message-State: APjAAAXFZqGxt/htvkGI5aoZ/5tUz8c7Wk2d/+UH4egCLEyF/3sogHc1 r8vFxt4uP6a/p354YYQOLV58OYeT X-Google-Smtp-Source: APXvYqyeTYWCza9cI+EcxkmdflLPb8DUCRv3Gr0Q7o9JbVRE2n287hDcgutXuYO65batgbp8XtMSBA== X-Received: by 2002:a63:d30f:: with SMTP id b15mr31187152pgg.341.1565640580464; Mon, 12 Aug 2019 13:09:40 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id n26sm110286451pfa.83.2019.08.12.13.09.39 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 12 Aug 2019 13:09:39 -0700 (PDT) From: Andrey Smirnov To: linux-watchdog@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Guenter Roeck , Rick Ramstetter , linux-kernel@vger.kernel.org Subject: [PATCH v2 17/22] watchdog: ziirave_wdt: Fix DOWNLOAD_END payload Date: Mon, 12 Aug 2019 13:09:01 -0700 Message-Id: <20190812200906.31344-18-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190812200906.31344-1-andrew.smirnov@gmail.com> References: <20190812200906.31344-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Bootloader firmware expects the following traffic for DOWNLOAD_END: S Addr Wr [A] 0x11 [A] P using ziirave_firm_write_byte() will result in S Addr Wr [A] 0x11 [A] 0x01 [A] 0x01 [A] P which happens to work because firmware will ignore any extra bytes sent. Fix this by converting the code to use i2c_smbus_write_byte() instead. Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Guenter Roeck Cc: Rick Ramstetter Cc: linux-watchdog@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Guenter Roeck --- drivers/watchdog/ziirave_wdt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/watchdog/ziirave_wdt.c b/drivers/watchdog/ziirave_wdt.c index 0185b9175cc0..a598780d73d3 100644 --- a/drivers/watchdog/ziirave_wdt.c +++ b/drivers/watchdog/ziirave_wdt.c @@ -425,7 +425,7 @@ static int ziirave_firm_upload(struct watchdog_device *wdd, } /* End download operation */ - ret = ziirave_firm_write_byte(wdd, ZIIRAVE_CMD_DOWNLOAD_END, 1, false); + ret = i2c_smbus_write_byte(client, ZIIRAVE_CMD_DOWNLOAD_END); if (ret) { dev_err(&client->dev, "Failed to end firmware download: %d\n", ret); From patchwork Mon Aug 12 20:09:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11090803 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6ABC913B1 for ; Mon, 12 Aug 2019 20:10:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5BD872856B for ; Mon, 12 Aug 2019 20:10:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4FE9C2857B; Mon, 12 Aug 2019 20:10:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F0A3E2856F for ; Mon, 12 Aug 2019 20:10:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727816AbfHLUJo (ORCPT ); Mon, 12 Aug 2019 16:09:44 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:44661 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727781AbfHLUJn (ORCPT ); Mon, 12 Aug 2019 16:09:43 -0400 Received: by mail-pl1-f195.google.com with SMTP id t14so48269338plr.11; Mon, 12 Aug 2019 13:09:42 -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 :mime-version:content-transfer-encoding; bh=GoHqMWoeBEMrIjbLSbTR7or87F8V770ooMxvzxudxeo=; b=pDEMCJ+gUgFE6FzktAdhoi91phyuBXIkv1Op7UAi8GjHzDwM18bQeFm1NnaojggXP8 5cl5Alp2+X1Yiob1XMqYsHJeNm1e8j2rWhvGZ4k4mTJuesue9Xozkm/21rY3EwOfBk9r rhLohCGdss9wFB0oy5sxYFDLuC9GxICOCViBm1RylbuhL/8tQPLKVfdWKgLcDGdyBAI2 9+emwTAtK/QUr1AWhPTXMWug00/kuktSAM2ZWl0Te++LZi9K/UBvd00OfbOSBTSbuia9 kys5YM8ku7PCqC91Ka+liQu8QI6sMM3XZFZqEJYvE3QsOeNoP1H4PwMt/3TcRGAq03A2 K6pA== 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:mime-version:content-transfer-encoding; bh=GoHqMWoeBEMrIjbLSbTR7or87F8V770ooMxvzxudxeo=; b=dn8WL9qeoXJFTJtFrMxZi20B0mB0qIBgPgICLlLqDOEnVQl5QKisGwSun99nltrHh6 SVJW2zKhStFxRgICoZmCAZk+xylzrkBVkGXio6X8PGI9yN6QD4LJ4UjxQvWYlN3dc7D/ 7uzsHC7XLIdm49/uByqB3NRrJU/4SrvkuvKNANyEazPsEl3RNmLmErmvriqK9PRrsc+A 2qL1dY478uEiOG8y/A773cs/5J2i8WKqqknra9ta1daRlM/IaI7RYf4McsOUQ+KrjPVm zwn+z2h9ZdWgZYUAElbn4mlCEcOOOfM5LwHkxneZqoWEO73cMr6XNFViHZZGCPRgoxwi Z+sw== X-Gm-Message-State: APjAAAX+4W0eF9kJGbQOApVMMyiXcR+Ag8G/Rag2K3nytAJb6crynKsd R59dIL5P0F2yM8TPH88vBljBYvvT X-Google-Smtp-Source: APXvYqyaZ3b7dnxh52ixz5DMKHMYp0ySfvRh5bgox/pqOQR0u/zyebMTpeAe//iijAfGSxVWrJ3d7w== X-Received: by 2002:a17:902:9a84:: with SMTP id w4mr33492746plp.160.1565640581949; Mon, 12 Aug 2019 13:09:41 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id n26sm110286451pfa.83.2019.08.12.13.09.40 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 12 Aug 2019 13:09:41 -0700 (PDT) From: Andrey Smirnov To: linux-watchdog@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Guenter Roeck , Rick Ramstetter , linux-kernel@vger.kernel.org Subject: [PATCH v2 18/22] watchdog: ziirave_wdt: Fix RESET_PROCESSOR payload Date: Mon, 12 Aug 2019 13:09:02 -0700 Message-Id: <20190812200906.31344-19-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190812200906.31344-1-andrew.smirnov@gmail.com> References: <20190812200906.31344-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Bootloader firmware expects the following traffic for RESET_PROCESSOR: S Addr Wr [A] 0x0b [A] 0x01 [A] P using ziirave_firm_write_byte() will result in S Addr Wr [A] 0x0b [A] 0x01 [A] 0x01 [A] P which happens to work because firmware will ignore any extra bytes and expected magic value matches byte count sent by i2c_smbus_write_block_data(). Fix this by converting the code to use i2c_smbus_write_byte_data() instead. Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Guenter Roeck Cc: Rick Ramstetter Cc: linux-watchdog@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Guenter Roeck --- drivers/watchdog/ziirave_wdt.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/watchdog/ziirave_wdt.c b/drivers/watchdog/ziirave_wdt.c index a598780d73d3..92df27350e41 100644 --- a/drivers/watchdog/ziirave_wdt.c +++ b/drivers/watchdog/ziirave_wdt.c @@ -73,6 +73,7 @@ static char *ziirave_reasons[] = {"power cycle", "hw watchdog", NULL, NULL, #define ZIIRAVE_CMD_DOWNLOAD_PACKET 0x0e #define ZIIRAVE_CMD_JUMP_TO_BOOTLOADER_MAGIC 1 +#define ZIIRAVE_CMD_RESET_PROCESSOR_MAGIC 1 #define ZIIRAVE_FW_VERSION_FMT "02.%02u.%02u" #define ZIIRAVE_BL_VERSION_FMT "01.%02u.%02u" @@ -433,8 +434,9 @@ static int ziirave_firm_upload(struct watchdog_device *wdd, } /* Reset the processor */ - ret = ziirave_firm_write_byte(wdd, ZIIRAVE_CMD_RESET_PROCESSOR, 1, - false); + ret = i2c_smbus_write_byte_data(client, + ZIIRAVE_CMD_RESET_PROCESSOR, + ZIIRAVE_CMD_RESET_PROCESSOR_MAGIC); if (ret) { dev_err(&client->dev, "Failed to reset the watchdog: %d\n", ret); From patchwork Mon Aug 12 20:09:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11090801 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EE25C112C for ; Mon, 12 Aug 2019 20:10:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD76D2856B for ; Mon, 12 Aug 2019 20:10:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CFDE12857B; Mon, 12 Aug 2019 20:10:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 71A5E2856B for ; Mon, 12 Aug 2019 20:10:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727825AbfHLUJp (ORCPT ); Mon, 12 Aug 2019 16:09:45 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:42790 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727819AbfHLUJo (ORCPT ); Mon, 12 Aug 2019 16:09:44 -0400 Received: by mail-pg1-f196.google.com with SMTP id t132so50030737pgb.9; Mon, 12 Aug 2019 13:09:44 -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 :mime-version:content-transfer-encoding; bh=Y/3NpRbAXSpks6ZVOUgLBx0/AW1xab8Pj1LqMmAn7qo=; b=cJgAvxwGq/F1fGo6TMU9j0IylL76YLy2x522a6bJVRDKi+sykIKq48UoG6VLM+mYOY IaIxesN6lg3pQ46pvA68CocEE49WGIya5aQTsA0c5qqBOthtBeupSqwWFiBZUKZ7257Y 3ZNv+5ywPSRpiQ/lB6Mqi1go+N+fZkEForZbaZQ7q5Ku5zQwdEbQBP7QJEFo9U/jD0wK DCMLVGYv2bYkkKUobJzeK1cJFdKK34c+atOZ4qtO/zA8wLz0LiyDXO/YlQ8dWlo4rLx6 KuqT4/iYymHjpxT3AWZLYA1WYSDL7l//sPngo38Js843laHeZIeuLnNwCQuMHu8xAv56 Nlsw== 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:mime-version:content-transfer-encoding; bh=Y/3NpRbAXSpks6ZVOUgLBx0/AW1xab8Pj1LqMmAn7qo=; b=CT/Uys/Qm6GdWloQTOOypXn/HdPQLx7GSa0VeninVn+Xhd/dEMoh6LR5tjQiZtdZx8 APVwwfQ7M1ViTBQCZIeJp+wT6zHFdBhHLmiBIMzRhUhKRVzxA2B9XzSAYIqR6pIhEHXb q8+K57HAGdLUDRwYAI/YRSLfU8K8XxPLtwscAMyrrqPH/+LWv1uvIwsB1H5tdOkP3zga 8zE1xxP2Xg3ZVjL9zA30/DkAJPDUOElMUvwzFp8+4X1a5dcrTOiHhMP/locBFkWPSiOY cryZ6eEoYKregjPs54XFMJzivk3bq5KzfPfC1NnJ3V/v1NFcEyHxlxPRwtyEYdHyjl0a VJ0A== X-Gm-Message-State: APjAAAVos5lqU30rG3RvWxpUoccgaJVsm4mcpvu/bU6p+XsaL/4c/1BH VGvDSs8wvT5PTnVeyAY37zIdJ+L7 X-Google-Smtp-Source: APXvYqzIJEo6XNER7IickBgoo+WdjfCIkgTxZCbeOfkljfSLpaPoSt0L/fKA8CgG8R2YuKBmC7wfJQ== X-Received: by 2002:a17:90a:c24e:: with SMTP id d14mr919163pjx.129.1565640583255; Mon, 12 Aug 2019 13:09:43 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id n26sm110286451pfa.83.2019.08.12.13.09.41 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 12 Aug 2019 13:09:42 -0700 (PDT) From: Andrey Smirnov To: linux-watchdog@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Guenter Roeck , Rick Ramstetter , linux-kernel@vger.kernel.org Subject: [PATCH v2 19/22] watchdog: ziirave_wdt: Drop status polling code Date: Mon, 12 Aug 2019 13:09:03 -0700 Message-Id: <20190812200906.31344-20-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190812200906.31344-1-andrew.smirnov@gmail.com> References: <20190812200906.31344-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Bootloader firmware doesn't implement DOWNLOAD_START or DOWNLOAD_PACKET in a non-blocking way. It will stretch the clock of the first status byte read until the operation is complete. Polling for the status is not really necessary since it will always succed on the first try. Replace polling code with a simple single byte read to simplify things. Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Guenter Roeck Cc: Rick Ramstetter Cc: linux-watchdog@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Guenter Roeck --- drivers/watchdog/ziirave_wdt.c | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/drivers/watchdog/ziirave_wdt.c b/drivers/watchdog/ziirave_wdt.c index 92df27350e41..681f65349779 100644 --- a/drivers/watchdog/ziirave_wdt.c +++ b/drivers/watchdog/ziirave_wdt.c @@ -57,11 +57,6 @@ static char *ziirave_reasons[] = {"power cycle", "hw watchdog", NULL, NULL, /* Received and ready for next Download packet. */ #define ZIIRAVE_FIRM_DOWNLOAD_ACK 1 -/* Currently writing to flash. Retry Download status in a moment! */ -#define ZIIRAVE_FIRM_DOWNLOAD_BUSY 2 - -/* Wait for ACK timeout in ms */ -#define ZIIRAVE_FIRM_WAIT_FOR_ACK_TIMEOUT 50 /* Firmware commands */ #define ZIIRAVE_CMD_DOWNLOAD_START 0x10 @@ -175,25 +170,16 @@ static unsigned int ziirave_wdt_get_timeleft(struct watchdog_device *wdd) return ret; } -static int ziirave_firm_wait_for_ack(struct watchdog_device *wdd) +static int ziirave_firm_read_ack(struct watchdog_device *wdd) { struct i2c_client *client = to_i2c_client(wdd->parent); int ret; - unsigned long timeout; - - timeout = jiffies + msecs_to_jiffies(ZIIRAVE_FIRM_WAIT_FOR_ACK_TIMEOUT); - do { - if (time_after(jiffies, timeout)) - return -ETIMEDOUT; - usleep_range(5000, 10000); - - ret = i2c_smbus_read_byte(client); - if (ret < 0) { - dev_err(&client->dev, "Failed to read byte\n"); - return ret; - } - } while (ret == ZIIRAVE_FIRM_DOWNLOAD_BUSY); + ret = i2c_smbus_read_byte(client); + if (ret < 0) { + dev_err(&client->dev, "Failed to read status byte\n"); + return ret; + } return ret == ZIIRAVE_FIRM_DOWNLOAD_ACK ? 0 : -EIO; } @@ -226,7 +212,7 @@ static int ziirave_firm_write_block_data(struct watchdog_device *wdd, } if (wait_for_ack) - ret = ziirave_firm_wait_for_ack(wdd); + ret = ziirave_firm_read_ack(wdd); return ret; } From patchwork Mon Aug 12 20:09:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11090799 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 67DE51398 for ; Mon, 12 Aug 2019 20:10:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 561002856F for ; Mon, 12 Aug 2019 20:10:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 47E172856B; Mon, 12 Aug 2019 20:10:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DBCC42856B for ; Mon, 12 Aug 2019 20:10:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727828AbfHLUJp (ORCPT ); Mon, 12 Aug 2019 16:09:45 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:35062 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727496AbfHLUJp (ORCPT ); Mon, 12 Aug 2019 16:09:45 -0400 Received: by mail-pl1-f195.google.com with SMTP id w24so48288655plp.2; Mon, 12 Aug 2019 13:09:45 -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 :mime-version:content-transfer-encoding; bh=RxWEj5XMwOhp9jEr2BxVYNQrB7abAMc2i7oVzlWuaws=; b=WD2YxYTpoBV1JC+G2nKak6sdXHA3qCJi8wJA+7zeuD5M9aSSf2wmtsl7QzQ+A5qvkc xO0ZSxarhAiHUXECiVGFUAC1TlEbB/a7xbmV5Nn0pJeUW9Uma32kSsnMmusKqax0mScI CrRBdipJJkm4hbLzXtIOBikrtq1qpHct/m4rSH9b1wprYKGw1MFzEOPtiCenFBYIBD5A sPDnypOwlfaaAt6FarR544rmqr1l9Y6YFOsHUMQNlgKhgJfv5MVDrlpuZvLpuWkJeCx2 BwJu1LCwCtT0JjhYyqQG0RynzwzRSNYOh+Jl7oNKCBynZyo/RqTrwYguMaM25ZiOGXqG hYzw== 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:mime-version:content-transfer-encoding; bh=RxWEj5XMwOhp9jEr2BxVYNQrB7abAMc2i7oVzlWuaws=; b=fm3AD7giNxJh+Totymbx/nJLxkNhxKJpWxpCkD4Uwezv9MEKpKMs4MWCW3P1zX/rIe 7YTiZZG1ndUm5pNzTHQvc7yOi41cH2qiEO61OCHxn8DBStiNkgBrYlcFRTp2omdKn7xa L3iChPsypmuU7+0HbTG0W7RwpdhAHKb/az7DCIPSPQSBE1MX1emUq8CoFi/+HE5oiZK+ MPr2FEoIegBE/7qjq21guz4wwZbUJiuN6cGV6rR9Teq/3IS/etUydWsmUwFUxQqxC+C7 AEG0ITmIHr7AetrfVAYJHYsi6SaPoGMg8TpgHNMYQGIamG4hdseojIXumM57frTH/NrQ r5SA== X-Gm-Message-State: APjAAAXHBfuU5A2VrMkX0/fjj2QZ/T6jZjmJ1hAdxSYzBFDBQCxAVPMZ td3Yi72JvHcwTVmMFeQ9DS1LP0G7 X-Google-Smtp-Source: APXvYqzkSsXZeoXM7L24AckIu+2acToD1OycG49Ca+NmMtt6Bk0QCXvBSoK2nsomtXYmVCPZ71OIfw== X-Received: by 2002:a17:902:100a:: with SMTP id b10mr33728350pla.338.1565640584405; Mon, 12 Aug 2019 13:09:44 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id n26sm110286451pfa.83.2019.08.12.13.09.43 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 12 Aug 2019 13:09:43 -0700 (PDT) From: Andrey Smirnov To: linux-watchdog@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Guenter Roeck , Rick Ramstetter , linux-kernel@vger.kernel.org Subject: [PATCH v2 20/22] watchdog: ziirave_wdt: Fix DOWNLOAD_START payload Date: Mon, 12 Aug 2019 13:09:04 -0700 Message-Id: <20190812200906.31344-21-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190812200906.31344-1-andrew.smirnov@gmail.com> References: <20190812200906.31344-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Bootloader firmware expects the following traffic for DOWNLOAD_END: S Addr Wr [A] 0x10 [A] P using ziirave_firm_write_byte() will result in S Addr Wr [A] 0x10 [A] 0x01 [A] 0x01 [A] P which happens to work because firmware will ignore any extra bytes sent. Fix this by converting the code to use i2c_smbus_write_byte() instead. Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Guenter Roeck Cc: Rick Ramstetter Cc: linux-watchdog@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Guenter Roeck --- drivers/watchdog/ziirave_wdt.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/watchdog/ziirave_wdt.c b/drivers/watchdog/ziirave_wdt.c index 681f65349779..ed69fa82e09c 100644 --- a/drivers/watchdog/ziirave_wdt.c +++ b/drivers/watchdog/ziirave_wdt.c @@ -217,13 +217,6 @@ static int ziirave_firm_write_block_data(struct watchdog_device *wdd, return ret; } -static int ziirave_firm_write_byte(struct watchdog_device *wdd, u8 command, - u8 byte, bool wait_for_ack) -{ - return ziirave_firm_write_block_data(wdd, command, 1, &byte, - wait_for_ack); -} - static bool ziirave_firm_addr_readonly(u32 addr) { return addr < ZIIRAVE_FIRM_FLASH_MEMORY_START || @@ -375,12 +368,18 @@ static int ziirave_firm_upload(struct watchdog_device *wdd, msleep(500); - ret = ziirave_firm_write_byte(wdd, ZIIRAVE_CMD_DOWNLOAD_START, 1, true); + ret = i2c_smbus_write_byte(client, ZIIRAVE_CMD_DOWNLOAD_START); if (ret) { dev_err(&client->dev, "Failed to start download\n"); return ret; } + ret = ziirave_firm_read_ack(wdd); + if (ret) { + dev_err(&client->dev, "No ACK for start download\n"); + return ret; + } + msleep(500); for (rec = (void *)fw->data; rec; rec = ihex_next_binrec(rec)) { From patchwork Mon Aug 12 20:09:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11090795 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 90E5D1398 for ; Mon, 12 Aug 2019 20:09:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 819142856B for ; Mon, 12 Aug 2019 20:09:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 75BA02857B; Mon, 12 Aug 2019 20:09:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D1A02856B for ; Mon, 12 Aug 2019 20:09:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727843AbfHLUJr (ORCPT ); Mon, 12 Aug 2019 16:09:47 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:34706 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727832AbfHLUJq (ORCPT ); Mon, 12 Aug 2019 16:09:46 -0400 Received: by mail-pl1-f196.google.com with SMTP id i2so48333008plt.1; Mon, 12 Aug 2019 13:09:46 -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 :mime-version:content-transfer-encoding; bh=G3aE0HR7FH8dxZEfkREqg9dVCNPdu5b7189bsJL1s1I=; b=VyJrl7Ydz3J26svxaTUS+WXyPZFZyX6onCknUDHWfh3YZrXjzwb6N7C8QDOQeZgv0l Jcv+4p5v5/UBKLMfJZ7/S7jXpfbrqRwhNbgGeJY/3jZ25jFOlJLkVqFH1B4/vJ1yB4ac KjVum2kt3pONCmil63qjxxe//95Y+3NKPNYaFU2hfZ/ye+kMXaV6eKhNn1wY+ts7hNvV ++oop01X74XIhItmvH6ZmKEoK+0uQ33iNDvLtATHyeaCuN7sr5gguixciutmyHHpy1di 8QtHR5AByJ+auXIggRAfO2sGXlEPkhVKCyzxOAHMU+qgekXGsw2lDNaSKqdjSnVnoPRG IjEw== 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:mime-version:content-transfer-encoding; bh=G3aE0HR7FH8dxZEfkREqg9dVCNPdu5b7189bsJL1s1I=; b=XN5oZZvb9F46UIMwIMRBQ/Ed4i8ZC1YsHKMyNNfB6kPGdU99D/pB4FH9XNKqQeieWi CREFjxkbe4m8SH/qbH31wfePmQQefA/leS9fIi745nwF1V88AO/nRzVJN0siQSmn099w WU/i0IitZNVc7s+MleEsOaQfkdEFZIpFz93smMu7Ua2NsIQT7RJF8lA8WQpDAp4ciqc1 p0scmFfNU+/3WgBnuJmfH74kn44dWQZx87BUTU+Ka+0o/8dBpUZnU2KOIMmBviHNqrxH YaCWpJUBpQTk4A6TD74jBrfkhBEkZjpr19J2rSng1+G1b4Ru1a7VQy7ummEClUvrkahH TbRA== X-Gm-Message-State: APjAAAU/Xy2dyadJNNRY3bvmkb/+jqF3dVYkq/3KtLDCdwq4cakVNE1i Crm8wQujKqni691tbTbhoGs/drnj X-Google-Smtp-Source: APXvYqzC5WkgKM6qxhcGrKVd7zOiPyHZItfP6NE4i8jBUw8R8pdqODfSOlB82hwMuHUFAHFO/GGcMw== X-Received: by 2002:a17:902:be01:: with SMTP id r1mr14556016pls.229.1565640585591; Mon, 12 Aug 2019 13:09:45 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id n26sm110286451pfa.83.2019.08.12.13.09.44 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 12 Aug 2019 13:09:44 -0700 (PDT) From: Andrey Smirnov To: linux-watchdog@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Guenter Roeck , Rick Ramstetter , linux-kernel@vger.kernel.org Subject: [PATCH v2 21/22] watchdog: ziirave_wdt: Drop ziirave_firm_write_block_data() Date: Mon, 12 Aug 2019 13:09:05 -0700 Message-Id: <20190812200906.31344-22-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190812200906.31344-1-andrew.smirnov@gmail.com> References: <20190812200906.31344-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There's only one user of ziirave_firm_write_block_data(), so we may as well inline it. Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Guenter Roeck Cc: Rick Ramstetter Cc: linux-watchdog@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Guenter Roeck --- drivers/watchdog/ziirave_wdt.c | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/drivers/watchdog/ziirave_wdt.c b/drivers/watchdog/ziirave_wdt.c index ed69fa82e09c..48278034cda6 100644 --- a/drivers/watchdog/ziirave_wdt.c +++ b/drivers/watchdog/ziirave_wdt.c @@ -197,26 +197,6 @@ static int ziirave_firm_set_read_addr(struct watchdog_device *wdd, u32 addr) sizeof(address), address); } -static int ziirave_firm_write_block_data(struct watchdog_device *wdd, - u8 command, u8 length, const u8 *data, - bool wait_for_ack) -{ - struct i2c_client *client = to_i2c_client(wdd->parent); - int ret; - - ret = i2c_smbus_write_block_data(client, command, length, data); - if (ret) { - dev_err(&client->dev, - "Failed to send command 0x%02x: %d\n", command, ret); - return ret; - } - - if (wait_for_ack) - ret = ziirave_firm_read_ack(wdd); - - return ret; -} - static bool ziirave_firm_addr_readonly(u32 addr) { return addr < ZIIRAVE_FIRM_FLASH_MEMORY_START || @@ -273,8 +253,15 @@ static int __ziirave_firm_write_pkt(struct watchdog_device *wdd, checksum += packet[i]; packet[ZIIRAVE_FIRM_PKT_TOTAL_SIZE - 1] = checksum; - ret = ziirave_firm_write_block_data(wdd, ZIIRAVE_CMD_DOWNLOAD_PACKET, - sizeof(packet), packet, true); + ret = i2c_smbus_write_block_data(client, ZIIRAVE_CMD_DOWNLOAD_PACKET, + sizeof(packet), packet); + if (ret) { + dev_err(&client->dev, + "Failed to send DOWNLOAD_PACKET: %d\n", ret); + return ret; + } + + ret = ziirave_firm_read_ack(wdd); if (ret) dev_err(&client->dev, "Failed to write firmware packet at address 0x%04x: %d\n", From patchwork Mon Aug 12 20:09:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11090797 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5AD2E112C for ; Mon, 12 Aug 2019 20:09:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 433812857B for ; Mon, 12 Aug 2019 20:09:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 35A2A2857E; Mon, 12 Aug 2019 20:09:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA6032857B for ; Mon, 12 Aug 2019 20:09:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727874AbfHLUJy (ORCPT ); Mon, 12 Aug 2019 16:09:54 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:37942 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727845AbfHLUJr (ORCPT ); Mon, 12 Aug 2019 16:09:47 -0400 Received: by mail-pl1-f195.google.com with SMTP id m12so9677874plt.5; Mon, 12 Aug 2019 13:09:47 -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 :mime-version:content-transfer-encoding; bh=rSn4tuKZh7KjRckQWxe8eHwjIPe1tvzNwIGDPWFexuA=; b=L85U5s9VnXBzPRt7PgMVfUXCp3mUWeCz2zIrBHDPgy2M3a5LA7zC548ijnAqRUvFMi B3QeuoZVIRyryI/cj7631lBmjkirVO6hsqZNDgtmYVGOr9k7JTDPEou2wifbSQjUoap+ xXq7Y0NEPJb7i4Y5GSFFwzs9ia/fUIDv1HAKEmpm/emMwWaFa2Yro24/SHjAiYAQs36i iak/u2OedUbaT8jZV5bpsNnCUKP9TLxEBdJTRzdYweF8SFQFcJ3JZHKit/tmlT9BVZ6c 1daQLqR5uEhDuCeU1uwzs/sgTGKsXyfsSBWb1Cu6ztz9n6fdDMau9GFpNxK8ABFCzywT PJzg== 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:mime-version:content-transfer-encoding; bh=rSn4tuKZh7KjRckQWxe8eHwjIPe1tvzNwIGDPWFexuA=; b=lWvPZuOdKwl7gePZzC4tjKbGk3S9lq0qks/Ut+/bnxvucoqLO7vLVhIqWsnaSA0vTD Cq/UR4Xe8j/aOLbI/kwSfjRlxtCIa4zze5mDYZXMMVkrqqoNvBjoYX5OAYP8I1qw8dcA 24HpVjD41dSXOhPZpwoJS1zB/2lsLzjahAUoVFn3MeLNSTkTf+Gl1imZGeD7mwaePvkj s9WsSH0u8y0a+WKy9XgPqpOdV6Ve6qaOuDgN9XnIbDJA+mXjgD/D0ac5Rpq/NlCvKmIP WQNke2lD+kLE9+wWa1o2vsC1RQDjvnGD1YM9FNhxsWXlXcVP7NtkT+tHbYCP7CL278kT Xbxw== X-Gm-Message-State: APjAAAUvOrxEtwfGX+95ucTPmCm1ez9hTFOjyZzxrm0jdF6AQapM64qB 4rER33AlIskJndZxWtvNr1nSoMl7 X-Google-Smtp-Source: APXvYqxgLPHrsjbeN3KKiZy1HL5N9Jye7eNgNXlR2sJEh5MyAo6nY8jKCeWFYGX34RD1zRgDOIFTdA== X-Received: by 2002:a17:902:b202:: with SMTP id t2mr6440736plr.303.1565640586869; Mon, 12 Aug 2019 13:09:46 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id n26sm110286451pfa.83.2019.08.12.13.09.45 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 12 Aug 2019 13:09:46 -0700 (PDT) From: Andrey Smirnov To: linux-watchdog@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Guenter Roeck , Rick Ramstetter , linux-kernel@vger.kernel.org Subject: [PATCH v2 22/22] watchdog: ziirave_wdt: Update checked I2C functionality mask Date: Mon, 12 Aug 2019 13:09:06 -0700 Message-Id: <20190812200906.31344-23-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190812200906.31344-1-andrew.smirnov@gmail.com> References: <20190812200906.31344-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Update checked I2C functionality mask to reflect all of the SMBus primitives used by this driver. Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Guenter Roeck Cc: Rick Ramstetter Cc: linux-watchdog@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Guenter Roeck --- drivers/watchdog/ziirave_wdt.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/watchdog/ziirave_wdt.c b/drivers/watchdog/ziirave_wdt.c index 48278034cda6..4a363a8b2d20 100644 --- a/drivers/watchdog/ziirave_wdt.c +++ b/drivers/watchdog/ziirave_wdt.c @@ -602,7 +602,10 @@ static int ziirave_wdt_probe(struct i2c_client *client, struct ziirave_wdt_data *w_priv; int val; - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) + if (!i2c_check_functionality(client->adapter, + I2C_FUNC_SMBUS_BYTE | + I2C_FUNC_SMBUS_BYTE_DATA | + I2C_FUNC_SMBUS_WRITE_BLOCK_DATA)) return -ENODEV; w_priv = devm_kzalloc(&client->dev, sizeof(*w_priv), GFP_KERNEL);