Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

can: gs_usb: gs_can_open(): always configure bitrates before starting device

So far the driver populated the struct can_priv::do_set_bittiming() and
struct can_priv::fd::do_set_data_bittiming() callbacks.

Before bringing up the interface, user space has to configure the bitrates.
With these callbacks the configuration is directly forwarded into the CAN
hardware. Then the interface can be brought up.

An ifdown-ifup cycle (without changing the bit rates) doesn't re-configure
the bitrates in the CAN hardware. This leads to a problem with the
CANable-2.5 [1] firmware, which resets the configured bit rates during
ifdown.

To fix the problem remove both bit timing callbacks and always configure
the bitrates in the struct net_device_ops::ndo_open() callback.

[1] https://github.com/Elmue/CANable-2.5-firmware-Slcan-and-Candlelight

Cc: stable@vger.kernel.org
Fixes: d08e973a77d1 ("can: gs_usb: Added support for the GS_USB CAN devices")
Link: https://patch.msgid.link/20260219-gs_usb-always-configure-bitrates-v2-1-671f8ba5b0a5@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

+16 -6
+16 -6
drivers/net/can/usb/gs_usb.c
··· 772 772 } 773 773 } 774 774 775 - static int gs_usb_set_bittiming(struct net_device *netdev) 775 + static int gs_usb_set_bittiming(struct gs_can *dev) 776 776 { 777 - struct gs_can *dev = netdev_priv(netdev); 778 777 struct can_bittiming *bt = &dev->can.bittiming; 779 778 struct gs_device_bittiming dbt = { 780 779 .prop_seg = cpu_to_le32(bt->prop_seg), ··· 790 791 GFP_KERNEL); 791 792 } 792 793 793 - static int gs_usb_set_data_bittiming(struct net_device *netdev) 794 + static int gs_usb_set_data_bittiming(struct gs_can *dev) 794 795 { 795 - struct gs_can *dev = netdev_priv(netdev); 796 796 struct can_bittiming *bt = &dev->can.fd.data_bittiming; 797 797 struct gs_device_bittiming dbt = { 798 798 .prop_seg = cpu_to_le32(bt->prop_seg), ··· 1054 1056 /* if hardware supports timestamps, enable it */ 1055 1057 if (dev->feature & GS_CAN_FEATURE_HW_TIMESTAMP) 1056 1058 flags |= GS_CAN_MODE_HW_TIMESTAMP; 1059 + 1060 + rc = gs_usb_set_bittiming(dev); 1061 + if (rc) { 1062 + netdev_err(netdev, "failed to set bittiming: %pe\n", ERR_PTR(rc)); 1063 + goto out_usb_kill_anchored_urbs; 1064 + } 1065 + 1066 + if (ctrlmode & CAN_CTRLMODE_FD) { 1067 + rc = gs_usb_set_data_bittiming(dev); 1068 + if (rc) { 1069 + netdev_err(netdev, "failed to set data bittiming: %pe\n", ERR_PTR(rc)); 1070 + goto out_usb_kill_anchored_urbs; 1071 + } 1072 + } 1057 1073 1058 1074 /* finally start device */ 1059 1075 dev->can.state = CAN_STATE_ERROR_ACTIVE; ··· 1382 1370 dev->can.state = CAN_STATE_STOPPED; 1383 1371 dev->can.clock.freq = le32_to_cpu(bt_const.fclk_can); 1384 1372 dev->can.bittiming_const = &dev->bt_const; 1385 - dev->can.do_set_bittiming = gs_usb_set_bittiming; 1386 1373 1387 1374 dev->can.ctrlmode_supported = CAN_CTRLMODE_CC_LEN8_DLC; 1388 1375 ··· 1405 1394 * GS_CAN_FEATURE_BT_CONST_EXT is set. 1406 1395 */ 1407 1396 dev->can.fd.data_bittiming_const = &dev->bt_const; 1408 - dev->can.fd.do_set_data_bittiming = gs_usb_set_data_bittiming; 1409 1397 } 1410 1398 1411 1399 if (feature & GS_CAN_FEATURE_TERMINATION) {