recovery.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Copyright (c) 2012 Qualcomm Atheros, Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include "core.h"
  17. #include "cfg80211.h"
  18. #include "debug.h"
  19. static void ath6kl_recovery_work(struct work_struct *work)
  20. {
  21. struct ath6kl *ar = container_of(work, struct ath6kl,
  22. fw_recovery.recovery_work);
  23. ar->state = ATH6KL_STATE_RECOVERY;
  24. del_timer_sync(&ar->fw_recovery.hb_timer);
  25. ath6kl_init_hw_restart(ar);
  26. ar->state = ATH6KL_STATE_ON;
  27. clear_bit(WMI_CTRL_EP_FULL, &ar->flag);
  28. ar->fw_recovery.err_reason = 0;
  29. if (ar->fw_recovery.hb_poll)
  30. mod_timer(&ar->fw_recovery.hb_timer, jiffies +
  31. msecs_to_jiffies(ar->fw_recovery.hb_poll));
  32. }
  33. void ath6kl_recovery_err_notify(struct ath6kl *ar, enum ath6kl_fw_err reason)
  34. {
  35. if (!ar->fw_recovery.enable)
  36. return;
  37. ath6kl_dbg(ATH6KL_DBG_RECOVERY, "Fw error detected, reason:%d\n",
  38. reason);
  39. set_bit(reason, &ar->fw_recovery.err_reason);
  40. if (!test_bit(RECOVERY_CLEANUP, &ar->flag) &&
  41. ar->state != ATH6KL_STATE_RECOVERY)
  42. queue_work(ar->ath6kl_wq, &ar->fw_recovery.recovery_work);
  43. }
  44. void ath6kl_recovery_hb_event(struct ath6kl *ar, u32 cookie)
  45. {
  46. if (cookie == ar->fw_recovery.seq_num)
  47. ar->fw_recovery.hb_pending = false;
  48. }
  49. static void ath6kl_recovery_hb_timer(struct timer_list *t)
  50. {
  51. struct ath6kl *ar = from_timer(ar, t, fw_recovery.hb_timer);
  52. int err;
  53. if (test_bit(RECOVERY_CLEANUP, &ar->flag) ||
  54. (ar->state == ATH6KL_STATE_RECOVERY))
  55. return;
  56. if (ar->fw_recovery.hb_pending)
  57. ar->fw_recovery.hb_misscnt++;
  58. else
  59. ar->fw_recovery.hb_misscnt = 0;
  60. if (ar->fw_recovery.hb_misscnt > ATH6KL_HB_RESP_MISS_THRES) {
  61. ar->fw_recovery.hb_misscnt = 0;
  62. ar->fw_recovery.seq_num = 0;
  63. ar->fw_recovery.hb_pending = false;
  64. ath6kl_recovery_err_notify(ar, ATH6KL_FW_HB_RESP_FAILURE);
  65. return;
  66. }
  67. ar->fw_recovery.seq_num++;
  68. ar->fw_recovery.hb_pending = true;
  69. err = ath6kl_wmi_get_challenge_resp_cmd(ar->wmi,
  70. ar->fw_recovery.seq_num, 0);
  71. if (err)
  72. ath6kl_warn("Failed to send hb challenge request, err:%d\n",
  73. err);
  74. mod_timer(&ar->fw_recovery.hb_timer, jiffies +
  75. msecs_to_jiffies(ar->fw_recovery.hb_poll));
  76. }
  77. void ath6kl_recovery_init(struct ath6kl *ar)
  78. {
  79. struct ath6kl_fw_recovery *recovery = &ar->fw_recovery;
  80. clear_bit(RECOVERY_CLEANUP, &ar->flag);
  81. INIT_WORK(&recovery->recovery_work, ath6kl_recovery_work);
  82. recovery->seq_num = 0;
  83. recovery->hb_misscnt = 0;
  84. ar->fw_recovery.hb_pending = false;
  85. timer_setup(&ar->fw_recovery.hb_timer, ath6kl_recovery_hb_timer,
  86. TIMER_DEFERRABLE);
  87. if (ar->fw_recovery.hb_poll)
  88. mod_timer(&ar->fw_recovery.hb_timer, jiffies +
  89. msecs_to_jiffies(ar->fw_recovery.hb_poll));
  90. }
  91. void ath6kl_recovery_cleanup(struct ath6kl *ar)
  92. {
  93. if (!ar->fw_recovery.enable)
  94. return;
  95. set_bit(RECOVERY_CLEANUP, &ar->flag);
  96. del_timer_sync(&ar->fw_recovery.hb_timer);
  97. cancel_work_sync(&ar->fw_recovery.recovery_work);
  98. }
  99. void ath6kl_recovery_suspend(struct ath6kl *ar)
  100. {
  101. if (!ar->fw_recovery.enable)
  102. return;
  103. ath6kl_recovery_cleanup(ar);
  104. if (!ar->fw_recovery.err_reason)
  105. return;
  106. /* Process pending fw error detection */
  107. ar->fw_recovery.err_reason = 0;
  108. WARN_ON(ar->state != ATH6KL_STATE_ON);
  109. ar->state = ATH6KL_STATE_RECOVERY;
  110. ath6kl_init_hw_restart(ar);
  111. ar->state = ATH6KL_STATE_ON;
  112. }
  113. void ath6kl_recovery_resume(struct ath6kl *ar)
  114. {
  115. if (!ar->fw_recovery.enable)
  116. return;
  117. clear_bit(RECOVERY_CLEANUP, &ar->flag);
  118. if (!ar->fw_recovery.hb_poll)
  119. return;
  120. ar->fw_recovery.hb_pending = false;
  121. ar->fw_recovery.seq_num = 0;
  122. ar->fw_recovery.hb_misscnt = 0;
  123. mod_timer(&ar->fw_recovery.hb_timer,
  124. jiffies + msecs_to_jiffies(ar->fw_recovery.hb_poll));
  125. }