xref: /openbmc/linux/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.h (revision cdd38c5f1ce4398ec58fec95904b75824daab7b5)
1*8e99ea8dSJohannes Berg /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2*8e99ea8dSJohannes Berg /*
3*8e99ea8dSJohannes Berg  * Copyright (C) 2012-2014 Intel Corporation
4*8e99ea8dSJohannes Berg  * Copyright (C) 2013-2014 Intel Mobile Communications GmbH
5*8e99ea8dSJohannes Berg  */
6e705c121SKalle Valo #define MVM_DEBUGFS_READ_FILE_OPS(name)					\
7e705c121SKalle Valo static const struct file_operations iwl_dbgfs_##name##_ops = {		\
8e705c121SKalle Valo 	.read = iwl_dbgfs_##name##_read,				\
9e705c121SKalle Valo 	.open = simple_open,						\
10e705c121SKalle Valo 	.llseek = generic_file_llseek,					\
11e705c121SKalle Valo }
12e705c121SKalle Valo 
13e705c121SKalle Valo #define MVM_DEBUGFS_WRITE_WRAPPER(name, buflen, argtype)		\
14e705c121SKalle Valo static ssize_t _iwl_dbgfs_##name##_write(struct file *file,		\
15e705c121SKalle Valo 					 const char __user *user_buf,	\
16e705c121SKalle Valo 					 size_t count, loff_t *ppos)	\
17e705c121SKalle Valo {									\
18e705c121SKalle Valo 	argtype *arg = file->private_data;				\
19e705c121SKalle Valo 	char buf[buflen] = {};						\
20e705c121SKalle Valo 	size_t buf_size = min(count, sizeof(buf) -  1);			\
21e705c121SKalle Valo 									\
22e705c121SKalle Valo 	if (copy_from_user(buf, user_buf, buf_size))			\
23e705c121SKalle Valo 		return -EFAULT;						\
24e705c121SKalle Valo 									\
25e705c121SKalle Valo 	return iwl_dbgfs_##name##_write(arg, buf, buf_size, ppos);	\
26e705c121SKalle Valo }									\
27e705c121SKalle Valo 
28e705c121SKalle Valo #define _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, buflen, argtype)		\
29e705c121SKalle Valo MVM_DEBUGFS_WRITE_WRAPPER(name, buflen, argtype)			\
30e705c121SKalle Valo static const struct file_operations iwl_dbgfs_##name##_ops = {		\
31e705c121SKalle Valo 	.write = _iwl_dbgfs_##name##_write,				\
32e705c121SKalle Valo 	.read = iwl_dbgfs_##name##_read,				\
33e705c121SKalle Valo 	.open = simple_open,						\
34e705c121SKalle Valo 	.llseek = generic_file_llseek,					\
35e705c121SKalle Valo };
36e705c121SKalle Valo 
37e705c121SKalle Valo #define _MVM_DEBUGFS_WRITE_FILE_OPS(name, buflen, argtype)		\
38e705c121SKalle Valo MVM_DEBUGFS_WRITE_WRAPPER(name, buflen, argtype)			\
39e705c121SKalle Valo static const struct file_operations iwl_dbgfs_##name##_ops = {		\
40e705c121SKalle Valo 	.write = _iwl_dbgfs_##name##_write,				\
41e705c121SKalle Valo 	.open = simple_open,						\
42e705c121SKalle Valo 	.llseek = generic_file_llseek,					\
43e705c121SKalle Valo };
44