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

Marc Kleine-Budde
2026-01-23T14:25:31Z

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

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?

> +}
> +
> static int grcan_receive(struct net_device *dev, int budget)
> {
> struct grcan_priv *priv = netdev_priv(dev);
> @@ -1400,15 +1415,22 @@ static netdev_tx_t grcan_start_xmit(struct sk_buff *skb,
> struct net_device *dev)
> {
> struct grcan_priv *priv = netdev_priv(dev);
> - struct grcan_registers __iomem *regs = priv->regs;
> + struct grcan_registers __iomem *regs;
> + u32 eff, rtr, dlc, tmp, err, can_id;
> struct grcan_dma *dma = &priv->dma;
> - struct can_frame *cf = (struct can_frame *)skb->data;
> + u32 bds, copy_len, payload_offset;
> u32 id, txwr, txrd, space, txctrl;
> - int slotindex;
> - u32 *slot;
> - u32 rtr, eff, dlc, tmp, err;
> + struct canfd_frame *cfd;
> + struct can_frame *cf;
> unsigned long flags;
> - u32 oneshotmode = priv->can.ctrlmode & CAN_CTRLMODE_ONE_SHOT;
> + u32 oneshotmode;
> + u8 *payload;
> + u32 *slot;
> + u8 len;
> + int i;
> +
> + regs = priv->regs;
> + oneshotmode = priv->can.ctrlmode & CAN_CTRLMODE_ONE_SHOT;
>
> if (can_dev_dropped_skb(dev, skb))
> return NETDEV_TX_OK;
> @@ -1419,6 +1441,18 @@ static netdev_tx_t grcan_start_xmit(struct sk_buff *skb,
> if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY)
> return NETDEV_TX_BUSY;
>
> + cfd = (struct canfd_frame *)skb->data;
> + len = cfd->len;
> + can_id = cfd->can_id;
> + payload = cfd->data;

one space in front of the "=" please

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 --]