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>
43 #include <linux/sched.h>
44 #include <linux/slab.h>
45 #include <linux/moduleparam.h>
54 static int iwm_send_lmac_ptrough_cmd(struct iwm_priv
*iwm
,
56 const void *lmac_payload
,
57 u16 lmac_payload_size
,
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
;
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
,
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
;
82 if (!test_bit(IWM_STATUS_READY
, &iwm
->status
)) {
83 IWM_ERR(iwm
, "Interface is not ready yet");
87 umac_cmd
.id
= UMAC_CMD_OPCODE_WIFI_IF_WRAPPER
;
90 ret
= iwm_hal_send_umac_cmd(iwm
, &udma_cmd
, &umac_cmd
,
91 payload
, payload_size
);
94 ret
= wait_event_interruptible_timeout(iwm
->wifi_ntfy_queue
,
95 test_and_clear_bit(oid
, &iwm
->wifi_ntfy
[0]),
98 return ret
? 0 : -EBUSY
;
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
) {
167 switch (iwm
->conf
.mode
) {
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
) {
184 memcpy(coex_table_cmd
.sta_prio
, iwm_sta_xor_prio_tbl
,
185 sizeof(iwm_sta_xor_prio_tbl
));
188 memcpy(coex_table_cmd
.sta_prio
, iwm_sta_cm_prio_tbl
,
189 sizeof(iwm_sta_cm_prio_tbl
));
192 IWM_ERR(iwm
, "Invalid coex_mode 0x%x\n",
197 IWM_WARN(iwm
, "coexistense disabled\n");
199 return iwm_send_lmac_ptrough_cmd(iwm
, COEX_PRIORITY_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
);
241 IWM_ERR(iwm
, "Couldn't alloc memory for RX IQ\n");
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");
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
);
266 int iwm_send_calib_results(struct iwm_priv
*iwm
)
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;
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
))
325 umac_cmd
.id
= UMAC_CMD_OPCODE_SET_PARAM_FIX
;
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
, ¶m
,
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
;
345 param
= kzalloc(payload_size
+
346 sizeof(struct iwm_umac_cmd_set_param_var
), GFP_KERNEL
);
348 IWM_ERR(iwm
, "Couldn't allocate param\n");
352 param_hdr
= (struct iwm_umac_cmd_set_param_var
*)param
;
354 umac_cmd
.id
= UMAC_CMD_OPCODE_SET_PARAM_VAR
;
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
) +
371 int iwm_send_umac_config(struct iwm_priv
*iwm
, __le32 reset_flags
)
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
);
381 ret
= iwm_umac_set_config_fix(iwm
, UMAC_PARAM_TBL_FA_CFG_FIX
,
383 iwm
->conf
.frag_threshold
);
387 ret
= iwm_umac_set_config_fix(iwm
, UMAC_PARAM_TBL_CFG_FIX
,
389 iwm
->conf
.rts_threshold
);
393 ret
= iwm_umac_set_config_fix(iwm
, UMAC_PARAM_TBL_CFG_FIX
,
394 CFG_CTS_TO_SELF
, iwm
->conf
.cts_to_self
);
398 ret
= iwm_umac_set_config_fix(iwm
, UMAC_PARAM_TBL_CFG_FIX
,
400 iwm
->conf
.wireless_mode
);
404 ret
= iwm_umac_set_config_fix(iwm
, UMAC_PARAM_TBL_CFG_FIX
,
405 CFG_COEX_MODE
, modparam_wiwi
);
410 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
411 CFG_ASSOCIATION_TIMEOUT,
412 iwm->conf.assoc_timeout);
416 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
418 iwm->conf.roam_timeout);
422 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
424 WIRELESS_MODE_11A | WIRELESS_MODE_11G);
429 ret
= iwm_umac_set_config_var(iwm
, CFG_NET_ADDR
,
430 iwm_to_ndev(iwm
)->dev_addr
, ETH_ALEN
);
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);
440 ret
= iwm_umac_set_config_fix(iwm
, UMAC_PARAM_TBL_CFG_FIX
,
441 CFG_PM_LEGACY_TX_TIMEOUT
, 0x15E);
445 ret
= iwm_umac_set_config_fix(iwm
, UMAC_PARAM_TBL_CFG_FIX
,
446 CFG_PM_CTRL_FLAGS
, 0x1);
450 ret
= iwm_umac_set_config_fix(iwm
, UMAC_PARAM_TBL_CFG_FIX
,
451 CFG_PM_KEEP_ALIVE_IN_BEACONS
, 0x80);
456 ret
= iwm_send_umac_reset(iwm
, reset_flags
, 1);
460 ret
= iwm_notif_handle(iwm
, UMAC_CMD_OPCODE_RESET
, IWM_SRC_UMAC
,
463 IWM_ERR(iwm
, "Wait for UMAC RESET timeout\n");
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
;
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
;
497 target_cmd
.opcode
= UMAC_HDI_OUT_OPCODE_READ
;
498 target_cmd
.addr
= address
;
499 target_cmd
.op1_sz
= cpu_to_le32(resp_size
);
501 target_cmd
.handle_by_hw
= 0;
505 ret
= iwm_hal_send_target_cmd(iwm
, &target_cmd
, NULL
);
507 IWM_ERR(iwm
, "Couldn't send READ command\n");
511 /* When succeeding, the send_target routine returns the seq number */
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
,
520 IWM_ERR(iwm
, "Didn't receive a target READ answer\n");
524 memcpy(response
, cmd
->buf
.hdr
+ sizeof(struct iwm_udma_in_hdr
),
532 int iwm_read_mac(struct iwm_priv
*iwm
, u8
*mac
)
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
));
542 if (is_valid_ether_addr(mac_align
))
543 memcpy(mac
, mac_align
, ETH_ALEN
);
545 IWM_ERR(iwm
, "Invalid EEPROM MAC\n");
546 memcpy(mac
, iwm
->conf
.mac_addr
, ETH_ALEN
);
547 get_random_bytes(&mac
[3], 3);
553 static int iwm_check_profile(struct iwm_priv
*iwm
)
555 if (!iwm
->umac_profile_active
)
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
);
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
);
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");
586 int iwm_set_tx_key(struct iwm_priv
*iwm
, u8 key_idx
)
588 struct iwm_umac_tx_key_id tx_key_id
;
591 ret
= iwm_check_profile(iwm
);
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
)
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
)
615 u8 cmd
[64], *sta_addr
, *key_data
, key_len
;
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
;
625 ret
= iwm_check_profile(iwm
);
630 sta_addr
= key
->hdr
.mac
;
632 key_len
= key
->key_len
;
633 key_idx
= key
->hdr
.key_idx
;
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
);
661 !!((auth_type
!= UMAC_AUTH_TYPE_8021X
) &&
662 (auth_type
!= UMAC_AUTH_TYPE_RSNA_PSK
));
664 cmd_size
= sizeof(struct iwm_umac_key_wep40
);
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
);
677 !!((auth_type
!= UMAC_AUTH_TYPE_8021X
) &&
678 (auth_type
!= UMAC_AUTH_TYPE_RSNA_PSK
));
680 cmd_size
= sizeof(struct iwm_umac_key_wep104
);
683 case WLAN_CIPHER_SUITE_CCMP
:
685 ccmp
->hdr
.oid
= UMAC_WIFI_IF_CMD_ADD_CCMP_KEY
;
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
);
696 memcpy(ccmp
->iv_count
, key
->seq
, key
->seq_len
);
698 cmd_size
= sizeof(struct iwm_umac_key_ccmp
);
701 case WLAN_CIPHER_SUITE_TKIP
:
703 tkip
->hdr
.oid
= UMAC_WIFI_IF_CMD_ADD_TKIP_KEY
;
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
,
714 memcpy(tkip
->mic_rx_key
,
715 key_data
+ IWM_TKIP_KEY_SIZE
+ IWM_TKIP_MIC_SIZE
,
719 memcpy(ccmp
->iv_count
, key
->seq
, key
->seq_len
);
721 cmd_size
= sizeof(struct iwm_umac_key_tkip
);
728 if ((key
->cipher
== WLAN_CIPHER_SUITE_TKIP
) ||
729 (key
->cipher
== WLAN_CIPHER_SUITE_CCMP
))
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
737 schedule_timeout_interruptible(usecs_to_jiffies(300));
739 ret
= iwm_send_wifi_if_cmd(iwm
, cmd
, cmd_size
, 1);
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
),
758 iwm
->keys
[key_idx
].key_len
= 0;
765 int iwm_send_mlme_profile(struct iwm_priv
*iwm
)
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);
778 IWM_ERR(iwm
, "Send profile command failed\n");
782 set_bit(IWM_STATUS_SME_CONNECTING
, &iwm
->status
);
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
)
804 ret
= __iwm_invalidate_mlme_profile(iwm
);
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
;
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;
851 ch_list
= kzalloc(size
, GFP_KERNEL
);
853 IWM_ERR(iwm
, "Couldn't allocate channel list cmd\n");
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
;
878 ret
= iwm_hal_send_umac_cmd(iwm
, &udma_cmd
, &umac_cmd
, ch_list
, size
);
885 int iwm_scan_ssids(struct iwm_priv
*iwm
, struct cfg80211_ssid
*ssids
,
888 struct iwm_umac_cmd_scan_request req
;
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
;
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);
908 IWM_ERR(iwm
, "Couldn't send scan request\n");
912 iwm
->scan_id
= (iwm
->scan_id
+ 1) % IWM_SCAN_ID_MAX
;
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
))
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
;
936 target_cmd
.op1_sz
= 0;
938 target_cmd
.handle_by_hw
= 0;
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
);
955 sta_info
= &iwm
->sta_table
[sta_id
];
956 if (!sta_info
->valid
) {
957 IWM_ERR(iwm
, "Invalid STA: %d\n", sta_id
);
961 umac_cmd
.id
= UMAC_CMD_OPCODE_STOP_RESUME_STA_TX
;
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
;
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
);
990 memcpy(&update
.bssid
, pmksa
->bssid
, ETH_ALEN
);
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);
997 IWM_ERR(iwm
, "PMKID update command failed\n");