blob: f21e864613d09b6d02c4ffe8f2b7e72e78b75e16 [file] [log] [blame]
Alexander Aringb6eea9c2014-10-28 18:21:20 +01001#ifndef __MAC802154_DRVIER_OPS
2#define __MAC802154_DRIVER_OPS
3
4#include <linux/types.h>
5#include <linux/rtnetlink.h>
6
7#include <net/mac802154.h>
8
9#include "ieee802154_i.h"
10
11static inline int
12drv_xmit_async(struct ieee802154_local *local, struct sk_buff *skb)
13{
14 return local->ops->xmit_async(&local->hw, skb);
15}
16
17static inline int
18drv_xmit_sync(struct ieee802154_local *local, struct sk_buff *skb)
19{
20 /* don't allow other operations while sync xmit */
21 ASSERT_RTNL();
22
23 might_sleep();
24
25 return local->ops->xmit_sync(&local->hw, skb);
26}
27
28static inline int drv_start(struct ieee802154_local *local)
29{
30 might_sleep();
31
Alexander Aringe363eca2014-10-28 18:21:26 +010032 local->started = true;
Alexander Aring538181a2014-10-28 18:21:27 +010033 smp_mb();
Alexander Aringe363eca2014-10-28 18:21:26 +010034
Alexander Aringb6eea9c2014-10-28 18:21:20 +010035 return local->ops->start(&local->hw);
36}
37
38static inline void drv_stop(struct ieee802154_local *local)
39{
40 might_sleep();
41
42 local->ops->stop(&local->hw);
Alexander Aringe363eca2014-10-28 18:21:26 +010043
Alexander Aring538181a2014-10-28 18:21:27 +010044 /* sync away all work on the tasklet before clearing started */
45 tasklet_disable(&local->tasklet);
46 tasklet_enable(&local->tasklet);
47
48 barrier();
49
Alexander Aringe363eca2014-10-28 18:21:26 +010050 local->started = false;
Alexander Aringb6eea9c2014-10-28 18:21:20 +010051}
52
Alexander Aring29cd54b2014-11-17 08:20:45 +010053static inline int
54drv_set_channel(struct ieee802154_local *local, u8 page, u8 channel)
Alexander Aringb6eea9c2014-10-28 18:21:20 +010055{
56 might_sleep();
57
58 return local->ops->set_channel(&local->hw, page, channel);
59}
60
Alexander Aring29cd54b2014-11-17 08:20:45 +010061static inline int drv_set_tx_power(struct ieee802154_local *local, s8 dbm)
Alexander Aringb6eea9c2014-10-28 18:21:20 +010062{
63 might_sleep();
64
65 if (!local->ops->set_txpower) {
66 WARN_ON(1);
67 return -EOPNOTSUPP;
68 }
69
70 return local->ops->set_txpower(&local->hw, dbm);
71}
72
Alexander Aring29cd54b2014-11-17 08:20:45 +010073static inline int drv_set_cca_mode(struct ieee802154_local *local, u8 cca_mode)
Alexander Aringb6eea9c2014-10-28 18:21:20 +010074{
75 might_sleep();
76
77 if (!local->ops->set_cca_mode) {
78 WARN_ON(1);
79 return -EOPNOTSUPP;
80 }
81
82 return local->ops->set_cca_mode(&local->hw, cca_mode);
83}
84
Alexander Aring29cd54b2014-11-17 08:20:45 +010085static inline int drv_set_lbt_mode(struct ieee802154_local *local, bool mode)
Alexander Aringb6eea9c2014-10-28 18:21:20 +010086{
87 might_sleep();
88
89 if (!local->ops->set_lbt) {
90 WARN_ON(1);
91 return -EOPNOTSUPP;
92 }
93
94 return local->ops->set_lbt(&local->hw, mode);
95}
96
Alexander Aring29cd54b2014-11-17 08:20:45 +010097static inline int
98drv_set_cca_ed_level(struct ieee802154_local *local, s32 ed_level)
Alexander Aringb6eea9c2014-10-28 18:21:20 +010099{
100 might_sleep();
101
102 if (!local->ops->set_cca_ed_level) {
103 WARN_ON(1);
104 return -EOPNOTSUPP;
105 }
106
107 return local->ops->set_cca_ed_level(&local->hw, ed_level);
108}
109
Alexander Aring29cd54b2014-11-17 08:20:45 +0100110static inline int drv_set_pan_id(struct ieee802154_local *local, __le16 pan_id)
Alexander Aringb6eea9c2014-10-28 18:21:20 +0100111{
112 struct ieee802154_hw_addr_filt filt;
113
114 might_sleep();
115
116 if (!local->ops->set_hw_addr_filt) {
117 WARN_ON(1);
118 return -EOPNOTSUPP;
119 }
120
121 filt.pan_id = pan_id;
122
123 return local->ops->set_hw_addr_filt(&local->hw, &filt,
124 IEEE802154_AFILT_PANID_CHANGED);
125}
126
Alexander Aring29cd54b2014-11-17 08:20:45 +0100127static inline int
128drv_set_extended_addr(struct ieee802154_local *local, __le64 extended_addr)
Alexander Aringb6eea9c2014-10-28 18:21:20 +0100129{
130 struct ieee802154_hw_addr_filt filt;
131
132 might_sleep();
133
134 if (!local->ops->set_hw_addr_filt) {
135 WARN_ON(1);
136 return -EOPNOTSUPP;
137 }
138
139 filt.ieee_addr = extended_addr;
140
141 return local->ops->set_hw_addr_filt(&local->hw, &filt,
142 IEEE802154_AFILT_IEEEADDR_CHANGED);
143}
144
Alexander Aring29cd54b2014-11-17 08:20:45 +0100145static inline int
146drv_set_short_addr(struct ieee802154_local *local, __le16 short_addr)
Alexander Aringb6eea9c2014-10-28 18:21:20 +0100147{
148 struct ieee802154_hw_addr_filt filt;
149
150 might_sleep();
151
152 if (!local->ops->set_hw_addr_filt) {
153 WARN_ON(1);
154 return -EOPNOTSUPP;
155 }
156
157 filt.short_addr = short_addr;
158
159 return local->ops->set_hw_addr_filt(&local->hw, &filt,
160 IEEE802154_AFILT_SADDR_CHANGED);
161}
162
Alexander Aring29cd54b2014-11-17 08:20:45 +0100163static inline int
164drv_set_pan_coord(struct ieee802154_local *local, bool is_coord)
Alexander Aringb6eea9c2014-10-28 18:21:20 +0100165{
166 struct ieee802154_hw_addr_filt filt;
167
168 might_sleep();
169
170 if (!local->ops->set_hw_addr_filt) {
171 WARN_ON(1);
172 return -EOPNOTSUPP;
173 }
174
175 filt.pan_coord = is_coord;
176
177 return local->ops->set_hw_addr_filt(&local->hw, &filt,
178 IEEE802154_AFILT_PANC_CHANGED);
179}
180
Alexander Aring29cd54b2014-11-17 08:20:45 +0100181static inline int
182drv_set_csma_params(struct ieee802154_local *local, u8 min_be, u8 max_be,
183 u8 max_csma_backoffs)
Alexander Aringb6eea9c2014-10-28 18:21:20 +0100184{
185 might_sleep();
186
187 if (!local->ops->set_csma_params) {
188 WARN_ON(1);
189 return -EOPNOTSUPP;
190 }
191
192 return local->ops->set_csma_params(&local->hw, min_be, max_be,
193 max_csma_backoffs);
194}
195
Alexander Aring29cd54b2014-11-17 08:20:45 +0100196static inline int
197drv_set_max_frame_retries(struct ieee802154_local *local, s8 max_frame_retries)
Alexander Aringb6eea9c2014-10-28 18:21:20 +0100198{
199 might_sleep();
200
201 if (!local->ops->set_frame_retries) {
202 WARN_ON(1);
203 return -EOPNOTSUPP;
204 }
205
206 return local->ops->set_frame_retries(&local->hw, max_frame_retries);
207}
208
Alexander Aring29cd54b2014-11-17 08:20:45 +0100209static inline int
210drv_set_promiscuous_mode(struct ieee802154_local *local, bool on)
Alexander Aring94b79222014-10-29 21:34:32 +0100211{
212 might_sleep();
213
214 if (!local->ops->set_promiscuous_mode) {
215 WARN_ON(1);
216 return -EOPNOTSUPP;
217 }
218
219 return local->ops->set_promiscuous_mode(&local->hw, on);
220}
221
Alexander Aringb6eea9c2014-10-28 18:21:20 +0100222#endif /* __MAC802154_DRVIER_OPS */