From patchwork Fri May 10 22:34:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 10939659 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 6954F1575 for ; Fri, 10 May 2019 22:35:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 581031FF29 for ; Fri, 10 May 2019 22:35:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4CB881FF3E; Fri, 10 May 2019 22:35:24 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EFF311FF30 for ; Fri, 10 May 2019 22:35:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=IuYkjkUbxTiCnzg/CggrCVNHarbgE0nhlFHMkTk6UMk=; b=ds/AEczzM/vgz5 olk196wj0cVWk9Dxr9k4m+mXcEpVFy5E+oC9E4ZRu0vO/JerC/TYaFTBu0a6iXCWGTWZAMBSuKdh3 aI7gfEK5xdn4a10p8yh9SVeRQSDwlagdl/F94PML9+YhRKYlJN/kfjLFiBTgBFWgzHtX5EBcSPcNs kVDirQ1lGMS7dnZJA2iNphEYL8IRM4E7y62uKzoWc6B4DfhoZkQcJNFQpMISGzNq83zUrXmDUdJuC 0XX4YsqQmN40SwjTf/K5AomeQ8gMAzVVKMDyuPQr+mPNm5k4Kzr7LY7OVwnBU7lFFedSuNlfgUfH5 fgABUpLuBEZzaiiXS2uw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hPE6m-0005H5-Ib; Fri, 10 May 2019 22:35:16 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hPE6i-0005F5-Ve for linux-rockchip@lists.infradead.org; Fri, 10 May 2019 22:35:14 +0000 Received: by mail-pg1-x544.google.com with SMTP id t22so3645630pgi.10 for ; Fri, 10 May 2019 15:35:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hV5HxwGs7gY03wK3rK8o6uhUFP9lcwaLtj0H4FYh2dk=; b=lTuSMAv25fNL9J/QKC0HQ9qmLRckYs3hBlUXs/+YYhydsEvcq+SyATaNCV1rCMDz89 BSTK5DP0LEnWSGUhOyGTr7I5U8Bw2WIhDsXgnfcmHVBa9ofbOBqOcP7XWDZOJDMDbQga 4Sw5ibIdQSa7/HY4XS9y5VByC3g0GUYAx2VI8= 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=hV5HxwGs7gY03wK3rK8o6uhUFP9lcwaLtj0H4FYh2dk=; b=hsFbatcMiqKM1xuW/a1YvivR87U2xhgFZW3T4ffIcd0DCYvu8agmnpeAAajzQn55po n7c8qhN125a/o8vheRYoJflagQ70FNC2Yac/t8M7L8A7oLAv2GZtiA7npvOHZk+FSIIh o2Q2Ul5ZNmf5M9y26NLjONDGh1B+z91zCeEOjN/VXq52AgtQ54ee2pdPsSAFZVYv418f EhO+FoGzXwGLlL27J85QPmyS6CQPqs2K7Ih4qlQfYOsqzLe+ZzQiIVv1WntF0VRWFQsQ rfQn6u1x9iTIBei3eo7uw0iK4HkiqJbztGA0+TQbpV/SSFieAxc0H+8xn/68YaQemqov 7oXg== X-Gm-Message-State: APjAAAWb8gSZw1HUj2odnkx3bqGxj0Qw7sMzPnNu0gfa9qnBKn/YfBIj dzzq9bO6Racfh1NuEin6VX8ROw== X-Google-Smtp-Source: APXvYqx00UvXi9LVlDxBQ/qgIeKHowFgu4na2sTLOT4tSNXiduy9+oOD4eLycJ+CqSEWgmcp1mI+eQ== X-Received: by 2002:a65:4c86:: with SMTP id m6mr16401970pgt.75.1557527712392; Fri, 10 May 2019 15:35:12 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:24fa:e766:52c9:e3b2]) by smtp.gmail.com with ESMTPSA id j6sm7689393pfe.107.2019.05.10.15.35.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 15:35:11 -0700 (PDT) From: Douglas Anderson To: Mark Brown , Benson Leung , Enric Balletbo i Serra Subject: [PATCH 1/4] spi: For controllers that need realtime always use the pump thread Date: Fri, 10 May 2019 15:34:34 -0700 Message-Id: <20190510223437.84368-2-dianders@chromium.org> X-Mailer: git-send-email 2.21.0.1020.gf2820cf01a-goog In-Reply-To: <20190510223437.84368-1-dianders@chromium.org> References: <20190510223437.84368-1-dianders@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190510_153513_015507_4E721A85 X-CRM114-Status: GOOD ( 13.45 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: drinkcat@chromium.org, briannorris@chromium.org, Douglas Anderson , linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, mka@chromium.org, Guenter Roeck , linux-spi@vger.kernel.org Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP If a controller specifies that it needs high priority for sending messages we should always schedule our transfers on the thread. If we don't do this we'll do the transfer in the caller's context which might not be very high priority. Signed-off-by: Douglas Anderson Reviewed-by: Guenter Roeck --- drivers/spi/spi.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 8eb7460dd744..0597f7086de3 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1230,8 +1230,11 @@ static void __spi_pump_messages(struct spi_controller *ctlr, bool in_kthread) return; } - /* If another context is idling the device then defer */ - if (ctlr->idling) { + /* + * If another context is idling the device then defer. + * If we are high priority then the thread should do the transfer. + */ + if (ctlr->idling || (ctlr->rt && !in_kthread)) { kthread_queue_work(&ctlr->kworker, &ctlr->pump_messages); spin_unlock_irqrestore(&ctlr->queue_lock, flags); return; From patchwork Fri May 10 22:34:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 10939661 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 9901B14DB for ; Fri, 10 May 2019 22:35:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8766F1FE84 for ; Fri, 10 May 2019 22:35:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7C1081FF30; Fri, 10 May 2019 22:35:24 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0A92A1FE84 for ; Fri, 10 May 2019 22:35:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=/JncWpzzDTiTxu9suAqTIeVItaCXeUyDL+bS0WD+/nc=; b=if5hK6UwS3+plU eAz5YprAM3rwcYmVsB4SGpodnoOCnbOXfcfhQ38cLg/KO6klLLxO7DwO/KQ1fYsxkRA4dttEhbtBi +/DfSaC78RloR/yZmoEr5BAiLfDEh/QATi+MX7Sxf/iJI1q4Yk/ajIyWofU5no2hH+WymmsTV78Sf 9sanVYDY8+YVTE6PXVtOrfGvkfLvoFkKFGckR6/tcB0fnR+rWCiGcvpdxIIlSnjobqCz/Bp1/Zj/Z 7DdGqkrC4/Y1KJbVMa1l/60h9OgX+zbRcBdU49CAdnRrX5mNlXz87nzMKRTebAST2BWC/RBcy+zO7 5R5hOVd6NEcQm0xSjjFQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hPE6n-0005Hm-35; Fri, 10 May 2019 22:35:17 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hPE6k-0005FN-7x for linux-rockchip@lists.infradead.org; Fri, 10 May 2019 22:35:15 +0000 Received: by mail-pl1-x644.google.com with SMTP id f12so1426821plt.8 for ; Fri, 10 May 2019 15:35:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=doCw/N2zOvYXAd8OCIMYOL6rqup36HMvttPF4EYXpko=; b=cRIbdkmecLpeESu4B+BXdMd9/JM9OJK8ztcaLFe9dfuxnMY+Jitael/9JVP8k60jlA J3wsHnI5sdOg+JWKKYo7Zyp/vf07eh6ERiK/545CGhQyN1GoTqWST1YwdnRxWiYXDoTK jQbAJ5dHC3nZale8aZ/S4s7YGHl3acaP8mSpE= 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=doCw/N2zOvYXAd8OCIMYOL6rqup36HMvttPF4EYXpko=; b=SP3ruBCh8nN4aDejzEckmPx9vlXvBiqM+8jvPq/1+a/odqWZEAAdf65U17UGzO4pJt hJlZm0bEz7qTSH9+qmw8EwKPXKUi+bsvWmBI04oRZEC7pbIxb3IlFDtjlrwXj2fgzINC Ee6oInMcJKaD6n0JjhimrR6/oZTxLLl+1ppWAnSyANfBR7ugkRmIzRie6QaOnYplBnP2 fukI0kwELHwFLD8a5sTzZ5F/vQX+ewDZt56eyQlt77gwlpdNNKvR8hC6YMOomcW98hkT S9yyBdlxc7X7BM2jUgnE2Y2Xya+Sc+SPl2VDnF0BClKdY86f0PjEMjaWykUYa15c6xLX Zu0g== X-Gm-Message-State: APjAAAUyeUiZX6IqhA7abqUX3hST/g5rV/dqmBWZr2YtgRx7xSucawpx VUzMSKjNReWXYaqdA1PVIjEHAg== X-Google-Smtp-Source: APXvYqwjhDuIhNyoShQ2Zv2d4SsycWHqb30wq1IHUOoZ0rI10IRiL+YdwxPeiG1rym70fwTBAGxlng== X-Received: by 2002:a17:902:e287:: with SMTP id cf7mr16084314plb.217.1557527713435; Fri, 10 May 2019 15:35:13 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:24fa:e766:52c9:e3b2]) by smtp.gmail.com with ESMTPSA id j6sm7689393pfe.107.2019.05.10.15.35.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 15:35:12 -0700 (PDT) From: Douglas Anderson To: Mark Brown , Benson Leung , Enric Balletbo i Serra Subject: [PATCH 2/4] spi: Allow SPI devices to specify that they are timing sensitive Date: Fri, 10 May 2019 15:34:35 -0700 Message-Id: <20190510223437.84368-3-dianders@chromium.org> X-Mailer: git-send-email 2.21.0.1020.gf2820cf01a-goog In-Reply-To: <20190510223437.84368-1-dianders@chromium.org> References: <20190510223437.84368-1-dianders@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190510_153514_280517_D01FC588 X-CRM114-Status: GOOD ( 21.61 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: drinkcat@chromium.org, briannorris@chromium.org, Douglas Anderson , linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, mka@chromium.org, Guenter Roeck , linux-spi@vger.kernel.org Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP If a device on the SPI bus is very sensitive to timing then it may be necessary (for correctness) not to get interrupted during a transfer. One example is the EC (Embedded Controller) on Chromebooks. The Chrome OS EC will drop a transfer if more than ~8ms passes between the chip select being asserted and the transfer finishing. The SPI framework already has code to handle the case where transfers are timing senstive. It can set its message pumping thread to realtime to to minimize interruptions during the transfer. However, at the moment, this mode can only be requested by a SPI controller. Let's allow the drivers for SPI devices to also request this mode. NOTE: at the moment if a given device on a bus says that it's timing sensitive then we'll pump all messages on that bus at high priority. It is possible we might want to relax this in the future but it seems like it should be fine for now. Signed-off-by: Douglas Anderson Reviewed-by: Guenter Roeck --- drivers/spi/spi.c | 34 ++++++++++++++++++++++++++++------ include/linux/spi/spi.h | 3 +++ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 0597f7086de3..d117ab3adafa 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1367,10 +1367,30 @@ static void spi_pump_messages(struct kthread_work *work) __spi_pump_messages(ctlr, true); } -static int spi_init_queue(struct spi_controller *ctlr) +/** + * spi_boost_thread_priority - set the controller to pump at realtime priority + * @ctlr: controller to boost priority of + * + * This can be called because the controller requested realtime priority + * (by setting the ->rt value before calling spi_register_controller()) or + * because a device on the bus said that its transfers were timing senstive. + * + * NOTE: at the moment if any device on a bus says it is timing sensitive then + * all the devices on this bus will do transfers at realtime priority. If + * this eventually becomes a problem we may see if we can find a way to boost + * the priority only temporarily during relevant transfers. + */ +static void spi_boost_thread_priority(struct spi_controller *ctlr) { struct sched_param param = { .sched_priority = MAX_RT_PRIO - 1 }; + dev_info(&ctlr->dev, + "will run message pump with realtime priority\n"); + sched_setscheduler(ctlr->kworker_task, SCHED_FIFO, ¶m); +} + +static int spi_init_queue(struct spi_controller *ctlr) +{ ctlr->running = false; ctlr->busy = false; @@ -1390,11 +1410,8 @@ static int spi_init_queue(struct spi_controller *ctlr) * request and the scheduling of the message pump thread. Without this * setting the message pump thread will remain at default priority. */ - if (ctlr->rt) { - dev_info(&ctlr->dev, - "will run message pump with realtime priority\n"); - sched_setscheduler(ctlr->kworker_task, SCHED_FIFO, ¶m); - } + if (ctlr->rt) + spi_boost_thread_priority(ctlr); return 0; } @@ -2985,6 +3002,11 @@ int spi_setup(struct spi_device *spi) spi_set_cs(spi, false); + if (spi->timing_sensitive && !spi->controller->rt) { + spi->controller->rt = true; + spi_boost_thread_priority(spi->controller); + } + dev_dbg(&spi->dev, "setup mode %d, %s%s%s%s%u bits/w, %u Hz max --> %d\n", (int) (spi->mode & (SPI_CPOL | SPI_CPHA)), (spi->mode & SPI_CS_HIGH) ? "cs_high, " : "", diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 053abd22ad31..ef6bdd4d25f2 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -109,6 +109,8 @@ void spi_statistics_add_transfer_stats(struct spi_statistics *stats, * This may be changed by the device's driver, or left at the * default (0) indicating protocol words are eight bit bytes. * The spi_transfer.bits_per_word can override this for each transfer. + * @timing_sensitive: Transfers for this device are senstive to timing + * so we should do our transfer at high priority. * @irq: Negative, or the number passed to request_irq() to receive * interrupts from this device. * @controller_state: Controller's runtime state @@ -143,6 +145,7 @@ struct spi_device { u32 max_speed_hz; u8 chip_select; u8 bits_per_word; + bool timing_sensitive; u32 mode; #define SPI_CPHA 0x01 /* clock phase */ #define SPI_CPOL 0x02 /* clock polarity */ From patchwork Fri May 10 22:34:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 10939655 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 10006912 for ; Fri, 10 May 2019 22:35:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F1ADC1FF40 for ; Fri, 10 May 2019 22:35:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E49711FF3E; Fri, 10 May 2019 22:35: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=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 91CB61FF29 for ; Fri, 10 May 2019 22:35:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=IN9eQfCCvweZ/lOwTGiEr4i1BIzx/xuv5LCeXxeyp0I=; b=IrlgM93z5xmI5k WfKcecfgbsymnPk1p1tfS2fqopdU1fWLRrAyk8machZhvuU0POIuy9K44B+phwIfvQepHjitkjWZM BUge49Pknc/ltlWOSP7Kk+GtgSZdd8M76Vr3T396axhS7nYASWeDnPkc1v3sSkMLTFPVxvvffJvmY 3gbyGTHVdbnLtTxPzzbt40/UynixQD8Nz/m6z/7HUWNwg4ham6rKHrETZEpqKxPL9XM74ggL7hizo Y502ZRvRmeD3BQTb9jN1VqnJPHukMKhsv0P8Cv/B2Jrp3NCeLlJ2DaoQ9osNCbI89Ymab8ufJM7DT RuKhCkCGAdi9cg+cwMBA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hPE6p-0005Ko-PK; Fri, 10 May 2019 22:35:19 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hPE6l-0005Fh-5b for linux-rockchip@lists.infradead.org; Fri, 10 May 2019 22:35:16 +0000 Received: by mail-pl1-x643.google.com with SMTP id y3so3454325plp.0 for ; Fri, 10 May 2019 15:35:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jTz3ssqMKwXih7kW/rvdj9F00tD72Ht0qosH9fDb+p4=; b=m5DmBmQbr31Nx984JHfCz3IviiH3OyT8HQZBJQFM6cOI5aigI4Q1QU5/kNqG58ZnzL G5AdfUDbw8rulMd43CuhdLXN4lqpXcrRNV64oa+qXQLvZpg5ZjXFusmd8Nfm3gylgfGZ EbNEyzhJHCYjJQgOcYgM0MwXEti/5KGL0K7uw= 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=jTz3ssqMKwXih7kW/rvdj9F00tD72Ht0qosH9fDb+p4=; b=B7WHcZo6TbgPvgKh42zLWg+dIGC+Ig09GRAMLHtiX2gjtOnHSiQBwdFpULxQRxhwVN YGzgqUpnTFILGzW7XqoVVFR/1Yue2U0QB2DE4qrWQtWVMpxK45hCa+XArav8QQqH+FX2 74lTGMFgQi6P9T5wzPbQ1f0xYjFkNYkWoodj690TFUFt2q2f7mP3WmLsW1bcUaipxk1E RUOPvnDUrhYT37AHu1gUQVV0AzzHg+i+JlHbqLbExs5DOUQtAjPCCxpseUmzpH08I2Pd f0QhAermSXXeWlNsfelt7cEuG3Mkc/XVhnJF+ztbQAkK2Zho5uSMEFn9HYhP5KRKSQon XVeQ== X-Gm-Message-State: APjAAAV+CdwEj3Y0TLIFG3sr9b7JL1+q/FHmnSoOO5jI7r4IZi47Pi6P 6nc5U2EZCm2mQ1R2O+yRyJvLLw== X-Google-Smtp-Source: APXvYqxeP1i6s9XT+hR15W2dLlmU4slR1FOWV1B51dcqbURu9NlJ7G6AyDsoKuooSYOBtHCWskhj2Q== X-Received: by 2002:a17:902:29e9:: with SMTP id h96mr16039999plb.258.1557527714413; Fri, 10 May 2019 15:35:14 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:24fa:e766:52c9:e3b2]) by smtp.gmail.com with ESMTPSA id j6sm7689393pfe.107.2019.05.10.15.35.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 15:35:13 -0700 (PDT) From: Douglas Anderson To: Mark Brown , Benson Leung , Enric Balletbo i Serra Subject: [PATCH 3/4] platform/chrome: cros_ec_spi: Set ourselves as timing sensitive Date: Fri, 10 May 2019 15:34:36 -0700 Message-Id: <20190510223437.84368-4-dianders@chromium.org> X-Mailer: git-send-email 2.21.0.1020.gf2820cf01a-goog In-Reply-To: <20190510223437.84368-1-dianders@chromium.org> References: <20190510223437.84368-1-dianders@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190510_153515_306772_7DF051AE X-CRM114-Status: GOOD ( 10.52 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: drinkcat@chromium.org, briannorris@chromium.org, Douglas Anderson , linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, mka@chromium.org, Guenter Roeck Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP All currently known ECs in the wild are very sensitive to timing. Specifically the ECs are known to drop a transfer if more than 8 ms passes from the assertion of the chip select until the transfer finishes. Let's use the new feature introduced in the patch ("spi: Allow SPI devices to specify that they are timing sensitive") to specify this and increase the success rate of our transfers. NOTE: if future Chrome OS ECs ever fix themselves to be less sensitive then we could consider adding a property (or compatible string) to not set this property. For now we need it across the board. With this change we can revert the commit 37a186225a0c ("platform/chrome: cros_ec_spi: Transfer messages at high priority"). ...and, in fact, transfers are _even more_ reliable than they were with that commit since the SPI framework will use a higher priority (realtime) and we no longer lose our priority when we get shunted over to the message pumping thread (because we now always get shunted and the thread is high priority). Signed-off-by: Douglas Anderson Reviewed-by: Guenter Roeck --- drivers/platform/chrome/cros_ec_spi.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/platform/chrome/cros_ec_spi.c b/drivers/platform/chrome/cros_ec_spi.c index 8e9451720e73..757a115502ec 100644 --- a/drivers/platform/chrome/cros_ec_spi.c +++ b/drivers/platform/chrome/cros_ec_spi.c @@ -703,6 +703,7 @@ static int cros_ec_spi_probe(struct spi_device *spi) spi->bits_per_word = 8; spi->mode = SPI_MODE_0; + spi->timing_sensitive = true; err = spi_setup(spi); if (err < 0) return err; From patchwork Fri May 10 22:34:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 10939657 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 2658892A for ; Fri, 10 May 2019 22:35:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 135121FF29 for ; Fri, 10 May 2019 22:35:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0786F1FF60; Fri, 10 May 2019 22:35:24 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 85DC31FE84 for ; Fri, 10 May 2019 22:35:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=lF7sAiKR5apaO5h3YkNdns0brkABV8ANljJ7vf/Qoic=; b=dbsLbBlhlS0Ve0 mMeu3qwtdr7Y3+xEy9oBNJlSFej0ShO2ETqO3nggUvgru08XWpuKYQwjhj1oXKX6IymmIsxjsua+n AIXFXCYG+vmuy0w0VjPl/KuXYonDYUWZLfH1LLJyxtumauhs1YpEPK19TjwTlf7WA3htOrC7A6duD 4Y/tpryVBe81Mr/q/hgamIGJTHiN7012gG4WRll3XcjHpMVNKuX4OR7tAlBvAqvZ193QzVpUzbGVs AQLPzV7qhVCUwKQHewY+oswgiJ01k6t3lQWc8nuIDZu1iwWp5lvYk780VDS7KcKi9pNTMTDJrv/vt AviO9CecWLyTEROmm3CQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hPE6q-0005LR-Gz; Fri, 10 May 2019 22:35:20 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hPE6m-0005GT-2F for linux-rockchip@lists.infradead.org; Fri, 10 May 2019 22:35:17 +0000 Received: by mail-pg1-x543.google.com with SMTP id 145so3649388pgg.9 for ; Fri, 10 May 2019 15:35:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QaD6p9yeCboFRN1O4f3agFfdrFqU2J5sjBMDQWDo2g0=; b=oPak1zDG4jOI/uCaxLX8GHqaGMSoiTU8gNv/Dn7HQtIJUcJqpsrpss2JiplUy66611 ublJS8OvyIhozjVuBWqpFT1OKbcYlS1+capXhghyJ5pjoxiKxdTRkFC+9mJIuVevuS+d Gp9v4NqLOyhGTqEqJgHr3umOhrqhTmwnwf91w= 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=QaD6p9yeCboFRN1O4f3agFfdrFqU2J5sjBMDQWDo2g0=; b=B98do9/bJVGyE7v5AnJCcwCmSExEzc3pSBu2OsMgumUb8zuiawKRuhDTl6ssumW87R Fo7sys+nUkkbGD2Rl8hhRWGEYDAeFO6TXaw/ogl9H80j5zqnqhHuiVSBmPiYK3xF2Pfk YtIAhg4eBZJTuLfu8K++dBzoL/g/+wQQgzXEvwYOSmn3st8P/Gu882BlrjRC4UElgMIO WUUox9az3UTWzjzvXP2/dItL7//EAj2GJEAdAx7DINZ3O40OqzEZfyn48tqBXHUFa4y6 DTiHEcpgSjWTRck+KwN/FeJL5tDmC4Fb5zrPkjxW/ZPe9++KFdoYW9aeDgrTzOVyyPgo zyLg== X-Gm-Message-State: APjAAAUiH++o8OPTruldOXcdVf71ipvJwULLvOnaYQRgyfX+DZ7r6ijO Igamx7ZhsjathGAyfd4ighU+YrhJWVk= X-Google-Smtp-Source: APXvYqzfM5/LmGIWWgBYDTcbycKUOiDEKbIXg5w7z1nWzDfcvuqgnSrkZZgBnWXxW3V3WNmk2pnBdg== X-Received: by 2002:aa7:8b8b:: with SMTP id r11mr17507706pfd.130.1557527715309; Fri, 10 May 2019 15:35:15 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:24fa:e766:52c9:e3b2]) by smtp.gmail.com with ESMTPSA id j6sm7689393pfe.107.2019.05.10.15.35.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 15:35:14 -0700 (PDT) From: Douglas Anderson To: Mark Brown , Benson Leung , Enric Balletbo i Serra Subject: [PATCH 4/4] Revert "platform/chrome: cros_ec_spi: Transfer messages at high priority" Date: Fri, 10 May 2019 15:34:37 -0700 Message-Id: <20190510223437.84368-5-dianders@chromium.org> X-Mailer: git-send-email 2.21.0.1020.gf2820cf01a-goog In-Reply-To: <20190510223437.84368-1-dianders@chromium.org> References: <20190510223437.84368-1-dianders@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190510_153516_106095_B97A316E X-CRM114-Status: GOOD ( 13.76 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: drinkcat@chromium.org, briannorris@chromium.org, Douglas Anderson , linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, mka@chromium.org, Guenter Roeck Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This reverts commit 37a186225a0c020516bafad2727fdcdfc039a1e4. We have a better solution in the patch ("platform/chrome: cros_ec_spi: Set ourselves as timing sensitive"). Let's revert the uglier and less reliable solution. Signed-off-by: Douglas Anderson Reviewed-by: Guenter Roeck --- drivers/platform/chrome/cros_ec_spi.c | 80 ++------------------------- 1 file changed, 6 insertions(+), 74 deletions(-) diff --git a/drivers/platform/chrome/cros_ec_spi.c b/drivers/platform/chrome/cros_ec_spi.c index 757a115502ec..70ff1ad09012 100644 --- a/drivers/platform/chrome/cros_ec_spi.c +++ b/drivers/platform/chrome/cros_ec_spi.c @@ -75,27 +75,6 @@ struct cros_ec_spi { unsigned int end_of_msg_delay; }; -typedef int (*cros_ec_xfer_fn_t) (struct cros_ec_device *ec_dev, - struct cros_ec_command *ec_msg); - -/** - * struct cros_ec_xfer_work_params - params for our high priority workers - * - * @work: The work_struct needed to queue work - * @fn: The function to use to transfer - * @ec_dev: ChromeOS EC device - * @ec_msg: Message to transfer - * @ret: The return value of the function - */ - -struct cros_ec_xfer_work_params { - struct work_struct work; - cros_ec_xfer_fn_t fn; - struct cros_ec_device *ec_dev; - struct cros_ec_command *ec_msg; - int ret; -}; - static void debug_packet(struct device *dev, const char *name, u8 *ptr, int len) { @@ -371,13 +350,13 @@ static int cros_ec_spi_receive_response(struct cros_ec_device *ec_dev, } /** - * do_cros_ec_pkt_xfer_spi - Transfer a packet over SPI and receive the reply + * cros_ec_pkt_xfer_spi - Transfer a packet over SPI and receive the reply * * @ec_dev: ChromeOS EC device * @ec_msg: Message to transfer */ -static int do_cros_ec_pkt_xfer_spi(struct cros_ec_device *ec_dev, - struct cros_ec_command *ec_msg) +static int cros_ec_pkt_xfer_spi(struct cros_ec_device *ec_dev, + struct cros_ec_command *ec_msg) { struct ec_host_response *response; struct cros_ec_spi *ec_spi = ec_dev->priv; @@ -514,13 +493,13 @@ static int do_cros_ec_pkt_xfer_spi(struct cros_ec_device *ec_dev, } /** - * do_cros_ec_cmd_xfer_spi - Transfer a message over SPI and receive the reply + * cros_ec_cmd_xfer_spi - Transfer a message over SPI and receive the reply * * @ec_dev: ChromeOS EC device * @ec_msg: Message to transfer */ -static int do_cros_ec_cmd_xfer_spi(struct cros_ec_device *ec_dev, - struct cros_ec_command *ec_msg) +static int cros_ec_cmd_xfer_spi(struct cros_ec_device *ec_dev, + struct cros_ec_command *ec_msg) { struct cros_ec_spi *ec_spi = ec_dev->priv; struct spi_transfer trans; @@ -632,53 +611,6 @@ static int do_cros_ec_cmd_xfer_spi(struct cros_ec_device *ec_dev, return ret; } -static void cros_ec_xfer_high_pri_work(struct work_struct *work) -{ - struct cros_ec_xfer_work_params *params; - - params = container_of(work, struct cros_ec_xfer_work_params, work); - params->ret = params->fn(params->ec_dev, params->ec_msg); -} - -static int cros_ec_xfer_high_pri(struct cros_ec_device *ec_dev, - struct cros_ec_command *ec_msg, - cros_ec_xfer_fn_t fn) -{ - struct cros_ec_xfer_work_params params; - - INIT_WORK_ONSTACK(¶ms.work, cros_ec_xfer_high_pri_work); - params.ec_dev = ec_dev; - params.ec_msg = ec_msg; - params.fn = fn; - - /* - * This looks a bit ridiculous. Why do the work on a - * different thread if we're just going to block waiting for - * the thread to finish? The key here is that the thread is - * running at high priority but the calling context might not - * be. We need to be at high priority to avoid getting - * context switched out for too long and the EC giving up on - * the transfer. - */ - queue_work(system_highpri_wq, ¶ms.work); - flush_work(¶ms.work); - destroy_work_on_stack(¶ms.work); - - return params.ret; -} - -static int cros_ec_pkt_xfer_spi(struct cros_ec_device *ec_dev, - struct cros_ec_command *ec_msg) -{ - return cros_ec_xfer_high_pri(ec_dev, ec_msg, do_cros_ec_pkt_xfer_spi); -} - -static int cros_ec_cmd_xfer_spi(struct cros_ec_device *ec_dev, - struct cros_ec_command *ec_msg) -{ - return cros_ec_xfer_high_pri(ec_dev, ec_msg, do_cros_ec_cmd_xfer_spi); -} - static void cros_ec_spi_dt_probe(struct cros_ec_spi *ec_spi, struct device *dev) { struct device_node *np = dev->of_node;