OSDN Git Service

ieee802154: 6lowpan: register packet layer while open
authorAlexander Aring <alex.aring@gmail.com>
Wed, 2 Sep 2015 12:21:17 +0000 (14:21 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Thu, 17 Sep 2015 11:20:02 +0000 (13:20 +0200)
This patch moves the open count handling while doing open of a lowpan
interface. We need the packet handler register at first when one lowpan
interface is up. There exists a small case when all lowpan interfaces
are down and the 802154 packet layer is still registered. To reduce some
overhead we will register the packet layer when the first lowpan
interface comes up and unregister when the last interface will become down.

Reviewed-by: Stefan Schmidt <stefan@osg.samsung.com>
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
net/ieee802154/6lowpan/core.c

index b0f0460..5b418ce 100644 (file)
@@ -76,9 +76,27 @@ static int lowpan_dev_init(struct net_device *ldev)
        return 0;
 }
 
+static int lowpan_open(struct net_device *dev)
+{
+       if (!open_count)
+               lowpan_rx_init();
+       open_count++;
+       return 0;
+}
+
+static int lowpan_stop(struct net_device *dev)
+{
+       open_count--;
+       if (!open_count)
+               lowpan_rx_exit();
+       return 0;
+}
+
 static const struct net_device_ops lowpan_netdev_ops = {
        .ndo_init               = lowpan_dev_init,
        .ndo_start_xmit         = lowpan_xmit,
+       .ndo_open               = lowpan_open,
+       .ndo_stop               = lowpan_stop,
 };
 
 static void lowpan_setup(struct net_device *ldev)
@@ -149,11 +167,6 @@ static int lowpan_newlink(struct net *src_net, struct net_device *ldev,
        }
 
        wdev->ieee802154_ptr->lowpan_dev = ldev;
-       if (!open_count)
-               lowpan_rx_init();
-
-       open_count++;
-
        return 0;
 }
 
@@ -163,11 +176,6 @@ static void lowpan_dellink(struct net_device *ldev, struct list_head *head)
 
        ASSERT_RTNL();
 
-       open_count--;
-
-       if (!open_count)
-               lowpan_rx_exit();
-
        wdev->ieee802154_ptr->lowpan_dev = NULL;
        unregister_netdevice(ldev);
        dev_put(wdev);