divasproc.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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/config.h>
  13. #include <linux/module.h>
  14. #include <linux/kernel.h>
  15. #include <linux/poll.h>
  16. #include <linux/proc_fs.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 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 = create_proc_entry(divas_proc_name,
  111. S_IFREG | S_IRUGO,
  112. proc_net_eicon);
  113. if (!divas_proc_entry)
  114. return (0);
  115. divas_proc_entry->proc_fops = &divas_fops;
  116. divas_proc_entry->owner = THIS_MODULE;
  117. return (1);
  118. }
  119. void remove_divas_proc(void)
  120. {
  121. if (divas_proc_entry) {
  122. remove_proc_entry(divas_proc_name, proc_net_eicon);
  123. divas_proc_entry = NULL;
  124. }
  125. }
  126. /*
  127. ** write group_optimization
  128. */
  129. static int
  130. write_grp_opt(struct file *file, const char __user *buffer, unsigned long count,
  131. void *data)
  132. {
  133. diva_os_xdi_adapter_t *a = (diva_os_xdi_adapter_t *) data;
  134. PISDN_ADAPTER IoAdapter = IoAdapters[a->controller - 1];
  135. if ((count == 1) || (count == 2)) {
  136. char c;
  137. if (get_user(c, buffer))
  138. return -EFAULT;
  139. switch (c) {
  140. case '0':
  141. IoAdapter->capi_cfg.cfg_1 &=
  142. ~DIVA_XDI_CAPI_CFG_1_GROUP_POPTIMIZATION_ON;
  143. break;
  144. case '1':
  145. IoAdapter->capi_cfg.cfg_1 |=
  146. DIVA_XDI_CAPI_CFG_1_GROUP_POPTIMIZATION_ON;
  147. break;
  148. default:
  149. return (-EINVAL);
  150. }
  151. return (count);
  152. }
  153. return (-EINVAL);
  154. }
  155. /*
  156. ** write dynamic_l1_down
  157. */
  158. static int
  159. write_d_l1_down(struct file *file, const char __user *buffer, unsigned long count,
  160. void *data)
  161. {
  162. diva_os_xdi_adapter_t *a = (diva_os_xdi_adapter_t *) data;
  163. PISDN_ADAPTER IoAdapter = IoAdapters[a->controller - 1];
  164. if ((count == 1) || (count == 2)) {
  165. char c;
  166. if (get_user(c, buffer))
  167. return -EFAULT;
  168. switch (c) {
  169. case '0':
  170. IoAdapter->capi_cfg.cfg_1 &=
  171. ~DIVA_XDI_CAPI_CFG_1_DYNAMIC_L1_ON;
  172. break;
  173. case '1':
  174. IoAdapter->capi_cfg.cfg_1 |=
  175. DIVA_XDI_CAPI_CFG_1_DYNAMIC_L1_ON;
  176. break;
  177. default:
  178. return (-EINVAL);
  179. }
  180. return (count);
  181. }
  182. return (-EINVAL);
  183. }
  184. /*
  185. ** read dynamic_l1_down
  186. */
  187. static int
  188. read_d_l1_down(char *page, char **start, off_t off, int count, int *eof,
  189. void *data)
  190. {
  191. int len = 0;
  192. diva_os_xdi_adapter_t *a = (diva_os_xdi_adapter_t *) data;
  193. PISDN_ADAPTER IoAdapter = IoAdapters[a->controller - 1];
  194. len += sprintf(page + len, "%s\n",
  195. (IoAdapter->capi_cfg.
  196. cfg_1 & DIVA_XDI_CAPI_CFG_1_DYNAMIC_L1_ON) ? "1" :
  197. "0");
  198. if (off + count >= len)
  199. *eof = 1;
  200. if (len < off)
  201. return 0;
  202. *start = page + off;
  203. return ((count < len - off) ? count : len - off);
  204. }
  205. /*
  206. ** read group_optimization
  207. */
  208. static int
  209. read_grp_opt(char *page, char **start, off_t off, int count, int *eof,
  210. void *data)
  211. {
  212. int len = 0;
  213. diva_os_xdi_adapter_t *a = (diva_os_xdi_adapter_t *) data;
  214. PISDN_ADAPTER IoAdapter = IoAdapters[a->controller - 1];
  215. len += sprintf(page + len, "%s\n",
  216. (IoAdapter->capi_cfg.
  217. cfg_1 & DIVA_XDI_CAPI_CFG_1_GROUP_POPTIMIZATION_ON)
  218. ? "1" : "0");
  219. if (off + count >= len)
  220. *eof = 1;
  221. if (len < off)
  222. return 0;
  223. *start = page + off;
  224. return ((count < len - off) ? count : len - off);
  225. }
  226. /*
  227. ** info write
  228. */
  229. static int
  230. info_write(struct file *file, const char __user *buffer, unsigned long count,
  231. void *data)
  232. {
  233. diva_os_xdi_adapter_t *a = (diva_os_xdi_adapter_t *) data;
  234. PISDN_ADAPTER IoAdapter = IoAdapters[a->controller - 1];
  235. char c[4];
  236. if (count <= 4)
  237. return -EINVAL;
  238. if (copy_from_user(c, buffer, 4))
  239. return -EFAULT;
  240. /* this is for test purposes only */
  241. if (!memcmp(c, "trap", 4)) {
  242. (*(IoAdapter->os_trap_nfy_Fnc)) (IoAdapter, IoAdapter->ANum);
  243. return (count);
  244. }
  245. return (-EINVAL);
  246. }
  247. /*
  248. ** info read
  249. */
  250. static int
  251. info_read(char *page, char **start, off_t off, int count, int *eof,
  252. void *data)
  253. {
  254. int i = 0;
  255. int len = 0;
  256. char *p;
  257. char tmpser[16];
  258. diva_os_xdi_adapter_t *a = (diva_os_xdi_adapter_t *) data;
  259. PISDN_ADAPTER IoAdapter = IoAdapters[a->controller - 1];
  260. len +=
  261. sprintf(page + len, "Name : %s\n",
  262. IoAdapter->Properties.Name);
  263. len += sprintf(page + len, "DSP state : %08x\n", a->dsp_mask);
  264. len += sprintf(page + len, "Channels : %02d\n",
  265. IoAdapter->Properties.Channels);
  266. len += sprintf(page + len, "E. max/used : %03d/%03d\n",
  267. IoAdapter->e_max, IoAdapter->e_count);
  268. diva_get_vserial_number(IoAdapter, tmpser);
  269. len += sprintf(page + len, "Serial : %s\n", tmpser);
  270. len +=
  271. sprintf(page + len, "IRQ : %d\n",
  272. IoAdapter->irq_info.irq_nr);
  273. len += sprintf(page + len, "CardIndex : %d\n", a->CardIndex);
  274. len += sprintf(page + len, "CardOrdinal : %d\n", a->CardOrdinal);
  275. len += sprintf(page + len, "Controller : %d\n", a->controller);
  276. len += sprintf(page + len, "Bus-Type : %s\n",
  277. (a->Bus ==
  278. DIVAS_XDI_ADAPTER_BUS_ISA) ? "ISA" : "PCI");
  279. len += sprintf(page + len, "Port-Name : %s\n", a->port_name);
  280. if (a->Bus == DIVAS_XDI_ADAPTER_BUS_PCI) {
  281. len +=
  282. sprintf(page + len, "PCI-bus : %d\n",
  283. a->resources.pci.bus);
  284. len +=
  285. sprintf(page + len, "PCI-func : %d\n",
  286. a->resources.pci.func);
  287. for (i = 0; i < 8; i++) {
  288. if (a->resources.pci.bar[i]) {
  289. len +=
  290. sprintf(page + len,
  291. "Mem / I/O %d : 0x%x / mapped : 0x%lx",
  292. i, a->resources.pci.bar[i],
  293. (unsigned long) a->resources.
  294. pci.addr[i]);
  295. if (a->resources.pci.length[i]) {
  296. len +=
  297. sprintf(page + len,
  298. " / length : %d",
  299. a->resources.pci.
  300. length[i]);
  301. }
  302. len += sprintf(page + len, "\n");
  303. }
  304. }
  305. }
  306. if ((!a->xdi_adapter.port) &&
  307. ((!a->xdi_adapter.ram) ||
  308. (!a->xdi_adapter.reset)
  309. || (!a->xdi_adapter.cfg))) {
  310. if (!IoAdapter->irq_info.irq_nr) {
  311. p = "slave";
  312. } else {
  313. p = "out of service";
  314. }
  315. } else if (a->xdi_adapter.trapped) {
  316. p = "trapped";
  317. } else if (a->xdi_adapter.Initialized) {
  318. p = "active";
  319. } else {
  320. p = "ready";
  321. }
  322. len += sprintf(page + len, "State : %s\n", p);
  323. if (off + count >= len)
  324. *eof = 1;
  325. if (len < off)
  326. return 0;
  327. *start = page + off;
  328. return ((count < len - off) ? count : len - off);
  329. }
  330. /*
  331. ** adapter proc init/de-init
  332. */
  333. /* --------------------------------------------------------------------------
  334. Create adapter directory and files in proc file system
  335. -------------------------------------------------------------------------- */
  336. int create_adapter_proc(diva_os_xdi_adapter_t * a)
  337. {
  338. struct proc_dir_entry *de, *pe;
  339. char tmp[16];
  340. sprintf(tmp, "%s%d", adapter_dir_name, a->controller);
  341. if (!(de = proc_mkdir(tmp, proc_net_eicon)))
  342. return (0);
  343. a->proc_adapter_dir = (void *) de;
  344. if (!(pe =
  345. create_proc_entry(info_proc_name, S_IFREG | S_IRUGO | S_IWUSR, de)))
  346. return (0);
  347. a->proc_info = (void *) pe;
  348. pe->write_proc = info_write;
  349. pe->read_proc = info_read;
  350. pe->data = a;
  351. if ((pe = create_proc_entry(grp_opt_proc_name,
  352. S_IFREG | S_IRUGO | S_IWUSR, de))) {
  353. a->proc_grp_opt = (void *) pe;
  354. pe->write_proc = write_grp_opt;
  355. pe->read_proc = read_grp_opt;
  356. pe->data = a;
  357. }
  358. if ((pe = create_proc_entry(d_l1_down_proc_name,
  359. S_IFREG | S_IRUGO | S_IWUSR, de))) {
  360. a->proc_d_l1_down = (void *) pe;
  361. pe->write_proc = write_d_l1_down;
  362. pe->read_proc = read_d_l1_down;
  363. pe->data = a;
  364. }
  365. DBG_TRC(("proc entry %s created", tmp));
  366. return (1);
  367. }
  368. /* --------------------------------------------------------------------------
  369. Remove adapter directory and files in proc file system
  370. -------------------------------------------------------------------------- */
  371. void remove_adapter_proc(diva_os_xdi_adapter_t * a)
  372. {
  373. char tmp[16];
  374. if (a->proc_adapter_dir) {
  375. if (a->proc_d_l1_down) {
  376. remove_proc_entry(d_l1_down_proc_name,
  377. (struct proc_dir_entry *) a->proc_adapter_dir);
  378. }
  379. if (a->proc_grp_opt) {
  380. remove_proc_entry(grp_opt_proc_name,
  381. (struct proc_dir_entry *) a->proc_adapter_dir);
  382. }
  383. if (a->proc_info) {
  384. remove_proc_entry(info_proc_name,
  385. (struct proc_dir_entry *) a->proc_adapter_dir);
  386. }
  387. sprintf(tmp, "%s%d", adapter_dir_name, a->controller);
  388. remove_proc_entry(tmp, proc_net_eicon);
  389. DBG_TRC(("proc entry %s%d removed", adapter_dir_name,
  390. a->controller));
  391. }
  392. }