History

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).

Oliver Hartkopp committed 12 years ago

Commit bc05a891 parent 9859ccd3 files · +41 −0Browse files

Unified · Split

3 files
  1. drivers/net/can/dev.c +39 −0
  2. include/linux/can/dev.h +1 −0
  3. include/uapi/linux/can/netlink.h +1 −0
drivers/net/can/dev.c+39−0
@@ -594,6 +594,39 @@ void free_candev(struct net_device *dev) · 593 unmodified lines
594594 }
595595 EXPORT_SYMBOL_GPL(free_candev);
596596
597+/*
598+ * changing MTU and control mode for CAN/CANFD devices
599+ */
600+int 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+}
628+EXPORT_SYMBOL_GPL(can_change_mtu);
629+
597630 /*
598631 * Common open function when the device gets opened.
599632 *
@@ -693,6 +726,12 @@ static int can_changelink(struct net_device *dev, · 93 unmodified lines
693726 return -EOPNOTSUPP;
694727 priv->ctrlmode &= ~cm->mask;
695728 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;
696735 }
697736
698737 if (data[IFLA_CAN_RESTART_MS]) {
include/linux/can/dev.h+1−0
@@ -113,6 +113,7 @@ struct can_priv *safe_candev_priv(struct net_device *dev); · 112 unmodified lines
113113
114114 int open_candev(struct net_device *dev);
115115 void close_candev(struct net_device *dev);
116+int can_change_mtu(struct net_device *dev, int new_mtu);
116117
117118 int register_candev(struct net_device *dev);
118119 void unregister_candev(struct net_device *dev);
include/uapi/linux/can/netlink.h+1−0
@@ -96,6 +96,7 @@ struct can_ctrlmode { · 95 unmodified lines
9696 #define CAN_CTRLMODE_3_SAMPLES 0x04 /* Triple sampling mode */
9797 #define CAN_CTRLMODE_ONE_SHOT 0x08 /* One-Shot mode */
9898 #define CAN_CTRLMODE_BERR_REPORTING 0x10 /* Bus-error reporting */
99+#define CAN_CTRLMODE_FD 0x20 /* CAN FD mode */
99100
100101 /*
101102 * CAN device statistics

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t