Re: [PATCH v3 13/15] can: grcan: Add CANFD TX support alongside legacy CAN

Marc Kleine-Budde
2026-01-27T14:13:03Z

[-- Attachment #1: Type: text/plain, Size: 3340 bytes --]

On 27.01.2026 15:06:55, Arun Muthusamy wrote:
>
> On 1/23/26 15:25, Marc Kleine-Budde wrote:
> > On 22.01.2026 13:10:36, Arun Muthusamy wrote:
> > > Include CANFD TX support with the legacy CAN support, enabling
> > > support for extended data payloads to provide higher bit rates.
> > >
> > > Signed-off-by: Arun Muthusamy <arun.muthusamy@gaisler.com>
> > > ---
> > > drivers/net/can/grcan.c | 102 +++++++++++++++++++++++++++++-----------
> > > 1 file changed, 74 insertions(+), 28 deletions(-)
> > >
> > > diff --git a/drivers/net/can/grcan.c b/drivers/net/can/grcan.c
> > > index 9fc18064fab1..508ad5320cff 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
> > > @@ -195,6 +196,10 @@ struct grcan_registers {
> > > #define GRCAN_MSG_OFF 0x00000002
> > > #define GRCAN_MSG_PASS 0x00000001
> > >
> > > +#define GRCAN_MSG_EID_MASK GENMASK(28, 0)
> > > +#define GRCAN_MSG_BID_MASK GENMASK(28, 18)
> > > +#define GRCAN_MSG_DLC_MASK GENMASK(31, 28)
> > > +
> > > #define GRCAN_BUFFER_ALIGNMENT 1024
> > > #define GRCAN_DEFAULT_BUFFER_SIZE 1024
> > > #define GRCAN_VALID_TR_SIZE_MASK 0x001fffc0
> > > @@ -227,6 +232,9 @@ struct grcan_registers {
> > > #define GRCANFD_FDBTR_PS2_BIT 5
> > > #define GRCANFD_FDBTR_SJW_BIT 0
> > >
> > > +#define GRCAN_TX_BRS BIT(25)
> > > +#define GRCAN_TX_FDF BIT(26)
> > > +
> > > /* Hardware capabilities */
> > > struct grcan_hwcap {
> > > /* CAN-FD capable, indicates GRCANFD IP.
> > > @@ -1218,6 +1226,13 @@ static void grcan_transmit_catch_up(struct net_device *dev)
> > > spin_unlock_irqrestore(&priv->lock, flags);
> > > }
> > >
> > > +static int grcan_numbds(int len)
> > > +{
> > > + if (len <= GRCAN_CLASSIC_DATA_SIZE)
> > > + return 1;
> > > + return 1 + ((len - GRCAN_CLASSIC_DATA_SIZE + GRCAN_MSG_SIZE) / GRCAN_MSG_SIZE);
> > This looks strange, what is calculated here? Why is "<=
> > GRCAN_CLASSIC_DATA_SIZE" a special case?
>
> grcan_numbds() calculates the number of buffer descriptors needed based on the data length.
> The condition "len <= GRCAN_CLASSIC_DATA_SIZE" addresses cases where the data length fits within a one buffer descriptor.
> For data lengths greater than "GRCAN_CLASSIC_DATA_SIZE", it computes additional descriptors needed.

What happens if "len = GRCAN_CLASSIC_DATA_SIZE + GRCAN_MSG_SIZE"?

| return 1 + ((len - GRCAN_CLASSIC_DATA_SIZE + GRCAN_MSG_SIZE) / GRCAN_MSG_SIZE);

= 1 + ((GRCAN_CLASSIC_DATA_SIZE + GRCAN_MSG_SIZE - GRCAN_CLASSIC_DATA_SIZE + GRCAN_MSG_SIZE) / GRCAN_MSG_SIZE);
= 1 + (( GRCAN_MSG_SIZE - + GRCAN_MSG_SIZE) / GRCAN_MSG_SIZE);
= 1 + 2;
= 3

Is this correct?

regards,
Marc

--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung Nürnberg | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]