Skip to content

Commit 50ea544

Browse files
can: mcp251xfd: fix ring configuration when switching from CAN-CC to CAN-FD mode
If the ring (rx, tx) and/or coalescing parameters (rx-frames-irq, tx-frames-irq) have been configured while the interface was in CAN-CC mode, but the interface is brought up in CAN-FD mode, the ring parameters might be too big. Use the default CAN-FD values in this case. Fixes: 9263c2e ("can: mcp251xfd: ring: add support for runtime configurable RX/TX ring parameters") Link: https://lore.kernel.org/all/20240805-mcp251xfd-fix-ringconfig-v1-1-72086f0ca5ee@pengutronix.de Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
1 parent 053ae05 commit 50ea544

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,16 @@ void can_ram_get_layout(struct can_ram_layout *layout,
9797
if (ring) {
9898
u8 num_rx_coalesce = 0, num_tx_coalesce = 0;
9999

100-
num_rx = can_ram_rounddown_pow_of_two(config, &config->rx, 0, ring->rx_pending);
100+
/* If the ring parameters have been configured in
101+
* CAN-CC mode, but and we are in CAN-FD mode now,
102+
* they might be to big. Use the default CAN-FD values
103+
* in this case.
104+
*/
105+
num_rx = ring->rx_pending;
106+
if (num_rx > layout->max_rx)
107+
num_rx = layout->default_rx;
108+
109+
num_rx = can_ram_rounddown_pow_of_two(config, &config->rx, 0, num_rx);
101110

102111
/* The ethtool doc says:
103112
* To disable coalescing, set usecs = 0 and max_frames = 1.

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,11 +469,25 @@ int mcp251xfd_ring_alloc(struct mcp251xfd_priv *priv)
469469

470470
/* switching from CAN-2.0 to CAN-FD mode or vice versa */
471471
if (fd_mode != test_bit(MCP251XFD_FLAGS_FD_MODE, priv->flags)) {
472+
const struct ethtool_ringparam ring = {
473+
.rx_pending = priv->rx_obj_num,
474+
.tx_pending = priv->tx->obj_num,
475+
};
476+
const struct ethtool_coalesce ec = {
477+
.rx_coalesce_usecs_irq = priv->rx_coalesce_usecs_irq,
478+
.rx_max_coalesced_frames_irq = priv->rx_obj_num_coalesce_irq,
479+
.tx_coalesce_usecs_irq = priv->tx_coalesce_usecs_irq,
480+
.tx_max_coalesced_frames_irq = priv->tx_obj_num_coalesce_irq,
481+
};
472482
struct can_ram_layout layout;
473483

474-
can_ram_get_layout(&layout, &mcp251xfd_ram_config, NULL, NULL, fd_mode);
475-
priv->rx_obj_num = layout.default_rx;
476-
tx_ring->obj_num = layout.default_tx;
484+
can_ram_get_layout(&layout, &mcp251xfd_ram_config, &ring, &ec, fd_mode);
485+
486+
priv->rx_obj_num = layout.cur_rx;
487+
priv->rx_obj_num_coalesce_irq = layout.rx_coalesce;
488+
489+
tx_ring->obj_num = layout.cur_tx;
490+
priv->tx_obj_num_coalesce_irq = layout.tx_coalesce;
477491
}
478492

479493
if (fd_mode) {

0 commit comments

Comments
 (0)