qdf_periodic_work.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Copyright (c) 2019 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for
  6. * any purpose with or without fee is hereby granted, provided that the
  7. * above copyright notice and this permission notice appear in all
  8. * copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  11. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  12. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  13. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  14. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  15. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  16. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  17. * PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. /**
  20. * DOC: qdf_periodic_work.h
  21. * A simple, periodic work type for repeatedly executing a callback with a
  22. * certain frequency.
  23. */
  24. #ifndef __QDF_PERIODIC_WORK_H
  25. #define __QDF_PERIODIC_WORK_H
  26. #include "i_qdf_periodic_work.h"
  27. #include "qdf_status.h"
  28. #include "qdf_types.h"
  29. typedef void (*qdf_periodic_work_cb)(void *context);
  30. /**
  31. * struct qdf_periodic_work - a deferred work type which executes a callback
  32. * periodically until stopped
  33. * @dwork: OS-specific delayed work
  34. * @callback: the callback to be executed periodically
  35. * @context: the context to pass to the callback
  36. * @msec: the delay between executions in milliseconds
  37. */
  38. struct qdf_periodic_work {
  39. struct __qdf_opaque_delayed_work dwork;
  40. qdf_periodic_work_cb callback;
  41. void *context;
  42. uint32_t msec;
  43. };
  44. /**
  45. * qdf_periodic_work_create() - initialized a periodic work @pwork
  46. * @pwork: the periodic work to initialize
  47. * @callback: the callback to be executed periodically
  48. * @context: the context to pass to the callback
  49. *
  50. * Return: QDF_STATUS
  51. */
  52. #define qdf_periodic_work_create(pwork, callback, context) \
  53. __qdf_periodic_work_create(pwork, callback, context, __func__, __LINE__)
  54. qdf_must_check QDF_STATUS
  55. __qdf_periodic_work_create(struct qdf_periodic_work *pwork,
  56. qdf_periodic_work_cb callback, void *context,
  57. const char *func, uint32_t line);
  58. /**
  59. * qdf_periodic_work_destroy() - deinitialize a periodic work @pwork
  60. * @pwork: the periodic work to de-initialize
  61. *
  62. * Return: None
  63. */
  64. #define qdf_periodic_work_destroy(pwork) \
  65. __qdf_periodic_work_destroy(pwork, __func__, __LINE__)
  66. void __qdf_periodic_work_destroy(struct qdf_periodic_work *pwork,
  67. const char *func, uint32_t line);
  68. /**
  69. * qdf_periodic_work_start() - begin periodic execution of @pwork callback
  70. * @pwork: the periodic work to start
  71. * @msec: the delay between executions in milliseconds
  72. *
  73. * Return: true if started successfully
  74. */
  75. bool qdf_periodic_work_start(struct qdf_periodic_work *pwork, uint32_t msec);
  76. /**
  77. * qdf_periodic_work_stop_async() - Asynchronously stop execution of @pwork
  78. * @pwork: the periodic work to stop
  79. *
  80. * When this returns, @pwork is guaranteed to not be queued, *but* its callback
  81. * may still be executing.
  82. *
  83. * This is safe to call from the @pwork callback.
  84. *
  85. * Return: true if @pwork was previously started
  86. */
  87. bool qdf_periodic_work_stop_async(struct qdf_periodic_work *pwork);
  88. /**
  89. * qdf_periodic_work_stop_sync() - Synchronously stop execution of @pwork
  90. * @pwork: the periodic work to stop
  91. *
  92. * When this returns, @pwork is guaranteed to not be queued, and its callback
  93. * not executing.
  94. *
  95. * This will deadlock if called from the @pwork callback.
  96. *
  97. * Return: true if @pwork was previously started
  98. */
  99. bool qdf_periodic_work_stop_sync(struct qdf_periodic_work *pwork);
  100. #ifdef WLAN_PERIODIC_WORK_DEBUG
  101. /**
  102. * qdf_periodic_work_check_for_leaks() - assert no periodic work leaks
  103. *
  104. * Return: None
  105. */
  106. void qdf_periodic_work_check_for_leaks(void);
  107. /**
  108. * qdf_periodic_work_feature_init() - global init logic for periodic work
  109. *
  110. * Return: None
  111. */
  112. void qdf_periodic_work_feature_init(void);
  113. /**
  114. * qdf_periodic_work_feature_deinit() - global de-init logic for periodic work
  115. *
  116. * Return: None
  117. */
  118. void qdf_periodic_work_feature_deinit(void);
  119. #else
  120. static inline void qdf_periodic_work_check_for_leaks(void) { }
  121. static inline void qdf_periodic_work_feature_init(void) { }
  122. static inline void qdf_periodic_work_feature_deinit(void) { }
  123. #endif /* WLAN_PERIODIC_WORK_DEBUG */
  124. #endif /* __QDF_PERIODIC_WORK_H */