aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/can
diff options
context:
space:
mode:
authorOliver Hartkopp <socketcan@hartkopp.net>2014-02-28 10:36:23 -0500
committerMarc Kleine-Budde <mkl@pengutronix.de>2014-03-07 03:18:22 -0500
commit9859ccd2c8be63ce939522e63e265f2b0caa1109 (patch)
treeaae08f7351b66eb224ce7b48763569d6189e3c7b /drivers/net/can
parent08da7da41ea490eab08ad9e2674e3b92d6aa2b07 (diff)
can: introduce the data bitrate configuration for CAN FD
As CAN FD offers a second bitrate for the data section of the CAN frame the infrastructure for storing and configuring this second bitrate is introduced. Improved the readability of the if-statement by inserting some newlines. 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')
-rw-r--r--drivers/net/can/dev.c45
1 files changed, 44 insertions, 1 deletions
diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index 8141290e4c18..8ebe112458c4 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -647,6 +647,10 @@ static const struct nla_policy can_policy[IFLA_CAN_MAX + 1] = {
647 = { .len = sizeof(struct can_bittiming_const) }, 647 = { .len = sizeof(struct can_bittiming_const) },
648 [IFLA_CAN_CLOCK] = { .len = sizeof(struct can_clock) }, 648 [IFLA_CAN_CLOCK] = { .len = sizeof(struct can_clock) },
649 [IFLA_CAN_BERR_COUNTER] = { .len = sizeof(struct can_berr_counter) }, 649 [IFLA_CAN_BERR_COUNTER] = { .len = sizeof(struct can_berr_counter) },
650 [IFLA_CAN_DATA_BITTIMING]
651 = { .len = sizeof(struct can_bittiming) },
652 [IFLA_CAN_DATA_BITTIMING_CONST]
653 = { .len = sizeof(struct can_bittiming_const) },
650}; 654};
651 655
652static int can_changelink(struct net_device *dev, 656static int can_changelink(struct net_device *dev,
@@ -707,6 +711,27 @@ static int can_changelink(struct net_device *dev,
707 return err; 711 return err;
708 } 712 }
709 713
714 if (data[IFLA_CAN_DATA_BITTIMING]) {
715 struct can_bittiming dbt;
716
717 /* Do not allow changing bittiming while running */
718 if (dev->flags & IFF_UP)
719 return -EBUSY;
720 memcpy(&dbt, nla_data(data[IFLA_CAN_DATA_BITTIMING]),
721 sizeof(dbt));
722 err = can_get_bittiming(dev, &dbt, priv->data_bittiming_const);
723 if (err)
724 return err;
725 memcpy(&priv->data_bittiming, &dbt, sizeof(dbt));
726
727 if (priv->do_set_data_bittiming) {
728 /* Finally, set the bit-timing registers */
729 err = priv->do_set_data_bittiming(dev);
730 if (err)
731 return err;
732 }
733 }
734
710 return 0; 735 return 0;
711} 736}
712 737
@@ -725,6 +750,10 @@ static size_t can_get_size(const struct net_device *dev)
725 size += nla_total_size(sizeof(u32)); /* IFLA_CAN_RESTART_MS */ 750 size += nla_total_size(sizeof(u32)); /* IFLA_CAN_RESTART_MS */
726 if (priv->do_get_berr_counter) /* IFLA_CAN_BERR_COUNTER */ 751 if (priv->do_get_berr_counter) /* IFLA_CAN_BERR_COUNTER */
727 size += nla_total_size(sizeof(struct can_berr_counter)); 752 size += nla_total_size(sizeof(struct can_berr_counter));
753 if (priv->data_bittiming.bitrate) /* IFLA_CAN_DATA_BITTIMING */
754 size += nla_total_size(sizeof(struct can_bittiming));
755 if (priv->data_bittiming_const) /* IFLA_CAN_DATA_BITTIMING_CONST */
756 size += nla_total_size(sizeof(struct can_bittiming_const));
728 757
729 return size; 758 return size;
730} 759}
@@ -738,20 +767,34 @@ static int can_fill_info(struct sk_buff *skb, const struct net_device *dev)
738 767
739 if (priv->do_get_state) 768 if (priv->do_get_state)
740 priv->do_get_state(dev, &state); 769 priv->do_get_state(dev, &state);
770
741 if ((priv->bittiming.bitrate && 771 if ((priv->bittiming.bitrate &&
742 nla_put(skb, IFLA_CAN_BITTIMING, 772 nla_put(skb, IFLA_CAN_BITTIMING,
743 sizeof(priv->bittiming), &priv->bittiming)) || 773 sizeof(priv->bittiming), &priv->bittiming)) ||
774
744 (priv->bittiming_const && 775 (priv->bittiming_const &&
745 nla_put(skb, IFLA_CAN_BITTIMING_CONST, 776 nla_put(skb, IFLA_CAN_BITTIMING_CONST,
746 sizeof(*priv->bittiming_const), priv->bittiming_const)) || 777 sizeof(*priv->bittiming_const), priv->bittiming_const)) ||
778
747 nla_put(skb, IFLA_CAN_CLOCK, sizeof(cm), &priv->clock) || 779 nla_put(skb, IFLA_CAN_CLOCK, sizeof(cm), &priv->clock) ||
748 nla_put_u32(skb, IFLA_CAN_STATE, state) || 780 nla_put_u32(skb, IFLA_CAN_STATE, state) ||
749 nla_put(skb, IFLA_CAN_CTRLMODE, sizeof(cm), &cm) || 781 nla_put(skb, IFLA_CAN_CTRLMODE, sizeof(cm), &cm) ||
750 nla_put_u32(skb, IFLA_CAN_RESTART_MS, priv->restart_ms) || 782 nla_put_u32(skb, IFLA_CAN_RESTART_MS, priv->restart_ms) ||
783
751 (priv->do_get_berr_counter && 784 (priv->do_get_berr_counter &&
752 !priv->do_get_berr_counter(dev, &bec) && 785 !priv->do_get_berr_counter(dev, &bec) &&
753 nla_put(skb, IFLA_CAN_BERR_COUNTER, sizeof(bec), &bec))) 786 nla_put(skb, IFLA_CAN_BERR_COUNTER, sizeof(bec), &bec)) ||
787
788 (priv->data_bittiming.bitrate &&
789 nla_put(skb, IFLA_CAN_DATA_BITTIMING,
790 sizeof(priv->data_bittiming), &priv->data_bittiming)) ||
791
792 (priv->data_bittiming_const &&
793 nla_put(skb, IFLA_CAN_DATA_BITTIMING_CONST,
794 sizeof(*priv->data_bittiming_const),
795 priv->data_bittiming_const)))
754 return -EMSGSIZE; 796 return -EMSGSIZE;
797
755 return 0; 798 return 0;
756} 799}
757 800