blob: 4b820cfeb538dac69ec1c3f493163b30578b267b [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
53static inline int drv_set_channel(struct ieee802154_local *local,
54 const u8 page, const u8 channel)
55{
56 might_sleep();
57
58 return local->ops->set_channel(&local->hw, page, channel);
59}
60
61static inline int drv_set_tx_power(struct ieee802154_local *local,
62 const s8 dbm)
63{
64 might_sleep();
65
66 if (!local->ops->set_txpower) {
67 WARN_ON(1);
68 return -EOPNOTSUPP;
69 }
70
71 return local->ops->set_txpower(&local->hw, dbm);
72}
73
74static inline int drv_set_cca_mode(struct ieee802154_local *local,
75 const u8 cca_mode)
76{
77 might_sleep();
78
79 if (!local->ops->set_cca_mode) {
80 WARN_ON(1);
81 return -EOPNOTSUPP;
82 }
83
84 return local->ops->set_cca_mode(&local->hw, cca_mode);
85}
86
87static inline int drv_set_lbt_mode(struct ieee802154_local *local,
88 const bool mode)
89{
90 might_sleep();
91
92 if (!local->ops->set_lbt) {
93 WARN_ON(1);
94 return -EOPNOTSUPP;
95 }
96
97 return local->ops->set_lbt(&local->hw, mode);
98}
99
100static inline int drv_set_cca_ed_level(struct ieee802154_local *local,
101 const s32 ed_level)
102{
103 might_sleep();
104
105 if (!local->ops->set_cca_ed_level) {
106 WARN_ON(1);
107 return -EOPNOTSUPP;
108 }
109
110 return local->ops->set_cca_ed_level(&local->hw, ed_level);
111}
112
113static inline int drv_set_pan_id(struct ieee802154_local *local,
114 const __le16 pan_id)
115{
116 struct ieee802154_hw_addr_filt filt;
117
118 might_sleep();
119
120 if (!local->ops->set_hw_addr_filt) {
121 WARN_ON(1);
122 return -EOPNOTSUPP;
123 }
124
125 filt.pan_id = pan_id;
126
127 return local->ops->set_hw_addr_filt(&local->hw, &filt,
128 IEEE802154_AFILT_PANID_CHANGED);
129}
130
131static inline int drv_set_extended_addr(struct ieee802154_local *local,
132 const __le64 extended_addr)
133{
134 struct ieee802154_hw_addr_filt filt;
135
136 might_sleep();
137
138 if (!local->ops->set_hw_addr_filt) {
139 WARN_ON(1);
140 return -EOPNOTSUPP;
141 }
142
143 filt.ieee_addr = extended_addr;
144
145 return local->ops->set_hw_addr_filt(&local->hw, &filt,
146 IEEE802154_AFILT_IEEEADDR_CHANGED);
147}
148
149static inline int drv_set_short_addr(struct ieee802154_local *local,
150 const __le16 short_addr)
151{
152 struct ieee802154_hw_addr_filt filt;
153
154 might_sleep();
155
156 if (!local->ops->set_hw_addr_filt) {
157 WARN_ON(1);
158 return -EOPNOTSUPP;
159 }
160
161 filt.short_addr = short_addr;
162
163 return local->ops->set_hw_addr_filt(&local->hw, &filt,
164 IEEE802154_AFILT_SADDR_CHANGED);
165}
166
167static inline int drv_set_pan_coord(struct ieee802154_local *local,
168 const bool is_coord)
169{
170 struct ieee802154_hw_addr_filt filt;
171
172 might_sleep();
173
174 if (!local->ops->set_hw_addr_filt) {
175 WARN_ON(1);
176 return -EOPNOTSUPP;
177 }
178
179 filt.pan_coord = is_coord;
180
181 return local->ops->set_hw_addr_filt(&local->hw, &filt,
182 IEEE802154_AFILT_PANC_CHANGED);
183}
184
185static inline int drv_set_csma_params(struct ieee802154_local *local,
186 u8 min_be, u8 max_be,
187 u8 max_csma_backoffs)
188{
189 might_sleep();
190
191 if (!local->ops->set_csma_params) {
192 WARN_ON(1);
193 return -EOPNOTSUPP;
194 }
195
196 return local->ops->set_csma_params(&local->hw, min_be, max_be,
197 max_csma_backoffs);
198}
199
200static inline int drv_set_max_frame_retries(struct ieee802154_local *local,
201 s8 max_frame_retries)
202{
203 might_sleep();
204
205 if (!local->ops->set_frame_retries) {
206 WARN_ON(1);
207 return -EOPNOTSUPP;
208 }
209
210 return local->ops->set_frame_retries(&local->hw, max_frame_retries);
211}
212
213#endif /* __MAC802154_DRVIER_OPS */