Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Intel Wireless Multicomm 3200 WiFi driver |
| 3 | * |
| 4 | * Copyright (C) 2009 Intel Corporation. All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions |
| 8 | * are met: |
| 9 | * |
| 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. |
| 19 | * |
| 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. |
| 31 | * |
| 32 | * |
| 33 | * Intel Corporation <ilw@linux.intel.com> |
| 34 | * Samuel Ortiz <samuel.ortiz@intel.com> |
| 35 | * Zhu Yi <yi.zhu@intel.com> |
| 36 | * |
| 37 | */ |
| 38 | |
| 39 | #include <linux/kernel.h> |
| 40 | #include <linux/wireless.h> |
| 41 | #include <linux/etherdevice.h> |
| 42 | #include <linux/ieee80211.h> |
| 43 | |
| 44 | #include "iwm.h" |
| 45 | #include "bus.h" |
| 46 | #include "hal.h" |
| 47 | #include "umac.h" |
| 48 | #include "commands.h" |
| 49 | #include "debug.h" |
| 50 | |
| 51 | static int iwm_send_lmac_ptrough_cmd(struct iwm_priv *iwm, |
| 52 | u8 lmac_cmd_id, |
| 53 | const void *lmac_payload, |
| 54 | u16 lmac_payload_size, |
| 55 | u8 resp) |
| 56 | { |
| 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; |
| 60 | |
| 61 | lmac_cmd.id = lmac_cmd_id; |
| 62 | |
| 63 | umac_cmd.id = UMAC_CMD_OPCODE_WIFI_PASS_THROUGH; |
| 64 | umac_cmd.resp = resp; |
| 65 | |
| 66 | return iwm_hal_send_host_cmd(iwm, &udma_cmd, &umac_cmd, &lmac_cmd, |
| 67 | lmac_payload, lmac_payload_size); |
| 68 | } |
| 69 | |
| 70 | int iwm_send_wifi_if_cmd(struct iwm_priv *iwm, void *payload, u16 payload_size, |
| 71 | bool resp) |
| 72 | { |
Samuel Ortiz | a70742f | 2009-06-15 21:59:51 +0200 | [diff] [blame] | 73 | struct iwm_umac_wifi_if *hdr = (struct iwm_umac_wifi_if *)payload; |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 74 | struct iwm_udma_wifi_cmd udma_cmd = UDMA_UMAC_INIT; |
| 75 | struct iwm_umac_cmd umac_cmd; |
Samuel Ortiz | a70742f | 2009-06-15 21:59:51 +0200 | [diff] [blame] | 76 | int ret; |
| 77 | u8 oid = hdr->oid; |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 78 | |
Samuel Ortiz | 56e3f08 | 2009-10-16 13:18:56 +0800 | [diff] [blame^] | 79 | if (!test_bit(IWM_STATUS_READY, &iwm->status)) { |
| 80 | IWM_ERR(iwm, "Interface is not ready yet"); |
| 81 | return -EAGAIN; |
| 82 | } |
| 83 | |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 84 | umac_cmd.id = UMAC_CMD_OPCODE_WIFI_IF_WRAPPER; |
| 85 | umac_cmd.resp = resp; |
| 86 | |
Samuel Ortiz | a70742f | 2009-06-15 21:59:51 +0200 | [diff] [blame] | 87 | ret = iwm_hal_send_umac_cmd(iwm, &udma_cmd, &umac_cmd, |
| 88 | payload, payload_size); |
| 89 | |
| 90 | if (resp) { |
| 91 | ret = wait_event_interruptible_timeout(iwm->wifi_ntfy_queue, |
| 92 | test_and_clear_bit(oid, &iwm->wifi_ntfy[0]), |
| 93 | 3 * HZ); |
| 94 | |
Zhu Yi | b6c3217 | 2009-07-16 17:34:12 +0800 | [diff] [blame] | 95 | return ret ? 0 : -EBUSY; |
Samuel Ortiz | a70742f | 2009-06-15 21:59:51 +0200 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | return ret; |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | static struct coex_event iwm_sta_xor_prio_tbl[COEX_EVENTS_NUM] = |
| 102 | { |
| 103 | {4, 3, 0, COEX_UNASSOC_IDLE_FLAGS}, |
| 104 | {4, 3, 0, COEX_UNASSOC_MANUAL_SCAN_FLAGS}, |
| 105 | {4, 3, 0, COEX_UNASSOC_AUTO_SCAN_FLAGS}, |
| 106 | {4, 3, 0, COEX_CALIBRATION_FLAGS}, |
| 107 | {4, 3, 0, COEX_PERIODIC_CALIBRATION_FLAGS}, |
| 108 | {4, 3, 0, COEX_CONNECTION_ESTAB_FLAGS}, |
| 109 | {4, 3, 0, COEX_ASSOCIATED_IDLE_FLAGS}, |
| 110 | {4, 3, 0, COEX_ASSOC_MANUAL_SCAN_FLAGS}, |
| 111 | {4, 3, 0, COEX_ASSOC_AUTO_SCAN_FLAGS}, |
| 112 | {4, 3, 0, COEX_ASSOC_ACTIVE_LEVEL_FLAGS}, |
| 113 | {6, 3, 0, COEX_XOR_RF_ON_FLAGS}, |
| 114 | {4, 3, 0, COEX_RF_OFF_FLAGS}, |
| 115 | {6, 6, 0, COEX_STAND_ALONE_DEBUG_FLAGS}, |
| 116 | {4, 3, 0, COEX_IPAN_ASSOC_LEVEL_FLAGS}, |
| 117 | {4, 3, 0, COEX_RSRVD1_FLAGS}, |
| 118 | {4, 3, 0, COEX_RSRVD2_FLAGS} |
| 119 | }; |
| 120 | |
| 121 | static struct coex_event iwm_sta_cm_prio_tbl[COEX_EVENTS_NUM] = |
| 122 | { |
| 123 | {1, 1, 0, COEX_UNASSOC_IDLE_FLAGS}, |
| 124 | {4, 3, 0, COEX_UNASSOC_MANUAL_SCAN_FLAGS}, |
| 125 | {3, 3, 0, COEX_UNASSOC_AUTO_SCAN_FLAGS}, |
| 126 | {5, 5, 0, COEX_CALIBRATION_FLAGS}, |
Zhu Yi | 191506e | 2009-06-15 21:59:53 +0200 | [diff] [blame] | 127 | {3, 3, 0, COEX_PERIODIC_CALIBRATION_FLAGS}, |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 128 | {5, 4, 0, COEX_CONNECTION_ESTAB_FLAGS}, |
| 129 | {4, 4, 0, COEX_ASSOCIATED_IDLE_FLAGS}, |
| 130 | {4, 4, 0, COEX_ASSOC_MANUAL_SCAN_FLAGS}, |
| 131 | {4, 4, 0, COEX_ASSOC_AUTO_SCAN_FLAGS}, |
| 132 | {4, 4, 0, COEX_ASSOC_ACTIVE_LEVEL_FLAGS}, |
| 133 | {1, 1, 0, COEX_RF_ON_FLAGS}, |
| 134 | {1, 1, 0, COEX_RF_OFF_FLAGS}, |
| 135 | {6, 6, 0, COEX_STAND_ALONE_DEBUG_FLAGS}, |
| 136 | {5, 4, 0, COEX_IPAN_ASSOC_LEVEL_FLAGS}, |
| 137 | {1, 1, 0, COEX_RSRVD1_FLAGS}, |
| 138 | {1, 1, 0, COEX_RSRVD2_FLAGS} |
| 139 | }; |
| 140 | |
| 141 | int iwm_send_prio_table(struct iwm_priv *iwm) |
| 142 | { |
| 143 | struct iwm_coex_prio_table_cmd coex_table_cmd; |
| 144 | u32 coex_enabled, mode_enabled; |
| 145 | |
| 146 | memset(&coex_table_cmd, 0, sizeof(struct iwm_coex_prio_table_cmd)); |
| 147 | |
| 148 | coex_table_cmd.flags = COEX_FLAGS_STA_TABLE_VALID_MSK; |
| 149 | |
| 150 | switch (iwm->conf.coexist_mode) { |
| 151 | case COEX_MODE_XOR: |
| 152 | case COEX_MODE_CM: |
| 153 | coex_enabled = 1; |
| 154 | break; |
| 155 | default: |
| 156 | coex_enabled = 0; |
| 157 | break; |
| 158 | } |
| 159 | |
| 160 | switch (iwm->conf.mode) { |
| 161 | case UMAC_MODE_BSS: |
| 162 | case UMAC_MODE_IBSS: |
| 163 | mode_enabled = 1; |
| 164 | break; |
| 165 | default: |
| 166 | mode_enabled = 0; |
| 167 | break; |
| 168 | } |
| 169 | |
| 170 | if (coex_enabled && mode_enabled) { |
| 171 | coex_table_cmd.flags |= COEX_FLAGS_COEX_ENABLE_MSK | |
| 172 | COEX_FLAGS_ASSOC_WAKEUP_UMASK_MSK | |
| 173 | COEX_FLAGS_UNASSOC_WAKEUP_UMASK_MSK; |
| 174 | |
| 175 | switch (iwm->conf.coexist_mode) { |
| 176 | case COEX_MODE_XOR: |
| 177 | memcpy(coex_table_cmd.sta_prio, iwm_sta_xor_prio_tbl, |
| 178 | sizeof(iwm_sta_xor_prio_tbl)); |
| 179 | break; |
| 180 | case COEX_MODE_CM: |
| 181 | memcpy(coex_table_cmd.sta_prio, iwm_sta_cm_prio_tbl, |
| 182 | sizeof(iwm_sta_cm_prio_tbl)); |
| 183 | break; |
| 184 | default: |
| 185 | IWM_ERR(iwm, "Invalid coex_mode 0x%x\n", |
| 186 | iwm->conf.coexist_mode); |
| 187 | break; |
| 188 | } |
| 189 | } else |
| 190 | IWM_WARN(iwm, "coexistense disabled\n"); |
| 191 | |
| 192 | return iwm_send_lmac_ptrough_cmd(iwm, COEX_PRIORITY_TABLE_CMD, |
| 193 | &coex_table_cmd, |
| 194 | sizeof(struct iwm_coex_prio_table_cmd), 1); |
| 195 | } |
| 196 | |
| 197 | int iwm_send_init_calib_cfg(struct iwm_priv *iwm, u8 calib_requested) |
| 198 | { |
| 199 | struct iwm_lmac_cal_cfg_cmd cal_cfg_cmd; |
| 200 | |
| 201 | memset(&cal_cfg_cmd, 0, sizeof(struct iwm_lmac_cal_cfg_cmd)); |
| 202 | |
| 203 | cal_cfg_cmd.ucode_cfg.init.enable = cpu_to_le32(calib_requested); |
| 204 | cal_cfg_cmd.ucode_cfg.init.start = cpu_to_le32(calib_requested); |
| 205 | cal_cfg_cmd.ucode_cfg.init.send_res = cpu_to_le32(calib_requested); |
| 206 | cal_cfg_cmd.ucode_cfg.flags = |
| 207 | cpu_to_le32(CALIB_CFG_FLAG_SEND_COMPLETE_NTFY_AFTER_MSK); |
| 208 | |
| 209 | return iwm_send_lmac_ptrough_cmd(iwm, CALIBRATION_CFG_CMD, &cal_cfg_cmd, |
| 210 | sizeof(struct iwm_lmac_cal_cfg_cmd), 1); |
| 211 | } |
| 212 | |
| 213 | int iwm_send_periodic_calib_cfg(struct iwm_priv *iwm, u8 calib_requested) |
| 214 | { |
| 215 | struct iwm_lmac_cal_cfg_cmd cal_cfg_cmd; |
| 216 | |
| 217 | memset(&cal_cfg_cmd, 0, sizeof(struct iwm_lmac_cal_cfg_cmd)); |
| 218 | |
| 219 | cal_cfg_cmd.ucode_cfg.periodic.enable = cpu_to_le32(calib_requested); |
| 220 | cal_cfg_cmd.ucode_cfg.periodic.start = cpu_to_le32(calib_requested); |
| 221 | |
| 222 | return iwm_send_lmac_ptrough_cmd(iwm, CALIBRATION_CFG_CMD, &cal_cfg_cmd, |
| 223 | sizeof(struct iwm_lmac_cal_cfg_cmd), 0); |
| 224 | } |
| 225 | |
| 226 | int iwm_store_rxiq_calib_result(struct iwm_priv *iwm) |
| 227 | { |
| 228 | struct iwm_calib_rxiq *rxiq; |
| 229 | u8 *eeprom_rxiq = iwm_eeprom_access(iwm, IWM_EEPROM_CALIB_RXIQ); |
| 230 | int grplen = sizeof(struct iwm_calib_rxiq_group); |
| 231 | |
| 232 | rxiq = kzalloc(sizeof(struct iwm_calib_rxiq), GFP_KERNEL); |
| 233 | if (!rxiq) { |
| 234 | IWM_ERR(iwm, "Couldn't alloc memory for RX IQ\n"); |
| 235 | return -ENOMEM; |
| 236 | } |
| 237 | |
| 238 | eeprom_rxiq = iwm_eeprom_access(iwm, IWM_EEPROM_CALIB_RXIQ); |
| 239 | if (IS_ERR(eeprom_rxiq)) { |
| 240 | IWM_ERR(iwm, "Couldn't access EEPROM RX IQ entry\n"); |
Julia Lawall | 9f9857b | 2009-08-01 10:55:53 +0200 | [diff] [blame] | 241 | kfree(rxiq); |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 242 | return PTR_ERR(eeprom_rxiq); |
| 243 | } |
| 244 | |
| 245 | iwm->calib_res[SHILOH_PHY_CALIBRATE_RX_IQ_CMD].buf = (u8 *)rxiq; |
| 246 | iwm->calib_res[SHILOH_PHY_CALIBRATE_RX_IQ_CMD].size = sizeof(*rxiq); |
| 247 | |
| 248 | rxiq->hdr.opcode = SHILOH_PHY_CALIBRATE_RX_IQ_CMD; |
| 249 | rxiq->hdr.first_grp = 0; |
| 250 | rxiq->hdr.grp_num = 1; |
| 251 | rxiq->hdr.all_data_valid = 1; |
| 252 | |
| 253 | memcpy(&rxiq->group[0], eeprom_rxiq, 4 * grplen); |
| 254 | memcpy(&rxiq->group[4], eeprom_rxiq + 6 * grplen, grplen); |
| 255 | |
| 256 | return 0; |
| 257 | } |
| 258 | |
| 259 | int iwm_send_calib_results(struct iwm_priv *iwm) |
| 260 | { |
| 261 | int i, ret = 0; |
| 262 | |
| 263 | for (i = PHY_CALIBRATE_OPCODES_NUM; i < CALIBRATION_CMD_NUM; i++) { |
| 264 | if (test_bit(i - PHY_CALIBRATE_OPCODES_NUM, |
| 265 | &iwm->calib_done_map)) { |
| 266 | IWM_DBG_CMD(iwm, DBG, |
| 267 | "Send calibration %d result\n", i); |
| 268 | ret |= iwm_send_lmac_ptrough_cmd(iwm, |
| 269 | REPLY_PHY_CALIBRATION_CMD, |
| 270 | iwm->calib_res[i].buf, |
| 271 | iwm->calib_res[i].size, 0); |
| 272 | |
| 273 | kfree(iwm->calib_res[i].buf); |
| 274 | iwm->calib_res[i].buf = NULL; |
| 275 | iwm->calib_res[i].size = 0; |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | return ret; |
| 280 | } |
| 281 | |
Samuel Ortiz | e85498b21 | 2009-10-16 13:18:48 +0800 | [diff] [blame] | 282 | int iwm_send_ct_kill_cfg(struct iwm_priv *iwm, u8 entry, u8 exit) |
| 283 | { |
| 284 | struct iwm_ct_kill_cfg_cmd cmd; |
| 285 | |
| 286 | cmd.entry_threshold = entry; |
| 287 | cmd.exit_threshold = exit; |
| 288 | |
| 289 | return iwm_send_lmac_ptrough_cmd(iwm, REPLY_CT_KILL_CONFIG_CMD, &cmd, |
| 290 | sizeof(struct iwm_ct_kill_cfg_cmd), 0); |
| 291 | } |
| 292 | |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 293 | int iwm_send_umac_reset(struct iwm_priv *iwm, __le32 reset_flags, bool resp) |
| 294 | { |
| 295 | struct iwm_udma_wifi_cmd udma_cmd = UDMA_UMAC_INIT; |
| 296 | struct iwm_umac_cmd umac_cmd; |
| 297 | struct iwm_umac_cmd_reset reset; |
| 298 | |
| 299 | reset.flags = reset_flags; |
| 300 | |
| 301 | umac_cmd.id = UMAC_CMD_OPCODE_RESET; |
| 302 | umac_cmd.resp = resp; |
| 303 | |
| 304 | return iwm_hal_send_umac_cmd(iwm, &udma_cmd, &umac_cmd, &reset, |
| 305 | sizeof(struct iwm_umac_cmd_reset)); |
| 306 | } |
| 307 | |
| 308 | int iwm_umac_set_config_fix(struct iwm_priv *iwm, u16 tbl, u16 key, u32 value) |
| 309 | { |
| 310 | struct iwm_udma_wifi_cmd udma_cmd = UDMA_UMAC_INIT; |
| 311 | struct iwm_umac_cmd umac_cmd; |
| 312 | struct iwm_umac_cmd_set_param_fix param; |
| 313 | |
| 314 | if ((tbl != UMAC_PARAM_TBL_CFG_FIX) && |
| 315 | (tbl != UMAC_PARAM_TBL_FA_CFG_FIX)) |
| 316 | return -EINVAL; |
| 317 | |
| 318 | umac_cmd.id = UMAC_CMD_OPCODE_SET_PARAM_FIX; |
| 319 | umac_cmd.resp = 0; |
| 320 | |
| 321 | param.tbl = cpu_to_le16(tbl); |
| 322 | param.key = cpu_to_le16(key); |
| 323 | param.value = cpu_to_le32(value); |
| 324 | |
| 325 | return iwm_hal_send_umac_cmd(iwm, &udma_cmd, &umac_cmd, ¶m, |
| 326 | sizeof(struct iwm_umac_cmd_set_param_fix)); |
| 327 | } |
| 328 | |
| 329 | int iwm_umac_set_config_var(struct iwm_priv *iwm, u16 key, |
| 330 | void *payload, u16 payload_size) |
| 331 | { |
| 332 | struct iwm_udma_wifi_cmd udma_cmd = UDMA_UMAC_INIT; |
| 333 | struct iwm_umac_cmd umac_cmd; |
| 334 | struct iwm_umac_cmd_set_param_var *param_hdr; |
| 335 | u8 *param; |
| 336 | int ret; |
| 337 | |
| 338 | param = kzalloc(payload_size + |
| 339 | sizeof(struct iwm_umac_cmd_set_param_var), GFP_KERNEL); |
| 340 | if (!param) { |
| 341 | IWM_ERR(iwm, "Couldn't allocate param\n"); |
| 342 | return -ENOMEM; |
| 343 | } |
| 344 | |
| 345 | param_hdr = (struct iwm_umac_cmd_set_param_var *)param; |
| 346 | |
| 347 | umac_cmd.id = UMAC_CMD_OPCODE_SET_PARAM_VAR; |
| 348 | umac_cmd.resp = 0; |
| 349 | |
| 350 | param_hdr->tbl = cpu_to_le16(UMAC_PARAM_TBL_CFG_VAR); |
| 351 | param_hdr->key = cpu_to_le16(key); |
| 352 | param_hdr->len = cpu_to_le16(payload_size); |
| 353 | memcpy(param + sizeof(struct iwm_umac_cmd_set_param_var), |
| 354 | payload, payload_size); |
| 355 | |
| 356 | ret = iwm_hal_send_umac_cmd(iwm, &udma_cmd, &umac_cmd, param, |
| 357 | sizeof(struct iwm_umac_cmd_set_param_var) + |
| 358 | payload_size); |
| 359 | kfree(param); |
| 360 | |
| 361 | return ret; |
| 362 | } |
| 363 | |
Zhu Yi | 191506e | 2009-06-15 21:59:53 +0200 | [diff] [blame] | 364 | int iwm_send_umac_config(struct iwm_priv *iwm, __le32 reset_flags) |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 365 | { |
| 366 | int ret; |
| 367 | |
| 368 | /* Use UMAC default values */ |
| 369 | ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX, |
| 370 | CFG_POWER_INDEX, iwm->conf.power_index); |
| 371 | if (ret < 0) |
| 372 | return ret; |
| 373 | |
| 374 | ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_FA_CFG_FIX, |
| 375 | CFG_FRAG_THRESHOLD, |
| 376 | iwm->conf.frag_threshold); |
| 377 | if (ret < 0) |
| 378 | return ret; |
| 379 | |
| 380 | ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX, |
| 381 | CFG_RTS_THRESHOLD, |
| 382 | iwm->conf.rts_threshold); |
| 383 | if (ret < 0) |
| 384 | return ret; |
| 385 | |
| 386 | ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX, |
| 387 | CFG_CTS_TO_SELF, iwm->conf.cts_to_self); |
| 388 | if (ret < 0) |
| 389 | return ret; |
| 390 | |
| 391 | ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX, |
Zhu Yi | 191506e | 2009-06-15 21:59:53 +0200 | [diff] [blame] | 392 | CFG_WIRELESS_MODE, |
| 393 | iwm->conf.wireless_mode); |
| 394 | if (ret < 0) |
| 395 | return ret; |
| 396 | |
| 397 | ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX, |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 398 | CFG_COEX_MODE, iwm->conf.coexist_mode); |
| 399 | if (ret < 0) |
| 400 | return ret; |
| 401 | |
| 402 | /* |
| 403 | ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX, |
| 404 | CFG_ASSOCIATION_TIMEOUT, |
| 405 | iwm->conf.assoc_timeout); |
| 406 | if (ret < 0) |
| 407 | return ret; |
| 408 | |
| 409 | ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX, |
| 410 | CFG_ROAM_TIMEOUT, |
| 411 | iwm->conf.roam_timeout); |
| 412 | if (ret < 0) |
| 413 | return ret; |
| 414 | |
| 415 | ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX, |
| 416 | CFG_WIRELESS_MODE, |
| 417 | WIRELESS_MODE_11A | WIRELESS_MODE_11G); |
| 418 | if (ret < 0) |
| 419 | return ret; |
| 420 | */ |
| 421 | |
| 422 | ret = iwm_umac_set_config_var(iwm, CFG_NET_ADDR, |
| 423 | iwm_to_ndev(iwm)->dev_addr, ETH_ALEN); |
| 424 | if (ret < 0) |
| 425 | return ret; |
| 426 | |
| 427 | /* UMAC PM static configurations */ |
| 428 | ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX, |
| 429 | CFG_PM_LEGACY_RX_TIMEOUT, 0x12C); |
| 430 | if (ret < 0) |
| 431 | return ret; |
| 432 | |
| 433 | ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX, |
| 434 | CFG_PM_LEGACY_TX_TIMEOUT, 0x15E); |
| 435 | if (ret < 0) |
| 436 | return ret; |
| 437 | |
| 438 | ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX, |
Zhu Yi | 191506e | 2009-06-15 21:59:53 +0200 | [diff] [blame] | 439 | CFG_PM_CTRL_FLAGS, 0x1); |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 440 | if (ret < 0) |
| 441 | return ret; |
| 442 | |
| 443 | ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX, |
| 444 | CFG_PM_KEEP_ALIVE_IN_BEACONS, 0x80); |
| 445 | if (ret < 0) |
| 446 | return ret; |
| 447 | |
| 448 | /* reset UMAC */ |
| 449 | ret = iwm_send_umac_reset(iwm, reset_flags, 1); |
| 450 | if (ret < 0) |
| 451 | return ret; |
| 452 | |
| 453 | ret = iwm_notif_handle(iwm, UMAC_CMD_OPCODE_RESET, IWM_SRC_UMAC, |
| 454 | WAIT_NOTIF_TIMEOUT); |
| 455 | if (ret) { |
| 456 | IWM_ERR(iwm, "Wait for UMAC RESET timeout\n"); |
| 457 | return ret; |
| 458 | } |
| 459 | |
| 460 | return ret; |
| 461 | } |
| 462 | |
| 463 | int iwm_send_packet(struct iwm_priv *iwm, struct sk_buff *skb, int pool_id) |
| 464 | { |
| 465 | struct iwm_udma_wifi_cmd udma_cmd; |
| 466 | struct iwm_umac_cmd umac_cmd; |
| 467 | struct iwm_tx_info *tx_info = skb_to_tx_info(skb); |
| 468 | |
| 469 | udma_cmd.eop = 1; /* always set eop for non-concatenated Tx */ |
| 470 | udma_cmd.credit_group = pool_id; |
| 471 | udma_cmd.ra_tid = tx_info->sta << 4 | tx_info->tid; |
| 472 | udma_cmd.lmac_offset = 0; |
| 473 | |
| 474 | umac_cmd.id = REPLY_TX; |
| 475 | umac_cmd.color = tx_info->color; |
| 476 | umac_cmd.resp = 0; |
| 477 | |
| 478 | return iwm_hal_send_umac_cmd(iwm, &udma_cmd, &umac_cmd, |
| 479 | skb->data, skb->len); |
| 480 | } |
| 481 | |
| 482 | static int iwm_target_read(struct iwm_priv *iwm, __le32 address, |
| 483 | u8 *response, u32 resp_size) |
| 484 | { |
| 485 | struct iwm_udma_nonwifi_cmd target_cmd; |
| 486 | struct iwm_nonwifi_cmd *cmd; |
| 487 | u16 seq_num; |
| 488 | int ret = 0; |
| 489 | |
| 490 | target_cmd.opcode = UMAC_HDI_OUT_OPCODE_READ; |
| 491 | target_cmd.addr = address; |
| 492 | target_cmd.op1_sz = cpu_to_le32(resp_size); |
| 493 | target_cmd.op2 = 0; |
| 494 | target_cmd.handle_by_hw = 0; |
| 495 | target_cmd.resp = 1; |
| 496 | target_cmd.eop = 1; |
| 497 | |
| 498 | ret = iwm_hal_send_target_cmd(iwm, &target_cmd, NULL); |
Zhu Yi | b6c3217 | 2009-07-16 17:34:12 +0800 | [diff] [blame] | 499 | if (ret < 0) { |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 500 | IWM_ERR(iwm, "Couldn't send READ command\n"); |
Zhu Yi | b6c3217 | 2009-07-16 17:34:12 +0800 | [diff] [blame] | 501 | return ret; |
| 502 | } |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 503 | |
| 504 | /* When succeding, the send_target routine returns the seq number */ |
| 505 | seq_num = ret; |
| 506 | |
| 507 | ret = wait_event_interruptible_timeout(iwm->nonwifi_queue, |
| 508 | (cmd = iwm_get_pending_nonwifi_cmd(iwm, seq_num, |
| 509 | UMAC_HDI_OUT_OPCODE_READ)) != NULL, |
| 510 | 2 * HZ); |
| 511 | |
| 512 | if (!ret) { |
| 513 | IWM_ERR(iwm, "Didn't receive a target READ answer\n"); |
| 514 | return ret; |
| 515 | } |
| 516 | |
| 517 | memcpy(response, cmd->buf.hdr + sizeof(struct iwm_udma_in_hdr), |
| 518 | resp_size); |
| 519 | |
| 520 | kfree(cmd); |
| 521 | |
Zhu Yi | b6c3217 | 2009-07-16 17:34:12 +0800 | [diff] [blame] | 522 | return 0; |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | int iwm_read_mac(struct iwm_priv *iwm, u8 *mac) |
| 526 | { |
| 527 | int ret; |
| 528 | u8 mac_align[ALIGN(ETH_ALEN, 8)]; |
| 529 | |
| 530 | ret = iwm_target_read(iwm, cpu_to_le32(WICO_MAC_ADDRESS_ADDR), |
| 531 | mac_align, sizeof(mac_align)); |
Zhu Yi | b6c3217 | 2009-07-16 17:34:12 +0800 | [diff] [blame] | 532 | if (ret) |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 533 | return ret; |
| 534 | |
| 535 | if (is_valid_ether_addr(mac_align)) |
| 536 | memcpy(mac, mac_align, ETH_ALEN); |
| 537 | else { |
| 538 | IWM_ERR(iwm, "Invalid EEPROM MAC\n"); |
| 539 | memcpy(mac, iwm->conf.mac_addr, ETH_ALEN); |
| 540 | get_random_bytes(&mac[3], 3); |
| 541 | } |
| 542 | |
| 543 | return 0; |
| 544 | } |
| 545 | |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 546 | static int iwm_check_profile(struct iwm_priv *iwm) |
| 547 | { |
| 548 | if (!iwm->umac_profile_active) |
| 549 | return -EAGAIN; |
| 550 | |
| 551 | if (iwm->umac_profile->sec.ucast_cipher != UMAC_CIPHER_TYPE_WEP_40 && |
| 552 | iwm->umac_profile->sec.ucast_cipher != UMAC_CIPHER_TYPE_WEP_104 && |
| 553 | iwm->umac_profile->sec.ucast_cipher != UMAC_CIPHER_TYPE_TKIP && |
| 554 | iwm->umac_profile->sec.ucast_cipher != UMAC_CIPHER_TYPE_CCMP) { |
| 555 | IWM_ERR(iwm, "Wrong unicast cipher: 0x%x\n", |
| 556 | iwm->umac_profile->sec.ucast_cipher); |
| 557 | return -EAGAIN; |
| 558 | } |
| 559 | |
| 560 | if (iwm->umac_profile->sec.mcast_cipher != UMAC_CIPHER_TYPE_WEP_40 && |
| 561 | iwm->umac_profile->sec.mcast_cipher != UMAC_CIPHER_TYPE_WEP_104 && |
| 562 | iwm->umac_profile->sec.mcast_cipher != UMAC_CIPHER_TYPE_TKIP && |
| 563 | iwm->umac_profile->sec.mcast_cipher != UMAC_CIPHER_TYPE_CCMP) { |
| 564 | IWM_ERR(iwm, "Wrong multicast cipher: 0x%x\n", |
| 565 | iwm->umac_profile->sec.mcast_cipher); |
| 566 | return -EAGAIN; |
| 567 | } |
| 568 | |
| 569 | if ((iwm->umac_profile->sec.ucast_cipher == UMAC_CIPHER_TYPE_WEP_40 || |
| 570 | iwm->umac_profile->sec.ucast_cipher == UMAC_CIPHER_TYPE_WEP_104) && |
| 571 | (iwm->umac_profile->sec.ucast_cipher != |
| 572 | iwm->umac_profile->sec.mcast_cipher)) { |
| 573 | IWM_ERR(iwm, "Unicast and multicast ciphers differ for WEP\n"); |
| 574 | } |
| 575 | |
| 576 | return 0; |
| 577 | } |
| 578 | |
Zhu Yi | 847c1e1 | 2009-08-03 14:37:03 +0800 | [diff] [blame] | 579 | int iwm_set_tx_key(struct iwm_priv *iwm, u8 key_idx) |
| 580 | { |
| 581 | struct iwm_umac_tx_key_id tx_key_id; |
| 582 | int ret; |
| 583 | |
| 584 | ret = iwm_check_profile(iwm); |
| 585 | if (ret < 0) |
| 586 | return ret; |
| 587 | |
| 588 | /* UMAC only allows to set default key for WEP and auth type is |
| 589 | * NOT 802.1X or RSNA. */ |
| 590 | if ((iwm->umac_profile->sec.ucast_cipher != UMAC_CIPHER_TYPE_WEP_40 && |
| 591 | iwm->umac_profile->sec.ucast_cipher != UMAC_CIPHER_TYPE_WEP_104) || |
| 592 | iwm->umac_profile->sec.auth_type == UMAC_AUTH_TYPE_8021X || |
| 593 | iwm->umac_profile->sec.auth_type == UMAC_AUTH_TYPE_RSNA_PSK) |
| 594 | return 0; |
| 595 | |
| 596 | tx_key_id.hdr.oid = UMAC_WIFI_IF_CMD_GLOBAL_TX_KEY_ID; |
| 597 | tx_key_id.hdr.buf_size = cpu_to_le16(sizeof(struct iwm_umac_tx_key_id) - |
| 598 | sizeof(struct iwm_umac_wifi_if)); |
| 599 | |
| 600 | tx_key_id.key_idx = key_idx; |
| 601 | |
| 602 | return iwm_send_wifi_if_cmd(iwm, &tx_key_id, sizeof(tx_key_id), 1); |
| 603 | } |
| 604 | |
Samuel Ortiz | 13e0fe70 | 2009-06-15 21:59:52 +0200 | [diff] [blame] | 605 | int iwm_set_key(struct iwm_priv *iwm, bool remove, struct iwm_key *key) |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 606 | { |
Samuel Ortiz | 13e0fe70 | 2009-06-15 21:59:52 +0200 | [diff] [blame] | 607 | int ret = 0; |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 608 | u8 cmd[64], *sta_addr, *key_data, key_len; |
| 609 | s8 key_idx; |
| 610 | u16 cmd_size = 0; |
| 611 | struct iwm_umac_key_hdr *key_hdr = &key->hdr; |
| 612 | struct iwm_umac_key_wep40 *wep40 = (struct iwm_umac_key_wep40 *)cmd; |
| 613 | struct iwm_umac_key_wep104 *wep104 = (struct iwm_umac_key_wep104 *)cmd; |
| 614 | struct iwm_umac_key_tkip *tkip = (struct iwm_umac_key_tkip *)cmd; |
| 615 | struct iwm_umac_key_ccmp *ccmp = (struct iwm_umac_key_ccmp *)cmd; |
| 616 | |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 617 | if (!remove) { |
| 618 | ret = iwm_check_profile(iwm); |
| 619 | if (ret < 0) |
| 620 | return ret; |
| 621 | } |
| 622 | |
| 623 | sta_addr = key->hdr.mac; |
| 624 | key_data = key->key; |
| 625 | key_len = key->key_len; |
| 626 | key_idx = key->hdr.key_idx; |
| 627 | |
| 628 | if (!remove) { |
Zhu Yi | beda278 | 2009-08-03 14:37:02 +0800 | [diff] [blame] | 629 | u8 auth_type = iwm->umac_profile->sec.auth_type; |
| 630 | |
Samuel Ortiz | 13e0fe70 | 2009-06-15 21:59:52 +0200 | [diff] [blame] | 631 | IWM_DBG_WEXT(iwm, DBG, "key_idx:%d\n", key_idx); |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 632 | IWM_DBG_WEXT(iwm, DBG, "key_len:%d\n", key_len); |
| 633 | IWM_DBG_WEXT(iwm, DBG, "MAC:%pM, idx:%d, multicast:%d\n", |
| 634 | key_hdr->mac, key_hdr->key_idx, key_hdr->multicast); |
| 635 | |
| 636 | IWM_DBG_WEXT(iwm, DBG, "profile: mcast:0x%x, ucast:0x%x\n", |
| 637 | iwm->umac_profile->sec.mcast_cipher, |
| 638 | iwm->umac_profile->sec.ucast_cipher); |
| 639 | IWM_DBG_WEXT(iwm, DBG, "profile: auth_type:0x%x, flags:0x%x\n", |
| 640 | iwm->umac_profile->sec.auth_type, |
| 641 | iwm->umac_profile->sec.flags); |
| 642 | |
Samuel Ortiz | 13e0fe70 | 2009-06-15 21:59:52 +0200 | [diff] [blame] | 643 | switch (key->cipher) { |
| 644 | case WLAN_CIPHER_SUITE_WEP40: |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 645 | wep40->hdr.oid = UMAC_WIFI_IF_CMD_ADD_WEP40_KEY; |
| 646 | wep40->hdr.buf_size = |
| 647 | cpu_to_le16(sizeof(struct iwm_umac_key_wep40) - |
| 648 | sizeof(struct iwm_umac_wifi_if)); |
| 649 | |
| 650 | memcpy(&wep40->key_hdr, key_hdr, |
| 651 | sizeof(struct iwm_umac_key_hdr)); |
| 652 | memcpy(wep40->key, key_data, key_len); |
Zhu Yi | beda278 | 2009-08-03 14:37:02 +0800 | [diff] [blame] | 653 | wep40->static_key = |
| 654 | !!((auth_type != UMAC_AUTH_TYPE_8021X) && |
| 655 | (auth_type != UMAC_AUTH_TYPE_RSNA_PSK)); |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 656 | |
| 657 | cmd_size = sizeof(struct iwm_umac_key_wep40); |
| 658 | break; |
| 659 | |
Samuel Ortiz | 13e0fe70 | 2009-06-15 21:59:52 +0200 | [diff] [blame] | 660 | case WLAN_CIPHER_SUITE_WEP104: |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 661 | wep104->hdr.oid = UMAC_WIFI_IF_CMD_ADD_WEP104_KEY; |
| 662 | wep104->hdr.buf_size = |
| 663 | cpu_to_le16(sizeof(struct iwm_umac_key_wep104) - |
| 664 | sizeof(struct iwm_umac_wifi_if)); |
| 665 | |
| 666 | memcpy(&wep104->key_hdr, key_hdr, |
| 667 | sizeof(struct iwm_umac_key_hdr)); |
| 668 | memcpy(wep104->key, key_data, key_len); |
Zhu Yi | beda278 | 2009-08-03 14:37:02 +0800 | [diff] [blame] | 669 | wep104->static_key = |
| 670 | !!((auth_type != UMAC_AUTH_TYPE_8021X) && |
| 671 | (auth_type != UMAC_AUTH_TYPE_RSNA_PSK)); |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 672 | |
| 673 | cmd_size = sizeof(struct iwm_umac_key_wep104); |
| 674 | break; |
| 675 | |
Samuel Ortiz | 13e0fe70 | 2009-06-15 21:59:52 +0200 | [diff] [blame] | 676 | case WLAN_CIPHER_SUITE_CCMP: |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 677 | key_hdr->key_idx++; |
| 678 | ccmp->hdr.oid = UMAC_WIFI_IF_CMD_ADD_CCMP_KEY; |
| 679 | ccmp->hdr.buf_size = |
| 680 | cpu_to_le16(sizeof(struct iwm_umac_key_ccmp) - |
| 681 | sizeof(struct iwm_umac_wifi_if)); |
| 682 | |
| 683 | memcpy(&ccmp->key_hdr, key_hdr, |
| 684 | sizeof(struct iwm_umac_key_hdr)); |
| 685 | |
| 686 | memcpy(ccmp->key, key_data, key_len); |
| 687 | |
Samuel Ortiz | 13e0fe70 | 2009-06-15 21:59:52 +0200 | [diff] [blame] | 688 | if (key->seq_len) |
| 689 | memcpy(ccmp->iv_count, key->seq, key->seq_len); |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 690 | |
| 691 | cmd_size = sizeof(struct iwm_umac_key_ccmp); |
| 692 | break; |
| 693 | |
Samuel Ortiz | 13e0fe70 | 2009-06-15 21:59:52 +0200 | [diff] [blame] | 694 | case WLAN_CIPHER_SUITE_TKIP: |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 695 | key_hdr->key_idx++; |
| 696 | tkip->hdr.oid = UMAC_WIFI_IF_CMD_ADD_TKIP_KEY; |
| 697 | tkip->hdr.buf_size = |
| 698 | cpu_to_le16(sizeof(struct iwm_umac_key_tkip) - |
| 699 | sizeof(struct iwm_umac_wifi_if)); |
| 700 | |
| 701 | memcpy(&tkip->key_hdr, key_hdr, |
| 702 | sizeof(struct iwm_umac_key_hdr)); |
| 703 | |
| 704 | memcpy(tkip->tkip_key, key_data, IWM_TKIP_KEY_SIZE); |
| 705 | memcpy(tkip->mic_tx_key, key_data + IWM_TKIP_KEY_SIZE, |
| 706 | IWM_TKIP_MIC_SIZE); |
| 707 | memcpy(tkip->mic_rx_key, |
| 708 | key_data + IWM_TKIP_KEY_SIZE + IWM_TKIP_MIC_SIZE, |
| 709 | IWM_TKIP_MIC_SIZE); |
| 710 | |
Samuel Ortiz | 13e0fe70 | 2009-06-15 21:59:52 +0200 | [diff] [blame] | 711 | if (key->seq_len) |
| 712 | memcpy(ccmp->iv_count, key->seq, key->seq_len); |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 713 | |
| 714 | cmd_size = sizeof(struct iwm_umac_key_tkip); |
| 715 | break; |
| 716 | |
| 717 | default: |
| 718 | return -ENOTSUPP; |
| 719 | } |
| 720 | |
Samuel Ortiz | 13e0fe70 | 2009-06-15 21:59:52 +0200 | [diff] [blame] | 721 | if ((key->cipher == WLAN_CIPHER_SUITE_TKIP) || |
| 722 | (key->cipher == WLAN_CIPHER_SUITE_CCMP)) |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 723 | /* |
| 724 | * UGLY_UGLY_UGLY |
| 725 | * Copied HACK from the MWG driver. |
| 726 | * Without it, the key is set before the second |
| 727 | * EAPOL frame is sent, and the latter is thus |
| 728 | * encrypted. |
| 729 | */ |
| 730 | schedule_timeout_interruptible(usecs_to_jiffies(300)); |
| 731 | |
| 732 | ret = iwm_send_wifi_if_cmd(iwm, cmd, cmd_size, 1); |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 733 | } else { |
| 734 | struct iwm_umac_key_remove key_remove; |
| 735 | |
Samuel Ortiz | 13e0fe70 | 2009-06-15 21:59:52 +0200 | [diff] [blame] | 736 | IWM_DBG_WEXT(iwm, ERR, "Removing key_idx:%d\n", key_idx); |
| 737 | |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 738 | key_remove.hdr.oid = UMAC_WIFI_IF_CMD_REMOVE_KEY; |
| 739 | key_remove.hdr.buf_size = |
| 740 | cpu_to_le16(sizeof(struct iwm_umac_key_remove) - |
| 741 | sizeof(struct iwm_umac_wifi_if)); |
| 742 | memcpy(&key_remove.key_hdr, key_hdr, |
| 743 | sizeof(struct iwm_umac_key_hdr)); |
| 744 | |
| 745 | ret = iwm_send_wifi_if_cmd(iwm, &key_remove, |
| 746 | sizeof(struct iwm_umac_key_remove), |
| 747 | 1); |
Zhu Yi | b6c3217 | 2009-07-16 17:34:12 +0800 | [diff] [blame] | 748 | if (ret) |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 749 | return ret; |
| 750 | |
Samuel Ortiz | 13e0fe70 | 2009-06-15 21:59:52 +0200 | [diff] [blame] | 751 | iwm->keys[key_idx].key_len = 0; |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 752 | } |
| 753 | |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 754 | return ret; |
| 755 | } |
| 756 | |
| 757 | |
| 758 | int iwm_send_mlme_profile(struct iwm_priv *iwm) |
| 759 | { |
Zhu Yi | 6e5db0a | 2009-07-16 17:34:13 +0800 | [diff] [blame] | 760 | int ret; |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 761 | struct iwm_umac_profile profile; |
| 762 | |
| 763 | memcpy(&profile, iwm->umac_profile, sizeof(profile)); |
| 764 | |
| 765 | profile.hdr.oid = UMAC_WIFI_IF_CMD_SET_PROFILE; |
| 766 | profile.hdr.buf_size = cpu_to_le16(sizeof(struct iwm_umac_profile) - |
| 767 | sizeof(struct iwm_umac_wifi_if)); |
| 768 | |
| 769 | ret = iwm_send_wifi_if_cmd(iwm, &profile, sizeof(profile), 1); |
Zhu Yi | b6c3217 | 2009-07-16 17:34:12 +0800 | [diff] [blame] | 770 | if (ret) { |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 771 | IWM_ERR(iwm, "Send profile command failed\n"); |
| 772 | return ret; |
| 773 | } |
| 774 | |
Zhu Yi | de15fd3 | 2009-09-01 15:14:01 +0200 | [diff] [blame] | 775 | set_bit(IWM_STATUS_SME_CONNECTING, &iwm->status); |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 776 | return 0; |
| 777 | } |
| 778 | |
| 779 | int iwm_invalidate_mlme_profile(struct iwm_priv *iwm) |
| 780 | { |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 781 | struct iwm_umac_invalidate_profile invalid; |
Samuel Ortiz | a70742f | 2009-06-15 21:59:51 +0200 | [diff] [blame] | 782 | int ret; |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 783 | |
| 784 | invalid.hdr.oid = UMAC_WIFI_IF_CMD_INVALIDATE_PROFILE; |
| 785 | invalid.hdr.buf_size = |
| 786 | cpu_to_le16(sizeof(struct iwm_umac_invalidate_profile) - |
| 787 | sizeof(struct iwm_umac_wifi_if)); |
| 788 | |
| 789 | invalid.reason = WLAN_REASON_UNSPECIFIED; |
| 790 | |
| 791 | ret = iwm_send_wifi_if_cmd(iwm, &invalid, sizeof(invalid), 1); |
Zhu Yi | b6c3217 | 2009-07-16 17:34:12 +0800 | [diff] [blame] | 792 | if (ret) |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 793 | return ret; |
| 794 | |
| 795 | ret = wait_event_interruptible_timeout(iwm->mlme_queue, |
Samuel Ortiz | a70742f | 2009-06-15 21:59:51 +0200 | [diff] [blame] | 796 | (iwm->umac_profile_active == 0), 2 * HZ); |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 797 | |
Zhu Yi | b6c3217 | 2009-07-16 17:34:12 +0800 | [diff] [blame] | 798 | return ret ? 0 : -EBUSY; |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 799 | } |
| 800 | |
Samuel Ortiz | 88e6195 | 2009-10-16 13:18:53 +0800 | [diff] [blame] | 801 | int iwm_tx_power_trigger(struct iwm_priv *iwm) |
| 802 | { |
| 803 | struct iwm_umac_pwr_trigger pwr_trigger; |
| 804 | |
| 805 | pwr_trigger.hdr.oid = UMAC_WIFI_IF_CMD_TX_PWR_TRIGGER; |
| 806 | pwr_trigger.hdr.buf_size = |
| 807 | cpu_to_le16(sizeof(struct iwm_umac_pwr_trigger) - |
| 808 | sizeof(struct iwm_umac_wifi_if)); |
| 809 | |
| 810 | |
| 811 | return iwm_send_wifi_if_cmd(iwm, &pwr_trigger, sizeof(pwr_trigger), 1); |
| 812 | } |
| 813 | |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 814 | int iwm_send_umac_stats_req(struct iwm_priv *iwm, u32 flags) |
| 815 | { |
| 816 | struct iwm_udma_wifi_cmd udma_cmd = UDMA_UMAC_INIT; |
| 817 | struct iwm_umac_cmd umac_cmd; |
| 818 | struct iwm_umac_cmd_stats_req stats_req; |
| 819 | |
| 820 | stats_req.flags = cpu_to_le32(flags); |
| 821 | |
| 822 | umac_cmd.id = UMAC_CMD_OPCODE_STATISTIC_REQUEST; |
| 823 | umac_cmd.resp = 0; |
| 824 | |
| 825 | return iwm_hal_send_umac_cmd(iwm, &udma_cmd, &umac_cmd, &stats_req, |
| 826 | sizeof(struct iwm_umac_cmd_stats_req)); |
| 827 | } |
| 828 | |
| 829 | int iwm_send_umac_channel_list(struct iwm_priv *iwm) |
| 830 | { |
| 831 | struct iwm_udma_wifi_cmd udma_cmd = UDMA_UMAC_INIT; |
| 832 | struct iwm_umac_cmd umac_cmd; |
| 833 | struct iwm_umac_cmd_get_channel_list *ch_list; |
| 834 | int size = sizeof(struct iwm_umac_cmd_get_channel_list) + |
| 835 | sizeof(struct iwm_umac_channel_info) * 4; |
| 836 | int ret; |
| 837 | |
| 838 | ch_list = kzalloc(size, GFP_KERNEL); |
| 839 | if (!ch_list) { |
| 840 | IWM_ERR(iwm, "Couldn't allocate channel list cmd\n"); |
| 841 | return -ENOMEM; |
| 842 | } |
| 843 | |
| 844 | ch_list->ch[0].band = UMAC_BAND_2GHZ; |
| 845 | ch_list->ch[0].type = UMAC_CHANNEL_WIDTH_20MHZ; |
| 846 | ch_list->ch[0].flags = UMAC_CHANNEL_FLAG_VALID; |
| 847 | |
| 848 | ch_list->ch[1].band = UMAC_BAND_5GHZ; |
| 849 | ch_list->ch[1].type = UMAC_CHANNEL_WIDTH_20MHZ; |
| 850 | ch_list->ch[1].flags = UMAC_CHANNEL_FLAG_VALID; |
| 851 | |
| 852 | ch_list->ch[2].band = UMAC_BAND_2GHZ; |
| 853 | ch_list->ch[2].type = UMAC_CHANNEL_WIDTH_20MHZ; |
| 854 | ch_list->ch[2].flags = UMAC_CHANNEL_FLAG_VALID | UMAC_CHANNEL_FLAG_IBSS; |
| 855 | |
| 856 | ch_list->ch[3].band = UMAC_BAND_5GHZ; |
| 857 | ch_list->ch[3].type = UMAC_CHANNEL_WIDTH_20MHZ; |
| 858 | ch_list->ch[3].flags = UMAC_CHANNEL_FLAG_VALID | UMAC_CHANNEL_FLAG_IBSS; |
| 859 | |
| 860 | ch_list->count = cpu_to_le16(4); |
| 861 | |
| 862 | umac_cmd.id = UMAC_CMD_OPCODE_GET_CHAN_INFO_LIST; |
| 863 | umac_cmd.resp = 1; |
| 864 | |
| 865 | ret = iwm_hal_send_umac_cmd(iwm, &udma_cmd, &umac_cmd, ch_list, size); |
| 866 | |
| 867 | kfree(ch_list); |
| 868 | |
| 869 | return ret; |
| 870 | } |
| 871 | |
| 872 | int iwm_scan_ssids(struct iwm_priv *iwm, struct cfg80211_ssid *ssids, |
| 873 | int ssid_num) |
| 874 | { |
| 875 | struct iwm_umac_cmd_scan_request req; |
| 876 | int i, ret; |
| 877 | |
| 878 | memset(&req, 0, sizeof(struct iwm_umac_cmd_scan_request)); |
| 879 | |
| 880 | req.hdr.oid = UMAC_WIFI_IF_CMD_SCAN_REQUEST; |
| 881 | req.hdr.buf_size = cpu_to_le16(sizeof(struct iwm_umac_cmd_scan_request) |
| 882 | - sizeof(struct iwm_umac_wifi_if)); |
| 883 | req.type = UMAC_WIFI_IF_SCAN_TYPE_USER; |
| 884 | req.timeout = 2; |
| 885 | req.seq_num = iwm->scan_id; |
| 886 | req.ssid_num = min(ssid_num, UMAC_WIFI_IF_PROBE_OPTION_MAX); |
| 887 | |
| 888 | for (i = 0; i < req.ssid_num; i++) { |
| 889 | memcpy(req.ssids[i].ssid, ssids[i].ssid, ssids[i].ssid_len); |
| 890 | req.ssids[i].ssid_len = ssids[i].ssid_len; |
| 891 | } |
| 892 | |
| 893 | ret = iwm_send_wifi_if_cmd(iwm, &req, sizeof(req), 0); |
Zhu Yi | b6c3217 | 2009-07-16 17:34:12 +0800 | [diff] [blame] | 894 | if (ret) { |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 895 | IWM_ERR(iwm, "Couldn't send scan request\n"); |
| 896 | return ret; |
| 897 | } |
| 898 | |
| 899 | iwm->scan_id = iwm->scan_id++ % IWM_SCAN_ID_MAX; |
| 900 | |
| 901 | return 0; |
| 902 | } |
| 903 | |
| 904 | int iwm_scan_one_ssid(struct iwm_priv *iwm, u8 *ssid, int ssid_len) |
| 905 | { |
| 906 | struct cfg80211_ssid one_ssid; |
| 907 | |
| 908 | if (test_and_set_bit(IWM_STATUS_SCANNING, &iwm->status)) |
| 909 | return 0; |
| 910 | |
| 911 | one_ssid.ssid_len = min(ssid_len, IEEE80211_MAX_SSID_LEN); |
| 912 | memcpy(&one_ssid.ssid, ssid, one_ssid.ssid_len); |
| 913 | |
| 914 | return iwm_scan_ssids(iwm, &one_ssid, 1); |
| 915 | } |
| 916 | |
| 917 | int iwm_target_reset(struct iwm_priv *iwm) |
| 918 | { |
| 919 | struct iwm_udma_nonwifi_cmd target_cmd; |
| 920 | |
| 921 | target_cmd.opcode = UMAC_HDI_OUT_OPCODE_REBOOT; |
| 922 | target_cmd.addr = 0; |
| 923 | target_cmd.op1_sz = 0; |
| 924 | target_cmd.op2 = 0; |
| 925 | target_cmd.handle_by_hw = 0; |
| 926 | target_cmd.resp = 0; |
| 927 | target_cmd.eop = 1; |
| 928 | |
| 929 | return iwm_hal_send_target_cmd(iwm, &target_cmd, NULL); |
| 930 | } |