blob: 75eaa6f877fa5b0bf2e3a902b35158d7aac987ae [file] [log] [blame]
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001/*
2 * Marvell Wireless LAN device driver: station command handling
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 * This function prepares command to set/get RSSI information.
30 *
31 * Preparation includes -
32 * - Setting command ID, action and proper size
33 * - Setting data/beacon average factors
34 * - Resetting SNR/NF/RSSI values in private structure
35 * - Ensuring correct endian-ness
36 */
37static int
38mwifiex_cmd_802_11_rssi_info(struct mwifiex_private *priv,
39 struct host_cmd_ds_command *cmd, u16 cmd_action)
40{
41 cmd->command = cpu_to_le16(HostCmd_CMD_RSSI_INFO);
42 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_rssi_info) +
43 S_DS_GEN);
44 cmd->params.rssi_info.action = cpu_to_le16(cmd_action);
45 cmd->params.rssi_info.ndata = cpu_to_le16(priv->data_avg_factor);
46 cmd->params.rssi_info.nbcn = cpu_to_le16(priv->bcn_avg_factor);
47
48 /* Reset SNR/NF/RSSI values in private structure */
49 priv->data_rssi_last = 0;
50 priv->data_nf_last = 0;
51 priv->data_rssi_avg = 0;
52 priv->data_nf_avg = 0;
53 priv->bcn_rssi_last = 0;
54 priv->bcn_nf_last = 0;
55 priv->bcn_rssi_avg = 0;
56 priv->bcn_nf_avg = 0;
57
58 return 0;
59}
60
61/*
62 * This function prepares command to set MAC control.
63 *
64 * Preparation includes -
65 * - Setting command ID, action and proper size
66 * - Ensuring correct endian-ness
67 */
68static int mwifiex_cmd_mac_control(struct mwifiex_private *priv,
69 struct host_cmd_ds_command *cmd,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -070070 u16 cmd_action, u16 *action)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070071{
72 struct host_cmd_ds_mac_control *mac_ctrl = &cmd->params.mac_ctrl;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070073
74 if (cmd_action != HostCmd_ACT_GEN_SET) {
75 dev_err(priv->adapter->dev,
76 "mac_control: only support set cmd\n");
77 return -1;
78 }
79
80 cmd->command = cpu_to_le16(HostCmd_CMD_MAC_CONTROL);
81 cmd->size =
82 cpu_to_le16(sizeof(struct host_cmd_ds_mac_control) + S_DS_GEN);
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -070083 mac_ctrl->action = cpu_to_le16(*action);
Bing Zhao5e6e3a92011-03-21 18:00:50 -070084
85 return 0;
86}
87
88/*
89 * This function prepares command to set/get SNMP MIB.
90 *
91 * Preparation includes -
92 * - Setting command ID, action and proper size
93 * - Setting SNMP MIB OID number and value
94 * (as required)
95 * - Ensuring correct endian-ness
96 *
97 * The following SNMP MIB OIDs are supported -
98 * - FRAG_THRESH_I : Fragmentation threshold
99 * - RTS_THRESH_I : RTS threshold
100 * - SHORT_RETRY_LIM_I : Short retry limit
101 * - DOT11D_I : 11d support
102 */
103static int mwifiex_cmd_802_11_snmp_mib(struct mwifiex_private *priv,
104 struct host_cmd_ds_command *cmd,
105 u16 cmd_action, u32 cmd_oid,
Amitkumar Karwarf3c8d252012-02-02 20:48:57 -0800106 u16 *ul_temp)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700107{
108 struct host_cmd_ds_802_11_snmp_mib *snmp_mib = &cmd->params.smib;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700109
110 dev_dbg(priv->adapter->dev, "cmd: SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid);
111 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SNMP_MIB);
112 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_snmp_mib)
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700113 - 1 + S_DS_GEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700114
Amitkumar Karwarf3c8d252012-02-02 20:48:57 -0800115 snmp_mib->oid = cpu_to_le16((u16)cmd_oid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700116 if (cmd_action == HostCmd_ACT_GEN_GET) {
117 snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_GET);
118 snmp_mib->buf_size = cpu_to_le16(MAX_SNMP_BUF_SIZE);
Amitkumar Karwarf3c8d252012-02-02 20:48:57 -0800119 le16_add_cpu(&cmd->size, MAX_SNMP_BUF_SIZE);
120 } else if (cmd_action == HostCmd_ACT_GEN_SET) {
121 snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_SET);
122 snmp_mib->buf_size = cpu_to_le16(sizeof(u16));
123 *((__le16 *) (snmp_mib->value)) = cpu_to_le16(*ul_temp);
124 le16_add_cpu(&cmd->size, sizeof(u16));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700125 }
126
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700127 dev_dbg(priv->adapter->dev,
128 "cmd: SNMP_CMD: Action=0x%x, OID=0x%x, OIDSize=0x%x,"
129 " Value=0x%x\n",
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700130 cmd_action, cmd_oid, le16_to_cpu(snmp_mib->buf_size),
131 le16_to_cpu(*(__le16 *) snmp_mib->value));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700132 return 0;
133}
134
135/*
136 * This function prepares command to get log.
137 *
138 * Preparation includes -
139 * - Setting command ID and proper size
140 * - Ensuring correct endian-ness
141 */
142static int
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700143mwifiex_cmd_802_11_get_log(struct host_cmd_ds_command *cmd)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700144{
145 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_GET_LOG);
146 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_get_log) +
147 S_DS_GEN);
148 return 0;
149}
150
151/*
152 * This function prepares command to set/get Tx data rate configuration.
153 *
154 * Preparation includes -
155 * - Setting command ID, action and proper size
156 * - Setting configuration index, rate scope and rate drop pattern
157 * parameters (as required)
158 * - Ensuring correct endian-ness
159 */
160static int mwifiex_cmd_tx_rate_cfg(struct mwifiex_private *priv,
161 struct host_cmd_ds_command *cmd,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700162 u16 cmd_action, u16 *pbitmap_rates)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700163{
164 struct host_cmd_ds_tx_rate_cfg *rate_cfg = &cmd->params.tx_rate_cfg;
165 struct mwifiex_rate_scope *rate_scope;
166 struct mwifiex_rate_drop_pattern *rate_drop;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700167 u32 i;
168
169 cmd->command = cpu_to_le16(HostCmd_CMD_TX_RATE_CFG);
170
171 rate_cfg->action = cpu_to_le16(cmd_action);
172 rate_cfg->cfg_index = 0;
173
174 rate_scope = (struct mwifiex_rate_scope *) ((u8 *) rate_cfg +
175 sizeof(struct host_cmd_ds_tx_rate_cfg));
176 rate_scope->type = cpu_to_le16(TLV_TYPE_RATE_SCOPE);
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700177 rate_scope->length = cpu_to_le16
178 (sizeof(*rate_scope) - sizeof(struct mwifiex_ie_types_header));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700179 if (pbitmap_rates != NULL) {
180 rate_scope->hr_dsss_rate_bitmap = cpu_to_le16(pbitmap_rates[0]);
181 rate_scope->ofdm_rate_bitmap = cpu_to_le16(pbitmap_rates[1]);
182 for (i = 0;
183 i < sizeof(rate_scope->ht_mcs_rate_bitmap) / sizeof(u16);
184 i++)
185 rate_scope->ht_mcs_rate_bitmap[i] =
186 cpu_to_le16(pbitmap_rates[2 + i]);
187 } else {
188 rate_scope->hr_dsss_rate_bitmap =
189 cpu_to_le16(priv->bitmap_rates[0]);
190 rate_scope->ofdm_rate_bitmap =
191 cpu_to_le16(priv->bitmap_rates[1]);
192 for (i = 0;
193 i < sizeof(rate_scope->ht_mcs_rate_bitmap) / sizeof(u16);
194 i++)
195 rate_scope->ht_mcs_rate_bitmap[i] =
196 cpu_to_le16(priv->bitmap_rates[2 + i]);
197 }
198
199 rate_drop = (struct mwifiex_rate_drop_pattern *) ((u8 *) rate_scope +
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700200 sizeof(struct mwifiex_rate_scope));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700201 rate_drop->type = cpu_to_le16(TLV_TYPE_RATE_DROP_CONTROL);
202 rate_drop->length = cpu_to_le16(sizeof(rate_drop->rate_drop_mode));
203 rate_drop->rate_drop_mode = 0;
204
205 cmd->size =
206 cpu_to_le16(S_DS_GEN + sizeof(struct host_cmd_ds_tx_rate_cfg) +
207 sizeof(struct mwifiex_rate_scope) +
208 sizeof(struct mwifiex_rate_drop_pattern));
209
210 return 0;
211}
212
213/*
214 * This function prepares command to set/get Tx power configuration.
215 *
216 * Preparation includes -
217 * - Setting command ID, action and proper size
218 * - Setting Tx power mode, power group TLV
219 * (as required)
220 * - Ensuring correct endian-ness
221 */
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700222static int mwifiex_cmd_tx_power_cfg(struct host_cmd_ds_command *cmd,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700223 u16 cmd_action,
224 struct host_cmd_ds_txpwr_cfg *txp)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700225{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700226 struct mwifiex_types_power_group *pg_tlv;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700227 struct host_cmd_ds_txpwr_cfg *cmd_txp_cfg = &cmd->params.txp_cfg;
228
229 cmd->command = cpu_to_le16(HostCmd_CMD_TXPWR_CFG);
230 cmd->size =
231 cpu_to_le16(S_DS_GEN + sizeof(struct host_cmd_ds_txpwr_cfg));
232 switch (cmd_action) {
233 case HostCmd_ACT_GEN_SET:
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700234 if (txp->mode) {
235 pg_tlv = (struct mwifiex_types_power_group
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700236 *) ((unsigned long) txp +
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700237 sizeof(struct host_cmd_ds_txpwr_cfg));
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700238 memmove(cmd_txp_cfg, txp,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700239 sizeof(struct host_cmd_ds_txpwr_cfg) +
240 sizeof(struct mwifiex_types_power_group) +
241 pg_tlv->length);
242
243 pg_tlv = (struct mwifiex_types_power_group *) ((u8 *)
244 cmd_txp_cfg +
245 sizeof(struct host_cmd_ds_txpwr_cfg));
246 cmd->size = cpu_to_le16(le16_to_cpu(cmd->size) +
247 sizeof(struct mwifiex_types_power_group) +
248 pg_tlv->length);
249 } else {
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700250 memmove(cmd_txp_cfg, txp, sizeof(*txp));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700251 }
252 cmd_txp_cfg->action = cpu_to_le16(cmd_action);
253 break;
254 case HostCmd_ACT_GEN_GET:
255 cmd_txp_cfg->action = cpu_to_le16(cmd_action);
256 break;
257 }
258
259 return 0;
260}
261
262/*
Amitkumar Karwarcaa89842012-06-27 19:57:57 -0700263 * This function prepares command to get RF Tx power.
264 */
265static int mwifiex_cmd_rf_tx_power(struct mwifiex_private *priv,
266 struct host_cmd_ds_command *cmd,
267 u16 cmd_action, void *data_buf)
268{
269 struct host_cmd_ds_rf_tx_pwr *txp = &cmd->params.txp;
270
271 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_rf_tx_pwr)
272 + S_DS_GEN);
273 cmd->command = cpu_to_le16(HostCmd_CMD_RF_TX_PWR);
274 txp->action = cpu_to_le16(cmd_action);
275
276 return 0;
277}
278
279/*
Amitkumar Karwar8a279d52012-07-02 19:32:33 -0700280 * This function prepares command to set rf antenna.
281 */
282static int mwifiex_cmd_rf_antenna(struct mwifiex_private *priv,
283 struct host_cmd_ds_command *cmd,
284 u16 cmd_action,
285 struct mwifiex_ds_ant_cfg *ant_cfg)
286{
287 struct host_cmd_ds_rf_ant_mimo *ant_mimo = &cmd->params.ant_mimo;
288 struct host_cmd_ds_rf_ant_siso *ant_siso = &cmd->params.ant_siso;
289
290 cmd->command = cpu_to_le16(HostCmd_CMD_RF_ANTENNA);
291
292 if (cmd_action != HostCmd_ACT_GEN_SET)
293 return 0;
294
295 if (priv->adapter->hw_dev_mcs_support == HT_STREAM_2X2) {
296 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_rf_ant_mimo) +
297 S_DS_GEN);
298 ant_mimo->action_tx = cpu_to_le16(HostCmd_ACT_SET_TX);
299 ant_mimo->tx_ant_mode = cpu_to_le16((u16)ant_cfg->tx_ant);
300 ant_mimo->action_rx = cpu_to_le16(HostCmd_ACT_SET_RX);
301 ant_mimo->rx_ant_mode = cpu_to_le16((u16)ant_cfg->rx_ant);
302 } else {
303 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_rf_ant_siso) +
304 S_DS_GEN);
305 ant_siso->action = cpu_to_le16(HostCmd_ACT_SET_BOTH);
306 ant_siso->ant_mode = cpu_to_le16((u16)ant_cfg->tx_ant);
307 }
308
309 return 0;
310}
311
312/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700313 * This function prepares command to set Host Sleep configuration.
314 *
315 * Preparation includes -
316 * - Setting command ID and proper size
317 * - Setting Host Sleep action, conditions, ARP filters
318 * (as required)
319 * - Ensuring correct endian-ness
320 */
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700321static int
322mwifiex_cmd_802_11_hs_cfg(struct mwifiex_private *priv,
323 struct host_cmd_ds_command *cmd,
324 u16 cmd_action,
325 struct mwifiex_hs_config_param *hscfg_param)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700326{
327 struct mwifiex_adapter *adapter = priv->adapter;
328 struct host_cmd_ds_802_11_hs_cfg_enh *hs_cfg = &cmd->params.opt_hs_cfg;
329 u16 hs_activate = false;
330
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700331 if (!hscfg_param)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700332 /* New Activate command */
333 hs_activate = true;
334 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_HS_CFG_ENH);
335
336 if (!hs_activate &&
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700337 (hscfg_param->conditions != cpu_to_le32(HOST_SLEEP_CFG_CANCEL)) &&
338 ((adapter->arp_filter_size > 0) &&
339 (adapter->arp_filter_size <= ARP_FILTER_MAX_BUF_SIZE))) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700340 dev_dbg(adapter->dev,
341 "cmd: Attach %d bytes ArpFilter to HSCfg cmd\n",
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700342 adapter->arp_filter_size);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700343 memcpy(((u8 *) hs_cfg) +
344 sizeof(struct host_cmd_ds_802_11_hs_cfg_enh),
345 adapter->arp_filter, adapter->arp_filter_size);
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700346 cmd->size = cpu_to_le16
347 (adapter->arp_filter_size +
348 sizeof(struct host_cmd_ds_802_11_hs_cfg_enh)
349 + S_DS_GEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700350 } else {
351 cmd->size = cpu_to_le16(S_DS_GEN + sizeof(struct
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700352 host_cmd_ds_802_11_hs_cfg_enh));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700353 }
354 if (hs_activate) {
355 hs_cfg->action = cpu_to_le16(HS_ACTIVATE);
356 hs_cfg->params.hs_activate.resp_ctrl = RESP_NEEDED;
357 } else {
358 hs_cfg->action = cpu_to_le16(HS_CONFIGURE);
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700359 hs_cfg->params.hs_config.conditions = hscfg_param->conditions;
360 hs_cfg->params.hs_config.gpio = hscfg_param->gpio;
361 hs_cfg->params.hs_config.gap = hscfg_param->gap;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700362 dev_dbg(adapter->dev,
363 "cmd: HS_CFG_CMD: condition:0x%x gpio:0x%x gap:0x%x\n",
364 hs_cfg->params.hs_config.conditions,
365 hs_cfg->params.hs_config.gpio,
366 hs_cfg->params.hs_config.gap);
367 }
368
369 return 0;
370}
371
372/*
373 * This function prepares command to set/get MAC address.
374 *
375 * Preparation includes -
376 * - Setting command ID, action and proper size
377 * - Setting MAC address (for SET only)
378 * - Ensuring correct endian-ness
379 */
380static int mwifiex_cmd_802_11_mac_address(struct mwifiex_private *priv,
381 struct host_cmd_ds_command *cmd,
382 u16 cmd_action)
383{
384 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_MAC_ADDRESS);
385 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_mac_address) +
386 S_DS_GEN);
387 cmd->result = 0;
388
389 cmd->params.mac_addr.action = cpu_to_le16(cmd_action);
390
391 if (cmd_action == HostCmd_ACT_GEN_SET)
392 memcpy(cmd->params.mac_addr.mac_addr, priv->curr_addr,
393 ETH_ALEN);
394 return 0;
395}
396
397/*
398 * This function prepares command to set MAC multicast address.
399 *
400 * Preparation includes -
401 * - Setting command ID, action and proper size
402 * - Setting MAC multicast address
403 * - Ensuring correct endian-ness
404 */
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700405static int
406mwifiex_cmd_mac_multicast_adr(struct host_cmd_ds_command *cmd,
407 u16 cmd_action,
408 struct mwifiex_multicast_list *mcast_list)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700409{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700410 struct host_cmd_ds_mac_multicast_adr *mcast_addr = &cmd->params.mc_addr;
411
412 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_mac_multicast_adr) +
413 S_DS_GEN);
414 cmd->command = cpu_to_le16(HostCmd_CMD_MAC_MULTICAST_ADR);
415
416 mcast_addr->action = cpu_to_le16(cmd_action);
417 mcast_addr->num_of_adrs =
418 cpu_to_le16((u16) mcast_list->num_multicast_addr);
419 memcpy(mcast_addr->mac_list, mcast_list->mac_list,
420 mcast_list->num_multicast_addr * ETH_ALEN);
421
422 return 0;
423}
424
425/*
426 * This function prepares command to deauthenticate.
427 *
428 * Preparation includes -
429 * - Setting command ID and proper size
430 * - Setting AP MAC address and reason code
431 * - Ensuring correct endian-ness
432 */
433static int mwifiex_cmd_802_11_deauthenticate(struct mwifiex_private *priv,
434 struct host_cmd_ds_command *cmd,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700435 u8 *mac)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700436{
437 struct host_cmd_ds_802_11_deauthenticate *deauth = &cmd->params.deauth;
438
439 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_DEAUTHENTICATE);
440 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_deauthenticate)
441 + S_DS_GEN);
442
443 /* Set AP MAC address */
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700444 memcpy(deauth->mac_addr, mac, ETH_ALEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700445
446 dev_dbg(priv->adapter->dev, "cmd: Deauth: %pM\n", deauth->mac_addr);
447
448 deauth->reason_code = cpu_to_le16(WLAN_REASON_DEAUTH_LEAVING);
449
450 return 0;
451}
452
453/*
454 * This function prepares command to stop Ad-Hoc network.
455 *
456 * Preparation includes -
457 * - Setting command ID and proper size
458 * - Ensuring correct endian-ness
459 */
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700460static int mwifiex_cmd_802_11_ad_hoc_stop(struct host_cmd_ds_command *cmd)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700461{
462 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_STOP);
463 cmd->size = cpu_to_le16(S_DS_GEN);
464 return 0;
465}
466
467/*
468 * This function sets WEP key(s) to key parameter TLV(s).
469 *
470 * Multi-key parameter TLVs are supported, so we can send multiple
471 * WEP keys in a single buffer.
472 */
473static int
474mwifiex_set_keyparamset_wep(struct mwifiex_private *priv,
475 struct mwifiex_ie_type_key_param_set *key_param_set,
476 u16 *key_param_len)
477{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700478 int cur_key_param_len;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700479 u8 i;
480
481 /* Multi-key_param_set TLV is supported */
482 for (i = 0; i < NUM_WEP_KEYS; i++) {
483 if ((priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP40) ||
484 (priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP104)) {
485 key_param_set->type =
486 cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
487/* Key_param_set WEP fixed length */
488#define KEYPARAMSET_WEP_FIXED_LEN 8
489 key_param_set->length = cpu_to_le16((u16)
490 (priv->wep_key[i].
491 key_length +
492 KEYPARAMSET_WEP_FIXED_LEN));
493 key_param_set->key_type_id =
494 cpu_to_le16(KEY_TYPE_ID_WEP);
495 key_param_set->key_info =
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -0700496 cpu_to_le16(KEY_ENABLED | KEY_UNICAST |
497 KEY_MCAST);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700498 key_param_set->key_len =
499 cpu_to_le16(priv->wep_key[i].key_length);
500 /* Set WEP key index */
501 key_param_set->key[0] = i;
502 /* Set default Tx key flag */
503 if (i ==
504 (priv->
505 wep_key_curr_index & HostCmd_WEP_KEY_INDEX_MASK))
506 key_param_set->key[1] = 1;
507 else
508 key_param_set->key[1] = 0;
509 memmove(&key_param_set->key[2],
510 priv->wep_key[i].key_material,
511 priv->wep_key[i].key_length);
512
513 cur_key_param_len = priv->wep_key[i].key_length +
514 KEYPARAMSET_WEP_FIXED_LEN +
515 sizeof(struct mwifiex_ie_types_header);
516 *key_param_len += (u16) cur_key_param_len;
517 key_param_set =
518 (struct mwifiex_ie_type_key_param_set *)
519 ((u8 *)key_param_set +
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700520 cur_key_param_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700521 } else if (!priv->wep_key[i].key_length) {
522 continue;
523 } else {
524 dev_err(priv->adapter->dev,
525 "key%d Length = %d is incorrect\n",
526 (i + 1), priv->wep_key[i].key_length);
527 return -1;
528 }
529 }
530
531 return 0;
532}
533
534/*
535 * This function prepares command to set/get/reset network key(s).
536 *
537 * Preparation includes -
538 * - Setting command ID, action and proper size
539 * - Setting WEP keys, WAPI keys or WPA keys along with required
540 * encryption (TKIP, AES) (as required)
541 * - Ensuring correct endian-ness
542 */
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700543static int
544mwifiex_cmd_802_11_key_material(struct mwifiex_private *priv,
545 struct host_cmd_ds_command *cmd,
546 u16 cmd_action, u32 cmd_oid,
547 struct mwifiex_ds_encrypt_key *enc_key)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700548{
549 struct host_cmd_ds_802_11_key_material *key_material =
550 &cmd->params.key_material;
Avinash Patil75edd2c2012-05-08 18:30:18 -0700551 struct host_cmd_tlv_mac_addr *tlv_mac;
552 u16 key_param_len = 0, cmd_size;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700553 int ret = 0;
554 const u8 bc_mac[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
555
556 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_KEY_MATERIAL);
557 key_material->action = cpu_to_le16(cmd_action);
558
559 if (cmd_action == HostCmd_ACT_GEN_GET) {
560 cmd->size =
561 cpu_to_le16(sizeof(key_material->action) + S_DS_GEN);
562 return ret;
563 }
564
565 if (!enc_key) {
566 memset(&key_material->key_param_set, 0,
567 (NUM_WEP_KEYS *
568 sizeof(struct mwifiex_ie_type_key_param_set)));
569 ret = mwifiex_set_keyparamset_wep(priv,
570 &key_material->key_param_set,
571 &key_param_len);
572 cmd->size = cpu_to_le16(key_param_len +
573 sizeof(key_material->action) + S_DS_GEN);
574 return ret;
575 } else
576 memset(&key_material->key_param_set, 0,
577 sizeof(struct mwifiex_ie_type_key_param_set));
578 if (enc_key->is_wapi_key) {
579 dev_dbg(priv->adapter->dev, "info: Set WAPI Key\n");
580 key_material->key_param_set.key_type_id =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700581 cpu_to_le16(KEY_TYPE_ID_WAPI);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700582 if (cmd_oid == KEY_INFO_ENABLED)
583 key_material->key_param_set.key_info =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700584 cpu_to_le16(KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700585 else
586 key_material->key_param_set.key_info =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700587 cpu_to_le16(!KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700588
589 key_material->key_param_set.key[0] = enc_key->key_index;
590 if (!priv->sec_info.wapi_key_on)
591 key_material->key_param_set.key[1] = 1;
592 else
593 /* set 0 when re-key */
594 key_material->key_param_set.key[1] = 0;
595
596 if (0 != memcmp(enc_key->mac_addr, bc_mac, sizeof(bc_mac))) {
597 /* WAPI pairwise key: unicast */
598 key_material->key_param_set.key_info |=
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -0700599 cpu_to_le16(KEY_UNICAST);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700600 } else { /* WAPI group key: multicast */
601 key_material->key_param_set.key_info |=
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -0700602 cpu_to_le16(KEY_MCAST);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700603 priv->sec_info.wapi_key_on = true;
604 }
605
606 key_material->key_param_set.type =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700607 cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700608 key_material->key_param_set.key_len =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700609 cpu_to_le16(WAPI_KEY_LEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700610 memcpy(&key_material->key_param_set.key[2],
611 enc_key->key_material, enc_key->key_len);
612 memcpy(&key_material->key_param_set.key[2 + enc_key->key_len],
613 enc_key->wapi_rxpn, WAPI_RXPN_LEN);
614 key_material->key_param_set.length =
615 cpu_to_le16(WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN);
616
617 key_param_len = (WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN) +
618 sizeof(struct mwifiex_ie_types_header);
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700619 cmd->size = cpu_to_le16(sizeof(key_material->action)
620 + S_DS_GEN + key_param_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700621 return ret;
622 }
623 if (enc_key->key_len == WLAN_KEY_LEN_CCMP) {
624 dev_dbg(priv->adapter->dev, "cmd: WPA_AES\n");
625 key_material->key_param_set.key_type_id =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700626 cpu_to_le16(KEY_TYPE_ID_AES);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700627 if (cmd_oid == KEY_INFO_ENABLED)
628 key_material->key_param_set.key_info =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700629 cpu_to_le16(KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700630 else
631 key_material->key_param_set.key_info =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700632 cpu_to_le16(!KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700633
634 if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
635 /* AES pairwise key: unicast */
636 key_material->key_param_set.key_info |=
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700637 cpu_to_le16(KEY_UNICAST);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700638 else /* AES group key: multicast */
639 key_material->key_param_set.key_info |=
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700640 cpu_to_le16(KEY_MCAST);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700641 } else if (enc_key->key_len == WLAN_KEY_LEN_TKIP) {
642 dev_dbg(priv->adapter->dev, "cmd: WPA_TKIP\n");
643 key_material->key_param_set.key_type_id =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700644 cpu_to_le16(KEY_TYPE_ID_TKIP);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700645 key_material->key_param_set.key_info =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700646 cpu_to_le16(KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700647
648 if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
649 /* TKIP pairwise key: unicast */
650 key_material->key_param_set.key_info |=
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700651 cpu_to_le16(KEY_UNICAST);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700652 else /* TKIP group key: multicast */
653 key_material->key_param_set.key_info |=
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700654 cpu_to_le16(KEY_MCAST);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700655 }
656
657 if (key_material->key_param_set.key_type_id) {
658 key_material->key_param_set.type =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700659 cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700660 key_material->key_param_set.key_len =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700661 cpu_to_le16((u16) enc_key->key_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700662 memcpy(key_material->key_param_set.key, enc_key->key_material,
663 enc_key->key_len);
664 key_material->key_param_set.length =
665 cpu_to_le16((u16) enc_key->key_len +
666 KEYPARAMSET_FIXED_LEN);
667
Avinash Patil75edd2c2012-05-08 18:30:18 -0700668 key_param_len = (u16)(enc_key->key_len + KEYPARAMSET_FIXED_LEN)
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700669 + sizeof(struct mwifiex_ie_types_header);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700670
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700671 cmd->size = cpu_to_le16(sizeof(key_material->action) + S_DS_GEN
672 + key_param_len);
Avinash Patil75edd2c2012-05-08 18:30:18 -0700673
674 if (priv->bss_type == MWIFIEX_BSS_TYPE_UAP) {
675 tlv_mac = (void *)((u8 *)&key_material->key_param_set +
676 key_param_len);
677 tlv_mac->tlv.type = cpu_to_le16(TLV_TYPE_STA_MAC_ADDR);
678 tlv_mac->tlv.len = cpu_to_le16(ETH_ALEN);
679 memcpy(tlv_mac->mac_addr, enc_key->mac_addr, ETH_ALEN);
680 cmd_size = key_param_len + S_DS_GEN +
681 sizeof(key_material->action) +
682 sizeof(struct host_cmd_tlv_mac_addr);
683 } else {
684 cmd_size = key_param_len + S_DS_GEN +
685 sizeof(key_material->action);
686 }
687 cmd->size = cpu_to_le16(cmd_size);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700688 }
689
690 return ret;
691}
692
693/*
694 * This function prepares command to set/get 11d domain information.
695 *
696 * Preparation includes -
697 * - Setting command ID, action and proper size
698 * - Setting domain information fields (for SET only)
699 * - Ensuring correct endian-ness
700 */
701static int mwifiex_cmd_802_11d_domain_info(struct mwifiex_private *priv,
702 struct host_cmd_ds_command *cmd,
703 u16 cmd_action)
704{
705 struct mwifiex_adapter *adapter = priv->adapter;
706 struct host_cmd_ds_802_11d_domain_info *domain_info =
707 &cmd->params.domain_info;
708 struct mwifiex_ietypes_domain_param_set *domain =
709 &domain_info->domain;
710 u8 no_of_triplet = adapter->domain_reg.no_of_triplet;
711
712 dev_dbg(adapter->dev, "info: 11D: no_of_triplet=0x%x\n", no_of_triplet);
713
714 cmd->command = cpu_to_le16(HostCmd_CMD_802_11D_DOMAIN_INFO);
715 domain_info->action = cpu_to_le16(cmd_action);
716 if (cmd_action == HostCmd_ACT_GEN_GET) {
717 cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
718 return 0;
719 }
720
721 /* Set domain info fields */
722 domain->header.type = cpu_to_le16(WLAN_EID_COUNTRY);
723 memcpy(domain->country_code, adapter->domain_reg.country_code,
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700724 sizeof(domain->country_code));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700725
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700726 domain->header.len =
727 cpu_to_le16((no_of_triplet *
728 sizeof(struct ieee80211_country_ie_triplet))
729 + sizeof(domain->country_code));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700730
731 if (no_of_triplet) {
732 memcpy(domain->triplet, adapter->domain_reg.triplet,
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700733 no_of_triplet * sizeof(struct
734 ieee80211_country_ie_triplet));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700735
736 cmd->size = cpu_to_le16(sizeof(domain_info->action) +
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700737 le16_to_cpu(domain->header.len) +
738 sizeof(struct mwifiex_ie_types_header)
739 + S_DS_GEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700740 } else {
741 cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
742 }
743
744 return 0;
745}
746
747/*
748 * This function prepares command to set/get RF channel.
749 *
750 * Preparation includes -
751 * - Setting command ID, action and proper size
752 * - Setting RF type and current RF channel (for SET only)
753 * - Ensuring correct endian-ness
754 */
755static int mwifiex_cmd_802_11_rf_channel(struct mwifiex_private *priv,
756 struct host_cmd_ds_command *cmd,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700757 u16 cmd_action, u16 *channel)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700758{
759 struct host_cmd_ds_802_11_rf_channel *rf_chan =
760 &cmd->params.rf_channel;
761 uint16_t rf_type = le16_to_cpu(rf_chan->rf_type);
762
763 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_RF_CHANNEL);
764 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_rf_channel)
765 + S_DS_GEN);
766
767 if (cmd_action == HostCmd_ACT_GEN_SET) {
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700768 if ((priv->adapter->adhoc_start_band & BAND_A) ||
769 (priv->adapter->adhoc_start_band & BAND_AN))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700770 rf_chan->rf_type =
771 cpu_to_le16(HostCmd_SCAN_RADIO_TYPE_A);
772
773 rf_type = le16_to_cpu(rf_chan->rf_type);
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -0800774 SET_SECONDARYCHAN(rf_type, priv->adapter->sec_chan_offset);
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700775 rf_chan->current_channel = cpu_to_le16(*channel);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700776 }
777 rf_chan->action = cpu_to_le16(cmd_action);
778 return 0;
779}
780
781/*
782 * This function prepares command to set/get IBSS coalescing status.
783 *
784 * Preparation includes -
785 * - Setting command ID, action and proper size
786 * - Setting status to enable or disable (for SET only)
787 * - Ensuring correct endian-ness
788 */
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700789static int mwifiex_cmd_ibss_coalescing_status(struct host_cmd_ds_command *cmd,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700790 u16 cmd_action, u16 *enable)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700791{
792 struct host_cmd_ds_802_11_ibss_status *ibss_coal =
793 &(cmd->params.ibss_coalescing);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700794
795 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_IBSS_COALESCING_STATUS);
796 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_ibss_status) +
797 S_DS_GEN);
798 cmd->result = 0;
799 ibss_coal->action = cpu_to_le16(cmd_action);
800
801 switch (cmd_action) {
802 case HostCmd_ACT_GEN_SET:
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700803 if (enable)
804 ibss_coal->enable = cpu_to_le16(*enable);
Dan Carpentera5e5aa62011-06-24 16:33:35 +0300805 else
806 ibss_coal->enable = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700807 break;
808
809 /* In other case.. Nothing to do */
810 case HostCmd_ACT_GEN_GET:
811 default:
812 break;
813 }
814
815 return 0;
816}
817
818/*
819 * This function prepares command to set/get register value.
820 *
821 * Preparation includes -
822 * - Setting command ID, action and proper size
823 * - Setting register offset (for both GET and SET) and
824 * register value (for SET only)
825 * - Ensuring correct endian-ness
826 *
827 * The following type of registers can be accessed with this function -
828 * - MAC register
829 * - BBP register
830 * - RF register
831 * - PMIC register
832 * - CAU register
833 * - EEPROM
834 */
835static int mwifiex_cmd_reg_access(struct host_cmd_ds_command *cmd,
836 u16 cmd_action, void *data_buf)
837{
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700838 struct mwifiex_ds_reg_rw *reg_rw = data_buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700839
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700840 switch (le16_to_cpu(cmd->command)) {
841 case HostCmd_CMD_MAC_REG_ACCESS:
842 {
843 struct host_cmd_ds_mac_reg_access *mac_reg;
844
845 cmd->size = cpu_to_le16(sizeof(*mac_reg) + S_DS_GEN);
846 mac_reg = (struct host_cmd_ds_mac_reg_access *) &cmd->
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700847 params.mac_reg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700848 mac_reg->action = cpu_to_le16(cmd_action);
849 mac_reg->offset =
850 cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
851 mac_reg->value = reg_rw->value;
852 break;
853 }
854 case HostCmd_CMD_BBP_REG_ACCESS:
855 {
856 struct host_cmd_ds_bbp_reg_access *bbp_reg;
857
858 cmd->size = cpu_to_le16(sizeof(*bbp_reg) + S_DS_GEN);
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700859 bbp_reg = (struct host_cmd_ds_bbp_reg_access *)
860 &cmd->params.bbp_reg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700861 bbp_reg->action = cpu_to_le16(cmd_action);
862 bbp_reg->offset =
863 cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
864 bbp_reg->value = (u8) le32_to_cpu(reg_rw->value);
865 break;
866 }
867 case HostCmd_CMD_RF_REG_ACCESS:
868 {
869 struct host_cmd_ds_rf_reg_access *rf_reg;
870
871 cmd->size = cpu_to_le16(sizeof(*rf_reg) + S_DS_GEN);
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700872 rf_reg = (struct host_cmd_ds_rf_reg_access *)
873 &cmd->params.rf_reg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700874 rf_reg->action = cpu_to_le16(cmd_action);
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700875 rf_reg->offset = cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700876 rf_reg->value = (u8) le32_to_cpu(reg_rw->value);
877 break;
878 }
879 case HostCmd_CMD_PMIC_REG_ACCESS:
880 {
881 struct host_cmd_ds_pmic_reg_access *pmic_reg;
882
883 cmd->size = cpu_to_le16(sizeof(*pmic_reg) + S_DS_GEN);
884 pmic_reg = (struct host_cmd_ds_pmic_reg_access *) &cmd->
885 params.pmic_reg;
886 pmic_reg->action = cpu_to_le16(cmd_action);
887 pmic_reg->offset =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700888 cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700889 pmic_reg->value = (u8) le32_to_cpu(reg_rw->value);
890 break;
891 }
892 case HostCmd_CMD_CAU_REG_ACCESS:
893 {
894 struct host_cmd_ds_rf_reg_access *cau_reg;
895
896 cmd->size = cpu_to_le16(sizeof(*cau_reg) + S_DS_GEN);
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700897 cau_reg = (struct host_cmd_ds_rf_reg_access *)
898 &cmd->params.rf_reg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700899 cau_reg->action = cpu_to_le16(cmd_action);
900 cau_reg->offset =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700901 cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700902 cau_reg->value = (u8) le32_to_cpu(reg_rw->value);
903 break;
904 }
905 case HostCmd_CMD_802_11_EEPROM_ACCESS:
906 {
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700907 struct mwifiex_ds_read_eeprom *rd_eeprom = data_buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700908 struct host_cmd_ds_802_11_eeprom_access *cmd_eeprom =
909 (struct host_cmd_ds_802_11_eeprom_access *)
910 &cmd->params.eeprom;
911
912 cmd->size = cpu_to_le16(sizeof(*cmd_eeprom) + S_DS_GEN);
913 cmd_eeprom->action = cpu_to_le16(cmd_action);
914 cmd_eeprom->offset = rd_eeprom->offset;
915 cmd_eeprom->byte_count = rd_eeprom->byte_count;
916 cmd_eeprom->value = 0;
917 break;
918 }
919 default:
920 return -1;
921 }
922
923 return 0;
924}
925
926/*
Amitkumar Karward930fae2011-10-11 17:41:21 -0700927 * This function prepares command to set PCI-Express
928 * host buffer configuration
929 *
930 * Preparation includes -
931 * - Setting command ID, action and proper size
932 * - Setting host buffer configuration
933 * - Ensuring correct endian-ness
934 */
935static int
936mwifiex_cmd_pcie_host_spec(struct mwifiex_private *priv,
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700937 struct host_cmd_ds_command *cmd, u16 action)
Amitkumar Karward930fae2011-10-11 17:41:21 -0700938{
939 struct host_cmd_ds_pcie_details *host_spec =
940 &cmd->params.pcie_host_spec;
941 struct pcie_service_card *card = priv->adapter->card;
942 phys_addr_t *buf_pa;
943
944 cmd->command = cpu_to_le16(HostCmd_CMD_PCIE_DESC_DETAILS);
945 cmd->size = cpu_to_le16(sizeof(struct
946 host_cmd_ds_pcie_details) + S_DS_GEN);
947 cmd->result = 0;
948
949 memset(host_spec, 0, sizeof(struct host_cmd_ds_pcie_details));
950
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700951 if (action != HostCmd_ACT_GEN_SET)
952 return 0;
953
954 /* Send the ring base addresses and count to firmware */
955 host_spec->txbd_addr_lo = (u32)(card->txbd_ring_pbase);
956 host_spec->txbd_addr_hi = (u32)(((u64)card->txbd_ring_pbase)>>32);
957 host_spec->txbd_count = MWIFIEX_MAX_TXRX_BD;
958 host_spec->rxbd_addr_lo = (u32)(card->rxbd_ring_pbase);
959 host_spec->rxbd_addr_hi = (u32)(((u64)card->rxbd_ring_pbase)>>32);
960 host_spec->rxbd_count = MWIFIEX_MAX_TXRX_BD;
961 host_spec->evtbd_addr_lo = (u32)(card->evtbd_ring_pbase);
962 host_spec->evtbd_addr_hi = (u32)(((u64)card->evtbd_ring_pbase)>>32);
963 host_spec->evtbd_count = MWIFIEX_MAX_EVT_BD;
964 if (card->sleep_cookie) {
965 buf_pa = MWIFIEX_SKB_PACB(card->sleep_cookie);
966 host_spec->sleep_cookie_addr_lo = (u32) *buf_pa;
967 host_spec->sleep_cookie_addr_hi = (u32) (((u64)*buf_pa) >> 32);
968 dev_dbg(priv->adapter->dev, "sleep_cook_lo phy addr: 0x%x\n",
969 host_spec->sleep_cookie_addr_lo);
Amitkumar Karward930fae2011-10-11 17:41:21 -0700970 }
971
972 return 0;
973}
974
975/*
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -0700976 * This function prepares command for event subscription, configuration
977 * and query. Events can be subscribed or unsubscribed. Current subscribed
978 * events can be queried. Also, current subscribed events are reported in
979 * every FW response.
980 */
981static int
982mwifiex_cmd_802_11_subsc_evt(struct mwifiex_private *priv,
983 struct host_cmd_ds_command *cmd,
984 struct mwifiex_ds_misc_subsc_evt *subsc_evt_cfg)
985{
986 struct host_cmd_ds_802_11_subsc_evt *subsc_evt = &cmd->params.subsc_evt;
987 struct mwifiex_ie_types_rssi_threshold *rssi_tlv;
988 u16 event_bitmap;
989 u8 *pos;
990
991 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SUBSCRIBE_EVENT);
992 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_subsc_evt) +
993 S_DS_GEN);
994
995 subsc_evt->action = cpu_to_le16(subsc_evt_cfg->action);
996 dev_dbg(priv->adapter->dev, "cmd: action: %d\n", subsc_evt_cfg->action);
997
998 /*For query requests, no configuration TLV structures are to be added.*/
999 if (subsc_evt_cfg->action == HostCmd_ACT_GEN_GET)
1000 return 0;
1001
1002 subsc_evt->events = cpu_to_le16(subsc_evt_cfg->events);
1003
1004 event_bitmap = subsc_evt_cfg->events;
1005 dev_dbg(priv->adapter->dev, "cmd: event bitmap : %16x\n",
1006 event_bitmap);
1007
1008 if (((subsc_evt_cfg->action == HostCmd_ACT_BITWISE_CLR) ||
1009 (subsc_evt_cfg->action == HostCmd_ACT_BITWISE_SET)) &&
1010 (event_bitmap == 0)) {
1011 dev_dbg(priv->adapter->dev, "Error: No event specified "
1012 "for bitwise action type\n");
1013 return -EINVAL;
1014 }
1015
1016 /*
1017 * Append TLV structures for each of the specified events for
1018 * subscribing or re-configuring. This is not required for
1019 * bitwise unsubscribing request.
1020 */
1021 if (subsc_evt_cfg->action == HostCmd_ACT_BITWISE_CLR)
1022 return 0;
1023
1024 pos = ((u8 *)subsc_evt) +
1025 sizeof(struct host_cmd_ds_802_11_subsc_evt);
1026
1027 if (event_bitmap & BITMASK_BCN_RSSI_LOW) {
1028 rssi_tlv = (struct mwifiex_ie_types_rssi_threshold *) pos;
1029
1030 rssi_tlv->header.type = cpu_to_le16(TLV_TYPE_RSSI_LOW);
1031 rssi_tlv->header.len =
1032 cpu_to_le16(sizeof(struct mwifiex_ie_types_rssi_threshold) -
1033 sizeof(struct mwifiex_ie_types_header));
1034 rssi_tlv->abs_value = subsc_evt_cfg->bcn_l_rssi_cfg.abs_value;
1035 rssi_tlv->evt_freq = subsc_evt_cfg->bcn_l_rssi_cfg.evt_freq;
1036
1037 dev_dbg(priv->adapter->dev, "Cfg Beacon Low Rssi event, "
1038 "RSSI:-%d dBm, Freq:%d\n",
1039 subsc_evt_cfg->bcn_l_rssi_cfg.abs_value,
1040 subsc_evt_cfg->bcn_l_rssi_cfg.evt_freq);
1041
1042 pos += sizeof(struct mwifiex_ie_types_rssi_threshold);
1043 le16_add_cpu(&cmd->size,
1044 sizeof(struct mwifiex_ie_types_rssi_threshold));
1045 }
1046
1047 if (event_bitmap & BITMASK_BCN_RSSI_HIGH) {
1048 rssi_tlv = (struct mwifiex_ie_types_rssi_threshold *) pos;
1049
1050 rssi_tlv->header.type = cpu_to_le16(TLV_TYPE_RSSI_HIGH);
1051 rssi_tlv->header.len =
1052 cpu_to_le16(sizeof(struct mwifiex_ie_types_rssi_threshold) -
1053 sizeof(struct mwifiex_ie_types_header));
1054 rssi_tlv->abs_value = subsc_evt_cfg->bcn_h_rssi_cfg.abs_value;
1055 rssi_tlv->evt_freq = subsc_evt_cfg->bcn_h_rssi_cfg.evt_freq;
1056
Bing Zhaod35ccaa2012-04-09 20:06:53 -07001057 dev_dbg(priv->adapter->dev, "Cfg Beacon High Rssi event, "
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -07001058 "RSSI:-%d dBm, Freq:%d\n",
1059 subsc_evt_cfg->bcn_h_rssi_cfg.abs_value,
1060 subsc_evt_cfg->bcn_h_rssi_cfg.evt_freq);
1061
1062 pos += sizeof(struct mwifiex_ie_types_rssi_threshold);
1063 le16_add_cpu(&cmd->size,
1064 sizeof(struct mwifiex_ie_types_rssi_threshold));
1065 }
1066
1067 return 0;
1068}
1069
1070/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001071 * This function prepares the commands before sending them to the firmware.
1072 *
1073 * This is a generic function which calls specific command preparation
1074 * routines based upon the command number.
1075 */
1076int mwifiex_sta_prepare_cmd(struct mwifiex_private *priv, uint16_t cmd_no,
1077 u16 cmd_action, u32 cmd_oid,
1078 void *data_buf, void *cmd_buf)
1079{
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -07001080 struct host_cmd_ds_command *cmd_ptr = cmd_buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001081 int ret = 0;
1082
1083 /* Prepare command */
1084 switch (cmd_no) {
1085 case HostCmd_CMD_GET_HW_SPEC:
1086 ret = mwifiex_cmd_get_hw_spec(priv, cmd_ptr);
1087 break;
1088 case HostCmd_CMD_MAC_CONTROL:
1089 ret = mwifiex_cmd_mac_control(priv, cmd_ptr, cmd_action,
1090 data_buf);
1091 break;
1092 case HostCmd_CMD_802_11_MAC_ADDRESS:
1093 ret = mwifiex_cmd_802_11_mac_address(priv, cmd_ptr,
1094 cmd_action);
1095 break;
1096 case HostCmd_CMD_MAC_MULTICAST_ADR:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001097 ret = mwifiex_cmd_mac_multicast_adr(cmd_ptr, cmd_action,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001098 data_buf);
1099 break;
1100 case HostCmd_CMD_TX_RATE_CFG:
1101 ret = mwifiex_cmd_tx_rate_cfg(priv, cmd_ptr, cmd_action,
1102 data_buf);
1103 break;
1104 case HostCmd_CMD_TXPWR_CFG:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001105 ret = mwifiex_cmd_tx_power_cfg(cmd_ptr, cmd_action,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001106 data_buf);
1107 break;
Amitkumar Karwarcaa89842012-06-27 19:57:57 -07001108 case HostCmd_CMD_RF_TX_PWR:
1109 ret = mwifiex_cmd_rf_tx_power(priv, cmd_ptr, cmd_action,
1110 data_buf);
1111 break;
Amitkumar Karwar8a279d52012-07-02 19:32:33 -07001112 case HostCmd_CMD_RF_ANTENNA:
1113 ret = mwifiex_cmd_rf_antenna(priv, cmd_ptr, cmd_action,
1114 data_buf);
1115 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001116 case HostCmd_CMD_802_11_PS_MODE_ENH:
1117 ret = mwifiex_cmd_enh_power_mode(priv, cmd_ptr, cmd_action,
1118 (uint16_t)cmd_oid, data_buf);
1119 break;
1120 case HostCmd_CMD_802_11_HS_CFG_ENH:
1121 ret = mwifiex_cmd_802_11_hs_cfg(priv, cmd_ptr, cmd_action,
1122 (struct mwifiex_hs_config_param *) data_buf);
1123 break;
1124 case HostCmd_CMD_802_11_SCAN:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001125 ret = mwifiex_cmd_802_11_scan(cmd_ptr, data_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001126 break;
1127 case HostCmd_CMD_802_11_BG_SCAN_QUERY:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001128 ret = mwifiex_cmd_802_11_bg_scan_query(cmd_ptr);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001129 break;
1130 case HostCmd_CMD_802_11_ASSOCIATE:
1131 ret = mwifiex_cmd_802_11_associate(priv, cmd_ptr, data_buf);
1132 break;
1133 case HostCmd_CMD_802_11_DEAUTHENTICATE:
1134 ret = mwifiex_cmd_802_11_deauthenticate(priv, cmd_ptr,
1135 data_buf);
1136 break;
1137 case HostCmd_CMD_802_11_AD_HOC_START:
1138 ret = mwifiex_cmd_802_11_ad_hoc_start(priv, cmd_ptr,
1139 data_buf);
1140 break;
1141 case HostCmd_CMD_802_11_GET_LOG:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001142 ret = mwifiex_cmd_802_11_get_log(cmd_ptr);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001143 break;
1144 case HostCmd_CMD_802_11_AD_HOC_JOIN:
1145 ret = mwifiex_cmd_802_11_ad_hoc_join(priv, cmd_ptr,
1146 data_buf);
1147 break;
1148 case HostCmd_CMD_802_11_AD_HOC_STOP:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001149 ret = mwifiex_cmd_802_11_ad_hoc_stop(cmd_ptr);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001150 break;
1151 case HostCmd_CMD_RSSI_INFO:
1152 ret = mwifiex_cmd_802_11_rssi_info(priv, cmd_ptr, cmd_action);
1153 break;
1154 case HostCmd_CMD_802_11_SNMP_MIB:
1155 ret = mwifiex_cmd_802_11_snmp_mib(priv, cmd_ptr, cmd_action,
1156 cmd_oid, data_buf);
1157 break;
1158 case HostCmd_CMD_802_11_TX_RATE_QUERY:
1159 cmd_ptr->command =
1160 cpu_to_le16(HostCmd_CMD_802_11_TX_RATE_QUERY);
1161 cmd_ptr->size =
1162 cpu_to_le16(sizeof(struct host_cmd_ds_tx_rate_query) +
1163 S_DS_GEN);
1164 priv->tx_rate = 0;
1165 ret = 0;
1166 break;
1167 case HostCmd_CMD_VERSION_EXT:
1168 cmd_ptr->command = cpu_to_le16(cmd_no);
1169 cmd_ptr->params.verext.version_str_sel =
1170 (u8) (*((u32 *) data_buf));
1171 memcpy(&cmd_ptr->params, data_buf,
1172 sizeof(struct host_cmd_ds_version_ext));
1173 cmd_ptr->size =
1174 cpu_to_le16(sizeof(struct host_cmd_ds_version_ext) +
1175 S_DS_GEN);
1176 ret = 0;
1177 break;
1178 case HostCmd_CMD_802_11_RF_CHANNEL:
1179 ret = mwifiex_cmd_802_11_rf_channel(priv, cmd_ptr, cmd_action,
1180 data_buf);
1181 break;
1182 case HostCmd_CMD_FUNC_INIT:
1183 if (priv->adapter->hw_status == MWIFIEX_HW_STATUS_RESET)
1184 priv->adapter->hw_status = MWIFIEX_HW_STATUS_READY;
1185 cmd_ptr->command = cpu_to_le16(cmd_no);
1186 cmd_ptr->size = cpu_to_le16(S_DS_GEN);
1187 break;
1188 case HostCmd_CMD_FUNC_SHUTDOWN:
1189 priv->adapter->hw_status = MWIFIEX_HW_STATUS_RESET;
1190 cmd_ptr->command = cpu_to_le16(cmd_no);
1191 cmd_ptr->size = cpu_to_le16(S_DS_GEN);
1192 break;
1193 case HostCmd_CMD_11N_ADDBA_REQ:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001194 ret = mwifiex_cmd_11n_addba_req(cmd_ptr, data_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001195 break;
1196 case HostCmd_CMD_11N_DELBA:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001197 ret = mwifiex_cmd_11n_delba(cmd_ptr, data_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001198 break;
1199 case HostCmd_CMD_11N_ADDBA_RSP:
1200 ret = mwifiex_cmd_11n_addba_rsp_gen(priv, cmd_ptr, data_buf);
1201 break;
1202 case HostCmd_CMD_802_11_KEY_MATERIAL:
1203 ret = mwifiex_cmd_802_11_key_material(priv, cmd_ptr,
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -07001204 cmd_action, cmd_oid,
1205 data_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001206 break;
1207 case HostCmd_CMD_802_11D_DOMAIN_INFO:
1208 ret = mwifiex_cmd_802_11d_domain_info(priv, cmd_ptr,
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -07001209 cmd_action);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001210 break;
1211 case HostCmd_CMD_RECONFIGURE_TX_BUFF:
1212 ret = mwifiex_cmd_recfg_tx_buf(priv, cmd_ptr, cmd_action,
1213 data_buf);
1214 break;
1215 case HostCmd_CMD_AMSDU_AGGR_CTRL:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001216 ret = mwifiex_cmd_amsdu_aggr_ctrl(cmd_ptr, cmd_action,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001217 data_buf);
1218 break;
1219 case HostCmd_CMD_11N_CFG:
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -07001220 ret = mwifiex_cmd_11n_cfg(cmd_ptr, cmd_action, data_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001221 break;
1222 case HostCmd_CMD_WMM_GET_STATUS:
1223 dev_dbg(priv->adapter->dev,
1224 "cmd: WMM: WMM_GET_STATUS cmd sent\n");
1225 cmd_ptr->command = cpu_to_le16(HostCmd_CMD_WMM_GET_STATUS);
1226 cmd_ptr->size =
1227 cpu_to_le16(sizeof(struct host_cmd_ds_wmm_get_status) +
1228 S_DS_GEN);
1229 ret = 0;
1230 break;
1231 case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001232 ret = mwifiex_cmd_ibss_coalescing_status(cmd_ptr, cmd_action,
1233 data_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001234 break;
1235 case HostCmd_CMD_MAC_REG_ACCESS:
1236 case HostCmd_CMD_BBP_REG_ACCESS:
1237 case HostCmd_CMD_RF_REG_ACCESS:
1238 case HostCmd_CMD_PMIC_REG_ACCESS:
1239 case HostCmd_CMD_CAU_REG_ACCESS:
1240 case HostCmd_CMD_802_11_EEPROM_ACCESS:
1241 ret = mwifiex_cmd_reg_access(cmd_ptr, cmd_action, data_buf);
1242 break;
1243 case HostCmd_CMD_SET_BSS_MODE:
1244 cmd_ptr->command = cpu_to_le16(cmd_no);
Bing Zhaoeecd8252011-03-28 17:55:41 -07001245 if (priv->bss_mode == NL80211_IFTYPE_ADHOC)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001246 cmd_ptr->params.bss_mode.con_type =
1247 CONNECTION_TYPE_ADHOC;
Bing Zhaoeecd8252011-03-28 17:55:41 -07001248 else if (priv->bss_mode == NL80211_IFTYPE_STATION)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001249 cmd_ptr->params.bss_mode.con_type =
1250 CONNECTION_TYPE_INFRA;
1251 cmd_ptr->size = cpu_to_le16(sizeof(struct
1252 host_cmd_ds_set_bss_mode) + S_DS_GEN);
1253 ret = 0;
1254 break;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001255 case HostCmd_CMD_PCIE_DESC_DETAILS:
1256 ret = mwifiex_cmd_pcie_host_spec(priv, cmd_ptr, cmd_action);
1257 break;
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -07001258 case HostCmd_CMD_802_11_SUBSCRIBE_EVENT:
1259 ret = mwifiex_cmd_802_11_subsc_evt(priv, cmd_ptr, data_buf);
1260 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001261 default:
1262 dev_err(priv->adapter->dev,
1263 "PREP_CMD: unknown cmd- %#x\n", cmd_no);
1264 ret = -1;
1265 break;
1266 }
1267 return ret;
1268}
1269
1270/*
1271 * This function issues commands to initialize firmware.
1272 *
1273 * This is called after firmware download to bring the card to
1274 * working state.
1275 *
1276 * The following commands are issued sequentially -
Amitkumar Karward930fae2011-10-11 17:41:21 -07001277 * - Set PCI-Express host buffer configuration (PCIE only)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001278 * - Function init (for first interface only)
1279 * - Read MAC address (for first interface only)
1280 * - Reconfigure Tx buffer size (for first interface only)
1281 * - Enable auto deep sleep (for first interface only)
1282 * - Get Tx rate
1283 * - Get Tx power
1284 * - Set IBSS coalescing status
1285 * - Set AMSDU aggregation control
1286 * - Set 11d control
1287 * - Set MAC control (this must be the last command to initialize firmware)
1288 */
1289int mwifiex_sta_init_cmd(struct mwifiex_private *priv, u8 first_sta)
1290{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001291 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001292 u16 enable = true;
1293 struct mwifiex_ds_11n_amsdu_aggr_ctrl amsdu_aggr_ctrl;
1294 struct mwifiex_ds_auto_ds auto_ds;
1295 enum state_11d_t state_11d;
Amitkumar Karwarcd27bc32011-07-08 20:40:30 -07001296 struct mwifiex_ds_11n_tx_cfg tx_cfg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001297
1298 if (first_sta) {
Amitkumar Karward930fae2011-10-11 17:41:21 -07001299 if (priv->adapter->iface_type == MWIFIEX_PCIE) {
1300 ret = mwifiex_send_cmd_async(priv,
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -07001301 HostCmd_CMD_PCIE_DESC_DETAILS,
1302 HostCmd_ACT_GEN_SET, 0, NULL);
Amitkumar Karward930fae2011-10-11 17:41:21 -07001303 if (ret)
1304 return -1;
1305 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001306
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001307 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_FUNC_INIT,
1308 HostCmd_ACT_GEN_SET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001309 if (ret)
1310 return -1;
1311 /* Read MAC address from HW */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001312 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_GET_HW_SPEC,
1313 HostCmd_ACT_GEN_GET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001314 if (ret)
1315 return -1;
1316
1317 /* Reconfigure tx buf size */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001318 ret = mwifiex_send_cmd_async(priv,
1319 HostCmd_CMD_RECONFIGURE_TX_BUFF,
1320 HostCmd_ACT_GEN_SET, 0,
1321 &priv->adapter->tx_buf_size);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001322 if (ret)
1323 return -1;
1324
Avinash Patil03785382012-05-08 18:30:14 -07001325 if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
1326 /* Enable IEEE PS by default */
1327 priv->adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
1328 ret = mwifiex_send_cmd_async(
1329 priv, HostCmd_CMD_802_11_PS_MODE_ENH,
1330 EN_AUTO_PS, BITMAP_STA_PS, NULL);
1331 if (ret)
1332 return -1;
1333 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001334 }
1335
1336 /* get tx rate */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001337 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_TX_RATE_CFG,
1338 HostCmd_ACT_GEN_GET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001339 if (ret)
1340 return -1;
1341 priv->data_rate = 0;
1342
1343 /* get tx power */
Amitkumar Karwarcaa89842012-06-27 19:57:57 -07001344 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_RF_TX_PWR,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001345 HostCmd_ACT_GEN_GET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001346 if (ret)
1347 return -1;
1348
Avinash Patil03785382012-05-08 18:30:14 -07001349 if (priv->bss_type == MWIFIEX_BSS_TYPE_STA) {
1350 /* set ibss coalescing_status */
1351 ret = mwifiex_send_cmd_async(
1352 priv, HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
1353 HostCmd_ACT_GEN_SET, 0, &enable);
1354 if (ret)
1355 return -1;
1356 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001357
1358 memset(&amsdu_aggr_ctrl, 0, sizeof(amsdu_aggr_ctrl));
1359 amsdu_aggr_ctrl.enable = true;
1360 /* Send request to firmware */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001361 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_AMSDU_AGGR_CTRL,
1362 HostCmd_ACT_GEN_SET, 0,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -07001363 &amsdu_aggr_ctrl);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001364 if (ret)
1365 return -1;
1366 /* MAC Control must be the last command in init_fw */
1367 /* set MAC Control */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001368 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
1369 HostCmd_ACT_GEN_SET, 0,
1370 &priv->curr_pkt_filter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001371 if (ret)
1372 return -1;
1373
Avinash Patil03785382012-05-08 18:30:14 -07001374 if (first_sta && priv->adapter->iface_type != MWIFIEX_USB &&
1375 priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001376 /* Enable auto deep sleep */
1377 auto_ds.auto_ds = DEEP_SLEEP_ON;
1378 auto_ds.idle_time = DEEP_SLEEP_IDLE_TIME;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001379 ret = mwifiex_send_cmd_async(priv,
1380 HostCmd_CMD_802_11_PS_MODE_ENH,
1381 EN_AUTO_PS, BITMAP_AUTO_DS,
1382 &auto_ds);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001383 if (ret)
1384 return -1;
1385 }
1386
Avinash Patil03785382012-05-08 18:30:14 -07001387 if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
1388 /* Send cmd to FW to enable/disable 11D function */
1389 state_11d = ENABLE_11D;
1390 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11_SNMP_MIB,
1391 HostCmd_ACT_GEN_SET, DOT11D_I,
1392 &state_11d);
1393 if (ret)
1394 dev_err(priv->adapter->dev,
1395 "11D: failed to enable 11D\n");
1396 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001397
Amitkumar Karwarcd27bc32011-07-08 20:40:30 -07001398 /* Send cmd to FW to configure 11n specific configuration
1399 * (Short GI, Channel BW, Green field support etc.) for transmit
1400 */
1401 tx_cfg.tx_htcap = MWIFIEX_FW_DEF_HTTXCFG;
1402 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_CFG,
1403 HostCmd_ACT_GEN_SET, 0, &tx_cfg);
1404
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001405 /* set last_init_cmd */
Amitkumar Karwarcd27bc32011-07-08 20:40:30 -07001406 priv->adapter->last_init_cmd = HostCmd_CMD_11N_CFG;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001407 ret = -EINPROGRESS;
1408
1409 return ret;
1410}