Merge branch 'drm-next' of git://people.freedesktop.org/~airlied/linux
[cascardo/linux.git] / drivers / net / wireless / iwlwifi / iwl-test.h
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 - 2013 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 COPYING.
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 - 2013 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
64 #ifndef __IWL_TEST_H__
65 #define __IWL_TEST_H__
66
67 #include <linux/types.h>
68 #include "iwl-trans.h"
69
70 struct iwl_test_trace {
71         u32 size;
72         u32 tsize;
73         u32 nchunks;
74         u8 *cpu_addr;
75         u8 *trace_addr;
76         dma_addr_t dma_addr;
77         bool enabled;
78 };
79
80 struct iwl_test_mem {
81         u32 size;
82         u32 nchunks;
83         u8 *addr;
84         bool in_read;
85 };
86
87 /*
88  * struct iwl_test_ops: callback to the op mode
89  *
90  * The structure defines the callbacks that the op_mode should handle,
91  * inorder to handle logic that is out of the scope of iwl_test. The
92  * op_mode must set all the callbacks.
93
94  * @send_cmd: handler that is used by the test object to request the
95  *  op_mode to send a command to the fw.
96  *
97  * @valid_hw_addr: handler that is used by the test object to request the
98  *  op_mode to check if the given address is a valid address.
99  *
100  * @get_fw_ver: handler used to get the FW version.
101  *
102  * @alloc_reply: handler used by the test object to request the op_mode
103  *  to allocate an skb for sending a reply to the user, and initialize
104  *  the skb. It is assumed that the test object only fills the required
105  *  attributes.
106  *
107  * @reply: handler used by the test object to request the op_mode to reply
108  *  to a request. The skb is an skb previously allocated by the the
109  *  alloc_reply callback.
110  I
111  * @alloc_event: handler used by the test object to request the op_mode
112  *  to allocate an skb for sending an event, and initialize
113  *  the skb. It is assumed that the test object only fills the required
114  *  attributes.
115  *
116  * @reply: handler used by the test object to request the op_mode to send
117  *  an event. The skb is an skb previously allocated by the the
118  *  alloc_event callback.
119  */
120 struct iwl_test_ops {
121         int (*send_cmd)(struct iwl_op_mode *op_modes,
122                         struct iwl_host_cmd *cmd);
123         bool (*valid_hw_addr)(u32 addr);
124         u32 (*get_fw_ver)(struct iwl_op_mode *op_mode);
125
126         struct sk_buff *(*alloc_reply)(struct iwl_op_mode *op_mode, int len);
127         int (*reply)(struct iwl_op_mode *op_mode, struct sk_buff *skb);
128         struct sk_buff* (*alloc_event)(struct iwl_op_mode *op_mode, int len);
129         void (*event)(struct iwl_op_mode *op_mode, struct sk_buff *skb);
130 };
131
132 struct iwl_test {
133         struct iwl_trans *trans;
134         struct iwl_test_ops *ops;
135         struct iwl_test_trace trace;
136         struct iwl_test_mem mem;
137         bool notify;
138 };
139
140 void iwl_test_init(struct iwl_test *tst, struct iwl_trans *trans,
141                    struct iwl_test_ops *ops);
142
143 void iwl_test_free(struct iwl_test *tst);
144
145 int iwl_test_parse(struct iwl_test *tst, struct nlattr **tb,
146                    void *data, int len);
147
148 int iwl_test_handle_cmd(struct iwl_test *tst, struct nlattr **tb);
149
150 int iwl_test_dump(struct iwl_test *tst, u32 cmd, struct sk_buff *skb,
151                   struct netlink_callback *cb);
152
153 void iwl_test_rx(struct iwl_test *tst, struct iwl_rx_cmd_buffer *rxb);
154
155 static inline void iwl_test_enable_notifications(struct iwl_test *tst,
156                                                  bool enable)
157 {
158         tst->notify = enable;
159 }
160
161 #endif