kcapi_proc.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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. static char *
  16. cardstate2str(unsigned short cardstate)
  17. {
  18. switch (cardstate) {
  19. case CARD_DETECTED: return "detected";
  20. case CARD_LOADING: return "loading";
  21. case CARD_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. {
  34. if (*pos < CAPI_MAXCONTR)
  35. return &capi_cards[*pos];
  36. return NULL;
  37. }
  38. static void *controller_next(struct seq_file *seq, void *v, loff_t *pos)
  39. {
  40. ++*pos;
  41. if (*pos < CAPI_MAXCONTR)
  42. return &capi_cards[*pos];
  43. return NULL;
  44. }
  45. static void controller_stop(struct seq_file *seq, void *v)
  46. {
  47. }
  48. static int controller_show(struct seq_file *seq, void *v)
  49. {
  50. struct capi_ctr *ctr = *(struct capi_ctr **) v;
  51. if (!ctr)
  52. return 0;
  53. seq_printf(seq, "%d %-10s %-8s %-16s %s\n",
  54. ctr->cnr, ctr->driver_name,
  55. cardstate2str(ctr->cardstate),
  56. ctr->name,
  57. ctr->procinfo ? ctr->procinfo(ctr) : "");
  58. return 0;
  59. }
  60. static int contrstats_show(struct seq_file *seq, void *v)
  61. {
  62. struct capi_ctr *ctr = *(struct capi_ctr **) v;
  63. if (!ctr)
  64. return 0;
  65. seq_printf(seq, "%d %lu %lu %lu %lu\n",
  66. ctr->cnr,
  67. ctr->nrecvctlpkt,
  68. ctr->nrecvdatapkt,
  69. ctr->nsentctlpkt,
  70. ctr->nsentdatapkt);
  71. return 0;
  72. }
  73. static struct seq_operations seq_controller_ops = {
  74. .start = controller_start,
  75. .next = controller_next,
  76. .stop = controller_stop,
  77. .show = controller_show,
  78. };
  79. static struct seq_operations seq_contrstats_ops = {
  80. .start = controller_start,
  81. .next = controller_next,
  82. .stop = controller_stop,
  83. .show = contrstats_show,
  84. };
  85. static int seq_controller_open(struct inode *inode, struct file *file)
  86. {
  87. return seq_open(file, &seq_controller_ops);
  88. }
  89. static int seq_contrstats_open(struct inode *inode, struct file *file)
  90. {
  91. return seq_open(file, &seq_contrstats_ops);
  92. }
  93. static struct file_operations proc_controller_ops = {
  94. .open = seq_controller_open,
  95. .read = seq_read,
  96. .llseek = seq_lseek,
  97. .release = seq_release,
  98. };
  99. static struct file_operations proc_contrstats_ops = {
  100. .open = seq_contrstats_open,
  101. .read = seq_read,
  102. .llseek = seq_lseek,
  103. .release = seq_release,
  104. };
  105. // /proc/capi/applications:
  106. // applid l3cnt dblkcnt dblklen #ncci recvqueuelen
  107. // /proc/capi/applstats:
  108. // applid nrecvctlpkt nrecvdatapkt nsentctlpkt nsentdatapkt
  109. // ---------------------------------------------------------------------------
  110. static void *
  111. applications_start(struct seq_file *seq, loff_t *pos)
  112. {
  113. if (*pos < CAPI_MAXAPPL)
  114. return &capi_applications[*pos];
  115. return NULL;
  116. }
  117. static void *
  118. applications_next(struct seq_file *seq, void *v, loff_t *pos)
  119. {
  120. ++*pos;
  121. if (*pos < CAPI_MAXAPPL)
  122. return &capi_applications[*pos];
  123. return NULL;
  124. }
  125. static void
  126. applications_stop(struct seq_file *seq, void *v)
  127. {
  128. }
  129. static int
  130. applications_show(struct seq_file *seq, void *v)
  131. {
  132. struct capi20_appl *ap = *(struct capi20_appl **) v;
  133. if (!ap)
  134. return 0;
  135. seq_printf(seq, "%u %d %d %d\n",
  136. ap->applid,
  137. ap->rparam.level3cnt,
  138. ap->rparam.datablkcnt,
  139. ap->rparam.datablklen);
  140. return 0;
  141. }
  142. static int
  143. applstats_show(struct seq_file *seq, void *v)
  144. {
  145. struct capi20_appl *ap = *(struct capi20_appl **) v;
  146. if (!ap)
  147. return 0;
  148. seq_printf(seq, "%u %lu %lu %lu %lu\n",
  149. ap->applid,
  150. ap->nrecvctlpkt,
  151. ap->nrecvdatapkt,
  152. ap->nsentctlpkt,
  153. ap->nsentdatapkt);
  154. return 0;
  155. }
  156. static struct seq_operations seq_applications_ops = {
  157. .start = applications_start,
  158. .next = applications_next,
  159. .stop = applications_stop,
  160. .show = applications_show,
  161. };
  162. static struct seq_operations seq_applstats_ops = {
  163. .start = applications_start,
  164. .next = applications_next,
  165. .stop = applications_stop,
  166. .show = applstats_show,
  167. };
  168. static int
  169. seq_applications_open(struct inode *inode, struct file *file)
  170. {
  171. return seq_open(file, &seq_applications_ops);
  172. }
  173. static int
  174. seq_applstats_open(struct inode *inode, struct file *file)
  175. {
  176. return seq_open(file, &seq_applstats_ops);
  177. }
  178. static struct file_operations proc_applications_ops = {
  179. .open = seq_applications_open,
  180. .read = seq_read,
  181. .llseek = seq_lseek,
  182. .release = seq_release,
  183. };
  184. static struct file_operations proc_applstats_ops = {
  185. .open = seq_applstats_open,
  186. .read = seq_read,
  187. .llseek = seq_lseek,
  188. .release = seq_release,
  189. };
  190. static void
  191. create_seq_entry(char *name, mode_t mode, const struct file_operations *f)
  192. {
  193. struct proc_dir_entry *entry;
  194. entry = create_proc_entry(name, mode, NULL);
  195. if (entry)
  196. entry->proc_fops = f;
  197. }
  198. // ---------------------------------------------------------------------------
  199. static __inline__ struct capi_driver *capi_driver_get_idx(loff_t pos)
  200. {
  201. struct capi_driver *drv = NULL;
  202. struct list_head *l;
  203. loff_t i;
  204. i = 0;
  205. list_for_each(l, &capi_drivers) {
  206. drv = list_entry(l, struct capi_driver, list);
  207. if (i++ == pos)
  208. return drv;
  209. }
  210. return NULL;
  211. }
  212. static void *capi_driver_start(struct seq_file *seq, loff_t *pos)
  213. {
  214. struct capi_driver *drv;
  215. read_lock(&capi_drivers_list_lock);
  216. drv = capi_driver_get_idx(*pos);
  217. return drv;
  218. }
  219. static void *capi_driver_next(struct seq_file *seq, void *v, loff_t *pos)
  220. {
  221. struct capi_driver *drv = (struct capi_driver *)v;
  222. ++*pos;
  223. if (drv->list.next == &capi_drivers) return NULL;
  224. return list_entry(drv->list.next, struct capi_driver, list);
  225. }
  226. static void capi_driver_stop(struct seq_file *seq, void *v)
  227. {
  228. read_unlock(&capi_drivers_list_lock);
  229. }
  230. static int capi_driver_show(struct seq_file *seq, void *v)
  231. {
  232. struct capi_driver *drv = (struct capi_driver *)v;
  233. seq_printf(seq, "%-32s %s\n", drv->name, drv->revision);
  234. return 0;
  235. }
  236. static struct seq_operations seq_capi_driver_ops = {
  237. .start = capi_driver_start,
  238. .next = capi_driver_next,
  239. .stop = capi_driver_stop,
  240. .show = capi_driver_show,
  241. };
  242. static int
  243. seq_capi_driver_open(struct inode *inode, struct file *file)
  244. {
  245. int err;
  246. err = seq_open(file, &seq_capi_driver_ops);
  247. return err;
  248. }
  249. static struct file_operations proc_driver_ops = {
  250. .open = seq_capi_driver_open,
  251. .read = seq_read,
  252. .llseek = seq_lseek,
  253. .release = seq_release,
  254. };
  255. // ---------------------------------------------------------------------------
  256. void __init
  257. kcapi_proc_init(void)
  258. {
  259. proc_mkdir("capi", NULL);
  260. proc_mkdir("capi/controllers", NULL);
  261. create_seq_entry("capi/controller", 0, &proc_controller_ops);
  262. create_seq_entry("capi/contrstats", 0, &proc_contrstats_ops);
  263. create_seq_entry("capi/applications", 0, &proc_applications_ops);
  264. create_seq_entry("capi/applstats", 0, &proc_applstats_ops);
  265. create_seq_entry("capi/driver", 0, &proc_driver_ops);
  266. }
  267. void __exit
  268. kcapi_proc_exit(void)
  269. {
  270. remove_proc_entry("capi/driver", NULL);
  271. remove_proc_entry("capi/controller", NULL);
  272. remove_proc_entry("capi/contrstats", NULL);
  273. remove_proc_entry("capi/applications", NULL);
  274. remove_proc_entry("capi/applstats", NULL);
  275. remove_proc_entry("capi/controllers", NULL);
  276. remove_proc_entry("capi", NULL);
  277. }