Subject: [PATCH 00/15] can: m_can: Optimizations for tcan and peripheral chips

Hi,

this series is aimed at optimizing the driver code for tcan chips and
more generally for peripheral m_can chips.

I did different things to improve the performance:
- Reduce the number of SPI transfers.
- Reduce the number of interrupts.
- Enable use of FIFOs.

I am working with a tcan4550 in loopback mode attached to a beaglebone
black. I am currently working on optimizing the receive path as well
which will be submitted in another series once it is done.

Best,
Markus

Markus Schneider-Pargmann (15):
can: m_can: Eliminate double read of TXFQS in tx_handler
can: m_can: Wakeup net queue once tx was issued
can: m_can: Cache tx putidx and transmits in flight
can: m_can: Use transmit event FIFO watermark level interrupt
can: m_can: Disable unused interrupts
can: m_can: Avoid reading irqstatus twice
can: m_can: Read register PSR only on error
can: m_can: Count TXE FIFO getidx in the driver
can: m_can: Count read getindex in the driver
can: m_can: Batch acknowledge rx fifo
can: m_can: Batch acknowledge transmit events
can: tcan4x5x: Remove invalid write in clear_interrupts
can: tcan4x5x: Fix use of register error status mask
can: tcan4x5x: Fix register range of first block
can: tcan4x5x: Specify separate read/write ranges

drivers/net/can/m_can/m_can.c | 140 +++++++++++++++---------
drivers/net/can/m_can/m_can.h | 5 +
drivers/net/can/m_can/tcan4x5x-core.c | 19 ++--
drivers/net/can/m_can/tcan4x5x-regmap.c | 45 ++++++--
4 files changed, 141 insertions(+), 68 deletions(-)


base-commit: 094226ad94f471a9f19e8f8e7140a09c2625abaa
prerequisite-patch-id: e9df6751d43bb0d1e3b8938d7e93bc1cfa22cef2
prerequisite-patch-id: dad9ec37af766bcafe54cb156f896267a0f47fe1
prerequisite-patch-id: f4e6f1a213a31df2741a5fa3baa87aa45ef6707a
--
2.38.1



Subject: [PATCH 12/15] can: tcan4x5x: Remove invalid write in clear_interrupts

Register 0x824 TCAN4X5X_MCAN_INT_REG is a read-only register. Any writes
to this register do not have any effect.

Remove this write. The m_can driver aldready clears the interrupts in
m_can_isr() by writing to M_CAN_IR which is translated to register
0x1050 which is a writable version of this register.

Signed-off-by: Markus Schneider-Pargmann <[email protected]>
---
drivers/net/can/m_can/tcan4x5x-core.c | 5 -----
1 file changed, 5 deletions(-)

diff --git a/drivers/net/can/m_can/tcan4x5x-core.c b/drivers/net/can/m_can/tcan4x5x-core.c
index 41645a24384c..1fec394b3517 100644
--- a/drivers/net/can/m_can/tcan4x5x-core.c
+++ b/drivers/net/can/m_can/tcan4x5x-core.c
@@ -204,11 +204,6 @@ static int tcan4x5x_clear_interrupts(struct m_can_classdev *cdev)
if (ret)
return ret;

- ret = tcan4x5x_write_tcan_reg(cdev, TCAN4X5X_MCAN_INT_REG,
- TCAN4X5X_ENABLE_MCAN_INT);
- if (ret)
- return ret;
-
ret = tcan4x5x_write_tcan_reg(cdev, TCAN4X5X_INT_FLAGS,
TCAN4X5X_CLEAR_ALL_INT);
if (ret)
--
2.38.1


Subject: [PATCH 08/15] can: m_can: Count TXE FIFO getidx in the driver

The getindex simply increases by one for every iteration. There is no
need to get the current getidx every time from a register. Instead we
can just count and wrap if necessary.

Signed-off-by: Markus Schneider-Pargmann <[email protected]>
---
drivers/net/can/m_can/m_can.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index 1d15beaea920..27095a7254dd 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -1021,15 +1021,13 @@ static int m_can_echo_tx_event(struct net_device *dev)

/* Get Tx Event fifo element count */
txe_count = FIELD_GET(TXEFS_EFFL_MASK, m_can_txefs);
+ fgi = FIELD_GET(TXEFS_EFGI_MASK, m_can_txefs);

