mac802154: remove mib lock
authorAlexander Aring <alex.aring@gmail.com>
Fri, 22 May 2015 15:43:54 +0000 (17:43 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Sat, 23 May 2015 15:57:08 +0000 (17:57 +0200)
This patch removes the mib lock. The new locking mechanism is to protect
the mib values with the rtnl lock. Note that this isn't always necessary
if we have an interface up the most mib values are readonly (e.g.
address settings). With this behaviour we can remove locking in
hotpath like frame parsing completely. It depends on context if we need
to hold the rtnl lock or not, this makes the callbacks of
ieee802154_mlme_ops unnecessary because these callbacks hols always the
locks.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Reviewed-by: Stefan Schmidt <stefan@osg.samsung.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
include/net/ieee802154_netdev.h
net/ieee802154/6lowpan/core.c
net/ieee802154/6lowpan/tx.c
net/ieee802154/nl-mac.c
net/ieee802154/socket.c
net/mac802154/ieee802154_i.h
net/mac802154/iface.c
net/mac802154/mac_cmd.c
net/mac802154/mib.c
net/mac802154/rx.c

index 144fefb4d619d80b854fae30f5e0c97fd9b12de9..84a72a1382a82601ffbc865b025d9d1ffc9320ff 100644 (file)
@@ -422,15 +422,6 @@ struct ieee802154_mlme_ops {
                               struct ieee802154_mac_params *params);
 
        struct ieee802154_llsec_ops *llsec;
-
-       /* The fields below are required. */
-
-       /*
-        * FIXME: these should become the part of PIB/MIB interface.
-        * However we still don't have IB interface of any kind
-        */
-       __le16 (*get_pan_id)(const struct net_device *dev);
-       __le16 (*get_short_addr)(const struct net_device *dev);
 };
 
 static inline struct ieee802154_mlme_ops *
index 2e77fada7e54fb82dbda7b816fbefa95d6649088..f20a387a1011021347af182060f3b8f4ceda7183 100644 (file)
 LIST_HEAD(lowpan_devices);
 static int lowpan_open_count;
 
-static __le16 lowpan_get_pan_id(const struct net_device *dev)
-{
-       struct net_device *real_dev = lowpan_dev_info(dev)->real_dev;
-
-       return ieee802154_mlme_ops(real_dev)->get_pan_id(real_dev);
-}
-
-static __le16 lowpan_get_short_addr(const struct net_device *dev)
-{
-       struct net_device *real_dev = lowpan_dev_info(dev)->real_dev;
-
-       return ieee802154_mlme_ops(real_dev)->get_short_addr(real_dev);
-}
-
 static struct header_ops lowpan_header_ops = {
        .create = lowpan_header_create,
 };
@@ -96,11 +82,6 @@ static const struct net_device_ops lowpan_netdev_ops = {
        .ndo_start_xmit         = lowpan_xmit,
 };
 
-static struct ieee802154_mlme_ops lowpan_mlme = {
-       .get_pan_id = lowpan_get_pan_id,
-       .get_short_addr = lowpan_get_short_addr,
-};
-
 static void lowpan_setup(struct net_device *dev)
 {
        dev->addr_len           = IEEE802154_ADDR_LEN;
@@ -116,7 +97,6 @@ static void lowpan_setup(struct net_device *dev)
 
        dev->netdev_ops         = &lowpan_netdev_ops;
        dev->header_ops         = &lowpan_header_ops;
-       dev->ml_priv            = &lowpan_mlme;
        dev->destructor         = free_netdev;
        dev->features           |= NETIF_F_NETNS_LOCAL;
 }
index 2349070bd534be9f12a4d8ea342be79fe89a8bcd..98acf7319754970f109a1c6f27d8ff9da161dac2 100644 (file)
@@ -207,7 +207,7 @@ static int lowpan_header(struct sk_buff *skb, struct net_device *dev)
 
        /* prepare wpan address data */
        sa.mode = IEEE802154_ADDR_LONG;
-       sa.pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev);
+       sa.pan_id = lowpan_dev_info(dev)->real_dev->ieee802154_ptr->pan_id;
        sa.extended_addr = ieee802154_devaddr_from_raw(saddr);
 
        /* intra-PAN communications */
index cdc1cc3543f6a2892c54e651f0692b37a779885c..ada58a81b75352f9ce297b26b9b49fb205f6ba81 100644 (file)
@@ -97,8 +97,10 @@ static int ieee802154_nl_fill_iface(struct sk_buff *msg, u32 portid,
        BUG_ON(!phy);
        get_device(&phy->dev);
 
-       short_addr = ops->get_short_addr(dev);
-       pan_id = ops->get_pan_id(dev);
+       rtnl_lock();
+       short_addr = dev->ieee802154_ptr->short_addr;
+       pan_id = dev->ieee802154_ptr->pan_id;
+       rtnl_unlock();
 
        if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
            nla_put_string(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy)) ||
