kcapi_proc.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*
  2. * Kernel CAPI 2.0 Module - /proc/capi handling
  3. *
  4. * Copyright 1999 by Carsten Paeth <[email protected]>
  5. * Copyright 2002 by Kai Germaschewski <[email protected]>
  6. *
  7. * This software may be used and distributed according to the terms
  8. * of the GNU General Public License, incorporated herein by reference.
  9. *
  10. */
  11. #include "kcapi.h"
  12. #include <linux/proc_fs.h>
  13. #include <linux/seq_file.h>
  14. #include <linux/init.h>
  15. #include <linux/export.h>
  16. static char *state2str(unsigned short state)
  17. {
  18. switch (state) {
  19. case CAPI_CTR_DETECTED: return "detected";
  20. case CAPI_CTR_LOADING: return "loading";
  21. case CAPI_CTR_RUNNING: return "running";
  22. default: return "???";
  23. }
  24. }
  25. // /proc/capi
  26. // ===========================================================================
  27. // /proc/capi/controller:
  28. // cnr driver cardstate name driverinfo
  29. // /proc/capi/contrstats:
  30. // cnr nrecvctlpkt nrecvdatapkt nsentctlpkt nsentdatapkt
  31. // ---------------------------------------------------------------------------
  32. static void *controller_start(struct seq_file *seq, loff_t *pos)
  33. __acquires(capi_controller_lock)
  34. {
  35. mutex_lock(&capi_controller_lock);
  36. if (*pos < CAPI_MAXCONTR)
  37. return &capi_controller[*pos];
  38. return NULL;
  39. }
  40. static void *controller_next(struct seq_file *seq, void *v, loff_t *pos)
  41. {
  42. ++*pos;
  43. if (*pos < CAPI_MAXCONTR)
  44. return &capi_controller[*pos];
  45. return NULL;
  46. }
  47. static void controller_stop(struct seq_file *seq, void *v)
  48. __releases(capi_controller_lock)
  49. {
  50. mutex_unlock(&capi_controller_lock);
  51. }
  52. static int controller_show(struct seq_file *seq, void *v)
  53. {
  54. struct capi_ctr *ctr = *(struct capi_ctr **) v;
  55. if (!ctr)
  56. return 0;
  57. seq_printf(seq, "%d %-10s %-8s %-16s %s\n",
  58. ctr->cnr, ctr->driver_name,
  59. state2str(ctr->state),
  60. ctr->name,
  61. ctr->procinfo ? ctr->procinfo(ctr) : "");
  62. return 0;
  63. }
  64. static int contrstats_show(struct seq_file *seq, void *v)
  65. {
  66. struct capi_ctr *ctr = *(struct capi_ctr **) v;
  67. if (!ctr)
  68. return 0;
  69. seq_printf(seq, "%d %lu %lu %lu %lu\n",
  70. ctr->cnr,
  71. ctr->nrecvctlpkt,
  72. ctr->nrecvdatapkt,
  73. ctr->nsentctlpkt,
  74. ctr->nsentdatapkt);
  75. return 0;
  76. }
  77. static const struct seq_operations seq_controller_ops = {
  78. .start = controller_start,
  79. .next = controller_next,
  80. .stop = controller_stop,
  81. .show = controller_show,
  82. };
  83. static const struct seq_operations seq_contrstats_ops = {
  84. .start = controller_start,
  85. .next = controller_next,
  86. .stop = controller_stop,
  87. .show = contrstats_show,
  88. };
  89. // /proc/capi/applications:
  90. // applid l3cnt dblkcnt dblklen #ncci recvqueuelen
  91. // /proc/capi/applstats:
  92. // applid nrecvctlpkt nrecvdatapkt nsentctlpkt nsentdatapkt
  93. // ---------------------------------------------------------------------------
  94. static void *applications_start(struct seq_file *seq, loff_t *pos)
  95. __acquires(capi_controller_lock)
  96. {
  97. mutex_lock(&capi_controller_lock);
  98. if (*pos < CAPI_MAXAPPL)
  99. return &capi_applications[*pos];
  100. return NULL;
  101. }
  102. static void *
  103. applications_next(struct seq_file *seq, void *v, loff_t *pos)
  104. {
  105. ++*pos;
  106. if (*pos < CAPI_MAXAPPL)
  107. return &capi_applications[*pos];
  108. return NULL;
  109. }
  110. static void applications_stop(struct seq_file *seq, void *v)
  111. __releases(capi_controller_lock)
  112. {
  113. mutex_unlock(&capi_controller_lock);
  114. }
  115. static int
  116. applications_show(struct seq_file *seq, void *v)
  117. {
  118. struct capi20_appl *ap = *(struct capi20_appl **) v;
  119. if (!ap)
  120. return 0;
  121. seq_printf(seq, "%u %d %d %d\n",
  122. ap->applid,
  123. ap->rparam.level3cnt,
  124. ap->rparam.datablkcnt,
  125. ap->rparam.datablklen);
  126. return 0;
  127. }
  128. static int
  129. applstats_show(struct seq_file *seq, void *v)
  130. {
  131. struct capi20_appl *ap = *(struct capi20_appl **) v;
  132. if (!ap)
  133. return 0;
  134. seq_printf(seq, "%u %lu %lu %lu %lu\n",
  135. ap->applid,
  136. ap->nrecvctlpkt,
  137. ap->nrecvdatapkt,
  138. ap->nsentctlpkt,
  139. ap->nsentdatapkt);
  140. return 0;
  141. }
  142. static const struct seq_operations seq_applications_ops = {
  143. .start = applications_start,
  144. .next = applications_next,
  145. .stop = applications_stop,
  146. .show = applications_show,
  147. };
  148. static const struct seq_operations seq_applstats_ops = {
  149. .start = applications_start,
  150. .next = applications_next,
  151. .stop = applications_stop,
  152. .show = applstats_show,
  153. };
  154. // ---------------------------------------------------------------------------
  155. /* /proc/capi/drivers is always empty */
  156. static ssize_t empty_read(struct file *file, char __user *buf,
  157. size_t size, loff_t *off)
  158. {
  159. return 0;
  160. }
  161. static const struct proc_ops empty_proc_ops = {
  162. .proc_read = empty_read,
  163. .proc_lseek = default_llseek,
  164. };
  165. // ---------------------------------------------------------------------------
  166. void __init
  167. kcapi_proc_init(void)
  168. {
  169. proc_mkdir("capi", NULL);
  170. proc_mkdir("capi/controllers", NULL);
  171. proc_create_seq("capi/controller", 0, NULL, &seq_controller_ops);
  172. proc_create_seq("capi/contrstats", 0, NULL, &seq_contrstats_ops);
  173. proc_create_seq("capi/applications", 0, NULL, &seq_applications_ops);
  174. proc_create_seq("capi/applstats", 0, NULL, &seq_applstats_ops);
  175. proc_create("capi/driver", 0, NULL, &empty_proc_ops);
  176. }
  177. void
  178. kcapi_proc_exit(void)
  179. {
  180. remove_proc_entry("capi/driver", NULL);
  181. remove_proc_entry("capi/controller", NULL);
  182. remove_proc_entry("capi/contrstats", NULL);
  183. remove_proc_entry("capi/applications", NULL);
  184. remove_proc_entry("capi/applstats", NULL);
  185. remove_proc_entry("capi/controllers", NULL);
  186. remove_proc_entry("capi", NULL);
  187. }