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/module.h>
14 #include <linux/kernel.h>
15 #include <linux/poll.h>
16 #include <linux/proc_fs.h>
17 #include <linux/seq_file.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 const 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 = proc_create(divas_proc_name, S_IFREG | S_IRUGO,
130 proc_net_eicon, &divas_fops);
131 if (!divas_proc_entry)
137 void remove_divas_proc(void)
139 if (divas_proc_entry) {
140 remove_proc_entry(divas_proc_name, proc_net_eicon);
141 divas_proc_entry = NULL;
145 static ssize_t grp_opt_proc_write(struct file *file, const char __user *buffer,
146 size_t count, loff_t *pos)
148 diva_os_xdi_adapter_t *a = PDE_DATA(file_inode(file));
149 PISDN_ADAPTER IoAdapter = IoAdapters[a->controller - 1];
151 if ((count == 1) || (count == 2)) {
153 if (get_user(c, buffer))
157 IoAdapter->capi_cfg.cfg_1 &=
158 ~DIVA_XDI_CAPI_CFG_1_GROUP_POPTIMIZATION_ON;
161 IoAdapter->capi_cfg.cfg_1 |=
162 DIVA_XDI_CAPI_CFG_1_GROUP_POPTIMIZATION_ON;
172 static ssize_t d_l1_down_proc_write(struct file *file, const char __user *buffer,
173 size_t count, loff_t *pos)
175 diva_os_xdi_adapter_t *a = PDE_DATA(file_inode(file));
176 PISDN_ADAPTER IoAdapter = IoAdapters[a->controller - 1];
178 if ((count == 1) || (count == 2)) {
180 if (get_user(c, buffer))
184 IoAdapter->capi_cfg.cfg_1 &=
185 ~DIVA_XDI_CAPI_CFG_1_DYNAMIC_L1_ON;
188 IoAdapter->capi_cfg.cfg_1 |=
189 DIVA_XDI_CAPI_CFG_1_DYNAMIC_L1_ON;
199 static int d_l1_down_proc_show(struct seq_file *m, void *v)
201 diva_os_xdi_adapter_t *a = m->private;
202 PISDN_ADAPTER IoAdapter = IoAdapters[a->controller - 1];
204 seq_printf(m, "%s\n",
205 (IoAdapter->capi_cfg.
206 cfg_1 & DIVA_XDI_CAPI_CFG_1_DYNAMIC_L1_ON) ? "1" :
211 static int d_l1_down_proc_open(struct inode *inode, struct file *file)
213 return single_open(file, d_l1_down_proc_show, PDE_DATA(inode));
216 static const struct file_operations d_l1_down_proc_fops = {
217 .owner = THIS_MODULE,
218 .open = d_l1_down_proc_open,
221 .release = single_release,
222 .write = d_l1_down_proc_write,
225 static int grp_opt_proc_show(struct seq_file *m, void *v)
227 diva_os_xdi_adapter_t *a = m->private;
228 PISDN_ADAPTER IoAdapter = IoAdapters[a->controller - 1];
230 seq_printf(m, "%s\n",
231 (IoAdapter->capi_cfg.
232 cfg_1 & DIVA_XDI_CAPI_CFG_1_GROUP_POPTIMIZATION_ON)
237 static int grp_opt_proc_open(struct inode *inode, struct file *file)
239 return single_open(file, grp_opt_proc_show, PDE_DATA(inode));
242 static const struct file_operations grp_opt_proc_fops = {
243 .owner = THIS_MODULE,
244 .open = grp_opt_proc_open,
247 .release = single_release,
248 .write = grp_opt_proc_write,
251 static ssize_t info_proc_write(struct file *file, const char __user *buffer,
252 size_t count, loff_t *pos)
254 diva_os_xdi_adapter_t *a = PDE_DATA(file_inode(file));
255 PISDN_ADAPTER IoAdapter = IoAdapters[a->controller - 1];
261 if (copy_from_user(c, buffer, 4))
264 /* this is for test purposes only */
265 if (!memcmp(c, "trap", 4)) {
266 (*(IoAdapter->os_trap_nfy_Fnc)) (IoAdapter, IoAdapter->ANum);
272 static int info_proc_show(struct seq_file *m, void *v)
277 diva_os_xdi_adapter_t *a = m->private;
278 PISDN_ADAPTER IoAdapter = IoAdapters[a->controller - 1];
280 seq_printf(m, "Name : %s\n", IoAdapter->Properties.Name);
281 seq_printf(m, "DSP state : %08x\n", a->dsp_mask);
282 seq_printf(m, "Channels : %02d\n", IoAdapter->Properties.Channels);
283 seq_printf(m, "E. max/used : %03d/%03d\n",
284 IoAdapter->e_max, IoAdapter->e_count);
285 diva_get_vserial_number(IoAdapter, tmpser);
286 seq_printf(m, "Serial : %s\n", tmpser);
287 seq_printf(m, "IRQ : %d\n", IoAdapter->irq_info.irq_nr);
288 seq_printf(m, "CardIndex : %d\n", a->CardIndex);
289 seq_printf(m, "CardOrdinal : %d\n", a->CardOrdinal);
290 seq_printf(m, "Controller : %d\n", a->controller);
291 seq_printf(m, "Bus-Type : %s\n",
293 DIVAS_XDI_ADAPTER_BUS_ISA) ? "ISA" : "PCI");
294 seq_printf(m, "Port-Name : %s\n", a->port_name);
295 if (a->Bus == DIVAS_XDI_ADAPTER_BUS_PCI) {
296 seq_printf(m, "PCI-bus : %d\n", a->resources.pci.bus);
297 seq_printf(m, "PCI-func : %d\n", a->resources.pci.func);
298 for (i = 0; i < 8; i++) {
299 if (a->resources.pci.bar[i]) {
301 "Mem / I/O %d : 0x%x / mapped : 0x%lx",
302 i, a->resources.pci.bar[i],
303 (unsigned long) a->resources.
305 if (a->resources.pci.length[i]) {
315 if ((!a->xdi_adapter.port) &&
316 ((!a->xdi_adapter.ram) ||
317 (!a->xdi_adapter.reset)
318 || (!a->xdi_adapter.cfg))) {
319 if (!IoAdapter->irq_info.irq_nr) {
322 p = "out of service";
324 } else if (a->xdi_adapter.trapped) {
326 } else if (a->xdi_adapter.Initialized) {
331 seq_printf(m, "State : %s\n", p);
336 static int info_proc_open(struct inode *inode, struct file *file)
338 return single_open(file, info_proc_show, PDE_DATA(inode));
341 static const struct file_operations info_proc_fops = {
342 .owner = THIS_MODULE,
343 .open = info_proc_open,
346 .release = single_release,
347 .write = info_proc_write,
351 ** adapter proc init/de-init
354 /* --------------------------------------------------------------------------
355 Create adapter directory and files in proc file system
356 -------------------------------------------------------------------------- */
357 int create_adapter_proc(diva_os_xdi_adapter_t *a)
359 struct proc_dir_entry *de, *pe;
362 sprintf(tmp, "%s%d", adapter_dir_name, a->controller);
363 if (!(de = proc_mkdir(tmp, proc_net_eicon)))
365 a->proc_adapter_dir = (void *) de;
367 pe = proc_create_data(info_proc_name, S_IRUGO | S_IWUSR, de,
371 a->proc_info = (void *) pe;
373 pe = proc_create_data(grp_opt_proc_name, S_IRUGO | S_IWUSR, de,
374 &grp_opt_proc_fops, a);
376 a->proc_grp_opt = (void *) pe;
377 pe = proc_create_data(d_l1_down_proc_name, S_IRUGO | S_IWUSR, de,
378 &d_l1_down_proc_fops, a);
380 a->proc_d_l1_down = (void *) pe;
382 DBG_TRC(("proc entry %s created", tmp));
387 /* --------------------------------------------------------------------------
388 Remove adapter directory and files in proc file system
389 -------------------------------------------------------------------------- */
390 void remove_adapter_proc(diva_os_xdi_adapter_t *a)
394 if (a->proc_adapter_dir) {
395 if (a->proc_d_l1_down) {
396 remove_proc_entry(d_l1_down_proc_name,
397 (struct proc_dir_entry *) a->proc_adapter_dir);
399 if (a->proc_grp_opt) {
400 remove_proc_entry(grp_opt_proc_name,
401 (struct proc_dir_entry *) a->proc_adapter_dir);
404 remove_proc_entry(info_proc_name,
405 (struct proc_dir_entry *) a->proc_adapter_dir);
407 sprintf(tmp, "%s%d", adapter_dir_name, a->controller);
408 remove_proc_entry(tmp, proc_net_eicon);
409 DBG_TRC(("proc entry %s%d removed", adapter_dir_name,