PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/net/wireless/tiwlan1251/pform/linux/src/bmtrace.c

http://github.com/CyanogenMod/cm-kernel
C | 183 lines | 120 code | 23 blank | 40 comment | 11 complexity | fb99e281273a0b602cf9bcbd86f6a2ba MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.0
  1. /****************************************************************************
  2. **+-----------------------------------------------------------------------+**
  3. **| |**
  4. **| Copyright(c) 1998 - 2008 Texas Instruments. All rights reserved. |**
  5. **| All rights reserved. |**
  6. **| |**
  7. **| Redistribution and use in source and binary forms, with or without |**
  8. **| modification, are permitted provided that the following conditions |**
  9. **| are met: |**
  10. **| |**
  11. **| * Redistributions of source code must retain the above copyright |**
  12. **| notice, this list of conditions and the following disclaimer. |**
  13. **| * Redistributions in binary form must reproduce the above copyright |**
  14. **| notice, this list of conditions and the following disclaimer in |**
  15. **| the documentation and/or other materials provided with the |**
  16. **| distribution. |**
  17. **| * Neither the name Texas Instruments nor the names of its |**
  18. **| contributors may be used to endorse or promote products derived |**
  19. **| from this software without specific prior written permission. |**
  20. **| |**
  21. **| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |**
  22. **| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |**
  23. **| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |**
  24. **| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |**
  25. **| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |**
  26. **| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |**
  27. **| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |**
  28. **| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |**
  29. **| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |**
  30. **| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |**
  31. **| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |**
  32. **| |**
  33. **+-----------------------------------------------------------------------+**
  34. ****************************************************************************/
  35. #include <linux/config.h>
  36. #include <linux/module.h>
  37. #include <linux/errno.h>
  38. #include <linux/string.h>
  39. #include <linux/proc_fs.h>
  40. #include "osApi.h"
  41. #include "esta_drv.h"
  42. #include "bmtrace.h"
  43. #define OS_READ_REG(drv,reg,p_val) \
  44. os_hwReadMemRegisterUINT32(drv, (UINT32 *)((unsigned long)drv->acx_reg.va + reg), p_val)
  45. typedef struct {
  46. unsigned long loc;/* trace entry identification */
  47. unsigned long ts;/* Timestamp */
  48. unsigned long p1; /* Parameter 1 */
  49. unsigned long p2; /* Parameter 2 */
  50. } bm_entry_t;
  51. typedef struct {
  52. int pos;
  53. int count;
  54. int print_pos;
  55. int nusers;
  56. unsigned long self_delay;
  57. tiwlan_net_dev_t *drv;
  58. bm_entry_t entry[1]; /* Array of entries */
  59. } bm_control_t;
  60. static bm_control_t *bm_control;
  61. static inline int bm_control_size(void)
  62. {
  63. return offsetof(bm_control_t, entry) + sizeof(bm_entry_t)*BM_NUM_ENTRIES;
  64. }
  65. static int bm_res_read_proc(char *page, char **start, off_t off,
  66. int count, int *eof, void *data)
  67. {
  68. int i;
  69. int len=0;
  70. int limit=count-80;
  71. int entry_count;
  72. unsigned long prev=0;
  73. int print_pos;
  74. print_pos = bm_control->print_pos++; /* It will disable tracing as well */
  75. entry_count = (bm_control->count > BM_NUM_ENTRIES) ? BM_NUM_ENTRIES : bm_control->count;
  76. /* Skip off entries */
  77. if ( print_pos >= entry_count) /* paranoid */
  78. {
  79. bm_control->pos = bm_control->count = bm_control->print_pos = 0;
  80. *eof = 1;
  81. return 0;
  82. }
  83. if (!off)
  84. {
  85. len = sprintf(page, "Events stored: %u discarded: %u\n",
  86. entry_count, bm_control->count-entry_count);
  87. len += sprintf(page+len, "loc delta ts p1 p2\n");
  88. }
  89. /* Initial index */
  90. if (bm_control->count > BM_NUM_ENTRIES)
  91. i = (bm_control->pos+print_pos-1)%BM_NUM_ENTRIES;
  92. else
  93. i = bm_control->print_pos-1;
  94. for(; (print_pos<entry_count) && (len<=limit); print_pos++)
  95. {
  96. bm_entry_t *bme= &bm_control->entry[i];
  97. len += sprintf(page+len,
  98. "%-3lu %-10lu %-10lu %-10lu %-10lu\n",
  99. bme->loc,
  100. ((bme->ts-prev)>bm_control->self_delay)?bme->ts-prev-bm_control->self_delay:0,
  101. bme->ts,
  102. bme->p1, bme->p2);
  103. prev = bme->ts;
  104. ++i;
  105. i %= BM_NUM_ENTRIES;
  106. }
  107. if (print_pos >= entry_count)
  108. {
  109. *eof = 1;
  110. bm_control->pos = bm_control->count = bm_control->print_pos = 0;
  111. }
  112. else
  113. bm_control->print_pos = print_pos;
  114. return len;
  115. }
  116. /* Initialization */
  117. int bm_init(struct tiwlan_net_dev *drv)
  118. {
  119. if (bm_control)
  120. {
  121. ++bm_control->nusers;
  122. return 0;
  123. }
  124. bm_control = (bm_control_t *)kmalloc(bm_control_size(), GFP_KERNEL);
  125. if (!bm_control)
  126. return -ENOMEM;
  127. memset(bm_control, 0, offsetof(bm_control_t, entry) + sizeof(bm_entry_t)*BM_NUM_ENTRIES);
  128. bm_control->nusers = 1;
  129. bm_control->drv = drv;
  130. create_proc_read_entry("bmtrace", 0, NULL, bm_res_read_proc, NULL);
  131. /* Measure self-delay */
  132. bm_trace(0, 0, 0);
  133. bm_trace(0, 0, 0);
  134. bm_control->self_delay = bm_control->entry[1].ts - bm_control->entry[0].ts;
  135. bm_control->pos = bm_control->count = 0;
  136. print_info("%s: self_delay=%lu\n", __FUNCTION__, bm_control->self_delay);
  137. return 0;
  138. }
  139. /* De-initialization */
  140. void bm_destroy(void)
  141. {
  142. if (--bm_control->nusers)
  143. return;
  144. remove_proc_entry("bmtrace", NULL);
  145. kfree( bm_control );
  146. }
  147. /* Add trace entry. not safe, but will do */
  148. void bm_trace(int loc, unsigned long p1, unsigned long p2)
  149. {
  150. int pos;
  151. if (!bm_control || bm_control->print_pos)
  152. return;
  153. pos = bm_control->pos;
  154. bm_control->pos = (pos+1) % BM_NUM_ENTRIES;
  155. ++bm_control->count;
  156. bm_control->entry[pos].ts = os_timeStampUs(NULL);
  157. bm_control->entry[pos].loc= loc;
  158. bm_control->entry[pos].p1 = p1;
  159. bm_control->entry[pos].p2 = p2;
  160. }