commands.c 27 KB

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