@@ -244,7 +246,9 @@ int ieee802154_associate_resp(struct sk_buff *skb, struct genl_info *info)
        addr.mode = IEEE802154_ADDR_LONG;
        addr.extended_addr = nla_get_hwaddr(
                        info->attrs[IEEE802154_ATTR_DEST_HW_ADDR]);
-       addr.pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev);
+       rtnl_lock();
+       addr.pan_id = dev->ieee802154_ptr->pan_id;
+       rtnl_unlock();
 
        ret = ieee802154_mlme_ops(dev)->assoc_resp(dev, &addr,
                nla_get_shortaddr(info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR]),
@@ -281,7 +285,9 @@ int ieee802154_disassociate_req(struct sk_buff *skb, struct genl_info *info)
                addr.short_addr = nla_get_shortaddr(
                                info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR]);
        }
-       addr.pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev);
+       rtnl_lock();
+       addr.pan_id = dev->ieee802154_ptr->pan_id;
+       rtnl_unlock();
 
        ret = ieee802154_mlme_ops(dev)->disassoc_req(dev, &addr,
                        nla_get_u8(info->attrs[IEEE802154_ATTR_REASON]));
index 7aaaf967df58d2339a03898065094ef1a30c51d2..e5cc2537c2a305b03234fb0cf3931ced92d344ac 100644 (file)
@@ -64,10 +64,8 @@ ieee802154_get_dev(struct net *net, const struct ieee802154_addr *addr)
                        if (tmp->type != ARPHRD_IEEE802154)
                                continue;
 
-                       pan_id = ieee802154_mlme_ops(tmp)->get_pan_id(tmp);
-                       short_addr =
-                               ieee802154_mlme_ops(tmp)->get_short_addr(tmp);
-
+                       pan_id = tmp->ieee802154_ptr->pan_id;
+                       short_addr = tmp->ieee802154_ptr->short_addr;
                        if (pan_id == addr->pan_id &&
                            short_addr == addr->short_addr) {
                                dev = tmp;
@@ -797,9 +795,9 @@ static int ieee802154_dgram_deliver(struct net_device *dev, struct sk_buff *skb)
        /* Data frame processing */
        BUG_ON(dev->type != ARPHRD_IEEE802154);
 
-       pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev);
-       short_addr = ieee802154_mlme_ops(dev)->get_short_addr(dev);
-       hw_addr = ieee802154_devaddr_from_raw(dev->dev_addr);
+       pan_id = dev->ieee802154_ptr->pan_id;
+       short_addr = dev->ieee802154_ptr->short_addr;
+       hw_addr = dev->ieee802154_ptr->extended_addr;
 
        read_lock(&dgram_lock);
        sk_for_each(sk, &dgram_head) {
index 56b3847466e9f9dc1133004c4cd2848d2fdfc670..eec668f3637ff37c9e12c1251cdca4cc59c75d7e 100644 (file)
@@ -86,8 +86,6 @@ struct ieee802154_sub_if_data {
        unsigned long state;
        char name[IFNAMSIZ];
 
-       spinlock_t mib_lock;
-
        /* protects sec from concurrent access by netlink. access by
         * encrypt/decrypt/header_create safe without additional protection.
         */
@@ -136,10 +134,6 @@ ieee802154_subif_start_xmit(struct sk_buff *skb, struct net_device *dev);
 enum hrtimer_restart ieee802154_xmit_ifs_timer(struct hrtimer *timer);
 
 /* MIB callbacks */
-void mac802154_dev_set_short_addr(struct net_device *dev, __le16 val);
-__le16 mac802154_dev_get_short_addr(const struct net_device *dev);
-__le16 mac802154_dev_get_pan_id(const struct net_device *dev);
-void mac802154_dev_set_pan_id(struct net_device *dev, __le16 val);
 void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan);
 
 int mac802154_get_params(struct net_device *dev,
index 0ec7bc402e2917d8b2fd39f7f7892c17b096c898..f30788d2702fa2e77d5f08111af7961dcc155a6e 100644 (file)
@@ -63,7 +63,6 @@ mac802154_wpan_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
        int err = -ENOIOCTLCMD;
 
        rtnl_lock();
-       spin_lock_bh(&sdata->mib_lock);
 
        switch (cmd) {
        case SIOCGIFADDR:
@@ -88,7 +87,6 @@ mac802154_wpan_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
        }
        case SIOCSIFADDR:
                if (netif_running(dev)) {
-                       spin_unlock_bh(&sdata->mib_lock);
                        rtnl_unlock();
                        return -EBUSY;
                }
@@ -111,7 +109,6 @@ mac802154_wpan_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
                break;
        }
 
-       spin_unlock_bh(&sdata->mib_lock);
        rtnl_unlock();
        return err;
 }
