diff options
author | alex.bluesman.smirnov@gmail.com <alex.bluesman.smirnov@gmail.com> | 2012-05-15 16:50:20 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2012-05-16 15:16:35 -0400 |
commit | 1010f540181b00c7013eeb04d1bf8aedd5a56835 (patch) | |
tree | d339760efacbff5cec1446e463a0699b5636d30c | |
parent | 0afd7ad9de6b85c0f7ad9edf787de854c8e2fbb5 (diff) |
mac802154: allocation of ieee802154 device
An interface to allocate and register ieee802154 compatible device.
The allocated device has the following representation in memory:
+-----------------------+
| struct wpan_phy |
+-----------------------+
| struct mac802154_priv |
+-----------------------+
| driver's private data |
+-----------------------+
Used by device drivers to register new instance in the stack.
Signed-off-by: Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | include/net/mac802154.h | 7 | ||||
-rw-r--r-- | net/Kconfig | 1 | ||||
-rw-r--r-- | net/Makefile | 1 | ||||
-rw-r--r-- | net/mac802154/Kconfig | 16 | ||||
-rw-r--r-- | net/mac802154/Makefile | 2 | ||||
-rw-r--r-- | net/mac802154/ieee802154_dev.c | 149 | ||||
-rw-r--r-- | net/mac802154/mac802154.h | 63 |
7 files changed, 239 insertions, 0 deletions
diff --git a/include/net/mac802154.h b/include/net/mac802154.h index 941c4e170b0c..397307516ba3 100644 --- a/include/net/mac802154.h +++ b/include/net/mac802154.h | |||
@@ -123,4 +123,11 @@ struct ieee802154_ops { | |||
123 | u8 addr[IEEE802154_ADDR_LEN]); | 123 | u8 addr[IEEE802154_ADDR_LEN]); |
124 | }; | 124 | }; |
125 | 125 | ||
126 | /* Basic interface to register ieee802154 device */ | ||
127 | struct ieee802154_dev * | ||
128 | ieee802154_alloc_device(size_t priv_data_lex, struct ieee802154_ops *ops); | ||
129 | void ieee802154_free_device(struct ieee802154_dev *dev); | ||
130 | int ieee802154_register_device(struct ieee802154_dev *dev); | ||
131 | void ieee802154_unregister_device(struct ieee802154_dev *dev); | ||
132 | |||
126 | #endif /* NET_MAC802154_H */ | 133 | #endif /* NET_MAC802154_H */ |
diff --git a/net/Kconfig b/net/Kconfig index e07272d0bb2d..4c06c7c513a4 100644 --- a/net/Kconfig +++ b/net/Kconfig | |||
@@ -211,6 +211,7 @@ source "net/econet/Kconfig" | |||
211 | source "net/wanrouter/Kconfig" | 211 | source "net/wanrouter/Kconfig" |
212 | source "net/phonet/Kconfig" | 212 | source "net/phonet/Kconfig" |
213 | source "net/ieee802154/Kconfig" | 213 | source "net/ieee802154/Kconfig" |
214 | source "net/mac802154/Kconfig" | ||
214 | source "net/sched/Kconfig" | 215 | source "net/sched/Kconfig" |
215 | source "net/dcb/Kconfig" | 216 | source "net/dcb/Kconfig" |
216 | source "net/dns_resolver/Kconfig" | 217 | source "net/dns_resolver/Kconfig" |
diff --git a/net/Makefile b/net/Makefile index ad432fa4d934..2a97cded8601 100644 --- a/net/Makefile +++ b/net/Makefile | |||
@@ -60,6 +60,7 @@ ifneq ($(CONFIG_DCB),) | |||
60 | obj-y += dcb/ | 60 | obj-y += dcb/ |
61 | endif | 61 | endif |
62 | obj-$(CONFIG_IEEE802154) += ieee802154/ | 62 | obj-$(CONFIG_IEEE802154) += ieee802154/ |
63 | obj-$(CONFIG_MAC802154) += mac802154/ | ||
63 | 64 | ||
64 | ifeq ($(CONFIG_NET),y) | 65 | ifeq ($(CONFIG_NET),y) |
65 | obj-$(CONFIG_SYSCTL) += sysctl_net.o | 66 | obj-$(CONFIG_SYSCTL) += sysctl_net.o |
diff --git a/net/mac802154/Kconfig b/net/mac802154/Kconfig new file mode 100644 index 000000000000..a967ddaa4e2f --- /dev/null +++ b/net/mac802154/Kconfig | |||
@@ -0,0 +1,16 @@ | |||
1 | config MAC802154 | ||
2 | tristate "Generic IEEE 802.15.4 Soft Networking Stack (mac802154)" | ||
3 | depends on IEEE802154 && EXPERIMENTAL | ||
4 | select CRC_CCITT | ||
5 | ---help--- | ||
6 | This option enables the hardware independent IEEE 802.15.4 | ||
7 | networking stack for SoftMAC devices (the ones implementing | ||
8 | only PHY level of IEEE 802.15.4 standard). | ||
9 | |||
10 | Note: this implementation is neither certified, nor feature | ||
11 | complete! Compatibility with other implementations hasn't | ||
12 | been tested yet! | ||
13 | |||
14 | If you plan to use HardMAC IEEE 802.15.4 devices, you can | ||
15 | say N here. Alternatievly you can say M to compile it as | ||
16 | module. | ||
diff --git a/net/mac802154/Makefile b/net/mac802154/Makefile new file mode 100644 index 000000000000..cda9393e1a4f --- /dev/null +++ b/net/mac802154/Makefile | |||
@@ -0,0 +1,2 @@ | |||
1 | obj-$(CONFIG_MAC802154) += mac802154.o | ||
2 | mac802154-objs := ieee802154_dev.o | ||
diff --git a/net/mac802154/ieee802154_dev.c b/net/mac802154/ieee802154_dev.c new file mode 100644 index 000000000000..d130271eb528 --- /dev/null +++ b/net/mac802154/ieee802154_dev.c | |||
@@ -0,0 +1,149 @@ | |||
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 | * | ||
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. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License along | ||
19 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
21 | */ | ||
22 | |||
23 | #include <linux/kernel.h> | ||
24 | #include <linux/module.h> | ||
25 | #include <linux/netdevice.h> | ||
26 | |||
27 | #include <net/mac802154.h> | ||
28 | #include <net/route.h> | ||
29 | #include <net/wpan-phy.h> | ||
30 | |||
31 | #include "mac802154.h" | ||
32 | |||
33 | struct ieee802154_dev * | ||
34 | ieee802154_alloc_device(size_t priv_data_len, struct ieee802154_ops *ops) | ||
35 | { | ||
36 | struct wpan_phy *phy; | ||
37 | struct mac802154_priv *priv; | ||
38 | size_t priv_size; | ||
39 | |||
40 | if (!ops || !ops->xmit || !ops->ed || !ops->start || | ||
41 | !ops->stop || !ops->set_channel) { | ||
42 | printk(KERN_ERR | ||
43 | "undefined IEEE802.15.4 device operations\n"); | ||
44 | return NULL; | ||
45 | } | ||
46 | |||
47 | /* Ensure 32-byte alignment of our private data and hw private data. | ||
48 | * We use the wpan_phy priv data for both our mac802154_priv and for | ||
49 | * the driver's private data | ||
50 | * | ||
51 | * in memory it'll be like this: | ||
52 | * | ||
53 | * +-----------------------+ | ||
54 | * | struct wpan_phy | | ||
55 | * +-----------------------+ | ||
56 | * | struct mac802154_priv | | ||
57 | * +-----------------------+ | ||
58 | * | driver's private data | | ||
59 | * +-----------------------+ | ||
60 | * | ||
61 | * Due to ieee802154 layer isn't aware of driver and MAC structures, | ||
62 | * so lets allign them here. | ||
63 | */ | ||
64 | |||
65 | priv_size = ALIGN(sizeof(*priv), NETDEV_ALIGN) + priv_data_len; | ||
66 | |||
67 | phy = wpan_phy_alloc(priv_size); | ||
68 | if (!phy) { | ||
69 | printk(KERN_ERR | ||
70 | "failure to allocate master IEEE802.15.4 device\n"); | ||
71 | return NULL; | ||
72 | } | ||
73 | |||
74 | priv = wpan_phy_priv(phy); | ||
75 | priv->hw.phy = priv->phy = phy; | ||
76 | priv->hw.priv = (char *)priv + ALIGN(sizeof(*priv), NETDEV_ALIGN); | ||
77 | priv->ops = ops; | ||
78 | |||
79 | INIT_LIST_HEAD(&priv->slaves); | ||
80 | mutex_init(&priv->slaves_mtx); | ||
81 | |||
82 | return &priv->hw; | ||
83 | } | ||
84 | EXPORT_SYMBOL(ieee802154_alloc_device); | ||
85 | |||
86 | void ieee802154_free_device(struct ieee802154_dev *hw) | ||
87 | { | ||
88 | struct mac802154_priv *priv = mac802154_to_priv(hw); | ||
89 | |||
90 | wpan_phy_free(priv->phy); | ||
91 | |||
92 | mutex_destroy(&priv->slaves_mtx); | ||
93 | } | ||
94 | EXPORT_SYMBOL(ieee802154_free_device); | ||
95 | |||
96 | int ieee802154_register_device(struct ieee802154_dev *dev) | ||
97 | { | ||
98 | struct mac802154_priv *priv = mac802154_to_priv(dev); | ||
99 | int rc = -ENOMEM; | ||
100 | |||
101 | priv->dev_workqueue = | ||
102 | create_singlethread_workqueue(wpan_phy_name(priv->phy)); | ||
103 | if (!priv->dev_workqueue) | ||
104 | goto out; | ||
105 | |||
106 | wpan_phy_set_dev(priv->phy, priv->hw.parent); | ||
107 | |||
108 | rc = wpan_phy_register(priv->phy); | ||
109 | if (rc < 0) | ||
110 | goto out_wq; | ||
111 | |||
112 | rtnl_lock(); | ||
113 | |||
114 | mutex_lock(&priv->slaves_mtx); | ||
115 | priv->running = MAC802154_DEVICE_RUN; | ||
116 | mutex_unlock(&priv->slaves_mtx); | ||
117 | |||
118 | rtnl_unlock(); | ||
119 | |||
120 | return 0; | ||
121 | |||
122 | out_wq: | ||
123 | destroy_workqueue(priv->dev_workqueue); | ||
124 | out: | ||
125 | return rc; | ||
126 | } | ||
127 | EXPORT_SYMBOL(ieee802154_register_device); | ||
128 | |||
129 | void ieee802154_unregister_device(struct ieee802154_dev *dev) | ||
130 | { | ||
131 | struct mac802154_priv *priv = mac802154_to_priv(dev); | ||
132 | |||
133 | flush_workqueue(priv->dev_workqueue); | ||
134 | destroy_workqueue(priv->dev_workqueue); | ||
135 | |||
136 | rtnl_lock(); | ||
137 | |||
138 | mutex_lock(&priv->slaves_mtx); | ||
139 | priv->running = MAC802154_DEVICE_STOPPED; | ||
140 | mutex_unlock(&priv->slaves_mtx); | ||
141 | |||
142 | rtnl_unlock(); | ||
143 | |||
144 | wpan_phy_unregister(priv->phy); | ||
145 | } | ||
146 | EXPORT_SYMBOL(ieee802154_unregister_device); | ||
147 | |||
148 | MODULE_DESCRIPTION("IEEE 802.15.4 implementation"); | ||
149 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/net/mac802154/mac802154.h b/net/mac802154/mac802154.h new file mode 100644 index 000000000000..980d0a24040e --- /dev/null +++ b/net/mac802154/mac802154.h | |||
@@ -0,0 +1,63 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2012 Siemens AG | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License version 2 | ||
6 | * as published by the Free Software Foundation. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License along | ||
14 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
16 | * | ||
17 | * Written by: | ||
18 | * Pavel Smolenskiy <pavel.smolenskiy@gmail.com> | ||
19 | * Maxim Gorbachyov <maxim.gorbachev@siemens.com> | ||
20 | * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
21 | * Alexander Smirnov <alex.bluesman.smirnov@gmail.com> | ||
22 | */ | ||
23 | #ifndef MAC802154_H | ||
24 | #define MAC802154_H | ||
25 | |||
26 | /* mac802154 device private data */ | ||
27 | struct mac802154_priv { | ||
28 | struct ieee802154_dev hw; | ||
29 | struct ieee802154_ops *ops; | ||
30 | |||
31 | /* ieee802154 phy */ | ||
32 | struct wpan_phy *phy; | ||
33 | |||
34 | int open_count; | ||
35 | |||
36 | /* As in mac80211 slaves list is modified: | ||
37 | * 1) under the RTNL | ||
38 | * 2) protected by slaves_mtx; | ||
39 | * 3) in an RCU manner | ||
40 | * | ||
41 | * So atomic readers can use any of this protection methods. | ||
42 | */ | ||
43 | struct list_head slaves; | ||
44 | struct mutex slaves_mtx; | ||
45 | |||
46 | /* This one is used for scanning and other jobs not to be interfered | ||
47 | * with serial driver. | ||
48 | */ | ||
49 | struct workqueue_struct *dev_workqueue; | ||
50 | |||
51 | /* SoftMAC device is registered and running. One can add subinterfaces. | ||
52 | * This flag should be modified under slaves_mtx and RTNL, so you can | ||
53 | * read them using any of protection methods. | ||
54 | */ | ||
55 | bool running; | ||
56 | }; | ||
57 | |||
58 | #define MAC802154_DEVICE_STOPPED 0x00 | ||
59 | #define MAC802154_DEVICE_RUN 0x01 | ||
60 | |||
61 | #define mac802154_to_priv(_hw) container_of(_hw, struct mac802154_priv, hw) | ||
62 | |||
63 | #endif /* MAC802154_H */ | ||