linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: linux-can@vger.kernel.org
Cc: kernel@pengutronix.de, Marc Kleine-Budde <mkl@pengutronix.de>
Subject: [PATCH 6/7] can: dev: berr_limit netlink support for configuration
Date: Mon,  7 Oct 2013 16:40:39 +0200	[thread overview]
Message-ID: <1381156840-24071-7-git-send-email-mkl@pengutronix.de> (raw)
In-Reply-To: <1381156840-24071-1-git-send-email-mkl@pengutronix.de>

This patch adds add netlink support to configure the berr_limit delay via
netlink.

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/dev.c            | 19 ++++++++++++++++++-
 include/uapi/linux/can/netlink.h |  1 +
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index 969d3cd..3119052 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -660,6 +660,7 @@ 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_BERR_LIMIT_MS]= { .type = NLA_MSECS },
 };
 
 static int can_changelink(struct net_device *dev,
@@ -722,6 +723,17 @@ static int can_changelink(struct net_device *dev,
 			return err;
 	}
 
+	if (data[IFLA_CAN_BERR_LIMIT_MS]) {
+		/* Do not allow changing berr limit delay while running */
+		if (!priv->do_berr_restart)
+			return -EOPNOTSUPP;
+		if (dev->flags & IFF_UP)
+			return -EBUSY;
+
+		priv->berr_limit_delay =
+			nla_get_msecs(data[IFLA_CAN_BERR_LIMIT_MS]);
+	}
+
 	return 0;
 }
 
@@ -739,6 +751,8 @@ 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 (priv->do_berr_restart)				/* IFLA_CAN_BERR_LIMIT_MS */
+		size += nla_total_size(sizeof(u64));
 
 	return size;
 }
@@ -763,7 +777,10 @@ static int can_fill_info(struct sk_buff *skb, const struct net_device *dev)
 	    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)))
+	     nla_put(skb, IFLA_CAN_BERR_COUNTER, sizeof(bec), &bec)) ||
+	    (priv->do_berr_restart &&
+	     nla_put_msecs(skb, IFLA_CAN_BERR_LIMIT_MS,
+			   priv->berr_limit_delay)))
 		return -EMSGSIZE;
 	return 0;
 }
diff --git a/include/uapi/linux/can/netlink.h b/include/uapi/linux/can/netlink.h
index df944ed..71f750e 100644
--- a/include/uapi/linux/can/netlink.h
+++ b/include/uapi/linux/can/netlink.h
@@ -122,6 +122,7 @@ enum {
 	IFLA_CAN_RESTART_MS,
 	IFLA_CAN_RESTART,
 	IFLA_CAN_BERR_COUNTER,
+	IFLA_CAN_BERR_LIMIT_MS,
 	__IFLA_CAN_MAX
 };
 
-- 
1.8.4.rc3


  parent reply	other threads:[~2013-10-07 14:40 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-07 14:40 [PATCH 1/7] can: berr_limit support Marc Kleine-Budde
2013-10-07 14:40 ` [PATCH 1/7] can: dev: fix nlmsg size calculation in can_get_size() Marc Kleine-Budde
2013-10-07 14:40 ` [PATCH 2/7] can: dev: sort can_get_size() by IFLA_CAN_* Marc Kleine-Budde
2013-10-07 14:40 ` [PATCH 3/7] can: dev: sort can_fill_info() " Marc Kleine-Budde
2013-10-07 14:40 ` [PATCH 4/7] can: dev: sort can_changelink() " Marc Kleine-Budde
2013-10-07 14:40 ` [PATCH 5/7] can: dev: add berr_limit infrastrucutre Marc Kleine-Budde
2013-10-07 15:39   ` Alexander Stein
2013-10-07 15:56     ` Marc Kleine-Budde
2013-10-07 16:00       ` Marc Kleine-Budde
2013-10-08  6:03         ` Alexander Stein
2013-10-08  7:05           ` Marc Kleine-Budde
2013-10-07 14:40 ` Marc Kleine-Budde [this message]
2013-10-07 14:40 ` [PATCH 7/7] can: flexcan: add berr_limit support Marc Kleine-Budde
2013-10-07 19:38 ` [PATCH 1/7] can: " Wolfgang Grandegger
2013-10-07 19:42   ` Marc Kleine-Budde

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=1381156840-24071-7-git-send-email-mkl@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=kernel@pengutronix.de \
    --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).