Alexander Aring | b6eea9c | 2014-10-28 18:21:20 +0100 | [diff] [blame] | 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 | |
Alexander Aring | e363eca | 2014-10-28 18:21:26 +0100 | [diff] [blame] | 32 | local->started = true; |
Alexander Aring | 538181a | 2014-10-28 18:21:27 +0100 | [diff] [blame] | 33 | smp_mb(); |
Alexander Aring | e363eca | 2014-10-28 18:21:26 +0100 | [diff] [blame] | 34 | |
Alexander Aring | b6eea9c | 2014-10-28 18:21:20 +0100 | [diff] [blame] | 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); |
Alexander Aring | e363eca | 2014-10-28 18:21:26 +0100 | [diff] [blame] | 43 | |
Alexander Aring | 538181a | 2014-10-28 18:21:27 +0100 | [diff] [blame] | 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 | |
Alexander Aring | e363eca | 2014-10-28 18:21:26 +0100 | [diff] [blame] | 50 | local->started = false; |
Alexander Aring | b6eea9c | 2014-10-28 18:21:20 +0100 | [diff] [blame] | 51 | } |
| 52 | |
Alexander Aring | 29cd54b | 2014-11-17 08:20:45 +0100 | [diff] [blame] | 53 | static inline int |
| 54 | drv_set_channel(struct ieee802154_local *local, u8 page, u8 channel) |
Alexander Aring | b6eea9c | 2014-10-28 18:21:20 +0100 | [diff] [blame] | 55 | { |
| 56 | might_sleep(); |
| 57 | |
| 58 | return local->ops->set_channel(&local->hw, page, channel); |
| 59 | } |
| 60 | |
Alexander Aring | 29cd54b | 2014-11-17 08:20:45 +0100 | [diff] [blame] | 61 | static inline int drv_set_tx_power(struct ieee802154_local *local, s8 dbm) |
Alexander Aring | b6eea9c | 2014-10-28 18:21:20 +0100 | [diff] [blame] | 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 | |
Alexander Aring | 29cd54b | 2014-11-17 08:20:45 +0100 | [diff] [blame] | 73 | static inline int drv_set_cca_mode(struct ieee802154_local *local, u8 cca_mode) |
Alexander Aring | b6eea9c | 2014-10-28 18:21:20 +0100 | [diff] [blame] | 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 | |
Alexander Aring | 29cd54b | 2014-11-17 08:20:45 +0100 | [diff] [blame] | 85 | 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] | 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 | |
Alexander Aring | 29cd54b | 2014-11-17 08:20:45 +0100 | [diff] [blame] | 97 | static inline int |
| 98 | drv_set_cca_ed_level(struct ieee802154_local *local, s32 ed_level) |
Alexander Aring | b6eea9c | 2014-10-28 18:21:20 +0100 | [diff] [blame] | 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 | |
Alexander Aring | 29cd54b | 2014-11-17 08:20:45 +0100 | [diff] [blame] | 110 | 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] | 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 | |
Alexander Aring | 29cd54b | 2014-11-17 08:20:45 +0100 | [diff] [blame] | 127 | static inline int |
| 128 | drv_set_extended_addr(struct ieee802154_local *local, __le64 extended_addr) |
Alexander Aring | b6eea9c | 2014-10-28 18:21:20 +0100 | [diff] [blame] | 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 | |
Alexander Aring | 29cd54b | 2014-11-17 08:20:45 +0100 | [diff] [blame] | 145 | static inline int |
| 146 | drv_set_short_addr(struct ieee802154_local *local, __le16 short_addr) |
Alexander Aring | b6eea9c | 2014-10-28 18:21:20 +0100 | [diff] [blame] | 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 | |
Alexander Aring | 29cd54b | 2014-11-17 08:20:45 +0100 | [diff] [blame] | 163 | static inline int |
| 164 | drv_set_pan_coord(struct ieee802154_local *local, bool is_coord) |
Alexander Aring | b6eea9c | 2014-10-28 18:21:20 +0100 | [diff] [blame] | 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 | |
Alexander Aring | 29cd54b | 2014-11-17 08:20:45 +0100 | [diff] [blame] | 181 | static inline int |
| 182 | drv_set_csma_params(struct ieee802154_local *local, u8 min_be, u8 max_be, |
| 183 | u8 max_csma_backoffs) |
Alexander Aring | b6eea9c | 2014-10-28 18:21:20 +0100 | [diff] [blame] | 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 | |
Alexander Aring | 29cd54b | 2014-11-17 08:20:45 +0100 | [diff] [blame] | 196 | static inline int |
| 197 | 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] | 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 | |
Alexander Aring | 29cd54b | 2014-11-17 08:20:45 +0100 | [diff] [blame] | 209 | static inline int |
| 210 | drv_set_promiscuous_mode(struct ieee802154_local *local, bool on) |
Alexander Aring | 94b7922 | 2014-10-29 21:34:32 +0100 | [diff] [blame] | 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 | |
Alexander Aring | b6eea9c | 2014-10-28 18:21:20 +0100 | [diff] [blame] | 222 | #endif /* __MAC802154_DRVIER_OPS */ |