commands.c 27 KB

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