qdf_cpuhp.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Copyright (c) 2017 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. /**
  19. * DOC: qdf_cpuhp
  20. * This file provides OS dependent QDF CPU hotplug APIs
  21. */
  22. #include "i_qdf_cpuhp.h"
  23. #include "qdf_trace.h"
  24. #include "linux/cpu.h"
  25. #include "linux/notifier.h"
  26. #include "linux/version.h"
  27. #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0)
  28. #include "linux/cpuhotplug.h"
  29. #endif
  30. static __qdf_cpuhp_emit __qdf_cpuhp_on_up;
  31. static __qdf_cpuhp_emit __qdf_cpuhp_on_down;
  32. #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 6, 0)
  33. static int qdf_cpuhp_legacy_handler(struct notifier_block *block,
  34. unsigned long state,
  35. void *hcpu)
  36. {
  37. unsigned long cpu = (unsigned long)hcpu;
  38. switch (state) {
  39. case CPU_ONLINE:
  40. __qdf_cpuhp_on_up(cpu);
  41. break;
  42. case CPU_DOWN_PREPARE:
  43. case CPU_DOWN_PREPARE_FROZEN:
  44. __qdf_cpuhp_on_down(cpu);
  45. break;
  46. default:
  47. break;
  48. }
  49. return NOTIFY_OK;
  50. }
  51. static struct notifier_block qdf_cpuhp_notifier_block = {
  52. .notifier_call = qdf_cpuhp_legacy_handler,
  53. };
  54. static inline void qdf_cpuhp_register_callbacks(void)
  55. {
  56. register_hotcpu_notifier(&qdf_cpuhp_notifier_block);
  57. }
  58. static inline void qdf_cpuhp_unregister_callbacks(void)
  59. {
  60. unregister_hotcpu_notifier(&qdf_cpuhp_notifier_block);
  61. }
  62. #else
  63. static enum cpuhp_state registered_hotplug_state;
  64. static int qdf_cpuhp_up_handler(unsigned int cpu)
  65. {
  66. __qdf_cpuhp_on_up(cpu);
  67. return 0;
  68. }
  69. static int qdf_cpuhp_down_handler(unsigned int cpu)
  70. {
  71. __qdf_cpuhp_on_down(cpu);
  72. return 0;
  73. }
  74. static inline void qdf_cpuhp_register_callbacks(void)
  75. {
  76. registered_hotplug_state = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
  77. "wlan/qca-qdf:online",
  78. qdf_cpuhp_up_handler,
  79. qdf_cpuhp_down_handler);
  80. }
  81. static inline void qdf_cpuhp_unregister_callbacks(void)
  82. {
  83. QDF_BUG(registered_hotplug_state);
  84. if (registered_hotplug_state)
  85. cpuhp_remove_state(registered_hotplug_state);
  86. }
  87. #endif /* KERNEL_VERSION(4, 6, 0) */
  88. void __qdf_cpuhp_os_init(__qdf_cpuhp_emit on_up, __qdf_cpuhp_emit on_down)
  89. {
  90. __qdf_cpuhp_on_up = on_up;
  91. __qdf_cpuhp_on_down = on_down;
  92. qdf_cpuhp_register_callbacks();
  93. }
  94. void __qdf_cpuhp_os_deinit(void)
  95. {
  96. qdf_cpuhp_unregister_callbacks();
  97. }