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>
This commit is contained in:
Carlos Sanchez 2025-04-14 11:29:10 +02:00 committed by Xiang Xiao
parent 732d811ea9
commit dd53c34722
8 changed files with 19 additions and 25 deletions

View File

@ -1601,15 +1601,13 @@ static int imx9_ioctl(struct net_driver_s *dev, int cmd,
if (ret == OK)
{
/* Reset CAN controller and start with new timings */
/* Apply the new timings (interface is guaranteed to be down) */
priv->arbi_timing = arbi_timing;
if (priv->canfd_capable)
{
priv->data_timing = data_timing;
}
imx9_ifup(dev);
}
}
break;

View File

@ -1569,15 +1569,13 @@ static int imxrt_ioctl(struct net_driver_s *dev, int cmd,
if (ret == OK)
{
/* Reset CAN controller and start with new timings */
/* Apply the new timings (interface is guaranteed to be down) */
priv->arbi_timing = arbi_timing;
if (priv->canfd_capable)
{
priv->data_timing = data_timing;
}
imxrt_ifup(dev);
}
}
break;

View File

@ -1533,13 +1533,12 @@ static int kinetis_ioctl(struct net_driver_s *dev, int cmd,
if (ret == OK)
{
/* Reset CAN controller and start with new timings */
/* Apply the new timings (interface is guaranteed to be down) */
priv->arbi_timing = arbi_timing;
#ifdef CONFIG_NET_CAN_CANFD
priv->data_timing = data_timing;
#endif
kinetis_ifup(dev);
}
}
break;

View File

@ -1516,13 +1516,12 @@ static int s32k1xx_ioctl(struct net_driver_s *dev, int cmd,
if (ret == OK)
{
/* Reset CAN controller and start with new timings */
/* Apply the new timings (interface is guaranteed to be down) */
priv->arbi_timing = arbi_timing;
#ifdef CONFIG_NET_CAN_CANFD
priv->data_timing = data_timing;
#endif
s32k1xx_ifup(dev);
}
}
break;

View File

@ -1707,13 +1707,12 @@ static int s32k3xx_ioctl(struct net_driver_s *dev, int cmd,
if (ret == OK)
{
/* Reset CAN controller and start with new timings */
/* Apply the new timings (interface is guaranteed to be down) */
priv->arbi_timing = arbi_timing;
#ifdef CONFIG_NET_CAN_CANFD
priv->data_timing = data_timing;
#endif
s32k3xx_ifup(dev);
}
}
break;

View File

@ -1966,19 +1966,12 @@ static int fdcan_netdev_ioctl(struct net_driver_s *dev, int cmd,
struct can_ioctl_data_s *req =
(struct can_ioctl_data_s *)((uintptr_t)arg);
/* Apply the new timings (interface is guaranteed to be down) */
priv->arbi_timing.bitrate = req->arbi_bitrate * 1000;
#ifdef CONFIG_NET_CAN_CANFD
priv->data_timing.bitrate = req->data_bitrate * 1000;
#endif
/* Reset CAN controller and start with new timings */
ret = fdcan_initialize(priv);
if (ret == OK)
{
ret = fdcan_ifup(dev);
}
}
break;
#endif /* CONFIG_NETDEV_CAN_BITRATE_IOCTL */

View File

@ -1634,15 +1634,13 @@ static int imx9_ioctl(struct net_driver_s *dev, int cmd,
if (ret == OK)
{
/* Reset CAN controller and start with new timings */
/* Apply the new timings (interface is guaranteed to be down) */
priv->arbi_timing = arbi_timing;
if (priv->canfd_capable)
{
priv->data_timing = data_timing;
}
imx9_ifup(dev);
}
}
break;

View File

@ -1176,8 +1176,18 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd,
#endif
#if defined(CONFIG_NETDEV_IOCTL) && defined(CONFIG_NETDEV_CAN_BITRATE_IOCTL)
case SIOCGCANBITRATE: /* Get bitrate from a CAN controller */
case SIOCSCANBITRATE: /* Set bitrate of a CAN controller */
if (dev->d_flags & IFF_UP)
{
/* Cannot set bitrate if the interface is up. */
ret = -EBUSY;
break;
}
/* If down, fall-through to common code in SIOCGCANBITRATE. */
case SIOCGCANBITRATE: /* Get bitrate from a CAN controller */
if (dev->d_ioctl)
{
FAR struct can_ioctl_data_s *can_bitrate_data =