Path: blob/master/net/mac80211/rc80211_minstrel_debugfs.c
15109 views
/*1* Copyright (C) 2008 Felix Fietkau <[email protected]>2*3* This program is free software; you can redistribute it and/or modify4* it under the terms of the GNU General Public License version 2 as5* published by the Free Software Foundation.6*7* Based on minstrel.c:8* Copyright (C) 2005-2007 Derek Smithies <[email protected]>9* Sponsored by Indranet Technologies Ltd10*11* Based on sample.c:12* Copyright (c) 2005 John Bicket13* All rights reserved.14*15* Redistribution and use in source and binary forms, with or without16* modification, are permitted provided that the following conditions17* are met:18* 1. Redistributions of source code must retain the above copyright19* notice, this list of conditions and the following disclaimer,20* without modification.21* 2. Redistributions in binary form must reproduce at minimum a disclaimer22* similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any23* redistribution must be conditioned upon including a substantially24* similar Disclaimer requirement for further binary redistribution.25* 3. Neither the names of the above-listed copyright holders nor the names26* of any contributors may be used to endorse or promote products derived27* from this software without specific prior written permission.28*29* Alternatively, this software may be distributed under the terms of the30* GNU General Public License ("GPL") version 2 as published by the Free31* Software Foundation.32*33* NO WARRANTY34* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS35* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT36* LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY37* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL38* THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,39* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF40* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS41* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER42* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)43* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF44* THE POSSIBILITY OF SUCH DAMAGES.45*/46#include <linux/netdevice.h>47#include <linux/types.h>48#include <linux/skbuff.h>49#include <linux/debugfs.h>50#include <linux/ieee80211.h>51#include <linux/slab.h>52#include <net/mac80211.h>53#include "rc80211_minstrel.h"5455int56minstrel_stats_open(struct inode *inode, struct file *file)57{58struct minstrel_sta_info *mi = inode->i_private;59struct minstrel_debugfs_info *ms;60unsigned int i, tp, prob, eprob;61char *p;6263ms = kmalloc(sizeof(*ms) + 4096, GFP_KERNEL);64if (!ms)65return -ENOMEM;6667file->private_data = ms;68p = ms->buf;69p += sprintf(p, "rate throughput ewma prob this prob "70"this succ/attempt success attempts\n");71for (i = 0; i < mi->n_rates; i++) {72struct minstrel_rate *mr = &mi->r[i];7374*(p++) = (i == mi->max_tp_rate) ? 'T' : ' ';75*(p++) = (i == mi->max_tp_rate2) ? 't' : ' ';76*(p++) = (i == mi->max_prob_rate) ? 'P' : ' ';77p += sprintf(p, "%3u%s", mr->bitrate / 2,78(mr->bitrate & 1 ? ".5" : " "));7980tp = mr->cur_tp / ((18000 << 10) / 96);81prob = mr->cur_prob / 18;82eprob = mr->probability / 18;8384p += sprintf(p, " %6u.%1u %6u.%1u %6u.%1u "85"%3u(%3u) %8llu %8llu\n",86tp / 10, tp % 10,87eprob / 10, eprob % 10,88prob / 10, prob % 10,89mr->last_success,90mr->last_attempts,91(unsigned long long)mr->succ_hist,92(unsigned long long)mr->att_hist);93}94p += sprintf(p, "\nTotal packet count:: ideal %d "95"lookaround %d\n\n",96mi->packet_count - mi->sample_count,97mi->sample_count);98ms->len = p - ms->buf;99100return 0;101}102103ssize_t104minstrel_stats_read(struct file *file, char __user *buf, size_t len, loff_t *ppos)105{106struct minstrel_debugfs_info *ms;107108ms = file->private_data;109return simple_read_from_buffer(buf, len, ppos, ms->buf, ms->len);110}111112int113minstrel_stats_release(struct inode *inode, struct file *file)114{115kfree(file->private_data);116return 0;117}118119static const struct file_operations minstrel_stat_fops = {120.owner = THIS_MODULE,121.open = minstrel_stats_open,122.read = minstrel_stats_read,123.release = minstrel_stats_release,124.llseek = default_llseek,125};126127void128minstrel_add_sta_debugfs(void *priv, void *priv_sta, struct dentry *dir)129{130struct minstrel_sta_info *mi = priv_sta;131132mi->dbg_stats = debugfs_create_file("rc_stats", S_IRUGO, dir, mi,133&minstrel_stat_fops);134}135136void137minstrel_remove_sta_debugfs(void *priv, void *priv_sta)138{139struct minstrel_sta_info *mi = priv_sta;140141debugfs_remove(mi->dbg_stats);142}143144145