recovery.c 4.1 KB

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