divasproc.c 11 KB

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