vserver 1.9.3
[linux-2.6.git] / drivers / isdn / hardware / eicon / mntfunc.c
index c942299..2949245 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: mntfunc.c,v 1.19 2004/01/09 21:22:03 armin Exp $
+/* $Id: mntfunc.c,v 1.19.6.2 2004/08/28 20:03:53 armin Exp $
  *
  * Driver for Eicon DIVA Server ISDN cards.
  * Maint module
@@ -23,17 +23,12 @@ extern char *DRIVERRELEASE_MNT;
 
 extern void DIVA_DIDD_Read(void *, int);
 
-#define MAX_DESCRIPTORS  32
-
 static dword notify_handle;
 static DESCRIPTOR DAdapter;
 static DESCRIPTOR MAdapter;
 static DESCRIPTOR MaintDescriptor =
     { IDI_DIMAINT, 0, 0, (IDI_CALL) diva_maint_prtComp };
 
-extern void *diva_os_malloc_tbuffer(unsigned long flags,
-                                   unsigned long size);
-extern void diva_os_free_tbuffer(unsigned long flags, void *ptr);
 extern int diva_os_copy_to_user(void *os_handle, void __user *dst,
                                const void *src, int length);
 extern int diva_os_copy_from_user(void *os_handle, void *dst,
@@ -46,16 +41,6 @@ static void no_printf(unsigned char *x, ...)
 
 #include "debuglib.c"
 
-/*
- * stop debug
- */
-static void stop_dbg(void)
-{
-       DbgDeregister();
-       memset(&MAdapter, 0, sizeof(MAdapter));
-       dprintf = no_printf;
-}
-
 /*
  *  DIDD callback function
  */
