From: kernel@martin.sperl.org
To: linux-can@vger.kernel.org, devicetree@vger.kernel.org,
Wolfgang Grandegger <wg@grandegger.com>,
Mark Kleine-Budde <mkl@pengutronix.de>,
Rob Herring <robh+dt@kernel.org>,
Mark Rutland <mark.rutland@arm.com>
Cc: Martin Sperl <kernel@martin.sperl.org>
Subject: [PATCH V7 RESEND 06/10] can: mcp25xxfd: optimize TEF read avoiding unnecessary SPI transfers
Date: Fri, 19 Apr 2019 05:14:28 +0000 [thread overview]
Message-ID: <20190419051432.13538-7-kernel@martin.sperl.org> (raw)
In-Reply-To: <20190419051432.13538-1-kernel@martin.sperl.org>
From: Martin Sperl <kernel@martin.sperl.org>
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 <kernel@martin.sperl.org>
---
drivers/net/can/spi/mcp25xxfd/mcp25xxfd_can_tx.c | 33 ++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/drivers/net/can/spi/mcp25xxfd/mcp25xxfd_can_tx.c b/drivers/net/can/spi/mcp25xxfd/mcp25xxfd_can_tx.c
index 04c32b91cee1..0d08bc9768d9 100644
--- a/drivers/net/can/spi/mcp25xxfd/mcp25xxfd_can_tx.c
+++ b/drivers/net/can/spi/mcp25xxfd/mcp25xxfd_can_tx.c
@@ -274,6 +274,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)
{
@@ -304,6 +311,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;
@@ -323,6 +349,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);
}
--
2.11.0
next prev parent reply other threads:[~2019-04-19 5:14 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-19 5:14 [PATCH V7 RESEND 00/10] Microchip mcp25xxfd can controller driver kernel
2019-04-19 5:14 ` [PATCH V7 RESEND 01/10] dt-binding: can: mcp25xxfd: document device tree bindings kernel
2019-04-19 5:14 ` [PATCH V7 RESEND 02/10] can: mcp25xxfd: Add Microchip mcp25xxfd CAN FD driver basics kernel
2019-04-19 5:14 ` [PATCH V7 RESEND 03/10] can: mcp25xxfd: add gpiolib support for GPIO0/1 (aka. INT0/INT1) kernel
2019-04-19 5:14 ` [PATCH V7 RESEND 04/10] can: mcp25xxfd: Add Microchip mcp25xxfd CAN FD driver kernel
2019-05-08 13:12 ` Marc Kleine-Budde
2019-05-08 16:00 ` kernel
2019-04-19 5:14 ` [PATCH V7 RESEND 05/10] can: mcp25xxfd: Add Can transmission support kernel
2019-04-19 5:14 ` kernel [this message]
2019-04-19 5:14 ` [PATCH V7 RESEND 07/10] can: mcp25xxfd: optimize TEF reads reading multiple TEFs in one go kernel
2019-04-19 5:14 ` [PATCH V7 RESEND 08/10] can: mcp25xxfd: optimize SPI reads of FIFOs in can2.0 mode kernel
2019-04-19 5:14 ` [PATCH V7 RESEND 09/10] can: mcp25xxfd: add prediction of CanFD frames sizes based on history kernel
2019-04-19 5:14 ` [PATCH V7 RESEND 10/10] can: mcp25xxfd: optimize reception of big CanFD frame reception with BRS kernel
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=20190419051432.13538-7-kernel@martin.sperl.org \
--to=kernel@martin.sperl.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mkl@pengutronix.de \
--cc=robh+dt@kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).