util.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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->curr_tx_buf_size = (u32) adapter->curr_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 management packet and send it
  135. * to the kernel.
  136. */
  137. int
  138. mwifiex_process_mgmt_packet(struct mwifiex_private *priv,
  139. struct sk_buff *skb)
  140. {
  141. struct rxpd *rx_pd;
  142. u16 pkt_len;
  143. if (!skb)
  144. return -1;
  145. rx_pd = (struct rxpd *)skb->data;
  146. skb_pull(skb, le16_to_cpu(rx_pd->rx_pkt_offset));
  147. skb_pull(skb, sizeof(pkt_len));
  148. pkt_len = le16_to_cpu(rx_pd->rx_pkt_length);
  149. /* Remove address4 */
  150. memmove(skb->data + sizeof(struct ieee80211_hdr_3addr),
  151. skb->data + sizeof(struct ieee80211_hdr),
  152. pkt_len - sizeof(struct ieee80211_hdr));
  153. pkt_len -= ETH_ALEN + sizeof(pkt_len);
  154. rx_pd->rx_pkt_length = cpu_to_le16(pkt_len);
  155. cfg80211_rx_mgmt(priv->wdev, priv->roc_cfg.chan.center_freq,
  156. CAL_RSSI(rx_pd->snr, rx_pd->nf),
  157. skb->data, pkt_len, GFP_ATOMIC);
  158. return 0;
  159. }
  160. /*
  161. * This function processes the received packet before sending it to the
  162. * kernel.
  163. *
  164. * It extracts the SKB from the received buffer and sends it to kernel.
  165. * In case the received buffer does not contain the data in SKB format,
  166. * the function creates a blank SKB, fills it with the data from the
  167. * received buffer and then sends this new SKB to the kernel.
  168. */
  169. int mwifiex_recv_packet(struct mwifiex_private *priv, struct sk_buff *skb)
  170. {
  171. if (!skb)
  172. return -1;
  173. skb->dev = priv->netdev;
  174. skb->protocol = eth_type_trans(skb, priv->netdev);
  175. skb->ip_summed = CHECKSUM_NONE;
  176. /* This is required only in case of 11n and USB as we alloc
  177. * a buffer of 4K only if its 11N (to be able to receive 4K
  178. * AMSDU packets). In case of SD we allocate buffers based
  179. * on the size of packet and hence this is not needed.
  180. *
  181. * Modifying the truesize here as our allocation for each
  182. * skb is 4K but we only receive 2K packets and this cause
  183. * the kernel to start dropping packets in case where
  184. * application has allocated buffer based on 2K size i.e.
  185. * if there a 64K packet received (in IP fragments and
  186. * application allocates 64K to receive this packet but
  187. * this packet would almost double up because we allocate
  188. * each 1.5K fragment in 4K and pass it up. As soon as the
  189. * 64K limit hits kernel will start to drop rest of the
  190. * fragments. Currently we fail the Filesndl-ht.scr script
  191. * for UDP, hence this fix
  192. */
  193. if ((priv->adapter->iface_type == MWIFIEX_USB) &&
  194. (skb->truesize > MWIFIEX_RX_DATA_BUF_SIZE))
  195. skb->truesize += (skb->len - MWIFIEX_RX_DATA_BUF_SIZE);
  196. priv->stats.rx_bytes += skb->len;
  197. priv->stats.rx_packets++;
  198. if (in_interrupt())
  199. netif_rx(skb);
  200. else
  201. netif_rx_ni(skb);
  202. return 0;
  203. }
  204. /*
  205. * IOCTL completion callback handler.
  206. *
  207. * This function is called when a pending IOCTL is completed.
  208. *
  209. * If work queue support is enabled, the function wakes up the
  210. * corresponding waiting function. Otherwise, it processes the
  211. * IOCTL response and frees the response buffer.
  212. */
  213. int mwifiex_complete_cmd(struct mwifiex_adapter *adapter,
  214. struct cmd_ctrl_node *cmd_node)
  215. {
  216. atomic_dec(&adapter->cmd_pending);
  217. dev_dbg(adapter->dev, "cmd completed: status=%d\n",
  218. adapter->cmd_wait_q.status);
  219. *(cmd_node->condition) = true;
  220. if (adapter->cmd_wait_q.status == -ETIMEDOUT)
  221. dev_err(adapter->dev, "cmd timeout\n");
  222. else
  223. wake_up_interruptible(&adapter->cmd_wait_q.wait);
  224. return 0;
  225. }