aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/iwlwifi/iwl-test.c
diff options
context:
space:
mode:
authorIlan Peer <ilan.peer@intel.com>2012-06-04 12:39:30 -0400
committerJohannes Berg <johannes.berg@intel.com>2012-06-11 05:41:18 -0400
commitc76fe6d19b8beffe792c390c0bd215d193512f1e (patch)
tree97457f8ad76187a4422757194d0a34bb977b24f3 /drivers/net/wireless/iwlwifi/iwl-test.c
parent3a6490c0840c0ae67cc3a51e1b724bd7e460041e (diff)
iwlwifi: decouple testmode and iwl-test
The iwl-test flows were based on the cfg80211 testmode APIs. To remove this coupling, the op mode (during the initialization of the iwl_test object) is responsible to set the callbacks that should be used by iwl-test to allocate skbs for events and replies and to send events and replies. The current op modes implement these callbacks based on the cfg80211 testmode APIs. Reviewed-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com> Signed-off-by: Ilan Peer <ilan.peer@intel.com> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Diffstat (limited to 'drivers/net/wireless/iwlwifi/iwl-test.c')
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-test.c109
1 files changed, 70 insertions, 39 deletions
diff --git a/drivers/net/wireless/iwlwifi/iwl-test.c b/drivers/net/wireless/iwlwifi/iwl-test.c
index 76e18630f35d..7a264aee2534 100644
--- a/drivers/net/wireless/iwlwifi/iwl-test.c
+++ b/drivers/net/wireless/iwlwifi/iwl-test.c
@@ -61,7 +61,9 @@
61 * 61 *
62 *****************************************************************************/ 62 *****************************************************************************/
63 63
64#include <linux/export.h>
64#include <net/netlink.h> 65#include <net/netlink.h>
66
65#include "iwl-io.h" 67#include "iwl-io.h"
66#include "iwl-fh.h" 68#include "iwl-fh.h"
67#include "iwl-prph.h" 69#include "iwl-prph.h"
@@ -178,13 +180,51 @@ void iwl_test_free(struct iwl_test *tst)
178} 180}
179EXPORT_SYMBOL_GPL(iwl_test_free); 181EXPORT_SYMBOL_GPL(iwl_test_free);
180 182
183static inline int iwl_test_send_cmd(struct iwl_test *tst,
184 struct iwl_host_cmd *cmd)
185{
186 return tst->ops->send_cmd(tst->trans->op_mode, cmd);
187}
188
189static inline bool iwl_test_valid_hw_addr(struct iwl_test *tst, u32 addr)
190{
191 return tst->ops->valid_hw_addr(addr);
192}
193
194static inline u32 iwl_test_fw_ver(struct iwl_test *tst)
195{
196 return tst->ops->get_fw_ver(tst->trans->op_mode);
197}
198
199static inline struct sk_buff*
200iwl_test_alloc_reply(struct iwl_test *tst, int len)
201{
202 return tst->ops->alloc_reply(tst->trans->op_mode, len);
203}
204
205static inline int iwl_test_reply(struct iwl_test *tst, struct sk_buff *skb)
206{
207 return tst->ops->reply(tst->trans->op_mode, skb);
208}
209
210static inline struct sk_buff*
211iwl_test_alloc_event(struct iwl_test *tst, int len)
212{
213 return tst->ops->alloc_event(tst->trans->op_mode, len);
214}
215
216static inline void
217iwl_test_event(struct iwl_test *tst, struct sk_buff *skb)
218{
219 return tst->ops->event(tst->trans->op_mode, skb);
220}
221
181/* 222/*
182 * This function handles the user application commands to the fw. The fw 223 * This function handles the user application commands to the fw. The fw
183 * commands are sent in a synchronuous manner. In case that the user requested 224 * commands are sent in a synchronuous manner. In case that the user requested
184 * to get commands response, it is send to the user. 225 * to get commands response, it is send to the user.
185 */ 226 */
186static int iwl_test_fw_cmd(struct iwl_test *tst, struct ieee80211_hw *hw, 227static int iwl_test_fw_cmd(struct iwl_test *tst, struct nlattr **tb)
187 struct nlattr **tb)
188{ 228{
189 struct iwl_host_cmd cmd; 229 struct iwl_host_cmd cmd;
190 struct iwl_rx_packet *pkt; 230 struct iwl_rx_packet *pkt;
@@ -214,7 +254,7 @@ static int iwl_test_fw_cmd(struct iwl_test *tst, struct ieee80211_hw *hw,
214 IWL_DEBUG_INFO(tst->trans, "test fw cmd=0x%x, flags 0x%x, len %d\n", 254 IWL_DEBUG_INFO(tst->trans, "test fw cmd=0x%x, flags 0x%x, len %d\n",
215 cmd.id, cmd.flags, cmd.len[0]); 255 cmd.id, cmd.flags, cmd.len[0]);
216 256
217 ret = tst->ops->send_cmd(tst->trans->op_mode, &cmd); 257 ret = iwl_test_send_cmd(tst, &cmd);
218 if (ret) { 258 if (ret) {
219 IWL_ERR(tst->trans, "Failed to send hcmd\n"); 259 IWL_ERR(tst->trans, "Failed to send hcmd\n");
220 return ret; 260 return ret;
@@ -230,7 +270,7 @@ static int iwl_test_fw_cmd(struct iwl_test *tst, struct ieee80211_hw *hw,
230 } 270 }
231 271
232 reply_len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK; 272 reply_len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
233 skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, reply_len + 20); 273 skb = iwl_test_alloc_reply(tst, reply_len + 20);
234 reply_buf = kmalloc(reply_len, GFP_KERNEL); 274 reply_buf = kmalloc(reply_len, GFP_KERNEL);
235 if (!skb || !reply_buf) { 275 if (!skb || !reply_buf) {
236 kfree_skb(skb); 276 kfree_skb(skb);
@@ -246,7 +286,7 @@ static int iwl_test_fw_cmd(struct iwl_test *tst, struct ieee80211_hw *hw,
246 IWL_TM_CMD_DEV2APP_UCODE_RX_PKT) || 286 IWL_TM_CMD_DEV2APP_UCODE_RX_PKT) ||
247 nla_put(skb, IWL_TM_ATTR_UCODE_RX_PKT, reply_len, reply_buf)) 287 nla_put(skb, IWL_TM_ATTR_UCODE_RX_PKT, reply_len, reply_buf))
248 goto nla_put_failure; 288 goto nla_put_failure;
249 return cfg80211_testmode_reply(skb); 289 return iwl_test_reply(tst, skb);
250 290
251nla_put_failure: 291nla_put_failure:
252 IWL_DEBUG_INFO(tst->trans, "Failed creating NL attributes\n"); 292 IWL_DEBUG_INFO(tst->trans, "Failed creating NL attributes\n");
@@ -258,8 +298,7 @@ nla_put_failure:
258/* 298/*
259 * Handles the user application commands for register access. 299 * Handles the user application commands for register access.
260 */ 300 */
261static int iwl_test_reg(struct iwl_test *tst, struct ieee80211_hw *hw, 301static int iwl_test_reg(struct iwl_test *tst, struct nlattr **tb)
262 struct nlattr **tb)
263{ 302{
264 u32 ofs, val32, cmd; 303 u32 ofs, val32, cmd;
265 u8 val8; 304 u8 val8;
@@ -293,14 +332,14 @@ static int iwl_test_reg(struct iwl_test *tst, struct ieee80211_hw *hw,
293 val32 = iwl_read_direct32(tst->trans, ofs); 332 val32 = iwl_read_direct32(tst->trans, ofs);
294 IWL_DEBUG_INFO(trans, "32 value to read 0x%x\n", val32); 333 IWL_DEBUG_INFO(trans, "32 value to read 0x%x\n", val32);
295 334
296 skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, 20); 335 skb = iwl_test_alloc_reply(tst, 20);
297 if (!skb) { 336 if (!skb) {
298 IWL_ERR(trans, "Memory allocation fail\n"); 337 IWL_ERR(trans, "Memory allocation fail\n");
299 return -ENOMEM; 338 return -ENOMEM;
300 } 339 }
301 if (nla_put_u32(skb, IWL_TM_ATTR_REG_VALUE32, val32)) 340 if (nla_put_u32(skb, IWL_TM_ATTR_REG_VALUE32, val32))
302 goto nla_put_failure; 341 goto nla_put_failure;
303 status = cfg80211_testmode_reply(skb); 342 status = iwl_test_reply(tst, skb);
304 if (status < 0) 343 if (status < 0)
305 IWL_ERR(trans, "Error sending msg : %d\n", status); 344 IWL_ERR(trans, "Error sending msg : %d\n", status);
306 break; 345 break;
@@ -343,8 +382,7 @@ nla_put_failure:
343 * Handles the request to start FW tracing. Allocates of the trace buffer 382 * Handles the request to start FW tracing. Allocates of the trace buffer
344 * and sends a reply to user space with the address of the allocated buffer. 383 * and sends a reply to user space with the address of the allocated buffer.
345 */ 384 */
346static int iwl_test_trace_begin(struct iwl_test *tst, struct ieee80211_hw *hw, 385static int iwl_test_trace_begin(struct iwl_test *tst, struct nlattr **tb)
347 struct nlattr **tb)
348{ 386{
349 struct sk_buff *skb; 387 struct sk_buff *skb;
350 int status = 0; 388 int status = 0;
@@ -378,9 +416,7 @@ static int iwl_test_trace_begin(struct iwl_test *tst, struct ieee80211_hw *hw,
378 416
379 memset(tst->trace.trace_addr, 0x03B, tst->trace.size); 417 memset(tst->trace.trace_addr, 0x03B, tst->trace.size);
380 418
381 skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, 419 skb = iwl_test_alloc_reply(tst, sizeof(tst->trace.dma_addr) + 20);
382 sizeof(tst->trace.dma_addr) + 20);
383
384 if (!skb) { 420 if (!skb) {
385 IWL_ERR(tst->trans, "Memory allocation fail\n"); 421 IWL_ERR(tst->trans, "Memory allocation fail\n");
386 iwl_test_trace_stop(tst); 422 iwl_test_trace_stop(tst);
@@ -392,7 +428,7 @@ static int iwl_test_trace_begin(struct iwl_test *tst, struct ieee80211_hw *hw,
392 (u64 *)&tst->trace.dma_addr)) 428 (u64 *)&tst->trace.dma_addr))
393 goto nla_put_failure; 429 goto nla_put_failure;
394 430
395 status = cfg80211_testmode_reply(skb); 431 status = iwl_test_reply(tst, skb);
396 if (status < 0) 432 if (status < 0)
397 IWL_ERR(tst->trans, "Error sending msg : %d\n", status); 433 IWL_ERR(tst->trans, "Error sending msg : %d\n", status);
398 434
@@ -485,7 +521,7 @@ static int iwl_test_indirect_write(struct iwl_test *tst, u32 addr,
485 iwl_write_prph(trans, addr+i, 521 iwl_write_prph(trans, addr+i,
486 *(u32 *)(buf+i)); 522 *(u32 *)(buf+i));
487 } 523 }
488 } else if (tst->ops->valid_hw_addr(addr)) { 524 } else if (iwl_test_valid_hw_addr(tst, addr)) {
489 _iwl_write_targ_mem_words(trans, addr, buf, size/4); 525 _iwl_write_targ_mem_words(trans, addr, buf, size/4);
490 } else { 526 } else {
491 return -EINVAL; 527 return -EINVAL;
@@ -541,8 +577,7 @@ static int iwl_test_notifications(struct iwl_test *tst,
541/* 577/*
542 * Handles the request to get the device id 578 * Handles the request to get the device id
543 */ 579 */
544static int iwl_test_get_dev_id(struct iwl_test *tst, struct ieee80211_hw *hw, 580static int iwl_test_get_dev_id(struct iwl_test *tst, struct nlattr **tb)
545 struct nlattr **tb)
546{ 581{
547 u32 devid = tst->trans->hw_id; 582 u32 devid = tst->trans->hw_id;
548 struct sk_buff *skb; 583 struct sk_buff *skb;
@@ -550,7 +585,7 @@ static int iwl_test_get_dev_id(struct iwl_test *tst, struct ieee80211_hw *hw,
550 585
551 IWL_DEBUG_INFO(tst->trans, "hw version: 0x%x\n", devid); 586 IWL_DEBUG_INFO(tst->trans, "hw version: 0x%x\n", devid);
552 587
553 skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, 20); 588 skb = iwl_test_alloc_reply(tst, 20);
554 if (!skb) { 589 if (!skb) {
555 IWL_ERR(tst->trans, "Memory allocation fail\n"); 590 IWL_ERR(tst->trans, "Memory allocation fail\n");
556 return -ENOMEM; 591 return -ENOMEM;
@@ -558,7 +593,7 @@ static int iwl_test_get_dev_id(struct iwl_test *tst, struct ieee80211_hw *hw,
558 593
559 if (nla_put_u32(skb, IWL_TM_ATTR_DEVICE_ID, devid)) 594 if (nla_put_u32(skb, IWL_TM_ATTR_DEVICE_ID, devid))
560 goto nla_put_failure; 595 goto nla_put_failure;
561 status = cfg80211_testmode_reply(skb); 596 status = iwl_test_reply(tst, skb);
562 if (status < 0) 597 if (status < 0)
563 IWL_ERR(tst->trans, "Error sending msg : %d\n", status); 598 IWL_ERR(tst->trans, "Error sending msg : %d\n", status);
564 599
@@ -572,16 +607,15 @@ nla_put_failure:
572/* 607/*
573 * Handles the request to get the FW version 608 * Handles the request to get the FW version
574 */ 609 */
575static int iwl_test_get_fw_ver(struct iwl_test *tst, struct ieee80211_hw *hw, 610static int iwl_test_get_fw_ver(struct iwl_test *tst, struct nlattr **tb)
576 struct nlattr **tb)
577{ 611{
578 struct sk_buff *skb; 612 struct sk_buff *skb;
579 int status; 613 int status;
580 u32 ver = tst->ops->get_fw_ver(tst->trans->op_mode); 614 u32 ver = iwl_test_fw_ver(tst);
581 615
582 IWL_DEBUG_INFO(tst->trans, "uCode version raw: 0x%x\n", ver); 616 IWL_DEBUG_INFO(tst->trans, "uCode version raw: 0x%x\n", ver);
583 617
584 skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, 20); 618 skb = iwl_test_alloc_reply(tst, 20);
585 if (!skb) { 619 if (!skb) {
586 IWL_ERR(tst->trans, "Memory allocation fail\n"); 620 IWL_ERR(tst->trans, "Memory allocation fail\n");
587 return -ENOMEM; 621 return -ENOMEM;
@@ -590,7 +624,7 @@ static int iwl_test_get_fw_ver(struct iwl_test *tst, struct ieee80211_hw *hw,
590 if (nla_put_u32(skb, IWL_TM_ATTR_FW_VERSION, ver)) 624 if (nla_put_u32(skb, IWL_TM_ATTR_FW_VERSION, ver))
591 goto nla_put_failure; 625 goto nla_put_failure;
592 626
593 status = cfg80211_testmode_reply(skb); 627 status = iwl_test_reply(tst, skb);
594 if (status < 0) 628 if (status < 0)
595 IWL_ERR(tst->trans, "Error sending msg : %d\n", status); 629 IWL_ERR(tst->trans, "Error sending msg : %d\n", status);
596 630
@@ -630,27 +664,26 @@ EXPORT_SYMBOL_GPL(iwl_test_parse);
630 * Returns 1 for unknown commands (not handled by the test object); negative 664 * Returns 1 for unknown commands (not handled by the test object); negative
631 * value in case of error. 665 * value in case of error.
632 */ 666 */
633int iwl_test_handle_cmd(struct iwl_test *tst, struct ieee80211_hw *hw, 667int iwl_test_handle_cmd(struct iwl_test *tst, struct nlattr **tb)
634 struct nlattr **tb)
635{ 668{
636 int result; 669 int result;
637 670
638 switch (nla_get_u32(tb[IWL_TM_ATTR_COMMAND])) { 671 switch (nla_get_u32(tb[IWL_TM_ATTR_COMMAND])) {
639 case IWL_TM_CMD_APP2DEV_UCODE: 672 case IWL_TM_CMD_APP2DEV_UCODE:
640 IWL_DEBUG_INFO(tst->trans, "test cmd to uCode\n"); 673 IWL_DEBUG_INFO(tst->trans, "test cmd to uCode\n");
641 result = iwl_test_fw_cmd(tst, hw, tb); 674 result = iwl_test_fw_cmd(tst, tb);
642 break; 675 break;
643 676
644 case IWL_TM_CMD_APP2DEV_DIRECT_REG_READ32: 677 case IWL_TM_CMD_APP2DEV_DIRECT_REG_READ32:
645 case IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE32: 678 case IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE32:
646 case IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE8: 679 case IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE8:
647 IWL_DEBUG_INFO(tst->trans, "test cmd to register\n"); 680 IWL_DEBUG_INFO(tst->trans, "test cmd to register\n");
648 result = iwl_test_reg(tst, hw, tb); 681 result = iwl_test_reg(tst, tb);
649 break; 682 break;
650 683
651 case IWL_TM_CMD_APP2DEV_BEGIN_TRACE: 684 case IWL_TM_CMD_APP2DEV_BEGIN_TRACE:
652 IWL_DEBUG_INFO(tst->trans, "test uCode trace cmd to driver\n"); 685 IWL_DEBUG_INFO(tst->trans, "test uCode trace cmd to driver\n");
653 result = iwl_test_trace_begin(tst, hw, tb); 686 result = iwl_test_trace_begin(tst, tb);
654 break; 687 break;
655 688
656 case IWL_TM_CMD_APP2DEV_END_TRACE: 689 case IWL_TM_CMD_APP2DEV_END_TRACE:
@@ -671,12 +704,12 @@ int iwl_test_handle_cmd(struct iwl_test *tst, struct ieee80211_hw *hw,
671 704
672 case IWL_TM_CMD_APP2DEV_GET_FW_VERSION: 705 case IWL_TM_CMD_APP2DEV_GET_FW_VERSION:
673 IWL_DEBUG_INFO(tst->trans, "test get FW ver cmd\n"); 706 IWL_DEBUG_INFO(tst->trans, "test get FW ver cmd\n");
674 result = iwl_test_get_fw_ver(tst, hw, tb); 707 result = iwl_test_get_fw_ver(tst, tb);
675 break; 708 break;
676 709
677 case IWL_TM_CMD_APP2DEV_GET_DEVICE_ID: 710 case IWL_TM_CMD_APP2DEV_GET_DEVICE_ID:
678 IWL_DEBUG_INFO(tst->trans, "test Get device ID cmd\n"); 711 IWL_DEBUG_INFO(tst->trans, "test Get device ID cmd\n");
679 result = iwl_test_get_dev_id(tst, hw, tb); 712 result = iwl_test_get_dev_id(tst, tb);
680 break; 713 break;
681 714
682 default: 715 default:
@@ -779,7 +812,7 @@ EXPORT_SYMBOL_GPL(iwl_test_dump);
779/* 812/*
780 * Multicast a spontaneous messages from the device to the user space. 813 * Multicast a spontaneous messages from the device to the user space.
781 */ 814 */
782static void iwl_test_send_rx(struct iwl_test *tst, struct ieee80211_hw *hw, 815static void iwl_test_send_rx(struct iwl_test *tst,
783 struct iwl_rx_cmd_buffer *rxb) 816 struct iwl_rx_cmd_buffer *rxb)
784{ 817{
785 struct sk_buff *skb; 818 struct sk_buff *skb;
@@ -792,8 +825,7 @@ static void iwl_test_send_rx(struct iwl_test *tst, struct ieee80211_hw *hw,
792 /* the length doesn't include len_n_flags field, so add it manually */ 825 /* the length doesn't include len_n_flags field, so add it manually */
793 length += sizeof(__le32); 826 length += sizeof(__le32);
794 827
795 skb = cfg80211_testmode_alloc_event_skb(hw->wiphy, 20 + length, 828 skb = iwl_test_alloc_event(tst, length + 20);
796 GFP_ATOMIC);
797 if (skb == NULL) { 829 if (skb == NULL) {
798 IWL_ERR(tst->trans, "Out of memory for message to user\n"); 830 IWL_ERR(tst->trans, "Out of memory for message to user\n");
799 return; 831 return;
@@ -804,7 +836,7 @@ static void iwl_test_send_rx(struct iwl_test *tst, struct ieee80211_hw *hw,
804 nla_put(skb, IWL_TM_ATTR_UCODE_RX_PKT, length, data)) 836 nla_put(skb, IWL_TM_ATTR_UCODE_RX_PKT, length, data))
805 goto nla_put_failure; 837 goto nla_put_failure;
806 838
807 cfg80211_testmode_event(skb, GFP_ATOMIC); 839 iwl_test_event(tst, skb);
808 return; 840 return;
809 841
810nla_put_failure: 842nla_put_failure:
@@ -816,10 +848,9 @@ nla_put_failure:
816 * Called whenever a Rx frames is recevied from the device. If notifications to 848 * Called whenever a Rx frames is recevied from the device. If notifications to
817 * the user space are requested, sends the frames to the user. 849 * the user space are requested, sends the frames to the user.
818 */ 850 */
819void iwl_test_rx(struct iwl_test *tst, struct ieee80211_hw *hw, 851void iwl_test_rx(struct iwl_test *tst, struct iwl_rx_cmd_buffer *rxb)
820 struct iwl_rx_cmd_buffer *rxb)
821{ 852{
822 if (tst->notify) 853 if (tst->notify)
823 iwl_test_send_rx(tst, hw, rxb); 854 iwl_test_send_rx(tst, rxb);
824} 855}
825EXPORT_SYMBOL_GPL(iwl_test_rx); 856EXPORT_SYMBOL_GPL(iwl_test_rx);