iwl-hcmd.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of version 2 of the GNU General Public License as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  19. * USA
  20. *
  21. * The full GNU General Public License is included in this distribution
  22. * in the file called LICENSE.GPL.
  23. *
  24. * Contact Information:
  25. * Intel Linux Wireless <ilw@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *****************************************************************************/
  28. #include <linux/kernel.h>
  29. #include <linux/module.h>
  30. #include <linux/sched.h>
  31. #include <net/mac80211.h>
  32. #include "iwl-dev.h"
  33. #include "iwl-debug.h"
  34. #include "iwl-eeprom.h"
  35. #include "iwl-core.h"
  36. const char *iwl_legacy_get_cmd_string(u8 cmd)
  37. {
  38. switch (cmd) {
  39. IWL_CMD(REPLY_ALIVE);
  40. IWL_CMD(REPLY_ERROR);
  41. IWL_CMD(REPLY_RXON);
  42. IWL_CMD(REPLY_RXON_ASSOC);
  43. IWL_CMD(REPLY_QOS_PARAM);
  44. IWL_CMD(REPLY_RXON_TIMING);
  45. IWL_CMD(REPLY_ADD_STA);
  46. IWL_CMD(REPLY_REMOVE_STA);
  47. IWL_CMD(REPLY_WEPKEY);
  48. IWL_CMD(REPLY_3945_RX);
  49. IWL_CMD(REPLY_TX);
  50. IWL_CMD(REPLY_RATE_SCALE);
  51. IWL_CMD(REPLY_LEDS_CMD);
  52. IWL_CMD(REPLY_TX_LINK_QUALITY_CMD);
  53. IWL_CMD(REPLY_CHANNEL_SWITCH);
  54. IWL_CMD(CHANNEL_SWITCH_NOTIFICATION);
  55. IWL_CMD(REPLY_SPECTRUM_MEASUREMENT_CMD);
  56. IWL_CMD(SPECTRUM_MEASURE_NOTIFICATION);
  57. IWL_CMD(POWER_TABLE_CMD);
  58. IWL_CMD(PM_SLEEP_NOTIFICATION);
  59. IWL_CMD(PM_DEBUG_STATISTIC_NOTIFIC);
  60. IWL_CMD(REPLY_SCAN_CMD);
  61. IWL_CMD(REPLY_SCAN_ABORT_CMD);
  62. IWL_CMD(SCAN_START_NOTIFICATION);
  63. IWL_CMD(SCAN_RESULTS_NOTIFICATION);
  64. IWL_CMD(SCAN_COMPLETE_NOTIFICATION);
  65. IWL_CMD(BEACON_NOTIFICATION);
  66. IWL_CMD(REPLY_TX_BEACON);
  67. IWL_CMD(REPLY_TX_PWR_TABLE_CMD);
  68. IWL_CMD(REPLY_BT_CONFIG);
  69. IWL_CMD(REPLY_STATISTICS_CMD);
  70. IWL_CMD(STATISTICS_NOTIFICATION);
  71. IWL_CMD(CARD_STATE_NOTIFICATION);
  72. IWL_CMD(MISSED_BEACONS_NOTIFICATION);
  73. IWL_CMD(REPLY_CT_KILL_CONFIG_CMD);
  74. IWL_CMD(SENSITIVITY_CMD);
  75. IWL_CMD(REPLY_PHY_CALIBRATION_CMD);
  76. IWL_CMD(REPLY_RX_PHY_CMD);
  77. IWL_CMD(REPLY_RX_MPDU_CMD);
  78. IWL_CMD(REPLY_RX);
  79. IWL_CMD(REPLY_COMPRESSED_BA);
  80. default:
  81. return "UNKNOWN";
  82. }
  83. }
  84. EXPORT_SYMBOL(iwl_legacy_get_cmd_string);
  85. #define HOST_COMPLETE_TIMEOUT (HZ / 2)
  86. static void iwl_legacy_generic_cmd_callback(struct iwl_priv *priv,
  87. struct iwl_device_cmd *cmd,
  88. struct iwl_rx_packet *pkt)
  89. {
  90. if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) {
  91. IWL_ERR(priv, "Bad return from %s (0x%08X)\n",
  92. iwl_legacy_get_cmd_string(cmd->hdr.cmd), pkt->hdr.flags);
  93. return;
  94. }
  95. #ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
  96. switch (cmd->hdr.cmd) {
  97. case REPLY_TX_LINK_QUALITY_CMD:
  98. case SENSITIVITY_CMD:
  99. IWL_DEBUG_HC_DUMP(priv, "back from %s (0x%08X)\n",
  100. iwl_legacy_get_cmd_string(cmd->hdr.cmd), pkt->hdr.flags);
  101. break;
  102. default:
  103. IWL_DEBUG_HC(priv, "back from %s (0x%08X)\n",
  104. iwl_legacy_get_cmd_string(cmd->hdr.cmd), pkt->hdr.flags);
  105. }
  106. #endif
  107. }
  108. static int
  109. iwl_legacy_send_cmd_async(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
  110. {
  111. int ret;
  112. BUG_ON(!(cmd->flags & CMD_ASYNC));
  113. /* An asynchronous command can not expect an SKB to be set. */
  114. BUG_ON(cmd->flags & CMD_WANT_SKB);
  115. /* Assign a generic callback if one is not provided */
  116. if (!cmd->callback)
  117. cmd->callback = iwl_legacy_generic_cmd_callback;
  118. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  119. return -EBUSY;
  120. ret = iwl_legacy_enqueue_hcmd(priv, cmd);
  121. if (ret < 0) {
  122. IWL_ERR(priv, "Error sending %s: enqueue_hcmd failed: %d\n",
  123. iwl_legacy_get_cmd_string(cmd->id), ret);
  124. return ret;
  125. }
  126. return 0;
  127. }
  128. int iwl_legacy_send_cmd_sync(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
  129. {
  130. int cmd_idx;
  131. int ret;
  132. lockdep_assert_held(&priv->mutex);
  133. BUG_ON(cmd->flags & CMD_ASYNC);
  134. /* A synchronous command can not have a callback set. */
  135. BUG_ON(cmd->callback);
  136. IWL_DEBUG_INFO(priv, "Attempting to send sync command %s\n",
  137. iwl_legacy_get_cmd_string(cmd->id));
  138. set_bit(STATUS_HCMD_ACTIVE, &priv->status);
  139. IWL_DEBUG_INFO(priv, "Setting HCMD_ACTIVE for command %s\n",
  140. iwl_legacy_get_cmd_string(cmd->id));
  141. cmd_idx = iwl_legacy_enqueue_hcmd(priv, cmd);
  142. if (cmd_idx < 0) {
  143. ret = cmd_idx;
  144. IWL_ERR(priv, "Error sending %s: enqueue_hcmd failed: %d\n",
  145. iwl_legacy_get_cmd_string(cmd->id), ret);
  146. goto out;
  147. }
  148. ret = wait_event_interruptible_timeout(priv->wait_command_queue,
  149. !test_bit(STATUS_HCMD_ACTIVE, &priv->status),
  150. HOST_COMPLETE_TIMEOUT);
  151. if (!ret) {
  152. if (test_bit(STATUS_HCMD_ACTIVE, &priv->status)) {
  153. IWL_ERR(priv,
  154. "Error sending %s: time out after %dms.\n",
  155. iwl_legacy_get_cmd_string(cmd->id),
  156. jiffies_to_msecs(HOST_COMPLETE_TIMEOUT));
  157. clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
  158. IWL_DEBUG_INFO(priv,
  159. "Clearing HCMD_ACTIVE for command %s\n",
  160. iwl_legacy_get_cmd_string(cmd->id));
  161. ret = -ETIMEDOUT;
  162. goto cancel;
  163. }
  164. }
  165. if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
  166. IWL_ERR(priv, "Command %s aborted: RF KILL Switch\n",
  167. iwl_legacy_get_cmd_string(cmd->id));
  168. ret = -ECANCELED;
  169. goto fail;
  170. }
  171. if (test_bit(STATUS_FW_ERROR, &priv->status)) {
  172. IWL_ERR(priv, "Command %s failed: FW Error\n",
  173. iwl_legacy_get_cmd_string(cmd->id));
  174. ret = -EIO;
  175. goto fail;
  176. }
  177. if ((cmd->flags & CMD_WANT_SKB) && !cmd->reply_page) {
  178. IWL_ERR(priv, "Error: Response NULL in '%s'\n",
  179. iwl_legacy_get_cmd_string(cmd->id));
  180. ret = -EIO;
  181. goto cancel;
  182. }
  183. ret = 0;
  184. goto out;
  185. cancel:
  186. if (cmd->flags & CMD_WANT_SKB) {
  187. /*
  188. * Cancel the CMD_WANT_SKB flag for the cmd in the
  189. * TX cmd queue. Otherwise in case the cmd comes
  190. * in later, it will possibly set an invalid
  191. * address (cmd->meta.source).
  192. */
  193. priv->txq[priv->cmd_queue].meta[cmd_idx].flags &=
  194. ~CMD_WANT_SKB;
  195. }
  196. fail:
  197. if (cmd->reply_page) {
  198. iwl_legacy_free_pages(priv, cmd->reply_page);
  199. cmd->reply_page = 0;
  200. }
  201. out:
  202. return ret;
  203. }
  204. EXPORT_SYMBOL(iwl_legacy_send_cmd_sync);
  205. int iwl_legacy_send_cmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
  206. {
  207. if (cmd->flags & CMD_ASYNC)
  208. return iwl_legacy_send_cmd_async(priv, cmd);
  209. return iwl_legacy_send_cmd_sync(priv, cmd);
  210. }
  211. EXPORT_SYMBOL(iwl_legacy_send_cmd);
  212. int
  213. iwl_legacy_send_cmd_pdu(struct iwl_priv *priv, u8 id, u16 len, const void *data)
  214. {
  215. struct iwl_host_cmd cmd = {
  216. .id = id,
  217. .len = len,
  218. .data = data,
  219. };
  220. return iwl_legacy_send_cmd_sync(priv, &cmd);
  221. }
  222. EXPORT_SYMBOL(iwl_legacy_send_cmd_pdu);
  223. int iwl_legacy_send_cmd_pdu_async(struct iwl_priv *priv,
  224. u8 id, u16 len, const void *data,
  225. void (*callback)(struct iwl_priv *priv,
  226. struct iwl_device_cmd *cmd,
  227. struct iwl_rx_packet *pkt))
  228. {
  229. struct iwl_host_cmd cmd = {
  230. .id = id,
  231. .len = len,
  232. .data = data,
  233. };
  234. cmd.flags |= CMD_ASYNC;
  235. cmd.callback = callback;
  236. return iwl_legacy_send_cmd_async(priv, &cmd);
  237. }
  238. EXPORT_SYMBOL(iwl_legacy_send_cmd_pdu_async);