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.
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
);
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
);
58 * IOCTL request handler to send function init/shutdown command
61 * This function prepares the correct firmware command and
64 int mwifiex_misc_ioctl_init_shutdown(struct mwifiex_adapter
*adapter
,
65 struct mwifiex_wait_queue
*wait
,
66 u32 func_init_shutdown
)
68 struct mwifiex_private
*priv
= adapter
->priv
[wait
->bss_index
];
72 if (func_init_shutdown
== MWIFIEX_FUNC_INIT
) {
73 cmd
= HostCmd_CMD_FUNC_INIT
;
74 } else if (func_init_shutdown
== MWIFIEX_FUNC_SHUTDOWN
) {
75 cmd
= HostCmd_CMD_FUNC_SHUTDOWN
;
77 dev_err(adapter
->dev
, "unsupported parameter\n");
81 /* Send command to firmware */
82 ret
= mwifiex_prepare_cmd(priv
, cmd
, HostCmd_ACT_GEN_SET
,
92 * IOCTL request handler to set/get debug information.
94 * This function collates/sets the information from/to different driver
97 int mwifiex_get_debug_info(struct mwifiex_private
*priv
,
98 struct mwifiex_debug_info
*info
)
100 struct mwifiex_adapter
*adapter
= priv
->adapter
;
103 memcpy(info
->packets_out
,
104 priv
->wmm
.packets_out
,
105 sizeof(priv
->wmm
.packets_out
));
106 info
->max_tx_buf_size
= (u32
) adapter
->max_tx_buf_size
;
107 info
->tx_buf_size
= (u32
) adapter
->tx_buf_size
;
108 info
->rx_tbl_num
= mwifiex_get_rx_reorder_tbl(
110 info
->tx_tbl_num
= mwifiex_get_tx_ba_stream_tbl(
112 info
->ps_mode
= adapter
->ps_mode
;
113 info
->ps_state
= adapter
->ps_state
;
114 info
->is_deep_sleep
= adapter
->is_deep_sleep
;
115 info
->pm_wakeup_card_req
= adapter
->pm_wakeup_card_req
;
116 info
->pm_wakeup_fw_try
= adapter
->pm_wakeup_fw_try
;
117 info
->is_hs_configured
= adapter
->is_hs_configured
;
118 info
->hs_activated
= adapter
->hs_activated
;
119 info
->num_cmd_host_to_card_failure
120 = adapter
->dbg
.num_cmd_host_to_card_failure
;
121 info
->num_cmd_sleep_cfm_host_to_card_failure
122 = adapter
->dbg
.num_cmd_sleep_cfm_host_to_card_failure
;
123 info
->num_tx_host_to_card_failure
124 = adapter
->dbg
.num_tx_host_to_card_failure
;
125 info
->num_event_deauth
= adapter
->dbg
.num_event_deauth
;
126 info
->num_event_disassoc
= adapter
->dbg
.num_event_disassoc
;
127 info
->num_event_link_lost
= adapter
->dbg
.num_event_link_lost
;
128 info
->num_cmd_deauth
= adapter
->dbg
.num_cmd_deauth
;
129 info
->num_cmd_assoc_success
=
130 adapter
->dbg
.num_cmd_assoc_success
;
131 info
->num_cmd_assoc_failure
=
132 adapter
->dbg
.num_cmd_assoc_failure
;
133 info
->num_tx_timeout
= adapter
->dbg
.num_tx_timeout
;
134 info
->num_cmd_timeout
= adapter
->dbg
.num_cmd_timeout
;
135 info
->timeout_cmd_id
= adapter
->dbg
.timeout_cmd_id
;
136 info
->timeout_cmd_act
= adapter
->dbg
.timeout_cmd_act
;
137 memcpy(info
->last_cmd_id
, adapter
->dbg
.last_cmd_id
,
138 sizeof(adapter
->dbg
.last_cmd_id
));
139 memcpy(info
->last_cmd_act
, adapter
->dbg
.last_cmd_act
,
140 sizeof(adapter
->dbg
.last_cmd_act
));
141 info
->last_cmd_index
= adapter
->dbg
.last_cmd_index
;
142 memcpy(info
->last_cmd_resp_id
, adapter
->dbg
.last_cmd_resp_id
,
143 sizeof(adapter
->dbg
.last_cmd_resp_id
));
144 info
->last_cmd_resp_index
= adapter
->dbg
.last_cmd_resp_index
;
145 memcpy(info
->last_event
, adapter
->dbg
.last_event
,
146 sizeof(adapter
->dbg
.last_event
));
147 info
->last_event_index
= adapter
->dbg
.last_event_index
;
148 info
->data_sent
= adapter
->data_sent
;
149 info
->cmd_sent
= adapter
->cmd_sent
;
150 info
->cmd_resp_received
= adapter
->cmd_resp_received
;
157 * This function processes the received packet before sending it to the
160 * It extracts the SKB from the received buffer and sends it to kernel.
161 * In case the received buffer does not contain the data in SKB format,
162 * the function creates a blank SKB, fills it with the data from the
163 * received buffer and then sends this new SKB to the kernel.
165 int mwifiex_recv_packet(struct mwifiex_adapter
*adapter
, struct sk_buff
*skb
)
167 struct mwifiex_rxinfo
*rx_info
= NULL
;
168 struct mwifiex_private
*priv
= NULL
;
173 rx_info
= MWIFIEX_SKB_RXCB(skb
);
174 priv
= mwifiex_bss_index_to_priv(adapter
, rx_info
->bss_index
);
178 skb
->dev
= priv
->netdev
;
179 skb
->protocol
= eth_type_trans(skb
, priv
->netdev
);
180 skb
->ip_summed
= CHECKSUM_NONE
;
181 priv
->stats
.rx_bytes
+= skb
->len
;
182 priv
->stats
.rx_packets
++;
192 * Receive packet completion callback handler.
194 * This function updates the statistics and frees the buffer SKB.
196 int mwifiex_recv_complete(struct mwifiex_adapter
*adapter
,
197 struct sk_buff
*skb
, int status
)
199 struct mwifiex_private
*priv
= NULL
;
200 struct mwifiex_rxinfo
*rx_info
= NULL
;
205 rx_info
= MWIFIEX_SKB_RXCB(skb
);
206 priv
= mwifiex_bss_index_to_priv(adapter
, rx_info
->bss_index
);
208 if (priv
&& (status
== -1))
209 priv
->stats
.rx_dropped
++;
211 dev_kfree_skb_any(skb
);
217 * IOCTL completion callback handler.
219 * This function is called when a pending IOCTL is completed.
221 * If work queue support is enabled, the function wakes up the
222 * corresponding waiting function. Otherwise, it processes the
223 * IOCTL response and frees the response buffer.
225 int mwifiex_ioctl_complete(struct mwifiex_adapter
*adapter
,
226 struct mwifiex_wait_queue
*wait_queue
,
229 enum mwifiex_error_code status_code
=
230 (enum mwifiex_error_code
) wait_queue
->status
;
232 atomic_dec(&adapter
->ioctl_pending
);
234 dev_dbg(adapter
->dev
, "cmd: IOCTL completed: status=%d,"
235 " status_code=%#x\n", status
, status_code
);
237 if (wait_queue
->enabled
) {
238 *wait_queue
->condition
= true;
239 wait_queue
->status
= status
;
240 if (status
&& (status_code
== MWIFIEX_ERROR_CMD_TIMEOUT
))
241 dev_err(adapter
->dev
, "cmd timeout\n");
243 wake_up_interruptible(wait_queue
->wait
);
246 dev_err(adapter
->dev
, "cmd failed: status_code=%#x\n",