rc80211_pid_debugfs.c
Go to the documentation of this file.
00001 /*
00002  * Copyright 2007, Mattias Nissler <mattias.nissler@gmx.de>
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License version 2 as
00006  * published by the Free Software Foundation.
00007  */
00008 
00009 #include <linux/sched.h>
00010 #include <linux/spinlock.h>
00011 #include <linux/poll.h>
00012 #include <linux/netdevice.h>
00013 #include <linux/types.h>
00014 #include <linux/skbuff.h>
00015 #include <linux/slab.h>
00016 #include <linux/export.h>
00017 
00018 #include <net/mac80211.h>
00019 #include "rate.h"
00020 
00021 #include "rc80211_pid.h"
00022 
00023 static void rate_control_pid_event(struct rc_pid_event_buffer *buf,
00024                                    enum rc_pid_event_type type,
00025                                    union rc_pid_event_data *data)
00026 {
00027         struct rc_pid_event *ev;
00028         unsigned long status;
00029 
00030         spin_lock_irqsave(&buf->lock, status);
00031         ev = &(buf->ring[buf->next_entry]);
00032         buf->next_entry = (buf->next_entry + 1) % RC_PID_EVENT_RING_SIZE;
00033 
00034         ev->timestamp = jiffies;
00035         ev->id = buf->ev_count++;
00036         ev->type = type;
00037         ev->data = *data;
00038 
00039         spin_unlock_irqrestore(&buf->lock, status);
00040 
00041         wake_up_all(&buf->waitqueue);
00042 }
00043 
00044 void rate_control_pid_event_tx_status(struct rc_pid_event_buffer *buf,
00045                                       struct ieee80211_tx_info *stat)
00046 {
00047         union rc_pid_event_data evd;
00048 
00049         evd.flags = stat->flags;
00050         memcpy(&evd.tx_status, stat, sizeof(struct ieee80211_tx_info));
00051         rate_control_pid_event(buf, RC_PID_EVENT_TYPE_TX_STATUS, &evd);
00052 }
00053 
00054 void rate_control_pid_event_rate_change(struct rc_pid_event_buffer *buf,
00055                                                int index, int rate)
00056 {
00057         union rc_pid_event_data evd;
00058 
00059         evd.index = index;
00060         evd.rate = rate;
00061         rate_control_pid_event(buf, RC_PID_EVENT_TYPE_RATE_CHANGE, &evd);
00062 }
00063 
00064 void rate_control_pid_event_tx_rate(struct rc_pid_event_buffer *buf,
00065                                            int index, int rate)
00066 {
00067         union rc_pid_event_data evd;
00068 
00069         evd.index = index;
00070         evd.rate = rate;
00071         rate_control_pid_event(buf, RC_PID_EVENT_TYPE_TX_RATE, &evd);
00072 }
00073 
00074 void rate_control_pid_event_pf_sample(struct rc_pid_event_buffer *buf,
00075                                              s32 pf_sample, s32 prop_err,
00076                                              s32 int_err, s32 der_err)
00077 {
00078         union rc_pid_event_data evd;
00079 
00080         evd.pf_sample = pf_sample;
00081         evd.prop_err = prop_err;
00082         evd.int_err = int_err;
00083         evd.der_err = der_err;
00084         rate_control_pid_event(buf, RC_PID_EVENT_TYPE_PF_SAMPLE, &evd);
00085 }
00086 
00087 static int rate_control_pid_events_open(struct inode *inode, struct file *file)
00088 {
00089         struct rc_pid_sta_info *sinfo = inode->i_private;
00090         struct rc_pid_event_buffer *events = &sinfo->events;
00091         struct rc_pid_events_file_info *file_info;
00092         unsigned long status;
00093 
00094         /* Allocate a state struct */
00095         file_info = kmalloc(sizeof(*file_info), GFP_KERNEL);
00096         if (file_info == NULL)
00097                 return -ENOMEM;
00098 
00099         spin_lock_irqsave(&events->lock, status);
00100 
00101         file_info->next_entry = events->next_entry;
00102         file_info->events = events;
00103 
00104         spin_unlock_irqrestore(&events->lock, status);
00105 
00106         file->private_data = file_info;
00107 
00108         return 0;
00109 }
00110 
00111 static int rate_control_pid_events_release(struct inode *inode,
00112                                            struct file *file)
00113 {
00114         struct rc_pid_events_file_info *file_info = file->private_data;
00115 
00116         kfree(file_info);
00117 
00118         return 0;
00119 }
00120 
00121 static unsigned int rate_control_pid_events_poll(struct file *file,
00122                                                  poll_table *wait)
00123 {
00124         struct rc_pid_events_file_info *file_info = file->private_data;
00125 
00126         poll_wait(file, &file_info->events->waitqueue, wait);
00127 
00128         return POLLIN | POLLRDNORM;
00129 }
00130 
00131 #define RC_PID_PRINT_BUF_SIZE 64
00132 
00133 static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
00134                                             size_t length, loff_t *offset)
00135 {
00136         struct rc_pid_events_file_info *file_info = file->private_data;
00137         struct rc_pid_event_buffer *events = file_info->events;
00138         struct rc_pid_event *ev;
00139         char pb[RC_PID_PRINT_BUF_SIZE];
00140         int ret;
00141         int p;
00142         unsigned long status;
00143 
00144         /* Check if there is something to read. */
00145         if (events->next_entry == file_info->next_entry) {
00146                 if (file->f_flags & O_NONBLOCK)
00147                         return -EAGAIN;
00148 
00149                 /* Wait */
00150                 ret = wait_event_interruptible(events->waitqueue,
00151                                 events->next_entry != file_info->next_entry);
00152 
00153                 if (ret)
00154                         return ret;
00155         }
00156 
00157         /* Write out one event per call. I don't care whether it's a little
00158          * inefficient, this is debugging code anyway. */
00159         spin_lock_irqsave(&events->lock, status);
00160 
00161         /* Get an event */
00162         ev = &(events->ring[file_info->next_entry]);
00163         file_info->next_entry = (file_info->next_entry + 1) %
00164                                 RC_PID_EVENT_RING_SIZE;
00165 
00166         /* Print information about the event. Note that userspace needs to
00167          * provide large enough buffers. */
00168         length = length < RC_PID_PRINT_BUF_SIZE ?
00169                  length : RC_PID_PRINT_BUF_SIZE;
00170         p = snprintf(pb, length, "%u %lu ", ev->id, ev->timestamp);
00171         switch (ev->type) {
00172         case RC_PID_EVENT_TYPE_TX_STATUS:
00173                 p += snprintf(pb + p, length - p, "tx_status %u %u",
00174                               !(ev->data.flags & IEEE80211_TX_STAT_ACK),
00175                               ev->data.tx_status.status.rates[0].idx);
00176                 break;
00177         case RC_PID_EVENT_TYPE_RATE_CHANGE:
00178                 p += snprintf(pb + p, length - p, "rate_change %d %d",
00179                               ev->data.index, ev->data.rate);
00180                 break;
00181         case RC_PID_EVENT_TYPE_TX_RATE:
00182                 p += snprintf(pb + p, length - p, "tx_rate %d %d",
00183                               ev->data.index, ev->data.rate);
00184                 break;
00185         case RC_PID_EVENT_TYPE_PF_SAMPLE:
00186                 p += snprintf(pb + p, length - p,
00187                               "pf_sample %d %d %d %d",
00188                               ev->data.pf_sample, ev->data.prop_err,
00189                               ev->data.int_err, ev->data.der_err);
00190                 break;
00191         }
00192         p += snprintf(pb + p, length - p, "\n");
00193 
00194         spin_unlock_irqrestore(&events->lock, status);
00195 
00196         if (copy_to_user(buf, pb, p))
00197                 return -EFAULT;
00198 
00199         return p;
00200 }
00201 
00202 #undef RC_PID_PRINT_BUF_SIZE
00203 
00204 static const struct file_operations rc_pid_fop_events = {
00205         .owner = THIS_MODULE,
00206         .read = rate_control_pid_events_read,
00207         .poll = rate_control_pid_events_poll,
00208         .open = rate_control_pid_events_open,
00209         .release = rate_control_pid_events_release,
00210         .llseek = noop_llseek,
00211 };
00212 
00213 void rate_control_pid_add_sta_debugfs(void *priv, void *priv_sta,
00214                                              struct dentry *dir)
00215 {
00216         struct rc_pid_sta_info *spinfo = priv_sta;
00217 
00218         spinfo->events_entry = debugfs_create_file("rc_pid_events", S_IRUGO,
00219                                                    dir, spinfo,
00220                                                    &rc_pid_fop_events);
00221 }
00222 
00223 void rate_control_pid_remove_sta_debugfs(void *priv, void *priv_sta)
00224 {
00225         struct rc_pid_sta_info *spinfo = priv_sta;
00226 
00227         debugfs_remove(spinfo->events_entry);
00228 }


ros_rt_wmp
Author(s): Danilo Tardioli, dantard@unizar.es
autogenerated on Fri Jan 3 2014 12:07:55