License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[linux-block.git] / net / mac802154 / driver-ops.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
ea6edfbc 2#ifndef __MAC802154_DRIVER_OPS
b6eea9ca
AA
3#define __MAC802154_DRIVER_OPS
4
5#include <linux/types.h>
6#include <linux/rtnetlink.h>
7
8#include <net/mac802154.h>
9
10#include "ieee802154_i.h"
0ecc4e68 11#include "trace.h"
b6eea9ca
AA
12
13static inline int
14drv_xmit_async(struct ieee802154_local *local, struct sk_buff *skb)
15{
16 return local->ops->xmit_async(&local->hw, skb);
17}
18
19static inline int
20drv_xmit_sync(struct ieee802154_local *local, struct sk_buff *skb)
21{
b6eea9ca
AA
22 might_sleep();
23
24 return local->ops->xmit_sync(&local->hw, skb);
25}
26
27static inline int drv_start(struct ieee802154_local *local)
28{
0ecc4e68
VB
29 int ret;
30
b6eea9ca
AA
31 might_sleep();
32
0ecc4e68 33 trace_802154_drv_start(local);
e363eca3 34 local->started = true;
538181a8 35 smp_mb();
0ecc4e68
VB
36 ret = local->ops->start(&local->hw);
37 trace_802154_drv_return_int(local, ret);
38 return ret;
b6eea9ca
AA
39}
40
41static inline void drv_stop(struct ieee802154_local *local)
42{
43 might_sleep();
44
0ecc4e68 45 trace_802154_drv_stop(local);
b6eea9ca 46 local->ops->stop(&local->hw);
0ecc4e68 47 trace_802154_drv_return_void(local);
e363eca3 48
538181a8
AA
49 /* sync away all work on the tasklet before clearing started */
50 tasklet_disable(&local->tasklet);
51 tasklet_enable(&local->tasklet);
52
53 barrier();
54
e363eca3 55 local->started = false;
b6eea9ca
AA
56}
57
29cd54b9
AA
58static inline int
59drv_set_channel(struct ieee802154_local *local, u8 page, u8 channel)
b6eea9ca 60{
0ecc4e68
VB
61 int ret;
62
b6eea9ca
AA
63 might_sleep();
64
0ecc4e68
VB
65 trace_802154_drv_set_channel(local, page, channel);
66 ret = local->ops->set_channel(&local->hw, page, channel);
67 trace_802154_drv_return_int(local, ret);
68 return ret;
b6eea9ca
AA
69}
70
e2eb173a 71static inline int drv_set_tx_power(struct ieee802154_local *local, s32 mbm)
b6eea9ca 72{
0ecc4e68
VB
73 int ret;
74
b6eea9ca
AA
75 might_sleep();
76
77 if (!local->ops->set_txpower) {
78 WARN_ON(1);
79 return -EOPNOTSUPP;
80 }
81
0ecc4e68
VB
82 trace_802154_drv_set_tx_power(local, mbm);
83 ret = local->ops->set_txpower(&local->hw, mbm);
84 trace_802154_drv_return_int(local, ret);
85 return ret;
b6eea9ca
AA
86}
87
7fe9a388
AA
88static inline int drv_set_cca_mode(struct ieee802154_local *local,
89 const struct wpan_phy_cca *cca)
b6eea9ca 90{
0ecc4e68
VB
91 int ret;
92
b6eea9ca
AA
93 might_sleep();
94
95 if (!local->ops->set_cca_mode) {
96 WARN_ON(1);
97 return -EOPNOTSUPP;
98 }
99
0ecc4e68
VB
100 trace_802154_drv_set_cca_mode(local, cca);
101 ret = local->ops->set_cca_mode(&local->hw, cca);
102 trace_802154_drv_return_int(local, ret);
103 return ret;
b6eea9ca
AA
104}
105
29cd54b9 106static inline int drv_set_lbt_mode(struct ieee802154_local *local, bool mode)
b6eea9ca 107{
0ecc4e68
VB
108 int ret;
109
b6eea9ca
AA
110 might_sleep();
111
112 if (!local->ops->set_lbt) {
113 WARN_ON(1);
114 return -EOPNOTSUPP;
115 }
116
0ecc4e68
VB
117 trace_802154_drv_set_lbt_mode(local, mode);
118 ret = local->ops->set_lbt(&local->hw, mode);
119 trace_802154_drv_return_int(local, ret);
120 return ret;
b6eea9ca
AA
121}
122
29cd54b9 123static inline int
32b23550 124drv_set_cca_ed_level(struct ieee802154_local *local, s32 mbm)
b6eea9ca 125{
0ecc4e68
VB
126 int ret;
127
b6eea9ca
AA
128 might_sleep();
129
130 if (!local->ops->set_cca_ed_level) {
131 WARN_ON(1);
132 return -EOPNOTSUPP;
133 }
134
0ecc4e68
VB
135 trace_802154_drv_set_cca_ed_level(local, mbm);
136 ret = local->ops->set_cca_ed_level(&local->hw, mbm);
137 trace_802154_drv_return_int(local, ret);
138 return ret;
b6eea9ca
AA
139}
140
29cd54b9 141static inline int drv_set_pan_id(struct ieee802154_local *local, __le16 pan_id)
b6eea9ca
AA
142{
143 struct ieee802154_hw_addr_filt filt;
0ecc4e68 144 int ret;
b6eea9ca
AA
145
146 might_sleep();
147
148 if (!local->ops->set_hw_addr_filt) {
149 WARN_ON(1);
150 return -EOPNOTSUPP;
151 }
152
153 filt.pan_id = pan_id;
154
0ecc4e68
VB
155 trace_802154_drv_set_pan_id(local, pan_id);
156 ret = local->ops->set_hw_addr_filt(&local->hw, &filt,
b6eea9ca 157 IEEE802154_AFILT_PANID_CHANGED);
0ecc4e68
VB
158 trace_802154_drv_return_int(local, ret);
159 return ret;
b6eea9ca
AA
160}
161
29cd54b9
AA
162static inline int
163drv_set_extended_addr(struct ieee802154_local *local, __le64 extended_addr)
b6eea9ca
AA
164{
165 struct ieee802154_hw_addr_filt filt;
0ecc4e68 166 int ret;
b6eea9ca
AA
167
168 might_sleep();
169
170 if (!local->ops->set_hw_addr_filt) {
171 WARN_ON(1);
172 return -EOPNOTSUPP;
173 }
174
175 filt.ieee_addr = extended_addr;
176
0ecc4e68
VB
177 trace_802154_drv_set_extended_addr(local, extended_addr);
178 ret = local->ops->set_hw_addr_filt(&local->hw, &filt,
b6eea9ca 179 IEEE802154_AFILT_IEEEADDR_CHANGED);
0ecc4e68
VB
180 trace_802154_drv_return_int(local, ret);
181 return ret;
b6eea9ca
AA
182}
183
29cd54b9
AA
184static inline int
185drv_set_short_addr(struct ieee802154_local *local, __le16 short_addr)
b6eea9ca
AA
186{
187 struct ieee802154_hw_addr_filt filt;
0ecc4e68 188 int ret;
b6eea9ca
AA
189
190 might_sleep();
191
192 if (!local->ops->set_hw_addr_filt) {
193 WARN_ON(1);
194 return -EOPNOTSUPP;
195 }
196
197 filt.short_addr = short_addr;
198
0ecc4e68
VB
199 trace_802154_drv_set_short_addr(local, short_addr);
200 ret = local->ops->set_hw_addr_filt(&local->hw, &filt,
b6eea9ca 201 IEEE802154_AFILT_SADDR_CHANGED);
0ecc4e68
VB
202 trace_802154_drv_return_int(local, ret);
203 return ret;
b6eea9ca
AA
204}
205
29cd54b9
AA
206static inline int
207drv_set_pan_coord(struct ieee802154_local *local, bool is_coord)
b6eea9ca
AA
208{
209 struct ieee802154_hw_addr_filt filt;
0ecc4e68 210 int ret;
b6eea9ca
AA
211
212 might_sleep();
213
214 if (!local->ops->set_hw_addr_filt) {
215 WARN_ON(1);
216 return -EOPNOTSUPP;
217 }
218
219 filt.pan_coord = is_coord;
220
0ecc4e68
VB
221 trace_802154_drv_set_pan_coord(local, is_coord);
222 ret = local->ops->set_hw_addr_filt(&local->hw, &filt,
b6eea9ca 223 IEEE802154_AFILT_PANC_CHANGED);
0ecc4e68
VB
224 trace_802154_drv_return_int(local, ret);
225 return ret;
b6eea9ca
AA
226}
227
29cd54b9
AA
228static inline int
229drv_set_csma_params(struct ieee802154_local *local, u8 min_be, u8 max_be,
230 u8 max_csma_backoffs)
b6eea9ca 231{
0ecc4e68
VB
232 int ret;
233
b6eea9ca
AA
234 might_sleep();
235
236 if (!local->ops->set_csma_params) {
237 WARN_ON(1);
238 return -EOPNOTSUPP;
239 }
240
0ecc4e68
VB
241 trace_802154_drv_set_csma_params(local, min_be, max_be,
242 max_csma_backoffs);
243 ret = local->ops->set_csma_params(&local->hw, min_be, max_be,
b6eea9ca 244 max_csma_backoffs);
0ecc4e68
VB
245 trace_802154_drv_return_int(local, ret);
246 return ret;
b6eea9ca
AA
247}
248
29cd54b9
AA
249static inline int
250drv_set_max_frame_retries(struct ieee802154_local *local, s8 max_frame_retries)
b6eea9ca 251{
0ecc4e68
VB
252 int ret;
253
b6eea9ca
AA
254 might_sleep();
255
256 if (!local->ops->set_frame_retries) {
257 WARN_ON(1);
258 return -EOPNOTSUPP;
259 }
260
0ecc4e68
VB
261 trace_802154_drv_set_max_frame_retries(local, max_frame_retries);
262 ret = local->ops->set_frame_retries(&local->hw, max_frame_retries);
263 trace_802154_drv_return_int(local, ret);
264 return ret;
b6eea9ca
AA
265}
266
29cd54b9
AA
267static inline int
268drv_set_promiscuous_mode(struct ieee802154_local *local, bool on)
94b79222 269{
0ecc4e68
VB
270 int ret;
271
94b79222
AA
272 might_sleep();
273
274 if (!local->ops->set_promiscuous_mode) {
275 WARN_ON(1);
276 return -EOPNOTSUPP;
277 }
278
0ecc4e68
VB
279 trace_802154_drv_set_promiscuous_mode(local, on);
280 ret = local->ops->set_promiscuous_mode(&local->hw, on);
281 trace_802154_drv_return_int(local, ret);
282 return ret;
94b79222
AA
283}
284
ea6edfbc 285#endif /* __MAC802154_DRIVER_OPS */