divasproc.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. /* $Id: divasproc.c,v 1.19.4.3 2005/01/31 12:22:20 armin Exp $
  2. *
  3. * Low level driver for Eicon DIVA Server ISDN cards.
  4. * /proc functions
  5. *
  6. * Copyright 2000-2003 by Armin Schindler (mac@melware.de)
  7. * Copyright 2000-2003 Cytronics & Melware (info@melware.de)
  8. *
  9. * This software may be used and distributed according to the terms
  10. * of the GNU General Public License, incorporated herein by reference.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/kernel.h>
  14. #include <linux/poll.h>
  15. #include <linux/proc_fs.h>
  16. #include <linux/seq_file.h>
  17. #include <linux/list.h>
  18. #include <asm/uaccess.h>
  19. #include "platform.h"
  20. #include "debuglib.h"
  21. #undef ID_MASK
  22. #undef N_DATA
  23. #include "pc.h"
  24. #include "di_defs.h"
  25. #include "divasync.h"
  26. #include "di.h"
  27. #include "io.h"
  28. #include "xdi_msg.h"
  29. #include "xdi_adapter.h"
  30. #include "diva.h"
  31. #include "diva_pci.h"
  32. extern PISDN_ADAPTER IoAdapters[MAX_ADAPTER];
  33. extern void divas_get_version(char *);
  34. extern void diva_get_vserial_number(PISDN_ADAPTER IoAdapter, char *buf);
  35. /*********************************************************
  36. ** Functions for /proc interface / File operations
  37. *********************************************************/
  38. static char *divas_proc_name = "divas";
  39. static char *adapter_dir_name = "adapter";
  40. static char *info_proc_name = "info";
  41. static char *grp_opt_proc_name = "group_optimization";
  42. static char *d_l1_down_proc_name = "dynamic_l1_down";
  43. /*
  44. ** "divas" entry
  45. */
  46. extern struct proc_dir_entry *proc_net_eicon;
  47. static struct proc_dir_entry *divas_proc_entry = NULL;
  48. static ssize_t
  49. divas_read(struct file *file, char __user *buf, size_t count, loff_t *off)
  50. {
  51. int len = 0;
  52. int cadapter;
  53. char tmpbuf[80];
  54. char tmpser[16];
  55. if (*off)
  56. return 0;
  57. divas_get_version(tmpbuf);
  58. if (copy_to_user(buf + len, &tmpbuf, strlen(tmpbuf)))
  59. return -EFAULT;
  60. len += strlen(tmpbuf);
  61. for (cadapter = 0; cadapter < MAX_ADAPTER; cadapter++) {
  62. if (IoAdapters[cadapter]) {
  63. diva_get_vserial_number(IoAdapters[cadapter],
  64. tmpser);
  65. sprintf(tmpbuf,
  66. "%2d: %-30s Serial:%-10s IRQ:%2d\n",
  67. cadapter + 1,
  68. IoAdapters[cadapter]->Properties.Name,
  69. tmpser,
  70. IoAdapters[cadapter]->irq_info.irq_nr);
  71. if ((strlen(tmpbuf) + len) > count)
  72. break;
  73. if (copy_to_user
  74. (buf + len, &tmpbuf,
  75. strlen(tmpbuf))) return -EFAULT;
  76. len += strlen(tmpbuf);
  77. }
  78. }
  79. *off += len;
  80. return (len);
  81. }
  82. static ssize_t
  83. divas_write(struct file *file, const char __user *buf, size_t count, loff_t *off)
  84. {
  85. return (-ENODEV);
  86. }
  87. static unsigned int divas_poll(struct file *file, poll_table *wait)
  88. {
  89. return (POLLERR);
  90. }
  91. static int divas_open(struct inode *inode, struct file *file)
  92. {
  93. return nonseekable_open(inode, file);
  94. }
  95. static int divas_close(struct inode *inode, struct file *file)
  96. {
  97. return (0);
  98. }
  99. static const struct file_operations divas_fops = {
  100. .owner = THIS_MODULE,
  101. .llseek = no_llseek,
  102. .read = divas_read,
  103. .write = divas_write,
  104. .poll = divas_poll,
  105. .open = divas_open,
  106. .release = divas_close
  107. };
  108. int create_divas_proc(void)
  109. {
  110. divas_proc_entry = proc_create(divas_proc_name, S_IFREG | S_IRUGO,
  111. proc_net_eicon, &divas_fops);
  112. if (!divas_proc_entry)
  113. return (0);
  114. return (1);
  115. }
  116. void remove_divas_proc(void)
  117. {
  118. if (divas_proc_entry) {
  119. remove_proc_entry(divas_proc_name, proc_net_eicon);
  120. divas_proc_entry = NULL;
  121. }
  122. }
  123. static ssize_t grp_opt_proc_write(struct file *file, const char __user *buffer,
  124. size_t count, loff_t *pos)
  125. {
  126. diva_os_xdi_adapter_t *a = PDE_DATA(file_inode(file));
  127. PISDN_ADAPTER IoAdapter = IoAdapters[a->controller - 1];
  128. if ((count == 1) || (count == 2)) {
  129. char c;
  130. if (get_user(c, buffer))
  131. return -EFAULT;
  132. switch (c) {
  133. case '0':
  134. IoAdapter->capi_cfg.cfg_1 &=
  135. ~DIVA_XDI_CAPI_CFG_1_GROUP_POPTIMIZATION_ON;
  136. break;
  137. case '1':
  138. IoAdapter->capi_cfg.cfg_1 |=
  139. DIVA_XDI_CAPI_CFG_1_GROUP_POPTIMIZATION_ON;
  140. break;
  141. default:
  142. return (-EINVAL);
  143. }
  144. return (count);
  145. }
  146. return (-EINVAL);
  147. }
  148. static ssize_t d_l1_down_proc_write(struct file *file, const char __user *buffer,
  149. size_t count, loff_t *pos)
  150. {
  151. diva_os_xdi_adapter_t *a = PDE_DATA(file_inode(file));
  152. PISDN_ADAPTER IoAdapter = IoAdapters[a->controller - 1];
  153. if ((count == 1) || (count == 2)) {
  154. char c;
  155. if (get_user(c, buffer))
  156. return -EFAULT;
  157. switch (c) {
  158. case '0':
  159. IoAdapter->capi_cfg.cfg_1 &=
  160. ~DIVA_XDI_CAPI_CFG_1_DYNAMIC_L1_ON;
  161. break;
  162. case '1':
  163. IoAdapter->capi_cfg.cfg_1 |=
  164. DIVA_XDI_CAPI_CFG_1_DYNAMIC_L1_ON;
  165. break;
  166. default:
  167. return (-EINVAL);
  168. }
  169. return (count);
  170. }
  171. return (-EINVAL);
  172. }
  173. static int d_l1_down_proc_show(struct seq_file *m, void *v)
  174. {
  175. diva_os_xdi_adapter_t *a = m->private;
  176. PISDN_ADAPTER IoAdapter = IoAdapters[a->controller - 1];
  177. seq_printf(m, "%s\n",
  178. (IoAdapter->capi_cfg.
  179. cfg_1 & DIVA_XDI_CAPI_CFG_1_DYNAMIC_L1_ON) ? "1" :
  180. "0");
  181. return 0;
  182. }
  183. static int d_l1_down_proc_open(struct inode *inode, struct file *file)
  184. {
  185. return single_open(file, d_l1_down_proc_show, PDE_DATA(inode));
  186. }
  187. static const struct file_operations d_l1_down_proc_fops = {
  188. .owner = THIS_MODULE,
  189. .open = d_l1_down_proc_open,
  190. .read = seq_read,
  191. .llseek = seq_lseek,
  192. .release = single_release,
  193. .write = d_l1_down_proc_write,
  194. };
  195. static int grp_opt_proc_show(struct seq_file *m, void *v)
  196. {
  197. diva_os_xdi_adapter_t *a = m->private;
  198. PISDN_ADAPTER IoAdapter = IoAdapters[a->controller - 1];
  199. seq_printf(m, "%s\n",
  200. (IoAdapter->capi_cfg.
  201. cfg_1 & DIVA_XDI_CAPI_CFG_1_GROUP_POPTIMIZATION_ON)
  202. ? "1" : "0");
  203. return 0;
  204. }
  205. static int grp_opt_proc_open(struct inode *inode, struct file *file)
  206. {
  207. return single_open(file, grp_opt_proc_show, PDE_DATA(inode));
  208. }
  209. static const struct file_operations grp_opt_proc_fops = {
  210. .owner = THIS_MODULE,
  211. .open = grp_opt_proc_open,
  212. .read = seq_read,
  213. .llseek = seq_lseek,
  214. .release = single_release,
  215. .write = grp_opt_proc_write,
  216. };
  217. static ssize_t info_proc_write(struct file *file, const char __user *buffer,
  218. size_t count, loff_t *pos)
  219. {
  220. diva_os_xdi_adapter_t *a = PDE_DATA(file_inode(file));
  221. PISDN_ADAPTER IoAdapter = IoAdapters[a->controller - 1];
  222. char c[4];
  223. if (count <= 4)
  224. return -EINVAL;
  225. if (copy_from_user(c, buffer, 4))
  226. return -EFAULT;
  227. /* this is for test purposes only */
  228. if (!memcmp(c, "trap", 4)) {
  229. (*(IoAdapter->os_trap_nfy_Fnc)) (IoAdapter, IoAdapter->ANum);
  230. return (count);
  231. }
  232. return (-EINVAL);
  233. }
  234. static int info_proc_show(struct seq_file *m, void *v)
  235. {
  236. int i = 0;
  237. char *p;
  238. char tmpser[16];
  239. diva_os_xdi_adapter_t *a = m->private;
  240. PISDN_ADAPTER IoAdapter = IoAdapters[a->controller - 1];
  241. seq_printf(m, "Name : %s\n", IoAdapter->Properties.Name);
  242. seq_printf(m, "DSP state : %08x\n", a->dsp_mask);
  243. seq_printf(m, "Channels : %02d\n", IoAdapter->Properties.Channels);
  244. seq_printf(m, "E. max/used : %03d/%03d\n",
  245. IoAdapter->e_max, IoAdapter->e_count);
  246. diva_get_vserial_number(IoAdapter, tmpser);
  247. seq_printf(m, "Serial : %s\n", tmpser);
  248. seq_printf(m, "IRQ : %d\n", IoAdapter->irq_info.irq_nr);
  249. seq_printf(m, "CardIndex : %d\n", a->CardIndex);
  250. seq_printf(m, "CardOrdinal : %d\n", a->CardOrdinal);
  251. seq_printf(m, "Controller : %d\n", a->controller);
  252. seq_printf(m, "Bus-Type : %s\n",
  253. (a->Bus ==
  254. DIVAS_XDI_ADAPTER_BUS_ISA) ? "ISA" : "PCI");
  255. seq_printf(m, "Port-Name : %s\n", a->port_name);
  256. if (a->Bus == DIVAS_XDI_ADAPTER_BUS_PCI) {
  257. seq_printf(m, "PCI-bus : %d\n", a->resources.pci.bus);
  258. seq_printf(m, "PCI-func : %d\n", a->resources.pci.func);
  259. for (i = 0; i < 8; i++) {
  260. if (a->resources.pci.bar[i]) {
  261. seq_printf(m,
  262. "Mem / I/O %d : 0x%x / mapped : 0x%lx",
  263. i, a->resources.pci.bar[i],
  264. (unsigned long) a->resources.
  265. pci.addr[i]);
  266. if (a->resources.pci.length[i]) {
  267. seq_printf(m,
  268. " / length : %d",
  269. a->resources.pci.
  270. length[i]);
  271. }
  272. seq_putc(m, '\n');
  273. }
  274. }
  275. }
  276. if ((!a->xdi_adapter.port) &&
  277. ((!a->xdi_adapter.ram) ||
  278. (!a->xdi_adapter.reset)
  279. || (!a->xdi_adapter.cfg))) {
  280. if (!IoAdapter->irq_info.irq_nr) {
  281. p = "slave";
  282. } else {
  283. p = "out of service";
  284. }
  285. } else if (a->xdi_adapter.trapped) {
  286. p = "trapped";
  287. } else if (a->xdi_adapter.Initialized) {
  288. p = "active";
  289. } else {
  290. p = "ready";
  291. }
  292. seq_printf(m, "State : %s\n", p);
  293. return 0;
  294. }
  295. static int info_proc_open(struct inode *inode, struct file *file)
  296. {
  297. return single_open(file, info_proc_show, PDE_DATA(inode));
  298. }
  299. static const struct file_operations info_proc_fops = {
  300. .owner = THIS_MODULE,
  301. .open = info_proc_open,
  302. .read = seq_read,
  303. .llseek = seq_lseek,
  304. .release = single_release,
  305. .write = info_proc_write,
  306. };
  307. /*
  308. ** adapter proc init/de-init
  309. */
  310. /* --------------------------------------------------------------------------
  311. Create adapter directory and files in proc file system
  312. -------------------------------------------------------------------------- */
  313. int create_adapter_proc(diva_os_xdi_adapter_t *a)
  314. {
  315. struct proc_dir_entry *de, *pe;
  316. char tmp[16];
  317. sprintf(tmp, "%s%d", adapter_dir_name, a->controller);
  318. if (!(de = proc_mkdir(tmp, proc_net_eicon)))
  319. return (0);
  320. a->proc_adapter_dir = (void *) de;
  321. pe = proc_create_data(info_proc_name, S_IRUGO | S_IWUSR, de,
  322. &info_proc_fops, a);
  323. if (!pe)
  324. return (0);
  325. a->proc_info = (void *) pe;
  326. pe = proc_create_data(grp_opt_proc_name, S_IRUGO | S_IWUSR, de,
  327. &grp_opt_proc_fops, a);
  328. if (pe)
  329. a->proc_grp_opt = (void *) pe;
  330. pe = proc_create_data(d_l1_down_proc_name, S_IRUGO | S_IWUSR, de,
  331. &d_l1_down_proc_fops, a);
  332. if (pe)
  333. a->proc_d_l1_down = (void *) pe;
  334. DBG_TRC(("proc entry %s created", tmp));
  335. return (1);
  336. }
  337. /* --------------------------------------------------------------------------
  338. Remove adapter directory and files in proc file system
  339. -------------------------------------------------------------------------- */
  340. void remove_adapter_proc(diva_os_xdi_adapter_t *a)
  341. {
  342. char tmp[16];
  343. if (a->proc_adapter_dir) {
  344. if (a->proc_d_l1_down) {
  345. remove_proc_entry(d_l1_down_proc_name,
  346. (struct proc_dir_entry *) a->proc_adapter_dir);
  347. }
  348. if (a->proc_grp_opt) {
  349. remove_proc_entry(grp_opt_proc_name,
  350. (struct proc_dir_entry *) a->proc_adapter_dir);
  351. }
  352. if (a->proc_info) {
  353. remove_proc_entry(info_proc_name,
  354. (struct proc_dir_entry *) a->proc_adapter_dir);
  355. }
  356. sprintf(tmp, "%s%d", adapter_dir_name, a->controller);
  357. remove_proc_entry(tmp, proc_net_eicon);
  358. DBG_TRC(("proc entry %s%d removed", adapter_dir_name,
  359. a->controller));
  360. }
  361. }