Skip to content

Commit ac2b81e

Browse files
can: mcp251xfd: mcp251xfd_ring_init(): check TX-coalescing configuration
When changing the interface from CAN-CC to CAN-FD mode the old coalescing parameters are re-used. This might cause problem, as the configured parameters are too big for CAN-FD mode. During testing an invalid TX coalescing configuration has been seen. The problem should be been fixed in the previous patch, but add a safeguard here to ensure that the number of TEF coalescing buffers (if configured) is exactly the half of all TEF buffers. Link: https://lore.kernel.org/all/20240805-mcp251xfd-fix-ringconfig-v1-2-72086f0ca5ee@pengutronix.de Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
1 parent 50ea544 commit ac2b81e

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

drivers/net/can/spi/mcp251xfd/mcp251xfd-ring.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ int mcp251xfd_ring_init(struct mcp251xfd_priv *priv)
290290
const struct mcp251xfd_rx_ring *rx_ring;
291291
u16 base = 0, ram_used;
292292
u8 fifo_nr = 1;
293-
int i;
293+
int err = 0, i;
294294

295295
netdev_reset_queue(priv->ndev);
296296

@@ -386,10 +386,18 @@ int mcp251xfd_ring_init(struct mcp251xfd_priv *priv)
386386
netdev_err(priv->ndev,
387387
"Error during ring configuration, using more RAM (%u bytes) than available (%u bytes).\n",
388388
ram_used, MCP251XFD_RAM_SIZE);
389-
return -ENOMEM;
389+
err = -ENOMEM;
390390
}
391391

392-
return 0;
392+
if (priv->tx_obj_num_coalesce_irq &&
393+
priv->tx_obj_num_coalesce_irq * 2 != priv->tx->obj_num) {
394+
netdev_err(priv->ndev,
395+
"Error during ring configuration, number of TEF coalescing buffers (%u) must be half of TEF buffers (%u).\n",
396+
priv->tx_obj_num_coalesce_irq, priv->tx->obj_num);
397+
err = -EINVAL;
398+
}
399+
400+
return err;
393401
}
394402

395403
void mcp251xfd_ring_free(struct mcp251xfd_priv *priv)

0 commit comments

Comments
 (0)