From: Vincent Mailhol <mailhol@kernel.org>
To: Arun Muthusamy <arun.muthusamy@gaisler.com>,
robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org,
mkl@pengutronix.de, mailhol@kernel.org
Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-can@vger.kernel.org, Daniel Hellstrom <daniel@gaisler.com>
Subject: Re: [PATCH v2 06/10] can: grcan: optimize DMA by 32-bit accesses
Date: Tue, 23 Dec 2025 21:40:21 +0100 [thread overview]
Message-ID: <6a033bd5-e9be-49c9-82a7-33874321480b@kernel.org> (raw)
In-Reply-To: <20251223105604.12675-7-arun.muthusamy@gaisler.com>
On 23/12/2025 at 11:56, Arun Muthusamy wrote:
> From: Daniel Hellstrom <daniel@gaisler.com>
>
> Optimizes DMA transfers in the GRCAN driver by reorganizing
> data handling to use 32-bit accesses instead of individual
> byte accesses.
>
> Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
> Signed-off-by: Arun Muthusamy <arun.muthusamy@gaisler.com>
> ---
> drivers/net/can/grcan.c | 22 +++++++++++-----------
> 1 file changed, 11 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/net/can/grcan.c b/drivers/net/can/grcan.c
> index cac85fbe6acf..8a6c59473cf4 100644
> --- a/drivers/net/can/grcan.c
> +++ b/drivers/net/can/grcan.c
> @@ -1218,7 +1218,7 @@ static int grcan_receive(struct net_device *dev, int budget)
> struct sk_buff *skb;
> u32 wr, rd, startrd;
> u32 *slot;
> - u32 i, rtr, eff, j, shift;
> + u32 rtr, eff;
> int work_done = 0;
>
> rd = grcan_read_reg(®s->rxrd);
> @@ -1254,10 +1254,10 @@ static int grcan_receive(struct net_device *dev, int budget)
> if (rtr) {
> cf->can_id |= CAN_RTR_FLAG;
> } else {
> - for (i = 0; i < cf->len; i++) {
> - j = GRCAN_MSG_DATA_SLOT_INDEX(i);
> - shift = GRCAN_MSG_DATA_SHIFT(i);
> - cf->data[i] = (u8)(slot[j] >> shift);
> + if (cf->can_dlc > 0) {
> + memcpy(cf->data, &slot[2], sizeof(u32));
> + if (cf->can_dlc > 4)
> + memcpy(cf->data + 4, &slot[3], sizeof(u32));
> }
Nitpick: you may instead do:
if (cf->can_dlc > 0)
memcpy(cf->data, &slot[2], sizeof(u32));
if (cf->can_dlc > 4)
memcpy(cf->data + 4, &slot[3], sizeof(u32));
and let the compiler take care of the optimization for you ;)
>
> stats->rx_bytes += cf->len;
> @@ -1397,8 +1397,7 @@ static netdev_tx_t grcan_start_xmit(struct sk_buff *skb,
> u32 id, txwr, txrd, space, txctrl;
> int slotindex;
> u32 *slot;
> - u32 i, rtr, eff, dlc, tmp, err;
> - int j, shift;
> + u32 rtr, eff, dlc, tmp, err;
> unsigned long flags;
> u32 oneshotmode = priv->can.ctrlmode & CAN_CTRLMODE_ONE_SHOT;
>
> @@ -1451,10 +1450,11 @@ static netdev_tx_t grcan_start_xmit(struct sk_buff *skb,
> slot[1] = ((dlc << GRCAN_MSG_DLC_BIT) & GRCAN_MSG_DLC);
> slot[2] = 0;
> slot[3] = 0;
> - for (i = 0; i < dlc; i++) {
> - j = GRCAN_MSG_DATA_SLOT_INDEX(i);
> - shift = GRCAN_MSG_DATA_SHIFT(i);
> - slot[j] |= cf->data[i] << shift;
> + if (dlc > 0) {
> + memcpy(&slot[2], cf->data, sizeof(u32));
> + slot[2] = *(u32 *)(cf->data);
Why do you have both the memcpy() and the "slot[2] =" assignment?
> + if (dlc > 4)
> + memcpy(&slot[3], cf->data + 4, sizeof(u32));
> }
>
> /* Checking that channel has not been disabled. These cases
Don't forget also to remove the unused macros.
Yours sincerely,
Vincent Mailhol
next prev parent reply other threads:[~2025-12-23 20:40 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-23 10:55 [PATCH v2 00/10] can: grcan: Enhance driver with CANFD Support and Improvements Arun Muthusamy
2025-12-23 10:55 ` [PATCH v2 01/10] dt-bindings: Add vendor prefix for Frontgrade Gaisler AB Arun Muthusamy
2025-12-27 12:31 ` Krzysztof Kozlowski
2025-12-23 10:55 ` [PATCH v2 02/10] dt-bindings: net: can: grcan: Convert GRCAN CAN controllers binding from txt to YAML Arun Muthusamy
2025-12-24 2:29 ` kernel test robot
2025-12-30 2:19 ` Rob Herring
2025-12-23 10:55 ` [PATCH v2 03/10] MAINTAINERS: Add maintainers for GRCAN CAN network driver Arun Muthusamy
2025-12-23 10:55 ` [PATCH v2 04/10] can: grcan: Add clock handling Arun Muthusamy
2025-12-23 10:55 ` [PATCH v2 05/10] can: grcan: add FD capability detection and nominal bit-timing Arun Muthusamy
2025-12-23 20:51 ` Vincent Mailhol
2025-12-23 10:56 ` [PATCH v2 06/10] can: grcan: optimize DMA by 32-bit accesses Arun Muthusamy
2025-12-23 20:40 ` Vincent Mailhol [this message]
2025-12-23 10:56 ` [PATCH v2 07/10] can: grcan: set DMA mask for GRCAN and GRCANFD to 32-bit Arun Muthusamy
2025-12-23 10:56 ` [PATCH v2 08/10] can: grcan: Add saving and restoring of CAN FD baud-rate registers Arun Muthusamy
2025-12-23 10:56 ` [PATCH v2 09/10] can: grcan: Reserve space between cap and next register to align with address layout Arun Muthusamy
2025-12-23 10:56 ` [PATCH v2 10/10] can: grcan: Add CANFD support alongside legacy CAN Arun Muthusamy
2025-12-23 21:09 ` Vincent Mailhol
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=6a033bd5-e9be-49c9-82a7-33874321480b@kernel.org \
--to=mailhol@kernel.org \
--cc=arun.muthusamy@gaisler.com \
--cc=conor+dt@kernel.org \
--cc=daniel@gaisler.com \
--cc=devicetree@vger.kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mkl@pengutronix.de \
--cc=robh@kernel.org \
/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