aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/can/dev.c
diff options
context:
space:
mode:
authorOliver Hartkopp <socketcan@hartkopp.net>2014-02-28 10:36:24 -0500
committerMarc Kleine-Budde <mkl@pengutronix.de>2014-03-07 03:18:23 -0500
commitbc05a8944a344acdb81a65de055ca6febbf9657c (patch)
treebf3e474f5bac669b5a9d4b3d07aa7119875334fc /drivers/net/can/dev.c
parent9859ccd2c8be63ce939522e63e265f2b0caa1109 (diff)
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: Oliver Hartkopp <socketcan@hartkopp.net> Acked-by: Stephane Grosjean <s.grosjean@peak-system.com> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Diffstat (limited to 'drivers/net/can/dev.c')
-rw-r--r--drivers/net/can/dev.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index 8ebe112458c4..4e20d82b799e 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -595,6 +595,39 @@ void free_candev(struct net_device *dev)
595EXPORT_SYMBOL_GPL(free_candev); 595EXPORT_SYMBOL_GPL(free_candev);
596 596
597/* 597/*
598 * changing MTU and control mode for CAN/CANFD devices
599 */
600int can_change_mtu(struct net_device *dev, int new_mtu)
601{
602 struct can_priv *priv = netdev_priv(dev);
603
604 /* Do not allow changing the MTU while running */
605 if (dev->flags & IFF_UP)
606 return -EBUSY;
607
608 /* allow change of MTU according to the CANFD ability of the device */
609 switch (new_mtu) {
610 case CAN_MTU:
611 priv->ctrlmode &= ~CAN_CTRLMODE_FD;
612 break;
613
614 case CANFD_MTU:
615 if (!(priv->ctrlmode_supported & CAN_CTRLMODE_FD))
616 return -EINVAL;
617
618 priv->ctrlmode |= CAN_CTRLMODE_FD;
619 break;
620
621 default:
622 return -EINVAL;
623 }
624
625 dev->mtu = new_mtu;
626 return 0;
627}
628EXPORT_SYMBOL_GPL(can_change_mtu);
629
630/*
598 * Common open function when the device gets opened. 631 * Common open function when the device gets opened.
599 * 632 *
600 * This function should be called in the open function of the device 633 * This function should be called in the open function of the device
@@ -693,6 +726,12 @@ static int can_changelink(struct net_device *dev,
693 return -EOPNOTSUPP; 726 return -EOPNOTSUPP;
694 priv->ctrlmode &= ~cm->mask; 727 priv->ctrlmode &= ~cm->mask;
695 priv->ctrlmode |= cm->flags; 728 priv->ctrlmode |= cm->flags;
729
730 /* CAN_CTRLMODE_FD can only be set when driver supports FD */
731 if (priv->ctrlmode & CAN_CTRLMODE_FD)
732 dev->mtu = CANFD_MTU;
733 else
734 dev->mtu = CAN_MTU;
696 } 735 }
697 736
698 if (data[IFLA_CAN_RESTART_MS]) { 737 if (data[IFLA_CAN_RESTART_MS]) {