iwl-testmode.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084
  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-wifi.h"
  73. #include "iwl-dev.h"
  74. #include "iwl-core.h"
  75. #include "iwl-debug.h"
  76. #include "iwl-io.h"
  77. #include "iwl-agn.h"
  78. #include "iwl-testmode.h"
  79. #include "iwl-trans.h"
  80. #include "iwl-bus.h"
  81. #include "iwl-fh.h"
  82. /* Periphery registers absolute lower bound. This is used in order to
  83. * differentiate registery access through HBUS_TARG_PRPH_* and
  84. * HBUS_TARG_MEM_* accesses.
  85. */
  86. #define IWL_TM_ABS_PRPH_START (0xA00000)
  87. /* The TLVs used in the gnl message policy between the kernel module and
  88. * user space application. iwl_testmode_gnl_msg_policy is to be carried
  89. * through the NL80211_CMD_TESTMODE channel regulated by nl80211.
  90. * See iwl-testmode.h
  91. */
  92. static
  93. struct nla_policy iwl_testmode_gnl_msg_policy[IWL_TM_ATTR_MAX] = {
  94. [IWL_TM_ATTR_COMMAND] = { .type = NLA_U32, },
  95. [IWL_TM_ATTR_UCODE_CMD_ID] = { .type = NLA_U8, },
  96. [IWL_TM_ATTR_UCODE_CMD_DATA] = { .type = NLA_UNSPEC, },
  97. [IWL_TM_ATTR_REG_OFFSET] = { .type = NLA_U32, },
  98. [IWL_TM_ATTR_REG_VALUE8] = { .type = NLA_U8, },
  99. [IWL_TM_ATTR_REG_VALUE32] = { .type = NLA_U32, },
  100. [IWL_TM_ATTR_SYNC_RSP] = { .type = NLA_UNSPEC, },
  101. [IWL_TM_ATTR_UCODE_RX_PKT] = { .type = NLA_UNSPEC, },
  102. [IWL_TM_ATTR_EEPROM] = { .type = NLA_UNSPEC, },
  103. [IWL_TM_ATTR_TRACE_ADDR] = { .type = NLA_UNSPEC, },
  104. [IWL_TM_ATTR_TRACE_DUMP] = { .type = NLA_UNSPEC, },
  105. [IWL_TM_ATTR_TRACE_SIZE] = { .type = NLA_U32, },
  106. [IWL_TM_ATTR_FIXRATE] = { .type = NLA_U32, },
  107. [IWL_TM_ATTR_UCODE_OWNER] = { .type = NLA_U8, },
  108. [IWL_TM_ATTR_MEM_ADDR] = { .type = NLA_U32, },
  109. [IWL_TM_ATTR_BUFFER_SIZE] = { .type = NLA_U32, },
  110. [IWL_TM_ATTR_BUFFER_DUMP] = { .type = NLA_UNSPEC, },
  111. [IWL_TM_ATTR_FW_VERSION] = { .type = NLA_U32, },
  112. [IWL_TM_ATTR_DEVICE_ID] = { .type = NLA_U32, },
  113. [IWL_TM_ATTR_FW_TYPE] = { .type = NLA_U32, },
  114. [IWL_TM_ATTR_FW_INST_SIZE] = { .type = NLA_U32, },
  115. [IWL_TM_ATTR_FW_DATA_SIZE] = { .type = NLA_U32, },
  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_mem_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_mem_buffer *rxb)
  150. {
  151. struct ieee80211_hw *hw = priv->hw;
  152. struct sk_buff *skb;
  153. void *data;
  154. int length;
  155. data = (void *)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. NLA_PUT(skb, IWL_TM_ATTR_UCODE_RX_PKT, length, data);
  168. cfg80211_testmode_event(skb, GFP_ATOMIC);
  169. return;
  170. nla_put_failure:
  171. kfree_skb(skb);
  172. IWL_ERR(priv, "Ouch, overran buffer, check allocation!\n");
  173. }
  174. void iwl_testmode_init(struct iwl_priv *priv)
  175. {
  176. priv->pre_rx_handler = iwl_testmode_ucode_rx_pkt;
  177. priv->testmode_trace.trace_enabled = false;
  178. priv->testmode_mem.read_in_progress = false;
  179. }
  180. static void iwl_mem_cleanup(struct iwl_priv *priv)
  181. {
  182. if (priv->testmode_mem.read_in_progress) {
  183. kfree(priv->testmode_mem.buff_addr);
  184. priv->testmode_mem.buff_addr = NULL;
  185. priv->testmode_mem.buff_size = 0;
  186. priv->testmode_mem.num_chunks = 0;
  187. priv->testmode_mem.read_in_progress = false;
  188. }
  189. }
  190. static void iwl_trace_cleanup(struct iwl_priv *priv)
  191. {
  192. if (priv->testmode_trace.trace_enabled) {
  193. if (priv->testmode_trace.cpu_addr &&
  194. priv->testmode_trace.dma_addr)
  195. dma_free_coherent(trans(priv)->dev,
  196. priv->testmode_trace.total_size,
  197. priv->testmode_trace.cpu_addr,
  198. priv->testmode_trace.dma_addr);
  199. priv->testmode_trace.trace_enabled = false;
  200. priv->testmode_trace.cpu_addr = NULL;
  201. priv->testmode_trace.trace_addr = NULL;
  202. priv->testmode_trace.dma_addr = 0;
  203. priv->testmode_trace.buff_size = 0;
  204. priv->testmode_trace.total_size = 0;
  205. }
  206. }
  207. void iwl_testmode_cleanup(struct iwl_priv *priv)
  208. {
  209. iwl_trace_cleanup(priv);
  210. iwl_mem_cleanup(priv);
  211. }
  212. /*
  213. * This function handles the user application commands to the ucode.
  214. *
  215. * It retrieves the mandatory fields IWL_TM_ATTR_UCODE_CMD_ID and
  216. * IWL_TM_ATTR_UCODE_CMD_DATA and calls to the handler to send the
  217. * host command to the ucode.
  218. *
  219. * If any mandatory field is missing, -ENOMSG is replied to the user space
  220. * application; otherwise, waits for the host command to be sent and checks
  221. * the return code. In case or error, it is returned, otherwise a reply is
  222. * allocated and the reply RX packet
  223. * is returned.
  224. *
  225. * @hw: ieee80211_hw object that represents the device
  226. * @tb: gnl message fields from the user space
  227. */
  228. static int iwl_testmode_ucode(struct ieee80211_hw *hw, struct nlattr **tb)
  229. {
  230. struct iwl_priv *priv = hw->priv;
  231. struct iwl_host_cmd cmd;
  232. struct iwl_rx_packet *pkt;
  233. struct sk_buff *skb;
  234. void *reply_buf;
  235. u32 reply_len;
  236. int ret;
  237. bool cmd_want_skb;
  238. memset(&cmd, 0, sizeof(struct iwl_host_cmd));
  239. if (!tb[IWL_TM_ATTR_UCODE_CMD_ID] ||
  240. !tb[IWL_TM_ATTR_UCODE_CMD_DATA]) {
  241. IWL_ERR(priv, "Missing ucode command mandatory fields\n");
  242. return -ENOMSG;
  243. }
  244. cmd.flags = CMD_ON_DEMAND | CMD_SYNC;
  245. cmd_want_skb = nla_get_flag(tb[IWL_TM_ATTR_UCODE_CMD_SKB]);
  246. if (cmd_want_skb)
  247. cmd.flags |= CMD_WANT_SKB;
  248. cmd.id = nla_get_u8(tb[IWL_TM_ATTR_UCODE_CMD_ID]);
  249. cmd.data[0] = nla_data(tb[IWL_TM_ATTR_UCODE_CMD_DATA]);
  250. cmd.len[0] = nla_len(tb[IWL_TM_ATTR_UCODE_CMD_DATA]);
  251. cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
  252. IWL_DEBUG_INFO(priv, "testmode ucode command ID 0x%x, flags 0x%x,"
  253. " len %d\n", cmd.id, cmd.flags, cmd.len[0]);
  254. ret = iwl_trans_send_cmd(trans(priv), &cmd);
  255. if (ret) {
  256. IWL_ERR(priv, "Failed to send hcmd\n");
  257. return ret;
  258. }
  259. if (!cmd_want_skb)
  260. return ret;
  261. /* Handling return of SKB to the user */
  262. pkt = (struct iwl_rx_packet *)cmd.reply_page;
  263. if (!pkt) {
  264. IWL_ERR(priv, "HCMD received a null response packet\n");
  265. return ret;
  266. }
  267. reply_len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
  268. skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, reply_len + 20);
  269. reply_buf = kmalloc(reply_len, GFP_KERNEL);
  270. if (!skb || !reply_buf) {
  271. kfree_skb(skb);
  272. kfree(reply_buf);
  273. return -ENOMEM;
  274. }
  275. /* The reply is in a page, that we cannot send to user space. */
  276. memcpy(reply_buf, &(pkt->hdr), reply_len);
  277. iwl_free_pages(priv->shrd, cmd.reply_page);
  278. NLA_PUT_U32(skb, IWL_TM_ATTR_COMMAND, IWL_TM_CMD_DEV2APP_UCODE_RX_PKT);
  279. NLA_PUT(skb, IWL_TM_ATTR_UCODE_RX_PKT, reply_len, reply_buf);
  280. return cfg80211_testmode_reply(skb);
  281. nla_put_failure:
  282. IWL_DEBUG_INFO(priv, "Failed creating NL attributes\n");
  283. return -ENOMSG;
  284. }
  285. /*
  286. * This function handles the user application commands for register access.
  287. *
  288. * It retrieves command ID carried with IWL_TM_ATTR_COMMAND and calls to the
  289. * handlers respectively.
  290. *
  291. * If it's an unknown commdn ID, -ENOSYS is returned; or -ENOMSG if the
  292. * mandatory fields(IWL_TM_ATTR_REG_OFFSET,IWL_TM_ATTR_REG_VALUE32,
  293. * IWL_TM_ATTR_REG_VALUE8) are missing; Otherwise 0 is replied indicating
  294. * the success of the command execution.
  295. *
  296. * If IWL_TM_ATTR_COMMAND is IWL_TM_CMD_APP2DEV_REG_READ32, the register read
  297. * value is returned with IWL_TM_ATTR_REG_VALUE32.
  298. *
  299. * @hw: ieee80211_hw object that represents the device
  300. * @tb: gnl message fields from the user space
  301. */
  302. static int iwl_testmode_reg(struct ieee80211_hw *hw, struct nlattr **tb)
  303. {
  304. struct iwl_priv *priv = hw->priv;
  305. u32 ofs, val32, cmd;
  306. u8 val8;
  307. struct sk_buff *skb;
  308. int status = 0;
  309. if (!tb[IWL_TM_ATTR_REG_OFFSET]) {
  310. IWL_ERR(priv, "Missing register offset\n");
  311. return -ENOMSG;
  312. }
  313. ofs = nla_get_u32(tb[IWL_TM_ATTR_REG_OFFSET]);
  314. IWL_INFO(priv, "testmode register access command offset 0x%x\n", ofs);
  315. /* Allow access only to FH/CSR/HBUS in direct mode.
  316. Since we don't have the upper bounds for the CSR and HBUS segments,
  317. we will use only the upper bound of FH for sanity check. */
  318. cmd = nla_get_u32(tb[IWL_TM_ATTR_COMMAND]);
  319. if ((cmd == IWL_TM_CMD_APP2DEV_DIRECT_REG_READ32 ||
  320. cmd == IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE32 ||
  321. cmd == IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE8) &&
  322. (ofs >= FH_MEM_UPPER_BOUND)) {
  323. IWL_ERR(priv, "offset out of segment (0x0 - 0x%x)\n",
  324. FH_MEM_UPPER_BOUND);
  325. return -EINVAL;
  326. }
  327. switch (cmd) {
  328. case IWL_TM_CMD_APP2DEV_DIRECT_REG_READ32:
  329. val32 = iwl_read_direct32(trans(priv), ofs);
  330. IWL_INFO(priv, "32bit value to read 0x%x\n", val32);
  331. skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, 20);
  332. if (!skb) {
  333. IWL_ERR(priv, "Memory allocation fail\n");
  334. return -ENOMEM;
  335. }
  336. NLA_PUT_U32(skb, IWL_TM_ATTR_REG_VALUE32, val32);
  337. status = cfg80211_testmode_reply(skb);
  338. if (status < 0)
  339. IWL_ERR(priv, "Error sending msg : %d\n", status);
  340. break;
  341. case IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE32:
  342. if (!tb[IWL_TM_ATTR_REG_VALUE32]) {
  343. IWL_ERR(priv, "Missing value to write\n");
  344. return -ENOMSG;
  345. } else {
  346. val32 = nla_get_u32(tb[IWL_TM_ATTR_REG_VALUE32]);
  347. IWL_INFO(priv, "32bit value to write 0x%x\n", val32);
  348. iwl_write_direct32(trans(priv), ofs, val32);
  349. }
  350. break;
  351. case IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE8:
  352. if (!tb[IWL_TM_ATTR_REG_VALUE8]) {
  353. IWL_ERR(priv, "Missing value to write\n");
  354. return -ENOMSG;
  355. } else {
  356. val8 = nla_get_u8(tb[IWL_TM_ATTR_REG_VALUE8]);
  357. IWL_INFO(priv, "8bit value to write 0x%x\n", val8);
  358. iwl_write8(trans(priv), ofs, val8);
  359. }
  360. break;
  361. default:
  362. IWL_ERR(priv, "Unknown testmode register command ID\n");
  363. return -ENOSYS;
  364. }
  365. return status;
  366. nla_put_failure:
  367. kfree_skb(skb);
  368. return -EMSGSIZE;
  369. }
  370. static int iwl_testmode_cfg_init_calib(struct iwl_priv *priv)
  371. {
  372. struct iwl_notification_wait calib_wait;
  373. int ret;
  374. iwl_init_notification_wait(priv->shrd, &calib_wait,
  375. CALIBRATION_COMPLETE_NOTIFICATION,
  376. NULL, NULL);
  377. ret = iwl_init_alive_start(trans(priv));
  378. if (ret) {
  379. IWL_ERR(priv, "Fail init calibration: %d\n", ret);
  380. goto cfg_init_calib_error;
  381. }
  382. ret = iwl_wait_notification(priv->shrd, &calib_wait, 2 * HZ);
  383. if (ret)
  384. IWL_ERR(priv, "Error detecting"
  385. " CALIBRATION_COMPLETE_NOTIFICATION: %d\n", ret);
  386. return ret;
  387. cfg_init_calib_error:
  388. iwl_remove_notification(priv->shrd, &calib_wait);
  389. return ret;
  390. }
  391. /*
  392. * This function handles the user application commands for driver.
  393. *
  394. * It retrieves command ID carried with IWL_TM_ATTR_COMMAND and calls to the
  395. * handlers respectively.
  396. *
  397. * If it's an unknown commdn ID, -ENOSYS is replied; otherwise, the returned
  398. * value of the actual command execution is replied to the user application.
  399. *
  400. * If there's any message responding to the user space, IWL_TM_ATTR_SYNC_RSP
  401. * is used for carry the message while IWL_TM_ATTR_COMMAND must set to
  402. * IWL_TM_CMD_DEV2APP_SYNC_RSP.
  403. *
  404. * @hw: ieee80211_hw object that represents the device
  405. * @tb: gnl message fields from the user space
  406. */
  407. static int iwl_testmode_driver(struct ieee80211_hw *hw, struct nlattr **tb)
  408. {
  409. struct iwl_priv *priv = hw->priv;
  410. struct iwl_trans *trans = trans(priv);
  411. struct sk_buff *skb;
  412. unsigned char *rsp_data_ptr = NULL;
  413. int status = 0, rsp_data_len = 0;
  414. u32 devid, inst_size = 0, data_size = 0;
  415. switch (nla_get_u32(tb[IWL_TM_ATTR_COMMAND])) {
  416. case IWL_TM_CMD_APP2DEV_GET_DEVICENAME:
  417. rsp_data_ptr = (unsigned char *)cfg(priv)->name;
  418. rsp_data_len = strlen(cfg(priv)->name);
  419. skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy,
  420. rsp_data_len + 20);
  421. if (!skb) {
  422. IWL_ERR(priv, "Memory allocation fail\n");
  423. return -ENOMEM;
  424. }
  425. NLA_PUT_U32(skb, IWL_TM_ATTR_COMMAND,
  426. IWL_TM_CMD_DEV2APP_SYNC_RSP);
  427. NLA_PUT(skb, IWL_TM_ATTR_SYNC_RSP,
  428. rsp_data_len, rsp_data_ptr);
  429. status = cfg80211_testmode_reply(skb);
  430. if (status < 0)
  431. IWL_ERR(priv, "Error sending msg : %d\n", status);
  432. break;
  433. case IWL_TM_CMD_APP2DEV_LOAD_INIT_FW:
  434. status = iwl_load_ucode_wait_alive(trans, IWL_UCODE_INIT);
  435. if (status)
  436. IWL_ERR(priv, "Error loading init ucode: %d\n", status);
  437. break;
  438. case IWL_TM_CMD_APP2DEV_CFG_INIT_CALIB:
  439. iwl_testmode_cfg_init_calib(priv);
  440. iwl_trans_stop_device(trans);
  441. break;
  442. case IWL_TM_CMD_APP2DEV_LOAD_RUNTIME_FW:
  443. status = iwl_load_ucode_wait_alive(trans, IWL_UCODE_REGULAR);
  444. if (status) {
  445. IWL_ERR(priv,
  446. "Error loading runtime ucode: %d\n", status);
  447. break;
  448. }
  449. status = iwl_alive_start(priv);
  450. if (status)
  451. IWL_ERR(priv,
  452. "Error starting the device: %d\n", status);
  453. break;
  454. case IWL_TM_CMD_APP2DEV_LOAD_WOWLAN_FW:
  455. iwl_scan_cancel_timeout(priv, 200);
  456. iwl_trans_stop_device(trans);
  457. status = iwl_load_ucode_wait_alive(trans, IWL_UCODE_WOWLAN);
  458. if (status) {
  459. IWL_ERR(priv,
  460. "Error loading WOWLAN ucode: %d\n", status);
  461. break;
  462. }
  463. status = iwl_alive_start(priv);
  464. if (status)
  465. IWL_ERR(priv,
  466. "Error starting the device: %d\n", status);
  467. break;
  468. case IWL_TM_CMD_APP2DEV_GET_EEPROM:
  469. if (priv->shrd->eeprom) {
  470. skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy,
  471. cfg(priv)->base_params->eeprom_size + 20);
  472. if (!skb) {
  473. IWL_ERR(priv, "Memory allocation fail\n");
  474. return -ENOMEM;
  475. }
  476. NLA_PUT_U32(skb, IWL_TM_ATTR_COMMAND,
  477. IWL_TM_CMD_DEV2APP_EEPROM_RSP);
  478. NLA_PUT(skb, IWL_TM_ATTR_EEPROM,
  479. cfg(priv)->base_params->eeprom_size,
  480. priv->shrd->eeprom);
  481. status = cfg80211_testmode_reply(skb);
  482. if (status < 0)
  483. IWL_ERR(priv, "Error sending msg : %d\n",
  484. status);
  485. } else
  486. return -EFAULT;
  487. break;
  488. case IWL_TM_CMD_APP2DEV_FIXRATE_REQ:
  489. if (!tb[IWL_TM_ATTR_FIXRATE]) {
  490. IWL_ERR(priv, "Missing fixrate setting\n");
  491. return -ENOMSG;
  492. }
  493. priv->tm_fixed_rate = nla_get_u32(tb[IWL_TM_ATTR_FIXRATE]);
  494. break;
  495. case IWL_TM_CMD_APP2DEV_GET_FW_VERSION:
  496. IWL_INFO(priv, "uCode version raw: 0x%x\n",
  497. nic(priv)->fw.ucode_ver);
  498. skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, 20);
  499. if (!skb) {
  500. IWL_ERR(priv, "Memory allocation fail\n");
  501. return -ENOMEM;
  502. }
  503. NLA_PUT_U32(skb, IWL_TM_ATTR_FW_VERSION,
  504. nic(priv)->fw.ucode_ver);
  505. status = cfg80211_testmode_reply(skb);
  506. if (status < 0)
  507. IWL_ERR(priv, "Error sending msg : %d\n", status);
  508. break;
  509. case IWL_TM_CMD_APP2DEV_GET_DEVICE_ID:
  510. devid = trans(priv)->hw_id;
  511. IWL_INFO(priv, "hw version: 0x%x\n", devid);
  512. skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, 20);
  513. if (!skb) {
  514. IWL_ERR(priv, "Memory allocation fail\n");
  515. return -ENOMEM;
  516. }
  517. NLA_PUT_U32(skb, IWL_TM_ATTR_DEVICE_ID, devid);
  518. status = cfg80211_testmode_reply(skb);
  519. if (status < 0)
  520. IWL_ERR(priv, "Error sending msg : %d\n", status);
  521. break;
  522. case IWL_TM_CMD_APP2DEV_GET_FW_INFO:
  523. skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, 20 + 8);
  524. if (!skb) {
  525. IWL_ERR(priv, "Memory allocation fail\n");
  526. return -ENOMEM;
  527. }
  528. switch (priv->shrd->ucode_type) {
  529. case IWL_UCODE_REGULAR:
  530. inst_size = nic(priv)->fw.ucode_rt.code.len;
  531. data_size = nic(priv)->fw.ucode_rt.data.len;
  532. break;
  533. case IWL_UCODE_INIT:
  534. inst_size = nic(priv)->fw.ucode_init.code.len;
  535. data_size = nic(priv)->fw.ucode_init.data.len;
  536. break;
  537. case IWL_UCODE_WOWLAN:
  538. inst_size = nic(priv)->fw.ucode_wowlan.code.len;
  539. data_size = nic(priv)->fw.ucode_wowlan.data.len;
  540. break;
  541. case IWL_UCODE_NONE:
  542. IWL_ERR(priv, "No uCode has not been loaded\n");
  543. break;
  544. default:
  545. IWL_ERR(priv, "Unsupported uCode type\n");
  546. break;
  547. }
  548. NLA_PUT_U32(skb, IWL_TM_ATTR_FW_TYPE, priv->shrd->ucode_type);
  549. NLA_PUT_U32(skb, IWL_TM_ATTR_FW_INST_SIZE, inst_size);
  550. NLA_PUT_U32(skb, IWL_TM_ATTR_FW_DATA_SIZE, data_size);
  551. status = cfg80211_testmode_reply(skb);
  552. if (status < 0)
  553. IWL_ERR(priv, "Error sending msg : %d\n", status);
  554. break;
  555. default:
  556. IWL_ERR(priv, "Unknown testmode driver command ID\n");
  557. return -ENOSYS;
  558. }
  559. return status;
  560. nla_put_failure:
  561. kfree_skb(skb);
  562. return -EMSGSIZE;
  563. }
  564. /*
  565. * This function handles the user application commands for uCode trace
  566. *
  567. * It retrieves command ID carried with IWL_TM_ATTR_COMMAND and calls to the
  568. * handlers respectively.
  569. *
  570. * If it's an unknown commdn ID, -ENOSYS is replied; otherwise, the returned
  571. * value of the actual command execution is replied to the user application.
  572. *
  573. * @hw: ieee80211_hw object that represents the device
  574. * @tb: gnl message fields from the user space
  575. */
  576. static int iwl_testmode_trace(struct ieee80211_hw *hw, struct nlattr **tb)
  577. {
  578. struct iwl_priv *priv = hw->priv;
  579. struct sk_buff *skb;
  580. int status = 0;
  581. struct device *dev = trans(priv)->dev;
  582. switch (nla_get_u32(tb[IWL_TM_ATTR_COMMAND])) {
  583. case IWL_TM_CMD_APP2DEV_BEGIN_TRACE:
  584. if (priv->testmode_trace.trace_enabled)
  585. return -EBUSY;
  586. if (!tb[IWL_TM_ATTR_TRACE_SIZE])
  587. priv->testmode_trace.buff_size = TRACE_BUFF_SIZE_DEF;
  588. else
  589. priv->testmode_trace.buff_size =
  590. nla_get_u32(tb[IWL_TM_ATTR_TRACE_SIZE]);
  591. if (!priv->testmode_trace.buff_size)
  592. return -EINVAL;
  593. if (priv->testmode_trace.buff_size < TRACE_BUFF_SIZE_MIN ||
  594. priv->testmode_trace.buff_size > TRACE_BUFF_SIZE_MAX)
  595. return -EINVAL;
  596. priv->testmode_trace.total_size =
  597. priv->testmode_trace.buff_size + TRACE_BUFF_PADD;
  598. priv->testmode_trace.cpu_addr =
  599. dma_alloc_coherent(dev,
  600. priv->testmode_trace.total_size,
  601. &priv->testmode_trace.dma_addr,
  602. GFP_KERNEL);
  603. if (!priv->testmode_trace.cpu_addr)
  604. return -ENOMEM;
  605. priv->testmode_trace.trace_enabled = true;
  606. priv->testmode_trace.trace_addr = (u8 *)PTR_ALIGN(
  607. priv->testmode_trace.cpu_addr, 0x100);
  608. memset(priv->testmode_trace.trace_addr, 0x03B,
  609. priv->testmode_trace.buff_size);
  610. skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy,
  611. sizeof(priv->testmode_trace.dma_addr) + 20);
  612. if (!skb) {
  613. IWL_ERR(priv, "Memory allocation fail\n");
  614. iwl_trace_cleanup(priv);
  615. return -ENOMEM;
  616. }
  617. NLA_PUT(skb, IWL_TM_ATTR_TRACE_ADDR,
  618. sizeof(priv->testmode_trace.dma_addr),
  619. (u64 *)&priv->testmode_trace.dma_addr);
  620. status = cfg80211_testmode_reply(skb);
  621. if (status < 0) {
  622. IWL_ERR(priv, "Error sending msg : %d\n", status);
  623. }
  624. priv->testmode_trace.num_chunks =
  625. DIV_ROUND_UP(priv->testmode_trace.buff_size,
  626. DUMP_CHUNK_SIZE);
  627. break;
  628. case IWL_TM_CMD_APP2DEV_END_TRACE:
  629. iwl_trace_cleanup(priv);
  630. break;
  631. default:
  632. IWL_ERR(priv, "Unknown testmode mem command ID\n");
  633. return -ENOSYS;
  634. }
  635. return status;
  636. nla_put_failure:
  637. kfree_skb(skb);
  638. if (nla_get_u32(tb[IWL_TM_ATTR_COMMAND]) ==
  639. IWL_TM_CMD_APP2DEV_BEGIN_TRACE)
  640. iwl_trace_cleanup(priv);
  641. return -EMSGSIZE;
  642. }
  643. static int iwl_testmode_trace_dump(struct ieee80211_hw *hw, struct nlattr **tb,
  644. struct sk_buff *skb,
  645. struct netlink_callback *cb)
  646. {
  647. struct iwl_priv *priv = hw->priv;
  648. int idx, length;
  649. if (priv->testmode_trace.trace_enabled &&
  650. priv->testmode_trace.trace_addr) {
  651. idx = cb->args[4];
  652. if (idx >= priv->testmode_trace.num_chunks)
  653. return -ENOENT;
  654. length = DUMP_CHUNK_SIZE;
  655. if (((idx + 1) == priv->testmode_trace.num_chunks) &&
  656. (priv->testmode_trace.buff_size % DUMP_CHUNK_SIZE))
  657. length = priv->testmode_trace.buff_size %
  658. DUMP_CHUNK_SIZE;
  659. NLA_PUT(skb, IWL_TM_ATTR_TRACE_DUMP, length,
  660. priv->testmode_trace.trace_addr +
  661. (DUMP_CHUNK_SIZE * idx));
  662. idx++;
  663. cb->args[4] = idx;
  664. return 0;
  665. } else
  666. return -EFAULT;
  667. nla_put_failure:
  668. return -ENOBUFS;
  669. }
  670. /*
  671. * This function handles the user application switch ucode ownership.
  672. *
  673. * It retrieves the mandatory fields IWL_TM_ATTR_UCODE_OWNER and
  674. * decide who the current owner of the uCode
  675. *
  676. * If the current owner is OWNERSHIP_TM, then the only host command
  677. * can deliver to uCode is from testmode, all the other host commands
  678. * will dropped.
  679. *
  680. * default driver is the owner of uCode in normal operational mode
  681. *
  682. * @hw: ieee80211_hw object that represents the device
  683. * @tb: gnl message fields from the user space
  684. */
  685. static int iwl_testmode_ownership(struct ieee80211_hw *hw, struct nlattr **tb)
  686. {
  687. struct iwl_priv *priv = hw->priv;
  688. u8 owner;
  689. if (!tb[IWL_TM_ATTR_UCODE_OWNER]) {
  690. IWL_ERR(priv, "Missing ucode owner\n");
  691. return -ENOMSG;
  692. }
  693. owner = nla_get_u8(tb[IWL_TM_ATTR_UCODE_OWNER]);
  694. if ((owner == IWL_OWNERSHIP_DRIVER) || (owner == IWL_OWNERSHIP_TM))
  695. priv->shrd->ucode_owner = owner;
  696. else {
  697. IWL_ERR(priv, "Invalid owner\n");
  698. return -EINVAL;
  699. }
  700. return 0;
  701. }
  702. static int iwl_testmode_indirect_read(struct iwl_priv *priv, u32 addr, u32 size)
  703. {
  704. struct iwl_trans *trans = trans(priv);
  705. unsigned long flags;
  706. int i;
  707. if (size & 0x3)
  708. return -EINVAL;
  709. priv->testmode_mem.buff_size = size;
  710. priv->testmode_mem.buff_addr =
  711. kmalloc(priv->testmode_mem.buff_size, GFP_KERNEL);
  712. if (priv->testmode_mem.buff_addr == NULL)
  713. return -ENOMEM;
  714. /* Hard-coded periphery absolute address */
  715. if (IWL_TM_ABS_PRPH_START <= addr &&
  716. addr < IWL_TM_ABS_PRPH_START + PRPH_END) {
  717. spin_lock_irqsave(&trans->reg_lock, flags);
  718. iwl_grab_nic_access(trans);
  719. iwl_write32(trans, HBUS_TARG_PRPH_RADDR,
  720. addr | (3 << 24));
  721. for (i = 0; i < size; i += 4)
  722. *(u32 *)(priv->testmode_mem.buff_addr + i) =
  723. iwl_read32(trans, HBUS_TARG_PRPH_RDAT);
  724. iwl_release_nic_access(trans);
  725. spin_unlock_irqrestore(&trans->reg_lock, flags);
  726. } else { /* target memory (SRAM) */
  727. _iwl_read_targ_mem_words(trans, addr,
  728. priv->testmode_mem.buff_addr,
  729. priv->testmode_mem.buff_size / 4);
  730. }
  731. priv->testmode_mem.num_chunks =
  732. DIV_ROUND_UP(priv->testmode_mem.buff_size, DUMP_CHUNK_SIZE);
  733. priv->testmode_mem.read_in_progress = true;
  734. return 0;
  735. }
  736. static int iwl_testmode_indirect_write(struct iwl_priv *priv, u32 addr,
  737. u32 size, unsigned char *buf)
  738. {
  739. struct iwl_trans *trans = trans(priv);
  740. u32 val, i;
  741. unsigned long flags;
  742. if (IWL_TM_ABS_PRPH_START <= addr &&
  743. addr < IWL_TM_ABS_PRPH_START + PRPH_END) {
  744. /* Periphery writes can be 1-3 bytes long, or DWORDs */
  745. if (size < 4) {
  746. memcpy(&val, buf, size);
  747. spin_lock_irqsave(&trans->reg_lock, flags);
  748. iwl_grab_nic_access(trans);
  749. iwl_write32(trans, HBUS_TARG_PRPH_WADDR,
  750. (addr & 0x0000FFFF) |
  751. ((size - 1) << 24));
  752. iwl_write32(trans, HBUS_TARG_PRPH_WDAT, val);
  753. iwl_release_nic_access(trans);
  754. /* needed after consecutive writes w/o read */
  755. mmiowb();
  756. spin_unlock_irqrestore(&trans->reg_lock, flags);
  757. } else {
  758. if (size % 4)
  759. return -EINVAL;
  760. for (i = 0; i < size; i += 4)
  761. iwl_write_prph(trans, addr+i,
  762. *(u32 *)(buf+i));
  763. }
  764. } else if (iwlagn_hw_valid_rtc_data_addr(addr) ||
  765. (IWLAGN_RTC_INST_LOWER_BOUND <= addr &&
  766. addr < IWLAGN_RTC_INST_UPPER_BOUND)) {
  767. _iwl_write_targ_mem_words(trans, addr, buf, size/4);
  768. } else
  769. return -EINVAL;
  770. return 0;
  771. }
  772. /*
  773. * This function handles the user application commands for SRAM data dump
  774. *
  775. * It retrieves the mandatory fields IWL_TM_ATTR_SRAM_ADDR and
  776. * IWL_TM_ATTR_SRAM_SIZE to decide the memory area for SRAM data reading
  777. *
  778. * Several error will be retured, -EBUSY if the SRAM data retrieved by
  779. * previous command has not been delivered to userspace, or -ENOMSG if
  780. * the mandatory fields (IWL_TM_ATTR_SRAM_ADDR,IWL_TM_ATTR_SRAM_SIZE)
  781. * are missing, or -ENOMEM if the buffer allocation fails.
  782. *
  783. * Otherwise 0 is replied indicating the success of the SRAM reading.
  784. *
  785. * @hw: ieee80211_hw object that represents the device
  786. * @tb: gnl message fields from the user space
  787. */
  788. static int iwl_testmode_indirect_mem(struct ieee80211_hw *hw,
  789. struct nlattr **tb)
  790. {
  791. struct iwl_priv *priv = hw->priv;
  792. u32 addr, size, cmd;
  793. unsigned char *buf;
  794. /* Both read and write should be blocked, for atomicity */
  795. if (priv->testmode_mem.read_in_progress)
  796. return -EBUSY;
  797. cmd = nla_get_u32(tb[IWL_TM_ATTR_COMMAND]);
  798. if (!tb[IWL_TM_ATTR_MEM_ADDR]) {
  799. IWL_ERR(priv, "Error finding memory offset address\n");
  800. return -ENOMSG;
  801. }
  802. addr = nla_get_u32(tb[IWL_TM_ATTR_MEM_ADDR]);
  803. if (!tb[IWL_TM_ATTR_BUFFER_SIZE]) {
  804. IWL_ERR(priv, "Error finding size for memory reading\n");
  805. return -ENOMSG;
  806. }
  807. size = nla_get_u32(tb[IWL_TM_ATTR_BUFFER_SIZE]);
  808. if (cmd == IWL_TM_CMD_APP2DEV_INDIRECT_BUFFER_READ)
  809. return iwl_testmode_indirect_read(priv, addr, size);
  810. else {
  811. if (!tb[IWL_TM_ATTR_BUFFER_DUMP])
  812. return -EINVAL;
  813. buf = (unsigned char *) nla_data(tb[IWL_TM_ATTR_BUFFER_DUMP]);
  814. return iwl_testmode_indirect_write(priv, addr, size, buf);
  815. }
  816. }
  817. static int iwl_testmode_buffer_dump(struct ieee80211_hw *hw, struct nlattr **tb,
  818. struct sk_buff *skb,
  819. struct netlink_callback *cb)
  820. {
  821. struct iwl_priv *priv = hw->priv;
  822. int idx, length;
  823. if (priv->testmode_mem.read_in_progress) {
  824. idx = cb->args[4];
  825. if (idx >= priv->testmode_mem.num_chunks) {
  826. iwl_mem_cleanup(priv);
  827. return -ENOENT;
  828. }
  829. length = DUMP_CHUNK_SIZE;
  830. if (((idx + 1) == priv->testmode_mem.num_chunks) &&
  831. (priv->testmode_mem.buff_size % DUMP_CHUNK_SIZE))
  832. length = priv->testmode_mem.buff_size %
  833. DUMP_CHUNK_SIZE;
  834. NLA_PUT(skb, IWL_TM_ATTR_BUFFER_DUMP, length,
  835. priv->testmode_mem.buff_addr +
  836. (DUMP_CHUNK_SIZE * idx));
  837. idx++;
  838. cb->args[4] = idx;
  839. return 0;
  840. } else
  841. return -EFAULT;
  842. nla_put_failure:
  843. return -ENOBUFS;
  844. }
  845. /* The testmode gnl message handler that takes the gnl message from the
  846. * user space and parses it per the policy iwl_testmode_gnl_msg_policy, then
  847. * invoke the corresponding handlers.
  848. *
  849. * This function is invoked when there is user space application sending
  850. * gnl message through the testmode tunnel NL80211_CMD_TESTMODE regulated
  851. * by nl80211.
  852. *
  853. * It retrieves the mandatory field, IWL_TM_ATTR_COMMAND, before
  854. * dispatching it to the corresponding handler.
  855. *
  856. * If IWL_TM_ATTR_COMMAND is missing, -ENOMSG is replied to user application;
  857. * -ENOSYS is replied to the user application if the command is unknown;
  858. * Otherwise, the command is dispatched to the respective handler.
  859. *
  860. * @hw: ieee80211_hw object that represents the device
  861. * @data: pointer to user space message
  862. * @len: length in byte of @data
  863. */
  864. int iwlagn_mac_testmode_cmd(struct ieee80211_hw *hw, void *data, int len)
  865. {
  866. struct nlattr *tb[IWL_TM_ATTR_MAX];
  867. struct iwl_priv *priv = hw->priv;
  868. int result;
  869. result = nla_parse(tb, IWL_TM_ATTR_MAX - 1, data, len,
  870. iwl_testmode_gnl_msg_policy);
  871. if (result != 0) {
  872. IWL_ERR(priv, "Error parsing the gnl message : %d\n", result);
  873. return result;
  874. }
  875. /* IWL_TM_ATTR_COMMAND is absolutely mandatory */
  876. if (!tb[IWL_TM_ATTR_COMMAND]) {
  877. IWL_ERR(priv, "Missing testmode command type\n");
  878. return -ENOMSG;
  879. }
  880. /* in case multiple accesses to the device happens */
  881. mutex_lock(&priv->shrd->mutex);
  882. switch (nla_get_u32(tb[IWL_TM_ATTR_COMMAND])) {
  883. case IWL_TM_CMD_APP2DEV_UCODE:
  884. IWL_DEBUG_INFO(priv, "testmode cmd to uCode\n");
  885. result = iwl_testmode_ucode(hw, tb);
  886. break;
  887. case IWL_TM_CMD_APP2DEV_DIRECT_REG_READ32:
  888. case IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE32:
  889. case IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE8:
  890. IWL_DEBUG_INFO(priv, "testmode cmd to register\n");
  891. result = iwl_testmode_reg(hw, tb);
  892. break;
  893. case IWL_TM_CMD_APP2DEV_GET_DEVICENAME:
  894. case IWL_TM_CMD_APP2DEV_LOAD_INIT_FW:
  895. case IWL_TM_CMD_APP2DEV_CFG_INIT_CALIB:
  896. case IWL_TM_CMD_APP2DEV_LOAD_RUNTIME_FW:
  897. case IWL_TM_CMD_APP2DEV_GET_EEPROM:
  898. case IWL_TM_CMD_APP2DEV_FIXRATE_REQ:
  899. case IWL_TM_CMD_APP2DEV_LOAD_WOWLAN_FW:
  900. case IWL_TM_CMD_APP2DEV_GET_FW_VERSION:
  901. case IWL_TM_CMD_APP2DEV_GET_DEVICE_ID:
  902. case IWL_TM_CMD_APP2DEV_GET_FW_INFO:
  903. IWL_DEBUG_INFO(priv, "testmode cmd to driver\n");
  904. result = iwl_testmode_driver(hw, tb);
  905. break;
  906. case IWL_TM_CMD_APP2DEV_BEGIN_TRACE:
  907. case IWL_TM_CMD_APP2DEV_END_TRACE:
  908. case IWL_TM_CMD_APP2DEV_READ_TRACE:
  909. IWL_DEBUG_INFO(priv, "testmode uCode trace cmd to driver\n");
  910. result = iwl_testmode_trace(hw, tb);
  911. break;
  912. case IWL_TM_CMD_APP2DEV_OWNERSHIP:
  913. IWL_DEBUG_INFO(priv, "testmode change uCode ownership\n");
  914. result = iwl_testmode_ownership(hw, tb);
  915. break;
  916. case IWL_TM_CMD_APP2DEV_INDIRECT_BUFFER_READ:
  917. case IWL_TM_CMD_APP2DEV_INDIRECT_BUFFER_WRITE:
  918. IWL_DEBUG_INFO(priv, "testmode indirect memory cmd "
  919. "to driver\n");
  920. result = iwl_testmode_indirect_mem(hw, tb);
  921. break;
  922. default:
  923. IWL_ERR(priv, "Unknown testmode command\n");
  924. result = -ENOSYS;
  925. break;
  926. }
  927. mutex_unlock(&priv->shrd->mutex);
  928. return result;
  929. }
  930. int iwlagn_mac_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *skb,
  931. struct netlink_callback *cb,
  932. void *data, int len)
  933. {
  934. struct nlattr *tb[IWL_TM_ATTR_MAX];
  935. struct iwl_priv *priv = hw->priv;
  936. int result;
  937. u32 cmd;
  938. if (cb->args[3]) {
  939. /* offset by 1 since commands start at 0 */
  940. cmd = cb->args[3] - 1;
  941. } else {
  942. result = nla_parse(tb, IWL_TM_ATTR_MAX - 1, data, len,
  943. iwl_testmode_gnl_msg_policy);
  944. if (result) {
  945. IWL_ERR(priv,
  946. "Error parsing the gnl message : %d\n", result);
  947. return result;
  948. }
  949. /* IWL_TM_ATTR_COMMAND is absolutely mandatory */
  950. if (!tb[IWL_TM_ATTR_COMMAND]) {
  951. IWL_ERR(priv, "Missing testmode command type\n");
  952. return -ENOMSG;
  953. }
  954. cmd = nla_get_u32(tb[IWL_TM_ATTR_COMMAND]);
  955. cb->args[3] = cmd + 1;
  956. }
  957. /* in case multiple accesses to the device happens */
  958. mutex_lock(&priv->shrd->mutex);
  959. switch (cmd) {
  960. case IWL_TM_CMD_APP2DEV_READ_TRACE:
  961. IWL_DEBUG_INFO(priv, "uCode trace cmd to driver\n");
  962. result = iwl_testmode_trace_dump(hw, tb, skb, cb);
  963. break;
  964. case IWL_TM_CMD_APP2DEV_INDIRECT_BUFFER_DUMP:
  965. IWL_DEBUG_INFO(priv, "testmode sram dump cmd to driver\n");
  966. result = iwl_testmode_buffer_dump(hw, tb, skb, cb);
  967. break;
  968. default:
  969. result = -EINVAL;
  970. break;
  971. }
  972. mutex_unlock(&priv->shrd->mutex);
  973. return result;
  974. }