qdf_lock.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. /*
  2. * Copyright (c) 2014-2021 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. * @file qdf_lock.h
  21. * This file abstracts locking operations.
  22. */
  23. #ifndef _QDF_LOCK_H
  24. #define _QDF_LOCK_H
  25. #include <qdf_types.h>
  26. #include <qdf_mem.h>
  27. #include <qdf_time.h>
  28. #include <i_qdf_trace.h>
  29. #ifndef QDF_LOCK_STATS
  30. #define QDF_LOCK_STATS 0
  31. #endif
  32. #ifndef QDF_LOCK_STATS_DESTROY_PRINT
  33. #define QDF_LOCK_STATS_DESTROY_PRINT 0
  34. #endif
  35. #ifndef QDF_LOCK_STATS_BUG_ON
  36. #define QDF_LOCK_STATS_BUG_ON 0
  37. #endif
  38. #ifndef QDF_LOCK_STATS_LIST
  39. #define QDF_LOCK_STATS_LIST 0
  40. #endif
  41. /* Max hold time in micro seconds, 0 to disable detection*/
  42. #define QDF_MAX_HOLD_TIME_ALOWED_SPINLOCK_IRQ 10000
  43. #define QDF_MAX_HOLD_TIME_ALOWED_SPINLOCK 0
  44. #if QDF_LOCK_STATS
  45. #define QDF_MAX_HOLD_TIME_ALOWED_SPINLOCK_BH 2000000
  46. #else
  47. #define QDF_MAX_HOLD_TIME_ALOWED_SPINLOCK_BH 1000000
  48. #endif
  49. #if !QDF_LOCK_STATS
  50. struct lock_stats {};
  51. #define BEFORE_LOCK(x...) do {} while (0)
  52. #define AFTER_LOCK(x...) do {} while (0)
  53. #define BEFORE_TRYLOCK(x...) do {} while (0)
  54. #define AFTER_TRYLOCK(x...) do {} while (0)
  55. #define BEFORE_UNLOCK(x...) do {} while (0)
  56. #define qdf_lock_stats_create(x...) do {} while (0)
  57. #define qdf_lock_stats_destroy(x...) do {} while (0)
  58. #define qdf_lock_stats_init(x...) do {} while (0)
  59. #define qdf_lock_stats_deinit(x...) do {} while (0)
  60. #else
  61. void qdf_lock_stats_init(void);
  62. void qdf_lock_stats_deinit(void);
  63. struct qdf_lock_cookie;
  64. struct lock_stats {
  65. const char *initialization_fn;
  66. const char *acquired_by;
  67. int line;
  68. int acquired;
  69. int contended;
  70. uint64_t contention_time;
  71. uint64_t non_contention_time;
  72. uint64_t held_time;
  73. uint64_t last_acquired;
  74. uint64_t max_contention_wait;
  75. uint64_t max_held_time;
  76. int num_large_contentions;
  77. int num_large_holds;
  78. struct qdf_lock_cookie *cookie;
  79. };
  80. #define LARGE_CONTENTION QDF_LOG_TIMESTAMP_CYCLES_PER_10_US
  81. #define BEFORE_LOCK(lock, was_locked) \
  82. do { \
  83. uint64_t BEFORE_LOCK_time; \
  84. uint64_t AFTER_LOCK_time; \
  85. bool BEFORE_LOCK_is_locked = was_locked; \
  86. BEFORE_LOCK_time = qdf_get_log_timestamp_lightweight(); \
  87. do {} while (0)
  88. #define AFTER_LOCK(lock, func) \
  89. lock->stats.acquired_by = func; \
  90. AFTER_LOCK_time = qdf_get_log_timestamp_lightweight(); \
  91. lock->stats.acquired++; \
  92. lock->stats.last_acquired = AFTER_LOCK_time; \
  93. if (BEFORE_LOCK_is_locked) { \
  94. lock->stats.contended++; \
  95. lock->stats.contention_time += \
  96. (AFTER_LOCK_time - BEFORE_LOCK_time); \
  97. } else { \
  98. lock->stats.non_contention_time += \
  99. (AFTER_LOCK_time - BEFORE_LOCK_time); \
  100. } \
  101. \
  102. if (AFTER_LOCK_time - BEFORE_LOCK_time > LARGE_CONTENTION) \
  103. lock->stats.num_large_contentions++; \
  104. \
  105. if (AFTER_LOCK_time - BEFORE_LOCK_time > \
  106. lock->stats.max_contention_wait) \
  107. lock->stats.max_contention_wait = \
  108. AFTER_LOCK_time - BEFORE_LOCK_time; \
  109. } while (0)
  110. #define BEFORE_TRYLOCK(lock) \
  111. do { \
  112. uint64_t BEFORE_LOCK_time; \
  113. uint64_t AFTER_LOCK_time; \
  114. BEFORE_LOCK_time = qdf_get_log_timestamp_lightweight(); \
  115. do {} while (0)
  116. #define AFTER_TRYLOCK(lock, trylock_return, func) \
  117. AFTER_LOCK_time = qdf_get_log_timestamp_lightweight(); \
  118. if (trylock_return) { \
  119. lock->stats.acquired++; \
  120. lock->stats.last_acquired = AFTER_LOCK_time; \
  121. lock->stats.non_contention_time += \
  122. (AFTER_LOCK_time - BEFORE_LOCK_time); \
  123. lock->stats.acquired_by = func; \
  124. } \
  125. } while (0)
  126. /* max_hold_time in US */
  127. #define BEFORE_UNLOCK(lock, max_hold_time) \
  128. do {\
  129. uint64_t BEFORE_UNLOCK_time; \
  130. uint64_t held_time; \
  131. BEFORE_UNLOCK_time = qdf_get_log_timestamp_lightweight(); \
  132. \
  133. if (unlikely(BEFORE_UNLOCK_time < lock->stats.last_acquired)) \
  134. held_time = 0; \
  135. else \
  136. held_time = BEFORE_UNLOCK_time - lock->stats.last_acquired; \
  137. \
  138. lock->stats.held_time += held_time; \
  139. \
  140. if (held_time > lock->stats.max_held_time) \
  141. lock->stats.max_held_time = held_time; \
  142. \
  143. if (held_time > LARGE_CONTENTION) \
  144. lock->stats.num_large_holds++; \
  145. if (QDF_LOCK_STATS_BUG_ON && max_hold_time && \
  146. held_time > qdf_usecs_to_log_timestamp(max_hold_time)) { \
  147. QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR, \
  148. "BEFORE_UNLOCK: lock held too long (%lluus)", \
  149. qdf_log_timestamp_to_usecs(held_time)); \
  150. QDF_BUG(0); \
  151. } \
  152. lock->stats.acquired_by = NULL; \
  153. } while (0)
  154. void qdf_lock_stats_cookie_destroy(struct lock_stats *stats);
  155. void qdf_lock_stats_cookie_create(struct lock_stats *stats,
  156. const char *func, int line);
  157. static inline void qdf_lock_stats_destroy(struct lock_stats *stats)
  158. {
  159. if (QDF_LOCK_STATS_DESTROY_PRINT) {
  160. QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_DEBUG,
  161. "%s: lock: %s %d \t"
  162. "acquired:\t%d\tcontended:\t%d\t"
  163. "contention_time\t%llu\tmax_contention_wait:\t%llu\t"
  164. "non_contention_time\t%llu\t"
  165. "held_time\t%llu\tmax_held:\t%llu"
  166. , __func__, stats->initialization_fn, stats->line,
  167. stats->acquired, stats->contended,
  168. qdf_log_timestamp_to_usecs(stats->contention_time),
  169. qdf_log_timestamp_to_usecs(stats->max_contention_wait),
  170. qdf_log_timestamp_to_usecs(stats->non_contention_time),
  171. qdf_log_timestamp_to_usecs(stats->held_time),
  172. qdf_log_timestamp_to_usecs(stats->max_held_time));
  173. }
  174. if (QDF_LOCK_STATS_LIST)
  175. qdf_lock_stats_cookie_destroy(stats);
  176. }
  177. #ifndef MEMORY_DEBUG
  178. #define qdf_mem_malloc_debug(x, y, z) qdf_mem_malloc(x)
  179. #endif
  180. /* qdf_lock_stats_create() - initialize the lock stats structure
  181. *
  182. */
  183. static inline void qdf_lock_stats_create(struct lock_stats *stats,
  184. const char *func, int line)
  185. {
  186. qdf_mem_zero(stats, sizeof(*stats));
  187. stats->initialization_fn = func;
  188. stats->line = line;
  189. if (QDF_LOCK_STATS_LIST)
  190. qdf_lock_stats_cookie_create(stats, func, line);
  191. }
  192. #endif
  193. #include <i_qdf_lock.h>
  194. #define WIFI_POWER_EVENT_DEFAULT_WAKELOCK_TIMEOUT 0
  195. #define WIFI_POWER_EVENT_WAKELOCK_TAKEN 0
  196. #define WIFI_POWER_EVENT_WAKELOCK_RELEASED 1
  197. /**
  198. * qdf_semaphore_acquire_timeout() - Take the semaphore before timeout
  199. * @m: semaphore to take
  200. * @timeout: maximum time to try to take the semaphore
  201. * Return: int
  202. */
  203. static inline int qdf_semaphore_acquire_timeout(struct semaphore *m,
  204. unsigned long timeout)
  205. {
  206. return __qdf_semaphore_acquire_timeout(m, timeout);
  207. }
  208. struct qdf_spinlock {
  209. __qdf_spinlock_t lock;
  210. struct lock_stats stats;
  211. };
  212. /**
  213. * @brief Platform spinlock object
  214. */
  215. typedef struct qdf_spinlock qdf_spinlock_t;
  216. /**
  217. * @brief Platform mutex object
  218. */
  219. typedef __qdf_semaphore_t qdf_semaphore_t;
  220. typedef __qdf_mutex_t qdf_mutex_t;
  221. /* function Declaration */
  222. QDF_STATUS qdf_mutex_create(qdf_mutex_t *m, const char *func, int line);
  223. #define qdf_mutex_create(m) qdf_mutex_create(m, __func__, __LINE__)
  224. QDF_STATUS qdf_mutex_acquire(qdf_mutex_t *m);
  225. QDF_STATUS qdf_mutex_release(qdf_mutex_t *m);
  226. QDF_STATUS qdf_mutex_destroy(qdf_mutex_t *lock);
  227. /**
  228. * qdf_spinlock_create - Initialize a spinlock
  229. * @lock: spinlock object pointer
  230. * Return: none
  231. */
  232. static inline void qdf_spinlock_create(qdf_spinlock_t *lock, const char *func,
  233. int line)
  234. {
  235. __qdf_spinlock_create(&lock->lock);
  236. /* spinlock stats create relies on the spinlock working allread */
  237. qdf_lock_stats_create(&lock->stats, func, line);
  238. }
  239. #define qdf_spinlock_create(x) qdf_spinlock_create(x, __func__, __LINE__)
  240. /**
  241. * qdf_spinlock_destroy - Delete a spinlock
  242. * @lock: spinlock object pointer
  243. * Return: none
  244. */
  245. static inline void qdf_spinlock_destroy(qdf_spinlock_t *lock)
  246. {
  247. qdf_lock_stats_destroy(&lock->stats);
  248. __qdf_spinlock_destroy(&lock->lock);
  249. }
  250. /**
  251. * qdf_spin_is_locked() - check if the spinlock is locked
  252. * @lock: spinlock object
  253. *
  254. * Return: nonzero if lock is held.
  255. */
  256. static inline int qdf_spin_is_locked(qdf_spinlock_t *lock)
  257. {
  258. return __qdf_spin_is_locked(&lock->lock);
  259. }
  260. /**
  261. * qdf_spin_trylock_bh() - spin trylock bottomhalf
  262. * @lock: spinlock object
  263. *
  264. * Return: nonzero if lock is acquired
  265. */
  266. static inline int qdf_spin_trylock_bh(qdf_spinlock_t *lock, const char *func)
  267. {
  268. int trylock_return;
  269. BEFORE_TRYLOCK(lock);
  270. trylock_return = __qdf_spin_trylock_bh(&lock->lock);
  271. AFTER_TRYLOCK(lock, trylock_return, func);
  272. return trylock_return;
  273. }
  274. #define qdf_spin_trylock_bh(lock) qdf_spin_trylock_bh(lock, __func__)
  275. /**
  276. * qdf_spin_trylock() - spin trylock
  277. * @lock: spinlock object
  278. * Return: int
  279. */
  280. static inline int qdf_spin_trylock(qdf_spinlock_t *lock, const char *func)
  281. {
  282. int result = 0;
  283. BEFORE_LOCK(lock, qdf_spin_is_locked(lock));
  284. result = __qdf_spin_trylock(&lock->lock);
  285. AFTER_LOCK(lock, func);
  286. return result;
  287. }
  288. #define qdf_spin_trylock(lock) qdf_spin_trylock(lock, __func__)
  289. /**
  290. * qdf_spin_lock_bh() - locks the spinlock mutex in soft irq context
  291. * @lock: spinlock object pointer
  292. * Return: none
  293. */
  294. static inline void qdf_spin_lock_bh(qdf_spinlock_t *lock, const char *func)
  295. {
  296. BEFORE_LOCK(lock, qdf_spin_is_locked(lock));
  297. __qdf_spin_lock_bh(&lock->lock);
  298. AFTER_LOCK(lock, func);
  299. }
  300. #define qdf_spin_lock_bh(lock) qdf_spin_lock_bh(lock, __func__)
  301. /**
  302. * qdf_spin_unlock_bh() - unlocks the spinlock mutex in soft irq context
  303. * @lock: spinlock object pointer
  304. * Return: none
  305. */
  306. static inline void qdf_spin_unlock_bh(qdf_spinlock_t *lock)
  307. {
  308. BEFORE_UNLOCK(lock, QDF_MAX_HOLD_TIME_ALOWED_SPINLOCK_BH);
  309. __qdf_spin_unlock_bh(&lock->lock);
  310. }
  311. /**
  312. * qdf_spinlock_irq_exec - Execute the input function with spinlock held
  313. * and interrupt disabled.
  314. * @hdl: OS handle
  315. * @lock: spinlock to be held for the critical region
  316. * @func: critical region function that to be executed
  317. * @context: context of the critical region function
  318. * Return: Boolean status returned by the critical region function
  319. */
  320. static inline bool qdf_spinlock_irq_exec(qdf_handle_t hdl,
  321. qdf_spinlock_t *lock,
  322. qdf_irqlocked_func_t func, void *arg)
  323. {
  324. return __qdf_spinlock_irq_exec(hdl, &lock->lock, func, arg);
  325. }
  326. /**
  327. * qdf_spin_lock() - Acquire a Spinlock(SMP) & disable Preemption (Preemptive)
  328. * @lock: Lock object
  329. *
  330. * Return: none
  331. */
  332. static inline void qdf_spin_lock(qdf_spinlock_t *lock, const char *func)
  333. {
  334. BEFORE_LOCK(lock, qdf_spin_is_locked(lock));
  335. __qdf_spin_lock(&lock->lock);
  336. AFTER_LOCK(lock, func);
  337. }
  338. #define qdf_spin_lock(lock) qdf_spin_lock(lock, __func__)
  339. /**
  340. * qdf_spin_unlock() - Unlock the spinlock and enables the Preemption
  341. * @lock: Lock object
  342. *
  343. * Return: none
  344. */
  345. static inline void qdf_spin_unlock(qdf_spinlock_t *lock)
  346. {
  347. BEFORE_UNLOCK(lock, QDF_MAX_HOLD_TIME_ALOWED_SPINLOCK);
  348. __qdf_spin_unlock(&lock->lock);
  349. }
  350. /**
  351. * qdf_spin_lock_irq() - Acquire a Spinlock(SMP) & save the irq state
  352. * @lock: Lock object
  353. * @flags: flags
  354. *
  355. * Return: none
  356. */
  357. static inline void qdf_spin_lock_irq(qdf_spinlock_t *lock, unsigned long flags,
  358. const char *func)
  359. {
  360. BEFORE_LOCK(lock, qdf_spin_is_locked(lock));
  361. __qdf_spin_lock_irq(&lock->lock.spinlock, flags);
  362. AFTER_LOCK(lock, func);
  363. }
  364. #define qdf_spin_lock_irq(lock, flags) qdf_spin_lock_irq(lock, flags, __func__)
  365. /**
  366. * qdf_spin_lock_irqsave() - Acquire a Spinlock (SMP) & disable Preemption
  367. * (Preemptive) and disable IRQs
  368. * @lock: Lock object
  369. *
  370. * Return: none
  371. */
  372. static inline void qdf_spin_lock_irqsave(qdf_spinlock_t *lock, const char *func)
  373. {
  374. BEFORE_LOCK(lock, qdf_spin_is_locked(lock));
  375. __qdf_spin_lock_irqsave(&lock->lock);
  376. AFTER_LOCK(lock, func);
  377. }
  378. #define qdf_spin_lock_irqsave(lock) qdf_spin_lock_irqsave(lock, __func__)
  379. /**
  380. * qdf_spin_unlock_irqrestore() - Unlock the spinlock and enables the
  381. * Preemption and enable IRQ
  382. * @lock: Lock object
  383. *
  384. * Return: none
  385. */
  386. static inline void qdf_spin_unlock_irqrestore(qdf_spinlock_t *lock)
  387. {
  388. BEFORE_UNLOCK(lock, QDF_MAX_HOLD_TIME_ALOWED_SPINLOCK_IRQ);
  389. __qdf_spin_unlock_irqrestore(&lock->lock);
  390. }
  391. /**
  392. * qdf_spin_unlock_irq() - Unlock a Spinlock(SMP) & save the restore state
  393. * @lock: Lock object
  394. * @flags: flags
  395. *
  396. * Return: none
  397. */
  398. static inline void qdf_spin_unlock_irq(qdf_spinlock_t *lock,
  399. unsigned long flags)
  400. {
  401. BEFORE_UNLOCK(lock, QDF_MAX_HOLD_TIME_ALOWED_SPINLOCK_IRQ);
  402. __qdf_spin_unlock_irq(&lock->lock.spinlock, flags);
  403. }
  404. /**
  405. * qdf_semaphore_init() - initialize a semaphore
  406. * @m: Semaphore to initialize
  407. * Return: None
  408. */
  409. static inline void qdf_semaphore_init(qdf_semaphore_t *m)
  410. {
  411. __qdf_semaphore_init(m);
  412. }
  413. /**
  414. * qdf_semaphore_acquire() - take the semaphore
  415. * @m: Semaphore to take
  416. * Return: int
  417. */
  418. static inline int qdf_semaphore_acquire(qdf_semaphore_t *m)
  419. {
  420. return __qdf_semaphore_acquire(m);
  421. }
  422. /**
  423. * qdf_semaphore_release() - give the semaphore
  424. * @m: Semaphore to give
  425. * Return: None
  426. */
  427. static inline void qdf_semaphore_release(qdf_semaphore_t *m)
  428. {
  429. __qdf_semaphore_release(m);
  430. }
  431. /**
  432. * qdf_semaphore_acquire_intr - Take the semaphore, interruptible version
  433. * @osdev: OS Device
  434. * @m: mutex to take
  435. * Return: int
  436. */
  437. static inline int qdf_semaphore_acquire_intr(qdf_semaphore_t *m)
  438. {
  439. return __qdf_semaphore_acquire_intr(m);
  440. }
  441. #ifdef WLAN_WAKE_LOCK_DEBUG
  442. /**
  443. * qdf_wake_lock_check_for_leaks() - assert no wake lock leaks
  444. *
  445. * Return: None
  446. */
  447. void qdf_wake_lock_check_for_leaks(void);
  448. /**
  449. * qdf_wake_lock_feature_init() - global init logic for wake lock
  450. *
  451. * Return: None
  452. */
  453. void qdf_wake_lock_feature_init(void);
  454. /**
  455. * qdf_wake_lock_feature_deinit() - global de-init logic for wake lock
  456. *
  457. * Return: None
  458. */
  459. void qdf_wake_lock_feature_deinit(void);
  460. #else
  461. static inline void qdf_wake_lock_check_for_leaks(void) { }
  462. static inline void qdf_wake_lock_feature_init(void) { }
  463. static inline void qdf_wake_lock_feature_deinit(void) { }
  464. #endif /* WLAN_WAKE_LOCK_DEBUG */
  465. /**
  466. * __qdf_wake_lock_create() - initialize a wake lock
  467. * @lock: The wake lock to initialize
  468. * @name: Name of wake lock
  469. * @func: caller function
  470. * @line: caller line
  471. * Return:
  472. * QDF status success: if wake lock is initialized
  473. * QDF status failure: if wake lock was not initialized
  474. */
  475. QDF_STATUS __qdf_wake_lock_create(qdf_wake_lock_t *lock, const char *name,
  476. const char *func, uint32_t line);
  477. /**
  478. * qdf_wake_lock_create() - initialized a wakeup source lock
  479. * @lock: the wakeup source lock to initialize
  480. * @name: the name of wakeup source lock
  481. *
  482. * Return: QDF_STATUS
  483. */
  484. #define qdf_wake_lock_create(lock, name) \
  485. __qdf_wake_lock_create(lock, name, __func__, __LINE__)
  486. QDF_STATUS qdf_wake_lock_acquire(qdf_wake_lock_t *lock, uint32_t reason);
  487. const char *qdf_wake_lock_name(qdf_wake_lock_t *lock);
  488. QDF_STATUS qdf_wake_lock_timeout_acquire(qdf_wake_lock_t *lock,
  489. uint32_t msec);
  490. QDF_STATUS qdf_wake_lock_release(qdf_wake_lock_t *lock, uint32_t reason);
  491. /**
  492. * __qdf_wake_lock_destroy() - destroy a wake lock
  493. * @lock: The wake lock to destroy
  494. * @func: caller function
  495. * @line: caller line
  496. *
  497. * Return: None
  498. */
  499. void __qdf_wake_lock_destroy(qdf_wake_lock_t *lock,
  500. const char *func, uint32_t line);
  501. /**
  502. * qdf_wake_lock_destroy() - deinitialize a wakeup source lock
  503. * @lock: the wakeup source lock to de-initialize
  504. *
  505. * Return: None
  506. */
  507. #define qdf_wake_lock_destroy(lock) \
  508. __qdf_wake_lock_destroy(lock, __func__, __LINE__)
  509. void qdf_pm_system_wakeup(void);
  510. QDF_STATUS qdf_spinlock_acquire(qdf_spinlock_t *lock);
  511. QDF_STATUS qdf_spinlock_release(qdf_spinlock_t *lock);
  512. /**
  513. * enum qdf_rtpm_type - Get and Put calls types
  514. * @QDF_RTPM_GET: Increment usage count and when system is suspended
  515. * schedule resume process, return depends on pm state.
  516. * @QDF_RTPM_GET_FORCE: Increment usage count and when system is suspended
  517. * shedule resume process, returns success irrespective of
  518. * pm_state.
  519. * @QDF_RTPM_GET_SYNC: Increment usage count and when system is suspended,
  520. * wait till process is resumed.
  521. * @QDF_RTPM_GET_NORESUME: Only increments usage count.
  522. * @QDF_RTPM_PUT: Decrements usage count and puts system in idle state.
  523. * @QDF_RTPM_PUT_SYNC_SUSPEND: Decrements usage count and puts system in
  524. * suspended state.
  525. * @QDF_RTPM_PUT_NOIDLE: Decrements usage count.
  526. */
  527. enum qdf_rtpm_call_type {
  528. QDF_RTPM_GET,
  529. QDF_RTPM_GET_FORCE,
  530. QDF_RTPM_GET_SYNC,
  531. QDF_RTPM_GET_NORESUME,
  532. QDF_RTPM_PUT,
  533. QDF_RTPM_PUT_SYNC_SUSPEND,
  534. QDF_RTPM_PUT_NOIDLE,
  535. };
  536. /**
  537. * enum qdf_rtpm_client_id - modules registered with runtime pm module
  538. * @QDF_RTPM_ID_RESERVED: Reserved ID
  539. * @QDF_RTPM_ID_PM_QOS_NOTIFY: PM QOS context
  540. * @QDF_RTPM_ID_BUS_SUSPEND: APSS Bus suspend context
  541. * @QDF_RTPM_ID_MAX: Max id
  542. */
  543. enum qdf_rtpm_client_id {
  544. QDF_RTPM_ID_RESERVED,
  545. QDF_RTPM_ID_PM_QOS_NOTIFY,
  546. QDF_RTPM_ID_WIPHY_SUSPEND,
  547. QDF_RTPM_ID_MAX
  548. };
  549. #define qdf_runtime_lock_init(lock) __qdf_runtime_lock_init(lock, #lock)
  550. #ifdef FEATURE_RUNTIME_PM
  551. /**
  552. * qdf_rtpm_register() - QDF wrapper to register a module with runtime PM.
  553. * @id: ID of the module which needs to be registered
  554. * @hif_rpm_cbk: callback to be called when get was called in suspended state.
  555. * @prevent_multiple_get: not allow simultaneous get calls or put calls
  556. *
  557. * Return: success status if registered
  558. */
  559. QDF_STATUS qdf_rtpm_register(uint32_t id, void (*hif_rpm_cbk)(void));
  560. /**
  561. * qdf_rtpm_deregister() - QDF wrapper to deregister the module
  562. * @id: ID of the module which needs to be de-registered
  563. *
  564. * Return: success status if successfully de-registered
  565. */
  566. QDF_STATUS qdf_rtpm_deregister(uint32_t id);
  567. /**
  568. * qdf_runtime_lock_init() - initialize runtime lock
  569. * @name: name of the runtime lock
  570. *
  571. * Initialize a runtime pm lock. This lock can be used
  572. * to prevent the runtime pm system from putting the bus
  573. * to sleep.
  574. *
  575. * Return: Success if lock initialized
  576. */
  577. QDF_STATUS __qdf_runtime_lock_init(qdf_runtime_lock_t *lock, const char *name);
  578. /**
  579. * qdf_runtime_lock_deinit() - deinitialize runtime pm lock
  580. * @lock: the lock to deinitialize
  581. *
  582. * Ensures the lock is released. Frees the runtime lock.
  583. *
  584. * Return: void
  585. */
  586. void qdf_runtime_lock_deinit(qdf_runtime_lock_t *lock);
  587. /**
  588. * qdf_rtpm_get() - Incremeant usage_count on the device to avoid suspend.
  589. * @type: get call types from hif_rpm_type
  590. * @id: ID of the module calling get()
  591. *
  592. * Return: success if a get has been issued, else error code.
  593. */
  594. QDF_STATUS qdf_rtpm_get(uint8_t type, uint32_t id);
  595. /**
  596. * qdf_rtpm_put() - Decremeant usage_count on the device to avoid suspend.
  597. * @type: put call types from hif_rpm_type
  598. * @id: ID of the module calling put()
  599. *
  600. * Return: success if a put has been issued, else error code.
  601. */
  602. QDF_STATUS qdf_rtpm_put(uint8_t type, uint32_t id);
  603. /**
  604. * qdf_runtime_pm_allow_suspend() - Prevent Runtime suspend
  605. * @data: runtime PM lock
  606. *
  607. * This function will prevent runtime suspend, by incrementing
  608. * device's usage count.
  609. *
  610. * Return: status
  611. */
  612. QDF_STATUS qdf_runtime_pm_prevent_suspend(qdf_runtime_lock_t *lock);
  613. /**
  614. * qdf_runtime_pm_allow_suspend() - Allow Runtime suspend
  615. * @data: runtime PM lock
  616. *
  617. * This function will allow runtime suspend, by decrementing
  618. * device's usage count.
  619. *
  620. * Return: status
  621. */
  622. QDF_STATUS qdf_runtime_pm_allow_suspend(qdf_runtime_lock_t *lock);
  623. /**
  624. * qdf_pm_runtime_sync_resume() - Invoke synchronous runtime resume.
  625. *
  626. * This function will invoke synchronous runtime resume.
  627. *
  628. * Return: Success if state is ON
  629. */
  630. QDF_STATUS qdf_rtpm_sync_resume(void);
  631. #else
  632. static inline
  633. QDF_STATUS qdf_rtpm_register(uint32_t id, void (*hif_rpm_cbk)(void))
  634. {
  635. return 0;
  636. }
  637. static inline
  638. QDF_STATUS qdf_rtpm_deregister(uint32_t id)
  639. {
  640. return QDF_STATUS_SUCCESS;
  641. }
  642. static inline
  643. QDF_STATUS __qdf_runtime_lock_init(qdf_runtime_lock_t *lock, const char *name)
  644. {
  645. return QDF_STATUS_SUCCESS;
  646. }
  647. static inline
  648. void qdf_runtime_lock_deinit(qdf_runtime_lock_t *lock)
  649. {
  650. }
  651. static inline
  652. QDF_STATUS qdf_rtpm_get(uint8_t type, uint32_t id)
  653. {
  654. return QDF_STATUS_SUCCESS;
  655. }
  656. static inline
  657. QDF_STATUS qdf_rtpm_put(uint8_t type, uint32_t id)
  658. {
  659. return QDF_STATUS_SUCCESS;
  660. }
  661. static inline
  662. QDF_STATUS qdf_runtime_pm_prevent_suspend(qdf_runtime_lock_t *lock)
  663. {
  664. return QDF_STATUS_SUCCESS;
  665. }
  666. static inline
  667. QDF_STATUS qdf_runtime_pm_allow_suspend(qdf_runtime_lock_t *lock)
  668. {
  669. return QDF_STATUS_SUCCESS;
  670. }
  671. static inline
  672. QDF_STATUS qdf_rtpm_sync_resume(void)
  673. {
  674. return QDF_STATUS_SUCCESS;
  675. }
  676. #endif /* FEATURE_RUNTIME_PM */
  677. #endif /* _QDF_LOCK_H */