iwl-hcmd.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2009 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 <net/mac80211.h>
  31. #include "iwl-dev.h" /* FIXME: remove */
  32. #include "iwl-debug.h"
  33. #include "iwl-eeprom.h"
  34. #include "iwl-core.h"
  35. const char *get_cmd_string(u8 cmd)
  36. {
  37. switch (cmd) {
  38. IWL_CMD(REPLY_ALIVE);
  39. IWL_CMD(REPLY_ERROR);
  40. IWL_CMD(REPLY_RXON);
  41. IWL_CMD(REPLY_RXON_ASSOC);
  42. IWL_CMD(REPLY_QOS_PARAM);
  43. IWL_CMD(REPLY_RXON_TIMING);
  44. IWL_CMD(REPLY_ADD_STA);
  45. IWL_CMD(REPLY_REMOVE_STA);
  46. IWL_CMD(REPLY_REMOVE_ALL_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(COEX_PRIORITY_TABLE_CMD);
  54. IWL_CMD(RADAR_NOTIFICATION);
  55. IWL_CMD(REPLY_QUIET_CMD);
  56. IWL_CMD(REPLY_CHANNEL_SWITCH);
  57. IWL_CMD(CHANNEL_SWITCH_NOTIFICATION);
  58. IWL_CMD(REPLY_SPECTRUM_MEASUREMENT_CMD);
  59. IWL_CMD(SPECTRUM_MEASURE_NOTIFICATION);
  60. IWL_CMD(POWER_TABLE_CMD);
  61. IWL_CMD(PM_SLEEP_NOTIFICATION);
  62. IWL_CMD(PM_DEBUG_STATISTIC_NOTIFIC);
  63. IWL_CMD(REPLY_SCAN_CMD);
  64. IWL_CMD(REPLY_SCAN_ABORT_CMD);
  65. IWL_CMD(SCAN_START_NOTIFICATION);
  66. IWL_CMD(SCAN_RESULTS_NOTIFICATION);
  67. IWL_CMD(SCAN_COMPLETE_NOTIFICATION);
  68. IWL_CMD(BEACON_NOTIFICATION);
  69. IWL_CMD(REPLY_TX_BEACON);
  70. IWL_CMD(WHO_IS_AWAKE_NOTIFICATION);
  71. IWL_CMD(QUIET_NOTIFICATION);
  72. IWL_CMD(REPLY_TX_PWR_TABLE_CMD);
  73. IWL_CMD(MEASURE_ABORT_NOTIFICATION);
  74. IWL_CMD(REPLY_BT_CONFIG);
  75. IWL_CMD(REPLY_STATISTICS_CMD);
  76. IWL_CMD(STATISTICS_NOTIFICATION);
  77. IWL_CMD(REPLY_CARD_STATE_CMD);
  78. IWL_CMD(CARD_STATE_NOTIFICATION);
  79. IWL_CMD(MISSED_BEACONS_NOTIFICATION);
  80. IWL_CMD(REPLY_CT_KILL_CONFIG_CMD);
  81. IWL_CMD(SENSITIVITY_CMD);
  82. IWL_CMD(REPLY_PHY_CALIBRATION_CMD);
  83. IWL_CMD(REPLY_RX_PHY_CMD);
  84. IWL_CMD(REPLY_RX_MPDU_CMD);
  85. IWL_CMD(REPLY_RX);
  86. IWL_CMD(REPLY_COMPRESSED_BA);
  87. IWL_CMD(CALIBRATION_CFG_CMD);
  88. IWL_CMD(CALIBRATION_RES_NOTIFICATION);
  89. IWL_CMD(CALIBRATION_COMPLETE_NOTIFICATION);
  90. IWL_CMD(REPLY_TX_POWER_DBM_CMD);
  91. IWL_CMD(TEMPERATURE_NOTIFICATION);
  92. IWL_CMD(TX_ANT_CONFIGURATION_CMD);
  93. default:
  94. return "UNKNOWN";
  95. }
  96. }
  97. EXPORT_SYMBOL(get_cmd_string);
  98. #define HOST_COMPLETE_TIMEOUT (HZ / 2)
  99. static void iwl_generic_cmd_callback(struct iwl_priv *priv,
  100. struct iwl_device_cmd *cmd,
  101. struct iwl_rx_packet *pkt)
  102. {
  103. if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) {
  104. IWL_ERR(priv, "Bad return from %s (0x%08X)\n",
  105. get_cmd_string(cmd->hdr.cmd), pkt->hdr.flags);
  106. return;
  107. }
  108. #ifdef CONFIG_IWLWIFI_DEBUG
  109. switch (cmd->hdr.cmd) {
  110. case REPLY_TX_LINK_QUALITY_CMD:
  111. case SENSITIVITY_CMD:
  112. IWL_DEBUG_HC_DUMP(priv, "back from %s (0x%08X)\n",
  113. get_cmd_string(cmd->hdr.cmd), pkt->hdr.flags);
  114. break;
  115. default:
  116. IWL_DEBUG_HC(priv, "back from %s (0x%08X)\n",
  117. get_cmd_string(cmd->hdr.cmd), pkt->hdr.flags);
  118. }
  119. #endif
  120. }
  121. static int iwl_send_cmd_async(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
  122. {
  123. int ret;
  124. BUG_ON(!(cmd->flags & CMD_ASYNC));
  125. /* An asynchronous command can not expect an SKB to be set. */
  126. BUG_ON(cmd->flags & CMD_WANT_SKB);
  127. /* Assign a generic callback if one is not provided */
  128. if (!cmd->callback)
  129. cmd->callback = iwl_generic_cmd_callback;
  130. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  131. return -EBUSY;
  132. ret = iwl_enqueue_hcmd(priv, cmd);
  133. if (ret < 0) {
  134. IWL_ERR(priv, "Error sending %s: enqueue_hcmd failed: %d\n",
  135. get_cmd_string(cmd->id), ret);
  136. return ret;
  137. }
  138. return 0;
  139. }
  140. int iwl_send_cmd_sync(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
  141. {
  142. int cmd_idx;
  143. int ret;
  144. BUG_ON(cmd->flags & CMD_ASYNC);
  145. /* A synchronous command can not have a callback set. */
  146. BUG_ON(cmd->callback);
  147. if (test_and_set_bit(STATUS_HCMD_SYNC_ACTIVE, &priv->status)) {
  148. IWL_ERR(priv,
  149. "Error sending %s: Already sending a host command\n",
  150. get_cmd_string(cmd->id));
  151. ret = -EBUSY;
  152. goto out;
  153. }
  154. set_bit(STATUS_HCMD_ACTIVE, &priv->status);
  155. cmd_idx = iwl_enqueue_hcmd(priv, cmd);
  156. if (cmd_idx < 0) {
  157. ret = cmd_idx;
  158. IWL_ERR(priv, "Error sending %s: enqueue_hcmd failed: %d\n",
  159. get_cmd_string(cmd->id), ret);
  160. goto out;
  161. }
  162. ret = wait_event_interruptible_timeout(priv->wait_command_queue,
  163. !test_bit(STATUS_HCMD_ACTIVE, &priv->status),
  164. HOST_COMPLETE_TIMEOUT);
  165. if (!ret) {
  166. if (test_bit(STATUS_HCMD_ACTIVE, &priv->status)) {
  167. IWL_ERR(priv,
  168. "Error sending %s: time out after %dms.\n",
  169. get_cmd_string(cmd->id),
  170. jiffies_to_msecs(HOST_COMPLETE_TIMEOUT));
  171. clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
  172. ret = -ETIMEDOUT;
  173. goto cancel;
  174. }
  175. }
  176. if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
  177. IWL_DEBUG_INFO(priv, "Command %s aborted: RF KILL Switch\n",
  178. get_cmd_string(cmd->id));
  179. ret = -ECANCELED;
  180. goto fail;
  181. }
  182. if (test_bit(STATUS_FW_ERROR, &priv->status)) {
  183. IWL_DEBUG_INFO(priv, "Command %s failed: FW Error\n",
  184. get_cmd_string(cmd->id));
  185. ret = -EIO;
  186. goto fail;
  187. }
  188. if ((cmd->flags & CMD_WANT_SKB) && !cmd->reply_page) {
  189. IWL_ERR(priv, "Error: Response NULL in '%s'\n",
  190. get_cmd_string(cmd->id));
  191. ret = -EIO;
  192. goto cancel;
  193. }
  194. ret = 0;
  195. goto out;
  196. cancel:
  197. if (cmd->flags & CMD_WANT_SKB) {
  198. /*
  199. * Cancel the CMD_WANT_SKB flag for the cmd in the
  200. * TX cmd queue. Otherwise in case the cmd comes
  201. * in later, it will possibly set an invalid
  202. * address (cmd->meta.source).
  203. */
  204. priv->txq[IWL_CMD_QUEUE_NUM].meta[cmd_idx].flags &=
  205. ~CMD_WANT_SKB;
  206. }
  207. fail:
  208. if (cmd->reply_page) {
  209. free_pages(cmd->reply_page, priv->hw_params.rx_page_order);
  210. cmd->reply_page = 0;
  211. }
  212. out:
  213. clear_bit(STATUS_HCMD_SYNC_ACTIVE, &priv->status);
  214. return ret;
  215. }
  216. EXPORT_SYMBOL(iwl_send_cmd_sync);
  217. int iwl_send_cmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
  218. {
  219. if (cmd->flags & CMD_ASYNC)
  220. return iwl_send_cmd_async(priv, cmd);
  221. return iwl_send_cmd_sync(priv, cmd);
  222. }
  223. EXPORT_SYMBOL(iwl_send_cmd);
  224. int iwl_send_cmd_pdu(struct iwl_priv *priv, u8 id, u16 len, const void *data)
  225. {
  226. struct iwl_host_cmd cmd = {
  227. .id = id,
  228. .len = len,
  229. .data = data,
  230. };
  231. return iwl_send_cmd_sync(priv, &cmd);
  232. }
  233. EXPORT_SYMBOL(iwl_send_cmd_pdu);
  234. int iwl_send_cmd_pdu_async(struct iwl_priv *priv,
  235. u8 id, u16 len, const void *data,
  236. void (*callback)(struct iwl_priv *priv,
  237. struct iwl_device_cmd *cmd,
  238. struct iwl_rx_packet *pkt))
  239. {
  240. struct iwl_host_cmd cmd = {
  241. .id = id,
  242. .len = len,
  243. .data = data,
  244. };
  245. cmd.flags |= CMD_ASYNC;
  246. cmd.callback = callback;
  247. return iwl_send_cmd_async(priv, &cmd);
  248. }
  249. EXPORT_SYMBOL(iwl_send_cmd_pdu_async);