util.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * Marvell Wireless LAN device driver: utility functions
  3. *
  4. * Copyright (C) 2011, Marvell International Ltd.
  5. *
  6. * This software file (the "File") is distributed by Marvell International
  7. * Ltd. under the terms of the GNU General Public License Version 2, June 1991
  8. * (the "License"). You may use, redistribute and/or modify this File in
  9. * accordance with the terms and conditions of the License, a copy of which
  10. * is available by writing to the Free Software Foundation, Inc.,
  11. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
  12. * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
  13. *
  14. * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
  16. * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
  17. * this warranty disclaimer.
  18. */
  19. #include "decl.h"
  20. #include "ioctl.h"
  21. #include "util.h"
  22. #include "fw.h"
  23. #include "main.h"
  24. #include "wmm.h"
  25. #include "11n.h"
  26. /*
  27. * Firmware initialization complete callback handler.
  28. *
  29. * This function wakes up the function waiting on the init
  30. * wait queue for the firmware initialization to complete.
  31. */
  32. int mwifiex_init_fw_complete(struct mwifiex_adapter *adapter)
  33. {
  34. adapter->init_wait_q_woken = true;
  35. wake_up_interruptible(&adapter->init_wait_q);
  36. return 0;
  37. }
  38. /*
  39. * Firmware shutdown complete callback handler.
  40. *
  41. * This function sets the hardware status to not ready and wakes up
  42. * the function waiting on the init wait queue for the firmware
  43. * shutdown to complete.
  44. */
  45. int mwifiex_shutdown_fw_complete(struct mwifiex_adapter *adapter)
  46. {
  47. adapter->hw_status = MWIFIEX_HW_STATUS_NOT_READY;
  48. adapter->init_wait_q_woken = true;
  49. wake_up_interruptible(&adapter->init_wait_q);
  50. return 0;
  51. }
  52. /*
  53. * This function sends init/shutdown command
  54. * to firmware.
  55. */
  56. int mwifiex_init_shutdown_fw(struct mwifiex_private *priv,
  57. u32 func_init_shutdown)
  58. {
  59. u16 cmd;
  60. if (func_init_shutdown == MWIFIEX_FUNC_INIT) {
  61. cmd = HostCmd_CMD_FUNC_INIT;
  62. } else if (func_init_shutdown == MWIFIEX_FUNC_SHUTDOWN) {
  63. cmd = HostCmd_CMD_FUNC_SHUTDOWN;
  64. } else {
  65. dev_err(priv->adapter->dev, "unsupported parameter\n");
  66. return -1;
  67. }
  68. return mwifiex_send_cmd_sync(priv, cmd, HostCmd_ACT_GEN_SET, 0, NULL);
  69. }
  70. EXPORT_SYMBOL_GPL(mwifiex_init_shutdown_fw);
  71. /*
  72. * IOCTL request handler to set/get debug information.
  73. *
  74. * This function collates/sets the information from/to different driver
  75. * structures.
  76. */
  77. int mwifiex_get_debug_info(struct mwifiex_private *priv,
  78. struct mwifiex_debug_info *info)
  79. {
  80. struct mwifiex_adapter *adapter = priv->adapter;
  81. if (info) {
  82. memcpy(info->packets_out,
  83. priv->wmm.packets_out,
  84. sizeof(priv->wmm.packets_out));
  85. info->max_tx_buf_size = (u32) adapter->max_tx_buf_size;
  86. info->tx_buf_size = (u32) adapter->tx_buf_size;
  87. info->rx_tbl_num = mwifiex_get_rx_reorder_tbl(priv,
  88. info->rx_tbl);
  89. info->tx_tbl_num = mwifiex_get_tx_ba_stream_tbl(priv,
  90. info->tx_tbl);
  91. info->ps_mode = adapter->ps_mode;
  92. info->ps_state = adapter->ps_state;
  93. info->is_deep_sleep = adapter->is_deep_sleep;
  94. info->pm_wakeup_card_req = adapter->pm_wakeup_card_req;
  95. info->pm_wakeup_fw_try = adapter->pm_wakeup_fw_try;
  96. info->is_hs_configured = adapter->is_hs_configured;
  97. info->hs_activated = adapter->hs_activated;
  98. info->num_cmd_host_to_card_failure
  99. = adapter->dbg.num_cmd_host_to_card_failure;
  100. info->num_cmd_sleep_cfm_host_to_card_failure
  101. = adapter->dbg.num_cmd_sleep_cfm_host_to_card_failure;
  102. info->num_tx_host_to_card_failure
  103. = adapter->dbg.num_tx_host_to_card_failure;
  104. info->num_event_deauth = adapter->dbg.num_event_deauth;
  105. info->num_event_disassoc = adapter->dbg.num_event_disassoc;
  106. info->num_event_link_lost = adapter->dbg.num_event_link_lost;
  107. info->num_cmd_deauth = adapter->dbg.num_cmd_deauth;
  108. info->num_cmd_assoc_success =
  109. adapter->dbg.num_cmd_assoc_success;
  110. info->num_cmd_assoc_failure =
  111. adapter->dbg.num_cmd_assoc_failure;
  112. info->num_tx_timeout = adapter->dbg.num_tx_timeout;
  113. info->num_cmd_timeout = adapter->dbg.num_cmd_timeout;
  114. info->timeout_cmd_id = adapter->dbg.timeout_cmd_id;
  115. info->timeout_cmd_act = adapter->dbg.timeout_cmd_act;
  116. memcpy(info->last_cmd_id, adapter->dbg.last_cmd_id,
  117. sizeof(adapter->dbg.last_cmd_id));
  118. memcpy(info->last_cmd_act, adapter->dbg.last_cmd_act,
  119. sizeof(adapter->dbg.last_cmd_act));
  120. info->last_cmd_index = adapter->dbg.last_cmd_index;
  121. memcpy(info->last_cmd_resp_id, adapter->dbg.last_cmd_resp_id,
  122. sizeof(adapter->dbg.last_cmd_resp_id));
  123. info->last_cmd_resp_index = adapter->dbg.last_cmd_resp_index;
  124. memcpy(info->last_event, adapter->dbg.last_event,
  125. sizeof(adapter->dbg.last_event));
  126. info->last_event_index = adapter->dbg.last_event_index;
  127. info->data_sent = adapter->data_sent;
  128. info->cmd_sent = adapter->cmd_sent;
  129. info->cmd_resp_received = adapter->cmd_resp_received;
  130. }
  131. return 0;
  132. }
  133. /*
  134. * This function processes the received packet before sending it to the
  135. * kernel.
  136. *
  137. * It extracts the SKB from the received buffer and sends it to kernel.
  138. * In case the received buffer does not contain the data in SKB format,
  139. * the function creates a blank SKB, fills it with the data from the
  140. * received buffer and then sends this new SKB to the kernel.
  141. */
  142. int mwifiex_recv_packet(struct mwifiex_adapter *adapter, struct sk_buff *skb)
  143. {
  144. struct mwifiex_rxinfo *rx_info;
  145. struct mwifiex_private *priv;
  146. if (!skb)
  147. return -1;
  148. rx_info = MWIFIEX_SKB_RXCB(skb);
  149. priv = mwifiex_get_priv_by_id(adapter, rx_info->bss_num,
  150. rx_info->bss_type);
  151. if (!priv)
  152. return -1;
  153. skb->dev = priv->netdev;
  154. skb->protocol = eth_type_trans(skb, priv->netdev);
  155. skb->ip_summed = CHECKSUM_NONE;
  156. priv->stats.rx_bytes += skb->len;
  157. priv->stats.rx_packets++;
  158. if (in_interrupt())
  159. netif_rx(skb);
  160. else
  161. netif_rx_ni(skb);
  162. return 0;
  163. }
  164. /*
  165. * IOCTL completion callback handler.
  166. *
  167. * This function is called when a pending IOCTL is completed.
  168. *
  169. * If work queue support is enabled, the function wakes up the
  170. * corresponding waiting function. Otherwise, it processes the
  171. * IOCTL response and frees the response buffer.
  172. */
  173. int mwifiex_complete_cmd(struct mwifiex_adapter *adapter,
  174. struct cmd_ctrl_node *cmd_node)
  175. {
  176. atomic_dec(&adapter->cmd_pending);
  177. dev_dbg(adapter->dev, "cmd completed: status=%d\n",
  178. adapter->cmd_wait_q.status);
  179. *(cmd_node->condition) = true;
  180. if (adapter->cmd_wait_q.status == -ETIMEDOUT)
  181. dev_err(adapter->dev, "cmd timeout\n");
  182. else
  183. wake_up_interruptible(&adapter->cmd_wait_q.wait);
  184. return 0;
  185. }