Linux 3.3-rc1
[zen-stable.git] / drivers / net / wireless / iwmc3200wifi / commands.c
blobbd75078c454b552d8df71758b3eba0d99c045578
1 /*
2 * Intel Wireless Multicomm 3200 WiFi driver
4 * Copyright (C) 2009 Intel Corporation. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Intel Corporation nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * Intel Corporation <ilw@linux.intel.com>
34 * Samuel Ortiz <samuel.ortiz@intel.com>
35 * Zhu Yi <yi.zhu@intel.com>
39 #include <linux/kernel.h>
40 #include <linux/wireless.h>
41 #include <linux/etherdevice.h>
42 #include <linux/ieee80211.h>
43 #include <linux/sched.h>
44 #include <linux/slab.h>
45 #include <linux/moduleparam.h>
47 #include "iwm.h"
48 #include "bus.h"
49 #include "hal.h"
50 #include "umac.h"
51 #include "commands.h"
52 #include "debug.h"
54 static int iwm_send_lmac_ptrough_cmd(struct iwm_priv *iwm,
55 u8 lmac_cmd_id,
56 const void *lmac_payload,
57 u16 lmac_payload_size,
58 u8 resp)
60 struct iwm_udma_wifi_cmd udma_cmd = UDMA_LMAC_INIT;
61 struct iwm_umac_cmd umac_cmd;
62 struct iwm_lmac_cmd lmac_cmd;
64 lmac_cmd.id = lmac_cmd_id;
66 umac_cmd.id = UMAC_CMD_OPCODE_WIFI_PASS_THROUGH;
67 umac_cmd.resp = resp;
69 return iwm_hal_send_host_cmd(iwm, &udma_cmd, &umac_cmd, &lmac_cmd,
70 lmac_payload, lmac_payload_size);
73 int iwm_send_wifi_if_cmd(struct iwm_priv *iwm, void *payload, u16 payload_size,
74 bool resp)
76 struct iwm_umac_wifi_if *hdr = (struct iwm_umac_wifi_if *)payload;
77 struct iwm_udma_wifi_cmd udma_cmd = UDMA_UMAC_INIT;
78 struct iwm_umac_cmd umac_cmd;
79 int ret;
80 u8 oid = hdr->oid;
82 if (!test_bit(IWM_STATUS_READY, &iwm->status)) {
83 IWM_ERR(iwm, "Interface is not ready yet");
84 return -EAGAIN;
87 umac_cmd.id = UMAC_CMD_OPCODE_WIFI_IF_WRAPPER;
88 umac_cmd.resp = resp;
90 ret = iwm_hal_send_umac_cmd(iwm, &udma_cmd, &umac_cmd,
91 payload, payload_size);
93 if (resp) {
94 ret = wait_event_interruptible_timeout(iwm->wifi_ntfy_queue,
95 test_and_clear_bit(oid, &iwm->wifi_ntfy[0]),
96 3 * HZ);
98 return ret ? 0 : -EBUSY;
101 return ret;
104 static int modparam_wiwi = COEX_MODE_CM;
105 module_param_named(wiwi, modparam_wiwi, int, 0644);
106 MODULE_PARM_DESC(wiwi, "Wifi-WiMAX coexistence: 1=SA, 2=XOR, 3=CM (default)");
108 static struct coex_event iwm_sta_xor_prio_tbl[COEX_EVENTS_NUM] =
110 {4, 3, 0, COEX_UNASSOC_IDLE_FLAGS},
111 {4, 3, 0, COEX_UNASSOC_MANUAL_SCAN_FLAGS},
112 {4, 3, 0, COEX_UNASSOC_AUTO_SCAN_FLAGS},
113 {4, 3, 0, COEX_CALIBRATION_FLAGS},
114 {4, 3, 0, COEX_PERIODIC_CALIBRATION_FLAGS},
115 {4, 3, 0, COEX_CONNECTION_ESTAB_FLAGS},
116 {4, 3, 0, COEX_ASSOCIATED_IDLE_FLAGS},
117 {4, 3, 0, COEX_ASSOC_MANUAL_SCAN_FLAGS},
118 {4, 3, 0, COEX_ASSOC_AUTO_SCAN_FLAGS},
119 {4, 3, 0, COEX_ASSOC_ACTIVE_LEVEL_FLAGS},
120 {6, 3, 0, COEX_XOR_RF_ON_FLAGS},
121 {4, 3, 0, COEX_RF_OFF_FLAGS},
122 {6, 6, 0, COEX_STAND_ALONE_DEBUG_FLAGS},
123 {4, 3, 0, COEX_IPAN_ASSOC_LEVEL_FLAGS},
124 {4, 3, 0, COEX_RSRVD1_FLAGS},
125 {4, 3, 0, COEX_RSRVD2_FLAGS}
128 static struct coex_event iwm_sta_cm_prio_tbl[COEX_EVENTS_NUM] =
130 {1, 1, 0, COEX_UNASSOC_IDLE_FLAGS},
131 {4, 4, 0, COEX_UNASSOC_MANUAL_SCAN_FLAGS},
132 {3, 3, 0, COEX_UNASSOC_AUTO_SCAN_FLAGS},
133 {6, 6, 0, COEX_CALIBRATION_FLAGS},
134 {3, 3, 0, COEX_PERIODIC_CALIBRATION_FLAGS},
135 {6, 5, 0, COEX_CONNECTION_ESTAB_FLAGS},
136 {4, 4, 0, COEX_ASSOCIATED_IDLE_FLAGS},
137 {4, 4, 0, COEX_ASSOC_MANUAL_SCAN_FLAGS},
138 {4, 4, 0, COEX_ASSOC_AUTO_SCAN_FLAGS},
139 {4, 4, 0, COEX_ASSOC_ACTIVE_LEVEL_FLAGS},
140 {1, 1, 0, COEX_RF_ON_FLAGS},
141 {1, 1, 0, COEX_RF_OFF_FLAGS},
142 {7, 7, 0, COEX_STAND_ALONE_DEBUG_FLAGS},
143 {5, 4, 0, COEX_IPAN_ASSOC_LEVEL_FLAGS},
144 {1, 1, 0, COEX_RSRVD1_FLAGS},
145 {1, 1, 0, COEX_RSRVD2_FLAGS}
148 int iwm_send_prio_table(struct iwm_priv *iwm)
150 struct iwm_coex_prio_table_cmd coex_table_cmd;
151 u32 coex_enabled, mode_enabled;
153 memset(&coex_table_cmd, 0, sizeof(struct iwm_coex_prio_table_cmd));
155 coex_table_cmd.flags = COEX_FLAGS_STA_TABLE_VALID_MSK;
157 switch (modparam_wiwi) {
158 case COEX_MODE_XOR:
159 case COEX_MODE_CM:
160 coex_enabled = 1;
161 break;
162 default:
163 coex_enabled = 0;
164 break;
167 switch (iwm->conf.mode) {
168 case UMAC_MODE_BSS:
169 case UMAC_MODE_IBSS:
170 mode_enabled = 1;
171 break;
172 default:
173 mode_enabled = 0;
174 break;
177 if (coex_enabled && mode_enabled) {
178 coex_table_cmd.flags |= COEX_FLAGS_COEX_ENABLE_MSK |
179 COEX_FLAGS_ASSOC_WAKEUP_UMASK_MSK |
180 COEX_FLAGS_UNASSOC_WAKEUP_UMASK_MSK;
182 switch (modparam_wiwi) {
183 case COEX_MODE_XOR:
184 memcpy(coex_table_cmd.sta_prio, iwm_sta_xor_prio_tbl,
185 sizeof(iwm_sta_xor_prio_tbl));
186 break;
187 case COEX_MODE_CM:
188 memcpy(coex_table_cmd.sta_prio, iwm_sta_cm_prio_tbl,
189 sizeof(iwm_sta_cm_prio_tbl));
190 break;
191 default:
192 IWM_ERR(iwm, "Invalid coex_mode 0x%x\n",
193 modparam_wiwi);
194 break;
196 } else
197 IWM_WARN(iwm, "coexistense disabled\n");
199 return iwm_send_lmac_ptrough_cmd(iwm, COEX_PRIORITY_TABLE_CMD,
200 &coex_table_cmd,
201 sizeof(struct iwm_coex_prio_table_cmd), 0);
204 int iwm_send_init_calib_cfg(struct iwm_priv *iwm, u8 calib_requested)
206 struct iwm_lmac_cal_cfg_cmd cal_cfg_cmd;
208 memset(&cal_cfg_cmd, 0, sizeof(struct iwm_lmac_cal_cfg_cmd));
210 cal_cfg_cmd.ucode_cfg.init.enable = cpu_to_le32(calib_requested);
211 cal_cfg_cmd.ucode_cfg.init.start = cpu_to_le32(calib_requested);
212 cal_cfg_cmd.ucode_cfg.init.send_res = cpu_to_le32(calib_requested);
213 cal_cfg_cmd.ucode_cfg.flags =
214 cpu_to_le32(CALIB_CFG_FLAG_SEND_COMPLETE_NTFY_AFTER_MSK);
216 return iwm_send_lmac_ptrough_cmd(iwm, CALIBRATION_CFG_CMD, &cal_cfg_cmd,
217 sizeof(struct iwm_lmac_cal_cfg_cmd), 1);
220 int iwm_send_periodic_calib_cfg(struct iwm_priv *iwm, u8 calib_requested)
222 struct iwm_lmac_cal_cfg_cmd cal_cfg_cmd;
224 memset(&cal_cfg_cmd, 0, sizeof(struct iwm_lmac_cal_cfg_cmd));
226 cal_cfg_cmd.ucode_cfg.periodic.enable = cpu_to_le32(calib_requested);
227 cal_cfg_cmd.ucode_cfg.periodic.start = cpu_to_le32(calib_requested);
229 return iwm_send_lmac_ptrough_cmd(iwm, CALIBRATION_CFG_CMD, &cal_cfg_cmd,
230 sizeof(struct iwm_lmac_cal_cfg_cmd), 0);
233 int iwm_store_rxiq_calib_result(struct iwm_priv *iwm)
235 struct iwm_calib_rxiq *rxiq;
236 u8 *eeprom_rxiq = iwm_eeprom_access(iwm, IWM_EEPROM_CALIB_RXIQ);
237 int grplen = sizeof(struct iwm_calib_rxiq_group);
239 rxiq = kzalloc(sizeof(struct iwm_calib_rxiq), GFP_KERNEL);
240 if (!rxiq) {
241 IWM_ERR(iwm, "Couldn't alloc memory for RX IQ\n");
242 return -ENOMEM;
245 eeprom_rxiq = iwm_eeprom_access(iwm, IWM_EEPROM_CALIB_RXIQ);
246 if (IS_ERR(eeprom_rxiq)) {
247 IWM_ERR(iwm, "Couldn't access EEPROM RX IQ entry\n");
248 kfree(rxiq);
249 return PTR_ERR(eeprom_rxiq);
252 iwm->calib_res[SHILOH_PHY_CALIBRATE_RX_IQ_CMD].buf = (u8 *)rxiq;
253 iwm->calib_res[SHILOH_PHY_CALIBRATE_RX_IQ_CMD].size = sizeof(*rxiq);
255 rxiq->hdr.opcode = SHILOH_PHY_CALIBRATE_RX_IQ_CMD;
256 rxiq->hdr.first_grp = 0;
257 rxiq->hdr.grp_num = 1;
258 rxiq->hdr.all_data_valid = 1;
260 memcpy(&rxiq->group[0], eeprom_rxiq, 4 * grplen);
261 memcpy(&rxiq->group[4], eeprom_rxiq + 6 * grplen, grplen);
263 return 0;
266 int iwm_send_calib_results(struct iwm_priv *iwm)
268 int i, ret = 0;
270 for (i = PHY_CALIBRATE_OPCODES_NUM; i < CALIBRATION_CMD_NUM; i++) {
271 if (test_bit(i - PHY_CALIBRATE_OPCODES_NUM,
272 &iwm->calib_done_map)) {
273 IWM_DBG_CMD(iwm, DBG,
274 "Send calibration %d result\n", i);
275 ret |= iwm_send_lmac_ptrough_cmd(iwm,
276 REPLY_PHY_CALIBRATION_CMD,
277 iwm->calib_res[i].buf,
278 iwm->calib_res[i].size, 0);
280 kfree(iwm->calib_res[i].buf);
281 iwm->calib_res[i].buf = NULL;
282 iwm->calib_res[i].size = 0;
286 return ret;
289 int iwm_send_ct_kill_cfg(struct iwm_priv *iwm, u8 entry, u8 exit)
291 struct iwm_ct_kill_cfg_cmd cmd;
293 cmd.entry_threshold = entry;
294 cmd.exit_threshold = exit;
296 return iwm_send_lmac_ptrough_cmd(iwm, REPLY_CT_KILL_CONFIG_CMD, &cmd,
297 sizeof(struct iwm_ct_kill_cfg_cmd), 0);
300 int iwm_send_umac_reset(struct iwm_priv *iwm, __le32 reset_flags, bool resp)
302 struct iwm_udma_wifi_cmd udma_cmd = UDMA_UMAC_INIT;
303 struct iwm_umac_cmd umac_cmd;
304 struct iwm_umac_cmd_reset reset;
306 reset.flags = reset_flags;
308 umac_cmd.id = UMAC_CMD_OPCODE_RESET;
309 umac_cmd.resp = resp;
311 return iwm_hal_send_umac_cmd(iwm, &udma_cmd, &umac_cmd, &reset,
312 sizeof(struct iwm_umac_cmd_reset));
315 int iwm_umac_set_config_fix(struct iwm_priv *iwm, u16 tbl, u16 key, u32 value)
317 struct iwm_udma_wifi_cmd udma_cmd = UDMA_UMAC_INIT;
318 struct iwm_umac_cmd umac_cmd;
319 struct iwm_umac_cmd_set_param_fix param;
321 if ((tbl != UMAC_PARAM_TBL_CFG_FIX) &&
322 (tbl != UMAC_PARAM_TBL_FA_CFG_FIX))
323 return -EINVAL;
325 umac_cmd.id = UMAC_CMD_OPCODE_SET_PARAM_FIX;
326 umac_cmd.resp = 0;
328 param.tbl = cpu_to_le16(tbl);
329 param.key = cpu_to_le16(key);
330 param.value = cpu_to_le32(value);
332 return iwm_hal_send_umac_cmd(iwm, &udma_cmd, &umac_cmd, &param,
333 sizeof(struct iwm_umac_cmd_set_param_fix));
336 int iwm_umac_set_config_var(struct iwm_priv *iwm, u16 key,
337 void *payload, u16 payload_size)
339 struct iwm_udma_wifi_cmd udma_cmd = UDMA_UMAC_INIT;
340 struct iwm_umac_cmd umac_cmd;
341 struct iwm_umac_cmd_set_param_var *param_hdr;
342 u8 *param;
343 int ret;
345 param = kzalloc(payload_size +
346 sizeof(struct iwm_umac_cmd_set_param_var), GFP_KERNEL);
347 if (!param) {
348 IWM_ERR(iwm, "Couldn't allocate param\n");
349 return -ENOMEM;
352 param_hdr = (struct iwm_umac_cmd_set_param_var *)param;
354 umac_cmd.id = UMAC_CMD_OPCODE_SET_PARAM_VAR;
355 umac_cmd.resp = 0;
357 param_hdr->tbl = cpu_to_le16(UMAC_PARAM_TBL_CFG_VAR);
358 param_hdr->key = cpu_to_le16(key);
359 param_hdr->len = cpu_to_le16(payload_size);
360 memcpy(param + sizeof(struct iwm_umac_cmd_set_param_var),
361 payload, payload_size);
363 ret = iwm_hal_send_umac_cmd(iwm, &udma_cmd, &umac_cmd, param,
364 sizeof(struct iwm_umac_cmd_set_param_var) +
365 payload_size);
366 kfree(param);
368 return ret;
371 int iwm_send_umac_config(struct iwm_priv *iwm, __le32 reset_flags)
373 int ret;
375 /* Use UMAC default values */
376 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
377 CFG_POWER_INDEX, iwm->conf.power_index);
378 if (ret < 0)
379 return ret;
381 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_FA_CFG_FIX,
382 CFG_FRAG_THRESHOLD,
383 iwm->conf.frag_threshold);
384 if (ret < 0)
385 return ret;
387 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
388 CFG_RTS_THRESHOLD,
389 iwm->conf.rts_threshold);
390 if (ret < 0)
391 return ret;
393 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
394 CFG_CTS_TO_SELF, iwm->conf.cts_to_self);
395 if (ret < 0)
396 return ret;
398 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
399 CFG_WIRELESS_MODE,
400 iwm->conf.wireless_mode);
401 if (ret < 0)
402 return ret;
404 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
405 CFG_COEX_MODE, modparam_wiwi);
406 if (ret < 0)
407 return ret;
410 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
411 CFG_ASSOCIATION_TIMEOUT,
412 iwm->conf.assoc_timeout);
413 if (ret < 0)
414 return ret;
416 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
417 CFG_ROAM_TIMEOUT,
418 iwm->conf.roam_timeout);
419 if (ret < 0)
420 return ret;
422 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
423 CFG_WIRELESS_MODE,
424 WIRELESS_MODE_11A | WIRELESS_MODE_11G);
425 if (ret < 0)
426 return ret;
429 ret = iwm_umac_set_config_var(iwm, CFG_NET_ADDR,
430 iwm_to_ndev(iwm)->dev_addr, ETH_ALEN);
431 if (ret < 0)
432 return ret;
434 /* UMAC PM static configurations */
435 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
436 CFG_PM_LEGACY_RX_TIMEOUT, 0x12C);
437 if (ret < 0)
438 return ret;
440 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
441 CFG_PM_LEGACY_TX_TIMEOUT, 0x15E);
442 if (ret < 0)
443 return ret;
445 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
446 CFG_PM_CTRL_FLAGS, 0x1);
447 if (ret < 0)
448 return ret;
450 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
451 CFG_PM_KEEP_ALIVE_IN_BEACONS, 0x80);
452 if (ret < 0)
453 return ret;
455 /* reset UMAC */
456 ret = iwm_send_umac_reset(iwm, reset_flags, 1);
457 if (ret < 0)
458 return ret;
460 ret = iwm_notif_handle(iwm, UMAC_CMD_OPCODE_RESET, IWM_SRC_UMAC,
461 WAIT_NOTIF_TIMEOUT);
462 if (ret) {
463 IWM_ERR(iwm, "Wait for UMAC RESET timeout\n");
464 return ret;
467 return ret;
470 int iwm_send_packet(struct iwm_priv *iwm, struct sk_buff *skb, int pool_id)
472 struct iwm_udma_wifi_cmd udma_cmd;
473 struct iwm_umac_cmd umac_cmd;
474 struct iwm_tx_info *tx_info = skb_to_tx_info(skb);
476 udma_cmd.eop = 1; /* always set eop for non-concatenated Tx */
477 udma_cmd.credit_group = pool_id;
478 udma_cmd.ra_tid = tx_info->sta << 4 | tx_info->tid;
479 udma_cmd.lmac_offset = 0;
481 umac_cmd.id = REPLY_TX;
482 umac_cmd.color = tx_info->color;
483 umac_cmd.resp = 0;
485 return iwm_hal_send_umac_cmd(iwm, &udma_cmd, &umac_cmd,
486 skb->data, skb->len);
489 static int iwm_target_read(struct iwm_priv *iwm, __le32 address,
490 u8 *response, u32 resp_size)
492 struct iwm_udma_nonwifi_cmd target_cmd;
493 struct iwm_nonwifi_cmd *cmd;
494 u16 seq_num;
495 int ret = 0;
497 target_cmd.opcode = UMAC_HDI_OUT_OPCODE_READ;
498 target_cmd.addr = address;
499 target_cmd.op1_sz = cpu_to_le32(resp_size);
500 target_cmd.op2 = 0;
501 target_cmd.handle_by_hw = 0;
502 target_cmd.resp = 1;
503 target_cmd.eop = 1;
505 ret = iwm_hal_send_target_cmd(iwm, &target_cmd, NULL);
506 if (ret < 0) {
507 IWM_ERR(iwm, "Couldn't send READ command\n");
508 return ret;
511 /* When succeeding, the send_target routine returns the seq number */
512 seq_num = ret;
514 ret = wait_event_interruptible_timeout(iwm->nonwifi_queue,
515 (cmd = iwm_get_pending_nonwifi_cmd(iwm, seq_num,
516 UMAC_HDI_OUT_OPCODE_READ)) != NULL,
517 2 * HZ);
519 if (!ret) {
520 IWM_ERR(iwm, "Didn't receive a target READ answer\n");
521 return ret;
524 memcpy(response, cmd->buf.hdr + sizeof(struct iwm_udma_in_hdr),
525 resp_size);
527 kfree(cmd);
529 return 0;
532 int iwm_read_mac(struct iwm_priv *iwm, u8 *mac)
534 int ret;
535 u8 mac_align[ALIGN(ETH_ALEN, 8)];
537 ret = iwm_target_read(iwm, cpu_to_le32(WICO_MAC_ADDRESS_ADDR),
538 mac_align, sizeof(mac_align));
539 if (ret)
540 return ret;
542 if (is_valid_ether_addr(mac_align))
543 memcpy(mac, mac_align, ETH_ALEN);
544 else {
545 IWM_ERR(iwm, "Invalid EEPROM MAC\n");
546 memcpy(mac, iwm->conf.mac_addr, ETH_ALEN);
547 get_random_bytes(&mac[3], 3);
550 return 0;
553 static int iwm_check_profile(struct iwm_priv *iwm)
555 if (!iwm->umac_profile_active)
556 return -EAGAIN;
558 if (iwm->umac_profile->sec.ucast_cipher != UMAC_CIPHER_TYPE_WEP_40 &&
559 iwm->umac_profile->sec.ucast_cipher != UMAC_CIPHER_TYPE_WEP_104 &&
560 iwm->umac_profile->sec.ucast_cipher != UMAC_CIPHER_TYPE_TKIP &&
561 iwm->umac_profile->sec.ucast_cipher != UMAC_CIPHER_TYPE_CCMP) {
562 IWM_ERR(iwm, "Wrong unicast cipher: 0x%x\n",
563 iwm->umac_profile->sec.ucast_cipher);
564 return -EAGAIN;
567 if (iwm->umac_profile->sec.mcast_cipher != UMAC_CIPHER_TYPE_WEP_40 &&
568 iwm->umac_profile->sec.mcast_cipher != UMAC_CIPHER_TYPE_WEP_104 &&
569 iwm->umac_profile->sec.mcast_cipher != UMAC_CIPHER_TYPE_TKIP &&
570 iwm->umac_profile->sec.mcast_cipher != UMAC_CIPHER_TYPE_CCMP) {
571 IWM_ERR(iwm, "Wrong multicast cipher: 0x%x\n",
572 iwm->umac_profile->sec.mcast_cipher);
573 return -EAGAIN;
576 if ((iwm->umac_profile->sec.ucast_cipher == UMAC_CIPHER_TYPE_WEP_40 ||
577 iwm->umac_profile->sec.ucast_cipher == UMAC_CIPHER_TYPE_WEP_104) &&
578 (iwm->umac_profile->sec.ucast_cipher !=
579 iwm->umac_profile->sec.mcast_cipher)) {
580 IWM_ERR(iwm, "Unicast and multicast ciphers differ for WEP\n");
583 return 0;
586 int iwm_set_tx_key(struct iwm_priv *iwm, u8 key_idx)
588 struct iwm_umac_tx_key_id tx_key_id;
589 int ret;
591 ret = iwm_check_profile(iwm);
592 if (ret < 0)
593 return ret;
595 /* UMAC only allows to set default key for WEP and auth type is
596 * NOT 802.1X or RSNA. */
597 if ((iwm->umac_profile->sec.ucast_cipher != UMAC_CIPHER_TYPE_WEP_40 &&
598 iwm->umac_profile->sec.ucast_cipher != UMAC_CIPHER_TYPE_WEP_104) ||
599 iwm->umac_profile->sec.auth_type == UMAC_AUTH_TYPE_8021X ||
600 iwm->umac_profile->sec.auth_type == UMAC_AUTH_TYPE_RSNA_PSK)
601 return 0;
603 tx_key_id.hdr.oid = UMAC_WIFI_IF_CMD_GLOBAL_TX_KEY_ID;
604 tx_key_id.hdr.buf_size = cpu_to_le16(sizeof(struct iwm_umac_tx_key_id) -
605 sizeof(struct iwm_umac_wifi_if));
607 tx_key_id.key_idx = key_idx;
609 return iwm_send_wifi_if_cmd(iwm, &tx_key_id, sizeof(tx_key_id), 1);
612 int iwm_set_key(struct iwm_priv *iwm, bool remove, struct iwm_key *key)
614 int ret = 0;
615 u8 cmd[64], *sta_addr, *key_data, key_len;
616 s8 key_idx;
617 u16 cmd_size = 0;
618 struct iwm_umac_key_hdr *key_hdr = &key->hdr;
619 struct iwm_umac_key_wep40 *wep40 = (struct iwm_umac_key_wep40 *)cmd;
620 struct iwm_umac_key_wep104 *wep104 = (struct iwm_umac_key_wep104 *)cmd;
621 struct iwm_umac_key_tkip *tkip = (struct iwm_umac_key_tkip *)cmd;
622 struct iwm_umac_key_ccmp *ccmp = (struct iwm_umac_key_ccmp *)cmd;
624 if (!remove) {
625 ret = iwm_check_profile(iwm);
626 if (ret < 0)
627 return ret;
630 sta_addr = key->hdr.mac;
631 key_data = key->key;
632 key_len = key->key_len;
633 key_idx = key->hdr.key_idx;
635 if (!remove) {
636 u8 auth_type = iwm->umac_profile->sec.auth_type;
638 IWM_DBG_WEXT(iwm, DBG, "key_idx:%d\n", key_idx);
639 IWM_DBG_WEXT(iwm, DBG, "key_len:%d\n", key_len);
640 IWM_DBG_WEXT(iwm, DBG, "MAC:%pM, idx:%d, multicast:%d\n",
641 key_hdr->mac, key_hdr->key_idx, key_hdr->multicast);
643 IWM_DBG_WEXT(iwm, DBG, "profile: mcast:0x%x, ucast:0x%x\n",
644 iwm->umac_profile->sec.mcast_cipher,
645 iwm->umac_profile->sec.ucast_cipher);
646 IWM_DBG_WEXT(iwm, DBG, "profile: auth_type:0x%x, flags:0x%x\n",
647 iwm->umac_profile->sec.auth_type,
648 iwm->umac_profile->sec.flags);
650 switch (key->cipher) {
651 case WLAN_CIPHER_SUITE_WEP40:
652 wep40->hdr.oid = UMAC_WIFI_IF_CMD_ADD_WEP40_KEY;
653 wep40->hdr.buf_size =
654 cpu_to_le16(sizeof(struct iwm_umac_key_wep40) -
655 sizeof(struct iwm_umac_wifi_if));
657 memcpy(&wep40->key_hdr, key_hdr,
658 sizeof(struct iwm_umac_key_hdr));
659 memcpy(wep40->key, key_data, key_len);
660 wep40->static_key =
661 !!((auth_type != UMAC_AUTH_TYPE_8021X) &&
662 (auth_type != UMAC_AUTH_TYPE_RSNA_PSK));
664 cmd_size = sizeof(struct iwm_umac_key_wep40);
665 break;
667 case WLAN_CIPHER_SUITE_WEP104:
668 wep104->hdr.oid = UMAC_WIFI_IF_CMD_ADD_WEP104_KEY;
669 wep104->hdr.buf_size =
670 cpu_to_le16(sizeof(struct iwm_umac_key_wep104) -
671 sizeof(struct iwm_umac_wifi_if));
673 memcpy(&wep104->key_hdr, key_hdr,
674 sizeof(struct iwm_umac_key_hdr));
675 memcpy(wep104->key, key_data, key_len);
676 wep104->static_key =
677 !!((auth_type != UMAC_AUTH_TYPE_8021X) &&
678 (auth_type != UMAC_AUTH_TYPE_RSNA_PSK));
680 cmd_size = sizeof(struct iwm_umac_key_wep104);
681 break;
683 case WLAN_CIPHER_SUITE_CCMP:
684 key_hdr->key_idx++;
685 ccmp->hdr.oid = UMAC_WIFI_IF_CMD_ADD_CCMP_KEY;
686 ccmp->hdr.buf_size =
687 cpu_to_le16(sizeof(struct iwm_umac_key_ccmp) -
688 sizeof(struct iwm_umac_wifi_if));
690 memcpy(&ccmp->key_hdr, key_hdr,
691 sizeof(struct iwm_umac_key_hdr));
693 memcpy(ccmp->key, key_data, key_len);
695 if (key->seq_len)
696 memcpy(ccmp->iv_count, key->seq, key->seq_len);
698 cmd_size = sizeof(struct iwm_umac_key_ccmp);
699 break;
701 case WLAN_CIPHER_SUITE_TKIP:
702 key_hdr->key_idx++;
703 tkip->hdr.oid = UMAC_WIFI_IF_CMD_ADD_TKIP_KEY;
704 tkip->hdr.buf_size =
705 cpu_to_le16(sizeof(struct iwm_umac_key_tkip) -
706 sizeof(struct iwm_umac_wifi_if));
708 memcpy(&tkip->key_hdr, key_hdr,
709 sizeof(struct iwm_umac_key_hdr));
711 memcpy(tkip->tkip_key, key_data, IWM_TKIP_KEY_SIZE);
712 memcpy(tkip->mic_tx_key, key_data + IWM_TKIP_KEY_SIZE,
713 IWM_TKIP_MIC_SIZE);
714 memcpy(tkip->mic_rx_key,
715 key_data + IWM_TKIP_KEY_SIZE + IWM_TKIP_MIC_SIZE,
716 IWM_TKIP_MIC_SIZE);
718 if (key->seq_len)
719 memcpy(ccmp->iv_count, key->seq, key->seq_len);
721 cmd_size = sizeof(struct iwm_umac_key_tkip);
722 break;
724 default:
725 return -ENOTSUPP;
728 if ((key->cipher == WLAN_CIPHER_SUITE_TKIP) ||
729 (key->cipher == WLAN_CIPHER_SUITE_CCMP))
731 * UGLY_UGLY_UGLY
732 * Copied HACK from the MWG driver.
733 * Without it, the key is set before the second
734 * EAPOL frame is sent, and the latter is thus
735 * encrypted.
737 schedule_timeout_interruptible(usecs_to_jiffies(300));
739 ret = iwm_send_wifi_if_cmd(iwm, cmd, cmd_size, 1);
740 } else {
741 struct iwm_umac_key_remove key_remove;
743 IWM_DBG_WEXT(iwm, ERR, "Removing key_idx:%d\n", key_idx);
745 key_remove.hdr.oid = UMAC_WIFI_IF_CMD_REMOVE_KEY;
746 key_remove.hdr.buf_size =
747 cpu_to_le16(sizeof(struct iwm_umac_key_remove) -
748 sizeof(struct iwm_umac_wifi_if));
749 memcpy(&key_remove.key_hdr, key_hdr,
750 sizeof(struct iwm_umac_key_hdr));
752 ret = iwm_send_wifi_if_cmd(iwm, &key_remove,
753 sizeof(struct iwm_umac_key_remove),
755 if (ret)
756 return ret;
758 iwm->keys[key_idx].key_len = 0;
761 return ret;
765 int iwm_send_mlme_profile(struct iwm_priv *iwm)
767 int ret;
768 struct iwm_umac_profile profile;
770 memcpy(&profile, iwm->umac_profile, sizeof(profile));
772 profile.hdr.oid = UMAC_WIFI_IF_CMD_SET_PROFILE;
773 profile.hdr.buf_size = cpu_to_le16(sizeof(struct iwm_umac_profile) -
774 sizeof(struct iwm_umac_wifi_if));
776 ret = iwm_send_wifi_if_cmd(iwm, &profile, sizeof(profile), 1);
777 if (ret) {
778 IWM_ERR(iwm, "Send profile command failed\n");
779 return ret;
782 set_bit(IWM_STATUS_SME_CONNECTING, &iwm->status);
783 return 0;
786 int __iwm_invalidate_mlme_profile(struct iwm_priv *iwm)
788 struct iwm_umac_invalidate_profile invalid;
790 invalid.hdr.oid = UMAC_WIFI_IF_CMD_INVALIDATE_PROFILE;
791 invalid.hdr.buf_size =
792 cpu_to_le16(sizeof(struct iwm_umac_invalidate_profile) -
793 sizeof(struct iwm_umac_wifi_if));
795 invalid.reason = WLAN_REASON_UNSPECIFIED;
797 return iwm_send_wifi_if_cmd(iwm, &invalid, sizeof(invalid), 1);
800 int iwm_invalidate_mlme_profile(struct iwm_priv *iwm)
802 int ret;
804 ret = __iwm_invalidate_mlme_profile(iwm);
805 if (ret)
806 return ret;
808 ret = wait_event_interruptible_timeout(iwm->mlme_queue,
809 (iwm->umac_profile_active == 0), 5 * HZ);
811 return ret ? 0 : -EBUSY;
814 int iwm_tx_power_trigger(struct iwm_priv *iwm)
816 struct iwm_umac_pwr_trigger pwr_trigger;
818 pwr_trigger.hdr.oid = UMAC_WIFI_IF_CMD_TX_PWR_TRIGGER;
819 pwr_trigger.hdr.buf_size =
820 cpu_to_le16(sizeof(struct iwm_umac_pwr_trigger) -
821 sizeof(struct iwm_umac_wifi_if));
824 return iwm_send_wifi_if_cmd(iwm, &pwr_trigger, sizeof(pwr_trigger), 1);
827 int iwm_send_umac_stats_req(struct iwm_priv *iwm, u32 flags)
829 struct iwm_udma_wifi_cmd udma_cmd = UDMA_UMAC_INIT;
830 struct iwm_umac_cmd umac_cmd;
831 struct iwm_umac_cmd_stats_req stats_req;
833 stats_req.flags = cpu_to_le32(flags);
835 umac_cmd.id = UMAC_CMD_OPCODE_STATISTIC_REQUEST;
836 umac_cmd.resp = 0;
838 return iwm_hal_send_umac_cmd(iwm, &udma_cmd, &umac_cmd, &stats_req,
839 sizeof(struct iwm_umac_cmd_stats_req));
842 int iwm_send_umac_channel_list(struct iwm_priv *iwm)
844 struct iwm_udma_wifi_cmd udma_cmd = UDMA_UMAC_INIT;
845 struct iwm_umac_cmd umac_cmd;
846 struct iwm_umac_cmd_get_channel_list *ch_list;
847 int size = sizeof(struct iwm_umac_cmd_get_channel_list) +
848 sizeof(struct iwm_umac_channel_info) * 4;
849 int ret;
851 ch_list = kzalloc(size, GFP_KERNEL);
852 if (!ch_list) {
853 IWM_ERR(iwm, "Couldn't allocate channel list cmd\n");
854 return -ENOMEM;
857 ch_list->ch[0].band = UMAC_BAND_2GHZ;
858 ch_list->ch[0].type = UMAC_CHANNEL_WIDTH_20MHZ;
859 ch_list->ch[0].flags = UMAC_CHANNEL_FLAG_VALID;
861 ch_list->ch[1].band = UMAC_BAND_5GHZ;
862 ch_list->ch[1].type = UMAC_CHANNEL_WIDTH_20MHZ;
863 ch_list->ch[1].flags = UMAC_CHANNEL_FLAG_VALID;
865 ch_list->ch[2].band = UMAC_BAND_2GHZ;
866 ch_list->ch[2].type = UMAC_CHANNEL_WIDTH_20MHZ;
867 ch_list->ch[2].flags = UMAC_CHANNEL_FLAG_VALID | UMAC_CHANNEL_FLAG_IBSS;
869 ch_list->ch[3].band = UMAC_BAND_5GHZ;
870 ch_list->ch[3].type = UMAC_CHANNEL_WIDTH_20MHZ;
871 ch_list->ch[3].flags = UMAC_CHANNEL_FLAG_VALID | UMAC_CHANNEL_FLAG_IBSS;
873 ch_list->count = cpu_to_le16(4);
875 umac_cmd.id = UMAC_CMD_OPCODE_GET_CHAN_INFO_LIST;
876 umac_cmd.resp = 1;
878 ret = iwm_hal_send_umac_cmd(iwm, &udma_cmd, &umac_cmd, ch_list, size);
880 kfree(ch_list);
882 return ret;
885 int iwm_scan_ssids(struct iwm_priv *iwm, struct cfg80211_ssid *ssids,
886 int ssid_num)
888 struct iwm_umac_cmd_scan_request req;
889 int i, ret;
891 memset(&req, 0, sizeof(struct iwm_umac_cmd_scan_request));
893 req.hdr.oid = UMAC_WIFI_IF_CMD_SCAN_REQUEST;
894 req.hdr.buf_size = cpu_to_le16(sizeof(struct iwm_umac_cmd_scan_request)
895 - sizeof(struct iwm_umac_wifi_if));
896 req.type = UMAC_WIFI_IF_SCAN_TYPE_USER;
897 req.timeout = 2;
898 req.seq_num = iwm->scan_id;
899 req.ssid_num = min(ssid_num, UMAC_WIFI_IF_PROBE_OPTION_MAX);
901 for (i = 0; i < req.ssid_num; i++) {
902 memcpy(req.ssids[i].ssid, ssids[i].ssid, ssids[i].ssid_len);
903 req.ssids[i].ssid_len = ssids[i].ssid_len;
906 ret = iwm_send_wifi_if_cmd(iwm, &req, sizeof(req), 0);
907 if (ret) {
908 IWM_ERR(iwm, "Couldn't send scan request\n");
909 return ret;
912 iwm->scan_id = (iwm->scan_id + 1) % IWM_SCAN_ID_MAX;
914 return 0;
917 int iwm_scan_one_ssid(struct iwm_priv *iwm, u8 *ssid, int ssid_len)
919 struct cfg80211_ssid one_ssid;
921 if (test_and_set_bit(IWM_STATUS_SCANNING, &iwm->status))
922 return 0;
924 one_ssid.ssid_len = min(ssid_len, IEEE80211_MAX_SSID_LEN);
925 memcpy(&one_ssid.ssid, ssid, one_ssid.ssid_len);
927 return iwm_scan_ssids(iwm, &one_ssid, 1);
930 int iwm_target_reset(struct iwm_priv *iwm)
932 struct iwm_udma_nonwifi_cmd target_cmd;
934 target_cmd.opcode = UMAC_HDI_OUT_OPCODE_REBOOT;
935 target_cmd.addr = 0;
936 target_cmd.op1_sz = 0;
937 target_cmd.op2 = 0;
938 target_cmd.handle_by_hw = 0;
939 target_cmd.resp = 0;
940 target_cmd.eop = 1;
942 return iwm_hal_send_target_cmd(iwm, &target_cmd, NULL);
945 int iwm_send_umac_stop_resume_tx(struct iwm_priv *iwm,
946 struct iwm_umac_notif_stop_resume_tx *ntf)
948 struct iwm_udma_wifi_cmd udma_cmd = UDMA_UMAC_INIT;
949 struct iwm_umac_cmd umac_cmd;
950 struct iwm_umac_cmd_stop_resume_tx stp_res_cmd;
951 struct iwm_sta_info *sta_info;
952 u8 sta_id = STA_ID_N_COLOR_ID(ntf->sta_id);
953 int i;
955 sta_info = &iwm->sta_table[sta_id];
956 if (!sta_info->valid) {
957 IWM_ERR(iwm, "Invalid STA: %d\n", sta_id);
958 return -EINVAL;
961 umac_cmd.id = UMAC_CMD_OPCODE_STOP_RESUME_STA_TX;
962 umac_cmd.resp = 0;
964 stp_res_cmd.flags = ntf->flags;
965 stp_res_cmd.sta_id = ntf->sta_id;
966 stp_res_cmd.stop_resume_tid_msk = ntf->stop_resume_tid_msk;
967 for (i = 0; i < IWM_UMAC_TID_NR; i++)
968 stp_res_cmd.last_seq_num[i] =
969 sta_info->tid_info[i].last_seq_num;
971 return iwm_hal_send_umac_cmd(iwm, &udma_cmd, &umac_cmd, &stp_res_cmd,
972 sizeof(struct iwm_umac_cmd_stop_resume_tx));
976 int iwm_send_pmkid_update(struct iwm_priv *iwm,
977 struct cfg80211_pmksa *pmksa, u32 command)
979 struct iwm_umac_pmkid_update update;
980 int ret;
982 memset(&update, 0, sizeof(struct iwm_umac_pmkid_update));
984 update.hdr.oid = UMAC_WIFI_IF_CMD_PMKID_UPDATE;
985 update.hdr.buf_size = cpu_to_le16(sizeof(struct iwm_umac_pmkid_update) -
986 sizeof(struct iwm_umac_wifi_if));
988 update.command = cpu_to_le32(command);
989 if (pmksa->bssid)
990 memcpy(&update.bssid, pmksa->bssid, ETH_ALEN);
991 if (pmksa->pmkid)
992 memcpy(&update.pmkid, pmksa->pmkid, WLAN_PMKID_LEN);
994 ret = iwm_send_wifi_if_cmd(iwm, &update,
995 sizeof(struct iwm_umac_pmkid_update), 0);
996 if (ret) {
997 IWM_ERR(iwm, "PMKID update command failed\n");
998 return ret;
1001 return 0;