rc80211_pid_debugfs.c 5.8 KB

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