@@ -374,8 +371,6 @@ static int mac802154_header_create(struct sk_buff *skb,
                return -EINVAL;
 
        if (!saddr) {
-               spin_lock_bh(&sdata->mib_lock);
-
                if (wpan_dev->short_addr == cpu_to_le16(IEEE802154_ADDR_BROADCAST) ||
                    wpan_dev->short_addr == cpu_to_le16(IEEE802154_ADDR_UNDEF) ||
                    wpan_dev->pan_id == cpu_to_le16(IEEE802154_PANID_BROADCAST)) {
@@ -387,8 +382,6 @@ static int mac802154_header_create(struct sk_buff *skb,
                }
 
                hdr.source.pan_id = wpan_dev->pan_id;
-
-               spin_unlock_bh(&sdata->mib_lock);
        } else {
                hdr.source = *(const struct ieee802154_addr *)saddr;
        }
@@ -500,7 +493,6 @@ ieee802154_setup_sdata(struct ieee802154_sub_if_data *sdata,
                sdata->dev->ml_priv = &mac802154_mlme_wpan;
                wpan_dev->promiscuous_mode = false;
 
-               spin_lock_init(&sdata->mib_lock);
                mutex_init(&sdata->sec_mtx);
 
                mac802154_llsec_init(&sdata->sec);
index 3b347d4d3d4ce076aa079393534502c16d7795e3..5220c2b2735b998f6aaf2df703edb825a849b2b7 100644 (file)
@@ -43,8 +43,8 @@ static int mac802154_mlme_start_req(struct net_device *dev,
 
        BUG_ON(addr->mode != IEEE802154_ADDR_SHORT);
 
-       mac802154_dev_set_pan_id(dev, addr->pan_id);
-       mac802154_dev_set_short_addr(dev, addr->short_addr);
+       dev->ieee802154_ptr->pan_id = addr->pan_id;
+       dev->ieee802154_ptr->short_addr = addr->short_addr;
        mac802154_dev_set_page_channel(dev, page, channel);
 
        if (ops->llsec) {
@@ -151,8 +151,6 @@ static struct ieee802154_llsec_ops mac802154_llsec_ops = {
 
 struct ieee802154_mlme_ops mac802154_mlme_wpan = {
        .start_req = mac802154_mlme_start_req,
-       .get_pan_id = mac802154_dev_get_pan_id,
-       .get_short_addr = mac802154_dev_get_short_addr,
 
        .llsec = &mac802154_llsec_ops,
 
index 00a62de9cc23864fb53cade722617fc9b651b724..73f94fbf87856a5b7d81ba0c27c50a0c6f5c54fb 100644 (file)
 #include "ieee802154_i.h"
 #include "driver-ops.h"
 
-void mac802154_dev_set_short_addr(struct net_device *dev, __le16 val)
-{
-       struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
-
-       BUG_ON(dev->type != ARPHRD_IEEE802154);
-
-       spin_lock_bh(&sdata->mib_lock);
-       sdata->wpan_dev.short_addr = val;
-       spin_unlock_bh(&sdata->mib_lock);
-}
-
-__le16 mac802154_dev_get_short_addr(const struct net_device *dev)
-{
-       struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
-       __le16 ret;
-
-       BUG_ON(dev->type != ARPHRD_IEEE802154);
-
-       spin_lock_bh(&sdata->mib_lock);
-       ret = sdata->wpan_dev.short_addr;
-       spin_unlock_bh(&sdata->mib_lock);
-
-       return ret;
-}
-
-__le16 mac802154_dev_get_pan_id(const struct net_device *dev)
-{
-       struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
-       __le16 ret;
-
-       BUG_ON(dev->type != ARPHRD_IEEE802154);
-
-       spin_lock_bh(&sdata->mib_lock);
-       ret = sdata->wpan_dev.pan_id;
-       spin_unlock_bh(&sdata->mib_lock);
-
-       return ret;
-}
-
-void mac802154_dev_set_pan_id(struct net_device *dev, __le16 val)
-{
-       struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
-
-       BUG_ON(dev->type != ARPHRD_IEEE802154);
-
-       spin_lock_bh(&sdata->mib_lock);
-       sdata->wpan_dev.pan_id = val;
-       spin_unlock_bh(&sdata->mib_lock);
-}
-
 void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan)
 {
        struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
index c0d67b2b4132b033ca28446556c5aefe7e047ee6..e0f10063cac3816fd6830376d65e955429445145 100644 (file)
@@ -47,8 +47,6 @@ ieee802154_subif_frame(struct ieee802154_sub_if_data *sdata,
 
        pr_debug("getting packet via slave interface %s\n", sdata->dev->name);
 
-       spin_lock_bh(&sdata->mib_lock);
-
        span = wpan_dev->pan_id;
        sshort = wpan_dev->short_addr;
 
@@ -83,13 +81,10 @@ ieee802154_subif_frame(struct ieee802154_sub_if_data *sdata,
                        skb->pkt_type = PACKET_OTHERHOST;
                break;
        default:
-               spin_unlock_bh(&sdata->mib_lock);
                pr_debug("invalid dest mode\n");
                goto fail;
        }
 
-       spin_unlock_bh(&sdata->mib_lock);
-
        skb->dev = sdata->dev;
 
        rc = mac802154_llsec_decrypt(&sdata->sec, skb);