Linux Audio

Check our new training course

Loading...
v4.6
 
  1/*
  2 * This file is part of wl1271
  3 *
  4 * Copyright (C) 2009 Nokia Corporation
  5 *
  6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
  7 *
  8 * This program is free software; you can redistribute it and/or
  9 * modify it under the terms of the GNU General Public License
 10 * version 2 as published by the Free Software Foundation.
 11 *
 12 * This program is distributed in the hope that it will be useful, but
 13 * WITHOUT ANY WARRANTY; without even the implied warranty of
 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 15 * General Public License for more details.
 16 *
 17 * You should have received a copy of the GNU General Public License
 18 * along with this program; if not, write to the Free Software
 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 20 * 02110-1301 USA
 21 *
 22 */
 23
 24#ifndef __DEBUGFS_H__
 25#define __DEBUGFS_H__
 26
 27#include "wlcore.h"
 28
 29__printf(4, 5) int wl1271_format_buffer(char __user *userbuf, size_t count,
 30					loff_t *ppos, char *fmt, ...);
 31
 32int wl1271_debugfs_init(struct wl1271 *wl);
 33void wl1271_debugfs_exit(struct wl1271 *wl);
 34void wl1271_debugfs_reset(struct wl1271 *wl);
 35void wl1271_debugfs_update_stats(struct wl1271 *wl);
 36
 37#define DEBUGFS_FORMAT_BUFFER_SIZE 256
 38
 39#define DEBUGFS_READONLY_FILE(name, fmt, value...)			\
 40static ssize_t name## _read(struct file *file, char __user *userbuf,	\
 41			    size_t count, loff_t *ppos)			\
 42{									\
 43	struct wl1271 *wl = file->private_data;				\
 44	return wl1271_format_buffer(userbuf, count, ppos,		\
 45				    fmt "\n", ##value);			\
 46}									\
 47									\
 48static const struct file_operations name## _ops = {			\
 49	.read = name## _read,						\
 50	.open = simple_open,						\
 51	.llseek	= generic_file_llseek,					\
 52};
 53
 54#define DEBUGFS_ADD(name, parent)					\
 55	do {								\
 56		entry = debugfs_create_file(#name, 0400, parent,	\
 57					    wl, &name## _ops);		\
 58		if (!entry || IS_ERR(entry))				\
 59			goto err;					\
 60	} while (0)
 61
 62
 63#define DEBUGFS_ADD_PREFIX(prefix, name, parent)			\
 64	do {								\
 65		entry = debugfs_create_file(#name, 0400, parent,	\
 66				    wl, &prefix## _## name## _ops);	\
 67		if (!entry || IS_ERR(entry))				\
 68			goto err;					\
 69	} while (0)
 70
 71#define DEBUGFS_FWSTATS_FILE(sub, name, fmt, struct_type)		\
 72static ssize_t sub## _ ##name## _read(struct file *file,		\
 73				      char __user *userbuf,		\
 74				      size_t count, loff_t *ppos)	\
 75{									\
 76	struct wl1271 *wl = file->private_data;				\
 77	struct struct_type *stats = wl->stats.fw_stats;			\
 78									\
 79	wl1271_debugfs_update_stats(wl);				\
 80									\
 81	return wl1271_format_buffer(userbuf, count, ppos, fmt "\n",	\
 82				    stats->sub.name);			\
 83}									\
 84									\
 85static const struct file_operations sub## _ ##name## _ops = {		\
 86	.read = sub## _ ##name## _read,					\
 87	.open = simple_open,						\
 88	.llseek	= generic_file_llseek,					\
 89};
 90
 91#define DEBUGFS_FWSTATS_FILE_ARRAY(sub, name, len, struct_type)		\
 92static ssize_t sub## _ ##name## _read(struct file *file,		\
 93				      char __user *userbuf,		\
 94				      size_t count, loff_t *ppos)	\
 95{									\
 96	struct wl1271 *wl = file->private_data;				\
 97	struct struct_type *stats = wl->stats.fw_stats;			\
 98	char buf[DEBUGFS_FORMAT_BUFFER_SIZE] = "";			\
 99	int res, i;							\
 
100									\
101	wl1271_debugfs_update_stats(wl);				\
102									\
103	for (i = 0; i < len; i++)					\
104		res = snprintf(buf, sizeof(buf), "%s[%d] = %d\n",	\
105			       buf, i, stats->sub.name[i]);		\
106									\
107	return wl1271_format_buffer(userbuf, count, ppos, "%s", buf);	\
108}									\
109									\
110static const struct file_operations sub## _ ##name## _ops = {		\
111	.read = sub## _ ##name## _read,					\
112	.open = simple_open,						\
113	.llseek	= generic_file_llseek,					\
114};
115
116#define DEBUGFS_FWSTATS_ADD(sub, name)					\
117	DEBUGFS_ADD(sub## _ ##name, stats)
118
119
120#endif /* WL1271_DEBUGFS_H */
v6.8
  1/* SPDX-License-Identifier: GPL-2.0-only */
  2/*
  3 * This file is part of wl1271
  4 *
  5 * Copyright (C) 2009 Nokia Corporation
  6 *
  7 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  8 */
  9
 10#ifndef __DEBUGFS_H__
 11#define __DEBUGFS_H__
 12
 13#include "wlcore.h"
 14
 15__printf(4, 5) int wl1271_format_buffer(char __user *userbuf, size_t count,
 16					loff_t *ppos, char *fmt, ...);
 17
 18int wl1271_debugfs_init(struct wl1271 *wl);
 19void wl1271_debugfs_exit(struct wl1271 *wl);
 20void wl1271_debugfs_reset(struct wl1271 *wl);
 21void wl1271_debugfs_update_stats(struct wl1271 *wl);
 22
 23#define DEBUGFS_FORMAT_BUFFER_SIZE 256
 24
 25#define DEBUGFS_READONLY_FILE(name, fmt, value...)			\
 26static ssize_t name## _read(struct file *file, char __user *userbuf,	\
 27			    size_t count, loff_t *ppos)			\
 28{									\
 29	struct wl1271 *wl = file->private_data;				\
 30	return wl1271_format_buffer(userbuf, count, ppos,		\
 31				    fmt "\n", ##value);			\
 32}									\
 33									\
 34static const struct file_operations name## _ops = {			\
 35	.read = name## _read,						\
 36	.open = simple_open,						\
 37	.llseek	= generic_file_llseek,					\
 38};
 39
 40#define DEBUGFS_ADD(name, parent)					\
 41	do {								\
 42		debugfs_create_file(#name, 0400, parent,		\
 43				    wl, &name## _ops);			\
 
 
 44	} while (0)
 45
 46
 47#define DEBUGFS_ADD_PREFIX(prefix, name, parent)			\
 48	do {								\
 49		debugfs_create_file(#name, 0400, parent,		\
 50				    wl, &prefix## _## name## _ops);	\
 
 
 51	} while (0)
 52
 53#define DEBUGFS_FWSTATS_FILE(sub, name, fmt, struct_type)		\
 54static ssize_t sub## _ ##name## _read(struct file *file,		\
 55				      char __user *userbuf,		\
 56				      size_t count, loff_t *ppos)	\
 57{									\
 58	struct wl1271 *wl = file->private_data;				\
 59	struct struct_type *stats = wl->stats.fw_stats;			\
 60									\
 61	wl1271_debugfs_update_stats(wl);				\
 62									\
 63	return wl1271_format_buffer(userbuf, count, ppos, fmt "\n",	\
 64				    stats->sub.name);			\
 65}									\
 66									\
 67static const struct file_operations sub## _ ##name## _ops = {		\
 68	.read = sub## _ ##name## _read,					\
 69	.open = simple_open,						\
 70	.llseek	= generic_file_llseek,					\
 71};
 72
 73#define DEBUGFS_FWSTATS_FILE_ARRAY(sub, name, len, struct_type)		\
 74static ssize_t sub## _ ##name## _read(struct file *file,		\
 75				      char __user *userbuf,		\
 76				      size_t count, loff_t *ppos)	\
 77{									\
 78	struct wl1271 *wl = file->private_data;				\
 79	struct struct_type *stats = wl->stats.fw_stats;			\
 80	char buf[DEBUGFS_FORMAT_BUFFER_SIZE] = "";			\
 81	int pos = 0;							\
 82	int i;								\
 83									\
 84	wl1271_debugfs_update_stats(wl);				\
 85									\
 86	for (i = 0; i < len && pos < sizeof(buf); i++)			\
 87		pos += snprintf(buf + pos, sizeof(buf) - pos,		\
 88			 "[%d] = %d\n", i, stats->sub.name[i]);		\
 89									\
 90	return wl1271_format_buffer(userbuf, count, ppos, "%s", buf);	\
 91}									\
 92									\
 93static const struct file_operations sub## _ ##name## _ops = {		\
 94	.read = sub## _ ##name## _read,					\
 95	.open = simple_open,						\
 96	.llseek	= generic_file_llseek,					\
 97};
 98
 99#define DEBUGFS_FWSTATS_ADD(sub, name)					\
100	DEBUGFS_ADD(sub## _ ##name, stats)
101
102
103#endif /* WL1271_DEBUGFS_H */