2007-09-26 07:57:13 +07:00
|
|
|
/*
|
2009-11-08 22:39:55 +07:00
|
|
|
Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com>
|
2007-09-26 07:57:13 +07:00
|
|
|
<http://rt2x00.serialmonkey.com>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2013-12-06 18:32:11 +07:00
|
|
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2007-09-26 07:57:13 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
Module: rt2x00lib
|
|
|
|
Abstract: rt2x00 debugfs specific routines.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/debugfs.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
2007-11-28 03:49:29 +07:00
|
|
|
#include <linux/poll.h>
|
2009-10-07 20:09:06 +07:00
|
|
|
#include <linux/sched.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2007-09-26 07:57:13 +07:00
|
|
|
#include <linux/uaccess.h>
|
|
|
|
|
|
|
|
#include "rt2x00.h"
|
|
|
|
#include "rt2x00lib.h"
|
2007-11-28 03:49:29 +07:00
|
|
|
#include "rt2x00dump.h"
|
2007-09-26 07:57:13 +07:00
|
|
|
|
2008-02-11 04:50:28 +07:00
|
|
|
#define MAX_LINE_LENGTH 64
|
2007-09-26 07:57:13 +07:00
|
|
|
|
2008-08-04 21:37:44 +07:00
|
|
|
struct rt2x00debug_crypto {
|
|
|
|
unsigned long success;
|
|
|
|
unsigned long icv_error;
|
|
|
|
unsigned long mic_error;
|
|
|
|
unsigned long key_error;
|
|
|
|
};
|
|
|
|
|
2007-09-26 07:57:13 +07:00
|
|
|
struct rt2x00debug_intf {
|
|
|
|
/*
|
|
|
|
* Pointer to driver structure where
|
|
|
|
* this debugfs entry belongs to.
|
|
|
|
*/
|
|
|
|
struct rt2x00_dev *rt2x00dev;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reference to the rt2x00debug structure
|
|
|
|
* which can be used to communicate with
|
|
|
|
* the registers.
|
|
|
|
*/
|
|
|
|
const struct rt2x00debug *debug;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Debugfs entries for:
|
|
|
|
* - driver folder
|
2007-11-28 03:48:16 +07:00
|
|
|
* - driver file
|
|
|
|
* - chipset file
|
2011-04-18 20:27:06 +07:00
|
|
|
* - device state flags file
|
|
|
|
* - device capability flags file
|
2007-11-28 03:48:16 +07:00
|
|
|
* - register folder
|
|
|
|
* - csr offset/value files
|
|
|
|
* - eeprom offset/value files
|
|
|
|
* - bbp offset/value files
|
|
|
|
* - rf offset/value files
|
2012-04-19 20:53:10 +07:00
|
|
|
* - rfcsr offset/value files
|
2008-02-11 04:50:28 +07:00
|
|
|
* - queue folder
|
2007-11-28 03:49:29 +07:00
|
|
|
* - frame dump file
|
2008-02-11 04:50:28 +07:00
|
|
|
* - queue stats file
|
2008-08-04 21:37:44 +07:00
|
|
|
* - crypto stats file
|
2007-09-26 07:57:13 +07:00
|
|
|
*/
|
|
|
|
struct dentry *driver_folder;
|
|
|
|
struct dentry *driver_entry;
|
|
|
|
struct dentry *chipset_entry;
|
2007-09-26 01:13:51 +07:00
|
|
|
struct dentry *dev_flags;
|
2011-04-18 20:27:06 +07:00
|
|
|
struct dentry *cap_flags;
|
2007-11-28 03:48:16 +07:00
|
|
|
struct dentry *register_folder;
|
2007-09-26 07:57:13 +07:00
|
|
|
struct dentry *csr_off_entry;
|
|
|
|
struct dentry *csr_val_entry;
|
|
|
|
struct dentry *eeprom_off_entry;
|
|
|
|
struct dentry *eeprom_val_entry;
|
|
|
|
struct dentry *bbp_off_entry;
|
|
|
|
struct dentry *bbp_val_entry;
|
|
|
|
struct dentry *rf_off_entry;
|
|
|
|
struct dentry *rf_val_entry;
|
2012-04-19 20:53:10 +07:00
|
|
|
struct dentry *rfcsr_off_entry;
|
|
|
|
struct dentry *rfcsr_val_entry;
|
2008-02-11 04:50:28 +07:00
|
|
|
struct dentry *queue_folder;
|
|
|
|
struct dentry *queue_frame_dump_entry;
|
|
|
|
struct dentry *queue_stats_entry;
|
2008-08-04 21:37:44 +07:00
|
|
|
struct dentry *crypto_stats_entry;
|
2007-11-28 03:49:29 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The frame dump file only allows a single reader,
|
|
|
|
* so we need to store the current state here.
|
|
|
|
*/
|
|
|
|
unsigned long frame_dump_flags;
|
|
|
|
#define FRAME_DUMP_FILE_OPEN 1
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We queue each frame before dumping it to the user,
|
|
|
|
* per read command we will pass a single skb structure
|
|
|
|
* so we should be prepared to queue multiple sk buffers
|
|
|
|
* before sending it to userspace.
|
|
|
|
*/
|
|
|
|
struct sk_buff_head frame_dump_skbqueue;
|
|
|
|
wait_queue_head_t frame_dump_waitqueue;
|
2007-09-26 07:57:13 +07:00
|
|
|
|
2008-08-04 21:37:44 +07:00
|
|
|
/*
|
|
|
|
* HW crypto statistics.
|
tree-wide: Assorted spelling fixes
In particular, several occurances of funny versions of 'success',
'unknown', 'therefore', 'acknowledge', 'argument', 'achieve', 'address',
'beginning', 'desirable', 'separate' and 'necessary' are fixed.
Signed-off-by: Daniel Mack <daniel@caiaq.de>
Cc: Joe Perches <joe@perches.com>
Cc: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2010-02-03 07:01:28 +07:00
|
|
|
* All statistics are stored separately per cipher type.
|
2008-08-04 21:37:44 +07:00
|
|
|
*/
|
|
|
|
struct rt2x00debug_crypto crypto_stats[CIPHER_MAX];
|
|
|
|
|
2007-09-26 07:57:13 +07:00
|
|
|
/*
|
|
|
|
* Driver and chipset files will use a data buffer
|
|
|
|
* that has been created in advance. This will simplify
|
|
|
|
* the code since we can use the debugfs functions.
|
|
|
|
*/
|
|
|
|
struct debugfs_blob_wrapper driver_blob;
|
|
|
|
struct debugfs_blob_wrapper chipset_blob;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Requested offset for each register type.
|
|
|
|
*/
|
|
|
|
unsigned int offset_csr;
|
|
|
|
unsigned int offset_eeprom;
|
|
|
|
unsigned int offset_bbp;
|
|
|
|
unsigned int offset_rf;
|
2012-04-19 20:53:10 +07:00
|
|
|
unsigned int offset_rfcsr;
|
2007-09-26 07:57:13 +07:00
|
|
|
};
|
|
|
|
|
2008-08-04 21:37:44 +07:00
|
|
|
void rt2x00debug_update_crypto(struct rt2x00_dev *rt2x00dev,
|
2008-12-20 16:53:29 +07:00
|
|
|
struct rxdone_entry_desc *rxdesc)
|
2008-08-04 21:37:44 +07:00
|
|
|
{
|
|
|
|
struct rt2x00debug_intf *intf = rt2x00dev->debugfs_intf;
|
2008-12-20 16:53:29 +07:00
|
|
|
enum cipher cipher = rxdesc->cipher;
|
|
|
|
enum rx_crypto status = rxdesc->cipher_status;
|
2008-08-04 21:37:44 +07:00
|
|
|
|
|
|
|
if (cipher == CIPHER_TKIP_NO_MIC)
|
|
|
|
cipher = CIPHER_TKIP;
|
2009-05-20 07:12:56 +07:00
|
|
|
if (cipher == CIPHER_NONE || cipher >= CIPHER_MAX)
|
2008-08-04 21:37:44 +07:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Remove CIPHER_NONE index */
|
|
|
|
cipher--;
|
|
|
|
|
|
|
|
intf->crypto_stats[cipher].success += (status == RX_CRYPTO_SUCCESS);
|
|
|
|
intf->crypto_stats[cipher].icv_error += (status == RX_CRYPTO_FAIL_ICV);
|
|
|
|
intf->crypto_stats[cipher].mic_error += (status == RX_CRYPTO_FAIL_MIC);
|
|
|
|
intf->crypto_stats[cipher].key_error += (status == RX_CRYPTO_FAIL_KEY);
|
|
|
|
}
|
|
|
|
|
2007-11-28 03:49:29 +07:00
|
|
|
void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev,
|
2008-05-10 18:41:32 +07:00
|
|
|
enum rt2x00_dump_type type, struct sk_buff *skb)
|
2007-11-28 03:49:29 +07:00
|
|
|
{
|
|
|
|
struct rt2x00debug_intf *intf = rt2x00dev->debugfs_intf;
|
2010-05-12 04:51:37 +07:00
|
|
|
struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
|
2007-11-28 03:49:29 +07:00
|
|
|
struct sk_buff *skbcopy;
|
|
|
|
struct rt2x00dump_hdr *dump_hdr;
|
|
|
|
struct timeval timestamp;
|
2010-05-12 04:51:43 +07:00
|
|
|
u32 data_len;
|
2007-11-28 03:49:29 +07:00
|
|
|
|
2010-11-05 02:38:56 +07:00
|
|
|
if (likely(!test_bit(FRAME_DUMP_FILE_OPEN, &intf->frame_dump_flags)))
|
2007-11-28 03:49:29 +07:00
|
|
|
return;
|
|
|
|
|
2010-11-05 02:38:56 +07:00
|
|
|
do_gettimeofday(×tamp);
|
|
|
|
|
2007-11-28 03:49:29 +07:00
|
|
|
if (skb_queue_len(&intf->frame_dump_skbqueue) > 20) {
|
2013-04-19 22:33:40 +07:00
|
|
|
rt2x00_dbg(rt2x00dev, "txrx dump queue length exceeded\n");
|
2007-11-28 03:49:29 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-05-12 04:51:43 +07:00
|
|
|
data_len = skb->len;
|
|
|
|
if (skbdesc->flags & SKBDESC_DESC_IN_SKB)
|
|
|
|
data_len -= skbdesc->desc_len;
|
|
|
|
|
|
|
|
skbcopy = alloc_skb(sizeof(*dump_hdr) + skbdesc->desc_len + data_len,
|
2007-11-28 03:49:29 +07:00
|
|
|
GFP_ATOMIC);
|
|
|
|
if (!skbcopy) {
|
2013-04-19 22:33:40 +07:00
|
|
|
rt2x00_dbg(rt2x00dev, "Failed to copy skb for dump\n");
|
2007-11-28 03:49:29 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dump_hdr = (struct rt2x00dump_hdr *)skb_put(skbcopy, sizeof(*dump_hdr));
|
|
|
|
dump_hdr->version = cpu_to_le32(DUMP_HEADER_VERSION);
|
|
|
|
dump_hdr->header_length = cpu_to_le32(sizeof(*dump_hdr));
|
2010-05-12 04:51:37 +07:00
|
|
|
dump_hdr->desc_length = cpu_to_le32(skbdesc->desc_len);
|
2010-05-12 04:51:43 +07:00
|
|
|
dump_hdr->data_length = cpu_to_le32(data_len);
|
2007-11-28 03:49:29 +07:00
|
|
|
dump_hdr->chip_rt = cpu_to_le16(rt2x00dev->chip.rt);
|
|
|
|
dump_hdr->chip_rf = cpu_to_le16(rt2x00dev->chip.rf);
|
2010-02-14 02:55:49 +07:00
|
|
|
dump_hdr->chip_rev = cpu_to_le16(rt2x00dev->chip.rev);
|
2008-05-10 18:41:32 +07:00
|
|
|
dump_hdr->type = cpu_to_le16(type);
|
2010-05-12 04:51:37 +07:00
|
|
|
dump_hdr->queue_index = skbdesc->entry->queue->qid;
|
|
|
|
dump_hdr->entry_index = skbdesc->entry->entry_idx;
|
2007-11-28 03:49:29 +07:00
|
|
|
dump_hdr->timestamp_sec = cpu_to_le32(timestamp.tv_sec);
|
|
|
|
dump_hdr->timestamp_usec = cpu_to_le32(timestamp.tv_usec);
|
|
|
|
|
2010-05-12 04:51:43 +07:00
|
|
|
if (!(skbdesc->flags & SKBDESC_DESC_IN_SKB))
|
|
|
|
memcpy(skb_put(skbcopy, skbdesc->desc_len), skbdesc->desc,
|
|
|
|
skbdesc->desc_len);
|
2008-06-07 03:54:08 +07:00
|
|
|
memcpy(skb_put(skbcopy, skb->len), skb->data, skb->len);
|
2007-11-28 03:49:29 +07:00
|
|
|
|
|
|
|
skb_queue_tail(&intf->frame_dump_skbqueue, skbcopy);
|
|
|
|
wake_up_interruptible(&intf->frame_dump_waitqueue);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify that the file has not been closed while we were working.
|
|
|
|
*/
|
|
|
|
if (!test_bit(FRAME_DUMP_FILE_OPEN, &intf->frame_dump_flags))
|
|
|
|
skb_queue_purge(&intf->frame_dump_skbqueue);
|
|
|
|
}
|
2010-05-13 18:16:36 +07:00
|
|
|
EXPORT_SYMBOL_GPL(rt2x00debug_dump_frame);
|
2007-11-28 03:49:29 +07:00
|
|
|
|
2007-09-26 07:57:13 +07:00
|
|
|
static int rt2x00debug_file_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
struct rt2x00debug_intf *intf = inode->i_private;
|
|
|
|
|
|
|
|
file->private_data = inode->i_private;
|
|
|
|
|
|
|
|
if (!try_module_get(intf->debug->owner))
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rt2x00debug_file_release(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
struct rt2x00debug_intf *intf = file->private_data;
|
|
|
|
|
|
|
|
module_put(intf->debug->owner);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-06 04:42:23 +07:00
|
|
|
static int rt2x00debug_open_queue_dump(struct inode *inode, struct file *file)
|
2007-11-28 03:49:29 +07:00
|
|
|
{
|
|
|
|
struct rt2x00debug_intf *intf = inode->i_private;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
retval = rt2x00debug_file_open(inode, file);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
if (test_and_set_bit(FRAME_DUMP_FILE_OPEN, &intf->frame_dump_flags)) {
|
|
|
|
rt2x00debug_file_release(inode, file);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-06 04:42:23 +07:00
|
|
|
static int rt2x00debug_release_queue_dump(struct inode *inode, struct file *file)
|
2007-11-28 03:49:29 +07:00
|
|
|
{
|
|
|
|
struct rt2x00debug_intf *intf = inode->i_private;
|
|
|
|
|
|
|
|
skb_queue_purge(&intf->frame_dump_skbqueue);
|
|
|
|
|
|
|
|
clear_bit(FRAME_DUMP_FILE_OPEN, &intf->frame_dump_flags);
|
|
|
|
|
|
|
|
return rt2x00debug_file_release(inode, file);
|
|
|
|
}
|
|
|
|
|
2008-02-06 04:42:23 +07:00
|
|
|
static ssize_t rt2x00debug_read_queue_dump(struct file *file,
|
|
|
|
char __user *buf,
|
|
|
|
size_t length,
|
|
|
|
loff_t *offset)
|
2007-11-28 03:49:29 +07:00
|
|
|
{
|
|
|
|
struct rt2x00debug_intf *intf = file->private_data;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
size_t status;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
if (file->f_flags & O_NONBLOCK)
|
|
|
|
return -EAGAIN;
|
|
|
|
|
|
|
|
retval =
|
|
|
|
wait_event_interruptible(intf->frame_dump_waitqueue,
|
|
|
|
(skb =
|
|
|
|
skb_dequeue(&intf->frame_dump_skbqueue)));
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
|
2014-02-26 00:12:52 +07:00
|
|
|
status = min_t(size_t, skb->len, length);
|
2007-11-28 03:49:29 +07:00
|
|
|
if (copy_to_user(buf, skb->data, status)) {
|
|
|
|
status = -EFAULT;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
*offset += status;
|
|
|
|
|
|
|
|
exit:
|
|
|
|
kfree_skb(skb);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2008-02-06 04:42:23 +07:00
|
|
|
static unsigned int rt2x00debug_poll_queue_dump(struct file *file,
|
2008-10-18 02:16:17 +07:00
|
|
|
poll_table *wait)
|
2007-11-28 03:49:29 +07:00
|
|
|
{
|
|
|
|
struct rt2x00debug_intf *intf = file->private_data;
|
|
|
|
|
|
|
|
poll_wait(file, &intf->frame_dump_waitqueue, wait);
|
|
|
|
|
|
|
|
if (!skb_queue_empty(&intf->frame_dump_skbqueue))
|
|
|
|
return POLLOUT | POLLWRNORM;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-06 04:42:23 +07:00
|
|
|
static const struct file_operations rt2x00debug_fop_queue_dump = {
|
2007-11-28 03:49:29 +07:00
|
|
|
.owner = THIS_MODULE,
|
2008-02-06 04:42:23 +07:00
|
|
|
.read = rt2x00debug_read_queue_dump,
|
|
|
|
.poll = rt2x00debug_poll_queue_dump,
|
|
|
|
.open = rt2x00debug_open_queue_dump,
|
|
|
|
.release = rt2x00debug_release_queue_dump,
|
llseek: automatically add .llseek fop
All file_operations should get a .llseek operation so we can make
nonseekable_open the default for future file operations without a
.llseek pointer.
The three cases that we can automatically detect are no_llseek, seq_lseek
and default_llseek. For cases where we can we can automatically prove that
the file offset is always ignored, we use noop_llseek, which maintains
the current behavior of not returning an error from a seek.
New drivers should normally not use noop_llseek but instead use no_llseek
and call nonseekable_open at open time. Existing drivers can be converted
to do the same when the maintainer knows for certain that no user code
relies on calling seek on the device file.
The generated code is often incorrectly indented and right now contains
comments that clarify for each added line why a specific variant was
chosen. In the version that gets submitted upstream, the comments will
be gone and I will manually fix the indentation, because there does not
seem to be a way to do that using coccinelle.
Some amount of new code is currently sitting in linux-next that should get
the same modifications, which I will do at the end of the merge window.
Many thanks to Julia Lawall for helping me learn to write a semantic
patch that does all this.
===== begin semantic patch =====
// This adds an llseek= method to all file operations,
// as a preparation for making no_llseek the default.
//
// The rules are
// - use no_llseek explicitly if we do nonseekable_open
// - use seq_lseek for sequential files
// - use default_llseek if we know we access f_pos
// - use noop_llseek if we know we don't access f_pos,
// but we still want to allow users to call lseek
//
@ open1 exists @
identifier nested_open;
@@
nested_open(...)
{
<+...
nonseekable_open(...)
...+>
}
@ open exists@
identifier open_f;
identifier i, f;
identifier open1.nested_open;
@@
int open_f(struct inode *i, struct file *f)
{
<+...
(
nonseekable_open(...)
|
nested_open(...)
)
...+>
}
@ read disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ read_no_fpos disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
... when != off
}
@ write @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ write_no_fpos @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
... when != off
}
@ fops0 @
identifier fops;
@@
struct file_operations fops = {
...
};
@ has_llseek depends on fops0 @
identifier fops0.fops;
identifier llseek_f;
@@
struct file_operations fops = {
...
.llseek = llseek_f,
...
};
@ has_read depends on fops0 @
identifier fops0.fops;
identifier read_f;
@@
struct file_operations fops = {
...
.read = read_f,
...
};
@ has_write depends on fops0 @
identifier fops0.fops;
identifier write_f;
@@
struct file_operations fops = {
...
.write = write_f,
...
};
@ has_open depends on fops0 @
identifier fops0.fops;
identifier open_f;
@@
struct file_operations fops = {
...
.open = open_f,
...
};
// use no_llseek if we call nonseekable_open
////////////////////////////////////////////
@ nonseekable1 depends on !has_llseek && has_open @
identifier fops0.fops;
identifier nso ~= "nonseekable_open";
@@
struct file_operations fops = {
... .open = nso, ...
+.llseek = no_llseek, /* nonseekable */
};
@ nonseekable2 depends on !has_llseek @
identifier fops0.fops;
identifier open.open_f;
@@
struct file_operations fops = {
... .open = open_f, ...
+.llseek = no_llseek, /* open uses nonseekable */
};
// use seq_lseek for sequential files
/////////////////////////////////////
@ seq depends on !has_llseek @
identifier fops0.fops;
identifier sr ~= "seq_read";
@@
struct file_operations fops = {
... .read = sr, ...
+.llseek = seq_lseek, /* we have seq_read */
};
// use default_llseek if there is a readdir
///////////////////////////////////////////
@ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier readdir_e;
@@
// any other fop is used that changes pos
struct file_operations fops = {
... .readdir = readdir_e, ...
+.llseek = default_llseek, /* readdir is present */
};
// use default_llseek if at least one of read/write touches f_pos
/////////////////////////////////////////////////////////////////
@ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read.read_f;
@@
// read fops use offset
struct file_operations fops = {
... .read = read_f, ...
+.llseek = default_llseek, /* read accesses f_pos */
};
@ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write.write_f;
@@
// write fops use offset
struct file_operations fops = {
... .write = write_f, ...
+ .llseek = default_llseek, /* write accesses f_pos */
};
// Use noop_llseek if neither read nor write accesses f_pos
///////////////////////////////////////////////////////////
@ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
identifier write_no_fpos.write_f;
@@
// write fops use offset
struct file_operations fops = {
...
.write = write_f,
.read = read_f,
...
+.llseek = noop_llseek, /* read and write both use no f_pos */
};
@ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write_no_fpos.write_f;
@@
struct file_operations fops = {
... .write = write_f, ...
+.llseek = noop_llseek, /* write uses no f_pos */
};
@ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
@@
struct file_operations fops = {
... .read = read_f, ...
+.llseek = noop_llseek, /* read uses no f_pos */
};
@ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
@@
struct file_operations fops = {
...
+.llseek = noop_llseek, /* no read or write fn */
};
===== End semantic patch =====
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Julia Lawall <julia@diku.dk>
Cc: Christoph Hellwig <hch@infradead.org>
2010-08-15 23:52:59 +07:00
|
|
|
.llseek = default_llseek,
|
2007-11-28 03:49:29 +07:00
|
|
|
};
|
|
|
|
|
2008-02-11 04:50:28 +07:00
|
|
|
static ssize_t rt2x00debug_read_queue_stats(struct file *file,
|
|
|
|
char __user *buf,
|
|
|
|
size_t length,
|
|
|
|
loff_t *offset)
|
|
|
|
{
|
|
|
|
struct rt2x00debug_intf *intf = file->private_data;
|
|
|
|
struct data_queue *queue;
|
2008-03-10 04:44:30 +07:00
|
|
|
unsigned long irqflags;
|
2008-02-11 04:50:28 +07:00
|
|
|
unsigned int lines = 1 + intf->rt2x00dev->data_queues;
|
|
|
|
size_t size;
|
|
|
|
char *data;
|
|
|
|
char *temp;
|
|
|
|
|
|
|
|
if (*offset)
|
|
|
|
return 0;
|
|
|
|
|
2010-08-11 14:02:48 +07:00
|
|
|
data = kcalloc(lines, MAX_LINE_LENGTH, GFP_KERNEL);
|
2008-02-11 04:50:28 +07:00
|
|
|
if (!data)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
temp = data +
|
2010-12-13 18:35:17 +07:00
|
|
|
sprintf(data, "qid\tflags\t\tcount\tlimit\tlength\tindex\tdma done\tdone\n");
|
2008-02-11 04:50:28 +07:00
|
|
|
|
|
|
|
queue_for_each(intf->rt2x00dev, queue) {
|
2010-11-06 21:48:05 +07:00
|
|
|
spin_lock_irqsave(&queue->index_lock, irqflags);
|
2008-02-11 04:50:28 +07:00
|
|
|
|
2010-12-13 18:35:17 +07:00
|
|
|
temp += sprintf(temp, "%d\t0x%.8x\t%d\t%d\t%d\t%d\t%d\t\t%d\n",
|
|
|
|
queue->qid, (unsigned int)queue->flags,
|
2008-02-11 04:50:28 +07:00
|
|
|
queue->count, queue->limit, queue->length,
|
|
|
|
queue->index[Q_INDEX],
|
2010-08-31 02:15:19 +07:00
|
|
|
queue->index[Q_INDEX_DMA_DONE],
|
2010-08-24 00:54:41 +07:00
|
|
|
queue->index[Q_INDEX_DONE]);
|
2008-02-11 04:50:28 +07:00
|
|
|
|
2010-11-06 21:48:05 +07:00
|
|
|
spin_unlock_irqrestore(&queue->index_lock, irqflags);
|
2008-02-11 04:50:28 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
size = strlen(data);
|
|
|
|
size = min(size, length);
|
|
|
|
|
|
|
|
if (copy_to_user(buf, data, size)) {
|
|
|
|
kfree(data);
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
kfree(data);
|
|
|
|
|
|
|
|
*offset += size;
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations rt2x00debug_fop_queue_stats = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.read = rt2x00debug_read_queue_stats,
|
|
|
|
.open = rt2x00debug_file_open,
|
|
|
|
.release = rt2x00debug_file_release,
|
llseek: automatically add .llseek fop
All file_operations should get a .llseek operation so we can make
nonseekable_open the default for future file operations without a
.llseek pointer.
The three cases that we can automatically detect are no_llseek, seq_lseek
and default_llseek. For cases where we can we can automatically prove that
the file offset is always ignored, we use noop_llseek, which maintains
the current behavior of not returning an error from a seek.
New drivers should normally not use noop_llseek but instead use no_llseek
and call nonseekable_open at open time. Existing drivers can be converted
to do the same when the maintainer knows for certain that no user code
relies on calling seek on the device file.
The generated code is often incorrectly indented and right now contains
comments that clarify for each added line why a specific variant was
chosen. In the version that gets submitted upstream, the comments will
be gone and I will manually fix the indentation, because there does not
seem to be a way to do that using coccinelle.
Some amount of new code is currently sitting in linux-next that should get
the same modifications, which I will do at the end of the merge window.
Many thanks to Julia Lawall for helping me learn to write a semantic
patch that does all this.
===== begin semantic patch =====
// This adds an llseek= method to all file operations,
// as a preparation for making no_llseek the default.
//
// The rules are
// - use no_llseek explicitly if we do nonseekable_open
// - use seq_lseek for sequential files
// - use default_llseek if we know we access f_pos
// - use noop_llseek if we know we don't access f_pos,
// but we still want to allow users to call lseek
//
@ open1 exists @
identifier nested_open;
@@
nested_open(...)
{
<+...
nonseekable_open(...)
...+>
}
@ open exists@
identifier open_f;
identifier i, f;
identifier open1.nested_open;
@@
int open_f(struct inode *i, struct file *f)
{
<+...
(
nonseekable_open(...)
|
nested_open(...)
)
...+>
}
@ read disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ read_no_fpos disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
... when != off
}
@ write @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ write_no_fpos @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
... when != off
}
@ fops0 @
identifier fops;
@@
struct file_operations fops = {
...
};
@ has_llseek depends on fops0 @
identifier fops0.fops;
identifier llseek_f;
@@
struct file_operations fops = {
...
.llseek = llseek_f,
...
};
@ has_read depends on fops0 @
identifier fops0.fops;
identifier read_f;
@@
struct file_operations fops = {
...
.read = read_f,
...
};
@ has_write depends on fops0 @
identifier fops0.fops;
identifier write_f;
@@
struct file_operations fops = {
...
.write = write_f,
...
};
@ has_open depends on fops0 @
identifier fops0.fops;
identifier open_f;
@@
struct file_operations fops = {
...
.open = open_f,
...
};
// use no_llseek if we call nonseekable_open
////////////////////////////////////////////
@ nonseekable1 depends on !has_llseek && has_open @
identifier fops0.fops;
identifier nso ~= "nonseekable_open";
@@
struct file_operations fops = {
... .open = nso, ...
+.llseek = no_llseek, /* nonseekable */
};
@ nonseekable2 depends on !has_llseek @
identifier fops0.fops;
identifier open.open_f;
@@
struct file_operations fops = {
... .open = open_f, ...
+.llseek = no_llseek, /* open uses nonseekable */
};
// use seq_lseek for sequential files
/////////////////////////////////////
@ seq depends on !has_llseek @
identifier fops0.fops;
identifier sr ~= "seq_read";
@@
struct file_operations fops = {
... .read = sr, ...
+.llseek = seq_lseek, /* we have seq_read */
};
// use default_llseek if there is a readdir
///////////////////////////////////////////
@ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier readdir_e;
@@
// any other fop is used that changes pos
struct file_operations fops = {
... .readdir = readdir_e, ...
+.llseek = default_llseek, /* readdir is present */
};
// use default_llseek if at least one of read/write touches f_pos
/////////////////////////////////////////////////////////////////
@ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read.read_f;
@@
// read fops use offset
struct file_operations fops = {
... .read = read_f, ...
+.llseek = default_llseek, /* read accesses f_pos */
};
@ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write.write_f;
@@
// write fops use offset
struct file_operations fops = {
... .write = write_f, ...
+ .llseek = default_llseek, /* write accesses f_pos */
};
// Use noop_llseek if neither read nor write accesses f_pos
///////////////////////////////////////////////////////////
@ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
identifier write_no_fpos.write_f;
@@
// write fops use offset
struct file_operations fops = {
...
.write = write_f,
.read = read_f,
...
+.llseek = noop_llseek, /* read and write both use no f_pos */
};
@ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write_no_fpos.write_f;
@@
struct file_operations fops = {
... .write = write_f, ...
+.llseek = noop_llseek, /* write uses no f_pos */
};
@ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
@@
struct file_operations fops = {
... .read = read_f, ...
+.llseek = noop_llseek, /* read uses no f_pos */
};
@ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
@@
struct file_operations fops = {
...
+.llseek = noop_llseek, /* no read or write fn */
};
===== End semantic patch =====
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Julia Lawall <julia@diku.dk>
Cc: Christoph Hellwig <hch@infradead.org>
2010-08-15 23:52:59 +07:00
|
|
|
.llseek = default_llseek,
|
2008-02-11 04:50:28 +07:00
|
|
|
};
|
|
|
|
|
2008-08-04 21:37:44 +07:00
|
|
|
#ifdef CONFIG_RT2X00_LIB_CRYPTO
|
|
|
|
static ssize_t rt2x00debug_read_crypto_stats(struct file *file,
|
|
|
|
char __user *buf,
|
|
|
|
size_t length,
|
|
|
|
loff_t *offset)
|
|
|
|
{
|
|
|
|
struct rt2x00debug_intf *intf = file->private_data;
|
2010-09-14 01:23:55 +07:00
|
|
|
static const char * const name[] = { "WEP64", "WEP128", "TKIP", "AES" };
|
2008-08-04 21:37:44 +07:00
|
|
|
char *data;
|
|
|
|
char *temp;
|
|
|
|
size_t size;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (*offset)
|
|
|
|
return 0;
|
|
|
|
|
2008-10-18 02:16:17 +07:00
|
|
|
data = kzalloc((1 + CIPHER_MAX) * MAX_LINE_LENGTH, GFP_KERNEL);
|
2008-08-04 21:37:44 +07:00
|
|
|
if (!data)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
temp = data;
|
|
|
|
temp += sprintf(data, "cipher\tsuccess\ticv err\tmic err\tkey err\n");
|
|
|
|
|
|
|
|
for (i = 0; i < CIPHER_MAX; i++) {
|
|
|
|
temp += sprintf(temp, "%s\t%lu\t%lu\t%lu\t%lu\n", name[i],
|
|
|
|
intf->crypto_stats[i].success,
|
|
|
|
intf->crypto_stats[i].icv_error,
|
|
|
|
intf->crypto_stats[i].mic_error,
|
|
|
|
intf->crypto_stats[i].key_error);
|
|
|
|
}
|
|
|
|
|
|
|
|
size = strlen(data);
|
|
|
|
size = min(size, length);
|
|
|
|
|
|
|
|
if (copy_to_user(buf, data, size)) {
|
|
|
|
kfree(data);
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
kfree(data);
|
|
|
|
|
|
|
|
*offset += size;
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations rt2x00debug_fop_crypto_stats = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.read = rt2x00debug_read_crypto_stats,
|
|
|
|
.open = rt2x00debug_file_open,
|
|
|
|
.release = rt2x00debug_file_release,
|
llseek: automatically add .llseek fop
All file_operations should get a .llseek operation so we can make
nonseekable_open the default for future file operations without a
.llseek pointer.
The three cases that we can automatically detect are no_llseek, seq_lseek
and default_llseek. For cases where we can we can automatically prove that
the file offset is always ignored, we use noop_llseek, which maintains
the current behavior of not returning an error from a seek.
New drivers should normally not use noop_llseek but instead use no_llseek
and call nonseekable_open at open time. Existing drivers can be converted
to do the same when the maintainer knows for certain that no user code
relies on calling seek on the device file.
The generated code is often incorrectly indented and right now contains
comments that clarify for each added line why a specific variant was
chosen. In the version that gets submitted upstream, the comments will
be gone and I will manually fix the indentation, because there does not
seem to be a way to do that using coccinelle.
Some amount of new code is currently sitting in linux-next that should get
the same modifications, which I will do at the end of the merge window.
Many thanks to Julia Lawall for helping me learn to write a semantic
patch that does all this.
===== begin semantic patch =====
// This adds an llseek= method to all file operations,
// as a preparation for making no_llseek the default.
//
// The rules are
// - use no_llseek explicitly if we do nonseekable_open
// - use seq_lseek for sequential files
// - use default_llseek if we know we access f_pos
// - use noop_llseek if we know we don't access f_pos,
// but we still want to allow users to call lseek
//
@ open1 exists @
identifier nested_open;
@@
nested_open(...)
{
<+...
nonseekable_open(...)
...+>
}
@ open exists@
identifier open_f;
identifier i, f;
identifier open1.nested_open;
@@
int open_f(struct inode *i, struct file *f)
{
<+...
(
nonseekable_open(...)
|
nested_open(...)
)
...+>
}
@ read disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ read_no_fpos disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
... when != off
}
@ write @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ write_no_fpos @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
... when != off
}
@ fops0 @
identifier fops;
@@
struct file_operations fops = {
...
};
@ has_llseek depends on fops0 @
identifier fops0.fops;
identifier llseek_f;
@@
struct file_operations fops = {
...
.llseek = llseek_f,
...
};
@ has_read depends on fops0 @
identifier fops0.fops;
identifier read_f;
@@
struct file_operations fops = {
...
.read = read_f,
...
};
@ has_write depends on fops0 @
identifier fops0.fops;
identifier write_f;
@@
struct file_operations fops = {
...
.write = write_f,
...
};
@ has_open depends on fops0 @
identifier fops0.fops;
identifier open_f;
@@
struct file_operations fops = {
...
.open = open_f,
...
};
// use no_llseek if we call nonseekable_open
////////////////////////////////////////////
@ nonseekable1 depends on !has_llseek && has_open @
identifier fops0.fops;
identifier nso ~= "nonseekable_open";
@@
struct file_operations fops = {
... .open = nso, ...
+.llseek = no_llseek, /* nonseekable */
};
@ nonseekable2 depends on !has_llseek @
identifier fops0.fops;
identifier open.open_f;
@@
struct file_operations fops = {
... .open = open_f, ...
+.llseek = no_llseek, /* open uses nonseekable */
};
// use seq_lseek for sequential files
/////////////////////////////////////
@ seq depends on !has_llseek @
identifier fops0.fops;
identifier sr ~= "seq_read";
@@
struct file_operations fops = {
... .read = sr, ...
+.llseek = seq_lseek, /* we have seq_read */
};
// use default_llseek if there is a readdir
///////////////////////////////////////////
@ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier readdir_e;
@@
// any other fop is used that changes pos
struct file_operations fops = {
... .readdir = readdir_e, ...
+.llseek = default_llseek, /* readdir is present */
};
// use default_llseek if at least one of read/write touches f_pos
/////////////////////////////////////////////////////////////////
@ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read.read_f;
@@
// read fops use offset
struct file_operations fops = {
... .read = read_f, ...
+.llseek = default_llseek, /* read accesses f_pos */
};
@ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write.write_f;
@@
// write fops use offset
struct file_operations fops = {
... .write = write_f, ...
+ .llseek = default_llseek, /* write accesses f_pos */
};
// Use noop_llseek if neither read nor write accesses f_pos
///////////////////////////////////////////////////////////
@ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
identifier write_no_fpos.write_f;
@@
// write fops use offset
struct file_operations fops = {
...
.write = write_f,
.read = read_f,
...
+.llseek = noop_llseek, /* read and write both use no f_pos */
};
@ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write_no_fpos.write_f;
@@
struct file_operations fops = {
... .write = write_f, ...
+.llseek = noop_llseek, /* write uses no f_pos */
};
@ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
@@
struct file_operations fops = {
... .read = read_f, ...
+.llseek = noop_llseek, /* read uses no f_pos */
};
@ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
@@
struct file_operations fops = {
...
+.llseek = noop_llseek, /* no read or write fn */
};
===== End semantic patch =====
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Julia Lawall <julia@diku.dk>
Cc: Christoph Hellwig <hch@infradead.org>
2010-08-15 23:52:59 +07:00
|
|
|
.llseek = default_llseek,
|
2008-08-04 21:37:44 +07:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2007-09-26 07:57:13 +07:00
|
|
|
#define RT2X00DEBUGFS_OPS_READ(__name, __format, __type) \
|
|
|
|
static ssize_t rt2x00debug_read_##__name(struct file *file, \
|
|
|
|
char __user *buf, \
|
|
|
|
size_t length, \
|
|
|
|
loff_t *offset) \
|
|
|
|
{ \
|
2007-11-28 03:48:16 +07:00
|
|
|
struct rt2x00debug_intf *intf = file->private_data; \
|
2007-09-26 07:57:13 +07:00
|
|
|
const struct rt2x00debug *debug = intf->debug; \
|
|
|
|
char line[16]; \
|
|
|
|
size_t size; \
|
2008-10-30 01:41:03 +07:00
|
|
|
unsigned int index = intf->offset_##__name; \
|
2007-09-26 07:57:13 +07:00
|
|
|
__type value; \
|
|
|
|
\
|
|
|
|
if (*offset) \
|
|
|
|
return 0; \
|
|
|
|
\
|
2008-10-30 01:41:03 +07:00
|
|
|
if (index >= debug->__name.word_count) \
|
2007-09-26 07:57:13 +07:00
|
|
|
return -EINVAL; \
|
|
|
|
\
|
2009-02-17 20:04:29 +07:00
|
|
|
index += (debug->__name.word_base / \
|
|
|
|
debug->__name.word_size); \
|
|
|
|
\
|
2008-10-30 01:41:03 +07:00
|
|
|
if (debug->__name.flags & RT2X00DEBUGFS_OFFSET) \
|
|
|
|
index *= debug->__name.word_size; \
|
|
|
|
\
|
|
|
|
debug->__name.read(intf->rt2x00dev, index, &value); \
|
2007-09-26 07:57:13 +07:00
|
|
|
\
|
|
|
|
size = sprintf(line, __format, value); \
|
|
|
|
\
|
|
|
|
if (copy_to_user(buf, line, size)) \
|
|
|
|
return -EFAULT; \
|
|
|
|
\
|
|
|
|
*offset += size; \
|
|
|
|
return size; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define RT2X00DEBUGFS_OPS_WRITE(__name, __type) \
|
|
|
|
static ssize_t rt2x00debug_write_##__name(struct file *file, \
|
|
|
|
const char __user *buf,\
|
|
|
|
size_t length, \
|
|
|
|
loff_t *offset) \
|
|
|
|
{ \
|
2007-11-28 03:48:16 +07:00
|
|
|
struct rt2x00debug_intf *intf = file->private_data; \
|
2007-09-26 07:57:13 +07:00
|
|
|
const struct rt2x00debug *debug = intf->debug; \
|
|
|
|
char line[16]; \
|
|
|
|
size_t size; \
|
2008-10-30 01:41:03 +07:00
|
|
|
unsigned int index = intf->offset_##__name; \
|
2007-09-26 07:57:13 +07:00
|
|
|
__type value; \
|
|
|
|
\
|
|
|
|
if (*offset) \
|
|
|
|
return 0; \
|
|
|
|
\
|
2008-10-30 01:41:03 +07:00
|
|
|
if (index >= debug->__name.word_count) \
|
2007-09-26 07:57:13 +07:00
|
|
|
return -EINVAL; \
|
|
|
|
\
|
2010-08-24 04:02:22 +07:00
|
|
|
if (length > sizeof(line)) \
|
|
|
|
return -EINVAL; \
|
|
|
|
\
|
2007-09-26 07:57:13 +07:00
|
|
|
if (copy_from_user(line, buf, length)) \
|
|
|
|
return -EFAULT; \
|
|
|
|
\
|
|
|
|
size = strlen(line); \
|
|
|
|
value = simple_strtoul(line, NULL, 0); \
|
|
|
|
\
|
2009-02-17 20:04:29 +07:00
|
|
|
index += (debug->__name.word_base / \
|
|
|
|
debug->__name.word_size); \
|
|
|
|
\
|
2008-10-30 01:41:03 +07:00
|
|
|
if (debug->__name.flags & RT2X00DEBUGFS_OFFSET) \
|
|
|
|
index *= debug->__name.word_size; \
|
|
|
|
\
|
|
|
|
debug->__name.write(intf->rt2x00dev, index, value); \
|
2007-09-26 07:57:13 +07:00
|
|
|
\
|
|
|
|
*offset += size; \
|
|
|
|
return size; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define RT2X00DEBUGFS_OPS(__name, __format, __type) \
|
|
|
|
RT2X00DEBUGFS_OPS_READ(__name, __format, __type); \
|
|
|
|
RT2X00DEBUGFS_OPS_WRITE(__name, __type); \
|
|
|
|
\
|
|
|
|
static const struct file_operations rt2x00debug_fop_##__name = {\
|
|
|
|
.owner = THIS_MODULE, \
|
|
|
|
.read = rt2x00debug_read_##__name, \
|
|
|
|
.write = rt2x00debug_write_##__name, \
|
|
|
|
.open = rt2x00debug_file_open, \
|
|
|
|
.release = rt2x00debug_file_release, \
|
2010-07-07 00:05:31 +07:00
|
|
|
.llseek = generic_file_llseek, \
|
2007-09-26 07:57:13 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
RT2X00DEBUGFS_OPS(csr, "0x%.8x\n", u32);
|
|
|
|
RT2X00DEBUGFS_OPS(eeprom, "0x%.4x\n", u16);
|
|
|
|
RT2X00DEBUGFS_OPS(bbp, "0x%.2x\n", u8);
|
|
|
|
RT2X00DEBUGFS_OPS(rf, "0x%.8x\n", u32);
|
2012-04-19 20:53:10 +07:00
|
|
|
RT2X00DEBUGFS_OPS(rfcsr, "0x%.2x\n", u8);
|
2007-09-26 07:57:13 +07:00
|
|
|
|
2007-09-26 01:13:51 +07:00
|
|
|
static ssize_t rt2x00debug_read_dev_flags(struct file *file,
|
|
|
|
char __user *buf,
|
|
|
|
size_t length,
|
|
|
|
loff_t *offset)
|
|
|
|
{
|
|
|
|
struct rt2x00debug_intf *intf = file->private_data;
|
|
|
|
char line[16];
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
if (*offset)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
size = sprintf(line, "0x%.8x\n", (unsigned int)intf->rt2x00dev->flags);
|
|
|
|
|
|
|
|
if (copy_to_user(buf, line, size))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
*offset += size;
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations rt2x00debug_fop_dev_flags = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.read = rt2x00debug_read_dev_flags,
|
|
|
|
.open = rt2x00debug_file_open,
|
|
|
|
.release = rt2x00debug_file_release,
|
llseek: automatically add .llseek fop
All file_operations should get a .llseek operation so we can make
nonseekable_open the default for future file operations without a
.llseek pointer.
The three cases that we can automatically detect are no_llseek, seq_lseek
and default_llseek. For cases where we can we can automatically prove that
the file offset is always ignored, we use noop_llseek, which maintains
the current behavior of not returning an error from a seek.
New drivers should normally not use noop_llseek but instead use no_llseek
and call nonseekable_open at open time. Existing drivers can be converted
to do the same when the maintainer knows for certain that no user code
relies on calling seek on the device file.
The generated code is often incorrectly indented and right now contains
comments that clarify for each added line why a specific variant was
chosen. In the version that gets submitted upstream, the comments will
be gone and I will manually fix the indentation, because there does not
seem to be a way to do that using coccinelle.
Some amount of new code is currently sitting in linux-next that should get
the same modifications, which I will do at the end of the merge window.
Many thanks to Julia Lawall for helping me learn to write a semantic
patch that does all this.
===== begin semantic patch =====
// This adds an llseek= method to all file operations,
// as a preparation for making no_llseek the default.
//
// The rules are
// - use no_llseek explicitly if we do nonseekable_open
// - use seq_lseek for sequential files
// - use default_llseek if we know we access f_pos
// - use noop_llseek if we know we don't access f_pos,
// but we still want to allow users to call lseek
//
@ open1 exists @
identifier nested_open;
@@
nested_open(...)
{
<+...
nonseekable_open(...)
...+>
}
@ open exists@
identifier open_f;
identifier i, f;
identifier open1.nested_open;
@@
int open_f(struct inode *i, struct file *f)
{
<+...
(
nonseekable_open(...)
|
nested_open(...)
)
...+>
}
@ read disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ read_no_fpos disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
... when != off
}
@ write @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ write_no_fpos @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
... when != off
}
@ fops0 @
identifier fops;
@@
struct file_operations fops = {
...
};
@ has_llseek depends on fops0 @
identifier fops0.fops;
identifier llseek_f;
@@
struct file_operations fops = {
...
.llseek = llseek_f,
...
};
@ has_read depends on fops0 @
identifier fops0.fops;
identifier read_f;
@@
struct file_operations fops = {
...
.read = read_f,
...
};
@ has_write depends on fops0 @
identifier fops0.fops;
identifier write_f;
@@
struct file_operations fops = {
...
.write = write_f,
...
};
@ has_open depends on fops0 @
identifier fops0.fops;
identifier open_f;
@@
struct file_operations fops = {
...
.open = open_f,
...
};
// use no_llseek if we call nonseekable_open
////////////////////////////////////////////
@ nonseekable1 depends on !has_llseek && has_open @
identifier fops0.fops;
identifier nso ~= "nonseekable_open";
@@
struct file_operations fops = {
... .open = nso, ...
+.llseek = no_llseek, /* nonseekable */
};
@ nonseekable2 depends on !has_llseek @
identifier fops0.fops;
identifier open.open_f;
@@
struct file_operations fops = {
... .open = open_f, ...
+.llseek = no_llseek, /* open uses nonseekable */
};
// use seq_lseek for sequential files
/////////////////////////////////////
@ seq depends on !has_llseek @
identifier fops0.fops;
identifier sr ~= "seq_read";
@@
struct file_operations fops = {
... .read = sr, ...
+.llseek = seq_lseek, /* we have seq_read */
};
// use default_llseek if there is a readdir
///////////////////////////////////////////
@ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier readdir_e;
@@
// any other fop is used that changes pos
struct file_operations fops = {
... .readdir = readdir_e, ...
+.llseek = default_llseek, /* readdir is present */
};
// use default_llseek if at least one of read/write touches f_pos
/////////////////////////////////////////////////////////////////
@ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read.read_f;
@@
// read fops use offset
struct file_operations fops = {
... .read = read_f, ...
+.llseek = default_llseek, /* read accesses f_pos */
};
@ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write.write_f;
@@
// write fops use offset
struct file_operations fops = {
... .write = write_f, ...
+ .llseek = default_llseek, /* write accesses f_pos */
};
// Use noop_llseek if neither read nor write accesses f_pos
///////////////////////////////////////////////////////////
@ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
identifier write_no_fpos.write_f;
@@
// write fops use offset
struct file_operations fops = {
...
.write = write_f,
.read = read_f,
...
+.llseek = noop_llseek, /* read and write both use no f_pos */
};
@ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write_no_fpos.write_f;
@@
struct file_operations fops = {
... .write = write_f, ...
+.llseek = noop_llseek, /* write uses no f_pos */
};
@ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
@@
struct file_operations fops = {
... .read = read_f, ...
+.llseek = noop_llseek, /* read uses no f_pos */
};
@ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
@@
struct file_operations fops = {
...
+.llseek = noop_llseek, /* no read or write fn */
};
===== End semantic patch =====
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Julia Lawall <julia@diku.dk>
Cc: Christoph Hellwig <hch@infradead.org>
2010-08-15 23:52:59 +07:00
|
|
|
.llseek = default_llseek,
|
2007-09-26 01:13:51 +07:00
|
|
|
};
|
|
|
|
|
2011-04-18 20:27:06 +07:00
|
|
|
static ssize_t rt2x00debug_read_cap_flags(struct file *file,
|
|
|
|
char __user *buf,
|
|
|
|
size_t length,
|
|
|
|
loff_t *offset)
|
|
|
|
{
|
|
|
|
struct rt2x00debug_intf *intf = file->private_data;
|
|
|
|
char line[16];
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
if (*offset)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
size = sprintf(line, "0x%.8x\n", (unsigned int)intf->rt2x00dev->cap_flags);
|
|
|
|
|
|
|
|
if (copy_to_user(buf, line, size))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
*offset += size;
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations rt2x00debug_fop_cap_flags = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.read = rt2x00debug_read_cap_flags,
|
|
|
|
.open = rt2x00debug_file_open,
|
|
|
|
.release = rt2x00debug_file_release,
|
|
|
|
.llseek = default_llseek,
|
|
|
|
};
|
|
|
|
|
2007-09-26 07:57:13 +07:00
|
|
|
static struct dentry *rt2x00debug_create_file_driver(const char *name,
|
|
|
|
struct rt2x00debug_intf
|
|
|
|
*intf,
|
|
|
|
struct debugfs_blob_wrapper
|
|
|
|
*blob)
|
|
|
|
{
|
|
|
|
char *data;
|
|
|
|
|
2008-02-11 04:50:28 +07:00
|
|
|
data = kzalloc(3 * MAX_LINE_LENGTH, GFP_KERNEL);
|
2007-09-26 07:57:13 +07:00
|
|
|
if (!data)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
blob->data = data;
|
2009-03-04 00:14:18 +07:00
|
|
|
data += sprintf(data, "driver:\t%s\n", intf->rt2x00dev->ops->name);
|
|
|
|
data += sprintf(data, "version:\t%s\n", DRV_VERSION);
|
2007-09-26 07:57:13 +07:00
|
|
|
blob->size = strlen(blob->data);
|
|
|
|
|
2008-07-27 20:06:05 +07:00
|
|
|
return debugfs_create_blob(name, S_IRUSR, intf->driver_folder, blob);
|
2007-09-26 07:57:13 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct dentry *rt2x00debug_create_file_chipset(const char *name,
|
|
|
|
struct rt2x00debug_intf
|
|
|
|
*intf,
|
|
|
|
struct
|
|
|
|
debugfs_blob_wrapper
|
|
|
|
*blob)
|
|
|
|
{
|
|
|
|
const struct rt2x00debug *debug = intf->debug;
|
|
|
|
char *data;
|
|
|
|
|
2012-04-19 20:53:10 +07:00
|
|
|
data = kzalloc(9 * MAX_LINE_LENGTH, GFP_KERNEL);
|
2007-09-26 07:57:13 +07:00
|
|
|
if (!data)
|
|
|
|
return NULL;
|
|
|
|
|
2008-01-07 05:38:10 +07:00
|
|
|
blob->data = data;
|
2009-03-04 00:14:18 +07:00
|
|
|
data += sprintf(data, "rt chip:\t%04x\n", intf->rt2x00dev->chip.rt);
|
|
|
|
data += sprintf(data, "rf chip:\t%04x\n", intf->rt2x00dev->chip.rf);
|
2010-02-14 02:55:49 +07:00
|
|
|
data += sprintf(data, "revision:\t%04x\n", intf->rt2x00dev->chip.rev);
|
2007-11-28 03:48:37 +07:00
|
|
|
data += sprintf(data, "\n");
|
2009-03-04 00:14:18 +07:00
|
|
|
data += sprintf(data, "register\tbase\twords\twordsize\n");
|
2012-04-19 20:04:52 +07:00
|
|
|
#define RT2X00DEBUGFS_SPRINTF_REGISTER(__name) \
|
|
|
|
{ \
|
|
|
|
if(debug->__name.read) \
|
|
|
|
data += sprintf(data, __stringify(__name) \
|
|
|
|
"\t%d\t%d\t%d\n", \
|
|
|
|
debug->__name.word_base, \
|
|
|
|
debug->__name.word_count, \
|
|
|
|
debug->__name.word_size); \
|
|
|
|
}
|
|
|
|
RT2X00DEBUGFS_SPRINTF_REGISTER(csr);
|
|
|
|
RT2X00DEBUGFS_SPRINTF_REGISTER(eeprom);
|
|
|
|
RT2X00DEBUGFS_SPRINTF_REGISTER(bbp);
|
|
|
|
RT2X00DEBUGFS_SPRINTF_REGISTER(rf);
|
2012-04-19 20:53:10 +07:00
|
|
|
RT2X00DEBUGFS_SPRINTF_REGISTER(rfcsr);
|
2012-04-19 20:04:52 +07:00
|
|
|
#undef RT2X00DEBUGFS_SPRINTF_REGISTER
|
|
|
|
|
2008-01-07 05:38:10 +07:00
|
|
|
blob->size = strlen(blob->data);
|
2007-09-26 07:57:13 +07:00
|
|
|
|
2008-07-27 20:06:05 +07:00
|
|
|
return debugfs_create_blob(name, S_IRUSR, intf->driver_folder, blob);
|
2007-09-26 07:57:13 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
void rt2x00debug_register(struct rt2x00_dev *rt2x00dev)
|
|
|
|
{
|
|
|
|
const struct rt2x00debug *debug = rt2x00dev->ops->debugfs;
|
|
|
|
struct rt2x00debug_intf *intf;
|
|
|
|
|
|
|
|
intf = kzalloc(sizeof(struct rt2x00debug_intf), GFP_KERNEL);
|
|
|
|
if (!intf) {
|
2013-04-19 22:33:40 +07:00
|
|
|
rt2x00_err(rt2x00dev, "Failed to allocate debug handler\n");
|
2007-09-26 07:57:13 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
intf->debug = debug;
|
|
|
|
intf->rt2x00dev = rt2x00dev;
|
|
|
|
rt2x00dev->debugfs_intf = intf;
|
|
|
|
|
|
|
|
intf->driver_folder =
|
|
|
|
debugfs_create_dir(intf->rt2x00dev->ops->name,
|
|
|
|
rt2x00dev->hw->wiphy->debugfsdir);
|
2008-10-22 16:07:25 +07:00
|
|
|
if (IS_ERR(intf->driver_folder) || !intf->driver_folder)
|
2007-09-26 07:57:13 +07:00
|
|
|
goto exit;
|
|
|
|
|
|
|
|
intf->driver_entry =
|
|
|
|
rt2x00debug_create_file_driver("driver", intf, &intf->driver_blob);
|
2008-10-22 16:07:25 +07:00
|
|
|
if (IS_ERR(intf->driver_entry) || !intf->driver_entry)
|
2007-09-26 07:57:13 +07:00
|
|
|
goto exit;
|
|
|
|
|
|
|
|
intf->chipset_entry =
|
|
|
|
rt2x00debug_create_file_chipset("chipset",
|
|
|
|
intf, &intf->chipset_blob);
|
2008-10-22 16:07:25 +07:00
|
|
|
if (IS_ERR(intf->chipset_entry) || !intf->chipset_entry)
|
2007-09-26 07:57:13 +07:00
|
|
|
goto exit;
|
|
|
|
|
2008-07-27 20:06:05 +07:00
|
|
|
intf->dev_flags = debugfs_create_file("dev_flags", S_IRUSR,
|
2007-09-26 01:13:51 +07:00
|
|
|
intf->driver_folder, intf,
|
|
|
|
&rt2x00debug_fop_dev_flags);
|
2008-10-22 16:07:25 +07:00
|
|
|
if (IS_ERR(intf->dev_flags) || !intf->dev_flags)
|
2007-09-26 01:13:51 +07:00
|
|
|
goto exit;
|
|
|
|
|
2011-04-18 20:27:06 +07:00
|
|
|
intf->cap_flags = debugfs_create_file("cap_flags", S_IRUSR,
|
|
|
|
intf->driver_folder, intf,
|
|
|
|
&rt2x00debug_fop_cap_flags);
|
|
|
|
if (IS_ERR(intf->cap_flags) || !intf->cap_flags)
|
|
|
|
goto exit;
|
|
|
|
|
2007-11-28 03:48:16 +07:00
|
|
|
intf->register_folder =
|
|
|
|
debugfs_create_dir("register", intf->driver_folder);
|
2008-10-22 16:07:25 +07:00
|
|
|
if (IS_ERR(intf->register_folder) || !intf->register_folder)
|
2007-11-28 03:48:16 +07:00
|
|
|
goto exit;
|
|
|
|
|
2012-04-19 20:04:52 +07:00
|
|
|
#define RT2X00DEBUGFS_CREATE_REGISTER_ENTRY(__intf, __name) \
|
|
|
|
({ \
|
|
|
|
if(debug->__name.read) { \
|
|
|
|
(__intf)->__name##_off_entry = \
|
|
|
|
debugfs_create_u32(__stringify(__name) "_offset", \
|
|
|
|
S_IRUSR | S_IWUSR, \
|
|
|
|
(__intf)->register_folder, \
|
|
|
|
&(__intf)->offset_##__name); \
|
|
|
|
if (IS_ERR((__intf)->__name##_off_entry) \
|
|
|
|
|| !(__intf)->__name##_off_entry) \
|
|
|
|
goto exit; \
|
|
|
|
\
|
|
|
|
(__intf)->__name##_val_entry = \
|
|
|
|
debugfs_create_file(__stringify(__name) "_value", \
|
|
|
|
S_IRUSR | S_IWUSR, \
|
|
|
|
(__intf)->register_folder, \
|
|
|
|
(__intf), &rt2x00debug_fop_##__name); \
|
|
|
|
if (IS_ERR((__intf)->__name##_val_entry) \
|
|
|
|
|| !(__intf)->__name##_val_entry) \
|
|
|
|
goto exit; \
|
|
|
|
} \
|
2007-09-26 07:57:13 +07:00
|
|
|
})
|
|
|
|
|
2007-11-28 03:48:16 +07:00
|
|
|
RT2X00DEBUGFS_CREATE_REGISTER_ENTRY(intf, csr);
|
|
|
|
RT2X00DEBUGFS_CREATE_REGISTER_ENTRY(intf, eeprom);
|
|
|
|
RT2X00DEBUGFS_CREATE_REGISTER_ENTRY(intf, bbp);
|
|
|
|
RT2X00DEBUGFS_CREATE_REGISTER_ENTRY(intf, rf);
|
2012-04-19 20:53:10 +07:00
|
|
|
RT2X00DEBUGFS_CREATE_REGISTER_ENTRY(intf, rfcsr);
|
2007-09-26 07:57:13 +07:00
|
|
|
|
2007-11-28 03:48:16 +07:00
|
|
|
#undef RT2X00DEBUGFS_CREATE_REGISTER_ENTRY
|
2007-09-26 07:57:13 +07:00
|
|
|
|
2008-02-11 04:50:28 +07:00
|
|
|
intf->queue_folder =
|
|
|
|
debugfs_create_dir("queue", intf->driver_folder);
|
2008-10-22 16:07:25 +07:00
|
|
|
if (IS_ERR(intf->queue_folder) || !intf->queue_folder)
|
2007-11-28 03:49:29 +07:00
|
|
|
goto exit;
|
|
|
|
|
2008-02-11 04:50:28 +07:00
|
|
|
intf->queue_frame_dump_entry =
|
2008-07-27 20:06:05 +07:00
|
|
|
debugfs_create_file("dump", S_IRUSR, intf->queue_folder,
|
2008-02-06 04:42:23 +07:00
|
|
|
intf, &rt2x00debug_fop_queue_dump);
|
2008-10-22 16:07:25 +07:00
|
|
|
if (IS_ERR(intf->queue_frame_dump_entry)
|
|
|
|
|| !intf->queue_frame_dump_entry)
|
2007-11-28 03:49:29 +07:00
|
|
|
goto exit;
|
|
|
|
|
|
|
|
skb_queue_head_init(&intf->frame_dump_skbqueue);
|
|
|
|
init_waitqueue_head(&intf->frame_dump_waitqueue);
|
|
|
|
|
2008-02-11 04:50:28 +07:00
|
|
|
intf->queue_stats_entry =
|
2008-07-27 20:06:05 +07:00
|
|
|
debugfs_create_file("queue", S_IRUSR, intf->queue_folder,
|
2008-02-11 04:50:28 +07:00
|
|
|
intf, &rt2x00debug_fop_queue_stats);
|
|
|
|
|
2008-08-04 21:37:44 +07:00
|
|
|
#ifdef CONFIG_RT2X00_LIB_CRYPTO
|
2013-10-11 18:18:41 +07:00
|
|
|
if (rt2x00_has_cap_hw_crypto(rt2x00dev))
|
2008-08-04 21:37:44 +07:00
|
|
|
intf->crypto_stats_entry =
|
|
|
|
debugfs_create_file("crypto", S_IRUGO, intf->queue_folder,
|
|
|
|
intf, &rt2x00debug_fop_crypto_stats);
|
|
|
|
#endif
|
|
|
|
|
2007-09-26 07:57:13 +07:00
|
|
|
return;
|
|
|
|
|
|
|
|
exit:
|
|
|
|
rt2x00debug_deregister(rt2x00dev);
|
2013-04-19 22:33:40 +07:00
|
|
|
rt2x00_err(rt2x00dev, "Failed to register debug handler\n");
|
2007-09-26 07:57:13 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
void rt2x00debug_deregister(struct rt2x00_dev *rt2x00dev)
|
|
|
|
{
|
2007-11-28 03:49:29 +07:00
|
|
|
struct rt2x00debug_intf *intf = rt2x00dev->debugfs_intf;
|
2007-09-26 07:57:13 +07:00
|
|
|
|
|
|
|
if (unlikely(!intf))
|
|
|
|
return;
|
|
|
|
|
2007-11-28 03:49:29 +07:00
|
|
|
skb_queue_purge(&intf->frame_dump_skbqueue);
|
|
|
|
|
2008-08-04 21:37:44 +07:00
|
|
|
#ifdef CONFIG_RT2X00_LIB_CRYPTO
|
|
|
|
debugfs_remove(intf->crypto_stats_entry);
|
|
|
|
#endif
|
2008-02-11 04:50:28 +07:00
|
|
|
debugfs_remove(intf->queue_stats_entry);
|
|
|
|
debugfs_remove(intf->queue_frame_dump_entry);
|
|
|
|
debugfs_remove(intf->queue_folder);
|
2012-04-19 20:53:10 +07:00
|
|
|
debugfs_remove(intf->rfcsr_val_entry);
|
|
|
|
debugfs_remove(intf->rfcsr_off_entry);
|
2007-09-26 07:57:13 +07:00
|
|
|
debugfs_remove(intf->rf_val_entry);
|
|
|
|
debugfs_remove(intf->rf_off_entry);
|
|
|
|
debugfs_remove(intf->bbp_val_entry);
|
|
|
|
debugfs_remove(intf->bbp_off_entry);
|
|
|
|
debugfs_remove(intf->eeprom_val_entry);
|
|
|
|
debugfs_remove(intf->eeprom_off_entry);
|
|
|
|
debugfs_remove(intf->csr_val_entry);
|
|
|
|
debugfs_remove(intf->csr_off_entry);
|
2007-11-28 03:48:16 +07:00
|
|
|
debugfs_remove(intf->register_folder);
|
2007-09-26 01:13:51 +07:00
|
|
|
debugfs_remove(intf->dev_flags);
|
2011-04-18 20:27:06 +07:00
|
|
|
debugfs_remove(intf->cap_flags);
|
2007-09-26 07:57:13 +07:00
|
|
|
debugfs_remove(intf->chipset_entry);
|
|
|
|
debugfs_remove(intf->driver_entry);
|
|
|
|
debugfs_remove(intf->driver_folder);
|
|
|
|
kfree(intf->chipset_blob.data);
|
|
|
|
kfree(intf->driver_blob.data);
|
|
|
|
kfree(intf);
|
|
|
|
|
|
|
|
rt2x00dev->debugfs_intf = NULL;
|
|
|
|
}
|