driver-ops.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. #ifndef __MAC802154_DRIVER_OPS
  2. #define __MAC802154_DRIVER_OPS
  3. #include <linux/types.h>
  4. #include <linux/rtnetlink.h>
  5. #include <net/mac802154.h>
  6. #include "ieee802154_i.h"
  7. #include "trace.h"
  8. static inline int
  9. drv_xmit_async(struct ieee802154_local *local, struct sk_buff *skb)
  10. {
  11. return local->ops->xmit_async(&local->hw, skb);
  12. }
  13. static inline int
  14. drv_xmit_sync(struct ieee802154_local *local, struct sk_buff *skb)
  15. {
  16. might_sleep();
  17. return local->ops->xmit_sync(&local->hw, skb);
  18. }
  19. static inline int drv_start(struct ieee802154_local *local)
  20. {
  21. int ret;
  22. might_sleep();
  23. trace_802154_drv_start(local);
  24. local->started = true;
  25. smp_mb();
  26. ret = local->ops->start(&local->hw);
  27. trace_802154_drv_return_int(local, ret);
  28. return ret;
  29. }
  30. static inline void drv_stop(struct ieee802154_local *local)
  31. {
  32. might_sleep();
  33. trace_802154_drv_stop(local);
  34. local->ops->stop(&local->hw);
  35. trace_802154_drv_return_void(local);
  36. /* sync away all work on the tasklet before clearing started */
  37. tasklet_disable(&local->tasklet);
  38. tasklet_enable(&local->tasklet);
  39. barrier();
  40. local->started = false;
  41. }
  42. static inline int
  43. drv_set_channel(struct ieee802154_local *local, u8 page, u8 channel)
  44. {
  45. int ret;
  46. might_sleep();
  47. trace_802154_drv_set_channel(local, page, channel);
  48. ret = local->ops->set_channel(&local->hw, page, channel);
  49. trace_802154_drv_return_int(local, ret);
  50. return ret;
  51. }
  52. static inline int drv_set_tx_power(struct ieee802154_local *local, s32 mbm)
  53. {
  54. int ret;
  55. might_sleep();
  56. if (!local->ops->set_txpower) {
  57. WARN_ON(1);
  58. return -EOPNOTSUPP;
  59. }
  60. trace_802154_drv_set_tx_power(local, mbm);
  61. ret = local->ops->set_txpower(&local->hw, mbm);
  62. trace_802154_drv_return_int(local, ret);
  63. return ret;
  64. }
  65. static inline int drv_set_cca_mode(struct ieee802154_local *local,
  66. const struct wpan_phy_cca *cca)
  67. {
  68. int ret;
  69. might_sleep();
  70. if (!local->ops->set_cca_mode) {
  71. WARN_ON(1);
  72. return -EOPNOTSUPP;
  73. }
  74. trace_802154_drv_set_cca_mode(local, cca);
  75. ret = local->ops->set_cca_mode(&local->hw, cca);
  76. trace_802154_drv_return_int(local, ret);
  77. return ret;
  78. }
  79. static inline int drv_set_lbt_mode(struct ieee802154_local *local, bool mode)
  80. {
  81. int ret;
  82. might_sleep();
  83. if (!local->ops->set_lbt) {
  84. WARN_ON(1);
  85. return -EOPNOTSUPP;
  86. }
  87. trace_802154_drv_set_lbt_mode(local, mode);
  88. ret = local->ops->set_lbt(&local->hw, mode);
  89. trace_802154_drv_return_int(local, ret);
  90. return ret;
  91. }
  92. static inline int
  93. drv_set_cca_ed_level(struct ieee802154_local *local, s32 mbm)
  94. {
  95. int ret;
  96. might_sleep();
  97. if (!local->ops->set_cca_ed_level) {
  98. WARN_ON(1);
  99. return -EOPNOTSUPP;
  100. }
  101. trace_802154_drv_set_cca_ed_level(local, mbm);
  102. ret = local->ops->set_cca_ed_level(&local->hw, mbm);
  103. trace_802154_drv_return_int(local, ret);
  104. return ret;
  105. }
  106. static inline int drv_set_pan_id(struct ieee802154_local *local, __le16 pan_id)
  107. {
  108. struct ieee802154_hw_addr_filt filt;
  109. int ret;
  110. might_sleep();
  111. if (!local->ops->set_hw_addr_filt) {
  112. WARN_ON(1);
  113. return -EOPNOTSUPP;
  114. }
  115. filt.pan_id = pan_id;
  116. trace_802154_drv_set_pan_id(local, pan_id);
  117. ret = local->ops->set_hw_addr_filt(&local->hw, &filt,
  118. IEEE802154_AFILT_PANID_CHANGED);
  119. trace_802154_drv_return_int(local, ret);
  120. return ret;
  121. }
  122. static inline int
  123. drv_set_extended_addr(struct ieee802154_local *local, __le64 extended_addr)
  124. {
  125. struct ieee802154_hw_addr_filt filt;
  126. int ret;
  127. might_sleep();
  128. if (!local->ops->set_hw_addr_filt) {
  129. WARN_ON(1);
  130. return -EOPNOTSUPP;
  131. }
  132. filt.ieee_addr = extended_addr;
  133. trace_802154_drv_set_extended_addr(local, extended_addr);
  134. ret = local->ops->set_hw_addr_filt(&local->hw, &filt,
  135. IEEE802154_AFILT_IEEEADDR_CHANGED);
  136. trace_802154_drv_return_int(local, ret);
  137. return ret;
  138. }
  139. static inline int
  140. drv_set_short_addr(struct ieee802154_local *local, __le16 short_addr)
  141. {
  142. struct ieee802154_hw_addr_filt filt;
  143. int ret;
  144. might_sleep();
  145. if (!local->ops->set_hw_addr_filt) {
  146. WARN_ON(1);
  147. return -EOPNOTSUPP;
  148. }
  149. filt.short_addr = short_addr;
  150. trace_802154_drv_set_short_addr(local, short_addr);
  151. ret = local->ops->set_hw_addr_filt(&local->hw, &filt,
  152. IEEE802154_AFILT_SADDR_CHANGED);
  153. trace_802154_drv_return_int(local, ret);
  154. return ret;
  155. }
  156. static inline int
  157. drv_set_pan_coord(struct ieee802154_local *local, bool is_coord)
  158. {
  159. struct ieee802154_hw_addr_filt filt;
  160. int ret;
  161. might_sleep();
  162. if (!local->ops->set_hw_addr_filt) {
  163. WARN_ON(1);
  164. return -EOPNOTSUPP;
  165. }
  166. filt.pan_coord = is_coord;
  167. trace_802154_drv_set_pan_coord(local, is_coord);
  168. ret = local->ops->set_hw_addr_filt(&local->hw, &filt,
  169. IEEE802154_AFILT_PANC_CHANGED);
  170. trace_802154_drv_return_int(local, ret);
  171. return ret;
  172. }
  173. static inline int
  174. drv_set_csma_params(struct ieee802154_local *local, u8 min_be, u8 max_be,
  175. u8 max_csma_backoffs)
  176. {
  177. int ret;
  178. might_sleep();
  179. if (!local->ops->set_csma_params) {
  180. WARN_ON(1);
  181. return -EOPNOTSUPP;
  182. }
  183. trace_802154_drv_set_csma_params(local, min_be, max_be,
  184. max_csma_backoffs);
  185. ret = local->ops->set_csma_params(&local->hw, min_be, max_be,
  186. max_csma_backoffs);
  187. trace_802154_drv_return_int(local, ret);
  188. return ret;
  189. }
  190. static inline int
  191. drv_set_max_frame_retries(struct ieee802154_local *local, s8 max_frame_retries)
  192. {
  193. int ret;
  194. might_sleep();
  195. if (!local->ops->set_frame_retries) {
  196. WARN_ON(1);
  197. return -EOPNOTSUPP;
  198. }
  199. trace_802154_drv_set_max_frame_retries(local, max_frame_retries);
  200. ret = local->ops->set_frame_retries(&local->hw, max_frame_retries);
  201. trace_802154_drv_return_int(local, ret);
  202. return ret;
  203. }
  204. static inline int
  205. drv_set_promiscuous_mode(struct ieee802154_local *local, bool on)
  206. {
  207. int ret;
  208. might_sleep();
  209. if (!local->ops->set_promiscuous_mode) {
  210. WARN_ON(1);
  211. return -EOPNOTSUPP;
  212. }
  213. trace_802154_drv_set_promiscuous_mode(local, on);
  214. ret = local->ops->set_promiscuous_mode(&local->hw, on);
  215. trace_802154_drv_return_int(local, ret);
  216. return ret;
  217. }
  218. #endif /* __MAC802154_DRIVER_OPS */