OMAP3: PM: Fixed VDD2 control to work from both sysfs and SRF API
[linux-ginger.git] / net / mac80211 / rc80211_pid_debugfs.c
blob45667054a5f305308a8bf1faff8b9def3b8b0749
1 /*
2 * Copyright 2007, Mattias Nissler <mattias.nissler@gmx.de>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
9 #include <linux/sched.h>
10 #include <linux/spinlock.h>
11 #include <linux/poll.h>
12 #include <linux/netdevice.h>
13 #include <linux/types.h>
14 #include <linux/skbuff.h>
16 #include <net/mac80211.h>
17 #include "rate.h"
19 #include "rc80211_pid.h"
21 static void rate_control_pid_event(struct rc_pid_event_buffer *buf,
22 enum rc_pid_event_type type,
23 union rc_pid_event_data *data)
25 struct rc_pid_event *ev;
26 unsigned long status;
28 spin_lock_irqsave(&buf->lock, status);
29 ev = &(buf->ring[buf->next_entry]);
30 buf->next_entry = (buf->next_entry + 1) % RC_PID_EVENT_RING_SIZE;
32 ev->timestamp = jiffies;
33 ev->id = buf->ev_count++;
34 ev->type = type;
35 ev->data = *data;
37 spin_unlock_irqrestore(&buf->lock, status);
39 wake_up_all(&buf->waitqueue);
42 void rate_control_pid_event_tx_status(struct rc_pid_event_buffer *buf,
43 struct ieee80211_tx_info *stat)
45 union rc_pid_event_data evd;
47 evd.flags = stat->flags;
48 memcpy(&evd.tx_status, stat, sizeof(struct ieee80211_tx_info));
49 rate_control_pid_event(buf, RC_PID_EVENT_TYPE_TX_STATUS, &evd);
52 void rate_control_pid_event_rate_change(struct rc_pid_event_buffer *buf,
53 int index, int rate)
55 union rc_pid_event_data evd;
57 evd.index = index;
58 evd.rate = rate;
59 rate_control_pid_event(buf, RC_PID_EVENT_TYPE_RATE_CHANGE, &evd);
62 void rate_control_pid_event_tx_rate(struct rc_pid_event_buffer *buf,
63 int index, int rate)
65 union rc_pid_event_data evd;
67 evd.index = index;
68 evd.rate = rate;
69 rate_control_pid_event(buf, RC_PID_EVENT_TYPE_TX_RATE, &evd);
72 void rate_control_pid_event_pf_sample(struct rc_pid_event_buffer *buf,
73 s32 pf_sample, s32 prop_err,
74 s32 int_err, s32 der_err)
76 union rc_pid_event_data evd;
78 evd.pf_sample = pf_sample;
79 evd.prop_err = prop_err;
80 evd.int_err = int_err;
81 evd.der_err = der_err;
82 rate_control_pid_event(buf, RC_PID_EVENT_TYPE_PF_SAMPLE, &evd);
85 static int rate_control_pid_events_open(struct inode *inode, struct file *file)
87 struct rc_pid_sta_info *sinfo = inode->i_private;
88 struct rc_pid_event_buffer *events = &sinfo->events;
89 struct rc_pid_events_file_info *file_info;
90 unsigned long status;
92 /* Allocate a state struct */
93 file_info = kmalloc(sizeof(*file_info), GFP_KERNEL);
94 if (file_info == NULL)
95 return -ENOMEM;
97 spin_lock_irqsave(&events->lock, status);
99 file_info->next_entry = events->next_entry;
100 file_info->events = events;
102 spin_unlock_irqrestore(&events->lock, status);
104 file->private_data = file_info;
106 return 0;
109 static int rate_control_pid_events_release(struct inode *inode,
110 struct file *file)
112 struct rc_pid_events_file_info *file_info = file->private_data;
114 kfree(file_info);
116 return 0;
119 static unsigned int rate_control_pid_events_poll(struct file *file,
120 poll_table *wait)
122 struct rc_pid_events_file_info *file_info = file->private_data;
124 poll_wait(file, &file_info->events->waitqueue, wait);
126 return POLLIN | POLLRDNORM;
129 #define RC_PID_PRINT_BUF_SIZE 64
131 static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
132 size_t length, loff_t *offset)
134 struct rc_pid_events_file_info *file_info = file->private_data;
135 struct rc_pid_event_buffer *events = file_info->events;
136 struct rc_pid_event *ev;
137 char pb[RC_PID_PRINT_BUF_SIZE];
138 int ret;
139 int p;
140 unsigned long status;
142 /* Check if there is something to read. */
143 if (events->next_entry == file_info->next_entry) {
144 if (file->f_flags & O_NONBLOCK)
145 return -EAGAIN;
147 /* Wait */
148 ret = wait_event_interruptible(events->waitqueue,
149 events->next_entry != file_info->next_entry);
151 if (ret)
152 return ret;
155 /* Write out one event per call. I don't care whether it's a little
156 * inefficient, this is debugging code anyway. */
157 spin_lock_irqsave(&events->lock, status);
159 /* Get an event */
160 ev = &(events->ring[file_info->next_entry]);
161 file_info->next_entry = (file_info->next_entry + 1) %
162 RC_PID_EVENT_RING_SIZE;
164 /* Print information about the event. Note that userpace needs to
165 * provide large enough buffers. */
166 length = length < RC_PID_PRINT_BUF_SIZE ?
167 length : RC_PID_PRINT_BUF_SIZE;
168 p = snprintf(pb, length, "%u %lu ", ev->id, ev->timestamp);
169 switch (ev->type) {
170 case RC_PID_EVENT_TYPE_TX_STATUS:
171 p += snprintf(pb + p, length - p, "tx_status %u %u",
172 !(ev->data.flags & IEEE80211_TX_STAT_ACK),
173 ev->data.tx_status.status.rates[0].idx);
174 break;
175 case RC_PID_EVENT_TYPE_RATE_CHANGE:
176 p += snprintf(pb + p, length - p, "rate_change %d %d",
177 ev->data.index, ev->data.rate);
178 break;
179 case RC_PID_EVENT_TYPE_TX_RATE:
180 p += snprintf(pb + p, length - p, "tx_rate %d %d",
181 ev->data.index, ev->data.rate);
182 break;
183 case RC_PID_EVENT_TYPE_PF_SAMPLE:
184 p += snprintf(pb + p, length - p,
185 "pf_sample %d %d %d %d",
186 ev->data.pf_sample, ev->data.prop_err,
187 ev->data.int_err, ev->data.der_err);
188 break;
190 p += snprintf(pb + p, length - p, "\n");
192 spin_unlock_irqrestore(&events->lock, status);
194 if (copy_to_user(buf, pb, p))
195 return -EFAULT;
197 return p;
200 #undef RC_PID_PRINT_BUF_SIZE
202 static const struct file_operations rc_pid_fop_events = {
203 .owner = THIS_MODULE,
204 .read = rate_control_pid_events_read,
205 .poll = rate_control_pid_events_poll,
206 .open = rate_control_pid_events_open,
207 .release = rate_control_pid_events_release,
210 void rate_control_pid_add_sta_debugfs(void *priv, void *priv_sta,
211 struct dentry *dir)
213 struct rc_pid_sta_info *spinfo = priv_sta;
215 spinfo->events_entry = debugfs_create_file("rc_pid_events", S_IRUGO,
216 dir, spinfo,
217 &rc_pid_fop_events);
220 void rate_control_pid_remove_sta_debugfs(void *priv, void *priv_sta)
222 struct rc_pid_sta_info *spinfo = priv_sta;
224 debugfs_remove(spinfo->events_entry);