xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /******************************************************************************
2*4882a593Smuzhiyun  *
3*4882a593Smuzhiyun  * This file is provided under a dual BSD/GPLv2 license.  When using or
4*4882a593Smuzhiyun  * redistributing this file, you may do so under either license.
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * GPL LICENSE SUMMARY
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
9*4882a593Smuzhiyun  * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
10*4882a593Smuzhiyun  *
11*4882a593Smuzhiyun  * This program is free software; you can redistribute it and/or modify
12*4882a593Smuzhiyun  * it under the terms of version 2 of the GNU General Public License as
13*4882a593Smuzhiyun  * published by the Free Software Foundation.
14*4882a593Smuzhiyun  *
15*4882a593Smuzhiyun  * This program is distributed in the hope that it will be useful, but
16*4882a593Smuzhiyun  * WITHOUT ANY WARRANTY; without even the implied warranty of
17*4882a593Smuzhiyun  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18*4882a593Smuzhiyun  * General Public License for more details.
19*4882a593Smuzhiyun  *
20*4882a593Smuzhiyun  * The full GNU General Public License is included in this distribution
21*4882a593Smuzhiyun  * in the file called COPYING.
22*4882a593Smuzhiyun  *
23*4882a593Smuzhiyun  * Contact Information:
24*4882a593Smuzhiyun  *  Intel Linux Wireless <linuxwifi@intel.com>
25*4882a593Smuzhiyun  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26*4882a593Smuzhiyun  *
27*4882a593Smuzhiyun  * BSD LICENSE
28*4882a593Smuzhiyun  *
29*4882a593Smuzhiyun  * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
30*4882a593Smuzhiyun  * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
31*4882a593Smuzhiyun  * All rights reserved.
32*4882a593Smuzhiyun  *
33*4882a593Smuzhiyun  * Redistribution and use in source and binary forms, with or without
34*4882a593Smuzhiyun  * modification, are permitted provided that the following conditions
35*4882a593Smuzhiyun  * are met:
36*4882a593Smuzhiyun  *
37*4882a593Smuzhiyun  *  * Redistributions of source code must retain the above copyright
38*4882a593Smuzhiyun  *    notice, this list of conditions and the following disclaimer.
39*4882a593Smuzhiyun  *  * Redistributions in binary form must reproduce the above copyright
40*4882a593Smuzhiyun  *    notice, this list of conditions and the following disclaimer in
41*4882a593Smuzhiyun  *    the documentation and/or other materials provided with the
42*4882a593Smuzhiyun  *    distribution.
43*4882a593Smuzhiyun  *  * Neither the name Intel Corporation nor the names of its
44*4882a593Smuzhiyun  *    contributors may be used to endorse or promote products derived
45*4882a593Smuzhiyun  *    from this software without specific prior written permission.
46*4882a593Smuzhiyun  *
47*4882a593Smuzhiyun  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
48*4882a593Smuzhiyun  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
49*4882a593Smuzhiyun  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
50*4882a593Smuzhiyun  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
51*4882a593Smuzhiyun  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
52*4882a593Smuzhiyun  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
53*4882a593Smuzhiyun  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
54*4882a593Smuzhiyun  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
55*4882a593Smuzhiyun  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
56*4882a593Smuzhiyun  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
57*4882a593Smuzhiyun  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
58*4882a593Smuzhiyun  *
59*4882a593Smuzhiyun  *****************************************************************************/
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun #define MVM_DEBUGFS_READ_FILE_OPS(name)					\
62*4882a593Smuzhiyun static const struct file_operations iwl_dbgfs_##name##_ops = {		\
63*4882a593Smuzhiyun 	.read = iwl_dbgfs_##name##_read,				\
64*4882a593Smuzhiyun 	.open = simple_open,						\
65*4882a593Smuzhiyun 	.llseek = generic_file_llseek,					\
66*4882a593Smuzhiyun }
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun #define MVM_DEBUGFS_WRITE_WRAPPER(name, buflen, argtype)		\
69*4882a593Smuzhiyun static ssize_t _iwl_dbgfs_##name##_write(struct file *file,		\
70*4882a593Smuzhiyun 					 const char __user *user_buf,	\
71*4882a593Smuzhiyun 					 size_t count, loff_t *ppos)	\
72*4882a593Smuzhiyun {									\
73*4882a593Smuzhiyun 	argtype *arg = file->private_data;				\
74*4882a593Smuzhiyun 	char buf[buflen] = {};						\
75*4882a593Smuzhiyun 	size_t buf_size = min(count, sizeof(buf) -  1);			\
76*4882a593Smuzhiyun 									\
77*4882a593Smuzhiyun 	if (copy_from_user(buf, user_buf, buf_size))			\
78*4882a593Smuzhiyun 		return -EFAULT;						\
79*4882a593Smuzhiyun 									\
80*4882a593Smuzhiyun 	return iwl_dbgfs_##name##_write(arg, buf, buf_size, ppos);	\
81*4882a593Smuzhiyun }									\
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun #define _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, buflen, argtype)		\
84*4882a593Smuzhiyun MVM_DEBUGFS_WRITE_WRAPPER(name, buflen, argtype)			\
85*4882a593Smuzhiyun static const struct file_operations iwl_dbgfs_##name##_ops = {		\
86*4882a593Smuzhiyun 	.write = _iwl_dbgfs_##name##_write,				\
87*4882a593Smuzhiyun 	.read = iwl_dbgfs_##name##_read,				\
88*4882a593Smuzhiyun 	.open = simple_open,						\
89*4882a593Smuzhiyun 	.llseek = generic_file_llseek,					\
90*4882a593Smuzhiyun };
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun #define _MVM_DEBUGFS_WRITE_FILE_OPS(name, buflen, argtype)		\
93*4882a593Smuzhiyun MVM_DEBUGFS_WRITE_WRAPPER(name, buflen, argtype)			\
94*4882a593Smuzhiyun static const struct file_operations iwl_dbgfs_##name##_ops = {		\
95*4882a593Smuzhiyun 	.write = _iwl_dbgfs_##name##_write,				\
96*4882a593Smuzhiyun 	.open = simple_open,						\
97*4882a593Smuzhiyun 	.llseek = generic_file_llseek,					\
98*4882a593Smuzhiyun };
99