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" |
| 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 | 7fe9a38 | 2014-12-10 15:33:12 +0100 | [diff] [blame] | 73 | static inline int drv_set_cca_mode(struct ieee802154_local *local, |
| 74 | const struct wpan_phy_cca *cca) |
Alexander Aring | b6eea9c | 2014-10-28 18:21:20 +0100 | [diff] [blame] | 75 | { |
| 76 | might_sleep(); |
| 77 | |
| 78 | if (!local->ops->set_cca_mode) { |
| 79 | WARN_ON(1); |
| 80 | return -EOPNOTSUPP; |
| 81 | } |
| 82 | |
Alexander Aring | 7fe9a38 | 2014-12-10 15:33:12 +0100 | [diff] [blame] | 83 | return local->ops->set_cca_mode(&local->hw, cca); |
Alexander Aring | b6eea9c | 2014-10-28 18:21:20 +0100 | [diff] [blame] | 84 | } |
| 85 | |
Alexander Aring | 29cd54b | 2014-11-17 08:20:45 +0100 | [diff] [blame] | 86 | 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] | 87 | { |
| 88 | might_sleep(); |
| 89 | |
| 90 | if (!local->ops->set_lbt) { |
| 91 | WARN_ON(1); |
| 92 | return -EOPNOTSUPP; |
| 93 | } |
| 94 | |
| 95 | return local->ops->set_lbt(&local->hw, mode); |
| 96 | } |
| 97 | |
Alexander Aring | 29cd54b | 2014-11-17 08:20:45 +0100 | [diff] [blame] | 98 | static inline int |
| 99 | drv_set_cca_ed_level(struct ieee802154_local *local, s32 ed_level) |
Alexander Aring | b6eea9c | 2014-10-28 18:21:20 +0100 | [diff] [blame] | 100 | { |
| 101 | might_sleep(); |
| 102 | |
| 103 | if (!local->ops->set_cca_ed_level) { |
| 104 | WARN_ON(1); |
| 105 | return -EOPNOTSUPP; |
| 106 | } |
| 107 | |
| 108 | return local->ops->set_cca_ed_level(&local->hw, ed_level); |
| 109 | } |
| 110 | |
Alexander Aring | 29cd54b | 2014-11-17 08:20:45 +0100 | [diff] [blame] | 111 | 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] | 112 | { |
| 113 | struct ieee802154_hw_addr_filt filt; |
| 114 | |
| 115 | might_sleep(); |
| 116 | |
| 117 | if (!local->ops->set_hw_addr_filt) { |
| 118 | WARN_ON(1); |
| 119 | return -EOPNOTSUPP; |
| 120 | } |
| 121 | |
| 122 | filt.pan_id = pan_id; |
| 123 | |
| 124 | return local->ops->set_hw_addr_filt(&local->hw, &filt, |
| 125 | IEEE802154_AFILT_PANID_CHANGED); |
| 126 | } |
| 127 | |
Alexander Aring | 29cd54b | 2014-11-17 08:20:45 +0100 | [diff] [blame] | 128 | static inline int |
| 129 | drv_set_extended_addr(struct ieee802154_local *local, __le64 extended_addr) |
Alexander Aring | b6eea9c | 2014-10-28 18:21:20 +0100 | [diff] [blame] | 130 | { |
| 131 | struct ieee802154_hw_addr_filt filt; |
| 132 | |
| 133 | might_sleep(); |
| 134 | |
| 135 | if (!local->ops->set_hw_addr_filt) { |
| 136 | WARN_ON(1); |
| 137 | return -EOPNOTSUPP; |
| 138 | } |
| 139 | |
| 140 | filt.ieee_addr = extended_addr; |
| 141 | |
| 142 | return local->ops->set_hw_addr_filt(&local->hw, &filt, |
| 143 | IEEE802154_AFILT_IEEEADDR_CHANGED); |
| 144 | } |
| 145 | |
Alexander Aring | 29cd54b | 2014-11-17 08:20:45 +0100 | [diff] [blame] | 146 | static inline int |
| 147 | drv_set_short_addr(struct ieee802154_local *local, __le16 short_addr) |
Alexander Aring | b6eea9c | 2014-10-28 18:21:20 +0100 | [diff] [blame] | 148 | { |
| 149 | struct ieee802154_hw_addr_filt filt; |
| 150 | |
| 151 | might_sleep(); |
| 152 | |
| 153 | if (!local->ops->set_hw_addr_filt) { |
| 154 | WARN_ON(1); |
| 155 | return -EOPNOTSUPP; |
| 156 | } |
| 157 | |
| 158 | filt.short_addr = short_addr; |
| 159 | |
| 160 | return local->ops->set_hw_addr_filt(&local->hw, &filt, |
| 161 | IEEE802154_AFILT_SADDR_CHANGED); |
| 162 | } |
| 163 | |
Alexander Aring | 29cd54b | 2014-11-17 08:20:45 +0100 | [diff] [blame] | 164 | static inline int |
| 165 | drv_set_pan_coord(struct ieee802154_local *local, bool is_coord) |
Alexander Aring | b6eea9c | 2014-10-28 18:21:20 +0100 | [diff] [blame] | 166 | { |
| 167 | struct ieee802154_hw_addr_filt filt; |
| 168 | |
| 169 | might_sleep(); |
| 170 | |
| 171 | if (!local->ops->set_hw_addr_filt) { |
| 172 | WARN_ON(1); |
| 173 | return -EOPNOTSUPP; |
| 174 | } |
| 175 | |
| 176 | filt.pan_coord = is_coord; |
| 177 | |
| 178 | return local->ops->set_hw_addr_filt(&local->hw, &filt, |
| 179 | IEEE802154_AFILT_PANC_CHANGED); |
| 180 | } |
| 181 | |
Alexander Aring | 29cd54b | 2014-11-17 08:20:45 +0100 | [diff] [blame] | 182 | static inline int |
| 183 | drv_set_csma_params(struct ieee802154_local *local, u8 min_be, u8 max_be, |
| 184 | u8 max_csma_backoffs) |
Alexander Aring | b6eea9c | 2014-10-28 18:21:20 +0100 | [diff] [blame] | 185 | { |
| 186 | might_sleep(); |
| 187 | |
| 188 | if (!local->ops->set_csma_params) { |
| 189 | WARN_ON(1); |
| 190 | return -EOPNOTSUPP; |
| 191 | } |
| 192 | |
| 193 | return local->ops->set_csma_params(&local->hw, min_be, max_be, |
| 194 | max_csma_backoffs); |
| 195 | } |
| 196 | |
Alexander Aring | 29cd54b | 2014-11-17 08:20:45 +0100 | [diff] [blame] | 197 | static inline int |
| 198 | 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] | 199 | { |
| 200 | might_sleep(); |
| 201 | |
| 202 | if (!local->ops->set_frame_retries) { |
| 203 | WARN_ON(1); |
| 204 | return -EOPNOTSUPP; |
| 205 | } |
| 206 | |
| 207 | return local->ops->set_frame_retries(&local->hw, max_frame_retries); |
| 208 | } |
| 209 | |
Alexander Aring | 29cd54b | 2014-11-17 08:20:45 +0100 | [diff] [blame] | 210 | static inline int |
| 211 | drv_set_promiscuous_mode(struct ieee802154_local *local, bool on) |
Alexander Aring | 94b7922 | 2014-10-29 21:34:32 +0100 | [diff] [blame] | 212 | { |
| 213 | might_sleep(); |
| 214 | |
| 215 | if (!local->ops->set_promiscuous_mode) { |
| 216 | WARN_ON(1); |
| 217 | return -EOPNOTSUPP; |
| 218 | } |
| 219 | |
| 220 | return local->ops->set_promiscuous_mode(&local->hw, on); |
| 221 | } |
| 222 | |
Nicolas Iooss | ea6edfb | 2015-03-19 21:23:40 +0800 | [diff] [blame] | 223 | #endif /* __MAC802154_DRIVER_OPS */ |