xref: /freebsd-src/sys/contrib/dev/iwlwifi/mvm/debugfs.h (revision a4128aad8503277614f2d214011ef60a19447b83)
192daf3a6SBjoern A. Zeeb /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
292daf3a6SBjoern A. Zeeb /*
3*a4128aadSBjoern A. Zeeb  * Copyright (C) 2023 Intel Corporation
492daf3a6SBjoern A. Zeeb  * Copyright (C) 2012-2014 Intel Corporation
592daf3a6SBjoern A. Zeeb  * Copyright (C) 2013-2014 Intel Mobile Communications GmbH
692daf3a6SBjoern A. Zeeb  */
792daf3a6SBjoern A. Zeeb #define MVM_DEBUGFS_READ_FILE_OPS(name)					\
892daf3a6SBjoern A. Zeeb static const struct file_operations iwl_dbgfs_##name##_ops = {		\
992daf3a6SBjoern A. Zeeb 	.read = iwl_dbgfs_##name##_read,				\
1092daf3a6SBjoern A. Zeeb 	.open = simple_open,						\
1192daf3a6SBjoern A. Zeeb 	.llseek = generic_file_llseek,					\
1292daf3a6SBjoern A. Zeeb }
1392daf3a6SBjoern A. Zeeb 
1492daf3a6SBjoern A. Zeeb #define MVM_DEBUGFS_WRITE_WRAPPER(name, buflen, argtype)		\
1592daf3a6SBjoern A. Zeeb static ssize_t _iwl_dbgfs_##name##_write(struct file *file,		\
1692daf3a6SBjoern A. Zeeb 					 const char __user *user_buf,	\
1792daf3a6SBjoern A. Zeeb 					 size_t count, loff_t *ppos)	\
1892daf3a6SBjoern A. Zeeb {									\
1992daf3a6SBjoern A. Zeeb 	argtype *arg = file->private_data;				\
2092daf3a6SBjoern A. Zeeb 	char buf[buflen] = {};						\
2192daf3a6SBjoern A. Zeeb 	size_t buf_size = min(count, sizeof(buf) -  1);			\
2292daf3a6SBjoern A. Zeeb 									\
2392daf3a6SBjoern A. Zeeb 	if (copy_from_user(buf, user_buf, buf_size))			\
2492daf3a6SBjoern A. Zeeb 		return -EFAULT;						\
2592daf3a6SBjoern A. Zeeb 									\
2692daf3a6SBjoern A. Zeeb 	return iwl_dbgfs_##name##_write(arg, buf, buf_size, ppos);	\
2792daf3a6SBjoern A. Zeeb }									\
2892daf3a6SBjoern A. Zeeb 
2992daf3a6SBjoern A. Zeeb #define _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, buflen, argtype)		\
3092daf3a6SBjoern A. Zeeb MVM_DEBUGFS_WRITE_WRAPPER(name, buflen, argtype)			\
3192daf3a6SBjoern A. Zeeb static const struct file_operations iwl_dbgfs_##name##_ops = {		\
3292daf3a6SBjoern A. Zeeb 	.write = _iwl_dbgfs_##name##_write,				\
3392daf3a6SBjoern A. Zeeb 	.read = iwl_dbgfs_##name##_read,				\
3492daf3a6SBjoern A. Zeeb 	.open = simple_open,						\
3592daf3a6SBjoern A. Zeeb 	.llseek = generic_file_llseek,					\
3692daf3a6SBjoern A. Zeeb };
3792daf3a6SBjoern A. Zeeb 
3892daf3a6SBjoern A. Zeeb #define _MVM_DEBUGFS_WRITE_FILE_OPS(name, buflen, argtype)		\
3992daf3a6SBjoern A. Zeeb MVM_DEBUGFS_WRITE_WRAPPER(name, buflen, argtype)			\
4092daf3a6SBjoern A. Zeeb static const struct file_operations iwl_dbgfs_##name##_ops = {		\
4192daf3a6SBjoern A. Zeeb 	.write = _iwl_dbgfs_##name##_write,				\
4292daf3a6SBjoern A. Zeeb 	.open = simple_open,						\
4392daf3a6SBjoern A. Zeeb 	.llseek = generic_file_llseek,					\
4492daf3a6SBjoern A. Zeeb };
45