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
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
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>
51 static int iwm_send_lmac_ptrough_cmd(struct iwm_priv *iwm,
53 const void *lmac_payload,
54 u16 lmac_payload_size,
57 struct iwm_udma_wifi_cmd udma_cmd = UDMA_LMAC_INIT;
58 struct iwm_umac_cmd umac_cmd;
59 struct iwm_lmac_cmd lmac_cmd;
61 lmac_cmd.id = lmac_cmd_id;
63 umac_cmd.id = UMAC_CMD_OPCODE_WIFI_PASS_THROUGH;
66 return iwm_hal_send_host_cmd(iwm, &udma_cmd, &umac_cmd, &lmac_cmd,
67 lmac_payload, lmac_payload_size);
70 int iwm_send_wifi_if_cmd(struct iwm_priv *iwm, void *payload, u16 payload_size,
73 struct iwm_umac_wifi_if *hdr = (struct iwm_umac_wifi_if *)payload;
74 struct iwm_udma_wifi_cmd udma_cmd = UDMA_UMAC_INIT;
75 struct iwm_umac_cmd umac_cmd;
79 umac_cmd.id = UMAC_CMD_OPCODE_WIFI_IF_WRAPPER;
82 ret = iwm_hal_send_umac_cmd(iwm, &udma_cmd, &umac_cmd,
83 payload, payload_size);
86 ret = wait_event_interruptible_timeout(iwm->wifi_ntfy_queue,
87 test_and_clear_bit(oid, &iwm->wifi_ntfy[0]),
97 static struct coex_event iwm_sta_xor_prio_tbl[COEX_EVENTS_NUM] =
99 {4, 3, 0, COEX_UNASSOC_IDLE_FLAGS},
100 {4, 3, 0, COEX_UNASSOC_MANUAL_SCAN_FLAGS},
101 {4, 3, 0, COEX_UNASSOC_AUTO_SCAN_FLAGS},
102 {4, 3, 0, COEX_CALIBRATION_FLAGS},
103 {4, 3, 0, COEX_PERIODIC_CALIBRATION_FLAGS},
104 {4, 3, 0, COEX_CONNECTION_ESTAB_FLAGS},
105 {4, 3, 0, COEX_ASSOCIATED_IDLE_FLAGS},
106 {4, 3, 0, COEX_ASSOC_MANUAL_SCAN_FLAGS},
107 {4, 3, 0, COEX_ASSOC_AUTO_SCAN_FLAGS},
108 {4, 3, 0, COEX_ASSOC_ACTIVE_LEVEL_FLAGS},
109 {6, 3, 0, COEX_XOR_RF_ON_FLAGS},
110 {4, 3, 0, COEX_RF_OFF_FLAGS},
111 {6, 6, 0, COEX_STAND_ALONE_DEBUG_FLAGS},
112 {4, 3, 0, COEX_IPAN_ASSOC_LEVEL_FLAGS},
113 {4, 3, 0, COEX_RSRVD1_FLAGS},
114 {4, 3, 0, COEX_RSRVD2_FLAGS}
117 static struct coex_event iwm_sta_cm_prio_tbl[COEX_EVENTS_NUM] =
119 {1, 1, 0, COEX_UNASSOC_IDLE_FLAGS},
120 {4, 3, 0, COEX_UNASSOC_MANUAL_SCAN_FLAGS},
121 {3, 3, 0, COEX_UNASSOC_AUTO_SCAN_FLAGS},
122 {5, 5, 0, COEX_CALIBRATION_FLAGS},
123 {4, 4, 0, COEX_PERIODIC_CALIBRATION_FLAGS},
124 {5, 4, 0, COEX_CONNECTION_ESTAB_FLAGS},
125 {4, 4, 0, COEX_ASSOCIATED_IDLE_FLAGS},
126 {4, 4, 0, COEX_ASSOC_MANUAL_SCAN_FLAGS},
127 {4, 4, 0, COEX_ASSOC_AUTO_SCAN_FLAGS},
128 {4, 4, 0, COEX_ASSOC_ACTIVE_LEVEL_FLAGS},
129 {1, 1, 0, COEX_RF_ON_FLAGS},
130 {1, 1, 0, COEX_RF_OFF_FLAGS},
131 {6, 6, 0, COEX_STAND_ALONE_DEBUG_FLAGS},
132 {5, 4, 0, COEX_IPAN_ASSOC_LEVEL_FLAGS},
133 {1, 1, 0, COEX_RSRVD1_FLAGS},
134 {1, 1, 0, COEX_RSRVD2_FLAGS}
137 int iwm_send_prio_table(struct iwm_priv *iwm)
139 struct iwm_coex_prio_table_cmd coex_table_cmd;
140 u32 coex_enabled, mode_enabled;
142 memset(&coex_table_cmd, 0, sizeof(struct iwm_coex_prio_table_cmd));
144 coex_table_cmd.flags = COEX_FLAGS_STA_TABLE_VALID_MSK;
146 switch (iwm->conf.coexist_mode) {
156 switch (iwm->conf.mode) {
166 if (coex_enabled && mode_enabled) {
167 coex_table_cmd.flags |= COEX_FLAGS_COEX_ENABLE_MSK |
168 COEX_FLAGS_ASSOC_WAKEUP_UMASK_MSK |
169 COEX_FLAGS_UNASSOC_WAKEUP_UMASK_MSK;
171 switch (iwm->conf.coexist_mode) {
173 memcpy(coex_table_cmd.sta_prio, iwm_sta_xor_prio_tbl,
174 sizeof(iwm_sta_xor_prio_tbl));
177 memcpy(coex_table_cmd.sta_prio, iwm_sta_cm_prio_tbl,
178 sizeof(iwm_sta_cm_prio_tbl));
181 IWM_ERR(iwm, "Invalid coex_mode 0x%x\n",
182 iwm->conf.coexist_mode);
186 IWM_WARN(iwm, "coexistense disabled\n");
188 return iwm_send_lmac_ptrough_cmd(iwm, COEX_PRIORITY_TABLE_CMD,
190 sizeof(struct iwm_coex_prio_table_cmd), 1);
193 int iwm_send_init_calib_cfg(struct iwm_priv *iwm, u8 calib_requested)
195 struct iwm_lmac_cal_cfg_cmd cal_cfg_cmd;
197 memset(&cal_cfg_cmd, 0, sizeof(struct iwm_lmac_cal_cfg_cmd));
199 cal_cfg_cmd.ucode_cfg.init.enable = cpu_to_le32(calib_requested);
200 cal_cfg_cmd.ucode_cfg.init.start = cpu_to_le32(calib_requested);
201 cal_cfg_cmd.ucode_cfg.init.send_res = cpu_to_le32(calib_requested);
202 cal_cfg_cmd.ucode_cfg.flags =
203 cpu_to_le32(CALIB_CFG_FLAG_SEND_COMPLETE_NTFY_AFTER_MSK);
205 return iwm_send_lmac_ptrough_cmd(iwm, CALIBRATION_CFG_CMD, &cal_cfg_cmd,
206 sizeof(struct iwm_lmac_cal_cfg_cmd), 1);
209 int iwm_send_periodic_calib_cfg(struct iwm_priv *iwm, u8 calib_requested)
211 struct iwm_lmac_cal_cfg_cmd cal_cfg_cmd;
213 memset(&cal_cfg_cmd, 0, sizeof(struct iwm_lmac_cal_cfg_cmd));
215 cal_cfg_cmd.ucode_cfg.periodic.enable = cpu_to_le32(calib_requested);
216 cal_cfg_cmd.ucode_cfg.periodic.start = cpu_to_le32(calib_requested);
218 return iwm_send_lmac_ptrough_cmd(iwm, CALIBRATION_CFG_CMD, &cal_cfg_cmd,
219 sizeof(struct iwm_lmac_cal_cfg_cmd), 0);
222 int iwm_store_rxiq_calib_result(struct iwm_priv *iwm)
224 struct iwm_calib_rxiq *rxiq;
225 u8 *eeprom_rxiq = iwm_eeprom_access(iwm, IWM_EEPROM_CALIB_RXIQ);
226 int grplen = sizeof(struct iwm_calib_rxiq_group);
228 rxiq = kzalloc(sizeof(struct iwm_calib_rxiq), GFP_KERNEL);
230 IWM_ERR(iwm, "Couldn't alloc memory for RX IQ\n");
234 eeprom_rxiq = iwm_eeprom_access(iwm, IWM_EEPROM_CALIB_RXIQ);
235 if (IS_ERR(eeprom_rxiq)) {
236 IWM_ERR(iwm, "Couldn't access EEPROM RX IQ entry\n");
237 return PTR_ERR(eeprom_rxiq);
240 iwm->calib_res[SHILOH_PHY_CALIBRATE_RX_IQ_CMD].buf = (u8 *)rxiq;
241 iwm->calib_res[SHILOH_PHY_CALIBRATE_RX_IQ_CMD].size = sizeof(*rxiq);
243 rxiq->hdr.opcode = SHILOH_PHY_CALIBRATE_RX_IQ_CMD;
244 rxiq->hdr.first_grp = 0;
245 rxiq->hdr.grp_num = 1;
246 rxiq->hdr.all_data_valid = 1;
248 memcpy(&rxiq->group[0], eeprom_rxiq, 4 * grplen);
249 memcpy(&rxiq->group[4], eeprom_rxiq + 6 * grplen, grplen);
254 int iwm_send_calib_results(struct iwm_priv *iwm)
258 for (i = PHY_CALIBRATE_OPCODES_NUM; i < CALIBRATION_CMD_NUM; i++) {
259 if (test_bit(i - PHY_CALIBRATE_OPCODES_NUM,
260 &iwm->calib_done_map)) {
261 IWM_DBG_CMD(iwm, DBG,
262 "Send calibration %d result\n", i);
263 ret |= iwm_send_lmac_ptrough_cmd(iwm,
264 REPLY_PHY_CALIBRATION_CMD,
265 iwm->calib_res[i].buf,
266 iwm->calib_res[i].size, 0);
268 kfree(iwm->calib_res[i].buf);
269 iwm->calib_res[i].buf = NULL;
270 iwm->calib_res[i].size = 0;
277 int iwm_send_umac_reset(struct iwm_priv *iwm, __le32 reset_flags, bool resp)
279 struct iwm_udma_wifi_cmd udma_cmd = UDMA_UMAC_INIT;
280 struct iwm_umac_cmd umac_cmd;
281 struct iwm_umac_cmd_reset reset;
283 reset.flags = reset_flags;
285 umac_cmd.id = UMAC_CMD_OPCODE_RESET;
286 umac_cmd.resp = resp;
288 return iwm_hal_send_umac_cmd(iwm, &udma_cmd, &umac_cmd, &reset,
289 sizeof(struct iwm_umac_cmd_reset));
292 int iwm_umac_set_config_fix(struct iwm_priv *iwm, u16 tbl, u16 key, u32 value)
294 struct iwm_udma_wifi_cmd udma_cmd = UDMA_UMAC_INIT;
295 struct iwm_umac_cmd umac_cmd;
296 struct iwm_umac_cmd_set_param_fix param;
298 if ((tbl != UMAC_PARAM_TBL_CFG_FIX) &&
299 (tbl != UMAC_PARAM_TBL_FA_CFG_FIX))
302 umac_cmd.id = UMAC_CMD_OPCODE_SET_PARAM_FIX;
305 param.tbl = cpu_to_le16(tbl);
306 param.key = cpu_to_le16(key);
307 param.value = cpu_to_le32(value);
309 return iwm_hal_send_umac_cmd(iwm, &udma_cmd, &umac_cmd, ¶m,
310 sizeof(struct iwm_umac_cmd_set_param_fix));
313 int iwm_umac_set_config_var(struct iwm_priv *iwm, u16 key,
314 void *payload, u16 payload_size)
316 struct iwm_udma_wifi_cmd udma_cmd = UDMA_UMAC_INIT;
317 struct iwm_umac_cmd umac_cmd;
318 struct iwm_umac_cmd_set_param_var *param_hdr;
322 param = kzalloc(payload_size +
323 sizeof(struct iwm_umac_cmd_set_param_var), GFP_KERNEL);
325 IWM_ERR(iwm, "Couldn't allocate param\n");
329 param_hdr = (struct iwm_umac_cmd_set_param_var *)param;
331 umac_cmd.id = UMAC_CMD_OPCODE_SET_PARAM_VAR;
334 param_hdr->tbl = cpu_to_le16(UMAC_PARAM_TBL_CFG_VAR);
335 param_hdr->key = cpu_to_le16(key);
336 param_hdr->len = cpu_to_le16(payload_size);
337 memcpy(param + sizeof(struct iwm_umac_cmd_set_param_var),
338 payload, payload_size);
340 ret = iwm_hal_send_umac_cmd(iwm, &udma_cmd, &umac_cmd, param,
341 sizeof(struct iwm_umac_cmd_set_param_var) +
348 int iwm_send_umac_config(struct iwm_priv *iwm,
353 /* Use UMAC default values */
354 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
355 CFG_POWER_INDEX, iwm->conf.power_index);
359 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_FA_CFG_FIX,
361 iwm->conf.frag_threshold);
365 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
367 iwm->conf.rts_threshold);
371 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
372 CFG_CTS_TO_SELF, iwm->conf.cts_to_self);
376 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
377 CFG_COEX_MODE, iwm->conf.coexist_mode);
382 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
383 CFG_ASSOCIATION_TIMEOUT,
384 iwm->conf.assoc_timeout);
388 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
390 iwm->conf.roam_timeout);
394 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
396 WIRELESS_MODE_11A | WIRELESS_MODE_11G);
401 ret = iwm_umac_set_config_var(iwm, CFG_NET_ADDR,
402 iwm_to_ndev(iwm)->dev_addr, ETH_ALEN);
406 /* UMAC PM static configurations */
407 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
408 CFG_PM_LEGACY_RX_TIMEOUT, 0x12C);
412 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
413 CFG_PM_LEGACY_TX_TIMEOUT, 0x15E);
417 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
418 CFG_PM_CTRL_FLAGS, 0x30001);
422 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
423 CFG_PM_KEEP_ALIVE_IN_BEACONS, 0x80);
428 ret = iwm_send_umac_reset(iwm, reset_flags, 1);
432 ret = iwm_notif_handle(iwm, UMAC_CMD_OPCODE_RESET, IWM_SRC_UMAC,
435 IWM_ERR(iwm, "Wait for UMAC RESET timeout\n");
442 int iwm_send_packet(struct iwm_priv *iwm, struct sk_buff *skb, int pool_id)
444 struct iwm_udma_wifi_cmd udma_cmd;
445 struct iwm_umac_cmd umac_cmd;
446 struct iwm_tx_info *tx_info = skb_to_tx_info(skb);
448 udma_cmd.eop = 1; /* always set eop for non-concatenated Tx */
449 udma_cmd.credit_group = pool_id;
450 udma_cmd.ra_tid = tx_info->sta << 4 | tx_info->tid;
451 udma_cmd.lmac_offset = 0;
453 umac_cmd.id = REPLY_TX;
454 umac_cmd.color = tx_info->color;
457 return iwm_hal_send_umac_cmd(iwm, &udma_cmd, &umac_cmd,
458 skb->data, skb->len);
461 static int iwm_target_read(struct iwm_priv *iwm, __le32 address,
462 u8 *response, u32 resp_size)
464 struct iwm_udma_nonwifi_cmd target_cmd;
465 struct iwm_nonwifi_cmd *cmd;
469 target_cmd.opcode = UMAC_HDI_OUT_OPCODE_READ;
470 target_cmd.addr = address;
471 target_cmd.op1_sz = cpu_to_le32(resp_size);
473 target_cmd.handle_by_hw = 0;
477 ret = iwm_hal_send_target_cmd(iwm, &target_cmd, NULL);
479 IWM_ERR(iwm, "Couldn't send READ command\n");
481 /* When succeding, the send_target routine returns the seq number */
484 ret = wait_event_interruptible_timeout(iwm->nonwifi_queue,
485 (cmd = iwm_get_pending_nonwifi_cmd(iwm, seq_num,
486 UMAC_HDI_OUT_OPCODE_READ)) != NULL,
490 IWM_ERR(iwm, "Didn't receive a target READ answer\n");
494 memcpy(response, cmd->buf.hdr + sizeof(struct iwm_udma_in_hdr),
502 int iwm_read_mac(struct iwm_priv *iwm, u8 *mac)
505 u8 mac_align[ALIGN(ETH_ALEN, 8)];
507 ret = iwm_target_read(iwm, cpu_to_le32(WICO_MAC_ADDRESS_ADDR),
508 mac_align, sizeof(mac_align));
512 if (is_valid_ether_addr(mac_align))
513 memcpy(mac, mac_align, ETH_ALEN);
515 IWM_ERR(iwm, "Invalid EEPROM MAC\n");
516 memcpy(mac, iwm->conf.mac_addr, ETH_ALEN);
517 get_random_bytes(&mac[3], 3);
523 int iwm_set_tx_key(struct iwm_priv *iwm, u8 key_idx)
525 struct iwm_umac_tx_key_id tx_key_id;
527 if (!iwm->default_key || !iwm->default_key->in_use)
530 tx_key_id.hdr.oid = UMAC_WIFI_IF_CMD_GLOBAL_TX_KEY_ID;
531 tx_key_id.hdr.buf_size = cpu_to_le16(sizeof(struct iwm_umac_tx_key_id) -
532 sizeof(struct iwm_umac_wifi_if));
534 tx_key_id.key_idx = key_idx;
536 return iwm_send_wifi_if_cmd(iwm, &tx_key_id, sizeof(tx_key_id), 1);
539 static int iwm_check_profile(struct iwm_priv *iwm)
541 if (!iwm->umac_profile_active)
544 if (iwm->umac_profile->sec.ucast_cipher != UMAC_CIPHER_TYPE_WEP_40 &&
545 iwm->umac_profile->sec.ucast_cipher != UMAC_CIPHER_TYPE_WEP_104 &&
546 iwm->umac_profile->sec.ucast_cipher != UMAC_CIPHER_TYPE_TKIP &&
547 iwm->umac_profile->sec.ucast_cipher != UMAC_CIPHER_TYPE_CCMP) {
548 IWM_ERR(iwm, "Wrong unicast cipher: 0x%x\n",
549 iwm->umac_profile->sec.ucast_cipher);
553 if (iwm->umac_profile->sec.mcast_cipher != UMAC_CIPHER_TYPE_WEP_40 &&
554 iwm->umac_profile->sec.mcast_cipher != UMAC_CIPHER_TYPE_WEP_104 &&
555 iwm->umac_profile->sec.mcast_cipher != UMAC_CIPHER_TYPE_TKIP &&
556 iwm->umac_profile->sec.mcast_cipher != UMAC_CIPHER_TYPE_CCMP) {
557 IWM_ERR(iwm, "Wrong multicast cipher: 0x%x\n",
558 iwm->umac_profile->sec.mcast_cipher);
562 if ((iwm->umac_profile->sec.ucast_cipher == UMAC_CIPHER_TYPE_WEP_40 ||
563 iwm->umac_profile->sec.ucast_cipher == UMAC_CIPHER_TYPE_WEP_104) &&
564 (iwm->umac_profile->sec.ucast_cipher !=
565 iwm->umac_profile->sec.mcast_cipher)) {
566 IWM_ERR(iwm, "Unicast and multicast ciphers differ for WEP\n");
572 int iwm_set_key(struct iwm_priv *iwm, bool remove, bool set_tx_key,
576 u8 cmd[64], *sta_addr, *key_data, key_len;
579 struct iwm_umac_key_hdr *key_hdr = &key->hdr;
580 struct iwm_umac_key_wep40 *wep40 = (struct iwm_umac_key_wep40 *)cmd;
581 struct iwm_umac_key_wep104 *wep104 = (struct iwm_umac_key_wep104 *)cmd;
582 struct iwm_umac_key_tkip *tkip = (struct iwm_umac_key_tkip *)cmd;
583 struct iwm_umac_key_ccmp *ccmp = (struct iwm_umac_key_ccmp *)cmd;
586 iwm->default_key = key;
589 * We check if our current profile is valid.
590 * If not, we dont push the key, we just cache them,
591 * so that with the next siwsessid call, the keys
592 * will be actually pushed.
595 ret = iwm_check_profile(iwm);
600 sta_addr = key->hdr.mac;
602 key_len = key->key_len;
603 key_idx = key->hdr.key_idx;
606 IWM_DBG_WEXT(iwm, DBG, "key_idx:%d set tx key:%d\n",
607 key_idx, set_tx_key);
608 IWM_DBG_WEXT(iwm, DBG, "key_len:%d\n", key_len);
609 IWM_DBG_WEXT(iwm, DBG, "MAC:%pM, idx:%d, multicast:%d\n",
610 key_hdr->mac, key_hdr->key_idx, key_hdr->multicast);
612 IWM_DBG_WEXT(iwm, DBG, "profile: mcast:0x%x, ucast:0x%x\n",
613 iwm->umac_profile->sec.mcast_cipher,
614 iwm->umac_profile->sec.ucast_cipher);
615 IWM_DBG_WEXT(iwm, DBG, "profile: auth_type:0x%x, flags:0x%x\n",
616 iwm->umac_profile->sec.auth_type,
617 iwm->umac_profile->sec.flags);
620 case UMAC_CIPHER_TYPE_WEP_40:
621 wep40->hdr.oid = UMAC_WIFI_IF_CMD_ADD_WEP40_KEY;
622 wep40->hdr.buf_size =
623 cpu_to_le16(sizeof(struct iwm_umac_key_wep40) -
624 sizeof(struct iwm_umac_wifi_if));
626 memcpy(&wep40->key_hdr, key_hdr,
627 sizeof(struct iwm_umac_key_hdr));
628 memcpy(wep40->key, key_data, key_len);
629 wep40->static_key = 1;
631 cmd_size = sizeof(struct iwm_umac_key_wep40);
634 case UMAC_CIPHER_TYPE_WEP_104:
635 wep104->hdr.oid = UMAC_WIFI_IF_CMD_ADD_WEP104_KEY;
636 wep104->hdr.buf_size =
637 cpu_to_le16(sizeof(struct iwm_umac_key_wep104) -
638 sizeof(struct iwm_umac_wifi_if));
640 memcpy(&wep104->key_hdr, key_hdr,
641 sizeof(struct iwm_umac_key_hdr));
642 memcpy(wep104->key, key_data, key_len);
643 wep104->static_key = 1;
645 cmd_size = sizeof(struct iwm_umac_key_wep104);
648 case UMAC_CIPHER_TYPE_CCMP:
650 ccmp->hdr.oid = UMAC_WIFI_IF_CMD_ADD_CCMP_KEY;
652 cpu_to_le16(sizeof(struct iwm_umac_key_ccmp) -
653 sizeof(struct iwm_umac_wifi_if));
655 memcpy(&ccmp->key_hdr, key_hdr,
656 sizeof(struct iwm_umac_key_hdr));
658 memcpy(ccmp->key, key_data, key_len);
660 if (key->flags & IW_ENCODE_EXT_RX_SEQ_VALID)
661 memcpy(ccmp->iv_count, key->rx_seq, 6);
663 cmd_size = sizeof(struct iwm_umac_key_ccmp);
666 case UMAC_CIPHER_TYPE_TKIP:
668 tkip->hdr.oid = UMAC_WIFI_IF_CMD_ADD_TKIP_KEY;
670 cpu_to_le16(sizeof(struct iwm_umac_key_tkip) -
671 sizeof(struct iwm_umac_wifi_if));
673 memcpy(&tkip->key_hdr, key_hdr,
674 sizeof(struct iwm_umac_key_hdr));
676 memcpy(tkip->tkip_key, key_data, IWM_TKIP_KEY_SIZE);
677 memcpy(tkip->mic_tx_key, key_data + IWM_TKIP_KEY_SIZE,
679 memcpy(tkip->mic_rx_key,
680 key_data + IWM_TKIP_KEY_SIZE + IWM_TKIP_MIC_SIZE,
683 if (key->flags & IW_ENCODE_EXT_RX_SEQ_VALID)
684 memcpy(ccmp->iv_count, key->rx_seq, 6);
686 cmd_size = sizeof(struct iwm_umac_key_tkip);
693 if ((key->alg == UMAC_CIPHER_TYPE_CCMP) ||
694 (key->alg == UMAC_CIPHER_TYPE_TKIP))
697 * Copied HACK from the MWG driver.
698 * Without it, the key is set before the second
699 * EAPOL frame is sent, and the latter is thus
702 schedule_timeout_interruptible(usecs_to_jiffies(300));
704 ret = iwm_send_wifi_if_cmd(iwm, cmd, cmd_size, 1);
709 * We need a default key only if it is set and
710 * if we're doing WEP.
712 if (iwm->default_key == key &&
713 ((key->alg == UMAC_CIPHER_TYPE_WEP_40) ||
714 (key->alg == UMAC_CIPHER_TYPE_WEP_104))) {
715 ret = iwm_set_tx_key(iwm, key_idx);
720 struct iwm_umac_key_remove key_remove;
722 key_remove.hdr.oid = UMAC_WIFI_IF_CMD_REMOVE_KEY;
723 key_remove.hdr.buf_size =
724 cpu_to_le16(sizeof(struct iwm_umac_key_remove) -
725 sizeof(struct iwm_umac_wifi_if));
726 memcpy(&key_remove.key_hdr, key_hdr,
727 sizeof(struct iwm_umac_key_hdr));
729 ret = iwm_send_wifi_if_cmd(iwm, &key_remove,
730 sizeof(struct iwm_umac_key_remove),
735 iwm->keys[key_idx].in_use = 0;
746 int iwm_send_mlme_profile(struct iwm_priv *iwm)
749 struct iwm_umac_profile profile;
751 memcpy(&profile, iwm->umac_profile, sizeof(profile));
753 profile.hdr.oid = UMAC_WIFI_IF_CMD_SET_PROFILE;
754 profile.hdr.buf_size = cpu_to_le16(sizeof(struct iwm_umac_profile) -
755 sizeof(struct iwm_umac_wifi_if));
757 ret = iwm_send_wifi_if_cmd(iwm, &profile, sizeof(profile), 1);
759 IWM_ERR(iwm, "Send profile command failed\n");
763 for (i = 0; i < IWM_NUM_KEYS; i++)
764 if (iwm->keys[i].in_use) {
766 struct iwm_key *key = &iwm->keys[i];
768 if (key == iwm->default_key)
771 /* Wait for the profile before sending the keys */
772 wait_event_interruptible_timeout(iwm->mlme_queue,
773 (test_bit(IWM_STATUS_ASSOCIATING, &iwm->status) ||
774 test_bit(IWM_STATUS_ASSOCIATED, &iwm->status)),
777 ret = iwm_set_key(iwm, 0, default_key, key);
785 int iwm_invalidate_mlme_profile(struct iwm_priv *iwm)
787 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 ret = iwm_send_wifi_if_cmd(iwm, &invalid, sizeof(invalid), 1);
801 ret = wait_event_interruptible_timeout(iwm->mlme_queue,
802 (iwm->umac_profile_active == 0), 2 * HZ);
809 int iwm_send_umac_stats_req(struct iwm_priv *iwm, u32 flags)
811 struct iwm_udma_wifi_cmd udma_cmd = UDMA_UMAC_INIT;
812 struct iwm_umac_cmd umac_cmd;
813 struct iwm_umac_cmd_stats_req stats_req;
815 stats_req.flags = cpu_to_le32(flags);
817 umac_cmd.id = UMAC_CMD_OPCODE_STATISTIC_REQUEST;
820 return iwm_hal_send_umac_cmd(iwm, &udma_cmd, &umac_cmd, &stats_req,
821 sizeof(struct iwm_umac_cmd_stats_req));
824 int iwm_send_umac_channel_list(struct iwm_priv *iwm)
826 struct iwm_udma_wifi_cmd udma_cmd = UDMA_UMAC_INIT;
827 struct iwm_umac_cmd umac_cmd;
828 struct iwm_umac_cmd_get_channel_list *ch_list;
829 int size = sizeof(struct iwm_umac_cmd_get_channel_list) +
830 sizeof(struct iwm_umac_channel_info) * 4;
833 ch_list = kzalloc(size, GFP_KERNEL);
835 IWM_ERR(iwm, "Couldn't allocate channel list cmd\n");
839 ch_list->ch[0].band = UMAC_BAND_2GHZ;
840 ch_list->ch[0].type = UMAC_CHANNEL_WIDTH_20MHZ;
841 ch_list->ch[0].flags = UMAC_CHANNEL_FLAG_VALID;
843 ch_list->ch[1].band = UMAC_BAND_5GHZ;
844 ch_list->ch[1].type = UMAC_CHANNEL_WIDTH_20MHZ;
845 ch_list->ch[1].flags = UMAC_CHANNEL_FLAG_VALID;
847 ch_list->ch[2].band = UMAC_BAND_2GHZ;
848 ch_list->ch[2].type = UMAC_CHANNEL_WIDTH_20MHZ;
849 ch_list->ch[2].flags = UMAC_CHANNEL_FLAG_VALID | UMAC_CHANNEL_FLAG_IBSS;
851 ch_list->ch[3].band = UMAC_BAND_5GHZ;
852 ch_list->ch[3].type = UMAC_CHANNEL_WIDTH_20MHZ;
853 ch_list->ch[3].flags = UMAC_CHANNEL_FLAG_VALID | UMAC_CHANNEL_FLAG_IBSS;
855 ch_list->count = cpu_to_le16(4);
857 umac_cmd.id = UMAC_CMD_OPCODE_GET_CHAN_INFO_LIST;
860 ret = iwm_hal_send_umac_cmd(iwm, &udma_cmd, &umac_cmd, ch_list, size);
867 int iwm_scan_ssids(struct iwm_priv *iwm, struct cfg80211_ssid *ssids,
870 struct iwm_umac_cmd_scan_request req;
873 memset(&req, 0, sizeof(struct iwm_umac_cmd_scan_request));
875 req.hdr.oid = UMAC_WIFI_IF_CMD_SCAN_REQUEST;
876 req.hdr.buf_size = cpu_to_le16(sizeof(struct iwm_umac_cmd_scan_request)
877 - sizeof(struct iwm_umac_wifi_if));
878 req.type = UMAC_WIFI_IF_SCAN_TYPE_USER;
880 req.seq_num = iwm->scan_id;
881 req.ssid_num = min(ssid_num, UMAC_WIFI_IF_PROBE_OPTION_MAX);
883 for (i = 0; i < req.ssid_num; i++) {
884 memcpy(req.ssids[i].ssid, ssids[i].ssid, ssids[i].ssid_len);
885 req.ssids[i].ssid_len = ssids[i].ssid_len;
888 ret = iwm_send_wifi_if_cmd(iwm, &req, sizeof(req), 0);
890 IWM_ERR(iwm, "Couldn't send scan request\n");
894 iwm->scan_id = iwm->scan_id++ % IWM_SCAN_ID_MAX;
899 int iwm_scan_one_ssid(struct iwm_priv *iwm, u8 *ssid, int ssid_len)
901 struct cfg80211_ssid one_ssid;
903 if (test_and_set_bit(IWM_STATUS_SCANNING, &iwm->status))
906 one_ssid.ssid_len = min(ssid_len, IEEE80211_MAX_SSID_LEN);
907 memcpy(&one_ssid.ssid, ssid, one_ssid.ssid_len);
909 return iwm_scan_ssids(iwm, &one_ssid, 1);
912 int iwm_target_reset(struct iwm_priv *iwm)
914 struct iwm_udma_nonwifi_cmd target_cmd;
916 target_cmd.opcode = UMAC_HDI_OUT_OPCODE_REBOOT;
918 target_cmd.op1_sz = 0;
920 target_cmd.handle_by_hw = 0;
924 return iwm_hal_send_target_cmd(iwm, &target_cmd, NULL);