driver-ops.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. 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
  38. drv_set_channel(struct ieee802154_local *local, u8 page, 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, s8 dbm)
  44. {
  45. might_sleep();
  46. if (!local->ops->set_txpower) {
  47. WARN_ON(1);
  48. return -EOPNOTSUPP;
  49. }
  50. return local->ops->set_txpower(&local->hw, dbm);
  51. }
  52. static inline int drv_set_cca_mode(struct ieee802154_local *local,
  53. const struct wpan_phy_cca *cca)
  54. {
  55. might_sleep();
  56. if (!local->ops->set_cca_mode) {
  57. WARN_ON(1);
  58. return -EOPNOTSUPP;
  59. }
  60. return local->ops->set_cca_mode(&local->hw, cca);
  61. }
  62. static inline int drv_set_lbt_mode(struct ieee802154_local *local, bool mode)
  63. {
  64. might_sleep();
  65. if (!local->ops->set_lbt) {
  66. WARN_ON(1);
  67. return -EOPNOTSUPP;
  68. }
  69. return local->ops->set_lbt(&local->hw, mode);
  70. }
  71. static inline int
  72. drv_set_cca_ed_level(struct ieee802154_local *local, s32 ed_level)
  73. {
  74. might_sleep();
  75. if (!local->ops->set_cca_ed_level) {
  76. WARN_ON(1);
  77. return -EOPNOTSUPP;
  78. }
  79. return local->ops->set_cca_ed_level(&local->hw, ed_level);
  80. }
  81. static inline int drv_set_pan_id(struct ieee802154_local *local, __le16 pan_id)
  82. {
  83. struct ieee802154_hw_addr_filt filt;
  84. might_sleep();
  85. if (!local->ops->set_hw_addr_filt) {
  86. WARN_ON(1);
  87. return -EOPNOTSUPP;
  88. }
  89. filt.pan_id = pan_id;
  90. return local->ops->set_hw_addr_filt(&local->hw, &filt,
  91. IEEE802154_AFILT_PANID_CHANGED);
  92. }
  93. static inline int
  94. drv_set_extended_addr(struct ieee802154_local *local, __le64 extended_addr)
  95. {
  96. struct ieee802154_hw_addr_filt filt;
  97. might_sleep();
  98. if (!local->ops->set_hw_addr_filt) {
  99. WARN_ON(1);
  100. return -EOPNOTSUPP;
  101. }
  102. filt.ieee_addr = extended_addr;
  103. return local->ops->set_hw_addr_filt(&local->hw, &filt,
  104. IEEE802154_AFILT_IEEEADDR_CHANGED);
  105. }
  106. static inline int
  107. drv_set_short_addr(struct ieee802154_local *local, __le16 short_addr)
  108. {
  109. struct ieee802154_hw_addr_filt filt;
  110. might_sleep();
  111. if (!local->ops->set_hw_addr_filt) {
  112. WARN_ON(1);
  113. return -EOPNOTSUPP;
  114. }
  115. filt.short_addr = short_addr;
  116. return local->ops->set_hw_addr_filt(&local->hw, &filt,
  117. IEEE802154_AFILT_SADDR_CHANGED);
  118. }
  119. static inline int
  120. drv_set_pan_coord(struct ieee802154_local *local, bool is_coord)
  121. {
  122. struct ieee802154_hw_addr_filt filt;
  123. might_sleep();
  124. if (!local->ops->set_hw_addr_filt) {
  125. WARN_ON(1);
  126. return -EOPNOTSUPP;
  127. }
  128. filt.pan_coord = is_coord;
  129. return local->ops->set_hw_addr_filt(&local->hw, &filt,
  130. IEEE802154_AFILT_PANC_CHANGED);
  131. }
  132. static inline int
  133. drv_set_csma_params(struct ieee802154_local *local, u8 min_be, u8 max_be,
  134. u8 max_csma_backoffs)
  135. {
  136. might_sleep();
  137. if (!local->ops->set_csma_params) {
  138. WARN_ON(1);
  139. return -EOPNOTSUPP;
  140. }
  141. return local->ops->set_csma_params(&local->hw, min_be, max_be,
  142. max_csma_backoffs);
  143. }
  144. static inline int
  145. drv_set_max_frame_retries(struct ieee802154_local *local, s8 max_frame_retries)
  146. {
  147. might_sleep();
  148. if (!local->ops->set_frame_retries) {
  149. WARN_ON(1);
  150. return -EOPNOTSUPP;
  151. }
  152. return local->ops->set_frame_retries(&local->hw, max_frame_retries);
  153. }
  154. static inline int
  155. drv_set_promiscuous_mode(struct ieee802154_local *local, bool on)
  156. {
  157. might_sleep();
  158. if (!local->ops->set_promiscuous_mode) {
  159. WARN_ON(1);
  160. return -EOPNOTSUPP;
  161. }
  162. return local->ops->set_promiscuous_mode(&local->hw, on);
  163. }
  164. #endif /* __MAC802154_DRIVER_OPS */