From patchwork Wed Nov 16 20:52:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Schneider-Pargmann X-Patchwork-Id: 21258 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp56782wrr; Wed, 16 Nov 2022 12:55:02 -0800 (PST) X-Google-Smtp-Source: AA0mqf7/R2w8f2iOUfH7rF2sh9iYFWjGrssJOytbr+slPMXCrRCylZIyxV/OwR7VYaS+VYTH19iw X-Received: by 2002:a17:907:766f:b0:78d:4795:ff1f with SMTP id kk15-20020a170907766f00b0078d4795ff1fmr19591941ejc.331.1668632101982; Wed, 16 Nov 2022 12:55:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668632101; cv=none; d=google.com; s=arc-20160816; b=h2uron8ZO48DrnG79O8Jc2D3ejqgeTSJRg2ysjvORGYTn46dbHZ4VVBGIg70xz4juT VN1eZSzLOnOvF36mxMyBejIEhFypLrbM2FIXmcC8RbhhPJutHRJ76WkMyLGkLt6lIaUm MCag+N1PZtjQFuRIMvN1YymS4NUfBSBHZyaM88qxC4gOKCkT/dYlruR4l1ulNMX/4vCr 3gCAtKNoChvkZSgzsamtxNeF/wuZ0s/3IrjLGIcEn234wNBCQRAU7FAhFeSzaVyo9rqW Z8M4G4xCPrqAOXNcOQ/iwB0GB3FEzL+DFSrv4SOtfx3RHLj2umnVLGHgBXynLdNpB+D0 qQug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=2rJ/wCekKfh+/zbab0KIF63OXyhft6t7a9cE754TRYE=; b=b95nAoDxTNvOiK1Nh6ZJXbh5Wl8vahhGC1BoVgvPFY2G7PYaVx1Gtu6R4m/DjYj3eQ fAraHpkSbjj8rp4bqsTvvJllFuzS1KNbj+65HYzmS2MmmAPukgng0/UXPn9t+VlTKGSe MREiR5kxVbJ0D8IuvkoE/TlFgH1hIN08AVPh4Snarp8fTvty7SKzgqK5LaHfKAdLmt+j GkpuOafyHqLgk7y8Q8pWd4XSudHjpwLe6Pkha+mFS3FVnzdDR0Y7htlLb52NdRTTc6wA MK9fQY7Zl48S5zf8+cXoVPeyOJnFASKGcuNyhrnhSL8KznUp4424QKzEXr/+9uRardlf wK6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=P2To7HYy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cs19-20020a170906dc9300b007af13652caasi6394010ejc.325.2022.11.16.12.54.39; Wed, 16 Nov 2022 12:55:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=P2To7HYy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238806AbiKPUyL (ORCPT + 99 others); Wed, 16 Nov 2022 15:54:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233340AbiKPUxo (ORCPT ); Wed, 16 Nov 2022 15:53:44 -0500 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4C10D89 for ; Wed, 16 Nov 2022 12:53:25 -0800 (PST) Received: by mail-ej1-x634.google.com with SMTP id n20so98457ejh.0 for ; Wed, 16 Nov 2022 12:53:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2rJ/wCekKfh+/zbab0KIF63OXyhft6t7a9cE754TRYE=; b=P2To7HYyeZgnQrgVSiKYZjY/MFYOIWjd/XCA+rlJONO4UE9NbuRNNXqh4OoyMZDMFD 8Jf5jjQg1yf4Vyr1mTAAW8m6RnMK0YsErEsVDcNgxGXty8Ezc6tEkn/cflJkqTKCAMtP GZ7exwXlAMjj1At6Tc/0RmiIDNSF1RMyZg3yIdEIJLGYXi1ucQ7ODKnL+s0di9XHxfaQ slvIwH/ocjac5SAAfER5A1IWBuhmNTJ+e/WhRYA/VeSeEWyGUUyumYgQbgc6gQMyylXG TOVZtkibuNn46tWev4OobR6gdDQVrGUxaw0tXDwxjwLTmKrHDf5404mUyxGyYeqnyRSa HUyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2rJ/wCekKfh+/zbab0KIF63OXyhft6t7a9cE754TRYE=; b=Oc62xkx8PN7ZMX42VHXAhrUkOD0PD2QXzNcovsQqIQRvv5YINLbL37GcNRfepS/XQY g5IcmZbQLRfFyvaknSzd8oegPITdGClcltjazgSwEUEc5eCz9/JvCJ7CrmQkaL05lQEY EfGVvqkAkaD7axdH/nTJ5ioJ0u27MZqa+CeNHTHiG/fMsrxNLIdaWaROriMP38BZAsWd w8HiYoltmX7YMXXA+7QCt0TTH5xQDa59uNuHH03QZiGSLahTB6GQC7wmEl9d9qhdUHVt v05sTdAGfn8cez7vSxlBmw/GXxyi3Chg9oSFlZEXiMp/dqqIKPl8i3ueuPSPHX0nDK9+ LSGQ== X-Gm-Message-State: ANoB5pmb8PlhRdQa1nBt1rxcsDyeN1VeXN/YWJDenC99Y8/j4dKz+K2L Wzm/fDGkM6r0wjSzdXyAIqSBkQ== X-Received: by 2002:a17:906:1248:b0:7ad:f9da:8986 with SMTP id u8-20020a170906124800b007adf9da8986mr19202437eja.54.1668632004349; Wed, 16 Nov 2022 12:53:24 -0800 (PST) Received: from blmsp.fritz.box ([2001:4090:a244:804b:353b:565:addf:3aa7]) by smtp.gmail.com with ESMTPSA id kv17-20020a17090778d100b007aece68483csm6782828ejc.193.2022.11.16.12.53.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Nov 2022 12:53:23 -0800 (PST) From: Markus Schneider-Pargmann To: Chandrasekar Ramakrishnan , Marc Kleine-Budde , Wolfgang Grandegger Cc: linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Markus Schneider-Pargmann Subject: [PATCH 01/15] can: m_can: Eliminate double read of TXFQS in tx_handler Date: Wed, 16 Nov 2022 21:52:54 +0100 Message-Id: <20221116205308.2996556-2-msp@baylibre.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221116205308.2996556-1-msp@baylibre.com> References: <20221116205308.2996556-1-msp@baylibre.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749687575246571356?= X-GMAIL-MSGID: =?utf-8?q?1749687575246571356?= The TXFQS register is read first to check if the fifo is full and then immediately again to get the putidx. This is unnecessary and adds significant overhead if read requests are done over a slow bus, for example SPI with tcan4x5x. Add a variable to store the value of the register. Split the m_can_tx_fifo_full function into two to avoid the hidden m_can_read call if not needed. Signed-off-by: Markus Schneider-Pargmann --- drivers/net/can/m_can/m_can.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 00d11e95fd98..2c01e3f7b23f 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -368,9 +368,14 @@ m_can_txe_fifo_read(struct m_can_classdev *cdev, u32 fgi, u32 offset, u32 *val) return cdev->ops->read_fifo(cdev, addr_offset, val, 1); } +static inline bool _m_can_tx_fifo_full(u32 txfqs) +{ + return !!(txfqs & TXFQS_TFQF); +} + static inline bool m_can_tx_fifo_full(struct m_can_classdev *cdev) { - return !!(m_can_read(cdev, M_CAN_TXFQS) & TXFQS_TFQF); + return _m_can_tx_fifo_full(m_can_read(cdev, M_CAN_TXFQS)); } static void m_can_config_endisable(struct m_can_classdev *cdev, bool enable) @@ -1585,6 +1590,7 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev) struct sk_buff *skb = cdev->tx_skb; struct id_and_dlc fifo_header; u32 cccr, fdflags; + u32 txfqs; int err; int putidx; @@ -1641,8 +1647,10 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev) } else { /* Transmit routine for version >= v3.1.x */ + txfqs = m_can_read(cdev, M_CAN_TXFQS); + /* Check if FIFO full */ - if (m_can_tx_fifo_full(cdev)) { + if (_m_can_tx_fifo_full(txfqs)) { /* This shouldn't happen */ netif_stop_queue(dev); netdev_warn(dev, @@ -1658,8 +1666,7 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev) } /* get put index for frame */ - putidx = FIELD_GET(TXFQS_TFQPI_MASK, - m_can_read(cdev, M_CAN_TXFQS)); + putidx = FIELD_GET(TXFQS_TFQPI_MASK, txfqs); /* Construct DLC Field, with CAN-FD configuration. * Use the put index of the fifo as the message marker,