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

Arun Muthusamy
2026-01-27T14:06:58Z

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.

-- BR, Arun Muthusamy Software Engineer Frontgrade Gaisler T : +46 (0)
700 558 528 arun.muthusamy@gaisler.com Frontgrade Gaisler AB, Kungsgatan
12, SE-411 19 GÖTEBORG, Sweden. +46 (0) 31 775 8650, www.gaisler.com
<http://www.gaisler.com>