iwl-testmode.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102
  1. /******************************************************************************
  2. *
  3. * This file is provided under a dual BSD/GPLv2 license. When using or
  4. * redistributing this file, you may do so under either license.
  5. *
  6. * GPL LICENSE SUMMARY
  7. *
  8. * Copyright(c) 2010 - 2012 Intel Corporation. All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of version 2 of the GNU General Public License as
  12. * published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  22. * USA
  23. *
  24. * The full GNU General Public License is included in this distribution
  25. * in the file called LICENSE.GPL.
  26. *
  27. * Contact Information:
  28. * Intel Linux Wireless <ilw@linux.intel.com>
  29. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  30. *
  31. * BSD LICENSE
  32. *
  33. * Copyright(c) 2010 - 2012 Intel Corporation. All rights reserved.
  34. * All rights reserved.
  35. *
  36. * Redistribution and use in source and binary forms, with or without
  37. * modification, are permitted provided that the following conditions
  38. * are met:
  39. *
  40. * * Redistributions of source code must retain the above copyright
  41. * notice, this list of conditions and the following disclaimer.
  42. * * Redistributions in binary form must reproduce the above copyright
  43. * notice, this list of conditions and the following disclaimer in
  44. * the documentation and/or other materials provided with the
  45. * distribution.
  46. * * Neither the name Intel Corporation nor the names of its
  47. * contributors may be used to endorse or promote products derived
  48. * from this software without specific prior written permission.
  49. *
  50. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  51. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  52. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  53. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  54. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  55. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  56. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  57. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  58. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  59. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  60. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  61. *
  62. *****************************************************************************/
  63. #include <linux/init.h>
  64. #include <linux/kernel.h>
  65. #include <linux/module.h>
  66. #include <linux/dma-mapping.h>
  67. #include <net/net_namespace.h>
  68. #include <linux/netdevice.h>
  69. #include <net/cfg80211.h>
  70. #include <net/mac80211.h>
  71. #include <net/netlink.h>
  72. #include "iwl-dev.h"
  73. #include "iwl-core.h"
  74. #include "iwl-debug.h"
  75. #include "iwl-io.h"
  76. #include "iwl-agn.h"
  77. #include "iwl-testmode.h"
  78. #include "iwl-trans.h"
  79. #include "iwl-fh.h"
  80. #include "iwl-prph.h"
  81. /* Periphery registers absolute lower bound. This is used in order to
  82. * differentiate registery access through HBUS_TARG_PRPH_* and
  83. * HBUS_TARG_MEM_* accesses.
  84. */
  85. #define IWL_TM_ABS_PRPH_START (0xA00000)
  86. /* The TLVs used in the gnl message policy between the kernel module and
  87. * user space application. iwl_testmode_gnl_msg_policy is to be carried
  88. * through the NL80211_CMD_TESTMODE channel regulated by nl80211.
  89. * See iwl-testmode.h
  90. */
  91. static
  92. struct nla_policy iwl_testmode_gnl_msg_policy[IWL_TM_ATTR_MAX] = {
  93. [IWL_TM_ATTR_COMMAND] = { .type = NLA_U32, },
  94. [IWL_TM_ATTR_UCODE_CMD_ID] = { .type = NLA_U8, },
  95. [IWL_TM_ATTR_UCODE_CMD_DATA] = { .type = NLA_UNSPEC, },
  96. [IWL_TM_ATTR_REG_OFFSET] = { .type = NLA_U32, },
  97. [IWL_TM_ATTR_REG_VALUE8] = { .type = NLA_U8, },
  98. [IWL_TM_ATTR_REG_VALUE32] = { .type = NLA_U32, },
  99. [IWL_TM_ATTR_SYNC_RSP] = { .type = NLA_UNSPEC, },
  100. [IWL_TM_ATTR_UCODE_RX_PKT] = { .type = NLA_UNSPEC, },
  101. [IWL_TM_ATTR_EEPROM] = { .type = NLA_UNSPEC, },
  102. [IWL_TM_ATTR_TRACE_ADDR] = { .type = NLA_UNSPEC, },
  103. [IWL_TM_ATTR_TRACE_DUMP] = { .type = NLA_UNSPEC, },
  104. [IWL_TM_ATTR_TRACE_SIZE] = { .type = NLA_U32, },
  105. [IWL_TM_ATTR_FIXRATE] = { .type = NLA_U32, },
  106. [IWL_TM_ATTR_UCODE_OWNER] = { .type = NLA_U8, },
  107. [IWL_TM_ATTR_MEM_ADDR] = { .type = NLA_U32, },
  108. [IWL_TM_ATTR_BUFFER_SIZE] = { .type = NLA_U32, },
  109. [IWL_TM_ATTR_BUFFER_DUMP] = { .type = NLA_UNSPEC, },
  110. [IWL_TM_ATTR_FW_VERSION] = { .type = NLA_U32, },
  111. [IWL_TM_ATTR_DEVICE_ID] = { .type = NLA_U32, },
  112. [IWL_TM_ATTR_FW_TYPE] = { .type = NLA_U32, },
  113. [IWL_TM_ATTR_FW_INST_SIZE] = { .type = NLA_U32, },
  114. [IWL_TM_ATTR_FW_DATA_SIZE] = { .type = NLA_U32, },
  115. [IWL_TM_ATTR_ENABLE_NOTIFICATION] = {.type = NLA_FLAG, },
  116. };
  117. /*
  118. * See the struct iwl_rx_packet in iwl-commands.h for the format of the
  119. * received events from the device
  120. */
  121. static inline int get_event_length(struct iwl_rx_cmd_buffer *rxb)
  122. {
  123. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  124. if (pkt)
  125. return le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
  126. else
  127. return 0;
  128. }
  129. /*
  130. * This function multicasts the spontaneous messages from the device to the
  131. * user space. It is invoked whenever there is a received messages
  132. * from the device. This function is called within the ISR of the rx handlers
  133. * in iwlagn driver.
  134. *
  135. * The parsing of the message content is left to the user space application,
  136. * The message content is treated as unattacked raw data and is encapsulated
  137. * with IWL_TM_ATTR_UCODE_RX_PKT multicasting to the user space.
  138. *
  139. * @priv: the instance of iwlwifi device
  140. * @rxb: pointer to rx data content received by the ISR
  141. *
  142. * See the message policies and TLVs in iwl_testmode_gnl_msg_policy[].
  143. * For the messages multicasting to the user application, the mandatory
  144. * TLV fields are :
  145. * IWL_TM_ATTR_COMMAND must be IWL_TM_CMD_DEV2APP_UCODE_RX_PKT
  146. * IWL_TM_ATTR_UCODE_RX_PKT for carrying the message content
  147. */
  148. static void iwl_testmode_ucode_rx_pkt(struct iwl_priv *priv,
  149. struct iwl_rx_cmd_buffer *rxb)
  150. {
  151. struct ieee80211_hw *hw = priv->hw;
  152. struct sk_buff *skb;
  153. void *data;
  154. int length;
  155. data = rxb_addr(rxb);
  156. length = get_event_length(rxb);
  157. if (!data || length == 0)
  158. return;
  159. skb = cfg80211_testmode_alloc_event_skb(hw->wiphy, 20 + length,
  160. GFP_ATOMIC);
  161. if (skb == NULL) {
  162. IWL_ERR(priv,
  163. "Run out of memory for messages to user space ?\n");
  164. return;
  165. }
  166. NLA_PUT_U32(skb, IWL_TM_ATTR_COMMAND, IWL_TM_CMD_DEV2APP_UCODE_RX_PKT);
  167. /* the length doesn't include len_n_flags field, so add it manually */
  168. NLA_PUT(skb, IWL_TM_ATTR_UCODE_RX_PKT, length + sizeof(__le32), data);
  169. cfg80211_testmode_event(skb, GFP_ATOMIC);
  170. return;
  171. nla_put_failure:
  172. kfree_skb(skb);
  173. IWL_ERR(priv, "Ouch, overran buffer, check allocation!\n");
  174. }
  175. void iwl_testmode_init(struct iwl_priv *priv)
  176. {
  177. priv->pre_rx_handler = NULL;
  178. priv->testmode_trace.trace_enabled = false;
  179. priv->testmode_mem.read_in_progress = false;
  180. }
  181. static void iwl_mem_cleanup(struct iwl_priv *priv)
  182. {
  183. if (priv->testmode_mem.read_in_progress) {
  184. kfree(priv->testmode_mem.buff_addr);
  185. priv->testmode_mem.buff_addr = NULL;
  186. priv->testmode_mem.buff_size = 0;
  187. priv->testmode_mem.num_chunks = 0;
  188. priv->testmode_mem.read_in_progress = false;
  189. }
  190. }
  191. static void iwl_trace_cleanup(struct iwl_priv *priv)
  192. {
  193. if (priv->testmode_trace.trace_enabled) {
  194. if (priv->testmode_trace.cpu_addr &&
  195. priv->testmode_trace.dma_addr)
  196. dma_free_coherent(trans(priv)->dev,
  197. priv->testmode_trace.total_size,
  198. priv->testmode_trace.cpu_addr,
  199. priv->testmode_trace.dma_addr);
  200. priv->testmode_trace.trace_enabled = false;
  201. priv->testmode_trace.cpu_addr = NULL;
  202. priv->testmode_trace.trace_addr = NULL;
  203. priv->testmode_trace.dma_addr = 0;
  204. priv->testmode_trace.buff_size = 0;
  205. priv->testmode_trace.total_size = 0;
  206. }
  207. }
  208. void iwl_testmode_cleanup(struct iwl_priv *priv)
  209. {
  210. iwl_trace_cleanup(priv);
  211. iwl_mem_cleanup(priv);
  212. }
  213. /*
  214. * This function handles the user application commands to the ucode.
  215. *
  216. * It retrieves the mandatory fields IWL_TM_ATTR_UCODE_CMD_ID and
  217. * IWL_TM_ATTR_UCODE_CMD_DATA and calls to the handler to send the
  218. * host command to the ucode.
  219. *
  220. * If any mandatory field is missing, -ENOMSG is replied to the user space
  221. * application; otherwise, waits for the host command to be sent and checks
  222. * the return code. In case or error, it is returned, otherwise a reply is
  223. * allocated and the reply RX packet
  224. * is returned.
  225. *
  226. * @hw: ieee80211_hw object that represents the device
  227. * @tb: gnl message fields from the user space
  228. */
  229. static int iwl_testmode_ucode(struct ieee80211_hw *hw, struct nlattr **tb)
  230. {
  231. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  232. struct iwl_host_cmd cmd;
  233. struct iwl_rx_packet *pkt;
  234. struct sk_buff *skb;
  235. void *reply_buf;
  236. u32 reply_len;
  237. int ret;
  238. bool cmd_want_skb;
  239. memset(&cmd, 0, sizeof(struct iwl_host_cmd));
  240. if (!tb[IWL_TM_ATTR_UCODE_CMD_ID] ||
  241. !tb[IWL_TM_ATTR_UCODE_CMD_DATA]) {
  242. IWL_ERR(priv, "Missing ucode command mandatory fields\n");
  243. return -ENOMSG;
  244. }
  245. cmd.flags = CMD_ON_DEMAND | CMD_SYNC;
  246. cmd_want_skb = nla_get_flag(tb[IWL_TM_ATTR_UCODE_CMD_SKB]);
  247. if (cmd_want_skb)
  248. cmd.flags |= CMD_WANT_SKB;
  249. cmd.id = nla_get_u8(tb[IWL_TM_ATTR_UCODE_CMD_ID]);
  250. cmd.data[0] = nla_data(tb[IWL_TM_ATTR_UCODE_CMD_DATA]);
  251. cmd.len[0] = nla_len(tb[IWL_TM_ATTR_UCODE_CMD_DATA]);
  252. cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
  253. IWL_DEBUG_INFO(priv, "testmode ucode command ID 0x%x, flags 0x%x,"
  254. " len %d\n", cmd.id, cmd.flags, cmd.len[0]);
  255. ret = iwl_dvm_send_cmd(priv, &cmd);
  256. if (ret) {
  257. IWL_ERR(priv, "Failed to send hcmd\n");
  258. return ret;
  259. }
  260. if (!cmd_want_skb)
  261. return ret;
  262. /* Handling return of SKB to the user */
  263. pkt = cmd.resp_pkt;
  264. if (!pkt) {
  265. IWL_ERR(priv, "HCMD received a null response packet\n");
  266. return ret;
  267. }
  268. reply_len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
  269. skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, reply_len + 20);
  270. reply_buf = kmalloc(reply_len, GFP_KERNEL);
  271. if (!skb || !reply_buf) {
  272. kfree_skb(skb);
  273. kfree(reply_buf);
  274. return -ENOMEM;
  275. }
  276. /* The reply is in a page, that we cannot send to user space. */
  277. memcpy(reply_buf, &(pkt->hdr), reply_len);
  278. iwl_free_resp(&cmd);
  279. NLA_PUT_U32(skb, IWL_TM_ATTR_COMMAND, IWL_TM_CMD_DEV2APP_UCODE_RX_PKT);
  280. NLA_PUT(skb, IWL_TM_ATTR_UCODE_RX_PKT, reply_len, reply_buf);
  281. return cfg80211_testmode_reply(skb);
  282. nla_put_failure:
  283. IWL_DEBUG_INFO(priv, "Failed creating NL attributes\n");
  284. return -ENOMSG;
  285. }
  286. /*
  287. * This function handles the user application commands for register access.
  288. *
  289. * It retrieves command ID carried with IWL_TM_ATTR_COMMAND and calls to the
  290. * handlers respectively.
  291. *
  292. * If it's an unknown commdn ID, -ENOSYS is returned; or -ENOMSG if the
  293. * mandatory fields(IWL_TM_ATTR_REG_OFFSET,IWL_TM_ATTR_REG_VALUE32,
  294. * IWL_TM_ATTR_REG_VALUE8) are missing; Otherwise 0 is replied indicating
  295. * the success of the command execution.
  296. *
  297. * If IWL_TM_ATTR_COMMAND is IWL_TM_CMD_APP2DEV_REG_READ32, the register read
  298. * value is returned with IWL_TM_ATTR_REG_VALUE32.
  299. *
  300. * @hw: ieee80211_hw object that represents the device
  301. * @tb: gnl message fields from the user space
  302. */
  303. static int iwl_testmode_reg(struct ieee80211_hw *hw, struct nlattr **tb)
  304. {
  305. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  306. u32 ofs, val32, cmd;
  307. u8 val8;
  308. struct sk_buff *skb;
  309. int status = 0;
  310. if (!tb[IWL_TM_ATTR_REG_OFFSET]) {
  311. IWL_ERR(priv, "Missing register offset\n");
  312. return -ENOMSG;
  313. }
  314. ofs = nla_get_u32(tb[IWL_TM_ATTR_REG_OFFSET]);
  315. IWL_INFO(priv, "testmode register access command offset 0x%x\n", ofs);
  316. /* Allow access only to FH/CSR/HBUS in direct mode.
  317. Since we don't have the upper bounds for the CSR and HBUS segments,
  318. we will use only the upper bound of FH for sanity check. */
  319. cmd = nla_get_u32(tb[IWL_TM_ATTR_COMMAND]);
  320. if ((cmd == IWL_TM_CMD_APP2DEV_DIRECT_REG_READ32 ||
  321. cmd == IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE32 ||
  322. cmd == IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE8) &&
  323. (ofs >= FH_MEM_UPPER_BOUND)) {
  324. IWL_ERR(priv, "offset out of segment (0x0 - 0x%x)\n",
  325. FH_MEM_UPPER_BOUND);
  326. return -EINVAL;
  327. }
  328. switch (cmd) {
  329. case IWL_TM_CMD_APP2DEV_DIRECT_REG_READ32:
  330. val32 = iwl_read_direct32(trans(priv), ofs);
  331. IWL_INFO(priv, "32bit value to read 0x%x\n", val32);
  332. skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, 20);
  333. if (!skb) {
  334. IWL_ERR(priv, "Memory allocation fail\n");
  335. return -ENOMEM;
  336. }
  337. NLA_PUT_U32(skb, IWL_TM_ATTR_REG_VALUE32, val32);
  338. status = cfg80211_testmode_reply(skb);
  339. if (status < 0)
  340. IWL_ERR(priv, "Error sending msg : %d\n", status);
  341. break;
  342. case IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE32:
  343. if (!tb[IWL_TM_ATTR_REG_VALUE32]) {
  344. IWL_ERR(priv, "Missing value to write\n");
  345. return -ENOMSG;
  346. } else {
  347. val32 = nla_get_u32(tb[IWL_TM_ATTR_REG_VALUE32]);
  348. IWL_INFO(priv, "32bit value to write 0x%x\n", val32);
  349. iwl_write_direct32(trans(priv), ofs, val32);
  350. }
  351. break;
  352. case IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE8:
  353. if (!tb[IWL_TM_ATTR_REG_VALUE8]) {
  354. IWL_ERR(priv, "Missing value to write\n");
  355. return -ENOMSG;
  356. } else {
  357. val8 = nla_get_u8(tb[IWL_TM_ATTR_REG_VALUE8]);
  358. IWL_INFO(priv, "8bit value to write 0x%x\n", val8);
  359. iwl_write8(trans(priv), ofs, val8);
  360. }
  361. break;
  362. default:
  363. IWL_ERR(priv, "Unknown testmode register command ID\n");
  364. return -ENOSYS;
  365. }
  366. return status;
  367. nla_put_failure:
  368. kfree_skb(skb);
  369. return -EMSGSIZE;
  370. }
  371. static int iwl_testmode_cfg_init_calib(struct iwl_priv *priv)
  372. {
  373. struct iwl_notification_wait calib_wait;
  374. int ret;
  375. iwl_init_notification_wait(&priv->notif_wait, &calib_wait,
  376. CALIBRATION_COMPLETE_NOTIFICATION,
  377. NULL, NULL);
  378. ret = iwl_init_alive_start(priv);
  379. if (ret) {
  380. IWL_ERR(priv, "Fail init calibration: %d\n", ret);
  381. goto cfg_init_calib_error;
  382. }
  383. ret = iwl_wait_notification(&priv->notif_wait, &calib_wait, 2 * HZ);
  384. if (ret)
  385. IWL_ERR(priv, "Error detecting"
  386. " CALIBRATION_COMPLETE_NOTIFICATION: %d\n", ret);
  387. return ret;
  388. cfg_init_calib_error:
  389. iwl_remove_notification(&priv->notif_wait, &calib_wait);
  390. return ret;
  391. }
  392. /*
  393. * This function handles the user application commands for driver.
  394. *
  395. * It retrieves command ID carried with IWL_TM_ATTR_COMMAND and calls to the
  396. * handlers respectively.
  397. *
  398. * If it's an unknown commdn ID, -ENOSYS is replied; otherwise, the returned
  399. * value of the actual command execution is replied to the user application.
  400. *
  401. * If there's any message responding to the user space, IWL_TM_ATTR_SYNC_RSP
  402. * is used for carry the message while IWL_TM_ATTR_COMMAND must set to
  403. * IWL_TM_CMD_DEV2APP_SYNC_RSP.
  404. *
  405. * @hw: ieee80211_hw object that represents the device
  406. * @tb: gnl message fields from the user space
  407. */
  408. static int iwl_testmode_driver(struct ieee80211_hw *hw, struct nlattr **tb)
  409. {
  410. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  411. struct iwl_trans *trans = trans(priv);
  412. struct sk_buff *skb;
  413. unsigned char *rsp_data_ptr = NULL;
  414. int status = 0, rsp_data_len = 0;
  415. u32 devid, inst_size = 0, data_size = 0;
  416. const struct fw_img *img;
  417. switch (nla_get_u32(tb[IWL_TM_ATTR_COMMAND])) {
  418. case IWL_TM_CMD_APP2DEV_GET_DEVICENAME:
  419. rsp_data_ptr = (unsigned char *)cfg(priv)->name;
  420. rsp_data_len = strlen(cfg(priv)->name);
  421. skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy,
  422. rsp_data_len + 20);
  423. if (!skb) {
  424. IWL_ERR(priv, "Memory allocation fail\n");
  425. return -ENOMEM;
  426. }
  427. NLA_PUT_U32(skb, IWL_TM_ATTR_COMMAND,
  428. IWL_TM_CMD_DEV2APP_SYNC_RSP);
  429. NLA_PUT(skb, IWL_TM_ATTR_SYNC_RSP,
  430. rsp_data_len, rsp_data_ptr);
  431. status = cfg80211_testmode_reply(skb);
  432. if (status < 0)
  433. IWL_ERR(priv, "Error sending msg : %d\n", status);
  434. break;
  435. case IWL_TM_CMD_APP2DEV_LOAD_INIT_FW:
  436. status = iwl_load_ucode_wait_alive(priv, IWL_UCODE_INIT);
  437. if (status)
  438. IWL_ERR(priv, "Error loading init ucode: %d\n", status);
  439. break;
  440. case IWL_TM_CMD_APP2DEV_CFG_INIT_CALIB:
  441. iwl_testmode_cfg_init_calib(priv);
  442. priv->ucode_loaded = false;
  443. iwl_trans_stop_device(trans);
  444. break;
  445. case IWL_TM_CMD_APP2DEV_LOAD_RUNTIME_FW:
  446. status = iwl_load_ucode_wait_alive(priv, IWL_UCODE_REGULAR);
  447. if (status) {
  448. IWL_ERR(priv,
  449. "Error loading runtime ucode: %d\n", status);
  450. break;
  451. }
  452. status = iwl_alive_start(priv);
  453. if (status)
  454. IWL_ERR(priv,
  455. "Error starting the device: %d\n", status);
  456. break;
  457. case IWL_TM_CMD_APP2DEV_LOAD_WOWLAN_FW:
  458. iwl_scan_cancel_timeout(priv, 200);
  459. priv->ucode_loaded = false;
  460. iwl_trans_stop_device(trans);
  461. status = iwl_load_ucode_wait_alive(priv, IWL_UCODE_WOWLAN);
  462. if (status) {
  463. IWL_ERR(priv,
  464. "Error loading WOWLAN ucode: %d\n", status);
  465. break;
  466. }
  467. status = iwl_alive_start(priv);
  468. if (status)
  469. IWL_ERR(priv,
  470. "Error starting the device: %d\n", status);
  471. break;
  472. case IWL_TM_CMD_APP2DEV_GET_EEPROM:
  473. if (priv->shrd->eeprom) {
  474. skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy,
  475. cfg(priv)->base_params->eeprom_size + 20);
  476. if (!skb) {
  477. IWL_ERR(priv, "Memory allocation fail\n");
  478. return -ENOMEM;
  479. }
  480. NLA_PUT_U32(skb, IWL_TM_ATTR_COMMAND,
  481. IWL_TM_CMD_DEV2APP_EEPROM_RSP);
  482. NLA_PUT(skb, IWL_TM_ATTR_EEPROM,
  483. cfg(priv)->base_params->eeprom_size,
  484. priv->shrd->eeprom);
  485. status = cfg80211_testmode_reply(skb);
  486. if (status < 0)
  487. IWL_ERR(priv, "Error sending msg : %d\n",
  488. status);
  489. } else
  490. return -EFAULT;
  491. break;
  492. case IWL_TM_CMD_APP2DEV_FIXRATE_REQ:
  493. if (!tb[IWL_TM_ATTR_FIXRATE]) {
  494. IWL_ERR(priv, "Missing fixrate setting\n");
  495. return -ENOMSG;
  496. }
  497. priv->tm_fixed_rate = nla_get_u32(tb[IWL_TM_ATTR_FIXRATE]);
  498. break;
  499. case IWL_TM_CMD_APP2DEV_GET_FW_VERSION:
  500. IWL_INFO(priv, "uCode version raw: 0x%x\n",
  501. priv->fw->ucode_ver);
  502. skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, 20);
  503. if (!skb) {
  504. IWL_ERR(priv, "Memory allocation fail\n");
  505. return -ENOMEM;
  506. }
  507. NLA_PUT_U32(skb, IWL_TM_ATTR_FW_VERSION,
  508. priv->fw->ucode_ver);
  509. status = cfg80211_testmode_reply(skb);
  510. if (status < 0)
  511. IWL_ERR(priv, "Error sending msg : %d\n", status);
  512. break;
  513. case IWL_TM_CMD_APP2DEV_GET_DEVICE_ID:
  514. devid = trans(priv)->hw_id;
  515. IWL_INFO(priv, "hw version: 0x%x\n", devid);
  516. skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, 20);
  517. if (!skb) {
  518. IWL_ERR(priv, "Memory allocation fail\n");
  519. return -ENOMEM;
  520. }
  521. NLA_PUT_U32(skb, IWL_TM_ATTR_DEVICE_ID, devid);
  522. status = cfg80211_testmode_reply(skb);
  523. if (status < 0)
  524. IWL_ERR(priv, "Error sending msg : %d\n", status);
  525. break;
  526. case IWL_TM_CMD_APP2DEV_GET_FW_INFO:
  527. skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, 20 + 8);
  528. if (!skb) {
  529. IWL_ERR(priv, "Memory allocation fail\n");
  530. return -ENOMEM;
  531. }
  532. if (!priv->ucode_loaded) {
  533. IWL_ERR(priv, "No uCode has not been loaded\n");
  534. return -EINVAL;
  535. } else {
  536. img = &priv->fw->img[priv->shrd->ucode_type];
  537. inst_size = img->sec[IWL_UCODE_SECTION_INST].len;
  538. data_size = img->sec[IWL_UCODE_SECTION_DATA].len;
  539. }
  540. NLA_PUT_U32(skb, IWL_TM_ATTR_FW_TYPE, priv->shrd->ucode_type);
  541. NLA_PUT_U32(skb, IWL_TM_ATTR_FW_INST_SIZE, inst_size);
  542. NLA_PUT_U32(skb, IWL_TM_ATTR_FW_DATA_SIZE, data_size);
  543. status = cfg80211_testmode_reply(skb);
  544. if (status < 0)
  545. IWL_ERR(priv, "Error sending msg : %d\n", status);
  546. break;
  547. default:
  548. IWL_ERR(priv, "Unknown testmode driver command ID\n");
  549. return -ENOSYS;
  550. }
  551. return status;
  552. nla_put_failure:
  553. kfree_skb(skb);
  554. return -EMSGSIZE;
  555. }
  556. /*
  557. * This function handles the user application commands for uCode trace
  558. *
  559. * It retrieves command ID carried with IWL_TM_ATTR_COMMAND and calls to the
  560. * handlers respectively.
  561. *
  562. * If it's an unknown commdn ID, -ENOSYS is replied; otherwise, the returned
  563. * value of the actual command execution is replied to the user application.
  564. *
  565. * @hw: ieee80211_hw object that represents the device
  566. * @tb: gnl message fields from the user space
  567. */
  568. static int iwl_testmode_trace(struct ieee80211_hw *hw, struct nlattr **tb)
  569. {
  570. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  571. struct sk_buff *skb;
  572. int status = 0;
  573. struct device *dev = trans(priv)->dev;
  574. switch (nla_get_u32(tb[IWL_TM_ATTR_COMMAND])) {
  575. case IWL_TM_CMD_APP2DEV_BEGIN_TRACE:
  576. if (priv->testmode_trace.trace_enabled)
  577. return -EBUSY;
  578. if (!tb[IWL_TM_ATTR_TRACE_SIZE])
  579. priv->testmode_trace.buff_size = TRACE_BUFF_SIZE_DEF;
  580. else
  581. priv->testmode_trace.buff_size =
  582. nla_get_u32(tb[IWL_TM_ATTR_TRACE_SIZE]);
  583. if (!priv->testmode_trace.buff_size)
  584. return -EINVAL;
  585. if (priv->testmode_trace.buff_size < TRACE_BUFF_SIZE_MIN ||
  586. priv->testmode_trace.buff_size > TRACE_BUFF_SIZE_MAX)
  587. return -EINVAL;
  588. priv->testmode_trace.total_size =
  589. priv->testmode_trace.buff_size + TRACE_BUFF_PADD;
  590. priv->testmode_trace.cpu_addr =
  591. dma_alloc_coherent(dev,
  592. priv->testmode_trace.total_size,
  593. &priv->testmode_trace.dma_addr,
  594. GFP_KERNEL);
  595. if (!priv->testmode_trace.cpu_addr)
  596. return -ENOMEM;
  597. priv->testmode_trace.trace_enabled = true;
  598. priv->testmode_trace.trace_addr = (u8 *)PTR_ALIGN(
  599. priv->testmode_trace.cpu_addr, 0x100);
  600. memset(priv->testmode_trace.trace_addr, 0x03B,
  601. priv->testmode_trace.buff_size);
  602. skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy,
  603. sizeof(priv->testmode_trace.dma_addr) + 20);
  604. if (!skb) {
  605. IWL_ERR(priv, "Memory allocation fail\n");
  606. iwl_trace_cleanup(priv);
  607. return -ENOMEM;
  608. }
  609. NLA_PUT(skb, IWL_TM_ATTR_TRACE_ADDR,
  610. sizeof(priv->testmode_trace.dma_addr),
  611. (u64 *)&priv->testmode_trace.dma_addr);
  612. status = cfg80211_testmode_reply(skb);
  613. if (status < 0) {
  614. IWL_ERR(priv, "Error sending msg : %d\n", status);
  615. }
  616. priv->testmode_trace.num_chunks =
  617. DIV_ROUND_UP(priv->testmode_trace.buff_size,
  618. DUMP_CHUNK_SIZE);
  619. break;
  620. case IWL_TM_CMD_APP2DEV_END_TRACE:
  621. iwl_trace_cleanup(priv);
  622. break;
  623. default:
  624. IWL_ERR(priv, "Unknown testmode mem command ID\n");
  625. return -ENOSYS;
  626. }
  627. return status;
  628. nla_put_failure:
  629. kfree_skb(skb);
  630. if (nla_get_u32(tb[IWL_TM_ATTR_COMMAND]) ==
  631. IWL_TM_CMD_APP2DEV_BEGIN_TRACE)
  632. iwl_trace_cleanup(priv);
  633. return -EMSGSIZE;
  634. }
  635. static int iwl_testmode_trace_dump(struct ieee80211_hw *hw,
  636. struct sk_buff *skb,
  637. struct netlink_callback *cb)
  638. {
  639. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  640. int idx, length;
  641. if (priv->testmode_trace.trace_enabled &&
  642. priv->testmode_trace.trace_addr) {
  643. idx = cb->args[4];
  644. if (idx >= priv->testmode_trace.num_chunks)
  645. return -ENOENT;
  646. length = DUMP_CHUNK_SIZE;
  647. if (((idx + 1) == priv->testmode_trace.num_chunks) &&
  648. (priv->testmode_trace.buff_size % DUMP_CHUNK_SIZE))
  649. length = priv->testmode_trace.buff_size %
  650. DUMP_CHUNK_SIZE;
  651. NLA_PUT(skb, IWL_TM_ATTR_TRACE_DUMP, length,
  652. priv->testmode_trace.trace_addr +
  653. (DUMP_CHUNK_SIZE * idx));
  654. idx++;
  655. cb->args[4] = idx;
  656. return 0;
  657. } else
  658. return -EFAULT;
  659. nla_put_failure:
  660. return -ENOBUFS;
  661. }
  662. /*
  663. * This function handles the user application switch ucode ownership.
  664. *
  665. * It retrieves the mandatory fields IWL_TM_ATTR_UCODE_OWNER and
  666. * decide who the current owner of the uCode
  667. *
  668. * If the current owner is OWNERSHIP_TM, then the only host command
  669. * can deliver to uCode is from testmode, all the other host commands
  670. * will dropped.
  671. *
  672. * default driver is the owner of uCode in normal operational mode
  673. *
  674. * @hw: ieee80211_hw object that represents the device
  675. * @tb: gnl message fields from the user space
  676. */
  677. static int iwl_testmode_ownership(struct ieee80211_hw *hw, struct nlattr **tb)
  678. {
  679. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  680. u8 owner;
  681. if (!tb[IWL_TM_ATTR_UCODE_OWNER]) {
  682. IWL_ERR(priv, "Missing ucode owner\n");
  683. return -ENOMSG;
  684. }
  685. owner = nla_get_u8(tb[IWL_TM_ATTR_UCODE_OWNER]);
  686. if (owner == IWL_OWNERSHIP_DRIVER) {
  687. priv->ucode_owner = owner;
  688. priv->pre_rx_handler = NULL;
  689. } else if (owner == IWL_OWNERSHIP_TM) {
  690. priv->pre_rx_handler = iwl_testmode_ucode_rx_pkt;
  691. priv->ucode_owner = owner;
  692. } else {
  693. IWL_ERR(priv, "Invalid owner\n");
  694. return -EINVAL;
  695. }
  696. return 0;
  697. }
  698. static int iwl_testmode_indirect_read(struct iwl_priv *priv, u32 addr, u32 size)
  699. {
  700. struct iwl_trans *trans = trans(priv);
  701. unsigned long flags;
  702. int i;
  703. if (size & 0x3)
  704. return -EINVAL;
  705. priv->testmode_mem.buff_size = size;
  706. priv->testmode_mem.buff_addr =
  707. kmalloc(priv->testmode_mem.buff_size, GFP_KERNEL);
  708. if (priv->testmode_mem.buff_addr == NULL)
  709. return -ENOMEM;
  710. /* Hard-coded periphery absolute address */
  711. if (IWL_TM_ABS_PRPH_START <= addr &&
  712. addr < IWL_TM_ABS_PRPH_START + PRPH_END) {
  713. spin_lock_irqsave(&trans->reg_lock, flags);
  714. iwl_grab_nic_access(trans);
  715. iwl_write32(trans, HBUS_TARG_PRPH_RADDR,
  716. addr | (3 << 24));
  717. for (i = 0; i < size; i += 4)
  718. *(u32 *)(priv->testmode_mem.buff_addr + i) =
  719. iwl_read32(trans, HBUS_TARG_PRPH_RDAT);
  720. iwl_release_nic_access(trans);
  721. spin_unlock_irqrestore(&trans->reg_lock, flags);
  722. } else { /* target memory (SRAM) */
  723. _iwl_read_targ_mem_words(trans, addr,
  724. priv->testmode_mem.buff_addr,
  725. priv->testmode_mem.buff_size / 4);
  726. }
  727. priv->testmode_mem.num_chunks =
  728. DIV_ROUND_UP(priv->testmode_mem.buff_size, DUMP_CHUNK_SIZE);
  729. priv->testmode_mem.read_in_progress = true;
  730. return 0;
  731. }
  732. static int iwl_testmode_indirect_write(struct iwl_priv *priv, u32 addr,
  733. u32 size, unsigned char *buf)
  734. {
  735. struct iwl_trans *trans = trans(priv);
  736. u32 val, i;
  737. unsigned long flags;
  738. if (IWL_TM_ABS_PRPH_START <= addr &&
  739. addr < IWL_TM_ABS_PRPH_START + PRPH_END) {
  740. /* Periphery writes can be 1-3 bytes long, or DWORDs */
  741. if (size < 4) {
  742. memcpy(&val, buf, size);
  743. spin_lock_irqsave(&trans->reg_lock, flags);
  744. iwl_grab_nic_access(trans);
  745. iwl_write32(trans, HBUS_TARG_PRPH_WADDR,
  746. (addr & 0x0000FFFF) |
  747. ((size - 1) << 24));
  748. iwl_write32(trans, HBUS_TARG_PRPH_WDAT, val);
  749. iwl_release_nic_access(trans);
  750. /* needed after consecutive writes w/o read */
  751. mmiowb();
  752. spin_unlock_irqrestore(&trans->reg_lock, flags);
  753. } else {
  754. if (size % 4)
  755. return -EINVAL;
  756. for (i = 0; i < size; i += 4)
  757. iwl_write_prph(trans, addr+i,
  758. *(u32 *)(buf+i));
  759. }
  760. } else if (iwlagn_hw_valid_rtc_data_addr(addr) ||
  761. (IWLAGN_RTC_INST_LOWER_BOUND <= addr &&
  762. addr < IWLAGN_RTC_INST_UPPER_BOUND)) {
  763. _iwl_write_targ_mem_words(trans, addr, buf, size/4);
  764. } else
  765. return -EINVAL;
  766. return 0;
  767. }
  768. /*
  769. * This function handles the user application commands for SRAM data dump
  770. *
  771. * It retrieves the mandatory fields IWL_TM_ATTR_SRAM_ADDR and
  772. * IWL_TM_ATTR_SRAM_SIZE to decide the memory area for SRAM data reading
  773. *
  774. * Several error will be retured, -EBUSY if the SRAM data retrieved by
  775. * previous command has not been delivered to userspace, or -ENOMSG if
  776. * the mandatory fields (IWL_TM_ATTR_SRAM_ADDR,IWL_TM_ATTR_SRAM_SIZE)
  777. * are missing, or -ENOMEM if the buffer allocation fails.
  778. *
  779. * Otherwise 0 is replied indicating the success of the SRAM reading.
  780. *
  781. * @hw: ieee80211_hw object that represents the device
  782. * @tb: gnl message fields from the user space
  783. */
  784. static int iwl_testmode_indirect_mem(struct ieee80211_hw *hw,
  785. struct nlattr **tb)
  786. {
  787. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  788. u32 addr, size, cmd;
  789. unsigned char *buf;
  790. /* Both read and write should be blocked, for atomicity */
  791. if (priv->testmode_mem.read_in_progress)
  792. return -EBUSY;
  793. cmd = nla_get_u32(tb[IWL_TM_ATTR_COMMAND]);
  794. if (!tb[IWL_TM_ATTR_MEM_ADDR]) {
  795. IWL_ERR(priv, "Error finding memory offset address\n");
  796. return -ENOMSG;
  797. }
  798. addr = nla_get_u32(tb[IWL_TM_ATTR_MEM_ADDR]);
  799. if (!tb[IWL_TM_ATTR_BUFFER_SIZE]) {
  800. IWL_ERR(priv, "Error finding size for memory reading\n");
  801. return -ENOMSG;
  802. }
  803. size = nla_get_u32(tb[IWL_TM_ATTR_BUFFER_SIZE]);
  804. if (cmd == IWL_TM_CMD_APP2DEV_INDIRECT_BUFFER_READ)
  805. return iwl_testmode_indirect_read(priv, addr, size);
  806. else {
  807. if (!tb[IWL_TM_ATTR_BUFFER_DUMP])
  808. return -EINVAL;
  809. buf = (unsigned char *) nla_data(tb[IWL_TM_ATTR_BUFFER_DUMP]);
  810. return iwl_testmode_indirect_write(priv, addr, size, buf);
  811. }
  812. }
  813. static int iwl_testmode_buffer_dump(struct ieee80211_hw *hw,
  814. struct sk_buff *skb,
  815. struct netlink_callback *cb)
  816. {
  817. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  818. int idx, length;
  819. if (priv->testmode_mem.read_in_progress) {
  820. idx = cb->args[4];
  821. if (idx >= priv->testmode_mem.num_chunks) {
  822. iwl_mem_cleanup(priv);
  823. return -ENOENT;
  824. }
  825. length = DUMP_CHUNK_SIZE;
  826. if (((idx + 1) == priv->testmode_mem.num_chunks) &&
  827. (priv->testmode_mem.buff_size % DUMP_CHUNK_SIZE))
  828. length = priv->testmode_mem.buff_size %
  829. DUMP_CHUNK_SIZE;
  830. NLA_PUT(skb, IWL_TM_ATTR_BUFFER_DUMP, length,
  831. priv->testmode_mem.buff_addr +
  832. (DUMP_CHUNK_SIZE * idx));
  833. idx++;
  834. cb->args[4] = idx;
  835. return 0;
  836. } else
  837. return -EFAULT;
  838. nla_put_failure:
  839. return -ENOBUFS;
  840. }
  841. static int iwl_testmode_notifications(struct ieee80211_hw *hw,
  842. struct nlattr **tb)
  843. {
  844. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  845. bool enable;
  846. enable = nla_get_flag(tb[IWL_TM_ATTR_ENABLE_NOTIFICATION]);
  847. if (enable)
  848. priv->pre_rx_handler = iwl_testmode_ucode_rx_pkt;
  849. else
  850. priv->pre_rx_handler = NULL;
  851. return 0;
  852. }
  853. /* The testmode gnl message handler that takes the gnl message from the
  854. * user space and parses it per the policy iwl_testmode_gnl_msg_policy, then
  855. * invoke the corresponding handlers.
  856. *
  857. * This function is invoked when there is user space application sending
  858. * gnl message through the testmode tunnel NL80211_CMD_TESTMODE regulated
  859. * by nl80211.
  860. *
  861. * It retrieves the mandatory field, IWL_TM_ATTR_COMMAND, before
  862. * dispatching it to the corresponding handler.
  863. *
  864. * If IWL_TM_ATTR_COMMAND is missing, -ENOMSG is replied to user application;
  865. * -ENOSYS is replied to the user application if the command is unknown;
  866. * Otherwise, the command is dispatched to the respective handler.
  867. *
  868. * @hw: ieee80211_hw object that represents the device
  869. * @data: pointer to user space message
  870. * @len: length in byte of @data
  871. */
  872. int iwlagn_mac_testmode_cmd(struct ieee80211_hw *hw, void *data, int len)
  873. {
  874. struct nlattr *tb[IWL_TM_ATTR_MAX];
  875. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  876. int result;
  877. result = nla_parse(tb, IWL_TM_ATTR_MAX - 1, data, len,
  878. iwl_testmode_gnl_msg_policy);
  879. if (result != 0) {
  880. IWL_ERR(priv, "Error parsing the gnl message : %d\n", result);
  881. return result;
  882. }
  883. /* IWL_TM_ATTR_COMMAND is absolutely mandatory */
  884. if (!tb[IWL_TM_ATTR_COMMAND]) {
  885. IWL_ERR(priv, "Missing testmode command type\n");
  886. return -ENOMSG;
  887. }
  888. /* in case multiple accesses to the device happens */
  889. mutex_lock(&priv->mutex);
  890. switch (nla_get_u32(tb[IWL_TM_ATTR_COMMAND])) {
  891. case IWL_TM_CMD_APP2DEV_UCODE:
  892. IWL_DEBUG_INFO(priv, "testmode cmd to uCode\n");
  893. result = iwl_testmode_ucode(hw, tb);
  894. break;
  895. case IWL_TM_CMD_APP2DEV_DIRECT_REG_READ32:
  896. case IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE32:
  897. case IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE8:
  898. IWL_DEBUG_INFO(priv, "testmode cmd to register\n");
  899. result = iwl_testmode_reg(hw, tb);
  900. break;
  901. case IWL_TM_CMD_APP2DEV_GET_DEVICENAME:
  902. case IWL_TM_CMD_APP2DEV_LOAD_INIT_FW:
  903. case IWL_TM_CMD_APP2DEV_CFG_INIT_CALIB:
  904. case IWL_TM_CMD_APP2DEV_LOAD_RUNTIME_FW:
  905. case IWL_TM_CMD_APP2DEV_GET_EEPROM:
  906. case IWL_TM_CMD_APP2DEV_FIXRATE_REQ:
  907. case IWL_TM_CMD_APP2DEV_LOAD_WOWLAN_FW:
  908. case IWL_TM_CMD_APP2DEV_GET_FW_VERSION:
  909. case IWL_TM_CMD_APP2DEV_GET_DEVICE_ID:
  910. case IWL_TM_CMD_APP2DEV_GET_FW_INFO:
  911. IWL_DEBUG_INFO(priv, "testmode cmd to driver\n");
  912. result = iwl_testmode_driver(hw, tb);
  913. break;
  914. case IWL_TM_CMD_APP2DEV_BEGIN_TRACE:
  915. case IWL_TM_CMD_APP2DEV_END_TRACE:
  916. case IWL_TM_CMD_APP2DEV_READ_TRACE:
  917. IWL_DEBUG_INFO(priv, "testmode uCode trace cmd to driver\n");
  918. result = iwl_testmode_trace(hw, tb);
  919. break;
  920. case IWL_TM_CMD_APP2DEV_OWNERSHIP:
  921. IWL_DEBUG_INFO(priv, "testmode change uCode ownership\n");
  922. result = iwl_testmode_ownership(hw, tb);
  923. break;
  924. case IWL_TM_CMD_APP2DEV_INDIRECT_BUFFER_READ:
  925. case IWL_TM_CMD_APP2DEV_INDIRECT_BUFFER_WRITE:
  926. IWL_DEBUG_INFO(priv, "testmode indirect memory cmd "
  927. "to driver\n");
  928. result = iwl_testmode_indirect_mem(hw, tb);
  929. break;
  930. case IWL_TM_CMD_APP2DEV_NOTIFICATIONS:
  931. IWL_DEBUG_INFO(priv, "testmode notifications cmd "
  932. "to driver\n");
  933. result = iwl_testmode_notifications(hw, tb);
  934. break;
  935. default:
  936. IWL_ERR(priv, "Unknown testmode command\n");
  937. result = -ENOSYS;
  938. break;
  939. }
  940. mutex_unlock(&priv->mutex);
  941. return result;
  942. }
  943. int iwlagn_mac_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *skb,
  944. struct netlink_callback *cb,
  945. void *data, int len)
  946. {
  947. struct nlattr *tb[IWL_TM_ATTR_MAX];
  948. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  949. int result;
  950. u32 cmd;
  951. if (cb->args[3]) {
  952. /* offset by 1 since commands start at 0 */
  953. cmd = cb->args[3] - 1;
  954. } else {
  955. result = nla_parse(tb, IWL_TM_ATTR_MAX - 1, data, len,
  956. iwl_testmode_gnl_msg_policy);
  957. if (result) {
  958. IWL_ERR(priv,
  959. "Error parsing the gnl message : %d\n", result);
  960. return result;
  961. }
  962. /* IWL_TM_ATTR_COMMAND is absolutely mandatory */
  963. if (!tb[IWL_TM_ATTR_COMMAND]) {
  964. IWL_ERR(priv, "Missing testmode command type\n");
  965. return -ENOMSG;
  966. }
  967. cmd = nla_get_u32(tb[IWL_TM_ATTR_COMMAND]);
  968. cb->args[3] = cmd + 1;
  969. }
  970. /* in case multiple accesses to the device happens */
  971. mutex_lock(&priv->mutex);
  972. switch (cmd) {
  973. case IWL_TM_CMD_APP2DEV_READ_TRACE:
  974. IWL_DEBUG_INFO(priv, "uCode trace cmd to driver\n");
  975. result = iwl_testmode_trace_dump(hw, skb, cb);
  976. break;
  977. case IWL_TM_CMD_APP2DEV_INDIRECT_BUFFER_DUMP:
  978. IWL_DEBUG_INFO(priv, "testmode sram dump cmd to driver\n");
  979. result = iwl_testmode_buffer_dump(hw, skb, cb);
  980. break;
  981. default:
  982. result = -EINVAL;
  983. break;
  984. }
  985. mutex_unlock(&priv->mutex);
  986. return result;
  987. }