From: Oliver Hartkopp <socketcan@hartkopp.net>
To: linux-can@vger.kernel.org
Cc: Oliver Hartkopp <socketcan@hartkopp.net>
Subject: [PATCH v5 4/6] can: introduce the data bitrate configuration for CAN FD
Date: Wed, 26 Feb 2014 23:11:00 +0100 [thread overview]
Message-ID: <1393452662-3154-5-git-send-email-socketcan@hartkopp.net> (raw)
In-Reply-To: <1393452662-3154-1-git-send-email-socketcan@hartkopp.net>
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.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
drivers/net/can/dev.c | 42 +++++++++++++++++++++++++++++++++++++++-
include/linux/can/dev.h | 6 ++++--
include/uapi/linux/can/netlink.h | 2 ++
3 files changed, 47 insertions(+), 3 deletions(-)
diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index 368d92d..7887691 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -660,6 +660,10 @@ static const struct nla_policy can_policy[IFLA_CAN_MAX + 1] = {
= { .len = sizeof(struct can_bittiming_const) },
[IFLA_CAN_CLOCK] = { .len = sizeof(struct can_clock) },
[IFLA_CAN_BERR_COUNTER] = { .len = sizeof(struct can_berr_counter) },
+ [IFLA_CAN_DATA_BITTIMING]
+ = { .len = sizeof(struct can_bittiming) },
+ [IFLA_CAN_DATA_BITTIMING_CONST]
+ = { .len = sizeof(struct can_bittiming_const) },
};
static int can_changelink(struct net_device *dev,
@@ -693,6 +697,29 @@ static int can_changelink(struct net_device *dev,
}
}
+ if (data[IFLA_CAN_DATA_BITTIMING]) {
+ struct can_bittiming bt;
+
+ /* Do not allow changing bittiming while running */
+ if (dev->flags & IFF_UP)
+ return -EBUSY;
+ memcpy(&bt, nla_data(data[IFLA_CAN_DATA_BITTIMING]),
+ sizeof(bt));
+ if ((!bt.bitrate && !bt.tq) || (bt.bitrate && bt.tq))
+ return -EINVAL;
+ err = can_get_bittiming(dev, &bt, priv->data_bittiming_const);
+ if (err)
+ return err;
+ memcpy(&priv->data_bittiming, &bt, sizeof(bt));
+
+ if (priv->do_set_data_bittiming) {
+ /* Finally, set the bit-timing registers */
+ err = priv->do_set_data_bittiming(dev);
+ if (err)
+ return err;
+ }
+ }
+
if (data[IFLA_CAN_CTRLMODE]) {
struct can_ctrlmode *cm;
@@ -740,6 +767,10 @@ static size_t can_get_size(const struct net_device *dev)
size += nla_total_size(sizeof(u32)); /* IFLA_CAN_RESTART_MS */
if (priv->do_get_berr_counter) /* IFLA_CAN_BERR_COUNTER */
size += nla_total_size(sizeof(struct can_berr_counter));
+ if (candev_has_bitrate(&priv->data_bittiming)) /* IFLA_CAN_DATA_BITTIMING */
+ size += nla_total_size(sizeof(struct can_bittiming));
+ if (priv->data_bittiming_const) /* IFLA_CAN_DATA_BITTIMING_CONST */
+ size += nla_total_size(sizeof(struct can_bittiming_const));
return size;
}
@@ -769,8 +800,17 @@ static int can_fill_info(struct sk_buff *skb, const struct net_device *dev)
(priv->do_get_berr_counter &&
!priv->do_get_berr_counter(dev, &bec) &&
- nla_put(skb, IFLA_CAN_BERR_COUNTER, sizeof(bec), &bec)))
+ nla_put(skb, IFLA_CAN_BERR_COUNTER, sizeof(bec), &bec)) ||
+
+ (candev_has_bitrate(&priv->data_bittiming) &&
+ nla_put(skb, IFLA_CAN_DATA_BITTIMING,
+ sizeof(priv->data_bittiming), &priv->data_bittiming)) ||
+
+ (priv->data_bittiming_const &&
+ nla_put(skb, IFLA_CAN_DATA_BITTIMING_CONST,
+ sizeof(*priv->data_bittiming_const), priv->data_bittiming_const)))
return -EMSGSIZE;
+
return 0;
}
diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h
index dc5f902..8adaee9 100644
--- a/include/linux/can/dev.h
+++ b/include/linux/can/dev.h
@@ -33,8 +33,9 @@ enum can_mode {
struct can_priv {
struct can_device_stats can_stats;
- struct can_bittiming bittiming;
- const struct can_bittiming_const *bittiming_const;
+ struct can_bittiming bittiming, data_bittiming;
+ const struct can_bittiming_const *bittiming_const,
+ *data_bittiming_const;
struct can_clock clock;
enum can_state state;
@@ -45,6 +46,7 @@ struct can_priv {
struct timer_list restart_timer;
int (*do_set_bittiming)(struct net_device *dev);
+ int (*do_set_data_bittiming)(struct net_device *dev);
int (*do_set_mode)(struct net_device *dev, enum can_mode mode);
int (*do_get_state)(const struct net_device *dev,
enum can_state *state);
diff --git a/include/uapi/linux/can/netlink.h b/include/uapi/linux/can/netlink.h
index df944ed..b41933d 100644
--- a/include/uapi/linux/can/netlink.h
+++ b/include/uapi/linux/can/netlink.h
@@ -122,6 +122,8 @@ enum {
IFLA_CAN_RESTART_MS,
IFLA_CAN_RESTART,
IFLA_CAN_BERR_COUNTER,
+ IFLA_CAN_DATA_BITTIMING,
+ IFLA_CAN_DATA_BITTIMING_CONST,
__IFLA_CAN_MAX
};
--
1.9.0
next prev parent reply other threads:[~2014-02-26 22:11 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-26 22:10 [PATCH v5 0/6] Add CAN FD infrastructure for CAN driver Oliver Hartkopp
2014-02-26 22:10 ` [PATCH v5 1/6] can: preserve skbuff protocol in can_put_echo_skb Oliver Hartkopp
2014-02-26 22:10 ` [PATCH v5 2/6] can: only send bitrate data via netlink when available Oliver Hartkopp
2014-02-26 22:10 ` [PATCH v5 3/6] can: provide a separate bittiming_const parameter to bittiming functions Oliver Hartkopp
2014-02-26 22:11 ` Oliver Hartkopp [this message]
2014-02-27 8:43 ` [PATCH v5 4/6] can: introduce the data bitrate configuration for CAN FD Marc Kleine-Budde
2014-02-27 18:05 ` Oliver Hartkopp
2014-02-28 10:56 ` Marc Kleine-Budde
2014-02-28 12:20 ` Oliver Hartkopp
2014-02-28 12:30 ` Marc Kleine-Budde
2014-02-28 12:33 ` Oliver Hartkopp
2014-02-28 12:52 ` Marc Kleine-Budde
2014-02-28 12:58 ` Oliver Hartkopp
2014-02-28 13:05 ` Marc Kleine-Budde
2014-02-28 13:09 ` Oliver Hartkopp
2014-02-28 13:18 ` Marc Kleine-Budde
2014-03-04 20:44 ` Marc Kleine-Budde
2014-02-26 22:11 ` [PATCH v5 5/6] can: allow to change the device mtu for CAN FD capable devices Oliver Hartkopp
2014-02-26 22:11 ` [PATCH v5 6/6] can: add bittiming check at interface open for CAN FD Oliver Hartkopp
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1393452662-3154-5-git-send-email-socketcan@hartkopp.net \
--to=socketcan@hartkopp.net \
--cc=linux-can@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).