rc80211_pid_debugfs.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /*
  2. * Copyright 2007, Mattias Nissler <mattias.nissler@gmx.de>
  3. *
  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. */
  8. #include <linux/sched.h>
  9. #include <linux/spinlock.h>
  10. #include <linux/poll.h>
  11. #include <linux/netdevice.h>
  12. #include <linux/types.h>
  13. #include <linux/skbuff.h>
  14. #include <linux/slab.h>
  15. #include <net/mac80211.h>
  16. #include "rate.h"
  17. #include "rc80211_pid.h"
  18. static void rate_control_pid_event(struct rc_pid_event_buffer *buf,
  19. enum rc_pid_event_type type,
  20. union rc_pid_event_data *data)
  21. {
  22. struct rc_pid_event *ev;
  23. unsigned long status;
  24. spin_lock_irqsave(&buf->lock, status);
  25. ev = &(buf->ring[buf->next_entry]);
  26. buf->next_entry = (buf->next_entry + 1) % RC_PID_EVENT_RING_SIZE;
  27. ev->timestamp = jiffies;
  28. ev->id = buf->ev_count++;
  29. ev->type = type;
  30. ev->data = *data;
  31. spin_unlock_irqrestore(&buf->lock, status);
  32. wake_up_all(&buf->waitqueue);
  33. }
  34. void rate_control_pid_event_tx_status(struct rc_pid_event_buffer *buf,
  35. struct ieee80211_tx_info *stat)
  36. {
  37. union rc_pid_event_data evd;
  38. evd.flags = stat->flags;
  39. memcpy(&evd.tx_status, stat, sizeof(struct ieee80211_tx_info));
  40. rate_control_pid_event(buf, RC_PID_EVENT_TYPE_TX_STATUS, &evd);
  41. }
  42. void rate_control_pid_event_rate_change(struct rc_pid_event_buffer *buf,
  43. int index, int rate)
  44. {
  45. union rc_pid_event_data evd;
  46. evd.index = index;
  47. evd.rate = rate;
  48. rate_control_pid_event(buf, RC_PID_EVENT_TYPE_RATE_CHANGE, &evd);
  49. }
  50. void rate_control_pid_event_tx_rate(struct rc_pid_event_buffer *buf,
  51. int index, int rate)
  52. {
  53. union rc_pid_event_data evd;
  54. evd.index = index;
  55. evd.rate = rate;
  56. rate_control_pid_event(buf, RC_PID_EVENT_TYPE_TX_RATE, &evd);
  57. }
  58. void rate_control_pid_event_pf_sample(struct rc_pid_event_buffer *buf,
  59. s32 pf_sample, s32 prop_err,
  60. s32 int_err, s32 der_err)
  61. {
  62. union rc_pid_event_data evd;
  63. evd.pf_sample = pf_sample;
  64. evd.prop_err = prop_err;
  65. evd.int_err = int_err;
  66. evd.der_err = der_err;
  67. rate_control_pid_event(buf, RC_PID_EVENT_TYPE_PF_SAMPLE, &evd);
  68. }
  69. static int rate_control_pid_events_open(struct inode *inode, struct file *file)
  70. {
  71. struct rc_pid_sta_info *sinfo = inode->i_private;
  72. struct rc_pid_event_buffer *events = &sinfo->events;
  73. struct rc_pid_events_file_info *file_info;
  74. unsigned long status;
  75. /* Allocate a state struct */
  76. file_info = kmalloc(sizeof(*file_info), GFP_KERNEL);
  77. if (file_info == NULL)
  78. return -ENOMEM;
  79. spin_lock_irqsave(&events->lock, status);
  80. file_info->next_entry = events->next_entry;
  81. file_info->events = events;
  82. spin_unlock_irqrestore(&events->lock, status);
  83. file->private_data = file_info;
  84. return 0;
  85. }
  86. static int rate_control_pid_events_release(struct inode *inode,
  87. struct file *file)
  88. {
  89. struct rc_pid_events_file_info *file_info = file->private_data;
  90. kfree(file_info);
  91. return 0;
  92. }
  93. static unsigned int rate_control_pid_events_poll(struct file *file,
  94. poll_table *wait)
  95. {
  96. struct rc_pid_events_file_info *file_info = file->private_data;
  97. poll_wait(file, &file_info->events->waitqueue, wait);
  98. return POLLIN | POLLRDNORM;
  99. }
  100. #define RC_PID_PRINT_BUF_SIZE 64
  101. static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
  102. size_t length, loff_t *offset)
  103. {
  104. struct rc_pid_events_file_info *file_info = file->private_data;
  105. struct rc_pid_event_buffer *events = file_info->events;
  106. struct rc_pid_event *ev;
  107. char pb[RC_PID_PRINT_BUF_SIZE];
  108. int ret;
  109. int p;
  110. unsigned long status;
  111. /* Check if there is something to read. */
  112. if (events->next_entry == file_info->next_entry) {
  113. if (file->f_flags & O_NONBLOCK)
  114. return -EAGAIN;
  115. /* Wait */
  116. ret = wait_event_interruptible(events->waitqueue,
  117. events->next_entry != file_info->next_entry);
  118. if (ret)
  119. return ret;
  120. }
  121. /* Write out one event per call. I don't care whether it's a little
  122. * inefficient, this is debugging code anyway. */
  123. spin_lock_irqsave(&events->lock, status);
  124. /* Get an event */
  125. ev = &(events->ring[file_info->next_entry]);
  126. file_info->next_entry = (file_info->next_entry + 1) %
  127. RC_PID_EVENT_RING_SIZE;
  128. /* Print information about the event. Note that userspace needs to
  129. * provide large enough buffers. */
  130. length = length < RC_PID_PRINT_BUF_SIZE ?
  131. length : RC_PID_PRINT_BUF_SIZE;
  132. p = snprintf(pb, length, "%u %lu ", ev->id, ev->timestamp);
  133. switch (ev->type) {
  134. case RC_PID_EVENT_TYPE_TX_STATUS:
  135. p += snprintf(pb + p, length - p, "tx_status %u %u",
  136. !(ev->data.flags & IEEE80211_TX_STAT_ACK),
  137. ev->data.tx_status.status.rates[0].idx);
  138. break;
  139. case RC_PID_EVENT_TYPE_RATE_CHANGE:
  140. p += snprintf(pb + p, length - p, "rate_change %d %d",
  141. ev->data.index, ev->data.rate);
  142. break;
  143. case RC_PID_EVENT_TYPE_TX_RATE:
  144. p += snprintf(pb + p, length - p, "tx_rate %d %d",
  145. ev->data.index, ev->data.rate);
  146. break;
  147. case RC_PID_EVENT_TYPE_PF_SAMPLE:
  148. p += snprintf(pb + p, length - p,
  149. "pf_sample %d %d %d %d",
  150. ev->data.pf_sample, ev->data.prop_err,
  151. ev->data.int_err, ev->data.der_err);
  152. break;
  153. }
  154. p += snprintf(pb + p, length - p, "\n");
  155. spin_unlock_irqrestore(&events->lock, status);
  156. if (copy_to_user(buf, pb, p))
  157. return -EFAULT;
  158. return p;
  159. }
  160. #undef RC_PID_PRINT_BUF_SIZE
  161. static const struct file_operations rc_pid_fop_events = {
  162. .owner = THIS_MODULE,
  163. .read = rate_control_pid_events_read,
  164. .poll = rate_control_pid_events_poll,
  165. .open = rate_control_pid_events_open,
  166. .release = rate_control_pid_events_release,
  167. .llseek = noop_llseek,
  168. };
  169. void rate_control_pid_add_sta_debugfs(void *priv, void *priv_sta,
  170. struct dentry *dir)
  171. {
  172. struct rc_pid_sta_info *spinfo = priv_sta;
  173. spinfo->events_entry = debugfs_create_file("rc_pid_events", S_IRUGO,
  174. dir, spinfo,
  175. &rc_pid_fop_events);
  176. }
  177. void rate_control_pid_remove_sta_debugfs(void *priv, void *priv_sta)
  178. {
  179. struct rc_pid_sta_info *spinfo = priv_sta;
  180. debugfs_remove(spinfo->events_entry);
  181. }