From patchwork Wed Feb 17 19:07:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Life is hard, and then you die" X-Patchwork-Id: 12092073 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F11FC433E0 for ; Wed, 17 Feb 2021 19:20:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E900664E68 for ; Wed, 17 Feb 2021 19:20:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232650AbhBQTTm (ORCPT ); Wed, 17 Feb 2021 14:19:42 -0500 Received: from ec2-44-228-98-151.us-west-2.compute.amazonaws.com ([44.228.98.151]:58896 "EHLO chill.innovation.ch" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232548AbhBQTTg (ORCPT ); Wed, 17 Feb 2021 14:19:36 -0500 Received: from localhost (localhost [127.0.0.1]) by chill.innovation.ch (Postfix) with ESMTP id 423071B6410; Wed, 17 Feb 2021 19:07:31 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at chill.innovation.ch Received: from chill.innovation.ch ([127.0.0.1]) by localhost (chill.innovation.ch [127.0.0.1]) (amavisd-new, port 10024) with LMTP id gTv6AwvRv-QZ; Wed, 17 Feb 2021 19:07:30 +0000 (UTC) From: =?utf-8?q?Ronald_Tschal=C3=A4r?= DKIM-Filter: OpenDKIM Filter v2.11.0 chill.innovation.ch B782B1B5EA9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=innovation.ch; s=default; t=1613588850; bh=kG3doMqYTJAWa6Cik1eP36mmnCuyDrLmpJlt/5Wwi6s=; h=From:To:Cc:Subject:Date:From; b=Ry5z7xRdtVseBSrzLncqrNUO2Jpldl3OV6yCb2Q5YOI5emoBTaN8z7cx18X4oroVg O0bqaRIenMC6nzDk9bLaJ0uf50PpGQ9QeSu+P2bUL2qlNhc6svieDbgTxBf2BL2tXU ui9z0F0yw1y+sD1CDB/DU1oJCcdG0L4QrmrF0RPNpo3aLyH7+LsLX9RtaVVDNupnW8 K0NDYUXmaUuSFdxugvvdiQs/q591YOK+1c3/gjHeNkOS9cvwiC460aZM2NdRkMutGL 0xt+9EcqNsAXi/esy3r6Gf3ulmz/WaYcRtKzI7tGEEgZO1zGrbpN309c0EStKj5+N7 bHm0rXznNNiXg== To: Dmitry Torokhov Cc: "Gustavo A. R. Silva" , Sergiu Cuciurean , Lee Jones , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] Input: applespi: Don't wait for responses to commands indefinitely. Date: Wed, 17 Feb 2021 11:07:16 -0800 Message-Id: <20210217190718.11035-1-ronald@innovation.ch> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org The response to a command may never arrive or it may be corrupted (and hence dropped) for some reason. While exceedingly rare, when it did happen it blocked all further commands. One way to fix this was to do a suspend/resume. However, recovering automatically seems like a nicer option. Hence this puts a time limit (1 sec) on how long we're willing to wait for a response, after which we assume it got lost. Signed-off-by: Ronald Tschalär --- drivers/input/keyboard/applespi.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/input/keyboard/applespi.c b/drivers/input/keyboard/applespi.c index d22223154177f..8494bf610fd70 100644 --- a/drivers/input/keyboard/applespi.c +++ b/drivers/input/keyboard/applespi.c @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include @@ -409,7 +410,7 @@ struct applespi_data { unsigned int cmd_msg_cntr; /* lock to protect the above parameters and flags below */ spinlock_t cmd_msg_lock; - bool cmd_msg_queued; + ktime_t cmd_msg_queued; enum applespi_evt_type cmd_evt_type; struct led_classdev backlight_info; @@ -729,7 +730,7 @@ static void applespi_msg_complete(struct applespi_data *applespi, wake_up_all(&applespi->drain_complete); if (is_write_msg) { - applespi->cmd_msg_queued = false; + applespi->cmd_msg_queued = 0; applespi_send_cmd_msg(applespi); } @@ -771,8 +772,16 @@ static int applespi_send_cmd_msg(struct applespi_data *applespi) return 0; /* check whether send is in progress */ - if (applespi->cmd_msg_queued) - return 0; + if (applespi->cmd_msg_queued) { + if (ktime_ms_delta(ktime_get(), applespi->cmd_msg_queued) < 1000) + return 0; + + dev_warn(&applespi->spi->dev, "Command %d timed out\n", + applespi->cmd_evt_type); + + applespi->cmd_msg_queued = 0; + applespi->write_active = false; + } /* set up packet */ memset(packet, 0, APPLESPI_PACKET_SIZE); @@ -869,7 +878,7 @@ static int applespi_send_cmd_msg(struct applespi_data *applespi) return sts; } - applespi->cmd_msg_queued = true; + applespi->cmd_msg_queued = ktime_get(); applespi->write_active = true; return 0; @@ -1921,7 +1930,7 @@ static int __maybe_unused applespi_resume(struct device *dev) applespi->drain = false; applespi->have_cl_led_on = false; applespi->have_bl_level = 0; - applespi->cmd_msg_queued = false; + applespi->cmd_msg_queued = 0; applespi->read_active = false; applespi->write_active = false; From patchwork Wed Feb 17 19:07:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Life is hard, and then you die" X-Patchwork-Id: 12092071 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85B59C433E0 for ; Wed, 17 Feb 2021 19:19:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 505E064E6C for ; Wed, 17 Feb 2021 19:19:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232413AbhBQTTO (ORCPT ); Wed, 17 Feb 2021 14:19:14 -0500 Received: from ec2-44-228-98-151.us-west-2.compute.amazonaws.com ([44.228.98.151]:58882 "EHLO chill.innovation.ch" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232548AbhBQTTN (ORCPT ); Wed, 17 Feb 2021 14:19:13 -0500 Received: from localhost (localhost [127.0.0.1]) by chill.innovation.ch (Postfix) with ESMTP id 9600C1B6411; Wed, 17 Feb 2021 19:07:31 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at chill.innovation.ch Received: from chill.innovation.ch ([127.0.0.1]) by localhost (chill.innovation.ch [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 6nrywUIMZ8Du; Wed, 17 Feb 2021 19:07:31 +0000 (UTC) From: =?utf-8?q?Ronald_Tschal=C3=A4r?= DKIM-Filter: OpenDKIM Filter v2.11.0 chill.innovation.ch E8A221B640F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=innovation.ch; s=default; t=1613588851; bh=qcHkDiWeuZJwaE8KC5P4fY1TNb7Og+nXRokLCY5UEZY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fn87dt6iKXKD/mZFkNdDq702zSjtc8dJjGOULqt1mchETIXEIRPxLPqht9FhdJp0a vtQrCDZ+La77bSTBMsdK26hb3ymmblOPAEY32vmIZheYJXm93yDwTQAqCVnQCXTcFU A8HQUTOLsf2SC3rR0dZHV+P4OTs2NliMurUv1LuLA7H9DnK5nD7GjpHN27uuyCgQno QrJWfTFsnBruRUWHKEct+CTa+Gm0VeqqfsmeC1nUXJuJQA+vSBtdXwLK1mqti0da7F br0Zoo+9IuPdTVdAao0Sjnkg3cHaf37usfl8jp2xSlSuXJvOWrGgTORLxEth3KSfbQ /l0G6Vr7jvw7Q== To: Dmitry Torokhov Cc: "Gustavo A. R. Silva" , Sergiu Cuciurean , Lee Jones , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] Input: applespi: Fix occasional crc errors under load. Date: Wed, 17 Feb 2021 11:07:17 -0800 Message-Id: <20210217190718.11035-2-ronald@innovation.ch> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210217190718.11035-1-ronald@innovation.ch> References: <20210217190718.11035-1-ronald@innovation.ch> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org For some reason, when the system is under heavy CPU load, the read following the write sometimes occurs unusually quickly, resulting in the read data not being quite ready and hence a bad packet getting read. Adding another delay after reading the status message appears to fix this. Signed-off-by: Ronald Tschalär --- drivers/input/keyboard/applespi.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/input/keyboard/applespi.c b/drivers/input/keyboard/applespi.c index 8494bf610fd70..f0a0067c48ff6 100644 --- a/drivers/input/keyboard/applespi.c +++ b/drivers/input/keyboard/applespi.c @@ -749,6 +749,8 @@ static void applespi_async_write_complete(void *context) applespi->tx_status, APPLESPI_STATUS_SIZE); + udelay(SPI_RW_CHG_DELAY_US); + if (!applespi_check_write_status(applespi, applespi->wr_m.status)) { /* * If we got an error, we presumably won't get the expected From patchwork Wed Feb 17 19:07:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Life is hard, and then you die" X-Patchwork-Id: 12092069 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44BEEC433E0 for ; Wed, 17 Feb 2021 19:19:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0A53764E63 for ; Wed, 17 Feb 2021 19:19:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232367AbhBQTTO (ORCPT ); Wed, 17 Feb 2021 14:19:14 -0500 Received: from ec2-44-228-98-151.us-west-2.compute.amazonaws.com ([44.228.98.151]:58878 "EHLO chill.innovation.ch" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232547AbhBQTTN (ORCPT ); Wed, 17 Feb 2021 14:19:13 -0500 X-Greylist: delayed 651 seconds by postgrey-1.27 at vger.kernel.org; Wed, 17 Feb 2021 14:19:10 EST Received: from localhost (localhost [127.0.0.1]) by chill.innovation.ch (Postfix) with ESMTP id 30D451B640F; Wed, 17 Feb 2021 19:07:32 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at chill.innovation.ch Received: from chill.innovation.ch ([127.0.0.1]) by localhost (chill.innovation.ch [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 7BxdjnFa6Gfu; Wed, 17 Feb 2021 19:07:31 +0000 (UTC) From: =?utf-8?q?Ronald_Tschal=C3=A4r?= DKIM-Filter: OpenDKIM Filter v2.11.0 chill.innovation.ch 77B491B5EA9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=innovation.ch; s=default; t=1613588851; bh=NTnBPdcPQ1mHAuBRtKTt9xZ5SgKJhiroAKknFH1WnTw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bjhz7O0GLjLTNOkGgBYYRnp9CBqiOsET9xfFY56qDsSxdHc7lpTIB8Nj5s8g0RGiX 4cJVGHvCZEkrfhaBvjueFaVDAUkMpdFoJVy+Ja9LoShKKssBoRdTneci9h3uTS/MIs NzrN6crorswasrDXGxzyydNVitahKYpClQ94koL7C9R554dJ38Y24OL87PrDWrci3S St0BCcJNP4kf06+0CipaFtNK2VwQ/kDrHG4g+v6UuA/cdT5eBqXFWlJd60NmbUk75+ ecC4d/6YGdC+ieNIb8JW15fcHsEpG+1NTvFW7NfbYc63ZIJkUVDiGlabMqH9Y52S2c wR4lmGJm+vm/g== To: Dmitry Torokhov Cc: "Gustavo A. R. Silva" , Sergiu Cuciurean , Lee Jones , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] Input: applespi: Add trace_event module param for early tracing. Date: Wed, 17 Feb 2021 11:07:18 -0800 Message-Id: <20210217190718.11035-3-ronald@innovation.ch> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210217190718.11035-1-ronald@innovation.ch> References: <20210217190718.11035-1-ronald@innovation.ch> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org The problem is that tracing can't be set via sysfs until the module is loaded, at which point the keyboard and trackpad initialization commands have already been run and hence tracing can't be used to debug problems here. Adding this param allows tracing to be enabled for messages sent and received during module probing. It takes comma-separated list of events, e.g. trace_event=applespi_tp_ini_cmd,applespi_bad_crc Signed-off-by: Ronald Tschalär Reported-by: kernel test robot Reported-by: kernel test robot --- drivers/input/keyboard/applespi.c | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/drivers/input/keyboard/applespi.c b/drivers/input/keyboard/applespi.c index f0a0067c48ff6..03f9ad0f83967 100644 --- a/drivers/input/keyboard/applespi.c +++ b/drivers/input/keyboard/applespi.c @@ -53,6 +53,8 @@ #include #include #include +#include +#include #include #include @@ -110,6 +112,10 @@ module_param_string(touchpad_dimensions, touchpad_dimensions, sizeof(touchpad_dimensions), 0444); MODULE_PARM_DESC(touchpad_dimensions, "The pixel dimensions of the touchpad, as XxY+W+H ."); +static char *trace_event; +module_param(trace_event, charp, 0444); +MODULE_PARM_DESC(trace_event, "Enable early event tracing. It takes the form of a comma-separated list of events to enable."); + /** * struct keyboard_protocol - keyboard message. * message.type = 0x0110, message.length = 0x000a @@ -1645,6 +1651,30 @@ static void applespi_save_bl_level(struct applespi_data *applespi, "Error saving backlight level to EFI vars: %d\n", sts); } +static void applespi_enable_early_event_tracing(struct device *dev) +{ + char *buf, *event; + int sts; + + if (trace_event && trace_event[0]) { + buf = kstrdup(trace_event, GFP_KERNEL); + if (!buf) + return; + + while ((event = strsep(&buf, ","))) { + if (event[0]) { + sts = trace_set_clr_event("applespi", event, 1); + if (sts) + dev_warn(dev, + "Error setting trace event '%s': %d\n", + event, sts); + } + } + + kfree(buf); + } +} + static int applespi_probe(struct spi_device *spi) { struct applespi_data *applespi; @@ -1653,6 +1683,8 @@ static int applespi_probe(struct spi_device *spi) int sts, i; unsigned long long gpe, usb_status; + applespi_enable_early_event_tracing(&spi->dev); + /* check if the USB interface is present and enabled already */ acpi_sts = acpi_evaluate_integer(spi_handle, "UIST", NULL, &usb_status); if (ACPI_SUCCESS(acpi_sts) && usb_status) {