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_udma_wifi_cmd udma_cmd
= UDMA_UMAC_INIT
;
74 struct iwm_umac_cmd umac_cmd
;
76 umac_cmd
.id
= UMAC_CMD_OPCODE_WIFI_IF_WRAPPER
;
79 return iwm_hal_send_umac_cmd(iwm
, &udma_cmd
, &umac_cmd
,
80 payload
, payload_size
);
83 static struct coex_event iwm_sta_xor_prio_tbl
[COEX_EVENTS_NUM
] =
85 {4, 3, 0, COEX_UNASSOC_IDLE_FLAGS
},
86 {4, 3, 0, COEX_UNASSOC_MANUAL_SCAN_FLAGS
},
87 {4, 3, 0, COEX_UNASSOC_AUTO_SCAN_FLAGS
},
88 {4, 3, 0, COEX_CALIBRATION_FLAGS
},
89 {4, 3, 0, COEX_PERIODIC_CALIBRATION_FLAGS
},
90 {4, 3, 0, COEX_CONNECTION_ESTAB_FLAGS
},
91 {4, 3, 0, COEX_ASSOCIATED_IDLE_FLAGS
},
92 {4, 3, 0, COEX_ASSOC_MANUAL_SCAN_FLAGS
},
93 {4, 3, 0, COEX_ASSOC_AUTO_SCAN_FLAGS
},
94 {4, 3, 0, COEX_ASSOC_ACTIVE_LEVEL_FLAGS
},
95 {6, 3, 0, COEX_XOR_RF_ON_FLAGS
},
96 {4, 3, 0, COEX_RF_OFF_FLAGS
},
97 {6, 6, 0, COEX_STAND_ALONE_DEBUG_FLAGS
},
98 {4, 3, 0, COEX_IPAN_ASSOC_LEVEL_FLAGS
},
99 {4, 3, 0, COEX_RSRVD1_FLAGS
},
100 {4, 3, 0, COEX_RSRVD2_FLAGS
}
103 static struct coex_event iwm_sta_cm_prio_tbl
[COEX_EVENTS_NUM
] =
105 {1, 1, 0, COEX_UNASSOC_IDLE_FLAGS
},
106 {4, 3, 0, COEX_UNASSOC_MANUAL_SCAN_FLAGS
},
107 {3, 3, 0, COEX_UNASSOC_AUTO_SCAN_FLAGS
},
108 {5, 5, 0, COEX_CALIBRATION_FLAGS
},
109 {4, 4, 0, COEX_PERIODIC_CALIBRATION_FLAGS
},
110 {5, 4, 0, COEX_CONNECTION_ESTAB_FLAGS
},
111 {4, 4, 0, COEX_ASSOCIATED_IDLE_FLAGS
},
112 {4, 4, 0, COEX_ASSOC_MANUAL_SCAN_FLAGS
},
113 {4, 4, 0, COEX_ASSOC_AUTO_SCAN_FLAGS
},
114 {4, 4, 0, COEX_ASSOC_ACTIVE_LEVEL_FLAGS
},
115 {1, 1, 0, COEX_RF_ON_FLAGS
},
116 {1, 1, 0, COEX_RF_OFF_FLAGS
},
117 {6, 6, 0, COEX_STAND_ALONE_DEBUG_FLAGS
},
118 {5, 4, 0, COEX_IPAN_ASSOC_LEVEL_FLAGS
},
119 {1, 1, 0, COEX_RSRVD1_FLAGS
},
120 {1, 1, 0, COEX_RSRVD2_FLAGS
}
123 int iwm_send_prio_table(struct iwm_priv
*iwm
)
125 struct iwm_coex_prio_table_cmd coex_table_cmd
;
126 u32 coex_enabled
, mode_enabled
;
128 memset(&coex_table_cmd
, 0, sizeof(struct iwm_coex_prio_table_cmd
));
130 coex_table_cmd
.flags
= COEX_FLAGS_STA_TABLE_VALID_MSK
;
132 switch (iwm
->conf
.coexist_mode
) {
142 switch (iwm
->conf
.mode
) {
152 if (coex_enabled
&& mode_enabled
) {
153 coex_table_cmd
.flags
|= COEX_FLAGS_COEX_ENABLE_MSK
|
154 COEX_FLAGS_ASSOC_WAKEUP_UMASK_MSK
|
155 COEX_FLAGS_UNASSOC_WAKEUP_UMASK_MSK
;
157 switch (iwm
->conf
.coexist_mode
) {
159 memcpy(coex_table_cmd
.sta_prio
, iwm_sta_xor_prio_tbl
,
160 sizeof(iwm_sta_xor_prio_tbl
));
163 memcpy(coex_table_cmd
.sta_prio
, iwm_sta_cm_prio_tbl
,
164 sizeof(iwm_sta_cm_prio_tbl
));
167 IWM_ERR(iwm
, "Invalid coex_mode 0x%x\n",
168 iwm
->conf
.coexist_mode
);
172 IWM_WARN(iwm
, "coexistense disabled\n");
174 return iwm_send_lmac_ptrough_cmd(iwm
, COEX_PRIORITY_TABLE_CMD
,
176 sizeof(struct iwm_coex_prio_table_cmd
), 1);
179 int iwm_send_init_calib_cfg(struct iwm_priv
*iwm
, u8 calib_requested
)
181 struct iwm_lmac_cal_cfg_cmd cal_cfg_cmd
;
183 memset(&cal_cfg_cmd
, 0, sizeof(struct iwm_lmac_cal_cfg_cmd
));
185 cal_cfg_cmd
.ucode_cfg
.init
.enable
= cpu_to_le32(calib_requested
);
186 cal_cfg_cmd
.ucode_cfg
.init
.start
= cpu_to_le32(calib_requested
);
187 cal_cfg_cmd
.ucode_cfg
.init
.send_res
= cpu_to_le32(calib_requested
);
188 cal_cfg_cmd
.ucode_cfg
.flags
=
189 cpu_to_le32(CALIB_CFG_FLAG_SEND_COMPLETE_NTFY_AFTER_MSK
);
191 return iwm_send_lmac_ptrough_cmd(iwm
, CALIBRATION_CFG_CMD
, &cal_cfg_cmd
,
192 sizeof(struct iwm_lmac_cal_cfg_cmd
), 1);
195 int iwm_send_periodic_calib_cfg(struct iwm_priv
*iwm
, u8 calib_requested
)
197 struct iwm_lmac_cal_cfg_cmd cal_cfg_cmd
;
199 memset(&cal_cfg_cmd
, 0, sizeof(struct iwm_lmac_cal_cfg_cmd
));
201 cal_cfg_cmd
.ucode_cfg
.periodic
.enable
= cpu_to_le32(calib_requested
);
202 cal_cfg_cmd
.ucode_cfg
.periodic
.start
= cpu_to_le32(calib_requested
);
204 return iwm_send_lmac_ptrough_cmd(iwm
, CALIBRATION_CFG_CMD
, &cal_cfg_cmd
,
205 sizeof(struct iwm_lmac_cal_cfg_cmd
), 0);
208 int iwm_store_rxiq_calib_result(struct iwm_priv
*iwm
)
210 struct iwm_calib_rxiq
*rxiq
;
211 u8
*eeprom_rxiq
= iwm_eeprom_access(iwm
, IWM_EEPROM_CALIB_RXIQ
);
212 int grplen
= sizeof(struct iwm_calib_rxiq_group
);
214 rxiq
= kzalloc(sizeof(struct iwm_calib_rxiq
), GFP_KERNEL
);
216 IWM_ERR(iwm
, "Couldn't alloc memory for RX IQ\n");
220 eeprom_rxiq
= iwm_eeprom_access(iwm
, IWM_EEPROM_CALIB_RXIQ
);
221 if (IS_ERR(eeprom_rxiq
)) {
222 IWM_ERR(iwm
, "Couldn't access EEPROM RX IQ entry\n");
224 return PTR_ERR(eeprom_rxiq
);
227 iwm
->calib_res
[SHILOH_PHY_CALIBRATE_RX_IQ_CMD
].buf
= (u8
*)rxiq
;
228 iwm
->calib_res
[SHILOH_PHY_CALIBRATE_RX_IQ_CMD
].size
= sizeof(*rxiq
);
230 rxiq
->hdr
.opcode
= SHILOH_PHY_CALIBRATE_RX_IQ_CMD
;
231 rxiq
->hdr
.first_grp
= 0;
232 rxiq
->hdr
.grp_num
= 1;
233 rxiq
->hdr
.all_data_valid
= 1;
235 memcpy(&rxiq
->group
[0], eeprom_rxiq
, 4 * grplen
);
236 memcpy(&rxiq
->group
[4], eeprom_rxiq
+ 6 * grplen
, grplen
);
241 int iwm_send_calib_results(struct iwm_priv
*iwm
)
245 for (i
= PHY_CALIBRATE_OPCODES_NUM
; i
< CALIBRATION_CMD_NUM
; i
++) {
246 if (test_bit(i
- PHY_CALIBRATE_OPCODES_NUM
,
247 &iwm
->calib_done_map
)) {
248 IWM_DBG_CMD(iwm
, DBG
,
249 "Send calibration %d result\n", i
);
250 ret
|= iwm_send_lmac_ptrough_cmd(iwm
,
251 REPLY_PHY_CALIBRATION_CMD
,
252 iwm
->calib_res
[i
].buf
,
253 iwm
->calib_res
[i
].size
, 0);
255 kfree(iwm
->calib_res
[i
].buf
);
256 iwm
->calib_res
[i
].buf
= NULL
;
257 iwm
->calib_res
[i
].size
= 0;
264 int iwm_send_umac_reset(struct iwm_priv
*iwm
, __le32 reset_flags
, bool resp
)
266 struct iwm_udma_wifi_cmd udma_cmd
= UDMA_UMAC_INIT
;
267 struct iwm_umac_cmd umac_cmd
;
268 struct iwm_umac_cmd_reset reset
;
270 reset
.flags
= reset_flags
;
272 umac_cmd
.id
= UMAC_CMD_OPCODE_RESET
;
273 umac_cmd
.resp
= resp
;
275 return iwm_hal_send_umac_cmd(iwm
, &udma_cmd
, &umac_cmd
, &reset
,
276 sizeof(struct iwm_umac_cmd_reset
));
279 int iwm_umac_set_config_fix(struct iwm_priv
*iwm
, u16 tbl
, u16 key
, u32 value
)
281 struct iwm_udma_wifi_cmd udma_cmd
= UDMA_UMAC_INIT
;
282 struct iwm_umac_cmd umac_cmd
;
283 struct iwm_umac_cmd_set_param_fix param
;
285 if ((tbl
!= UMAC_PARAM_TBL_CFG_FIX
) &&
286 (tbl
!= UMAC_PARAM_TBL_FA_CFG_FIX
))
289 umac_cmd
.id
= UMAC_CMD_OPCODE_SET_PARAM_FIX
;
292 param
.tbl
= cpu_to_le16(tbl
);
293 param
.key
= cpu_to_le16(key
);
294 param
.value
= cpu_to_le32(value
);
296 return iwm_hal_send_umac_cmd(iwm
, &udma_cmd
, &umac_cmd
, ¶m
,
297 sizeof(struct iwm_umac_cmd_set_param_fix
));
300 int iwm_umac_set_config_var(struct iwm_priv
*iwm
, u16 key
,
301 void *payload
, u16 payload_size
)
303 struct iwm_udma_wifi_cmd udma_cmd
= UDMA_UMAC_INIT
;
304 struct iwm_umac_cmd umac_cmd
;
305 struct iwm_umac_cmd_set_param_var
*param_hdr
;
309 param
= kzalloc(payload_size
+
310 sizeof(struct iwm_umac_cmd_set_param_var
), GFP_KERNEL
);
312 IWM_ERR(iwm
, "Couldn't allocate param\n");
316 param_hdr
= (struct iwm_umac_cmd_set_param_var
*)param
;
318 umac_cmd
.id
= UMAC_CMD_OPCODE_SET_PARAM_VAR
;
321 param_hdr
->tbl
= cpu_to_le16(UMAC_PARAM_TBL_CFG_VAR
);
322 param_hdr
->key
= cpu_to_le16(key
);
323 param_hdr
->len
= cpu_to_le16(payload_size
);
324 memcpy(param
+ sizeof(struct iwm_umac_cmd_set_param_var
),
325 payload
, payload_size
);
327 ret
= iwm_hal_send_umac_cmd(iwm
, &udma_cmd
, &umac_cmd
, param
,
328 sizeof(struct iwm_umac_cmd_set_param_var
) +
335 int iwm_send_umac_config(struct iwm_priv
*iwm
,
340 /* Use UMAC default values */
341 ret
= iwm_umac_set_config_fix(iwm
, UMAC_PARAM_TBL_CFG_FIX
,
342 CFG_POWER_INDEX
, iwm
->conf
.power_index
);
346 ret
= iwm_umac_set_config_fix(iwm
, UMAC_PARAM_TBL_FA_CFG_FIX
,
348 iwm
->conf
.frag_threshold
);
352 ret
= iwm_umac_set_config_fix(iwm
, UMAC_PARAM_TBL_CFG_FIX
,
354 iwm
->conf
.rts_threshold
);
358 ret
= iwm_umac_set_config_fix(iwm
, UMAC_PARAM_TBL_CFG_FIX
,
359 CFG_CTS_TO_SELF
, iwm
->conf
.cts_to_self
);
363 ret
= iwm_umac_set_config_fix(iwm
, UMAC_PARAM_TBL_CFG_FIX
,
364 CFG_COEX_MODE
, iwm
->conf
.coexist_mode
);
369 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
370 CFG_ASSOCIATION_TIMEOUT,
371 iwm->conf.assoc_timeout);
375 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
377 iwm->conf.roam_timeout);
381 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
383 WIRELESS_MODE_11A | WIRELESS_MODE_11G);
388 ret
= iwm_umac_set_config_var(iwm
, CFG_NET_ADDR
,
389 iwm_to_ndev(iwm
)->dev_addr
, ETH_ALEN
);
393 /* UMAC PM static configurations */
394 ret
= iwm_umac_set_config_fix(iwm
, UMAC_PARAM_TBL_CFG_FIX
,
395 CFG_PM_LEGACY_RX_TIMEOUT
, 0x12C);
399 ret
= iwm_umac_set_config_fix(iwm
, UMAC_PARAM_TBL_CFG_FIX
,
400 CFG_PM_LEGACY_TX_TIMEOUT
, 0x15E);
404 ret
= iwm_umac_set_config_fix(iwm
, UMAC_PARAM_TBL_CFG_FIX
,
405 CFG_PM_CTRL_FLAGS
, 0x30001);
409 ret
= iwm_umac_set_config_fix(iwm
, UMAC_PARAM_TBL_CFG_FIX
,
410 CFG_PM_KEEP_ALIVE_IN_BEACONS
, 0x80);
415 ret
= iwm_send_umac_reset(iwm
, reset_flags
, 1);
419 ret
= iwm_notif_handle(iwm
, UMAC_CMD_OPCODE_RESET
, IWM_SRC_UMAC
,
422 IWM_ERR(iwm
, "Wait for UMAC RESET timeout\n");
429 int iwm_send_packet(struct iwm_priv
*iwm
, struct sk_buff
*skb
, int pool_id
)
431 struct iwm_udma_wifi_cmd udma_cmd
;
432 struct iwm_umac_cmd umac_cmd
;
433 struct iwm_tx_info
*tx_info
= skb_to_tx_info(skb
);
435 udma_cmd
.eop
= 1; /* always set eop for non-concatenated Tx */
436 udma_cmd
.credit_group
= pool_id
;
437 udma_cmd
.ra_tid
= tx_info
->sta
<< 4 | tx_info
->tid
;
438 udma_cmd
.lmac_offset
= 0;
440 umac_cmd
.id
= REPLY_TX
;
441 umac_cmd
.color
= tx_info
->color
;
444 return iwm_hal_send_umac_cmd(iwm
, &udma_cmd
, &umac_cmd
,
445 skb
->data
, skb
->len
);
448 static int iwm_target_read(struct iwm_priv
*iwm
, __le32 address
,
449 u8
*response
, u32 resp_size
)
451 struct iwm_udma_nonwifi_cmd target_cmd
;
452 struct iwm_nonwifi_cmd
*cmd
;
456 target_cmd
.opcode
= UMAC_HDI_OUT_OPCODE_READ
;
457 target_cmd
.addr
= address
;
458 target_cmd
.op1_sz
= cpu_to_le32(resp_size
);
460 target_cmd
.handle_by_hw
= 0;
464 ret
= iwm_hal_send_target_cmd(iwm
, &target_cmd
, NULL
);
466 IWM_ERR(iwm
, "Couldn't send READ command\n");
468 /* When succeding, the send_target routine returns the seq number */
471 ret
= wait_event_interruptible_timeout(iwm
->nonwifi_queue
,
472 (cmd
= iwm_get_pending_nonwifi_cmd(iwm
, seq_num
,
473 UMAC_HDI_OUT_OPCODE_READ
)) != NULL
,
477 IWM_ERR(iwm
, "Didn't receive a target READ answer\n");
481 memcpy(response
, cmd
->buf
.hdr
+ sizeof(struct iwm_udma_in_hdr
),
489 int iwm_read_mac(struct iwm_priv
*iwm
, u8
*mac
)
492 u8 mac_align
[ALIGN(ETH_ALEN
, 8)];
494 ret
= iwm_target_read(iwm
, cpu_to_le32(WICO_MAC_ADDRESS_ADDR
),
495 mac_align
, sizeof(mac_align
));
499 if (is_valid_ether_addr(mac_align
))
500 memcpy(mac
, mac_align
, ETH_ALEN
);
502 IWM_ERR(iwm
, "Invalid EEPROM MAC\n");
503 memcpy(mac
, iwm
->conf
.mac_addr
, ETH_ALEN
);
504 get_random_bytes(&mac
[3], 3);
510 int iwm_set_tx_key(struct iwm_priv
*iwm
, u8 key_idx
)
512 struct iwm_umac_tx_key_id tx_key_id
;
514 if (!iwm
->default_key
|| !iwm
->default_key
->in_use
)
517 tx_key_id
.hdr
.oid
= UMAC_WIFI_IF_CMD_GLOBAL_TX_KEY_ID
;
518 tx_key_id
.hdr
.buf_size
= cpu_to_le16(sizeof(struct iwm_umac_tx_key_id
) -
519 sizeof(struct iwm_umac_wifi_if
));
521 tx_key_id
.key_idx
= key_idx
;
523 return iwm_send_wifi_if_cmd(iwm
, &tx_key_id
, sizeof(tx_key_id
), 1);
526 static int iwm_check_profile(struct iwm_priv
*iwm
)
528 if (!iwm
->umac_profile_active
)
531 if (iwm
->umac_profile
->sec
.ucast_cipher
!= UMAC_CIPHER_TYPE_WEP_40
&&
532 iwm
->umac_profile
->sec
.ucast_cipher
!= UMAC_CIPHER_TYPE_WEP_104
&&
533 iwm
->umac_profile
->sec
.ucast_cipher
!= UMAC_CIPHER_TYPE_TKIP
&&
534 iwm
->umac_profile
->sec
.ucast_cipher
!= UMAC_CIPHER_TYPE_CCMP
) {
535 IWM_ERR(iwm
, "Wrong unicast cipher: 0x%x\n",
536 iwm
->umac_profile
->sec
.ucast_cipher
);
540 if (iwm
->umac_profile
->sec
.mcast_cipher
!= UMAC_CIPHER_TYPE_WEP_40
&&
541 iwm
->umac_profile
->sec
.mcast_cipher
!= UMAC_CIPHER_TYPE_WEP_104
&&
542 iwm
->umac_profile
->sec
.mcast_cipher
!= UMAC_CIPHER_TYPE_TKIP
&&
543 iwm
->umac_profile
->sec
.mcast_cipher
!= UMAC_CIPHER_TYPE_CCMP
) {
544 IWM_ERR(iwm
, "Wrong multicast cipher: 0x%x\n",
545 iwm
->umac_profile
->sec
.mcast_cipher
);
549 if ((iwm
->umac_profile
->sec
.ucast_cipher
== UMAC_CIPHER_TYPE_WEP_40
||
550 iwm
->umac_profile
->sec
.ucast_cipher
== UMAC_CIPHER_TYPE_WEP_104
) &&
551 (iwm
->umac_profile
->sec
.ucast_cipher
!=
552 iwm
->umac_profile
->sec
.mcast_cipher
)) {
553 IWM_ERR(iwm
, "Unicast and multicast ciphers differ for WEP\n");
559 int iwm_set_key(struct iwm_priv
*iwm
, bool remove
, bool set_tx_key
,
563 u8 cmd
[64], *sta_addr
, *key_data
, key_len
;
566 struct iwm_umac_key_hdr
*key_hdr
= &key
->hdr
;
567 struct iwm_umac_key_wep40
*wep40
= (struct iwm_umac_key_wep40
*)cmd
;
568 struct iwm_umac_key_wep104
*wep104
= (struct iwm_umac_key_wep104
*)cmd
;
569 struct iwm_umac_key_tkip
*tkip
= (struct iwm_umac_key_tkip
*)cmd
;
570 struct iwm_umac_key_ccmp
*ccmp
= (struct iwm_umac_key_ccmp
*)cmd
;
573 iwm
->default_key
= key
;
576 * We check if our current profile is valid.
577 * If not, we dont push the key, we just cache them,
578 * so that with the next siwsessid call, the keys
579 * will be actually pushed.
582 ret
= iwm_check_profile(iwm
);
587 sta_addr
= key
->hdr
.mac
;
589 key_len
= key
->key_len
;
590 key_idx
= key
->hdr
.key_idx
;
593 IWM_DBG_WEXT(iwm
, DBG
, "key_idx:%d set tx key:%d\n",
594 key_idx
, set_tx_key
);
595 IWM_DBG_WEXT(iwm
, DBG
, "key_len:%d\n", key_len
);
596 IWM_DBG_WEXT(iwm
, DBG
, "MAC:%pM, idx:%d, multicast:%d\n",
597 key_hdr
->mac
, key_hdr
->key_idx
, key_hdr
->multicast
);
599 IWM_DBG_WEXT(iwm
, DBG
, "profile: mcast:0x%x, ucast:0x%x\n",
600 iwm
->umac_profile
->sec
.mcast_cipher
,
601 iwm
->umac_profile
->sec
.ucast_cipher
);
602 IWM_DBG_WEXT(iwm
, DBG
, "profile: auth_type:0x%x, flags:0x%x\n",
603 iwm
->umac_profile
->sec
.auth_type
,
604 iwm
->umac_profile
->sec
.flags
);
607 case UMAC_CIPHER_TYPE_WEP_40
:
608 wep40
->hdr
.oid
= UMAC_WIFI_IF_CMD_ADD_WEP40_KEY
;
609 wep40
->hdr
.buf_size
=
610 cpu_to_le16(sizeof(struct iwm_umac_key_wep40
) -
611 sizeof(struct iwm_umac_wifi_if
));
613 memcpy(&wep40
->key_hdr
, key_hdr
,
614 sizeof(struct iwm_umac_key_hdr
));
615 memcpy(wep40
->key
, key_data
, key_len
);
616 wep40
->static_key
= 1;
618 cmd_size
= sizeof(struct iwm_umac_key_wep40
);
621 case UMAC_CIPHER_TYPE_WEP_104
:
622 wep104
->hdr
.oid
= UMAC_WIFI_IF_CMD_ADD_WEP104_KEY
;
623 wep104
->hdr
.buf_size
=
624 cpu_to_le16(sizeof(struct iwm_umac_key_wep104
) -
625 sizeof(struct iwm_umac_wifi_if
));
627 memcpy(&wep104
->key_hdr
, key_hdr
,
628 sizeof(struct iwm_umac_key_hdr
));
629 memcpy(wep104
->key
, key_data
, key_len
);
630 wep104
->static_key
= 1;
632 cmd_size
= sizeof(struct iwm_umac_key_wep104
);
635 case UMAC_CIPHER_TYPE_CCMP
:
637 ccmp
->hdr
.oid
= UMAC_WIFI_IF_CMD_ADD_CCMP_KEY
;
639 cpu_to_le16(sizeof(struct iwm_umac_key_ccmp
) -
640 sizeof(struct iwm_umac_wifi_if
));
642 memcpy(&ccmp
->key_hdr
, key_hdr
,
643 sizeof(struct iwm_umac_key_hdr
));
645 memcpy(ccmp
->key
, key_data
, key_len
);
647 if (key
->flags
& IW_ENCODE_EXT_RX_SEQ_VALID
)
648 memcpy(ccmp
->iv_count
, key
->rx_seq
, 6);
650 cmd_size
= sizeof(struct iwm_umac_key_ccmp
);
653 case UMAC_CIPHER_TYPE_TKIP
:
655 tkip
->hdr
.oid
= UMAC_WIFI_IF_CMD_ADD_TKIP_KEY
;
657 cpu_to_le16(sizeof(struct iwm_umac_key_tkip
) -
658 sizeof(struct iwm_umac_wifi_if
));
660 memcpy(&tkip
->key_hdr
, key_hdr
,
661 sizeof(struct iwm_umac_key_hdr
));
663 memcpy(tkip
->tkip_key
, key_data
, IWM_TKIP_KEY_SIZE
);
664 memcpy(tkip
->mic_tx_key
, key_data
+ IWM_TKIP_KEY_SIZE
,
666 memcpy(tkip
->mic_rx_key
,
667 key_data
+ IWM_TKIP_KEY_SIZE
+ IWM_TKIP_MIC_SIZE
,
670 if (key
->flags
& IW_ENCODE_EXT_RX_SEQ_VALID
)
671 memcpy(ccmp
->iv_count
, key
->rx_seq
, 6);
673 cmd_size
= sizeof(struct iwm_umac_key_tkip
);
680 if ((key
->alg
== UMAC_CIPHER_TYPE_CCMP
) ||
681 (key
->alg
== UMAC_CIPHER_TYPE_TKIP
))
684 * Copied HACK from the MWG driver.
685 * Without it, the key is set before the second
686 * EAPOL frame is sent, and the latter is thus
689 schedule_timeout_interruptible(usecs_to_jiffies(300));
691 ret
= iwm_send_wifi_if_cmd(iwm
, cmd
, cmd_size
, 1);
696 * We need a default key only if it is set and
697 * if we're doing WEP.
699 if (iwm
->default_key
== key
&&
700 ((key
->alg
== UMAC_CIPHER_TYPE_WEP_40
) ||
701 (key
->alg
== UMAC_CIPHER_TYPE_WEP_104
))) {
702 ret
= iwm_set_tx_key(iwm
, key_idx
);
707 struct iwm_umac_key_remove key_remove
;
709 key_remove
.hdr
.oid
= UMAC_WIFI_IF_CMD_REMOVE_KEY
;
710 key_remove
.hdr
.buf_size
=
711 cpu_to_le16(sizeof(struct iwm_umac_key_remove
) -
712 sizeof(struct iwm_umac_wifi_if
));
713 memcpy(&key_remove
.key_hdr
, key_hdr
,
714 sizeof(struct iwm_umac_key_hdr
));
716 ret
= iwm_send_wifi_if_cmd(iwm
, &key_remove
,
717 sizeof(struct iwm_umac_key_remove
),
722 iwm
->keys
[key_idx
].in_use
= 0;
733 int iwm_send_mlme_profile(struct iwm_priv
*iwm
)
736 struct iwm_umac_profile profile
;
738 memcpy(&profile
, iwm
->umac_profile
, sizeof(profile
));
740 profile
.hdr
.oid
= UMAC_WIFI_IF_CMD_SET_PROFILE
;
741 profile
.hdr
.buf_size
= cpu_to_le16(sizeof(struct iwm_umac_profile
) -
742 sizeof(struct iwm_umac_wifi_if
));
744 ret
= iwm_send_wifi_if_cmd(iwm
, &profile
, sizeof(profile
), 1);
746 IWM_ERR(iwm
, "Send profile command failed\n");
750 /* Wait for the profile to be active */
751 ret
= wait_event_interruptible_timeout(iwm
->mlme_queue
,
752 iwm
->umac_profile_active
== 1,
758 for (i
= 0; i
< IWM_NUM_KEYS
; i
++)
759 if (iwm
->keys
[i
].in_use
) {
761 struct iwm_key
*key
= &iwm
->keys
[i
];
763 if (key
== iwm
->default_key
)
766 /* Wait for the profile before sending the keys */
767 wait_event_interruptible_timeout(iwm
->mlme_queue
,
768 (test_bit(IWM_STATUS_ASSOCIATING
, &iwm
->status
) ||
769 test_bit(IWM_STATUS_ASSOCIATED
, &iwm
->status
)),
772 ret
= iwm_set_key(iwm
, 0, default_key
, key
);
780 int iwm_invalidate_mlme_profile(struct iwm_priv
*iwm
)
783 struct iwm_umac_invalidate_profile invalid
;
785 invalid
.hdr
.oid
= UMAC_WIFI_IF_CMD_INVALIDATE_PROFILE
;
786 invalid
.hdr
.buf_size
=
787 cpu_to_le16(sizeof(struct iwm_umac_invalidate_profile
) -
788 sizeof(struct iwm_umac_wifi_if
));
790 invalid
.reason
= WLAN_REASON_UNSPECIFIED
;
792 ret
= iwm_send_wifi_if_cmd(iwm
, &invalid
, sizeof(invalid
), 1);
796 ret
= wait_event_interruptible_timeout(iwm
->mlme_queue
,
797 (iwm
->umac_profile_active
== 0),
805 int iwm_send_umac_stats_req(struct iwm_priv
*iwm
, u32 flags
)
807 struct iwm_udma_wifi_cmd udma_cmd
= UDMA_UMAC_INIT
;
808 struct iwm_umac_cmd umac_cmd
;
809 struct iwm_umac_cmd_stats_req stats_req
;
811 stats_req
.flags
= cpu_to_le32(flags
);
813 umac_cmd
.id
= UMAC_CMD_OPCODE_STATISTIC_REQUEST
;
816 return iwm_hal_send_umac_cmd(iwm
, &udma_cmd
, &umac_cmd
, &stats_req
,
817 sizeof(struct iwm_umac_cmd_stats_req
));
820 int iwm_send_umac_channel_list(struct iwm_priv
*iwm
)
822 struct iwm_udma_wifi_cmd udma_cmd
= UDMA_UMAC_INIT
;
823 struct iwm_umac_cmd umac_cmd
;
824 struct iwm_umac_cmd_get_channel_list
*ch_list
;
825 int size
= sizeof(struct iwm_umac_cmd_get_channel_list
) +
826 sizeof(struct iwm_umac_channel_info
) * 4;
829 ch_list
= kzalloc(size
, GFP_KERNEL
);
831 IWM_ERR(iwm
, "Couldn't allocate channel list cmd\n");
835 ch_list
->ch
[0].band
= UMAC_BAND_2GHZ
;
836 ch_list
->ch
[0].type
= UMAC_CHANNEL_WIDTH_20MHZ
;
837 ch_list
->ch
[0].flags
= UMAC_CHANNEL_FLAG_VALID
;
839 ch_list
->ch
[1].band
= UMAC_BAND_5GHZ
;
840 ch_list
->ch
[1].type
= UMAC_CHANNEL_WIDTH_20MHZ
;
841 ch_list
->ch
[1].flags
= UMAC_CHANNEL_FLAG_VALID
;
843 ch_list
->ch
[2].band
= UMAC_BAND_2GHZ
;
844 ch_list
->ch
[2].type
= UMAC_CHANNEL_WIDTH_20MHZ
;
845 ch_list
->ch
[2].flags
= UMAC_CHANNEL_FLAG_VALID
| UMAC_CHANNEL_FLAG_IBSS
;
847 ch_list
->ch
[3].band
= UMAC_BAND_5GHZ
;
848 ch_list
->ch
[3].type
= UMAC_CHANNEL_WIDTH_20MHZ
;
849 ch_list
->ch
[3].flags
= UMAC_CHANNEL_FLAG_VALID
| UMAC_CHANNEL_FLAG_IBSS
;
851 ch_list
->count
= cpu_to_le16(4);
853 umac_cmd
.id
= UMAC_CMD_OPCODE_GET_CHAN_INFO_LIST
;
856 ret
= iwm_hal_send_umac_cmd(iwm
, &udma_cmd
, &umac_cmd
, ch_list
, size
);
863 int iwm_scan_ssids(struct iwm_priv
*iwm
, struct cfg80211_ssid
*ssids
,
866 struct iwm_umac_cmd_scan_request req
;
869 memset(&req
, 0, sizeof(struct iwm_umac_cmd_scan_request
));
871 req
.hdr
.oid
= UMAC_WIFI_IF_CMD_SCAN_REQUEST
;
872 req
.hdr
.buf_size
= cpu_to_le16(sizeof(struct iwm_umac_cmd_scan_request
)
873 - sizeof(struct iwm_umac_wifi_if
));
874 req
.type
= UMAC_WIFI_IF_SCAN_TYPE_USER
;
876 req
.seq_num
= iwm
->scan_id
;
877 req
.ssid_num
= min(ssid_num
, UMAC_WIFI_IF_PROBE_OPTION_MAX
);
879 for (i
= 0; i
< req
.ssid_num
; i
++) {
880 memcpy(req
.ssids
[i
].ssid
, ssids
[i
].ssid
, ssids
[i
].ssid_len
);
881 req
.ssids
[i
].ssid_len
= ssids
[i
].ssid_len
;
884 ret
= iwm_send_wifi_if_cmd(iwm
, &req
, sizeof(req
), 0);
886 IWM_ERR(iwm
, "Couldn't send scan request\n");
890 iwm
->scan_id
= iwm
->scan_id
++ % IWM_SCAN_ID_MAX
;
895 int iwm_scan_one_ssid(struct iwm_priv
*iwm
, u8
*ssid
, int ssid_len
)
897 struct cfg80211_ssid one_ssid
;
899 if (test_and_set_bit(IWM_STATUS_SCANNING
, &iwm
->status
))
902 one_ssid
.ssid_len
= min(ssid_len
, IEEE80211_MAX_SSID_LEN
);
903 memcpy(&one_ssid
.ssid
, ssid
, one_ssid
.ssid_len
);
905 return iwm_scan_ssids(iwm
, &one_ssid
, 1);
908 int iwm_target_reset(struct iwm_priv
*iwm
)
910 struct iwm_udma_nonwifi_cmd target_cmd
;
912 target_cmd
.opcode
= UMAC_HDI_OUT_OPCODE_REBOOT
;
914 target_cmd
.op1_sz
= 0;
916 target_cmd
.handle_by_hw
= 0;
920 return iwm_hal_send_target_cmd(iwm
, &target_cmd
, NULL
);