From: Vincent Mailhol <mailhol@kernel.org>
To: Arun Muthusamy <arun.muthusamy@gaisler.com>
Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-can@vger.kernel.org, robh@kernel.org, krzk+dt@kernel.org,
conor+dt@kernel.org, mkl@pengutronix.de
Subject: Re: [PATCH v5 12/16] can: grcan: Refactor GRCAN DMA buffer to use structured memory layout
Date: Sun, 22 Feb 2026 16:46:18 +0100 [thread overview]
Message-ID: <e1517670-92f9-405d-934e-b9341bea27ac@kernel.org> (raw)
In-Reply-To: <20260216135344.23246-13-arun.muthusamy@gaisler.com>
On 16/02/2026 at 14:53, Arun Muthusamy wrote:
> Introduce a structured layout that accurately represents the hardware memory by using struct grcan_msg_slot.
> This structure encapsulates the message parameters, including id, dlc, and data.
>
> Signed-off-by: Arun Muthusamy <arun.muthusamy@gaisler.com>
> ---
> drivers/net/can/grcan.c | 25 ++++++++++++++++++++-----
> 1 file changed, 20 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/can/grcan.c b/drivers/net/can/grcan.c
> index 3104946071dd..28fa219e1c3b 100644
> --- a/drivers/net/can/grcan.c
> +++ b/drivers/net/can/grcan.c
> @@ -174,6 +174,7 @@ struct grcan_registers {
> #define GRCAN_IRQ_DEFAULT (GRCAN_IRQ_RX | GRCAN_IRQ_TX | GRCAN_IRQ_ERRORS)
>
> #define GRCAN_MSG_SIZE 16
> +#define GRCAN_CLASSIC_DATA_SIZE 8
>
> #define GRCAN_MSG_IDE 0x80000000
> #define GRCAN_MSG_RTR 0x40000000
> @@ -239,9 +240,23 @@ struct grcan_hwcap {
> bool fd;
> };
>
> +union grcan_msg_slot {
> + /* First slot: header + 8 bytes payload */
> + struct {
> + u32 id;
> + u32 ctrl;
> + u8 data[GRCAN_CLASSIC_DATA_SIZE];
^^^^^^^^^^^^^^^^^^^^^^^
Remove this GRCAN_CLASSIC_DATA_SIZE macro and instead use CAN_MAX_DLEN.
> + } __packed header;
> +
> + /* Continuation slot: payload only */
> + struct {
> + u8 data[GRCAN_MSG_SIZE];
> + } __packed frags;
> +} __packed;
> +
> struct grcan_dma_buffer {
> size_t size;
> - void *buf;
> + union grcan_msg_slot *msg_slot;
> dma_addr_t handle;
> };
Nitpick: you can use an anonymous union:
/* First slot: header + 8 bytes payload */
struct grcan_msg_header {
u32 id;
u32 ctrl;
u8 data[CAN_MAX_DLEN];
} __packed;
/* Continuation slot: payload only */
struct grcan_msg_fragment {
u8 data[GRCAN_MSG_SIZE];
} __packed;
struct grcan_dma_buffer {
size_t size;
void *buf;
union {
struct grcan_msg_header *header;
struct grcan_msg_fragment *frag;
};
dma_addr_t handle;
};
With this, you can do:
dma->rx->header
dma->rx->frag
instead of:
dma->rx.msg_slot->header
dma->rx.msg_slot->frag
> @@ -1019,8 +1034,8 @@ static int grcan_allocate_dma_buffers(struct net_device *dev,
> small->handle = large->handle + lsize;
> shift = large->handle - dma->base_handle;
>
> - large->buf = dma->base_buf + shift;
> - small->buf = large->buf + lsize;
> + large->msg_slot = (union grcan_msg_slot *)((u8 *)dma->base_buf + shift);
> + small->msg_slot = (union grcan_msg_slot *)((u8 *)large->msg_slot + lsize);
>
> return 0;
> }
> @@ -1237,7 +1252,7 @@ static int grcan_receive(struct net_device *dev, int budget)
> continue;
> }
>
> - slot = dma->rx.buf + rd;
> + slot = (u32 *)((u8 *)dma->rx.msg_slot + rd);
> eff = slot[0] & GRCAN_MSG_IDE;
> rtr = slot[0] & GRCAN_MSG_RTR;
> if (eff) {
> @@ -1418,7 +1433,7 @@ static netdev_tx_t grcan_start_xmit(struct sk_buff *skb,
> space = grcan_txspace(dma->tx.size, txwr, priv->eskbp);
>
> slotindex = txwr / GRCAN_MSG_SIZE;
> - slot = dma->tx.buf + txwr;
> + slot = (u32 *)((u8 *)dma->tx.msg_slot + txwr);
As told in my previous message, refactor the code in this commit.
> if (unlikely(space == 1))
> netif_stop_queue(dev);
Yours sincerely,
Vincent Mailhol
next prev parent reply other threads:[~2026-02-22 15:46 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-16 13:53 [PATCH v5 00/16] can: grcan: Enhance driver with CANFD Support and Improvements Arun Muthusamy
2026-02-16 13:53 ` [PATCH v5 01/16] dt-bindings: Add vendor prefix for Frontgrade Gaisler AB Arun Muthusamy
2026-02-16 14:53 ` Krzysztof Kozlowski
2026-02-16 13:53 ` [PATCH v5 02/16] net: can: Convert gaisler,grcan to DT schema Arun Muthusamy
2026-02-16 14:59 ` Krzysztof Kozlowski
2026-02-16 13:53 ` [PATCH v5 03/16] MAINTAINERS: Add maintainers for GRCAN CAN network driver Arun Muthusamy
2026-02-16 13:53 ` [PATCH v5 04/16] can: grcan: Add clock handling Arun Muthusamy
2026-02-16 13:53 ` [PATCH v5 05/16] can: grcan: Replace bit timing macros with literal values Arun Muthusamy
2026-02-16 15:01 ` Krzysztof Kozlowski
2026-03-05 15:43 ` Arun Muthusamy
2026-02-16 13:53 ` [PATCH v5 06/16] can: grcan: Simplify timing configuration Arun Muthusamy
2026-02-16 13:53 ` [PATCH v5 07/16] can: grcan: add FD capability detection and nominal bit-timing Arun Muthusamy
2026-02-16 13:53 ` [PATCH v5 08/16] can: grcan: optimize DMA by 32-bit accesses Arun Muthusamy
2026-02-16 13:53 ` [PATCH v5 09/16] can: grcan: set DMA mask for GRCAN and GRCANFD to 32-bit Arun Muthusamy
2026-02-16 13:53 ` [PATCH v5 10/16] can: grcan: Add saving and restoring of CAN FD baud-rate registers Arun Muthusamy
2026-02-16 13:53 ` [PATCH v5 11/16] can: grcan: Reserve space between cap and next register to align with address layout Arun Muthusamy
2026-02-16 13:53 ` [PATCH v5 12/16] can: grcan: Refactor GRCAN DMA buffer to use structured memory layout Arun Muthusamy
2026-02-22 15:46 ` Vincent Mailhol [this message]
2026-02-16 13:53 ` [PATCH v5 13/16] can: grcan: Add CANFD TX support alongside legacy CAN Arun Muthusamy
2026-02-22 15:28 ` Vincent Mailhol
2026-02-16 13:53 ` [PATCH v5 14/16] can: grcan: Add CANFD RX " Arun Muthusamy
2026-02-16 13:53 ` [PATCH v5 15/16] can: grcan: Update echo skb handling to match variable length CANFD frame Arun Muthusamy
2026-02-16 13:53 ` [PATCH v5 16/16] can: grcan: Advertise CANFD capability Arun Muthusamy
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=e1517670-92f9-405d-934e-b9341bea27ac@kernel.org \
--to=mailhol@kernel.org \
--cc=arun.muthusamy@gaisler.com \
--cc=conor+dt@kernel.org \
--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