commands.c 26 KB

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