/* Get and process all sent elements */
for (i = 0; i < txe_count; i++) {
u32 txe, timestamp = 0;
int err;

- /* retrieve get index */
- fgi = FIELD_GET(TXEFS_EFGI_MASK, m_can_read(cdev, M_CAN_TXEFS));
-
/* get message marker, timestamp */
err = m_can_txe_fifo_read(cdev, fgi, 4, &txe);
if (err) {
@@ -1043,6 +1041,7 @@ static int m_can_echo_tx_event(struct net_device *dev)
/* ack txe element */
m_can_write(cdev, M_CAN_TXEFA, FIELD_PREP(TXEFA_EFAI_MASK,
fgi));
+ fgi = (++fgi >= cdev->mcfg[MRAM_TXE].num ? 0 : fgi);
--cdev->tx_fifo_in_flight;

/* update stats */
--
2.38.1


2022-12-02 14:23:46

by Marc Kleine-Budde

[permalink] [raw]
Subject: Re: [PATCH 00/15] can: m_can: Optimizations for tcan and peripheral chips

On 16.11.2022 21:52:53, Markus Schneider-Pargmann wrote:
> Hi,
>
> this series is aimed at optimizing the driver code for tcan chips and
> more generally for peripheral m_can chips.
>
> I did different things to improve the performance:
> - Reduce the number of SPI transfers.
> - Reduce the number of interrupts.
> - Enable use of FIFOs.
>
> I am working with a tcan4550 in loopback mode attached to a beaglebone
> black. I am currently working on optimizing the receive path as well
> which will be submitted in another series once it is done.

The patches I've not commented on look fine. If you re-spin the series
only containing those, I'll include them in my next pull request, which
I'll send out soonish.

regards,
Marc

> Best,
> Markus
>
> Markus Schneider-Pargmann (15):
> can: m_can: Eliminate double read of TXFQS in tx_handler
> can: m_can: Wakeup net queue once tx was issued
> can: m_can: Cache tx putidx and transmits in flight
> can: m_can: Use transmit event FIFO watermark level interrupt
> can: m_can: Disable unused interrupts
> can: m_can: Avoid reading irqstatus twice
> can: m_can: Read register PSR only on error
> can: m_can: Count TXE FIFO getidx in the driver
> can: m_can: Count read getindex in the driver
> can: m_can: Batch acknowledge rx fifo
> can: m_can: Batch acknowledge transmit events
> can: tcan4x5x: Remove invalid write in clear_interrupts
> can: tcan4x5x: Fix use of register error status mask
> can: tcan4x5x: Fix register range of first block
> can: tcan4x5x: Specify separate read/write ranges
>
> drivers/net/can/m_can/m_can.c | 140 +++++++++++++++---------
> drivers/net/can/m_can/m_can.h | 5 +
> drivers/net/can/m_can/tcan4x5x-core.c | 19 ++--
> drivers/net/can/m_can/tcan4x5x-regmap.c | 45 ++++++--
> 4 files changed, 141 insertions(+), 68 deletions(-)
>
>
> base-commit: 094226ad94f471a9f19e8f8e7140a09c2625abaa
> prerequisite-patch-id: e9df6751d43bb0d1e3b8938d7e93bc1cfa22cef2
> prerequisite-patch-id: dad9ec37af766bcafe54cb156f896267a0f47fe1
> prerequisite-patch-id: f4e6f1a213a31df2741a5fa3baa87aa45ef6707a

BTW: I don't have access to these prerequisite-patch-id.

--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |


Attachments:
(No filename) (2.46 kB)
signature.asc (499.00 B)
Download all attachments

2022-12-02 14:44:10

by Marc Kleine-Budde

[permalink] [raw]
Subject: Re: [PATCH 12/15] can: tcan4x5x: Remove invalid write in clear_interrupts

On 16.11.2022 21:53:05, Markus Schneider-Pargmann wrote:
> Register 0x824 TCAN4X5X_MCAN_INT_REG is a read-only register. Any writes
> to this register do not have any effect.
>
> Remove this write. The m_can driver aldready clears the interrupts in
> m_can_isr() by writing to M_CAN_IR which is translated to register
> 0x1050 which is a writable version of this register.
>
> Signed-off-by: Markus Schneider-Pargmann <[email protected]>

Please add a fixes tag.

Marc

> ---
> drivers/net/can/m_can/tcan4x5x-core.c | 5 -----
> 1 file changed, 5 deletions(-)
>
> diff --git a/drivers/net/can/m_can/tcan4x5x-core.c b/drivers/net/can/m_can/tcan4x5x-core.c
> index 41645a24384c..1fec394b3517 100644
> --- a/drivers/net/can/m_can/tcan4x5x-core.c
> +++ b/drivers/net/can/m_can/tcan4x5x-core.c
> @@ -204,11 +204,6 @@ static int tcan4x5x_clear_interrupts(struct m_can_classdev *cdev)
> if (ret)
> return ret;
>
> - ret = tcan4x5x_write_tcan_reg(cdev, TCAN4X5X_MCAN_INT_REG,
> - TCAN4X5X_ENABLE_MCAN_INT);
> - if (ret)
> - return ret;
> -
> ret = tcan4x5x_write_tcan_reg(cdev, TCAN4X5X_INT_FLAGS,
> TCAN4X5X_CLEAR_ALL_INT);
> if (ret)
> --
> 2.38.1
>
>

--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |


Attachments:
(No filename) (1.46 kB)
signature.asc (499.00 B)
Download all attachments
Subject: Re: [PATCH 00/15] can: m_can: Optimizations for tcan and peripheral chips

Good Morning Marc,

On Fri, Dec 02, 2022 at 03:03:06PM +0100, Marc Kleine-Budde wrote:
> On 16.11.2022 21:52:53, Markus Schneider-Pargmann wrote:
> > Hi,
> >
> > this series is aimed at optimizing the driver code for tcan chips and
> > more generally for peripheral m_can chips.
> >
> > I did different things to improve the performance:
> > - Reduce the number of SPI transfers.
> > - Reduce the number of interrupts.
> > - Enable use of FIFOs.
> >
> > I am working with a tcan4550 in loopback mode attached to a beaglebone
> > black. I am currently working on optimizing the receive path as well
> > which will be submitted in another series once it is done.
>
> The patches I've not commented on look fine. If you re-spin the series
> only containing those, I'll include them in my next pull request, which
> I'll send out soonish.

Ok, thank you, I will send a subset of the patches today.

>
> regards,
> Marc
>
> > Best,
> > Markus
> >
> > Markus Schneider-Pargmann (15):
> > can: m_can: Eliminate double read of TXFQS in tx_handler
> > can: m_can: Wakeup net queue once tx was issued
> > can: m_can: Cache tx putidx and transmits in flight
> > can: m_can: Use transmit event FIFO watermark level interrupt
> > can: m_can: Disable unused interrupts
> > can: m_can: Avoid reading irqstatus twice
> > can: m_can: Read register PSR only on error
> > can: m_can: Count TXE FIFO getidx in the driver
> > can: m_can: Count read getindex in the driver
> > can: m_can: Batch acknowledge rx fifo
> > can: m_can: Batch acknowledge transmit events
> > can: tcan4x5x: Remove invalid write in clear_interrupts
> > can: tcan4x5x: Fix use of register error status mask
> > can: tcan4x5x: Fix register range of first block
> > can: tcan4x5x: Specify separate read/write ranges
> >
> > drivers/net/can/m_can/m_can.c | 140 +++++++++++++++---------
> > drivers/net/can/m_can/m_can.h | 5 +
> > drivers/net/can/m_can/tcan4x5x-core.c | 19 ++--
> > drivers/net/can/m_can/tcan4x5x-regmap.c | 45 ++++++--
> > 4 files changed, 141 insertions(+), 68 deletions(-)
> >
> >
> > base-commit: 094226ad94f471a9f19e8f8e7140a09c2625abaa
> > prerequisite-patch-id: e9df6751d43bb0d1e3b8938d7e93bc1cfa22cef2
> > prerequisite-patch-id: dad9ec37af766bcafe54cb156f896267a0f47fe1
> > prerequisite-patch-id: f4e6f1a213a31df2741a5fa3baa87aa45ef6707a
>
> BTW: I don't have access to these prerequisite-patch-id.

I think I messed up here. I have three patches, SPI fixes and devicetree
snippet that this series is based on. I guess I shouldn't have used
--base then or rebase on something without these patches first.

Thanks,
Markus