public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Arvid Brodin <arvid.brodin@alten•se>
To: "David S. Miller" <davem@davemloft•net>
Cc: "netdev@vger•kernel.org" <netdev@vger•kernel.org>
Subject: [PATCH net-next 04/10] net/hsr: Operstate handling cleanup.
Date: Fri, 4 Jul 2014 23:36:40 +0200	[thread overview]
Message-ID: <53B71E68.30809@alten.se> (raw)

Signed-off-by: Arvid Brodin <arvid.brodin@alten•se>
---
 net/hsr/hsr_device.c | 37 ++++++++++++++++++++++++++++---------
 net/hsr/hsr_device.h |  6 +-----
 net/hsr/hsr_main.c   |  9 +--------
 3 files changed, 30 insertions(+), 22 deletions(-)

diff --git a/net/hsr/hsr_device.c b/net/hsr/hsr_device.c
index f224067..8936b3c 100644
--- a/net/hsr/hsr_device.c
+++ b/net/hsr/hsr_device.c
@@ -46,31 +46,36 @@ static void __hsr_set_operstate(struct net_device *dev, int transition)
 	}
 }
 
-void hsr_set_operstate(struct net_device *hsr_dev, struct net_device *slave1,
-		       struct net_device *slave2)
+static void hsr_set_operstate(struct net_device *hsr_dev, bool has_carrier)
 {
 	if (!is_admin_up(hsr_dev)) {
 		__hsr_set_operstate(hsr_dev, IF_OPER_DOWN);
 		return;
 	}
 
-	if (is_slave_up(slave1) || is_slave_up(slave2))
+	if (has_carrier)
 		__hsr_set_operstate(hsr_dev, IF_OPER_UP);
 	else
 		__hsr_set_operstate(hsr_dev, IF_OPER_LOWERLAYERDOWN);
 }
 
-void hsr_set_carrier(struct net_device *hsr_dev, struct net_device *slave1,
-		     struct net_device *slave2)
+static bool hsr_check_carrier(struct hsr_priv *hsr)
 {
-	if (is_slave_up(slave1) || is_slave_up(slave2))
-		netif_carrier_on(hsr_dev);
+	bool has_carrier;
+
+	has_carrier = (is_slave_up(hsr->slave[0]) || is_slave_up(hsr->slave[1]));
+
+	if (has_carrier)
+		netif_carrier_on(hsr->dev);
 	else
-		netif_carrier_off(hsr_dev);
+		netif_carrier_off(hsr->dev);
+
+	return has_carrier;
 }
 
 
-void hsr_check_announce(struct net_device *hsr_dev, int old_operstate)
+static void hsr_check_announce(struct net_device *hsr_dev,
+			       unsigned char old_operstate)
 {
 	struct hsr_priv *hsr;
 
@@ -89,6 +94,20 @@ void hsr_check_announce(struct net_device *hsr_dev, int old_operstate)
 		del_timer(&hsr->announce_timer);
 }
 
+void hsr_check_carrier_and_operstate(struct hsr_priv *hsr)
+{
+	unsigned char old_operstate;
+	bool has_carrier;
+
+	/* netif_stacked_transfer_operstate() cannot be used here since
+	 * it doesn't set IF_OPER_LOWERLAYERDOWN (?)
+	 */
+	old_operstate = hsr->dev->operstate;
+	has_carrier = hsr_check_carrier(hsr);
+	hsr_set_operstate(hsr->dev, has_carrier);
+	hsr_check_announce(hsr->dev, old_operstate);
+}
+
 
 int hsr_get_max_mtu(struct hsr_priv *hsr)
 {
diff --git a/net/hsr/hsr_device.h b/net/hsr/hsr_device.h
index feb744f..108a5d5 100644
--- a/net/hsr/hsr_device.h
+++ b/net/hsr/hsr_device.h
@@ -18,11 +18,7 @@
 void hsr_dev_setup(struct net_device *dev);
 int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2],
 		     unsigned char multicast_spec);
-void hsr_set_operstate(struct net_device *hsr_dev, struct net_device *slave1,
-		       struct net_device *slave2);
-void hsr_set_carrier(struct net_device *hsr_dev, struct net_device *slave1,
-		     struct net_device *slave2);
-void hsr_check_announce(struct net_device *hsr_dev, int old_operstate);
+void hsr_check_carrier_and_operstate(struct hsr_priv *hsr);
 bool is_hsr_master(struct net_device *dev);
 int hsr_get_max_mtu(struct hsr_priv *hsr);
 
diff --git a/net/hsr/hsr_main.c b/net/hsr/hsr_main.c
index 5f9cd7f..431b528 100644
--- a/net/hsr/hsr_main.c
+++ b/net/hsr/hsr_main.c
@@ -91,7 +91,6 @@ static int hsr_netdev_notify(struct notifier_block *nb, unsigned long event,
 {
 	struct net_device *slave, *other_slave;
 	struct hsr_priv *hsr;
-	int old_operstate;
 	int mtu_max;
 	int res;
 	struct net_device *dev;
@@ -115,13 +114,7 @@ static int hsr_netdev_notify(struct notifier_block *nb, unsigned long event,
 	case NETDEV_UP:		/* Administrative state DOWN */
 	case NETDEV_DOWN:	/* Administrative state UP */
 	case NETDEV_CHANGE:	/* Link (carrier) state changes */
-		old_operstate = hsr->dev->operstate;
-		hsr_set_carrier(hsr->dev, slave, other_slave);
-		/* netif_stacked_transfer_operstate() cannot be used here since
-		 * it doesn't set IF_OPER_LOWERLAYERDOWN (?)
-		 */
-		hsr_set_operstate(hsr->dev, slave, other_slave);
-		hsr_check_announce(hsr->dev, old_operstate);
+		hsr_check_carrier_and_operstate(hsr);
 		break;
 	case NETDEV_CHANGEADDR:
 
-- 
1.8.3.2

-- 
Arvid Brodin | Consultant (Linux)
ALTEN | Knarrarnäsgatan 7 | SE-164 40 Kista | Sweden
arvid.brodin@alten•se | www.alten.se/en/

                 reply	other threads:[~2014-07-04 21:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=53B71E68.30809@alten.se \
    --to=arvid.brodin@alten$(echo .)se \
    --cc=davem@davemloft$(echo .)net \
    --cc=netdev@vger$(echo .)kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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