1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __MAC802154_DRIVER_OPS
3 #define __MAC802154_DRIVER_OPS
5 #include <linux/types.h>
6 #include <linux/rtnetlink.h>
8 #include <net/mac802154.h>
10 #include "ieee802154_i.h"
14 drv_xmit_async(struct ieee802154_local *local, struct sk_buff *skb)
16 return local->ops->xmit_async(&local->hw, skb);
20 drv_xmit_sync(struct ieee802154_local *local, struct sk_buff *skb)
24 return local->ops->xmit_sync(&local->hw, skb);
27 static inline int drv_set_pan_id(struct ieee802154_local *local, __le16 pan_id)
29 struct ieee802154_hw_addr_filt filt;
34 if (!local->ops->set_hw_addr_filt) {
41 trace_802154_drv_set_pan_id(local, pan_id);
42 ret = local->ops->set_hw_addr_filt(&local->hw, &filt,
43 IEEE802154_AFILT_PANID_CHANGED);
44 trace_802154_drv_return_int(local, ret);
49 drv_set_extended_addr(struct ieee802154_local *local, __le64 extended_addr)
51 struct ieee802154_hw_addr_filt filt;
56 if (!local->ops->set_hw_addr_filt) {
61 filt.ieee_addr = extended_addr;
63 trace_802154_drv_set_extended_addr(local, extended_addr);
64 ret = local->ops->set_hw_addr_filt(&local->hw, &filt,
65 IEEE802154_AFILT_IEEEADDR_CHANGED);
66 trace_802154_drv_return_int(local, ret);
71 drv_set_short_addr(struct ieee802154_local *local, __le16 short_addr)
73 struct ieee802154_hw_addr_filt filt;
78 if (!local->ops->set_hw_addr_filt) {
83 filt.short_addr = short_addr;
85 trace_802154_drv_set_short_addr(local, short_addr);
86 ret = local->ops->set_hw_addr_filt(&local->hw, &filt,
87 IEEE802154_AFILT_SADDR_CHANGED);
88 trace_802154_drv_return_int(local, ret);
93 drv_set_pan_coord(struct ieee802154_local *local, bool is_coord)
95 struct ieee802154_hw_addr_filt filt;
100 if (!local->ops->set_hw_addr_filt) {
105 filt.pan_coord = is_coord;
107 trace_802154_drv_set_pan_coord(local, is_coord);
108 ret = local->ops->set_hw_addr_filt(&local->hw, &filt,
109 IEEE802154_AFILT_PANC_CHANGED);
110 trace_802154_drv_return_int(local, ret);
115 drv_set_promiscuous_mode(struct ieee802154_local *local, bool on)
121 if (!local->ops->set_promiscuous_mode) {
126 trace_802154_drv_set_promiscuous_mode(local, on);
127 ret = local->ops->set_promiscuous_mode(&local->hw, on);
128 trace_802154_drv_return_int(local, ret);
132 static inline int drv_start(struct ieee802154_local *local,
133 enum ieee802154_filtering_level level,
134 const struct ieee802154_hw_addr_filt *addr_filt)
140 /* setup receive mode parameters e.g. address mode */
141 if (local->hw.flags & IEEE802154_HW_AFILT) {
142 ret = drv_set_pan_id(local, addr_filt->pan_id);
146 ret = drv_set_short_addr(local, addr_filt->short_addr);
150 ret = drv_set_extended_addr(local, addr_filt->ieee_addr);
156 case IEEE802154_FILTERING_NONE:
158 case IEEE802154_FILTERING_1_FCS:
160 case IEEE802154_FILTERING_2_PROMISCUOUS:
161 /* TODO: Requires a different receive mode setup e.g.
162 * at86rf233 hardware.
165 case IEEE802154_FILTERING_3_SCAN:
166 if (local->hw.flags & IEEE802154_HW_PROMISCUOUS) {
167 ret = drv_set_promiscuous_mode(local, true);
174 /* In practice other filtering levels can be requested, but as
175 * for now most hardware/drivers only support
176 * IEEE802154_FILTERING_NONE, we fallback to this actual
177 * filtering level in hardware and make our own additional
178 * filtering in mac802154 receive path.
180 * TODO: Move this logic to the device drivers as hardware may
181 * support more higher level filters. Hardware may also require
182 * a different order how register are set, which could currently
183 * be buggy, so all received parameters need to be moved to the
184 * start() callback and let the driver go into the mode before
185 * it will turn on receive handling.
187 local->phy->filtering = IEEE802154_FILTERING_NONE;
189 case IEEE802154_FILTERING_4_FRAME_FIELDS:
190 /* Do not error out if IEEE802154_HW_PROMISCUOUS because we
191 * expect the hardware to operate at the level
192 * IEEE802154_FILTERING_4_FRAME_FIELDS anyway.
194 if (local->hw.flags & IEEE802154_HW_PROMISCUOUS) {
195 ret = drv_set_promiscuous_mode(local, false);
200 local->phy->filtering = IEEE802154_FILTERING_4_FRAME_FIELDS;
207 trace_802154_drv_start(local);
208 local->started = true;
210 ret = local->ops->start(&local->hw);
211 trace_802154_drv_return_int(local, ret);
215 static inline void drv_stop(struct ieee802154_local *local)
219 trace_802154_drv_stop(local);
220 local->ops->stop(&local->hw);
221 trace_802154_drv_return_void(local);
223 /* sync away all work on the tasklet before clearing started */
224 tasklet_disable(&local->tasklet);
225 tasklet_enable(&local->tasklet);
229 local->started = false;
233 drv_set_channel(struct ieee802154_local *local, u8 page, u8 channel)
239 trace_802154_drv_set_channel(local, page, channel);
240 ret = local->ops->set_channel(&local->hw, page, channel);
241 trace_802154_drv_return_int(local, ret);
245 static inline int drv_set_tx_power(struct ieee802154_local *local, s32 mbm)
251 if (!local->ops->set_txpower) {
256 trace_802154_drv_set_tx_power(local, mbm);
257 ret = local->ops->set_txpower(&local->hw, mbm);
258 trace_802154_drv_return_int(local, ret);
262 static inline int drv_set_cca_mode(struct ieee802154_local *local,
263 const struct wpan_phy_cca *cca)
269 if (!local->ops->set_cca_mode) {
274 trace_802154_drv_set_cca_mode(local, cca);
275 ret = local->ops->set_cca_mode(&local->hw, cca);
276 trace_802154_drv_return_int(local, ret);
280 static inline int drv_set_lbt_mode(struct ieee802154_local *local, bool mode)
286 if (!local->ops->set_lbt) {
291 trace_802154_drv_set_lbt_mode(local, mode);
292 ret = local->ops->set_lbt(&local->hw, mode);
293 trace_802154_drv_return_int(local, ret);
298 drv_set_cca_ed_level(struct ieee802154_local *local, s32 mbm)
304 if (!local->ops->set_cca_ed_level) {
309 trace_802154_drv_set_cca_ed_level(local, mbm);
310 ret = local->ops->set_cca_ed_level(&local->hw, mbm);
311 trace_802154_drv_return_int(local, ret);
316 drv_set_csma_params(struct ieee802154_local *local, u8 min_be, u8 max_be,
317 u8 max_csma_backoffs)
323 if (!local->ops->set_csma_params) {
328 trace_802154_drv_set_csma_params(local, min_be, max_be,
330 ret = local->ops->set_csma_params(&local->hw, min_be, max_be,
332 trace_802154_drv_return_int(local, ret);
337 drv_set_max_frame_retries(struct ieee802154_local *local, s8 max_frame_retries)
343 if (!local->ops->set_frame_retries) {
348 trace_802154_drv_set_max_frame_retries(local, max_frame_retries);
349 ret = local->ops->set_frame_retries(&local->hw, max_frame_retries);
350 trace_802154_drv_return_int(local, ret);
354 #endif /* __MAC802154_DRIVER_OPS */