recovery.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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(unsigned long data)
  50. {
  51. struct ath6kl *ar = (struct ath6kl *) data;
  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. ar->fw_recovery.hb_timer.function = ath6kl_recovery_hb_timer;
  86. ar->fw_recovery.hb_timer.data = (unsigned long) ar;
  87. init_timer_deferrable(&ar->fw_recovery.hb_timer);
  88. if (ar->fw_recovery.hb_poll)
  89. mod_timer(&ar->fw_recovery.hb_timer, jiffies +
  90. msecs_to_jiffies(ar->fw_recovery.hb_poll));
  91. }
  92. void ath6kl_recovery_cleanup(struct ath6kl *ar)
  93. {
  94. if (!ar->fw_recovery.enable)
  95. return;
  96. set_bit(RECOVERY_CLEANUP, &ar->flag);
  97. del_timer_sync(&ar->fw_recovery.hb_timer);
  98. cancel_work_sync(&ar->fw_recovery.recovery_work);
  99. }
  100. void ath6kl_recovery_suspend(struct ath6kl *ar)
  101. {
  102. if (!ar->fw_recovery.enable)
  103. return;
  104. ath6kl_recovery_cleanup(ar);
  105. if (!ar->fw_recovery.err_reason)
  106. return;
  107. /* Process pending fw error detection */
  108. ar->fw_recovery.err_reason = 0;
  109. WARN_ON(ar->state != ATH6KL_STATE_ON);
  110. ar->state = ATH6KL_STATE_RECOVERY;
  111. ath6kl_init_hw_restart(ar);
  112. ar->state = ATH6KL_STATE_ON;
  113. }
  114. void ath6kl_recovery_resume(struct ath6kl *ar)
  115. {
  116. if (!ar->fw_recovery.enable)
  117. return;
  118. clear_bit(RECOVERY_CLEANUP, &ar->flag);
  119. if (!ar->fw_recovery.hb_poll)
  120. return;
  121. ar->fw_recovery.hb_pending = false;
  122. ar->fw_recovery.seq_num = 0;
  123. ar->fw_recovery.hb_misscnt = 0;
  124. mod_timer(&ar->fw_recovery.hb_timer,
  125. jiffies + msecs_to_jiffies(ar->fw_recovery.hb_poll));
  126. }