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