divasproc.c 11 KB

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