From: Oliver Hartkopp <socketcan@hartkopp.net>
To: linux-can@vger.kernel.org
Cc: Oliver Hartkopp <socketcan@hartkopp.net>
Subject: [PATCH v5 2/6] can: only send bitrate data via netlink when available
Date: Wed, 26 Feb 2014 23:10:58 +0100 [thread overview]
Message-ID: <1393452662-3154-3-git-send-email-socketcan@hartkopp.net> (raw)
In-Reply-To: <1393452662-3154-1-git-send-email-socketcan@hartkopp.net>
When setting the bitrate both can_calc_bittiming() and can_fixup_bittiming()
lead to the bitrate and the tq variable to be set, when a proper bit timing
is available.
This patch introduces a helper function and only provides the bit timing via
netlink when it's set properly.
This is also a preparation for the CAN FD specific bittiming configurations
which are not existing in non-FD drivers.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
drivers/net/can/dev.c | 24 ++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index e1a3741..e88934c 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -597,6 +597,16 @@ void free_candev(struct net_device *dev)
EXPORT_SYMBOL_GPL(free_candev);
/*
+ * When setting the bitrate both can_calc_bittiming() and can_fixup_bittiming()
+ * lead to the bitrate and the tq variable to be set, when a proper bit timing
+ * is available.
+ */
+static inline int candev_has_bitrate(struct can_bittiming *bt)
+{
+ return (bt->bitrate && bt->tq);
+}
+
+/*
* Common open function when the device gets opened.
*
* This function should be called in the open function of the device
@@ -606,7 +616,7 @@ int open_candev(struct net_device *dev)
{
struct can_priv *priv = netdev_priv(dev);
- if (!priv->bittiming.tq && !priv->bittiming.bitrate) {
+ if (!candev_has_bitrate(&priv->bittiming)) {
netdev_err(dev, "bit-timing not yet defined\n");
return -EINVAL;
}
@@ -719,7 +729,8 @@ static size_t can_get_size(const struct net_device *dev)
struct can_priv *priv = netdev_priv(dev);
size_t size = 0;
- size += nla_total_size(sizeof(struct can_bittiming)); /* IFLA_CAN_BITTIMING */
+ if (candev_has_bitrate(&priv->bittiming)) /* IFLA_CAN_BITTIMING */
+ size += nla_total_size(sizeof(struct can_bittiming));
if (priv->bittiming_const) /* IFLA_CAN_BITTIMING_CONST */
size += nla_total_size(sizeof(struct can_bittiming_const));
size += nla_total_size(sizeof(struct can_clock)); /* IFLA_CAN_CLOCK */
@@ -741,15 +752,20 @@ static int can_fill_info(struct sk_buff *skb, const struct net_device *dev)
if (priv->do_get_state)
priv->do_get_state(dev, &state);
- if (nla_put(skb, IFLA_CAN_BITTIMING,
- sizeof(priv->bittiming), &priv->bittiming) ||
+
+ if ((candev_has_bitrate(&priv->bittiming) &&
+ nla_put(skb, IFLA_CAN_BITTIMING,
+ sizeof(priv->bittiming), &priv->bittiming)) ||
+
(priv->bittiming_const &&
nla_put(skb, IFLA_CAN_BITTIMING_CONST,
sizeof(*priv->bittiming_const), priv->bittiming_const)) ||
+
nla_put(skb, IFLA_CAN_CLOCK, sizeof(cm), &priv->clock) ||
nla_put_u32(skb, IFLA_CAN_STATE, state) ||
nla_put(skb, IFLA_CAN_CTRLMODE, sizeof(cm), &cm) ||
nla_put_u32(skb, IFLA_CAN_RESTART_MS, priv->restart_ms) ||
+
(priv->do_get_berr_counter &&
!priv->do_get_berr_counter(dev, &bec) &&
nla_put(skb, IFLA_CAN_BERR_COUNTER, sizeof(bec), &bec)))
--
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 ` Oliver Hartkopp [this message]
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 ` [PATCH v5 4/6] can: introduce the data bitrate configuration for CAN FD Oliver Hartkopp
2014-02-27 8:43 ` 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-3-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).