@@ -66,7 +51,9 @@ static void *didd_callback(void *context, DESCRIPTOR * adapter,
                DBG_ERR(("cb: Change in DAdapter ? Oops ?."));
        } else if (adapter->type == IDI_DIMAINT) {
                if (removal) {
-                       stop_dbg();
+                       DbgDeregister();
+                       memset(&MAdapter, 0, sizeof(MAdapter));
+                       dprintf = no_printf;
                } else {
                        memcpy(&MAdapter, adapter, sizeof(MAdapter));
                        dprintf = (DIVA_DI_PRINTF) MAdapter.request;
@@ -131,8 +118,6 @@ static void DIVA_EXIT_FUNCTION disconnect_didd(void)
 {
        IDI_SYNC_REQ req;
 
-       stop_dbg();
-
        req.didd_notify.e.Req = 0;
        req.didd_notify.e.Rc = IDI_SYNC_REQ_DIDD_REMOVE_ADAPTER_NOTIFY;
        req.didd_notify.info.handle = notify_handle;
@@ -193,34 +178,63 @@ int maint_read_write(void __user *buf, int count)
                }
                break;
 
+    /*
+       Filter commands will ignore the ID due to fact that filtering affects
+       the B- channel and Audio Tap trace levels only. Also MAINT driver will
+       select the right trace ID by itself
+       */
+       case DITRACE_WRITE_SELECTIVE_TRACE_FILTER:
+               if (!mask) {
+                       ret = diva_set_trace_filter (1, "*");
+               } else if (mask < sizeof(data)) {
+                       if (copy_from_user(data, (char __user *)buf+12, mask)) {
+                               ret = -EFAULT;
+                       } else {
+                               ret = diva_set_trace_filter ((int)mask, data);
+                       }
+               } else {
+                       ret = -EINVAL;
+               }
+               break;
+
+       case DITRACE_READ_SELECTIVE_TRACE_FILTER:
+               if ((ret = diva_get_trace_filter (sizeof(data), data)) > 0) {
+                       if (copy_to_user (buf, data, ret))
+                               ret = -EFAULT;
+               } else {
+                       ret = -ENODEV;
+               }
+               break;
+
        case DITRACE_READ_TRACE_ENTRY:{
                        diva_os_spin_lock_magic_t old_irql;
                        word size;
                        diva_dbg_entry_head_t *pmsg;
                        byte *pbuf;
 
-                       if ((pmsg = diva_maint_get_message(&size, &old_irql))) {
+                       if (!(pbuf = diva_os_malloc(0, mask))) {
+                               return (-ENOMEM);
+                       }
+
+                       for(;;) {
+                               if (!(pmsg =
+                                   diva_maint_get_message(&size, &old_irql))) {
+                                       break;
+                               }
                                if (size > mask) {
                                        diva_maint_ack_message(0, &old_irql);
                                        ret = -EINVAL;
-                               } else {
-                                       if (!(pbuf = diva_os_malloc_tbuffer(0, size)))
-                                       {
-                                               diva_maint_ack_message(0, &old_irql);
-                                               ret = -ENOMEM;
-                                       } else {
-                                               ret = size;
-                                               memcpy(pbuf, pmsg, size);
-                                               diva_maint_ack_message(1, &old_irql);
-                                               if ((count < size) || diva_os_copy_to_user (NULL, buf,
-                                                    (void *) pbuf, size))
-                                                       ret = -EFAULT;
-                                               diva_os_free_tbuffer(0, pbuf);
-                                       }
+                                       break;
                                }
-                       } else {
-                               ret = 0;
+                               ret = size;
+                               memcpy(pbuf, pmsg, size);
+                               diva_maint_ack_message(1, &old_irql);
+                               if ((count < size) ||
+                                    diva_os_copy_to_user (NULL, buf, (void *) pbuf, size))
+                                                       ret = -EFAULT;
+                               break;
                        }
+                       diva_os_free(0, pbuf);
                }
                break;
 
@@ -235,7 +249,7 @@ int maint_read_write(void __user *buf, int count)
                                ret = -EINVAL;
                                break;
                        }
-                       if (!(pbuf = diva_os_malloc_tbuffer(0, mask))) {
+                       if (!(pbuf = diva_os_malloc(0, mask))) {
                                return (-ENOMEM);
                        }
 
@@ -273,7 +287,7 @@ int maint_read_write(void __user *buf, int count)
                        } else {
                                ret = written;
                        }
-                       diva_os_free_tbuffer(0, pbuf);
+                       diva_os_free(0, pbuf);
                }
                break;
 
@@ -302,7 +316,7 @@ int DIVA_INIT_FUNCTION mntfunc_init(int *buffer_length, void **buffer,
        } else {
                while ((*buffer_length >= (64 * 1024))
                       &&
-                      (!(*buffer = diva_os_malloc_tbuffer(0, *buffer_length)))) {
+                      (!(*buffer = diva_os_malloc (0, *buffer_length)))) {
                        *buffer_length -= 1024;
                }
 
@@ -314,7 +328,7 @@ int DIVA_INIT_FUNCTION mntfunc_init(int *buffer_length, void **buffer,
 
        if (diva_maint_init(*buffer, *buffer_length, (diva_dbg_mem == 0))) {
                if (!diva_dbg_mem) {
-                       diva_os_free_tbuffer(0, *buffer);
+                       diva_os_free (0, *buffer);
                }
                DBG_ERR(("init: maint init failed"));
                return (0);
@@ -324,7 +338,7 @@ int DIVA_INIT_FUNCTION mntfunc_init(int *buffer_length, void **buffer,
                DBG_ERR(("init: failed to connect to DIDD."));
                diva_maint_finit();
                if (!diva_dbg_mem) {
-                       diva_os_free_tbuffer(0, *buffer);
+                       diva_os_free (0, *buffer);
                }
                return (0);
        }
@@ -339,6 +353,8 @@ void DIVA_EXIT_FUNCTION mntfunc_finit(void)
        void *buffer;
        int i = 100;
 
+       DbgDeregister();
+
        while (diva_mnt_shutdown_xdi_adapters() && i--) {
                diva_os_sleep(10);
        }
@@ -346,6 +362,9 @@ void DIVA_EXIT_FUNCTION mntfunc_finit(void)
        disconnect_didd();
 
        if ((buffer = diva_maint_finit())) {
-               diva_os_free_tbuffer(0, buffer);
+               diva_os_free (0, buffer);
        }
+
+       memset(&MAdapter, 0, sizeof(MAdapter));
+       dprintf = no_printf;
 }