driver-ops.h 5.8 KB

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