64 #include <linux/export.h>
80 #define IWL_ABS_PRPH_START (0xA00000)
125 static inline void iwl_test_trace_clear(
struct iwl_test *
tst)
130 static void iwl_test_trace_stop(
struct iwl_test *
tst)
132 if (!tst->
trace.enabled)
135 if (tst->
trace.cpu_addr && tst->
trace.dma_addr)
139 tst->
trace.dma_addr);
141 iwl_test_trace_clear(tst);
144 static inline void iwl_test_mem_clear(
struct iwl_test *tst)
149 static inline void iwl_test_mem_stop(
struct iwl_test *tst)
151 if (!tst->
mem.in_read)
154 iwl_test_mem_clear(tst);
168 iwl_test_trace_clear(tst);
169 iwl_test_mem_clear(tst);
178 iwl_test_mem_stop(tst);
179 iwl_test_trace_stop(tst);
183 static inline int iwl_test_send_cmd(
struct iwl_test *tst,
186 return tst->
ops->send_cmd(tst->
trans->op_mode, cmd);
189 static inline bool iwl_test_valid_hw_addr(
struct iwl_test *tst,
u32 addr)
191 return tst->
ops->valid_hw_addr(addr);
194 static inline u32 iwl_test_fw_ver(
struct iwl_test *tst)
196 return tst->
ops->get_fw_ver(tst->
trans->op_mode);
200 iwl_test_alloc_reply(
struct iwl_test *tst,
int len)
202 return tst->
ops->alloc_reply(tst->
trans->op_mode, len);
207 return tst->
ops->reply(tst->
trans->op_mode, skb);
211 iwl_test_alloc_event(
struct iwl_test *tst,
int len)
213 return tst->
ops->alloc_event(tst->
trans->op_mode, len);
219 return tst->
ops->event(tst->
trans->op_mode, skb);
241 IWL_ERR(tst->
trans,
"Missing fw command mandatory fields\n");
251 cmd.
data[0] = nla_data(tb[IWL_TM_ATTR_UCODE_CMD_DATA]);
252 cmd.
len[0] = nla_len(tb[IWL_TM_ATTR_UCODE_CMD_DATA]);
257 ret = iwl_test_send_cmd(tst, &cmd);
268 IWL_ERR(tst->
trans,
"HCMD received a null response packet\n");
273 skb = iwl_test_alloc_reply(tst, reply_len + 20);
275 if (!skb || !reply_buf) {
282 memcpy(reply_buf, &(pkt->
hdr), reply_len);
288 goto nla_put_failure;
289 return iwl_test_reply(tst, skb);
310 IWL_ERR(trans,
"Missing reg offset\n");
314 ofs = nla_get_u32(tb[IWL_TM_ATTR_REG_OFFSET]);
325 IWL_ERR(trans,
"offset out of segment (0x0 - 0x%x)\n",
335 skb = iwl_test_alloc_reply(tst, 20);
337 IWL_ERR(trans,
"Memory allocation fail\n");
341 goto nla_put_failure;
342 status = iwl_test_reply(tst, skb);
344 IWL_ERR(trans,
"Error sending msg : %d\n", status);
349 IWL_ERR(trans,
"Missing value to write\n");
352 val32 = nla_get_u32(tb[IWL_TM_ATTR_REG_VALUE32]);
360 IWL_ERR(trans,
"Missing value to write\n");
363 val8 = nla_get_u8(tb[IWL_TM_ATTR_REG_VALUE8]);
365 iwl_write8(tst->
trans, ofs, val8);
370 IWL_ERR(trans,
"Unknown test register cmd ID\n");
385 static int iwl_test_trace_begin(
struct iwl_test *tst,
struct nlattr **tb)
390 if (tst->
trace.enabled)
397 nla_get_u32(tb[IWL_TM_ATTR_TRACE_SIZE]);
399 if (!tst->
trace.size)
409 &tst->
trace.dma_addr,
411 if (!tst->
trace.cpu_addr)
414 tst->
trace.enabled =
true;
419 skb = iwl_test_alloc_reply(tst,
sizeof(tst->
trace.dma_addr) + 20);
422 iwl_test_trace_stop(tst);
427 sizeof(tst->
trace.dma_addr),
429 goto nla_put_failure;
431 status = iwl_test_reply(tst, skb);
433 IWL_ERR(tst->
trans,
"Error sending msg : %d\n", status);
444 iwl_test_trace_stop(tst);
473 for (i = 0; i <
size; i += 4)
477 spin_unlock_irqrestore(&trans->
reg_lock, flags);
486 tst->
mem.in_read =
true;
495 static int iwl_test_indirect_write(
struct iwl_test *tst,
u32 addr,
496 u32 size,
unsigned char *
buf)
510 (addr & 0x0000FFFF) |
516 spin_unlock_irqrestore(&trans->
reg_lock, flags);
520 for (i = 0; i <
size; i += 4)
524 }
else if (iwl_test_valid_hw_addr(tst, addr)) {
536 static int iwl_test_indirect_mem(
struct iwl_test *tst,
struct nlattr **tb)
542 if (tst->
mem.in_read)
547 IWL_ERR(tst->
trans,
"Error finding memory offset address\n");
550 addr = nla_get_u32(tb[IWL_TM_ATTR_MEM_ADDR]);
552 IWL_ERR(tst->
trans,
"Error finding size for memory reading\n");
555 size = nla_get_u32(tb[IWL_TM_ATTR_BUFFER_SIZE]);
558 return iwl_test_indirect_read(tst, addr, size);
562 buf = (
unsigned char *)nla_data(tb[IWL_TM_ATTR_BUFFER_DUMP]);
563 return iwl_test_indirect_write(tst, addr, size, buf);
570 static int iwl_test_notifications(
struct iwl_test *tst,
580 static int iwl_test_get_dev_id(
struct iwl_test *tst,
struct nlattr **tb)
588 skb = iwl_test_alloc_reply(tst, 20);
595 goto nla_put_failure;
596 status = iwl_test_reply(tst, skb);
598 IWL_ERR(tst->
trans,
"Error sending msg : %d\n", status);
610 static int iwl_test_get_fw_ver(
struct iwl_test *tst,
struct nlattr **tb)
614 u32 ver = iwl_test_fw_ver(tst);
618 skb = iwl_test_alloc_reply(tst, 20);
625 goto nla_put_failure;
627 status = iwl_test_reply(tst, skb);
629 IWL_ERR(tst->
trans,
"Error sending msg : %d\n", status);
647 iwl_testmode_gnl_msg_policy);
649 IWL_ERR(tst->
trans,
"Fail parse gnl msg: %d\n", result);
674 result = iwl_test_fw_cmd(tst, tb);
681 result = iwl_test_reg(tst, tb);
686 result = iwl_test_trace_begin(tst, tb);
690 iwl_test_trace_stop(tst);
697 result = iwl_test_indirect_mem(tst, tb);
702 result = iwl_test_notifications(tst, tb);
707 result = iwl_test_get_fw_ver(tst, tb);
712 result = iwl_test_get_dev_id(tst, tb);
724 static int iwl_test_trace_dump(
struct iwl_test *tst,
struct sk_buff *skb,
729 if (!tst->
trace.enabled || !tst->
trace.trace_addr)
733 if (idx >= tst->
trace.nchunks)
737 if (((idx + 1) == tst->
trace.nchunks) &&
739 length = tst->
trace.size %
744 goto nla_put_failure;
753 static int iwl_test_buffer_dump(
struct iwl_test *tst,
struct sk_buff *skb,
758 if (!tst->
mem.in_read)
762 if (idx >= tst->
mem.nchunks) {
763 iwl_test_mem_stop(tst);
768 if (((idx + 1) == tst->
mem.nchunks) &&
774 goto nla_put_failure;
796 result = iwl_test_trace_dump(tst, skb, cb);
801 result = iwl_test_buffer_dump(tst, skb, cb);
815 static void iwl_test_send_rx(
struct iwl_test *tst,
828 skb = iwl_test_alloc_event(tst, length + 20);
830 IWL_ERR(tst->
trans,
"Out of memory for message to user\n");
837 goto nla_put_failure;
839 iwl_test_event(tst, skb);
844 IWL_ERR(tst->
trans,
"Ouch, overran buffer, check allocation!\n");
854 iwl_test_send_rx(tst, rxb);