blob: 387d4cf94853c7bbad1cb7a20d2b316eddd8ae1e [file] [log] [blame]
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +00001/*
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 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2
11 * as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +000017 */
18
19#include <linux/kernel.h>
20#include <linux/module.h>
21#include <linux/netdevice.h>
22
alex.bluesman.smirnov@gmail.com62610ad2012-05-15 20:50:28 +000023#include <net/netlink.h>
24#include <linux/nl802154.h>
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +000025#include <net/mac802154.h>
Phoebe Buckheisterb70ab2e2014-03-14 21:23:59 +010026#include <net/ieee802154_netdev.h>
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +000027#include <net/route.h>
Alexander Aring5ad60d32014-10-25 09:41:02 +020028#include <net/cfg802154.h>
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +000029
Alexander Aring0f1556b2014-10-25 09:41:00 +020030#include "ieee802154_i.h"
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +000031
alex.bluesman.smirnov@gmail.com62610ad2012-05-15 20:50:28 +000032int mac802154_slave_open(struct net_device *dev)
33{
34 struct mac802154_sub_if_data *priv = netdev_priv(dev);
Phoebe Buckheister336908f2014-03-31 21:37:45 +020035 struct mac802154_sub_if_data *subif;
Alexander Aringa5e1ec52014-10-25 17:16:35 +020036 struct ieee802154_local *local = priv->hw;
alex.bluesman.smirnov@gmail.com62610ad2012-05-15 20:50:28 +000037 int res = 0;
38
Phoebe Buckheister336908f2014-03-31 21:37:45 +020039 ASSERT_RTNL();
40
41 if (priv->type == IEEE802154_DEV_WPAN) {
42 mutex_lock(&priv->hw->slaves_mtx);
43 list_for_each_entry(subif, &priv->hw->slaves, list) {
44 if (subif != priv && subif->type == priv->type &&
45 subif->running) {
46 mutex_unlock(&priv->hw->slaves_mtx);
47 return -EBUSY;
48 }
49 }
50 mutex_unlock(&priv->hw->slaves_mtx);
51 }
52
53 mutex_lock(&priv->hw->slaves_mtx);
54 priv->running = true;
55 mutex_unlock(&priv->hw->slaves_mtx);
56
Alexander Aringa5e1ec52014-10-25 17:16:35 +020057 if (local->open_count++ == 0) {
58 res = local->ops->start(&local->hw);
alex.bluesman.smirnov@gmail.com62610ad2012-05-15 20:50:28 +000059 WARN_ON(res);
60 if (res)
61 goto err;
62 }
63
Alexander Aringa5e1ec52014-10-25 17:16:35 +020064 if (local->ops->ieee_addr) {
Phoebe Buckheisterb70ab2e2014-03-14 21:23:59 +010065 __le64 addr = ieee802154_devaddr_from_raw(dev->dev_addr);
66
Alexander Aringa5e1ec52014-10-25 17:16:35 +020067 res = local->ops->ieee_addr(&local->hw, addr);
alex.bluesman.smirnov@gmail.com62610ad2012-05-15 20:50:28 +000068 WARN_ON(res);
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 priv->hw->open_count--;
78
79 return res;
80}
81
82int mac802154_slave_close(struct net_device *dev)
83{
84 struct mac802154_sub_if_data *priv = netdev_priv(dev);
Alexander Aringa5e1ec52014-10-25 17:16:35 +020085 struct ieee802154_local *local = priv->hw;
alex.bluesman.smirnov@gmail.com62610ad2012-05-15 20:50:28 +000086
Phoebe Buckheister336908f2014-03-31 21:37:45 +020087 ASSERT_RTNL();
88
alex.bluesman.smirnov@gmail.com62610ad2012-05-15 20:50:28 +000089 netif_stop_queue(dev);
90
Phoebe Buckheister336908f2014-03-31 21:37:45 +020091 mutex_lock(&priv->hw->slaves_mtx);
92 priv->running = false;
93 mutex_unlock(&priv->hw->slaves_mtx);
94
Alexander Aringa5e1ec52014-10-25 17:16:35 +020095 if (!--local->open_count)
96 local->ops->stop(&local->hw);
alex.bluesman.smirnov@gmail.com62610ad2012-05-15 20:50:28 +000097
98 return 0;
99}
100
101static int
102mac802154_netdev_register(struct wpan_phy *phy, struct net_device *dev)
103{
104 struct mac802154_sub_if_data *priv;
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200105 struct ieee802154_local *local;
alex.bluesman.smirnov@gmail.com62610ad2012-05-15 20:50:28 +0000106 int err;
107
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200108 local = wpan_phy_priv(phy);
alex.bluesman.smirnov@gmail.com62610ad2012-05-15 20:50:28 +0000109
110 priv = netdev_priv(dev);
111 priv->dev = dev;
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200112 priv->hw = local;
alex.bluesman.smirnov@gmail.com62610ad2012-05-15 20:50:28 +0000113
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200114 dev->needed_headroom = local->hw.extra_tx_headroom;
alex.bluesman.smirnov@gmail.com62610ad2012-05-15 20:50:28 +0000115
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200116 SET_NETDEV_DEV(dev, &local->phy->dev);
alex.bluesman.smirnov@gmail.com62610ad2012-05-15 20:50:28 +0000117
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200118 mutex_lock(&local->slaves_mtx);
119 if (!local->running) {
120 mutex_unlock(&local->slaves_mtx);
alex.bluesman.smirnov@gmail.com62610ad2012-05-15 20:50:28 +0000121 return -ENODEV;
122 }
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200123 mutex_unlock(&local->slaves_mtx);
alex.bluesman.smirnov@gmail.com62610ad2012-05-15 20:50:28 +0000124
125 err = register_netdev(dev);
126 if (err < 0)
127 return err;
128
129 rtnl_lock();
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200130 mutex_lock(&local->slaves_mtx);
131 list_add_tail_rcu(&priv->list, &local->slaves);
132 mutex_unlock(&local->slaves_mtx);
alex.bluesman.smirnov@gmail.com62610ad2012-05-15 20:50:28 +0000133 rtnl_unlock();
134
135 return 0;
136}
137
138static void
139mac802154_del_iface(struct wpan_phy *phy, struct net_device *dev)
140{
141 struct mac802154_sub_if_data *sdata;
Varka Bhadram4710d802014-07-02 09:01:09 +0530142
alex.bluesman.smirnov@gmail.com62610ad2012-05-15 20:50:28 +0000143 ASSERT_RTNL();
144
145 sdata = netdev_priv(dev);
146
147 BUG_ON(sdata->hw->phy != phy);
148
149 mutex_lock(&sdata->hw->slaves_mtx);
150 list_del_rcu(&sdata->list);
151 mutex_unlock(&sdata->hw->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{
160 struct net_device *dev;
161 int err = -ENOMEM;
162
alex.bluesman.smirnov@gmail.com62610ad2012-05-15 20:50:28 +0000163 switch (type) {
alex.bluesman.smirnov@gmail.com06060692012-05-15 20:50:29 +0000164 case IEEE802154_DEV_MONITOR:
165 dev = alloc_netdev(sizeof(struct mac802154_sub_if_data),
Tom Gundersenc835a672014-07-14 16:37:24 +0200166 name, NET_NAME_UNKNOWN,
167 mac802154_monitor_setup);
alex.bluesman.smirnov@gmail.com06060692012-05-15 20:50:29 +0000168 break;
alex.bluesman.smirnov@gmail.com32bad7e2012-06-25 23:24:48 +0000169 case IEEE802154_DEV_WPAN:
170 dev = alloc_netdev(sizeof(struct mac802154_sub_if_data),
Tom Gundersenc835a672014-07-14 16:37:24 +0200171 name, NET_NAME_UNKNOWN,
172 mac802154_wpan_setup);
alex.bluesman.smirnov@gmail.com32bad7e2012-06-25 23:24:48 +0000173 break;
alex.bluesman.smirnov@gmail.com62610ad2012-05-15 20:50:28 +0000174 default:
175 dev = NULL;
176 err = -EINVAL;
177 break;
178 }
179 if (!dev)
180 goto err;
181
182 err = mac802154_netdev_register(phy, dev);
183 if (err)
184 goto err_free;
185
186 dev_hold(dev); /* we return an incremented device refcount */
187 return dev;
188
189err_free:
190 free_netdev(dev);
191err:
192 return ERR_PTR(err);
193}
194
Phoebe Buckheister9b2777d2014-02-17 11:34:08 +0100195static int mac802154_set_txpower(struct wpan_phy *phy, int db)
196{
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200197 struct ieee802154_local *local = wpan_phy_priv(phy);
Phoebe Buckheister9b2777d2014-02-17 11:34:08 +0100198
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200199 return local->ops->set_txpower(&local->hw, db);
Phoebe Buckheister9b2777d2014-02-17 11:34:08 +0100200}
201
Phoebe Buckheister84dda3c2014-02-17 11:34:10 +0100202static int mac802154_set_lbt(struct wpan_phy *phy, bool on)
203{
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200204 struct ieee802154_local *local = wpan_phy_priv(phy);
Phoebe Buckheister84dda3c2014-02-17 11:34:10 +0100205
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200206 return local->ops->set_lbt(&local->hw, on);
Phoebe Buckheister84dda3c2014-02-17 11:34:10 +0100207}
208
Phoebe Buckheisterba08fea2014-02-17 11:34:11 +0100209static int mac802154_set_cca_mode(struct wpan_phy *phy, u8 mode)
210{
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200211 struct ieee802154_local *local = wpan_phy_priv(phy);
Phoebe Buckheisterba08fea2014-02-17 11:34:11 +0100212
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200213 return local->ops->set_cca_mode(&local->hw, mode);
Phoebe Buckheisterba08fea2014-02-17 11:34:11 +0100214}
215
Phoebe Buckheister6ca00192014-02-17 11:34:12 +0100216static int mac802154_set_cca_ed_level(struct wpan_phy *phy, s32 level)
217{
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200218 struct ieee802154_local *local = wpan_phy_priv(phy);
Phoebe Buckheister6ca00192014-02-17 11:34:12 +0100219
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200220 return local->ops->set_cca_ed_level(&local->hw, level);
Phoebe Buckheister6ca00192014-02-17 11:34:12 +0100221}
222
Phoebe Buckheister4244db12014-02-17 11:34:14 +0100223static int mac802154_set_csma_params(struct wpan_phy *phy, u8 min_be,
224 u8 max_be, u8 retries)
225{
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200226 struct ieee802154_local *local = wpan_phy_priv(phy);
Phoebe Buckheister4244db12014-02-17 11:34:14 +0100227
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200228 return local->ops->set_csma_params(&local->hw, min_be, max_be, retries);
Phoebe Buckheister4244db12014-02-17 11:34:14 +0100229}
230
231static int mac802154_set_frame_retries(struct wpan_phy *phy, s8 retries)
232{
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200233 struct ieee802154_local *local = wpan_phy_priv(phy);
Phoebe Buckheister4244db12014-02-17 11:34:14 +0100234
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200235 return local->ops->set_frame_retries(&local->hw, retries);
Phoebe Buckheister4244db12014-02-17 11:34:14 +0100236}
237
Alexander Aring5a504392014-10-25 17:16:34 +0200238struct ieee802154_hw *
239ieee802154_alloc_hw(size_t priv_data_len, struct ieee802154_ops *ops)
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +0000240{
241 struct wpan_phy *phy;
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200242 struct ieee802154_local *local;
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +0000243 size_t priv_size;
244
245 if (!ops || !ops->xmit || !ops->ed || !ops->start ||
246 !ops->stop || !ops->set_channel) {
Chen Weilong83a1a7c2013-10-30 15:28:07 +0800247 pr_err("undefined IEEE802.15.4 device operations\n");
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +0000248 return NULL;
249 }
250
251 /* Ensure 32-byte alignment of our private data and hw private data.
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200252 * We use the wpan_phy priv data for both our ieee802154_local and for
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +0000253 * the driver's private data
254 *
255 * in memory it'll be like this:
256 *
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200257 * +-------------------------+
258 * | struct wpan_phy |
259 * +-------------------------+
260 * | struct ieee802154_local |
261 * +-------------------------+
262 * | driver's private data |
263 * +-------------------------+
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +0000264 *
265 * Due to ieee802154 layer isn't aware of driver and MAC structures,
Alexander Aring139f14a2014-10-25 05:25:08 +0200266 * so lets align them here.
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +0000267 */
268
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200269 priv_size = ALIGN(sizeof(*local), NETDEV_ALIGN) + priv_data_len;
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +0000270
271 phy = wpan_phy_alloc(priv_size);
272 if (!phy) {
Chen Weilong83a1a7c2013-10-30 15:28:07 +0800273 pr_err("failure to allocate master IEEE802.15.4 device\n");
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +0000274 return NULL;
275 }
276
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200277 local = wpan_phy_priv(phy);
278 local->phy = phy;
279 local->hw.phy = local->phy;
280 local->hw.priv = (char *)local + ALIGN(sizeof(*local), NETDEV_ALIGN);
281 local->ops = ops;
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +0000282
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200283 INIT_LIST_HEAD(&local->slaves);
284 mutex_init(&local->slaves_mtx);
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +0000285
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200286 return &local->hw;
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +0000287}
Alexander Aring5a504392014-10-25 17:16:34 +0200288EXPORT_SYMBOL(ieee802154_alloc_hw);
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +0000289
Alexander Aring5a504392014-10-25 17:16:34 +0200290void ieee802154_free_hw(struct ieee802154_hw *hw)
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +0000291{
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200292 struct ieee802154_local *local = mac802154_to_priv(hw);
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +0000293
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200294 BUG_ON(!list_empty(&local->slaves));
alex.bluesman.smirnov@gmail.com62610ad2012-05-15 20:50:28 +0000295
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200296 mutex_destroy(&local->slaves_mtx);
Konstantin Khlebnikov1e9f9542012-12-14 01:03:03 +0000297
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200298 wpan_phy_free(local->phy);
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +0000299}
Alexander Aring5a504392014-10-25 17:16:34 +0200300EXPORT_SYMBOL(ieee802154_free_hw);
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +0000301
Alexander Aring5a504392014-10-25 17:16:34 +0200302int ieee802154_register_hw(struct ieee802154_hw *hw)
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +0000303{
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200304 struct ieee802154_local *local = mac802154_to_priv(hw);
Alexander Aring640985e2014-07-03 00:20:43 +0200305 int rc = -ENOSYS;
306
Alexander Aring5a504392014-10-25 17:16:34 +0200307 if (hw->flags & IEEE802154_HW_TXPOWER) {
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200308 if (!local->ops->set_txpower)
Alexander Aring640985e2014-07-03 00:20:43 +0200309 goto out;
310
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200311 local->phy->set_txpower = mac802154_set_txpower;
Alexander Aring640985e2014-07-03 00:20:43 +0200312 }
313
Alexander Aring5a504392014-10-25 17:16:34 +0200314 if (hw->flags & IEEE802154_HW_LBT) {
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200315 if (!local->ops->set_lbt)
Alexander Aring640985e2014-07-03 00:20:43 +0200316 goto out;
317
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200318 local->phy->set_lbt = mac802154_set_lbt;
Alexander Aring640985e2014-07-03 00:20:43 +0200319 }
320
Alexander Aring5a504392014-10-25 17:16:34 +0200321 if (hw->flags & IEEE802154_HW_CCA_MODE) {
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200322 if (!local->ops->set_cca_mode)
Alexander Aring640985e2014-07-03 00:20:43 +0200323 goto out;
324
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200325 local->phy->set_cca_mode = mac802154_set_cca_mode;
Alexander Aring640985e2014-07-03 00:20:43 +0200326 }
327
Alexander Aring5a504392014-10-25 17:16:34 +0200328 if (hw->flags & IEEE802154_HW_CCA_ED_LEVEL) {
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200329 if (!local->ops->set_cca_ed_level)
Alexander Aring640985e2014-07-03 00:20:43 +0200330 goto out;
331
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200332 local->phy->set_cca_ed_level = mac802154_set_cca_ed_level;
Alexander Aring640985e2014-07-03 00:20:43 +0200333 }
334
Alexander Aring5a504392014-10-25 17:16:34 +0200335 if (hw->flags & IEEE802154_HW_CSMA_PARAMS) {
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200336 if (!local->ops->set_csma_params)
Alexander Aring640985e2014-07-03 00:20:43 +0200337 goto out;
338
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200339 local->phy->set_csma_params = mac802154_set_csma_params;
Alexander Aring640985e2014-07-03 00:20:43 +0200340 }
341
Alexander Aring5a504392014-10-25 17:16:34 +0200342 if (hw->flags & IEEE802154_HW_FRAME_RETRIES) {
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200343 if (!local->ops->set_frame_retries)
Alexander Aring640985e2014-07-03 00:20:43 +0200344 goto out;
345
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200346 local->phy->set_frame_retries = mac802154_set_frame_retries;
Alexander Aring640985e2014-07-03 00:20:43 +0200347 }
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +0000348
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200349 local->dev_workqueue =
350 create_singlethread_workqueue(wpan_phy_name(local->phy));
351 if (!local->dev_workqueue) {
Alexander Aring640985e2014-07-03 00:20:43 +0200352 rc = -ENOMEM;
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +0000353 goto out;
Alexander Aring640985e2014-07-03 00:20:43 +0200354 }
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +0000355
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200356 wpan_phy_set_dev(local->phy, local->hw.parent);
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +0000357
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200358 local->phy->add_iface = mac802154_add_iface;
359 local->phy->del_iface = mac802154_del_iface;
alex.bluesman.smirnov@gmail.com62610ad2012-05-15 20:50:28 +0000360
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200361 rc = wpan_phy_register(local->phy);
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +0000362 if (rc < 0)
363 goto out_wq;
364
365 rtnl_lock();
366
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200367 mutex_lock(&local->slaves_mtx);
368 local->running = MAC802154_DEVICE_RUN;
369 mutex_unlock(&local->slaves_mtx);
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +0000370
371 rtnl_unlock();
372
373 return 0;
374
375out_wq:
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200376 destroy_workqueue(local->dev_workqueue);
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +0000377out:
378 return rc;
379}
Alexander Aring5a504392014-10-25 17:16:34 +0200380EXPORT_SYMBOL(ieee802154_register_hw);
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +0000381
Alexander Aring5a504392014-10-25 17:16:34 +0200382void ieee802154_unregister_hw(struct ieee802154_hw *hw)
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +0000383{
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200384 struct ieee802154_local *local = mac802154_to_priv(hw);
alex.bluesman.smirnov@gmail.com62610ad2012-05-15 20:50:28 +0000385 struct mac802154_sub_if_data *sdata, *next;
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +0000386
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200387 flush_workqueue(local->dev_workqueue);
388 destroy_workqueue(local->dev_workqueue);
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +0000389
390 rtnl_lock();
391
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200392 mutex_lock(&local->slaves_mtx);
393 local->running = MAC802154_DEVICE_STOPPED;
394 mutex_unlock(&local->slaves_mtx);
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +0000395
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200396 list_for_each_entry_safe(sdata, next, &local->slaves, list) {
alex.bluesman.smirnov@gmail.com62610ad2012-05-15 20:50:28 +0000397 mutex_lock(&sdata->hw->slaves_mtx);
398 list_del(&sdata->list);
399 mutex_unlock(&sdata->hw->slaves_mtx);
400
401 unregister_netdevice(sdata->dev);
402 }
403
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +0000404 rtnl_unlock();
405
Alexander Aringa5e1ec52014-10-25 17:16:35 +0200406 wpan_phy_unregister(local->phy);
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +0000407}
Alexander Aring5a504392014-10-25 17:16:34 +0200408EXPORT_SYMBOL(ieee802154_unregister_hw);
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +0000409
410MODULE_DESCRIPTION("IEEE 802.15.4 implementation");
411MODULE_LICENSE("GPL v2");