1 /* $Id: divasproc.c,v 1.19.4.3 2005/01/31 12:22:20 armin Exp $
3 * Low level driver for Eicon DIVA Server ISDN cards.
6 * Copyright 2000-2003 by Armin Schindler (mac@melware.de)
7 * Copyright 2000-2003 Cytronics & Melware (info@melware.de)
9 * This software may be used and distributed according to the terms
10 * of the GNU General Public License, incorporated herein by reference.
13 #include <linux/config.h>
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/poll.h>
17 #include <linux/proc_fs.h>
18 #include <linux/list.h>
19 #include <asm/uaccess.h>
31 #include "xdi_adapter.h"
36 extern PISDN_ADAPTER IoAdapters
[MAX_ADAPTER
];
37 extern void divas_get_version(char *);
38 extern void diva_get_vserial_number(PISDN_ADAPTER IoAdapter
, char *buf
);
40 /*********************************************************
41 ** Functions for /proc interface / File operations
42 *********************************************************/
44 static char *divas_proc_name
= "divas";
45 static char *adapter_dir_name
= "adapter";
46 static char *info_proc_name
= "info";
47 static char *grp_opt_proc_name
= "group_optimization";
48 static char *d_l1_down_proc_name
= "dynamic_l1_down";
54 extern struct proc_dir_entry
*proc_net_eicon
;
55 static struct proc_dir_entry
*divas_proc_entry
= NULL
;
58 divas_read(struct file
*file
, char __user
*buf
, size_t count
, loff_t
* off
)
68 divas_get_version(tmpbuf
);
69 if (copy_to_user(buf
+ len
, &tmpbuf
, strlen(tmpbuf
)))
71 len
+= strlen(tmpbuf
);
73 for (cadapter
= 0; cadapter
< MAX_ADAPTER
; cadapter
++) {
74 if (IoAdapters
[cadapter
]) {
75 diva_get_vserial_number(IoAdapters
[cadapter
],
78 "%2d: %-30s Serial:%-10s IRQ:%2d\n",
80 IoAdapters
[cadapter
]->Properties
.Name
,
82 IoAdapters
[cadapter
]->irq_info
.irq_nr
);
83 if ((strlen(tmpbuf
) + len
) > count
)
87 strlen(tmpbuf
))) return -EFAULT
;
88 len
+= strlen(tmpbuf
);
97 divas_write(struct file
*file
, const char __user
*buf
, size_t count
, loff_t
* off
)
102 static unsigned int divas_poll(struct file
*file
, poll_table
* wait
)
107 static int divas_open(struct inode
*inode
, struct file
*file
)
109 return nonseekable_open(inode
, file
);
112 static int divas_close(struct inode
*inode
, struct file
*file
)
117 static struct file_operations divas_fops
= {
118 .owner
= THIS_MODULE
,
121 .write
= divas_write
,
124 .release
= divas_close
127 int create_divas_proc(void)
129 divas_proc_entry
= create_proc_entry(divas_proc_name
,
132 if (!divas_proc_entry
)
135 divas_proc_entry
->proc_fops
= &divas_fops
;
136 divas_proc_entry
->owner
= THIS_MODULE
;
141 void remove_divas_proc(void)
143 if (divas_proc_entry
) {
144 remove_proc_entry(divas_proc_name
, proc_net_eicon
);
145 divas_proc_entry
= NULL
;
150 ** write group_optimization
153 write_grp_opt(struct file
*file
, const char __user
*buffer
, unsigned long count
,
156 diva_os_xdi_adapter_t
*a
= (diva_os_xdi_adapter_t
*) data
;
157 PISDN_ADAPTER IoAdapter
= IoAdapters
[a
->controller
- 1];
159 if ((count
== 1) || (count
== 2)) {
161 if (get_user(c
, buffer
))
165 IoAdapter
->capi_cfg
.cfg_1
&=
166 ~DIVA_XDI_CAPI_CFG_1_GROUP_POPTIMIZATION_ON
;
169 IoAdapter
->capi_cfg
.cfg_1
|=
170 DIVA_XDI_CAPI_CFG_1_GROUP_POPTIMIZATION_ON
;
181 ** write dynamic_l1_down
184 write_d_l1_down(struct file
*file
, const char __user
*buffer
, unsigned long count
,
187 diva_os_xdi_adapter_t
*a
= (diva_os_xdi_adapter_t
*) data
;
188 PISDN_ADAPTER IoAdapter
= IoAdapters
[a
->controller
- 1];
190 if ((count
== 1) || (count
== 2)) {
192 if (get_user(c
, buffer
))
196 IoAdapter
->capi_cfg
.cfg_1
&=
197 ~DIVA_XDI_CAPI_CFG_1_DYNAMIC_L1_ON
;
200 IoAdapter
->capi_cfg
.cfg_1
|=
201 DIVA_XDI_CAPI_CFG_1_DYNAMIC_L1_ON
;
213 ** read dynamic_l1_down
216 read_d_l1_down(char *page
, char **start
, off_t off
, int count
, int *eof
,
220 diva_os_xdi_adapter_t
*a
= (diva_os_xdi_adapter_t
*) data
;
221 PISDN_ADAPTER IoAdapter
= IoAdapters
[a
->controller
- 1];
223 len
+= sprintf(page
+ len
, "%s\n",
224 (IoAdapter
->capi_cfg
.
225 cfg_1
& DIVA_XDI_CAPI_CFG_1_DYNAMIC_L1_ON
) ? "1" :
228 if (off
+ count
>= len
)
233 return ((count
< len
- off
) ? count
: len
- off
);
237 ** read group_optimization
240 read_grp_opt(char *page
, char **start
, off_t off
, int count
, int *eof
,
244 diva_os_xdi_adapter_t
*a
= (diva_os_xdi_adapter_t
*) data
;
245 PISDN_ADAPTER IoAdapter
= IoAdapters
[a
->controller
- 1];
247 len
+= sprintf(page
+ len
, "%s\n",
248 (IoAdapter
->capi_cfg
.
249 cfg_1
& DIVA_XDI_CAPI_CFG_1_GROUP_POPTIMIZATION_ON
)
252 if (off
+ count
>= len
)
257 return ((count
< len
- off
) ? count
: len
- off
);
264 info_write(struct file
*file
, const char __user
*buffer
, unsigned long count
,
267 diva_os_xdi_adapter_t
*a
= (diva_os_xdi_adapter_t
*) data
;
268 PISDN_ADAPTER IoAdapter
= IoAdapters
[a
->controller
- 1];
274 if (copy_from_user(c
, buffer
, 4))
277 /* this is for test purposes only */
278 if (!memcmp(c
, "trap", 4)) {
279 (*(IoAdapter
->os_trap_nfy_Fnc
)) (IoAdapter
, IoAdapter
->ANum
);
289 info_read(char *page
, char **start
, off_t off
, int count
, int *eof
,
296 diva_os_xdi_adapter_t
*a
= (diva_os_xdi_adapter_t
*) data
;
297 PISDN_ADAPTER IoAdapter
= IoAdapters
[a
->controller
- 1];
300 sprintf(page
+ len
, "Name : %s\n",
301 IoAdapter
->Properties
.Name
);
302 len
+= sprintf(page
+ len
, "DSP state : %08x\n", a
->dsp_mask
);
303 len
+= sprintf(page
+ len
, "Channels : %02d\n",
304 IoAdapter
->Properties
.Channels
);
305 len
+= sprintf(page
+ len
, "E. max/used : %03d/%03d\n",
306 IoAdapter
->e_max
, IoAdapter
->e_count
);
307 diva_get_vserial_number(IoAdapter
, tmpser
);
308 len
+= sprintf(page
+ len
, "Serial : %s\n", tmpser
);
310 sprintf(page
+ len
, "IRQ : %d\n",
311 IoAdapter
->irq_info
.irq_nr
);
312 len
+= sprintf(page
+ len
, "CardIndex : %d\n", a
->CardIndex
);
313 len
+= sprintf(page
+ len
, "CardOrdinal : %d\n", a
->CardOrdinal
);
314 len
+= sprintf(page
+ len
, "Controller : %d\n", a
->controller
);
315 len
+= sprintf(page
+ len
, "Bus-Type : %s\n",
317 DIVAS_XDI_ADAPTER_BUS_ISA
) ? "ISA" : "PCI");
318 len
+= sprintf(page
+ len
, "Port-Name : %s\n", a
->port_name
);
319 if (a
->Bus
== DIVAS_XDI_ADAPTER_BUS_PCI
) {
321 sprintf(page
+ len
, "PCI-bus : %d\n",
322 a
->resources
.pci
.bus
);
324 sprintf(page
+ len
, "PCI-func : %d\n",
325 a
->resources
.pci
.func
);
326 for (i
= 0; i
< 8; i
++) {
327 if (a
->resources
.pci
.bar
[i
]) {
330 "Mem / I/O %d : 0x%x / mapped : 0x%lx",
331 i
, a
->resources
.pci
.bar
[i
],
332 (unsigned long) a
->resources
.
334 if (a
->resources
.pci
.length
[i
]) {
341 len
+= sprintf(page
+ len
, "\n");
345 if ((!a
->xdi_adapter
.port
) &&
346 ((!a
->xdi_adapter
.ram
) ||
347 (!a
->xdi_adapter
.reset
)
348 || (!a
->xdi_adapter
.cfg
))) {
349 if (!IoAdapter
->irq_info
.irq_nr
) {
352 p
= "out of service";
354 } else if (a
->xdi_adapter
.trapped
) {
356 } else if (a
->xdi_adapter
.Initialized
) {
361 len
+= sprintf(page
+ len
, "State : %s\n", p
);
363 if (off
+ count
>= len
)
368 return ((count
< len
- off
) ? count
: len
- off
);
372 ** adapter proc init/de-init
375 /* --------------------------------------------------------------------------
376 Create adapter directory and files in proc file system
377 -------------------------------------------------------------------------- */
378 int create_adapter_proc(diva_os_xdi_adapter_t
* a
)
380 struct proc_dir_entry
*de
, *pe
;
383 sprintf(tmp
, "%s%d", adapter_dir_name
, a
->controller
);
384 if (!(de
= proc_mkdir(tmp
, proc_net_eicon
)))
386 a
->proc_adapter_dir
= (void *) de
;
389 create_proc_entry(info_proc_name
, S_IFREG
| S_IRUGO
| S_IWUSR
, de
)))
391 a
->proc_info
= (void *) pe
;
392 pe
->write_proc
= info_write
;
393 pe
->read_proc
= info_read
;
396 if ((pe
= create_proc_entry(grp_opt_proc_name
,
397 S_IFREG
| S_IRUGO
| S_IWUSR
, de
))) {
398 a
->proc_grp_opt
= (void *) pe
;
399 pe
->write_proc
= write_grp_opt
;
400 pe
->read_proc
= read_grp_opt
;
403 if ((pe
= create_proc_entry(d_l1_down_proc_name
,
404 S_IFREG
| S_IRUGO
| S_IWUSR
, de
))) {
405 a
->proc_d_l1_down
= (void *) pe
;
406 pe
->write_proc
= write_d_l1_down
;
407 pe
->read_proc
= read_d_l1_down
;
411 DBG_TRC(("proc entry %s created", tmp
));
416 /* --------------------------------------------------------------------------
417 Remove adapter directory and files in proc file system
418 -------------------------------------------------------------------------- */
419 void remove_adapter_proc(diva_os_xdi_adapter_t
* a
)
423 if (a
->proc_adapter_dir
) {
424 if (a
->proc_d_l1_down
) {
425 remove_proc_entry(d_l1_down_proc_name
,
426 (struct proc_dir_entry
*) a
->proc_adapter_dir
);
428 if (a
->proc_grp_opt
) {
429 remove_proc_entry(grp_opt_proc_name
,
430 (struct proc_dir_entry
*) a
->proc_adapter_dir
);
433 remove_proc_entry(info_proc_name
,
434 (struct proc_dir_entry
*) a
->proc_adapter_dir
);
436 sprintf(tmp
, "%s%d", adapter_dir_name
, a
->controller
);
437 remove_proc_entry(tmp
, proc_net_eicon
);
438 DBG_TRC(("proc entry %s%d removed", adapter_dir_name
,