Commit bc05a894 authored by Oliver Hartkopp's avatar Oliver Hartkopp Committed by Marc Kleine-Budde

can: allow to change the device mtu for CAN FD capable devices

The configuration for CAN FD depends on CAN_CTRLMODE_FD enabled in the driver
specific ctrlmode_supported capabilities.

The configuration can be done either with the 'fd { on | off }' option in the
'ip' tool from iproute2 or by setting the CAN netdevice MTU to CAN_MTU (16) or
to CANFD_MTU (72).
Signed-off-by: default avatarOliver Hartkopp <socketcan@hartkopp.net>
Acked-by: default avatarStephane Grosjean <s.grosjean@peak-system.com>
Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parent 9859ccd2
...@@ -594,6 +594,39 @@ void free_candev(struct net_device *dev) ...@@ -594,6 +594,39 @@ void free_candev(struct net_device *dev)
} }
EXPORT_SYMBOL_GPL(free_candev); EXPORT_SYMBOL_GPL(free_candev);
/*
* changing MTU and control mode for CAN/CANFD devices
*/
int can_change_mtu(struct net_device *dev, int new_mtu)
{
struct can_priv *priv = netdev_priv(dev);
/* Do not allow changing the MTU while running */
if (dev->flags & IFF_UP)
return -EBUSY;
/* allow change of MTU according to the CANFD ability of the device */
switch (new_mtu) {
case CAN_MTU:
priv->ctrlmode &= ~CAN_CTRLMODE_FD;
break;
case CANFD_MTU:
if (!(priv->ctrlmode_supported & CAN_CTRLMODE_FD))
return -EINVAL;
priv->ctrlmode |= CAN_CTRLMODE_FD;
break;
default:
return -EINVAL;
}
dev->mtu = new_mtu;
return 0;
}
EXPORT_SYMBOL_GPL(can_change_mtu);
/* /*
* Common open function when the device gets opened. * Common open function when the device gets opened.
* *
...@@ -693,6 +726,12 @@ static int can_changelink(struct net_device *dev, ...@@ -693,6 +726,12 @@ static int can_changelink(struct net_device *dev,
return -EOPNOTSUPP; return -EOPNOTSUPP;
priv->ctrlmode &= ~cm->mask; priv->ctrlmode &= ~cm->mask;
priv->ctrlmode |= cm->flags; priv->ctrlmode |= cm->flags;
/* CAN_CTRLMODE_FD can only be set when driver supports FD */
if (priv->ctrlmode & CAN_CTRLMODE_FD)
dev->mtu = CANFD_MTU;
else
dev->mtu = CAN_MTU;
} }
if (data[IFLA_CAN_RESTART_MS]) { if (data[IFLA_CAN_RESTART_MS]) {
......
...@@ -113,6 +113,7 @@ struct can_priv *safe_candev_priv(struct net_device *dev); ...@@ -113,6 +113,7 @@ struct can_priv *safe_candev_priv(struct net_device *dev);
int open_candev(struct net_device *dev); int open_candev(struct net_device *dev);
void close_candev(struct net_device *dev); void close_candev(struct net_device *dev);
int can_change_mtu(struct net_device *dev, int new_mtu);
int register_candev(struct net_device *dev); int register_candev(struct net_device *dev);
void unregister_candev(struct net_device *dev); void unregister_candev(struct net_device *dev);
......
...@@ -96,6 +96,7 @@ struct can_ctrlmode { ...@@ -96,6 +96,7 @@ struct can_ctrlmode {
#define CAN_CTRLMODE_3_SAMPLES 0x04 /* Triple sampling mode */ #define CAN_CTRLMODE_3_SAMPLES 0x04 /* Triple sampling mode */
#define CAN_CTRLMODE_ONE_SHOT 0x08 /* One-Shot mode */ #define CAN_CTRLMODE_ONE_SHOT 0x08 /* One-Shot mode */
#define CAN_CTRLMODE_BERR_REPORTING 0x10 /* Bus-error reporting */ #define CAN_CTRLMODE_BERR_REPORTING 0x10 /* Bus-error reporting */
#define CAN_CTRLMODE_FD 0x20 /* CAN FD mode */
/* /*
* CAN device statistics * CAN device statistics
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment