kcapi_proc.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. /*
  2. * Kernel CAPI 2.0 Module - /proc/capi handling
  3. *
  4. * Copyright 1999 by Carsten Paeth <calle@calle.de>
  5. * Copyright 2002 by Kai Germaschewski <kai@germaschewski.name>
  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. static int seq_controller_open(struct inode *inode, struct file *file)
  90. {
  91. return seq_open(file, &seq_controller_ops);
  92. }
  93. static int seq_contrstats_open(struct inode *inode, struct file *file)
  94. {
  95. return seq_open(file, &seq_contrstats_ops);
  96. }
  97. static const struct file_operations proc_controller_ops = {
  98. .owner = THIS_MODULE,
  99. .open = seq_controller_open,
  100. .read = seq_read,
  101. .llseek = seq_lseek,
  102. .release = seq_release,
  103. };
  104. static const struct file_operations proc_contrstats_ops = {
  105. .owner = THIS_MODULE,
  106. .open = seq_contrstats_open,
  107. .read = seq_read,
  108. .llseek = seq_lseek,
  109. .release = seq_release,
  110. };
  111. // /proc/capi/applications:
  112. // applid l3cnt dblkcnt dblklen #ncci recvqueuelen
  113. // /proc/capi/applstats:
  114. // applid nrecvctlpkt nrecvdatapkt nsentctlpkt nsentdatapkt
  115. // ---------------------------------------------------------------------------
  116. static void *applications_start(struct seq_file *seq, loff_t *pos)
  117. __acquires(capi_controller_lock)
  118. {
  119. mutex_lock(&capi_controller_lock);
  120. if (*pos < CAPI_MAXAPPL)
  121. return &capi_applications[*pos];
  122. return NULL;
  123. }
  124. static void *
  125. applications_next(struct seq_file *seq, void *v, loff_t *pos)
  126. {
  127. ++*pos;
  128. if (*pos < CAPI_MAXAPPL)
  129. return &capi_applications[*pos];
  130. return NULL;
  131. }
  132. static void applications_stop(struct seq_file *seq, void *v)
  133. __releases(capi_controller_lock)
  134. {
  135. mutex_unlock(&capi_controller_lock);
  136. }
  137. static int
  138. applications_show(struct seq_file *seq, void *v)
  139. {
  140. struct capi20_appl *ap = *(struct capi20_appl **) v;
  141. if (!ap)
  142. return 0;
  143. seq_printf(seq, "%u %d %d %d\n",
  144. ap->applid,
  145. ap->rparam.level3cnt,
  146. ap->rparam.datablkcnt,
  147. ap->rparam.datablklen);
  148. return 0;
  149. }
  150. static int
  151. applstats_show(struct seq_file *seq, void *v)
  152. {
  153. struct capi20_appl *ap = *(struct capi20_appl **) v;
  154. if (!ap)
  155. return 0;
  156. seq_printf(seq, "%u %lu %lu %lu %lu\n",
  157. ap->applid,
  158. ap->nrecvctlpkt,
  159. ap->nrecvdatapkt,
  160. ap->nsentctlpkt,
  161. ap->nsentdatapkt);
  162. return 0;
  163. }
  164. static const struct seq_operations seq_applications_ops = {
  165. .start = applications_start,
  166. .next = applications_next,
  167. .stop = applications_stop,
  168. .show = applications_show,
  169. };
  170. static const struct seq_operations seq_applstats_ops = {
  171. .start = applications_start,
  172. .next = applications_next,
  173. .stop = applications_stop,
  174. .show = applstats_show,
  175. };
  176. static int
  177. seq_applications_open(struct inode *inode, struct file *file)
  178. {
  179. return seq_open(file, &seq_applications_ops);
  180. }
  181. static int
  182. seq_applstats_open(struct inode *inode, struct file *file)
  183. {
  184. return seq_open(file, &seq_applstats_ops);
  185. }
  186. static const struct file_operations proc_applications_ops = {
  187. .owner = THIS_MODULE,
  188. .open = seq_applications_open,
  189. .read = seq_read,
  190. .llseek = seq_lseek,
  191. .release = seq_release,
  192. };
  193. static const struct file_operations proc_applstats_ops = {
  194. .owner = THIS_MODULE,
  195. .open = seq_applstats_open,
  196. .read = seq_read,
  197. .llseek = seq_lseek,
  198. .release = seq_release,
  199. };
  200. // ---------------------------------------------------------------------------
  201. static void *capi_driver_start(struct seq_file *seq, loff_t *pos)
  202. __acquires(&capi_drivers_lock)
  203. {
  204. mutex_lock(&capi_drivers_lock);
  205. return seq_list_start(&capi_drivers, *pos);
  206. }
  207. static void *capi_driver_next(struct seq_file *seq, void *v, loff_t *pos)
  208. {
  209. return seq_list_next(v, &capi_drivers, pos);
  210. }
  211. static void capi_driver_stop(struct seq_file *seq, void *v)
  212. __releases(&capi_drivers_lock)
  213. {
  214. mutex_unlock(&capi_drivers_lock);
  215. }
  216. static int capi_driver_show(struct seq_file *seq, void *v)
  217. {
  218. struct capi_driver *drv = list_entry(v, struct capi_driver, list);
  219. seq_printf(seq, "%-32s %s\n", drv->name, drv->revision);
  220. return 0;
  221. }
  222. static const struct seq_operations seq_capi_driver_ops = {
  223. .start = capi_driver_start,
  224. .next = capi_driver_next,
  225. .stop = capi_driver_stop,
  226. .show = capi_driver_show,
  227. };
  228. static int
  229. seq_capi_driver_open(struct inode *inode, struct file *file)
  230. {
  231. int err;
  232. err = seq_open(file, &seq_capi_driver_ops);
  233. return err;
  234. }
  235. static const struct file_operations proc_driver_ops = {
  236. .owner = THIS_MODULE,
  237. .open = seq_capi_driver_open,
  238. .read = seq_read,
  239. .llseek = seq_lseek,
  240. .release = seq_release,
  241. };
  242. // ---------------------------------------------------------------------------
  243. void __init
  244. kcapi_proc_init(void)
  245. {
  246. proc_mkdir("capi", NULL);
  247. proc_mkdir("capi/controllers", NULL);
  248. proc_create("capi/controller", 0, NULL, &proc_controller_ops);
  249. proc_create("capi/contrstats", 0, NULL, &proc_contrstats_ops);
  250. proc_create("capi/applications", 0, NULL, &proc_applications_ops);
  251. proc_create("capi/applstats", 0, NULL, &proc_applstats_ops);
  252. proc_create("capi/driver", 0, NULL, &proc_driver_ops);
  253. }
  254. void __exit
  255. kcapi_proc_exit(void)
  256. {
  257. remove_proc_entry("capi/driver", NULL);
  258. remove_proc_entry("capi/controller", NULL);
  259. remove_proc_entry("capi/contrstats", NULL);
  260. remove_proc_entry("capi/applications", NULL);
  261. remove_proc_entry("capi/applstats", NULL);
  262. remove_proc_entry("capi/controllers", NULL);
  263. remove_proc_entry("capi", NULL);
  264. }