• Fedor Ross's avatar
    can: mcp251xfd: __mcp251xfd_chip_set_mode(): increase poll timeout · 9efa1a54
    Fedor Ross authored
    The mcp251xfd controller needs an idle bus to enter 'Normal CAN 2.0
    mode' or . The maximum length of a CAN frame is 736 bits (64 data
    bytes, CAN-FD, EFF mode, worst case bit stuffing and interframe
    spacing). For low bit rates like 10 kbit/s the arbitrarily chosen
    MCP251XFD_POLL_TIMEOUT_US of 1 ms is too small.
    
    Otherwise during polling for the CAN controller to enter 'Normal CAN
    2.0 mode' the timeout limit is exceeded and the configuration fails
    with:
    
    | $ ip link set dev can1 up type can bitrate 10000
    | [  731.911072] mcp251xfd spi2.1 can1: Controller failed to enter mode CAN 2.0 Mode (6) and stays in Configuration Mode (4) (con=0x068b0760, osc=0x00000468).
    | [  731.927192] mcp251xfd spi2.1 can1: CRC read error at address 0x0e0c (length=4, data=00 00 00 00, CRC=0x0000) retrying.
    | [  731.938101] A link change request failed with some changes committed already. Interface can1 may have been left with an inconsistent configuration, please check.
    | RTNETLINK answers: Connection timed out
    
    Make MCP251XFD_POLL_TIMEOUT_US timeout calculation dynamic. Use
    maximum of 1ms and bit time of 1 full 64 data bytes CAN-FD frame in
    EFF mode, worst case bit stuffing and interframe spacing at the
    current bit rate.
    
    For easier backporting define the macro MCP251XFD_FRAME_LEN_MAX_BITS
    that holds the max frame length in bits, which is 736. This can be
    replaced by can_frame_bits(true, true, true, true, CANFD_MAX_DLEN) in
    a cleanup patch later.
    
    Fixes: 55e5b97f ("can: mcp25xxfd: add driver for Microchip MCP25xxFD SPI CAN")
    Signed-off-by: default avatarFedor Ross <fedor.ross@ifm.com>
    Signed-off-by: default avatarMarek Vasut <marex@denx.de>
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/all/20230717-mcp251xfd-fix-increase-poll-timeout-v5-1-06600f34c684@pengutronix.deSigned-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
    9efa1a54
mcp251xfd-core.c 56 KB