diff options
author | Alexander Aring <alex.aring@gmail.com> | 2014-11-01 23:18:35 -0400 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2014-11-01 23:51:06 -0400 |
commit | a5dd1d72d868ec9c8f44d60ca29900b6a38321b4 (patch) | |
tree | 9710a262a7ac980362ad1459115447b75905a4a6 /net | |
parent | fe58d016e396fc685364b5a1743faf83c1fb8103 (diff) |
cfg802154: introduce cfg802154_registered_device
This patch introduce the cfg802154_registered_device struct. Like
cfg80211_registered_device in wireless this should contain similar
functionality for cfg802154. This patch should not change any behaviour.
We just adds cfg802154_registered_device as container for wpan_phy struct.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net')
-rw-r--r-- | net/ieee802154/core.c | 39 | ||||
-rw-r--r-- | net/ieee802154/core.h | 18 | ||||
-rw-r--r-- | net/ieee802154/sysfs.c | 15 | ||||
-rw-r--r-- | net/mac802154/main.c | 2 |
4 files changed, 57 insertions, 17 deletions
diff --git a/net/ieee802154/core.c b/net/ieee802154/core.c index dc294a415d05..ed5b014dbec7 100644 --- a/net/ieee802154/core.c +++ b/net/ieee802154/core.c | |||
@@ -21,6 +21,7 @@ | |||
21 | 21 | ||
22 | #include "ieee802154.h" | 22 | #include "ieee802154.h" |
23 | #include "sysfs.h" | 23 | #include "sysfs.h" |
24 | #include "core.h" | ||
24 | 25 | ||
25 | static DEFINE_MUTEX(wpan_phy_mutex); | 26 | static DEFINE_MUTEX(wpan_phy_mutex); |
26 | static int wpan_phy_idx; | 27 | static int wpan_phy_idx; |
@@ -76,31 +77,38 @@ static int wpan_phy_idx_valid(int idx) | |||
76 | return idx >= 0; | 77 | return idx >= 0; |
77 | } | 78 | } |
78 | 79 | ||
79 | struct wpan_phy *wpan_phy_alloc(size_t priv_size) | 80 | struct wpan_phy * |
81 | wpan_phy_alloc(const struct cfg802154_ops *ops, size_t priv_size) | ||
80 | { | 82 | { |
81 | struct wpan_phy *phy = kzalloc(sizeof(*phy) + priv_size, | 83 | struct cfg802154_registered_device *rdev; |
82 | GFP_KERNEL); | 84 | size_t alloc_size; |
85 | |||
86 | alloc_size = sizeof(*rdev) + priv_size; | ||
87 | rdev = kzalloc(alloc_size, GFP_KERNEL); | ||
88 | if (!rdev) | ||
89 | return NULL; | ||
90 | |||
91 | rdev->ops = ops; | ||
83 | 92 | ||
84 | if (!phy) | ||
85 | goto out; | ||
86 | mutex_lock(&wpan_phy_mutex); | 93 | mutex_lock(&wpan_phy_mutex); |
87 | phy->idx = wpan_phy_idx++; | 94 | rdev->wpan_phy.idx = wpan_phy_idx++; |
88 | if (unlikely(!wpan_phy_idx_valid(phy->idx))) { | 95 | if (unlikely(!wpan_phy_idx_valid(rdev->wpan_phy.idx))) { |
89 | wpan_phy_idx--; | 96 | wpan_phy_idx--; |
90 | mutex_unlock(&wpan_phy_mutex); | 97 | mutex_unlock(&wpan_phy_mutex); |
91 | kfree(phy); | 98 | kfree(rdev); |
92 | goto out; | 99 | goto out; |
93 | } | 100 | } |
94 | mutex_unlock(&wpan_phy_mutex); | 101 | mutex_unlock(&wpan_phy_mutex); |
95 | 102 | ||
96 | mutex_init(&phy->pib_lock); | 103 | mutex_init(&rdev->wpan_phy.pib_lock); |
97 | 104 | ||
98 | device_initialize(&phy->dev); | 105 | device_initialize(&rdev->wpan_phy.dev); |
99 | dev_set_name(&phy->dev, "wpan-phy%d", phy->idx); | 106 | dev_set_name(&rdev->wpan_phy.dev, "wpan-phy%d", rdev->wpan_phy.idx); |
100 | 107 | ||
101 | phy->dev.class = &wpan_phy_class; | 108 | rdev->wpan_phy.dev.class = &wpan_phy_class; |
109 | rdev->wpan_phy.dev.platform_data = rdev; | ||
102 | 110 | ||
103 | return phy; | 111 | return &rdev->wpan_phy; |
104 | 112 | ||
105 | out: | 113 | out: |
106 | return NULL; | 114 | return NULL; |
@@ -125,6 +133,11 @@ void wpan_phy_free(struct wpan_phy *phy) | |||
125 | } | 133 | } |
126 | EXPORT_SYMBOL(wpan_phy_free); | 134 | EXPORT_SYMBOL(wpan_phy_free); |
127 | 135 | ||
136 | void cfg802154_dev_free(struct cfg802154_registered_device *rdev) | ||
137 | { | ||
138 | kfree(rdev); | ||
139 | } | ||
140 | |||
128 | static int __init wpan_phy_class_init(void) | 141 | static int __init wpan_phy_class_init(void) |
129 | { | 142 | { |
130 | int rc; | 143 | int rc; |
diff --git a/net/ieee802154/core.h b/net/ieee802154/core.h new file mode 100644 index 000000000000..26752ca54b4f --- /dev/null +++ b/net/ieee802154/core.h | |||
@@ -0,0 +1,18 @@ | |||
1 | #ifndef __IEEE802154_CORE_H | ||
2 | #define __IEEE802154_CORE_H | ||
3 | |||
4 | #include <net/cfg802154.h> | ||
5 | |||
6 | struct cfg802154_registered_device { | ||
7 | const struct cfg802154_ops *ops; | ||
8 | |||
9 | /* must be last because of the way we do wpan_phy_priv(), | ||
10 | * and it should at least be aligned to NETDEV_ALIGN | ||
11 | */ | ||
12 | struct wpan_phy wpan_phy __aligned(NETDEV_ALIGN); | ||
13 | }; | ||
14 | |||
15 | /* free object */ | ||
16 | void cfg802154_dev_free(struct cfg802154_registered_device *rdev); | ||
17 | |||
18 | #endif /* __IEEE802154_CORE_H */ | ||
diff --git a/net/ieee802154/sysfs.c b/net/ieee802154/sysfs.c index eb9ca6f99122..c6e038099e07 100644 --- a/net/ieee802154/sysfs.c +++ b/net/ieee802154/sysfs.c | |||
@@ -17,6 +17,15 @@ | |||
17 | 17 | ||
18 | #include <net/cfg802154.h> | 18 | #include <net/cfg802154.h> |
19 | 19 | ||
20 | #include "core.h" | ||
21 | |||
22 | static inline struct cfg802154_registered_device * | ||
23 | dev_to_rdev(struct device *dev) | ||
24 | { | ||
25 | return container_of(dev, struct cfg802154_registered_device, | ||
26 | wpan_phy.dev); | ||
27 | } | ||
28 | |||
20 | #define MASTER_SHOW_COMPLEX(name, format_string, args...) \ | 29 | #define MASTER_SHOW_COMPLEX(name, format_string, args...) \ |
21 | static ssize_t name ## _show(struct device *dev, \ | 30 | static ssize_t name ## _show(struct device *dev, \ |
22 | struct device_attribute *attr, char *buf) \ | 31 | struct device_attribute *attr, char *buf) \ |
@@ -60,11 +69,11 @@ static ssize_t channels_supported_show(struct device *dev, | |||
60 | } | 69 | } |
61 | static DEVICE_ATTR_RO(channels_supported); | 70 | static DEVICE_ATTR_RO(channels_supported); |
62 | 71 | ||
63 | static void wpan_phy_release(struct device *d) | 72 | static void wpan_phy_release(struct device *dev) |
64 | { | 73 | { |
65 | struct wpan_phy *phy = container_of(d, struct wpan_phy, dev); | 74 | struct cfg802154_registered_device *rdev = dev_to_rdev(dev); |
66 | 75 | ||
67 | kfree(phy); | 76 | cfg802154_dev_free(rdev); |
68 | } | 77 | } |
69 | 78 | ||
70 | static struct attribute *pmib_attrs[] = { | 79 | static struct attribute *pmib_attrs[] = { |
diff --git a/net/mac802154/main.c b/net/mac802154/main.c index 86e533ed3775..ebc2bb123cfe 100644 --- a/net/mac802154/main.c +++ b/net/mac802154/main.c | |||
@@ -169,7 +169,7 @@ ieee802154_alloc_hw(size_t priv_data_len, const struct ieee802154_ops *ops) | |||
169 | 169 | ||
170 | priv_size = ALIGN(sizeof(*local), NETDEV_ALIGN) + priv_data_len; | 170 | priv_size = ALIGN(sizeof(*local), NETDEV_ALIGN) + priv_data_len; |
171 | 171 | ||
172 | phy = wpan_phy_alloc(priv_size); | 172 | phy = wpan_phy_alloc(NULL, priv_size); |
173 | if (!phy) { | 173 | if (!phy) { |
174 | pr_err("failure to allocate master IEEE802.15.4 device\n"); | 174 | pr_err("failure to allocate master IEEE802.15.4 device\n"); |
175 | return NULL; | 175 | return NULL; |