driver-ops.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. #ifndef __MAC802154_DRVIER_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. static inline int
  8. drv_xmit_async(struct ieee802154_local *local, struct sk_buff *skb)
  9. {
  10. return local->ops->xmit_async(&local->hw, skb);
  11. }
  12. static inline int
  13. drv_xmit_sync(struct ieee802154_local *local, struct sk_buff *skb)
  14. {
  15. /* don't allow other operations while sync xmit */
  16. ASSERT_RTNL();
  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. might_sleep();
  23. local->started = true;
  24. smp_mb();
  25. return local->ops->start(&local->hw);
  26. }
  27. static inline void drv_stop(struct ieee802154_local *local)
  28. {
  29. might_sleep();
  30. local->ops->stop(&local->hw);
  31. /* sync away all work on the tasklet before clearing started */
  32. tasklet_disable(&local->tasklet);
  33. tasklet_enable(&local->tasklet);
  34. barrier();
  35. local->started = false;
  36. }
  37. static inline int drv_set_channel(struct ieee802154_local *local,
  38. const u8 page, const u8 channel)
  39. {
  40. might_sleep();
  41. return local->ops->set_channel(&local->hw, page, channel);
  42. }
  43. static inline int drv_set_tx_power(struct ieee802154_local *local,
  44. const s8 dbm)
  45. {
  46. might_sleep();
  47. if (!local->ops->set_txpower) {
  48. WARN_ON(1);
  49. return -EOPNOTSUPP;
  50. }
  51. return local->ops->set_txpower(&local->hw, dbm);
  52. }
  53. static inline int drv_set_cca_mode(struct ieee802154_local *local,
  54. const u8 cca_mode)
  55. {
  56. might_sleep();
  57. if (!local->ops->set_cca_mode) {
  58. WARN_ON(1);
  59. return -EOPNOTSUPP;
  60. }
  61. return local->ops->set_cca_mode(&local->hw, cca_mode);
  62. }
  63. static inline int drv_set_lbt_mode(struct ieee802154_local *local,
  64. const bool mode)
  65. {
  66. might_sleep();
  67. if (!local->ops->set_lbt) {
  68. WARN_ON(1);
  69. return -EOPNOTSUPP;
  70. }
  71. return local->ops->set_lbt(&local->hw, mode);
  72. }
  73. static inline int drv_set_cca_ed_level(struct ieee802154_local *local,
  74. const s32 ed_level)
  75. {
  76. might_sleep();
  77. if (!local->ops->set_cca_ed_level) {
  78. WARN_ON(1);
  79. return -EOPNOTSUPP;
  80. }
  81. return local->ops->set_cca_ed_level(&local->hw, ed_level);
  82. }
  83. static inline int drv_set_pan_id(struct ieee802154_local *local,
  84. const __le16 pan_id)
  85. {
  86. struct ieee802154_hw_addr_filt filt;
  87. might_sleep();
  88. if (!local->ops->set_hw_addr_filt) {
  89. WARN_ON(1);
  90. return -EOPNOTSUPP;
  91. }
  92. filt.pan_id = pan_id;
  93. return local->ops->set_hw_addr_filt(&local->hw, &filt,
  94. IEEE802154_AFILT_PANID_CHANGED);
  95. }
  96. static inline int drv_set_extended_addr(struct ieee802154_local *local,
  97. const __le64 extended_addr)
  98. {
  99. struct ieee802154_hw_addr_filt filt;
  100. might_sleep();
  101. if (!local->ops->set_hw_addr_filt) {
  102. WARN_ON(1);
  103. return -EOPNOTSUPP;
  104. }
  105. filt.ieee_addr = extended_addr;
  106. return local->ops->set_hw_addr_filt(&local->hw, &filt,
  107. IEEE802154_AFILT_IEEEADDR_CHANGED);
  108. }
  109. static inline int drv_set_short_addr(struct ieee802154_local *local,
  110. const __le16 short_addr)
  111. {
  112. struct ieee802154_hw_addr_filt filt;
  113. might_sleep();
  114. if (!local->ops->set_hw_addr_filt) {
  115. WARN_ON(1);
  116. return -EOPNOTSUPP;
  117. }
  118. filt.short_addr = short_addr;
  119. return local->ops->set_hw_addr_filt(&local->hw, &filt,
  120. IEEE802154_AFILT_SADDR_CHANGED);
  121. }
  122. static inline int drv_set_pan_coord(struct ieee802154_local *local,
  123. const bool is_coord)
  124. {
  125. struct ieee802154_hw_addr_filt filt;
  126. might_sleep();
  127. if (!local->ops->set_hw_addr_filt) {
  128. WARN_ON(1);
  129. return -EOPNOTSUPP;
  130. }
  131. filt.pan_coord = is_coord;
  132. return local->ops->set_hw_addr_filt(&local->hw, &filt,
  133. IEEE802154_AFILT_PANC_CHANGED);
  134. }
  135. static inline int drv_set_csma_params(struct ieee802154_local *local,
  136. u8 min_be, u8 max_be,
  137. u8 max_csma_backoffs)
  138. {
  139. might_sleep();
  140. if (!local->ops->set_csma_params) {
  141. WARN_ON(1);
  142. return -EOPNOTSUPP;
  143. }
  144. return local->ops->set_csma_params(&local->hw, min_be, max_be,
  145. max_csma_backoffs);
  146. }
  147. static inline int drv_set_max_frame_retries(struct ieee802154_local *local,
  148. s8 max_frame_retries)
  149. {
  150. might_sleep();
  151. if (!local->ops->set_frame_retries) {
  152. WARN_ON(1);
  153. return -EOPNOTSUPP;
  154. }
  155. return local->ops->set_frame_retries(&local->hw, max_frame_retries);
  156. }
  157. static inline int drv_set_promiscuous_mode(struct ieee802154_local *local,
  158. const bool on)
  159. {
  160. might_sleep();
  161. if (!local->ops->set_promiscuous_mode) {
  162. WARN_ON(1);
  163. return -EOPNOTSUPP;
  164. }
  165. return local->ops->set_promiscuous_mode(&local->hw, on);
  166. }
  167. #endif /* __MAC802154_DRVIER_OPS */