util.c 8.4 KB

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