recovery.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. ar->fw_recovery.err_reason = 0;
  28. if (ar->fw_recovery.enable)
  29. mod_timer(&ar->fw_recovery.hb_timer, jiffies +
  30. msecs_to_jiffies(ar->fw_recovery.hb_poll));
  31. }
  32. void ath6kl_recovery_err_notify(struct ath6kl *ar, enum ath6kl_fw_err reason)
  33. {
  34. ath6kl_dbg(ATH6KL_DBG_RECOVERY, "Fw error detected, reason:%d\n",
  35. reason);
  36. set_bit(reason, &ar->fw_recovery.err_reason);
  37. if (ar->fw_recovery.enable && ar->state != ATH6KL_STATE_RECOVERY)
  38. queue_work(ar->ath6kl_wq, &ar->fw_recovery.recovery_work);
  39. }
  40. void ath6kl_recovery_hb_event(struct ath6kl *ar, u32 cookie)
  41. {
  42. if (cookie == ar->fw_recovery.seq_num)
  43. ar->fw_recovery.hb_pending = false;
  44. }
  45. static void ath6kl_recovery_hb_timer(unsigned long data)
  46. {
  47. struct ath6kl *ar = (struct ath6kl *) data;
  48. int err;
  49. if (!ar->fw_recovery.enable)
  50. return;
  51. if (ar->fw_recovery.hb_pending)
  52. ar->fw_recovery.hb_misscnt++;
  53. else
  54. ar->fw_recovery.hb_misscnt = 0;
  55. if (ar->fw_recovery.hb_misscnt > ATH6KL_HB_RESP_MISS_THRES) {
  56. ar->fw_recovery.hb_misscnt = 0;
  57. ar->fw_recovery.seq_num = 0;
  58. ar->fw_recovery.hb_pending = false;
  59. ath6kl_recovery_err_notify(ar, ATH6KL_FW_HB_RESP_FAILURE);
  60. return;
  61. }
  62. ar->fw_recovery.seq_num++;
  63. ar->fw_recovery.hb_pending = true;
  64. err = ath6kl_wmi_get_challenge_resp_cmd(ar->wmi,
  65. ar->fw_recovery.seq_num, 0);
  66. if (err)
  67. ath6kl_warn("Failed to send hb challenge request, err:%d\n",
  68. err);
  69. if ((ar->state == ATH6KL_STATE_RECOVERY) || !ar->fw_recovery.enable)
  70. return;
  71. mod_timer(&ar->fw_recovery.hb_timer, jiffies +
  72. msecs_to_jiffies(ar->fw_recovery.hb_poll));
  73. }
  74. void ath6kl_recovery_init(struct ath6kl *ar)
  75. {
  76. struct ath6kl_fw_recovery *recovery = &ar->fw_recovery;
  77. recovery->enable = true;
  78. INIT_WORK(&recovery->recovery_work, ath6kl_recovery_work);
  79. recovery->seq_num = 0;
  80. recovery->hb_misscnt = 0;
  81. ar->fw_recovery.hb_pending = false;
  82. ar->fw_recovery.hb_timer.function = ath6kl_recovery_hb_timer;
  83. ar->fw_recovery.hb_timer.data = (unsigned long) ar;
  84. init_timer_deferrable(&ar->fw_recovery.hb_timer);
  85. if (ar->fw_recovery.hb_poll)
  86. mod_timer(&ar->fw_recovery.hb_timer, jiffies +
  87. msecs_to_jiffies(ar->fw_recovery.hb_poll));
  88. }
  89. void ath6kl_recovery_cleanup(struct ath6kl *ar)
  90. {
  91. ar->fw_recovery.enable = false;
  92. del_timer_sync(&ar->fw_recovery.hb_timer);
  93. cancel_work_sync(&ar->fw_recovery.recovery_work);
  94. }
  95. void ath6kl_recovery_suspend(struct ath6kl *ar)
  96. {
  97. ath6kl_recovery_cleanup(ar);
  98. if (!ar->fw_recovery.err_reason)
  99. return;
  100. /* Process pending fw error detection */
  101. ar->fw_recovery.err_reason = 0;
  102. WARN_ON(ar->state != ATH6KL_STATE_ON);
  103. ar->state = ATH6KL_STATE_RECOVERY;
  104. ath6kl_init_hw_restart(ar);
  105. ar->state = ATH6KL_STATE_ON;
  106. }
  107. void ath6kl_recovery_resume(struct ath6kl *ar)
  108. {
  109. ar->fw_recovery.enable = true;
  110. if (!ar->fw_recovery.hb_poll)
  111. return;
  112. ar->fw_recovery.hb_pending = false;
  113. ar->fw_recovery.seq_num = 0;
  114. ar->fw_recovery.hb_misscnt = 0;
  115. mod_timer(&ar->fw_recovery.hb_timer,
  116. jiffies + msecs_to_jiffies(ar->fw_recovery.hb_poll));
  117. }