util.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. * IOCTL request handler to send function init/shutdown command
  54. * to firmware.
  55. *
  56. * This function prepares the correct firmware command and
  57. * issues it.
  58. */
  59. int mwifiex_misc_ioctl_init_shutdown(struct mwifiex_adapter *adapter,
  60. struct mwifiex_wait_queue *wait,
  61. u32 func_init_shutdown)
  62. {
  63. struct mwifiex_private *priv = adapter->priv[wait->bss_index];
  64. int ret;
  65. u16 cmd;
  66. if (func_init_shutdown == MWIFIEX_FUNC_INIT) {
  67. cmd = HostCmd_CMD_FUNC_INIT;
  68. } else if (func_init_shutdown == MWIFIEX_FUNC_SHUTDOWN) {
  69. cmd = HostCmd_CMD_FUNC_SHUTDOWN;
  70. } else {
  71. dev_err(adapter->dev, "unsupported parameter\n");
  72. return -1;
  73. }
  74. /* Send command to firmware */
  75. ret = mwifiex_prepare_cmd(priv, cmd, HostCmd_ACT_GEN_SET,
  76. 0, wait, NULL);
  77. if (!ret)
  78. ret = -EINPROGRESS;
  79. return ret;
  80. }
  81. /*
  82. * IOCTL request handler to set/get debug information.
  83. *
  84. * This function collates/sets the information from/to different driver
  85. * structures.
  86. */
  87. int mwifiex_get_debug_info(struct mwifiex_private *priv,
  88. struct mwifiex_debug_info *info)
  89. {
  90. struct mwifiex_adapter *adapter = priv->adapter;
  91. if (info) {
  92. memcpy(info->packets_out,
  93. priv->wmm.packets_out,
  94. sizeof(priv->wmm.packets_out));
  95. info->max_tx_buf_size = (u32) adapter->max_tx_buf_size;
  96. info->tx_buf_size = (u32) adapter->tx_buf_size;
  97. info->rx_tbl_num = mwifiex_get_rx_reorder_tbl(
  98. priv, info->rx_tbl);
  99. info->tx_tbl_num = mwifiex_get_tx_ba_stream_tbl(
  100. priv, info->tx_tbl);
  101. info->ps_mode = adapter->ps_mode;
  102. info->ps_state = adapter->ps_state;
  103. info->is_deep_sleep = adapter->is_deep_sleep;
  104. info->pm_wakeup_card_req = adapter->pm_wakeup_card_req;
  105. info->pm_wakeup_fw_try = adapter->pm_wakeup_fw_try;
  106. info->is_hs_configured = adapter->is_hs_configured;
  107. info->hs_activated = adapter->hs_activated;
  108. info->num_cmd_host_to_card_failure
  109. = adapter->dbg.num_cmd_host_to_card_failure;
  110. info->num_cmd_sleep_cfm_host_to_card_failure
  111. = adapter->dbg.num_cmd_sleep_cfm_host_to_card_failure;
  112. info->num_tx_host_to_card_failure
  113. = adapter->dbg.num_tx_host_to_card_failure;
  114. info->num_event_deauth = adapter->dbg.num_event_deauth;
  115. info->num_event_disassoc = adapter->dbg.num_event_disassoc;
  116. info->num_event_link_lost = adapter->dbg.num_event_link_lost;
  117. info->num_cmd_deauth = adapter->dbg.num_cmd_deauth;
  118. info->num_cmd_assoc_success =
  119. adapter->dbg.num_cmd_assoc_success;
  120. info->num_cmd_assoc_failure =
  121. adapter->dbg.num_cmd_assoc_failure;
  122. info->num_tx_timeout = adapter->dbg.num_tx_timeout;
  123. info->num_cmd_timeout = adapter->dbg.num_cmd_timeout;
  124. info->timeout_cmd_id = adapter->dbg.timeout_cmd_id;
  125. info->timeout_cmd_act = adapter->dbg.timeout_cmd_act;
  126. memcpy(info->last_cmd_id, adapter->dbg.last_cmd_id,
  127. sizeof(adapter->dbg.last_cmd_id));
  128. memcpy(info->last_cmd_act, adapter->dbg.last_cmd_act,
  129. sizeof(adapter->dbg.last_cmd_act));
  130. info->last_cmd_index = adapter->dbg.last_cmd_index;
  131. memcpy(info->last_cmd_resp_id, adapter->dbg.last_cmd_resp_id,
  132. sizeof(adapter->dbg.last_cmd_resp_id));
  133. info->last_cmd_resp_index = adapter->dbg.last_cmd_resp_index;
  134. memcpy(info->last_event, adapter->dbg.last_event,
  135. sizeof(adapter->dbg.last_event));
  136. info->last_event_index = adapter->dbg.last_event_index;
  137. info->data_sent = adapter->data_sent;
  138. info->cmd_sent = adapter->cmd_sent;
  139. info->cmd_resp_received = adapter->cmd_resp_received;
  140. }
  141. return 0;
  142. }
  143. /*
  144. * This function processes the received packet before sending it to the
  145. * kernel.
  146. *
  147. * It extracts the SKB from the received buffer and sends it to kernel.
  148. * In case the received buffer does not contain the data in SKB format,
  149. * the function creates a blank SKB, fills it with the data from the
  150. * received buffer and then sends this new SKB to the kernel.
  151. */
  152. int mwifiex_recv_packet(struct mwifiex_adapter *adapter, struct sk_buff *skb)
  153. {
  154. struct mwifiex_rxinfo *rx_info = NULL;
  155. struct mwifiex_private *priv = NULL;
  156. if (!skb)
  157. return -1;
  158. rx_info = MWIFIEX_SKB_RXCB(skb);
  159. priv = mwifiex_bss_index_to_priv(adapter, rx_info->bss_index);
  160. if (!priv)
  161. return -1;
  162. skb->dev = priv->netdev;
  163. skb->protocol = eth_type_trans(skb, priv->netdev);
  164. skb->ip_summed = CHECKSUM_NONE;
  165. priv->stats.rx_bytes += skb->len;
  166. priv->stats.rx_packets++;
  167. if (in_interrupt())
  168. netif_rx(skb);
  169. else
  170. netif_rx_ni(skb);
  171. return 0;
  172. }
  173. /*
  174. * Receive packet completion callback handler.
  175. *
  176. * This function updates the statistics and frees the buffer SKB.
  177. */
  178. int mwifiex_recv_complete(struct mwifiex_adapter *adapter,
  179. struct sk_buff *skb, int status)
  180. {
  181. struct mwifiex_private *priv = NULL;
  182. struct mwifiex_rxinfo *rx_info = NULL;
  183. if (!skb)
  184. return 0;
  185. rx_info = MWIFIEX_SKB_RXCB(skb);
  186. priv = mwifiex_bss_index_to_priv(adapter, rx_info->bss_index);
  187. if (priv && (status == -1))
  188. priv->stats.rx_dropped++;
  189. dev_kfree_skb_any(skb);
  190. return 0;
  191. }
  192. /*
  193. * IOCTL completion callback handler.
  194. *
  195. * This function is called when a pending IOCTL is completed.
  196. *
  197. * If work queue support is enabled, the function wakes up the
  198. * corresponding waiting function. Otherwise, it processes the
  199. * IOCTL response and frees the response buffer.
  200. */
  201. int mwifiex_ioctl_complete(struct mwifiex_adapter *adapter,
  202. struct mwifiex_wait_queue *wait_queue,
  203. int status)
  204. {
  205. enum mwifiex_error_code status_code =
  206. (enum mwifiex_error_code) wait_queue->status;
  207. atomic_dec(&adapter->ioctl_pending);
  208. dev_dbg(adapter->dev, "cmd: IOCTL completed: status=%d,"
  209. " status_code=%#x\n", status, status_code);
  210. if (wait_queue->enabled) {
  211. *wait_queue->condition = true;
  212. wait_queue->status = status;
  213. if (status && (status_code == MWIFIEX_ERROR_CMD_TIMEOUT))
  214. dev_err(adapter->dev, "cmd timeout\n");
  215. else
  216. wake_up_interruptible(wait_queue->wait);
  217. } else {
  218. if (status)
  219. dev_err(adapter->dev, "cmd failed: status_code=%#x\n",
  220. status_code);
  221. kfree(wait_queue);
  222. }
  223. return 0;
  224. }