]> rtime.felk.cvut.cz Git - socketcan-devel.git/blobdiff - kernel/2.6/drivers/net/can/dev.c
candev: allow SJW user setting for bittiming calculation
[socketcan-devel.git] / kernel / 2.6 / drivers / net / can / dev.c
index 643693d1310cf10dc7c178454457a5c412eb0545..59e779be38ee0c9c589b920befe67180145231c7 100644 (file)
@@ -160,7 +160,19 @@ static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt)
        bt->prop_seg = tseg1 / 2;
        bt->phase_seg1 = tseg1 - bt->prop_seg;
        bt->phase_seg2 = tseg2;
-       bt->sjw = 1;
+
+       /* check for sjw user settings */
+       if (!bt->sjw || !btc->sjw_max)
+               bt->sjw = 1;
+       else {
+               /* bt->sjw is at least 1 -> sanitize upper bound to sjw_max */
+               if (bt->sjw > btc->sjw_max)
+                       bt->sjw = btc->sjw_max;
+               /* bt->sjw must not be higher than tseg2 */
+               if (tseg2 < bt->sjw)
+                       bt->sjw = tseg2;
+       }
+
        bt->brp = best_brp;
 #ifndef CONFIG_CAN_DEV_SYSFS
        /* real bit-rate */
@@ -649,6 +661,7 @@ static const struct nla_policy can_policy[IFLA_CAN_MAX + 1] = {
        [IFLA_CAN_BITTIMING_CONST]
                                = { .len = sizeof(struct can_bittiming_const) },
        [IFLA_CAN_CLOCK]        = { .len = sizeof(struct can_clock) },
+       [IFLA_CAN_BERR_COUNTER] = { .len = sizeof(struct can_berr_counter) },
 };
 
 static int can_changelink(struct net_device *dev,
@@ -724,6 +737,8 @@ static size_t can_get_size(const struct net_device *dev)
        size += nla_total_size(sizeof(u32));  /* IFLA_CAN_RESTART_MS */
        size += sizeof(struct can_bittiming); /* IFLA_CAN_BITTIMING */
        size += sizeof(struct can_clock);     /* IFLA_CAN_CLOCK */
+       if (priv->do_get_berr_counter)        /* IFLA_CAN_BERR_COUNTER */
+               size += sizeof(struct can_berr_counter);
        if (priv->bittiming_const)            /* IFLA_CAN_BITTIMING_CONST */
                size += sizeof(struct can_bittiming_const);
 
@@ -734,6 +749,7 @@ static int can_fill_info(struct sk_buff *skb, const struct net_device *dev)
 {
        struct can_priv *priv = netdev_priv(dev);
        struct can_ctrlmode cm = {.flags = priv->ctrlmode};
+       struct can_berr_counter bec;
        enum can_state state = priv->state;
 
        if (priv->do_get_state)
@@ -744,6 +760,8 @@ static int can_fill_info(struct sk_buff *skb, const struct net_device *dev)
        NLA_PUT(skb, IFLA_CAN_BITTIMING,
                sizeof(priv->bittiming), &priv->bittiming);
        NLA_PUT(skb, IFLA_CAN_CLOCK, sizeof(cm), &priv->clock);
+       if (priv->do_get_berr_counter && !priv->do_get_berr_counter(dev, &bec))
+               NLA_PUT(skb, IFLA_CAN_BERR_COUNTER, sizeof(bec), &bec);
        if (priv->bittiming_const)
                NLA_PUT(skb, IFLA_CAN_BITTIMING_CONST,
                        sizeof(*priv->bittiming_const), priv->bittiming_const);