Skip to content

Commit 2df6162

Browse files
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: d08e973 ("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>
1 parent 6dfd65a commit 2df6162

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

drivers/net/can/usb/gs_usb.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -772,9 +772,8 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
772772
}
773773
}
774774

775-
static int gs_usb_set_bittiming(struct net_device *netdev)
775+
static int gs_usb_set_bittiming(struct gs_can *dev)
776776
{
777-
struct gs_can *dev = netdev_priv(netdev);
778777
struct can_bittiming *bt = &dev->can.bittiming;
779778
struct gs_device_bittiming dbt = {
780779
.prop_seg = cpu_to_le32(bt->prop_seg),
@@ -791,9 +790,8 @@ static int gs_usb_set_bittiming(struct net_device *netdev)
791790
GFP_KERNEL);
792791
}
793792

794-
static int gs_usb_set_data_bittiming(struct net_device *netdev)
793+
static int gs_usb_set_data_bittiming(struct gs_can *dev)
795794
{
796-
struct gs_can *dev = netdev_priv(netdev);
797795
struct can_bittiming *bt = &dev->can.fd.data_bittiming;
798796
struct gs_device_bittiming dbt = {
799797
.prop_seg = cpu_to_le32(bt->prop_seg),
@@ -1057,6 +1055,20 @@ static int gs_can_open(struct net_device *netdev)
10571055
if (dev->feature & GS_CAN_FEATURE_HW_TIMESTAMP)
10581056
flags |= GS_CAN_MODE_HW_TIMESTAMP;
10591057

1058+
rc = gs_usb_set_bittiming(dev);
1059+
if (rc) {
1060+
netdev_err(netdev, "failed to set bittiming: %pe\n", ERR_PTR(rc));
1061+
goto out_usb_kill_anchored_urbs;
1062+
}
1063+
1064+
if (ctrlmode & CAN_CTRLMODE_FD) {
1065+
rc = gs_usb_set_data_bittiming(dev);
1066+
if (rc) {
1067+
netdev_err(netdev, "failed to set data bittiming: %pe\n", ERR_PTR(rc));
1068+
goto out_usb_kill_anchored_urbs;
1069+
}
1070+
}
1071+
10601072
/* finally start device */
10611073
dev->can.state = CAN_STATE_ERROR_ACTIVE;
10621074
dm.flags = cpu_to_le32(flags);
@@ -1370,7 +1382,6 @@ static struct gs_can *gs_make_candev(unsigned int channel,
13701382
dev->can.state = CAN_STATE_STOPPED;
13711383
dev->can.clock.freq = le32_to_cpu(bt_const.fclk_can);
13721384
dev->can.bittiming_const = &dev->bt_const;
1373-
dev->can.do_set_bittiming = gs_usb_set_bittiming;
13741385

13751386
dev->can.ctrlmode_supported = CAN_CTRLMODE_CC_LEN8_DLC;
13761387

@@ -1394,7 +1405,6 @@ static struct gs_can *gs_make_candev(unsigned int channel,
13941405
* GS_CAN_FEATURE_BT_CONST_EXT is set.
13951406
*/
13961407
dev->can.fd.data_bittiming_const = &dev->bt_const;
1397-
dev->can.fd.do_set_data_bittiming = gs_usb_set_data_bittiming;
13981408
}
13991409

14001410
if (feature & GS_CAN_FEATURE_TERMINATION) {

0 commit comments

Comments
 (0)