From patchwork Wed Jun 10 07:47:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 187740 Delivered-To: patch@linaro.org Received: by 2002:a92:cf06:0:0:0:0:0 with SMTP id c6csp255565ilo; Wed, 10 Jun 2020 00:48:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxToWMGPswLqYMFXBGwwkVc1tgSejY0NaMOK1239wHpZzetf9qo3n7vvAlDqHcdY1NTsFX0 X-Received: by 2002:a17:906:4ada:: with SMTP id u26mr2272785ejt.368.1591775281231; Wed, 10 Jun 2020 00:48:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591775281; cv=none; d=google.com; s=arc-20160816; b=z4zTo4OGA3HUtP2Ifesyj60QD31A/LGHLXnUdrTy4008NiwPG6qwIbeVKacaL0WLth y0+4KRxn+nMy6jBFPFnteSi+FxEI9/BdMkBqqIPvaGMK3QOR6vh/eNf/jUF+LLaOkpPU AsmPar3STfnQypFteVfdc4mP4PXHLhWAJHBofe4z8rwv9JU1qrrzipZQT7ivm5etwiL4 mV5tVdatGlEmj4rrWGF7EZnRtBGafVaLVpqnMuS7TbWqwE4yptB0mMaBtBOWQvngFsct oBRqo/8Dr2tC5Ll/7//lk5GZlhjPDtHy16Pon4ShFBhvbT12ggt7AO5lR/tCPaKLB+hb ghnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=dSE9dqY0eKEnI3JM3RkevfVx7P9DxAySSIY6zGnKG0k=; b=KK8q4AWksmFJmEYtHrc7LD9tgn0e28SZdusMdS42DutSJz+Wbi0qP3WqgdRHv6YaRq zchygRGMvBxqwZvtlUbPNvNKPzviYFSiO6eHkqcWU49J6FWcFVjV0Ubz8xWtSQixgb5X X5EqEOhOXKvRvvE+RXpGw/qVODInyPcblFs+zIRTn3E4cJ1CZXbKf19o+LNHHf9FnGcv DgmY/wwQ/xFd9VInFNoPbA+vRJ0AnSGuI4CXAFKiCHpFj26yaR6XOjPKgITSzshEIaaJ /IdTPr7prtdHxHl2zILOb8HTH5NPybW2DL4kzTspGkAmqvUzp+ZkP4Tc3PWlZm7EGqql cuGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FbW0xRSD; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a62si12230669edf.361.2020.06.10.00.48.01; Wed, 10 Jun 2020 00:48:01 -0700 (PDT) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FbW0xRSD; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726763AbgFJHr7 (ORCPT + 6 others); Wed, 10 Jun 2020 03:47:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726758AbgFJHrx (ORCPT ); Wed, 10 Jun 2020 03:47:53 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 573D4C08C5C2 for ; Wed, 10 Jun 2020 00:47:53 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id r18so610315pgk.11 for ; Wed, 10 Jun 2020 00:47:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dSE9dqY0eKEnI3JM3RkevfVx7P9DxAySSIY6zGnKG0k=; b=FbW0xRSDuDBHPICwLz6J0+xSwKToUC5OHVH6pVC2xAJKD3+d9wSqcJ4aQA5mQIgkuh QPr3AusxGl9SkAEq3GF9VJszl07SB1IOqHsBUpxMjDsPrB4sjGCdlg+01WKWCDXKjbVj Pe5SrDBj25ONBPbOIxAA9jOKWywKcDUY5HhCjMxxHsnJwqqiI/shd8ir17LXRuxuFCsi lpXXBIN69PrCtDXTk0VmJCjzWEYR+Oa6pljEJZj2VIZBoIyXEcyf+iyvooVfzstaDxVM R0fRobXFQahfQzfmrrmoripc6I6KiBUPG/lFdZ4u0ujBNosSQEJQeMYNCxYCg0j2rGlo e1SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dSE9dqY0eKEnI3JM3RkevfVx7P9DxAySSIY6zGnKG0k=; b=pEsNLi29sDy9G0WDnNIswfz8EzinAnUM2looqQ+A4vfGznIPyFJvRvOvSEC7nU3hcX p47JtQvvv5MInUg89Kt0nh/f0JfClJCXVjy9uBm10rp28OJvezJDwFDkVEuuXyurGBrG mvsgfzIVI+6ApXfHuyl8rP2Gq+sbpkiXMiCG4DCiP86lY3wnx1Ad//TNa3lGjq1+MdpK ScMkkV7wZGOLhAAXgngfEEJDm9w2wxeN5IPDK13z/0UrrbKrUnt+RKz9AVWhArmPyrtM qBX043VRyf58LJB7YadgkNE1p/Zouyhb5xqPRvKYVvFD8oqSN1f9dfWTF2OSJYUM2grS /LGw== X-Gm-Message-State: AOAM531AFLB6oE8LNVprlRZx2d8MD2Pe7Szvd64uaIWyMbV6vd64Xb4w zWi+kGm/4mfxSlYPbNUnj1uN X-Received: by 2002:a62:2acf:: with SMTP id q198mr1696952pfq.48.1591775272783; Wed, 10 Jun 2020 00:47:52 -0700 (PDT) Received: from Mani-XPS-13-9360.localdomain ([2409:4072:630f:1dba:c41:a14e:6586:388a]) by smtp.gmail.com with ESMTPSA id u1sm10075040pgf.28.2020.06.10.00.47.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2020 00:47:52 -0700 (PDT) From: Manivannan Sadhasivam To: wg@grandegger.com, mkl@pengutronix.de, robh+dt@kernel.org Cc: kernel@martin.sperl.org, linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Manivannan Sadhasivam Subject: [RESEND PATCH 5/6] can: mcp25xxfd: Optimize TEF read by avoiding unnecessary SPI transfers Date: Wed, 10 Jun 2020 13:17:10 +0530 Message-Id: <20200610074711.10969-6-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200610074711.10969-1-manivannan.sadhasivam@linaro.org> References: <20200610074711.10969-1-manivannan.sadhasivam@linaro.org> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Martin Sperl We have already enough information to know how many tx-messages have been terminated so that we do not have to query TEF every time if there is anything pending but we can read the tefs blindly. This avoids 1 SPI transfer per TEF read. Signed-off-by: Martin Sperl Signed-off-by: Manivannan Sadhasivam --- .../net/can/spi/mcp25xxfd/mcp25xxfd_can_tx.c | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) -- 2.17.1 diff --git a/drivers/net/can/spi/mcp25xxfd/mcp25xxfd_can_tx.c b/drivers/net/can/spi/mcp25xxfd/mcp25xxfd_can_tx.c index 5ea1e525e776..6f066cb95844 100644 --- a/drivers/net/can/spi/mcp25xxfd/mcp25xxfd_can_tx.c +++ b/drivers/net/can/spi/mcp25xxfd/mcp25xxfd_can_tx.c @@ -263,6 +263,13 @@ int mcp25xxfd_can_tx_handle_int_tefif_fifo(struct mcp25xxfd_can_priv *cpriv) MCP25XXFD_CAN_TEFCON_UINC); } +/* reading TEF entries can be made even more efficient by reading + * multiple TEF entries in one go. + * Under the assumption that we have count(TEF) >= count(TX_FIFO) + * we can even release TEFs early (before we read them) + * (and potentially restarting the transmit-queue early aswell) + */ + static int mcp25xxfd_can_tx_handle_int_tefif_conservative(struct mcp25xxfd_can_priv *cpriv) { @@ -293,6 +300,25 @@ mcp25xxfd_can_tx_handle_int_tefif_conservative(struct mcp25xxfd_can_priv *cpriv) return 0; } +static int +mcp25xxfd_can_tx_handle_int_tefif_optimized(struct mcp25xxfd_can_priv *cpriv, + u32 finished) +{ + int i, fifo, ret; + + /* now iterate those */ + for (i = 0, fifo = cpriv->fifos.tx.start; i < cpriv->fifos.tx.count; + i++, fifo++) { + if (finished & BIT(fifo)) { + ret = mcp25xxfd_can_tx_handle_int_tefif_fifo(cpriv); + if (ret) + return ret; + } + } + + return 0; +} + int mcp25xxfd_can_tx_handle_int_tefif(struct mcp25xxfd_can_priv *cpriv) { unsigned long flags; @@ -310,6 +336,13 @@ int mcp25xxfd_can_tx_handle_int_tefif(struct mcp25xxfd_can_priv *cpriv) spin_unlock_irqrestore(&cpriv->fifos.tx_queue->lock, flags); + /* run in optimized mode if possible */ + if (finished) + return mcp25xxfd_can_tx_handle_int_tefif_optimized(cpriv, + finished); + /* otherwise play it safe */ + netdev_warn(cpriv->can.dev, + "Something is wrong - we got a TEF interrupt but we were not able to detect a finished fifo\n"); return mcp25xxfd_can_tx_handle_int_tefif_conservative(cpriv); }