Commit | Line | Data |
---|---|---|
b6eea9ca AA |
1 | #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 | ||
11 | static inline int | |
12 | drv_xmit_async(struct ieee802154_local *local, struct sk_buff *skb) | |
13 | { | |
14 | return local->ops->xmit_async(&local->hw, skb); | |
15 | } | |
16 | ||
17 | static inline int | |
18 | drv_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 | ||
28 | static inline int drv_start(struct ieee802154_local *local) | |
29 | { | |
30 | might_sleep(); | |
31 | ||
e363eca3 | 32 | local->started = true; |
538181a8 | 33 | smp_mb(); |
e363eca3 | 34 | |
b6eea9ca AA |
35 | return local->ops->start(&local->hw); |
36 | } | |
37 | ||
38 | static inline void drv_stop(struct ieee802154_local *local) | |
39 | { | |
40 | might_sleep(); | |
41 | ||
42 | local->ops->stop(&local->hw); | |
e363eca3 | 43 | |
538181a8 AA |
44 | /* sync away all work on the tasklet before clearing started */ |
45 | tasklet_disable(&local->tasklet); | |
46 | tasklet_enable(&local->tasklet); | |
47 | ||
48 | barrier(); | |
49 | ||
e363eca3 | 50 | local->started = false; |
b6eea9ca AA |
51 | } |
52 | ||
29cd54b9 AA |
53 | static inline int |
54 | drv_set_channel(struct ieee802154_local *local, u8 page, u8 channel) | |
b6eea9ca AA |
55 | { |
56 | might_sleep(); | |
57 | ||
58 | return local->ops->set_channel(&local->hw, page, channel); | |
59 | } | |
60 | ||
29cd54b9 | 61 | static inline int drv_set_tx_power(struct ieee802154_local *local, s8 dbm) |
b6eea9ca AA |
62 | { |
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 | ||
29cd54b9 | 73 | static inline int drv_set_cca_mode(struct ieee802154_local *local, u8 cca_mode) |
b6eea9ca AA |
74 | { |
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 | ||
29cd54b9 | 85 | static inline int drv_set_lbt_mode(struct ieee802154_local *local, bool mode) |
b6eea9ca AA |
86 | { |
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 | ||
29cd54b9 AA |
97 | static inline int |
98 | drv_set_cca_ed_level(struct ieee802154_local *local, s32 ed_level) | |
b6eea9ca AA |
99 | { |
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 | ||
29cd54b9 | 110 | static inline int drv_set_pan_id(struct ieee802154_local *local, __le16 pan_id) |
b6eea9ca AA |
111 | { |
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 | ||
29cd54b9 AA |
127 | static inline int |
128 | drv_set_extended_addr(struct ieee802154_local *local, __le64 extended_addr) | |
b6eea9ca AA |
129 | { |
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 | ||
29cd54b9 AA |
145 | static inline int |
146 | drv_set_short_addr(struct ieee802154_local *local, __le16 short_addr) | |
b6eea9ca AA |
147 | { |
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 | ||
29cd54b9 AA |
163 | static inline int |
164 | drv_set_pan_coord(struct ieee802154_local *local, bool is_coord) | |
b6eea9ca AA |
165 | { |
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 | ||
29cd54b9 AA |
181 | static inline int |
182 | drv_set_csma_params(struct ieee802154_local *local, u8 min_be, u8 max_be, | |
183 | u8 max_csma_backoffs) | |
b6eea9ca AA |
184 | { |
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 | ||
29cd54b9 AA |
196 | static inline int |
197 | drv_set_max_frame_retries(struct ieee802154_local *local, s8 max_frame_retries) | |
b6eea9ca AA |
198 | { |
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 | ||
29cd54b9 AA |
209 | static inline int |
210 | drv_set_promiscuous_mode(struct ieee802154_local *local, bool on) | |
94b79222 AA |
211 | { |
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 | ||
b6eea9ca | 222 | #endif /* __MAC802154_DRVIER_OPS */ |