All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Schneider-Pargmann <msp@baylibre.com>
To: Chandrasekar Ramakrishnan <rcsekar@samsung.com>,
	Marc Kleine-Budde <mkl@pengutronix.de>,
	Wolfgang Grandegger <wg@grandegger.com>
Cc: linux-can@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Markus Schneider-Pargmann <msp@baylibre.com>
Subject: [PATCH v2 01/11] can: m_can: Eliminate double read of TXFQS in tx_handler
Date: Tue,  6 Dec 2022 12:57:18 +0100	[thread overview]
Message-ID: <20221206115728.1056014-2-msp@baylibre.com> (raw)
In-Reply-To: <20221206115728.1056014-1-msp@baylibre.com>

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 <msp@baylibre.com>
---
 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 e5575d2755e4..0cc0abde9b1d 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,
-- 
2.38.1


  reply	other threads:[~2022-12-06 11:57 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-06 11:57 [PATCH v2 00/11] can: m_can: Optimizations for tcan and peripheral chips Markus Schneider-Pargmann
2022-12-06 11:57 ` Markus Schneider-Pargmann [this message]
2022-12-06 11:57 ` [PATCH v2 02/11] can: m_can: Avoid reading irqstatus twice Markus Schneider-Pargmann
2022-12-06 11:57 ` [PATCH v2 03/11] can: m_can: Read register PSR only on error Markus Schneider-Pargmann
2022-12-06 11:57 ` [PATCH v2 04/11] can: m_can: Count TXE FIFO getidx in the driver Markus Schneider-Pargmann
2022-12-06 11:57 ` [PATCH v2 05/11] can: m_can: Count read getindex " Markus Schneider-Pargmann
2022-12-06 11:57 ` [PATCH v2 06/11] can: m_can: Batch acknowledge transmit events Markus Schneider-Pargmann
2022-12-06 11:57 ` [PATCH v2 07/11] can: m_can: Batch acknowledge rx fifo Markus Schneider-Pargmann
2022-12-06 11:57 ` [PATCH v2 08/11] can: tcan4x5x: Remove invalid write in clear_interrupts Markus Schneider-Pargmann
2022-12-06 11:57 ` [PATCH v2 09/11] can: tcan4x5x: Fix use of register error status mask Markus Schneider-Pargmann
2022-12-06 11:57 ` [PATCH v2 10/11] can: tcan4x5x: Fix register range of first two blocks Markus Schneider-Pargmann
2022-12-06 11:57 ` [PATCH v2 11/11] can: tcan4x5x: Specify separate read/write ranges Markus Schneider-Pargmann
2022-12-06 16:20   ` Marc Kleine-Budde
2022-12-12 10:54     ` Marc Kleine-Budde
2022-12-13 17:10       ` Markus Schneider-Pargmann
2022-12-13 19:10         ` Markus Schneider-Pargmann
2022-12-13 19:13           ` Marc Kleine-Budde

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221206115728.1056014-2-msp@baylibre.com \
    --to=msp@baylibre.com \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=netdev@vger.kernel.org \
    --cc=rcsekar@samsung.com \
    --cc=wg@grandegger.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.