blob: e1dc3e41c65db7689dac81dfa438b5e1d3c98cac [file] [log] [blame]
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001/*
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
20#include "decl.h"
21#include "ioctl.h"
22#include "util.h"
23#include "fw.h"
24#include "main.h"
25#include "wmm.h"
26#include "11n.h"
27
28/*
29 * Firmware initialization complete callback handler.
30 *
31 * This function wakes up the function waiting on the init
32 * wait queue for the firmware initialization to complete.
33 */
34int mwifiex_init_fw_complete(struct mwifiex_adapter *adapter)
35{
36
37 adapter->init_wait_q_woken = true;
38 wake_up_interruptible(&adapter->init_wait_q);
39 return 0;
40}
41
42/*
43 * Firmware shutdown complete callback handler.
44 *
45 * This function sets the hardware status to not ready and wakes up
46 * the function waiting on the init wait queue for the firmware
47 * shutdown to complete.
48 */
49int mwifiex_shutdown_fw_complete(struct mwifiex_adapter *adapter)
50{
51 adapter->hw_status = MWIFIEX_HW_STATUS_NOT_READY;
52 adapter->init_wait_q_woken = true;
53 wake_up_interruptible(&adapter->init_wait_q);
54 return 0;
55}
56
57/*
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070058 * This function sends init/shutdown command
Bing Zhao5e6e3a92011-03-21 18:00:50 -070059 * to firmware.
Bing Zhao5e6e3a92011-03-21 18:00:50 -070060 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070061int mwifiex_init_shutdown_fw(struct mwifiex_private *priv,
62 u32 func_init_shutdown)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070063{
Bing Zhao5e6e3a92011-03-21 18:00:50 -070064 u16 cmd;
65
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 {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070071 dev_err(priv->adapter->dev, "unsupported parameter\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -070072 return -1;
73 }
74
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -070075 return mwifiex_send_cmd_sync(priv, cmd, HostCmd_ACT_GEN_SET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -070076}
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070077EXPORT_SYMBOL_GPL(mwifiex_init_shutdown_fw);
Bing Zhao5e6e3a92011-03-21 18:00:50 -070078
79/*
80 * IOCTL request handler to set/get debug information.
81 *
82 * This function collates/sets the information from/to different driver
83 * structures.
84 */
85int mwifiex_get_debug_info(struct mwifiex_private *priv,
86 struct mwifiex_debug_info *info)
87{
88 struct mwifiex_adapter *adapter = priv->adapter;
89
90 if (info) {
91 memcpy(info->packets_out,
92 priv->wmm.packets_out,
93 sizeof(priv->wmm.packets_out));
94 info->max_tx_buf_size = (u32) adapter->max_tx_buf_size;
95 info->tx_buf_size = (u32) adapter->tx_buf_size;
Yogesh Ashok Powarc65a30f2012-03-13 19:22:42 -070096 info->rx_tbl_num = mwifiex_get_rx_reorder_tbl(priv,
97 info->rx_tbl);
98 info->tx_tbl_num = mwifiex_get_tx_ba_stream_tbl(priv,
99 info->tx_tbl);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700100 info->ps_mode = adapter->ps_mode;
101 info->ps_state = adapter->ps_state;
102 info->is_deep_sleep = adapter->is_deep_sleep;
103 info->pm_wakeup_card_req = adapter->pm_wakeup_card_req;
104 info->pm_wakeup_fw_try = adapter->pm_wakeup_fw_try;
105 info->is_hs_configured = adapter->is_hs_configured;
106 info->hs_activated = adapter->hs_activated;
107 info->num_cmd_host_to_card_failure
Yogesh Ashok Powarc65a30f2012-03-13 19:22:42 -0700108 = adapter->dbg.num_cmd_host_to_card_failure;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700109 info->num_cmd_sleep_cfm_host_to_card_failure
110 = adapter->dbg.num_cmd_sleep_cfm_host_to_card_failure;
111 info->num_tx_host_to_card_failure
Yogesh Ashok Powarc65a30f2012-03-13 19:22:42 -0700112 = adapter->dbg.num_tx_host_to_card_failure;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700113 info->num_event_deauth = adapter->dbg.num_event_deauth;
114 info->num_event_disassoc = adapter->dbg.num_event_disassoc;
115 info->num_event_link_lost = adapter->dbg.num_event_link_lost;
116 info->num_cmd_deauth = adapter->dbg.num_cmd_deauth;
117 info->num_cmd_assoc_success =
Yogesh Ashok Powarc65a30f2012-03-13 19:22:42 -0700118 adapter->dbg.num_cmd_assoc_success;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700119 info->num_cmd_assoc_failure =
Yogesh Ashok Powarc65a30f2012-03-13 19:22:42 -0700120 adapter->dbg.num_cmd_assoc_failure;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700121 info->num_tx_timeout = adapter->dbg.num_tx_timeout;
122 info->num_cmd_timeout = adapter->dbg.num_cmd_timeout;
123 info->timeout_cmd_id = adapter->dbg.timeout_cmd_id;
124 info->timeout_cmd_act = adapter->dbg.timeout_cmd_act;
125 memcpy(info->last_cmd_id, adapter->dbg.last_cmd_id,
126 sizeof(adapter->dbg.last_cmd_id));
127 memcpy(info->last_cmd_act, adapter->dbg.last_cmd_act,
128 sizeof(adapter->dbg.last_cmd_act));
129 info->last_cmd_index = adapter->dbg.last_cmd_index;
130 memcpy(info->last_cmd_resp_id, adapter->dbg.last_cmd_resp_id,
131 sizeof(adapter->dbg.last_cmd_resp_id));
132 info->last_cmd_resp_index = adapter->dbg.last_cmd_resp_index;
133 memcpy(info->last_event, adapter->dbg.last_event,
134 sizeof(adapter->dbg.last_event));
135 info->last_event_index = adapter->dbg.last_event_index;
136 info->data_sent = adapter->data_sent;
137 info->cmd_sent = adapter->cmd_sent;
138 info->cmd_resp_received = adapter->cmd_resp_received;
139 }
140
141 return 0;
142}
143
144/*
Stone Piao2dbaf752012-09-25 20:23:35 -0700145 * This function processes the received management packet and send it
146 * to the kernel.
147 */
148int
149mwifiex_process_mgmt_packet(struct mwifiex_adapter *adapter,
150 struct sk_buff *skb)
151{
152 struct rxpd *rx_pd;
153 struct mwifiex_private *priv;
154 u16 pkt_len;
155
156 if (!skb)
157 return -1;
158
159 rx_pd = (struct rxpd *)skb->data;
160 priv = mwifiex_get_priv_by_id(adapter, rx_pd->bss_num, rx_pd->bss_type);
161 if (!priv)
162 return -1;
163
164 skb_pull(skb, le16_to_cpu(rx_pd->rx_pkt_offset));
165 skb_pull(skb, sizeof(pkt_len));
166
167 pkt_len = le16_to_cpu(rx_pd->rx_pkt_length);
168
169 /* Remove address4 */
170 memmove(skb->data + sizeof(struct ieee80211_hdr_3addr),
171 skb->data + sizeof(struct ieee80211_hdr),
172 pkt_len - sizeof(struct ieee80211_hdr));
173
174 pkt_len -= ETH_ALEN + sizeof(pkt_len);
175 rx_pd->rx_pkt_length = cpu_to_le16(pkt_len);
176
177 cfg80211_rx_mgmt(priv->wdev, priv->mgmt_rx_freq,
178 CAL_RSSI(rx_pd->snr, rx_pd->nf),
179 skb->data, pkt_len, GFP_ATOMIC);
180
181 return 0;
182}
183
184/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700185 * This function processes the received packet before sending it to the
186 * kernel.
187 *
188 * It extracts the SKB from the received buffer and sends it to kernel.
189 * In case the received buffer does not contain the data in SKB format,
190 * the function creates a blank SKB, fills it with the data from the
191 * received buffer and then sends this new SKB to the kernel.
192 */
193int mwifiex_recv_packet(struct mwifiex_adapter *adapter, struct sk_buff *skb)
194{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700195 struct mwifiex_rxinfo *rx_info;
196 struct mwifiex_private *priv;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700197
198 if (!skb)
199 return -1;
200
201 rx_info = MWIFIEX_SKB_RXCB(skb);
Yogesh Ashok Powar9da9a3b2012-01-11 20:06:11 -0800202 priv = mwifiex_get_priv_by_id(adapter, rx_info->bss_num,
Yogesh Ashok Powarc65a30f2012-03-13 19:22:42 -0700203 rx_info->bss_type);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700204 if (!priv)
205 return -1;
206
207 skb->dev = priv->netdev;
208 skb->protocol = eth_type_trans(skb, priv->netdev);
209 skb->ip_summed = CHECKSUM_NONE;
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700210
211 /* This is required only in case of 11n and USB as we alloc
212 * a buffer of 4K only if its 11N (to be able to receive 4K
213 * AMSDU packets). In case of SD we allocate buffers based
214 * on the size of packet and hence this is not needed.
215 *
216 * Modifying the truesize here as our allocation for each
217 * skb is 4K but we only receive 2K packets and this cause
218 * the kernel to start dropping packets in case where
219 * application has allocated buffer based on 2K size i.e.
220 * if there a 64K packet received (in IP fragments and
221 * application allocates 64K to receive this packet but
222 * this packet would almost double up because we allocate
223 * each 1.5K fragment in 4K and pass it up. As soon as the
224 * 64K limit hits kernel will start to drop rest of the
225 * fragments. Currently we fail the Filesndl-ht.scr script
226 * for UDP, hence this fix
227 */
228 if ((adapter->iface_type == MWIFIEX_USB) &&
229 (skb->truesize > MWIFIEX_RX_DATA_BUF_SIZE))
230 skb->truesize += (skb->len - MWIFIEX_RX_DATA_BUF_SIZE);
231
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700232 priv->stats.rx_bytes += skb->len;
233 priv->stats.rx_packets++;
234 if (in_interrupt())
235 netif_rx(skb);
236 else
237 netif_rx_ni(skb);
238
239 return 0;
240}
241
242/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700243 * IOCTL completion callback handler.
244 *
245 * This function is called when a pending IOCTL is completed.
246 *
247 * If work queue support is enabled, the function wakes up the
248 * corresponding waiting function. Otherwise, it processes the
249 * IOCTL response and frees the response buffer.
250 */
Amitkumar Karwarefaaa8b2011-10-12 20:28:06 -0700251int mwifiex_complete_cmd(struct mwifiex_adapter *adapter,
252 struct cmd_ctrl_node *cmd_node)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700253{
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700254 atomic_dec(&adapter->cmd_pending);
255 dev_dbg(adapter->dev, "cmd completed: status=%d\n",
Yogesh Ashok Powarc65a30f2012-03-13 19:22:42 -0700256 adapter->cmd_wait_q.status);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700257
Amitkumar Karwarefaaa8b2011-10-12 20:28:06 -0700258 *(cmd_node->condition) = true;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700259
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700260 if (adapter->cmd_wait_q.status == -ETIMEDOUT)
261 dev_err(adapter->dev, "cmd timeout\n");
262 else
263 wake_up_interruptible(&adapter->cmd_wait_q.wait);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700264
265 return 0;
266}