commands.c 27 KB

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