main.c (036562f9c4d942f2fbc77ae3215309bde340546f) main.c (04e850fe06312a9f570fcc7dbd0f141c012df404)
1/*
2 * Copyright (C) 2007-2012 Siemens AG
3 *
4 * Written by:
5 * Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
6 *
7 * Based on the code from 'linux-zigbee.sourceforge.net' project.
8 *

--- 19 unchanged lines hidden (view full) ---

28#include <net/cfg802154.h>
29
30#include "ieee802154_i.h"
31
32int mac802154_slave_open(struct net_device *dev)
33{
34 struct ieee802154_sub_if_data *sdata = netdev_priv(dev);
35 struct ieee802154_sub_if_data *subif;
1/*
2 * Copyright (C) 2007-2012 Siemens AG
3 *
4 * Written by:
5 * Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
6 *
7 * Based on the code from 'linux-zigbee.sourceforge.net' project.
8 *

--- 19 unchanged lines hidden (view full) ---

28#include <net/cfg802154.h>
29
30#include "ieee802154_i.h"
31
32int mac802154_slave_open(struct net_device *dev)
33{
34 struct ieee802154_sub_if_data *sdata = netdev_priv(dev);
35 struct ieee802154_sub_if_data *subif;
36 struct ieee802154_local *local = sdata->hw;
36 struct ieee802154_local *local = sdata->local;
37 int res = 0;
38
39 ASSERT_RTNL();
40
41 if (sdata->type == IEEE802154_DEV_WPAN) {
37 int res = 0;
38
39 ASSERT_RTNL();
40
41 if (sdata->type == IEEE802154_DEV_WPAN) {
42 mutex_lock(&sdata->hw->slaves_mtx);
43 list_for_each_entry(subif, &sdata->hw->slaves, list) {
42 mutex_lock(&sdata->local->slaves_mtx);
43 list_for_each_entry(subif, &sdata->local->slaves, list) {
44 if (subif != sdata && subif->type == sdata->type &&
45 subif->running) {
44 if (subif != sdata && subif->type == sdata->type &&
45 subif->running) {
46 mutex_unlock(&sdata->hw->slaves_mtx);
46 mutex_unlock(&sdata->local->slaves_mtx);
47 return -EBUSY;
48 }
49 }
47 return -EBUSY;
48 }
49 }
50 mutex_unlock(&sdata->hw->slaves_mtx);
50 mutex_unlock(&sdata->local->slaves_mtx);
51 }
52
51 }
52
53 mutex_lock(&sdata->hw->slaves_mtx);
53 mutex_lock(&sdata->local->slaves_mtx);
54 sdata->running = true;
54 sdata->running = true;
55 mutex_unlock(&sdata->hw->slaves_mtx);
55 mutex_unlock(&sdata->local->slaves_mtx);
56
57 if (local->open_count++ == 0) {
58 res = local->ops->start(&local->hw);
59 WARN_ON(res);
60 if (res)
61 goto err;
62 }
63

--- 5 unchanged lines hidden (view full) ---

69 if (res)
70 goto err;
71 mac802154_dev_set_ieee_addr(dev);
72 }
73
74 netif_start_queue(dev);
75 return 0;
76err:
56
57 if (local->open_count++ == 0) {
58 res = local->ops->start(&local->hw);
59 WARN_ON(res);
60 if (res)
61 goto err;
62 }
63

--- 5 unchanged lines hidden (view full) ---

69 if (res)
70 goto err;
71 mac802154_dev_set_ieee_addr(dev);
72 }
73
74 netif_start_queue(dev);
75 return 0;
76err:
77 sdata->hw->open_count--;
77 sdata->local->open_count--;
78
79 return res;
80}
81
82int mac802154_slave_close(struct net_device *dev)
83{
84 struct ieee802154_sub_if_data *sdata = netdev_priv(dev);
78
79 return res;
80}
81
82int mac802154_slave_close(struct net_device *dev)
83{
84 struct ieee802154_sub_if_data *sdata = netdev_priv(dev);
85 struct ieee802154_local *local = sdata->hw;
85 struct ieee802154_local *local = sdata->local;
86
87 ASSERT_RTNL();
88
89 netif_stop_queue(dev);
90
86
87 ASSERT_RTNL();
88
89 netif_stop_queue(dev);
90
91 mutex_lock(&sdata->hw->slaves_mtx);
91 mutex_lock(&sdata->local->slaves_mtx);
92 sdata->running = false;
92 sdata->running = false;
93 mutex_unlock(&sdata->hw->slaves_mtx);
93 mutex_unlock(&sdata->local->slaves_mtx);
94
95 if (!--local->open_count)
96 local->ops->stop(&local->hw);
97
98 return 0;
99}
100
101static int
102mac802154_netdev_register(struct wpan_phy *phy, struct net_device *dev)
103{
104 struct ieee802154_sub_if_data *sdata;
105 struct ieee802154_local *local;
106 int err;
107
108 local = wpan_phy_priv(phy);
109
110 sdata = netdev_priv(dev);
111 sdata->dev = dev;
94
95 if (!--local->open_count)
96 local->ops->stop(&local->hw);
97
98 return 0;
99}
100
101static int
102mac802154_netdev_register(struct wpan_phy *phy, struct net_device *dev)
103{
104 struct ieee802154_sub_if_data *sdata;
105 struct ieee802154_local *local;
106 int err;
107
108 local = wpan_phy_priv(phy);
109
110 sdata = netdev_priv(dev);
111 sdata->dev = dev;
112 sdata->hw = local;
112 sdata->local = local;
113
114 dev->needed_headroom = local->hw.extra_tx_headroom;
115
116 SET_NETDEV_DEV(dev, &local->phy->dev);
117
118 mutex_lock(&local->slaves_mtx);
119 if (!local->running) {
120 mutex_unlock(&local->slaves_mtx);

--- 18 unchanged lines hidden (view full) ---

139mac802154_del_iface(struct wpan_phy *phy, struct net_device *dev)
140{
141 struct ieee802154_sub_if_data *sdata;
142
143 ASSERT_RTNL();
144
145 sdata = netdev_priv(dev);
146
113
114 dev->needed_headroom = local->hw.extra_tx_headroom;
115
116 SET_NETDEV_DEV(dev, &local->phy->dev);
117
118 mutex_lock(&local->slaves_mtx);
119 if (!local->running) {
120 mutex_unlock(&local->slaves_mtx);

--- 18 unchanged lines hidden (view full) ---

139mac802154_del_iface(struct wpan_phy *phy, struct net_device *dev)
140{
141 struct ieee802154_sub_if_data *sdata;
142
143 ASSERT_RTNL();
144
145 sdata = netdev_priv(dev);
146
147 BUG_ON(sdata->hw->phy != phy);
147 BUG_ON(sdata->local->phy != phy);
148
148
149 mutex_lock(&sdata->hw->slaves_mtx);
149 mutex_lock(&sdata->local->slaves_mtx);
150 list_del_rcu(&sdata->list);
150 list_del_rcu(&sdata->list);
151 mutex_unlock(&sdata->hw->slaves_mtx);
151 mutex_unlock(&sdata->local->slaves_mtx);
152
153 synchronize_rcu();
154 unregister_netdevice(sdata->dev);
155}
156
157static struct net_device *
158mac802154_add_iface(struct wpan_phy *phy, const char *name, int type)
159{

--- 229 unchanged lines hidden (view full) ---

389
390 rtnl_lock();
391
392 mutex_lock(&local->slaves_mtx);
393 local->running = MAC802154_DEVICE_STOPPED;
394 mutex_unlock(&local->slaves_mtx);
395
396 list_for_each_entry_safe(sdata, next, &local->slaves, list) {
152
153 synchronize_rcu();
154 unregister_netdevice(sdata->dev);
155}
156
157static struct net_device *
158mac802154_add_iface(struct wpan_phy *phy, const char *name, int type)
159{

--- 229 unchanged lines hidden (view full) ---

389
390 rtnl_lock();
391
392 mutex_lock(&local->slaves_mtx);
393 local->running = MAC802154_DEVICE_STOPPED;
394 mutex_unlock(&local->slaves_mtx);
395
396 list_for_each_entry_safe(sdata, next, &local->slaves, list) {
397 mutex_lock(&sdata->hw->slaves_mtx);
397 mutex_lock(&sdata->local->slaves_mtx);
398 list_del(&sdata->list);
398 list_del(&sdata->list);
399 mutex_unlock(&sdata->hw->slaves_mtx);
399 mutex_unlock(&sdata->local->slaves_mtx);
400
401 unregister_netdevice(sdata->dev);
402 }
403
404 rtnl_unlock();
405
406 wpan_phy_unregister(local->phy);
407}
408EXPORT_SYMBOL(ieee802154_unregister_hw);
409
410MODULE_DESCRIPTION("IEEE 802.15.4 implementation");
411MODULE_LICENSE("GPL v2");
400
401 unregister_netdevice(sdata->dev);
402 }
403
404 rtnl_unlock();
405
406 wpan_phy_unregister(local->phy);
407}
408EXPORT_SYMBOL(ieee802154_unregister_hw);
409
410MODULE_DESCRIPTION("IEEE 802.15.4 implementation");
411MODULE_LICENSE("GPL v2");