Revert "Merge branch 'ath6kl-next' of master.kernel.org:/pub/scm/linux/kernel/git...
[linux-2.6/next.git] / drivers / net / wireless / mwifiex / util.c
blobd41291529bc0f074c6721279051e24429c21ca2d
1 /*
2 * Marvell Wireless LAN device driver: utility functions
4 * Copyright (C) 2011, Marvell International Ltd.
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.
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.
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"
29 * Firmware initialization complete callback handler.
31 * This function wakes up the function waiting on the init
32 * wait queue for the firmware initialization to complete.
34 int mwifiex_init_fw_complete(struct mwifiex_adapter *adapter)
37 adapter->init_wait_q_woken = true;
38 wake_up_interruptible(&adapter->init_wait_q);
39 return 0;
43 * Firmware shutdown complete callback handler.
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.
49 int mwifiex_shutdown_fw_complete(struct mwifiex_adapter *adapter)
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;
58 * This function sends init/shutdown command
59 * to firmware.
61 int mwifiex_init_shutdown_fw(struct mwifiex_private *priv,
62 u32 func_init_shutdown)
64 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(priv->adapter->dev, "unsupported parameter\n");
72 return -1;
75 return mwifiex_send_cmd_sync(priv, cmd, HostCmd_ACT_GEN_SET, 0, NULL);
77 EXPORT_SYMBOL_GPL(mwifiex_init_shutdown_fw);
80 * IOCTL request handler to set/get debug information.
82 * This function collates/sets the information from/to different driver
83 * structures.
85 int mwifiex_get_debug_info(struct mwifiex_private *priv,
86 struct mwifiex_debug_info *info)
88 struct mwifiex_adapter *adapter = priv->adapter;
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;
96 info->rx_tbl_num = mwifiex_get_rx_reorder_tbl(
97 priv, info->rx_tbl);
98 info->tx_tbl_num = mwifiex_get_tx_ba_stream_tbl(
99 priv, info->tx_tbl);
100 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
108 = adapter->dbg.num_cmd_host_to_card_failure;
109 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
112 = adapter->dbg.num_tx_host_to_card_failure;
113 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 =
118 adapter->dbg.num_cmd_assoc_success;
119 info->num_cmd_assoc_failure =
120 adapter->dbg.num_cmd_assoc_failure;
121 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;
141 return 0;
145 * This function processes the received packet before sending it to the
146 * kernel.
148 * It extracts the SKB from the received buffer and sends it to kernel.
149 * In case the received buffer does not contain the data in SKB format,
150 * the function creates a blank SKB, fills it with the data from the
151 * received buffer and then sends this new SKB to the kernel.
153 int mwifiex_recv_packet(struct mwifiex_adapter *adapter, struct sk_buff *skb)
155 struct mwifiex_rxinfo *rx_info;
156 struct mwifiex_private *priv;
158 if (!skb)
159 return -1;
161 rx_info = MWIFIEX_SKB_RXCB(skb);
162 priv = mwifiex_bss_index_to_priv(adapter, rx_info->bss_index);
163 if (!priv)
164 return -1;
166 skb->dev = priv->netdev;
167 skb->protocol = eth_type_trans(skb, priv->netdev);
168 skb->ip_summed = CHECKSUM_NONE;
169 priv->stats.rx_bytes += skb->len;
170 priv->stats.rx_packets++;
171 if (in_interrupt())
172 netif_rx(skb);
173 else
174 netif_rx_ni(skb);
176 return 0;
180 * IOCTL completion callback handler.
182 * This function is called when a pending IOCTL is completed.
184 * If work queue support is enabled, the function wakes up the
185 * corresponding waiting function. Otherwise, it processes the
186 * IOCTL response and frees the response buffer.
188 int mwifiex_complete_cmd(struct mwifiex_adapter *adapter)
190 atomic_dec(&adapter->cmd_pending);
191 dev_dbg(adapter->dev, "cmd completed: status=%d\n",
192 adapter->cmd_wait_q.status);
194 adapter->cmd_wait_q.condition = true;
196 if (adapter->cmd_wait_q.status == -ETIMEDOUT)
197 dev_err(adapter->dev, "cmd timeout\n");
198 else
199 wake_up_interruptible(&adapter->cmd_wait_q.wait);
201 return 0;