Skip to content

Commit dd53c34

Browse files
csanchezdllxiaoxiang781216
authored andcommitted
net/netdev: Change SIOCSCANBITRATE to require interface down.
Previously, SIOCSCANBITRATE brought the iterface up to ensure changes where immediately applied. This was confusing, see https://lists.apache.org/thread/g8d0m6yp7noywhroby5br4hxt3r4og2c Now SIOCSCANBITRATE fails is interface is up. All existing SocketCAN drivers updated. Signed-off-by: Carlos Sanchez <carlossanchez@geotab.com>
1 parent 732d811 commit dd53c34

File tree

8 files changed

+19
-25
lines changed

8 files changed

+19
-25
lines changed

arch/arm/src/imx9/imx9_flexcan.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,15 +1601,13 @@ static int imx9_ioctl(struct net_driver_s *dev, int cmd,
16011601

16021602
if (ret == OK)
16031603
{
1604-
/* Reset CAN controller and start with new timings */
1604+
/* Apply the new timings (interface is guaranteed to be down) */
16051605

16061606
priv->arbi_timing = arbi_timing;
16071607
if (priv->canfd_capable)
16081608
{
16091609
priv->data_timing = data_timing;
16101610
}
1611-
1612-
imx9_ifup(dev);
16131611
}
16141612
}
16151613
break;

arch/arm/src/imxrt/imxrt_flexcan.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,15 +1569,13 @@ static int imxrt_ioctl(struct net_driver_s *dev, int cmd,
15691569

15701570
if (ret == OK)
15711571
{
1572-
/* Reset CAN controller and start with new timings */
1572+
/* Apply the new timings (interface is guaranteed to be down) */
15731573

15741574
priv->arbi_timing = arbi_timing;
15751575
if (priv->canfd_capable)
15761576
{
15771577
priv->data_timing = data_timing;
15781578
}
1579-
1580-
imxrt_ifup(dev);
15811579
}
15821580
}
15831581
break;

arch/arm/src/kinetis/kinetis_flexcan.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,13 +1533,12 @@ static int kinetis_ioctl(struct net_driver_s *dev, int cmd,
15331533

15341534
if (ret == OK)
15351535
{
1536-
/* Reset CAN controller and start with new timings */
1536+
/* Apply the new timings (interface is guaranteed to be down) */
15371537

15381538
priv->arbi_timing = arbi_timing;
15391539
#ifdef CONFIG_NET_CAN_CANFD
15401540
priv->data_timing = data_timing;
15411541
#endif
1542-
kinetis_ifup(dev);
15431542
}
15441543
}
15451544
break;

arch/arm/src/s32k1xx/s32k1xx_flexcan.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,13 +1516,12 @@ static int s32k1xx_ioctl(struct net_driver_s *dev, int cmd,
15161516

15171517
if (ret == OK)
15181518
{
1519-
/* Reset CAN controller and start with new timings */
1519+
/* Apply the new timings (interface is guaranteed to be down) */
15201520

15211521
priv->arbi_timing = arbi_timing;
15221522
#ifdef CONFIG_NET_CAN_CANFD
15231523
priv->data_timing = data_timing;
15241524
#endif
1525-
s32k1xx_ifup(dev);
15261525
}
15271526
}
15281527
break;

arch/arm/src/s32k3xx/s32k3xx_flexcan.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,13 +1707,12 @@ static int s32k3xx_ioctl(struct net_driver_s *dev, int cmd,
17071707

17081708
if (ret == OK)
17091709
{
1710-
/* Reset CAN controller and start with new timings */
1710+
/* Apply the new timings (interface is guaranteed to be down) */
17111711

17121712
priv->arbi_timing = arbi_timing;
17131713
#ifdef CONFIG_NET_CAN_CANFD
17141714
priv->data_timing = data_timing;
17151715
#endif
1716-
s32k3xx_ifup(dev);
17171716
}
17181717
}
17191718
break;

arch/arm/src/stm32h7/stm32_fdcan_sock.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,19 +1966,12 @@ static int fdcan_netdev_ioctl(struct net_driver_s *dev, int cmd,
19661966
struct can_ioctl_data_s *req =
19671967
(struct can_ioctl_data_s *)((uintptr_t)arg);
19681968

1969+
/* Apply the new timings (interface is guaranteed to be down) */
1970+
19691971
priv->arbi_timing.bitrate = req->arbi_bitrate * 1000;
19701972
#ifdef CONFIG_NET_CAN_CANFD
19711973
priv->data_timing.bitrate = req->data_bitrate * 1000;
19721974
#endif
1973-
1974-
/* Reset CAN controller and start with new timings */
1975-
1976-
ret = fdcan_initialize(priv);
1977-
1978-
if (ret == OK)
1979-
{
1980-
ret = fdcan_ifup(dev);
1981-
}
19821975
}
19831976
break;
19841977
#endif /* CONFIG_NETDEV_CAN_BITRATE_IOCTL */

arch/arm64/src/imx9/imx9_flexcan.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,15 +1634,13 @@ static int imx9_ioctl(struct net_driver_s *dev, int cmd,
16341634

16351635
if (ret == OK)
16361636
{
1637-
/* Reset CAN controller and start with new timings */
1637+
/* Apply the new timings (interface is guaranteed to be down) */
16381638

16391639
priv->arbi_timing = arbi_timing;
16401640
if (priv->canfd_capable)
16411641
{
16421642
priv->data_timing = data_timing;
16431643
}
1644-
1645-
imx9_ifup(dev);
16461644
}
16471645
}
16481646
break;

net/netdev/netdev_ioctl.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1176,8 +1176,18 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd,
11761176
#endif
11771177

11781178
#if defined(CONFIG_NETDEV_IOCTL) && defined(CONFIG_NETDEV_CAN_BITRATE_IOCTL)
1179-
case SIOCGCANBITRATE: /* Get bitrate from a CAN controller */
11801179
case SIOCSCANBITRATE: /* Set bitrate of a CAN controller */
1180+
if (dev->d_flags & IFF_UP)
1181+
{
1182+
/* Cannot set bitrate if the interface is up. */
1183+
1184+
ret = -EBUSY;
1185+
break;
1186+
}
1187+
1188+
/* If down, fall-through to common code in SIOCGCANBITRATE. */
1189+
1190+
case SIOCGCANBITRATE: /* Get bitrate from a CAN controller */
11811191
if (dev->d_ioctl)
11821192
{
11831193
FAR struct can_ioctl_data_s *can_bitrate_data =

0 commit comments

Comments
 (0)