commands.c 25 KB

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