[Pkg-voip-commits] r1656 - in zaptel/trunk/debian: . patches
Kilian Krause
kilian at costa.debian.org
Sun Apr 30 16:30:37 UTC 2006
Author: kilian
Date: 2006-04-30 16:30:35 +0000 (Sun, 30 Apr 2006)
New Revision: 1656
Removed:
zaptel/trunk/debian/patches/01_ztdummy.dpatch
zaptel/trunk/debian/patches/Makefile.dpatch
zaptel/trunk/debian/patches/Makefile_pscmd.dpatch
zaptel/trunk/debian/patches/bristuff-0.2.0-RC8n.dpatch
zaptel/trunk/debian/patches/bristuff-0.3.0-PRE1.dpatch
zaptel/trunk/debian/patches/bristuff-0.3.0-PRE1d.dpatch
zaptel/trunk/debian/patches/bristuff-0.3.0-PRE1f.dpatch
zaptel/trunk/debian/patches/bristuff-0.3.0-PRE1h.dpatch
zaptel/trunk/debian/patches/dot_version.dpatch
zaptel/trunk/debian/patches/rtai.dpatch
zaptel/trunk/debian/patches/xpp.dpatch
zaptel/trunk/debian/patches/zaphfc_0.2.0-RC8n_florz-8.dpatch
zaptel/trunk/debian/patches/zaphfc_gcc4.dpatch
zaptel/trunk/debian/patches/ztcfg_init.dpatch
Modified:
zaptel/trunk/debian/changelog
zaptel/trunk/debian/patches/00list
zaptel/trunk/debian/patches/Makefile_deps_kern.dpatch
zaptel/trunk/debian/patches/Makefile_deps_utils.dpatch
zaptel/trunk/debian/patches/Makefile_gendigits.dpatch
zaptel/trunk/debian/patches/Makefile_kbuild.dpatch
zaptel/trunk/debian/patches/Makefile_targets.dpatch
zaptel/trunk/debian/patches/Makefile_xpp.dpatch
zaptel/trunk/debian/patches/gendigits.dpatch
zaptel/trunk/debian/patches/xpp_fixes.dpatch
Log:
weed out unused patches and mark submitted patches to rember on next release.
Modified: zaptel/trunk/debian/changelog
===================================================================
--- zaptel/trunk/debian/changelog 2006-04-30 15:19:14 UTC (rev 1655)
+++ zaptel/trunk/debian/changelog 2006-04-30 16:30:35 UTC (rev 1656)
@@ -1,10 +1,15 @@
zaptel (1:1.2.5-2) UNRELEASED; urgency=low
+ [ Lionel Elie Mamane ]
* NOT RELEASED YET
* Load ztdummy when needed, not when not needed.
- -- Lionel Elie Mamane <lmamane at debian.org> Mon, 17 Apr 2006 01:07:11 +0200
+ [ Kilian Krause ]
+ * Weed out old unused patches. Add comments which patches have been included
+ upstream for next release.
+ -- Kilian Krause <kilian at debian.org> Sun, 30 Apr 2006 18:29:16 +0200
+
zaptel (1:1.2.5-1) unstable; urgency=low
[ Tzafrir Cohen ]
Modified: zaptel/trunk/debian/patches/00list
===================================================================
--- zaptel/trunk/debian/patches/00list 2006-04-30 15:19:14 UTC (rev 1655)
+++ zaptel/trunk/debian/patches/00list 2006-04-30 16:30:35 UTC (rev 1656)
@@ -1,7 +1,6 @@
Makefile_deps_kern
Makefile_deps_utils
Makefile_uname
-#Makefile_pscmd
Makefile_targets
Makefile_kbuild
Makefile_xpp
@@ -11,7 +10,6 @@
echocan_env
ukcid
xpp_fixes
-#dot_version
bristuff
Makefile_gendigits
gendigits
Deleted: zaptel/trunk/debian/patches/01_ztdummy.dpatch
===================================================================
--- zaptel/trunk/debian/patches/01_ztdummy.dpatch 2006-04-30 15:19:14 UTC (rev 1655)
+++ zaptel/trunk/debian/patches/01_ztdummy.dpatch 2006-04-30 16:30:35 UTC (rev 1656)
@@ -1,170 +0,0 @@
-#! /bin/sh /usr/share/dpatch/dpatch-run
-## 01_ztdummy.dpatch by Santiago Ruano Rincón <santiago at unicauca.edu.co>
-##
-## All lines beginning with `## DP:' are a description of the patch.
-## DP: Patch to improve the ztdummy accuracy on kernel 2.6
-## DP: from http://bugs.digium.com/view.php?id=4301
-
- at DPATCH@
-diff -urNad zaptel-1.0.9/ztdummy.c /tmp/dpep.OJH6qB/zaptel-1.0.9/ztdummy.c
---- zaptel-1.0.9/ztdummy.c 2005-01-21 00:05:18.000000000 -0500
-+++ /tmp/dpep.OJH6qB/zaptel-1.0.9/ztdummy.c 2005-07-15 18:59:33.000000000 -0500
-@@ -6,6 +6,7 @@
- * Written by Robert Pleh <robert.pleh at hermes.si>
- * 2.6 version by Tony Hoyle
- * Unified by Mark Spencer <markster at digium.com>
-+ * Converted to use RTC on i386 by Tony Mountifield <tony at softins.co.uk>
- *
- * Copyright (C) 2002, Hermes Softlab
- * Copyright (C) 2004, Digium, Inc.
-@@ -38,6 +39,15 @@
- # error "This kernel is too old: not supported by this file"
- #endif
-
-+/*
-+ * NOTE: (only applies to kernel 2.6)
-+ * If using an i386 architecture without a PC real-time clock,
-+ * the #define USE_RTC should be commented out.
-+ */
-+#if defined(__i386__)
-+#define USE_RTC
-+#endif
-+
- #include <linux/kernel.h>
- #include <linux/errno.h>
- #include <linux/module.h>
-@@ -54,6 +64,9 @@
- #include <asm/io.h>
- #endif
- #ifdef LINUX26
-+#ifdef USE_RTC
-+#include <linux/rtc.h>
-+#endif
- #include <linux/moduleparam.h>
- #endif
- #include "ztdummy.h"
-@@ -77,8 +90,10 @@
- static int debug = 0;
-
- #ifdef LINUX26
-+#ifndef USE_RTC
- /* New 2.6 kernel timer stuff */
- static struct timer_list timer;
-+#endif
- #else
- #if LINUX_VERSION_CODE < VERSION_CODE(2,4,5)
- # error "This kernel is too old: not supported by this file"
-@@ -103,6 +118,28 @@
-
-
- #ifdef LINUX26
-+#ifdef USE_RTC
-+/* rtc_interrupt - called at 1024Hz from hook in RTC handler */
-+static void rtc_interrupt(void *private_data)
-+{
-+ struct ztdummy *ztd = private_data;
-+ unsigned int ticks;
-+
-+ atomic_inc(&ztd->ticks);
-+ ticks = atomic_read(&ztd->ticks);
-+ if (ticks == 42 || ticks == 85) {
-+ /* skip it */
-+ } else if (ticks >= 128) {
-+ /* skip and restart count */
-+ atomic_set(&ztd->ticks, 0);
-+ } else {
-+ /* zaptel timing - called in 125 of every 128 interrupts = 1000Hz */
-+ zt_receive(&ztd->span);
-+ zt_transmit(&ztd->span);
-+ }
-+}
-+#else
-+/* use kernel system tick timer if PC architecture RTC is not available */
- static void ztdummy_timer(unsigned long param)
- {
- zt_receive(&ztd->span);
-@@ -110,6 +147,7 @@
- timer.expires = jiffies + 1;
- add_timer(&timer);
- }
-+#endif
- #else
- static void ztdummy_interrupt(int irq, void *dev_id, struct pt_regs *regs)
- {
-@@ -150,7 +188,11 @@
-
- int init_module(void)
- {
--#ifndef LINUX26
-+#ifdef LINUX26
-+#ifdef USE_RTC
-+ int err;
-+#endif
-+#else
- int irq;
- spinlock_t mylock = SPIN_LOCK_UNLOCKED;
-
-@@ -180,10 +222,25 @@
- }
-
- #ifdef LINUX26
-+#ifdef USE_RTC
-+ atomic_set(&ztd->ticks, 0);
-+ ztd->rtc_task.func = rtc_interrupt;
-+ ztd->rtc_task.private_data = ztd;
-+ err = rtc_register(&ztd->rtc_task);
-+ if (err < 0) {
-+ printk("ztdummy: Unable to register zaptel rtc driver\n");
-+ zt_unregister(&ztd->span);
-+ kfree(ztd);
-+ return err;
-+ }
-+ rtc_control(&ztd->rtc_task, RTC_IRQP_SET, 1024); /* 1024 Hz */
-+ rtc_control(&ztd->rtc_task, RTC_PIE_ON, 0);
-+#else
- init_timer(&timer);
- timer.function = ztdummy_timer;
- timer.expires = jiffies + 1;
- add_timer(&timer);
-+#endif
- #else
- irq=s->irq;
- spin_lock_irq(&mylock);
-@@ -214,7 +271,12 @@
- void cleanup_module(void)
- {
- #ifdef LINUX26
-+#ifdef USE_RTC
-+ rtc_control(&ztd->rtc_task, RTC_PIE_OFF, 0);
-+ rtc_unregister(&ztd->rtc_task);
-+#else
- del_timer(&timer);
-+#endif
- #else
- free_irq(s->irq, ztd); /* disable interrupts */
- #endif
-diff -urNad zaptel-1.0.9/ztdummy.h /tmp/dpep.OJH6qB/zaptel-1.0.9/ztdummy.h
---- zaptel-1.0.9/ztdummy.h 2003-02-24 01:00:31.000000000 -0500
-+++ /tmp/dpep.OJH6qB/zaptel-1.0.9/ztdummy.h 2005-07-15 18:59:33.000000000 -0500
-@@ -32,9 +32,16 @@
- struct ztdummy {
- struct zt_span span;
- struct zt_chan chan;
-+#ifdef LINUX26
-+#ifdef USE_RTC
-+ atomic_t ticks;
-+ rtc_task_t rtc_task;
-+#endif
-+#endif
- };
-
-
-+#ifndef LINUX26
- /* Uhci definitions and structures - from file usb-uhci.h */
- #define TD_CTRL_IOC (1 << 24) /* Interrupt on Complete */
- #define USBSTS 2
-@@ -141,3 +148,4 @@
- struct pci_pool *desc_pool;
- long last_error_time; // last error output in uhci_interrupt()
- } uhci_t, *puhci_t;
-+#endif
Deleted: zaptel/trunk/debian/patches/Makefile.dpatch
===================================================================
--- zaptel/trunk/debian/patches/Makefile.dpatch 2006-04-30 15:19:14 UTC (rev 1655)
+++ zaptel/trunk/debian/patches/Makefile.dpatch 2006-04-30 16:30:35 UTC (rev 1656)
@@ -1,291 +0,0 @@
-#! /bin/sh /usr/share/dpatch/dpatch-run
-## Makefile.dpatch by Kilian Krause <kk at verfaction.de>
-##
-## All lines beginning with `## DP:' are a description of the patch.
-## DP: imported old Makefile changes
-
- at DPATCH@
-diff -urNad zaptel-1.0.9.1/Makefile /tmp/dpep.gXSxS1/zaptel-1.0.9.1/Makefile
---- zaptel-1.0.9.1/Makefile 2005-08-18 23:53:47.000000000 -0500
-+++ /tmp/dpep.gXSxS1/zaptel-1.0.9.1/Makefile 2005-08-18 23:58:23.000000000 -0500
-@@ -13,17 +13,27 @@
- # (assuming He's running Linux -- which we all know He must).
- #
- HOSTCC=gcc
--KINCLUDES=$(shell if [ -d /usr/src/linux-2.4/include ]; then echo /usr/src/linux-2.4/include ; else echo /usr/src/linux/include ; fi)
-+KINCLUDES=$(KSRC)/include
-+ifeq ($(KVERS),)
-+KVERS = `uname -r`
-+endif
-+
-+ifeq ($(DEB_HOST_GNU_TYPE),)
-+ UNAME_M=`uname -m`
-+else
-+ UNAME_M=$(DEB_HOST_GNU_TYPE)
-+endif
-+
-
- CFLAGS+=-I. -O4 -g -Wall -DBUILDING_TONEZONE #-DTONEZONE_DRIVER
--CFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-fsigned-char"; fi)
--CFLAGS+=$(shell if uname -m | grep -q x86_64; then echo "-m64"; fi)
-+CFLAGS+=-fsigned-char
-+CFLAGS+=$(shell if echo $(UNAME_M) | grep -q x86_64; then echo "-m64"; fi)
- LCFLAGS=-fPIC $(CFLAGS) -DBUILDING_TONEZONE
--KFLAGS+=-I/usr/src/linux/include -O6
--KFLAGS+=-DMODULE -D__KERNEL__ -DEXPORT_SYMTAB -I/usr/src/linux/drivers/net \
-- -Wall -I. -Wstrict-prototypes -fomit-frame-pointer -I/usr/src/linux/drivers/net/wan -I /usr/src/linux/include -I/usr/src/linux/include/net
-+KFLAGS+=-I$(KSRC)/include -O2
-+KFLAGS+=-DMODULE -D__KERNEL__ -DEXPORT_SYMTAB -I$(KSRC)/drivers/net \
-+ -Wall -I. -Wstrict-prototypes -fomit-frame-pointer -I$(KSRC)/drivers/net/wan -I $(KSRC)/include -I$(KSRC)/include/net
- KFLAGS+=$(shell if [ -f $(KINCLUDES)/linux/modversions.h ] ; then echo "-DMODVERSIONS -include $(KINCLUDES)/linux/modversions.h" ; fi)
--KFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-msoft-float -fsigned-char"; fi)
-++ KFLAGS+=$(shell if echo $(UNAME_M) | grep -q ppc; then echo "-msoft-float -fsigned-char"; fi)
- #
- # Features are now configured in zconfig.h
- #
-@@ -35,19 +45,20 @@
- ROOT_PREFIX=
- INSTALL_PREFIX=
-
--CONFIG_FILE=$(INSTALL_PREFIX)/etc/zaptel.conf
--CFLAGS+=-DZAPTEL_CONFIG=\"$(CONFIG_FILE)\"
-+CONFIG_FILE=$(DESTDIR)$(INSTALL_PREFIX)/etc/zaptel.conf
-+CFLAGS+=-DZAPTEL_CONFIG=\"$(DESTDIR)$(CONFIG_FILE)\"
-
--BUILDVER=$(shell if uname -r | grep -q ^2.6; then echo "linux26"; else echo "linux24"; fi)
--MODCONF=$(shell if [ -d $(ROOT_PREFIX)/etc/modprobe.d ]; then echo "$(ROOT_PREFIX)/etc/modprobe.d/zaptel"; elif [ -d $(ROOT_PREFIX)/etc/modutils ]; then echo "$(ROOT_PREFIX)/etc/modutils/zaptel"; elif [ -f $(ROOT_PREFIX)/etc/modprobe.conf ]; then echo "$(ROOT_PREFIX)/etc/modprobe.conf"; elif [ -f $(ROOT_PREFIX)/etc/modules.conf ]; then echo "$(ROOT_PREFIX)/etc/modules.conf"; else echo $(ROOT_PREFIX)/etc/conf.modules ; fi)
-+BUILDVER=$(shell if echo $(KVERS) | grep -q ^2.6; then echo "linux26"; else echo "linux24"; fi)
-+BUILDVER-MODULES=$(shell if echo $(KVERS) | grep -q ^2.6; then echo "linux26-modules"; else echo "linux24-modules"; fi)
-+MODCONF=$(shell if [ -d $(DESTDIR)$(INSTALL_PREFIX)/etc/modprobe.d ]; then echo "$(DESTDIR)$(INSTALL_PREFIX)/etc/modprobe.d/zaptel"; elif [ -d $(DESTDIR)$(INSTALL_PREFIX)/etc/modutils ]; then echo "$(DESTDIR)$(INSTALL_PREFIX)/etc/modutils/zaptel"; elif [ -f $(DESTDIR)$(INSTALL_PREFIX)/etc/modprobe.conf ]; then echo "$(DESTDIR)$(INSTALL_PREFIX)/etc/modprobe.conf"; elif [ -f $(DESTDIR)$(INSTALL_PREFIX)/etc/modules.conf ]; then echo "$(DESTDIR)$(INSTALL_PREFIX)/etc/modules.conf"; else echo $(DESTDIR)$(INSTALL_PREFIX)/etc/conf.modules ; fi)
-
- ifeq (${BUILDVER},linux24)
- #We only support DEVFS in linux 2.4 kernels, since its considered obsolete post 2.4
--DYNFS=$(ps ax | grep -v grep | grep -q devfsd && echo "yes")
-+DYNFS=$(shell ps ax | grep -v grep | grep -q devfsd && echo "yes")
- endif
- ifeq (${BUILDVER},linux26)
- #Tests for newer linux-2.6 udev support
--DYNFS=$(ps ax | grep -v grep | grep udevd && echo "yes")
-+DYNFS=$(shell ps ax | grep -v grep | grep udevd && echo "yes")
- endif
-
- CHKCONFIG=$(shell sh -c 'type -p chkconfig' 2> /dev/null)
-@@ -57,9 +68,14 @@
-
- TZOBJS=zonedata.lo tonezone.lo
- LIBTONEZONE=libtonezone.so.1.0
-+LIBTONEZONESHORT=$(shell echo $(LIBTONEZONE) | sed -e 's/\.[0-9]\+$$//' )
- MODULES=zaptel tor2 torisa wcusb wcfxo wcfxs \
- ztdynamic ztd-eth wct1xxp wct4xxp wcte11xp # ztdummy
- #MODULES+=wcfxsusb
-+BRIMODULES=qozap/qozap zaphfc/zaphfc zaphfc-florz/zaphfc-florz
-+
-+MODULES+=$(BRIMODULES)
-+
-
- MODULESO=$(shell for x in $(MODULES); do echo "$$x.o "; done )
- MODULESKO=$(shell for x in $(MODULES); do echo "$$x.ko "; done )
-@@ -71,16 +87,28 @@
- PRIMARY=torisa
- #PRIMARY=wcfxo
- PWD=$(shell pwd)
--KERNEL_SOURCE?=/lib/modules/`uname -r`/build
-
- all: $(BUILDVER) $(LIBTONEZONE)
-
-+ modules: $(BUILDVER-MODULES)
-+
-+programs: $(LIBTONEZONE) $(BINS)
-+
-+linux24-modules: $(MODULESO)
-+
-+linux26-modules: prereq
-+ make -C $(KSRC) SUBDIRS=$(PWD) modules
-+ make -C $(KSRC) SUBDIRS="$(PWD)/zaphfc" modules
-+ make -C $(KSRC) SUBDIRS="$(PWD)/qozap " modules
-+
- linux24: $(MODULESO) $(BINS)
-
- linux26:
- linux26: prereq $(BINS)
-- @if ! [ -d $(KERNEL_SOURCE) ]; then echo "You do not appear to have the kernel sources for your current kernel installed."; exit 1 ; fi
-- make -C $(KERNEL_SOURCE) SUBDIRS=$(PWD) modules
-+ @if ! [ -d $(KSRC) ]; then echo "You do not appear to have the kernel sources for your current kernel installed."; exit 1 ; fi
-+ make -C $(KSRC) SUBDIRS=$(PWD) modules
-+ make -C $(KSRC) SUBDIRS="$(PWD)/zaphfc" modules
-+ make -C $(KSRC) SUBDIRS="$(PWD)/qozap " modules
-
- obj-m := $(MODULESO) ztdummy.o
-
-@@ -141,6 +169,12 @@
- tor2ee: tor2ee.o
- $(CC) $(CFLAGS) -o tor2ee tor2ee.o -lpci
-
-+zaphfc.o: zaphfc/zaphfc.c zaphfc/zaphfc.h
-+ $(CC) -c zaphfc/zaphfc.c $(KFLAGS)
-+
-+qozap.o: qozap/qozap.c qozap/qozap.h
-+ $(CC) -c qozap/qozap.c $(KFLAGS)
-+
- zonedata.lo: zonedata.c
- $(CC) -c $(LCFLAGS) -o zonedata.lo zonedata.c
-
-@@ -236,62 +270,61 @@
- ztdiag: ztdiag.o
- $(CC) -o ztdiag ztdiag.o
-
--devices:
--ifeq ($(DYNFS),)
-- mkdir -p $(INSTALL_PREFIX)/dev/zap
-- rm -f $(INSTALL_PREFIX)/dev/zap/ctl
-- rm -f $(INSTALL_PREFIX)/dev/zap/channel
-- rm -f $(INSTALL_PREFIX)/dev/zap/pseudo
-- rm -f $(INSTALL_PREFIX)/dev/zap/timer
-- rm -f $(INSTALL_PREFIX)/dev/zap/253
-- rm -f $(INSTALL_PREFIX)/dev/zap/252
-- rm -f $(INSTALL_PREFIX)/dev/zap/251
-- rm -f $(INSTALL_PREFIX)/dev/zap/250
-- mknod $(INSTALL_PREFIX)/dev/zap/ctl c 196 0
-- mknod $(INSTALL_PREFIX)/dev/zap/timer c 196 253
-- mknod $(INSTALL_PREFIX)/dev/zap/channel c 196 254
-- mknod $(INSTALL_PREFIX)/dev/zap/pseudo c 196 255
-- N=1; \
-- while [ $$N -lt 250 ]; do \
-- rm -f $(INSTALL_PREFIX)/dev/zap/$$N; \
-- mknod $(INSTALL_PREFIX)/dev/zap/$$N c 196 $$N; \
-- N=$$[$$N+1]; \
-- done
--else
-- @echo "**** Dynamic filesystem detected -- not creating device nodes"
-- @echo "**** If you are running udev, read README.udev"
--endif
-+install: install-programs install-modules install-modconf #devices
-
--install: all devices
-- install -D -m 755 ztcfg $(INSTALL_PREFIX)/sbin/ztcfg
-+install-programs: programs
-+ install -D -m 755 ztcfg $(DESTDIR)/sbin/ztcfg
- if [ -f sethdlc-new ]; then \
-- install -D -m 755 sethdlc-new $(INSTALL_PREFIX)/sbin/sethdlc; \
-+ install -D -m 755 sethdlc-new $(DESTDIR)/sbin/sethdlc; \
- elif [ -f sethdlc ]; then \
-- install -D -m 755 sethdlc $(INSTALL_PREFIX)/sbin/sethdlc ; \
-+ install -D -m 755 sethdlc $(DESTDIR)/sbin/sethdlc ; \
- fi
-- if [ -f zttool ]; then install -D -m 755 zttool $(INSTALL_PREFIX)/sbin/zttool; fi
-+ if [ -f zttool ]; then install -D -m 755 zttool $(DESTDIR)/sbin/zttool; fi
-+ if [ -f ztmonitor ]; then install -D -m 755 ztmonitor $(DESTDIR)/sbin/ztmonitor; fi
-+ if [ -f zttest ]; then install -D -m 755 zttest $(DESTDIR)/sbin/zttest; fi
-+ if [ -f ztspeed ]; then install -D -m 755 ztspeed $(DESTDIR)/sbin/ztspeed; fi
-+
-+
-+# install -D -m 755 $(LIBTONEZONE) $(INSTALL_PREFIX)/usr/lib/$(LIBTONEZONE)
-+# if [ -x /usr/sbin/sestatus ] && (/usr/sbin/sestatus | grep "SELinux status:" | grep -q "enabled") ; then restorecon -v $(INSTALL_PREFIX)/usr/lib/$(LIBTONEZONE); fi
-+# install -D -m 644 zaptel.h $(INSTALL_PREFIX)/usr/include/linux/zaptel.h
-+# install -D -m 644 torisa.h $(INSTALL_PREFIX)/usr/include/linux/torisa.h
-+
-+ install -D -m 644 tonezone.h $(DESTDIR)/usr/include/tonezone.h
-+
-+ install -d $(DESTDIR)/usr/lib
-+ install -m 755 $(LIBTONEZONE) $(DESTDIR)/usr/lib
-+ ln -sf $(LIBTONEZONE) $(DESTDIR)/usr/lib/libtonezone.so
-+ ln -sf $(LIBTONEZONE) $(DESTDIR)/usr/lib/$(LIBTONEZONESHORT)
-+# /sbin/ldconfig -n $(DESTDIR)$(INSTALL_PREFIX)/lib
-+
-+install-modules:
-+ mkdir -p $(DESTDIR)/lib/modules/$(KVERS)/zaptel
-+
- if [ -f zaptel.ko ]; then \
- for x in $(MODULESKO) ztdummy.ko; do \
-- install -D -m 644 $$x $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/$$x ; \
-+ install -m 644 $$x $(DESTDIR)/lib/modules/$(KVERS)/zaptel ; \
- done; \
- if ! [ -f wcfxsusb.ko ]; then \
-- rm -f $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/wcfxsusb.o; \
-+ rm -f $(DESTDIR)/lib/modules/$(KVERS)/zaptel/wcfxsusb.o; \
- fi; \
- else \
- for x in $(MODULESO); do \
-- install -D -m 644 $$x $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/$$x ; \
-+ install -m 644 $$x $(DESTDIR)/lib/modules/$(KVERS)/zaptel ; \
- done; \
- if ! [ -f wcfxsusb.o ]; then \
-- rm -f $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/wcfxsusb.ko; \
-+ rm -f $(DESTDIR)/lib/modules/$(KVERS)/zaptel/wcfxsusb.ko; \
- fi; \
- fi
-- install -D -m 755 $(LIBTONEZONE) $(INSTALL_PREFIX)/usr/lib/$(LIBTONEZONE)
-- if [ -x /usr/sbin/sestatus ] && (/usr/sbin/sestatus | grep "SELinux status:" | grep -q "enabled") ; then restorecon -v $(INSTALL_PREFIX)/usr/lib/$(LIBTONEZONE); fi
-- install -D -m 644 zaptel.h $(INSTALL_PREFIX)/usr/include/linux/zaptel.h
-- install -D -m 644 torisa.h $(INSTALL_PREFIX)/usr/include/linux/torisa.h
-- install -D -m 644 tonezone.h $(INSTALL_PREFIX)/usr/include/tonezone.h
-- ( cd $(INSTALL_PREFIX)/usr/lib ; rm -f libtonezone.so ; ln -sf $(LIBTONEZONE) libtonezone.so )
-- [ `id -u` = 0 ] && /sbin/ldconfig || :
-+
-+ mkdir -p $(DESTDIR)$(INSTALL_PREFIX)/usr/include/linux
-+# install -m 644 zaptel.h $(DESTDIR)$(INSTALL_PREFIX)/usr/include/linux
-+# install -m 644 torisa.h $(DESTDIR)$(INSTALL_PREFIX)/usr/include/linux
-+# install -D -m 644 tonezone.h $(INSTALL_PREFIX)/usr/include/tonezone.h
-+# ( cd $(INSTALL_PREFIX)/usr/lib ; rm -f libtonezone.so ; ln -sf $(LIBTONEZONE) libtonezone.so )
-+# [ `id -u` = 0 ] && /sbin/ldconfig || :
-+
-+install-modconf:
- if [ -f $(MODCONF) ]; then mv -f $(MODCONF) $(MODCONF).bak ; fi
- cat $(MODCONF).bak | grep -v "alias char-major-250" | \
- grep -v "post-install torisa /sbin/ztcfg" | \
-@@ -303,6 +336,7 @@
- if ! grep "alias char-major-196" $(MODCONF); then \
- echo "alias char-major-196 $(PRIMARY)" >> $(MODCONF); \
- fi
-+
- for x in $(MODULES); do \
- if ! grep "post-install $$x" $(MODCONF); then \
- if ! grep "install $$x " $(MODCONF); then \
-@@ -323,27 +357,30 @@
- if [ -d /etc/modutils ]; then \
- /sbin/update-modules ; \
- fi
-- [ `id -u` = 0 ] && /sbin/depmod -a || :
-- [ -f $(CONFIG_FILE) ] || install -D -m 644 zaptel.conf.sample $(CONFIG_FILE)
-+ -/sbin/depmod -a
-+ [ -f $(DESTDIR)$(CONFIG_FILE) ] || install -m 644 zaptel.conf.sample $(DESTDIR)$(CONFIG_FILE)
-
--config:
-- if [ -d $(INSTALL_PREFIX)/etc/rc.d/init.d ]; then \
-- install -D -m 755 zaptel.init $(INSTALL_PREFIX)/etc/rc.d/init.d/zaptel; \
-- $(CHKCONFIG) --add zaptel; \
-- elif [ -d $(INSTALL_PREFIX)/etc/init.d ]; then \
-- install -D -m 755 zaptel.init $(INSTALL_PREFIX)/etc/init.d/zaptel; \
-- $(CHKCONFIG) --add zaptel; \
-- fi
-- if [ ! -f /etc/sysconfig/zaptel ]; then \
-- install -D -m 644 zaptel.sysconfig $(INSTALL_PREFIX)/etc/sysconfig/zaptel; \
-- fi
-- if [ -d /etc/sysconfig/network-scripts ]; then \
-- install -D -m 755 ifup-hdlc $(INSTALL_PREFIX)/etc/sysconfig/network-scripts/ifup-hdlc; \
-- fi
-+#config:
-+# if [ -d $(INSTALL_PREFIX)/etc/rc.d/init.d ]; then \
-+# install -D -m 755 zaptel.init $(INSTALL_PREFIX)/etc/rc.d/init.d/zaptel; \
-+# $(CHKCONFIG) --add zaptel; \
-+# elif [ -d $(INSTALL_PREFIX)/etc/init.d ]; then \
-+# install -D -m 755 zaptel.init $(INSTALL_PREFIX)/etc/init.d/zaptel; \
-+# $(CHKCONFIG) --add zaptel; \
-+# fi
-+# if [ ! -f /etc/sysconfig/zaptel ]; then \
-+# install -D -m 644 zaptel.sysconfig $(INSTALL_PREFIX)/etc/sysconfig/zaptel; \
-+# fi
-+# if [ -d /etc/sysconfig/network-scripts ]; then \
-+# install -D -m 755 ifup-hdlc $(INSTALL_PREFIX)/etc/sysconfig/network-scripts/ifup-hdlc; \
-+# fi
-
- clean:
-+ -make -C $(KSRC) SUBDIRS=$(PWD)/zaphfc clean
-+ -make -C $(KSRC) SUBDIRS=$(PWD)/qozap clean
- rm -f torisatool makefw tor2fw.h
-- rm -f zttool ztspeed zttest ztmonitor
-+ rm -f fxstest ztmonitor ztspeed zttest
-+ rm -f zttool
- rm -f *.o ztcfg tzdriver sethdlc sethdlc-new
- rm -f $(TZOBJS) $(LIBTONEZONE) *.lo
- rm -f *.ko *.mod.c .*o.cmd
Modified: zaptel/trunk/debian/patches/Makefile_deps_kern.dpatch
===================================================================
--- zaptel/trunk/debian/patches/Makefile_deps_kern.dpatch 2006-04-30 15:19:14 UTC (rev 1655)
+++ zaptel/trunk/debian/patches/Makefile_deps_kern.dpatch 2006-04-30 16:30:35 UTC (rev 1656)
@@ -5,6 +5,7 @@
## DP: Remove unnecessary dependencies of kernel modules.
## DP: Patch has no functional effect as the rule below already adds
## DP: dependency on zaptel.h .
+## -- applied upstream in 1.2 branch
@DPATCH@
diff -urNad zaptel-1.2.2~/Makefile zaptel-1.2.2/Makefile
Modified: zaptel/trunk/debian/patches/Makefile_deps_utils.dpatch
===================================================================
--- zaptel/trunk/debian/patches/Makefile_deps_utils.dpatch 2006-04-30 15:19:14 UTC (rev 1655)
+++ zaptel/trunk/debian/patches/Makefile_deps_utils.dpatch 2006-04-30 16:30:35 UTC (rev 1656)
@@ -3,6 +3,7 @@
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Clean dependencies and build flags of misc. utils
+## -- make specific, cannot be commited upstream.
@DPATCH@
diff -urNad zaptel-1.2.0-0beta1/Makefile /tmp/dpep.GxuAYU/zaptel-1.2.0-0beta1/Makefile
Modified: zaptel/trunk/debian/patches/Makefile_gendigits.dpatch
===================================================================
--- zaptel/trunk/debian/patches/Makefile_gendigits.dpatch 2006-04-30 15:19:14 UTC (rev 1655)
+++ zaptel/trunk/debian/patches/Makefile_gendigits.dpatch 2006-04-30 16:30:35 UTC (rev 1656)
@@ -2,7 +2,8 @@
## Makefiles_gendigits.dpatch by Kilian Krause <kilian at debian.org>
##
## All lines beginning with `## DP:' are a description of the patch.
-## DP: No description.
+## DP: complementary patch to gendigits.dpatch
+## -- applied upstream in 1.2 branch
@DPATCH@
diff -urNad zaptel-1.2.5/Makefile /tmp/dpep.lRxQzx/zaptel-1.2.5/Makefile
Modified: zaptel/trunk/debian/patches/Makefile_kbuild.dpatch
===================================================================
--- zaptel/trunk/debian/patches/Makefile_kbuild.dpatch 2006-04-30 15:19:14 UTC (rev 1655)
+++ zaptel/trunk/debian/patches/Makefile_kbuild.dpatch 2006-04-30 16:30:35 UTC (rev 1656)
@@ -4,6 +4,7 @@
## All lines beginning with `## DP:' are a description of the patch.
## DP: use kbuild (the kernel build system) more extensively. This will
## DP: be useful for recursive builds.
+## -- applied upstream in 1.2 branch
@DPATCH@
diff -urNad zaptel-1.2.0/Makefile /tmp/dpep.UEJtoR/zaptel-1.2.0/Makefile
Deleted: zaptel/trunk/debian/patches/Makefile_pscmd.dpatch
===================================================================
--- zaptel/trunk/debian/patches/Makefile_pscmd.dpatch 2006-04-30 15:19:14 UTC (rev 1655)
+++ zaptel/trunk/debian/patches/Makefile_pscmd.dpatch 2006-04-30 16:30:35 UTC (rev 1656)
@@ -1,30 +0,0 @@
-#! /bin/sh /usr/share/dpatch/dpatch-run
-## Makefile_pscmd.dpatch by Tzafrir Cohen <tzafrir.cohen at xorcom.com>
-##
-## All lines beginning with `## DP:' are a description of the patch.
-## DP: Removes some unneeded and incorrect cruft, IMHO. See note below.
-
- at DPATCH@
-diff -urNad zaptel-1.2.0-0beta1/Makefile /tmp/dpep.Erjape/zaptel-1.2.0-0beta1/Makefile
---- zaptel-1.2.0-0beta1/Makefile 2005-09-08 08:39:30.000000000 +0300
-+++ /tmp/dpep.Erjape/zaptel-1.2.0-0beta1/Makefile 2005-09-08 08:45:25.000000000 +0300
-@@ -93,14 +93,11 @@
- endif
- endif
-
--ifeq (${BUILDVER},linux24)
--#We only support DEVFS in linux 2.4 kernels, since its considered obsolete post 2.4
--DYNFS:=$(shell ps ax | grep -v grep | grep -q devfsd && echo "yes")
--endif
--ifeq (${BUILDVER},linux26)
--#Tests for newer linux-2.6 udev support
--DYNFS:=$(shell ps ax | grep -v grep | grep udevd && echo "yes")
--endif
-+# This is not related to the version that we build. Rather, to the
-+# version that we runs. If we build for 2.4 using 2.4 headers on a 2.6
-+# system with udev mounted on /dev , no point in installing files to /dev
-+# because they'll be wiped at next reboot.
-+DYNFS=$(shell ps ax | grep -v grep | grep -qw 'devfsd\|udevd' && echo "yes")
-
- CHKCONFIG:=$(shell sh -c 'type -p chkconfig' 2> /dev/null)
- ifndef CHKCONFIG
Modified: zaptel/trunk/debian/patches/Makefile_targets.dpatch
===================================================================
--- zaptel/trunk/debian/patches/Makefile_targets.dpatch 2006-04-30 15:19:14 UTC (rev 1655)
+++ zaptel/trunk/debian/patches/Makefile_targets.dpatch 2006-04-30 16:30:35 UTC (rev 1656)
@@ -4,6 +4,7 @@
## All lines beginning with `## DP:' are a description of the patch.
## DP: Adds targets modules, programs, install-modules and install-programs to
## DP: allow separate installation of the programs and the modules
+## -- will be fixed later on.. still pending.
@DPATCH@
diff -urNad zaptel-1.2.1/Makefile /tmp/dpep.hnX6Yg/zaptel-1.2.1/Makefile
Modified: zaptel/trunk/debian/patches/Makefile_xpp.dpatch
===================================================================
--- zaptel/trunk/debian/patches/Makefile_xpp.dpatch 2006-04-30 15:19:14 UTC (rev 1655)
+++ zaptel/trunk/debian/patches/Makefile_xpp.dpatch 2006-04-30 16:30:35 UTC (rev 1656)
@@ -4,6 +4,7 @@
## All lines beginning with `## DP:' are a description of the patch.
## DP: patch the makefile to build (using kbuild on 2.6) the xpp modules
## DP: in the subdirectory xpp/
+## -- applied upstream in 1.2 branch
@DPATCH@
diff -urNad zaptel-1.2.0/Makefile /tmp/dpep.HPVfs0/zaptel-1.2.0/Makefile
Deleted: zaptel/trunk/debian/patches/bristuff-0.2.0-RC8n.dpatch
===================================================================
--- zaptel/trunk/debian/patches/bristuff-0.2.0-RC8n.dpatch 2006-04-30 15:19:14 UTC (rev 1655)
+++ zaptel/trunk/debian/patches/bristuff-0.2.0-RC8n.dpatch 2006-04-30 16:30:35 UTC (rev 1656)
@@ -1,4281 +0,0 @@
-#! /bin/sh /usr/share/dpatch/dpatch-run
-## bristuff_prueba.dpatch by <santiago at unicauca.edu.co>
-##
-## All lines beginning with `## DP:' are a description of the patch.
-## DP: No description.
-
- at DPATCH@
-diff -urNad zaptel-1.0.9/Makefile /tmp/dpep.gzWFVh/zaptel-1.0.9/Makefile
---- zaptel-1.0.9/Makefile 2005-05-11 21:26:49.000000000 -0500
-+++ /tmp/dpep.gzWFVh/zaptel-1.0.9/Makefile 2005-07-30 01:09:25.000000000 -0500
-@@ -19,7 +19,7 @@
- CFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-fsigned-char"; fi)
- CFLAGS+=$(shell if uname -m | grep -q x86_64; then echo "-m64"; fi)
- LCFLAGS=-fPIC $(CFLAGS) -DBUILDING_TONEZONE
--KFLAGS+=-I/usr/src/linux-2.4/include -O6
-+KFLAGS+=-I/usr/src/linux/include -O6
- KFLAGS+=-DMODULE -D__KERNEL__ -DEXPORT_SYMTAB -I/usr/src/linux/drivers/net \
- -Wall -I. -Wstrict-prototypes -fomit-frame-pointer -I/usr/src/linux/drivers/net/wan -I /usr/src/linux/include -I/usr/src/linux/include/net
- KFLAGS+=$(shell if [ -f $(KINCLUDES)/linux/modversions.h ] ; then echo "-DMODVERSIONS -include $(KINCLUDES)/linux/modversions.h" ; fi)
-@@ -43,11 +43,11 @@
-
- ifeq (${BUILDVER},linux24)
- #We only support DEVFS in linux 2.4 kernels, since its considered obsolete post 2.4
--DYNFS=$(shell ps ax | grep -v grep | grep -q devfsd && echo "yes")
-+DYNFS=$(ps ax | grep -v grep | grep -q devfsd && echo "yes")
- endif
- ifeq (${BUILDVER},linux26)
- #Tests for newer linux-2.6 udev support
--DYNFS=$(shell ps ax | grep -v grep | grep udevd && echo "yes")
-+DYNFS=$(ps ax | grep -v grep | grep udevd && echo "yes")
- endif
-
- CHKCONFIG=$(shell sh -c 'type -p chkconfig' 2> /dev/null)
-@@ -343,7 +343,7 @@
-
- clean:
- rm -f torisatool makefw tor2fw.h
-- rm -f zttool
-+ rm -f zttool ztspeed zttest ztmonitor
- rm -f *.o ztcfg tzdriver sethdlc sethdlc-new
- rm -f $(TZOBJS) $(LIBTONEZONE) *.lo
- rm -f *.ko *.mod.c .*o.cmd
-@@ -351,3 +351,4 @@
- rm -f libtonezone*
- rm -f tor2ee
- rm -f core
-+ rm -rf .tmp_versions
-diff -urNad zaptel-1.0.9/qozap/LICENSE /tmp/dpep.gzWFVh/zaptel-1.0.9/qozap/LICENSE
---- zaptel-1.0.9/qozap/LICENSE 1969-12-31 19:00:00.000000000 -0500
-+++ /tmp/dpep.gzWFVh/zaptel-1.0.9/qozap/LICENSE 2003-08-18 20:24:43.000000000 -0500
-@@ -0,0 +1,341 @@
-+
-+ GNU GENERAL PUBLIC LICENSE
-+ Version 2, June 1991
-+
-+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-+ Everyone is permitted to copy and distribute verbatim copies
-+ of this license document, but changing it is not allowed.
-+
-+ Preamble
-+
-+ The licenses for most software are designed to take away your
-+freedom to share and change it. By contrast, the GNU General Public
-+License is intended to guarantee your freedom to share and change free
-+software--to make sure the software is free for all its users. This
-+General Public License applies to most of the Free Software
-+Foundation's software and to any other program whose authors commit to
-+using it. (Some other Free Software Foundation software is covered by
-+the GNU Library General Public License instead.) You can apply it to
-+your programs, too.
-+
-+ When we speak of free software, we are referring to freedom, not
-+price. Our General Public Licenses are designed to make sure that you
-+have the freedom to distribute copies of free software (and charge for
-+this service if you wish), that you receive source code or can get it
-+if you want it, that you can change the software or use pieces of it
-+in new free programs; and that you know you can do these things.
-+
-+ To protect your rights, we need to make restrictions that forbid
-+anyone to deny you these rights or to ask you to surrender the rights.
-+These restrictions translate to certain responsibilities for you if you
-+distribute copies of the software, or if you modify it.
-+
-+ For example, if you distribute copies of such a program, whether
-+gratis or for a fee, you must give the recipients all the rights that
-+you have. You must make sure that they, too, receive or can get the
-+source code. And you must show them these terms so they know their
-+rights.
-+
-+ We protect your rights with two steps: (1) copyright the software, and
-+(2) offer you this license which gives you legal permission to copy,
-+distribute and/or modify the software.
-+
-+ Also, for each author's protection and ours, we want to make certain
-+that everyone understands that there is no warranty for this free
-+software. If the software is modified by someone else and passed on, we
-+want its recipients to know that what they have is not the original, so
-+that any problems introduced by others will not reflect on the original
-+authors' reputations.
-+
-+ Finally, any free program is threatened constantly by software
-+patents. We wish to avoid the danger that redistributors of a free
-+program will individually obtain patent licenses, in effect making the
-+program proprietary. To prevent this, we have made it clear that any
-+patent must be licensed for everyone's free use or not licensed at all.
-+
-+ The precise terms and conditions for copying, distribution and
-+modification follow.
-+
-+ GNU GENERAL PUBLIC LICENSE
-+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-+
-+ 0. This License applies to any program or other work which contains
-+a notice placed by the copyright holder saying it may be distributed
-+under the terms of this General Public License. The "Program", below,
-+refers to any such program or work, and a "work based on the Program"
-+means either the Program or any derivative work under copyright law:
-+that is to say, a work containing the Program or a portion of it,
-+either verbatim or with modifications and/or translated into another
-+language. (Hereinafter, translation is included without limitation in
-+the term "modification".) Each licensee is addressed as "you".
-+
-+Activities other than copying, distribution and modification are not
-+covered by this License; they are outside its scope. The act of
-+running the Program is not restricted, and the output from the Program
-+is covered only if its contents constitute a work based on the
-+Program (independent of having been made by running the Program).
-+Whether that is true depends on what the Program does.
-+
-+ 1. You may copy and distribute verbatim copies of the Program's
-+source code as you receive it, in any medium, provided that you
-+conspicuously and appropriately publish on each copy an appropriate
-+copyright notice and disclaimer of warranty; keep intact all the
-+notices that refer to this License and to the absence of any warranty;
-+and give any other recipients of the Program a copy of this License
-+along with the Program.
-+
-+You may charge a fee for the physical act of transferring a copy, and
-+you may at your option offer warranty protection in exchange for a fee.
-+
-+ 2. You may modify your copy or copies of the Program or any portion
-+of it, thus forming a work based on the Program, and copy and
-+distribute such modifications or work under the terms of Section 1
-+above, provided that you also meet all of these conditions:
-+
-+ a) You must cause the modified files to carry prominent notices
-+ stating that you changed the files and the date of any change.
-+
-+ b) You must cause any work that you distribute or publish, that in
-+ whole or in part contains or is derived from the Program or any
-+ part thereof, to be licensed as a whole at no charge to all third
-+ parties under the terms of this License.
-+
-+ c) If the modified program normally reads commands interactively
-+ when run, you must cause it, when started running for such
-+ interactive use in the most ordinary way, to print or display an
-+ announcement including an appropriate copyright notice and a
-+ notice that there is no warranty (or else, saying that you provide
-+ a warranty) and that users may redistribute the program under
-+ these conditions, and telling the user how to view a copy of this
-+ License. (Exception: if the Program itself is interactive but
-+ does not normally print such an announcement, your work based on
-+ the Program is not required to print an announcement.)
-+
-+These requirements apply to the modified work as a whole. If
-+identifiable sections of that work are not derived from the Program,
-+and can be reasonably considered independent and separate works in
-+themselves, then this License, and its terms, do not apply to those
-+sections when you distribute them as separate works. But when you
-+distribute the same sections as part of a whole which is a work based
-+on the Program, the distribution of the whole must be on the terms of
-+this License, whose permissions for other licensees extend to the
-+entire whole, and thus to each and every part regardless of who wrote it.
-+
-+Thus, it is not the intent of this section to claim rights or contest
-+your rights to work written entirely by you; rather, the intent is to
-+exercise the right to control the distribution of derivative or
-+collective works based on the Program.
-+
-+In addition, mere aggregation of another work not based on the Program
-+with the Program (or with a work based on the Program) on a volume of
-+a storage or distribution medium does not bring the other work under
-+the scope of this License.
-+
-+ 3. You may copy and distribute the Program (or a work based on it,
-+under Section 2) in object code or executable form under the terms of
-+Sections 1 and 2 above provided that you also do one of the following:
-+
-+ a) Accompany it with the complete corresponding machine-readable
-+ source code, which must be distributed under the terms of Sections
-+ 1 and 2 above on a medium customarily used for software interchange; or,
-+
-+ b) Accompany it with a written offer, valid for at least three
-+ years, to give any third party, for a charge no more than your
-+ cost of physically performing source distribution, a complete
-+ machine-readable copy of the corresponding source code, to be
-+ distributed under the terms of Sections 1 and 2 above on a medium
-+ customarily used for software interchange; or,
-+
-+ c) Accompany it with the information you received as to the offer
-+ to distribute corresponding source code. (This alternative is
-+ allowed only for noncommercial distribution and only if you
-+ received the program in object code or executable form with such
-+ an offer, in accord with Subsection b above.)
-+
-+The source code for a work means the preferred form of the work for
-+making modifications to it. For an executable work, complete source
-+code means all the source code for all modules it contains, plus any
-+associated interface definition files, plus the scripts used to
-+control compilation and installation of the executable. However, as a
-+special exception, the source code distributed need not include
-+anything that is normally distributed (in either source or binary
-+form) with the major components (compiler, kernel, and so on) of the
-+operating system on which the executable runs, unless that component
-+itself accompanies the executable.
-+
-+If distribution of executable or object code is made by offering
-+access to copy from a designated place, then offering equivalent
-+access to copy the source code from the same place counts as
-+distribution of the source code, even though third parties are not
-+compelled to copy the source along with the object code.
-+
-+ 4. You may not copy, modify, sublicense, or distribute the Program
-+except as expressly provided under this License. Any attempt
-+otherwise to copy, modify, sublicense or distribute the Program is
-+void, and will automatically terminate your rights under this License.
-+However, parties who have received copies, or rights, from you under
-+this License will not have their licenses terminated so long as such
-+parties remain in full compliance.
-+
-+ 5. You are not required to accept this License, since you have not
-+signed it. However, nothing else grants you permission to modify or
-+distribute the Program or its derivative works. These actions are
-+prohibited by law if you do not accept this License. Therefore, by
-+modifying or distributing the Program (or any work based on the
-+Program), you indicate your acceptance of this License to do so, and
-+all its terms and conditions for copying, distributing or modifying
-+the Program or works based on it.
-+
-+ 6. Each time you redistribute the Program (or any work based on the
-+Program), the recipient automatically receives a license from the
-+original licensor to copy, distribute or modify the Program subject to
-+these terms and conditions. You may not impose any further
-+restrictions on the recipients' exercise of the rights granted herein.
-+You are not responsible for enforcing compliance by third parties to
-+this License.
-+
-+ 7. If, as a consequence of a court judgment or allegation of patent
-+infringement or for any other reason (not limited to patent issues),
-+conditions are imposed on you (whether by court order, agreement or
-+otherwise) that contradict the conditions of this License, they do not
-+excuse you from the conditions of this License. If you cannot
-+distribute so as to satisfy simultaneously your obligations under this
-+License and any other pertinent obligations, then as a consequence you
-+may not distribute the Program at all. For example, if a patent
-+license would not permit royalty-free redistribution of the Program by
-+all those who receive copies directly or indirectly through you, then
-+the only way you could satisfy both it and this License would be to
-+refrain entirely from distribution of the Program.
-+
-+If any portion of this section is held invalid or unenforceable under
-+any particular circumstance, the balance of the section is intended to
-+apply and the section as a whole is intended to apply in other
-+circumstances.
-+
-+It is not the purpose of this section to induce you to infringe any
-+patents or other property right claims or to contest validity of any
-+such claims; this section has the sole purpose of protecting the
-+integrity of the free software distribution system, which is
-+implemented by public license practices. Many people have made
-+generous contributions to the wide range of software distributed
-+through that system in reliance on consistent application of that
-+system; it is up to the author/donor to decide if he or she is willing
-+to distribute software through any other system and a licensee cannot
-+impose that choice.
-+
-+This section is intended to make thoroughly clear what is believed to
-+be a consequence of the rest of this License.
-+
-+ 8. If the distribution and/or use of the Program is restricted in
-+certain countries either by patents or by copyrighted interfaces, the
-+original copyright holder who places the Program under this License
-+may add an explicit geographical distribution limitation excluding
-+those countries, so that distribution is permitted only in or among
-+countries not thus excluded. In such case, this License incorporates
-+the limitation as if written in the body of this License.
-+
-+ 9. The Free Software Foundation may publish revised and/or new versions
-+of the General Public License from time to time. Such new versions will
-+be similar in spirit to the present version, but may differ in detail to
-+address new problems or concerns.
-+
-+Each version is given a distinguishing version number. If the Program
-+specifies a version number of this License which applies to it and "any
-+later version", you have the option of following the terms and conditions
-+either of that version or of any later version published by the Free
-+Software Foundation. If the Program does not specify a version number of
-+this License, you may choose any version ever published by the Free Software
-+Foundation.
-+
-+ 10. If you wish to incorporate parts of the Program into other free
-+programs whose distribution conditions are different, write to the author
-+to ask for permission. For software which is copyrighted by the Free
-+Software Foundation, write to the Free Software Foundation; we sometimes
-+make exceptions for this. Our decision will be guided by the two goals
-+of preserving the free status of all derivatives of our free software and
-+of promoting the sharing and reuse of software generally.
-+
-+ NO WARRANTY
-+
-+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-+REPAIR OR CORRECTION.
-+
-+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-+POSSIBILITY OF SUCH DAMAGES.
-+
-+ END OF TERMS AND CONDITIONS
-+
-+ How to Apply These Terms to Your New Programs
-+
-+ If you develop a new program, and you want it to be of the greatest
-+possible use to the public, the best way to achieve this is to make it
-+free software which everyone can redistribute and change under these terms.
-+
-+ To do so, attach the following notices to the program. It is safest
-+to attach them to the start of each source file to most effectively
-+convey the exclusion of warranty; and each file should have at least
-+the "copyright" line and a pointer to where the full notice is found.
-+
-+ <one line to give the program's name and a brief idea of what it does.>
-+ Copyright (C) 19yy <name of author>
-+
-+ This program is free software; you can redistribute it and/or modify
-+ it under the terms of the GNU General Public License as published by
-+ the Free Software Foundation; either version 2 of the License, or
-+ (at your option) any later version.
-+
-+ This program is distributed in the hope that it will be useful,
-+ but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ GNU General Public License for more details.
-+
-+ You should have received a copy of the GNU General Public License
-+ along with this program; if not, write to the Free Software
-+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-+
-+
-+Also add information on how to contact you by electronic and paper mail.
-+
-+If the program is interactive, make it output a short notice like this
-+when it starts in an interactive mode:
-+
-+ Gnomovision version 69, Copyright (C) 19yy name of author
-+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-+ This is free software, and you are welcome to redistribute it
-+ under certain conditions; type `show c' for details.
-+
-+The hypothetical commands `show w' and `show c' should show the appropriate
-+parts of the General Public License. Of course, the commands you use may
-+be called something other than `show w' and `show c'; they could even be
-+mouse-clicks or menu items--whatever suits your program.
-+
-+You should also get your employer (if you work as a programmer) or your
-+school, if any, to sign a "copyright disclaimer" for the program, if
-+necessary. Here is a sample; alter the names:
-+
-+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
-+
-+ <signature of Ty Coon>, 1 April 1989
-+ Ty Coon, President of Vice
-+
-+This General Public License does not permit incorporating your program into
-+proprietary programs. If your program is a subroutine library, you may
-+consider it more useful to permit linking proprietary applications with the
-+library. If this is what you want to do, use the GNU Library General
-+Public License instead of this License.
-diff -urNad zaptel-1.0.9/qozap/Makefile /tmp/dpep.gzWFVh/zaptel-1.0.9/qozap/Makefile
---- zaptel-1.0.9/qozap/Makefile 1969-12-31 19:00:00.000000000 -0500
-+++ /tmp/dpep.gzWFVh/zaptel-1.0.9/qozap/Makefile 2005-07-04 11:54:20.000000000 -0500
-@@ -0,0 +1,91 @@
-+KINCLUDES = /usr/src/linux/include
-+BRISTUFFBASE = $(shell dirname `pwd`)
-+
-+ZAP = $(shell [ -f $(BRISTUFFBASE)/zaptel-1.0.9/zaptel.h ] && echo "-I$(BRISTUFFBASE)/zaptel-1.0.9")
-+
-+HOSTCC=gcc
-+
-+CFLAGS+=-I. $(ZAP) -O4 -g -Wall -DBUILDING_TONEZONE #-DTONEZONE_DRIVER
-+CFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-fsigned-char"; fi)
-+
-+KFLAGS=-D__KERNEL__ -DMODULE -DEXPORT_SYMTAB -fomit-frame-pointer -O2 -Wall -I$(KINCLUDES) $(ZAP)
-+KFLAGS+=$(shell [ -f $(KINCLUDES)/linux/modversions.h ] && echo "-DMODVERSIONS -include $(KINCLUDES)/linux/modversions.h")
-+KFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-msoft-float -fsigned-char"; fi)
-+
-+OBJS=qozap.o
-+
-+BUILDVER=$(shell if uname -r | grep -q ^2.6; then echo "linux26"; else echo "linux24"; fi)
-+
-+MODCONF=$(shell if [ -d $(INSTALL_PREFIX)/etc/modprobe.d ]; then echo "$(INSTALL_PREFIX)/etc/modprobe.d/zaptel"; elif [ -d $(INSTALL_PREFIX)/etc/modutils ]; then echo "$(INSTALL_PREFIX)/etc/modutils/zaptel"; elif [ -f $(INSTALL_PREFIX)/etc/modprobe.conf ]; then echo "$(INSTALL_PREFIX)/modprobe.conf"; elif [ -f $(INSTALL_PREFIX)/etc/modules.conf ]; then echo "$(INSTALL_PREFIX)/etc/modules.conf"; else echo $(INSTALL_PREFIX)/etc/conf.modules ; fi)
-+
-+MODULES=qozap
-+
-+MODULESO=$(shell for x in $(MODULES); do echo "$$x.o "; done )
-+MODULESKO=$(shell for x in $(MODULES); do echo "$$x.ko "; done )
-+
-+PWD=$(shell pwd)
-+
-+obj-m := $(MODULESO)
-+
-+all: $(BUILDVER)
-+
-+linux24: $(OBJS)
-+ sync
-+
-+linux26:
-+ @if ! [ -d /usr/src/linux-2.6 ]; then echo "Link /usr/src/linux-2.6 to your kernel sources first!"; exit 1 ; fi
-+ make -C /usr/src/linux-2.6 SUBDIRS=$(PWD) ZAP=$(ZAP) modules
-+obj-m := $(OBJS)
-+
-+qozap.o: qozap.c qozap.h
-+ $(CC) -c qozap.c $(KFLAGS)
-+
-+clean:
-+ rm -f $(OBJS) *.ko *.mod.c *.mod.o .*o.cmd *~
-+ rm -rf .tmp_versions
-+
-+testlinux24: all
-+ modprobe zaptel
-+ insmod ./qozap.o
-+ ztcfg -v
-+ cat /proc/interrupts
-+ sleep 1
-+ cat /proc/interrupts
-+ rmmod qozap zaptel
-+
-+testlinux26: all
-+ modprobe zaptel
-+ insmod ./qozap.ko
-+ ztcfg -v
-+ cat /proc/interrupts
-+ sleep 1
-+ cat /proc/interrupts
-+ rmmod qozap zaptel
-+
-+reload: unload load
-+load: load$(BUILDVER)
-+
-+test: test$(BUILDVER)
-+
-+
-+loadlinux24: linux24
-+ modprobe zaptel
-+ insmod ./qozap.o
-+ ztcfg -v
-+
-+loadlinux26: linux26
-+ sync
-+ modprobe zaptel
-+ insmod ./qozap.ko
-+ ztcfg -v
-+
-+unload:
-+ rmmod qozap zaptel
-+
-+install: install$(BUILDVER)
-+
-+installlinux26:
-+ install -D -m 644 qozap.ko $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/qozap.ko
-+
-+installlinux24:
-+ install -D -m 644 qozap.o $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/qozap.o
-diff -urNad zaptel-1.0.9/qozap/qozap.c /tmp/dpep.gzWFVh/zaptel-1.0.9/qozap/qozap.c
---- zaptel-1.0.9/qozap/qozap.c 1969-12-31 19:00:00.000000000 -0500
-+++ /tmp/dpep.gzWFVh/zaptel-1.0.9/qozap/qozap.c 2005-07-28 02:21:53.000000000 -0500
-@@ -0,0 +1,1255 @@
-+/*
-+ * qozap.c - Zaptel driver for the quadBRI PCI ISDN card
-+ * and the octoBRI PCI ISDN card!
-+ *
-+ * Copyright (C) 2003, 2004, 2005 Junghanns.NET GmbH
-+ *
-+ * Klaus-Peter Junghanns <kpj at junghanns.net>
-+ *
-+ * This program is free software and may be modified and
-+ * distributed under the terms of the GNU Public License.
-+ *
-+ */
-+#include <linux/kernel.h>
-+#include <linux/module.h>
-+#include <linux/pci.h>
-+#include <linux/init.h>
-+#include <linux/interrupt.h>
-+#include <zaptel.h>
-+#include "qozap.h"
-+
-+#if CONFIG_PCI
-+
-+static int doubleclock=0;
-+static int ports=-1; /* autodetect */
-+static int debug=0;
-+static struct qoz_card *qoz_dev_list = NULL;
-+static int qoz_dev_count = 0;
-+static int totalBRIs = 0;
-+static struct pci_dev *multi_qoz = NULL;
-+static spinlock_t registerlock = SPIN_LOCK_UNLOCKED;
-+
-+static int ztqoz_shutdown(struct zt_span *span);
-+
-+int qoz_waitbusy(struct qoz_card *qoztmp) {
-+ int x=1000;
-+ while (x-- && (qoz_inb(qoztmp,qoz_R_STATUS) & 1));
-+ if (x < 0) {
-+ return -1;
-+ } else {
-+ return 0;
-+ }
-+}
-+
-+void qoz_shutdownCard(struct qoz_card *qoztmp) {
-+ int s=0;
-+ unsigned long flags;
-+ int stports=0;
-+ if (qoztmp == NULL) {
-+ printk(KERN_INFO "qozap: shutting down NULL card!\n");
-+ return;
-+ }
-+
-+ if (qoztmp->pci_io == NULL) {
-+ return;
-+ }
-+
-+ if (debug)
-+ printk(KERN_INFO "qozap: shutting down card %d (cardID %d) at %p.\n",qoztmp->cardno,qoztmp->cardID,qoztmp->pci_io);
-+
-+ if (qoztmp->ztdev != NULL) {
-+ stports = qoztmp->stports;
-+ for (s=0; s < stports; s++) {
-+ if(qoztmp->ztdev->spans[s].flags & ZT_FLAG_RUNNING) {
-+ ztqoz_shutdown(&qoztmp->ztdev->spans[s]);
-+ if (debug)
-+ printk(KERN_INFO "qozap: shutdown card %d span %d.\n",qoztmp->cardno,s+1);
-+ }
-+ }
-+ }
-+
-+ spin_lock_irqsave(&qoztmp->lock,flags);
-+
-+ // turn off irqs
-+ qoz_outb(qoztmp,qoz_R_IRQ_CTRL, 0);
-+ qoz_outb(qoztmp,qoz_R_IRQMSK_MISC, 0);
-+ qoz_outb(qoztmp,qoz_R_SCI_MSK, 0);
-+
-+ free_irq(qoztmp->irq,qoztmp);
-+
-+ // softreset
-+ qoz_outb(qoztmp,qoz_R_CIRM,0x8);
-+ qoz_outb(qoztmp,qoz_R_CIRM,0x0);
-+ qoz_waitbusy(qoztmp);
-+
-+ qoz_outb(qoztmp,qoz_R_IRQMSK_MISC, 0);
-+ qoz_outb(qoztmp,qoz_R_SCI_MSK, 0);
-+ qoz_outb(qoztmp,qoz_R_IRQ_CTRL, 0);
-+
-+ iounmap((void *) qoztmp->pci_io);
-+ qoztmp->pci_io = NULL;
-+
-+ if (qoztmp->pcidev != NULL) {
-+ pci_disable_device(qoztmp->pcidev);
-+ }
-+ pci_write_config_word(qoztmp->pcidev, PCI_COMMAND, 0); // disable memio
-+
-+ spin_unlock_irqrestore(&qoztmp->lock,flags);
-+
-+ if (qoztmp->ztdev != NULL) {
-+ stports = qoztmp->stports;
-+ for (s=0; s < stports; s++) {
-+ if(qoztmp->ztdev->spans[s].flags & ZT_FLAG_REGISTERED) {
-+ zt_unregister(&qoztmp->ztdev->spans[s]);
-+ if (debug)
-+ printk(KERN_INFO "qozap: unregistered card %d span %d.\n",qoztmp->cardno,s+1);
-+ }
-+ }
-+ kfree(qoztmp->ztdev);
-+ qoztmp->ztdev = NULL;
-+ }
-+}
-+
-+void qoz_doLEDs(struct qoz_card *qoztmp) {
-+ if ((qoztmp->type == 0xb520) && (qoztmp->stports == 4)){
-+// if ((qoztmp->ticks > 0) && (qoztmp->ticks <= 300)) {
-+ qoz_outb(qoztmp,qoz_R_GPIO_SEL,0x20 | 0x10);
-+ qoz_outb(qoztmp,qoz_R_GPIO_EN1,0xf);
-+ qoz_outb(qoztmp,qoz_R_GPIO_OUT1,(qoztmp->leds[0] | (qoztmp->leds[1] << 1) | (qoztmp->leds[2] << 2) | (qoztmp->leds[3] << 3)));
-+/* }
-+ if ((qoztmp->ticks > 300) && (qoztmp->ticks <= 600)) {
-+ qoz_outb(qoztmp,qoz_R_GPIO_EN1,0x0);
-+ } */
-+ }
-+}
-+
-+void qoz_resetCard(struct qoz_card *qoztmp) {
-+ unsigned long flags;
-+ unsigned char i=0;
-+ spin_lock_irqsave(&(qoztmp->lock),flags);
-+ pci_write_config_word(qoztmp->pcidev, PCI_COMMAND, PCI_COMMAND_MEMORY); // enable memio
-+
-+ // soft reset
-+ qoz_outb(qoztmp,qoz_R_CIRM,0x8);
-+ qoz_outb(qoztmp,qoz_R_CIRM,0x0);
-+ qoz_waitbusy(qoztmp);
-+
-+ // fifo reset
-+ qoz_outb(qoztmp,qoz_R_CIRM,0x10);
-+ qoz_outb(qoztmp,qoz_R_CIRM,0x0);
-+ qoz_waitbusy(qoztmp);
-+
-+ // s/t reset
-+ qoz_outb(qoztmp,qoz_R_CIRM,0x40);
-+ qoz_outb(qoztmp,qoz_R_CIRM,0x0);
-+ qoz_waitbusy(qoztmp);
-+
-+ // set S0 amplitude
-+ qoz_outb(qoztmp,qoz_R_PWM_MD,0xa0);
-+ qoz_outb(qoztmp,qoz_R_PWM1,0x19);
-+
-+ // set up the timer
-+ qoz_outb(qoztmp,qoz_R_TI_WD, 0x2); // 1 ms
-+ qoz_outb(qoztmp,qoz_R_IRQMSK_MISC, 0x2);
-+ qoz_outb(qoztmp,qoz_R_PCM_MD0, 0x1);
-+
-+ // all state changes
-+ qoz_outb(qoztmp,qoz_R_SCI_MSK, 0xff);
-+
-+ if (qoztmp->type == 0xb552) {
-+ qoz_outb(qoztmp,qoz_R_FIFO_MD,0x16);
-+ } else {
-+ qoz_outb(qoztmp,qoz_R_FIFO_MD,0x26);
-+ }
-+
-+ // double clock
-+ if (doubleclock == 1) {
-+ // hopefully you have set CLK_MODE correctly!
-+ qoz_outb(qoztmp,qoz_R_BRG_PCM_CFG,0x20);
-+ } else {
-+ if (qoztmp->type == 0x08b4) {
-+ qoz_outb(qoztmp,qoz_R_BRG_PCM_CFG,0x0);
-+ } else {
-+ qoz_outb(qoztmp,qoz_R_BRG_PCM_CFG,0x20);
-+ }
-+ }
-+ qoz_outb(qoztmp,qoz_R_CTRL,0x0);
-+
-+ // LEDs RED
-+ qoztmp->leds[0] = 0x0;
-+ qoztmp->leds[1] = 0x0;
-+ qoztmp->leds[2] = 0x0;
-+ qoztmp->leds[3] = 0x0;
-+ qoztmp->leds[4] = 0x0;
-+ qoztmp->leds[5] = 0x0;
-+ qoztmp->leds[6] = 0x0;
-+ qoztmp->leds[7] = 0x0;
-+
-+ /* Finally enable IRQ output */
-+ qoz_outb(qoztmp,qoz_R_IRQ_CTRL, 0x8 | 0x1);
-+ if (qoztmp->type == 0xb552) {
-+ qoztmp->stports = 8;
-+ } else {
-+ qoztmp->stports = 4;
-+ }
-+ qoztmp->ticks = 0;
-+ qoztmp->clicks = 0;
-+
-+ for (i=0;i<qoztmp->stports;i++) {
-+ if (qoztmp->st[i].nt_mode) {
-+ qoz_outb(qoztmp,qoz_R_ST_SYNC,0x8 | i);
-+ break;
-+ }
-+ }
-+ if (i != qoztmp->stports) {
-+ qoz_outb(qoztmp,qoz_R_ST_SYNC,0x0);
-+ }
-+ spin_unlock_irqrestore(&(qoztmp->lock),flags);
-+}
-+
-+void qoz_registerCard(struct qoz_card *qozcard) {
-+ spin_lock(®isterlock);
-+ if (qozcard != NULL) {
-+ qozcard->prev = NULL;
-+ qozcard->next = qoz_dev_list;
-+ if (qoz_dev_list) {
-+ qoz_dev_list->prev = qozcard;
-+ }
-+ qoz_dev_list = qozcard;
-+ qozcard->cardno = ++qoz_dev_count;
-+ } else {
-+ printk(KERN_INFO "qozap: trying to register NULL card.\n");
-+ }
-+ spin_unlock(®isterlock);
-+}
-+
-+static int qoz_dfifo_tx(struct qoz_card *qoztmp, int stport) {
-+ int chan = 2;
-+ int x=0;
-+ char fifo = 0;
-+ char offset = 0;
-+
-+ if (qoztmp->type == 0xb552) {
-+ offset = 24;
-+ } else {
-+ offset = 28;
-+ }
-+
-+ fifo = stport + offset;
-+
-+ if (qoztmp->ztdev->chans[stport][chan].bytes2transmit < 1) {
-+ return 0;
-+ } else {
-+ /* select fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,fifo << 1);
-+ qoz_waitbusy(qoztmp);
-+
-+ if (debug > 1)
-+ printk(KERN_INFO "qozap: card %d stport %d TX [ ", qoztmp->cardno, stport + 1);
-+ /* copy frame to fifo */
-+ for (x=0;x<qoztmp->ztdev->chans[stport][chan].bytes2transmit;x++) {
-+ if (debug > 1)
-+ printk("%#x ",qoztmp->dtxbuf[stport][x]);
-+ qoz_outb(qoztmp,qoz_A_FIFO_DATA0,qoztmp->dtxbuf[stport][x]);
-+ }
-+ if (debug > 1)
-+ printk("] %d bytes\n",qoztmp->ztdev->chans[stport][chan].bytes2transmit);
-+
-+ if (qoztmp->ztdev->chans[stport][chan].eoftx == 1) {
-+ /* transmit HDLC frame */
-+ qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x1);
-+ qoz_waitbusy(qoztmp);
-+ }
-+ }
-+ return 0;
-+}
-+
-+static int qoz_fifo_tx(struct qoz_card *qoztmp, char fifo) {
-+ int stport = fifo / 2;
-+ int chan = fifo % 2;
-+
-+ /* select fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,0x80 | (fifo << 1));
-+ qoz_waitbusy(qoztmp);
-+ /* transmit 8 bytes of transparent data */
-+ qoz_outdw(qoztmp,qoz_A_FIFO_DATA0,*((unsigned int *) &qoztmp->txbuf[stport][chan][0]));
-+ qoz_outdw(qoztmp,qoz_A_FIFO_DATA0,*((unsigned int *) &qoztmp->txbuf[stport][chan][4]));
-+
-+ return 0;
-+}
-+
-+static int qoz_dfifo_rx(struct qoz_card *qoztmp, int stport) {
-+ unsigned char f1=1,f2=1,data,stat;
-+ unsigned char of1=0,of2=0;
-+ int len,i;
-+ unsigned short z1=1,z2=1;
-+ unsigned short oz1=0,oz2=0;
-+ char fifo = 0;
-+ char offset = 0;
-+
-+ if (qoztmp->type == 0xb552) {
-+ offset = 24;
-+ } else {
-+ offset = 28;
-+ }
-+
-+ fifo = stport + offset;
-+ // select rx fifo
-+
-+ qoz_outb(qoztmp,qoz_R_FIFO,(fifo << 1) | 1);
-+ qoz_waitbusy(qoztmp);
-+
-+ while ((of1 != f1) && (of2 != f2)) {
-+ of1 = f1;
-+ of2 = f2;
-+ f1 = qoz_inb(qoztmp,qoz_A_F1) & 0xf;
-+ f2 = qoz_inb(qoztmp,qoz_A_F2) & 0xf;
-+ }
-+
-+ if (f1 == f2) {
-+ /* no frame */
-+ qoztmp->st[stport].drx--;
-+ qoztmp->ztdev->chans[stport][2].bytes2receive = 0;
-+ return 0;
-+ }
-+
-+ while ((oz1 != z1) && (oz2 != z2)) {
-+ oz1 = z1;
-+ oz2 = z2;
-+ if (qoztmp->type != 0xb552) {
-+ z1 = qoz_inw(qoztmp,qoz_A_Z1) & 0x7ff;
-+ z2 = qoz_inw(qoztmp,qoz_A_Z2) & 0x7ff;
-+ } else {
-+ z1 = qoz_inw(qoztmp,qoz_A_Z1) & 0x3ff;
-+ z2 = qoz_inw(qoztmp,qoz_A_Z2) & 0x3ff;
-+ }
-+ }
-+
-+ if (qoztmp->type == 0xb552) {
-+ len = z1 - z2;
-+ if (len < 0) {
-+ len += qoz_DFIFO_SIZE8;
-+ }
-+ } else {
-+ len = z1 - z2;
-+ if (len < 0) {
-+ len += qoz_DFIFO_SIZE4;
-+ }
-+ }
-+
-+ if (len > qoz_DFIFO_SIZE4) {
-+ printk(KERN_INFO "\nqozap: buffer overflow in D channel RX!\n");
-+ qoztmp->ztdev->chans[stport][2].bytes2receive = 0;
-+ qoztmp->ztdev->chans[stport][2].eofrx = 0;
-+ } else {
-+ if (debug > 1) printk(KERN_INFO "qozap: card %d span %d RX [ ", qoztmp->cardno, stport + 1);
-+ for (i=0; i<len; i++) {
-+ data = qoz_inb(qoztmp,qoz_A_FIFO_DATA0);
-+ qoztmp->drxbuf[stport][i] = data;
-+ if (debug > 1) printk("%#x ",data);
-+ }
-+ if (debug > 1) printk("] %d bytes\n", len);
-+ qoztmp->ztdev->chans[stport][2].bytes2receive = i;
-+ qoztmp->ztdev->chans[stport][2].eofrx = 1;
-+ }
-+
-+ stat = qoz_inb(qoztmp,qoz_A_FIFO_DATA0);
-+ if (stat != 0x0) {
-+ // bad CRC, skip it
-+ printk(KERN_INFO "qozap: CRC error for HDLC frame on card %d (cardID %d) S/T port %d\n",qoztmp->cardno, qoztmp->cardID, stport+1);
-+ qoztmp->ztdev->chans[stport][2].bytes2receive = 0;
-+ qoztmp->ztdev->chans[stport][2].eofrx = 0;
-+// zt_qevent_nolock(&qoztmp->ztdev->chans[stport][2], ZT_EVENT_BADFCS);
-+ }
-+ qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x1);
-+ qoz_waitbusy(qoztmp);
-+
-+ /* frame recevived */
-+ if (qoztmp->st[stport].drx > 0) {
-+ qoztmp->st[stport].drx--;
-+ } else {
-+ printk(KERN_INFO "qozap: trying to receive too much (card %d span %d drx %d)\n", qoztmp->cardno, stport+1, qoztmp->st[stport].drx);
-+ qoztmp->st[stport].drx = 0;
-+ }
-+ return 0;
-+}
-+
-+
-+static int qoz_fifo_rx(struct qoz_card *qoztmp, char fifo) {
-+ int stport = fifo / 2;
-+ int chan = fifo % 2;
-+ unsigned char data;
-+ int len,i;
-+ unsigned short z1=1,z2=1;
-+ unsigned short oz1=0,oz2=0;
-+ int mumbojumbo=0;
-+
-+ /* select rx fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,0x80 | (fifo << 1) | 1);
-+ qoz_waitbusy(qoztmp);
-+
-+ while ((oz1 != z1) && (oz2 != z2)) {
-+ oz1 = z1;
-+ oz2 = z2;
-+ z1 = qoz_inw(qoztmp,qoz_A_Z1) & 0x7f;
-+ z2 = qoz_inw(qoztmp,qoz_A_Z2) & 0x7f;
-+ }
-+ len = z1 - z2;
-+ if (len < 0) {
-+ len += qoz_FIFO_SIZE;
-+ }
-+ if (len > 2 * ZT_CHUNKSIZE) {
-+ mumbojumbo = len - (2 * ZT_CHUNKSIZE);
-+ len = ZT_CHUNKSIZE;
-+ for (i=0;i<mumbojumbo;i++) {
-+ data = qoz_inb(qoztmp,qoz_A_FIFO_DATA0);
-+ }
-+ qoztmp->clicks++;
-+ if ((qoztmp->clicks > 100) || (debug == 4)) {
-+ printk(KERN_CRIT "qozap: dropped audio card %d cardid %d bytes %d z1 %d z2 %d\n", qoztmp->cardno, qoztmp->cardID, mumbojumbo, z1, z2);
-+ qoztmp->clicks = 0;
-+ }
-+ }
-+ if (len < ZT_CHUNKSIZE) {
-+// printk(KERN_INFO "qozap: not enough to receive (%d bytes)\n",len);
-+ return 0;
-+ } else {
-+ *((unsigned int *) &qoztmp->rxbuf[stport][chan][0]) = qoz_indw(qoztmp,qoz_A_FIFO_DATA0);
-+ *((unsigned int *) &qoztmp->rxbuf[stport][chan][4]) = qoz_indw(qoztmp,qoz_A_FIFO_DATA0);
-+ }
-+
-+ zt_ec_chunk(&qoztmp->ztdev->spans[stport].chans[chan], qoztmp->ztdev->spans[stport].chans[chan].readchunk, qoztmp->ztdev->spans[stport].chans[chan].writechunk);
-+
-+// printk(KERN_INFO "s/t port %d, channel %d, dbufi=%d, f1=%d, f2=%d, z1=%d, z2=%d => len = %d stat=%#x, hdlc=%d\n",stport,chan,qoztmp->st[stport].dbufi,f1,f2,z1,z2,len,stat,hdlc);
-+ return 0;
-+}
-+
-+
-+static inline void qoz_run(struct qoz_card *qoztmp) {
-+ int s=0;
-+ if (qoztmp->ztdev != NULL) {
-+ for (s=0;s<qoztmp->stports;s++) {
-+ if (qoztmp->ztdev->spans[s].flags & ZT_FLAG_RUNNING) {
-+ /* oh zaptel! tell us what to transmit... */
-+ zt_transmit(&qoztmp->ztdev->spans[s]);
-+ /* B1 xmit */
-+ qoz_fifo_tx(qoztmp, s * 2);
-+ /* B2 xmit */
-+ qoz_fifo_tx(qoztmp, (s * 2) + 1);
-+ /* D xmit */
-+ qoz_dfifo_tx(qoztmp, s);
-+
-+ qoztmp->ztdev->chans[s][2].bytes2receive = 0;
-+ qoztmp->ztdev->chans[s][2].bytes2transmit = 0;
-+ qoztmp->ztdev->chans[s][2].eofrx = 0;
-+ qoztmp->ztdev->chans[s][2].eoftx = 0;
-+
-+ }
-+ /* B1 receive */
-+ qoz_fifo_rx(qoztmp,(s*2));
-+ /* B2 receive */
-+ qoz_fifo_rx(qoztmp,(s*2)+1);
-+ /* d-chan data */
-+ if (qoztmp->st[s].drx > 0) {
-+ if (debug > 2)
-+ printk(KERN_CRIT "qozap: card %d st[%d].drx = %d\n", qoztmp->cardno, s, qoztmp->st[s].drx);
-+ qoz_dfifo_rx(qoztmp, s);
-+ }
-+ if (qoztmp->ztdev->spans[s].flags & ZT_FLAG_RUNNING) {
-+ /* oh zaptel! thou shall receive! */
-+ zt_receive(&(qoztmp->ztdev->spans[s]));
-+ }
-+ }
-+ }
-+}
-+
-+#ifdef LINUX26
-+static irqreturn_t qoz_interrupt(int irq, void *dev_id, struct pt_regs *regs) {
-+#else
-+static void qoz_interrupt(int irq, void *dev_id, struct pt_regs *regs) {
-+#endif
-+ struct qoz_card *qoztmp = dev_id;
-+ struct zt_qoz *ztqoz = qoztmp->ztdev;
-+ unsigned long flags;
-+ unsigned char irq_misc,irq_sci,status,l1state,irq_foview,fi;
-+ int st=0,i=0,offset=0;
-+
-+ if (!qoztmp) {
-+#ifdef LINUX26
-+ return IRQ_NONE;
-+#else
-+ return;
-+#endif
-+ }
-+
-+ if (!qoztmp->pci_io) {
-+ printk(KERN_CRIT "qozap: no pci mem\n");
-+#ifdef LINUX26
-+ return IRQ_NONE;
-+#else
-+ return;
-+#endif
-+ }
-+
-+ spin_lock_irqsave(&(qoztmp->lock),flags);
-+ status = qoz_inb(qoztmp,qoz_R_STATUS);
-+ irq_sci = qoz_inb(qoztmp,qoz_R_SCI);
-+
-+ if (!(status & 0x80) && !(status & 0x40) && (irq_sci == 0)) {
-+// printk(KERN_CRIT "qozap: status %#x\n", status);
-+ // it's not us!
-+ spin_unlock_irqrestore(&(qoztmp->lock),flags);
-+#ifdef LINUX26
-+ return IRQ_NONE;
-+#else
-+ return;
-+#endif
-+ }
-+
-+ // misc irq
-+ if (status & 0x40) {
-+ irq_misc = qoz_inb(qoztmp,qoz_R_IRQ_MISC);
-+ if (irq_misc & 0x2) {
-+ // qozap timer
-+ qoztmp->ticks++;
-+ qoz_run(qoztmp);
-+ if (qoztmp->ticks % 100) {
-+ qoz_doLEDs(qoztmp);
-+ }
-+ if (qoztmp->ticks > 600) {
-+ qoztmp->ticks = 0;
-+ }
-+ }
-+ if (irq_misc & 0x4) {
-+ // printk(KERN_INFO "qozap proc/nonproc irq\n");
-+ }
-+ }
-+ if (status & 0x80) {
-+ /* fifo irq */
-+ irq_foview = qoz_inb(qoztmp,qoz_R_IRQ_OVIEW);
-+ if (qoztmp->type == 0xb552) {
-+ if (irq_foview & 0x60) {
-+ offset = 0;
-+ fi = qoz_inb(qoztmp,qoz_R_IRQ_FIFO_BL6);
-+ for (i=0; i < 8; i++) {
-+ if (fi & (1 << i)) {
-+ st = offset + (i / 2);
-+ if (i % 2) {
-+ if (debug > 2)
-+ printk(KERN_CRIT "qozap: HDLC RX irq fifo %d span %d\n", i, st+1);
-+ qoztmp->st[st].drx += 1;
-+ } else {
-+ if (debug > 2)
-+ printk(KERN_CRIT "qozap: HDLC TX irq fifo %d span %d\n", i, st+1);
-+ }
-+ }
-+ }
-+ }
-+ if (irq_foview & 0x80) {
-+ offset = 4;
-+ fi = qoz_inb(qoztmp,qoz_R_IRQ_FIFO_BL7);
-+ for (i=0; i < 8; i++) {
-+ if (fi & (1 << i)) {
-+ st = offset + (i / 2);
-+ if (i % 2) {
-+ if (debug > 2)
-+ printk(KERN_CRIT "qozap: HDLC RX irq fifo %d span %d\n", i, st+1);
-+ qoztmp->st[st].drx += 1;
-+ } else {
-+ if (debug > 2)
-+ printk(KERN_CRIT "qozap: HDLC TX irq fifo %d span %d\n", i, st+1);
-+ }
-+ }
-+ }
-+ }
-+ } else {
-+ if (irq_foview & 0x80) {
-+ fi = qoz_inb(qoztmp,qoz_R_IRQ_FIFO_BL7);
-+ for (i=0; i < 8; i++) {
-+ if (fi & (1 << i)) {
-+ st = i / 2;
-+ if (i % 2) {
-+ if (debug > 2)
-+ printk(KERN_CRIT "qozap: HDLC RX irq fifo %d span %d\n", i, st+1);
-+ qoztmp->st[st].drx += 1;
-+ } else {
-+ if (debug > 2)
-+ printk(KERN_CRIT "qozap: HDLC TX irq fifo %d span %d\n", i, st+1);
-+ }
-+ }
-+ }
-+ }
-+ }
-+ }
-+
-+ /* state machine irq */
-+ if (irq_sci != 0) {
-+ if (debug > 1) {
-+ printk(KERN_INFO "R_BERT_STA = %#x\n", qoz_inb(qoztmp, qoz_R_BERT_STA) & 7);
-+ }
-+ for (st=0;st<qoztmp->stports;st++) {
-+ if (irq_sci & (1 << st)) {
-+ qoz_outb(qoztmp,qoz_R_ST_SEL,st);
-+ l1state = qoz_inb(qoztmp,qoz_A_ST_RD_STA) & 0xf;
-+ if (debug > 1) {
-+ printk(KERN_INFO "A_ST_RD_STA = %#x\n", qoz_inb(qoztmp, qoz_A_ST_RD_STA));
-+ }
-+ if (qoztmp->st[st].nt_mode == 1) {
-+ if (debug)
-+ printk(KERN_INFO "card %d span %d state G%d (A_ST_RD_STA = %#x)\n",qoztmp->cardno,st+1,l1state,qoz_inb(qoztmp,qoz_A_ST_RD_STA));
-+ // NT state machine
-+ if (l1state == 3) {
-+ // keep layer1 up!
-+ if (qoztmp->stports == 8) {
-+ sprintf(ztqoz->spans[st].desc,"octoBRI PCI ISDN Card %d Span %d [NT] Layer 1 ACTIVATED (G%d)",qoztmp->cardno ,st + 1, l1state);
-+ } else {
-+ sprintf(ztqoz->spans[st].desc,"quadBRI PCI ISDN Card %d Span %d [NT] (cardID %d) Layer 1 ACTIVATED (G%d)",qoztmp->cardno ,st + 1,ztqoz->card->cardID, l1state);
-+ }
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,3 | 0x10 );
-+ qoztmp->leds[st] = 1;
-+ } else {
-+ if (qoztmp->stports == 8) {
-+ sprintf(ztqoz->spans[st].desc,"octoBRI PCI ISDN Card %d Span %d [NT] Layer 1 DEACTIVATED (G%d)",qoztmp->cardno ,st + 1, l1state);
-+ } else {
-+ sprintf(ztqoz->spans[st].desc,"quadBRI PCI ISDN Card %d Span %d [NT] (cardID %d) Layer 1 DEACTIVATED (G%d)",qoztmp->cardno ,st + 1,ztqoz->card->cardID, l1state);
-+ }
-+ qoztmp->leds[st] = 0;
-+ }
-+ } else {
-+ if (debug)
-+ printk(KERN_INFO "card %d span %d state F%d (A_ST_RD_STA = %#x)\n",qoztmp->cardno,st+1,l1state,qoz_inb(qoztmp,qoz_A_ST_RD_STA));
-+ // TE state machine
-+ if (l1state == 3) {
-+ /* keep layer1 up, if the span is started. */
-+ if (qoztmp->ztdev->spans[st].flags & ZT_FLAG_RUNNING) {
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x60);
-+ }
-+ qoztmp->leds[st] = 0;
-+ if (qoztmp->stports == 8) {
-+ sprintf(ztqoz->spans[st].desc,"octoBRI PCI ISDN Card %d Span %d [TE] Layer 1 DEACTIVATED (F%d)",qoztmp->cardno ,st + 1, l1state);
-+ } else {
-+ sprintf(ztqoz->spans[st].desc,"quadBRI PCI ISDN Card %d Span %d [TE] (cardID %d) Layer 1 DEACTIVATED (F%d)",qoztmp->cardno ,st + 1,ztqoz->card->cardID, l1state);
-+ }
-+ } else if (l1state == 7) {
-+ qoztmp->leds[st] = 1;
-+ if (qoztmp->stports == 8) {
-+ sprintf(ztqoz->spans[st].desc,"octoBRI PCI ISDN Card %d Span %d [TE] Layer 1 ACTIVATED (F%d)",qoztmp->cardno ,st + 1, l1state);
-+ } else {
-+ sprintf(ztqoz->spans[st].desc,"quadBRI PCI ISDN Card %d Span %d [TE] (cardID %d) Layer 1 ACTIVATED (F%d)",qoztmp->cardno ,st + 1,ztqoz->card->cardID, l1state);
-+ }
-+ } else {
-+ if (qoztmp->stports == 8) {
-+ sprintf(ztqoz->spans[st].desc,"octoBRI PCI ISDN Card %d Span %d [TE] Layer 1 DEACTIVATED (F%d)",qoztmp->cardno ,st + 1, l1state);
-+ } else {
-+ sprintf(ztqoz->spans[st].desc,"quadBRI PCI ISDN Card %d Span %d [TE] (cardID %d) Layer 1 DEACTIVATED (F%d)",qoztmp->cardno ,st + 1,ztqoz->card->cardID, l1state);
-+ }
-+ }
-+ }
-+
-+ }
-+ }
-+ }
-+ spin_unlock_irqrestore(&(qoztmp->lock),flags);
-+#ifdef LINUX26
-+ return IRQ_RETVAL(1);
-+#endif
-+}
-+
-+static int ztqoz_open(struct zt_chan *chan) {
-+// printk(KERN_INFO "qozap: channel %d opened.\n",chan->channo);
-+#ifndef LINUX26
-+ MOD_INC_USE_COUNT;
-+#else
-+ try_module_get(THIS_MODULE);
-+#endif
-+ return 0;
-+}
-+
-+static int ztqoz_close(struct zt_chan *chan) {
-+// printk(KERN_INFO "qozap: channel %d closed.\n",chan->channo);
-+#ifndef LINUX26
-+ MOD_DEC_USE_COUNT;
-+#else
-+ module_put(THIS_MODULE);
-+#endif
-+ return 0;
-+}
-+
-+static int ztqoz_rbsbits(struct zt_chan *chan, int bits) {
-+ return 0;
-+}
-+
-+static int ztqoz_ioctl(struct zt_chan *chan, unsigned int cmd, unsigned long data) {
-+ switch(cmd) {
-+ default:
-+ return -ENOTTY;
-+ }
-+ return 0;
-+}
-+
-+static int ztqoz_startup(struct zt_span *span) {
-+ struct zt_qoz *qozt = span->pvt;
-+ struct qoz_card *qoztmp = qozt->card;
-+ unsigned long flags;
-+ int alreadyrunning;
-+ int i=0;
-+ int offset = 0;
-+
-+ if (qoztmp == NULL) {
-+ printk(KERN_INFO "qozap: no card for span at startup!\n");
-+ }
-+
-+ alreadyrunning = span->flags & ZT_FLAG_RUNNING;
-+// printk(KERN_CRIT "already running %d flags %d\n", alreadyrunning, span->flags);
-+
-+ if (!alreadyrunning) {
-+ span->chans[2].flags &= ~ZT_FLAG_HDLC;
-+ span->chans[2].flags |= ZT_FLAG_BRIDCHAN;
-+
-+ /* setup B channel buffers (8 bytes each) */
-+ for (i=0; i<2 ; i++) {
-+ memset(qoztmp->rxbuf[span->offset][i],0x0,sizeof(qoztmp->rxbuf[span->offset][i]));
-+ span->chans[i].readchunk = qoztmp->rxbuf[span->offset][i];
-+ memset(qoztmp->txbuf[span->offset][i],0x0,sizeof(qoztmp->txbuf[span->offset][i]));
-+ span->chans[i].writechunk = qoztmp->txbuf[span->offset][i];
-+ }
-+ /* setup D channel buffer */
-+ memset(qoztmp->dtxbuf[span->offset],0x0,sizeof(qoztmp->dtxbuf[span->offset]));
-+ span->chans[2].writechunk = qoztmp->dtxbuf[span->offset];
-+ qoztmp->ztdev->chans[span->offset][2].maxbytes2transmit = sizeof(qoztmp->dtxbuf[span->offset]);
-+
-+ memset(qoztmp->drxbuf[span->offset],0x0,sizeof(qoztmp->drxbuf[span->offset]));
-+ span->chans[2].readchunk = qoztmp->drxbuf[span->offset];
-+
-+ span->flags |= ZT_FLAG_RUNNING;
-+ } else {
-+// printk(KERN_CRIT "already running\n");
-+ return 0;
-+ }
-+
-+ spin_lock_irqsave(&qoztmp->lock,flags);
-+ // irqs off
-+ qoz_outb(qoztmp,qoz_R_IRQ_CTRL, 0);
-+
-+ if (qoztmp->type == 0xb552) {
-+ offset = 24;
-+ } else {
-+ offset = 28;
-+ }
-+
-+ /* setup D-FIFO TX */
-+ qoz_outb(qoztmp,qoz_R_FIFO,(span->offset + offset) << 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x2);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0xD);
-+ qoz_outb(qoztmp,qoz_A_SUBCH_CFG,0x2);
-+ qoz_outb(qoztmp,qoz_A_CHANNEL,((span->offset * 4) + 2) << 1);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x1);
-+
-+ /* setup D-FIFO RX */
-+ qoz_outb(qoztmp,qoz_R_FIFO,((span->offset + offset) << 1) | 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x2);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0xD);
-+ qoz_outb(qoztmp,qoz_A_SUBCH_CFG,0x2);
-+ qoz_outb(qoztmp,qoz_A_CHANNEL,(((span->offset * 4) + 2) << 1) | 1);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x1);
-+
-+ /* setup B1-FIFO TX */
-+ qoz_outb(qoztmp,qoz_R_FIFO,(span->offset * 2) << 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x2);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x2);
-+ qoz_outb(qoztmp,qoz_A_CHANNEL,(span->offset * 4) << 1);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x1);
-+
-+ /* setup B1-FIFO RX */
-+ qoz_outb(qoztmp,qoz_R_FIFO,((span->offset * 2) << 1) | 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x2);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x2);
-+ qoz_outb(qoztmp,qoz_A_CHANNEL,((span->offset * 4) << 1) | 1);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x1);
-+
-+ /* setup B2-FIFO TX */
-+ qoz_outb(qoztmp,qoz_R_FIFO,((span->offset * 2) + 1) << 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x2);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x2);
-+ qoz_outb(qoztmp,qoz_A_CHANNEL,((span->offset * 4) + 1) << 1);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x1);
-+
-+ /* setup B2-FIFO RX */
-+ qoz_outb(qoztmp,qoz_R_FIFO,(((span->offset * 2) + 1) << 1) | 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x2);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x2);
-+ qoz_outb(qoztmp,qoz_A_CHANNEL,((((span->offset) * 4) + 1) << 1) | 1);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x1);
-+
-+ if (debug)
-+ printk(KERN_INFO "qozap: starting card %d span %d/%d.\n",qoztmp->cardno,span->spanno,span->offset);
-+
-+ /* activate layer 1 */
-+ qoz_outb(qoztmp,qoz_R_ST_SEL,span->offset);
-+ if (qoztmp->st[span->offset].nt_mode == 1) {
-+ // NT mode
-+ qoz_outb(qoztmp,qoz_A_ST_CTRL0,0x7);
-+ qoz_outb(qoztmp,qoz_A_ST_CTRL1,0x0);
-+ qoz_outb(qoztmp,qoz_A_ST_CTRL2,0x3);
-+ qoz_outb(qoztmp,qoz_A_ST_CLK_DLY,0x60 | CLKDEL_NT);
-+ } else {
-+ // TE mode
-+ qoz_outb(qoztmp,qoz_A_ST_CTRL0,0x3);
-+ qoz_outb(qoztmp,qoz_A_ST_CTRL1,0x0);
-+ qoz_outb(qoztmp,qoz_A_ST_CTRL2,0x3);
-+ qoz_outb(qoztmp,qoz_A_ST_CLK_DLY,CLKDEL_TE);
-+ }
-+
-+ qoz_outb(qoztmp,qoz_R_ST_SEL,span->offset);
-+ if (qoztmp->st[span->offset].nt_mode == 1) {
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x80);
-+ } else {
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x0);
-+ }
-+ /* enable irqs */
-+ qoz_outb(qoztmp,qoz_R_IRQ_CTRL, 8 | 1);
-+ spin_unlock_irqrestore(&qoztmp->lock,flags);
-+
-+ qoz_outb(qoztmp,qoz_R_ST_SEL,span->offset);
-+ if (qoztmp->st[span->offset].nt_mode == 1) {
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x60 | 0x80); // ACT, G2->G3 EN
-+ } else {
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x60); // start Activation
-+ }
-+
-+ return 0;
-+}
-+
-+static int ztqoz_shutdown(struct zt_span *span) {
-+ struct zt_qoz *ztqoz = span->pvt;
-+ struct qoz_card *qoztmp = ztqoz->card;
-+ int alreadyrunning;
-+ int offset = 0;
-+
-+ if (qoztmp == NULL) {
-+ printk(KERN_CRIT "qozap: qoztmp == NULL!\n");
-+ return 0;
-+
-+ }
-+
-+ alreadyrunning = span->flags & ZT_FLAG_RUNNING;
-+
-+ if (!alreadyrunning) {
-+ return 0;
-+ }
-+
-+// printk(KERN_CRIT "qozap: stopping card %d port %d.\n",qoztmp->cardno, span->offset + 1);
-+
-+ // turn off irqs for all fifos
-+ if (qoztmp->type == 0xb552) {
-+ offset = 24;
-+ } else {
-+ offset = 28;
-+ }
-+
-+ /* disable D TX fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,(span->offset + offset) << 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x1);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x0);
-+
-+ /* disable D RX fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,((span->offset + offset) << 1) | 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x1);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x0);
-+
-+ /* disable B1 TX fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,(span->offset * 2) << 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x2);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x0);
-+
-+ /* disable B1 RX fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,((span->offset * 2) << 1) | 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x2);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x0);
-+
-+ /* disable B2 TX fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,(((span->offset) * 2) + 1) << 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x2);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x0);
-+
-+ /* disable B2 RX fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,((((span->offset) * 2) + 1) << 1) | 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x2);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x0);
-+
-+ span->flags &= ~ZT_FLAG_RUNNING;
-+
-+ /* Deactivate Layer 1 */
-+ qoz_outb(qoztmp,qoz_R_ST_SEL,span->offset);
-+ if (qoztmp->st[span->offset].nt_mode == 1) {
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x40);
-+ } else {
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x40);
-+ }
-+
-+
-+// printk(KERN_CRIT "qozap: card %d span %d/%d down.\n",qoztmp->cardno,span->spanno,span->offset);
-+ return 0;
-+}
-+
-+static int ztqoz_maint(struct zt_span *span, int cmd) {
-+ return 0;
-+}
-+
-+static int ztqoz_chanconfig(struct zt_chan *chan,int sigtype) {
-+// printk(KERN_INFO "chan_config sigtype=%d\n",sigtype);
-+ return 0;
-+}
-+
-+static int ztqoz_spanconfig(struct zt_span *span,struct zt_lineconfig *lc) {
-+// span->lineconfig = lc->lineconfig;
-+ return 0;
-+}
-+
-+static int ztqoz_initialize(struct zt_qoz *ztqoz) {
-+ struct qoz_card *qoztmp = ztqoz->card;
-+ int i=0,s=0;
-+
-+ for (s=0; s < ztqoz->card->stports; s++) {
-+ memset(&ztqoz->spans[s],0,sizeof(struct zt_span)); // you never can tell...
-+ sprintf(ztqoz->spans[s].name,"ztqoz/%d/%d",qoz_dev_count + 1,s + 1);
-+ if (ztqoz->card->stports == 8) {
-+ if (qoztmp->st[s].nt_mode == 1){
-+ sprintf(ztqoz->spans[s].desc,"octoBRI PCI ISDN Card %d Span %d [NT]",qoztmp->cardno,s + 1);
-+ } else {
-+ sprintf(ztqoz->spans[s].desc,"octoBRI PCI ISDN Card %d Span %d [TE]",qoztmp->cardno,s + 1);
-+ }
-+ } else {
-+ if (ztqoz->card->cardID < 0xff) {
-+ if (qoztmp->st[s].nt_mode == 1){
-+ sprintf(ztqoz->spans[s].desc,"quadBRI PCI ISDN Card %d Span %d [NT] (cardID %d)",qoztmp->cardno,s + 1,ztqoz->card->cardID);
-+ } else {
-+ sprintf(ztqoz->spans[s].desc,"quadBRI PCI ISDN Card %d Span %d [TE] (cardID %d)",qoztmp->cardno,s + 1,ztqoz->card->cardID);
-+ }
-+ } else {
-+ if (qoztmp->st[s].nt_mode == 1){
-+ sprintf(ztqoz->spans[s].desc,"quadBRI PCI ISDN Card %d Span %d [NT]",qoztmp->cardno,s + 1);
-+ } else {
-+ sprintf(ztqoz->spans[s].desc,"quadBRI PCI ISDN Card %d Span %d [TE]",qoztmp->cardno,s + 1);
-+ }
-+ }
-+ }
-+
-+ ztqoz->spans[s].spanconfig = ztqoz_spanconfig;
-+ ztqoz->spans[s].chanconfig = ztqoz_chanconfig;
-+ ztqoz->spans[s].startup = ztqoz_startup;
-+ ztqoz->spans[s].shutdown = ztqoz_shutdown;
-+ ztqoz->spans[s].maint = ztqoz_maint;
-+ ztqoz->spans[s].rbsbits = ztqoz_rbsbits;
-+ ztqoz->spans[s].open = ztqoz_open;
-+ ztqoz->spans[s].close = ztqoz_close;
-+ ztqoz->spans[s].ioctl = ztqoz_ioctl;
-+
-+ ztqoz->spans[s].chans = ztqoz->chans[s];
-+ ztqoz->spans[s].channels = 3;
-+ ztqoz->spans[s].deflaw = ZT_LAW_ALAW;
-+ ztqoz->spans[s].linecompat = ZT_CONFIG_AMI | ZT_CONFIG_CCS; // <--- this is really BS
-+ init_waitqueue_head(&ztqoz->spans[s].maintq);
-+ ztqoz->spans[s].pvt = ztqoz;
-+ ztqoz->spans[s].offset = s;
-+
-+ for (i=0; i < ztqoz->spans[s].channels; i++) {
-+ memset(&(ztqoz->chans[s][i]),0x0,sizeof(struct zt_chan));
-+ sprintf(ztqoz->chans[s][i].name,"ztqoz%d/%d/%d",qoz_dev_count + 1,s + 1,i + 1);
-+ ztqoz->chans[s][i].pvt = ztqoz;
-+ ztqoz->chans[s][i].sigcap = ZT_SIG_EM | ZT_SIG_CLEAR | ZT_SIG_FXSLS | ZT_SIG_FXSGS | ZT_SIG_FXSKS | ZT_SIG_FXOLS | ZT_SIG_FXOGS | ZT_SIG_FXOKS | ZT_SIG_CAS | ZT_SIG_SF;
-+ ztqoz->chans[s][i].chanpos = i + 1;
-+ }
-+
-+ if (zt_register(&ztqoz->spans[s],0)) {
-+ printk(KERN_INFO "qozap: unable to register zaptel span %d!\n",s+1);
-+ return -1;
-+ }
-+// printk(KERN_INFO "qozap: registered zaptel span %d.\n",s+1);
-+ }
-+
-+ return 0;
-+}
-+
-+int qoz_findCards(unsigned int pcidid) {
-+ struct pci_dev *tmp;
-+ struct qoz_card *qoztmp = NULL;
-+ struct zt_qoz *ztqoz = NULL;
-+ int i=0;
-+ unsigned char dips=0;
-+ int cid=0;
-+ int modes=0;
-+ tmp = pci_find_device(PCI_VENDOR_ID_CCD,pcidid,multi_qoz);
-+ while (tmp != NULL) {
-+ multi_qoz = tmp; // skip this next time.
-+
-+ if (pci_enable_device(tmp)) {
-+ multi_qoz = NULL;
-+ return -1;
-+ }
-+
-+ qoztmp = kmalloc(sizeof(struct qoz_card),GFP_KERNEL);
-+ if (!qoztmp) {
-+ printk(KERN_WARNING "qozap: unable to kmalloc!\n");
-+ pci_disable_device(tmp);
-+ multi_qoz = NULL;
-+ return -ENOMEM;
-+ }
-+ memset(qoztmp, 0x0, sizeof(struct qoz_card));
-+
-+ spin_lock_init(&qoztmp->lock);
-+ qoztmp->pcidev = tmp;
-+ qoztmp->pcibus = tmp->bus->number;
-+ qoztmp->pcidevfn = tmp->devfn;
-+
-+ if (!tmp->irq) {
-+ printk(KERN_WARNING "qozap: no irq!\n");
-+ } else {
-+ qoztmp->irq = tmp->irq;
-+ }
-+
-+ qoztmp->pci_io = (char *) tmp->resource[1].start;
-+ if (!qoztmp->pci_io) {
-+ printk(KERN_WARNING "qozap: no iomem!\n");
-+ pci_disable_device(tmp);
-+ multi_qoz = NULL;
-+ return -EIO;
-+ }
-+
-+ if (request_irq(qoztmp->irq, qoz_interrupt, SA_INTERRUPT | SA_SHIRQ, "qozap", qoztmp)) {
-+ printk(KERN_WARNING "qozap: unable to register irq\n");
-+ kfree(qoztmp);
-+ pci_disable_device(tmp);
-+ multi_qoz = NULL;
-+ return -EIO;
-+ }
-+
-+
-+ qoztmp->pci_io = ioremap((ulong) qoztmp->pci_io, 256);
-+
-+
-+ pci_write_config_word(qoztmp->pcidev, PCI_COMMAND, PCI_COMMAND_MEMORY); // enable memio
-+
-+ // disable ints
-+ qoz_outb(qoztmp,qoz_R_IRQ_CTRL, 0);
-+
-+ ztqoz = kmalloc(sizeof(struct zt_qoz),GFP_KERNEL);
-+ if (!ztqoz) {
-+ printk(KERN_INFO "qozap: unable to kmalloc!\n");
-+ qoz_shutdownCard(qoztmp);
-+ kfree(qoztmp);
-+ multi_qoz = NULL;
-+ return -ENOMEM;
-+ }
-+ memset(ztqoz, 0x0, sizeof(struct zt_qoz));
-+
-+ if (pcidid == PCI_DEVICE_ID_CCD_M) {
-+ qoztmp->stports = 8;
-+ } else {
-+ qoztmp->stports = 4;
-+ }
-+
-+
-+ if ((tmp->subsystem_device==0xb520) && (pcidid == PCI_DEVICE_ID_CCD_M4)) {
-+ // printk(KERN_INFO "MODES = %#x.\n",modes);
-+ qoz_outb(qoztmp,qoz_R_GPIO_SEL,0x80 | 0x40);
-+ dips = (qoz_inb(qoztmp,qoz_R_GPIO_IN1) >> 5);
-+ cid = 7;
-+ for (i=0;i<3;i++) {
-+ if ((dips & (1 << i)) != 0) {
-+ cid -= (1 << (2-i));
-+ }
-+ }
-+ // printk(KERN_INFO "DIPS = %#x CID= %#x\n",dips,cid);
-+ } else {
-+ cid = 0xff;
-+ }
-+
-+ if (ports == -1) {
-+ if ((tmp->subsystem_device==0xb520) && (pcidid == PCI_DEVICE_ID_CCD_M4)) {
-+ modes = qoz_inb(qoztmp,qoz_R_GPI_IN3) >> 4;
-+ } else {
-+ modes = 0; // assume TE mode
-+ }
-+ } else {
-+ modes = ports >> totalBRIs;
-+ }
-+
-+ if (pcidid == PCI_DEVICE_ID_CCD_M4) {
-+ switch (tmp->subsystem_device) {
-+ case 0x08b4:
-+ if (ports == -1) ports = 0; /* assume TE mode if no ports param */
-+ printk(KERN_INFO
-+ "qozap: CologneChip HFC-4S evaluation board configured at mem %#x IRQ %d HZ %d\n",
-+ (u_int) qoztmp->pci_io,
-+ qoztmp->irq, HZ);
-+ break;
-+ case 0xb520:
-+ printk(KERN_INFO
-+ "qozap: Junghanns.NET quadBRI card configured at mem %#x IRQ %d HZ %d CardID %d\n",
-+ (u_int) qoztmp->pci_io,
-+ qoztmp->irq, HZ, cid);
-+ break;
-+ }
-+ totalBRIs += 4;
-+ } else {
-+ switch (tmp->subsystem_device) {
-+ case 0xb552:
-+ printk(KERN_INFO
-+ "qozap: Junghanns.NET octoBRI card configured at mem %#x IRQ %d HZ %d\n",
-+ (u_int) qoztmp->pci_io,
-+ qoztmp->irq, HZ);
-+ break;
-+ default:
-+ iounmap((void *) qoztmp->pci_io);
-+ if (qoztmp->pcidev != NULL) {
-+ pci_disable_device(qoztmp->pcidev);
-+ }
-+ pci_write_config_word(qoztmp->pcidev, PCI_COMMAND, 0); // disable memio
-+ free_irq(qoztmp->irq,qoztmp);
-+ kfree(qoztmp);
-+ qoztmp = NULL;
-+ tmp = pci_find_device(PCI_VENDOR_ID_CCD,pcidid,multi_qoz);
-+ continue;
-+ break;
-+ }
-+ totalBRIs += 8;
-+ }
-+
-+ qoztmp->cardID = cid;
-+ qoztmp->type = tmp->subsystem_device;
-+
-+ printk(KERN_INFO "qozap: S/T ports: %d [",qoztmp->stports);
-+ for (i=0;i<qoztmp->stports;i++) {
-+ if ((modes & (1 << i)) != 0) {
-+ qoztmp->st[i].nt_mode = 1;
-+ printk(" NT");
-+ } else {
-+ qoztmp->st[i].nt_mode = 0;
-+ printk(" TE");
-+ }
-+ }
-+ printk(" ]\n");
-+
-+ ztqoz->card = qoztmp;
-+ qoztmp->ztdev = ztqoz;
-+
-+ qoz_registerCard(qoztmp);
-+
-+ tmp = pci_find_device(PCI_VENDOR_ID_CCD,pcidid,multi_qoz);
-+ }
-+ return 0;
-+}
-+
-+
-+int qoz_sortCards(void) {
-+ int changed=0,tmpcardno;
-+ struct qoz_card *tmpcard,*tmpcard2;
-+ spin_lock(®isterlock);
-+ do {
-+ changed = 0;
-+ tmpcard = qoz_dev_list;
-+ while (tmpcard != NULL) {
-+ if (tmpcard->prev) {
-+ if (tmpcard->prev->cardID > tmpcard->cardID) {
-+ tmpcardno = tmpcard->prev->cardno;
-+ tmpcard->prev->cardno = tmpcard->cardno;
-+ tmpcard->cardno = tmpcardno;
-+
-+ tmpcard2 = tmpcard->prev;
-+ if (tmpcard2->prev) {
-+ tmpcard2->prev->next = tmpcard;
-+ } else {
-+ qoz_dev_list = tmpcard;
-+ }
-+ if (tmpcard->next) {
-+ tmpcard->next->prev = tmpcard2;
-+ }
-+ tmpcard2->next = tmpcard->next;
-+ tmpcard->prev = tmpcard2->prev;
-+ tmpcard->next = tmpcard2;
-+ tmpcard2->prev = tmpcard;
-+ changed = 1;
-+ tmpcard = tmpcard2;
-+ }
-+ }
-+ tmpcard = tmpcard->next;
-+ }
-+ } while (changed == 1);
-+ spin_unlock(®isterlock);
-+ return 0;
-+}
-+
-+int qoz_zapCards(void) {
-+ struct qoz_card *tmpcard;
-+ tmpcard = qoz_dev_list;
-+ while (tmpcard != NULL) {
-+ ztqoz_initialize(tmpcard->ztdev);
-+ qoz_resetCard(tmpcard);
-+ tmpcard = tmpcard->next;
-+ }
-+ return 0;
-+}
-+
-+
-+int init_module(void) {
-+ multi_qoz = NULL;
-+ qoz_findCards(PCI_DEVICE_ID_CCD_M4);
-+ qoz_findCards(PCI_DEVICE_ID_CCD_M);
-+ qoz_sortCards();
-+ qoz_zapCards();
-+ if (qoz_dev_count == 0) {
-+ printk(KERN_INFO "qozap: no multiBRI cards found.\n");
-+ } else {
-+ printk(KERN_INFO "qozap: %d multiBRI card(s) in this box, %d BRI ports total.\n",qoz_dev_count, totalBRIs);
-+ }
-+ return 0;
-+}
-+
-+void cleanup_module(void) {
-+ struct qoz_card *tmpcard,*tmplist;
-+ int i=0;
-+ tmplist = qoz_dev_list;
-+ while (tmplist != NULL) {
-+ qoz_shutdownCard(tmplist);
-+ tmplist = tmplist->next;
-+ }
-+ tmplist = qoz_dev_list;
-+ spin_lock(®isterlock);
-+ while (tmplist != NULL) {
-+ tmpcard = tmplist->next;
-+ kfree(tmplist);
-+ i++;
-+ tmplist = tmpcard;
-+ }
-+ spin_unlock(®isterlock);
-+ printk(KERN_INFO "qozap: shutdown %d multiBRI cards.\n", i);
-+}
-+#endif
-+
-+MODULE_PARM(doubleclock,"i");
-+MODULE_PARM(ports,"i");
-+MODULE_PARM(debug,"i");
-+MODULE_DESCRIPTION("quad/octo BRI zaptel driver");
-+MODULE_AUTHOR("Klaus-Peter Junghanns <kpj at junghanns.net>");
-+#ifdef MODULE_LICENSE
-+MODULE_LICENSE("GPL");
-+#endif
-diff -urNad zaptel-1.0.9/qozap/qozap.h /tmp/dpep.gzWFVh/zaptel-1.0.9/qozap/qozap.h
---- zaptel-1.0.9/qozap/qozap.h 1969-12-31 19:00:00.000000000 -0500
-+++ /tmp/dpep.gzWFVh/zaptel-1.0.9/qozap/qozap.h 2005-02-26 13:12:09.000000000 -0500
-@@ -0,0 +1,204 @@
-+#define qoz_SPANS 8
-+#define qoz_FIFO_SIZE 128
-+#define qoz_DFIFO_SIZE4 2048
-+#define qoz_DFIFO_SIZE8 1024
-+
-+typedef struct qoz_span {
-+ unsigned char nt_mode;
-+ unsigned char btx;
-+ unsigned char bswapped;
-+ unsigned char drx;
-+} qoz_span;
-+
-+typedef struct qoz_regs {
-+ unsigned char fifo_en;
-+ unsigned char ctmt;
-+ unsigned char int_m1;
-+ unsigned char int_m2;
-+ unsigned char sctrl;
-+ unsigned char sctrl_e;
-+ unsigned char sctrl_r;
-+ unsigned char connect;
-+ unsigned char trm;
-+ unsigned char mst_mode;
-+} qoz_regs;
-+
-+typedef struct qoz_card {
-+ spinlock_t lock;
-+ int cardID;
-+ unsigned char leds[8];
-+ unsigned char cardno;
-+ unsigned int irq;
-+ unsigned int iomem;
-+ unsigned char *pci_io;
-+ struct qoz_span st[qoz_SPANS];
-+ unsigned int pcibus;
-+ unsigned int pcidevfn;
-+ struct pci_dev *pcidev;
-+ struct zt_qoz *ztdev;
-+ unsigned char rxbuf[qoz_SPANS][2][ZT_CHUNKSIZE];
-+ unsigned char txbuf[qoz_SPANS][2][ZT_CHUNKSIZE];
-+ unsigned char drxbuf[qoz_SPANS][qoz_DFIFO_SIZE4];
-+ unsigned char dtxbuf[qoz_SPANS][qoz_DFIFO_SIZE4];
-+ unsigned char stports;
-+ unsigned int ticks;
-+ unsigned int clicks;
-+ unsigned int type;
-+ struct qoz_card *next;
-+ struct qoz_card *prev;
-+} qoz_card;
-+
-+
-+typedef struct zt_qoz {
-+ unsigned int usecount;
-+ struct zt_span spans[qoz_SPANS];
-+ struct zt_chan chans[qoz_SPANS][3];
-+ struct qoz_card *card;
-+} zt_qoz;
-+
-+#define qoz_outb(a,b,c) (writeb((c),(a)->pci_io+(b)))
-+#define qoz_inb(a,b) (readb((a)->pci_io+(b)))
-+
-+#define qoz_outw(a,b,c) (writew((c),(a)->pci_io+(b)))
-+#define qoz_inw(a,b) (readw((a)->pci_io+(b)))
-+
-+#define qoz_outdw(a,b,c) (writel((c),(a)->pci_io+(b)))
-+#define qoz_indw(a,b) (readl((a)->pci_io+(b)))
-+
-+/* Write only registers */
-+#define qoz_A_CH_MSK 0xF4
-+#define qoz_A_CHANNEL 0xFC
-+#define qoz_A_CON_HDLC 0xFA
-+#define qoz_A_CONF 0xD1
-+#define qoz_A_FIFO_SEQ 0xFD
-+#define qoz_R_INC_RES_FIFO 0x0E
-+#define qoz_A_IRQ_MSK 0xFF
-+#define qoz_A_SL_CFG 0xD0
-+#define qoz_A_ST_B1_TX 0x3C
-+#define qoz_A_ST_B2_TX 0x3D
-+#define qoz_A_ST_CLK_DLY 0x37
-+#define qoz_A_ST_CTRL0 0x31
-+#define qoz_A_ST_CTRL1 0x32
-+#define qoz_A_ST_CTRL2 0x33
-+#define qoz_A_ST_D_TX 0x3E
-+#define qoz_A_ST_SQ_WR 0x34
-+#define qoz_A_ST_WR_STA 0x30
-+#define qoz_A_SUBCH_CFG 0xFB
-+#define qoz_R_BERT_WD_MD 0x1B
-+#define qoz_R_BRG_CTRL 0x45
-+#define qoz_R_BRG_MD 0x47
-+#define qoz_R_BRG_PCM_CFG 0x02
-+#define qoz_R_BRG_TIM_SEL01 0x4C
-+#define qoz_R_BRG_TIM_SEL23 0x4D
-+#define qoz_R_BRG_TIM_SEL45 0x4E
-+#define qoz_R_BRG_TIM_SEL67 0x4F
-+#define qoz_R_BRG_TIM0 0x48
-+#define qoz_R_BRG_TIM1 0x49
-+#define qoz_R_BRG_TIM2 0x4A
-+#define qoz_R_BRG_TIM3 0x4B
-+#define qoz_R_CIRM 0x00
-+#define qoz_R_CONF_EN 0x18
-+#define qoz_R_CTRL 0x01
-+#define qoz_R_DTMF0 0x1C
-+#define qoz_R_DTMF1 0x1D
-+#define qoz_R_FIFO_MD 0x0D
-+#define qoz_R_FIFO 0x0F
-+#define qoz_R_FIRST_FIFO 0x0B
-+#define qoz_R_FSM_IDX 0x0F
-+#define qoz_R_GPIO_EN0 0x42
-+#define qoz_R_GPIO_EN1 0x43
-+#define qoz_R_GPIO_OUT0 0x40
-+#define qoz_R_GPIO_OUT1 0x41
-+#define qoz_R_GPIO_SEL 0x44
-+#define qoz_R_IRQ_CTRL 0x13
-+#define qoz_R_IRQMSK_MISC 0x11
-+#define qoz_R_PCM_MD0 0x14
-+#define qoz_R_PCM_MD1 0x15
-+#define qoz_R_PCM_MD2 0x15
-+#define qoz_R_PWM_MD 0x46
-+#define qoz_R_PWM0 0x38
-+#define qoz_R_PWM1 0x39
-+#define qoz_R_RAM_ADDR0 0x08
-+#define qoz_R_RAM_ADDR1 0x09
-+#define qoz_R_RAM_ADDR2 0x0A
-+#define qoz_R_RAM_MISC 0x0C
-+#define qoz_R_SCI_MSK 0x12
-+#define qoz_R_SH0H 0x15
-+#define qoz_R_SH0L 0x15
-+#define qoz_R_SH1H 0x15
-+#define qoz_R_SH1L 0x15
-+#define qoz_R_SL_SEL0 0x15
-+#define qoz_R_SL_SEL1 0x15
-+#define qoz_R_SL_SEL2 0x15
-+#define qoz_R_SL_SEL3 0x15
-+#define qoz_R_SL_SEL4 0x15
-+#define qoz_R_SL_SEL5 0x15
-+#define qoz_R_SL_SEL6 0x15
-+#define qoz_R_SL_SEL7 0x15
-+#define qoz_R_SLOT 0x10
-+#define qoz_R_ST_SEL 0x16
-+#define qoz_R_ST_SYNC 0x17
-+#define qoz_R_TI_WD 0x1A
-+
-+/* Read only registers */
-+#define qoz_A_F1 0x0C
-+#define qoz_A_F12 0x0C
-+#define qoz_A_F2 0x0D
-+#define qoz_A_ST_B1_RX 0x3C
-+#define qoz_A_ST_B2_TX 0x3D
-+#define qoz_A_ST_D_RX 0x3E
-+#define qoz_A_ST_E_RX 0x3F
-+#define qoz_A_ST_RD_STA 0x30
-+#define qoz_A_ST_SQ_RD 0x34
-+#define qoz_A_Z1 0x04
-+#define qoz_A_Z12 0x04
-+#define qoz_A_Z1H 0x05
-+#define qoz_A_Z1L 0x04
-+#define qoz_A_Z2 0x06
-+#define qoz_A_Z2H 0x07
-+#define qoz_A_Z2L 0x06
-+#define qoz_R_BERT_ECH 0x1B
-+#define qoz_R_BERT_ECL 0x1A
-+#define qoz_R_BERT_STA 0x17
-+#define qoz_R_CHIP_ID 0x16
-+#define qoz_R_CHIP_RV 0x1F
-+#define qoz_R_CONF_OFLOW 0x14
-+#define qoz_R_F0_CNTH 0x19
-+#define qoz_R_F0_CNTL 0x18
-+#define qoz_R_GPI_IN0 0x44
-+#define qoz_R_GPI_IN1 0x45
-+#define qoz_R_GPI_IN2 0x46
-+#define qoz_R_GPI_IN3 0x47
-+#define qoz_R_GPIO_IN0 0x40
-+#define qoz_R_GPIO_IN1 0x41
-+#define qoz_R_INT_DATA 0x88
-+#define qoz_R_IRQ_FIFO_BL0 0xC8
-+#define qoz_R_IRQ_FIFO_BL1 0xC9
-+#define qoz_R_IRQ_FIFO_BL2 0xCA
-+#define qoz_R_IRQ_FIFO_BL3 0xCB
-+#define qoz_R_IRQ_FIFO_BL4 0xCC
-+#define qoz_R_IRQ_FIFO_BL5 0xCD
-+#define qoz_R_IRQ_FIFO_BL6 0xCE
-+#define qoz_R_IRQ_FIFO_BL7 0xCF
-+#define qoz_R_IRQ_MISC 0x11
-+#define qoz_R_IRQ_OVIEW 0x10
-+#define qoz_R_RAM_USE 0x15
-+#define qoz_R_SCI 0x12
-+#define qoz_R_STATUS 0x1C
-+
-+/* Read/Write registers */
-+#define qoz_A_FIFO_DATA0_NOINC 0x84
-+#define qoz_A_FIFO_DATA0 0x80
-+#define qoz_A_FIFO_DATA1_NOINC 0x84
-+#define qoz_A_FIFO_DATA1 0x80
-+#define qoz_A_FIFO_DATA2_NOINC 0x84
-+#define qoz_A_FIFO_DATA2 0x80
-+#define qoz_R_RAM_DATA 0xC0
-+
-+#define PCI_DEVICE_ID_CCD_M 0x16b8
-+#define PCI_DEVICE_ID_CCD_M4 0x08b4
-+#define CLKDEL_TE 0xe /* CLKDEL in TE mode */
-+#define CLKDEL_NT 0xc /* CLKDEL in NT mode */
-+
-+#define HFC8S_CHIP_ID 0x80
-+#define HFC4S_CHIP_ID 0xC0
-diff -urNad zaptel-1.0.9/qozap/TODO /tmp/dpep.gzWFVh/zaptel-1.0.9/qozap/TODO
---- zaptel-1.0.9/qozap/TODO 1969-12-31 19:00:00.000000000 -0500
-+++ /tmp/dpep.gzWFVh/zaptel-1.0.9/qozap/TODO 2004-10-24 11:57:44.000000000 -0500
-@@ -0,0 +1,4 @@
-+- native-native bridging
-+- onchip dtmf
-+- E channel support for full debug
-+
-diff -urNad zaptel-1.0.9/qozap/zapata.conf /tmp/dpep.gzWFVh/zaptel-1.0.9/qozap/zapata.conf
---- zaptel-1.0.9/qozap/zapata.conf 1969-12-31 19:00:00.000000000 -0500
-+++ /tmp/dpep.gzWFVh/zaptel-1.0.9/qozap/zapata.conf 2005-01-25 20:26:51.000000000 -0500
-@@ -0,0 +1,49 @@
-+;
-+; Zapata telephony interface
-+;
-+; Configuration file
-+
-+[channels]
-+;
-+; Default language
-+;
-+;language=en
-+;
-+; Default context
-+;
-+;
-+switchtype = euroisdn
-+
-+; p2mp TE mode (for connecting ISDN lines in point-to-multipoint mode)
-+signalling = bri_cpe_ptmp
-+; p2p TE mode (for connecting ISDN lines in point-to-point mode)
-+;signalling = bri_cpe
-+; p2mp NT mode (for connecting ISDN phones in point-to-multipoint mode)
-+;signalling = bri_net_ptmp
-+; p2p NT mode (for connecting an ISDN pbx in point-to-point mode)
-+;signalling = bri_net
-+
-+pridialplan = local
-+prilocaldialplan = local
-+nationalprefix = 0
-+internationalprefix = 00
-+
-+echocancel = yes
-+
-+context=demo
-+group = 1
-+; S/T port 1
-+channel => 1-2
-+
-+group = 2
-+; S/T port 2
-+channel => 4-5
-+
-+group = 3
-+; S/T port 3
-+channel => 7-8
-+
-+group = 4
-+; S/T port 4
-+channel => 10-11
-+
-diff -urNad zaptel-1.0.9/qozap/zapata.conf.octoBRI /tmp/dpep.gzWFVh/zaptel-1.0.9/qozap/zapata.conf.octoBRI
---- zaptel-1.0.9/qozap/zapata.conf.octoBRI 1969-12-31 19:00:00.000000000 -0500
-+++ /tmp/dpep.gzWFVh/zaptel-1.0.9/qozap/zapata.conf.octoBRI 2005-01-25 20:27:05.000000000 -0500
-@@ -0,0 +1,65 @@
-+;
-+; Zapata telephony interface
-+;
-+; Configuration file
-+
-+[channels]
-+;
-+; Default language
-+;
-+;language=en
-+;
-+; Default context
-+;
-+;
-+switchtype = euroisdn
-+
-+; p2mp TE mode (for connecting ISDN lines in point-to-multipoint mode)
-+signalling = bri_cpe_ptmp
-+; p2p TE mode (for connecting ISDN lines in point-to-point mode)
-+;signalling = bri_cpe
-+; p2mp NT mode (for connecting ISDN phones in point-to-multipoint mode)
-+;signalling = bri_net_ptmp
-+; p2p NT mode (for connecting an ISDN pbx in point-to-point mode)
-+;signalling = bri_net
-+
-+pridialplan = local
-+prilocaldialplan = local
-+nationalprefix = 0
-+internationalprefix = 00
-+
-+echocancel = yes
-+
-+context=demo
-+group = 1
-+; S/T port 1
-+channel => 1-2
-+
-+group = 2
-+; S/T port 2
-+channel => 4-5
-+
-+group = 3
-+; S/T port 3
-+channel => 7-8
-+
-+group = 4
-+; S/T port 4
-+channel => 10-11
-+
-+group = 5
-+; S/T port 5
-+channel => 13-14
-+
-+group = 6
-+; S/T port 6
-+channel => 16-17
-+
-+group = 7
-+; S/T port 7
-+channel => 19-20
-+
-+group = 8
-+; S/T port 8
-+channel => 22-23
-+
-diff -urNad zaptel-1.0.9/qozap/zaptel.conf /tmp/dpep.gzWFVh/zaptel-1.0.9/qozap/zaptel.conf
---- zaptel-1.0.9/qozap/zaptel.conf 1969-12-31 19:00:00.000000000 -0500
-+++ /tmp/dpep.gzWFVh/zaptel-1.0.9/qozap/zaptel.conf 2004-04-03 18:54:49.000000000 -0500
-@@ -0,0 +1,18 @@
-+loadzone=nl
-+defaultzone=nl
-+# qozap span definitions
-+# most of the values should be bogus because we are not really zaptel
-+span=1,1,3,ccs,ami
-+span=2,0,3,ccs,ami
-+span=3,0,3,ccs,ami
-+span=4,0,3,ccs,ami
-+
-+bchan=1,2
-+dchan=3
-+bchan=4,5
-+dchan=6
-+bchan=7,8
-+dchan=9
-+bchan=10,11
-+dchan=12
-+
-diff -urNad zaptel-1.0.9/qozap/zaptel.conf.octoBRI /tmp/dpep.gzWFVh/zaptel-1.0.9/qozap/zaptel.conf.octoBRI
---- zaptel-1.0.9/qozap/zaptel.conf.octoBRI 1969-12-31 19:00:00.000000000 -0500
-+++ /tmp/dpep.gzWFVh/zaptel-1.0.9/qozap/zaptel.conf.octoBRI 2005-01-25 20:27:11.000000000 -0500
-@@ -0,0 +1,30 @@
-+loadzone=nl
-+defaultzone=nl
-+# qozap span definitions
-+# most of the values should be bogus because we are not really zaptel
-+span=1,1,3,ccs,ami
-+span=2,0,3,ccs,ami
-+span=3,0,3,ccs,ami
-+span=4,0,3,ccs,ami
-+span=5,1,3,ccs,ami
-+span=6,0,3,ccs,ami
-+span=7,0,3,ccs,ami
-+span=8,0,3,ccs,ami
-+
-+bchan=1,2
-+dchan=3
-+bchan=4,5
-+dchan=6
-+bchan=7,8
-+dchan=9
-+bchan=10,11
-+dchan=12
-+bchan=13,14
-+dchan=15
-+bchan=16,17
-+dchan=18
-+bchan=19,20
-+dchan=21
-+bchan=22,23
-+dchan=24
-+
-diff -urNad zaptel-1.0.9/zaphfc/LICENSE /tmp/dpep.gzWFVh/zaptel-1.0.9/zaphfc/LICENSE
---- zaptel-1.0.9/zaphfc/LICENSE 1969-12-31 19:00:00.000000000 -0500
-+++ /tmp/dpep.gzWFVh/zaptel-1.0.9/zaphfc/LICENSE 2003-08-18 20:24:43.000000000 -0500
-@@ -0,0 +1,341 @@
-+
-+ GNU GENERAL PUBLIC LICENSE
-+ Version 2, June 1991
-+
-+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-+ Everyone is permitted to copy and distribute verbatim copies
-+ of this license document, but changing it is not allowed.
-+
-+ Preamble
-+
-+ The licenses for most software are designed to take away your
-+freedom to share and change it. By contrast, the GNU General Public
-+License is intended to guarantee your freedom to share and change free
-+software--to make sure the software is free for all its users. This
-+General Public License applies to most of the Free Software
-+Foundation's software and to any other program whose authors commit to
-+using it. (Some other Free Software Foundation software is covered by
-+the GNU Library General Public License instead.) You can apply it to
-+your programs, too.
-+
-+ When we speak of free software, we are referring to freedom, not
-+price. Our General Public Licenses are designed to make sure that you
-+have the freedom to distribute copies of free software (and charge for
-+this service if you wish), that you receive source code or can get it
-+if you want it, that you can change the software or use pieces of it
-+in new free programs; and that you know you can do these things.
-+
-+ To protect your rights, we need to make restrictions that forbid
-+anyone to deny you these rights or to ask you to surrender the rights.
-+These restrictions translate to certain responsibilities for you if you
-+distribute copies of the software, or if you modify it.
-+
-+ For example, if you distribute copies of such a program, whether
-+gratis or for a fee, you must give the recipients all the rights that
-+you have. You must make sure that they, too, receive or can get the
-+source code. And you must show them these terms so they know their
-+rights.
-+
-+ We protect your rights with two steps: (1) copyright the software, and
-+(2) offer you this license which gives you legal permission to copy,
-+distribute and/or modify the software.
-+
-+ Also, for each author's protection and ours, we want to make certain
-+that everyone understands that there is no warranty for this free
-+software. If the software is modified by someone else and passed on, we
-+want its recipients to know that what they have is not the original, so
-+that any problems introduced by others will not reflect on the original
-+authors' reputations.
-+
-+ Finally, any free program is threatened constantly by software
-+patents. We wish to avoid the danger that redistributors of a free
-+program will individually obtain patent licenses, in effect making the
-+program proprietary. To prevent this, we have made it clear that any
-+patent must be licensed for everyone's free use or not licensed at all.
-+
-+ The precise terms and conditions for copying, distribution and
-+modification follow.
-+
-+ GNU GENERAL PUBLIC LICENSE
-+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-+
-+ 0. This License applies to any program or other work which contains
-+a notice placed by the copyright holder saying it may be distributed
-+under the terms of this General Public License. The "Program", below,
-+refers to any such program or work, and a "work based on the Program"
-+means either the Program or any derivative work under copyright law:
-+that is to say, a work containing the Program or a portion of it,
-+either verbatim or with modifications and/or translated into another
-+language. (Hereinafter, translation is included without limitation in
-+the term "modification".) Each licensee is addressed as "you".
-+
-+Activities other than copying, distribution and modification are not
-+covered by this License; they are outside its scope. The act of
-+running the Program is not restricted, and the output from the Program
-+is covered only if its contents constitute a work based on the
-+Program (independent of having been made by running the Program).
-+Whether that is true depends on what the Program does.
-+
-+ 1. You may copy and distribute verbatim copies of the Program's
-+source code as you receive it, in any medium, provided that you
-+conspicuously and appropriately publish on each copy an appropriate
-+copyright notice and disclaimer of warranty; keep intact all the
-+notices that refer to this License and to the absence of any warranty;
-+and give any other recipients of the Program a copy of this License
-+along with the Program.
-+
-+You may charge a fee for the physical act of transferring a copy, and
-+you may at your option offer warranty protection in exchange for a fee.
-+
-+ 2. You may modify your copy or copies of the Program or any portion
-+of it, thus forming a work based on the Program, and copy and
-+distribute such modifications or work under the terms of Section 1
-+above, provided that you also meet all of these conditions:
-+
-+ a) You must cause the modified files to carry prominent notices
-+ stating that you changed the files and the date of any change.
-+
-+ b) You must cause any work that you distribute or publish, that in
-+ whole or in part contains or is derived from the Program or any
-+ part thereof, to be licensed as a whole at no charge to all third
-+ parties under the terms of this License.
-+
-+ c) If the modified program normally reads commands interactively
-+ when run, you must cause it, when started running for such
-+ interactive use in the most ordinary way, to print or display an
-+ announcement including an appropriate copyright notice and a
-+ notice that there is no warranty (or else, saying that you provide
-+ a warranty) and that users may redistribute the program under
-+ these conditions, and telling the user how to view a copy of this
-+ License. (Exception: if the Program itself is interactive but
-+ does not normally print such an announcement, your work based on
-+ the Program is not required to print an announcement.)
-+
-+These requirements apply to the modified work as a whole. If
-+identifiable sections of that work are not derived from the Program,
-+and can be reasonably considered independent and separate works in
-+themselves, then this License, and its terms, do not apply to those
-+sections when you distribute them as separate works. But when you
-+distribute the same sections as part of a whole which is a work based
-+on the Program, the distribution of the whole must be on the terms of
-+this License, whose permissions for other licensees extend to the
-+entire whole, and thus to each and every part regardless of who wrote it.
-+
-+Thus, it is not the intent of this section to claim rights or contest
-+your rights to work written entirely by you; rather, the intent is to
-+exercise the right to control the distribution of derivative or
-+collective works based on the Program.
-+
-+In addition, mere aggregation of another work not based on the Program
-+with the Program (or with a work based on the Program) on a volume of
-+a storage or distribution medium does not bring the other work under
-+the scope of this License.
-+
-+ 3. You may copy and distribute the Program (or a work based on it,
-+under Section 2) in object code or executable form under the terms of
-+Sections 1 and 2 above provided that you also do one of the following:
-+
-+ a) Accompany it with the complete corresponding machine-readable
-+ source code, which must be distributed under the terms of Sections
-+ 1 and 2 above on a medium customarily used for software interchange; or,
-+
-+ b) Accompany it with a written offer, valid for at least three
-+ years, to give any third party, for a charge no more than your
-+ cost of physically performing source distribution, a complete
-+ machine-readable copy of the corresponding source code, to be
-+ distributed under the terms of Sections 1 and 2 above on a medium
-+ customarily used for software interchange; or,
-+
-+ c) Accompany it with the information you received as to the offer
-+ to distribute corresponding source code. (This alternative is
-+ allowed only for noncommercial distribution and only if you
-+ received the program in object code or executable form with such
-+ an offer, in accord with Subsection b above.)
-+
-+The source code for a work means the preferred form of the work for
-+making modifications to it. For an executable work, complete source
-+code means all the source code for all modules it contains, plus any
-+associated interface definition files, plus the scripts used to
-+control compilation and installation of the executable. However, as a
-+special exception, the source code distributed need not include
-+anything that is normally distributed (in either source or binary
-+form) with the major components (compiler, kernel, and so on) of the
-+operating system on which the executable runs, unless that component
-+itself accompanies the executable.
-+
-+If distribution of executable or object code is made by offering
-+access to copy from a designated place, then offering equivalent
-+access to copy the source code from the same place counts as
-+distribution of the source code, even though third parties are not
-+compelled to copy the source along with the object code.
-+
-+ 4. You may not copy, modify, sublicense, or distribute the Program
-+except as expressly provided under this License. Any attempt
-+otherwise to copy, modify, sublicense or distribute the Program is
-+void, and will automatically terminate your rights under this License.
-+However, parties who have received copies, or rights, from you under
-+this License will not have their licenses terminated so long as such
-+parties remain in full compliance.
-+
-+ 5. You are not required to accept this License, since you have not
-+signed it. However, nothing else grants you permission to modify or
-+distribute the Program or its derivative works. These actions are
-+prohibited by law if you do not accept this License. Therefore, by
-+modifying or distributing the Program (or any work based on the
-+Program), you indicate your acceptance of this License to do so, and
-+all its terms and conditions for copying, distributing or modifying
-+the Program or works based on it.
-+
-+ 6. Each time you redistribute the Program (or any work based on the
-+Program), the recipient automatically receives a license from the
-+original licensor to copy, distribute or modify the Program subject to
-+these terms and conditions. You may not impose any further
-+restrictions on the recipients' exercise of the rights granted herein.
-+You are not responsible for enforcing compliance by third parties to
-+this License.
-+
-+ 7. If, as a consequence of a court judgment or allegation of patent
-+infringement or for any other reason (not limited to patent issues),
-+conditions are imposed on you (whether by court order, agreement or
-+otherwise) that contradict the conditions of this License, they do not
-+excuse you from the conditions of this License. If you cannot
-+distribute so as to satisfy simultaneously your obligations under this
-+License and any other pertinent obligations, then as a consequence you
-+may not distribute the Program at all. For example, if a patent
-+license would not permit royalty-free redistribution of the Program by
-+all those who receive copies directly or indirectly through you, then
-+the only way you could satisfy both it and this License would be to
-+refrain entirely from distribution of the Program.
-+
-+If any portion of this section is held invalid or unenforceable under
-+any particular circumstance, the balance of the section is intended to
-+apply and the section as a whole is intended to apply in other
-+circumstances.
-+
-+It is not the purpose of this section to induce you to infringe any
-+patents or other property right claims or to contest validity of any
-+such claims; this section has the sole purpose of protecting the
-+integrity of the free software distribution system, which is
-+implemented by public license practices. Many people have made
-+generous contributions to the wide range of software distributed
-+through that system in reliance on consistent application of that
-+system; it is up to the author/donor to decide if he or she is willing
-+to distribute software through any other system and a licensee cannot
-+impose that choice.
-+
-+This section is intended to make thoroughly clear what is believed to
-+be a consequence of the rest of this License.
-+
-+ 8. If the distribution and/or use of the Program is restricted in
-+certain countries either by patents or by copyrighted interfaces, the
-+original copyright holder who places the Program under this License
-+may add an explicit geographical distribution limitation excluding
-+those countries, so that distribution is permitted only in or among
-+countries not thus excluded. In such case, this License incorporates
-+the limitation as if written in the body of this License.
-+
-+ 9. The Free Software Foundation may publish revised and/or new versions
-+of the General Public License from time to time. Such new versions will
-+be similar in spirit to the present version, but may differ in detail to
-+address new problems or concerns.
-+
-+Each version is given a distinguishing version number. If the Program
-+specifies a version number of this License which applies to it and "any
-+later version", you have the option of following the terms and conditions
-+either of that version or of any later version published by the Free
-+Software Foundation. If the Program does not specify a version number of
-+this License, you may choose any version ever published by the Free Software
-+Foundation.
-+
-+ 10. If you wish to incorporate parts of the Program into other free
-+programs whose distribution conditions are different, write to the author
-+to ask for permission. For software which is copyrighted by the Free
-+Software Foundation, write to the Free Software Foundation; we sometimes
-+make exceptions for this. Our decision will be guided by the two goals
-+of preserving the free status of all derivatives of our free software and
-+of promoting the sharing and reuse of software generally.
-+
-+ NO WARRANTY
-+
-+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-+REPAIR OR CORRECTION.
-+
-+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-+POSSIBILITY OF SUCH DAMAGES.
-+
-+ END OF TERMS AND CONDITIONS
-+
-+ How to Apply These Terms to Your New Programs
-+
-+ If you develop a new program, and you want it to be of the greatest
-+possible use to the public, the best way to achieve this is to make it
-+free software which everyone can redistribute and change under these terms.
-+
-+ To do so, attach the following notices to the program. It is safest
-+to attach them to the start of each source file to most effectively
-+convey the exclusion of warranty; and each file should have at least
-+the "copyright" line and a pointer to where the full notice is found.
-+
-+ <one line to give the program's name and a brief idea of what it does.>
-+ Copyright (C) 19yy <name of author>
-+
-+ This program is free software; you can redistribute it and/or modify
-+ it under the terms of the GNU General Public License as published by
-+ the Free Software Foundation; either version 2 of the License, or
-+ (at your option) any later version.
-+
-+ This program is distributed in the hope that it will be useful,
-+ but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ GNU General Public License for more details.
-+
-+ You should have received a copy of the GNU General Public License
-+ along with this program; if not, write to the Free Software
-+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-+
-+
-+Also add information on how to contact you by electronic and paper mail.
-+
-+If the program is interactive, make it output a short notice like this
-+when it starts in an interactive mode:
-+
-+ Gnomovision version 69, Copyright (C) 19yy name of author
-+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-+ This is free software, and you are welcome to redistribute it
-+ under certain conditions; type `show c' for details.
-+
-+The hypothetical commands `show w' and `show c' should show the appropriate
-+parts of the General Public License. Of course, the commands you use may
-+be called something other than `show w' and `show c'; they could even be
-+mouse-clicks or menu items--whatever suits your program.
-+
-+You should also get your employer (if you work as a programmer) or your
-+school, if any, to sign a "copyright disclaimer" for the program, if
-+necessary. Here is a sample; alter the names:
-+
-+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
-+
-+ <signature of Ty Coon>, 1 April 1989
-+ Ty Coon, President of Vice
-+
-+This General Public License does not permit incorporating your program into
-+proprietary programs. If your program is a subroutine library, you may
-+consider it more useful to permit linking proprietary applications with the
-+library. If this is what you want to do, use the GNU Library General
-+Public License instead of this License.
-diff -urNad zaptel-1.0.9/zaphfc/Makefile /tmp/dpep.gzWFVh/zaptel-1.0.9/zaphfc/Makefile
---- zaptel-1.0.9/zaphfc/Makefile 1969-12-31 19:00:00.000000000 -0500
-+++ /tmp/dpep.gzWFVh/zaptel-1.0.9/zaphfc/Makefile 2005-07-04 11:54:37.000000000 -0500
-@@ -0,0 +1,118 @@
-+KINCLUDES = /usr/src/linux/include
-+BRISTUFFBASE = $(shell dirname `pwd`)
-+
-+ZAP = $(shell [ -f $(BRISTUFFBASE)/zaptel-1.0.9/zaptel.h ] && echo "-I$(BRISTUFFBASE)/zaptel-1.0.9")
-+RTAI = $(shell [ -f /usr/realtime/include/rtai.h ] && echo "-DRTAITIMING -I/usr/realtime/include")
-+
-+HOSTCC=gcc
-+
-+CFLAGS+=-I. $(ZAP) $(RTAI) -O2 -g -Wall -DBUILDING_TONEZONE
-+CFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-fsigned-char"; fi)
-+
-+KFLAGS=-D__KERNEL__ -DMODULE -DEXPORT_SYMTAB -fomit-frame-pointer -O2 -Wall -I$(KINCLUDES) $(ZAP) $(RTAI) -Wall
-+KFLAGS+=$(shell [ -f $(KINCLUDES)/linux/modversions.h ] && echo "-DMODVERSIONS -include $(KINCLUDES)/linux/modversions.h")
-+KFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-msoft-float -fsigned-char"; fi)
-+
-+
-+BUILDVER=$(shell if uname -r | grep -q ^2.6; then echo "linux26"; else echo "linux24"; fi)
-+
-+MODCONF=$(shell if [ -d $(INSTALL_PREFIX)/etc/modprobe.d ]; then echo "$(INSTALL_PREFIX)/etc/modprobe.d/zaptel"; elif [ -d $(INSTALL_PREFIX)/etc/modutils ]; then echo "$(INSTALL_PREFIX)/etc/modutils/zaptel"; elif [ -f $(INSTALL_PREFIX)/etc/modprobe.conf ]; then echo "$(INSTALL_PREFIX)/modprobe.conf"; elif [ -f $(INSTALL_PREFIX)/etc/modules.conf ]; then echo "$(INSTALL_PREFIX)/etc/modules.conf"; else echo $(INSTALL_PREFIX)/etc/conf.modules ; fi)
-+
-+OBJS=zaphfc.o
-+
-+MODULES=zaphfc
-+
-+MODULESO=$(shell for x in $(MODULES); do echo "$$x.o "; done )
-+MODULESKO=$(shell for x in $(MODULES); do echo "$$x.ko "; done )
-+
-+PWD=$(shell pwd)
-+
-+obj-m := $(MODULESO)
-+
-+all: $(BUILDVER)
-+
-+linux24: $(OBJS)
-+ sync
-+
-+
-+zaphfc.o: zaphfc.c zaphfc.h
-+ $(CC) -c zaphfc.c $(KFLAGS)
-+
-+clean:
-+ rm -f $(OBJS) *.ko *.mod.c *.mod.o .*o.cmd *~
-+ rm -rf .tmp_versions
-+
-+test: all
-+ modprobe zaptel
-+ insmod ./zaphfc.o
-+ cat /proc/interrupts
-+ sleep 1
-+ cat /proc/interrupts
-+ rmmod zaphfc
-+ rmmod zaptel
-+
-+load: load$(BUILDVER)
-+
-+loadNT: load$(BUILDVER)NT
-+
-+load-debug: load$(BUILDVER)-debug
-+
-+loadNT-debug: load$(BUILDVER)NT-debug
-+
-+loadlinux24: all
-+ modprobe zaptel
-+ insmod ./zaphfc.o
-+ ztcfg -v
-+
-+loadlinux24-debug: all
-+ modprobe zaptel
-+ insmod ./zaphfc.o debug=1
-+ ztcfg -v
-+
-+loadlinux26: linux26
-+ modprobe zaptel
-+ insmod ./zaphfc.ko
-+ ztcfg -v
-+
-+loadlinux26-debug: linux26
-+ modprobe zaptel
-+ insmod ./zaphfc.ko debug=1
-+ ztcfg -v
-+
-+loadlinux24NT: all
-+ modprobe zaptel
-+ insmod ./zaphfc.o modes=1
-+ ztcfg -v
-+
-+loadlinux24NT-debug: all
-+ modprobe zaptel
-+ insmod ./zaphfc.o modes=1 debug=1
-+ ztcfg -v
-+
-+loadlinux26NT: linux26
-+ modprobe zaptel
-+ insmod ./zaphfc.ko modes=1
-+ ztcfg -v
-+
-+loadlinux26NT-debug: linux26
-+ modprobe zaptel
-+ insmod ./zaphfc.ko modes=1 debug=1
-+ ztcfg -v
-+
-+unload:
-+ -rmmod zaphfc zaptel
-+
-+zaphfc.ko: zaphfc.c zaphfc.h
-+
-+linux26:
-+ @if ! [ -d /usr/src/linux-2.6 ]; then echo "Link /usr/src/linux-2.6 to your kernel sources first!"; exit 1 ; fi
-+ make -C /usr/src/linux-2.6 SUBDIRS=$(PWD) ZAP=$(ZAP) modules
-+
-+install: install$(BUILDVER)
-+
-+installlinux26:
-+ install -D -m 644 zaphfc.ko $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/zaphfc.ko
-+
-+installlinux24:
-+ install -D -m 644 zaphfc.o $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/zaphfc.o
-+
-diff -urNad zaptel-1.0.9/zaphfc/zapata.conf /tmp/dpep.gzWFVh/zaptel-1.0.9/zaphfc/zapata.conf
---- zaptel-1.0.9/zaphfc/zapata.conf 1969-12-31 19:00:00.000000000 -0500
-+++ /tmp/dpep.gzWFVh/zaptel-1.0.9/zaphfc/zapata.conf 2005-02-26 12:24:32.000000000 -0500
-@@ -0,0 +1,38 @@
-+;
-+; Zapata telephony interface
-+;
-+; Configuration file
-+
-+[channels]
-+;
-+; Default language
-+;
-+;language=en
-+;
-+; Default context
-+;
-+;
-+switchtype = euroisdn
-+; p2mp TE mode
-+signalling = bri_cpe_ptmp
-+
-+; p2p TE mode
-+;signalling = bri_cpe
-+; p2mp NT mode
-+;signalling = bri_net_ptmp
-+; p2p NT mode
-+;signalling = bri_net
-+
-+pridialplan = dynamic
-+prilocaldialplan = local
-+nationalprefix = 0
-+internationalprefix = 00
-+
-+echocancel=yes
-+echotraining = 100
-+echocancelwhenbridged=yes
-+
-+immediate=yes
-+group = 1
-+context=demo
-+channel => 1-2
-diff -urNad zaptel-1.0.9/zaphfc/zaphfc.c /tmp/dpep.gzWFVh/zaptel-1.0.9/zaphfc/zaphfc.c
---- zaptel-1.0.9/zaphfc/zaphfc.c 1969-12-31 19:00:00.000000000 -0500
-+++ /tmp/dpep.gzWFVh/zaptel-1.0.9/zaphfc/zaphfc.c 2005-03-06 13:51:13.000000000 -0500
-@@ -0,0 +1,1149 @@
-+/*
-+ * zaphfc.c - Zaptel driver for HFC-S PCI A based ISDN BRI cards
-+ *
-+ * kernel module inspired by HFC PCI ISDN4Linux and Zaptel drivers
-+ *
-+ * Copyright (C) 2002, 2003, 2004, 2005 Junghanns.NET GmbH
-+ *
-+ * Klaus-Peter Junghanns <kpj at junghanns.net>
-+ *
-+ * This program is free software and may be modified and
-+ * distributed under the terms of the GNU Public License.
-+ *
-+ */
-+
-+#include <linux/kernel.h>
-+#include <linux/module.h>
-+#ifdef RTAITIMING
-+#include <asm/io.h>
-+#include <rtai.h>
-+#include <rtai_sched.h>
-+#include <rtai_fifos.h>
-+#endif
-+#include <linux/pci.h>
-+#include <linux/init.h>
-+#include <linux/interrupt.h>
-+#include <linux/delay.h>
-+#include <zaptel.h>
-+#include "zaphfc.h"
-+
-+#if CONFIG_PCI
-+
-+#define CLKDEL_TE 0x0f /* CLKDEL in TE mode */
-+#define CLKDEL_NT 0x6c /* CLKDEL in NT mode */
-+
-+typedef struct {
-+ int vendor_id;
-+ int device_id;
-+ char *vendor_name;
-+ char *card_name;
-+} PCI_ENTRY;
-+
-+static const PCI_ENTRY id_list[] =
-+{
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_2BD0, "CCD/Billion/Asuscom", "2BD0"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B000, "Billion", "B000"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B006, "Billion", "B006"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B007, "Billion", "B007"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B008, "Billion", "B008"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B009, "Billion", "B009"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B00A, "Billion", "B00A"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B00B, "Billion", "B00B"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B00C, "Billion", "B00C"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B100, "Seyeon", "B100"},
-+ {PCI_VENDOR_ID_ABOCOM, PCI_DEVICE_ID_ABOCOM_2BD1, "Abocom/Magitek", "2BD1"},
-+ {PCI_VENDOR_ID_ASUSTEK, PCI_DEVICE_ID_ASUSTEK_0675, "Asuscom/Askey", "675"},
-+ {PCI_VENDOR_ID_BERKOM, PCI_DEVICE_ID_BERKOM_T_CONCEPT, "German telekom", "T-Concept"},
-+ {PCI_VENDOR_ID_BERKOM, PCI_DEVICE_ID_BERKOM_A1T, "German telekom", "A1T"},
-+ {PCI_VENDOR_ID_ANIGMA, PCI_DEVICE_ID_ANIGMA_MC145575, "Motorola MC145575", "MC145575"},
-+ {PCI_VENDOR_ID_ZOLTRIX, PCI_DEVICE_ID_ZOLTRIX_2BD0, "Zoltrix", "2BD0"},
-+ {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_IOM2_E,"Digi International", "Digi DataFire Micro V IOM2 (Europe)"},
-+ {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_E,"Digi International", "Digi DataFire Micro V (Europe)"},
-+ {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_IOM2_A,"Digi International", "Digi DataFire Micro V IOM2 (North America)"},
-+ {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_A,"Digi International", "Digi DataFire Micro V (North America)"},
-+ {0x182d, 0x3069,"Sitecom","Isdn 128 PCI"},
-+ {0, 0, NULL, NULL},
-+};
-+
-+static struct hfc_card *hfc_dev_list = NULL;
-+static int hfc_dev_count = 0;
-+static int modes = 0; // all TE
-+static int debug = 0;
-+static struct pci_dev *multi_hfc = NULL;
-+static spinlock_t registerlock = SPIN_LOCK_UNLOCKED;
-+
-+void hfc_shutdownCard(struct hfc_card *hfctmp) {
-+ unsigned long flags;
-+
-+ if (hfctmp == NULL) {
-+ return;
-+ }
-+
-+ if (hfctmp->pci_io == NULL) {
-+ return;
-+ }
-+
-+ spin_lock_irqsave(&hfctmp->lock,flags);
-+
-+ printk(KERN_INFO "zaphfc: shutting down card at %p.\n",hfctmp->pci_io);
-+
-+ /* Clear interrupt mask */
-+ hfctmp->regs.int_m2 = 0;
-+ hfc_outb(hfctmp, hfc_INT_M2, hfctmp->regs.int_m2);
-+
-+ /* Reset pending interrupts */
-+ hfc_inb(hfctmp, hfc_INT_S1);
-+
-+ /* Wait for interrupts that might still be pending */
-+ spin_unlock_irqrestore(&hfctmp->lock, flags);
-+ set_current_state(TASK_UNINTERRUPTIBLE);
-+ schedule_timeout((30 * HZ) / 1000); // wait 30 ms
-+ spin_lock_irqsave(&hfctmp->lock,flags);
-+
-+ /* Remove interrupt handler */
-+ if (hfctmp->irq) {
-+ free_irq(hfctmp->irq, hfctmp);
-+ }
-+
-+ /* Soft-reset the card */
-+ hfc_outb(hfctmp, hfc_CIRM, hfc_CIRM_RESET); // softreset on
-+
-+ spin_unlock_irqrestore(&hfctmp->lock, flags);
-+ set_current_state(TASK_UNINTERRUPTIBLE);
-+ schedule_timeout((30 * HZ) / 1000); // wait 30 ms
-+ spin_lock_irqsave(&hfctmp->lock,flags);
-+
-+ hfc_outb(hfctmp,hfc_CIRM,0); // softreset off
-+
-+ pci_write_config_word(hfctmp->pcidev, PCI_COMMAND, 0); // disable memio and bustmaster
-+
-+ if (hfctmp->fifomem != NULL) {
-+ kfree(hfctmp->fifomem);
-+ }
-+ iounmap((void *) hfctmp->pci_io);
-+ hfctmp->pci_io = NULL;
-+ if (hfctmp->pcidev != NULL) {
-+ pci_disable_device(hfctmp->pcidev);
-+ }
-+ spin_unlock_irqrestore(&hfctmp->lock,flags);
-+ if (hfctmp->ztdev != NULL) {
-+ zt_unregister(&hfctmp->ztdev->span);
-+ kfree(hfctmp->ztdev);
-+ printk(KERN_INFO "unregistered from zaptel.\n");
-+ }
-+}
-+
-+void hfc_resetCard(struct hfc_card *hfctmp) {
-+ unsigned long flags;
-+
-+ spin_lock_irqsave(&hfctmp->lock,flags);
-+ pci_write_config_word(hfctmp->pcidev, PCI_COMMAND, PCI_COMMAND_MEMORY); // enable memio
-+ hfctmp->regs.int_m2 = 0;
-+ hfc_outb(hfctmp, hfc_INT_M2, hfctmp->regs.int_m2);
-+
-+// printk(KERN_INFO "zaphfc: resetting card.\n");
-+ pci_set_master(hfctmp->pcidev);
-+ hfc_outb(hfctmp, hfc_CIRM, hfc_CIRM_RESET); // softreset on
-+ spin_unlock_irqrestore(&hfctmp->lock, flags);
-+
-+ set_current_state(TASK_UNINTERRUPTIBLE);
-+ schedule_timeout((30 * HZ) / 1000); // wait 30 ms
-+ hfc_outb(hfctmp, hfc_CIRM, 0); // softreset off
-+
-+ set_current_state(TASK_UNINTERRUPTIBLE);
-+ schedule_timeout((20 * HZ) / 1000); // wait 20 ms
-+ if (hfc_inb(hfctmp,hfc_STATUS) & hfc_STATUS_PCI_PROC) {
-+ printk(KERN_WARNING "zaphfc: hfc busy.\n");
-+ }
-+
-+// hfctmp->regs.fifo_en = hfc_FIFOEN_D | hfc_FIFOEN_B1 | hfc_FIFOEN_B2;
-+// hfctmp->regs.fifo_en = hfc_FIFOEN_D; /* only D fifos enabled */
-+ hfctmp->regs.fifo_en = 0; /* no fifos enabled */
-+ hfc_outb(hfctmp, hfc_FIFO_EN, hfctmp->regs.fifo_en);
-+
-+ hfctmp->regs.trm = 2;
-+ hfc_outb(hfctmp, hfc_TRM, hfctmp->regs.trm);
-+
-+ if (hfctmp->regs.nt_mode == 1) {
-+ hfc_outb(hfctmp, hfc_CLKDEL, CLKDEL_NT); /* ST-Bit delay for NT-Mode */
-+ } else {
-+ hfc_outb(hfctmp, hfc_CLKDEL, CLKDEL_TE); /* ST-Bit delay for TE-Mode */
-+ }
-+ hfctmp->regs.sctrl_e = hfc_SCTRL_E_AUTO_AWAKE;
-+ hfc_outb(hfctmp, hfc_SCTRL_E, hfctmp->regs.sctrl_e); /* S/T Auto awake */
-+ hfctmp->regs.bswapped = 0; /* no exchange */
-+
-+ hfctmp->regs.ctmt = hfc_CTMT_TRANSB1 | hfc_CTMT_TRANSB2; // all bchans are transparent , no freaking hdlc
-+ hfc_outb(hfctmp, hfc_CTMT, hfctmp->regs.ctmt);
-+
-+ hfctmp->regs.int_m1 = 0;
-+ hfc_outb(hfctmp, hfc_INT_M1, hfctmp->regs.int_m1);
-+
-+#ifdef RTAITIMING
-+ hfctmp->regs.int_m2 = 0;
-+#else
-+ hfctmp->regs.int_m2 = hfc_M2_PROC_TRANS;
-+#endif
-+ hfc_outb(hfctmp, hfc_INT_M2, hfctmp->regs.int_m2);
-+
-+ /* Clear already pending ints */
-+ hfc_inb(hfctmp, hfc_INT_S1);
-+
-+ if (hfctmp->regs.nt_mode == 1) {
-+ hfctmp->regs.sctrl = 3 | hfc_SCTRL_NONE_CAP | hfc_SCTRL_MODE_NT; /* set tx_lo mode, error in datasheet ! */
-+ } else {
-+ hfctmp->regs.sctrl = 3 | hfc_SCTRL_NONE_CAP | hfc_SCTRL_MODE_TE; /* set tx_lo mode, error in datasheet ! */
-+ }
-+
-+ hfctmp->regs.mst_mode = hfc_MST_MODE_MASTER; /* HFC Master Mode */
-+ hfc_outb(hfctmp, hfc_MST_MODE, hfctmp->regs.mst_mode);
-+
-+ hfc_outb(hfctmp, hfc_SCTRL, hfctmp->regs.sctrl);
-+ hfctmp->regs.sctrl_r = 3;
-+ hfc_outb(hfctmp, hfc_SCTRL_R, hfctmp->regs.sctrl_r);
-+
-+ hfctmp->regs.connect = 0;
-+ hfc_outb(hfctmp, hfc_CONNECT, hfctmp->regs.connect);
-+
-+ hfc_outb(hfctmp, hfc_CIRM, 0x80 | 0x40); // bit order
-+
-+ /* Finally enable IRQ output */
-+#ifndef RTAITIMING
-+ hfctmp->regs.int_m2 |= hfc_M2_IRQ_ENABLE;
-+ hfc_outb(hfctmp, hfc_INT_M2, hfctmp->regs.int_m2);
-+#endif
-+
-+ /* clear pending ints */
-+ hfc_inb(hfctmp, hfc_INT_S1);
-+ hfc_inb(hfctmp, hfc_INT_S2);
-+}
-+
-+void hfc_registerCard(struct hfc_card *hfccard) {
-+ spin_lock(®isterlock);
-+ if (hfccard != NULL) {
-+ hfccard->cardno = hfc_dev_count++;
-+ hfccard->next = hfc_dev_list;
-+ hfc_dev_list = hfccard;
-+ }
-+ spin_unlock(®isterlock);
-+}
-+
-+static void hfc_btrans(struct hfc_card *hfctmp, char whichB) {
-+ // we are called with irqs disabled from the irq handler
-+ int count, maxlen, total;
-+ unsigned char *f1, *f2;
-+ unsigned short *z1, *z2, newz1;
-+ int freebytes;
-+
-+ if (whichB == 1) {
-+ f1 = (char *)(hfctmp->fifos + hfc_FIFO_B1TX_F1);
-+ f2 = (char *)(hfctmp->fifos + hfc_FIFO_B1TX_F2);
-+ z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B1TX_Z1 + (*f1 * 4));
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B1TX_Z2 + (*f1 * 4));
-+ } else {
-+ f1 = (char *)(hfctmp->fifos + hfc_FIFO_B2TX_F1);
-+ f2 = (char *)(hfctmp->fifos + hfc_FIFO_B2TX_F2);
-+ z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B2TX_Z1 + (*f1 * 4));
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B2TX_Z2 + (*f1 * 4));
-+ }
-+
-+ freebytes = *z2 - *z1;
-+ if (freebytes <= 0) {
-+ freebytes += hfc_B_FIFO_SIZE;
-+ }
-+ count = ZT_CHUNKSIZE;
-+
-+ total = count;
-+ if (freebytes < count) {
-+ hfctmp->clicks++;
-+ /* only spit out this warning once per second to not make things worse! */
-+ if (hfctmp->clicks > 100) {
-+ printk(KERN_CRIT "zaphfc: bchan tx fifo full, dropping audio! (z1=%d, z2=%d)\n",*z1,*z2);
-+ hfctmp->clicks = 0;
-+ }
-+ return;
-+ }
-+
-+ maxlen = (hfc_B_FIFO_SIZE + hfc_B_SUB_VAL) - *z1;
-+ if (maxlen > count) {
-+ maxlen = count;
-+ }
-+ newz1 = *z1 + total;
-+ if (newz1 >= (hfc_B_FIFO_SIZE + hfc_B_SUB_VAL)) { newz1 -= hfc_B_FIFO_SIZE; }
-+
-+ if (whichB == 1) {
-+ memcpy((char *)(hfctmp->fifos + hfc_FIFO_B1TX_ZOFF + *z1),hfctmp->ztdev->chans[0].writechunk, maxlen);
-+ } else {
-+ memcpy((char *)(hfctmp->fifos + hfc_FIFO_B2TX_ZOFF + *z1),hfctmp->ztdev->chans[1].writechunk, maxlen);
-+ }
-+
-+ count -= maxlen;
-+ if (count > 0) {
-+ // Buffer wrap
-+ if (whichB == 1) {
-+ memcpy((char *)(hfctmp->fifos + hfc_FIFO_B1TX_ZOFF + hfc_B_SUB_VAL),hfctmp->ztdev->chans[0].writechunk+maxlen, count);
-+ } else {
-+ memcpy((char *)(hfctmp->fifos + hfc_FIFO_B2TX_ZOFF + hfc_B_SUB_VAL),hfctmp->ztdev->chans[1].writechunk+maxlen, count);
-+ }
-+ }
-+
-+ *z1 = newz1; /* send it now */
-+
-+// if (count > 0) printk(KERN_CRIT "zaphfc: bchan tx fifo (f1=%d, f2=%d, z1=%d, z2=%d)\n",(*f1) & hfc_FMASK,(*f2) & hfc_FMASK, *z1, *z2);
-+ return;
-+}
-+
-+static void hfc_brec(struct hfc_card *hfctmp, char whichB) {
-+ // we are called with irqs disabled from the irq handler
-+ int count, maxlen, drop;
-+ volatile unsigned char *f1, *f2;
-+ volatile unsigned short *z1, *z2, newz2;
-+ int bytes = 0;
-+
-+ if (whichB == 1) {
-+ f1 = (char *)(hfctmp->fifos + hfc_FIFO_B1RX_F1);
-+ f2 = (char *)(hfctmp->fifos + hfc_FIFO_B1RX_F2);
-+ z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B1RX_Z1 + (*f1 * 4));
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B1RX_Z2 + (*f1 * 4));
-+ } else {
-+ f1 = (char *)(hfctmp->fifos + hfc_FIFO_B2RX_F1);
-+ f2 = (char *)(hfctmp->fifos + hfc_FIFO_B2RX_F2);
-+ z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B2RX_Z1 + (*f1 * 4));
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B2RX_Z2 + (*f1 * 4));
-+ }
-+
-+ bytes = *z1 - *z2;
-+ if (bytes < 0) {
-+ bytes += hfc_B_FIFO_SIZE;
-+ }
-+ count = ZT_CHUNKSIZE;
-+
-+ if (bytes < ZT_CHUNKSIZE) {
-+#ifndef RTAITIMING
-+ printk(KERN_CRIT "zaphfc: bchan rx fifo not enough bytes to receive! (z1=%d, z2=%d, wanted %d got %d), probably a buffer overrun.\n",*z1,*z2,ZT_CHUNKSIZE,bytes);
-+#endif
-+ return;
-+ }
-+
-+ /* allowing the buffering of hfc_BCHAN_BUFFER bytes of audio data works around irq jitter */
-+ if (bytes > hfc_BCHAN_BUFFER + ZT_CHUNKSIZE) {
-+ /* if the system is too slow to handle it, we will have to drop it all (except 1 zaptel chunk) */
-+ drop = bytes - ZT_CHUNKSIZE;
-+ hfctmp->clicks++;
-+ /* only spit out this warning once per second to not make things worse! */
-+ if (hfctmp->clicks > 100) {
-+ printk(KERN_CRIT "zaphfc: dropped audio (z1=%d, z2=%d, wanted %d got %d, dropped %d).\n",*z1,*z2,count,bytes,drop);
-+ hfctmp->clicks = 0;
-+ }
-+ /* hm, we are processing the b chan data tooooo slowly... let's drop the lost audio */
-+ newz2 = *z2 + drop;
-+ if (newz2 >= (hfc_B_FIFO_SIZE + hfc_B_SUB_VAL)) {
-+ newz2 -= hfc_B_FIFO_SIZE;
-+ }
-+ *z2 = newz2;
-+ }
-+
-+
-+ maxlen = (hfc_B_FIFO_SIZE + hfc_B_SUB_VAL) - *z2;
-+ if (maxlen > count) {
-+ maxlen = count;
-+ }
-+ if (whichB == 1) {
-+ memcpy(hfctmp->ztdev->chans[0].readchunk,(char *)(hfctmp->fifos + hfc_FIFO_B1RX_ZOFF + *z2), maxlen);
-+ } else {
-+ memcpy(hfctmp->ztdev->chans[1].readchunk,(char *)(hfctmp->fifos + hfc_FIFO_B2RX_ZOFF + *z2), maxlen);
-+ }
-+ newz2 = *z2 + count;
-+ if (newz2 >= (hfc_B_FIFO_SIZE + hfc_B_SUB_VAL)) {
-+ newz2 -= hfc_B_FIFO_SIZE;
-+ }
-+ *z2 = newz2;
-+
-+ count -= maxlen;
-+ if (count > 0) {
-+ // Buffer wrap
-+ if (whichB == 1) {
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B1RX_Z2 + (*f1 * 4));
-+ memcpy(hfctmp->ztdev->chans[0].readchunk + maxlen,(char *)(hfctmp->fifos + hfc_FIFO_B1RX_ZOFF + hfc_B_SUB_VAL), count);
-+ } else {
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B2RX_Z2 + (*f1 * 4));
-+ memcpy(hfctmp->ztdev->chans[1].readchunk + maxlen,(char *)(hfctmp->fifos + hfc_FIFO_B2RX_ZOFF + hfc_B_SUB_VAL), count);
-+ }
-+ newz2 = *z2 + count;
-+ if (newz2 >= (hfc_B_FIFO_SIZE + hfc_B_SUB_VAL)) {
-+ newz2 -= hfc_B_FIFO_SIZE;
-+ }
-+ }
-+
-+
-+ if (whichB == 1) {
-+ zt_ec_chunk(&hfctmp->ztdev->chans[0], hfctmp->ztdev->chans[0].readchunk, hfctmp->ztdev->chans[0].writechunk);
-+ } else {
-+ zt_ec_chunk(&hfctmp->ztdev->chans[1], hfctmp->ztdev->chans[1].readchunk, hfctmp->ztdev->chans[1].writechunk);
-+ }
-+ return;
-+}
-+
-+
-+static void hfc_dtrans(struct hfc_card *hfctmp) {
-+ // we are called with irqs disabled from the irq handler
-+ int x;
-+ int count, maxlen, total;
-+ unsigned char *f1, *f2, newf1;
-+ unsigned short *z1, *z2, newz1;
-+ int frames, freebytes;
-+
-+ if (hfctmp->ztdev->chans[2].bytes2transmit == 0) {
-+ return;
-+ }
-+
-+ f1 = (char *)(hfctmp->fifos + hfc_FIFO_DTX_F1);
-+ f2 = (char *)(hfctmp->fifos + hfc_FIFO_DTX_F2);
-+ z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DTX_Z1 + (*f1 * 4));
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DTX_Z2 + (*f1 * 4));
-+
-+ frames = (*f1 - *f2) & hfc_FMASK;
-+ if (frames < 0) {
-+ frames += hfc_MAX_DFRAMES + 1;
-+ }
-+
-+ if (frames >= hfc_MAX_DFRAMES) {
-+ printk(KERN_CRIT "zaphfc: dchan tx fifo total number of frames exceeded!\n");
-+ return;
-+ }
-+
-+ freebytes = *z2 - *z1;
-+ if (freebytes <= 0) {
-+ freebytes += hfc_D_FIFO_SIZE;
-+ }
-+ count = hfctmp->ztdev->chans[2].bytes2transmit;
-+
-+ total = count;
-+ if (freebytes < count) {
-+ printk(KERN_CRIT "zaphfc: dchan tx fifo not enough free bytes! (z1=%d, z2=%d)\n",*z1,*z2);
-+ return;
-+ }
-+
-+ newz1 = (*z1 + count) & hfc_ZMASK;
-+ newf1 = ((*f1 + 1) & hfc_MAX_DFRAMES) | (hfc_MAX_DFRAMES + 1); // next frame
-+
-+ if (count > 0) {
-+ if (debug) {
-+ printk(KERN_CRIT "zaphfc: card %d TX [ ", hfctmp->cardno);
-+ for (x=0; x<count; x++) {
-+ printk("%#2x ",hfctmp->dtransbuf[x]);
-+ }
-+ if (hfctmp->ztdev->chans[2].eoftx == 1) {
-+ printk("] %d bytes\n", count);
-+ } else {
-+ printk("..] %d bytes\n", count);
-+ }
-+ }
-+ maxlen = hfc_D_FIFO_SIZE - *z1;
-+ if (maxlen > count) {
-+ maxlen = count;
-+ }
-+ memcpy((char *)(hfctmp->fifos + hfc_FIFO_DTX_ZOFF + *z1),hfctmp->ztdev->chans[2].writechunk, maxlen);
-+ count -= maxlen;
-+ if (count > 0) {
-+ memcpy((char *)(hfctmp->fifos + hfc_FIFO_DTX_ZOFF),(char *)(hfctmp->ztdev->chans[2].writechunk + maxlen), count);
-+ }
-+ }
-+
-+ *z1 = newz1;
-+
-+ if (hfctmp->ztdev->chans[2].eoftx == 1) {
-+ *f1 = newf1;
-+ z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DTX_Z1 + (*f1 * 4));
-+ *z1 = newz1;
-+ hfctmp->ztdev->chans[2].eoftx = 0;
-+ }
-+// printk(KERN_CRIT "zaphfc: dchan tx fifo (f1=%d, f2=%d, z1=%d, z2=%d)\n",(*f1) & hfc_FMASK,(*f2) & hfc_FMASK, *z1, *z2);
-+ return;
-+}
-+
-+/* receive a complete hdlc frame, skip broken or short frames */
-+static void hfc_drec(struct hfc_card *hfctmp) {
-+ int count=0, maxlen=0, framelen=0;
-+ unsigned char *f1, *f2, *crcstat;
-+ unsigned short *z1, *z2, oldz2, newz2;
-+
-+ hfctmp->ztdev->chans[2].bytes2receive=0;
-+ hfctmp->ztdev->chans[2].eofrx = 0;
-+
-+ /* put the received data into the zaptel buffer
-+ we'll call zt_receive() later when the timer fires. */
-+ f1 = (char *)(hfctmp->fifos + hfc_FIFO_DRX_F1);
-+ f2 = (char *)(hfctmp->fifos + hfc_FIFO_DRX_F2);
-+
-+ if (*f1 == *f2) return; /* nothing received, strange eh? */
-+
-+ z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DRX_Z1 + (*f2 * 4));
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DRX_Z2 + (*f2 * 4));
-+
-+ /* calculate length of frame, including 2 bytes CRC and 1 byte STAT */
-+ count = *z1 - *z2;
-+
-+ if (count < 0) {
-+ count += hfc_D_FIFO_SIZE; /* ring buffer wrapped */
-+ }
-+ count++;
-+ framelen = count;
-+
-+ crcstat = (char *)(hfctmp->fifos + hfc_FIFO_DRX_ZOFF + *z1);
-+
-+ if ((framelen < 4) || (*crcstat != 0x0)) {
-+ /* the frame is too short for a valid HDLC frame or the CRC is borked */
-+ printk(KERN_CRIT "zaphfc: empty HDLC frame or bad CRC received (framelen = %d, stat = %#x, card = %d).\n", framelen, *crcstat, hfctmp->cardno);
-+ oldz2 = *z2;
-+ *f2 = ((*f2 + 1) & hfc_MAX_DFRAMES) | (hfc_MAX_DFRAMES + 1); /* NEXT!!! */
-+ // recalculate z2, because Z2 is a function of F2 Z2(F2) and we INCed F2!!!
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DRX_Z2 + (*f2 * 4));
-+ *z2 = (oldz2 + framelen) & hfc_ZMASK;
-+ hfctmp->drecinframe = 0;
-+ hfctmp->regs.int_drec--;
-+ /* skip short or broken frames */
-+ hfctmp->ztdev->chans[2].bytes2receive = 0;
-+ return;
-+ }
-+
-+ count -= 1; /* strip STAT */
-+ hfctmp->ztdev->chans[2].eofrx = 1;
-+
-+ if (count + *z2 <= hfc_D_FIFO_SIZE) {
-+ maxlen = count;
-+ } else {
-+ maxlen = hfc_D_FIFO_SIZE - *z2;
-+ }
-+
-+ /* copy first part */
-+ memcpy(hfctmp->drecbuf, (char *)(hfctmp->fifos + hfc_FIFO_DRX_ZOFF + *z2), maxlen);
-+ hfctmp->ztdev->chans[2].bytes2receive += maxlen;
-+
-+ count -= maxlen;
-+ if (count > 0) {
-+ /* ring buffer wrapped, copy rest from start of d fifo */
-+ memcpy(hfctmp->drecbuf + maxlen, (char *)(hfctmp->fifos + hfc_FIFO_DRX_ZOFF), count);
-+ hfctmp->ztdev->chans[2].bytes2receive += count;
-+ }
-+
-+ /* frame read */
-+ oldz2 = *z2;
-+ newz2 = (oldz2 + framelen) & hfc_ZMASK;
-+ *f2 = ((*f2 + 1) & hfc_MAX_DFRAMES) | (hfc_MAX_DFRAMES + 1); /* NEXT!!! */
-+ /* recalculate z2, because Z2 is a function of F2 Z2(F2) and we INCed F2!!! */
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DRX_Z2 + (*f2 * 4));
-+ *z2 = newz2;
-+ hfctmp->drecinframe = 0;
-+ hfctmp->regs.int_drec--;
-+}
-+
-+#ifndef RTAITIMING
-+#ifdef LINUX26
-+static irqreturn_t hfc_interrupt(int irq, void *dev_id, struct pt_regs *regs) {
-+#else
-+static void hfc_interrupt(int irq, void *dev_id, struct pt_regs *regs) {
-+#endif
-+ struct hfc_card *hfctmp = dev_id;
-+ unsigned long flags = 0;
-+ unsigned char stat;
-+#else
-+static void hfc_service(struct hfc_card *hfctmp) {
-+#endif
-+ struct zt_hfc *zthfc;
-+ unsigned char s1, s2, l1state;
-+ int x;
-+
-+ if (!hfctmp) {
-+#ifndef RTAITIMING
-+#ifdef LINUX26
-+ return IRQ_NONE;
-+#else
-+ return;
-+#endif
-+#else
-+ /* rtai */
-+ return;
-+#endif
-+ }
-+
-+ if (!hfctmp->pci_io) {
-+ printk(KERN_WARNING "%s: IO-mem disabled, cannot handle interrupt\n",
-+ __FUNCTION__);
-+#ifndef RTAITIMING
-+#ifdef LINUX26
-+ return IRQ_NONE;
-+#else
-+ return;
-+#endif
-+#else
-+ /* rtai */
-+ return;
-+#endif
-+ }
-+
-+ /* we assume a few things in this irq handler:
-+ - the hfc-pci will only generate "timer" irqs (proc/non-proc)
-+ - we need to use every 8th IRQ (to generate 1khz timing)
-+ OR
-+ - if we use rtai for timing the hfc-pci will not generate ANY irq,
-+ instead rtai will call this "fake" irq with a 1khz realtime timer. :)
-+ - rtai will directly service the card, not like it used to by triggering
-+ the linux irq
-+ */
-+
-+#ifndef RTAITIMING
-+ spin_lock_irqsave(&hfctmp->lock, flags);
-+ stat = hfc_inb(hfctmp, hfc_STATUS);
-+
-+ if ((stat & hfc_STATUS_ANYINT) == 0) {
-+ // maybe we are sharing the irq
-+ spin_unlock_irqrestore(&hfctmp->lock,flags);
-+#ifdef LINUX26
-+ return IRQ_NONE;
-+#else
-+ return;
-+#endif
-+ }
-+#endif
-+
-+ s1 = hfc_inb(hfctmp, hfc_INT_S1);
-+ s2 = hfc_inb(hfctmp, hfc_INT_S2);
-+ if (s1 != 0) {
-+ if (s1 & hfc_INTS_TIMER) {
-+ // timer (bit 7)
-+ // printk(KERN_CRIT "timer %d %d %d.\n", stat, s1, s2);
-+ }
-+ if (s1 & hfc_INTS_L1STATE) {
-+ // state machine (bit 6)
-+ // printk(KERN_CRIT "zaphfc: layer 1 state machine interrupt\n");
-+ zthfc = hfctmp->ztdev;
-+ l1state = hfc_inb(hfctmp,hfc_STATES) & hfc_STATES_STATE_MASK;
-+ if (hfctmp->regs.nt_mode == 1) {
-+ if (debug) {
-+ printk(KERN_CRIT "zaphfc: card %d layer 1 state = G%d\n", hfctmp->cardno, l1state);
-+ }
-+ switch (l1state) {
-+ case 3:
-+#ifdef RTAITIMING
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [NT] layer 1 ACTIVATED (G%d) [realtime]", hfctmp->cardno, l1state);
-+#else
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [NT] layer 1 ACTIVATED (G%d)", hfctmp->cardno, l1state);
-+#endif
-+ break;
-+ default:
-+#ifdef RTAITIMING
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [NT] layer 1 DEACTIVATED (G%d) [realtime]", hfctmp->cardno, l1state);
-+#else
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [NT] layer 1 DEACTIVATED (G%d)", hfctmp->cardno, l1state);
-+#endif
-+ }
-+ if (l1state == 2) {
-+ hfc_outb(hfctmp, hfc_STATES, hfc_STATES_ACTIVATE | hfc_STATES_DO_ACTION | hfc_STATES_NT_G2_G3);
-+ } else if (l1state == 3) {
-+ // fix to G3 state (see specs)
-+ hfc_outb(hfctmp, hfc_STATES, hfc_STATES_LOAD_STATE | 3);
-+ }
-+ } else {
-+ if (debug) {
-+ printk(KERN_CRIT "zaphfc: card %d layer 1 state = F%d\n", hfctmp->cardno, l1state);
-+ }
-+ switch (l1state) {
-+ case 7:
-+#ifdef RTAITIMING
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [TE] layer 1 ACTIVATED (F%d) [realtime]", hfctmp->cardno, l1state);
-+#else
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [TE] layer 1 ACTIVATED (F%d)", hfctmp->cardno, l1state);
-+#endif
-+ break;
-+ default:
-+#ifdef RTAITIMING
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [TE] layer 1 DEACTIVATED (F%d) [realtime]", hfctmp->cardno, l1state);
-+#else
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [TE] layer 1 DEACTIVATED (F%d)", hfctmp->cardno, l1state);
-+#endif
-+ }
-+ if (l1state == 3) {
-+ hfc_outb(hfctmp, hfc_STATES, hfc_STATES_DO_ACTION | hfc_STATES_ACTIVATE);
-+ }
-+ }
-+
-+ }
-+ if (s1 & hfc_INTS_DREC) {
-+ // D chan RX (bit 5)
-+ hfctmp->regs.int_drec++;
-+ // mr. zapata there is something for you!
-+ // printk(KERN_CRIT "d chan rx\n");
-+ }
-+ if (s1 & hfc_INTS_B2REC) {
-+ // B2 chan RX (bit 4)
-+ }
-+ if (s1 & hfc_INTS_B1REC) {
-+ // B1 chan RX (bit 3)
-+ }
-+ if (s1 & hfc_INTS_DTRANS) {
-+ // D chan TX (bit 2)
-+// printk(KERN_CRIT "zaphfc: dchan frame transmitted.\n");
-+ }
-+ if (s1 & hfc_INTS_B2TRANS) {
-+ // B2 chan TX (bit 1)
-+ }
-+ if (s1 & hfc_INTS_B1TRANS) {
-+ // B1 chan TX (bit 0)
-+ }
-+ }
-+#ifdef RTAITIMING
-+ /* fake an irq */
-+ s2 |= hfc_M2_PROC_TRANS;
-+#endif
-+ if (s2 != 0) {
-+ if (s2 & hfc_M2_PMESEL) {
-+ // kaboom irq (bit 7)
-+ printk(KERN_CRIT "zaphfc: sync lost, pci performance too low. you might have some cpu throtteling enabled.\n");
-+ }
-+ if (s2 & hfc_M2_GCI_MON_REC) {
-+ // RxR monitor channel (bit 2)
-+ }
-+ if (s2 & hfc_M2_GCI_I_CHG) {
-+ // GCI I-change (bit 1)
-+ }
-+ if (s2 & hfc_M2_PROC_TRANS) {
-+ // processing/non-processing transition (bit 0)
-+ hfctmp->ticks++;
-+#ifndef RTAITIMING
-+ if (hfctmp->ticks > 7) {
-+ // welcome to zaptel timing :)
-+#endif
-+ hfctmp->ticks = 0;
-+
-+ if (hfctmp->ztdev->span.flags & ZT_FLAG_RUNNING) {
-+ // clear dchan buffer
-+ hfctmp->ztdev->chans[2].bytes2transmit = 0;
-+ hfctmp->ztdev->chans[2].maxbytes2transmit = hfc_D_FIFO_SIZE;
-+
-+ zt_transmit(&(hfctmp->ztdev->span));
-+
-+ hfc_btrans(hfctmp,1);
-+ hfc_btrans(hfctmp,2);
-+ hfc_dtrans(hfctmp);
-+ }
-+
-+ hfc_brec(hfctmp,1);
-+ hfc_brec(hfctmp,2);
-+ if (hfctmp->regs.int_drec > 0) {
-+ // dchan data to read
-+ hfc_drec(hfctmp);
-+ if (hfctmp->ztdev->chans[2].bytes2receive > 0) {
-+ if (debug) {
-+ printk(KERN_CRIT "zaphfc: card %d RX [ ", hfctmp->cardno);
-+ if (hfctmp->ztdev->chans[2].eofrx) {
-+ /* dont output CRC == less user confusion */
-+ for (x=0; x < hfctmp->ztdev->chans[2].bytes2receive - 2; x++) {
-+ printk("%#2x ", hfctmp->drecbuf[x]);
-+ }
-+ printk("] %d bytes\n", hfctmp->ztdev->chans[2].bytes2receive - 2);
-+ } else {
-+ for (x=0; x < hfctmp->ztdev->chans[2].bytes2receive; x++) {
-+ printk("%#2x ", hfctmp->drecbuf[x]);
-+ }
-+ printk("..] %d bytes\n", hfctmp->ztdev->chans[2].bytes2receive);
-+ }
-+ }
-+ }
-+ } else {
-+ // hmm....ok, let zaptel receive nothing
-+ hfctmp->ztdev->chans[2].bytes2receive = 0;
-+ }
-+ if (hfctmp->ztdev->span.flags & ZT_FLAG_RUNNING) {
-+ zt_receive(&(hfctmp->ztdev->span));
-+ }
-+
-+#ifndef RTAITIMING
-+ }
-+#endif
-+ }
-+
-+ }
-+#ifndef RTAITIMING
-+ spin_unlock_irqrestore(&hfctmp->lock,flags);
-+#ifdef LINUX26
-+ return IRQ_RETVAL(1);
-+#endif
-+#endif
-+}
-+
-+
-+static int zthfc_open(struct zt_chan *chan) {
-+ struct zt_hfc *zthfc = chan->pvt;
-+ struct hfc_card *hfctmp = zthfc->card;
-+
-+ if (!hfctmp) {
-+ return 0;
-+ }
-+#ifndef LINUX26
-+ MOD_INC_USE_COUNT;
-+#else
-+ try_module_get(THIS_MODULE);
-+#endif
-+ return 0;
-+}
-+
-+static int zthfc_close(struct zt_chan *chan) {
-+ struct zt_hfc *zthfc = chan->pvt;
-+ struct hfc_card *hfctmp = zthfc->card;
-+
-+ if (!hfctmp) {
-+ return 0;
-+ }
-+
-+#ifndef LINUX26
-+ MOD_DEC_USE_COUNT;
-+#else
-+ module_put(THIS_MODULE);
-+#endif
-+ return 0;
-+}
-+
-+static int zthfc_rbsbits(struct zt_chan *chan, int bits) {
-+ return 0;
-+}
-+
-+static int zthfc_ioctl(struct zt_chan *chan, unsigned int cmd, unsigned long data) {
-+ switch(cmd) {
-+ default:
-+ return -ENOTTY;
-+ }
-+ return 0;
-+}
-+
-+static int zthfc_startup(struct zt_span *span) {
-+ struct zt_hfc *zthfc = span->pvt;
-+ struct hfc_card *hfctmp = zthfc->card;
-+ int alreadyrunning;
-+
-+ if (hfctmp == NULL) {
-+ printk(KERN_INFO "zaphfc: no card for span at startup!\n");
-+ }
-+ alreadyrunning = span->flags & ZT_FLAG_RUNNING;
-+
-+ if (!alreadyrunning) {
-+ span->chans[2].flags &= ~ZT_FLAG_HDLC;
-+ span->chans[2].flags |= ZT_FLAG_BRIDCHAN;
-+
-+ span->flags |= ZT_FLAG_RUNNING;
-+
-+ hfctmp->ticks = -2;
-+ hfctmp->clicks = 0;
-+ hfctmp->regs.fifo_en = hfc_FIFOEN_D | hfc_FIFOEN_B1 | hfc_FIFOEN_B2;
-+ hfc_outb(hfctmp, hfc_FIFO_EN, hfctmp->regs.fifo_en);
-+ } else {
-+ return 0;
-+ }
-+
-+ // drivers, start engines!
-+ hfc_outb(hfctmp, hfc_STATES, hfc_STATES_DO_ACTION | hfc_STATES_ACTIVATE);
-+ return 0;
-+}
-+
-+static int zthfc_shutdown(struct zt_span *span) {
-+ return 0;
-+}
-+
-+static int zthfc_maint(struct zt_span *span, int cmd) {
-+ return 0;
-+}
-+
-+static int zthfc_chanconfig(struct zt_chan *chan, int sigtype) {
-+// printk(KERN_CRIT "chan_config sigtype=%d\n", sigtype);
-+ return 0;
-+}
-+
-+static int zthfc_spanconfig(struct zt_span *span, struct zt_lineconfig *lc) {
-+ span->lineconfig = lc->lineconfig;
-+ return 0;
-+}
-+
-+static int zthfc_initialize(struct zt_hfc *zthfc) {
-+ struct hfc_card *hfctmp = zthfc->card;
-+ int i;
-+
-+ memset(&zthfc->span, 0x0, sizeof(struct zt_span)); // you never can tell...
-+
-+ sprintf(zthfc->span.name, "ZTHFC%d", hfc_dev_count + 1);
-+ if (hfctmp->regs.nt_mode == 1) {
-+#ifdef RTAITIMING
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [NT] [realtime]", hfc_dev_count + 1);
-+#else
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [NT]", hfc_dev_count + 1);
-+#endif
-+ } else {
-+#ifdef RTAITIMING
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [TE] [realtime]", hfc_dev_count + 1);
-+#else
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [TE]", hfc_dev_count + 1);
-+#endif
-+ }
-+
-+ zthfc->span.spanconfig = zthfc_spanconfig;
-+ zthfc->span.chanconfig = zthfc_chanconfig;
-+ zthfc->span.startup = zthfc_startup;
-+ zthfc->span.shutdown = zthfc_shutdown;
-+ zthfc->span.maint = zthfc_maint;
-+ zthfc->span.rbsbits = zthfc_rbsbits;
-+ zthfc->span.open = zthfc_open;
-+ zthfc->span.close = zthfc_close;
-+ zthfc->span.ioctl = zthfc_ioctl;
-+
-+ zthfc->span.chans = zthfc->chans;
-+ zthfc->span.channels = 3;
-+ zthfc->span.deflaw = ZT_LAW_ALAW;
-+ zthfc->span.linecompat = ZT_CONFIG_AMI | ZT_CONFIG_CCS; // <--- this is really BS
-+ zthfc->span.offset = 0;
-+ init_waitqueue_head(&zthfc->span.maintq);
-+ zthfc->span.pvt = zthfc;
-+
-+ for (i = 0; i < zthfc->span.channels; i++) {
-+ memset(&(zthfc->chans[i]), 0x0, sizeof(struct zt_chan));
-+ sprintf(zthfc->chans[i].name, "ZTHFC%d/%d/%d", hfc_dev_count + 1,0,i + 1);
-+ zthfc->chans[i].pvt = zthfc;
-+ zthfc->chans[i].sigcap = ZT_SIG_EM | ZT_SIG_CLEAR | ZT_SIG_FXSLS | ZT_SIG_FXSGS | ZT_SIG_FXSKS | ZT_SIG_FXOLS | ZT_SIG_FXOGS | ZT_SIG_FXOKS | ZT_SIG_CAS | ZT_SIG_SF;
-+ zthfc->chans[i].chanpos = i + 1;
-+ }
-+
-+ if (zt_register(&zthfc->span,0)) {
-+ printk(KERN_CRIT "unable to register zaptel device!\n");
-+ return -1;
-+ }
-+// printk(KERN_CRIT "zaphfc: registered zaptel device!\n");
-+ return 0;
-+}
-+
-+#ifdef RTAITIMING
-+#define TICK_PERIOD 1000000
-+#define TICK_PERIOD2 1000000000
-+#define TASK_PRIORITY 1
-+#define STACK_SIZE 10000
-+
-+static RT_TASK rt_task;
-+static struct hfc_card *rtai_hfc_list[hfc_MAX_CARDS];
-+static unsigned char rtai_hfc_counter = 0;
-+
-+static void rtai_register_hfc(struct hfc_card *hfctmp) {
-+ rtai_hfc_list[rtai_hfc_counter++] = hfctmp;
-+}
-+
-+static void rtai_loop(int t) {
-+ int i=0;
-+ for (;;) {
-+ for (i=0; i < rtai_hfc_counter; i++) {
-+ if (rtai_hfc_list[i] != NULL)
-+ hfc_service(rtai_hfc_list[i]);
-+ }
-+ rt_task_wait_period();
-+ }
-+}
-+#endif
-+
-+int hfc_findCards(int pcivendor, int pcidevice, char *vendor_name, char *card_name) {
-+ struct pci_dev *tmp;
-+ struct hfc_card *hfctmp = NULL;
-+ struct zt_hfc *zthfc = NULL;
-+
-+ tmp = pci_find_device(pcivendor, pcidevice, multi_hfc);
-+ while (tmp != NULL) {
-+ multi_hfc = tmp; // skip this next time.
-+
-+ if (pci_enable_device(tmp)) {
-+ multi_hfc = NULL;
-+ return -1;
-+ }
-+ pci_set_master(tmp);
-+
-+ hfctmp = kmalloc(sizeof(struct hfc_card), GFP_KERNEL);
-+ if (!hfctmp) {
-+ printk(KERN_WARNING "zaphfc: unable to kmalloc!\n");
-+ pci_disable_device(tmp);
-+ multi_hfc = NULL;
-+ return -ENOMEM;
-+ }
-+ memset(hfctmp, 0x0, sizeof(struct hfc_card));
-+ spin_lock_init(&hfctmp->lock);
-+
-+ hfctmp->pcidev = tmp;
-+ hfctmp->pcibus = tmp->bus->number;
-+ hfctmp->pcidevfn = tmp->devfn;
-+
-+ if (!tmp->irq) {
-+ printk(KERN_WARNING "zaphfc: no irq!\n");
-+ } else {
-+ hfctmp->irq = tmp->irq;
-+ }
-+
-+ hfctmp->pci_io = (char *) tmp->resource[1].start;
-+ if (!hfctmp->pci_io) {
-+ printk(KERN_WARNING "zaphfc: no iomem!\n");
-+ kfree(hfctmp);
-+ pci_disable_device(tmp);
-+ multi_hfc = NULL;
-+ return -1;
-+ }
-+
-+ hfctmp->fifomem = kmalloc(65536, GFP_KERNEL);
-+ if (!hfctmp->fifomem) {
-+ printk(KERN_WARNING "zaphfc: unable to kmalloc fifomem!\n");
-+ kfree(hfctmp);
-+ pci_disable_device(tmp);
-+ multi_hfc = NULL;
-+ return -ENOMEM;
-+ } else {
-+ memset(hfctmp->fifomem, 0x0, 65536);
-+ (ulong) hfctmp->fifos = (((ulong) hfctmp->fifomem) & ~0x7FFF) + 0x8000;
-+ pci_write_config_dword(hfctmp->pcidev, 0x80, (u_int) virt_to_bus(hfctmp->fifos));
-+ hfctmp->pci_io = ioremap((ulong) hfctmp->pci_io, 256);
-+ }
-+
-+#ifdef RTAITIMING
-+ /* we need no stinking irq */
-+ hfctmp->irq = 0;
-+#else
-+ if (request_irq(hfctmp->irq, &hfc_interrupt, SA_INTERRUPT | SA_SHIRQ, "zaphfc", hfctmp)) {
-+ printk(KERN_WARNING "zaphfc: unable to register irq\n");
-+ kfree(hfctmp->fifomem);
-+ kfree(hfctmp);
-+ iounmap((void *) hfctmp->pci_io);
-+ pci_disable_device(tmp);
-+ multi_hfc = NULL;
-+ return -EIO;
-+ }
-+#endif
-+
-+#ifdef RTAITIMING
-+ rtai_register_hfc(hfctmp);
-+#endif
-+ printk(KERN_INFO
-+ "zaphfc: %s %s configured at mem %#x fifo %#x(%#x) IRQ %d HZ %d\n",
-+ vendor_name, card_name,
-+ (u_int) hfctmp->pci_io,
-+ (u_int) hfctmp->fifos,
-+ (u_int) virt_to_bus(hfctmp->fifos),
-+ hfctmp->irq, HZ);
-+ pci_write_config_word(hfctmp->pcidev, PCI_COMMAND, PCI_COMMAND_MEMORY); // enable memio
-+ hfctmp->regs.int_m1 = 0; // no ints
-+ hfctmp->regs.int_m2 = 0; // not at all
-+ hfc_outb(hfctmp,hfc_INT_M1,hfctmp->regs.int_m1);
-+ hfc_outb(hfctmp,hfc_INT_M2,hfctmp->regs.int_m2);
-+
-+ if ((modes & (1 << hfc_dev_count)) != 0) {
-+ printk(KERN_INFO "zaphfc: Card %d configured for NT mode\n",hfc_dev_count);
-+ hfctmp->regs.nt_mode = 1;
-+ } else {
-+ printk(KERN_INFO "zaphfc: Card %d configured for TE mode\n",hfc_dev_count);
-+ hfctmp->regs.nt_mode = 0;
-+ }
-+
-+ zthfc = kmalloc(sizeof(struct zt_hfc),GFP_KERNEL);
-+ if (!zthfc) {
-+ printk(KERN_CRIT "zaphfc: unable to kmalloc!\n");
-+ hfc_shutdownCard(hfctmp);
-+ kfree(hfctmp);
-+ multi_hfc = NULL;
-+ return -ENOMEM;
-+ }
-+ memset(zthfc, 0x0, sizeof(struct zt_hfc));
-+
-+ zthfc->card = hfctmp;
-+ zthfc_initialize(zthfc);
-+ hfctmp->ztdev = zthfc;
-+
-+ memset(hfctmp->drecbuf, 0x0, sizeof(hfctmp->drecbuf));
-+ hfctmp->ztdev->chans[2].readchunk = hfctmp->drecbuf;
-+
-+ memset(hfctmp->dtransbuf, 0x0, sizeof(hfctmp->dtransbuf));
-+ hfctmp->ztdev->chans[2].writechunk = hfctmp->dtransbuf;
-+
-+ memset(hfctmp->brecbuf[0], 0x0, sizeof(hfctmp->brecbuf[0]));
-+ hfctmp->ztdev->chans[0].readchunk = hfctmp->brecbuf[0];
-+ memset(hfctmp->btransbuf[0], 0x0, sizeof(hfctmp->btransbuf[0]));
-+ hfctmp->ztdev->chans[0].writechunk = hfctmp->btransbuf[0];
-+
-+ memset(hfctmp->brecbuf[1], 0x0, sizeof(hfctmp->brecbuf[1]));
-+ hfctmp->ztdev->chans[1].readchunk = hfctmp->brecbuf[1];
-+ memset(hfctmp->btransbuf[1], 0x0, sizeof(hfctmp->btransbuf[1]));
-+ hfctmp->ztdev->chans[1].writechunk = hfctmp->btransbuf[1];
-+
-+
-+ hfc_registerCard(hfctmp);
-+ hfc_resetCard(hfctmp);
-+ tmp = pci_find_device(pcivendor, pcidevice, multi_hfc);
-+ }
-+ return 0;
-+}
-+
-+
-+
-+int init_module(void) {
-+ int i = 0;
-+#ifdef RTAITIMING
-+ RTIME tick_period;
-+ for (i=0; i < hfc_MAX_CARDS; i++) {
-+ rtai_hfc_list[i] = NULL;
-+ }
-+ rt_set_periodic_mode();
-+#endif
-+ i = 0;
-+ while (id_list[i].vendor_id) {
-+ multi_hfc = NULL;
-+ hfc_findCards(id_list[i].vendor_id, id_list[i].device_id, id_list[i].vendor_name, id_list[i].card_name);
-+ i++;
-+ }
-+#ifdef RTAITIMING
-+ for (i=0; i < hfc_MAX_CARDS; i++) {
-+ if (rtai_hfc_list[i]) {
-+ printk(KERN_INFO
-+ "zaphfc: configured %d at mem %#x fifo %#x(%#x) for realtime servicing\n",
-+ rtai_hfc_list[i]->cardno,
-+ (u_int) rtai_hfc_list[i]->pci_io,
-+ (u_int) rtai_hfc_list[i]->fifos,
-+ (u_int) virt_to_bus(rtai_hfc_list[i]->fifos));
-+
-+ }
-+ }
-+ rt_task_init(&rt_task, rtai_loop, 1, STACK_SIZE, TASK_PRIORITY, 0, 0);
-+ tick_period = start_rt_timer(nano2count(TICK_PERIOD));
-+ rt_task_make_periodic(&rt_task, rt_get_time() + tick_period, tick_period);
-+#endif
-+ printk(KERN_INFO "zaphfc: %d hfc-pci card(s) in this box.\n", hfc_dev_count);
-+ return 0;
-+}
-+
-+void cleanup_module(void) {
-+ struct hfc_card *tmpcard;
-+#ifdef RTAITIMING
-+ stop_rt_timer();
-+ rt_task_delete(&rt_task);
-+#endif
-+ printk(KERN_INFO "zaphfc: stop\n");
-+// spin_lock(®isterlock);
-+ while (hfc_dev_list != NULL) {
-+ if (hfc_dev_list == NULL) break;
-+ hfc_shutdownCard(hfc_dev_list);
-+ tmpcard = hfc_dev_list;
-+ hfc_dev_list = hfc_dev_list->next;
-+ if (tmpcard != NULL) {
-+ kfree(tmpcard);
-+ tmpcard = NULL;
-+ printk(KERN_INFO "zaphfc: freed one card.\n");
-+ }
-+ }
-+// spin_unlock(®isterlock);
-+}
-+#endif
-+
-+
-+MODULE_DESCRIPTION("HFC-S PCI A Zaptel Driver");
-+MODULE_AUTHOR("Klaus-Peter Junghanns <kpj at junghanns.net>");
-+#ifdef MODULE_LICENSE
-+MODULE_LICENSE("GPL");
-+#endif
-+MODULE_PARM(modes,"i");
-+MODULE_PARM(debug,"i");
-diff -urNad zaptel-1.0.9/zaphfc/zaphfc.h /tmp/dpep.gzWFVh/zaptel-1.0.9/zaphfc/zaphfc.h
---- zaptel-1.0.9/zaphfc/zaphfc.h 1969-12-31 19:00:00.000000000 -0500
-+++ /tmp/dpep.gzWFVh/zaptel-1.0.9/zaphfc/zaphfc.h 2005-02-26 17:30:32.000000000 -0500
-@@ -0,0 +1,289 @@
-+/*
-+ * zaphfc.h - Zaptel driver for HFC-S PCI A based ISDN BRI cards
-+ *
-+ * kernel module based on HFC PCI ISDN4Linux and Zaptel drivers
-+ *
-+ * Copyright (C) 2002, 2003, 2004, 2005 Junghanns.NET GmbH
-+ *
-+ * Klaus-Peter Junghanns <kpj at junghanns.net>
-+ *
-+ * This program is free software and may be modified and
-+ * distributed under the terms of the GNU Public License.
-+ *
-+ */
-+
-+/* HFC register addresses - accessed using memory mapped I/O */
-+/* For a list, see datasheet section 3.2.1 at page 21 */
-+
-+#define hfc_outb(a,b,c) (writeb((c),(a)->pci_io+(b)))
-+#define hfc_inb(a,b) (readb((a)->pci_io+(b)))
-+
-+/* GCI/IOM bus monitor registers */
-+
-+#define hfc_C_I 0x08
-+#define hfc_TRxR 0x0C
-+#define hfc_MON1_D 0x28
-+#define hfc_MON2_D 0x2C
-+
-+
-+/* GCI/IOM bus timeslot registers */
-+
-+#define hfc_B1_SSL 0x80
-+#define hfc_B2_SSL 0x84
-+#define hfc_AUX1_SSL 0x88
-+#define hfc_AUX2_SSL 0x8C
-+#define hfc_B1_RSL 0x90
-+#define hfc_B2_RSL 0x94
-+#define hfc_AUX1_RSL 0x98
-+#define hfc_AUX2_RSL 0x9C
-+
-+/* GCI/IOM bus data registers */
-+
-+#define hfc_B1_D 0xA0
-+#define hfc_B2_D 0xA4
-+#define hfc_AUX1_D 0xA8
-+#define hfc_AUX2_D 0xAC
-+
-+/* GCI/IOM bus configuration registers */
-+
-+#define hfc_MST_EMOD 0xB4
-+#define hfc_MST_MODE 0xB8
-+#define hfc_CONNECT 0xBC
-+
-+
-+/* Interrupt and status registers */
-+
-+#define hfc_FIFO_EN 0x44
-+#define hfc_TRM 0x48
-+#define hfc_B_MODE 0x4C
-+#define hfc_CHIP_ID 0x58
-+#define hfc_CIRM 0x60
-+#define hfc_CTMT 0x64
-+#define hfc_INT_M1 0x68
-+#define hfc_INT_M2 0x6C
-+#define hfc_INT_S1 0x78
-+#define hfc_INT_S2 0x7C
-+#define hfc_STATUS 0x70
-+
-+/* S/T section registers */
-+
-+#define hfc_STATES 0xC0
-+#define hfc_SCTRL 0xC4
-+#define hfc_SCTRL_E 0xC8
-+#define hfc_SCTRL_R 0xCC
-+#define hfc_SQ 0xD0
-+#define hfc_CLKDEL 0xDC
-+#define hfc_B1_REC 0xF0
-+#define hfc_B1_SEND 0xF0
-+#define hfc_B2_REC 0xF4
-+#define hfc_B2_SEND 0xF4
-+#define hfc_D_REC 0xF8
-+#define hfc_D_SEND 0xF8
-+#define hfc_E_REC 0xFC
-+
-+/* Bits and values in various HFC PCI registers */
-+
-+/* bits in status register (READ) */
-+#define hfc_STATUS_PCI_PROC 0x02
-+#define hfc_STATUS_NBUSY 0x04
-+#define hfc_STATUS_TIMER_ELAP 0x10
-+#define hfc_STATUS_STATINT 0x20
-+#define hfc_STATUS_FRAMEINT 0x40
-+#define hfc_STATUS_ANYINT 0x80
-+
-+/* bits in CTMT (Write) */
-+#define hfc_CTMT_CLTIMER 0x80
-+#define hfc_CTMT_TIM3_125 0x04
-+#define hfc_CTMT_TIM25 0x10
-+#define hfc_CTMT_TIM50 0x14
-+#define hfc_CTMT_TIM400 0x18
-+#define hfc_CTMT_TIM800 0x1C
-+#define hfc_CTMT_AUTO_TIMER 0x20
-+#define hfc_CTMT_TRANSB2 0x02
-+#define hfc_CTMT_TRANSB1 0x01
-+
-+/* bits in CIRM (Write) */
-+#define hfc_CIRM_AUX_MSK 0x07
-+#define hfc_CIRM_RESET 0x08
-+#define hfc_CIRM_B1_REV 0x40
-+#define hfc_CIRM_B2_REV 0x80
-+
-+/* bits in INT_M1 and INT_S1 */
-+#define hfc_INTS_B1TRANS 0x01
-+#define hfc_INTS_B2TRANS 0x02
-+#define hfc_INTS_DTRANS 0x04
-+#define hfc_INTS_B1REC 0x08
-+#define hfc_INTS_B2REC 0x10
-+#define hfc_INTS_DREC 0x20
-+#define hfc_INTS_L1STATE 0x40
-+#define hfc_INTS_TIMER 0x80
-+
-+/* bits in INT_M2 */
-+#define hfc_M2_PROC_TRANS 0x01
-+#define hfc_M2_GCI_I_CHG 0x02
-+#define hfc_M2_GCI_MON_REC 0x04
-+#define hfc_M2_IRQ_ENABLE 0x08
-+#define hfc_M2_PMESEL 0x80
-+
-+/* bits in STATES */
-+#define hfc_STATES_STATE_MASK 0x0F
-+#define hfc_STATES_LOAD_STATE 0x10
-+#define hfc_STATES_ACTIVATE 0x20
-+#define hfc_STATES_DO_ACTION 0x40
-+#define hfc_STATES_NT_G2_G3 0x80
-+
-+/* bits in HFCD_MST_MODE */
-+#define hfc_MST_MODE_MASTER 0x01
-+#define hfc_MST_MODE_SLAVE 0x00
-+/* remaining bits are for codecs control */
-+
-+/* bits in HFCD_SCTRL */
-+#define hfc_SCTRL_B1_ENA 0x01
-+#define hfc_SCTRL_B2_ENA 0x02
-+#define hfc_SCTRL_MODE_TE 0x00
-+#define hfc_SCTRL_MODE_NT 0x04
-+#define hfc_SCTRL_LOW_PRIO 0x08
-+#define hfc_SCTRL_SQ_ENA 0x10
-+#define hfc_SCTRL_TEST 0x20
-+#define hfc_SCTRL_NONE_CAP 0x40
-+#define hfc_SCTRL_PWR_DOWN 0x80
-+
-+/* bits in SCTRL_E */
-+#define hfc_SCTRL_E_AUTO_AWAKE 0x01
-+#define hfc_SCTRL_E_DBIT_1 0x04
-+#define hfc_SCTRL_E_IGNORE_COL 0x08
-+#define hfc_SCTRL_E_CHG_B1_B2 0x80
-+
-+/* bits in FIFO_EN register */
-+#define hfc_FIFOEN_B1TX 0x01
-+#define hfc_FIFOEN_B1RX 0x02
-+#define hfc_FIFOEN_B2TX 0x04
-+#define hfc_FIFOEN_B2RX 0x08
-+#define hfc_FIFOEN_DTX 0x10
-+#define hfc_FIFOEN_DRX 0x20
-+
-+#define hfc_FIFOEN_B1 (hfc_FIFOEN_B1TX|hfc_FIFOEN_B1RX)
-+#define hfc_FIFOEN_B2 (hfc_FIFOEN_B2TX|hfc_FIFOEN_B2RX)
-+#define hfc_FIFOEN_D (hfc_FIFOEN_DTX|hfc_FIFOEN_DRX)
-+
-+/* bits in the CONNECT register */
-+#define hfc_CONNECT_B1_shift 0
-+#define hfc_CONNECT_B2_shift 3
-+
-+#define hfc_CONNECT_HFC_from_ST 0x0
-+#define hfc_CONNECT_HFC_from_GCI 0x1
-+#define hfc_CONNECT_ST_from_HFC 0x0
-+#define hfc_CONNECT_ST_from_GCI 0x2
-+#define hfc_CONNECT_GCI_from_HFC 0x0
-+#define hfc_CONNECT_GCI_from_ST 0x4
-+
-+/* bits in the __SSL and __RSL registers */
-+#define hfc_SRSL_STIO 0x40
-+#define hfc_SRSL_ENABLE 0x80
-+#define hfc_SRCL_SLOT_MASK 0x1f
-+
-+/* FIFO memory definitions */
-+
-+#define hfc_FMASK 0x000f
-+#define hfc_ZMASK 0x01ff
-+#define hfc_ZMASKB 0x1fff
-+
-+#define hfc_D_FIFO_SIZE 0x0200
-+#define hfc_B_SUB_VAL 0x0200
-+#define hfc_B_FIFO_SIZE 0x1E00
-+#define hfc_MAX_DFRAMES 0x000f
-+
-+#define hfc_FIFO_DTX_Z1 0x2080
-+#define hfc_FIFO_DTX_Z2 0x2082
-+#define hfc_FIFO_DTX_F1 0x20a0
-+#define hfc_FIFO_DTX_F2 0x20a1
-+#define hfc_FIFO_DTX 0x0000
-+#define hfc_FIFO_DTX_ZOFF 0x000
-+
-+#define hfc_FIFO_DRX_Z1 0x6080
-+#define hfc_FIFO_DRX_Z2 0x6082
-+#define hfc_FIFO_DRX_F1 0x60a0
-+#define hfc_FIFO_DRX_F2 0x60a1
-+#define hfc_FIFO_DRX 0x4000
-+#define hfc_FIFO_DRX_ZOFF 0x4000
-+
-+#define hfc_FIFO_B1TX_Z1 0x2000
-+#define hfc_FIFO_B1TX_Z2 0x2002
-+#define hfc_FIFO_B1RX_Z1 0x6000
-+#define hfc_FIFO_B1RX_Z2 0x6002
-+
-+#define hfc_FIFO_B1TX_F1 0x2080
-+#define hfc_FIFO_B1TX_F2 0x2081
-+#define hfc_FIFO_B1RX_F1 0x6080
-+#define hfc_FIFO_B1RX_F2 0x6081
-+
-+#define hfc_FIFO_B1RX_ZOFF 0x4000
-+#define hfc_FIFO_B1TX_ZOFF 0x0000
-+
-+#define hfc_FIFO_B2TX_Z1 0x2100
-+#define hfc_FIFO_B2TX_Z2 0x2102
-+#define hfc_FIFO_B2RX_Z1 0x6100
-+#define hfc_FIFO_B2RX_Z2 0x6102
-+
-+#define hfc_FIFO_B2TX_F1 0x2180
-+#define hfc_FIFO_B2TX_F2 0x2181
-+#define hfc_FIFO_B2RX_F1 0x6180
-+#define hfc_FIFO_B2RX_F2 0x6181
-+
-+#define hfc_FIFO_B2RX_ZOFF 0x6000
-+#define hfc_FIFO_B2TX_ZOFF 0x2000
-+
-+#define hfc_BTRANS_THRESHOLD 128
-+#define hfc_BTRANS_THRESMASK 0x00
-+
-+/* Structures */
-+
-+typedef struct hfc_regs {
-+ unsigned char fifo_en;
-+ unsigned char ctmt;
-+ unsigned char int_m1;
-+ unsigned char int_m2;
-+ unsigned char sctrl;
-+ unsigned char sctrl_e;
-+ unsigned char sctrl_r;
-+ unsigned char connect;
-+ unsigned char trm;
-+ unsigned char mst_mode;
-+ unsigned char bswapped;
-+ unsigned char nt_mode;
-+ unsigned char int_drec;
-+} hfc_regs;
-+
-+typedef struct hfc_card {
-+ spinlock_t lock;
-+ unsigned int irq;
-+ unsigned int iomem;
-+ int ticks;
-+ int clicks;
-+ unsigned char *pci_io;
-+ void *fifomem; // start of the shared mem
-+ volatile void *fifos; // 32k aligned mem for the fifos
-+ struct hfc_regs regs;
-+ unsigned int pcibus;
-+ unsigned int pcidevfn;
-+ struct pci_dev *pcidev;
-+ struct zt_hfc *ztdev;
-+ int drecinframe;
-+ unsigned char drecbuf[hfc_D_FIFO_SIZE];
-+ unsigned char dtransbuf[hfc_D_FIFO_SIZE];
-+ unsigned char brecbuf[2][ZT_CHUNKSIZE];
-+ unsigned char btransbuf[2][ZT_CHUNKSIZE];
-+ unsigned char cardno;
-+ struct hfc_card *next;
-+} hfc_card;
-+
-+typedef struct zt_hfc {
-+ unsigned int usecount;
-+ struct zt_span span;
-+ struct zt_chan chans[3];
-+ struct hfc_card *card;
-+} zt_hfc;
-+
-+/* tune this */
-+#define hfc_BCHAN_BUFFER 8
-+#define hfc_MAX_CARDS 8
-diff -urNad zaptel-1.0.9/zaphfc/zaptel.conf /tmp/dpep.gzWFVh/zaptel-1.0.9/zaphfc/zaptel.conf
---- zaptel-1.0.9/zaphfc/zaptel.conf 1969-12-31 19:00:00.000000000 -0500
-+++ /tmp/dpep.gzWFVh/zaptel-1.0.9/zaphfc/zaptel.conf 2004-03-24 09:35:12.000000000 -0500
-@@ -0,0 +1,8 @@
-+# hfc-s pci a span definition
-+# most of the values should be bogus because we are not really zaptel
-+loadzone=nl
-+defaultzone=nl
-+
-+span=1,1,3,ccs,ami
-+bchan=1-2
-+dchan=3
-diff -urNad zaptel-1.0.9/zaptel.c /tmp/dpep.gzWFVh/zaptel-1.0.9/zaptel.c
---- zaptel-1.0.9/zaptel.c 2005-06-15 16:31:22.000000000 -0500
-+++ /tmp/dpep.gzWFVh/zaptel-1.0.9/zaptel.c 2005-07-30 01:09:25.000000000 -0500
-@@ -4851,11 +4851,40 @@
- *(txb++) = fasthdlc_tx_run_nocheck(&ms->txhdlc);
- }
- bytes -= left;
-+#ifdef CONFIG_ZAPATA_BRI_DCHANS
-+ } else if (ms->flags & ZT_FLAG_BRIDCHAN) {
-+ /*
-+ * Let's get this right, we want to transmit complete frames only.
-+ * The card driver will do the dirty HDLC work for us.
-+ * txb (transmit buffer) is supposed to be big enough to store one frame
-+ * we will make this as big as the D fifo (1KB or 2KB)
-+ */
-+
-+ /* there are 'left' bytes in the user buffer left to transmit */
-+ left = ms->writen[ms->outwritebuf] - ms->writeidx[ms->outwritebuf] - 2;
-+ if (left > ms->maxbytes2transmit) {
-+ memcpy(txb, buf + ms->writeidx[ms->outwritebuf], ms->maxbytes2transmit);
-+ ms->writeidx[ms->outwritebuf] += ms->maxbytes2transmit;
-+ txb += ms->maxbytes2transmit;
-+ ms->bytes2transmit = ms->maxbytes2transmit;
-+ ms->eoftx = 0;
-+ } else {
-+ memcpy(txb, buf + ms->writeidx[ms->outwritebuf], left);
-+ ms->writeidx[ms->outwritebuf] += left + 2;
-+ txb += left;
-+ ms->bytes2transmit = left;
-+ ms->eoftx = 1;
-+ }
-+ bytes = 0;
-+#endif
- } else {
- memcpy(txb, buf + ms->writeidx[ms->outwritebuf], left);
- ms->writeidx[ms->outwritebuf]+=left;
- txb += left;
- bytes -= left;
-+#if defined(CONFIG_ZAPATA_BRI_DCHANS)
-+ ms->bytes2transmit=ZT_CHUNKSIZE;
-+#endif
- }
- /* Check buffer status */
- if (ms->writeidx[ms->outwritebuf] >= ms->writen[ms->outwritebuf]) {
-@@ -4900,6 +4929,17 @@
- /* Transmit a flag if this is an HDLC channel */
- if (ms->flags & ZT_FLAG_HDLC)
- fasthdlc_tx_frame_nocheck(&ms->txhdlc);
-+#if defined(CONFIG_ZAPATA_BRI_DCHANS)
-+ if(ms->flags & ZT_FLAG_BRIDCHAN) {
-+ // if (ms->bytes2transmit > 0) {
-+ // txb += 2;
-+ // ms->bytes2transmit -= 2;
-+ bytes=0;
-+ ms->eoftx = 1;
-+// printk(KERN_CRIT "zaptel EOF(%d) bytes2transmit %d\n",ms->eoftx,ms->bytes2transmit);
-+ // }
-+ }
-+#endif
- #ifdef CONFIG_ZAPATA_NET
- if (ms->flags & ZT_FLAG_NETDEV)
- netif_wake_queue(ztchan_to_dev(ms));
-@@ -4910,7 +4950,7 @@
- tasklet_schedule(&ms->ppp_calls);
- }
- #endif
-- }
-+ }
- } else if (ms->curtone && !(ms->flags & ZT_FLAG_PSEUDO)) {
- left = ms->curtone->tonesamples - ms->tonep;
- if (left > bytes)
-@@ -4948,8 +4988,17 @@
- } else if (ms->flags & ZT_FLAG_CLEAR) {
- /* Clear channels should idle with 0xff for the sake
- of silly PRI's that care about idle B channels */
-+#if defined(CONFIG_ZAPATA_BRI_DCHANS)
-+ // ms->bytes2transmit=0;
-+#endif
- memset(txb, 0xff, bytes);
- bytes = 0;
-+#if defined(CONFIG_ZAPATA_BRI_DCHANS)
-+ } else if(ms->flags & ZT_FLAG_BRIDCHAN) {
-+ // ms->bytes2transmit = ZT_CHUNKSIZE - bytes;
-+ bytes = 0;
-+ if (ms->bytes2transmit > 0) printk(KERN_CRIT "bytes2transmit %d\n",ms->bytes2transmit);
-+#endif
- } else {
- memset(txb, ZT_LIN2X(0, ms), bytes); /* Lastly we use silence on telephony channels */
- bytes = 0;
-@@ -5648,6 +5697,13 @@
- int left, x;
-
- int bytes = ZT_CHUNKSIZE;
-+#if defined(CONFIG_ZAPATA_BRI_DCHANS)
-+ if (ms->flags & ZT_FLAG_BRIDCHAN) {
-+ bytes = ms->bytes2receive;
-+ if (bytes < 1) return;
-+// printk(KERN_CRIT "bytes2receive %d\n",ms->bytes2receive);
-+ }
-+#endif
-
- while(bytes) {
- #if defined(CONFIG_ZAPATA_NET) || defined(CONFIG_ZAPATA_PPP)
-@@ -5706,6 +5762,19 @@
- }
- }
- }
-+#ifdef CONFIG_ZAPATA_BRI_DCHANS
-+ } else if (ms->flags & ZT_FLAG_BRIDCHAN) {
-+ memcpy(buf + ms->readidx[ms->inreadbuf], rxb, left);
-+ rxb += left;
-+ ms->readidx[ms->inreadbuf] += left;
-+ bytes -= left;
-+ if (ms->eofrx == 1) {
-+ eof=1;
-+ }
-+// printk(KERN_CRIT "receiving %d bytes\n",ms->bytes2receive);
-+ ms->bytes2receive = 0;
-+ ms->eofrx = 0;
-+#endif
- } else {
- /* Not HDLC */
- memcpy(buf + ms->readidx[ms->inreadbuf], rxb, left);
-diff -urNad zaptel-1.0.9/zaptel.h /tmp/dpep.gzWFVh/zaptel-1.0.9/zaptel.h
---- zaptel-1.0.9/zaptel.h 2005-06-15 16:31:22.000000000 -0500
-+++ /tmp/dpep.gzWFVh/zaptel-1.0.9/zaptel.h 2005-07-30 01:09:25.000000000 -0500
-@@ -956,6 +956,13 @@
- int do_ppp_error;
- struct sk_buff_head ppp_rq;
- #endif
-+#ifdef CONFIG_ZAPATA_BRI_DCHANS
-+ int bytes2receive;
-+ int maxbytes2transmit; /* size of the tx buffer in the card driver */
-+ int bytes2transmit;
-+ int eofrx;
-+ int eoftx;
-+#endif
- spinlock_t lock;
- char name[40]; /* Name */
- /* Specified by zaptel */
-@@ -1030,7 +1037,7 @@
- int txbufpolicy; /* Buffer policy */
- int rxbufpolicy; /* Buffer policy */
- int txdisable; /* Disable transmitter */
-- int rxdisable; /* Disable receiver */
-+ int rxdisable; /* Disable receiver */
-
-
- /* Tone zone stuff */
-@@ -1193,6 +1200,10 @@
- #define ZT_FLAG_T1PPP (1 << 15)
- #define ZT_FLAG_SIGFREEZE (1 << 16) /* Freeze signalling */
-
-+#if defined(CONFIG_ZAPATA_BRI_DCHANS)
-+#define ZT_FLAG_BRIDCHAN (1 << 17)
-+#endif
-+
- struct zt_span {
- spinlock_t lock;
- void *pvt; /* Private stuff */
-diff -urNad zaptel-1.0.9/zconfig.h /tmp/dpep.gzWFVh/zaptel-1.0.9/zconfig.h
---- zaptel-1.0.9/zconfig.h 2005-01-01 19:19:57.000000000 -0500
-+++ /tmp/dpep.gzWFVh/zaptel-1.0.9/zconfig.h 2005-07-30 01:09:25.000000000 -0500
-@@ -127,4 +127,10 @@
- */
- /* #define TDM_REVH_MATCHALL */
-
-+/*
-+ * Uncomment the following for BRI D channels
-+ *
-+ */
-+#define CONFIG_ZAPATA_BRI_DCHANS
-+
- #endif
Deleted: zaptel/trunk/debian/patches/bristuff-0.3.0-PRE1.dpatch
===================================================================
--- zaptel/trunk/debian/patches/bristuff-0.3.0-PRE1.dpatch 2006-04-30 15:19:14 UTC (rev 1655)
+++ zaptel/trunk/debian/patches/bristuff-0.3.0-PRE1.dpatch 2006-04-30 16:30:35 UTC (rev 1656)
@@ -1,173 +0,0 @@
-#! /bin/sh /usr/share/dpatch/dpatch-run
-## bristuff.dpatch imported by Kilian Krause <kilian at debian.org>
-##
-## All lines beginning with `## DP:' are a description of the patch.
-## DP: Import bristuff 0.3.0-PRE1 for Asterisk 1.2.0 support
- at DPATCH@
-diff -urN zaptel-1.2.0.orig/zaptel.c zaptel-1.2.0/zaptel.c
---- zaptel-1.2.0.orig/zaptel.c 2005-11-11 21:48:43.000000000 +0100
-+++ zaptel-1.2.0/zaptel.c 2005-11-20 11:57:22.000000000 +0100
-@@ -4901,11 +4901,40 @@
- *(txb++) = fasthdlc_tx_run_nocheck(&ms->txhdlc);
- }
- bytes -= left;
-+#ifdef CONFIG_ZAPATA_BRI_DCHANS
-+ } else if (ms->flags & ZT_FLAG_BRIDCHAN) {
-+ /*
-+ * Let's get this right, we want to transmit complete frames only.
-+ * The card driver will do the dirty HDLC work for us.
-+ * txb (transmit buffer) is supposed to be big enough to store one frame
-+ * we will make this as big as the D fifo (1KB or 2KB)
-+ */
-+
-+ /* there are 'left' bytes in the user buffer left to transmit */
-+ left = ms->writen[ms->outwritebuf] - ms->writeidx[ms->outwritebuf] - 2;
-+ if (left > ms->maxbytes2transmit) {
-+ memcpy(txb, buf + ms->writeidx[ms->outwritebuf], ms->maxbytes2transmit);
-+ ms->writeidx[ms->outwritebuf] += ms->maxbytes2transmit;
-+ txb += ms->maxbytes2transmit;
-+ ms->bytes2transmit = ms->maxbytes2transmit;
-+ ms->eoftx = 0;
-+ } else {
-+ memcpy(txb, buf + ms->writeidx[ms->outwritebuf], left);
-+ ms->writeidx[ms->outwritebuf] += left + 2;
-+ txb += left;
-+ ms->bytes2transmit = left;
-+ ms->eoftx = 1;
-+ }
-+ bytes = 0;
-+#endif
- } else {
- memcpy(txb, buf + ms->writeidx[ms->outwritebuf], left);
- ms->writeidx[ms->outwritebuf]+=left;
- txb += left;
- bytes -= left;
-+#if defined(CONFIG_ZAPATA_BRI_DCHANS)
-+ ms->bytes2transmit=ZT_CHUNKSIZE;
-+#endif
- }
- /* Check buffer status */
- if (ms->writeidx[ms->outwritebuf] >= ms->writen[ms->outwritebuf]) {
-@@ -4950,6 +4979,17 @@
- /* Transmit a flag if this is an HDLC channel */
- if (ms->flags & ZT_FLAG_HDLC)
- fasthdlc_tx_frame_nocheck(&ms->txhdlc);
-+#if defined(CONFIG_ZAPATA_BRI_DCHANS)
-+ if(ms->flags & ZT_FLAG_BRIDCHAN) {
-+ // if (ms->bytes2transmit > 0) {
-+ // txb += 2;
-+ // ms->bytes2transmit -= 2;
-+ bytes=0;
-+ ms->eoftx = 1;
-+// printk(KERN_CRIT "zaptel EOF(%d) bytes2transmit %d\n",ms->eoftx,ms->bytes2transmit);
-+ // }
-+ }
-+#endif
- #ifdef CONFIG_ZAPATA_NET
- if (ms->flags & ZT_FLAG_NETDEV)
- netif_wake_queue(ztchan_to_dev(ms));
-@@ -4960,7 +5000,7 @@
- tasklet_schedule(&ms->ppp_calls);
- }
- #endif
-- }
-+ }
- } else if (ms->curtone && !(ms->flags & ZT_FLAG_PSEUDO)) {
- left = ms->curtone->tonesamples - ms->tonep;
- if (left > bytes)
-@@ -5006,6 +5046,10 @@
- memset(txb, 0xFF, bytes);
- }
- bytes = 0;
-+#if defined(CONFIG_ZAPATA_BRI_DCHANS)
-+ } else if(ms->flags & ZT_FLAG_BRIDCHAN) {
-+ bytes = 0;
-+#endif
- } else {
- memset(txb, ZT_LIN2X(0, ms), bytes); /* Lastly we use silence on telephony channels */
- bytes = 0;
-@@ -5731,6 +5775,13 @@
- int left, x;
-
- int bytes = ZT_CHUNKSIZE;
-+#if defined(CONFIG_ZAPATA_BRI_DCHANS)
-+ if (ms->flags & ZT_FLAG_BRIDCHAN) {
-+ bytes = ms->bytes2receive;
-+ if (bytes < 1) return;
-+// printk(KERN_CRIT "bytes2receive %d\n",ms->bytes2receive);
-+ }
-+#endif
-
- while(bytes) {
- #if defined(CONFIG_ZAPATA_NET) || defined(CONFIG_ZAPATA_PPP)
-@@ -5789,6 +5840,19 @@
- }
- }
- }
-+#ifdef CONFIG_ZAPATA_BRI_DCHANS
-+ } else if (ms->flags & ZT_FLAG_BRIDCHAN) {
-+ memcpy(buf + ms->readidx[ms->inreadbuf], rxb, left);
-+ rxb += left;
-+ ms->readidx[ms->inreadbuf] += left;
-+ bytes -= left;
-+ if (ms->eofrx == 1) {
-+ eof=1;
-+ }
-+// printk(KERN_CRIT "receiving %d bytes\n",ms->bytes2receive);
-+ ms->bytes2receive = 0;
-+ ms->eofrx = 0;
-+#endif
- } else {
- /* Not HDLC */
- memcpy(buf + ms->readidx[ms->inreadbuf], rxb, left);
-diff -urN zaptel-1.2.0.orig/zaptel.h zaptel-1.2.0/zaptel.h
---- zaptel-1.2.0.orig/zaptel.h 2005-10-27 18:05:07.000000000 +0200
-+++ zaptel-1.2.0/zaptel.h 2005-11-20 11:52:31.000000000 +0100
-@@ -981,6 +981,13 @@
- int do_ppp_error;
- struct sk_buff_head ppp_rq;
- #endif
-+#ifdef CONFIG_ZAPATA_BRI_DCHANS
-+ int bytes2receive;
-+ int maxbytes2transmit; /* size of the tx buffer in the card driver */
-+ int bytes2transmit;
-+ int eofrx;
-+ int eoftx;
-+#endif
- spinlock_t lock;
- char name[40]; /* Name */
- /* Specified by zaptel */
-@@ -1055,7 +1062,7 @@
- int txbufpolicy; /* Buffer policy */
- int rxbufpolicy; /* Buffer policy */
- int txdisable; /* Disable transmitter */
-- int rxdisable; /* Disable receiver */
-+ int rxdisable; /* Disable receiver */
-
-
- /* Tone zone stuff */
-@@ -1218,6 +1225,10 @@
- #define ZT_FLAG_T1PPP (1 << 15)
- #define ZT_FLAG_SIGFREEZE (1 << 16) /* Freeze signalling */
-
-+#if defined(CONFIG_ZAPATA_BRI_DCHANS)
-+#define ZT_FLAG_BRIDCHAN (1 << 17)
-+#endif
-+
- struct zt_span {
- spinlock_t lock;
- void *pvt; /* Private stuff */
-diff -urN zaptel-1.2.0.orig/zconfig.h zaptel-1.2.0/zconfig.h
---- zaptel-1.2.0.orig/zconfig.h 2005-10-27 18:05:07.000000000 +0200
-+++ zaptel-1.2.0/zconfig.h 2005-11-20 11:52:31.000000000 +0100
-@@ -152,4 +152,10 @@
- */
- /* #define FXSFLASH */
-
-+/*
-+ * Uncomment the following for BRI D channels
-+ *
-+ */
-+#define CONFIG_ZAPATA_BRI_DCHANS
-+
- #endif
Deleted: zaptel/trunk/debian/patches/bristuff-0.3.0-PRE1d.dpatch
===================================================================
--- zaptel/trunk/debian/patches/bristuff-0.3.0-PRE1d.dpatch 2006-04-30 15:19:14 UTC (rev 1655)
+++ zaptel/trunk/debian/patches/bristuff-0.3.0-PRE1d.dpatch 2006-04-30 16:30:35 UTC (rev 1656)
@@ -1,6687 +0,0 @@
-#! /bin/sh /usr/share/dpatch/dpatch-run
-## bristuff-0.3.0-PRE1d.dpatch by Tzafrir Cohen <tzafrir.cohen at xorcom.com>
-##
-## All lines beginning with `## DP:' are a description of the patch.
-## DP: The zapbri modules (cwain, qozap, zaphfc) and zaptel patch from the
-## DP: bristuff patch by Klaus-Peter Junghanns. Version 0.3.0-PRE1d
-
- at DPATCH@
-diff -urNad zaptel-1.2.1/cwain/cwain.c /tmp/dpep.LWjGif/zaptel-1.2.1/cwain/cwain.c
---- zaptel-1.2.1/cwain/cwain.c 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.LWjGif/zaptel-1.2.1/cwain/cwain.c 2005-10-11 17:36:14.000000000 +0200
-@@ -0,0 +1,1489 @@
-+/*
-+ * cwain.c - Zaptel driver for the Junghanns.NET E1 card
-+ *
-+ * c.w.a.i.n. == card without an interesting name
-+ *
-+ * single/double E1 board
-+ *
-+ * Copyright (C) 2004, 2005 Junghanns.NET GmbH
-+ *
-+ * Klaus-Peter Junghanns <kpj at junghanns.net>
-+ *
-+ * This program is free software and may be modified and
-+ * distributed under the terms of the GNU Public License.
-+ *
-+ */
-+#include <linux/kernel.h>
-+#include <linux/module.h>
-+#include <linux/pci.h>
-+#include <linux/init.h>
-+#include <linux/interrupt.h>
-+#include <zaptel.h>
-+#include "cwain.h"
-+
-+#if CONFIG_PCI
-+
-+static int ports=-1; /* autodetect */
-+static int debug=0;
-+static struct zt_cwain *cwain_span_list = NULL;
-+static int cwain_span_count = 0;
-+static struct zt_cwain_card *cwain_card_list = NULL;
-+static int cwain_card_count = 0;
-+static struct pci_dev *multi_cwain = NULL;
-+static spinlock_t cwain_span_registerlock = SPIN_LOCK_UNLOCKED;
-+static spinlock_t cwain_card_registerlock = SPIN_LOCK_UNLOCKED;
-+
-+static int ztcwain_shutdown(struct zt_span *span);
-+
-+int cwain_waitbusy(struct zt_cwain *cwaintmp) {
-+ int x=1000;
-+ while (x-- && (cwain_inb(cwaintmp,cwain_R_STATUS) & 1));
-+ if (x < 0) {
-+ printk(KERN_CRIT "cwain: really busy waiting!\n");
-+ return -1;
-+ } else {
-+ if ((x < 990) && (cwaintmp->ticks > 500)) {
-+ printk(KERN_CRIT "cwain: waited %d\n", 1000 - x);
-+ }
-+ return 0;
-+ }
-+}
-+
-+void cwain_unregister_zap_span(struct zt_cwain *cwainspan) {
-+ if (!cwainspan) {
-+ printk(KERN_INFO "cwain: shutting down NULL span!\n");
-+ return;
-+ }
-+ if(cwainspan->span.flags & ZT_FLAG_RUNNING) {
-+ ztcwain_shutdown(&cwainspan->span);
-+ if (debug)
-+ printk(KERN_INFO "cwain: shutdown span %d.\n",cwainspan->cardno);
-+ }
-+ if(cwainspan->span.flags & ZT_FLAG_REGISTERED) {
-+ zt_unregister(&cwainspan->span);
-+ if (debug)
-+ printk(KERN_INFO "cwain: unregistered span %d.\n",cwainspan->cardno);
-+ }
-+}
-+
-+void cwain_shutdown_span(struct zt_cwain *cwainspan) {
-+
-+ if (!cwainspan) {
-+ printk(KERN_INFO "cwain: shutting down NULL span!\n");
-+ return;
-+ }
-+
-+ if (cwainspan->pci_io == NULL) {
-+ return;
-+ }
-+
-+ if (debug)
-+ printk(KERN_INFO "cwain: shutting down span %d (cardID %d) at %p.\n",cwainspan->cardno,cwainspan->cardID,cwainspan->pci_io);
-+
-+ // turn off irqs
-+
-+ // softreset
-+ cwain_outb(cwainspan,cwain_R_CIRM,0x8);
-+ cwain_outb(cwainspan,cwain_R_CIRM,0x0);
-+ cwain_waitbusy(cwainspan);
-+
-+ cwain_outb(cwainspan,cwain_R_IRQMSK_MISC, 0);
-+ cwain_outb(cwainspan,cwain_R_IRQ_CTRL, 0);
-+
-+ pci_write_config_word(cwainspan->pcidev, PCI_COMMAND, 0); // disable memio
-+
-+ if (cwainspan->pcidev != NULL) {
-+ pci_disable_device(cwainspan->pcidev);
-+ cwainspan->pcidev = NULL;
-+ }
-+
-+// iounmap((void *) cwainspan->pci_io);
-+// cwainspan->pci_io = NULL;
-+}
-+
-+void cwain_shutdown_card(struct zt_cwain_card *cwaintmp) {
-+ unsigned long flags = 0;
-+ int i = 0;
-+
-+ if (!cwaintmp) {
-+ printk(KERN_INFO "cwain: shutting down NULL card!\n");
-+ return;
-+ }
-+
-+ for (i=0;i<cwaintmp->spans;i++) {
-+ cwain_unregister_zap_span(cwaintmp->span[i]);
-+ }
-+
-+ spin_lock_irqsave(&cwaintmp->lock,flags);
-+
-+ // turn off irqs
-+ cwain_outb(cwaintmp->span[0],cwain_R_IRQ_CTRL, 0);
-+ cwain_outb(cwaintmp->span[0],cwain_R_IRQMSK_MISC, 0);
-+
-+ for (i=0;i<cwaintmp->spans;i++) {
-+ cwain_shutdown_span(cwaintmp->span[i]);
-+ }
-+ spin_unlock_irqrestore(&cwaintmp->lock,flags);
-+
-+ for (i=0;i<cwaintmp->spans;i++) {
-+ iounmap((void *) cwaintmp->span[i]->pci_io);
-+ cwaintmp->span[i]->pci_io = NULL;
-+ }
-+
-+ free_irq(cwaintmp->irq,cwaintmp);
-+}
-+
-+void cwain_doLEDs(struct zt_cwain *cwaintmp) {
-+ /*
-+ O1 O3 (red)
-+ O2 O4 (green)
-+ */
-+ if (!(cwaintmp->span.flags & ZT_FLAG_RUNNING)) {
-+ return;
-+ }
-+ if ((cwaintmp->type == 0xb553) || (cwaintmp->type == 0xb554)) {
-+ /* sync status */
-+ if (((cwaintmp->sync_sta & 0x07) == 0x07) && cwaintmp->sync) {
-+ cwaintmp->leds[0] = 1;
-+ cwaintmp->leds[1] = 0;
-+ } else {
-+ cwaintmp->leds[0] = 0;
-+ cwaintmp->leds[1] = 1;
-+ }
-+ /* multiframe alignment */
-+ if ((cwaintmp->sync_sta & 0x20) == 0x20) {
-+ cwaintmp->leds[2] = 1;
-+ cwaintmp->leds[3] = 0;
-+ } else {
-+ if ((cwaintmp->span.lineconfig & ZT_CONFIG_CRC4) && cwaintmp->sync) {
-+ /* CRC4 requested */
-+ cwaintmp->leds[2] = 0;
-+ cwaintmp->leds[3] = 1;
-+ } else {
-+ /* no CRC4, disable 3 and 4 */
-+ cwaintmp->leds[2] = 1;
-+ cwaintmp->leds[3] = 1;
-+ }
-+ }
-+ cwain_outb(cwaintmp,cwain_R_GPIO_OUT1,(cwaintmp->leds[0] | (cwaintmp->leds[1] << 1) | (cwaintmp->leds[2] << 2) | (cwaintmp->leds[3] << 3)));
-+ }
-+}
-+
-+void cwain_reset_span(struct zt_cwain *cwaintmp) {
-+ int i = 0;
-+ pci_write_config_word(cwaintmp->pcidev, PCI_COMMAND, PCI_COMMAND_MEMORY); // enable memio
-+
-+ /* FIFO, HDLC reset */
-+ cwain_outb(cwaintmp,cwain_R_CIRM,0x10);
-+ cwain_outb(cwaintmp,cwain_R_CIRM,0x0);
-+ cwain_waitbusy(cwaintmp);
-+
-+ /* PCM reset */
-+ cwain_outb(cwaintmp,cwain_R_CIRM,0x20);
-+ cwain_outb(cwaintmp,cwain_R_CIRM,0x0);
-+ cwain_waitbusy(cwaintmp);
-+
-+ for (i=0; i<128; i++) {
-+ cwain_outb(cwaintmp,cwain_R_SLOT, i);
-+ cwain_outb(cwaintmp,cwain_A_SL_CFG, 0x0);
-+ }
-+
-+ /* E1 reset */
-+ cwain_outb(cwaintmp,cwain_R_CIRM,0x40);
-+ cwain_outb(cwaintmp,cwain_R_CIRM,0x0);
-+ cwain_waitbusy(cwaintmp);
-+
-+ /* 128 byte B chans, 4096 byte D chans */
-+ cwain_outb(cwaintmp,cwain_R_FIFO_MD,0x36);
-+ cwain_outb(cwaintmp,cwain_R_BRG_PCM_CFG,0x0);
-+ cwain_outb(cwaintmp,cwain_R_CTRL,0x0);
-+
-+ /* no blinky blink */
-+ cwain_outb(cwaintmp,cwain_R_GPIO_SEL,0x20 | 0x10);
-+ cwain_outb(cwaintmp,cwain_R_GPIO_EN1,0x0f);
-+ cwain_outb(cwaintmp,cwain_R_GPIO_OUT1,0x0f);
-+
-+ cwaintmp->leds[0] = 1;
-+ cwaintmp->leds[1] = 1;
-+ cwaintmp->leds[2] = 1;
-+ cwaintmp->leds[3] = 1;
-+
-+ cwaintmp->ticks = 0;
-+ cwaintmp->clicks = 0;
-+}
-+
-+struct zt_cwain_card *cwain_get_card(unsigned int pcibus) {
-+ struct zt_cwain_card *cwaintmp = cwain_card_list;
-+ spin_lock(&cwain_card_registerlock);
-+ while (cwaintmp) {
-+ if (cwaintmp->pcibus == pcibus) {
-+ break;
-+ }
-+ cwaintmp = cwaintmp->next;
-+ }
-+ spin_unlock(&cwain_card_registerlock);
-+ return cwaintmp;
-+}
-+
-+
-+void cwain_register_card(struct zt_cwain_card *cwaincard) {
-+ spin_lock(&cwain_card_registerlock);
-+ if (cwaincard != NULL) {
-+ cwaincard->prev = NULL;
-+ cwaincard->next = cwain_card_list;
-+ if (cwain_card_list) {
-+ cwain_card_list->prev = cwaincard;
-+ }
-+ cwain_card_list = cwaincard;
-+ cwain_card_count++;
-+ } else {
-+ printk(KERN_INFO "cwain: trying to register NULL card.\n");
-+ }
-+ spin_unlock(&cwain_card_registerlock);
-+}
-+
-+int cwain_register_span(struct zt_cwain *cwainspan) {
-+ struct zt_cwain_card *cwaintmp;
-+ spin_lock(&cwain_span_registerlock);
-+ if (cwainspan != NULL) {
-+ cwainspan->prev = NULL;
-+ cwainspan->next = cwain_span_list;
-+ if (cwain_span_list) {
-+ cwain_span_list->prev = cwainspan;
-+ }
-+ cwain_span_list = cwainspan;
-+ cwainspan->cardno = ++cwain_span_count;
-+ } else {
-+ printk(KERN_INFO "cwain: trying to register NULL span.\n");
-+ }
-+ spin_unlock(&cwain_span_registerlock);
-+
-+ if (cwainspan->type == 0xb553) {
-+ cwaintmp = kmalloc(sizeof(struct zt_cwain_card),GFP_KERNEL);
-+ if (!cwaintmp) {
-+ printk(KERN_WARNING "cwain: unable to kmalloc!\n");
-+ return -1;
-+ }
-+ memset(cwaintmp, 0x0, sizeof(struct zt_cwain_card));
-+
-+ spin_lock_init(&cwaintmp->lock);
-+ cwaintmp->pcibus = cwainspan->pcibus;
-+ cwaintmp->span[0] = cwainspan;
-+ cwaintmp->syncs[0] = -1;
-+ cwaintmp->spans = 1;
-+ cwaintmp->cardID = cwainspan->cardID;
-+ cwain_register_card(cwaintmp);
-+ printk(KERN_INFO
-+ "cwain: Junghanns.NET singleE1 PCI ISDN card configured at mem %#x IRQ %d HZ %d CardID %d\n",
-+ (u_int) cwainspan->pci_io,
-+ cwaintmp->span[0]->irq, HZ, cwainspan->cardID);
-+ } else {
-+ cwaintmp = cwain_get_card(cwainspan->pcibus);
-+ if (!cwaintmp) {
-+ cwaintmp = kmalloc(sizeof(struct zt_cwain_card),GFP_KERNEL);
-+ if (!cwaintmp) {
-+ printk(KERN_WARNING "cwain: unable to kmalloc!\n");
-+ return -1;
-+ }
-+ memset(cwaintmp, 0x0, sizeof(struct zt_cwain_card));
-+
-+ spin_lock_init(&cwaintmp->lock);
-+ cwaintmp->pcibus = cwainspan->pcibus;
-+ cwaintmp->spans = cwainspan->type - 46419;
-+ cwaintmp->span[0] = cwainspan;
-+ cwaintmp->cardID = cwainspan->cardID;
-+ cwaintmp->syncs[0] = -1;
-+ cwain_register_card(cwaintmp);
-+ } else {
-+ cwaintmp->spans = cwainspan->type - 46418;
-+ if (cwainspan->cardID < cwaintmp->cardID) {
-+ cwaintmp->cardID = cwainspan->cardID;
-+ cwaintmp->span[1] = cwaintmp->span[0];
-+ cwaintmp->syncs[1] = cwaintmp->syncs[0];
-+ cwaintmp->span[0] = cwainspan;
-+ } else {
-+ cwaintmp->span[1] = cwainspan;
-+ cwaintmp->syncs[1] = -1;
-+ }
-+ printk(KERN_INFO
-+ "cwain: Junghanns.NET doubleE1 PCI ISDN card configured at mem (%#x / %#x) IRQ %d HZ %d CardID (%d / %d) bus %#x\n",
-+ (u_int) cwaintmp->span[0]->pci_io, (u_int) cwaintmp->span[1]->pci_io,
-+ cwaintmp->span[0]->irq, HZ, cwaintmp->span[0]->cardID, cwaintmp->span[1]->cardID, cwaintmp->pcibus);
-+ }
-+ }
-+ return 0;
-+}
-+
-+static int cwain_dfifo_tx(struct zt_cwain *cwaintmp) {
-+ int chan = 15;
-+ int x=0;
-+ char fifo = 0;
-+
-+ fifo = 0x1F;
-+
-+ if (cwaintmp->chans[chan].bytes2transmit < 1) {
-+ return 0;
-+ } else {
-+ /* select fifo */
-+ cwain_outb(cwaintmp,cwain_R_FIFO,fifo << 1);
-+ cwain_waitbusy(cwaintmp);
-+
-+ if (debug)
-+ printk(KERN_INFO "cwain: card %d TX [ ", cwaintmp->cardno);
-+ /* copy frame to fifo */
-+ for (x=0;x<cwaintmp->chans[chan].bytes2transmit;x++) {
-+ if (debug)
-+ printk("%#x ",cwaintmp->dtxbuf[x]);
-+ cwain_outb(cwaintmp,cwain_A_FIFO_DATA0,cwaintmp->dtxbuf[x]);
-+ }
-+ if (debug)
-+ printk("]\n");
-+ if (debug)
-+ printk(KERN_INFO "ztx %d bytes\n",cwaintmp->chans[chan].bytes2transmit);
-+
-+ if (cwaintmp->chans[chan].eoftx == 1) {
-+ /* transmit HDLC frame */
-+ cwain_outb(cwaintmp,cwain_R_INC_RES_FIFO,0x1);
-+ cwain_waitbusy(cwaintmp);
-+ }
-+ }
-+ return 0;
-+}
-+
-+static int cwain_fifo_tx(struct zt_cwain *cwaintmp, char fifo) {
-+ int chan;
-+ if (fifo >= 15) {
-+ chan = fifo;
-+ } else {
-+ chan = fifo;
-+ }
-+ /* select fifo */
-+ cwain_outb(cwaintmp,cwain_R_FIFO,0x80 | (fifo << 1));
-+ cwain_waitbusy(cwaintmp);
-+ /* transmit 8 bytes of transparent data */
-+ cwain_outdw(cwaintmp,cwain_A_FIFO_DATA0,*((unsigned int *) &cwaintmp->txbuf[chan][0]));
-+ cwain_outdw(cwaintmp,cwain_A_FIFO_DATA0,*((unsigned int *) &cwaintmp->txbuf[chan][4]));
-+
-+ return 0;
-+}
-+
-+static int cwain_dfifo_rx(struct zt_cwain *cwaintmp) {
-+ int chan = 15;
-+ unsigned char f1=1,f2=1,data,stat;
-+ unsigned char of1=0,of2=0;
-+ int len,i;
-+ unsigned short z1=1,z2=1;
-+ unsigned short oz1=0,oz2=0;
-+ char fifo = 0;
-+
-+ fifo = 0x1F;
-+
-+ /* select fifo */
-+ cwain_outb(cwaintmp,cwain_R_FIFO,(fifo << 1) | 1);
-+ cwain_waitbusy(cwaintmp);
-+
-+ while ((oz1 != z1) && (oz2 != z2)) {
-+ oz1 = z1;
-+ oz2 = z2;
-+ z1 = cwain_inw(cwaintmp,cwain_A_Z1) & 0xfff;
-+ z2 = cwain_inw(cwaintmp,cwain_A_Z2) & 0xfff;
-+ }
-+
-+ len = z1-(z2 & 0xfff);
-+ if (len < 0) {
-+ len += cwain_DFIFO_SIZE;
-+ }
-+
-+ while ((of1 != f1) && (of2 != f2)) {
-+ of1 = f1;
-+ of2 = f2;
-+ f1 = cwain_inb(cwaintmp,cwain_A_F1) & 0xf;
-+ f2 = cwain_inb(cwaintmp,cwain_A_F2) & 0xf;
-+ }
-+
-+ if (len > cwain_DFIFO_SIZE) {
-+ printk(KERN_INFO "\ncwain: buffer overflow in D channel RX!\n");
-+ cwaintmp->chans[chan].bytes2receive = 0;
-+ cwaintmp->chans[chan].eofrx = 0;
-+ } else {
-+ if (debug) printk(KERN_INFO "cwain: card %d RX [ ", cwaintmp->cardno);
-+ for (i=0; i<len; i++) {
-+ data = cwain_inb(cwaintmp,cwain_A_FIFO_DATA0);
-+ cwaintmp->drxbuf[i] = data;
-+ if (debug) printk("%#x ",data);
-+ }
-+ if (debug) printk("] %d bytes\n", i);
-+ cwaintmp->chans[chan].bytes2receive = i;
-+ cwaintmp->chans[chan].eofrx = 1;
-+ }
-+
-+ stat = cwain_inb(cwaintmp,cwain_A_FIFO_DATA0);
-+ if (stat != 0x0) {
-+ // bad CRC, skip it
-+ if (cwaintmp->sync) {
-+ printk(KERN_INFO "cwain: BAD CRC for hdlc frame on card %d (cardID %d) stat %#x\n",cwaintmp->cardno, cwaintmp->cardID, stat);
-+ }
-+ cwaintmp->chans[chan].bytes2receive = 0;
-+ cwaintmp->chans[chan].eofrx = 0;
-+// zt_qevent_nolock(&cwaintmp->spans[stport].chans[chan], ZT_EVENT_BADFCS);
-+ }
-+ cwain_outb(cwaintmp,cwain_R_INC_RES_FIFO,0x1);
-+ cwain_waitbusy(cwaintmp);
-+
-+ /* frame received */
-+ cwaintmp->drx--;
-+ return 0;
-+}
-+
-+
-+static int cwain_fifo_rx(struct zt_cwain *cwaintmp, char fifo) {
-+ int chan;
-+ unsigned char data;
-+ int len,i;
-+ unsigned short z1=1,z2=1;
-+ unsigned short oz1=0,oz2=0;
-+ int mumbojumbo=0;
-+ int x = 1000;
-+
-+ if (fifo >= 15) {
-+ chan = fifo; /* +1 */
-+ } else {
-+ chan = fifo;
-+ }
-+
-+ // select rx fifo
-+
-+ // no hdlc, transparent data
-+ cwain_outb(cwaintmp,cwain_R_FIFO,0x80 | (fifo << 1) | 1);
-+ cwain_waitbusy(cwaintmp);
-+
-+ while (x-- && ((oz1 != z1) && (oz2 != z2))) {
-+ oz1 = z1;
-+ oz2 = z2;
-+ z1 = cwain_inw(cwaintmp,cwain_A_Z1) & 0x1ff;
-+ z2 = cwain_inw(cwaintmp,cwain_A_Z2) & 0x1ff;
-+ }
-+ if (x < 500) {
-+ printk(KERN_CRIT "cwain: prevented endless loop\n");
-+ }
-+
-+ len = z1-(z2 & 0x1ff);
-+ if (len < 0) {
-+ len += cwain_FIFO_SIZE;
-+ }
-+// if (len > 2 * ZT_CHUNKSIZE) {
-+ if (len > cwain_FIFO_HW) {
-+// mumbojumbo = len - (2 * ZT_CHUNKSIZE);
-+ mumbojumbo = len - (cwain_FIFO_HW);
-+ len = ZT_CHUNKSIZE;
-+ for (i=0;i<mumbojumbo;i++) {
-+ data = cwain_inb(cwaintmp,cwain_A_FIFO_DATA0);
-+ }
-+ cwaintmp->clicks++;
-+ }
-+ if (len < ZT_CHUNKSIZE) {
-+ if (cwaintmp->clicks > 501) {
-+ printk(KERN_INFO "cwain: not enough to receive (%d bytes)\n",len);
-+ }
-+ return 0;
-+ } else {
-+ *((unsigned int *) &cwaintmp->rxbuf[chan][0]) = cwain_indw(cwaintmp,cwain_A_FIFO_DATA0);
-+ *((unsigned int *) &cwaintmp->rxbuf[chan][4]) = cwain_indw(cwaintmp,cwain_A_FIFO_DATA0);
-+ }
-+
-+ zt_ec_chunk(&cwaintmp->span.chans[chan], cwaintmp->span.chans[chan].readchunk, cwaintmp->span.chans[chan].writechunk);
-+
-+ if (cwaintmp->clicks > 500) {
-+ printk(KERN_INFO "cwain: span %d dropped audio fifo %d mj %d\n", cwaintmp->cardID, fifo, mumbojumbo);
-+ cwaintmp->clicks = 0;
-+ }
-+// printk(KERN_INFO "s/t port %d, channel %d, dbufi=%d, f1=%d, f2=%d, z1=%d, z2=%d => len = %d stat=%#x, hdlc=%d\n",stport,chan,cwaintmp->st[stport].dbufi,f1,f2,z1,z2,len,stat,hdlc);
-+ return 0;
-+}
-+
-+void cwain_set_master(struct zt_cwain_card *cwaintmp, int span) {
-+ int i=0;
-+
-+ if (cwaintmp->syncsrc == span) return;
-+
-+ for (i=0; i < cwaintmp->spans; i++) {
-+ if (i != span) {
-+ if (cwaintmp->syncs[i] > 0) {
-+ /* enable PCM slave mode, PCM32, synced to E1 receive */
-+ cwain_outb(cwaintmp->span[i],cwain_R_PCM_MD0, 0x90);
-+ cwain_outb(cwaintmp->span[i],cwain_R_PCM_MD1, 0x0);
-+ cwain_outb(cwaintmp->span[span],cwain_R_PCM_MD0, 0xA0);
-+ cwain_outb(cwaintmp->span[i],cwain_R_PCM_MD2, 0x00);
-+ } else {
-+ /* enable PCM slave mode, PCM32 */
-+ cwain_outb(cwaintmp->span[i],cwain_R_PCM_MD0, 0x90);
-+ cwain_outb(cwaintmp->span[i],cwain_R_PCM_MD1, 0x0);
-+ cwain_outb(cwaintmp->span[span],cwain_R_PCM_MD0, 0xA0);
-+ cwain_outb(cwaintmp->span[i],cwain_R_PCM_MD2, 0x00);
-+ }
-+ cwaintmp->master[i] = 0;
-+ cwaintmp->span[i]->span.syncsrc = 0;
-+ }
-+ }
-+
-+ if (cwaintmp->syncs[span] > 0) {
-+ /* enable PCM master mode, PCM32, synced to E1 receive */
-+ if (debug)
-+ printk(KERN_INFO "cwain: cardID %d span %d, PCM master E1 sync\n", cwaintmp->cardID, span);
-+ cwain_outb(cwaintmp->span[span],cwain_R_PCM_MD0, 0x91);
-+ cwain_outb(cwaintmp->span[span],cwain_R_PCM_MD1, 0x0);
-+ cwain_outb(cwaintmp->span[span],cwain_R_PCM_MD0, 0xA1);
-+ cwain_outb(cwaintmp->span[span],cwain_R_PCM_MD2, 0x00);
-+ cwaintmp->span[span]->span.syncsrc = 1;
-+ } else {
-+ /* enable PCM master mode, PCM32, free running */
-+ if (debug)
-+ printk(KERN_INFO "cwain: cardID %d span %d, PCM master\n", cwaintmp->cardID, span);
-+ cwain_outb(cwaintmp->span[span],cwain_R_PCM_MD0, 0x91);
-+ cwain_outb(cwaintmp->span[span],cwain_R_PCM_MD1, 0x0);
-+ cwain_outb(cwaintmp->span[span],cwain_R_PCM_MD0, 0xA1);
-+ cwain_outb(cwaintmp->span[span],cwain_R_PCM_MD2, 0x04);
-+ cwaintmp->span[span]->span.syncsrc = 0;
-+ }
-+
-+ cwaintmp->master[span] = 1;
-+ cwaintmp->syncsrc = span;
-+}
-+
-+void cwain_check_timing(struct zt_cwain_card *cwaintmp) {
-+ int i=0;
-+ int bestsync = 42;
-+
-+ for (i=0; i < cwaintmp->spans; i++) {
-+ if ((cwaintmp->syncs[i] > 0) && ((cwaintmp->span[i]->sync_sta & 0x7) == 0x7)) {
-+ if (bestsync < cwaintmp->spans) {
-+ if (cwaintmp->syncs[i] < cwaintmp->syncs[bestsync]) {
-+ bestsync = i;
-+ }
-+ } else {
-+ bestsync = i;
-+ }
-+ }
-+ }
-+
-+ if (cwaintmp->syncsrc >= 0) {
-+ if (debug > 3)
-+ printk(KERN_INFO "cwain: bestsync %d cwaintmp->syncsrc %d\n", bestsync, cwaintmp->syncsrc);
-+
-+ if (bestsync == cwaintmp->syncsrc) {
-+ if (debug > 3)
-+ printk(KERN_INFO "cwain: already on best syncsrc %d\n", bestsync);
-+ return;
-+ }
-+
-+ /* if we have a better syncsrc */
-+ if (bestsync < cwaintmp->spans) {
-+ if (debug)
-+ printk(KERN_INFO "cwain: found better syncsrc %d\n", bestsync);
-+ cwain_set_master(cwaintmp, bestsync);
-+ return;
-+ }
-+ }
-+
-+ /* if reelection failed, find internal sync source */
-+ if (cwaintmp->syncsrc == -1) {
-+ /* no master yet */
-+ if (debug > 3)
-+ printk(KERN_INFO "cwain: no clocksource found cardID %d\n", cwaintmp->cardID);
-+ for (i=0; i < cwaintmp->spans; i++) {
-+ /* find the first internal source */
-+ if (debug > 3)
-+ printk(KERN_INFO "cwain: cwaintmp->syncs[%d] = %d\n", i, cwaintmp->syncs[i]);
-+ if (cwaintmp->syncs[i] == 0) {
-+ if (debug)
-+ printk(KERN_INFO "cwain: using internal clock of span %d\n", i);
-+ cwain_set_master(cwaintmp, i);
-+ return;
-+ }
-+ }
-+ }
-+
-+ /* if we have no internal sync source the only thing we can do is to enable any of the possible sync sources*/
-+ if (cwaintmp->syncsrc == -1) {
-+ /* find the first possible sync source with framing */
-+ for (i=0; i < cwaintmp->spans; i++) {
-+ if (cwaintmp->syncs[i] > 0) {
-+ if (debug)
-+ printk(KERN_INFO "cwain: desperately using clock of span %d\n", i);
-+ cwain_set_master(cwaintmp, i);
-+ break;
-+ }
-+ }
-+ }
-+}
-+
-+static inline void cwain_isr_run(struct zt_cwain *cwaintmp) {
-+ int fifo=0;
-+ if (cwaintmp->span.flags & ZT_FLAG_RUNNING) {
-+ /* oh zaptel! tell us what to transmit... */
-+ zt_transmit(&cwaintmp->span);
-+ /* B chans 1-15 mapped to fifos 0-14 */
-+ /* B chans 17-31 mapped to fifos 15-29 */
-+ for (fifo=0; fifo < 30; fifo++) {
-+ /* B xmit */
-+ cwain_fifo_tx(cwaintmp, fifo);
-+ }
-+ if (cwaintmp->sync) {
-+ cwain_dfifo_tx(cwaintmp);
-+ }
-+
-+ cwaintmp->chans[15].bytes2receive = 0;
-+ cwaintmp->chans[15].bytes2transmit = 0;
-+ cwaintmp->chans[15].eofrx = 0;
-+ cwaintmp->chans[15].eoftx = 0;
-+
-+ for (fifo=0; fifo < 30; fifo++) {
-+ /* B rx */
-+ cwain_fifo_rx(cwaintmp, fifo);
-+ }
-+
-+ /* d-chan data */
-+ if ((cwaintmp->drx > 0) && cwaintmp->sync){
-+ if (debug > 2)
-+ printk(KERN_CRIT "drx = %d\n", cwaintmp->drx);
-+ cwain_dfifo_rx(cwaintmp);
-+ }
-+ /* oh zaptel! thou shall receive! */
-+ zt_receive(&(cwaintmp->span));
-+ }
-+}
-+
-+void cwain_isr_sync(struct zt_cwain *cwainspan) {
-+ unsigned char sync_sta;
-+ unsigned char sync_ok = 0;
-+ unsigned char jatt_sta = 0;
-+
-+ if (!cwainspan->span.flags & ZT_FLAG_RUNNING) {
-+ return;
-+ }
-+
-+ sync_sta = cwain_inb(cwainspan, cwain_R_SYNC_STA);
-+
-+if ((!cwainspan->sync) || (sync_sta != cwainspan->sync_sta)) {
-+
-+ if (debug > 2)
-+ printk(KERN_CRIT "cwain: cardID %d R_SYNC_STA =%#x\n", cwainspan->cardID, sync_sta);
-+
-+ if (cwainspan->span.lineconfig & ZT_CONFIG_CRC4) {
-+ if ((sync_sta & 0x80) == 0x80) {
-+ /* reset MFA detection */
-+ cwain_outb(cwainspan ,cwain_R_RX_SL0_CFG1,0x41);
-+ } else if ((sync_sta & 0x27) == 0x27) {
-+ if ((cwainspan->sync_sta & 0x27) != 0x27) {
-+ /* sync achieved, restart JATT */
-+ if (debug)
-+ printk(KERN_INFO "cwain: %d starting jitter attenuator\n", cwainspan->cardID);
-+ cwain_outb(cwainspan, cwain_R_JATT_CFG,0x9c);
-+ }
-+ sync_ok = 0x27;
-+ } else {
-+ sync_ok = 0x00;
-+ }
-+ } else {
-+ if ((sync_sta & 0x07) == 0x07) {
-+ if ((cwainspan->sync_sta & 0x7) != 0x7) {
-+ /* sync achieved, restart JATT */
-+ if (debug)
-+ printk(KERN_INFO "cwain: %d starting jitter attenuator\n", cwainspan->cardID);
-+ cwain_outb(cwainspan, cwain_R_JATT_CFG,0x9c);
-+ }
-+ sync_ok = 0x07;
-+ } else {
-+ sync_ok = 0x00;
-+ }
-+ }
-+
-+ cwainspan->sync_sta = sync_sta;
-+
-+ jatt_sta = cwain_inb(cwainspan, cwain_R_JATT_STA);
-+ if ((jatt_sta & 0x60) != 0x60) {
-+ if (debug > 2)
-+ printk(KERN_INFO "cwain: %d jitter attenuator %#x\n", cwainspan->cardID, (jatt_sta & 0x60) >> 5);
-+ sync_ok = 0x00;
-+ } else if (!cwainspan->sync && sync_ok) {
-+ if (debug)
-+ printk(KERN_CRIT "cwain: %d jitter attenuator %#x ok!\n", cwainspan->cardID, (jatt_sta & 0x60) >> 5);
-+ }
-+
-+ if (sync_ok && (!cwainspan->sync)) {
-+ /* elastic buffer offsets */
-+ cwain_outb(cwainspan,cwain_R_RX_OFFS,0x06);
-+ cwain_outb(cwainspan,cwain_R_TX_OFFS,0x06);
-+
-+ if (debug > 2)
-+ printk(KERN_INFO "cwain: enabling D channel fifos\n");
-+ cwain_outb(cwainspan,cwain_R_FIFO,0x1F << 1);
-+ cwain_waitbusy(cwainspan);
-+ cwain_outb(cwainspan,cwain_A_CON_HDLC,0xd);
-+ cwain_outb(cwainspan,cwain_A_IRQ_MSK,0x1);
-+
-+ cwain_outb(cwainspan,cwain_R_FIFO,(0x1F << 1) | 1);
-+ cwain_waitbusy(cwainspan);
-+ cwain_outb(cwainspan,cwain_A_CON_HDLC,0xd);
-+ cwain_outb(cwainspan,cwain_A_IRQ_MSK,0x1);
-+ cwainspan->span.alarms = ZT_ALARM_NONE;
-+ zt_alarm_notify(&cwainspan->span);
-+ }
-+ if (!sync_ok && cwainspan->sync) {
-+ if (debug > 2)
-+ printk(KERN_INFO "cwain: disabling D channel fifos\n");
-+ cwain_outb(cwainspan,cwain_R_FIFO,0x1F << 1);
-+ cwain_waitbusy(cwainspan);
-+ cwain_outb(cwainspan,cwain_A_CON_HDLC,0x1);
-+ cwain_outb(cwainspan,cwain_A_IRQ_MSK,0x0);
-+ cwain_outb(cwainspan,cwain_R_FIFO,(0x1F << 1) | 1);
-+ cwain_waitbusy(cwainspan);
-+ cwain_outb(cwainspan,cwain_A_CON_HDLC,0x1);
-+ cwain_outb(cwainspan,cwain_A_IRQ_MSK,0x0);
-+ cwainspan->span.alarms = ZT_ALARM_RED;
-+ zt_alarm_notify(&cwainspan->span);
-+ }
-+
-+ cwainspan->sync = sync_ok;
-+ if (sync_ok) {
-+ switch (cwainspan->type) {
-+ case 0xb553:
-+ sprintf(cwainspan->span.desc,"Junghanns.NET singleE1 PCI ISDN Card %d (cardID %d) SYNCED",cwainspan->cardno,cwainspan->cardID);
-+ break;
-+ case 0xb554:
-+ sprintf(cwainspan->span.desc,"Junghanns.NET doubleE1 PCI ISDN Card %d (cardID %d) (1 E1 port) SYNCED",cwainspan->cardno,cwainspan->cardID);
-+ break;
-+ }
-+ } else {
-+ switch (cwainspan->type) {
-+ case 0xb553:
-+ sprintf(cwainspan->span.desc,"Junghanns.NET singleE1 PCI ISDN Card %d (cardID %d) NO SYNC (sync_sta = %#x)",cwainspan->cardno,cwainspan->cardID, sync_sta);
-+ break;
-+ case 0xb554:
-+ sprintf(cwainspan->span.desc,"Junghanns.NET doubleE1 PCI ISDN Card %d (cardID %d) (1 E1 port) NO SYNC (sync_sta = %#x)",cwainspan->cardno,cwainspan->cardID, sync_sta);
-+ break;
-+ }
-+ }
-+ cwain_doLEDs(cwainspan);
-+}
-+}
-+
-+int cwain_isr_fifo(struct zt_cwain *cwainspan, unsigned char status) {
-+ unsigned char irq_foview,fi;
-+
-+ if (status & 0x80) {
-+ /* fifo irq */
-+ irq_foview = cwain_inb(cwainspan,cwain_R_IRQ_OVIEW);
-+ if (irq_foview & 0x80) {
-+ fi = cwain_inb(cwainspan,cwain_R_IRQ_FIFO_BL7);
-+ if (fi & 0x80) {
-+ if (debug > 2)
-+ printk(KERN_CRIT "cwain: fifo 31 RX irq for D channel\n");
-+ cwainspan->drx += 1;
-+ }
-+ }
-+ return 1;
-+ }
-+ return 0;
-+}
-+
-+#ifdef LINUX26
-+static irqreturn_t cwain_interrupt(int irq, void *dev_id, struct pt_regs *regs) {
-+#else
-+static void cwain_interrupt(int irq, void *dev_id, struct pt_regs *regs) {
-+#endif
-+ struct zt_cwain_card *cwaintmp = dev_id;
-+ unsigned char status, status2, status_tmp, irq_misc, irq_misc2;
-+ unsigned long flags;
-+ int i = 0;
-+ int l1event = 0;
-+
-+ if (!cwaintmp || cwaintmp->dead) {
-+#ifdef LINUX26
-+ return IRQ_NONE;
-+#else
-+ return;
-+#endif
-+ }
-+
-+
-+ spin_lock_irqsave(&(cwaintmp->lock),flags);
-+ status = cwain_inb(cwaintmp->span[0],cwain_R_STATUS);
-+
-+ status2 = 0;
-+
-+ for (i=0;i<cwaintmp->spans;i++) {
-+ if (i == 0) {
-+ status_tmp = status;
-+ } else {
-+ status_tmp = cwain_inb(cwaintmp->span[i],cwain_R_STATUS);
-+ status2 = status_tmp;
-+ }
-+ cwain_isr_fifo(cwaintmp->span[i], status_tmp);
-+ }
-+
-+ if (!(status & 0x80) && !(status & 0x40)) {
-+ // it's not us!
-+ spin_unlock_irqrestore(&(cwaintmp->lock),flags);
-+#ifdef LINUX26
-+ return IRQ_NONE;
-+#else
-+ return;
-+#endif
-+ }
-+
-+ // misc irq
-+ if (status & 0x40) {
-+ irq_misc = cwain_inb(cwaintmp->span[0],cwain_R_IRQ_MISC);
-+ if (irq_misc & 0x2) {
-+ /* cwain timer */
-+ cwaintmp->ticks++;
-+ for (i=0;i<cwaintmp->spans;i++) {
-+ cwain_isr_run(cwaintmp->span[i]);
-+ }
-+ if (cwaintmp->ticks == 500) {
-+ cwaintmp->ticks = 0;
-+ }
-+ }
-+ if (irq_misc & 0x1) {
-+ /* state machine */
-+ if (debug > 4)
-+ printk(KERN_INFO "cwain: state machine irq\n");
-+ l1event++;
-+ }
-+ if (irq_misc & 0x10) {
-+ for (i=0;i<cwaintmp->spans;i++) {
-+ cwain_isr_sync(cwaintmp->span[i]);
-+ }
-+ }
-+ }
-+
-+ // misc irq
-+ if (status2 & 0x40) {
-+ if (cwaintmp->spans == 2) {
-+ irq_misc2 = cwain_inb(cwaintmp->span[1],cwain_R_IRQ_MISC);
-+ }
-+ if (irq_misc2 & 0x1) {
-+ /* state machine 2 */
-+ if (debug > 4)
-+ printk(KERN_INFO "cwain: state machine 2 irq\n");
-+ l1event++;
-+ }
-+ }
-+
-+ if (l1event > 0) {
-+// printk(KERN_INFO "cwain: l1event %d\n", l1event);
-+ if (cwaintmp->spans == 2) {
-+ cwain_check_timing(cwaintmp);
-+ }
-+ for (i=0;i<cwaintmp->spans;i++) {
-+ cwain_isr_sync(cwaintmp->span[i]);
-+ }
-+ }
-+
-+ spin_unlock_irqrestore(&(cwaintmp->lock),flags);
-+#ifdef LINUX26
-+ return IRQ_RETVAL(1);
-+#endif
-+}
-+
-+static int ztcwain_open(struct zt_chan *chan) {
-+// printk(KERN_INFO "cwain: channel %d opened.\n",chan->channo);
-+#ifndef LINUX26
-+ MOD_INC_USE_COUNT;
-+#else
-+ try_module_get(THIS_MODULE);
-+#endif
-+ return 0;
-+}
-+
-+static int ztcwain_close(struct zt_chan *chan) {
-+// printk(KERN_INFO "cwain: channel %d closed.\n",chan->channo);
-+#ifndef LINUX26
-+ MOD_DEC_USE_COUNT;
-+#else
-+ module_put(THIS_MODULE);
-+#endif
-+ return 0;
-+}
-+
-+static int ztcwain_rbsbits(struct zt_chan *chan, int bits) {
-+ return 0;
-+}
-+
-+static int ztcwain_ioctl(struct zt_chan *chan, unsigned int cmd, unsigned long data) {
-+ switch(cmd) {
-+ default:
-+ return -ENOTTY;
-+ }
-+ return 0;
-+}
-+
-+static int ztcwain_startup(struct zt_span *span) {
-+ struct zt_cwain_card *cwaincard = span->pvt;
-+ struct zt_cwain *cwaintmp;
-+ unsigned long flags;
-+ int alreadyrunning;
-+ int i=0;
-+
-+// printk(KERN_INFO "cwain: startup spanno %d offset %d\n", span->spanno, span->offset);
-+
-+ if (cwaincard == NULL) {
-+ printk(KERN_CRIT "cwain: cwaincard == NULL!\n");
-+ return 0;
-+ }
-+
-+ cwaintmp = cwaincard->span[span->offset];
-+ if (cwaintmp == NULL) {
-+ printk(KERN_CRIT "cwain: cwaintmp == NULL!\n");
-+ return 0;
-+ }
-+
-+
-+ alreadyrunning = span->flags & ZT_FLAG_RUNNING;
-+// printk(KERN_CRIT "already running %d flags %d\n", alreadyrunning, span->flags);
-+
-+ if (!alreadyrunning) {
-+ span->chans[15].flags &= ~ZT_FLAG_HDLC;
-+ span->chans[15].flags |= ZT_FLAG_BRIDCHAN; /* yes! */
-+
-+ /* setup B channel buffers (8 bytes each) */
-+ for (i=0; i<15 ; i++) {
-+ memset(cwaintmp->rxbuf[i],0x0,sizeof(cwaintmp->rxbuf[i]));
-+ memset(cwaintmp->txbuf[i],0x0,sizeof(cwaintmp->txbuf[i]));
-+
-+ span->chans[i].readchunk = cwaintmp->rxbuf[i];
-+ span->chans[i].writechunk = cwaintmp->txbuf[i];
-+ }
-+ for (i=16; i<31 ; i++) {
-+ memset(cwaintmp->rxbuf[i-1],0x0,sizeof(cwaintmp->rxbuf[i-1]));
-+ memset(cwaintmp->txbuf[i-1],0x0,sizeof(cwaintmp->txbuf[i-1]));
-+ span->chans[i].readchunk = cwaintmp->rxbuf[i-1];
-+ span->chans[i].writechunk = cwaintmp->txbuf[i-1];
-+ }
-+ /* setup D channel buffer */
-+ memset(cwaintmp->dtxbuf,0x0,sizeof(cwaintmp->dtxbuf));
-+ span->chans[15].writechunk = cwaintmp->dtxbuf;
-+ cwaintmp->chans[15].maxbytes2transmit = sizeof(cwaintmp->dtxbuf);
-+
-+ memset(cwaintmp->drxbuf,0x0,sizeof(cwaintmp->drxbuf));
-+ span->chans[15].readchunk = cwaintmp->drxbuf;
-+
-+ span->flags |= ZT_FLAG_RUNNING;
-+ } else {
-+ printk(KERN_CRIT "already running\n");
-+ return 0;
-+ }
-+
-+ spin_lock_irqsave(&cwaintmp->lock,flags);
-+ // irqs off
-+ cwain_outb(cwaintmp,cwain_R_IRQ_CTRL, 0);
-+
-+ /* setup D-FIFO TX */
-+ cwain_outb(cwaintmp,cwain_R_FIFO,0x1F << 1);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_R_INC_RES_FIFO,0x2);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_A_CON_HDLC,0x1);
-+ cwain_outb(cwaintmp,cwain_A_SUBCH_CFG,0x0);
-+ cwain_outb(cwaintmp,cwain_A_CHANNEL,0x10 << 1);
-+ cwain_outb(cwaintmp,cwain_A_IRQ_MSK,0x0);
-+
-+ /* setup D-FIFO RX */
-+ cwain_outb(cwaintmp,cwain_R_FIFO,(0x1F << 1) | 1);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_R_INC_RES_FIFO,0x2);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_A_CON_HDLC,0x1);
-+ cwain_outb(cwaintmp,cwain_A_SUBCH_CFG,0x0);
-+ cwain_outb(cwaintmp,cwain_A_CHANNEL,(0x10 << 1) | 1);
-+ cwain_outb(cwaintmp,cwain_A_IRQ_MSK,0x0);
-+
-+ /* setup B-FIFOs TX */
-+ /* map ts 1 to 15 to fifos 0 to 14 */
-+ for (i=1; i<16 ; i++) {
-+ cwain_outb(cwaintmp,cwain_R_FIFO,(i - 1) << 1);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_R_INC_RES_FIFO,0x2);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_A_CON_HDLC,0x2);
-+ cwain_outb(cwaintmp,cwain_A_CHANNEL,i << 1);
-+ cwain_outb(cwaintmp,cwain_A_IRQ_MSK,0x1);
-+ }
-+ /* map ts 17 to 31 to fifos 15 to 29 */
-+ for (i=17; i<32 ; i++) {
-+ cwain_outb(cwaintmp,cwain_R_FIFO,(i - 2) << 1);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_R_INC_RES_FIFO,0x2);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_A_CON_HDLC,0x2);
-+ cwain_outb(cwaintmp,cwain_A_CHANNEL,i << 1);
-+ cwain_outb(cwaintmp,cwain_A_IRQ_MSK,0x1);
-+ }
-+
-+ /* setup B-FIFOs RX */
-+ /* map ts 1 to 15 to fifos 0 to 14 */
-+ for (i=1; i<16 ; i++) {
-+ cwain_outb(cwaintmp,cwain_R_FIFO,((i-1) << 1) | 1);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_R_INC_RES_FIFO,0x2);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_A_CON_HDLC,0x2);
-+ cwain_outb(cwaintmp,cwain_A_CHANNEL,(i << 1) | 1);
-+ cwain_outb(cwaintmp,cwain_A_IRQ_MSK,0x1);
-+ }
-+ /* map ts 17 to 31 to fifos 15 to 29 */
-+ for (i=17; i<32 ; i++) {
-+ cwain_outb(cwaintmp,cwain_R_FIFO,((i-2) << 1) | 1);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_R_INC_RES_FIFO,0x2);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_A_CON_HDLC,0x2);
-+ cwain_outb(cwaintmp,cwain_A_CHANNEL,(i << 1) | 1);
-+ cwain_outb(cwaintmp,cwain_A_IRQ_MSK,0x1);
-+ }
-+
-+ if (debug)
-+ printk(KERN_INFO "cwain: starting card %d span %d/%d.\n",cwaintmp->cardno,span->spanno,span->offset);
-+
-+ if (cwaincard->spans == 1) {
-+ cwain_set_master(cwaincard, 0);
-+ }
-+
-+ /* setup E1 amplitude */
-+ cwain_outb(cwaintmp,cwain_R_PWM_MD,0x20);
-+ cwain_outb(cwaintmp,cwain_R_PWM0,0x50);
-+ cwain_outb(cwaintmp,cwain_R_PWM1,0xff);
-+
-+ /* setup E1 transceiver */
-+ cwain_outb(cwaintmp,cwain_R_TX_SL0,0xf8); // R_TX_FR1
-+ cwain_outb(cwaintmp,cwain_R_TX_SL0_CFG0,0x00); /* semiautomatic mode */
-+
-+ cwain_outb(cwaintmp,cwain_R_RX_SL0_CFG0,0x6); /* 0x26 */
-+
-+ if (cwaintmp->span.lineconfig & ZT_CONFIG_AMI) {
-+ cwain_outb(cwaintmp,cwain_R_TX0,0x82);
-+ cwain_outb(cwaintmp,cwain_R_RX0,0x02);
-+ } else if (cwaintmp->span.lineconfig & ZT_CONFIG_HDB3) {
-+ cwain_outb(cwaintmp,cwain_R_TX0,0x81);
-+ cwain_outb(cwaintmp,cwain_R_RX0,0x01);
-+ }
-+
-+ /* transmitter mode */
-+ cwain_outb(cwaintmp,cwain_R_TX1,0x60);
-+
-+ cwain_outb(cwaintmp,cwain_R_LOS0,0x10);
-+ cwain_outb(cwaintmp,cwain_R_LOS1,0x10);
-+
-+ if (cwaintmp->span.lineconfig & ZT_CONFIG_CRC4) {
-+ /* crc4 multiframe */
-+ cwain_outb(cwaintmp,cwain_R_TX_SL0_CFG1,0x31);
-+// cwain_outb(cwaintmp,cwain_R_RX_SL0_CFG1,0x41);
-+ cwain_outb(cwaintmp,cwain_R_RX_SL0_CFG1,0x03);
-+ } else {
-+ /* doubleframe */
-+ cwain_outb(cwaintmp,cwain_R_TX_SL0_CFG1,0x0);
-+// cwain_outb(cwaintmp,cwain_R_RX_SL0_CFG1,0x40);
-+ cwain_outb(cwaintmp,cwain_R_RX_SL0_CFG1,0x02);
-+ }
-+
-+
-+ /* setup sync mode */
-+ if (cwaincard->syncs[span->offset] > 0) {
-+ cwain_outb(cwaintmp,cwain_R_SYNC_CTRL,0x2);
-+ cwain_outb(cwaintmp,cwain_R_SYNC_OUT,0x1);
-+ /* layer 1, here we go! */
-+ cwain_outb(cwaintmp,cwain_R_E1_WR_STA,0x00);
-+ } else {
-+// cwain_outb(cwaintmp,cwain_R_SYNC_CTRL,0x5);
-+ cwain_outb(cwaintmp,cwain_R_SYNC_CTRL,0x7);
-+ cwain_outb(cwaintmp,cwain_R_SYNC_OUT,0x0);
-+ /* layer 1, up! */
-+ cwain_outb(cwaintmp,cwain_R_E1_WR_STA,0x11);
-+ }
-+
-+ cwaintmp->sync = 0;
-+ cwaintmp->sync_sta = 0;
-+
-+ /* enable irqs */
-+ cwain_outb(cwaintmp,cwain_R_IRQ_CTRL, 8 | 1);
-+ spin_unlock_irqrestore(&cwaintmp->lock,flags);
-+
-+ return 0;
-+}
-+
-+static int ztcwain_shutdown(struct zt_span *span) {
-+ struct zt_cwain_card *cwaincard = span->pvt;
-+ struct zt_cwain *cwaintmp;
-+ unsigned long flags;
-+ int alreadyrunning;
-+ int i=0;
-+
-+ if (cwaincard == NULL) {
-+ printk(KERN_CRIT "cwain: cwaincard == NULL!\n");
-+ return 0;
-+ }
-+
-+ cwaintmp = cwaincard->span[span->offset];
-+ if (cwaintmp == NULL) {
-+ printk(KERN_CRIT "cwain: cwaintmp == NULL!\n");
-+ return 0;
-+ }
-+
-+ alreadyrunning = span->flags & ZT_FLAG_RUNNING;
-+
-+ if (!alreadyrunning) {
-+ return 0;
-+ }
-+ spin_lock_irqsave(&cwaintmp->lock,flags);
-+
-+// printk(KERN_CRIT "cwain: stopping card %d span %d/%d.\n",cwaintmp->cardno,span->spanno,span->offset);
-+
-+ // turn off irqs for all fifos
-+
-+ /* disable FIFO TX */
-+ for (i=0; i<0x20 ; i++) {
-+ cwain_outb(cwaintmp,cwain_R_FIFO,i << 1);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_A_IRQ_MSK,0x0);
-+ }
-+
-+ /* disable FIFO RX */
-+ for (i=0; i<0x20 ; i++) {
-+ cwain_outb(cwaintmp,cwain_R_FIFO,(i << 1) | 1);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_A_IRQ_MSK,0x0);
-+ }
-+
-+
-+ /* Deactivate Layer 1 */
-+ cwain_outb(cwaintmp,cwain_R_E1_WR_STA,0x10);
-+
-+ cwain_outb(cwaintmp,cwain_R_IRQ_CTRL, 0);
-+// cwain_outb(cwaintmp,cwain_R_IRQMSK_MISC, 0);
-+ cwain_inb(cwaintmp,cwain_R_STATUS);
-+
-+
-+ span->flags &= ~ZT_FLAG_RUNNING;
-+
-+
-+ spin_unlock_irqrestore(&cwaintmp->lock,flags);
-+
-+// printk(KERN_CRIT "cwain: card %d span %d/%d down.\n",cwaintmp->cardno,span->spanno,span->offset);
-+ return 0;
-+}
-+
-+static int ztcwain_maint(struct zt_span *span, int cmd) {
-+ return 0;
-+}
-+
-+static int ztcwain_chanconfig(struct zt_chan *chan,int sigtype) {
-+// printk(KERN_INFO "chan_config sigtype=%d\n", sigtype);
-+ return 0;
-+}
-+
-+static int ztcwain_spanconfig(struct zt_span *span,struct zt_lineconfig *lc) {
-+ struct zt_cwain_card *cwaincard = span->pvt;
-+ span->lineconfig = lc->lineconfig;
-+ span->syncsrc = lc->sync;
-+
-+ cwaincard->syncs[span->offset] = lc->sync;
-+ cwaincard->syncsrc = -1;
-+// printk(KERN_INFO "span_config %d lineconfig=%d syncsrc=%d\n", span->spanno, lc->lineconfig, lc->sync);
-+// cwain_check_timing(cwaincard);
-+ return 0;
-+}
-+
-+static int ztcwain_initialize(struct zt_cwain *cwaintmp, struct zt_cwain_card *cwaincard, int offset) {
-+ int i=0;
-+
-+ memset(&cwaintmp->span,0,sizeof(struct zt_span)); // you never can tell...
-+ sprintf(cwaintmp->span.name,"cwain/%d",cwaintmp->cardno);
-+ switch (cwaintmp->type) {
-+ case 0xb553:
-+ sprintf(cwaintmp->span.desc,"Junghanns.NET singleE1 PCI ISDN Card %d (cardID %d)",cwaintmp->cardno,cwaintmp->cardID);
-+ break;
-+ case 0xb554:
-+ sprintf(cwaintmp->span.desc,"Junghanns.NET doubleE1 PCI ISDN Card %d (cardID %d) (1 E1 port)",cwaintmp->cardno,cwaintmp->cardID);
-+ break;
-+ default:
-+ return -1;
-+ }
-+ cwaintmp->span.spanconfig = ztcwain_spanconfig;
-+ cwaintmp->span.chanconfig = ztcwain_chanconfig;
-+ cwaintmp->span.startup = ztcwain_startup;
-+ cwaintmp->span.shutdown = ztcwain_shutdown;
-+ cwaintmp->span.maint = ztcwain_maint;
-+ cwaintmp->span.rbsbits = ztcwain_rbsbits;
-+ cwaintmp->span.open = ztcwain_open;
-+ cwaintmp->span.close = ztcwain_close;
-+ cwaintmp->span.ioctl = ztcwain_ioctl;
-+
-+ cwaintmp->span.chans = cwaintmp->chans;
-+ cwaintmp->span.channels = 31;
-+ cwaintmp->span.deflaw = ZT_LAW_ALAW;
-+ cwaintmp->span.linecompat = ZT_CONFIG_AMI | ZT_CONFIG_HDB3 | ZT_CONFIG_CCS;
-+ init_waitqueue_head(&cwaintmp->span.maintq);
-+ cwaintmp->span.pvt = cwaincard;
-+ cwaintmp->span.offset = offset;
-+
-+ for (i=0; i < cwaintmp->span.channels; i++) {
-+ memset(&(cwaintmp->chans[i]),0x0,sizeof(struct zt_chan));
-+ sprintf(cwaintmp->chans[i].name,"cwain%d/%d",cwain_span_count + 1,i + 1);
-+ cwaintmp->chans[i].pvt = cwaintmp;
-+ cwaintmp->chans[i].sigcap = ZT_SIG_CLEAR;
-+ cwaintmp->chans[i].chanpos = i + 1;
-+ }
-+
-+ if (zt_register(&cwaintmp->span,0)) {
-+ printk(KERN_INFO "cwain: unable to register zaptel span!\n");
-+ return -1;
-+ }
-+// printk(KERN_INFO "cwain: registered zaptel span %d.\n",s+1);
-+
-+ return 0;
-+}
-+
-+int cwain_reset_card(struct zt_cwain_card *cwaintmp) {
-+ unsigned long flags;
-+ int i = 0;
-+
-+ cwaintmp->irq = cwaintmp->span[0]->irq;
-+
-+ if (cwaintmp->spans == 2) {
-+ if (request_irq(cwaintmp->irq, cwain_interrupt, SA_INTERRUPT | SA_SHIRQ, "cwain2", cwaintmp)) {
-+ printk(KERN_WARNING "cwain: unable to register irq\n");
-+ return -1;
-+ }
-+ } else {
-+ if (request_irq(cwaintmp->irq, cwain_interrupt, SA_INTERRUPT | SA_SHIRQ, "cwain", cwaintmp)) {
-+ printk(KERN_WARNING "cwain: unable to register irq\n");
-+ return -1;
-+ }
-+ }
-+
-+ spin_lock_irqsave(&(cwaintmp->lock),flags);
-+
-+ for (i=0;i<cwaintmp->spans;i++) {
-+ cwain_reset_span(cwaintmp->span[i]);
-+ }
-+
-+ /* no master yet, force reelection */
-+ cwaintmp->syncsrc = -1;
-+
-+ /* set up the timer 1 khz, zaptel timing */
-+ cwain_outb(cwaintmp->span[0],cwain_R_TI_WD, 0x2);
-+
-+ if (cwaintmp->spans == 2) {
-+ cwain_outb(cwaintmp->span[1],cwain_R_IRQMSK_MISC, 0x1);
-+ }
-+ /* enable timer interrupts */
-+ cwain_outb(cwaintmp->span[0],cwain_R_IRQMSK_MISC, 0x13);
-+
-+ /* Finally enable IRQ output */
-+ cwain_outb(cwaintmp->span[0],cwain_R_IRQ_CTRL, 0x8 | 0x1);
-+
-+ spin_unlock_irqrestore(&(cwaintmp->lock),flags);
-+ return 0;
-+}
-+
-+int cwain_find_spans(unsigned int pcidid) {
-+ struct pci_dev *tmp;
-+ struct zt_cwain *cwaintmp = NULL;
-+ int i=0;
-+ unsigned char dips=0;
-+ int cid=0;
-+ int modes=0;
-+ tmp = pci_find_device(PCI_VENDOR_ID_CCD,pcidid,multi_cwain);
-+ while (tmp != NULL) {
-+ multi_cwain = tmp; // skip this next time.
-+
-+ if (pci_enable_device(tmp)) {
-+ multi_cwain = NULL;
-+ return -1;
-+ }
-+
-+ cwaintmp = kmalloc(sizeof(struct zt_cwain),GFP_KERNEL);
-+ if (!cwaintmp) {
-+ printk(KERN_WARNING "cwain: unable to kmalloc!\n");
-+ pci_disable_device(tmp);
-+ multi_cwain = NULL;
-+ return -ENOMEM;
-+ }
-+ memset(cwaintmp, 0x0, sizeof(struct zt_cwain));
-+
-+ spin_lock_init(&cwaintmp->lock);
-+ cwaintmp->pcidev = tmp;
-+ cwaintmp->pcibus = tmp->bus->number;
-+ cwaintmp->pcidevfn = tmp->devfn;
-+
-+
-+ cwaintmp->pci_io = (char *) tmp->resource[1].start;
-+ if (!cwaintmp->pci_io) {
-+ printk(KERN_WARNING "cwain: no iomem!\n");
-+ pci_disable_device(tmp);
-+ multi_cwain = NULL;
-+ return -EIO;
-+ }
-+
-+ if (!tmp->irq) {
-+ printk(KERN_WARNING "cwain: PCI device has no irq!\n");
-+ pci_disable_device(tmp);
-+ multi_cwain = NULL;
-+ return -EIO;
-+ }
-+
-+ cwaintmp->irq = tmp->irq;
-+
-+ cwaintmp->pci_io = ioremap((ulong) cwaintmp->pci_io, 256);
-+
-+ /* enable memio */
-+ pci_write_config_word(cwaintmp->pcidev, PCI_COMMAND, PCI_COMMAND_MEMORY);
-+
-+ /* disable interrupts */
-+ cwain_outb(cwaintmp,cwain_R_IRQ_CTRL, 0);
-+
-+ if (((tmp->subsystem_device==0xb553) || (tmp->subsystem_device==0xb554))&& (pcidid == PCI_DEVICE_ID_CCD_E)) {
-+ dips = (cwain_inb(cwaintmp,cwain_R_GPI_IN0) >> 5);
-+ cid = 7;
-+ for (i=0;i<3;i++) {
-+ if ((dips & (1 << i)) != 0) {
-+ cid -= (1 << (2-i));
-+ }
-+ }
-+// printk(KERN_INFO "DIPS = %#x CID= %#x\n",dips,cid);
-+ } else {
-+ cid = 0xff;
-+ }
-+
-+ if (ports == -1) {
-+ if ((tmp->subsystem_device==0xb520) && (pcidid == PCI_DEVICE_ID_CCD_E)) {
-+ modes = (cwain_inb(cwaintmp,cwain_R_GPI_IN0) >> 4) & 0x01;
-+ } else {
-+ modes = 0; // assume TE mode
-+ }
-+ } else {
-+ modes = ports >> cwain_span_count;
-+ }
-+
-+
-+ cwaintmp->cardID = cid;
-+ cwaintmp->type = tmp->subsystem_device;
-+
-+ if ((modes & 1) != 0) {
-+ cwaintmp->nt_mode = 1;
-+ } else {
-+ cwaintmp->nt_mode = 0;
-+ }
-+
-+ cwain_register_span(cwaintmp);
-+
-+ tmp = pci_find_device(PCI_VENDOR_ID_CCD,pcidid,multi_cwain);
-+ }
-+ return 0;
-+}
-+
-+
-+int cwain_sort_cards(void) {
-+ int changed=0,tmpcardno;
-+ struct zt_cwain_card *tmpcard,*tmpcard2;
-+ spin_lock(&cwain_card_registerlock);
-+ do {
-+ changed = 0;
-+ tmpcard = cwain_card_list;
-+ while (tmpcard != NULL) {
-+ if (tmpcard->prev) {
-+ if (tmpcard->prev->cardID > tmpcard->cardID) {
-+ tmpcardno = tmpcard->prev->cardno;
-+ tmpcard->prev->cardno = tmpcard->cardno;
-+ tmpcard->cardno = tmpcardno;
-+
-+ tmpcard2 = tmpcard->prev;
-+ if (tmpcard2->prev) {
-+ tmpcard2->prev->next = tmpcard;
-+ } else {
-+ cwain_card_list = tmpcard;
-+ }
-+ if (tmpcard->next) {
-+ tmpcard->next->prev = tmpcard2;
-+ }
-+ tmpcard2->next = tmpcard->next;
-+ tmpcard->prev = tmpcard2->prev;
-+ tmpcard->next = tmpcard2;
-+ tmpcard2->prev = tmpcard;
-+ changed = 1;
-+ tmpcard = tmpcard2;
-+ }
-+ }
-+ tmpcard = tmpcard->next;
-+ }
-+ } while (changed == 1);
-+ spin_unlock(&cwain_card_registerlock);
-+ return 0;
-+}
-+
-+int cwain_zap_cards(void) {
-+ struct zt_cwain_card *tmpcard = cwain_card_list;
-+ int i=0;
-+ int res=0;
-+ while (tmpcard != NULL) {
-+ for (i=0; i<tmpcard->spans; i++) {
-+ ztcwain_initialize(tmpcard->span[i], tmpcard, i);
-+ }
-+ res = cwain_reset_card(tmpcard);
-+ tmpcard = tmpcard->next;
-+ }
-+ return res;
-+}
-+
-+
-+int init_module(void) {
-+ multi_cwain = NULL;
-+ cwain_find_spans(PCI_DEVICE_ID_CCD_E);
-+ cwain_sort_cards();
-+ cwain_zap_cards();
-+ if (cwain_card_count == 0) {
-+ printk(KERN_INFO "cwain: no cwain cards found.\n");
-+ } else {
-+ printk(KERN_INFO "cwain: %d cwain card(s) in this box, %d E1 ports total.\n", cwain_card_count, cwain_span_count);
-+ }
-+ return 0;
-+}
-+
-+void cleanup_module(void) {
-+ struct zt_cwain_card *tmpcard,*tmplist;
-+ struct zt_cwain *tmpspan,*spanlist;
-+ int i=0;
-+ int j=0;
-+
-+ tmplist = cwain_card_list;
-+ tmpcard = NULL;
-+ while (tmplist) {
-+ tmpcard = tmplist;
-+ tmplist = tmplist->next;
-+
-+ tmpcard->dead = 1;
-+ cwain_shutdown_card(tmpcard);
-+ kfree(tmpcard);
-+ i++;
-+ }
-+
-+ spanlist = cwain_span_list;
-+ tmpspan = NULL;
-+ while (spanlist) {
-+ tmpspan = spanlist;
-+ spanlist = spanlist->next;
-+ kfree(tmpspan);
-+ j++;
-+ }
-+ printk(KERN_INFO "cwain: shutdown %d spans, %d cwain cards.\n", j, i);
-+}
-+#endif
-+
-+MODULE_PARM(ports,"i");
-+MODULE_PARM(debug,"i");
-+MODULE_DESCRIPTION("cwain zaptel driver");
-+MODULE_AUTHOR("Klaus-Peter Junghanns <kpj at junghanns.net>");
-+#ifdef MODULE_LICENSE
-+MODULE_LICENSE("GPL");
-+#endif
-diff -urNad zaptel-1.2.1/cwain/cwain.h /tmp/dpep.LWjGif/zaptel-1.2.1/cwain/cwain.h
---- zaptel-1.2.1/cwain/cwain.h 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.LWjGif/zaptel-1.2.1/cwain/cwain.h 2005-09-26 09:59:05.000000000 +0300
-@@ -0,0 +1,238 @@
-+#define cwain_FIFO_SIZE 128
-+#define cwain_DFIFO_SIZE 4096
-+#define cwain_FIFO_HW 13
-+
-+typedef struct zt_cwain {
-+ /* pci resources */
-+ unsigned int irq;
-+ unsigned int iomem;
-+ unsigned char *pci_io;
-+ unsigned int pcibus;
-+ unsigned int pcidevfn;
-+ struct pci_dev *pcidev;
-+ unsigned int type;
-+
-+ /* lock to protect the structure */
-+ spinlock_t lock;
-+ int cardID;
-+ unsigned char cardno;
-+
-+ /* ticks and clicks, fish and chips */
-+ unsigned int ticks;
-+ unsigned int clicks;
-+ unsigned char nt_mode;
-+ unsigned char sync_sta;
-+ unsigned char sync;
-+ int syncmode;
-+
-+ /* blinky blink */
-+ unsigned char leds[4];
-+
-+ /* B chan buffers */
-+ unsigned char rxbuf[30][ZT_CHUNKSIZE];
-+ unsigned char txbuf[30][ZT_CHUNKSIZE];
-+
-+ /* number of RXed dchan frames */
-+ unsigned char drx;
-+ /* D chan buffer */
-+ unsigned char drxbuf[cwain_DFIFO_SIZE];
-+ unsigned char dtxbuf[cwain_DFIFO_SIZE];
-+
-+
-+ /* zaptel resources */
-+ struct zt_span span;
-+ struct zt_chan chans[31];
-+
-+ /* more zaptel stuff */
-+ unsigned int usecount;
-+ int spantype;
-+ int spanflags;
-+
-+ /* linked list */
-+ struct zt_cwain *next;
-+ struct zt_cwain *prev;
-+
-+} zt_cwain;
-+
-+typedef struct zt_cwain_card {
-+ /* lock to protect the structure */
-+ spinlock_t lock;
-+
-+ unsigned int spans;
-+ unsigned int dead;
-+ int cardID;
-+ unsigned char cardno;
-+ unsigned int ticks;
-+
-+ struct zt_cwain *span[2];
-+ int syncsrc;
-+ int syncs[2];
-+ int master[2];
-+
-+ unsigned int irq;
-+ unsigned int pcibus;
-+
-+ /* linked list */
-+ struct zt_cwain_card *next;
-+ struct zt_cwain_card *prev;
-+} zt_cwain_card;
-+
-+#define cwain_outb(a,b,c) (writeb((c),(a)->pci_io+(b)))
-+#define cwain_inb(a,b) (readb((a)->pci_io+(b)))
-+
-+#define cwain_outw(a,b,c) (writew((c),(a)->pci_io+(b)))
-+#define cwain_inw(a,b) (readw((a)->pci_io+(b)))
-+
-+#define cwain_outdw(a,b,c) (writel((c),(a)->pci_io+(b)))
-+#define cwain_indw(a,b) (readl((a)->pci_io+(b)))
-+
-+
-+/* Write only registers */
-+#define cwain_A_CH_MSK 0xF4
-+#define cwain_A_CHANNEL 0xFC
-+#define cwain_A_CON_HDLC 0xFA
-+#define cwain_A_CONF 0xD1
-+#define cwain_A_FIFO_SEQ 0xFD
-+#define cwain_R_INC_RES_FIFO 0x0E
-+#define cwain_A_IRQ_MSK 0xFF
-+#define cwain_A_SL_CFG 0xD0
-+#define cwain_A_SUBCH_CFG 0xFB
-+#define cwain_R_BERT_WD_MD 0x1B
-+#define cwain_R_BRG_PCM_CFG 0x02
-+#define cwain_R_CIRM 0x00
-+#define cwain_R_CONF_EN 0x18
-+#define cwain_R_CTRL 0x01
-+#define cwain_R_DTMF 0x1C
-+#define cwain_R_DTMF_N 0x1D
-+#define cwain_R_E1_WR_STA 0x20
-+#define cwain_R_FIFO_MD 0x0D
-+#define cwain_R_FIFO 0x0F
-+#define cwain_R_FIRST_FIFO 0x0B
-+#define cwain_R_FSM_IDX 0x0F
-+#define cwain_R_GPIO_EN0 0x42
-+#define cwain_R_GPIO_EN1 0x43
-+#define cwain_R_GPIO_OUT0 0x40
-+#define cwain_R_GPIO_OUT1 0x41
-+#define cwain_R_GPIO_SEL 0x44
-+#define cwain_R_IRQ_CTRL 0x13
-+#define cwain_R_IRQMSK_MISC 0x11
-+#define cwain_R_JATT_CFG 0x2F
-+#define cwain_R_LOS0 0x22
-+#define cwain_R_LOS1 0x23
-+#define cwain_R_PCM_MD0 0x14
-+#define cwain_R_PCM_MD1 0x15
-+#define cwain_R_PCM_MD2 0x15
-+#define cwain_R_PWM_MD 0x46
-+#define cwain_R_PWM0 0x38
-+#define cwain_R_PWM1 0x39
-+#define cwain_R_RAM_ADDR0 0x08
-+#define cwain_R_RAM_ADDR1 0x09
-+#define cwain_R_RAM_ADDR2 0x0A
-+#define cwain_R_RAM_MISC 0x0C
-+#define cwain_R_RX_OFFS 0x30
-+#define cwain_R_RX_SL0_CFG0 0x25
-+#define cwain_R_RX_SL0_CFG1 0x26
-+#define cwain_R_RX0 0x24
-+#define cwain_R_SH0H 0x15
-+#define cwain_R_SH0L 0x15
-+#define cwain_R_SH1H 0x15
-+#define cwain_R_SH1L 0x15
-+#define cwain_R_SL_SEL0 0x15
-+#define cwain_R_SL_SEL1 0x15
-+#define cwain_R_SL_SEL2 0x15
-+#define cwain_R_SL_SEL3 0x15
-+#define cwain_R_SL_SEL4 0x15
-+#define cwain_R_SL_SEL5 0x15
-+#define cwain_R_SL_SEL6 0x15
-+#define cwain_R_SL_SEL7 0x15
-+#define cwain_R_SLOT 0x10
-+#define cwain_R_SYNC_CTRL 0x35
-+#define cwain_R_SYNC_OUT 0x31
-+#define cwain_R_TI_WD 0x1A
-+#define cwain_R_TX_OFFS 0x34
-+#define cwain_R_TX_SL0_CFG0 0x2C
-+#define cwain_R_TX_SL0_CFG1 0x2E
-+#define cwain_R_TX_SL0 0x2D
-+#define cwain_R_TX0 0x28
-+#define cwain_R_TX1 0x29
-+
-+#define cwain_R_TX_FR0 0x2C
-+#define cwain_R_TX_FR1 0x2D
-+#define cwain_R_TX_FR2 0x2E
-+
-+#define cwain_R_RX_FR0 0x25
-+#define cwain_R_RX_FR1 0x26
-+
-+/* Read only registers */
-+#define cwain_A_F1 0x0C
-+#define cwain_A_F12 0x0C
-+#define cwain_A_F2 0x0D
-+#define cwain_A_Z1 0x04
-+#define cwain_A_Z12 0x04
-+#define cwain_A_Z1H 0x05
-+#define cwain_A_Z1L 0x04
-+#define cwain_A_Z2 0x06
-+#define cwain_A_Z2H 0x07
-+#define cwain_A_Z2L 0x06
-+#define cwain_R_BERT_ECH 0x1B
-+#define cwain_R_BERT_ECL 0x1A
-+#define cwain_R_BERT_STA 0x17
-+#define cwain_R_CHIP_ID 0x16
-+#define cwain_R_CHIP_RV 0x1F
-+#define cwain_R_CONF_OFLOW 0x14
-+#define cwain_R_CRC_ECH 0x35
-+#define cwain_R_CRC_ECL 0x34
-+#define cwain_R_E_ECH 0x37
-+#define cwain_R_E_ECL 0x36
-+#define cwain_R_E1_RD_STA 0x20
-+#define cwain_R_F0_CNTH 0x19
-+#define cwain_R_F0_CNTL 0x18
-+#define cwain_R_FAS_ECH 0x31
-+#define cwain_R_FAS_ECL 0x30
-+#define cwain_R_GPI_IN0 0x44
-+#define cwain_R_GPI_IN1 0x45
-+#define cwain_R_GPI_IN2 0x46
-+#define cwain_R_GPI_IN3 0x47
-+#define cwain_R_GPIO_IN0 0x40
-+#define cwain_R_GPIO_IN1 0x41
-+#define cwain_R_INT_DATA 0x88
-+#define cwain_R_IRQ_FIFO_BL0 0xC8
-+#define cwain_R_IRQ_FIFO_BL1 0xC9
-+#define cwain_R_IRQ_FIFO_BL2 0xCA
-+#define cwain_R_IRQ_FIFO_BL3 0xCB
-+#define cwain_R_IRQ_FIFO_BL4 0xCC
-+#define cwain_R_IRQ_FIFO_BL5 0xCD
-+#define cwain_R_IRQ_FIFO_BL6 0xCE
-+#define cwain_R_IRQ_FIFO_BL7 0xCF
-+#define cwain_R_IRQ_MISC 0x11
-+#define cwain_R_IRQ_OVIEW 0x10
-+#define cwain_R_JATT_STA 0x2B
-+#define cwain_R_RAM_USE 0x15
-+#define cwain_R_RX_SL0_0 0x25
-+#define cwain_R_RX_SL0_1 0x26
-+#define cwain_R_RX_SL0_2 0x27
-+#define cwain_R_SA6_VAL13_ECH 0x39
-+#define cwain_R_SA6_VAL13_ECL 0x38
-+#define cwain_R_SA6_VAL23_ECH 0x3B
-+#define cwain_R_SA6_VAL23_ECL 0x3A
-+#define cwain_R_SLIP 0x2C
-+#define cwain_R_STATUS 0x1C
-+#define cwain_R_SYNC_STA 0x24
-+#define cwain_R_VIO_ECH 0x33
-+#define cwain_R_VIO_ECL 0x32
-+
-+
-+/* Read/Write registers */
-+#define cwain_A_FIFO_DATA0_NOINC 0x84
-+#define cwain_A_FIFO_DATA0 0x80
-+#define cwain_A_FIFO_DATA1_NOINC 0x84
-+#define cwain_A_FIFO_DATA1 0x80
-+#define cwain_A_FIFO_DATA2_NOINC 0x84
-+#define cwain_A_FIFO_DATA2 0x80
-+#define cwain_R_RAM_DATA 0xC0
-+
-+#define PCI_DEVICE_ID_CCD_E 0x30b1
-+
-+#define CLKDEL_TE 0xe /* CLKDEL in TE mode */
-+#define CLKDEL_NT 0xc /* CLKDEL in NT mode */
-+
-diff -urNad zaptel-1.2.1/cwain/LICENSE /tmp/dpep.LWjGif/zaptel-1.2.1/cwain/LICENSE
---- zaptel-1.2.1/cwain/LICENSE 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.LWjGif/zaptel-1.2.1/cwain/LICENSE 2005-09-26 09:59:05.000000000 +0300
-@@ -0,0 +1,341 @@
-+
-+ GNU GENERAL PUBLIC LICENSE
-+ Version 2, June 1991
-+
-+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-+ Everyone is permitted to copy and distribute verbatim copies
-+ of this license document, but changing it is not allowed.
-+
-+ Preamble
-+
-+ The licenses for most software are designed to take away your
-+freedom to share and change it. By contrast, the GNU General Public
-+License is intended to guarantee your freedom to share and change free
-+software--to make sure the software is free for all its users. This
-+General Public License applies to most of the Free Software
-+Foundation's software and to any other program whose authors commit to
-+using it. (Some other Free Software Foundation software is covered by
-+the GNU Library General Public License instead.) You can apply it to
-+your programs, too.
-+
-+ When we speak of free software, we are referring to freedom, not
-+price. Our General Public Licenses are designed to make sure that you
-+have the freedom to distribute copies of free software (and charge for
-+this service if you wish), that you receive source code or can get it
-+if you want it, that you can change the software or use pieces of it
-+in new free programs; and that you know you can do these things.
-+
-+ To protect your rights, we need to make restrictions that forbid
-+anyone to deny you these rights or to ask you to surrender the rights.
-+These restrictions translate to certain responsibilities for you if you
-+distribute copies of the software, or if you modify it.
-+
-+ For example, if you distribute copies of such a program, whether
-+gratis or for a fee, you must give the recipients all the rights that
-+you have. You must make sure that they, too, receive or can get the
-+source code. And you must show them these terms so they know their
-+rights.
-+
-+ We protect your rights with two steps: (1) copyright the software, and
-+(2) offer you this license which gives you legal permission to copy,
-+distribute and/or modify the software.
-+
-+ Also, for each author's protection and ours, we want to make certain
-+that everyone understands that there is no warranty for this free
-+software. If the software is modified by someone else and passed on, we
-+want its recipients to know that what they have is not the original, so
-+that any problems introduced by others will not reflect on the original
-+authors' reputations.
-+
-+ Finally, any free program is threatened constantly by software
-+patents. We wish to avoid the danger that redistributors of a free
-+program will individually obtain patent licenses, in effect making the
-+program proprietary. To prevent this, we have made it clear that any
-+patent must be licensed for everyone's free use or not licensed at all.
-+
-+ The precise terms and conditions for copying, distribution and
-+modification follow.
-+
-+ GNU GENERAL PUBLIC LICENSE
-+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-+
-+ 0. This License applies to any program or other work which contains
-+a notice placed by the copyright holder saying it may be distributed
-+under the terms of this General Public License. The "Program", below,
-+refers to any such program or work, and a "work based on the Program"
-+means either the Program or any derivative work under copyright law:
-+that is to say, a work containing the Program or a portion of it,
-+either verbatim or with modifications and/or translated into another
-+language. (Hereinafter, translation is included without limitation in
-+the term "modification".) Each licensee is addressed as "you".
-+
-+Activities other than copying, distribution and modification are not
-+covered by this License; they are outside its scope. The act of
-+running the Program is not restricted, and the output from the Program
-+is covered only if its contents constitute a work based on the
-+Program (independent of having been made by running the Program).
-+Whether that is true depends on what the Program does.
-+
-+ 1. You may copy and distribute verbatim copies of the Program's
-+source code as you receive it, in any medium, provided that you
-+conspicuously and appropriately publish on each copy an appropriate
-+copyright notice and disclaimer of warranty; keep intact all the
-+notices that refer to this License and to the absence of any warranty;
-+and give any other recipients of the Program a copy of this License
-+along with the Program.
-+
-+You may charge a fee for the physical act of transferring a copy, and
-+you may at your option offer warranty protection in exchange for a fee.
-+
-+ 2. You may modify your copy or copies of the Program or any portion
-+of it, thus forming a work based on the Program, and copy and
-+distribute such modifications or work under the terms of Section 1
-+above, provided that you also meet all of these conditions:
-+
-+ a) You must cause the modified files to carry prominent notices
-+ stating that you changed the files and the date of any change.
-+
-+ b) You must cause any work that you distribute or publish, that in
-+ whole or in part contains or is derived from the Program or any
-+ part thereof, to be licensed as a whole at no charge to all third
-+ parties under the terms of this License.
-+
-+ c) If the modified program normally reads commands interactively
-+ when run, you must cause it, when started running for such
-+ interactive use in the most ordinary way, to print or display an
-+ announcement including an appropriate copyright notice and a
-+ notice that there is no warranty (or else, saying that you provide
-+ a warranty) and that users may redistribute the program under
-+ these conditions, and telling the user how to view a copy of this
-+ License. (Exception: if the Program itself is interactive but
-+ does not normally print such an announcement, your work based on
-+ the Program is not required to print an announcement.)
-+
-+These requirements apply to the modified work as a whole. If
-+identifiable sections of that work are not derived from the Program,
-+and can be reasonably considered independent and separate works in
-+themselves, then this License, and its terms, do not apply to those
-+sections when you distribute them as separate works. But when you
-+distribute the same sections as part of a whole which is a work based
-+on the Program, the distribution of the whole must be on the terms of
-+this License, whose permissions for other licensees extend to the
-+entire whole, and thus to each and every part regardless of who wrote it.
-+
-+Thus, it is not the intent of this section to claim rights or contest
-+your rights to work written entirely by you; rather, the intent is to
-+exercise the right to control the distribution of derivative or
-+collective works based on the Program.
-+
-+In addition, mere aggregation of another work not based on the Program
-+with the Program (or with a work based on the Program) on a volume of
-+a storage or distribution medium does not bring the other work under
-+the scope of this License.
-+
-+ 3. You may copy and distribute the Program (or a work based on it,
-+under Section 2) in object code or executable form under the terms of
-+Sections 1 and 2 above provided that you also do one of the following:
-+
-+ a) Accompany it with the complete corresponding machine-readable
-+ source code, which must be distributed under the terms of Sections
-+ 1 and 2 above on a medium customarily used for software interchange; or,
-+
-+ b) Accompany it with a written offer, valid for at least three
-+ years, to give any third party, for a charge no more than your
-+ cost of physically performing source distribution, a complete
-+ machine-readable copy of the corresponding source code, to be
-+ distributed under the terms of Sections 1 and 2 above on a medium
-+ customarily used for software interchange; or,
-+
-+ c) Accompany it with the information you received as to the offer
-+ to distribute corresponding source code. (This alternative is
-+ allowed only for noncommercial distribution and only if you
-+ received the program in object code or executable form with such
-+ an offer, in accord with Subsection b above.)
-+
-+The source code for a work means the preferred form of the work for
-+making modifications to it. For an executable work, complete source
-+code means all the source code for all modules it contains, plus any
-+associated interface definition files, plus the scripts used to
-+control compilation and installation of the executable. However, as a
-+special exception, the source code distributed need not include
-+anything that is normally distributed (in either source or binary
-+form) with the major components (compiler, kernel, and so on) of the
-+operating system on which the executable runs, unless that component
-+itself accompanies the executable.
-+
-+If distribution of executable or object code is made by offering
-+access to copy from a designated place, then offering equivalent
-+access to copy the source code from the same place counts as
-+distribution of the source code, even though third parties are not
-+compelled to copy the source along with the object code.
-+
-+ 4. You may not copy, modify, sublicense, or distribute the Program
-+except as expressly provided under this License. Any attempt
-+otherwise to copy, modify, sublicense or distribute the Program is
-+void, and will automatically terminate your rights under this License.
-+However, parties who have received copies, or rights, from you under
-+this License will not have their licenses terminated so long as such
-+parties remain in full compliance.
-+
-+ 5. You are not required to accept this License, since you have not
-+signed it. However, nothing else grants you permission to modify or
-+distribute the Program or its derivative works. These actions are
-+prohibited by law if you do not accept this License. Therefore, by
-+modifying or distributing the Program (or any work based on the
-+Program), you indicate your acceptance of this License to do so, and
-+all its terms and conditions for copying, distributing or modifying
-+the Program or works based on it.
-+
-+ 6. Each time you redistribute the Program (or any work based on the
-+Program), the recipient automatically receives a license from the
-+original licensor to copy, distribute or modify the Program subject to
-+these terms and conditions. You may not impose any further
-+restrictions on the recipients' exercise of the rights granted herein.
-+You are not responsible for enforcing compliance by third parties to
-+this License.
-+
-+ 7. If, as a consequence of a court judgment or allegation of patent
-+infringement or for any other reason (not limited to patent issues),
-+conditions are imposed on you (whether by court order, agreement or
-+otherwise) that contradict the conditions of this License, they do not
-+excuse you from the conditions of this License. If you cannot
-+distribute so as to satisfy simultaneously your obligations under this
-+License and any other pertinent obligations, then as a consequence you
-+may not distribute the Program at all. For example, if a patent
-+license would not permit royalty-free redistribution of the Program by
-+all those who receive copies directly or indirectly through you, then
-+the only way you could satisfy both it and this License would be to
-+refrain entirely from distribution of the Program.
-+
-+If any portion of this section is held invalid or unenforceable under
-+any particular circumstance, the balance of the section is intended to
-+apply and the section as a whole is intended to apply in other
-+circumstances.
-+
-+It is not the purpose of this section to induce you to infringe any
-+patents or other property right claims or to contest validity of any
-+such claims; this section has the sole purpose of protecting the
-+integrity of the free software distribution system, which is
-+implemented by public license practices. Many people have made
-+generous contributions to the wide range of software distributed
-+through that system in reliance on consistent application of that
-+system; it is up to the author/donor to decide if he or she is willing
-+to distribute software through any other system and a licensee cannot
-+impose that choice.
-+
-+This section is intended to make thoroughly clear what is believed to
-+be a consequence of the rest of this License.
-+
-+ 8. If the distribution and/or use of the Program is restricted in
-+certain countries either by patents or by copyrighted interfaces, the
-+original copyright holder who places the Program under this License
-+may add an explicit geographical distribution limitation excluding
-+those countries, so that distribution is permitted only in or among
-+countries not thus excluded. In such case, this License incorporates
-+the limitation as if written in the body of this License.
-+
-+ 9. The Free Software Foundation may publish revised and/or new versions
-+of the General Public License from time to time. Such new versions will
-+be similar in spirit to the present version, but may differ in detail to
-+address new problems or concerns.
-+
-+Each version is given a distinguishing version number. If the Program
-+specifies a version number of this License which applies to it and "any
-+later version", you have the option of following the terms and conditions
-+either of that version or of any later version published by the Free
-+Software Foundation. If the Program does not specify a version number of
-+this License, you may choose any version ever published by the Free Software
-+Foundation.
-+
-+ 10. If you wish to incorporate parts of the Program into other free
-+programs whose distribution conditions are different, write to the author
-+to ask for permission. For software which is copyrighted by the Free
-+Software Foundation, write to the Free Software Foundation; we sometimes
-+make exceptions for this. Our decision will be guided by the two goals
-+of preserving the free status of all derivatives of our free software and
-+of promoting the sharing and reuse of software generally.
-+
-+ NO WARRANTY
-+
-+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-+REPAIR OR CORRECTION.
-+
-+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-+POSSIBILITY OF SUCH DAMAGES.
-+
-+ END OF TERMS AND CONDITIONS
-+
-+ How to Apply These Terms to Your New Programs
-+
-+ If you develop a new program, and you want it to be of the greatest
-+possible use to the public, the best way to achieve this is to make it
-+free software which everyone can redistribute and change under these terms.
-+
-+ To do so, attach the following notices to the program. It is safest
-+to attach them to the start of each source file to most effectively
-+convey the exclusion of warranty; and each file should have at least
-+the "copyright" line and a pointer to where the full notice is found.
-+
-+ <one line to give the program's name and a brief idea of what it does.>
-+ Copyright (C) 19yy <name of author>
-+
-+ This program is free software; you can redistribute it and/or modify
-+ it under the terms of the GNU General Public License as published by
-+ the Free Software Foundation; either version 2 of the License, or
-+ (at your option) any later version.
-+
-+ This program is distributed in the hope that it will be useful,
-+ but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ GNU General Public License for more details.
-+
-+ You should have received a copy of the GNU General Public License
-+ along with this program; if not, write to the Free Software
-+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-+
-+
-+Also add information on how to contact you by electronic and paper mail.
-+
-+If the program is interactive, make it output a short notice like this
-+when it starts in an interactive mode:
-+
-+ Gnomovision version 69, Copyright (C) 19yy name of author
-+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-+ This is free software, and you are welcome to redistribute it
-+ under certain conditions; type `show c' for details.
-+
-+The hypothetical commands `show w' and `show c' should show the appropriate
-+parts of the General Public License. Of course, the commands you use may
-+be called something other than `show w' and `show c'; they could even be
-+mouse-clicks or menu items--whatever suits your program.
-+
-+You should also get your employer (if you work as a programmer) or your
-+school, if any, to sign a "copyright disclaimer" for the program, if
-+necessary. Here is a sample; alter the names:
-+
-+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
-+
-+ <signature of Ty Coon>, 1 April 1989
-+ Ty Coon, President of Vice
-+
-+This General Public License does not permit incorporating your program into
-+proprietary programs. If your program is a subroutine library, you may
-+consider it more useful to permit linking proprietary applications with the
-+library. If this is what you want to do, use the GNU Library General
-+Public License instead of this License.
-diff -urNad zaptel-1.2.1/cwain/Makefile /tmp/dpep.LWjGif/zaptel-1.2.1/cwain/Makefile
---- zaptel-1.2.1/cwain/Makefile 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.LWjGif/zaptel-1.2.1/cwain/Makefile 2005-12-21 15:44:12.000000000 +0200
-@@ -0,0 +1,90 @@
-+KINCLUDES = /usr/src/linux/include
-+BRISTUFFBASE = $(shell dirname `pwd`)
-+
-+ZAP = $(shell [ -f $(BRISTUFFBASE)/zaptel-1.2.1/zaptel.h ] && echo "-I$(BRISTUFFBASE)/zaptel-1.2.1")
-+
-+HOSTCC=gcc
-+
-+CFLAGS+=-I. $(ZAP) -O4 -g -Wall #-DBLINKYBLINK
-+CFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-fsigned-char"; fi)
-+
-+KFLAGS=-D__KERNEL__ -DMODULE -DEXPORT_SYMTAB -fomit-frame-pointer -O2 -Wall -I$(KINCLUDES) $(ZAP)
-+KFLAGS+=$(shell [ -f $(KINCLUDES)/linux/modversions.h ] && echo "-DMODVERSIONS -include $(KINCLUDES)/linux/modversions.h")
-+KFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-msoft-float -fsigned-char"; fi)
-+
-+OBJS=cwain.o
-+
-+BUILDVER=$(shell if uname -r | grep -q ^2.6; then echo "linux26"; else echo "linux24"; fi)
-+
-+MODCONF=$(shell if [ -d $(INSTALL_PREFIX)/etc/modprobe.d ]; then echo "$(INSTALL_PREFIX)/etc/modprobe.d/zaptel"; elif [ -d $(INSTALL_PREFIX)/etc/modutils ]; then echo "$(INSTALL_PREFIX)/etc/modutils/zaptel"; elif [ -f $(INSTALL_PREFIX)/etc/modprobe.conf ]; then echo "$(INSTALL_PREFIX)/modprobe.conf"; elif [ -f $(INSTALL_PREFIX)/etc/modules.conf ]; then echo "$(INSTALL_PREFIX)/etc/modules.conf"; else echo $(INSTALL_PREFIX)/etc/conf.modules ; fi)
-+
-+MODULES=cwain
-+
-+MODULESO=$(shell for x in $(MODULES); do echo "$$x.o "; done )
-+MODULESKO=$(shell for x in $(MODULES); do echo "$$x.ko "; done )
-+
-+PWD=$(shell pwd)
-+
-+obj-m := $(MODULESO)
-+
-+all: $(BUILDVER)
-+
-+linux24: $(OBJS)
-+ sync
-+
-+linux26:
-+ @if ! [ -d /usr/src/linux-2.6 ]; then echo "Link /usr/src/linux-2.6 to your kernel sources first!"; exit 1 ; fi
-+ make -C /usr/src/linux-2.6 SUBDIRS=$(PWD) ZAP=$(ZAP) modules
-+obj-m := $(OBJS)
-+
-+cwain.o: cwain.c cwain.h
-+ $(CC) -c cwain.c $(KFLAGS)
-+
-+clean:
-+ rm -f $(OBJS) *.ko *.mod.c *.mod.o .*o.cmd *~
-+
-+testlinux24: all
-+ modprobe zaptel
-+ insmod ./cwain.o
-+ ztcfg -v
-+ cat /proc/interrupts
-+ sleep 1
-+ cat /proc/interrupts
-+ rmmod cwain zaptel
-+
-+testlinux26: all
-+ modprobe zaptel
-+ insmod ./cwain.ko
-+ ztcfg -v
-+ cat /proc/interrupts
-+ sleep 5
-+ cat /proc/interrupts
-+ rmmod cwain zaptel
-+
-+reload: unload load
-+load: load$(BUILDVER)
-+
-+test: test$(BUILDVER)
-+
-+
-+loadlinux24: linux24
-+ modprobe zaptel
-+ insmod ./cwain.o
-+ ztcfg -v
-+
-+loadlinux26: linux26
-+ sync
-+ modprobe zaptel
-+ insmod ./cwain.ko debug=1
-+ ztcfg -v
-+
-+install: install$(BUILDVER)
-+
-+installlinux26:
-+ install -D -m 644 cwain.ko $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/cwain.ko
-+
-+installlinux24:
-+ install -D -m 644 cwain.o $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/cwain.o
-+
-+unload:
-+ rmmod cwain zaptel
-diff -urNad zaptel-1.2.1/cwain/TODO /tmp/dpep.LWjGif/zaptel-1.2.1/cwain/TODO
---- zaptel-1.2.1/cwain/TODO 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.LWjGif/zaptel-1.2.1/cwain/TODO 2005-09-26 09:59:05.000000000 +0300
-@@ -0,0 +1 @@
-+
-diff -urNad zaptel-1.2.1/cwain/zaptel.conf /tmp/dpep.LWjGif/zaptel-1.2.1/cwain/zaptel.conf
---- zaptel-1.2.1/cwain/zaptel.conf 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.LWjGif/zaptel-1.2.1/cwain/zaptel.conf 2005-10-27 11:26:41.000000000 +0200
-@@ -0,0 +1,11 @@
-+loadzone=nl
-+defaultzone=nl
-+span=1,2,3,ccs,hdb3,crc4
-+
-+alaw=1-31
-+
-+bchan=1-15
-+dchan=16
-+bchan=17-31
-+
-+
-diff -urNad zaptel-1.2.1/qozap/LICENSE /tmp/dpep.LWjGif/zaptel-1.2.1/qozap/LICENSE
---- zaptel-1.2.1/qozap/LICENSE 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.LWjGif/zaptel-1.2.1/qozap/LICENSE 2005-06-13 10:03:36.000000000 +0300
-@@ -0,0 +1,341 @@
-+
-+ GNU GENERAL PUBLIC LICENSE
-+ Version 2, June 1991
-+
-+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-+ Everyone is permitted to copy and distribute verbatim copies
-+ of this license document, but changing it is not allowed.
-+
-+ Preamble
-+
-+ The licenses for most software are designed to take away your
-+freedom to share and change it. By contrast, the GNU General Public
-+License is intended to guarantee your freedom to share and change free
-+software--to make sure the software is free for all its users. This
-+General Public License applies to most of the Free Software
-+Foundation's software and to any other program whose authors commit to
-+using it. (Some other Free Software Foundation software is covered by
-+the GNU Library General Public License instead.) You can apply it to
-+your programs, too.
-+
-+ When we speak of free software, we are referring to freedom, not
-+price. Our General Public Licenses are designed to make sure that you
-+have the freedom to distribute copies of free software (and charge for
-+this service if you wish), that you receive source code or can get it
-+if you want it, that you can change the software or use pieces of it
-+in new free programs; and that you know you can do these things.
-+
-+ To protect your rights, we need to make restrictions that forbid
-+anyone to deny you these rights or to ask you to surrender the rights.
-+These restrictions translate to certain responsibilities for you if you
-+distribute copies of the software, or if you modify it.
-+
-+ For example, if you distribute copies of such a program, whether
-+gratis or for a fee, you must give the recipients all the rights that
-+you have. You must make sure that they, too, receive or can get the
-+source code. And you must show them these terms so they know their
-+rights.
-+
-+ We protect your rights with two steps: (1) copyright the software, and
-+(2) offer you this license which gives you legal permission to copy,
-+distribute and/or modify the software.
-+
-+ Also, for each author's protection and ours, we want to make certain
-+that everyone understands that there is no warranty for this free
-+software. If the software is modified by someone else and passed on, we
-+want its recipients to know that what they have is not the original, so
-+that any problems introduced by others will not reflect on the original
-+authors' reputations.
-+
-+ Finally, any free program is threatened constantly by software
-+patents. We wish to avoid the danger that redistributors of a free
-+program will individually obtain patent licenses, in effect making the
-+program proprietary. To prevent this, we have made it clear that any
-+patent must be licensed for everyone's free use or not licensed at all.
-+
-+ The precise terms and conditions for copying, distribution and
-+modification follow.
-+
-+ GNU GENERAL PUBLIC LICENSE
-+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-+
-+ 0. This License applies to any program or other work which contains
-+a notice placed by the copyright holder saying it may be distributed
-+under the terms of this General Public License. The "Program", below,
-+refers to any such program or work, and a "work based on the Program"
-+means either the Program or any derivative work under copyright law:
-+that is to say, a work containing the Program or a portion of it,
-+either verbatim or with modifications and/or translated into another
-+language. (Hereinafter, translation is included without limitation in
-+the term "modification".) Each licensee is addressed as "you".
-+
-+Activities other than copying, distribution and modification are not
-+covered by this License; they are outside its scope. The act of
-+running the Program is not restricted, and the output from the Program
-+is covered only if its contents constitute a work based on the
-+Program (independent of having been made by running the Program).
-+Whether that is true depends on what the Program does.
-+
-+ 1. You may copy and distribute verbatim copies of the Program's
-+source code as you receive it, in any medium, provided that you
-+conspicuously and appropriately publish on each copy an appropriate
-+copyright notice and disclaimer of warranty; keep intact all the
-+notices that refer to this License and to the absence of any warranty;
-+and give any other recipients of the Program a copy of this License
-+along with the Program.
-+
-+You may charge a fee for the physical act of transferring a copy, and
-+you may at your option offer warranty protection in exchange for a fee.
-+
-+ 2. You may modify your copy or copies of the Program or any portion
-+of it, thus forming a work based on the Program, and copy and
-+distribute such modifications or work under the terms of Section 1
-+above, provided that you also meet all of these conditions:
-+
-+ a) You must cause the modified files to carry prominent notices
-+ stating that you changed the files and the date of any change.
-+
-+ b) You must cause any work that you distribute or publish, that in
-+ whole or in part contains or is derived from the Program or any
-+ part thereof, to be licensed as a whole at no charge to all third
-+ parties under the terms of this License.
-+
-+ c) If the modified program normally reads commands interactively
-+ when run, you must cause it, when started running for such
-+ interactive use in the most ordinary way, to print or display an
-+ announcement including an appropriate copyright notice and a
-+ notice that there is no warranty (or else, saying that you provide
-+ a warranty) and that users may redistribute the program under
-+ these conditions, and telling the user how to view a copy of this
-+ License. (Exception: if the Program itself is interactive but
-+ does not normally print such an announcement, your work based on
-+ the Program is not required to print an announcement.)
-+
-+These requirements apply to the modified work as a whole. If
-+identifiable sections of that work are not derived from the Program,
-+and can be reasonably considered independent and separate works in
-+themselves, then this License, and its terms, do not apply to those
-+sections when you distribute them as separate works. But when you
-+distribute the same sections as part of a whole which is a work based
-+on the Program, the distribution of the whole must be on the terms of
-+this License, whose permissions for other licensees extend to the
-+entire whole, and thus to each and every part regardless of who wrote it.
-+
-+Thus, it is not the intent of this section to claim rights or contest
-+your rights to work written entirely by you; rather, the intent is to
-+exercise the right to control the distribution of derivative or
-+collective works based on the Program.
-+
-+In addition, mere aggregation of another work not based on the Program
-+with the Program (or with a work based on the Program) on a volume of
-+a storage or distribution medium does not bring the other work under
-+the scope of this License.
-+
-+ 3. You may copy and distribute the Program (or a work based on it,
-+under Section 2) in object code or executable form under the terms of
-+Sections 1 and 2 above provided that you also do one of the following:
-+
-+ a) Accompany it with the complete corresponding machine-readable
-+ source code, which must be distributed under the terms of Sections
-+ 1 and 2 above on a medium customarily used for software interchange; or,
-+
-+ b) Accompany it with a written offer, valid for at least three
-+ years, to give any third party, for a charge no more than your
-+ cost of physically performing source distribution, a complete
-+ machine-readable copy of the corresponding source code, to be
-+ distributed under the terms of Sections 1 and 2 above on a medium
-+ customarily used for software interchange; or,
-+
-+ c) Accompany it with the information you received as to the offer
-+ to distribute corresponding source code. (This alternative is
-+ allowed only for noncommercial distribution and only if you
-+ received the program in object code or executable form with such
-+ an offer, in accord with Subsection b above.)
-+
-+The source code for a work means the preferred form of the work for
-+making modifications to it. For an executable work, complete source
-+code means all the source code for all modules it contains, plus any
-+associated interface definition files, plus the scripts used to
-+control compilation and installation of the executable. However, as a
-+special exception, the source code distributed need not include
-+anything that is normally distributed (in either source or binary
-+form) with the major components (compiler, kernel, and so on) of the
-+operating system on which the executable runs, unless that component
-+itself accompanies the executable.
-+
-+If distribution of executable or object code is made by offering
-+access to copy from a designated place, then offering equivalent
-+access to copy the source code from the same place counts as
-+distribution of the source code, even though third parties are not
-+compelled to copy the source along with the object code.
-+
-+ 4. You may not copy, modify, sublicense, or distribute the Program
-+except as expressly provided under this License. Any attempt
-+otherwise to copy, modify, sublicense or distribute the Program is
-+void, and will automatically terminate your rights under this License.
-+However, parties who have received copies, or rights, from you under
-+this License will not have their licenses terminated so long as such
-+parties remain in full compliance.
-+
-+ 5. You are not required to accept this License, since you have not
-+signed it. However, nothing else grants you permission to modify or
-+distribute the Program or its derivative works. These actions are
-+prohibited by law if you do not accept this License. Therefore, by
-+modifying or distributing the Program (or any work based on the
-+Program), you indicate your acceptance of this License to do so, and
-+all its terms and conditions for copying, distributing or modifying
-+the Program or works based on it.
-+
-+ 6. Each time you redistribute the Program (or any work based on the
-+Program), the recipient automatically receives a license from the
-+original licensor to copy, distribute or modify the Program subject to
-+these terms and conditions. You may not impose any further
-+restrictions on the recipients' exercise of the rights granted herein.
-+You are not responsible for enforcing compliance by third parties to
-+this License.
-+
-+ 7. If, as a consequence of a court judgment or allegation of patent
-+infringement or for any other reason (not limited to patent issues),
-+conditions are imposed on you (whether by court order, agreement or
-+otherwise) that contradict the conditions of this License, they do not
-+excuse you from the conditions of this License. If you cannot
-+distribute so as to satisfy simultaneously your obligations under this
-+License and any other pertinent obligations, then as a consequence you
-+may not distribute the Program at all. For example, if a patent
-+license would not permit royalty-free redistribution of the Program by
-+all those who receive copies directly or indirectly through you, then
-+the only way you could satisfy both it and this License would be to
-+refrain entirely from distribution of the Program.
-+
-+If any portion of this section is held invalid or unenforceable under
-+any particular circumstance, the balance of the section is intended to
-+apply and the section as a whole is intended to apply in other
-+circumstances.
-+
-+It is not the purpose of this section to induce you to infringe any
-+patents or other property right claims or to contest validity of any
-+such claims; this section has the sole purpose of protecting the
-+integrity of the free software distribution system, which is
-+implemented by public license practices. Many people have made
-+generous contributions to the wide range of software distributed
-+through that system in reliance on consistent application of that
-+system; it is up to the author/donor to decide if he or she is willing
-+to distribute software through any other system and a licensee cannot
-+impose that choice.
-+
-+This section is intended to make thoroughly clear what is believed to
-+be a consequence of the rest of this License.
-+
-+ 8. If the distribution and/or use of the Program is restricted in
-+certain countries either by patents or by copyrighted interfaces, the
-+original copyright holder who places the Program under this License
-+may add an explicit geographical distribution limitation excluding
-+those countries, so that distribution is permitted only in or among
-+countries not thus excluded. In such case, this License incorporates
-+the limitation as if written in the body of this License.
-+
-+ 9. The Free Software Foundation may publish revised and/or new versions
-+of the General Public License from time to time. Such new versions will
-+be similar in spirit to the present version, but may differ in detail to
-+address new problems or concerns.
-+
-+Each version is given a distinguishing version number. If the Program
-+specifies a version number of this License which applies to it and "any
-+later version", you have the option of following the terms and conditions
-+either of that version or of any later version published by the Free
-+Software Foundation. If the Program does not specify a version number of
-+this License, you may choose any version ever published by the Free Software
-+Foundation.
-+
-+ 10. If you wish to incorporate parts of the Program into other free
-+programs whose distribution conditions are different, write to the author
-+to ask for permission. For software which is copyrighted by the Free
-+Software Foundation, write to the Free Software Foundation; we sometimes
-+make exceptions for this. Our decision will be guided by the two goals
-+of preserving the free status of all derivatives of our free software and
-+of promoting the sharing and reuse of software generally.
-+
-+ NO WARRANTY
-+
-+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-+REPAIR OR CORRECTION.
-+
-+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-+POSSIBILITY OF SUCH DAMAGES.
-+
-+ END OF TERMS AND CONDITIONS
-+
-+ How to Apply These Terms to Your New Programs
-+
-+ If you develop a new program, and you want it to be of the greatest
-+possible use to the public, the best way to achieve this is to make it
-+free software which everyone can redistribute and change under these terms.
-+
-+ To do so, attach the following notices to the program. It is safest
-+to attach them to the start of each source file to most effectively
-+convey the exclusion of warranty; and each file should have at least
-+the "copyright" line and a pointer to where the full notice is found.
-+
-+ <one line to give the program's name and a brief idea of what it does.>
-+ Copyright (C) 19yy <name of author>
-+
-+ This program is free software; you can redistribute it and/or modify
-+ it under the terms of the GNU General Public License as published by
-+ the Free Software Foundation; either version 2 of the License, or
-+ (at your option) any later version.
-+
-+ This program is distributed in the hope that it will be useful,
-+ but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ GNU General Public License for more details.
-+
-+ You should have received a copy of the GNU General Public License
-+ along with this program; if not, write to the Free Software
-+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-+
-+
-+Also add information on how to contact you by electronic and paper mail.
-+
-+If the program is interactive, make it output a short notice like this
-+when it starts in an interactive mode:
-+
-+ Gnomovision version 69, Copyright (C) 19yy name of author
-+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-+ This is free software, and you are welcome to redistribute it
-+ under certain conditions; type `show c' for details.
-+
-+The hypothetical commands `show w' and `show c' should show the appropriate
-+parts of the General Public License. Of course, the commands you use may
-+be called something other than `show w' and `show c'; they could even be
-+mouse-clicks or menu items--whatever suits your program.
-+
-+You should also get your employer (if you work as a programmer) or your
-+school, if any, to sign a "copyright disclaimer" for the program, if
-+necessary. Here is a sample; alter the names:
-+
-+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
-+
-+ <signature of Ty Coon>, 1 April 1989
-+ Ty Coon, President of Vice
-+
-+This General Public License does not permit incorporating your program into
-+proprietary programs. If your program is a subroutine library, you may
-+consider it more useful to permit linking proprietary applications with the
-+library. If this is what you want to do, use the GNU Library General
-+Public License instead of this License.
-diff -urNad zaptel-1.2.1/qozap/Makefile /tmp/dpep.LWjGif/zaptel-1.2.1/qozap/Makefile
---- zaptel-1.2.1/qozap/Makefile 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.LWjGif/zaptel-1.2.1/qozap/Makefile 2005-12-21 15:44:21.000000000 +0200
-@@ -0,0 +1,91 @@
-+KINCLUDES = /usr/src/linux/include
-+BRISTUFFBASE = $(shell dirname `pwd`)
-+
-+ZAP = $(shell [ -f $(BRISTUFFBASE)/zaptel-1.2.1/zaptel.h ] && echo "-I$(BRISTUFFBASE)/zaptel-1.2.1")
-+
-+HOSTCC=gcc
-+
-+CFLAGS+=-I. $(ZAP) -O4 -g -Wall -DBUILDING_TONEZONE #-DTONEZONE_DRIVER
-+CFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-fsigned-char"; fi)
-+
-+KFLAGS=-D__KERNEL__ -DMODULE -DEXPORT_SYMTAB -fomit-frame-pointer -O2 -Wall -I$(KINCLUDES) $(ZAP)
-+KFLAGS+=$(shell [ -f $(KINCLUDES)/linux/modversions.h ] && echo "-DMODVERSIONS -include $(KINCLUDES)/linux/modversions.h")
-+KFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-msoft-float -fsigned-char"; fi)
-+
-+OBJS=qozap.o
-+
-+BUILDVER=$(shell if uname -r | grep -q ^2.6; then echo "linux26"; else echo "linux24"; fi)
-+
-+MODCONF=$(shell if [ -d $(INSTALL_PREFIX)/etc/modprobe.d ]; then echo "$(INSTALL_PREFIX)/etc/modprobe.d/zaptel"; elif [ -d $(INSTALL_PREFIX)/etc/modutils ]; then echo "$(INSTALL_PREFIX)/etc/modutils/zaptel"; elif [ -f $(INSTALL_PREFIX)/etc/modprobe.conf ]; then echo "$(INSTALL_PREFIX)/modprobe.conf"; elif [ -f $(INSTALL_PREFIX)/etc/modules.conf ]; then echo "$(INSTALL_PREFIX)/etc/modules.conf"; else echo $(INSTALL_PREFIX)/etc/conf.modules ; fi)
-+
-+MODULES=qozap
-+
-+MODULESO=$(shell for x in $(MODULES); do echo "$$x.o "; done )
-+MODULESKO=$(shell for x in $(MODULES); do echo "$$x.ko "; done )
-+
-+PWD=$(shell pwd)
-+
-+obj-m := $(MODULESO)
-+
-+all: $(BUILDVER)
-+
-+linux24: $(OBJS)
-+ sync
-+
-+linux26:
-+ @if ! [ -d /usr/src/linux-2.6 ]; then echo "Link /usr/src/linux-2.6 to your kernel sources first!"; exit 1 ; fi
-+ make -C /usr/src/linux-2.6 SUBDIRS=$(PWD) ZAP=$(ZAP) modules
-+obj-m := $(OBJS)
-+
-+qozap.o: qozap.c qozap.h
-+ $(CC) -c qozap.c $(KFLAGS)
-+
-+clean:
-+ rm -f $(OBJS) *.ko *.mod.c *.mod.o .*o.cmd *~
-+ rm -rf .tmp_versions
-+
-+testlinux24: all
-+ modprobe zaptel
-+ insmod ./qozap.o
-+ ztcfg -v
-+ cat /proc/interrupts
-+ sleep 1
-+ cat /proc/interrupts
-+ rmmod qozap zaptel
-+
-+testlinux26: all
-+ modprobe zaptel
-+ insmod ./qozap.ko
-+ ztcfg -v
-+ cat /proc/interrupts
-+ sleep 1
-+ cat /proc/interrupts
-+ rmmod qozap zaptel
-+
-+reload: unload load
-+load: load$(BUILDVER)
-+
-+test: test$(BUILDVER)
-+
-+
-+loadlinux24: linux24
-+ modprobe zaptel
-+ insmod ./qozap.o
-+ ztcfg -v
-+
-+loadlinux26: linux26
-+ sync
-+ modprobe zaptel
-+ insmod ./qozap.ko
-+ ztcfg -v
-+
-+unload:
-+ rmmod qozap zaptel
-+
-+install: install$(BUILDVER)
-+
-+installlinux26:
-+ install -D -m 644 qozap.ko $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/qozap.ko
-+
-+installlinux24:
-+ install -D -m 644 qozap.o $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/qozap.o
-diff -urNad zaptel-1.2.1/qozap/qozap.c /tmp/dpep.LWjGif/zaptel-1.2.1/qozap/qozap.c
---- zaptel-1.2.1/qozap/qozap.c 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.LWjGif/zaptel-1.2.1/qozap/qozap.c 2005-08-01 09:58:20.000000000 +0300
-@@ -0,0 +1,1493 @@
-+/*
-+ * qozap.c - Zaptel driver for the quadBRI PCI ISDN card
-+ * and the octoBRI PCI ISDN card!
-+ *
-+ * Copyright (C) 2003, 2004, 2005 Junghanns.NET GmbH
-+ *
-+ * Klaus-Peter Junghanns <kpj at junghanns.net>
-+ *
-+ * This program is free software and may be modified and
-+ * distributed under the terms of the GNU Public License.
-+ *
-+ */
-+#include <linux/kernel.h>
-+#include <linux/module.h>
-+#include <linux/pci.h>
-+#include <linux/init.h>
-+#include <linux/interrupt.h>
-+#include <zaptel.h>
-+#include "qozap.h"
-+
-+#if CONFIG_PCI
-+
-+static int doubleclock=0;
-+static int ports=-1; /* autodetect */
-+static int bloop=0;
-+static int debug=0;
-+static struct qoz_card *qoz_dev_list = NULL;
-+static int qoz_dev_count = 0;
-+static int totalBRIs = 0;
-+static struct pci_dev *multi_qoz = NULL;
-+static spinlock_t registerlock = SPIN_LOCK_UNLOCKED;
-+
-+static int ztqoz_shutdown(struct zt_span *span);
-+
-+int qoz_waitbusy(struct qoz_card *qoztmp) {
-+ int x=1000;
-+ while (x-- && (qoz_inb(qoztmp,qoz_R_STATUS) & 1));
-+ if (x < 0) {
-+ return -1;
-+ } else {
-+ return 0;
-+ }
-+}
-+
-+void qoz_shutdownCard(struct qoz_card *qoztmp) {
-+ int s=0;
-+ unsigned long flags;
-+ int stports=0;
-+ if (qoztmp == NULL) {
-+ printk(KERN_INFO "qozap: shutting down NULL card!\n");
-+ return;
-+ }
-+
-+ if ((qoztmp->pci_io == NULL) || (qoztmp->ioport == 0)) {
-+ return;
-+ }
-+
-+ if (debug)
-+ printk(KERN_INFO "qozap: shutting down card %d (cardID %d) at io port %#x.\n",qoztmp->cardno,qoztmp->cardID,(u_int) qoztmp->ioport);
-+
-+ if (qoztmp->ztdev != NULL) {
-+ stports = qoztmp->stports;
-+ for (s=0; s < stports; s++) {
-+ if(qoztmp->ztdev->spans[s].flags & ZT_FLAG_RUNNING) {
-+ ztqoz_shutdown(&qoztmp->ztdev->spans[s]);
-+ if (debug)
-+ printk(KERN_INFO "qozap: shutdown card %d span %d.\n",qoztmp->cardno,s+1);
-+ }
-+ }
-+ }
-+
-+ spin_lock_irqsave(&qoztmp->lock,flags);
-+
-+ // turn off irqs
-+ qoz_outb(qoztmp,qoz_R_IRQ_CTRL, 0);
-+ qoz_outb(qoztmp,qoz_R_IRQMSK_MISC, 0);
-+ qoz_outb(qoztmp,qoz_R_SCI_MSK, 0);
-+
-+ free_irq(qoztmp->irq,qoztmp);
-+
-+ // softreset
-+ qoz_outb(qoztmp,qoz_R_CIRM,0x8);
-+ qoz_outb(qoztmp,qoz_R_CIRM,0x0);
-+ qoz_waitbusy(qoztmp);
-+
-+ qoz_outb(qoztmp,qoz_R_IRQMSK_MISC, 0);
-+ qoz_outb(qoztmp,qoz_R_SCI_MSK, 0);
-+ qoz_outb(qoztmp,qoz_R_IRQ_CTRL, 0);
-+
-+ release_region(qoztmp->ioport, 7);
-+ iounmap((void *) qoztmp->pci_io);
-+
-+ qoztmp->pci_io = NULL;
-+ qoztmp->ioport = 0;
-+
-+ if (qoztmp->pcidev != NULL) {
-+ pci_disable_device(qoztmp->pcidev);
-+ }
-+ pci_write_config_word(qoztmp->pcidev, PCI_COMMAND, 0);
-+
-+ spin_unlock_irqrestore(&qoztmp->lock,flags);
-+
-+ if (qoztmp->ztdev != NULL) {
-+ stports = qoztmp->stports;
-+ for (s=0; s < stports; s++) {
-+ if(qoztmp->ztdev->spans[s].flags & ZT_FLAG_REGISTERED) {
-+ zt_unregister(&qoztmp->ztdev->spans[s]);
-+ if (debug)
-+ printk(KERN_INFO "qozap: unregistered card %d span %d.\n",qoztmp->cardno,s+1);
-+ }
-+ }
-+ kfree(qoztmp->ztdev);
-+ qoztmp->ztdev = NULL;
-+ }
-+}
-+
-+void qoz_doLEDs(struct qoz_card *qoztmp) {
-+ unsigned char leds = 0x0;
-+ if ((qoztmp->type == 0xb520) && (qoztmp->stports == 4)){
-+// if ((qoztmp->ticks > 0) && (qoztmp->ticks <= 300)) {
-+ qoz_outb(qoztmp,qoz_R_GPIO_SEL,0x20 | 0x10);
-+ qoz_outb(qoztmp,qoz_R_GPIO_EN1,0xf);
-+ qoz_outb(qoztmp,qoz_R_GPIO_OUT1,(qoztmp->leds[0] | (qoztmp->leds[1] << 1) | (qoztmp->leds[2] << 2) | (qoztmp->leds[3] << 3)));
-+/* }
-+ if ((qoztmp->ticks > 300) && (qoztmp->ticks <= 600)) {
-+ qoz_outb(qoztmp,qoz_R_GPIO_EN1,0x0);
-+ } */
-+ } else if ((qoztmp->type == 0xb550) && (qoztmp->stports == 4)){
-+ qoz_outb(qoztmp,qoz_R_GPIO_SEL,0x80 | 0x40 | 0x20 | 0x10);
-+ qoz_outb(qoztmp,qoz_R_GPIO_EN1,0xff);
-+ if (qoztmp->leds[0] == 0) {
-+ leds |= 0x80;
-+ } else {
-+ leds |= 0x40;
-+ }
-+ if (qoztmp->leds[1] == 0) {
-+ leds |= 0x10;
-+ } else {
-+ leds |= 0x20;
-+ }
-+ if (qoztmp->leds[2] == 0) {
-+ leds |= 0x04;
-+ } else {
-+ leds |= 0x08;
-+ }
-+ if (qoztmp->leds[3] == 0) {
-+ leds |= 0x02;
-+ } else {
-+ leds |= 0x01;
-+ }
-+ /* 0x80 st1g
-+ 0x40 st1r
-+ 0x20 st2r
-+ 0x10 st2g
-+ 0x08 st3r
-+ 0x04 st3g
-+ 0x02 st4g
-+ 0x01 st4r
-+ */
-+ qoz_outb(qoztmp,qoz_R_GPIO_OUT1, leds);
-+ }
-+}
-+
-+void qoz_doWD(struct qoz_card *qoztmp) {
-+ if (!qoztmp->wdp) {
-+ return;
-+ }
-+ if (qoztmp->wdp == 1) {
-+ qoz_outdw_io(qoztmp,0x4000, qoz_WD_P2);
-+ qoztmp->wdp = 2;
-+ } else {
-+ qoz_outdw_io(qoztmp,0x4000, qoz_WD_P1);
-+ qoztmp->wdp = 1;
-+ }
-+ qoz_inb_io(qoztmp,qoz_R_CHIP_ID);
-+}
-+
-+void qoz_undoWD(struct qoz_card *qoztmp) {
-+ printk(KERN_INFO "qozap: Stopping hardware watchdog.\n");
-+ qoz_outdw_io(qoztmp,0x4000, qoz_WD_P0);
-+ qoztmp->wdp = 0;
-+ qoz_inb_io(qoztmp,qoz_R_CHIP_ID);
-+}
-+
-+void qoz_resetCard(struct qoz_card *qoztmp) {
-+ unsigned long flags;
-+ unsigned char i=0;
-+ spin_lock_irqsave(&(qoztmp->lock),flags);
-+ pci_write_config_word(qoztmp->pcidev, PCI_COMMAND, PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
-+
-+ // soft reset
-+ qoz_outb(qoztmp,qoz_R_CIRM,0x8);
-+ qoz_outb(qoztmp,qoz_R_CIRM,0x0);
-+ qoz_waitbusy(qoztmp);
-+
-+ // fifo reset
-+ qoz_outb(qoztmp,qoz_R_CIRM,0x10);
-+ qoz_outb(qoztmp,qoz_R_CIRM,0x0);
-+ qoz_waitbusy(qoztmp);
-+
-+ // s/t reset
-+ qoz_outb(qoztmp,qoz_R_CIRM,0x40);
-+ qoz_outb(qoztmp,qoz_R_CIRM,0x0);
-+ qoz_waitbusy(qoztmp);
-+
-+ /* set S0 amplitude */
-+ qoz_outb(qoztmp,qoz_R_PWM_MD,0xa0);
-+ if (qoztmp->type == 0xb552) {
-+ qoz_outb(qoztmp,qoz_R_PWM0,0x19);
-+ } else {
-+ qoz_outb(qoztmp,qoz_R_PWM0,0x1E);
-+ }
-+
-+ /* set up the timer */
-+ qoz_outb(qoztmp,qoz_R_TI_WD, 0x2);
-+ qoz_outb(qoztmp,qoz_R_IRQMSK_MISC, 0x2);
-+ qoz_outb(qoztmp,qoz_R_PCM_MD0, 0x1);
-+
-+ /* all state changes */
-+ qoz_outb(qoztmp,qoz_R_SCI_MSK, 0xff);
-+
-+ if (qoztmp->type == 0xb552) {
-+ qoz_outb(qoztmp,qoz_R_FIFO_MD,0x16);
-+ } else {
-+ qoz_outb(qoztmp,qoz_R_FIFO_MD,0x26);
-+ }
-+
-+ // double clock
-+ if (doubleclock == 1) {
-+ // hopefully you have set CLK_MODE correctly!
-+ qoz_outb(qoztmp,qoz_R_BRG_PCM_CFG,0x20);
-+ } else {
-+ if (qoztmp->type == 0x08b4) {
-+ qoz_outb(qoztmp,qoz_R_BRG_PCM_CFG,0x0);
-+ } else if (qoztmp->type == 0xb550) {
-+ qoz_outb(qoztmp,qoz_R_BRG_PCM_CFG,0x23);
-+ } else if (qoztmp->type == 0xb520) {
-+ qoz_outb(qoztmp,qoz_R_BRG_PCM_CFG,0x20);
-+ } else {
-+ /* you are on your own here! */
-+ qoz_outb(qoztmp,qoz_R_BRG_PCM_CFG,0x20);
-+ }
-+ }
-+ qoz_outb(qoztmp,qoz_R_CTRL,0x0);
-+
-+ /* R0 G1 */
-+ qoztmp->leds[0] = 0x0;
-+ qoztmp->leds[1] = 0x0;
-+ qoztmp->leds[2] = 0x0;
-+ qoztmp->leds[3] = 0x0;
-+ qoztmp->leds[4] = 0x0;
-+ qoztmp->leds[5] = 0x0;
-+ qoztmp->leds[6] = 0x0;
-+ qoztmp->leds[7] = 0x0;
-+
-+ /* Finally enable IRQ output */
-+ qoz_outb(qoztmp,qoz_R_IRQ_CTRL, 0x8 | 0x1);
-+ if (qoztmp->type == 0xb552) {
-+ qoztmp->stports = 8;
-+ } else {
-+ qoztmp->stports = 4;
-+ }
-+ qoztmp->ticks = 0;
-+ qoztmp->clicks = 0;
-+ if (qoztmp->type == 0xb550) {
-+ printk(KERN_INFO "qozap: Starting hardware watchdog.\n");
-+ qoztmp->wdp = 2;
-+ } else {
-+ qoztmp->wdp = 0;
-+ }
-+
-+ for (i=0;i<qoztmp->stports;i++) {
-+ if (qoztmp->st[i].nt_mode) {
-+ qoz_outb(qoztmp,qoz_R_ST_SYNC,0x8 | i);
-+ if (debug)
-+ printk(KERN_INFO "qoztmp: using NT port %d for sync\n", i);
-+ break;
-+ }
-+ }
-+ if (i == qoztmp->stports) {
-+ qoz_outb(qoztmp,qoz_R_ST_SYNC,0x0);
-+ }
-+ spin_unlock_irqrestore(&(qoztmp->lock),flags);
-+}
-+
-+void qoz_registerCard(struct qoz_card *qozcard) {
-+ spin_lock(®isterlock);
-+ if (qozcard != NULL) {
-+ qozcard->prev = NULL;
-+ qozcard->next = qoz_dev_list;
-+ if (qoz_dev_list) {
-+ qoz_dev_list->prev = qozcard;
-+ }
-+ qoz_dev_list = qozcard;
-+ qozcard->cardno = ++qoz_dev_count;
-+ } else {
-+ printk(KERN_INFO "qozap: trying to register NULL card.\n");
-+ }
-+ spin_unlock(®isterlock);
-+}
-+
-+static int qoz_dfifo_tx(struct qoz_card *qoztmp, int stport) {
-+ int chan = 2;
-+ int x=0;
-+ char fifo = 0;
-+ char offset = 0;
-+
-+ if (qoztmp->type == 0xb552) {
-+ offset = 24;
-+ } else {
-+ offset = 28;
-+ }
-+
-+ fifo = stport + offset;
-+
-+ if (qoztmp->ztdev->chans[stport][chan].bytes2transmit < 1) {
-+ return 0;
-+ } else {
-+ /* select fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,fifo << 1);
-+ qoz_waitbusy(qoztmp);
-+
-+ if (debug > 1)
-+ printk(KERN_INFO "qozap: card %d stport %d TX [ ", qoztmp->cardno, stport + 1);
-+ /* copy frame to fifo */
-+ for (x=0;x<qoztmp->ztdev->chans[stport][chan].bytes2transmit;x++) {
-+ if (debug > 1)
-+ printk("%#x ",qoztmp->dtxbuf[stport][x]);
-+ qoz_outb(qoztmp,qoz_A_FIFO_DATA0,qoztmp->dtxbuf[stport][x]);
-+ }
-+ if (debug > 1)
-+ printk("] %d bytes\n",qoztmp->ztdev->chans[stport][chan].bytes2transmit);
-+
-+ if (qoztmp->ztdev->chans[stport][chan].eoftx == 1) {
-+ /* transmit HDLC frame */
-+ qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x1);
-+ qoz_waitbusy(qoztmp);
-+ }
-+ }
-+ return 0;
-+}
-+
-+static int qoz_fifo_tx(struct qoz_card *qoztmp, char fifo) {
-+ int stport = fifo / 2;
-+ int chan = fifo % 2;
-+
-+ /* select fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,0x80 | (fifo << 1));
-+ qoz_waitbusy(qoztmp);
-+ /* transmit 8 bytes of transparent data */
-+ qoz_outdw(qoztmp,qoz_A_FIFO_DATA0,*((unsigned int *) &qoztmp->txbuf[stport][chan][0]));
-+ qoz_outdw(qoztmp,qoz_A_FIFO_DATA0,*((unsigned int *) &qoztmp->txbuf[stport][chan][4]));
-+
-+ return 0;
-+}
-+
-+static int qoz_dfifo_rx(struct qoz_card *qoztmp, int stport) {
-+ unsigned char f1=1,f2=1,data,stat;
-+ unsigned char of1=0,of2=0;
-+ int len,i;
-+ unsigned short z1=1,z2=1;
-+ unsigned short oz1=0,oz2=0;
-+ char fifo = 0;
-+ char offset = 0;
-+
-+ if (qoztmp->type == 0xb552) {
-+ offset = 24;
-+ } else {
-+ offset = 28;
-+ }
-+
-+ fifo = stport + offset;
-+ // select rx fifo
-+
-+ qoz_outb(qoztmp,qoz_R_FIFO,(fifo << 1) | 1);
-+ qoz_waitbusy(qoztmp);
-+
-+ while ((of1 != f1) && (of2 != f2)) {
-+ of1 = f1;
-+ of2 = f2;
-+ f1 = qoz_inb(qoztmp,qoz_A_F1) & 0xf;
-+ f2 = qoz_inb(qoztmp,qoz_A_F2) & 0xf;
-+ }
-+
-+ if (f1 == f2) {
-+ /* no frame */
-+ qoztmp->st[stport].drx--;
-+ qoztmp->ztdev->chans[stport][2].bytes2receive = 0;
-+ return 0;
-+ }
-+
-+ while ((oz1 != z1) && (oz2 != z2)) {
-+ oz1 = z1;
-+ oz2 = z2;
-+ if (qoztmp->type != 0xb552) {
-+ z1 = qoz_inw(qoztmp,qoz_A_Z1) & 0x7ff;
-+ z2 = qoz_inw(qoztmp,qoz_A_Z2) & 0x7ff;
-+ } else {
-+ z1 = qoz_inw(qoztmp,qoz_A_Z1) & 0x3ff;
-+ z2 = qoz_inw(qoztmp,qoz_A_Z2) & 0x3ff;
-+ }
-+ }
-+
-+ if (qoztmp->type == 0xb552) {
-+ len = z1 - z2;
-+ if (len < 0) {
-+ len += qoz_DFIFO_SIZE8;
-+ }
-+ } else {
-+ len = z1 - z2;
-+ if (len < 0) {
-+ len += qoz_DFIFO_SIZE4;
-+ }
-+ }
-+
-+ if (len > qoz_DFIFO_SIZE4) {
-+ printk(KERN_INFO "\nqozap: buffer overflow in D channel RX!\n");
-+ qoztmp->ztdev->chans[stport][2].bytes2receive = 0;
-+ qoztmp->ztdev->chans[stport][2].eofrx = 0;
-+ } else {
-+ if (debug > 1) printk(KERN_INFO "qozap: card %d span %d RX [ ", qoztmp->cardno, stport + 1);
-+ for (i=0; i<len; i++) {
-+ data = qoz_inb(qoztmp,qoz_A_FIFO_DATA0);
-+ qoztmp->drxbuf[stport][i] = data;
-+ if (debug > 1) printk("%#x ",data);
-+ }
-+ if (debug > 1) printk("] %d bytes\n", len);
-+ qoztmp->ztdev->chans[stport][2].bytes2receive = i;
-+ qoztmp->ztdev->chans[stport][2].eofrx = 1;
-+ }
-+
-+ stat = qoz_inb(qoztmp,qoz_A_FIFO_DATA0);
-+ if (stat != 0x0) {
-+ // bad CRC, skip it
-+ printk(KERN_INFO "qozap: CRC error for HDLC frame on card %d (cardID %d) S/T port %d\n",qoztmp->cardno, qoztmp->cardID, stport+1);
-+ qoztmp->ztdev->chans[stport][2].bytes2receive = 0;
-+ qoztmp->ztdev->chans[stport][2].eofrx = 0;
-+// zt_qevent_nolock(&qoztmp->ztdev->chans[stport][2], ZT_EVENT_BADFCS);
-+ }
-+ qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x1);
-+ qoz_waitbusy(qoztmp);
-+
-+ /* frame recevived */
-+ if (qoztmp->st[stport].drx > 0) {
-+ qoztmp->st[stport].drx--;
-+ } else {
-+ printk(KERN_INFO "qozap: trying to receive too much (card %d span %d drx %d)\n", qoztmp->cardno, stport+1, qoztmp->st[stport].drx);
-+ qoztmp->st[stport].drx = 0;
-+ }
-+ return 0;
-+}
-+
-+
-+static int qoz_fifo_rx(struct qoz_card *qoztmp, char fifo) {
-+ int stport = fifo / 2;
-+ int chan = fifo % 2;
-+ unsigned char data;
-+ int len,i;
-+ unsigned short z1=1,z2=1;
-+ unsigned short oz1=0,oz2=0;
-+ int mumbojumbo=0;
-+
-+ /* select rx fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,0x80 | (fifo << 1) | 1);
-+ qoz_waitbusy(qoztmp);
-+
-+ while ((oz1 != z1) && (oz2 != z2)) {
-+ oz1 = z1;
-+ oz2 = z2;
-+ z1 = qoz_inw(qoztmp,qoz_A_Z1) & 0x7f;
-+ z2 = qoz_inw(qoztmp,qoz_A_Z2) & 0x7f;
-+ }
-+ len = z1 - z2;
-+ if (len < 0) {
-+ len += qoz_FIFO_SIZE;
-+ }
-+ if (len > 2 * ZT_CHUNKSIZE) {
-+ mumbojumbo = len - (2 * ZT_CHUNKSIZE);
-+ len = ZT_CHUNKSIZE;
-+ for (i=0;i<mumbojumbo;i++) {
-+ data = qoz_inb(qoztmp,qoz_A_FIFO_DATA0);
-+ }
-+ qoztmp->clicks++;
-+ if ((qoztmp->clicks > 1) || (debug == 4)) {
-+ printk(KERN_CRIT "qozap: dropped audio card %d cardid %d bytes %d z1 %d z2 %d\n", qoztmp->cardno, qoztmp->cardID, mumbojumbo, z1, z2);
-+ qoztmp->clicks = 0;
-+ }
-+ }
-+ if (len < ZT_CHUNKSIZE) {
-+// printk(KERN_INFO "qozap: not enough to receive (%d bytes)\n",len);
-+ return 0;
-+ } else {
-+ if (bloop) {
-+ *((unsigned int *) &qoztmp->txbuf[stport][chan][0]) = qoz_indw(qoztmp,qoz_A_FIFO_DATA0);
-+ *((unsigned int *) &qoztmp->txbuf[stport][chan][4]) = qoz_indw(qoztmp,qoz_A_FIFO_DATA0);
-+ } else {
-+ *((unsigned int *) &qoztmp->rxbuf[stport][chan][0]) = qoz_indw(qoztmp,qoz_A_FIFO_DATA0);
-+ *((unsigned int *) &qoztmp->rxbuf[stport][chan][4]) = qoz_indw(qoztmp,qoz_A_FIFO_DATA0);
-+ }
-+ }
-+ if (bloop == 0)
-+ zt_ec_chunk(&qoztmp->ztdev->spans[stport].chans[chan], qoztmp->ztdev->spans[stport].chans[chan].readchunk, qoztmp->ztdev->spans[stport].chans[chan].writechunk);
-+
-+// printk(KERN_INFO "s/t port %d, channel %d, dbufi=%d, f1=%d, f2=%d, z1=%d, z2=%d => len = %d stat=%#x, hdlc=%d\n",stport,chan,qoztmp->st[stport].dbufi,f1,f2,z1,z2,len,stat,hdlc);
-+ return 0;
-+}
-+
-+
-+static inline void qoz_run(struct qoz_card *qoztmp) {
-+ int s=0;
-+ if (qoztmp->ztdev != NULL) {
-+ for (s=0;s<qoztmp->stports;s++) {
-+ if (!bloop) {
-+ if (qoztmp->ztdev->spans[s].flags & ZT_FLAG_RUNNING) {
-+ /* oh zaptel! tell us what to transmit... */
-+ zt_transmit(&qoztmp->ztdev->spans[s]);
-+ /* B1 xmit */
-+ qoz_fifo_tx(qoztmp, s * 2);
-+ /* B2 xmit */
-+ qoz_fifo_tx(qoztmp, (s * 2) + 1);
-+
-+ if ((qoztmp->st[s].layer1state != 7) && (qoztmp->ztdev->chans[s][2].bytes2transmit > 0) && (qoztmp->st[s].nt_mode != 1)) {
-+ if (qoztmp->st[s].t3 == -1) {
-+ printk(KERN_INFO "qozap: activating layer 1, span %d\n",s);
-+ qoztmp->st[s].t3 = 0;
-+ qoz_outb(qoztmp,qoz_R_ST_SEL, s);
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x60);
-+ } else {
-+ }
-+ }
-+
-+ /* D xmit */
-+ if (qoztmp->ztdev->spans[s].alarms != ZT_ALARM_RED) {
-+ qoz_dfifo_tx(qoztmp, s);
-+ } else {
-+ if ((qoztmp->st[s].t3 == -1) && (qoztmp->st[s].t4 == -1) && (qoztmp->st[s].layer1state == 3) && (qoztmp->st[s].nt_mode != 1)) {
-+ /* clear alarms */
-+ printk(KERN_INFO "qozap: clearing alarms on span %d\n",s);
-+ qoztmp->ztdev->spans[s].alarms = ZT_ALARM_NONE;
-+ zt_alarm_notify(&qoztmp->ztdev->spans[s]);
-+ }
-+ }
-+
-+ qoztmp->ztdev->chans[s][2].bytes2receive = 0;
-+ qoztmp->ztdev->chans[s][2].bytes2transmit = 0;
-+ qoztmp->ztdev->chans[s][2].eofrx = 0;
-+ qoztmp->ztdev->chans[s][2].eoftx = 0;
-+
-+ }
-+
-+ /* B1 receive */
-+ qoz_fifo_rx(qoztmp,(s*2));
-+ /* B2 receive */
-+ qoz_fifo_rx(qoztmp,(s*2)+1);
-+ /* d-chan data */
-+ if (qoztmp->st[s].drx > 0) {
-+ if (debug > 2)
-+ printk(KERN_CRIT "qozap: card %d st[%d].drx = %d\n", qoztmp->cardno, s, qoztmp->st[s].drx);
-+ qoz_dfifo_rx(qoztmp, s);
-+ }
-+ if (qoztmp->ztdev->spans[s].flags & ZT_FLAG_RUNNING) {
-+ /* oh zaptel! thou shall receive! */
-+ zt_receive(&(qoztmp->ztdev->spans[s]));
-+ }
-+ } else {
-+ // loop
-+ /* B1 receive */
-+ qoz_fifo_rx(qoztmp,(s*2));
-+ /* B2 receive */
-+ qoz_fifo_rx(qoztmp,(s*2)+1);
-+ /* d-chan data */
-+/* if (qoztmp->st[s].drx > 0) {
-+ if (debug > 2)
-+ printk(KERN_CRIT "qozap: card %d st[%d].drx = %d\n", qoztmp->cardno, s, qoztmp->st[s].drx);
-+ qoz_dfifo_rx(qoztmp, s);
-+ }
-+ if (qoztmp->ztdev->spans[s].flags & ZT_FLAG_RUNNING) {
-+ zt_receive(&(qoztmp->ztdev->spans[s]));
-+ }
-+*/
-+ if (qoztmp->ztdev->spans[s].flags & ZT_FLAG_RUNNING) {
-+ /* oh zaptel! tell us what to transmit... */
-+ // zt_transmit(&qoztmp->ztdev->spans[s]);
-+ /* B1 xmit */
-+ qoz_fifo_tx(qoztmp, s * 2);
-+ /* B2 xmit */
-+ qoz_fifo_tx(qoztmp, (s * 2) + 1);
-+ /* D xmit */
-+// qoz_dfifo_tx(qoztmp, s);
-+
-+ qoztmp->ztdev->chans[s][2].bytes2receive = 0;
-+ qoztmp->ztdev->chans[s][2].bytes2transmit = 0;
-+ qoztmp->ztdev->chans[s][2].eofrx = 0;
-+ qoztmp->ztdev->chans[s][2].eoftx = 0;
-+
-+ }
-+ }
-+ }
-+ }
-+}
-+
-+#ifdef LINUX26
-+static irqreturn_t qoz_interrupt(int irq, void *dev_id, struct pt_regs *regs) {
-+#else
-+static void qoz_interrupt(int irq, void *dev_id, struct pt_regs *regs) {
-+#endif
-+ struct qoz_card *qoztmp = dev_id;
-+ struct zt_qoz *ztqoz = qoztmp->ztdev;
-+ unsigned long flags;
-+ unsigned char irq_misc,irq_sci,status,l1state,irq_foview,fi;
-+ int st=0,i=0,offset=0;
-+ int j=0;
-+
-+ if (!qoztmp) {
-+#ifdef LINUX26
-+ return IRQ_NONE;
-+#else
-+ return;
-+#endif
-+ }
-+
-+ if ((!qoztmp->pci_io) || (!qoztmp->ioport)) {
-+ printk(KERN_CRIT "qozap: no pci mem/io\n");
-+#ifdef LINUX26
-+ return IRQ_NONE;
-+#else
-+ return;
-+#endif
-+ }
-+
-+ spin_lock_irqsave(&(qoztmp->lock),flags);
-+ status = qoz_inb(qoztmp,qoz_R_STATUS);
-+ irq_sci = qoz_inb(qoztmp,qoz_R_SCI);
-+
-+ if (!(status & 0x80) && !(status & 0x40) && (irq_sci == 0)) {
-+// printk(KERN_CRIT "qozap: status %#x\n", status);
-+ // it's not us!
-+ spin_unlock_irqrestore(&(qoztmp->lock),flags);
-+#ifdef LINUX26
-+ return IRQ_NONE;
-+#else
-+ return;
-+#endif
-+ }
-+ /* state machine irq */
-+ if (irq_sci != 0) {
-+ if (debug > 1) {
-+ printk(KERN_INFO "R_BERT_STA = %#x\n", qoz_inb(qoztmp, qoz_R_BERT_STA) & 7);
-+ }
-+ for (st=0;st<qoztmp->stports;st++) {
-+ if (irq_sci & (1 << st)) {
-+ qoz_outb(qoztmp,qoz_R_ST_SEL,st);
-+ l1state = qoz_inb(qoztmp,qoz_A_ST_RD_STA) & 0xf;
-+ if (debug > 1) {
-+ printk(KERN_INFO "A_ST_RD_STA = %#x\n", qoz_inb(qoztmp, qoz_A_ST_RD_STA));
-+ }
-+ qoztmp->st[st].layer1state = l1state;
-+ if (qoztmp->st[st].nt_mode == 1) {
-+ if (debug)
-+ printk(KERN_INFO "card %d span %d state G%d (A_ST_RD_STA = %#x)\n",qoztmp->cardno,st+1,l1state,qoz_inb(qoztmp,qoz_A_ST_RD_STA));
-+ // NT state machine
-+ if (l1state == 3) {
-+ // keep layer1 up!
-+ if (qoztmp->stports == 8) {
-+ sprintf(ztqoz->spans[st].desc,"octoBRI PCI ISDN Card %d Span %d [NT] Layer 1 ACTIVATED (G%d)",qoztmp->cardno ,st + 1, l1state);
-+ } else {
-+ sprintf(ztqoz->spans[st].desc,"quadBRI PCI ISDN Card %d Span %d [NT] (cardID %d) Layer 1 ACTIVATED (G%d)",qoztmp->cardno ,st + 1,ztqoz->card->cardID, l1state);
-+ }
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,3 | 0x10 );
-+ qoztmp->leds[st] = 1;
-+ } else {
-+ if (qoztmp->stports == 8) {
-+ sprintf(ztqoz->spans[st].desc,"octoBRI PCI ISDN Card %d Span %d [NT] Layer 1 DEACTIVATED (G%d)",qoztmp->cardno ,st + 1, l1state);
-+ } else {
-+ sprintf(ztqoz->spans[st].desc,"quadBRI PCI ISDN Card %d Span %d [NT] (cardID %d) Layer 1 DEACTIVATED (G%d)",qoztmp->cardno ,st + 1,ztqoz->card->cardID, l1state);
-+ }
-+ qoztmp->leds[st] = 0;
-+ }
-+ } else {
-+ if (debug)
-+ printk(KERN_INFO "card %d span %d state F%d (A_ST_RD_STA = %#x)\n",qoztmp->cardno,st+1,l1state,qoz_inb(qoztmp,qoz_A_ST_RD_STA));
-+ // TE state machine
-+ if (l1state == 3) {
-+ if (qoztmp->st[st].t3 > -1) {
-+ /* keep layer1 up, if the span is started. */
-+ if (qoztmp->ztdev->spans[st].flags & ZT_FLAG_RUNNING) {
-+printk("qozap: re-activating layer1 span %d\n", st);
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x60);
-+ }
-+ } else {
-+printk("qozap: not re-activating layer1 span %d\n", st);
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x40);
-+ /* if we tried to activate layer 1 and it failed make this an alarm */
-+// qoztmp->ztdev->spans[st].alarms = ZT_ALARM_RED;
-+// zt_alarm_notify(&qoztmp->ztdev->spans[st]);
-+ /* if the network shuts us down in idle mode dont make this an alarm */
-+ }
-+ qoztmp->leds[st] = 0;
-+ if (qoztmp->stports == 8) {
-+ sprintf(ztqoz->spans[st].desc,"octoBRI PCI ISDN Card %d Span %d [TE] Layer 1 DEACTIVATED (F%d)",qoztmp->cardno ,st + 1, l1state);
-+ } else {
-+ sprintf(ztqoz->spans[st].desc,"quadBRI PCI ISDN Card %d Span %d [TE] (cardID %d) Layer 1 DEACTIVATED (F%d)",qoztmp->cardno ,st + 1,ztqoz->card->cardID, l1state);
-+ }
-+ } else if (l1state == 7) {
-+ /* activation complete, stop timer t3 */
-+ qoztmp->st[st].t3 = -1;
-+ qoztmp->ztdev->spans[st].alarms = ZT_ALARM_NONE;
-+ zt_alarm_notify(&qoztmp->ztdev->spans[st]);
-+ qoztmp->leds[st] = 1;
-+ if (qoztmp->stports == 8) {
-+ sprintf(ztqoz->spans[st].desc,"octoBRI PCI ISDN Card %d Span %d [TE] Layer 1 ACTIVATED (F%d)",qoztmp->cardno ,st + 1, l1state);
-+ } else {
-+ sprintf(ztqoz->spans[st].desc,"quadBRI PCI ISDN Card %d Span %d [TE] (cardID %d) Layer 1 ACTIVATED (F%d)",qoztmp->cardno ,st + 1,ztqoz->card->cardID, l1state);
-+ }
-+ } else if (l1state == 8) {
-+ /* lost framing */
-+ printk(KERN_INFO "qozap: starting t4 for span %d\n", st);
-+ qoztmp->st[st].t4 = 0;
-+ } else {
-+ if (qoztmp->stports == 8) {
-+ sprintf(ztqoz->spans[st].desc,"octoBRI PCI ISDN Card %d Span %d [TE] Layer 1 DEACTIVATED (F%d)",qoztmp->cardno ,st + 1, l1state);
-+ } else {
-+ sprintf(ztqoz->spans[st].desc,"quadBRI PCI ISDN Card %d Span %d [TE] (cardID %d) Layer 1 DEACTIVATED (F%d)",qoztmp->cardno ,st + 1,ztqoz->card->cardID, l1state);
-+ }
-+ }
-+ }
-+
-+ }
-+ }
-+ }
-+
-+
-+ // misc irq
-+ if (status & 0x40) {
-+ irq_misc = qoz_inb(qoztmp,qoz_R_IRQ_MISC);
-+ if (irq_misc & 0x2) {
-+ // qozap timer
-+ qoztmp->ticks++;
-+ qoz_run(qoztmp);
-+ if (qoztmp->ticks % 100) {
-+ qoz_doLEDs(qoztmp);
-+ }
-+ if (qoztmp->ticks % 40) {
-+ /* you thought that 42 was the answer.... */
-+ qoz_doWD(qoztmp);
-+ }
-+ if (qoztmp->ticks > 1000) {
-+ qoztmp->ticks = 0;
-+ for (j=0;j<qoztmp->stports;j++) {
-+ /* t3 */
-+ if (qoztmp->st[j].t3 >= 0) {
-+ qoztmp->st[j].t3++;
-+ }
-+ if (qoztmp->st[j].nt_mode != 1) {
-+ if ((qoztmp->st[j].t3 > qoz_T3) && (qoztmp->st[j].layer1state != 7)) {
-+ /* deactivate layer 1 */
-+ printk(KERN_INFO "qozap: t3 timer expired for span %d\n", j);
-+ qoz_outb(qoztmp,qoz_R_ST_SEL, j);
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA, 0x40 );
-+ qoztmp->st[j].t3 = -1;
-+ qoztmp->ztdev->spans[j].alarms = ZT_ALARM_RED;
-+ zt_alarm_notify(&qoztmp->ztdev->spans[j]);
-+ qoz_waitbusy(qoztmp);
-+ }
-+ }
-+ /* t4 */
-+ if (qoztmp->st[j].t4 >= 0) {
-+ qoztmp->st[j].t4++;
-+ }
-+ if (qoztmp->st[j].nt_mode != 1) {
-+ if ((qoztmp->st[j].t4 > qoz_T4) && (qoztmp->st[j].layer1state != 7)) {
-+ /* deactivate layer 1 */
-+ printk(KERN_INFO "qozap: t4 timer expired for span %d\n", j);
-+ qoz_outb(qoztmp,qoz_R_ST_SEL, j);
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA, 0x40 );
-+ qoztmp->st[j].t4 = -1;
-+ qoztmp->ztdev->spans[j].alarms = ZT_ALARM_RED;
-+ zt_alarm_notify(&qoztmp->ztdev->spans[j]);
-+ qoz_waitbusy(qoztmp);
-+ }
-+ }
-+ }
-+ }
-+ }
-+ if (irq_misc & 0x4) {
-+ // printk(KERN_INFO "qozap proc/nonproc irq\n");
-+ }
-+ }
-+ if (status & 0x80) {
-+ /* fifo irq */
-+ irq_foview = qoz_inb(qoztmp,qoz_R_IRQ_OVIEW);
-+ if (qoztmp->type == 0xb552) {
-+ if (irq_foview & 0x60) {
-+ offset = 0;
-+ fi = qoz_inb(qoztmp,qoz_R_IRQ_FIFO_BL6);
-+ for (i=0; i < 8; i++) {
-+ if (fi & (1 << i)) {
-+ st = offset + (i / 2);
-+ if (i % 2) {
-+ if (debug > 2)
-+ printk(KERN_CRIT "qozap: HDLC RX irq fifo %d span %d\n", i, st+1);
-+ qoztmp->st[st].drx += 1;
-+ } else {
-+ if (debug > 2)
-+ printk(KERN_CRIT "qozap: HDLC TX irq fifo %d span %d\n", i, st+1);
-+ }
-+ }
-+ }
-+ }
-+ if (irq_foview & 0x80) {
-+ offset = 4;
-+ fi = qoz_inb(qoztmp,qoz_R_IRQ_FIFO_BL7);
-+ for (i=0; i < 8; i++) {
-+ if (fi & (1 << i)) {
-+ st = offset + (i / 2);
-+ if (i % 2) {
-+ if (debug > 2)
-+ printk(KERN_CRIT "qozap: HDLC RX irq fifo %d span %d\n", i, st+1);
-+ qoztmp->st[st].drx += 1;
-+ } else {
-+ if (debug > 2)
-+ printk(KERN_CRIT "qozap: HDLC TX irq fifo %d span %d\n", i, st+1);
-+ }
-+ }
-+ }
-+ }
-+ } else {
-+ if (irq_foview & 0x80) {
-+ fi = qoz_inb(qoztmp,qoz_R_IRQ_FIFO_BL7);
-+ for (i=0; i < 8; i++) {
-+ if (fi & (1 << i)) {
-+ st = i / 2;
-+ if (i % 2) {
-+ if (debug > 2)
-+ printk(KERN_CRIT "qozap: HDLC RX irq fifo %d span %d\n", i, st+1);
-+ qoztmp->st[st].drx += 1;
-+ } else {
-+ if (debug > 2)
-+ printk(KERN_CRIT "qozap: HDLC TX irq fifo %d span %d\n", i, st+1);
-+ }
-+ }
-+ }
-+ }
-+ }
-+ }
-+
-+ spin_unlock_irqrestore(&(qoztmp->lock),flags);
-+#ifdef LINUX26
-+ return IRQ_RETVAL(1);
-+#endif
-+}
-+
-+static int ztqoz_open(struct zt_chan *chan) {
-+// printk(KERN_INFO "qozap: channel %d opened.\n",chan->channo);
-+#ifndef LINUX26
-+ MOD_INC_USE_COUNT;
-+#else
-+ try_module_get(THIS_MODULE);
-+#endif
-+ return 0;
-+}
-+
-+static int ztqoz_close(struct zt_chan *chan) {
-+// printk(KERN_INFO "qozap: channel %d closed.\n",chan->channo);
-+#ifndef LINUX26
-+ MOD_DEC_USE_COUNT;
-+#else
-+ module_put(THIS_MODULE);
-+#endif
-+ return 0;
-+}
-+
-+static int ztqoz_rbsbits(struct zt_chan *chan, int bits) {
-+ return 0;
-+}
-+
-+static int ztqoz_ioctl(struct zt_chan *chan, unsigned int cmd, unsigned long data) {
-+ switch(cmd) {
-+ default:
-+ return -ENOTTY;
-+ }
-+ return 0;
-+}
-+
-+static int ztqoz_startup(struct zt_span *span) {
-+ struct zt_qoz *qozt = span->pvt;
-+ struct qoz_card *qoztmp = qozt->card;
-+ unsigned long flags;
-+ int alreadyrunning;
-+ int i=0;
-+ int offset = 0;
-+
-+ if (qoztmp == NULL) {
-+ printk(KERN_INFO "qozap: no card for span at startup!\n");
-+ }
-+
-+ alreadyrunning = span->flags & ZT_FLAG_RUNNING;
-+// printk(KERN_CRIT "already running %d flags %d\n", alreadyrunning, span->flags);
-+
-+ if (!alreadyrunning) {
-+ span->chans[2].flags &= ~ZT_FLAG_HDLC;
-+ span->chans[2].flags |= ZT_FLAG_BRIDCHAN;
-+
-+ /* setup B channel buffers (8 bytes each) */
-+ for (i=0; i<2 ; i++) {
-+ memset(qoztmp->rxbuf[span->offset][i],0x0,sizeof(qoztmp->rxbuf[span->offset][i]));
-+ span->chans[i].readchunk = qoztmp->rxbuf[span->offset][i];
-+ memset(qoztmp->txbuf[span->offset][i],0x0,sizeof(qoztmp->txbuf[span->offset][i]));
-+ span->chans[i].writechunk = qoztmp->txbuf[span->offset][i];
-+ }
-+ /* setup D channel buffer */
-+ memset(qoztmp->dtxbuf[span->offset],0x0,sizeof(qoztmp->dtxbuf[span->offset]));
-+ span->chans[2].writechunk = qoztmp->dtxbuf[span->offset];
-+ qoztmp->ztdev->chans[span->offset][2].maxbytes2transmit = sizeof(qoztmp->dtxbuf[span->offset]);
-+
-+ memset(qoztmp->drxbuf[span->offset],0x0,sizeof(qoztmp->drxbuf[span->offset]));
-+ span->chans[2].readchunk = qoztmp->drxbuf[span->offset];
-+
-+ span->flags |= ZT_FLAG_RUNNING;
-+ } else {
-+// printk(KERN_CRIT "already running\n");
-+ return 0;
-+ }
-+
-+ spin_lock_irqsave(&qoztmp->lock,flags);
-+ // irqs off
-+ qoz_outb(qoztmp,qoz_R_IRQ_CTRL, 0);
-+
-+ if (qoztmp->type == 0xb552) {
-+ offset = 24;
-+ } else {
-+ offset = 28;
-+ }
-+
-+ /* setup D-FIFO TX */
-+ qoz_outb(qoztmp,qoz_R_FIFO,(span->offset + offset) << 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x2);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0xD);
-+ qoz_outb(qoztmp,qoz_A_SUBCH_CFG,0x2);
-+ qoz_outb(qoztmp,qoz_A_CHANNEL,((span->offset * 4) + 2) << 1);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x1);
-+
-+ /* setup D-FIFO RX */
-+ qoz_outb(qoztmp,qoz_R_FIFO,((span->offset + offset) << 1) | 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x2);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0xD);
-+ qoz_outb(qoztmp,qoz_A_SUBCH_CFG,0x2);
-+ qoz_outb(qoztmp,qoz_A_CHANNEL,(((span->offset * 4) + 2) << 1) | 1);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x1);
-+
-+ /* setup B1-FIFO TX */
-+ qoz_outb(qoztmp,qoz_R_FIFO,(span->offset * 2) << 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x2);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x2);
-+ qoz_outb(qoztmp,qoz_A_CHANNEL,(span->offset * 4) << 1);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x1);
-+
-+ /* setup B1-FIFO RX */
-+ qoz_outb(qoztmp,qoz_R_FIFO,((span->offset * 2) << 1) | 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x2);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x2);
-+ qoz_outb(qoztmp,qoz_A_CHANNEL,((span->offset * 4) << 1) | 1);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x1);
-+
-+ /* setup B2-FIFO TX */
-+ qoz_outb(qoztmp,qoz_R_FIFO,((span->offset * 2) + 1) << 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x2);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x2);
-+ qoz_outb(qoztmp,qoz_A_CHANNEL,((span->offset * 4) + 1) << 1);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x1);
-+
-+ /* setup B2-FIFO RX */
-+ qoz_outb(qoztmp,qoz_R_FIFO,(((span->offset * 2) + 1) << 1) | 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x2);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x2);
-+ qoz_outb(qoztmp,qoz_A_CHANNEL,((((span->offset) * 4) + 1) << 1) | 1);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x1);
-+
-+ if (debug)
-+ printk(KERN_INFO "qozap: starting card %d span %d/%d.\n",qoztmp->cardno,span->spanno,span->offset);
-+
-+ /* activate layer 1 */
-+ qoz_outb(qoztmp,qoz_R_ST_SEL,span->offset);
-+ if (qoztmp->st[span->offset].nt_mode == 1) {
-+ // NT mode
-+ qoz_outb(qoztmp,qoz_A_ST_CTRL0,0x7);
-+ qoz_outb(qoztmp,qoz_A_ST_CTRL1,0x0);
-+ qoz_outb(qoztmp,qoz_A_ST_CTRL2,0x3);
-+ qoz_outb(qoztmp,qoz_A_ST_CLK_DLY,0x60 | CLKDEL_NT);
-+ } else {
-+ // TE mode
-+ qoz_outb(qoztmp,qoz_A_ST_CTRL0,0x3);
-+ qoz_outb(qoztmp,qoz_A_ST_CTRL1,0x0);
-+ qoz_outb(qoztmp,qoz_A_ST_CTRL2,0x3);
-+ if (qoztmp->type == 0xb550) {
-+ qoz_outb(qoztmp,qoz_A_ST_CLK_DLY,CLKDEL_TE);
-+ } else {
-+ qoz_outb(qoztmp,qoz_A_ST_CLK_DLY,CLKDEL_TE + 1);
-+ }
-+ }
-+ qoztmp->st[span->offset].t3 = 0;
-+ qoztmp->st[span->offset].t4 = -1;
-+
-+ qoz_outb(qoztmp,qoz_R_ST_SEL,span->offset);
-+ if (qoztmp->st[span->offset].nt_mode == 1) {
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x80);
-+ } else {
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x0);
-+ }
-+ /* enable irqs */
-+ qoz_outb(qoztmp,qoz_R_IRQ_CTRL, 8 | 1);
-+ spin_unlock_irqrestore(&qoztmp->lock,flags);
-+
-+ qoz_outb(qoztmp,qoz_R_ST_SEL,span->offset);
-+ if (qoztmp->st[span->offset].nt_mode == 1) {
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x60 | 0x80); // ACT, G2->G3 EN
-+ } else {
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x60); // start Activation
-+ }
-+
-+ return 0;
-+}
-+
-+static int ztqoz_shutdown(struct zt_span *span) {
-+ struct zt_qoz *ztqoz = span->pvt;
-+ struct qoz_card *qoztmp = ztqoz->card;
-+ int alreadyrunning;
-+ int offset = 0;
-+
-+ if (qoztmp == NULL) {
-+ printk(KERN_CRIT "qozap: qoztmp == NULL!\n");
-+ return 0;
-+
-+ }
-+
-+ alreadyrunning = span->flags & ZT_FLAG_RUNNING;
-+
-+ if (!alreadyrunning) {
-+ return 0;
-+ }
-+
-+// printk(KERN_CRIT "qozap: stopping card %d port %d.\n",qoztmp->cardno, span->offset + 1);
-+
-+ // turn off irqs for all fifos
-+ if (qoztmp->type == 0xb552) {
-+ offset = 24;
-+ } else {
-+ offset = 28;
-+ }
-+
-+ /* disable D TX fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,(span->offset + offset) << 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x1);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x0);
-+
-+ /* disable D RX fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,((span->offset + offset) << 1) | 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x1);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x0);
-+
-+ /* disable B1 TX fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,(span->offset * 2) << 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x2);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x0);
-+
-+ /* disable B1 RX fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,((span->offset * 2) << 1) | 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x2);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x0);
-+
-+ /* disable B2 TX fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,(((span->offset) * 2) + 1) << 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x2);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x0);
-+
-+ /* disable B2 RX fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,((((span->offset) * 2) + 1) << 1) | 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x2);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x0);
-+
-+ span->flags &= ~ZT_FLAG_RUNNING;
-+
-+ /* Deactivate Layer 1 */
-+ qoz_outb(qoztmp,qoz_R_ST_SEL,span->offset);
-+ if (qoztmp->st[span->offset].nt_mode == 1) {
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x40);
-+ } else {
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x40);
-+ }
-+
-+
-+// printk(KERN_CRIT "qozap: card %d span %d/%d down.\n",qoztmp->cardno,span->spanno,span->offset);
-+ return 0;
-+}
-+
-+static int ztqoz_maint(struct zt_span *span, int cmd) {
-+ return 0;
-+}
-+
-+static int ztqoz_chanconfig(struct zt_chan *chan,int sigtype) {
-+// printk(KERN_INFO "chan_config sigtype=%d\n",sigtype);
-+ return 0;
-+}
-+
-+static int ztqoz_spanconfig(struct zt_span *span,struct zt_lineconfig *lc) {
-+// span->lineconfig = lc->lineconfig;
-+ return 0;
-+}
-+
-+static int ztqoz_initialize(struct zt_qoz *ztqoz) {
-+ struct qoz_card *qoztmp = ztqoz->card;
-+ int i=0,s=0;
-+
-+ for (s=0; s < ztqoz->card->stports; s++) {
-+ memset(&ztqoz->spans[s],0,sizeof(struct zt_span)); // you never can tell...
-+ sprintf(ztqoz->spans[s].name,"ztqoz/%d/%d",qoz_dev_count + 1,s + 1);
-+ if (ztqoz->card->stports == 8) {
-+ if (qoztmp->st[s].nt_mode == 1){
-+ sprintf(ztqoz->spans[s].desc,"octoBRI PCI ISDN Card %d Span %d [NT]",qoztmp->cardno,s + 1);
-+ } else {
-+ sprintf(ztqoz->spans[s].desc,"octoBRI PCI ISDN Card %d Span %d [TE]",qoztmp->cardno,s + 1);
-+ }
-+ } else {
-+ if (ztqoz->card->cardID < 0xff) {
-+ if (qoztmp->st[s].nt_mode == 1){
-+ sprintf(ztqoz->spans[s].desc,"quadBRI PCI ISDN Card %d Span %d [NT] (cardID %d)",qoztmp->cardno,s + 1,ztqoz->card->cardID);
-+ } else {
-+ sprintf(ztqoz->spans[s].desc,"quadBRI PCI ISDN Card %d Span %d [TE] (cardID %d)",qoztmp->cardno,s + 1,ztqoz->card->cardID);
-+ }
-+ } else {
-+ if (qoztmp->st[s].nt_mode == 1){
-+ sprintf(ztqoz->spans[s].desc,"quadBRI PCI ISDN Card %d Span %d [NT]",qoztmp->cardno,s + 1);
-+ } else {
-+ sprintf(ztqoz->spans[s].desc,"quadBRI PCI ISDN Card %d Span %d [TE]",qoztmp->cardno,s + 1);
-+ }
-+ }
-+ }
-+
-+ ztqoz->spans[s].spanconfig = ztqoz_spanconfig;
-+ ztqoz->spans[s].chanconfig = ztqoz_chanconfig;
-+ ztqoz->spans[s].startup = ztqoz_startup;
-+ ztqoz->spans[s].shutdown = ztqoz_shutdown;
-+ ztqoz->spans[s].maint = ztqoz_maint;
-+ ztqoz->spans[s].rbsbits = ztqoz_rbsbits;
-+ ztqoz->spans[s].open = ztqoz_open;
-+ ztqoz->spans[s].close = ztqoz_close;
-+ ztqoz->spans[s].ioctl = ztqoz_ioctl;
-+
-+ ztqoz->spans[s].chans = ztqoz->chans[s];
-+ ztqoz->spans[s].channels = 3;
-+ ztqoz->spans[s].deflaw = ZT_LAW_ALAW;
-+ ztqoz->spans[s].linecompat = ZT_CONFIG_AMI | ZT_CONFIG_CCS; // <--- this is really BS
-+ init_waitqueue_head(&ztqoz->spans[s].maintq);
-+ ztqoz->spans[s].pvt = ztqoz;
-+ ztqoz->spans[s].offset = s;
-+
-+ for (i=0; i < ztqoz->spans[s].channels; i++) {
-+ memset(&(ztqoz->chans[s][i]),0x0,sizeof(struct zt_chan));
-+ sprintf(ztqoz->chans[s][i].name,"ztqoz%d/%d/%d",qoz_dev_count + 1,s + 1,i + 1);
-+ ztqoz->chans[s][i].pvt = ztqoz;
-+ ztqoz->chans[s][i].sigcap = ZT_SIG_EM | ZT_SIG_CLEAR | ZT_SIG_FXSLS | ZT_SIG_FXSGS | ZT_SIG_FXSKS | ZT_SIG_FXOLS | ZT_SIG_FXOGS | ZT_SIG_FXOKS | ZT_SIG_CAS | ZT_SIG_SF;
-+ ztqoz->chans[s][i].chanpos = i + 1;
-+ }
-+
-+ if (zt_register(&ztqoz->spans[s],0)) {
-+ printk(KERN_INFO "qozap: unable to register zaptel span %d!\n",s+1);
-+ return -1;
-+ }
-+// printk(KERN_INFO "qozap: registered zaptel span %d.\n",s+1);
-+ }
-+
-+ return 0;
-+}
-+
-+int qoz_findCards(unsigned int pcidid) {
-+ struct pci_dev *tmp;
-+ struct qoz_card *qoztmp = NULL;
-+ struct zt_qoz *ztqoz = NULL;
-+ int i=0;
-+ unsigned char dips=0;
-+ int cid=0;
-+ int modes=0;
-+ tmp = pci_find_device(PCI_VENDOR_ID_CCD,pcidid,multi_qoz);
-+ while (tmp != NULL) {
-+ multi_qoz = tmp; // skip this next time.
-+
-+ if (pci_enable_device(tmp)) {
-+ multi_qoz = NULL;
-+ return -1;
-+ }
-+
-+ qoztmp = kmalloc(sizeof(struct qoz_card),GFP_KERNEL);
-+ if (!qoztmp) {
-+ printk(KERN_WARNING "qozap: unable to kmalloc!\n");
-+ pci_disable_device(tmp);
-+ multi_qoz = NULL;
-+ return -ENOMEM;
-+ }
-+ memset(qoztmp, 0x0, sizeof(struct qoz_card));
-+
-+ spin_lock_init(&qoztmp->lock);
-+ qoztmp->pcidev = tmp;
-+ qoztmp->pcibus = tmp->bus->number;
-+ qoztmp->pcidevfn = tmp->devfn;
-+
-+ if (!tmp->irq) {
-+ printk(KERN_WARNING "qozap: no irq!\n");
-+ } else {
-+ qoztmp->irq = tmp->irq;
-+ }
-+
-+ qoztmp->pci_io = (char *) tmp->resource[1].start;
-+ if (!qoztmp->pci_io) {
-+ printk(KERN_WARNING "qozap: no iomem!\n");
-+ pci_disable_device(tmp);
-+ multi_qoz = NULL;
-+ return -EIO;
-+ }
-+
-+ qoztmp->ioport = tmp->resource[0].start;
-+ if (!qoztmp->ioport) {
-+ printk(KERN_WARNING "qozap: no ioport!\n");
-+ pci_disable_device(tmp);
-+ multi_qoz = NULL;
-+ return -EIO;
-+ }
-+ if (!request_region(qoztmp->ioport, 7, "qozap")) {
-+ printk(KERN_WARNING "qozap: couldnt request io range!\n");
-+ pci_disable_device(tmp);
-+ multi_qoz = NULL;
-+ return -EIO;
-+ }
-+
-+ if (request_irq(qoztmp->irq, qoz_interrupt, SA_INTERRUPT | SA_SHIRQ, "qozap", qoztmp)) {
-+ printk(KERN_WARNING "qozap: unable to register irq\n");
-+ kfree(qoztmp);
-+ pci_disable_device(tmp);
-+ multi_qoz = NULL;
-+ return -EIO;
-+ }
-+
-+ qoztmp->pci_io = ioremap((ulong) qoztmp->pci_io, 256);
-+
-+ pci_write_config_word(qoztmp->pcidev, PCI_COMMAND, PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
-+
-+ // disable ints
-+ qoz_outb(qoztmp,qoz_R_IRQ_CTRL, 0);
-+
-+ ztqoz = kmalloc(sizeof(struct zt_qoz),GFP_KERNEL);
-+ if (!ztqoz) {
-+ printk(KERN_INFO "qozap: unable to kmalloc!\n");
-+ qoz_shutdownCard(qoztmp);
-+ kfree(qoztmp);
-+ multi_qoz = NULL;
-+ return -ENOMEM;
-+ }
-+ memset(ztqoz, 0x0, sizeof(struct zt_qoz));
-+
-+ if (pcidid == PCI_DEVICE_ID_CCD_M) {
-+ qoztmp->stports = 8;
-+ } else {
-+ qoztmp->stports = 4;
-+ }
-+
-+
-+ if ((tmp->subsystem_device==0xb520) && (pcidid == PCI_DEVICE_ID_CCD_M4)) {
-+ // printk(KERN_INFO "MODES = %#x.\n",modes);
-+ qoz_outb(qoztmp,qoz_R_GPIO_SEL,0x80 | 0x40);
-+ dips = (qoz_inb(qoztmp,qoz_R_GPIO_IN1) >> 5);
-+ cid = 7;
-+ for (i=0;i<3;i++) {
-+ if ((dips & (1 << i)) != 0) {
-+ cid -= (1 << (2-i));
-+ }
-+ }
-+ // printk(KERN_INFO "DIPS = %#x CID= %#x\n",dips,cid);
-+ } else if ((tmp->subsystem_device==0xb550) && (pcidid == PCI_DEVICE_ID_CCD_M4)) {
-+ // printk(KERN_INFO "MODES = %#x.\n",modes);
-+ dips = ~(qoz_inb(qoztmp,qoz_R_GPI_IN3) & 7);
-+ cid = 0;
-+ for (i=0;i<3;i++) {
-+ if ((dips & (1 << i)) != 0) {
-+ cid += (1 << i);
-+ }
-+ }
-+ printk(KERN_INFO "DIPS = %#x CID= %#x\n",dips,cid);
-+ } else {
-+ cid = 0xff;
-+ }
-+
-+ if (ports == -1) {
-+ if ((tmp->subsystem_device==0xb520) && (pcidid == PCI_DEVICE_ID_CCD_M4)) {
-+ modes = qoz_inb(qoztmp,qoz_R_GPI_IN3) >> 4;
-+ } else if ((tmp->subsystem_device==0xb550) && (pcidid == PCI_DEVICE_ID_CCD_M4)) {
-+ qoz_outb(qoztmp,qoz_R_GPIO_SEL,0xff);
-+ qoz_outb(qoztmp,qoz_R_GPIO_EN0,0x00);
-+ printk(KERN_CRIT "gpio_in0 %#x \n", qoz_inb(qoztmp,qoz_R_GPIO_IN0));
-+ printk(KERN_CRIT "gpio_in1 %#x \n", qoz_inb(qoztmp,qoz_R_GPIO_IN1));
-+ printk(KERN_CRIT "gpi_in1 %#x \n", qoz_inb(qoztmp,qoz_R_GPI_IN1));
-+ printk(KERN_CRIT "gpi_in2 %#x \n", qoz_inb(qoztmp,qoz_R_GPI_IN2));
-+ printk(KERN_CRIT "gpi_in3 %#x \n", qoz_inb(qoztmp,qoz_R_GPI_IN3));
-+ modes = qoz_inb(qoztmp,qoz_R_GPI_IN3) >> 4;
-+ } else {
-+ modes = 0; // assume TE mode
-+ }
-+ } else {
-+ modes = ports >> totalBRIs;
-+ }
-+
-+ if (pcidid == PCI_DEVICE_ID_CCD_M4) {
-+ switch (tmp->subsystem_device) {
-+ case 0x08b4:
-+ if (ports == -1) ports = 0; /* assume TE mode if no ports param */
-+ printk(KERN_INFO
-+ "qozap: CologneChip HFC-4S evaluation board configured at io port %#x IRQ %d HZ %d\n",
-+ (u_int) qoztmp->ioport,
-+ qoztmp->irq, HZ);
-+ break;
-+ case 0xb520:
-+ printk(KERN_INFO
-+ "qozap: Junghanns.NET quadBRI card configured at io port %#x IRQ %d HZ %d CardID %d\n",
-+ (u_int) qoztmp->ioport,
-+ qoztmp->irq, HZ, cid);
-+ break;
-+ case 0xb550:
-+ printk(KERN_INFO
-+ "qozap: Junghanns.NET quadBRI (Version 2.0) card configured at io port %#x IRQ %d HZ %d CardID %d\n",
-+ (u_int) qoztmp->ioport,
-+ qoztmp->irq, HZ, cid);
-+ break;
-+ }
-+ totalBRIs += 4;
-+ } else {
-+ switch (tmp->subsystem_device) {
-+ case 0xb552:
-+ printk(KERN_INFO
-+ "qozap: Junghanns.NET octoBRI card configured at io port %#x IRQ %d HZ %d\n",
-+ (u_int) qoztmp->ioport,
-+ qoztmp->irq, HZ);
-+ break;
-+ default:
-+ if (qoztmp->pcidev != NULL) {
-+ pci_disable_device(qoztmp->pcidev);
-+ }
-+ pci_write_config_word(qoztmp->pcidev, PCI_COMMAND, 0);
-+ free_irq(qoztmp->irq,qoztmp);
-+ kfree(qoztmp);
-+ qoztmp = NULL;
-+ tmp = pci_find_device(PCI_VENDOR_ID_CCD,pcidid,multi_qoz);
-+ continue;
-+ break;
-+ }
-+ totalBRIs += 8;
-+ }
-+
-+ qoztmp->cardID = cid;
-+ qoztmp->type = tmp->subsystem_device;
-+
-+ printk(KERN_INFO "qozap: S/T ports: %d [",qoztmp->stports);
-+ for (i=0;i<qoztmp->stports;i++) {
-+ if ((modes & (1 << i)) != 0) {
-+ qoztmp->st[i].nt_mode = 1;
-+ printk(" NT");
-+ } else {
-+ qoztmp->st[i].nt_mode = 0;
-+ printk(" TE");
-+ }
-+ }
-+ printk(" ]\n");
-+
-+ ztqoz->card = qoztmp;
-+ qoztmp->ztdev = ztqoz;
-+
-+ qoz_registerCard(qoztmp);
-+ tmp = pci_find_device(PCI_VENDOR_ID_CCD,pcidid,multi_qoz);
-+ }
-+ return 0;
-+}
-+
-+
-+int qoz_sortCards(void) {
-+ int changed=0,tmpcardno;
-+ struct qoz_card *tmpcard,*tmpcard2;
-+ spin_lock(®isterlock);
-+ do {
-+ changed = 0;
-+ tmpcard = qoz_dev_list;
-+ while (tmpcard != NULL) {
-+ if (tmpcard->prev) {
-+ if (tmpcard->prev->cardID > tmpcard->cardID) {
-+ tmpcardno = tmpcard->prev->cardno;
-+ tmpcard->prev->cardno = tmpcard->cardno;
-+ tmpcard->cardno = tmpcardno;
-+
-+ tmpcard2 = tmpcard->prev;
-+ if (tmpcard2->prev) {
-+ tmpcard2->prev->next = tmpcard;
-+ } else {
-+ qoz_dev_list = tmpcard;
-+ }
-+ if (tmpcard->next) {
-+ tmpcard->next->prev = tmpcard2;
-+ }
-+ tmpcard2->next = tmpcard->next;
-+ tmpcard->prev = tmpcard2->prev;
-+ tmpcard->next = tmpcard2;
-+ tmpcard2->prev = tmpcard;
-+ changed = 1;
-+ tmpcard = tmpcard2;
-+ }
-+ }
-+ tmpcard = tmpcard->next;
-+ }
-+ } while (changed == 1);
-+ spin_unlock(®isterlock);
-+ return 0;
-+}
-+
-+int qoz_zapCards(void) {
-+ struct qoz_card *tmpcard;
-+ tmpcard = qoz_dev_list;
-+ while (tmpcard != NULL) {
-+ ztqoz_initialize(tmpcard->ztdev);
-+ qoz_resetCard(tmpcard);
-+ tmpcard = tmpcard->next;
-+ }
-+ return 0;
-+}
-+
-+
-+int init_module(void) {
-+ multi_qoz = NULL;
-+ qoz_findCards(PCI_DEVICE_ID_CCD_M4);
-+ qoz_findCards(PCI_DEVICE_ID_CCD_M);
-+ qoz_sortCards();
-+ qoz_zapCards();
-+ if (qoz_dev_count == 0) {
-+ printk(KERN_INFO "qozap: no multiBRI cards found.\n");
-+ } else {
-+ printk(KERN_INFO "qozap: %d multiBRI card(s) in this box, %d BRI ports total, bloop %d.\n",qoz_dev_count, totalBRIs, bloop);
-+ }
-+ return 0;
-+}
-+
-+void cleanup_module(void) {
-+ struct qoz_card *tmpcard,*tmplist;
-+ int i=0;
-+ tmplist = qoz_dev_list;
-+ while (tmplist != NULL) {
-+ qoz_undoWD(tmplist);
-+ qoz_shutdownCard(tmplist);
-+ tmplist = tmplist->next;
-+ }
-+ tmplist = qoz_dev_list;
-+ spin_lock(®isterlock);
-+ while (tmplist != NULL) {
-+ tmpcard = tmplist->next;
-+ kfree(tmplist);
-+ i++;
-+ tmplist = tmpcard;
-+ }
-+ spin_unlock(®isterlock);
-+ printk(KERN_INFO "qozap: shutdown %d multiBRI cards.\n", i);
-+}
-+#endif
-+
-+MODULE_PARM(doubleclock,"i");
-+MODULE_PARM(ports,"i");
-+MODULE_PARM(bloop,"i");
-+MODULE_PARM(debug,"i");
-+MODULE_DESCRIPTION("quad/octo BRI zaptel driver");
-+MODULE_AUTHOR("Klaus-Peter Junghanns <kpj at junghanns.net>");
-+#ifdef MODULE_LICENSE
-+MODULE_LICENSE("GPL");
-+#endif
-diff -urNad zaptel-1.2.1/qozap/qozap.h /tmp/dpep.LWjGif/zaptel-1.2.1/qozap/qozap.h
---- zaptel-1.2.1/qozap/qozap.h 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.LWjGif/zaptel-1.2.1/qozap/qozap.h 2005-06-13 11:56:43.000000000 +0300
-@@ -0,0 +1,237 @@
-+#define qoz_SPANS 8
-+#define qoz_FIFO_SIZE 128
-+#define qoz_DFIFO_SIZE4 2048
-+#define qoz_DFIFO_SIZE8 1024
-+
-+typedef struct qoz_span {
-+ unsigned char nt_mode;
-+ unsigned char btx;
-+ unsigned char bswapped;
-+ unsigned char drx;
-+ int t3;
-+ int t4;
-+ unsigned char layer1state;
-+} qoz_span;
-+
-+typedef struct qoz_regs {
-+ unsigned char fifo_en;
-+ unsigned char ctmt;
-+ unsigned char int_m1;
-+ unsigned char int_m2;
-+ unsigned char sctrl;
-+ unsigned char sctrl_e;
-+ unsigned char sctrl_r;
-+ unsigned char connect;
-+ unsigned char trm;
-+ unsigned char mst_mode;
-+} qoz_regs;
-+
-+typedef struct qoz_card {
-+ spinlock_t lock;
-+ int cardID;
-+ unsigned char leds[8];
-+ unsigned char cardno;
-+ unsigned int irq;
-+ unsigned int iomem;
-+ unsigned char *pci_io;
-+ unsigned long ioport;
-+ struct qoz_span st[qoz_SPANS];
-+ unsigned int pcibus;
-+ unsigned int pcidevfn;
-+ struct pci_dev *pcidev;
-+ struct zt_qoz *ztdev;
-+ unsigned char rxbuf[qoz_SPANS][2][ZT_CHUNKSIZE];
-+ unsigned char txbuf[qoz_SPANS][2][ZT_CHUNKSIZE];
-+ unsigned char drxbuf[qoz_SPANS][qoz_DFIFO_SIZE4];
-+ unsigned char dtxbuf[qoz_SPANS][qoz_DFIFO_SIZE4];
-+ unsigned char stports;
-+ unsigned int ticks;
-+ unsigned int clicks;
-+ unsigned int type;
-+ unsigned int wdp;
-+ struct qoz_card *next;
-+ struct qoz_card *prev;
-+} qoz_card;
-+
-+
-+typedef struct zt_qoz {
-+ unsigned int usecount;
-+ struct zt_span spans[qoz_SPANS];
-+ struct zt_chan chans[qoz_SPANS][3];
-+ struct qoz_card *card;
-+} zt_qoz;
-+
-+#define qoz_outb_io(a,b,c) \
-+ outw((b), ((a)->ioport+4)); \
-+ outb((c), ((a)->ioport));
-+
-+#define qoz_inb_io(a,b) ({ outw((b), (a)->ioport+4); inb((a)->ioport); })
-+
-+#define qoz_outw_io(a,b,c) \
-+ outw((b), ((a)->ioport+4)); \
-+ outw((c), ((a)->ioport));
-+
-+#define qoz_inw_io(a,b) ({ outw((b), (a)->ioport+4); inw((a)->ioport); })
-+
-+#define qoz_outdw_io(a,b,c) \
-+ outw((b), ((a)->ioport+4)); \
-+ outl((c), ((a)->ioport));
-+
-+#define qoz_indw_io(a,b) ({ outw((b), (a)->ioport+4); inl((a)->ioport); })
-+
-+#define qoz_outb(a,b,c) (writeb((c),(a)->pci_io+(b)))
-+#define qoz_inb(a,b) (readb((a)->pci_io+(b)))
-+
-+#define qoz_outw(a,b,c) (writew((c),(a)->pci_io+(b)))
-+#define qoz_inw(a,b) (readw((a)->pci_io+(b)))
-+
-+#define qoz_outdw(a,b,c) (writel((c),(a)->pci_io+(b)))
-+#define qoz_indw(a,b) (readl((a)->pci_io+(b)))
-+
-+
-+/* Write only registers */
-+#define qoz_A_CH_MSK 0xF4
-+#define qoz_A_CHANNEL 0xFC
-+#define qoz_A_CON_HDLC 0xFA
-+#define qoz_A_CONF 0xD1
-+#define qoz_A_FIFO_SEQ 0xFD
-+#define qoz_R_INC_RES_FIFO 0x0E
-+#define qoz_A_IRQ_MSK 0xFF
-+#define qoz_A_SL_CFG 0xD0
-+#define qoz_A_ST_B1_TX 0x3C
-+#define qoz_A_ST_B2_TX 0x3D
-+#define qoz_A_ST_CLK_DLY 0x37
-+#define qoz_A_ST_CTRL0 0x31
-+#define qoz_A_ST_CTRL1 0x32
-+#define qoz_A_ST_CTRL2 0x33
-+#define qoz_A_ST_D_TX 0x3E
-+#define qoz_A_ST_SQ_WR 0x34
-+#define qoz_A_ST_WR_STA 0x30
-+#define qoz_A_SUBCH_CFG 0xFB
-+#define qoz_R_BERT_WD_MD 0x1B
-+#define qoz_R_BRG_CTRL 0x45
-+#define qoz_R_BRG_MD 0x47
-+#define qoz_R_BRG_PCM_CFG 0x02
-+#define qoz_R_BRG_TIM_SEL01 0x4C
-+#define qoz_R_BRG_TIM_SEL23 0x4D
-+#define qoz_R_BRG_TIM_SEL45 0x4E
-+#define qoz_R_BRG_TIM_SEL67 0x4F
-+#define qoz_R_BRG_TIM0 0x48
-+#define qoz_R_BRG_TIM1 0x49
-+#define qoz_R_BRG_TIM2 0x4A
-+#define qoz_R_BRG_TIM3 0x4B
-+#define qoz_R_CIRM 0x00
-+#define qoz_R_CONF_EN 0x18
-+#define qoz_R_CTRL 0x01
-+#define qoz_R_DTMF0 0x1C
-+#define qoz_R_DTMF1 0x1D
-+#define qoz_R_FIFO_MD 0x0D
-+#define qoz_R_FIFO 0x0F
-+#define qoz_R_FIRST_FIFO 0x0B
-+#define qoz_R_FSM_IDX 0x0F
-+#define qoz_R_GPIO_EN0 0x42
-+#define qoz_R_GPIO_EN1 0x43
-+#define qoz_R_GPIO_OUT0 0x40
-+#define qoz_R_GPIO_OUT1 0x41
-+#define qoz_R_GPIO_SEL 0x44
-+#define qoz_R_IRQ_CTRL 0x13
-+#define qoz_R_IRQMSK_MISC 0x11
-+#define qoz_R_PCM_MD0 0x14
-+#define qoz_R_PCM_MD1 0x15
-+#define qoz_R_PCM_MD2 0x15
-+#define qoz_R_PWM_MD 0x46
-+#define qoz_R_PWM0 0x38
-+#define qoz_R_PWM1 0x39
-+#define qoz_R_RAM_ADDR0 0x08
-+#define qoz_R_RAM_ADDR1 0x09
-+#define qoz_R_RAM_ADDR2 0x0A
-+#define qoz_R_RAM_MISC 0x0C
-+#define qoz_R_SCI_MSK 0x12
-+#define qoz_R_SH0H 0x15
-+#define qoz_R_SH0L 0x15
-+#define qoz_R_SH1H 0x15
-+#define qoz_R_SH1L 0x15
-+#define qoz_R_SL_SEL0 0x15
-+#define qoz_R_SL_SEL1 0x15
-+#define qoz_R_SL_SEL2 0x15
-+#define qoz_R_SL_SEL3 0x15
-+#define qoz_R_SL_SEL4 0x15
-+#define qoz_R_SL_SEL5 0x15
-+#define qoz_R_SL_SEL6 0x15
-+#define qoz_R_SL_SEL7 0x15
-+#define qoz_R_SLOT 0x10
-+#define qoz_R_ST_SEL 0x16
-+#define qoz_R_ST_SYNC 0x17
-+#define qoz_R_TI_WD 0x1A
-+
-+/* Read only registers */
-+#define qoz_A_F1 0x0C
-+#define qoz_A_F12 0x0C
-+#define qoz_A_F2 0x0D
-+#define qoz_A_ST_B1_RX 0x3C
-+#define qoz_A_ST_B2_TX 0x3D
-+#define qoz_A_ST_D_RX 0x3E
-+#define qoz_A_ST_E_RX 0x3F
-+#define qoz_A_ST_RD_STA 0x30
-+#define qoz_A_ST_SQ_RD 0x34
-+#define qoz_A_Z1 0x04
-+#define qoz_A_Z12 0x04
-+#define qoz_A_Z1H 0x05
-+#define qoz_A_Z1L 0x04
-+#define qoz_A_Z2 0x06
-+#define qoz_A_Z2H 0x07
-+#define qoz_A_Z2L 0x06
-+#define qoz_R_BERT_ECH 0x1B
-+#define qoz_R_BERT_ECL 0x1A
-+#define qoz_R_BERT_STA 0x17
-+#define qoz_R_CHIP_ID 0x16
-+#define qoz_R_CHIP_RV 0x1F
-+#define qoz_R_CONF_OFLOW 0x14
-+#define qoz_R_F0_CNTH 0x19
-+#define qoz_R_F0_CNTL 0x18
-+#define qoz_R_GPI_IN0 0x44
-+#define qoz_R_GPI_IN1 0x45
-+#define qoz_R_GPI_IN2 0x46
-+#define qoz_R_GPI_IN3 0x47
-+#define qoz_R_GPIO_IN0 0x40
-+#define qoz_R_GPIO_IN1 0x41
-+#define qoz_R_INT_DATA 0x88
-+#define qoz_R_IRQ_FIFO_BL0 0xC8
-+#define qoz_R_IRQ_FIFO_BL1 0xC9
-+#define qoz_R_IRQ_FIFO_BL2 0xCA
-+#define qoz_R_IRQ_FIFO_BL3 0xCB
-+#define qoz_R_IRQ_FIFO_BL4 0xCC
-+#define qoz_R_IRQ_FIFO_BL5 0xCD
-+#define qoz_R_IRQ_FIFO_BL6 0xCE
-+#define qoz_R_IRQ_FIFO_BL7 0xCF
-+#define qoz_R_IRQ_MISC 0x11
-+#define qoz_R_IRQ_OVIEW 0x10
-+#define qoz_R_RAM_USE 0x15
-+#define qoz_R_SCI 0x12
-+#define qoz_R_STATUS 0x1C
-+
-+/* Read/Write registers */
-+#define qoz_A_FIFO_DATA0_NOINC 0x84
-+#define qoz_A_FIFO_DATA0 0x80
-+#define qoz_A_FIFO_DATA1_NOINC 0x84
-+#define qoz_A_FIFO_DATA1 0x80
-+#define qoz_A_FIFO_DATA2_NOINC 0x84
-+#define qoz_A_FIFO_DATA2 0x80
-+#define qoz_R_RAM_DATA 0xC0
-+
-+#define PCI_DEVICE_ID_CCD_M 0x16b8
-+#define PCI_DEVICE_ID_CCD_M4 0x08b4
-+#define CLKDEL_TE 0xe /* CLKDEL in TE mode */
-+#define CLKDEL_NT 0xc /* CLKDEL in NT mode */
-+
-+#define HFC8S_CHIP_ID 0x80
-+#define HFC4S_CHIP_ID 0xC0
-+
-+#define qoz_WD_P0 0x000000
-+#define qoz_WD_P1 0x808080
-+#define qoz_WD_P2 0x404040
-+
-+#define qoz_T3 3
-+#define qoz_T4 1
-+
-+
-diff -urNad zaptel-1.2.1/qozap/TODO /tmp/dpep.LWjGif/zaptel-1.2.1/qozap/TODO
---- zaptel-1.2.1/qozap/TODO 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.LWjGif/zaptel-1.2.1/qozap/TODO 2005-06-13 10:03:36.000000000 +0300
-@@ -0,0 +1,9 @@
-+- native-native bridging
-+- onchip dtmf
-+- E channel support for full debug
-+
-+
-+t3 (5ms max)
-+
-+t4 (500ms) layer 1 down/up
-+
-diff -urNad zaptel-1.2.1/qozap/zapata.conf /tmp/dpep.LWjGif/zaptel-1.2.1/qozap/zapata.conf
---- zaptel-1.2.1/qozap/zapata.conf 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.LWjGif/zaptel-1.2.1/qozap/zapata.conf 2005-06-13 10:03:36.000000000 +0300
-@@ -0,0 +1,49 @@
-+;
-+; Zapata telephony interface
-+;
-+; Configuration file
-+
-+[channels]
-+;
-+; Default language
-+;
-+;language=en
-+;
-+; Default context
-+;
-+;
-+switchtype = euroisdn
-+
-+; p2mp TE mode (for connecting ISDN lines in point-to-multipoint mode)
-+signalling = bri_cpe_ptmp
-+; p2p TE mode (for connecting ISDN lines in point-to-point mode)
-+;signalling = bri_cpe
-+; p2mp NT mode (for connecting ISDN phones in point-to-multipoint mode)
-+;signalling = bri_net_ptmp
-+; p2p NT mode (for connecting an ISDN pbx in point-to-point mode)
-+;signalling = bri_net
-+
-+pridialplan = local
-+prilocaldialplan = local
-+nationalprefix = 0
-+internationalprefix = 00
-+
-+echocancel = yes
-+
-+context=demo
-+group = 1
-+; S/T port 1
-+channel => 1-2
-+
-+group = 2
-+; S/T port 2
-+channel => 4-5
-+
-+group = 3
-+; S/T port 3
-+channel => 7-8
-+
-+group = 4
-+; S/T port 4
-+channel => 10-11
-+
-diff -urNad zaptel-1.2.1/qozap/zapata.conf.octoBRI /tmp/dpep.LWjGif/zaptel-1.2.1/qozap/zapata.conf.octoBRI
---- zaptel-1.2.1/qozap/zapata.conf.octoBRI 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.LWjGif/zaptel-1.2.1/qozap/zapata.conf.octoBRI 2005-06-13 10:03:36.000000000 +0300
-@@ -0,0 +1,65 @@
-+;
-+; Zapata telephony interface
-+;
-+; Configuration file
-+
-+[channels]
-+;
-+; Default language
-+;
-+;language=en
-+;
-+; Default context
-+;
-+;
-+switchtype = euroisdn
-+
-+; p2mp TE mode (for connecting ISDN lines in point-to-multipoint mode)
-+signalling = bri_cpe_ptmp
-+; p2p TE mode (for connecting ISDN lines in point-to-point mode)
-+;signalling = bri_cpe
-+; p2mp NT mode (for connecting ISDN phones in point-to-multipoint mode)
-+;signalling = bri_net_ptmp
-+; p2p NT mode (for connecting an ISDN pbx in point-to-point mode)
-+;signalling = bri_net
-+
-+pridialplan = local
-+prilocaldialplan = local
-+nationalprefix = 0
-+internationalprefix = 00
-+
-+echocancel = yes
-+
-+context=demo
-+group = 1
-+; S/T port 1
-+channel => 1-2
-+
-+group = 2
-+; S/T port 2
-+channel => 4-5
-+
-+group = 3
-+; S/T port 3
-+channel => 7-8
-+
-+group = 4
-+; S/T port 4
-+channel => 10-11
-+
-+group = 5
-+; S/T port 5
-+channel => 13-14
-+
-+group = 6
-+; S/T port 6
-+channel => 16-17
-+
-+group = 7
-+; S/T port 7
-+channel => 19-20
-+
-+group = 8
-+; S/T port 8
-+channel => 22-23
-+
-diff -urNad zaptel-1.2.1/qozap/zaptel.conf /tmp/dpep.LWjGif/zaptel-1.2.1/qozap/zaptel.conf
---- zaptel-1.2.1/qozap/zaptel.conf 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.LWjGif/zaptel-1.2.1/qozap/zaptel.conf 2005-11-20 16:35:32.000000000 +0200
-@@ -0,0 +1,18 @@
-+loadzone=nl
-+defaultzone=nl
-+# qozap span definitions
-+# most of the values should be bogus because we are not really zaptel
-+span=1,1,3,ccs,ami
-+span=2,2,3,ccs,ami
-+span=3,0,3,ccs,ami
-+span=4,0,3,ccs,ami
-+
-+bchan=1,2
-+dchan=3
-+bchan=4,5
-+dchan=6
-+bchan=7,8
-+dchan=9
-+bchan=10,11
-+dchan=12
-+
-diff -urNad zaptel-1.2.1/qozap/zaptel.conf.octoBRI /tmp/dpep.LWjGif/zaptel-1.2.1/qozap/zaptel.conf.octoBRI
---- zaptel-1.2.1/qozap/zaptel.conf.octoBRI 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.LWjGif/zaptel-1.2.1/qozap/zaptel.conf.octoBRI 2005-06-13 10:03:36.000000000 +0300
-@@ -0,0 +1,30 @@
-+loadzone=nl
-+defaultzone=nl
-+# qozap span definitions
-+# most of the values should be bogus because we are not really zaptel
-+span=1,1,3,ccs,ami
-+span=2,0,3,ccs,ami
-+span=3,0,3,ccs,ami
-+span=4,0,3,ccs,ami
-+span=5,1,3,ccs,ami
-+span=6,0,3,ccs,ami
-+span=7,0,3,ccs,ami
-+span=8,0,3,ccs,ami
-+
-+bchan=1,2
-+dchan=3
-+bchan=4,5
-+dchan=6
-+bchan=7,8
-+dchan=9
-+bchan=10,11
-+dchan=12
-+bchan=13,14
-+dchan=15
-+bchan=16,17
-+dchan=18
-+bchan=19,20
-+dchan=21
-+bchan=22,23
-+dchan=24
-+
-diff -urNad zaptel-1.2.1/zaphfc/LICENSE /tmp/dpep.LWjGif/zaptel-1.2.1/zaphfc/LICENSE
---- zaptel-1.2.1/zaphfc/LICENSE 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.LWjGif/zaptel-1.2.1/zaphfc/LICENSE 2003-08-19 04:24:43.000000000 +0300
-@@ -0,0 +1,341 @@
-+
-+ GNU GENERAL PUBLIC LICENSE
-+ Version 2, June 1991
-+
-+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-+ Everyone is permitted to copy and distribute verbatim copies
-+ of this license document, but changing it is not allowed.
-+
-+ Preamble
-+
-+ The licenses for most software are designed to take away your
-+freedom to share and change it. By contrast, the GNU General Public
-+License is intended to guarantee your freedom to share and change free
-+software--to make sure the software is free for all its users. This
-+General Public License applies to most of the Free Software
-+Foundation's software and to any other program whose authors commit to
-+using it. (Some other Free Software Foundation software is covered by
-+the GNU Library General Public License instead.) You can apply it to
-+your programs, too.
-+
-+ When we speak of free software, we are referring to freedom, not
-+price. Our General Public Licenses are designed to make sure that you
-+have the freedom to distribute copies of free software (and charge for
-+this service if you wish), that you receive source code or can get it
-+if you want it, that you can change the software or use pieces of it
-+in new free programs; and that you know you can do these things.
-+
-+ To protect your rights, we need to make restrictions that forbid
-+anyone to deny you these rights or to ask you to surrender the rights.
-+These restrictions translate to certain responsibilities for you if you
-+distribute copies of the software, or if you modify it.
-+
-+ For example, if you distribute copies of such a program, whether
-+gratis or for a fee, you must give the recipients all the rights that
-+you have. You must make sure that they, too, receive or can get the
-+source code. And you must show them these terms so they know their
-+rights.
-+
-+ We protect your rights with two steps: (1) copyright the software, and
-+(2) offer you this license which gives you legal permission to copy,
-+distribute and/or modify the software.
-+
-+ Also, for each author's protection and ours, we want to make certain
-+that everyone understands that there is no warranty for this free
-+software. If the software is modified by someone else and passed on, we
-+want its recipients to know that what they have is not the original, so
-+that any problems introduced by others will not reflect on the original
-+authors' reputations.
-+
-+ Finally, any free program is threatened constantly by software
-+patents. We wish to avoid the danger that redistributors of a free
-+program will individually obtain patent licenses, in effect making the
-+program proprietary. To prevent this, we have made it clear that any
-+patent must be licensed for everyone's free use or not licensed at all.
-+
-+ The precise terms and conditions for copying, distribution and
-+modification follow.
-+
-+ GNU GENERAL PUBLIC LICENSE
-+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-+
-+ 0. This License applies to any program or other work which contains
-+a notice placed by the copyright holder saying it may be distributed
-+under the terms of this General Public License. The "Program", below,
-+refers to any such program or work, and a "work based on the Program"
-+means either the Program or any derivative work under copyright law:
-+that is to say, a work containing the Program or a portion of it,
-+either verbatim or with modifications and/or translated into another
-+language. (Hereinafter, translation is included without limitation in
-+the term "modification".) Each licensee is addressed as "you".
-+
-+Activities other than copying, distribution and modification are not
-+covered by this License; they are outside its scope. The act of
-+running the Program is not restricted, and the output from the Program
-+is covered only if its contents constitute a work based on the
-+Program (independent of having been made by running the Program).
-+Whether that is true depends on what the Program does.
-+
-+ 1. You may copy and distribute verbatim copies of the Program's
-+source code as you receive it, in any medium, provided that you
-+conspicuously and appropriately publish on each copy an appropriate
-+copyright notice and disclaimer of warranty; keep intact all the
-+notices that refer to this License and to the absence of any warranty;
-+and give any other recipients of the Program a copy of this License
-+along with the Program.
-+
-+You may charge a fee for the physical act of transferring a copy, and
-+you may at your option offer warranty protection in exchange for a fee.
-+
-+ 2. You may modify your copy or copies of the Program or any portion
-+of it, thus forming a work based on the Program, and copy and
-+distribute such modifications or work under the terms of Section 1
-+above, provided that you also meet all of these conditions:
-+
-+ a) You must cause the modified files to carry prominent notices
-+ stating that you changed the files and the date of any change.
-+
-+ b) You must cause any work that you distribute or publish, that in
-+ whole or in part contains or is derived from the Program or any
-+ part thereof, to be licensed as a whole at no charge to all third
-+ parties under the terms of this License.
-+
-+ c) If the modified program normally reads commands interactively
-+ when run, you must cause it, when started running for such
-+ interactive use in the most ordinary way, to print or display an
-+ announcement including an appropriate copyright notice and a
-+ notice that there is no warranty (or else, saying that you provide
-+ a warranty) and that users may redistribute the program under
-+ these conditions, and telling the user how to view a copy of this
-+ License. (Exception: if the Program itself is interactive but
-+ does not normally print such an announcement, your work based on
-+ the Program is not required to print an announcement.)
-+
-+These requirements apply to the modified work as a whole. If
-+identifiable sections of that work are not derived from the Program,
-+and can be reasonably considered independent and separate works in
-+themselves, then this License, and its terms, do not apply to those
-+sections when you distribute them as separate works. But when you
-+distribute the same sections as part of a whole which is a work based
-+on the Program, the distribution of the whole must be on the terms of
-+this License, whose permissions for other licensees extend to the
-+entire whole, and thus to each and every part regardless of who wrote it.
-+
-+Thus, it is not the intent of this section to claim rights or contest
-+your rights to work written entirely by you; rather, the intent is to
-+exercise the right to control the distribution of derivative or
-+collective works based on the Program.
-+
-+In addition, mere aggregation of another work not based on the Program
-+with the Program (or with a work based on the Program) on a volume of
-+a storage or distribution medium does not bring the other work under
-+the scope of this License.
-+
-+ 3. You may copy and distribute the Program (or a work based on it,
-+under Section 2) in object code or executable form under the terms of
-+Sections 1 and 2 above provided that you also do one of the following:
-+
-+ a) Accompany it with the complete corresponding machine-readable
-+ source code, which must be distributed under the terms of Sections
-+ 1 and 2 above on a medium customarily used for software interchange; or,
-+
-+ b) Accompany it with a written offer, valid for at least three
-+ years, to give any third party, for a charge no more than your
-+ cost of physically performing source distribution, a complete
-+ machine-readable copy of the corresponding source code, to be
-+ distributed under the terms of Sections 1 and 2 above on a medium
-+ customarily used for software interchange; or,
-+
-+ c) Accompany it with the information you received as to the offer
-+ to distribute corresponding source code. (This alternative is
-+ allowed only for noncommercial distribution and only if you
-+ received the program in object code or executable form with such
-+ an offer, in accord with Subsection b above.)
-+
-+The source code for a work means the preferred form of the work for
-+making modifications to it. For an executable work, complete source
-+code means all the source code for all modules it contains, plus any
-+associated interface definition files, plus the scripts used to
-+control compilation and installation of the executable. However, as a
-+special exception, the source code distributed need not include
-+anything that is normally distributed (in either source or binary
-+form) with the major components (compiler, kernel, and so on) of the
-+operating system on which the executable runs, unless that component
-+itself accompanies the executable.
-+
-+If distribution of executable or object code is made by offering
-+access to copy from a designated place, then offering equivalent
-+access to copy the source code from the same place counts as
-+distribution of the source code, even though third parties are not
-+compelled to copy the source along with the object code.
-+
-+ 4. You may not copy, modify, sublicense, or distribute the Program
-+except as expressly provided under this License. Any attempt
-+otherwise to copy, modify, sublicense or distribute the Program is
-+void, and will automatically terminate your rights under this License.
-+However, parties who have received copies, or rights, from you under
-+this License will not have their licenses terminated so long as such
-+parties remain in full compliance.
-+
-+ 5. You are not required to accept this License, since you have not
-+signed it. However, nothing else grants you permission to modify or
-+distribute the Program or its derivative works. These actions are
-+prohibited by law if you do not accept this License. Therefore, by
-+modifying or distributing the Program (or any work based on the
-+Program), you indicate your acceptance of this License to do so, and
-+all its terms and conditions for copying, distributing or modifying
-+the Program or works based on it.
-+
-+ 6. Each time you redistribute the Program (or any work based on the
-+Program), the recipient automatically receives a license from the
-+original licensor to copy, distribute or modify the Program subject to
-+these terms and conditions. You may not impose any further
-+restrictions on the recipients' exercise of the rights granted herein.
-+You are not responsible for enforcing compliance by third parties to
-+this License.
-+
-+ 7. If, as a consequence of a court judgment or allegation of patent
-+infringement or for any other reason (not limited to patent issues),
-+conditions are imposed on you (whether by court order, agreement or
-+otherwise) that contradict the conditions of this License, they do not
-+excuse you from the conditions of this License. If you cannot
-+distribute so as to satisfy simultaneously your obligations under this
-+License and any other pertinent obligations, then as a consequence you
-+may not distribute the Program at all. For example, if a patent
-+license would not permit royalty-free redistribution of the Program by
-+all those who receive copies directly or indirectly through you, then
-+the only way you could satisfy both it and this License would be to
-+refrain entirely from distribution of the Program.
-+
-+If any portion of this section is held invalid or unenforceable under
-+any particular circumstance, the balance of the section is intended to
-+apply and the section as a whole is intended to apply in other
-+circumstances.
-+
-+It is not the purpose of this section to induce you to infringe any
-+patents or other property right claims or to contest validity of any
-+such claims; this section has the sole purpose of protecting the
-+integrity of the free software distribution system, which is
-+implemented by public license practices. Many people have made
-+generous contributions to the wide range of software distributed
-+through that system in reliance on consistent application of that
-+system; it is up to the author/donor to decide if he or she is willing
-+to distribute software through any other system and a licensee cannot
-+impose that choice.
-+
-+This section is intended to make thoroughly clear what is believed to
-+be a consequence of the rest of this License.
-+
-+ 8. If the distribution and/or use of the Program is restricted in
-+certain countries either by patents or by copyrighted interfaces, the
-+original copyright holder who places the Program under this License
-+may add an explicit geographical distribution limitation excluding
-+those countries, so that distribution is permitted only in or among
-+countries not thus excluded. In such case, this License incorporates
-+the limitation as if written in the body of this License.
-+
-+ 9. The Free Software Foundation may publish revised and/or new versions
-+of the General Public License from time to time. Such new versions will
-+be similar in spirit to the present version, but may differ in detail to
-+address new problems or concerns.
-+
-+Each version is given a distinguishing version number. If the Program
-+specifies a version number of this License which applies to it and "any
-+later version", you have the option of following the terms and conditions
-+either of that version or of any later version published by the Free
-+Software Foundation. If the Program does not specify a version number of
-+this License, you may choose any version ever published by the Free Software
-+Foundation.
-+
-+ 10. If you wish to incorporate parts of the Program into other free
-+programs whose distribution conditions are different, write to the author
-+to ask for permission. For software which is copyrighted by the Free
-+Software Foundation, write to the Free Software Foundation; we sometimes
-+make exceptions for this. Our decision will be guided by the two goals
-+of preserving the free status of all derivatives of our free software and
-+of promoting the sharing and reuse of software generally.
-+
-+ NO WARRANTY
-+
-+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-+REPAIR OR CORRECTION.
-+
-+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-+POSSIBILITY OF SUCH DAMAGES.
-+
-+ END OF TERMS AND CONDITIONS
-+
-+ How to Apply These Terms to Your New Programs
-+
-+ If you develop a new program, and you want it to be of the greatest
-+possible use to the public, the best way to achieve this is to make it
-+free software which everyone can redistribute and change under these terms.
-+
-+ To do so, attach the following notices to the program. It is safest
-+to attach them to the start of each source file to most effectively
-+convey the exclusion of warranty; and each file should have at least
-+the "copyright" line and a pointer to where the full notice is found.
-+
-+ <one line to give the program's name and a brief idea of what it does.>
-+ Copyright (C) 19yy <name of author>
-+
-+ This program is free software; you can redistribute it and/or modify
-+ it under the terms of the GNU General Public License as published by
-+ the Free Software Foundation; either version 2 of the License, or
-+ (at your option) any later version.
-+
-+ This program is distributed in the hope that it will be useful,
-+ but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ GNU General Public License for more details.
-+
-+ You should have received a copy of the GNU General Public License
-+ along with this program; if not, write to the Free Software
-+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-+
-+
-+Also add information on how to contact you by electronic and paper mail.
-+
-+If the program is interactive, make it output a short notice like this
-+when it starts in an interactive mode:
-+
-+ Gnomovision version 69, Copyright (C) 19yy name of author
-+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-+ This is free software, and you are welcome to redistribute it
-+ under certain conditions; type `show c' for details.
-+
-+The hypothetical commands `show w' and `show c' should show the appropriate
-+parts of the General Public License. Of course, the commands you use may
-+be called something other than `show w' and `show c'; they could even be
-+mouse-clicks or menu items--whatever suits your program.
-+
-+You should also get your employer (if you work as a programmer) or your
-+school, if any, to sign a "copyright disclaimer" for the program, if
-+necessary. Here is a sample; alter the names:
-+
-+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
-+
-+ <signature of Ty Coon>, 1 April 1989
-+ Ty Coon, President of Vice
-+
-+This General Public License does not permit incorporating your program into
-+proprietary programs. If your program is a subroutine library, you may
-+consider it more useful to permit linking proprietary applications with the
-+library. If this is what you want to do, use the GNU Library General
-+Public License instead of this License.
-diff -urNad zaptel-1.2.1/zaphfc/Makefile /tmp/dpep.LWjGif/zaptel-1.2.1/zaphfc/Makefile
---- zaptel-1.2.1/zaphfc/Makefile 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.LWjGif/zaptel-1.2.1/zaphfc/Makefile 2005-12-21 15:44:35.000000000 +0200
-@@ -0,0 +1,118 @@
-+KINCLUDES = /usr/src/linux/include
-+BRISTUFFBASE = $(shell dirname `pwd`)
-+
-+ZAP = $(shell [ -f $(BRISTUFFBASE)/zaptel-1.2.1/zaptel.h ] && echo "-I$(BRISTUFFBASE)/zaptel-1.2.1")
-+RTAI = $(shell [ -f /usr/realtime/include/rtai.h ] && echo "-DRTAITIMING -I/usr/realtime/include")
-+
-+HOSTCC=gcc
-+
-+CFLAGS+=-I. $(ZAP) $(RTAI) -O2 -g -Wall -DBUILDING_TONEZONE
-+CFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-fsigned-char"; fi)
-+
-+KFLAGS=-D__KERNEL__ -DMODULE -DEXPORT_SYMTAB -fomit-frame-pointer -O2 -Wall -I$(KINCLUDES) $(ZAP) $(RTAI) -Wall
-+KFLAGS+=$(shell [ -f $(KINCLUDES)/linux/modversions.h ] && echo "-DMODVERSIONS -include $(KINCLUDES)/linux/modversions.h")
-+KFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-msoft-float -fsigned-char"; fi)
-+
-+
-+BUILDVER=$(shell if uname -r | grep -q ^2.6; then echo "linux26"; else echo "linux24"; fi)
-+
-+MODCONF=$(shell if [ -d $(INSTALL_PREFIX)/etc/modprobe.d ]; then echo "$(INSTALL_PREFIX)/etc/modprobe.d/zaptel"; elif [ -d $(INSTALL_PREFIX)/etc/modutils ]; then echo "$(INSTALL_PREFIX)/etc/modutils/zaptel"; elif [ -f $(INSTALL_PREFIX)/etc/modprobe.conf ]; then echo "$(INSTALL_PREFIX)/modprobe.conf"; elif [ -f $(INSTALL_PREFIX)/etc/modules.conf ]; then echo "$(INSTALL_PREFIX)/etc/modules.conf"; else echo $(INSTALL_PREFIX)/etc/conf.modules ; fi)
-+
-+OBJS=zaphfc.o
-+
-+MODULES=zaphfc
-+
-+MODULESO=$(shell for x in $(MODULES); do echo "$$x.o "; done )
-+MODULESKO=$(shell for x in $(MODULES); do echo "$$x.ko "; done )
-+
-+PWD=$(shell pwd)
-+
-+obj-m := $(MODULESO)
-+
-+all: $(BUILDVER)
-+
-+linux24: $(OBJS)
-+ sync
-+
-+
-+zaphfc.o: zaphfc.c zaphfc.h
-+ $(CC) -c zaphfc.c $(KFLAGS)
-+
-+clean:
-+ rm -f $(OBJS) *.ko *.mod.c *.mod.o .*o.cmd *~
-+ rm -rf .tmp_versions
-+
-+test: all
-+ modprobe zaptel
-+ insmod ./zaphfc.o
-+ cat /proc/interrupts
-+ sleep 1
-+ cat /proc/interrupts
-+ rmmod zaphfc
-+ rmmod zaptel
-+
-+load: load$(BUILDVER)
-+
-+loadNT: load$(BUILDVER)NT
-+
-+load-debug: load$(BUILDVER)-debug
-+
-+loadNT-debug: load$(BUILDVER)NT-debug
-+
-+loadlinux24: all
-+ modprobe zaptel
-+ insmod ./zaphfc.o
-+ ztcfg -v
-+
-+loadlinux24-debug: all
-+ modprobe zaptel
-+ insmod ./zaphfc.o debug=1
-+ ztcfg -v
-+
-+loadlinux26: linux26
-+ modprobe zaptel
-+ insmod ./zaphfc.ko
-+ ztcfg -v
-+
-+loadlinux26-debug: linux26
-+ modprobe zaptel
-+ insmod ./zaphfc.ko debug=1
-+ ztcfg -v
-+
-+loadlinux24NT: all
-+ modprobe zaptel
-+ insmod ./zaphfc.o modes=1
-+ ztcfg -v
-+
-+loadlinux24NT-debug: all
-+ modprobe zaptel
-+ insmod ./zaphfc.o modes=1 debug=1
-+ ztcfg -v
-+
-+loadlinux26NT: linux26
-+ modprobe zaptel
-+ insmod ./zaphfc.ko modes=1
-+ ztcfg -v
-+
-+loadlinux26NT-debug: linux26
-+ modprobe zaptel
-+ insmod ./zaphfc.ko modes=1 debug=1
-+ ztcfg -v
-+
-+unload:
-+ -rmmod zaphfc zaptel
-+
-+zaphfc.ko: zaphfc.c zaphfc.h
-+
-+linux26:
-+ @if ! [ -d /usr/src/linux-2.6 ]; then echo "Link /usr/src/linux-2.6 to your kernel sources first!"; exit 1 ; fi
-+ make -C /usr/src/linux-2.6 SUBDIRS=$(PWD) ZAP=$(ZAP) modules
-+
-+install: install$(BUILDVER)
-+
-+installlinux26:
-+ install -D -m 644 zaphfc.ko $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/zaphfc.ko
-+
-+installlinux24:
-+ install -D -m 644 zaphfc.o $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/zaphfc.o
-+
-diff -urNad zaptel-1.2.1/zaphfc/zapata.conf /tmp/dpep.LWjGif/zaptel-1.2.1/zaphfc/zapata.conf
---- zaptel-1.2.1/zaphfc/zapata.conf 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.LWjGif/zaptel-1.2.1/zaphfc/zapata.conf 2005-02-26 19:24:32.000000000 +0200
-@@ -0,0 +1,38 @@
-+;
-+; Zapata telephony interface
-+;
-+; Configuration file
-+
-+[channels]
-+;
-+; Default language
-+;
-+;language=en
-+;
-+; Default context
-+;
-+;
-+switchtype = euroisdn
-+; p2mp TE mode
-+signalling = bri_cpe_ptmp
-+
-+; p2p TE mode
-+;signalling = bri_cpe
-+; p2mp NT mode
-+;signalling = bri_net_ptmp
-+; p2p NT mode
-+;signalling = bri_net
-+
-+pridialplan = dynamic
-+prilocaldialplan = local
-+nationalprefix = 0
-+internationalprefix = 00
-+
-+echocancel=yes
-+echotraining = 100
-+echocancelwhenbridged=yes
-+
-+immediate=yes
-+group = 1
-+context=demo
-+channel => 1-2
-diff -urNad zaptel-1.2.1/zaphfc/zaphfc.c /tmp/dpep.LWjGif/zaptel-1.2.1/zaphfc/zaphfc.c
---- zaptel-1.2.1/zaphfc/zaphfc.c 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.LWjGif/zaptel-1.2.1/zaphfc/zaphfc.c 2005-11-20 19:58:16.000000000 +0200
-@@ -0,0 +1,1149 @@
-+/*
-+ * zaphfc.c - Zaptel driver for HFC-S PCI A based ISDN BRI cards
-+ *
-+ * kernel module inspired by HFC PCI ISDN4Linux and Zaptel drivers
-+ *
-+ * Copyright (C) 2002, 2003, 2004, 2005 Junghanns.NET GmbH
-+ *
-+ * Klaus-Peter Junghanns <kpj at junghanns.net>
-+ *
-+ * This program is free software and may be modified and
-+ * distributed under the terms of the GNU Public License.
-+ *
-+ */
-+
-+#include <linux/kernel.h>
-+#include <linux/module.h>
-+#ifdef RTAITIMING
-+#include <asm/io.h>
-+#include <rtai.h>
-+#include <rtai_sched.h>
-+#include <rtai_fifos.h>
-+#endif
-+#include <linux/pci.h>
-+#include <linux/init.h>
-+#include <linux/interrupt.h>
-+#include <linux/delay.h>
-+#include <zaptel.h>
-+#include "zaphfc.h"
-+
-+#if CONFIG_PCI
-+
-+#define CLKDEL_TE 0x0f /* CLKDEL in TE mode */
-+#define CLKDEL_NT 0x6c /* CLKDEL in NT mode */
-+
-+typedef struct {
-+ int vendor_id;
-+ int device_id;
-+ char *vendor_name;
-+ char *card_name;
-+} PCI_ENTRY;
-+
-+static const PCI_ENTRY id_list[] =
-+{
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_2BD0, "CCD/Billion/Asuscom", "2BD0"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B000, "Billion", "B000"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B006, "Billion", "B006"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B007, "Billion", "B007"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B008, "Billion", "B008"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B009, "Billion", "B009"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B00A, "Billion", "B00A"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B00B, "Billion", "B00B"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B00C, "Billion", "B00C"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B100, "Seyeon", "B100"},
-+ {PCI_VENDOR_ID_ABOCOM, PCI_DEVICE_ID_ABOCOM_2BD1, "Abocom/Magitek", "2BD1"},
-+ {PCI_VENDOR_ID_ASUSTEK, PCI_DEVICE_ID_ASUSTEK_0675, "Asuscom/Askey", "675"},
-+ {PCI_VENDOR_ID_BERKOM, PCI_DEVICE_ID_BERKOM_T_CONCEPT, "German telekom", "T-Concept"},
-+ {PCI_VENDOR_ID_BERKOM, PCI_DEVICE_ID_BERKOM_A1T, "German telekom", "A1T"},
-+ {PCI_VENDOR_ID_ANIGMA, PCI_DEVICE_ID_ANIGMA_MC145575, "Motorola MC145575", "MC145575"},
-+ {PCI_VENDOR_ID_ZOLTRIX, PCI_DEVICE_ID_ZOLTRIX_2BD0, "Zoltrix", "2BD0"},
-+ {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_IOM2_E,"Digi International", "Digi DataFire Micro V IOM2 (Europe)"},
-+ {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_E,"Digi International", "Digi DataFire Micro V (Europe)"},
-+ {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_IOM2_A,"Digi International", "Digi DataFire Micro V IOM2 (North America)"},
-+ {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_A,"Digi International", "Digi DataFire Micro V (North America)"},
-+ {0x182d, 0x3069,"Sitecom","Isdn 128 PCI"},
-+ {0, 0, NULL, NULL},
-+};
-+
-+static struct hfc_card *hfc_dev_list = NULL;
-+static int hfc_dev_count = 0;
-+static int modes = 0; // all TE
-+static int debug = 0;
-+static struct pci_dev *multi_hfc = NULL;
-+static spinlock_t registerlock = SPIN_LOCK_UNLOCKED;
-+
-+void hfc_shutdownCard(struct hfc_card *hfctmp) {
-+ unsigned long flags;
-+
-+ if (hfctmp == NULL) {
-+ return;
-+ }
-+
-+ if (hfctmp->pci_io == NULL) {
-+ return;
-+ }
-+
-+ spin_lock_irqsave(&hfctmp->lock,flags);
-+
-+ printk(KERN_INFO "zaphfc: shutting down card at %p.\n",hfctmp->pci_io);
-+
-+ /* Clear interrupt mask */
-+ hfctmp->regs.int_m2 = 0;
-+ hfc_outb(hfctmp, hfc_INT_M2, hfctmp->regs.int_m2);
-+
-+ /* Reset pending interrupts */
-+ hfc_inb(hfctmp, hfc_INT_S1);
-+
-+ /* Wait for interrupts that might still be pending */
-+ spin_unlock_irqrestore(&hfctmp->lock, flags);
-+ set_current_state(TASK_UNINTERRUPTIBLE);
-+ schedule_timeout((30 * HZ) / 1000); // wait 30 ms
-+ spin_lock_irqsave(&hfctmp->lock,flags);
-+
-+ /* Remove interrupt handler */
-+ if (hfctmp->irq) {
-+ free_irq(hfctmp->irq, hfctmp);
-+ }
-+
-+ /* Soft-reset the card */
-+ hfc_outb(hfctmp, hfc_CIRM, hfc_CIRM_RESET); // softreset on
-+
-+ spin_unlock_irqrestore(&hfctmp->lock, flags);
-+ set_current_state(TASK_UNINTERRUPTIBLE);
-+ schedule_timeout((30 * HZ) / 1000); // wait 30 ms
-+ spin_lock_irqsave(&hfctmp->lock,flags);
-+
-+ hfc_outb(hfctmp,hfc_CIRM,0); // softreset off
-+
-+ pci_write_config_word(hfctmp->pcidev, PCI_COMMAND, 0); // disable memio and bustmaster
-+
-+ if (hfctmp->fifomem != NULL) {
-+ kfree(hfctmp->fifomem);
-+ }
-+ iounmap((void *) hfctmp->pci_io);
-+ hfctmp->pci_io = NULL;
-+ if (hfctmp->pcidev != NULL) {
-+ pci_disable_device(hfctmp->pcidev);
-+ }
-+ spin_unlock_irqrestore(&hfctmp->lock,flags);
-+ if (hfctmp->ztdev != NULL) {
-+ zt_unregister(&hfctmp->ztdev->span);
-+ kfree(hfctmp->ztdev);
-+ printk(KERN_INFO "unregistered from zaptel.\n");
-+ }
-+}
-+
-+void hfc_resetCard(struct hfc_card *hfctmp) {
-+ unsigned long flags;
-+
-+ spin_lock_irqsave(&hfctmp->lock,flags);
-+ pci_write_config_word(hfctmp->pcidev, PCI_COMMAND, PCI_COMMAND_MEMORY); // enable memio
-+ hfctmp->regs.int_m2 = 0;
-+ hfc_outb(hfctmp, hfc_INT_M2, hfctmp->regs.int_m2);
-+
-+// printk(KERN_INFO "zaphfc: resetting card.\n");
-+ pci_set_master(hfctmp->pcidev);
-+ hfc_outb(hfctmp, hfc_CIRM, hfc_CIRM_RESET); // softreset on
-+ spin_unlock_irqrestore(&hfctmp->lock, flags);
-+
-+ set_current_state(TASK_UNINTERRUPTIBLE);
-+ schedule_timeout((30 * HZ) / 1000); // wait 30 ms
-+ hfc_outb(hfctmp, hfc_CIRM, 0); // softreset off
-+
-+ set_current_state(TASK_UNINTERRUPTIBLE);
-+ schedule_timeout((20 * HZ) / 1000); // wait 20 ms
-+ if (hfc_inb(hfctmp,hfc_STATUS) & hfc_STATUS_PCI_PROC) {
-+ printk(KERN_WARNING "zaphfc: hfc busy.\n");
-+ }
-+
-+// hfctmp->regs.fifo_en = hfc_FIFOEN_D | hfc_FIFOEN_B1 | hfc_FIFOEN_B2;
-+// hfctmp->regs.fifo_en = hfc_FIFOEN_D; /* only D fifos enabled */
-+ hfctmp->regs.fifo_en = 0; /* no fifos enabled */
-+ hfc_outb(hfctmp, hfc_FIFO_EN, hfctmp->regs.fifo_en);
-+
-+ hfctmp->regs.trm = 2;
-+ hfc_outb(hfctmp, hfc_TRM, hfctmp->regs.trm);
-+
-+ if (hfctmp->regs.nt_mode == 1) {
-+ hfc_outb(hfctmp, hfc_CLKDEL, CLKDEL_NT); /* ST-Bit delay for NT-Mode */
-+ } else {
-+ hfc_outb(hfctmp, hfc_CLKDEL, CLKDEL_TE); /* ST-Bit delay for TE-Mode */
-+ }
-+ hfctmp->regs.sctrl_e = hfc_SCTRL_E_AUTO_AWAKE;
-+ hfc_outb(hfctmp, hfc_SCTRL_E, hfctmp->regs.sctrl_e); /* S/T Auto awake */
-+ hfctmp->regs.bswapped = 0; /* no exchange */
-+
-+ hfctmp->regs.ctmt = hfc_CTMT_TRANSB1 | hfc_CTMT_TRANSB2; // all bchans are transparent , no freaking hdlc
-+ hfc_outb(hfctmp, hfc_CTMT, hfctmp->regs.ctmt);
-+
-+ hfctmp->regs.int_m1 = 0;
-+ hfc_outb(hfctmp, hfc_INT_M1, hfctmp->regs.int_m1);
-+
-+#ifdef RTAITIMING
-+ hfctmp->regs.int_m2 = 0;
-+#else
-+ hfctmp->regs.int_m2 = hfc_M2_PROC_TRANS;
-+#endif
-+ hfc_outb(hfctmp, hfc_INT_M2, hfctmp->regs.int_m2);
-+
-+ /* Clear already pending ints */
-+ hfc_inb(hfctmp, hfc_INT_S1);
-+
-+ if (hfctmp->regs.nt_mode == 1) {
-+ hfctmp->regs.sctrl = 3 | hfc_SCTRL_NONE_CAP | hfc_SCTRL_MODE_NT; /* set tx_lo mode, error in datasheet ! */
-+ } else {
-+ hfctmp->regs.sctrl = 3 | hfc_SCTRL_NONE_CAP | hfc_SCTRL_MODE_TE; /* set tx_lo mode, error in datasheet ! */
-+ }
-+
-+ hfctmp->regs.mst_mode = hfc_MST_MODE_MASTER; /* HFC Master Mode */
-+ hfc_outb(hfctmp, hfc_MST_MODE, hfctmp->regs.mst_mode);
-+
-+ hfc_outb(hfctmp, hfc_SCTRL, hfctmp->regs.sctrl);
-+ hfctmp->regs.sctrl_r = 3;
-+ hfc_outb(hfctmp, hfc_SCTRL_R, hfctmp->regs.sctrl_r);
-+
-+ hfctmp->regs.connect = 0;
-+ hfc_outb(hfctmp, hfc_CONNECT, hfctmp->regs.connect);
-+
-+ hfc_outb(hfctmp, hfc_CIRM, 0x80 | 0x40); // bit order
-+
-+ /* Finally enable IRQ output */
-+#ifndef RTAITIMING
-+ hfctmp->regs.int_m2 |= hfc_M2_IRQ_ENABLE;
-+ hfc_outb(hfctmp, hfc_INT_M2, hfctmp->regs.int_m2);
-+#endif
-+
-+ /* clear pending ints */
-+ hfc_inb(hfctmp, hfc_INT_S1);
-+ hfc_inb(hfctmp, hfc_INT_S2);
-+}
-+
-+void hfc_registerCard(struct hfc_card *hfccard) {
-+ spin_lock(®isterlock);
-+ if (hfccard != NULL) {
-+ hfccard->cardno = hfc_dev_count++;
-+ hfccard->next = hfc_dev_list;
-+ hfc_dev_list = hfccard;
-+ }
-+ spin_unlock(®isterlock);
-+}
-+
-+static void hfc_btrans(struct hfc_card *hfctmp, char whichB) {
-+ // we are called with irqs disabled from the irq handler
-+ int count, maxlen, total;
-+ unsigned char *f1, *f2;
-+ unsigned short *z1, *z2, newz1;
-+ int freebytes;
-+
-+ if (whichB == 1) {
-+ f1 = (char *)(hfctmp->fifos + hfc_FIFO_B1TX_F1);
-+ f2 = (char *)(hfctmp->fifos + hfc_FIFO_B1TX_F2);
-+ z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B1TX_Z1 + (*f1 * 4));
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B1TX_Z2 + (*f1 * 4));
-+ } else {
-+ f1 = (char *)(hfctmp->fifos + hfc_FIFO_B2TX_F1);
-+ f2 = (char *)(hfctmp->fifos + hfc_FIFO_B2TX_F2);
-+ z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B2TX_Z1 + (*f1 * 4));
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B2TX_Z2 + (*f1 * 4));
-+ }
-+
-+ freebytes = *z2 - *z1;
-+ if (freebytes <= 0) {
-+ freebytes += hfc_B_FIFO_SIZE;
-+ }
-+ count = ZT_CHUNKSIZE;
-+
-+ total = count;
-+ if (freebytes < count) {
-+ hfctmp->clicks++;
-+ /* only spit out this warning once per second to not make things worse! */
-+ if (hfctmp->clicks > 100) {
-+ printk(KERN_CRIT "zaphfc: bchan tx fifo full, dropping audio! (z1=%d, z2=%d)\n",*z1,*z2);
-+ hfctmp->clicks = 0;
-+ }
-+ return;
-+ }
-+
-+ maxlen = (hfc_B_FIFO_SIZE + hfc_B_SUB_VAL) - *z1;
-+ if (maxlen > count) {
-+ maxlen = count;
-+ }
-+ newz1 = *z1 + total;
-+ if (newz1 >= (hfc_B_FIFO_SIZE + hfc_B_SUB_VAL)) { newz1 -= hfc_B_FIFO_SIZE; }
-+
-+ if (whichB == 1) {
-+ memcpy((char *)(hfctmp->fifos + hfc_FIFO_B1TX_ZOFF + *z1),hfctmp->ztdev->chans[0].writechunk, maxlen);
-+ } else {
-+ memcpy((char *)(hfctmp->fifos + hfc_FIFO_B2TX_ZOFF + *z1),hfctmp->ztdev->chans[1].writechunk, maxlen);
-+ }
-+
-+ count -= maxlen;
-+ if (count > 0) {
-+ // Buffer wrap
-+ if (whichB == 1) {
-+ memcpy((char *)(hfctmp->fifos + hfc_FIFO_B1TX_ZOFF + hfc_B_SUB_VAL),hfctmp->ztdev->chans[0].writechunk+maxlen, count);
-+ } else {
-+ memcpy((char *)(hfctmp->fifos + hfc_FIFO_B2TX_ZOFF + hfc_B_SUB_VAL),hfctmp->ztdev->chans[1].writechunk+maxlen, count);
-+ }
-+ }
-+
-+ *z1 = newz1; /* send it now */
-+
-+// if (count > 0) printk(KERN_CRIT "zaphfc: bchan tx fifo (f1=%d, f2=%d, z1=%d, z2=%d)\n",(*f1) & hfc_FMASK,(*f2) & hfc_FMASK, *z1, *z2);
-+ return;
-+}
-+
-+static void hfc_brec(struct hfc_card *hfctmp, char whichB) {
-+ // we are called with irqs disabled from the irq handler
-+ int count, maxlen, drop;
-+ volatile unsigned char *f1, *f2;
-+ volatile unsigned short *z1, *z2, newz2;
-+ int bytes = 0;
-+
-+ if (whichB == 1) {
-+ f1 = (char *)(hfctmp->fifos + hfc_FIFO_B1RX_F1);
-+ f2 = (char *)(hfctmp->fifos + hfc_FIFO_B1RX_F2);
-+ z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B1RX_Z1 + (*f1 * 4));
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B1RX_Z2 + (*f1 * 4));
-+ } else {
-+ f1 = (char *)(hfctmp->fifos + hfc_FIFO_B2RX_F1);
-+ f2 = (char *)(hfctmp->fifos + hfc_FIFO_B2RX_F2);
-+ z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B2RX_Z1 + (*f1 * 4));
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B2RX_Z2 + (*f1 * 4));
-+ }
-+
-+ bytes = *z1 - *z2;
-+ if (bytes < 0) {
-+ bytes += hfc_B_FIFO_SIZE;
-+ }
-+ count = ZT_CHUNKSIZE;
-+
-+ if (bytes < ZT_CHUNKSIZE) {
-+#ifndef RTAITIMING
-+ printk(KERN_CRIT "zaphfc: bchan rx fifo not enough bytes to receive! (z1=%d, z2=%d, wanted %d got %d), probably a buffer overrun.\n",*z1,*z2,ZT_CHUNKSIZE,bytes);
-+#endif
-+ return;
-+ }
-+
-+ /* allowing the buffering of hfc_BCHAN_BUFFER bytes of audio data works around irq jitter */
-+ if (bytes > hfc_BCHAN_BUFFER + ZT_CHUNKSIZE) {
-+ /* if the system is too slow to handle it, we will have to drop it all (except 1 zaptel chunk) */
-+ drop = bytes - ZT_CHUNKSIZE;
-+ hfctmp->clicks++;
-+ /* only spit out this warning once per second to not make things worse! */
-+ if (hfctmp->clicks > 100) {
-+ printk(KERN_CRIT "zaphfc: dropped audio (z1=%d, z2=%d, wanted %d got %d, dropped %d).\n",*z1,*z2,count,bytes,drop);
-+ hfctmp->clicks = 0;
-+ }
-+ /* hm, we are processing the b chan data tooooo slowly... let's drop the lost audio */
-+ newz2 = *z2 + drop;
-+ if (newz2 >= (hfc_B_FIFO_SIZE + hfc_B_SUB_VAL)) {
-+ newz2 -= hfc_B_FIFO_SIZE;
-+ }
-+ *z2 = newz2;
-+ }
-+
-+
-+ maxlen = (hfc_B_FIFO_SIZE + hfc_B_SUB_VAL) - *z2;
-+ if (maxlen > count) {
-+ maxlen = count;
-+ }
-+ if (whichB == 1) {
-+ memcpy(hfctmp->ztdev->chans[0].readchunk,(char *)(hfctmp->fifos + hfc_FIFO_B1RX_ZOFF + *z2), maxlen);
-+ } else {
-+ memcpy(hfctmp->ztdev->chans[1].readchunk,(char *)(hfctmp->fifos + hfc_FIFO_B2RX_ZOFF + *z2), maxlen);
-+ }
-+ newz2 = *z2 + count;
-+ if (newz2 >= (hfc_B_FIFO_SIZE + hfc_B_SUB_VAL)) {
-+ newz2 -= hfc_B_FIFO_SIZE;
-+ }
-+ *z2 = newz2;
-+
-+ count -= maxlen;
-+ if (count > 0) {
-+ // Buffer wrap
-+ if (whichB == 1) {
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B1RX_Z2 + (*f1 * 4));
-+ memcpy(hfctmp->ztdev->chans[0].readchunk + maxlen,(char *)(hfctmp->fifos + hfc_FIFO_B1RX_ZOFF + hfc_B_SUB_VAL), count);
-+ } else {
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B2RX_Z2 + (*f1 * 4));
-+ memcpy(hfctmp->ztdev->chans[1].readchunk + maxlen,(char *)(hfctmp->fifos + hfc_FIFO_B2RX_ZOFF + hfc_B_SUB_VAL), count);
-+ }
-+ newz2 = *z2 + count;
-+ if (newz2 >= (hfc_B_FIFO_SIZE + hfc_B_SUB_VAL)) {
-+ newz2 -= hfc_B_FIFO_SIZE;
-+ }
-+ }
-+
-+
-+ if (whichB == 1) {
-+ zt_ec_chunk(&hfctmp->ztdev->chans[0], hfctmp->ztdev->chans[0].readchunk, hfctmp->ztdev->chans[0].writechunk);
-+ } else {
-+ zt_ec_chunk(&hfctmp->ztdev->chans[1], hfctmp->ztdev->chans[1].readchunk, hfctmp->ztdev->chans[1].writechunk);
-+ }
-+ return;
-+}
-+
-+
-+static void hfc_dtrans(struct hfc_card *hfctmp) {
-+ // we are called with irqs disabled from the irq handler
-+ int x;
-+ int count, maxlen, total;
-+ unsigned char *f1, *f2, newf1;
-+ unsigned short *z1, *z2, newz1;
-+ int frames, freebytes;
-+
-+ if (hfctmp->ztdev->chans[2].bytes2transmit == 0) {
-+ return;
-+ }
-+
-+ f1 = (char *)(hfctmp->fifos + hfc_FIFO_DTX_F1);
-+ f2 = (char *)(hfctmp->fifos + hfc_FIFO_DTX_F2);
-+ z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DTX_Z1 + (*f1 * 4));
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DTX_Z2 + (*f1 * 4));
-+
-+ frames = (*f1 - *f2) & hfc_FMASK;
-+ if (frames < 0) {
-+ frames += hfc_MAX_DFRAMES + 1;
-+ }
-+
-+ if (frames >= hfc_MAX_DFRAMES) {
-+ printk(KERN_CRIT "zaphfc: dchan tx fifo total number of frames exceeded!\n");
-+ return;
-+ }
-+
-+ freebytes = *z2 - *z1;
-+ if (freebytes <= 0) {
-+ freebytes += hfc_D_FIFO_SIZE;
-+ }
-+ count = hfctmp->ztdev->chans[2].bytes2transmit;
-+
-+ total = count;
-+ if (freebytes < count) {
-+ printk(KERN_CRIT "zaphfc: dchan tx fifo not enough free bytes! (z1=%d, z2=%d)\n",*z1,*z2);
-+ return;
-+ }
-+
-+ newz1 = (*z1 + count) & hfc_ZMASK;
-+ newf1 = ((*f1 + 1) & hfc_MAX_DFRAMES) | (hfc_MAX_DFRAMES + 1); // next frame
-+
-+ if (count > 0) {
-+ if (debug) {
-+ printk(KERN_CRIT "zaphfc: card %d TX [ ", hfctmp->cardno);
-+ for (x=0; x<count; x++) {
-+ printk("%#2x ",hfctmp->dtransbuf[x]);
-+ }
-+ if (hfctmp->ztdev->chans[2].eoftx == 1) {
-+ printk("] %d bytes\n", count);
-+ } else {
-+ printk("..] %d bytes\n", count);
-+ }
-+ }
-+ maxlen = hfc_D_FIFO_SIZE - *z1;
-+ if (maxlen > count) {
-+ maxlen = count;
-+ }
-+ memcpy((char *)(hfctmp->fifos + hfc_FIFO_DTX_ZOFF + *z1),hfctmp->ztdev->chans[2].writechunk, maxlen);
-+ count -= maxlen;
-+ if (count > 0) {
-+ memcpy((char *)(hfctmp->fifos + hfc_FIFO_DTX_ZOFF),(char *)(hfctmp->ztdev->chans[2].writechunk + maxlen), count);
-+ }
-+ }
-+
-+ *z1 = newz1;
-+
-+ if (hfctmp->ztdev->chans[2].eoftx == 1) {
-+ *f1 = newf1;
-+ z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DTX_Z1 + (*f1 * 4));
-+ *z1 = newz1;
-+ hfctmp->ztdev->chans[2].eoftx = 0;
-+ }
-+// printk(KERN_CRIT "zaphfc: dchan tx fifo (f1=%d, f2=%d, z1=%d, z2=%d)\n",(*f1) & hfc_FMASK,(*f2) & hfc_FMASK, *z1, *z2);
-+ return;
-+}
-+
-+/* receive a complete hdlc frame, skip broken or short frames */
-+static void hfc_drec(struct hfc_card *hfctmp) {
-+ int count=0, maxlen=0, framelen=0;
-+ unsigned char *f1, *f2, *crcstat;
-+ unsigned short *z1, *z2, oldz2, newz2;
-+
-+ hfctmp->ztdev->chans[2].bytes2receive=0;
-+ hfctmp->ztdev->chans[2].eofrx = 0;
-+
-+ /* put the received data into the zaptel buffer
-+ we'll call zt_receive() later when the timer fires. */
-+ f1 = (char *)(hfctmp->fifos + hfc_FIFO_DRX_F1);
-+ f2 = (char *)(hfctmp->fifos + hfc_FIFO_DRX_F2);
-+
-+ if (*f1 == *f2) return; /* nothing received, strange eh? */
-+
-+ z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DRX_Z1 + (*f2 * 4));
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DRX_Z2 + (*f2 * 4));
-+
-+ /* calculate length of frame, including 2 bytes CRC and 1 byte STAT */
-+ count = *z1 - *z2;
-+
-+ if (count < 0) {
-+ count += hfc_D_FIFO_SIZE; /* ring buffer wrapped */
-+ }
-+ count++;
-+ framelen = count;
-+
-+ crcstat = (char *)(hfctmp->fifos + hfc_FIFO_DRX_ZOFF + *z1);
-+
-+ if ((framelen < 4) || (*crcstat != 0x0)) {
-+ /* the frame is too short for a valid HDLC frame or the CRC is borked */
-+ printk(KERN_CRIT "zaphfc: empty HDLC frame or bad CRC received (framelen = %d, stat = %#x, card = %d).\n", framelen, *crcstat, hfctmp->cardno);
-+ oldz2 = *z2;
-+ *f2 = ((*f2 + 1) & hfc_MAX_DFRAMES) | (hfc_MAX_DFRAMES + 1); /* NEXT!!! */
-+ // recalculate z2, because Z2 is a function of F2 Z2(F2) and we INCed F2!!!
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DRX_Z2 + (*f2 * 4));
-+ *z2 = (oldz2 + framelen) & hfc_ZMASK;
-+ hfctmp->drecinframe = 0;
-+ hfctmp->regs.int_drec--;
-+ /* skip short or broken frames */
-+ hfctmp->ztdev->chans[2].bytes2receive = 0;
-+ return;
-+ }
-+
-+ count -= 1; /* strip STAT */
-+ hfctmp->ztdev->chans[2].eofrx = 1;
-+
-+ if (count + *z2 <= hfc_D_FIFO_SIZE) {
-+ maxlen = count;
-+ } else {
-+ maxlen = hfc_D_FIFO_SIZE - *z2;
-+ }
-+
-+ /* copy first part */
-+ memcpy(hfctmp->drecbuf, (char *)(hfctmp->fifos + hfc_FIFO_DRX_ZOFF + *z2), maxlen);
-+ hfctmp->ztdev->chans[2].bytes2receive += maxlen;
-+
-+ count -= maxlen;
-+ if (count > 0) {
-+ /* ring buffer wrapped, copy rest from start of d fifo */
-+ memcpy(hfctmp->drecbuf + maxlen, (char *)(hfctmp->fifos + hfc_FIFO_DRX_ZOFF), count);
-+ hfctmp->ztdev->chans[2].bytes2receive += count;
-+ }
-+
-+ /* frame read */
-+ oldz2 = *z2;
-+ newz2 = (oldz2 + framelen) & hfc_ZMASK;
-+ *f2 = ((*f2 + 1) & hfc_MAX_DFRAMES) | (hfc_MAX_DFRAMES + 1); /* NEXT!!! */
-+ /* recalculate z2, because Z2 is a function of F2 Z2(F2) and we INCed F2!!! */
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DRX_Z2 + (*f2 * 4));
-+ *z2 = newz2;
-+ hfctmp->drecinframe = 0;
-+ hfctmp->regs.int_drec--;
-+}
-+
-+#ifndef RTAITIMING
-+#ifdef LINUX26
-+static irqreturn_t hfc_interrupt(int irq, void *dev_id, struct pt_regs *regs) {
-+#else
-+static void hfc_interrupt(int irq, void *dev_id, struct pt_regs *regs) {
-+#endif
-+ struct hfc_card *hfctmp = dev_id;
-+ unsigned long flags = 0;
-+ unsigned char stat;
-+#else
-+static void hfc_service(struct hfc_card *hfctmp) {
-+#endif
-+ struct zt_hfc *zthfc;
-+ unsigned char s1, s2, l1state;
-+ int x;
-+
-+ if (!hfctmp) {
-+#ifndef RTAITIMING
-+#ifdef LINUX26
-+ return IRQ_NONE;
-+#else
-+ return;
-+#endif
-+#else
-+ /* rtai */
-+ return;
-+#endif
-+ }
-+
-+ if (!hfctmp->pci_io) {
-+ printk(KERN_WARNING "%s: IO-mem disabled, cannot handle interrupt\n",
-+ __FUNCTION__);
-+#ifndef RTAITIMING
-+#ifdef LINUX26
-+ return IRQ_NONE;
-+#else
-+ return;
-+#endif
-+#else
-+ /* rtai */
-+ return;
-+#endif
-+ }
-+
-+ /* we assume a few things in this irq handler:
-+ - the hfc-pci will only generate "timer" irqs (proc/non-proc)
-+ - we need to use every 8th IRQ (to generate 1khz timing)
-+ OR
-+ - if we use rtai for timing the hfc-pci will not generate ANY irq,
-+ instead rtai will call this "fake" irq with a 1khz realtime timer. :)
-+ - rtai will directly service the card, not like it used to by triggering
-+ the linux irq
-+ */
-+
-+#ifndef RTAITIMING
-+ spin_lock_irqsave(&hfctmp->lock, flags);
-+ stat = hfc_inb(hfctmp, hfc_STATUS);
-+
-+ if ((stat & hfc_STATUS_ANYINT) == 0) {
-+ // maybe we are sharing the irq
-+ spin_unlock_irqrestore(&hfctmp->lock,flags);
-+#ifdef LINUX26
-+ return IRQ_NONE;
-+#else
-+ return;
-+#endif
-+ }
-+#endif
-+
-+ s1 = hfc_inb(hfctmp, hfc_INT_S1);
-+ s2 = hfc_inb(hfctmp, hfc_INT_S2);
-+ if (s1 != 0) {
-+ if (s1 & hfc_INTS_TIMER) {
-+ // timer (bit 7)
-+ // printk(KERN_CRIT "timer %d %d %d.\n", stat, s1, s2);
-+ }
-+ if (s1 & hfc_INTS_L1STATE) {
-+ // state machine (bit 6)
-+ // printk(KERN_CRIT "zaphfc: layer 1 state machine interrupt\n");
-+ zthfc = hfctmp->ztdev;
-+ l1state = hfc_inb(hfctmp,hfc_STATES) & hfc_STATES_STATE_MASK;
-+ if (hfctmp->regs.nt_mode == 1) {
-+ if (debug) {
-+ printk(KERN_CRIT "zaphfc: card %d layer 1 state = G%d\n", hfctmp->cardno, l1state);
-+ }
-+ switch (l1state) {
-+ case 3:
-+#ifdef RTAITIMING
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [NT] layer 1 ACTIVATED (G%d) [realtime]", hfctmp->cardno, l1state);
-+#else
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [NT] layer 1 ACTIVATED (G%d)", hfctmp->cardno, l1state);
-+#endif
-+ break;
-+ default:
-+#ifdef RTAITIMING
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [NT] layer 1 DEACTIVATED (G%d) [realtime]", hfctmp->cardno, l1state);
-+#else
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [NT] layer 1 DEACTIVATED (G%d)", hfctmp->cardno, l1state);
-+#endif
-+ }
-+ if (l1state == 2) {
-+ hfc_outb(hfctmp, hfc_STATES, hfc_STATES_ACTIVATE | hfc_STATES_DO_ACTION | hfc_STATES_NT_G2_G3);
-+ } else if (l1state == 3) {
-+ // fix to G3 state (see specs)
-+ hfc_outb(hfctmp, hfc_STATES, hfc_STATES_LOAD_STATE | 3);
-+ }
-+ } else {
-+ if (debug) {
-+ printk(KERN_CRIT "zaphfc: card %d layer 1 state = F%d\n", hfctmp->cardno, l1state);
-+ }
-+ switch (l1state) {
-+ case 7:
-+#ifdef RTAITIMING
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [TE] layer 1 ACTIVATED (F%d) [realtime]", hfctmp->cardno, l1state);
-+#else
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [TE] layer 1 ACTIVATED (F%d)", hfctmp->cardno, l1state);
-+#endif
-+ break;
-+ default:
-+#ifdef RTAITIMING
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [TE] layer 1 DEACTIVATED (F%d) [realtime]", hfctmp->cardno, l1state);
-+#else
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [TE] layer 1 DEACTIVATED (F%d)", hfctmp->cardno, l1state);
-+#endif
-+ }
-+ if (l1state == 3) {
-+ hfc_outb(hfctmp, hfc_STATES, hfc_STATES_DO_ACTION | hfc_STATES_ACTIVATE);
-+ }
-+ }
-+
-+ }
-+ if (s1 & hfc_INTS_DREC) {
-+ // D chan RX (bit 5)
-+ hfctmp->regs.int_drec++;
-+ // mr. zapata there is something for you!
-+ // printk(KERN_CRIT "d chan rx\n");
-+ }
-+ if (s1 & hfc_INTS_B2REC) {
-+ // B2 chan RX (bit 4)
-+ }
-+ if (s1 & hfc_INTS_B1REC) {
-+ // B1 chan RX (bit 3)
-+ }
-+ if (s1 & hfc_INTS_DTRANS) {
-+ // D chan TX (bit 2)
-+// printk(KERN_CRIT "zaphfc: dchan frame transmitted.\n");
-+ }
-+ if (s1 & hfc_INTS_B2TRANS) {
-+ // B2 chan TX (bit 1)
-+ }
-+ if (s1 & hfc_INTS_B1TRANS) {
-+ // B1 chan TX (bit 0)
-+ }
-+ }
-+#ifdef RTAITIMING
-+ /* fake an irq */
-+ s2 |= hfc_M2_PROC_TRANS;
-+#endif
-+ if (s2 != 0) {
-+ if (s2 & hfc_M2_PMESEL) {
-+ // kaboom irq (bit 7)
-+ printk(KERN_CRIT "zaphfc: sync lost, pci performance too low. you might have some cpu throtteling enabled.\n");
-+ }
-+ if (s2 & hfc_M2_GCI_MON_REC) {
-+ // RxR monitor channel (bit 2)
-+ }
-+ if (s2 & hfc_M2_GCI_I_CHG) {
-+ // GCI I-change (bit 1)
-+ }
-+ if (s2 & hfc_M2_PROC_TRANS) {
-+ // processing/non-processing transition (bit 0)
-+ hfctmp->ticks++;
-+#ifndef RTAITIMING
-+ if (hfctmp->ticks > 7) {
-+ // welcome to zaptel timing :)
-+#endif
-+ hfctmp->ticks = 0;
-+
-+ if (hfctmp->ztdev->span.flags & ZT_FLAG_RUNNING) {
-+ // clear dchan buffer
-+ hfctmp->ztdev->chans[2].bytes2transmit = 0;
-+ hfctmp->ztdev->chans[2].maxbytes2transmit = hfc_D_FIFO_SIZE;
-+
-+ zt_transmit(&(hfctmp->ztdev->span));
-+
-+ hfc_btrans(hfctmp,1);
-+ hfc_btrans(hfctmp,2);
-+ hfc_dtrans(hfctmp);
-+ }
-+
-+ hfc_brec(hfctmp,1);
-+ hfc_brec(hfctmp,2);
-+ if (hfctmp->regs.int_drec > 0) {
-+ // dchan data to read
-+ hfc_drec(hfctmp);
-+ if (hfctmp->ztdev->chans[2].bytes2receive > 0) {
-+ if (debug) {
-+ printk(KERN_CRIT "zaphfc: card %d RX [ ", hfctmp->cardno);
-+ if (hfctmp->ztdev->chans[2].eofrx) {
-+ /* dont output CRC == less user confusion */
-+ for (x=0; x < hfctmp->ztdev->chans[2].bytes2receive - 2; x++) {
-+ printk("%#2x ", hfctmp->drecbuf[x]);
-+ }
-+ printk("] %d bytes\n", hfctmp->ztdev->chans[2].bytes2receive - 2);
-+ } else {
-+ for (x=0; x < hfctmp->ztdev->chans[2].bytes2receive; x++) {
-+ printk("%#2x ", hfctmp->drecbuf[x]);
-+ }
-+ printk("..] %d bytes\n", hfctmp->ztdev->chans[2].bytes2receive);
-+ }
-+ }
-+ }
-+ } else {
-+ // hmm....ok, let zaptel receive nothing
-+ hfctmp->ztdev->chans[2].bytes2receive = 0;
-+ }
-+ if (hfctmp->ztdev->span.flags & ZT_FLAG_RUNNING) {
-+ zt_receive(&(hfctmp->ztdev->span));
-+ }
-+
-+#ifndef RTAITIMING
-+ }
-+#endif
-+ }
-+
-+ }
-+#ifndef RTAITIMING
-+ spin_unlock_irqrestore(&hfctmp->lock,flags);
-+#ifdef LINUX26
-+ return IRQ_RETVAL(1);
-+#endif
-+#endif
-+}
-+
-+
-+static int zthfc_open(struct zt_chan *chan) {
-+ struct zt_hfc *zthfc = chan->pvt;
-+ struct hfc_card *hfctmp = zthfc->card;
-+
-+ if (!hfctmp) {
-+ return 0;
-+ }
-+#ifndef LINUX26
-+ MOD_INC_USE_COUNT;
-+#else
-+ try_module_get(THIS_MODULE);
-+#endif
-+ return 0;
-+}
-+
-+static int zthfc_close(struct zt_chan *chan) {
-+ struct zt_hfc *zthfc = chan->pvt;
-+ struct hfc_card *hfctmp = zthfc->card;
-+
-+ if (!hfctmp) {
-+ return 0;
-+ }
-+
-+#ifndef LINUX26
-+ MOD_DEC_USE_COUNT;
-+#else
-+ module_put(THIS_MODULE);
-+#endif
-+ return 0;
-+}
-+
-+static int zthfc_rbsbits(struct zt_chan *chan, int bits) {
-+ return 0;
-+}
-+
-+static int zthfc_ioctl(struct zt_chan *chan, unsigned int cmd, unsigned long data) {
-+ switch(cmd) {
-+ default:
-+ return -ENOTTY;
-+ }
-+ return 0;
-+}
-+
-+static int zthfc_startup(struct zt_span *span) {
-+ struct zt_hfc *zthfc = span->pvt;
-+ struct hfc_card *hfctmp = zthfc->card;
-+ int alreadyrunning;
-+
-+ if (hfctmp == NULL) {
-+ printk(KERN_INFO "zaphfc: no card for span at startup!\n");
-+ }
-+ alreadyrunning = span->flags & ZT_FLAG_RUNNING;
-+
-+ if (!alreadyrunning) {
-+ span->chans[2].flags &= ~ZT_FLAG_HDLC;
-+ span->chans[2].flags |= ZT_FLAG_BRIDCHAN;
-+
-+ span->flags |= ZT_FLAG_RUNNING;
-+
-+ hfctmp->ticks = -2;
-+ hfctmp->clicks = 0;
-+ hfctmp->regs.fifo_en = hfc_FIFOEN_D | hfc_FIFOEN_B1 | hfc_FIFOEN_B2;
-+ hfc_outb(hfctmp, hfc_FIFO_EN, hfctmp->regs.fifo_en);
-+ } else {
-+ return 0;
-+ }
-+
-+ // drivers, start engines!
-+ hfc_outb(hfctmp, hfc_STATES, hfc_STATES_DO_ACTION | hfc_STATES_ACTIVATE);
-+ return 0;
-+}
-+
-+static int zthfc_shutdown(struct zt_span *span) {
-+ return 0;
-+}
-+
-+static int zthfc_maint(struct zt_span *span, int cmd) {
-+ return 0;
-+}
-+
-+static int zthfc_chanconfig(struct zt_chan *chan, int sigtype) {
-+// printk(KERN_CRIT "chan_config sigtype=%d\n", sigtype);
-+ return 0;
-+}
-+
-+static int zthfc_spanconfig(struct zt_span *span, struct zt_lineconfig *lc) {
-+ span->lineconfig = lc->lineconfig;
-+ return 0;
-+}
-+
-+static int zthfc_initialize(struct zt_hfc *zthfc) {
-+ struct hfc_card *hfctmp = zthfc->card;
-+ int i;
-+
-+ memset(&zthfc->span, 0x0, sizeof(struct zt_span)); // you never can tell...
-+
-+ sprintf(zthfc->span.name, "ZTHFC%d", hfc_dev_count + 1);
-+ if (hfctmp->regs.nt_mode == 1) {
-+#ifdef RTAITIMING
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [NT] [realtime]", hfc_dev_count + 1);
-+#else
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [NT]", hfc_dev_count + 1);
-+#endif
-+ } else {
-+#ifdef RTAITIMING
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [TE] [realtime]", hfc_dev_count + 1);
-+#else
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [TE]", hfc_dev_count + 1);
-+#endif
-+ }
-+
-+ zthfc->span.spanconfig = zthfc_spanconfig;
-+ zthfc->span.chanconfig = zthfc_chanconfig;
-+ zthfc->span.startup = zthfc_startup;
-+ zthfc->span.shutdown = zthfc_shutdown;
-+ zthfc->span.maint = zthfc_maint;
-+ zthfc->span.rbsbits = zthfc_rbsbits;
-+ zthfc->span.open = zthfc_open;
-+ zthfc->span.close = zthfc_close;
-+ zthfc->span.ioctl = zthfc_ioctl;
-+
-+ zthfc->span.chans = zthfc->chans;
-+ zthfc->span.channels = 3;
-+ zthfc->span.deflaw = ZT_LAW_ALAW;
-+ zthfc->span.linecompat = ZT_CONFIG_AMI | ZT_CONFIG_CCS; // <--- this is really BS
-+ zthfc->span.offset = 0;
-+ init_waitqueue_head(&zthfc->span.maintq);
-+ zthfc->span.pvt = zthfc;
-+
-+ for (i = 0; i < zthfc->span.channels; i++) {
-+ memset(&(zthfc->chans[i]), 0x0, sizeof(struct zt_chan));
-+ sprintf(zthfc->chans[i].name, "ZTHFC%d/%d/%d", hfc_dev_count + 1,0,i + 1);
-+ zthfc->chans[i].pvt = zthfc;
-+ zthfc->chans[i].sigcap = ZT_SIG_EM | ZT_SIG_CLEAR | ZT_SIG_FXSLS | ZT_SIG_FXSGS | ZT_SIG_FXSKS | ZT_SIG_FXOLS | ZT_SIG_FXOGS | ZT_SIG_FXOKS | ZT_SIG_CAS | ZT_SIG_SF;
-+ zthfc->chans[i].chanpos = i + 1;
-+ }
-+
-+ if (zt_register(&zthfc->span,0)) {
-+ printk(KERN_CRIT "unable to register zaptel device!\n");
-+ return -1;
-+ }
-+// printk(KERN_CRIT "zaphfc: registered zaptel device!\n");
-+ return 0;
-+}
-+
-+#ifdef RTAITIMING
-+#define TICK_PERIOD 1000000
-+#define TICK_PERIOD2 1000000000
-+#define TASK_PRIORITY 1
-+#define STACK_SIZE 10000
-+
-+static RT_TASK rt_task;
-+static struct hfc_card *rtai_hfc_list[hfc_MAX_CARDS];
-+static unsigned char rtai_hfc_counter = 0;
-+
-+static void rtai_register_hfc(struct hfc_card *hfctmp) {
-+ rtai_hfc_list[rtai_hfc_counter++] = hfctmp;
-+}
-+
-+static void rtai_loop(int t) {
-+ int i=0;
-+ for (;;) {
-+ for (i=0; i < rtai_hfc_counter; i++) {
-+ if (rtai_hfc_list[i] != NULL)
-+ hfc_service(rtai_hfc_list[i]);
-+ }
-+ rt_task_wait_period();
-+ }
-+}
-+#endif
-+
-+int hfc_findCards(int pcivendor, int pcidevice, char *vendor_name, char *card_name) {
-+ struct pci_dev *tmp;
-+ struct hfc_card *hfctmp = NULL;
-+ struct zt_hfc *zthfc = NULL;
-+
-+ tmp = pci_find_device(pcivendor, pcidevice, multi_hfc);
-+ while (tmp != NULL) {
-+ multi_hfc = tmp; // skip this next time.
-+
-+ if (pci_enable_device(tmp)) {
-+ multi_hfc = NULL;
-+ return -1;
-+ }
-+ pci_set_master(tmp);
-+
-+ hfctmp = kmalloc(sizeof(struct hfc_card), GFP_KERNEL);
-+ if (!hfctmp) {
-+ printk(KERN_WARNING "zaphfc: unable to kmalloc!\n");
-+ pci_disable_device(tmp);
-+ multi_hfc = NULL;
-+ return -ENOMEM;
-+ }
-+ memset(hfctmp, 0x0, sizeof(struct hfc_card));
-+ spin_lock_init(&hfctmp->lock);
-+
-+ hfctmp->pcidev = tmp;
-+ hfctmp->pcibus = tmp->bus->number;
-+ hfctmp->pcidevfn = tmp->devfn;
-+
-+ if (!tmp->irq) {
-+ printk(KERN_WARNING "zaphfc: no irq!\n");
-+ } else {
-+ hfctmp->irq = tmp->irq;
-+ }
-+
-+ hfctmp->pci_io = (char *) tmp->resource[1].start;
-+ if (!hfctmp->pci_io) {
-+ printk(KERN_WARNING "zaphfc: no iomem!\n");
-+ kfree(hfctmp);
-+ pci_disable_device(tmp);
-+ multi_hfc = NULL;
-+ return -1;
-+ }
-+
-+ hfctmp->fifomem = kmalloc(65536, GFP_KERNEL);
-+ if (!hfctmp->fifomem) {
-+ printk(KERN_WARNING "zaphfc: unable to kmalloc fifomem!\n");
-+ kfree(hfctmp);
-+ pci_disable_device(tmp);
-+ multi_hfc = NULL;
-+ return -ENOMEM;
-+ } else {
-+ memset(hfctmp->fifomem, 0x0, 65536);
-+ hfctmp->fifos = (((ulong) hfctmp->fifomem) & ~0x7FFF) + 0x8000;
-+ pci_write_config_dword(hfctmp->pcidev, 0x80, (u_int) virt_to_bus(hfctmp->fifos));
-+ hfctmp->pci_io = ioremap((ulong) hfctmp->pci_io, 256);
-+ }
-+
-+#ifdef RTAITIMING
-+ /* we need no stinking irq */
-+ hfctmp->irq = 0;
-+#else
-+ if (request_irq(hfctmp->irq, &hfc_interrupt, SA_INTERRUPT | SA_SHIRQ, "zaphfc", hfctmp)) {
-+ printk(KERN_WARNING "zaphfc: unable to register irq\n");
-+ kfree(hfctmp->fifomem);
-+ kfree(hfctmp);
-+ iounmap((void *) hfctmp->pci_io);
-+ pci_disable_device(tmp);
-+ multi_hfc = NULL;
-+ return -EIO;
-+ }
-+#endif
-+
-+#ifdef RTAITIMING
-+ rtai_register_hfc(hfctmp);
-+#endif
-+ printk(KERN_INFO
-+ "zaphfc: %s %s configured at mem %#x fifo %#x(%#x) IRQ %d HZ %d\n",
-+ vendor_name, card_name,
-+ (u_int) hfctmp->pci_io,
-+ (u_int) hfctmp->fifos,
-+ (u_int) virt_to_bus(hfctmp->fifos),
-+ hfctmp->irq, HZ);
-+ pci_write_config_word(hfctmp->pcidev, PCI_COMMAND, PCI_COMMAND_MEMORY); // enable memio
-+ hfctmp->regs.int_m1 = 0; // no ints
-+ hfctmp->regs.int_m2 = 0; // not at all
-+ hfc_outb(hfctmp,hfc_INT_M1,hfctmp->regs.int_m1);
-+ hfc_outb(hfctmp,hfc_INT_M2,hfctmp->regs.int_m2);
-+
-+ if ((modes & (1 << hfc_dev_count)) != 0) {
-+ printk(KERN_INFO "zaphfc: Card %d configured for NT mode\n",hfc_dev_count);
-+ hfctmp->regs.nt_mode = 1;
-+ } else {
-+ printk(KERN_INFO "zaphfc: Card %d configured for TE mode\n",hfc_dev_count);
-+ hfctmp->regs.nt_mode = 0;
-+ }
-+
-+ zthfc = kmalloc(sizeof(struct zt_hfc),GFP_KERNEL);
-+ if (!zthfc) {
-+ printk(KERN_CRIT "zaphfc: unable to kmalloc!\n");
-+ hfc_shutdownCard(hfctmp);
-+ kfree(hfctmp);
-+ multi_hfc = NULL;
-+ return -ENOMEM;
-+ }
-+ memset(zthfc, 0x0, sizeof(struct zt_hfc));
-+
-+ zthfc->card = hfctmp;
-+ zthfc_initialize(zthfc);
-+ hfctmp->ztdev = zthfc;
-+
-+ memset(hfctmp->drecbuf, 0x0, sizeof(hfctmp->drecbuf));
-+ hfctmp->ztdev->chans[2].readchunk = hfctmp->drecbuf;
-+
-+ memset(hfctmp->dtransbuf, 0x0, sizeof(hfctmp->dtransbuf));
-+ hfctmp->ztdev->chans[2].writechunk = hfctmp->dtransbuf;
-+
-+ memset(hfctmp->brecbuf[0], 0x0, sizeof(hfctmp->brecbuf[0]));
-+ hfctmp->ztdev->chans[0].readchunk = hfctmp->brecbuf[0];
-+ memset(hfctmp->btransbuf[0], 0x0, sizeof(hfctmp->btransbuf[0]));
-+ hfctmp->ztdev->chans[0].writechunk = hfctmp->btransbuf[0];
-+
-+ memset(hfctmp->brecbuf[1], 0x0, sizeof(hfctmp->brecbuf[1]));
-+ hfctmp->ztdev->chans[1].readchunk = hfctmp->brecbuf[1];
-+ memset(hfctmp->btransbuf[1], 0x0, sizeof(hfctmp->btransbuf[1]));
-+ hfctmp->ztdev->chans[1].writechunk = hfctmp->btransbuf[1];
-+
-+
-+ hfc_registerCard(hfctmp);
-+ hfc_resetCard(hfctmp);
-+ tmp = pci_find_device(pcivendor, pcidevice, multi_hfc);
-+ }
-+ return 0;
-+}
-+
-+
-+
-+int init_module(void) {
-+ int i = 0;
-+#ifdef RTAITIMING
-+ RTIME tick_period;
-+ for (i=0; i < hfc_MAX_CARDS; i++) {
-+ rtai_hfc_list[i] = NULL;
-+ }
-+ rt_set_periodic_mode();
-+#endif
-+ i = 0;
-+ while (id_list[i].vendor_id) {
-+ multi_hfc = NULL;
-+ hfc_findCards(id_list[i].vendor_id, id_list[i].device_id, id_list[i].vendor_name, id_list[i].card_name);
-+ i++;
-+ }
-+#ifdef RTAITIMING
-+ for (i=0; i < hfc_MAX_CARDS; i++) {
-+ if (rtai_hfc_list[i]) {
-+ printk(KERN_INFO
-+ "zaphfc: configured %d at mem %#x fifo %#x(%#x) for realtime servicing\n",
-+ rtai_hfc_list[i]->cardno,
-+ (u_int) rtai_hfc_list[i]->pci_io,
-+ (u_int) rtai_hfc_list[i]->fifos,
-+ (u_int) virt_to_bus(rtai_hfc_list[i]->fifos));
-+
-+ }
-+ }
-+ rt_task_init(&rt_task, rtai_loop, 1, STACK_SIZE, TASK_PRIORITY, 0, 0);
-+ tick_period = start_rt_timer(nano2count(TICK_PERIOD));
-+ rt_task_make_periodic(&rt_task, rt_get_time() + tick_period, tick_period);
-+#endif
-+ printk(KERN_INFO "zaphfc: %d hfc-pci card(s) in this box.\n", hfc_dev_count);
-+ return 0;
-+}
-+
-+void cleanup_module(void) {
-+ struct hfc_card *tmpcard;
-+#ifdef RTAITIMING
-+ stop_rt_timer();
-+ rt_task_delete(&rt_task);
-+#endif
-+ printk(KERN_INFO "zaphfc: stop\n");
-+// spin_lock(®isterlock);
-+ while (hfc_dev_list != NULL) {
-+ if (hfc_dev_list == NULL) break;
-+ hfc_shutdownCard(hfc_dev_list);
-+ tmpcard = hfc_dev_list;
-+ hfc_dev_list = hfc_dev_list->next;
-+ if (tmpcard != NULL) {
-+ kfree(tmpcard);
-+ tmpcard = NULL;
-+ printk(KERN_INFO "zaphfc: freed one card.\n");
-+ }
-+ }
-+// spin_unlock(®isterlock);
-+}
-+#endif
-+
-+
-+MODULE_DESCRIPTION("HFC-S PCI A Zaptel Driver");
-+MODULE_AUTHOR("Klaus-Peter Junghanns <kpj at junghanns.net>");
-+#ifdef MODULE_LICENSE
-+MODULE_LICENSE("GPL");
-+#endif
-+MODULE_PARM(modes,"i");
-+MODULE_PARM(debug,"i");
-diff -urNad zaptel-1.2.1/zaphfc/zaphfc.h /tmp/dpep.LWjGif/zaptel-1.2.1/zaphfc/zaphfc.h
---- zaptel-1.2.1/zaphfc/zaphfc.h 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.LWjGif/zaptel-1.2.1/zaphfc/zaphfc.h 2005-02-27 00:30:32.000000000 +0200
-@@ -0,0 +1,289 @@
-+/*
-+ * zaphfc.h - Zaptel driver for HFC-S PCI A based ISDN BRI cards
-+ *
-+ * kernel module based on HFC PCI ISDN4Linux and Zaptel drivers
-+ *
-+ * Copyright (C) 2002, 2003, 2004, 2005 Junghanns.NET GmbH
-+ *
-+ * Klaus-Peter Junghanns <kpj at junghanns.net>
-+ *
-+ * This program is free software and may be modified and
-+ * distributed under the terms of the GNU Public License.
-+ *
-+ */
-+
-+/* HFC register addresses - accessed using memory mapped I/O */
-+/* For a list, see datasheet section 3.2.1 at page 21 */
-+
-+#define hfc_outb(a,b,c) (writeb((c),(a)->pci_io+(b)))
-+#define hfc_inb(a,b) (readb((a)->pci_io+(b)))
-+
-+/* GCI/IOM bus monitor registers */
-+
-+#define hfc_C_I 0x08
-+#define hfc_TRxR 0x0C
-+#define hfc_MON1_D 0x28
-+#define hfc_MON2_D 0x2C
-+
-+
-+/* GCI/IOM bus timeslot registers */
-+
-+#define hfc_B1_SSL 0x80
-+#define hfc_B2_SSL 0x84
-+#define hfc_AUX1_SSL 0x88
-+#define hfc_AUX2_SSL 0x8C
-+#define hfc_B1_RSL 0x90
-+#define hfc_B2_RSL 0x94
-+#define hfc_AUX1_RSL 0x98
-+#define hfc_AUX2_RSL 0x9C
-+
-+/* GCI/IOM bus data registers */
-+
-+#define hfc_B1_D 0xA0
-+#define hfc_B2_D 0xA4
-+#define hfc_AUX1_D 0xA8
-+#define hfc_AUX2_D 0xAC
-+
-+/* GCI/IOM bus configuration registers */
-+
-+#define hfc_MST_EMOD 0xB4
-+#define hfc_MST_MODE 0xB8
-+#define hfc_CONNECT 0xBC
-+
-+
-+/* Interrupt and status registers */
-+
-+#define hfc_FIFO_EN 0x44
-+#define hfc_TRM 0x48
-+#define hfc_B_MODE 0x4C
-+#define hfc_CHIP_ID 0x58
-+#define hfc_CIRM 0x60
-+#define hfc_CTMT 0x64
-+#define hfc_INT_M1 0x68
-+#define hfc_INT_M2 0x6C
-+#define hfc_INT_S1 0x78
-+#define hfc_INT_S2 0x7C
-+#define hfc_STATUS 0x70
-+
-+/* S/T section registers */
-+
-+#define hfc_STATES 0xC0
-+#define hfc_SCTRL 0xC4
-+#define hfc_SCTRL_E 0xC8
-+#define hfc_SCTRL_R 0xCC
-+#define hfc_SQ 0xD0
-+#define hfc_CLKDEL 0xDC
-+#define hfc_B1_REC 0xF0
-+#define hfc_B1_SEND 0xF0
-+#define hfc_B2_REC 0xF4
-+#define hfc_B2_SEND 0xF4
-+#define hfc_D_REC 0xF8
-+#define hfc_D_SEND 0xF8
-+#define hfc_E_REC 0xFC
-+
-+/* Bits and values in various HFC PCI registers */
-+
-+/* bits in status register (READ) */
-+#define hfc_STATUS_PCI_PROC 0x02
-+#define hfc_STATUS_NBUSY 0x04
-+#define hfc_STATUS_TIMER_ELAP 0x10
-+#define hfc_STATUS_STATINT 0x20
-+#define hfc_STATUS_FRAMEINT 0x40
-+#define hfc_STATUS_ANYINT 0x80
-+
-+/* bits in CTMT (Write) */
-+#define hfc_CTMT_CLTIMER 0x80
-+#define hfc_CTMT_TIM3_125 0x04
-+#define hfc_CTMT_TIM25 0x10
-+#define hfc_CTMT_TIM50 0x14
-+#define hfc_CTMT_TIM400 0x18
-+#define hfc_CTMT_TIM800 0x1C
-+#define hfc_CTMT_AUTO_TIMER 0x20
-+#define hfc_CTMT_TRANSB2 0x02
-+#define hfc_CTMT_TRANSB1 0x01
-+
-+/* bits in CIRM (Write) */
-+#define hfc_CIRM_AUX_MSK 0x07
-+#define hfc_CIRM_RESET 0x08
-+#define hfc_CIRM_B1_REV 0x40
-+#define hfc_CIRM_B2_REV 0x80
-+
-+/* bits in INT_M1 and INT_S1 */
-+#define hfc_INTS_B1TRANS 0x01
-+#define hfc_INTS_B2TRANS 0x02
-+#define hfc_INTS_DTRANS 0x04
-+#define hfc_INTS_B1REC 0x08
-+#define hfc_INTS_B2REC 0x10
-+#define hfc_INTS_DREC 0x20
-+#define hfc_INTS_L1STATE 0x40
-+#define hfc_INTS_TIMER 0x80
-+
-+/* bits in INT_M2 */
-+#define hfc_M2_PROC_TRANS 0x01
-+#define hfc_M2_GCI_I_CHG 0x02
-+#define hfc_M2_GCI_MON_REC 0x04
-+#define hfc_M2_IRQ_ENABLE 0x08
-+#define hfc_M2_PMESEL 0x80
-+
-+/* bits in STATES */
-+#define hfc_STATES_STATE_MASK 0x0F
-+#define hfc_STATES_LOAD_STATE 0x10
-+#define hfc_STATES_ACTIVATE 0x20
-+#define hfc_STATES_DO_ACTION 0x40
-+#define hfc_STATES_NT_G2_G3 0x80
-+
-+/* bits in HFCD_MST_MODE */
-+#define hfc_MST_MODE_MASTER 0x01
-+#define hfc_MST_MODE_SLAVE 0x00
-+/* remaining bits are for codecs control */
-+
-+/* bits in HFCD_SCTRL */
-+#define hfc_SCTRL_B1_ENA 0x01
-+#define hfc_SCTRL_B2_ENA 0x02
-+#define hfc_SCTRL_MODE_TE 0x00
-+#define hfc_SCTRL_MODE_NT 0x04
-+#define hfc_SCTRL_LOW_PRIO 0x08
-+#define hfc_SCTRL_SQ_ENA 0x10
-+#define hfc_SCTRL_TEST 0x20
-+#define hfc_SCTRL_NONE_CAP 0x40
-+#define hfc_SCTRL_PWR_DOWN 0x80
-+
-+/* bits in SCTRL_E */
-+#define hfc_SCTRL_E_AUTO_AWAKE 0x01
-+#define hfc_SCTRL_E_DBIT_1 0x04
-+#define hfc_SCTRL_E_IGNORE_COL 0x08
-+#define hfc_SCTRL_E_CHG_B1_B2 0x80
-+
-+/* bits in FIFO_EN register */
-+#define hfc_FIFOEN_B1TX 0x01
-+#define hfc_FIFOEN_B1RX 0x02
-+#define hfc_FIFOEN_B2TX 0x04
-+#define hfc_FIFOEN_B2RX 0x08
-+#define hfc_FIFOEN_DTX 0x10
-+#define hfc_FIFOEN_DRX 0x20
-+
-+#define hfc_FIFOEN_B1 (hfc_FIFOEN_B1TX|hfc_FIFOEN_B1RX)
-+#define hfc_FIFOEN_B2 (hfc_FIFOEN_B2TX|hfc_FIFOEN_B2RX)
-+#define hfc_FIFOEN_D (hfc_FIFOEN_DTX|hfc_FIFOEN_DRX)
-+
-+/* bits in the CONNECT register */
-+#define hfc_CONNECT_B1_shift 0
-+#define hfc_CONNECT_B2_shift 3
-+
-+#define hfc_CONNECT_HFC_from_ST 0x0
-+#define hfc_CONNECT_HFC_from_GCI 0x1
-+#define hfc_CONNECT_ST_from_HFC 0x0
-+#define hfc_CONNECT_ST_from_GCI 0x2
-+#define hfc_CONNECT_GCI_from_HFC 0x0
-+#define hfc_CONNECT_GCI_from_ST 0x4
-+
-+/* bits in the __SSL and __RSL registers */
-+#define hfc_SRSL_STIO 0x40
-+#define hfc_SRSL_ENABLE 0x80
-+#define hfc_SRCL_SLOT_MASK 0x1f
-+
-+/* FIFO memory definitions */
-+
-+#define hfc_FMASK 0x000f
-+#define hfc_ZMASK 0x01ff
-+#define hfc_ZMASKB 0x1fff
-+
-+#define hfc_D_FIFO_SIZE 0x0200
-+#define hfc_B_SUB_VAL 0x0200
-+#define hfc_B_FIFO_SIZE 0x1E00
-+#define hfc_MAX_DFRAMES 0x000f
-+
-+#define hfc_FIFO_DTX_Z1 0x2080
-+#define hfc_FIFO_DTX_Z2 0x2082
-+#define hfc_FIFO_DTX_F1 0x20a0
-+#define hfc_FIFO_DTX_F2 0x20a1
-+#define hfc_FIFO_DTX 0x0000
-+#define hfc_FIFO_DTX_ZOFF 0x000
-+
-+#define hfc_FIFO_DRX_Z1 0x6080
-+#define hfc_FIFO_DRX_Z2 0x6082
-+#define hfc_FIFO_DRX_F1 0x60a0
-+#define hfc_FIFO_DRX_F2 0x60a1
-+#define hfc_FIFO_DRX 0x4000
-+#define hfc_FIFO_DRX_ZOFF 0x4000
-+
-+#define hfc_FIFO_B1TX_Z1 0x2000
-+#define hfc_FIFO_B1TX_Z2 0x2002
-+#define hfc_FIFO_B1RX_Z1 0x6000
-+#define hfc_FIFO_B1RX_Z2 0x6002
-+
-+#define hfc_FIFO_B1TX_F1 0x2080
-+#define hfc_FIFO_B1TX_F2 0x2081
-+#define hfc_FIFO_B1RX_F1 0x6080
-+#define hfc_FIFO_B1RX_F2 0x6081
-+
-+#define hfc_FIFO_B1RX_ZOFF 0x4000
-+#define hfc_FIFO_B1TX_ZOFF 0x0000
-+
-+#define hfc_FIFO_B2TX_Z1 0x2100
-+#define hfc_FIFO_B2TX_Z2 0x2102
-+#define hfc_FIFO_B2RX_Z1 0x6100
-+#define hfc_FIFO_B2RX_Z2 0x6102
-+
-+#define hfc_FIFO_B2TX_F1 0x2180
-+#define hfc_FIFO_B2TX_F2 0x2181
-+#define hfc_FIFO_B2RX_F1 0x6180
-+#define hfc_FIFO_B2RX_F2 0x6181
-+
-+#define hfc_FIFO_B2RX_ZOFF 0x6000
-+#define hfc_FIFO_B2TX_ZOFF 0x2000
-+
-+#define hfc_BTRANS_THRESHOLD 128
-+#define hfc_BTRANS_THRESMASK 0x00
-+
-+/* Structures */
-+
-+typedef struct hfc_regs {
-+ unsigned char fifo_en;
-+ unsigned char ctmt;
-+ unsigned char int_m1;
-+ unsigned char int_m2;
-+ unsigned char sctrl;
-+ unsigned char sctrl_e;
-+ unsigned char sctrl_r;
-+ unsigned char connect;
-+ unsigned char trm;
-+ unsigned char mst_mode;
-+ unsigned char bswapped;
-+ unsigned char nt_mode;
-+ unsigned char int_drec;
-+} hfc_regs;
-+
-+typedef struct hfc_card {
-+ spinlock_t lock;
-+ unsigned int irq;
-+ unsigned int iomem;
-+ int ticks;
-+ int clicks;
-+ unsigned char *pci_io;
-+ void *fifomem; // start of the shared mem
-+ volatile void *fifos; // 32k aligned mem for the fifos
-+ struct hfc_regs regs;
-+ unsigned int pcibus;
-+ unsigned int pcidevfn;
-+ struct pci_dev *pcidev;
-+ struct zt_hfc *ztdev;
-+ int drecinframe;
-+ unsigned char drecbuf[hfc_D_FIFO_SIZE];
-+ unsigned char dtransbuf[hfc_D_FIFO_SIZE];
-+ unsigned char brecbuf[2][ZT_CHUNKSIZE];
-+ unsigned char btransbuf[2][ZT_CHUNKSIZE];
-+ unsigned char cardno;
-+ struct hfc_card *next;
-+} hfc_card;
-+
-+typedef struct zt_hfc {
-+ unsigned int usecount;
-+ struct zt_span span;
-+ struct zt_chan chans[3];
-+ struct hfc_card *card;
-+} zt_hfc;
-+
-+/* tune this */
-+#define hfc_BCHAN_BUFFER 8
-+#define hfc_MAX_CARDS 8
-diff -urNad zaptel-1.2.1/zaphfc/zaptel.conf /tmp/dpep.LWjGif/zaptel-1.2.1/zaphfc/zaptel.conf
---- zaptel-1.2.1/zaphfc/zaptel.conf 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.LWjGif/zaptel-1.2.1/zaphfc/zaptel.conf 2004-03-24 16:35:12.000000000 +0200
-@@ -0,0 +1,8 @@
-+# hfc-s pci a span definition
-+# most of the values should be bogus because we are not really zaptel
-+loadzone=nl
-+defaultzone=nl
-+
-+span=1,1,3,ccs,ami
-+bchan=1-2
-+dchan=3
-diff -urNad zaptel-1.2.1/zaptel.c /tmp/dpep.LWjGif/zaptel-1.2.1/zaptel.c
---- zaptel-1.2.1/zaptel.c 2005-12-02 02:03:01.000000000 +0200
-+++ /tmp/dpep.LWjGif/zaptel-1.2.1/zaptel.c 2005-12-21 22:50:47.000000000 +0200
-@@ -4912,11 +4912,40 @@
- *(txb++) = fasthdlc_tx_run_nocheck(&ms->txhdlc);
- }
- bytes -= left;
-+#ifdef CONFIG_ZAPATA_BRI_DCHANS
-+ } else if (ms->flags & ZT_FLAG_BRIDCHAN) {
-+ /*
-+ * Let's get this right, we want to transmit complete frames only.
-+ * The card driver will do the dirty HDLC work for us.
-+ * txb (transmit buffer) is supposed to be big enough to store one frame
-+ * we will make this as big as the D fifo (1KB or 2KB)
-+ */
-+
-+ /* there are 'left' bytes in the user buffer left to transmit */
-+ left = ms->writen[ms->outwritebuf] - ms->writeidx[ms->outwritebuf] - 2;
-+ if (left > ms->maxbytes2transmit) {
-+ memcpy(txb, buf + ms->writeidx[ms->outwritebuf], ms->maxbytes2transmit);
-+ ms->writeidx[ms->outwritebuf] += ms->maxbytes2transmit;
-+ txb += ms->maxbytes2transmit;
-+ ms->bytes2transmit = ms->maxbytes2transmit;
-+ ms->eoftx = 0;
-+ } else {
-+ memcpy(txb, buf + ms->writeidx[ms->outwritebuf], left);
-+ ms->writeidx[ms->outwritebuf] += left + 2;
-+ txb += left;
-+ ms->bytes2transmit = left;
-+ ms->eoftx = 1;
-+ }
-+ bytes = 0;
-+#endif
- } else {
- memcpy(txb, buf + ms->writeidx[ms->outwritebuf], left);
- ms->writeidx[ms->outwritebuf]+=left;
- txb += left;
- bytes -= left;
-+#if defined(CONFIG_ZAPATA_BRI_DCHANS)
-+ ms->bytes2transmit=ZT_CHUNKSIZE;
-+#endif
- }
- /* Check buffer status */
- if (ms->writeidx[ms->outwritebuf] >= ms->writen[ms->outwritebuf]) {
-@@ -4961,6 +4990,17 @@
- /* Transmit a flag if this is an HDLC channel */
- if (ms->flags & ZT_FLAG_HDLC)
- fasthdlc_tx_frame_nocheck(&ms->txhdlc);
-+#if defined(CONFIG_ZAPATA_BRI_DCHANS)
-+ if(ms->flags & ZT_FLAG_BRIDCHAN) {
-+ // if (ms->bytes2transmit > 0) {
-+ // txb += 2;
-+ // ms->bytes2transmit -= 2;
-+ bytes=0;
-+ ms->eoftx = 1;
-+// printk(KERN_CRIT "zaptel EOF(%d) bytes2transmit %d\n",ms->eoftx,ms->bytes2transmit);
-+ // }
-+ }
-+#endif
- #ifdef CONFIG_ZAPATA_NET
- if (ms->flags & ZT_FLAG_NETDEV)
- netif_wake_queue(ztchan_to_dev(ms));
-@@ -5017,6 +5057,10 @@
- memset(txb, 0xFF, bytes);
- }
- bytes = 0;
-+#if defined(CONFIG_ZAPATA_BRI_DCHANS)
-+ } else if(ms->flags & ZT_FLAG_BRIDCHAN) {
-+ bytes = 0;
-+#endif
- } else {
- memset(txb, ZT_LIN2X(0, ms), bytes); /* Lastly we use silence on telephony channels */
- bytes = 0;
-@@ -5742,6 +5786,13 @@
- int left, x;
-
- int bytes = ZT_CHUNKSIZE;
-+#if defined(CONFIG_ZAPATA_BRI_DCHANS)
-+ if (ms->flags & ZT_FLAG_BRIDCHAN) {
-+ bytes = ms->bytes2receive;
-+ if (bytes < 1) return;
-+// printk(KERN_CRIT "bytes2receive %d\n",ms->bytes2receive);
-+ }
-+#endif
-
- while(bytes) {
- #if defined(CONFIG_ZAPATA_NET) || defined(CONFIG_ZAPATA_PPP)
-@@ -5800,6 +5851,19 @@
- }
- }
- }
-+#ifdef CONFIG_ZAPATA_BRI_DCHANS
-+ } else if (ms->flags & ZT_FLAG_BRIDCHAN) {
-+ memcpy(buf + ms->readidx[ms->inreadbuf], rxb, left);
-+ rxb += left;
-+ ms->readidx[ms->inreadbuf] += left;
-+ bytes -= left;
-+ if (ms->eofrx == 1) {
-+ eof=1;
-+ }
-+// printk(KERN_CRIT "receiving %d bytes\n",ms->bytes2receive);
-+ ms->bytes2receive = 0;
-+ ms->eofrx = 0;
-+#endif
- } else {
- /* Not HDLC */
- memcpy(buf + ms->readidx[ms->inreadbuf], rxb, left);
-diff -urNad zaptel-1.2.1/zaptel.h /tmp/dpep.LWjGif/zaptel-1.2.1/zaptel.h
---- zaptel-1.2.1/zaptel.h 2005-11-29 20:42:08.000000000 +0200
-+++ /tmp/dpep.LWjGif/zaptel-1.2.1/zaptel.h 2005-12-21 22:50:47.000000000 +0200
-@@ -981,6 +981,13 @@
- int do_ppp_error;
- struct sk_buff_head ppp_rq;
- #endif
-+#ifdef CONFIG_ZAPATA_BRI_DCHANS
-+ int bytes2receive;
-+ int maxbytes2transmit; /* size of the tx buffer in the card driver */
-+ int bytes2transmit;
-+ int eofrx;
-+ int eoftx;
-+#endif
- spinlock_t lock;
- char name[40]; /* Name */
- /* Specified by zaptel */
-@@ -1218,6 +1225,10 @@
- #define ZT_FLAG_T1PPP (1 << 15)
- #define ZT_FLAG_SIGFREEZE (1 << 16) /* Freeze signalling */
-
-+#if defined(CONFIG_ZAPATA_BRI_DCHANS)
-+#define ZT_FLAG_BRIDCHAN (1 << 17)
-+#endif
-+
- struct zt_span {
- spinlock_t lock;
- void *pvt; /* Private stuff */
-diff -urNad zaptel-1.2.1/zconfig.h /tmp/dpep.LWjGif/zaptel-1.2.1/zconfig.h
---- zaptel-1.2.1/zconfig.h 2005-11-29 20:42:08.000000000 +0200
-+++ /tmp/dpep.LWjGif/zaptel-1.2.1/zconfig.h 2005-12-21 22:50:47.000000000 +0200
-@@ -152,4 +152,10 @@
- */
- /* #define FXSFLASH */
-
-+/*
-+ * Uncomment the following for BRI D channels
-+ *
-+ */
-+#define CONFIG_ZAPATA_BRI_DCHANS
-+
- #endif
Deleted: zaptel/trunk/debian/patches/bristuff-0.3.0-PRE1f.dpatch
===================================================================
--- zaptel/trunk/debian/patches/bristuff-0.3.0-PRE1f.dpatch 2006-04-30 15:19:14 UTC (rev 1655)
+++ zaptel/trunk/debian/patches/bristuff-0.3.0-PRE1f.dpatch 2006-04-30 16:30:35 UTC (rev 1656)
@@ -1,6687 +0,0 @@
-#! /bin/sh /usr/share/dpatch/dpatch-run
-## bristuff-0.3.0-PRE1d.dpatch by Tzafrir Cohen <tzafrir.cohen at xorcom.com>
-##
-## All lines beginning with `## DP:' are a description of the patch.
-## DP: The zapbri modules (cwain, qozap, zaphfc) and zaptel patch from the
-## DP: bristuff patch by Klaus-Peter Junghanns. Version 0.3.0-PRE1f
-
- at DPATCH@
-diff -urNad zaptel-1.2.1/cwain/cwain.c /tmp/dpep.RTh8jH/zaptel-1.2.1/cwain/cwain.c
---- zaptel-1.2.1/cwain/cwain.c 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.RTh8jH/zaptel-1.2.1/cwain/cwain.c 2005-10-11 17:36:14.000000000 +0200
-@@ -0,0 +1,1489 @@
-+/*
-+ * cwain.c - Zaptel driver for the Junghanns.NET E1 card
-+ *
-+ * c.w.a.i.n. == card without an interesting name
-+ *
-+ * single/double E1 board
-+ *
-+ * Copyright (C) 2004, 2005 Junghanns.NET GmbH
-+ *
-+ * Klaus-Peter Junghanns <kpj at junghanns.net>
-+ *
-+ * This program is free software and may be modified and
-+ * distributed under the terms of the GNU Public License.
-+ *
-+ */
-+#include <linux/kernel.h>
-+#include <linux/module.h>
-+#include <linux/pci.h>
-+#include <linux/init.h>
-+#include <linux/interrupt.h>
-+#include <zaptel.h>
-+#include "cwain.h"
-+
-+#if CONFIG_PCI
-+
-+static int ports=-1; /* autodetect */
-+static int debug=0;
-+static struct zt_cwain *cwain_span_list = NULL;
-+static int cwain_span_count = 0;
-+static struct zt_cwain_card *cwain_card_list = NULL;
-+static int cwain_card_count = 0;
-+static struct pci_dev *multi_cwain = NULL;
-+static spinlock_t cwain_span_registerlock = SPIN_LOCK_UNLOCKED;
-+static spinlock_t cwain_card_registerlock = SPIN_LOCK_UNLOCKED;
-+
-+static int ztcwain_shutdown(struct zt_span *span);
-+
-+int cwain_waitbusy(struct zt_cwain *cwaintmp) {
-+ int x=1000;
-+ while (x-- && (cwain_inb(cwaintmp,cwain_R_STATUS) & 1));
-+ if (x < 0) {
-+ printk(KERN_CRIT "cwain: really busy waiting!\n");
-+ return -1;
-+ } else {
-+ if ((x < 990) && (cwaintmp->ticks > 500)) {
-+ printk(KERN_CRIT "cwain: waited %d\n", 1000 - x);
-+ }
-+ return 0;
-+ }
-+}
-+
-+void cwain_unregister_zap_span(struct zt_cwain *cwainspan) {
-+ if (!cwainspan) {
-+ printk(KERN_INFO "cwain: shutting down NULL span!\n");
-+ return;
-+ }
-+ if(cwainspan->span.flags & ZT_FLAG_RUNNING) {
-+ ztcwain_shutdown(&cwainspan->span);
-+ if (debug)
-+ printk(KERN_INFO "cwain: shutdown span %d.\n",cwainspan->cardno);
-+ }
-+ if(cwainspan->span.flags & ZT_FLAG_REGISTERED) {
-+ zt_unregister(&cwainspan->span);
-+ if (debug)
-+ printk(KERN_INFO "cwain: unregistered span %d.\n",cwainspan->cardno);
-+ }
-+}
-+
-+void cwain_shutdown_span(struct zt_cwain *cwainspan) {
-+
-+ if (!cwainspan) {
-+ printk(KERN_INFO "cwain: shutting down NULL span!\n");
-+ return;
-+ }
-+
-+ if (cwainspan->pci_io == NULL) {
-+ return;
-+ }
-+
-+ if (debug)
-+ printk(KERN_INFO "cwain: shutting down span %d (cardID %d) at %p.\n",cwainspan->cardno,cwainspan->cardID,cwainspan->pci_io);
-+
-+ // turn off irqs
-+
-+ // softreset
-+ cwain_outb(cwainspan,cwain_R_CIRM,0x8);
-+ cwain_outb(cwainspan,cwain_R_CIRM,0x0);
-+ cwain_waitbusy(cwainspan);
-+
-+ cwain_outb(cwainspan,cwain_R_IRQMSK_MISC, 0);
-+ cwain_outb(cwainspan,cwain_R_IRQ_CTRL, 0);
-+
-+ pci_write_config_word(cwainspan->pcidev, PCI_COMMAND, 0); // disable memio
-+
-+ if (cwainspan->pcidev != NULL) {
-+ pci_disable_device(cwainspan->pcidev);
-+ cwainspan->pcidev = NULL;
-+ }
-+
-+// iounmap((void *) cwainspan->pci_io);
-+// cwainspan->pci_io = NULL;
-+}
-+
-+void cwain_shutdown_card(struct zt_cwain_card *cwaintmp) {
-+ unsigned long flags = 0;
-+ int i = 0;
-+
-+ if (!cwaintmp) {
-+ printk(KERN_INFO "cwain: shutting down NULL card!\n");
-+ return;
-+ }
-+
-+ for (i=0;i<cwaintmp->spans;i++) {
-+ cwain_unregister_zap_span(cwaintmp->span[i]);
-+ }
-+
-+ spin_lock_irqsave(&cwaintmp->lock,flags);
-+
-+ // turn off irqs
-+ cwain_outb(cwaintmp->span[0],cwain_R_IRQ_CTRL, 0);
-+ cwain_outb(cwaintmp->span[0],cwain_R_IRQMSK_MISC, 0);
-+
-+ for (i=0;i<cwaintmp->spans;i++) {
-+ cwain_shutdown_span(cwaintmp->span[i]);
-+ }
-+ spin_unlock_irqrestore(&cwaintmp->lock,flags);
-+
-+ for (i=0;i<cwaintmp->spans;i++) {
-+ iounmap((void *) cwaintmp->span[i]->pci_io);
-+ cwaintmp->span[i]->pci_io = NULL;
-+ }
-+
-+ free_irq(cwaintmp->irq,cwaintmp);
-+}
-+
-+void cwain_doLEDs(struct zt_cwain *cwaintmp) {
-+ /*
-+ O1 O3 (red)
-+ O2 O4 (green)
-+ */
-+ if (!(cwaintmp->span.flags & ZT_FLAG_RUNNING)) {
-+ return;
-+ }
-+ if ((cwaintmp->type == 0xb553) || (cwaintmp->type == 0xb554)) {
-+ /* sync status */
-+ if (((cwaintmp->sync_sta & 0x07) == 0x07) && cwaintmp->sync) {
-+ cwaintmp->leds[0] = 1;
-+ cwaintmp->leds[1] = 0;
-+ } else {
-+ cwaintmp->leds[0] = 0;
-+ cwaintmp->leds[1] = 1;
-+ }
-+ /* multiframe alignment */
-+ if ((cwaintmp->sync_sta & 0x20) == 0x20) {
-+ cwaintmp->leds[2] = 1;
-+ cwaintmp->leds[3] = 0;
-+ } else {
-+ if ((cwaintmp->span.lineconfig & ZT_CONFIG_CRC4) && cwaintmp->sync) {
-+ /* CRC4 requested */
-+ cwaintmp->leds[2] = 0;
-+ cwaintmp->leds[3] = 1;
-+ } else {
-+ /* no CRC4, disable 3 and 4 */
-+ cwaintmp->leds[2] = 1;
-+ cwaintmp->leds[3] = 1;
-+ }
-+ }
-+ cwain_outb(cwaintmp,cwain_R_GPIO_OUT1,(cwaintmp->leds[0] | (cwaintmp->leds[1] << 1) | (cwaintmp->leds[2] << 2) | (cwaintmp->leds[3] << 3)));
-+ }
-+}
-+
-+void cwain_reset_span(struct zt_cwain *cwaintmp) {
-+ int i = 0;
-+ pci_write_config_word(cwaintmp->pcidev, PCI_COMMAND, PCI_COMMAND_MEMORY); // enable memio
-+
-+ /* FIFO, HDLC reset */
-+ cwain_outb(cwaintmp,cwain_R_CIRM,0x10);
-+ cwain_outb(cwaintmp,cwain_R_CIRM,0x0);
-+ cwain_waitbusy(cwaintmp);
-+
-+ /* PCM reset */
-+ cwain_outb(cwaintmp,cwain_R_CIRM,0x20);
-+ cwain_outb(cwaintmp,cwain_R_CIRM,0x0);
-+ cwain_waitbusy(cwaintmp);
-+
-+ for (i=0; i<128; i++) {
-+ cwain_outb(cwaintmp,cwain_R_SLOT, i);
-+ cwain_outb(cwaintmp,cwain_A_SL_CFG, 0x0);
-+ }
-+
-+ /* E1 reset */
-+ cwain_outb(cwaintmp,cwain_R_CIRM,0x40);
-+ cwain_outb(cwaintmp,cwain_R_CIRM,0x0);
-+ cwain_waitbusy(cwaintmp);
-+
-+ /* 128 byte B chans, 4096 byte D chans */
-+ cwain_outb(cwaintmp,cwain_R_FIFO_MD,0x36);
-+ cwain_outb(cwaintmp,cwain_R_BRG_PCM_CFG,0x0);
-+ cwain_outb(cwaintmp,cwain_R_CTRL,0x0);
-+
-+ /* no blinky blink */
-+ cwain_outb(cwaintmp,cwain_R_GPIO_SEL,0x20 | 0x10);
-+ cwain_outb(cwaintmp,cwain_R_GPIO_EN1,0x0f);
-+ cwain_outb(cwaintmp,cwain_R_GPIO_OUT1,0x0f);
-+
-+ cwaintmp->leds[0] = 1;
-+ cwaintmp->leds[1] = 1;
-+ cwaintmp->leds[2] = 1;
-+ cwaintmp->leds[3] = 1;
-+
-+ cwaintmp->ticks = 0;
-+ cwaintmp->clicks = 0;
-+}
-+
-+struct zt_cwain_card *cwain_get_card(unsigned int pcibus) {
-+ struct zt_cwain_card *cwaintmp = cwain_card_list;
-+ spin_lock(&cwain_card_registerlock);
-+ while (cwaintmp) {
-+ if (cwaintmp->pcibus == pcibus) {
-+ break;
-+ }
-+ cwaintmp = cwaintmp->next;
-+ }
-+ spin_unlock(&cwain_card_registerlock);
-+ return cwaintmp;
-+}
-+
-+
-+void cwain_register_card(struct zt_cwain_card *cwaincard) {
-+ spin_lock(&cwain_card_registerlock);
-+ if (cwaincard != NULL) {
-+ cwaincard->prev = NULL;
-+ cwaincard->next = cwain_card_list;
-+ if (cwain_card_list) {
-+ cwain_card_list->prev = cwaincard;
-+ }
-+ cwain_card_list = cwaincard;
-+ cwain_card_count++;
-+ } else {
-+ printk(KERN_INFO "cwain: trying to register NULL card.\n");
-+ }
-+ spin_unlock(&cwain_card_registerlock);
-+}
-+
-+int cwain_register_span(struct zt_cwain *cwainspan) {
-+ struct zt_cwain_card *cwaintmp;
-+ spin_lock(&cwain_span_registerlock);
-+ if (cwainspan != NULL) {
-+ cwainspan->prev = NULL;
-+ cwainspan->next = cwain_span_list;
-+ if (cwain_span_list) {
-+ cwain_span_list->prev = cwainspan;
-+ }
-+ cwain_span_list = cwainspan;
-+ cwainspan->cardno = ++cwain_span_count;
-+ } else {
-+ printk(KERN_INFO "cwain: trying to register NULL span.\n");
-+ }
-+ spin_unlock(&cwain_span_registerlock);
-+
-+ if (cwainspan->type == 0xb553) {
-+ cwaintmp = kmalloc(sizeof(struct zt_cwain_card),GFP_KERNEL);
-+ if (!cwaintmp) {
-+ printk(KERN_WARNING "cwain: unable to kmalloc!\n");
-+ return -1;
-+ }
-+ memset(cwaintmp, 0x0, sizeof(struct zt_cwain_card));
-+
-+ spin_lock_init(&cwaintmp->lock);
-+ cwaintmp->pcibus = cwainspan->pcibus;
-+ cwaintmp->span[0] = cwainspan;
-+ cwaintmp->syncs[0] = -1;
-+ cwaintmp->spans = 1;
-+ cwaintmp->cardID = cwainspan->cardID;
-+ cwain_register_card(cwaintmp);
-+ printk(KERN_INFO
-+ "cwain: Junghanns.NET singleE1 PCI ISDN card configured at mem %#x IRQ %d HZ %d CardID %d\n",
-+ (u_int) cwainspan->pci_io,
-+ cwaintmp->span[0]->irq, HZ, cwainspan->cardID);
-+ } else {
-+ cwaintmp = cwain_get_card(cwainspan->pcibus);
-+ if (!cwaintmp) {
-+ cwaintmp = kmalloc(sizeof(struct zt_cwain_card),GFP_KERNEL);
-+ if (!cwaintmp) {
-+ printk(KERN_WARNING "cwain: unable to kmalloc!\n");
-+ return -1;
-+ }
-+ memset(cwaintmp, 0x0, sizeof(struct zt_cwain_card));
-+
-+ spin_lock_init(&cwaintmp->lock);
-+ cwaintmp->pcibus = cwainspan->pcibus;
-+ cwaintmp->spans = cwainspan->type - 46419;
-+ cwaintmp->span[0] = cwainspan;
-+ cwaintmp->cardID = cwainspan->cardID;
-+ cwaintmp->syncs[0] = -1;
-+ cwain_register_card(cwaintmp);
-+ } else {
-+ cwaintmp->spans = cwainspan->type - 46418;
-+ if (cwainspan->cardID < cwaintmp->cardID) {
-+ cwaintmp->cardID = cwainspan->cardID;
-+ cwaintmp->span[1] = cwaintmp->span[0];
-+ cwaintmp->syncs[1] = cwaintmp->syncs[0];
-+ cwaintmp->span[0] = cwainspan;
-+ } else {
-+ cwaintmp->span[1] = cwainspan;
-+ cwaintmp->syncs[1] = -1;
-+ }
-+ printk(KERN_INFO
-+ "cwain: Junghanns.NET doubleE1 PCI ISDN card configured at mem (%#x / %#x) IRQ %d HZ %d CardID (%d / %d) bus %#x\n",
-+ (u_int) cwaintmp->span[0]->pci_io, (u_int) cwaintmp->span[1]->pci_io,
-+ cwaintmp->span[0]->irq, HZ, cwaintmp->span[0]->cardID, cwaintmp->span[1]->cardID, cwaintmp->pcibus);
-+ }
-+ }
-+ return 0;
-+}
-+
-+static int cwain_dfifo_tx(struct zt_cwain *cwaintmp) {
-+ int chan = 15;
-+ int x=0;
-+ char fifo = 0;
-+
-+ fifo = 0x1F;
-+
-+ if (cwaintmp->chans[chan].bytes2transmit < 1) {
-+ return 0;
-+ } else {
-+ /* select fifo */
-+ cwain_outb(cwaintmp,cwain_R_FIFO,fifo << 1);
-+ cwain_waitbusy(cwaintmp);
-+
-+ if (debug)
-+ printk(KERN_INFO "cwain: card %d TX [ ", cwaintmp->cardno);
-+ /* copy frame to fifo */
-+ for (x=0;x<cwaintmp->chans[chan].bytes2transmit;x++) {
-+ if (debug)
-+ printk("%#x ",cwaintmp->dtxbuf[x]);
-+ cwain_outb(cwaintmp,cwain_A_FIFO_DATA0,cwaintmp->dtxbuf[x]);
-+ }
-+ if (debug)
-+ printk("]\n");
-+ if (debug)
-+ printk(KERN_INFO "ztx %d bytes\n",cwaintmp->chans[chan].bytes2transmit);
-+
-+ if (cwaintmp->chans[chan].eoftx == 1) {
-+ /* transmit HDLC frame */
-+ cwain_outb(cwaintmp,cwain_R_INC_RES_FIFO,0x1);
-+ cwain_waitbusy(cwaintmp);
-+ }
-+ }
-+ return 0;
-+}
-+
-+static int cwain_fifo_tx(struct zt_cwain *cwaintmp, char fifo) {
-+ int chan;
-+ if (fifo >= 15) {
-+ chan = fifo;
-+ } else {
-+ chan = fifo;
-+ }
-+ /* select fifo */
-+ cwain_outb(cwaintmp,cwain_R_FIFO,0x80 | (fifo << 1));
-+ cwain_waitbusy(cwaintmp);
-+ /* transmit 8 bytes of transparent data */
-+ cwain_outdw(cwaintmp,cwain_A_FIFO_DATA0,*((unsigned int *) &cwaintmp->txbuf[chan][0]));
-+ cwain_outdw(cwaintmp,cwain_A_FIFO_DATA0,*((unsigned int *) &cwaintmp->txbuf[chan][4]));
-+
-+ return 0;
-+}
-+
-+static int cwain_dfifo_rx(struct zt_cwain *cwaintmp) {
-+ int chan = 15;
-+ unsigned char f1=1,f2=1,data,stat;
-+ unsigned char of1=0,of2=0;
-+ int len,i;
-+ unsigned short z1=1,z2=1;
-+ unsigned short oz1=0,oz2=0;
-+ char fifo = 0;
-+
-+ fifo = 0x1F;
-+
-+ /* select fifo */
-+ cwain_outb(cwaintmp,cwain_R_FIFO,(fifo << 1) | 1);
-+ cwain_waitbusy(cwaintmp);
-+
-+ while ((oz1 != z1) && (oz2 != z2)) {
-+ oz1 = z1;
-+ oz2 = z2;
-+ z1 = cwain_inw(cwaintmp,cwain_A_Z1) & 0xfff;
-+ z2 = cwain_inw(cwaintmp,cwain_A_Z2) & 0xfff;
-+ }
-+
-+ len = z1-(z2 & 0xfff);
-+ if (len < 0) {
-+ len += cwain_DFIFO_SIZE;
-+ }
-+
-+ while ((of1 != f1) && (of2 != f2)) {
-+ of1 = f1;
-+ of2 = f2;
-+ f1 = cwain_inb(cwaintmp,cwain_A_F1) & 0xf;
-+ f2 = cwain_inb(cwaintmp,cwain_A_F2) & 0xf;
-+ }
-+
-+ if (len > cwain_DFIFO_SIZE) {
-+ printk(KERN_INFO "\ncwain: buffer overflow in D channel RX!\n");
-+ cwaintmp->chans[chan].bytes2receive = 0;
-+ cwaintmp->chans[chan].eofrx = 0;
-+ } else {
-+ if (debug) printk(KERN_INFO "cwain: card %d RX [ ", cwaintmp->cardno);
-+ for (i=0; i<len; i++) {
-+ data = cwain_inb(cwaintmp,cwain_A_FIFO_DATA0);
-+ cwaintmp->drxbuf[i] = data;
-+ if (debug) printk("%#x ",data);
-+ }
-+ if (debug) printk("] %d bytes\n", i);
-+ cwaintmp->chans[chan].bytes2receive = i;
-+ cwaintmp->chans[chan].eofrx = 1;
-+ }
-+
-+ stat = cwain_inb(cwaintmp,cwain_A_FIFO_DATA0);
-+ if (stat != 0x0) {
-+ // bad CRC, skip it
-+ if (cwaintmp->sync) {
-+ printk(KERN_INFO "cwain: BAD CRC for hdlc frame on card %d (cardID %d) stat %#x\n",cwaintmp->cardno, cwaintmp->cardID, stat);
-+ }
-+ cwaintmp->chans[chan].bytes2receive = 0;
-+ cwaintmp->chans[chan].eofrx = 0;
-+// zt_qevent_nolock(&cwaintmp->spans[stport].chans[chan], ZT_EVENT_BADFCS);
-+ }
-+ cwain_outb(cwaintmp,cwain_R_INC_RES_FIFO,0x1);
-+ cwain_waitbusy(cwaintmp);
-+
-+ /* frame received */
-+ cwaintmp->drx--;
-+ return 0;
-+}
-+
-+
-+static int cwain_fifo_rx(struct zt_cwain *cwaintmp, char fifo) {
-+ int chan;
-+ unsigned char data;
-+ int len,i;
-+ unsigned short z1=1,z2=1;
-+ unsigned short oz1=0,oz2=0;
-+ int mumbojumbo=0;
-+ int x = 1000;
-+
-+ if (fifo >= 15) {
-+ chan = fifo; /* +1 */
-+ } else {
-+ chan = fifo;
-+ }
-+
-+ // select rx fifo
-+
-+ // no hdlc, transparent data
-+ cwain_outb(cwaintmp,cwain_R_FIFO,0x80 | (fifo << 1) | 1);
-+ cwain_waitbusy(cwaintmp);
-+
-+ while (x-- && ((oz1 != z1) && (oz2 != z2))) {
-+ oz1 = z1;
-+ oz2 = z2;
-+ z1 = cwain_inw(cwaintmp,cwain_A_Z1) & 0x1ff;
-+ z2 = cwain_inw(cwaintmp,cwain_A_Z2) & 0x1ff;
-+ }
-+ if (x < 500) {
-+ printk(KERN_CRIT "cwain: prevented endless loop\n");
-+ }
-+
-+ len = z1-(z2 & 0x1ff);
-+ if (len < 0) {
-+ len += cwain_FIFO_SIZE;
-+ }
-+// if (len > 2 * ZT_CHUNKSIZE) {
-+ if (len > cwain_FIFO_HW) {
-+// mumbojumbo = len - (2 * ZT_CHUNKSIZE);
-+ mumbojumbo = len - (cwain_FIFO_HW);
-+ len = ZT_CHUNKSIZE;
-+ for (i=0;i<mumbojumbo;i++) {
-+ data = cwain_inb(cwaintmp,cwain_A_FIFO_DATA0);
-+ }
-+ cwaintmp->clicks++;
-+ }
-+ if (len < ZT_CHUNKSIZE) {
-+ if (cwaintmp->clicks > 501) {
-+ printk(KERN_INFO "cwain: not enough to receive (%d bytes)\n",len);
-+ }
-+ return 0;
-+ } else {
-+ *((unsigned int *) &cwaintmp->rxbuf[chan][0]) = cwain_indw(cwaintmp,cwain_A_FIFO_DATA0);
-+ *((unsigned int *) &cwaintmp->rxbuf[chan][4]) = cwain_indw(cwaintmp,cwain_A_FIFO_DATA0);
-+ }
-+
-+ zt_ec_chunk(&cwaintmp->span.chans[chan], cwaintmp->span.chans[chan].readchunk, cwaintmp->span.chans[chan].writechunk);
-+
-+ if (cwaintmp->clicks > 500) {
-+ printk(KERN_INFO "cwain: span %d dropped audio fifo %d mj %d\n", cwaintmp->cardID, fifo, mumbojumbo);
-+ cwaintmp->clicks = 0;
-+ }
-+// printk(KERN_INFO "s/t port %d, channel %d, dbufi=%d, f1=%d, f2=%d, z1=%d, z2=%d => len = %d stat=%#x, hdlc=%d\n",stport,chan,cwaintmp->st[stport].dbufi,f1,f2,z1,z2,len,stat,hdlc);
-+ return 0;
-+}
-+
-+void cwain_set_master(struct zt_cwain_card *cwaintmp, int span) {
-+ int i=0;
-+
-+ if (cwaintmp->syncsrc == span) return;
-+
-+ for (i=0; i < cwaintmp->spans; i++) {
-+ if (i != span) {
-+ if (cwaintmp->syncs[i] > 0) {
-+ /* enable PCM slave mode, PCM32, synced to E1 receive */
-+ cwain_outb(cwaintmp->span[i],cwain_R_PCM_MD0, 0x90);
-+ cwain_outb(cwaintmp->span[i],cwain_R_PCM_MD1, 0x0);
-+ cwain_outb(cwaintmp->span[span],cwain_R_PCM_MD0, 0xA0);
-+ cwain_outb(cwaintmp->span[i],cwain_R_PCM_MD2, 0x00);
-+ } else {
-+ /* enable PCM slave mode, PCM32 */
-+ cwain_outb(cwaintmp->span[i],cwain_R_PCM_MD0, 0x90);
-+ cwain_outb(cwaintmp->span[i],cwain_R_PCM_MD1, 0x0);
-+ cwain_outb(cwaintmp->span[span],cwain_R_PCM_MD0, 0xA0);
-+ cwain_outb(cwaintmp->span[i],cwain_R_PCM_MD2, 0x00);
-+ }
-+ cwaintmp->master[i] = 0;
-+ cwaintmp->span[i]->span.syncsrc = 0;
-+ }
-+ }
-+
-+ if (cwaintmp->syncs[span] > 0) {
-+ /* enable PCM master mode, PCM32, synced to E1 receive */
-+ if (debug)
-+ printk(KERN_INFO "cwain: cardID %d span %d, PCM master E1 sync\n", cwaintmp->cardID, span);
-+ cwain_outb(cwaintmp->span[span],cwain_R_PCM_MD0, 0x91);
-+ cwain_outb(cwaintmp->span[span],cwain_R_PCM_MD1, 0x0);
-+ cwain_outb(cwaintmp->span[span],cwain_R_PCM_MD0, 0xA1);
-+ cwain_outb(cwaintmp->span[span],cwain_R_PCM_MD2, 0x00);
-+ cwaintmp->span[span]->span.syncsrc = 1;
-+ } else {
-+ /* enable PCM master mode, PCM32, free running */
-+ if (debug)
-+ printk(KERN_INFO "cwain: cardID %d span %d, PCM master\n", cwaintmp->cardID, span);
-+ cwain_outb(cwaintmp->span[span],cwain_R_PCM_MD0, 0x91);
-+ cwain_outb(cwaintmp->span[span],cwain_R_PCM_MD1, 0x0);
-+ cwain_outb(cwaintmp->span[span],cwain_R_PCM_MD0, 0xA1);
-+ cwain_outb(cwaintmp->span[span],cwain_R_PCM_MD2, 0x04);
-+ cwaintmp->span[span]->span.syncsrc = 0;
-+ }
-+
-+ cwaintmp->master[span] = 1;
-+ cwaintmp->syncsrc = span;
-+}
-+
-+void cwain_check_timing(struct zt_cwain_card *cwaintmp) {
-+ int i=0;
-+ int bestsync = 42;
-+
-+ for (i=0; i < cwaintmp->spans; i++) {
-+ if ((cwaintmp->syncs[i] > 0) && ((cwaintmp->span[i]->sync_sta & 0x7) == 0x7)) {
-+ if (bestsync < cwaintmp->spans) {
-+ if (cwaintmp->syncs[i] < cwaintmp->syncs[bestsync]) {
-+ bestsync = i;
-+ }
-+ } else {
-+ bestsync = i;
-+ }
-+ }
-+ }
-+
-+ if (cwaintmp->syncsrc >= 0) {
-+ if (debug > 3)
-+ printk(KERN_INFO "cwain: bestsync %d cwaintmp->syncsrc %d\n", bestsync, cwaintmp->syncsrc);
-+
-+ if (bestsync == cwaintmp->syncsrc) {
-+ if (debug > 3)
-+ printk(KERN_INFO "cwain: already on best syncsrc %d\n", bestsync);
-+ return;
-+ }
-+
-+ /* if we have a better syncsrc */
-+ if (bestsync < cwaintmp->spans) {
-+ if (debug)
-+ printk(KERN_INFO "cwain: found better syncsrc %d\n", bestsync);
-+ cwain_set_master(cwaintmp, bestsync);
-+ return;
-+ }
-+ }
-+
-+ /* if reelection failed, find internal sync source */
-+ if (cwaintmp->syncsrc == -1) {
-+ /* no master yet */
-+ if (debug > 3)
-+ printk(KERN_INFO "cwain: no clocksource found cardID %d\n", cwaintmp->cardID);
-+ for (i=0; i < cwaintmp->spans; i++) {
-+ /* find the first internal source */
-+ if (debug > 3)
-+ printk(KERN_INFO "cwain: cwaintmp->syncs[%d] = %d\n", i, cwaintmp->syncs[i]);
-+ if (cwaintmp->syncs[i] == 0) {
-+ if (debug)
-+ printk(KERN_INFO "cwain: using internal clock of span %d\n", i);
-+ cwain_set_master(cwaintmp, i);
-+ return;
-+ }
-+ }
-+ }
-+
-+ /* if we have no internal sync source the only thing we can do is to enable any of the possible sync sources*/
-+ if (cwaintmp->syncsrc == -1) {
-+ /* find the first possible sync source with framing */
-+ for (i=0; i < cwaintmp->spans; i++) {
-+ if (cwaintmp->syncs[i] > 0) {
-+ if (debug)
-+ printk(KERN_INFO "cwain: desperately using clock of span %d\n", i);
-+ cwain_set_master(cwaintmp, i);
-+ break;
-+ }
-+ }
-+ }
-+}
-+
-+static inline void cwain_isr_run(struct zt_cwain *cwaintmp) {
-+ int fifo=0;
-+ if (cwaintmp->span.flags & ZT_FLAG_RUNNING) {
-+ /* oh zaptel! tell us what to transmit... */
-+ zt_transmit(&cwaintmp->span);
-+ /* B chans 1-15 mapped to fifos 0-14 */
-+ /* B chans 17-31 mapped to fifos 15-29 */
-+ for (fifo=0; fifo < 30; fifo++) {
-+ /* B xmit */
-+ cwain_fifo_tx(cwaintmp, fifo);
-+ }
-+ if (cwaintmp->sync) {
-+ cwain_dfifo_tx(cwaintmp);
-+ }
-+
-+ cwaintmp->chans[15].bytes2receive = 0;
-+ cwaintmp->chans[15].bytes2transmit = 0;
-+ cwaintmp->chans[15].eofrx = 0;
-+ cwaintmp->chans[15].eoftx = 0;
-+
-+ for (fifo=0; fifo < 30; fifo++) {
-+ /* B rx */
-+ cwain_fifo_rx(cwaintmp, fifo);
-+ }
-+
-+ /* d-chan data */
-+ if ((cwaintmp->drx > 0) && cwaintmp->sync){
-+ if (debug > 2)
-+ printk(KERN_CRIT "drx = %d\n", cwaintmp->drx);
-+ cwain_dfifo_rx(cwaintmp);
-+ }
-+ /* oh zaptel! thou shall receive! */
-+ zt_receive(&(cwaintmp->span));
-+ }
-+}
-+
-+void cwain_isr_sync(struct zt_cwain *cwainspan) {
-+ unsigned char sync_sta;
-+ unsigned char sync_ok = 0;
-+ unsigned char jatt_sta = 0;
-+
-+ if (!cwainspan->span.flags & ZT_FLAG_RUNNING) {
-+ return;
-+ }
-+
-+ sync_sta = cwain_inb(cwainspan, cwain_R_SYNC_STA);
-+
-+if ((!cwainspan->sync) || (sync_sta != cwainspan->sync_sta)) {
-+
-+ if (debug > 2)
-+ printk(KERN_CRIT "cwain: cardID %d R_SYNC_STA =%#x\n", cwainspan->cardID, sync_sta);
-+
-+ if (cwainspan->span.lineconfig & ZT_CONFIG_CRC4) {
-+ if ((sync_sta & 0x80) == 0x80) {
-+ /* reset MFA detection */
-+ cwain_outb(cwainspan ,cwain_R_RX_SL0_CFG1,0x41);
-+ } else if ((sync_sta & 0x27) == 0x27) {
-+ if ((cwainspan->sync_sta & 0x27) != 0x27) {
-+ /* sync achieved, restart JATT */
-+ if (debug)
-+ printk(KERN_INFO "cwain: %d starting jitter attenuator\n", cwainspan->cardID);
-+ cwain_outb(cwainspan, cwain_R_JATT_CFG,0x9c);
-+ }
-+ sync_ok = 0x27;
-+ } else {
-+ sync_ok = 0x00;
-+ }
-+ } else {
-+ if ((sync_sta & 0x07) == 0x07) {
-+ if ((cwainspan->sync_sta & 0x7) != 0x7) {
-+ /* sync achieved, restart JATT */
-+ if (debug)
-+ printk(KERN_INFO "cwain: %d starting jitter attenuator\n", cwainspan->cardID);
-+ cwain_outb(cwainspan, cwain_R_JATT_CFG,0x9c);
-+ }
-+ sync_ok = 0x07;
-+ } else {
-+ sync_ok = 0x00;
-+ }
-+ }
-+
-+ cwainspan->sync_sta = sync_sta;
-+
-+ jatt_sta = cwain_inb(cwainspan, cwain_R_JATT_STA);
-+ if ((jatt_sta & 0x60) != 0x60) {
-+ if (debug > 2)
-+ printk(KERN_INFO "cwain: %d jitter attenuator %#x\n", cwainspan->cardID, (jatt_sta & 0x60) >> 5);
-+ sync_ok = 0x00;
-+ } else if (!cwainspan->sync && sync_ok) {
-+ if (debug)
-+ printk(KERN_CRIT "cwain: %d jitter attenuator %#x ok!\n", cwainspan->cardID, (jatt_sta & 0x60) >> 5);
-+ }
-+
-+ if (sync_ok && (!cwainspan->sync)) {
-+ /* elastic buffer offsets */
-+ cwain_outb(cwainspan,cwain_R_RX_OFFS,0x06);
-+ cwain_outb(cwainspan,cwain_R_TX_OFFS,0x06);
-+
-+ if (debug > 2)
-+ printk(KERN_INFO "cwain: enabling D channel fifos\n");
-+ cwain_outb(cwainspan,cwain_R_FIFO,0x1F << 1);
-+ cwain_waitbusy(cwainspan);
-+ cwain_outb(cwainspan,cwain_A_CON_HDLC,0xd);
-+ cwain_outb(cwainspan,cwain_A_IRQ_MSK,0x1);
-+
-+ cwain_outb(cwainspan,cwain_R_FIFO,(0x1F << 1) | 1);
-+ cwain_waitbusy(cwainspan);
-+ cwain_outb(cwainspan,cwain_A_CON_HDLC,0xd);
-+ cwain_outb(cwainspan,cwain_A_IRQ_MSK,0x1);
-+ cwainspan->span.alarms = ZT_ALARM_NONE;
-+ zt_alarm_notify(&cwainspan->span);
-+ }
-+ if (!sync_ok && cwainspan->sync) {
-+ if (debug > 2)
-+ printk(KERN_INFO "cwain: disabling D channel fifos\n");
-+ cwain_outb(cwainspan,cwain_R_FIFO,0x1F << 1);
-+ cwain_waitbusy(cwainspan);
-+ cwain_outb(cwainspan,cwain_A_CON_HDLC,0x1);
-+ cwain_outb(cwainspan,cwain_A_IRQ_MSK,0x0);
-+ cwain_outb(cwainspan,cwain_R_FIFO,(0x1F << 1) | 1);
-+ cwain_waitbusy(cwainspan);
-+ cwain_outb(cwainspan,cwain_A_CON_HDLC,0x1);
-+ cwain_outb(cwainspan,cwain_A_IRQ_MSK,0x0);
-+ cwainspan->span.alarms = ZT_ALARM_RED;
-+ zt_alarm_notify(&cwainspan->span);
-+ }
-+
-+ cwainspan->sync = sync_ok;
-+ if (sync_ok) {
-+ switch (cwainspan->type) {
-+ case 0xb553:
-+ sprintf(cwainspan->span.desc,"Junghanns.NET singleE1 PCI ISDN Card %d (cardID %d) SYNCED",cwainspan->cardno,cwainspan->cardID);
-+ break;
-+ case 0xb554:
-+ sprintf(cwainspan->span.desc,"Junghanns.NET doubleE1 PCI ISDN Card %d (cardID %d) (1 E1 port) SYNCED",cwainspan->cardno,cwainspan->cardID);
-+ break;
-+ }
-+ } else {
-+ switch (cwainspan->type) {
-+ case 0xb553:
-+ sprintf(cwainspan->span.desc,"Junghanns.NET singleE1 PCI ISDN Card %d (cardID %d) NO SYNC (sync_sta = %#x)",cwainspan->cardno,cwainspan->cardID, sync_sta);
-+ break;
-+ case 0xb554:
-+ sprintf(cwainspan->span.desc,"Junghanns.NET doubleE1 PCI ISDN Card %d (cardID %d) (1 E1 port) NO SYNC (sync_sta = %#x)",cwainspan->cardno,cwainspan->cardID, sync_sta);
-+ break;
-+ }
-+ }
-+ cwain_doLEDs(cwainspan);
-+}
-+}
-+
-+int cwain_isr_fifo(struct zt_cwain *cwainspan, unsigned char status) {
-+ unsigned char irq_foview,fi;
-+
-+ if (status & 0x80) {
-+ /* fifo irq */
-+ irq_foview = cwain_inb(cwainspan,cwain_R_IRQ_OVIEW);
-+ if (irq_foview & 0x80) {
-+ fi = cwain_inb(cwainspan,cwain_R_IRQ_FIFO_BL7);
-+ if (fi & 0x80) {
-+ if (debug > 2)
-+ printk(KERN_CRIT "cwain: fifo 31 RX irq for D channel\n");
-+ cwainspan->drx += 1;
-+ }
-+ }
-+ return 1;
-+ }
-+ return 0;
-+}
-+
-+#ifdef LINUX26
-+static irqreturn_t cwain_interrupt(int irq, void *dev_id, struct pt_regs *regs) {
-+#else
-+static void cwain_interrupt(int irq, void *dev_id, struct pt_regs *regs) {
-+#endif
-+ struct zt_cwain_card *cwaintmp = dev_id;
-+ unsigned char status, status2, status_tmp, irq_misc, irq_misc2;
-+ unsigned long flags;
-+ int i = 0;
-+ int l1event = 0;
-+
-+ if (!cwaintmp || cwaintmp->dead) {
-+#ifdef LINUX26
-+ return IRQ_NONE;
-+#else
-+ return;
-+#endif
-+ }
-+
-+
-+ spin_lock_irqsave(&(cwaintmp->lock),flags);
-+ status = cwain_inb(cwaintmp->span[0],cwain_R_STATUS);
-+
-+ status2 = 0;
-+
-+ for (i=0;i<cwaintmp->spans;i++) {
-+ if (i == 0) {
-+ status_tmp = status;
-+ } else {
-+ status_tmp = cwain_inb(cwaintmp->span[i],cwain_R_STATUS);
-+ status2 = status_tmp;
-+ }
-+ cwain_isr_fifo(cwaintmp->span[i], status_tmp);
-+ }
-+
-+ if (!(status & 0x80) && !(status & 0x40)) {
-+ // it's not us!
-+ spin_unlock_irqrestore(&(cwaintmp->lock),flags);
-+#ifdef LINUX26
-+ return IRQ_NONE;
-+#else
-+ return;
-+#endif
-+ }
-+
-+ // misc irq
-+ if (status & 0x40) {
-+ irq_misc = cwain_inb(cwaintmp->span[0],cwain_R_IRQ_MISC);
-+ if (irq_misc & 0x2) {
-+ /* cwain timer */
-+ cwaintmp->ticks++;
-+ for (i=0;i<cwaintmp->spans;i++) {
-+ cwain_isr_run(cwaintmp->span[i]);
-+ }
-+ if (cwaintmp->ticks == 500) {
-+ cwaintmp->ticks = 0;
-+ }
-+ }
-+ if (irq_misc & 0x1) {
-+ /* state machine */
-+ if (debug > 4)
-+ printk(KERN_INFO "cwain: state machine irq\n");
-+ l1event++;
-+ }
-+ if (irq_misc & 0x10) {
-+ for (i=0;i<cwaintmp->spans;i++) {
-+ cwain_isr_sync(cwaintmp->span[i]);
-+ }
-+ }
-+ }
-+
-+ // misc irq
-+ if (status2 & 0x40) {
-+ if (cwaintmp->spans == 2) {
-+ irq_misc2 = cwain_inb(cwaintmp->span[1],cwain_R_IRQ_MISC);
-+ }
-+ if (irq_misc2 & 0x1) {
-+ /* state machine 2 */
-+ if (debug > 4)
-+ printk(KERN_INFO "cwain: state machine 2 irq\n");
-+ l1event++;
-+ }
-+ }
-+
-+ if (l1event > 0) {
-+// printk(KERN_INFO "cwain: l1event %d\n", l1event);
-+ if (cwaintmp->spans == 2) {
-+ cwain_check_timing(cwaintmp);
-+ }
-+ for (i=0;i<cwaintmp->spans;i++) {
-+ cwain_isr_sync(cwaintmp->span[i]);
-+ }
-+ }
-+
-+ spin_unlock_irqrestore(&(cwaintmp->lock),flags);
-+#ifdef LINUX26
-+ return IRQ_RETVAL(1);
-+#endif
-+}
-+
-+static int ztcwain_open(struct zt_chan *chan) {
-+// printk(KERN_INFO "cwain: channel %d opened.\n",chan->channo);
-+#ifndef LINUX26
-+ MOD_INC_USE_COUNT;
-+#else
-+ try_module_get(THIS_MODULE);
-+#endif
-+ return 0;
-+}
-+
-+static int ztcwain_close(struct zt_chan *chan) {
-+// printk(KERN_INFO "cwain: channel %d closed.\n",chan->channo);
-+#ifndef LINUX26
-+ MOD_DEC_USE_COUNT;
-+#else
-+ module_put(THIS_MODULE);
-+#endif
-+ return 0;
-+}
-+
-+static int ztcwain_rbsbits(struct zt_chan *chan, int bits) {
-+ return 0;
-+}
-+
-+static int ztcwain_ioctl(struct zt_chan *chan, unsigned int cmd, unsigned long data) {
-+ switch(cmd) {
-+ default:
-+ return -ENOTTY;
-+ }
-+ return 0;
-+}
-+
-+static int ztcwain_startup(struct zt_span *span) {
-+ struct zt_cwain_card *cwaincard = span->pvt;
-+ struct zt_cwain *cwaintmp;
-+ unsigned long flags;
-+ int alreadyrunning;
-+ int i=0;
-+
-+// printk(KERN_INFO "cwain: startup spanno %d offset %d\n", span->spanno, span->offset);
-+
-+ if (cwaincard == NULL) {
-+ printk(KERN_CRIT "cwain: cwaincard == NULL!\n");
-+ return 0;
-+ }
-+
-+ cwaintmp = cwaincard->span[span->offset];
-+ if (cwaintmp == NULL) {
-+ printk(KERN_CRIT "cwain: cwaintmp == NULL!\n");
-+ return 0;
-+ }
-+
-+
-+ alreadyrunning = span->flags & ZT_FLAG_RUNNING;
-+// printk(KERN_CRIT "already running %d flags %d\n", alreadyrunning, span->flags);
-+
-+ if (!alreadyrunning) {
-+ span->chans[15].flags &= ~ZT_FLAG_HDLC;
-+ span->chans[15].flags |= ZT_FLAG_BRIDCHAN; /* yes! */
-+
-+ /* setup B channel buffers (8 bytes each) */
-+ for (i=0; i<15 ; i++) {
-+ memset(cwaintmp->rxbuf[i],0x0,sizeof(cwaintmp->rxbuf[i]));
-+ memset(cwaintmp->txbuf[i],0x0,sizeof(cwaintmp->txbuf[i]));
-+
-+ span->chans[i].readchunk = cwaintmp->rxbuf[i];
-+ span->chans[i].writechunk = cwaintmp->txbuf[i];
-+ }
-+ for (i=16; i<31 ; i++) {
-+ memset(cwaintmp->rxbuf[i-1],0x0,sizeof(cwaintmp->rxbuf[i-1]));
-+ memset(cwaintmp->txbuf[i-1],0x0,sizeof(cwaintmp->txbuf[i-1]));
-+ span->chans[i].readchunk = cwaintmp->rxbuf[i-1];
-+ span->chans[i].writechunk = cwaintmp->txbuf[i-1];
-+ }
-+ /* setup D channel buffer */
-+ memset(cwaintmp->dtxbuf,0x0,sizeof(cwaintmp->dtxbuf));
-+ span->chans[15].writechunk = cwaintmp->dtxbuf;
-+ cwaintmp->chans[15].maxbytes2transmit = sizeof(cwaintmp->dtxbuf);
-+
-+ memset(cwaintmp->drxbuf,0x0,sizeof(cwaintmp->drxbuf));
-+ span->chans[15].readchunk = cwaintmp->drxbuf;
-+
-+ span->flags |= ZT_FLAG_RUNNING;
-+ } else {
-+ printk(KERN_CRIT "already running\n");
-+ return 0;
-+ }
-+
-+ spin_lock_irqsave(&cwaintmp->lock,flags);
-+ // irqs off
-+ cwain_outb(cwaintmp,cwain_R_IRQ_CTRL, 0);
-+
-+ /* setup D-FIFO TX */
-+ cwain_outb(cwaintmp,cwain_R_FIFO,0x1F << 1);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_R_INC_RES_FIFO,0x2);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_A_CON_HDLC,0x1);
-+ cwain_outb(cwaintmp,cwain_A_SUBCH_CFG,0x0);
-+ cwain_outb(cwaintmp,cwain_A_CHANNEL,0x10 << 1);
-+ cwain_outb(cwaintmp,cwain_A_IRQ_MSK,0x0);
-+
-+ /* setup D-FIFO RX */
-+ cwain_outb(cwaintmp,cwain_R_FIFO,(0x1F << 1) | 1);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_R_INC_RES_FIFO,0x2);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_A_CON_HDLC,0x1);
-+ cwain_outb(cwaintmp,cwain_A_SUBCH_CFG,0x0);
-+ cwain_outb(cwaintmp,cwain_A_CHANNEL,(0x10 << 1) | 1);
-+ cwain_outb(cwaintmp,cwain_A_IRQ_MSK,0x0);
-+
-+ /* setup B-FIFOs TX */
-+ /* map ts 1 to 15 to fifos 0 to 14 */
-+ for (i=1; i<16 ; i++) {
-+ cwain_outb(cwaintmp,cwain_R_FIFO,(i - 1) << 1);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_R_INC_RES_FIFO,0x2);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_A_CON_HDLC,0x2);
-+ cwain_outb(cwaintmp,cwain_A_CHANNEL,i << 1);
-+ cwain_outb(cwaintmp,cwain_A_IRQ_MSK,0x1);
-+ }
-+ /* map ts 17 to 31 to fifos 15 to 29 */
-+ for (i=17; i<32 ; i++) {
-+ cwain_outb(cwaintmp,cwain_R_FIFO,(i - 2) << 1);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_R_INC_RES_FIFO,0x2);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_A_CON_HDLC,0x2);
-+ cwain_outb(cwaintmp,cwain_A_CHANNEL,i << 1);
-+ cwain_outb(cwaintmp,cwain_A_IRQ_MSK,0x1);
-+ }
-+
-+ /* setup B-FIFOs RX */
-+ /* map ts 1 to 15 to fifos 0 to 14 */
-+ for (i=1; i<16 ; i++) {
-+ cwain_outb(cwaintmp,cwain_R_FIFO,((i-1) << 1) | 1);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_R_INC_RES_FIFO,0x2);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_A_CON_HDLC,0x2);
-+ cwain_outb(cwaintmp,cwain_A_CHANNEL,(i << 1) | 1);
-+ cwain_outb(cwaintmp,cwain_A_IRQ_MSK,0x1);
-+ }
-+ /* map ts 17 to 31 to fifos 15 to 29 */
-+ for (i=17; i<32 ; i++) {
-+ cwain_outb(cwaintmp,cwain_R_FIFO,((i-2) << 1) | 1);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_R_INC_RES_FIFO,0x2);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_A_CON_HDLC,0x2);
-+ cwain_outb(cwaintmp,cwain_A_CHANNEL,(i << 1) | 1);
-+ cwain_outb(cwaintmp,cwain_A_IRQ_MSK,0x1);
-+ }
-+
-+ if (debug)
-+ printk(KERN_INFO "cwain: starting card %d span %d/%d.\n",cwaintmp->cardno,span->spanno,span->offset);
-+
-+ if (cwaincard->spans == 1) {
-+ cwain_set_master(cwaincard, 0);
-+ }
-+
-+ /* setup E1 amplitude */
-+ cwain_outb(cwaintmp,cwain_R_PWM_MD,0x20);
-+ cwain_outb(cwaintmp,cwain_R_PWM0,0x50);
-+ cwain_outb(cwaintmp,cwain_R_PWM1,0xff);
-+
-+ /* setup E1 transceiver */
-+ cwain_outb(cwaintmp,cwain_R_TX_SL0,0xf8); // R_TX_FR1
-+ cwain_outb(cwaintmp,cwain_R_TX_SL0_CFG0,0x00); /* semiautomatic mode */
-+
-+ cwain_outb(cwaintmp,cwain_R_RX_SL0_CFG0,0x6); /* 0x26 */
-+
-+ if (cwaintmp->span.lineconfig & ZT_CONFIG_AMI) {
-+ cwain_outb(cwaintmp,cwain_R_TX0,0x82);
-+ cwain_outb(cwaintmp,cwain_R_RX0,0x02);
-+ } else if (cwaintmp->span.lineconfig & ZT_CONFIG_HDB3) {
-+ cwain_outb(cwaintmp,cwain_R_TX0,0x81);
-+ cwain_outb(cwaintmp,cwain_R_RX0,0x01);
-+ }
-+
-+ /* transmitter mode */
-+ cwain_outb(cwaintmp,cwain_R_TX1,0x60);
-+
-+ cwain_outb(cwaintmp,cwain_R_LOS0,0x10);
-+ cwain_outb(cwaintmp,cwain_R_LOS1,0x10);
-+
-+ if (cwaintmp->span.lineconfig & ZT_CONFIG_CRC4) {
-+ /* crc4 multiframe */
-+ cwain_outb(cwaintmp,cwain_R_TX_SL0_CFG1,0x31);
-+// cwain_outb(cwaintmp,cwain_R_RX_SL0_CFG1,0x41);
-+ cwain_outb(cwaintmp,cwain_R_RX_SL0_CFG1,0x03);
-+ } else {
-+ /* doubleframe */
-+ cwain_outb(cwaintmp,cwain_R_TX_SL0_CFG1,0x0);
-+// cwain_outb(cwaintmp,cwain_R_RX_SL0_CFG1,0x40);
-+ cwain_outb(cwaintmp,cwain_R_RX_SL0_CFG1,0x02);
-+ }
-+
-+
-+ /* setup sync mode */
-+ if (cwaincard->syncs[span->offset] > 0) {
-+ cwain_outb(cwaintmp,cwain_R_SYNC_CTRL,0x2);
-+ cwain_outb(cwaintmp,cwain_R_SYNC_OUT,0x1);
-+ /* layer 1, here we go! */
-+ cwain_outb(cwaintmp,cwain_R_E1_WR_STA,0x00);
-+ } else {
-+// cwain_outb(cwaintmp,cwain_R_SYNC_CTRL,0x5);
-+ cwain_outb(cwaintmp,cwain_R_SYNC_CTRL,0x7);
-+ cwain_outb(cwaintmp,cwain_R_SYNC_OUT,0x0);
-+ /* layer 1, up! */
-+ cwain_outb(cwaintmp,cwain_R_E1_WR_STA,0x11);
-+ }
-+
-+ cwaintmp->sync = 0;
-+ cwaintmp->sync_sta = 0;
-+
-+ /* enable irqs */
-+ cwain_outb(cwaintmp,cwain_R_IRQ_CTRL, 8 | 1);
-+ spin_unlock_irqrestore(&cwaintmp->lock,flags);
-+
-+ return 0;
-+}
-+
-+static int ztcwain_shutdown(struct zt_span *span) {
-+ struct zt_cwain_card *cwaincard = span->pvt;
-+ struct zt_cwain *cwaintmp;
-+ unsigned long flags;
-+ int alreadyrunning;
-+ int i=0;
-+
-+ if (cwaincard == NULL) {
-+ printk(KERN_CRIT "cwain: cwaincard == NULL!\n");
-+ return 0;
-+ }
-+
-+ cwaintmp = cwaincard->span[span->offset];
-+ if (cwaintmp == NULL) {
-+ printk(KERN_CRIT "cwain: cwaintmp == NULL!\n");
-+ return 0;
-+ }
-+
-+ alreadyrunning = span->flags & ZT_FLAG_RUNNING;
-+
-+ if (!alreadyrunning) {
-+ return 0;
-+ }
-+ spin_lock_irqsave(&cwaintmp->lock,flags);
-+
-+// printk(KERN_CRIT "cwain: stopping card %d span %d/%d.\n",cwaintmp->cardno,span->spanno,span->offset);
-+
-+ // turn off irqs for all fifos
-+
-+ /* disable FIFO TX */
-+ for (i=0; i<0x20 ; i++) {
-+ cwain_outb(cwaintmp,cwain_R_FIFO,i << 1);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_A_IRQ_MSK,0x0);
-+ }
-+
-+ /* disable FIFO RX */
-+ for (i=0; i<0x20 ; i++) {
-+ cwain_outb(cwaintmp,cwain_R_FIFO,(i << 1) | 1);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_A_IRQ_MSK,0x0);
-+ }
-+
-+
-+ /* Deactivate Layer 1 */
-+ cwain_outb(cwaintmp,cwain_R_E1_WR_STA,0x10);
-+
-+ cwain_outb(cwaintmp,cwain_R_IRQ_CTRL, 0);
-+// cwain_outb(cwaintmp,cwain_R_IRQMSK_MISC, 0);
-+ cwain_inb(cwaintmp,cwain_R_STATUS);
-+
-+
-+ span->flags &= ~ZT_FLAG_RUNNING;
-+
-+
-+ spin_unlock_irqrestore(&cwaintmp->lock,flags);
-+
-+// printk(KERN_CRIT "cwain: card %d span %d/%d down.\n",cwaintmp->cardno,span->spanno,span->offset);
-+ return 0;
-+}
-+
-+static int ztcwain_maint(struct zt_span *span, int cmd) {
-+ return 0;
-+}
-+
-+static int ztcwain_chanconfig(struct zt_chan *chan,int sigtype) {
-+// printk(KERN_INFO "chan_config sigtype=%d\n", sigtype);
-+ return 0;
-+}
-+
-+static int ztcwain_spanconfig(struct zt_span *span,struct zt_lineconfig *lc) {
-+ struct zt_cwain_card *cwaincard = span->pvt;
-+ span->lineconfig = lc->lineconfig;
-+ span->syncsrc = lc->sync;
-+
-+ cwaincard->syncs[span->offset] = lc->sync;
-+ cwaincard->syncsrc = -1;
-+// printk(KERN_INFO "span_config %d lineconfig=%d syncsrc=%d\n", span->spanno, lc->lineconfig, lc->sync);
-+// cwain_check_timing(cwaincard);
-+ return 0;
-+}
-+
-+static int ztcwain_initialize(struct zt_cwain *cwaintmp, struct zt_cwain_card *cwaincard, int offset) {
-+ int i=0;
-+
-+ memset(&cwaintmp->span,0,sizeof(struct zt_span)); // you never can tell...
-+ sprintf(cwaintmp->span.name,"cwain/%d",cwaintmp->cardno);
-+ switch (cwaintmp->type) {
-+ case 0xb553:
-+ sprintf(cwaintmp->span.desc,"Junghanns.NET singleE1 PCI ISDN Card %d (cardID %d)",cwaintmp->cardno,cwaintmp->cardID);
-+ break;
-+ case 0xb554:
-+ sprintf(cwaintmp->span.desc,"Junghanns.NET doubleE1 PCI ISDN Card %d (cardID %d) (1 E1 port)",cwaintmp->cardno,cwaintmp->cardID);
-+ break;
-+ default:
-+ return -1;
-+ }
-+ cwaintmp->span.spanconfig = ztcwain_spanconfig;
-+ cwaintmp->span.chanconfig = ztcwain_chanconfig;
-+ cwaintmp->span.startup = ztcwain_startup;
-+ cwaintmp->span.shutdown = ztcwain_shutdown;
-+ cwaintmp->span.maint = ztcwain_maint;
-+ cwaintmp->span.rbsbits = ztcwain_rbsbits;
-+ cwaintmp->span.open = ztcwain_open;
-+ cwaintmp->span.close = ztcwain_close;
-+ cwaintmp->span.ioctl = ztcwain_ioctl;
-+
-+ cwaintmp->span.chans = cwaintmp->chans;
-+ cwaintmp->span.channels = 31;
-+ cwaintmp->span.deflaw = ZT_LAW_ALAW;
-+ cwaintmp->span.linecompat = ZT_CONFIG_AMI | ZT_CONFIG_HDB3 | ZT_CONFIG_CCS;
-+ init_waitqueue_head(&cwaintmp->span.maintq);
-+ cwaintmp->span.pvt = cwaincard;
-+ cwaintmp->span.offset = offset;
-+
-+ for (i=0; i < cwaintmp->span.channels; i++) {
-+ memset(&(cwaintmp->chans[i]),0x0,sizeof(struct zt_chan));
-+ sprintf(cwaintmp->chans[i].name,"cwain%d/%d",cwain_span_count + 1,i + 1);
-+ cwaintmp->chans[i].pvt = cwaintmp;
-+ cwaintmp->chans[i].sigcap = ZT_SIG_CLEAR;
-+ cwaintmp->chans[i].chanpos = i + 1;
-+ }
-+
-+ if (zt_register(&cwaintmp->span,0)) {
-+ printk(KERN_INFO "cwain: unable to register zaptel span!\n");
-+ return -1;
-+ }
-+// printk(KERN_INFO "cwain: registered zaptel span %d.\n",s+1);
-+
-+ return 0;
-+}
-+
-+int cwain_reset_card(struct zt_cwain_card *cwaintmp) {
-+ unsigned long flags;
-+ int i = 0;
-+
-+ cwaintmp->irq = cwaintmp->span[0]->irq;
-+
-+ if (cwaintmp->spans == 2) {
-+ if (request_irq(cwaintmp->irq, cwain_interrupt, SA_INTERRUPT | SA_SHIRQ, "cwain2", cwaintmp)) {
-+ printk(KERN_WARNING "cwain: unable to register irq\n");
-+ return -1;
-+ }
-+ } else {
-+ if (request_irq(cwaintmp->irq, cwain_interrupt, SA_INTERRUPT | SA_SHIRQ, "cwain", cwaintmp)) {
-+ printk(KERN_WARNING "cwain: unable to register irq\n");
-+ return -1;
-+ }
-+ }
-+
-+ spin_lock_irqsave(&(cwaintmp->lock),flags);
-+
-+ for (i=0;i<cwaintmp->spans;i++) {
-+ cwain_reset_span(cwaintmp->span[i]);
-+ }
-+
-+ /* no master yet, force reelection */
-+ cwaintmp->syncsrc = -1;
-+
-+ /* set up the timer 1 khz, zaptel timing */
-+ cwain_outb(cwaintmp->span[0],cwain_R_TI_WD, 0x2);
-+
-+ if (cwaintmp->spans == 2) {
-+ cwain_outb(cwaintmp->span[1],cwain_R_IRQMSK_MISC, 0x1);
-+ }
-+ /* enable timer interrupts */
-+ cwain_outb(cwaintmp->span[0],cwain_R_IRQMSK_MISC, 0x13);
-+
-+ /* Finally enable IRQ output */
-+ cwain_outb(cwaintmp->span[0],cwain_R_IRQ_CTRL, 0x8 | 0x1);
-+
-+ spin_unlock_irqrestore(&(cwaintmp->lock),flags);
-+ return 0;
-+}
-+
-+int cwain_find_spans(unsigned int pcidid) {
-+ struct pci_dev *tmp;
-+ struct zt_cwain *cwaintmp = NULL;
-+ int i=0;
-+ unsigned char dips=0;
-+ int cid=0;
-+ int modes=0;
-+ tmp = pci_find_device(PCI_VENDOR_ID_CCD,pcidid,multi_cwain);
-+ while (tmp != NULL) {
-+ multi_cwain = tmp; // skip this next time.
-+
-+ if (pci_enable_device(tmp)) {
-+ multi_cwain = NULL;
-+ return -1;
-+ }
-+
-+ cwaintmp = kmalloc(sizeof(struct zt_cwain),GFP_KERNEL);
-+ if (!cwaintmp) {
-+ printk(KERN_WARNING "cwain: unable to kmalloc!\n");
-+ pci_disable_device(tmp);
-+ multi_cwain = NULL;
-+ return -ENOMEM;
-+ }
-+ memset(cwaintmp, 0x0, sizeof(struct zt_cwain));
-+
-+ spin_lock_init(&cwaintmp->lock);
-+ cwaintmp->pcidev = tmp;
-+ cwaintmp->pcibus = tmp->bus->number;
-+ cwaintmp->pcidevfn = tmp->devfn;
-+
-+
-+ cwaintmp->pci_io = (char *) tmp->resource[1].start;
-+ if (!cwaintmp->pci_io) {
-+ printk(KERN_WARNING "cwain: no iomem!\n");
-+ pci_disable_device(tmp);
-+ multi_cwain = NULL;
-+ return -EIO;
-+ }
-+
-+ if (!tmp->irq) {
-+ printk(KERN_WARNING "cwain: PCI device has no irq!\n");
-+ pci_disable_device(tmp);
-+ multi_cwain = NULL;
-+ return -EIO;
-+ }
-+
-+ cwaintmp->irq = tmp->irq;
-+
-+ cwaintmp->pci_io = ioremap((ulong) cwaintmp->pci_io, 256);
-+
-+ /* enable memio */
-+ pci_write_config_word(cwaintmp->pcidev, PCI_COMMAND, PCI_COMMAND_MEMORY);
-+
-+ /* disable interrupts */
-+ cwain_outb(cwaintmp,cwain_R_IRQ_CTRL, 0);
-+
-+ if (((tmp->subsystem_device==0xb553) || (tmp->subsystem_device==0xb554))&& (pcidid == PCI_DEVICE_ID_CCD_E)) {
-+ dips = (cwain_inb(cwaintmp,cwain_R_GPI_IN0) >> 5);
-+ cid = 7;
-+ for (i=0;i<3;i++) {
-+ if ((dips & (1 << i)) != 0) {
-+ cid -= (1 << (2-i));
-+ }
-+ }
-+// printk(KERN_INFO "DIPS = %#x CID= %#x\n",dips,cid);
-+ } else {
-+ cid = 0xff;
-+ }
-+
-+ if (ports == -1) {
-+ if ((tmp->subsystem_device==0xb520) && (pcidid == PCI_DEVICE_ID_CCD_E)) {
-+ modes = (cwain_inb(cwaintmp,cwain_R_GPI_IN0) >> 4) & 0x01;
-+ } else {
-+ modes = 0; // assume TE mode
-+ }
-+ } else {
-+ modes = ports >> cwain_span_count;
-+ }
-+
-+
-+ cwaintmp->cardID = cid;
-+ cwaintmp->type = tmp->subsystem_device;
-+
-+ if ((modes & 1) != 0) {
-+ cwaintmp->nt_mode = 1;
-+ } else {
-+ cwaintmp->nt_mode = 0;
-+ }
-+
-+ cwain_register_span(cwaintmp);
-+
-+ tmp = pci_find_device(PCI_VENDOR_ID_CCD,pcidid,multi_cwain);
-+ }
-+ return 0;
-+}
-+
-+
-+int cwain_sort_cards(void) {
-+ int changed=0,tmpcardno;
-+ struct zt_cwain_card *tmpcard,*tmpcard2;
-+ spin_lock(&cwain_card_registerlock);
-+ do {
-+ changed = 0;
-+ tmpcard = cwain_card_list;
-+ while (tmpcard != NULL) {
-+ if (tmpcard->prev) {
-+ if (tmpcard->prev->cardID > tmpcard->cardID) {
-+ tmpcardno = tmpcard->prev->cardno;
-+ tmpcard->prev->cardno = tmpcard->cardno;
-+ tmpcard->cardno = tmpcardno;
-+
-+ tmpcard2 = tmpcard->prev;
-+ if (tmpcard2->prev) {
-+ tmpcard2->prev->next = tmpcard;
-+ } else {
-+ cwain_card_list = tmpcard;
-+ }
-+ if (tmpcard->next) {
-+ tmpcard->next->prev = tmpcard2;
-+ }
-+ tmpcard2->next = tmpcard->next;
-+ tmpcard->prev = tmpcard2->prev;
-+ tmpcard->next = tmpcard2;
-+ tmpcard2->prev = tmpcard;
-+ changed = 1;
-+ tmpcard = tmpcard2;
-+ }
-+ }
-+ tmpcard = tmpcard->next;
-+ }
-+ } while (changed == 1);
-+ spin_unlock(&cwain_card_registerlock);
-+ return 0;
-+}
-+
-+int cwain_zap_cards(void) {
-+ struct zt_cwain_card *tmpcard = cwain_card_list;
-+ int i=0;
-+ int res=0;
-+ while (tmpcard != NULL) {
-+ for (i=0; i<tmpcard->spans; i++) {
-+ ztcwain_initialize(tmpcard->span[i], tmpcard, i);
-+ }
-+ res = cwain_reset_card(tmpcard);
-+ tmpcard = tmpcard->next;
-+ }
-+ return res;
-+}
-+
-+
-+int init_module(void) {
-+ multi_cwain = NULL;
-+ cwain_find_spans(PCI_DEVICE_ID_CCD_E);
-+ cwain_sort_cards();
-+ cwain_zap_cards();
-+ if (cwain_card_count == 0) {
-+ printk(KERN_INFO "cwain: no cwain cards found.\n");
-+ } else {
-+ printk(KERN_INFO "cwain: %d cwain card(s) in this box, %d E1 ports total.\n", cwain_card_count, cwain_span_count);
-+ }
-+ return 0;
-+}
-+
-+void cleanup_module(void) {
-+ struct zt_cwain_card *tmpcard,*tmplist;
-+ struct zt_cwain *tmpspan,*spanlist;
-+ int i=0;
-+ int j=0;
-+
-+ tmplist = cwain_card_list;
-+ tmpcard = NULL;
-+ while (tmplist) {
-+ tmpcard = tmplist;
-+ tmplist = tmplist->next;
-+
-+ tmpcard->dead = 1;
-+ cwain_shutdown_card(tmpcard);
-+ kfree(tmpcard);
-+ i++;
-+ }
-+
-+ spanlist = cwain_span_list;
-+ tmpspan = NULL;
-+ while (spanlist) {
-+ tmpspan = spanlist;
-+ spanlist = spanlist->next;
-+ kfree(tmpspan);
-+ j++;
-+ }
-+ printk(KERN_INFO "cwain: shutdown %d spans, %d cwain cards.\n", j, i);
-+}
-+#endif
-+
-+MODULE_PARM(ports,"i");
-+MODULE_PARM(debug,"i");
-+MODULE_DESCRIPTION("cwain zaptel driver");
-+MODULE_AUTHOR("Klaus-Peter Junghanns <kpj at junghanns.net>");
-+#ifdef MODULE_LICENSE
-+MODULE_LICENSE("GPL");
-+#endif
-diff -urNad zaptel-1.2.1/cwain/cwain.h /tmp/dpep.RTh8jH/zaptel-1.2.1/cwain/cwain.h
---- zaptel-1.2.1/cwain/cwain.h 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.RTh8jH/zaptel-1.2.1/cwain/cwain.h 2005-09-26 09:59:05.000000000 +0300
-@@ -0,0 +1,238 @@
-+#define cwain_FIFO_SIZE 128
-+#define cwain_DFIFO_SIZE 4096
-+#define cwain_FIFO_HW 13
-+
-+typedef struct zt_cwain {
-+ /* pci resources */
-+ unsigned int irq;
-+ unsigned int iomem;
-+ unsigned char *pci_io;
-+ unsigned int pcibus;
-+ unsigned int pcidevfn;
-+ struct pci_dev *pcidev;
-+ unsigned int type;
-+
-+ /* lock to protect the structure */
-+ spinlock_t lock;
-+ int cardID;
-+ unsigned char cardno;
-+
-+ /* ticks and clicks, fish and chips */
-+ unsigned int ticks;
-+ unsigned int clicks;
-+ unsigned char nt_mode;
-+ unsigned char sync_sta;
-+ unsigned char sync;
-+ int syncmode;
-+
-+ /* blinky blink */
-+ unsigned char leds[4];
-+
-+ /* B chan buffers */
-+ unsigned char rxbuf[30][ZT_CHUNKSIZE];
-+ unsigned char txbuf[30][ZT_CHUNKSIZE];
-+
-+ /* number of RXed dchan frames */
-+ unsigned char drx;
-+ /* D chan buffer */
-+ unsigned char drxbuf[cwain_DFIFO_SIZE];
-+ unsigned char dtxbuf[cwain_DFIFO_SIZE];
-+
-+
-+ /* zaptel resources */
-+ struct zt_span span;
-+ struct zt_chan chans[31];
-+
-+ /* more zaptel stuff */
-+ unsigned int usecount;
-+ int spantype;
-+ int spanflags;
-+
-+ /* linked list */
-+ struct zt_cwain *next;
-+ struct zt_cwain *prev;
-+
-+} zt_cwain;
-+
-+typedef struct zt_cwain_card {
-+ /* lock to protect the structure */
-+ spinlock_t lock;
-+
-+ unsigned int spans;
-+ unsigned int dead;
-+ int cardID;
-+ unsigned char cardno;
-+ unsigned int ticks;
-+
-+ struct zt_cwain *span[2];
-+ int syncsrc;
-+ int syncs[2];
-+ int master[2];
-+
-+ unsigned int irq;
-+ unsigned int pcibus;
-+
-+ /* linked list */
-+ struct zt_cwain_card *next;
-+ struct zt_cwain_card *prev;
-+} zt_cwain_card;
-+
-+#define cwain_outb(a,b,c) (writeb((c),(a)->pci_io+(b)))
-+#define cwain_inb(a,b) (readb((a)->pci_io+(b)))
-+
-+#define cwain_outw(a,b,c) (writew((c),(a)->pci_io+(b)))
-+#define cwain_inw(a,b) (readw((a)->pci_io+(b)))
-+
-+#define cwain_outdw(a,b,c) (writel((c),(a)->pci_io+(b)))
-+#define cwain_indw(a,b) (readl((a)->pci_io+(b)))
-+
-+
-+/* Write only registers */
-+#define cwain_A_CH_MSK 0xF4
-+#define cwain_A_CHANNEL 0xFC
-+#define cwain_A_CON_HDLC 0xFA
-+#define cwain_A_CONF 0xD1
-+#define cwain_A_FIFO_SEQ 0xFD
-+#define cwain_R_INC_RES_FIFO 0x0E
-+#define cwain_A_IRQ_MSK 0xFF
-+#define cwain_A_SL_CFG 0xD0
-+#define cwain_A_SUBCH_CFG 0xFB
-+#define cwain_R_BERT_WD_MD 0x1B
-+#define cwain_R_BRG_PCM_CFG 0x02
-+#define cwain_R_CIRM 0x00
-+#define cwain_R_CONF_EN 0x18
-+#define cwain_R_CTRL 0x01
-+#define cwain_R_DTMF 0x1C
-+#define cwain_R_DTMF_N 0x1D
-+#define cwain_R_E1_WR_STA 0x20
-+#define cwain_R_FIFO_MD 0x0D
-+#define cwain_R_FIFO 0x0F
-+#define cwain_R_FIRST_FIFO 0x0B
-+#define cwain_R_FSM_IDX 0x0F
-+#define cwain_R_GPIO_EN0 0x42
-+#define cwain_R_GPIO_EN1 0x43
-+#define cwain_R_GPIO_OUT0 0x40
-+#define cwain_R_GPIO_OUT1 0x41
-+#define cwain_R_GPIO_SEL 0x44
-+#define cwain_R_IRQ_CTRL 0x13
-+#define cwain_R_IRQMSK_MISC 0x11
-+#define cwain_R_JATT_CFG 0x2F
-+#define cwain_R_LOS0 0x22
-+#define cwain_R_LOS1 0x23
-+#define cwain_R_PCM_MD0 0x14
-+#define cwain_R_PCM_MD1 0x15
-+#define cwain_R_PCM_MD2 0x15
-+#define cwain_R_PWM_MD 0x46
-+#define cwain_R_PWM0 0x38
-+#define cwain_R_PWM1 0x39
-+#define cwain_R_RAM_ADDR0 0x08
-+#define cwain_R_RAM_ADDR1 0x09
-+#define cwain_R_RAM_ADDR2 0x0A
-+#define cwain_R_RAM_MISC 0x0C
-+#define cwain_R_RX_OFFS 0x30
-+#define cwain_R_RX_SL0_CFG0 0x25
-+#define cwain_R_RX_SL0_CFG1 0x26
-+#define cwain_R_RX0 0x24
-+#define cwain_R_SH0H 0x15
-+#define cwain_R_SH0L 0x15
-+#define cwain_R_SH1H 0x15
-+#define cwain_R_SH1L 0x15
-+#define cwain_R_SL_SEL0 0x15
-+#define cwain_R_SL_SEL1 0x15
-+#define cwain_R_SL_SEL2 0x15
-+#define cwain_R_SL_SEL3 0x15
-+#define cwain_R_SL_SEL4 0x15
-+#define cwain_R_SL_SEL5 0x15
-+#define cwain_R_SL_SEL6 0x15
-+#define cwain_R_SL_SEL7 0x15
-+#define cwain_R_SLOT 0x10
-+#define cwain_R_SYNC_CTRL 0x35
-+#define cwain_R_SYNC_OUT 0x31
-+#define cwain_R_TI_WD 0x1A
-+#define cwain_R_TX_OFFS 0x34
-+#define cwain_R_TX_SL0_CFG0 0x2C
-+#define cwain_R_TX_SL0_CFG1 0x2E
-+#define cwain_R_TX_SL0 0x2D
-+#define cwain_R_TX0 0x28
-+#define cwain_R_TX1 0x29
-+
-+#define cwain_R_TX_FR0 0x2C
-+#define cwain_R_TX_FR1 0x2D
-+#define cwain_R_TX_FR2 0x2E
-+
-+#define cwain_R_RX_FR0 0x25
-+#define cwain_R_RX_FR1 0x26
-+
-+/* Read only registers */
-+#define cwain_A_F1 0x0C
-+#define cwain_A_F12 0x0C
-+#define cwain_A_F2 0x0D
-+#define cwain_A_Z1 0x04
-+#define cwain_A_Z12 0x04
-+#define cwain_A_Z1H 0x05
-+#define cwain_A_Z1L 0x04
-+#define cwain_A_Z2 0x06
-+#define cwain_A_Z2H 0x07
-+#define cwain_A_Z2L 0x06
-+#define cwain_R_BERT_ECH 0x1B
-+#define cwain_R_BERT_ECL 0x1A
-+#define cwain_R_BERT_STA 0x17
-+#define cwain_R_CHIP_ID 0x16
-+#define cwain_R_CHIP_RV 0x1F
-+#define cwain_R_CONF_OFLOW 0x14
-+#define cwain_R_CRC_ECH 0x35
-+#define cwain_R_CRC_ECL 0x34
-+#define cwain_R_E_ECH 0x37
-+#define cwain_R_E_ECL 0x36
-+#define cwain_R_E1_RD_STA 0x20
-+#define cwain_R_F0_CNTH 0x19
-+#define cwain_R_F0_CNTL 0x18
-+#define cwain_R_FAS_ECH 0x31
-+#define cwain_R_FAS_ECL 0x30
-+#define cwain_R_GPI_IN0 0x44
-+#define cwain_R_GPI_IN1 0x45
-+#define cwain_R_GPI_IN2 0x46
-+#define cwain_R_GPI_IN3 0x47
-+#define cwain_R_GPIO_IN0 0x40
-+#define cwain_R_GPIO_IN1 0x41
-+#define cwain_R_INT_DATA 0x88
-+#define cwain_R_IRQ_FIFO_BL0 0xC8
-+#define cwain_R_IRQ_FIFO_BL1 0xC9
-+#define cwain_R_IRQ_FIFO_BL2 0xCA
-+#define cwain_R_IRQ_FIFO_BL3 0xCB
-+#define cwain_R_IRQ_FIFO_BL4 0xCC
-+#define cwain_R_IRQ_FIFO_BL5 0xCD
-+#define cwain_R_IRQ_FIFO_BL6 0xCE
-+#define cwain_R_IRQ_FIFO_BL7 0xCF
-+#define cwain_R_IRQ_MISC 0x11
-+#define cwain_R_IRQ_OVIEW 0x10
-+#define cwain_R_JATT_STA 0x2B
-+#define cwain_R_RAM_USE 0x15
-+#define cwain_R_RX_SL0_0 0x25
-+#define cwain_R_RX_SL0_1 0x26
-+#define cwain_R_RX_SL0_2 0x27
-+#define cwain_R_SA6_VAL13_ECH 0x39
-+#define cwain_R_SA6_VAL13_ECL 0x38
-+#define cwain_R_SA6_VAL23_ECH 0x3B
-+#define cwain_R_SA6_VAL23_ECL 0x3A
-+#define cwain_R_SLIP 0x2C
-+#define cwain_R_STATUS 0x1C
-+#define cwain_R_SYNC_STA 0x24
-+#define cwain_R_VIO_ECH 0x33
-+#define cwain_R_VIO_ECL 0x32
-+
-+
-+/* Read/Write registers */
-+#define cwain_A_FIFO_DATA0_NOINC 0x84
-+#define cwain_A_FIFO_DATA0 0x80
-+#define cwain_A_FIFO_DATA1_NOINC 0x84
-+#define cwain_A_FIFO_DATA1 0x80
-+#define cwain_A_FIFO_DATA2_NOINC 0x84
-+#define cwain_A_FIFO_DATA2 0x80
-+#define cwain_R_RAM_DATA 0xC0
-+
-+#define PCI_DEVICE_ID_CCD_E 0x30b1
-+
-+#define CLKDEL_TE 0xe /* CLKDEL in TE mode */
-+#define CLKDEL_NT 0xc /* CLKDEL in NT mode */
-+
-diff -urNad zaptel-1.2.1/cwain/LICENSE /tmp/dpep.RTh8jH/zaptel-1.2.1/cwain/LICENSE
---- zaptel-1.2.1/cwain/LICENSE 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.RTh8jH/zaptel-1.2.1/cwain/LICENSE 2005-09-26 09:59:05.000000000 +0300
-@@ -0,0 +1,341 @@
-+
-+ GNU GENERAL PUBLIC LICENSE
-+ Version 2, June 1991
-+
-+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-+ Everyone is permitted to copy and distribute verbatim copies
-+ of this license document, but changing it is not allowed.
-+
-+ Preamble
-+
-+ The licenses for most software are designed to take away your
-+freedom to share and change it. By contrast, the GNU General Public
-+License is intended to guarantee your freedom to share and change free
-+software--to make sure the software is free for all its users. This
-+General Public License applies to most of the Free Software
-+Foundation's software and to any other program whose authors commit to
-+using it. (Some other Free Software Foundation software is covered by
-+the GNU Library General Public License instead.) You can apply it to
-+your programs, too.
-+
-+ When we speak of free software, we are referring to freedom, not
-+price. Our General Public Licenses are designed to make sure that you
-+have the freedom to distribute copies of free software (and charge for
-+this service if you wish), that you receive source code or can get it
-+if you want it, that you can change the software or use pieces of it
-+in new free programs; and that you know you can do these things.
-+
-+ To protect your rights, we need to make restrictions that forbid
-+anyone to deny you these rights or to ask you to surrender the rights.
-+These restrictions translate to certain responsibilities for you if you
-+distribute copies of the software, or if you modify it.
-+
-+ For example, if you distribute copies of such a program, whether
-+gratis or for a fee, you must give the recipients all the rights that
-+you have. You must make sure that they, too, receive or can get the
-+source code. And you must show them these terms so they know their
-+rights.
-+
-+ We protect your rights with two steps: (1) copyright the software, and
-+(2) offer you this license which gives you legal permission to copy,
-+distribute and/or modify the software.
-+
-+ Also, for each author's protection and ours, we want to make certain
-+that everyone understands that there is no warranty for this free
-+software. If the software is modified by someone else and passed on, we
-+want its recipients to know that what they have is not the original, so
-+that any problems introduced by others will not reflect on the original
-+authors' reputations.
-+
-+ Finally, any free program is threatened constantly by software
-+patents. We wish to avoid the danger that redistributors of a free
-+program will individually obtain patent licenses, in effect making the
-+program proprietary. To prevent this, we have made it clear that any
-+patent must be licensed for everyone's free use or not licensed at all.
-+
-+ The precise terms and conditions for copying, distribution and
-+modification follow.
-+
-+ GNU GENERAL PUBLIC LICENSE
-+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-+
-+ 0. This License applies to any program or other work which contains
-+a notice placed by the copyright holder saying it may be distributed
-+under the terms of this General Public License. The "Program", below,
-+refers to any such program or work, and a "work based on the Program"
-+means either the Program or any derivative work under copyright law:
-+that is to say, a work containing the Program or a portion of it,
-+either verbatim or with modifications and/or translated into another
-+language. (Hereinafter, translation is included without limitation in
-+the term "modification".) Each licensee is addressed as "you".
-+
-+Activities other than copying, distribution and modification are not
-+covered by this License; they are outside its scope. The act of
-+running the Program is not restricted, and the output from the Program
-+is covered only if its contents constitute a work based on the
-+Program (independent of having been made by running the Program).
-+Whether that is true depends on what the Program does.
-+
-+ 1. You may copy and distribute verbatim copies of the Program's
-+source code as you receive it, in any medium, provided that you
-+conspicuously and appropriately publish on each copy an appropriate
-+copyright notice and disclaimer of warranty; keep intact all the
-+notices that refer to this License and to the absence of any warranty;
-+and give any other recipients of the Program a copy of this License
-+along with the Program.
-+
-+You may charge a fee for the physical act of transferring a copy, and
-+you may at your option offer warranty protection in exchange for a fee.
-+
-+ 2. You may modify your copy or copies of the Program or any portion
-+of it, thus forming a work based on the Program, and copy and
-+distribute such modifications or work under the terms of Section 1
-+above, provided that you also meet all of these conditions:
-+
-+ a) You must cause the modified files to carry prominent notices
-+ stating that you changed the files and the date of any change.
-+
-+ b) You must cause any work that you distribute or publish, that in
-+ whole or in part contains or is derived from the Program or any
-+ part thereof, to be licensed as a whole at no charge to all third
-+ parties under the terms of this License.
-+
-+ c) If the modified program normally reads commands interactively
-+ when run, you must cause it, when started running for such
-+ interactive use in the most ordinary way, to print or display an
-+ announcement including an appropriate copyright notice and a
-+ notice that there is no warranty (or else, saying that you provide
-+ a warranty) and that users may redistribute the program under
-+ these conditions, and telling the user how to view a copy of this
-+ License. (Exception: if the Program itself is interactive but
-+ does not normally print such an announcement, your work based on
-+ the Program is not required to print an announcement.)
-+
-+These requirements apply to the modified work as a whole. If
-+identifiable sections of that work are not derived from the Program,
-+and can be reasonably considered independent and separate works in
-+themselves, then this License, and its terms, do not apply to those
-+sections when you distribute them as separate works. But when you
-+distribute the same sections as part of a whole which is a work based
-+on the Program, the distribution of the whole must be on the terms of
-+this License, whose permissions for other licensees extend to the
-+entire whole, and thus to each and every part regardless of who wrote it.
-+
-+Thus, it is not the intent of this section to claim rights or contest
-+your rights to work written entirely by you; rather, the intent is to
-+exercise the right to control the distribution of derivative or
-+collective works based on the Program.
-+
-+In addition, mere aggregation of another work not based on the Program
-+with the Program (or with a work based on the Program) on a volume of
-+a storage or distribution medium does not bring the other work under
-+the scope of this License.
-+
-+ 3. You may copy and distribute the Program (or a work based on it,
-+under Section 2) in object code or executable form under the terms of
-+Sections 1 and 2 above provided that you also do one of the following:
-+
-+ a) Accompany it with the complete corresponding machine-readable
-+ source code, which must be distributed under the terms of Sections
-+ 1 and 2 above on a medium customarily used for software interchange; or,
-+
-+ b) Accompany it with a written offer, valid for at least three
-+ years, to give any third party, for a charge no more than your
-+ cost of physically performing source distribution, a complete
-+ machine-readable copy of the corresponding source code, to be
-+ distributed under the terms of Sections 1 and 2 above on a medium
-+ customarily used for software interchange; or,
-+
-+ c) Accompany it with the information you received as to the offer
-+ to distribute corresponding source code. (This alternative is
-+ allowed only for noncommercial distribution and only if you
-+ received the program in object code or executable form with such
-+ an offer, in accord with Subsection b above.)
-+
-+The source code for a work means the preferred form of the work for
-+making modifications to it. For an executable work, complete source
-+code means all the source code for all modules it contains, plus any
-+associated interface definition files, plus the scripts used to
-+control compilation and installation of the executable. However, as a
-+special exception, the source code distributed need not include
-+anything that is normally distributed (in either source or binary
-+form) with the major components (compiler, kernel, and so on) of the
-+operating system on which the executable runs, unless that component
-+itself accompanies the executable.
-+
-+If distribution of executable or object code is made by offering
-+access to copy from a designated place, then offering equivalent
-+access to copy the source code from the same place counts as
-+distribution of the source code, even though third parties are not
-+compelled to copy the source along with the object code.
-+
-+ 4. You may not copy, modify, sublicense, or distribute the Program
-+except as expressly provided under this License. Any attempt
-+otherwise to copy, modify, sublicense or distribute the Program is
-+void, and will automatically terminate your rights under this License.
-+However, parties who have received copies, or rights, from you under
-+this License will not have their licenses terminated so long as such
-+parties remain in full compliance.
-+
-+ 5. You are not required to accept this License, since you have not
-+signed it. However, nothing else grants you permission to modify or
-+distribute the Program or its derivative works. These actions are
-+prohibited by law if you do not accept this License. Therefore, by
-+modifying or distributing the Program (or any work based on the
-+Program), you indicate your acceptance of this License to do so, and
-+all its terms and conditions for copying, distributing or modifying
-+the Program or works based on it.
-+
-+ 6. Each time you redistribute the Program (or any work based on the
-+Program), the recipient automatically receives a license from the
-+original licensor to copy, distribute or modify the Program subject to
-+these terms and conditions. You may not impose any further
-+restrictions on the recipients' exercise of the rights granted herein.
-+You are not responsible for enforcing compliance by third parties to
-+this License.
-+
-+ 7. If, as a consequence of a court judgment or allegation of patent
-+infringement or for any other reason (not limited to patent issues),
-+conditions are imposed on you (whether by court order, agreement or
-+otherwise) that contradict the conditions of this License, they do not
-+excuse you from the conditions of this License. If you cannot
-+distribute so as to satisfy simultaneously your obligations under this
-+License and any other pertinent obligations, then as a consequence you
-+may not distribute the Program at all. For example, if a patent
-+license would not permit royalty-free redistribution of the Program by
-+all those who receive copies directly or indirectly through you, then
-+the only way you could satisfy both it and this License would be to
-+refrain entirely from distribution of the Program.
-+
-+If any portion of this section is held invalid or unenforceable under
-+any particular circumstance, the balance of the section is intended to
-+apply and the section as a whole is intended to apply in other
-+circumstances.
-+
-+It is not the purpose of this section to induce you to infringe any
-+patents or other property right claims or to contest validity of any
-+such claims; this section has the sole purpose of protecting the
-+integrity of the free software distribution system, which is
-+implemented by public license practices. Many people have made
-+generous contributions to the wide range of software distributed
-+through that system in reliance on consistent application of that
-+system; it is up to the author/donor to decide if he or she is willing
-+to distribute software through any other system and a licensee cannot
-+impose that choice.
-+
-+This section is intended to make thoroughly clear what is believed to
-+be a consequence of the rest of this License.
-+
-+ 8. If the distribution and/or use of the Program is restricted in
-+certain countries either by patents or by copyrighted interfaces, the
-+original copyright holder who places the Program under this License
-+may add an explicit geographical distribution limitation excluding
-+those countries, so that distribution is permitted only in or among
-+countries not thus excluded. In such case, this License incorporates
-+the limitation as if written in the body of this License.
-+
-+ 9. The Free Software Foundation may publish revised and/or new versions
-+of the General Public License from time to time. Such new versions will
-+be similar in spirit to the present version, but may differ in detail to
-+address new problems or concerns.
-+
-+Each version is given a distinguishing version number. If the Program
-+specifies a version number of this License which applies to it and "any
-+later version", you have the option of following the terms and conditions
-+either of that version or of any later version published by the Free
-+Software Foundation. If the Program does not specify a version number of
-+this License, you may choose any version ever published by the Free Software
-+Foundation.
-+
-+ 10. If you wish to incorporate parts of the Program into other free
-+programs whose distribution conditions are different, write to the author
-+to ask for permission. For software which is copyrighted by the Free
-+Software Foundation, write to the Free Software Foundation; we sometimes
-+make exceptions for this. Our decision will be guided by the two goals
-+of preserving the free status of all derivatives of our free software and
-+of promoting the sharing and reuse of software generally.
-+
-+ NO WARRANTY
-+
-+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-+REPAIR OR CORRECTION.
-+
-+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-+POSSIBILITY OF SUCH DAMAGES.
-+
-+ END OF TERMS AND CONDITIONS
-+
-+ How to Apply These Terms to Your New Programs
-+
-+ If you develop a new program, and you want it to be of the greatest
-+possible use to the public, the best way to achieve this is to make it
-+free software which everyone can redistribute and change under these terms.
-+
-+ To do so, attach the following notices to the program. It is safest
-+to attach them to the start of each source file to most effectively
-+convey the exclusion of warranty; and each file should have at least
-+the "copyright" line and a pointer to where the full notice is found.
-+
-+ <one line to give the program's name and a brief idea of what it does.>
-+ Copyright (C) 19yy <name of author>
-+
-+ This program is free software; you can redistribute it and/or modify
-+ it under the terms of the GNU General Public License as published by
-+ the Free Software Foundation; either version 2 of the License, or
-+ (at your option) any later version.
-+
-+ This program is distributed in the hope that it will be useful,
-+ but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ GNU General Public License for more details.
-+
-+ You should have received a copy of the GNU General Public License
-+ along with this program; if not, write to the Free Software
-+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-+
-+
-+Also add information on how to contact you by electronic and paper mail.
-+
-+If the program is interactive, make it output a short notice like this
-+when it starts in an interactive mode:
-+
-+ Gnomovision version 69, Copyright (C) 19yy name of author
-+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-+ This is free software, and you are welcome to redistribute it
-+ under certain conditions; type `show c' for details.
-+
-+The hypothetical commands `show w' and `show c' should show the appropriate
-+parts of the General Public License. Of course, the commands you use may
-+be called something other than `show w' and `show c'; they could even be
-+mouse-clicks or menu items--whatever suits your program.
-+
-+You should also get your employer (if you work as a programmer) or your
-+school, if any, to sign a "copyright disclaimer" for the program, if
-+necessary. Here is a sample; alter the names:
-+
-+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
-+
-+ <signature of Ty Coon>, 1 April 1989
-+ Ty Coon, President of Vice
-+
-+This General Public License does not permit incorporating your program into
-+proprietary programs. If your program is a subroutine library, you may
-+consider it more useful to permit linking proprietary applications with the
-+library. If this is what you want to do, use the GNU Library General
-+Public License instead of this License.
-diff -urNad zaptel-1.2.1/cwain/Makefile /tmp/dpep.RTh8jH/zaptel-1.2.1/cwain/Makefile
---- zaptel-1.2.1/cwain/Makefile 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.RTh8jH/zaptel-1.2.1/cwain/Makefile 2005-12-21 15:44:12.000000000 +0200
-@@ -0,0 +1,90 @@
-+KINCLUDES = /usr/src/linux/include
-+BRISTUFFBASE = $(shell dirname `pwd`)
-+
-+ZAP = $(shell [ -f $(BRISTUFFBASE)/zaptel-1.2.1/zaptel.h ] && echo "-I$(BRISTUFFBASE)/zaptel-1.2.1")
-+
-+HOSTCC=gcc
-+
-+CFLAGS+=-I. $(ZAP) -O4 -g -Wall #-DBLINKYBLINK
-+CFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-fsigned-char"; fi)
-+
-+KFLAGS=-D__KERNEL__ -DMODULE -DEXPORT_SYMTAB -fomit-frame-pointer -O2 -Wall -I$(KINCLUDES) $(ZAP)
-+KFLAGS+=$(shell [ -f $(KINCLUDES)/linux/modversions.h ] && echo "-DMODVERSIONS -include $(KINCLUDES)/linux/modversions.h")
-+KFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-msoft-float -fsigned-char"; fi)
-+
-+OBJS=cwain.o
-+
-+BUILDVER=$(shell if uname -r | grep -q ^2.6; then echo "linux26"; else echo "linux24"; fi)
-+
-+MODCONF=$(shell if [ -d $(INSTALL_PREFIX)/etc/modprobe.d ]; then echo "$(INSTALL_PREFIX)/etc/modprobe.d/zaptel"; elif [ -d $(INSTALL_PREFIX)/etc/modutils ]; then echo "$(INSTALL_PREFIX)/etc/modutils/zaptel"; elif [ -f $(INSTALL_PREFIX)/etc/modprobe.conf ]; then echo "$(INSTALL_PREFIX)/modprobe.conf"; elif [ -f $(INSTALL_PREFIX)/etc/modules.conf ]; then echo "$(INSTALL_PREFIX)/etc/modules.conf"; else echo $(INSTALL_PREFIX)/etc/conf.modules ; fi)
-+
-+MODULES=cwain
-+
-+MODULESO=$(shell for x in $(MODULES); do echo "$$x.o "; done )
-+MODULESKO=$(shell for x in $(MODULES); do echo "$$x.ko "; done )
-+
-+PWD=$(shell pwd)
-+
-+obj-m := $(MODULESO)
-+
-+all: $(BUILDVER)
-+
-+linux24: $(OBJS)
-+ sync
-+
-+linux26:
-+ @if ! [ -d /usr/src/linux-2.6 ]; then echo "Link /usr/src/linux-2.6 to your kernel sources first!"; exit 1 ; fi
-+ make -C /usr/src/linux-2.6 SUBDIRS=$(PWD) ZAP=$(ZAP) modules
-+obj-m := $(OBJS)
-+
-+cwain.o: cwain.c cwain.h
-+ $(CC) -c cwain.c $(KFLAGS)
-+
-+clean:
-+ rm -f $(OBJS) *.ko *.mod.c *.mod.o .*o.cmd *~
-+
-+testlinux24: all
-+ modprobe zaptel
-+ insmod ./cwain.o
-+ ztcfg -v
-+ cat /proc/interrupts
-+ sleep 1
-+ cat /proc/interrupts
-+ rmmod cwain zaptel
-+
-+testlinux26: all
-+ modprobe zaptel
-+ insmod ./cwain.ko
-+ ztcfg -v
-+ cat /proc/interrupts
-+ sleep 5
-+ cat /proc/interrupts
-+ rmmod cwain zaptel
-+
-+reload: unload load
-+load: load$(BUILDVER)
-+
-+test: test$(BUILDVER)
-+
-+
-+loadlinux24: linux24
-+ modprobe zaptel
-+ insmod ./cwain.o
-+ ztcfg -v
-+
-+loadlinux26: linux26
-+ sync
-+ modprobe zaptel
-+ insmod ./cwain.ko debug=1
-+ ztcfg -v
-+
-+install: install$(BUILDVER)
-+
-+installlinux26:
-+ install -D -m 644 cwain.ko $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/cwain.ko
-+
-+installlinux24:
-+ install -D -m 644 cwain.o $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/cwain.o
-+
-+unload:
-+ rmmod cwain zaptel
-diff -urNad zaptel-1.2.1/cwain/TODO /tmp/dpep.RTh8jH/zaptel-1.2.1/cwain/TODO
---- zaptel-1.2.1/cwain/TODO 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.RTh8jH/zaptel-1.2.1/cwain/TODO 2005-09-26 09:59:05.000000000 +0300
-@@ -0,0 +1 @@
-+
-diff -urNad zaptel-1.2.1/cwain/zaptel.conf /tmp/dpep.RTh8jH/zaptel-1.2.1/cwain/zaptel.conf
---- zaptel-1.2.1/cwain/zaptel.conf 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.RTh8jH/zaptel-1.2.1/cwain/zaptel.conf 2005-10-27 11:26:41.000000000 +0200
-@@ -0,0 +1,11 @@
-+loadzone=nl
-+defaultzone=nl
-+span=1,2,3,ccs,hdb3,crc4
-+
-+alaw=1-31
-+
-+bchan=1-15
-+dchan=16
-+bchan=17-31
-+
-+
-diff -urNad zaptel-1.2.1/qozap/LICENSE /tmp/dpep.RTh8jH/zaptel-1.2.1/qozap/LICENSE
---- zaptel-1.2.1/qozap/LICENSE 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.RTh8jH/zaptel-1.2.1/qozap/LICENSE 2005-06-13 10:03:36.000000000 +0300
-@@ -0,0 +1,341 @@
-+
-+ GNU GENERAL PUBLIC LICENSE
-+ Version 2, June 1991
-+
-+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-+ Everyone is permitted to copy and distribute verbatim copies
-+ of this license document, but changing it is not allowed.
-+
-+ Preamble
-+
-+ The licenses for most software are designed to take away your
-+freedom to share and change it. By contrast, the GNU General Public
-+License is intended to guarantee your freedom to share and change free
-+software--to make sure the software is free for all its users. This
-+General Public License applies to most of the Free Software
-+Foundation's software and to any other program whose authors commit to
-+using it. (Some other Free Software Foundation software is covered by
-+the GNU Library General Public License instead.) You can apply it to
-+your programs, too.
-+
-+ When we speak of free software, we are referring to freedom, not
-+price. Our General Public Licenses are designed to make sure that you
-+have the freedom to distribute copies of free software (and charge for
-+this service if you wish), that you receive source code or can get it
-+if you want it, that you can change the software or use pieces of it
-+in new free programs; and that you know you can do these things.
-+
-+ To protect your rights, we need to make restrictions that forbid
-+anyone to deny you these rights or to ask you to surrender the rights.
-+These restrictions translate to certain responsibilities for you if you
-+distribute copies of the software, or if you modify it.
-+
-+ For example, if you distribute copies of such a program, whether
-+gratis or for a fee, you must give the recipients all the rights that
-+you have. You must make sure that they, too, receive or can get the
-+source code. And you must show them these terms so they know their
-+rights.
-+
-+ We protect your rights with two steps: (1) copyright the software, and
-+(2) offer you this license which gives you legal permission to copy,
-+distribute and/or modify the software.
-+
-+ Also, for each author's protection and ours, we want to make certain
-+that everyone understands that there is no warranty for this free
-+software. If the software is modified by someone else and passed on, we
-+want its recipients to know that what they have is not the original, so
-+that any problems introduced by others will not reflect on the original
-+authors' reputations.
-+
-+ Finally, any free program is threatened constantly by software
-+patents. We wish to avoid the danger that redistributors of a free
-+program will individually obtain patent licenses, in effect making the
-+program proprietary. To prevent this, we have made it clear that any
-+patent must be licensed for everyone's free use or not licensed at all.
-+
-+ The precise terms and conditions for copying, distribution and
-+modification follow.
-+
-+ GNU GENERAL PUBLIC LICENSE
-+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-+
-+ 0. This License applies to any program or other work which contains
-+a notice placed by the copyright holder saying it may be distributed
-+under the terms of this General Public License. The "Program", below,
-+refers to any such program or work, and a "work based on the Program"
-+means either the Program or any derivative work under copyright law:
-+that is to say, a work containing the Program or a portion of it,
-+either verbatim or with modifications and/or translated into another
-+language. (Hereinafter, translation is included without limitation in
-+the term "modification".) Each licensee is addressed as "you".
-+
-+Activities other than copying, distribution and modification are not
-+covered by this License; they are outside its scope. The act of
-+running the Program is not restricted, and the output from the Program
-+is covered only if its contents constitute a work based on the
-+Program (independent of having been made by running the Program).
-+Whether that is true depends on what the Program does.
-+
-+ 1. You may copy and distribute verbatim copies of the Program's
-+source code as you receive it, in any medium, provided that you
-+conspicuously and appropriately publish on each copy an appropriate
-+copyright notice and disclaimer of warranty; keep intact all the
-+notices that refer to this License and to the absence of any warranty;
-+and give any other recipients of the Program a copy of this License
-+along with the Program.
-+
-+You may charge a fee for the physical act of transferring a copy, and
-+you may at your option offer warranty protection in exchange for a fee.
-+
-+ 2. You may modify your copy or copies of the Program or any portion
-+of it, thus forming a work based on the Program, and copy and
-+distribute such modifications or work under the terms of Section 1
-+above, provided that you also meet all of these conditions:
-+
-+ a) You must cause the modified files to carry prominent notices
-+ stating that you changed the files and the date of any change.
-+
-+ b) You must cause any work that you distribute or publish, that in
-+ whole or in part contains or is derived from the Program or any
-+ part thereof, to be licensed as a whole at no charge to all third
-+ parties under the terms of this License.
-+
-+ c) If the modified program normally reads commands interactively
-+ when run, you must cause it, when started running for such
-+ interactive use in the most ordinary way, to print or display an
-+ announcement including an appropriate copyright notice and a
-+ notice that there is no warranty (or else, saying that you provide
-+ a warranty) and that users may redistribute the program under
-+ these conditions, and telling the user how to view a copy of this
-+ License. (Exception: if the Program itself is interactive but
-+ does not normally print such an announcement, your work based on
-+ the Program is not required to print an announcement.)
-+
-+These requirements apply to the modified work as a whole. If
-+identifiable sections of that work are not derived from the Program,
-+and can be reasonably considered independent and separate works in
-+themselves, then this License, and its terms, do not apply to those
-+sections when you distribute them as separate works. But when you
-+distribute the same sections as part of a whole which is a work based
-+on the Program, the distribution of the whole must be on the terms of
-+this License, whose permissions for other licensees extend to the
-+entire whole, and thus to each and every part regardless of who wrote it.
-+
-+Thus, it is not the intent of this section to claim rights or contest
-+your rights to work written entirely by you; rather, the intent is to
-+exercise the right to control the distribution of derivative or
-+collective works based on the Program.
-+
-+In addition, mere aggregation of another work not based on the Program
-+with the Program (or with a work based on the Program) on a volume of
-+a storage or distribution medium does not bring the other work under
-+the scope of this License.
-+
-+ 3. You may copy and distribute the Program (or a work based on it,
-+under Section 2) in object code or executable form under the terms of
-+Sections 1 and 2 above provided that you also do one of the following:
-+
-+ a) Accompany it with the complete corresponding machine-readable
-+ source code, which must be distributed under the terms of Sections
-+ 1 and 2 above on a medium customarily used for software interchange; or,
-+
-+ b) Accompany it with a written offer, valid for at least three
-+ years, to give any third party, for a charge no more than your
-+ cost of physically performing source distribution, a complete
-+ machine-readable copy of the corresponding source code, to be
-+ distributed under the terms of Sections 1 and 2 above on a medium
-+ customarily used for software interchange; or,
-+
-+ c) Accompany it with the information you received as to the offer
-+ to distribute corresponding source code. (This alternative is
-+ allowed only for noncommercial distribution and only if you
-+ received the program in object code or executable form with such
-+ an offer, in accord with Subsection b above.)
-+
-+The source code for a work means the preferred form of the work for
-+making modifications to it. For an executable work, complete source
-+code means all the source code for all modules it contains, plus any
-+associated interface definition files, plus the scripts used to
-+control compilation and installation of the executable. However, as a
-+special exception, the source code distributed need not include
-+anything that is normally distributed (in either source or binary
-+form) with the major components (compiler, kernel, and so on) of the
-+operating system on which the executable runs, unless that component
-+itself accompanies the executable.
-+
-+If distribution of executable or object code is made by offering
-+access to copy from a designated place, then offering equivalent
-+access to copy the source code from the same place counts as
-+distribution of the source code, even though third parties are not
-+compelled to copy the source along with the object code.
-+
-+ 4. You may not copy, modify, sublicense, or distribute the Program
-+except as expressly provided under this License. Any attempt
-+otherwise to copy, modify, sublicense or distribute the Program is
-+void, and will automatically terminate your rights under this License.
-+However, parties who have received copies, or rights, from you under
-+this License will not have their licenses terminated so long as such
-+parties remain in full compliance.
-+
-+ 5. You are not required to accept this License, since you have not
-+signed it. However, nothing else grants you permission to modify or
-+distribute the Program or its derivative works. These actions are
-+prohibited by law if you do not accept this License. Therefore, by
-+modifying or distributing the Program (or any work based on the
-+Program), you indicate your acceptance of this License to do so, and
-+all its terms and conditions for copying, distributing or modifying
-+the Program or works based on it.
-+
-+ 6. Each time you redistribute the Program (or any work based on the
-+Program), the recipient automatically receives a license from the
-+original licensor to copy, distribute or modify the Program subject to
-+these terms and conditions. You may not impose any further
-+restrictions on the recipients' exercise of the rights granted herein.
-+You are not responsible for enforcing compliance by third parties to
-+this License.
-+
-+ 7. If, as a consequence of a court judgment or allegation of patent
-+infringement or for any other reason (not limited to patent issues),
-+conditions are imposed on you (whether by court order, agreement or
-+otherwise) that contradict the conditions of this License, they do not
-+excuse you from the conditions of this License. If you cannot
-+distribute so as to satisfy simultaneously your obligations under this
-+License and any other pertinent obligations, then as a consequence you
-+may not distribute the Program at all. For example, if a patent
-+license would not permit royalty-free redistribution of the Program by
-+all those who receive copies directly or indirectly through you, then
-+the only way you could satisfy both it and this License would be to
-+refrain entirely from distribution of the Program.
-+
-+If any portion of this section is held invalid or unenforceable under
-+any particular circumstance, the balance of the section is intended to
-+apply and the section as a whole is intended to apply in other
-+circumstances.
-+
-+It is not the purpose of this section to induce you to infringe any
-+patents or other property right claims or to contest validity of any
-+such claims; this section has the sole purpose of protecting the
-+integrity of the free software distribution system, which is
-+implemented by public license practices. Many people have made
-+generous contributions to the wide range of software distributed
-+through that system in reliance on consistent application of that
-+system; it is up to the author/donor to decide if he or she is willing
-+to distribute software through any other system and a licensee cannot
-+impose that choice.
-+
-+This section is intended to make thoroughly clear what is believed to
-+be a consequence of the rest of this License.
-+
-+ 8. If the distribution and/or use of the Program is restricted in
-+certain countries either by patents or by copyrighted interfaces, the
-+original copyright holder who places the Program under this License
-+may add an explicit geographical distribution limitation excluding
-+those countries, so that distribution is permitted only in or among
-+countries not thus excluded. In such case, this License incorporates
-+the limitation as if written in the body of this License.
-+
-+ 9. The Free Software Foundation may publish revised and/or new versions
-+of the General Public License from time to time. Such new versions will
-+be similar in spirit to the present version, but may differ in detail to
-+address new problems or concerns.
-+
-+Each version is given a distinguishing version number. If the Program
-+specifies a version number of this License which applies to it and "any
-+later version", you have the option of following the terms and conditions
-+either of that version or of any later version published by the Free
-+Software Foundation. If the Program does not specify a version number of
-+this License, you may choose any version ever published by the Free Software
-+Foundation.
-+
-+ 10. If you wish to incorporate parts of the Program into other free
-+programs whose distribution conditions are different, write to the author
-+to ask for permission. For software which is copyrighted by the Free
-+Software Foundation, write to the Free Software Foundation; we sometimes
-+make exceptions for this. Our decision will be guided by the two goals
-+of preserving the free status of all derivatives of our free software and
-+of promoting the sharing and reuse of software generally.
-+
-+ NO WARRANTY
-+
-+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-+REPAIR OR CORRECTION.
-+
-+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-+POSSIBILITY OF SUCH DAMAGES.
-+
-+ END OF TERMS AND CONDITIONS
-+
-+ How to Apply These Terms to Your New Programs
-+
-+ If you develop a new program, and you want it to be of the greatest
-+possible use to the public, the best way to achieve this is to make it
-+free software which everyone can redistribute and change under these terms.
-+
-+ To do so, attach the following notices to the program. It is safest
-+to attach them to the start of each source file to most effectively
-+convey the exclusion of warranty; and each file should have at least
-+the "copyright" line and a pointer to where the full notice is found.
-+
-+ <one line to give the program's name and a brief idea of what it does.>
-+ Copyright (C) 19yy <name of author>
-+
-+ This program is free software; you can redistribute it and/or modify
-+ it under the terms of the GNU General Public License as published by
-+ the Free Software Foundation; either version 2 of the License, or
-+ (at your option) any later version.
-+
-+ This program is distributed in the hope that it will be useful,
-+ but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ GNU General Public License for more details.
-+
-+ You should have received a copy of the GNU General Public License
-+ along with this program; if not, write to the Free Software
-+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-+
-+
-+Also add information on how to contact you by electronic and paper mail.
-+
-+If the program is interactive, make it output a short notice like this
-+when it starts in an interactive mode:
-+
-+ Gnomovision version 69, Copyright (C) 19yy name of author
-+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-+ This is free software, and you are welcome to redistribute it
-+ under certain conditions; type `show c' for details.
-+
-+The hypothetical commands `show w' and `show c' should show the appropriate
-+parts of the General Public License. Of course, the commands you use may
-+be called something other than `show w' and `show c'; they could even be
-+mouse-clicks or menu items--whatever suits your program.
-+
-+You should also get your employer (if you work as a programmer) or your
-+school, if any, to sign a "copyright disclaimer" for the program, if
-+necessary. Here is a sample; alter the names:
-+
-+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
-+
-+ <signature of Ty Coon>, 1 April 1989
-+ Ty Coon, President of Vice
-+
-+This General Public License does not permit incorporating your program into
-+proprietary programs. If your program is a subroutine library, you may
-+consider it more useful to permit linking proprietary applications with the
-+library. If this is what you want to do, use the GNU Library General
-+Public License instead of this License.
-diff -urNad zaptel-1.2.1/qozap/Makefile /tmp/dpep.RTh8jH/zaptel-1.2.1/qozap/Makefile
---- zaptel-1.2.1/qozap/Makefile 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.RTh8jH/zaptel-1.2.1/qozap/Makefile 2005-12-21 15:44:21.000000000 +0200
-@@ -0,0 +1,91 @@
-+KINCLUDES = /usr/src/linux/include
-+BRISTUFFBASE = $(shell dirname `pwd`)
-+
-+ZAP = $(shell [ -f $(BRISTUFFBASE)/zaptel-1.2.1/zaptel.h ] && echo "-I$(BRISTUFFBASE)/zaptel-1.2.1")
-+
-+HOSTCC=gcc
-+
-+CFLAGS+=-I. $(ZAP) -O4 -g -Wall -DBUILDING_TONEZONE #-DTONEZONE_DRIVER
-+CFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-fsigned-char"; fi)
-+
-+KFLAGS=-D__KERNEL__ -DMODULE -DEXPORT_SYMTAB -fomit-frame-pointer -O2 -Wall -I$(KINCLUDES) $(ZAP)
-+KFLAGS+=$(shell [ -f $(KINCLUDES)/linux/modversions.h ] && echo "-DMODVERSIONS -include $(KINCLUDES)/linux/modversions.h")
-+KFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-msoft-float -fsigned-char"; fi)
-+
-+OBJS=qozap.o
-+
-+BUILDVER=$(shell if uname -r | grep -q ^2.6; then echo "linux26"; else echo "linux24"; fi)
-+
-+MODCONF=$(shell if [ -d $(INSTALL_PREFIX)/etc/modprobe.d ]; then echo "$(INSTALL_PREFIX)/etc/modprobe.d/zaptel"; elif [ -d $(INSTALL_PREFIX)/etc/modutils ]; then echo "$(INSTALL_PREFIX)/etc/modutils/zaptel"; elif [ -f $(INSTALL_PREFIX)/etc/modprobe.conf ]; then echo "$(INSTALL_PREFIX)/modprobe.conf"; elif [ -f $(INSTALL_PREFIX)/etc/modules.conf ]; then echo "$(INSTALL_PREFIX)/etc/modules.conf"; else echo $(INSTALL_PREFIX)/etc/conf.modules ; fi)
-+
-+MODULES=qozap
-+
-+MODULESO=$(shell for x in $(MODULES); do echo "$$x.o "; done )
-+MODULESKO=$(shell for x in $(MODULES); do echo "$$x.ko "; done )
-+
-+PWD=$(shell pwd)
-+
-+obj-m := $(MODULESO)
-+
-+all: $(BUILDVER)
-+
-+linux24: $(OBJS)
-+ sync
-+
-+linux26:
-+ @if ! [ -d /usr/src/linux-2.6 ]; then echo "Link /usr/src/linux-2.6 to your kernel sources first!"; exit 1 ; fi
-+ make -C /usr/src/linux-2.6 SUBDIRS=$(PWD) ZAP=$(ZAP) modules
-+obj-m := $(OBJS)
-+
-+qozap.o: qozap.c qozap.h
-+ $(CC) -c qozap.c $(KFLAGS)
-+
-+clean:
-+ rm -f $(OBJS) *.ko *.mod.c *.mod.o .*o.cmd *~
-+ rm -rf .tmp_versions
-+
-+testlinux24: all
-+ modprobe zaptel
-+ insmod ./qozap.o
-+ ztcfg -v
-+ cat /proc/interrupts
-+ sleep 1
-+ cat /proc/interrupts
-+ rmmod qozap zaptel
-+
-+testlinux26: all
-+ modprobe zaptel
-+ insmod ./qozap.ko
-+ ztcfg -v
-+ cat /proc/interrupts
-+ sleep 1
-+ cat /proc/interrupts
-+ rmmod qozap zaptel
-+
-+reload: unload load
-+load: load$(BUILDVER)
-+
-+test: test$(BUILDVER)
-+
-+
-+loadlinux24: linux24
-+ modprobe zaptel
-+ insmod ./qozap.o
-+ ztcfg -v
-+
-+loadlinux26: linux26
-+ sync
-+ modprobe zaptel
-+ insmod ./qozap.ko
-+ ztcfg -v
-+
-+unload:
-+ rmmod qozap zaptel
-+
-+install: install$(BUILDVER)
-+
-+installlinux26:
-+ install -D -m 644 qozap.ko $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/qozap.ko
-+
-+installlinux24:
-+ install -D -m 644 qozap.o $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/qozap.o
-diff -urNad zaptel-1.2.1/qozap/qozap.c /tmp/dpep.RTh8jH/zaptel-1.2.1/qozap/qozap.c
---- zaptel-1.2.1/qozap/qozap.c 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.RTh8jH/zaptel-1.2.1/qozap/qozap.c 2005-08-01 09:58:20.000000000 +0300
-@@ -0,0 +1,1493 @@
-+/*
-+ * qozap.c - Zaptel driver for the quadBRI PCI ISDN card
-+ * and the octoBRI PCI ISDN card!
-+ *
-+ * Copyright (C) 2003, 2004, 2005 Junghanns.NET GmbH
-+ *
-+ * Klaus-Peter Junghanns <kpj at junghanns.net>
-+ *
-+ * This program is free software and may be modified and
-+ * distributed under the terms of the GNU Public License.
-+ *
-+ */
-+#include <linux/kernel.h>
-+#include <linux/module.h>
-+#include <linux/pci.h>
-+#include <linux/init.h>
-+#include <linux/interrupt.h>
-+#include <zaptel.h>
-+#include "qozap.h"
-+
-+#if CONFIG_PCI
-+
-+static int doubleclock=0;
-+static int ports=-1; /* autodetect */
-+static int bloop=0;
-+static int debug=0;
-+static struct qoz_card *qoz_dev_list = NULL;
-+static int qoz_dev_count = 0;
-+static int totalBRIs = 0;
-+static struct pci_dev *multi_qoz = NULL;
-+static spinlock_t registerlock = SPIN_LOCK_UNLOCKED;
-+
-+static int ztqoz_shutdown(struct zt_span *span);
-+
-+int qoz_waitbusy(struct qoz_card *qoztmp) {
-+ int x=1000;
-+ while (x-- && (qoz_inb(qoztmp,qoz_R_STATUS) & 1));
-+ if (x < 0) {
-+ return -1;
-+ } else {
-+ return 0;
-+ }
-+}
-+
-+void qoz_shutdownCard(struct qoz_card *qoztmp) {
-+ int s=0;
-+ unsigned long flags;
-+ int stports=0;
-+ if (qoztmp == NULL) {
-+ printk(KERN_INFO "qozap: shutting down NULL card!\n");
-+ return;
-+ }
-+
-+ if ((qoztmp->pci_io == NULL) || (qoztmp->ioport == 0)) {
-+ return;
-+ }
-+
-+ if (debug)
-+ printk(KERN_INFO "qozap: shutting down card %d (cardID %d) at io port %#x.\n",qoztmp->cardno,qoztmp->cardID,(u_int) qoztmp->ioport);
-+
-+ if (qoztmp->ztdev != NULL) {
-+ stports = qoztmp->stports;
-+ for (s=0; s < stports; s++) {
-+ if(qoztmp->ztdev->spans[s].flags & ZT_FLAG_RUNNING) {
-+ ztqoz_shutdown(&qoztmp->ztdev->spans[s]);
-+ if (debug)
-+ printk(KERN_INFO "qozap: shutdown card %d span %d.\n",qoztmp->cardno,s+1);
-+ }
-+ }
-+ }
-+
-+ spin_lock_irqsave(&qoztmp->lock,flags);
-+
-+ // turn off irqs
-+ qoz_outb(qoztmp,qoz_R_IRQ_CTRL, 0);
-+ qoz_outb(qoztmp,qoz_R_IRQMSK_MISC, 0);
-+ qoz_outb(qoztmp,qoz_R_SCI_MSK, 0);
-+
-+ free_irq(qoztmp->irq,qoztmp);
-+
-+ // softreset
-+ qoz_outb(qoztmp,qoz_R_CIRM,0x8);
-+ qoz_outb(qoztmp,qoz_R_CIRM,0x0);
-+ qoz_waitbusy(qoztmp);
-+
-+ qoz_outb(qoztmp,qoz_R_IRQMSK_MISC, 0);
-+ qoz_outb(qoztmp,qoz_R_SCI_MSK, 0);
-+ qoz_outb(qoztmp,qoz_R_IRQ_CTRL, 0);
-+
-+ release_region(qoztmp->ioport, 7);
-+ iounmap((void *) qoztmp->pci_io);
-+
-+ qoztmp->pci_io = NULL;
-+ qoztmp->ioport = 0;
-+
-+ if (qoztmp->pcidev != NULL) {
-+ pci_disable_device(qoztmp->pcidev);
-+ }
-+ pci_write_config_word(qoztmp->pcidev, PCI_COMMAND, 0);
-+
-+ spin_unlock_irqrestore(&qoztmp->lock,flags);
-+
-+ if (qoztmp->ztdev != NULL) {
-+ stports = qoztmp->stports;
-+ for (s=0; s < stports; s++) {
-+ if(qoztmp->ztdev->spans[s].flags & ZT_FLAG_REGISTERED) {
-+ zt_unregister(&qoztmp->ztdev->spans[s]);
-+ if (debug)
-+ printk(KERN_INFO "qozap: unregistered card %d span %d.\n",qoztmp->cardno,s+1);
-+ }
-+ }
-+ kfree(qoztmp->ztdev);
-+ qoztmp->ztdev = NULL;
-+ }
-+}
-+
-+void qoz_doLEDs(struct qoz_card *qoztmp) {
-+ unsigned char leds = 0x0;
-+ if ((qoztmp->type == 0xb520) && (qoztmp->stports == 4)){
-+// if ((qoztmp->ticks > 0) && (qoztmp->ticks <= 300)) {
-+ qoz_outb(qoztmp,qoz_R_GPIO_SEL,0x20 | 0x10);
-+ qoz_outb(qoztmp,qoz_R_GPIO_EN1,0xf);
-+ qoz_outb(qoztmp,qoz_R_GPIO_OUT1,(qoztmp->leds[0] | (qoztmp->leds[1] << 1) | (qoztmp->leds[2] << 2) | (qoztmp->leds[3] << 3)));
-+/* }
-+ if ((qoztmp->ticks > 300) && (qoztmp->ticks <= 600)) {
-+ qoz_outb(qoztmp,qoz_R_GPIO_EN1,0x0);
-+ } */
-+ } else if ((qoztmp->type == 0xb550) && (qoztmp->stports == 4)){
-+ qoz_outb(qoztmp,qoz_R_GPIO_SEL,0x80 | 0x40 | 0x20 | 0x10);
-+ qoz_outb(qoztmp,qoz_R_GPIO_EN1,0xff);
-+ if (qoztmp->leds[0] == 0) {
-+ leds |= 0x80;
-+ } else {
-+ leds |= 0x40;
-+ }
-+ if (qoztmp->leds[1] == 0) {
-+ leds |= 0x10;
-+ } else {
-+ leds |= 0x20;
-+ }
-+ if (qoztmp->leds[2] == 0) {
-+ leds |= 0x04;
-+ } else {
-+ leds |= 0x08;
-+ }
-+ if (qoztmp->leds[3] == 0) {
-+ leds |= 0x02;
-+ } else {
-+ leds |= 0x01;
-+ }
-+ /* 0x80 st1g
-+ 0x40 st1r
-+ 0x20 st2r
-+ 0x10 st2g
-+ 0x08 st3r
-+ 0x04 st3g
-+ 0x02 st4g
-+ 0x01 st4r
-+ */
-+ qoz_outb(qoztmp,qoz_R_GPIO_OUT1, leds);
-+ }
-+}
-+
-+void qoz_doWD(struct qoz_card *qoztmp) {
-+ if (!qoztmp->wdp) {
-+ return;
-+ }
-+ if (qoztmp->wdp == 1) {
-+ qoz_outdw_io(qoztmp,0x4000, qoz_WD_P2);
-+ qoztmp->wdp = 2;
-+ } else {
-+ qoz_outdw_io(qoztmp,0x4000, qoz_WD_P1);
-+ qoztmp->wdp = 1;
-+ }
-+ qoz_inb_io(qoztmp,qoz_R_CHIP_ID);
-+}
-+
-+void qoz_undoWD(struct qoz_card *qoztmp) {
-+ printk(KERN_INFO "qozap: Stopping hardware watchdog.\n");
-+ qoz_outdw_io(qoztmp,0x4000, qoz_WD_P0);
-+ qoztmp->wdp = 0;
-+ qoz_inb_io(qoztmp,qoz_R_CHIP_ID);
-+}
-+
-+void qoz_resetCard(struct qoz_card *qoztmp) {
-+ unsigned long flags;
-+ unsigned char i=0;
-+ spin_lock_irqsave(&(qoztmp->lock),flags);
-+ pci_write_config_word(qoztmp->pcidev, PCI_COMMAND, PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
-+
-+ // soft reset
-+ qoz_outb(qoztmp,qoz_R_CIRM,0x8);
-+ qoz_outb(qoztmp,qoz_R_CIRM,0x0);
-+ qoz_waitbusy(qoztmp);
-+
-+ // fifo reset
-+ qoz_outb(qoztmp,qoz_R_CIRM,0x10);
-+ qoz_outb(qoztmp,qoz_R_CIRM,0x0);
-+ qoz_waitbusy(qoztmp);
-+
-+ // s/t reset
-+ qoz_outb(qoztmp,qoz_R_CIRM,0x40);
-+ qoz_outb(qoztmp,qoz_R_CIRM,0x0);
-+ qoz_waitbusy(qoztmp);
-+
-+ /* set S0 amplitude */
-+ qoz_outb(qoztmp,qoz_R_PWM_MD,0xa0);
-+ if (qoztmp->type == 0xb552) {
-+ qoz_outb(qoztmp,qoz_R_PWM0,0x19);
-+ } else {
-+ qoz_outb(qoztmp,qoz_R_PWM0,0x1E);
-+ }
-+
-+ /* set up the timer */
-+ qoz_outb(qoztmp,qoz_R_TI_WD, 0x2);
-+ qoz_outb(qoztmp,qoz_R_IRQMSK_MISC, 0x2);
-+ qoz_outb(qoztmp,qoz_R_PCM_MD0, 0x1);
-+
-+ /* all state changes */
-+ qoz_outb(qoztmp,qoz_R_SCI_MSK, 0xff);
-+
-+ if (qoztmp->type == 0xb552) {
-+ qoz_outb(qoztmp,qoz_R_FIFO_MD,0x16);
-+ } else {
-+ qoz_outb(qoztmp,qoz_R_FIFO_MD,0x26);
-+ }
-+
-+ // double clock
-+ if (doubleclock == 1) {
-+ // hopefully you have set CLK_MODE correctly!
-+ qoz_outb(qoztmp,qoz_R_BRG_PCM_CFG,0x20);
-+ } else {
-+ if (qoztmp->type == 0x08b4) {
-+ qoz_outb(qoztmp,qoz_R_BRG_PCM_CFG,0x0);
-+ } else if (qoztmp->type == 0xb550) {
-+ qoz_outb(qoztmp,qoz_R_BRG_PCM_CFG,0x23);
-+ } else if (qoztmp->type == 0xb520) {
-+ qoz_outb(qoztmp,qoz_R_BRG_PCM_CFG,0x20);
-+ } else {
-+ /* you are on your own here! */
-+ qoz_outb(qoztmp,qoz_R_BRG_PCM_CFG,0x20);
-+ }
-+ }
-+ qoz_outb(qoztmp,qoz_R_CTRL,0x0);
-+
-+ /* R0 G1 */
-+ qoztmp->leds[0] = 0x0;
-+ qoztmp->leds[1] = 0x0;
-+ qoztmp->leds[2] = 0x0;
-+ qoztmp->leds[3] = 0x0;
-+ qoztmp->leds[4] = 0x0;
-+ qoztmp->leds[5] = 0x0;
-+ qoztmp->leds[6] = 0x0;
-+ qoztmp->leds[7] = 0x0;
-+
-+ /* Finally enable IRQ output */
-+ qoz_outb(qoztmp,qoz_R_IRQ_CTRL, 0x8 | 0x1);
-+ if (qoztmp->type == 0xb552) {
-+ qoztmp->stports = 8;
-+ } else {
-+ qoztmp->stports = 4;
-+ }
-+ qoztmp->ticks = 0;
-+ qoztmp->clicks = 0;
-+ if (qoztmp->type == 0xb550) {
-+ printk(KERN_INFO "qozap: Starting hardware watchdog.\n");
-+ qoztmp->wdp = 2;
-+ } else {
-+ qoztmp->wdp = 0;
-+ }
-+
-+ for (i=0;i<qoztmp->stports;i++) {
-+ if (qoztmp->st[i].nt_mode) {
-+ qoz_outb(qoztmp,qoz_R_ST_SYNC,0x8 | i);
-+ if (debug)
-+ printk(KERN_INFO "qoztmp: using NT port %d for sync\n", i);
-+ break;
-+ }
-+ }
-+ if (i == qoztmp->stports) {
-+ qoz_outb(qoztmp,qoz_R_ST_SYNC,0x0);
-+ }
-+ spin_unlock_irqrestore(&(qoztmp->lock),flags);
-+}
-+
-+void qoz_registerCard(struct qoz_card *qozcard) {
-+ spin_lock(®isterlock);
-+ if (qozcard != NULL) {
-+ qozcard->prev = NULL;
-+ qozcard->next = qoz_dev_list;
-+ if (qoz_dev_list) {
-+ qoz_dev_list->prev = qozcard;
-+ }
-+ qoz_dev_list = qozcard;
-+ qozcard->cardno = ++qoz_dev_count;
-+ } else {
-+ printk(KERN_INFO "qozap: trying to register NULL card.\n");
-+ }
-+ spin_unlock(®isterlock);
-+}
-+
-+static int qoz_dfifo_tx(struct qoz_card *qoztmp, int stport) {
-+ int chan = 2;
-+ int x=0;
-+ char fifo = 0;
-+ char offset = 0;
-+
-+ if (qoztmp->type == 0xb552) {
-+ offset = 24;
-+ } else {
-+ offset = 28;
-+ }
-+
-+ fifo = stport + offset;
-+
-+ if (qoztmp->ztdev->chans[stport][chan].bytes2transmit < 1) {
-+ return 0;
-+ } else {
-+ /* select fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,fifo << 1);
-+ qoz_waitbusy(qoztmp);
-+
-+ if (debug > 1)
-+ printk(KERN_INFO "qozap: card %d stport %d TX [ ", qoztmp->cardno, stport + 1);
-+ /* copy frame to fifo */
-+ for (x=0;x<qoztmp->ztdev->chans[stport][chan].bytes2transmit;x++) {
-+ if (debug > 1)
-+ printk("%#x ",qoztmp->dtxbuf[stport][x]);
-+ qoz_outb(qoztmp,qoz_A_FIFO_DATA0,qoztmp->dtxbuf[stport][x]);
-+ }
-+ if (debug > 1)
-+ printk("] %d bytes\n",qoztmp->ztdev->chans[stport][chan].bytes2transmit);
-+
-+ if (qoztmp->ztdev->chans[stport][chan].eoftx == 1) {
-+ /* transmit HDLC frame */
-+ qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x1);
-+ qoz_waitbusy(qoztmp);
-+ }
-+ }
-+ return 0;
-+}
-+
-+static int qoz_fifo_tx(struct qoz_card *qoztmp, char fifo) {
-+ int stport = fifo / 2;
-+ int chan = fifo % 2;
-+
-+ /* select fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,0x80 | (fifo << 1));
-+ qoz_waitbusy(qoztmp);
-+ /* transmit 8 bytes of transparent data */
-+ qoz_outdw(qoztmp,qoz_A_FIFO_DATA0,*((unsigned int *) &qoztmp->txbuf[stport][chan][0]));
-+ qoz_outdw(qoztmp,qoz_A_FIFO_DATA0,*((unsigned int *) &qoztmp->txbuf[stport][chan][4]));
-+
-+ return 0;
-+}
-+
-+static int qoz_dfifo_rx(struct qoz_card *qoztmp, int stport) {
-+ unsigned char f1=1,f2=1,data,stat;
-+ unsigned char of1=0,of2=0;
-+ int len,i;
-+ unsigned short z1=1,z2=1;
-+ unsigned short oz1=0,oz2=0;
-+ char fifo = 0;
-+ char offset = 0;
-+
-+ if (qoztmp->type == 0xb552) {
-+ offset = 24;
-+ } else {
-+ offset = 28;
-+ }
-+
-+ fifo = stport + offset;
-+ // select rx fifo
-+
-+ qoz_outb(qoztmp,qoz_R_FIFO,(fifo << 1) | 1);
-+ qoz_waitbusy(qoztmp);
-+
-+ while ((of1 != f1) && (of2 != f2)) {
-+ of1 = f1;
-+ of2 = f2;
-+ f1 = qoz_inb(qoztmp,qoz_A_F1) & 0xf;
-+ f2 = qoz_inb(qoztmp,qoz_A_F2) & 0xf;
-+ }
-+
-+ if (f1 == f2) {
-+ /* no frame */
-+ qoztmp->st[stport].drx--;
-+ qoztmp->ztdev->chans[stport][2].bytes2receive = 0;
-+ return 0;
-+ }
-+
-+ while ((oz1 != z1) && (oz2 != z2)) {
-+ oz1 = z1;
-+ oz2 = z2;
-+ if (qoztmp->type != 0xb552) {
-+ z1 = qoz_inw(qoztmp,qoz_A_Z1) & 0x7ff;
-+ z2 = qoz_inw(qoztmp,qoz_A_Z2) & 0x7ff;
-+ } else {
-+ z1 = qoz_inw(qoztmp,qoz_A_Z1) & 0x3ff;
-+ z2 = qoz_inw(qoztmp,qoz_A_Z2) & 0x3ff;
-+ }
-+ }
-+
-+ if (qoztmp->type == 0xb552) {
-+ len = z1 - z2;
-+ if (len < 0) {
-+ len += qoz_DFIFO_SIZE8;
-+ }
-+ } else {
-+ len = z1 - z2;
-+ if (len < 0) {
-+ len += qoz_DFIFO_SIZE4;
-+ }
-+ }
-+
-+ if (len > qoz_DFIFO_SIZE4) {
-+ printk(KERN_INFO "\nqozap: buffer overflow in D channel RX!\n");
-+ qoztmp->ztdev->chans[stport][2].bytes2receive = 0;
-+ qoztmp->ztdev->chans[stport][2].eofrx = 0;
-+ } else {
-+ if (debug > 1) printk(KERN_INFO "qozap: card %d span %d RX [ ", qoztmp->cardno, stport + 1);
-+ for (i=0; i<len; i++) {
-+ data = qoz_inb(qoztmp,qoz_A_FIFO_DATA0);
-+ qoztmp->drxbuf[stport][i] = data;
-+ if (debug > 1) printk("%#x ",data);
-+ }
-+ if (debug > 1) printk("] %d bytes\n", len);
-+ qoztmp->ztdev->chans[stport][2].bytes2receive = i;
-+ qoztmp->ztdev->chans[stport][2].eofrx = 1;
-+ }
-+
-+ stat = qoz_inb(qoztmp,qoz_A_FIFO_DATA0);
-+ if (stat != 0x0) {
-+ // bad CRC, skip it
-+ printk(KERN_INFO "qozap: CRC error for HDLC frame on card %d (cardID %d) S/T port %d\n",qoztmp->cardno, qoztmp->cardID, stport+1);
-+ qoztmp->ztdev->chans[stport][2].bytes2receive = 0;
-+ qoztmp->ztdev->chans[stport][2].eofrx = 0;
-+// zt_qevent_nolock(&qoztmp->ztdev->chans[stport][2], ZT_EVENT_BADFCS);
-+ }
-+ qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x1);
-+ qoz_waitbusy(qoztmp);
-+
-+ /* frame recevived */
-+ if (qoztmp->st[stport].drx > 0) {
-+ qoztmp->st[stport].drx--;
-+ } else {
-+ printk(KERN_INFO "qozap: trying to receive too much (card %d span %d drx %d)\n", qoztmp->cardno, stport+1, qoztmp->st[stport].drx);
-+ qoztmp->st[stport].drx = 0;
-+ }
-+ return 0;
-+}
-+
-+
-+static int qoz_fifo_rx(struct qoz_card *qoztmp, char fifo) {
-+ int stport = fifo / 2;
-+ int chan = fifo % 2;
-+ unsigned char data;
-+ int len,i;
-+ unsigned short z1=1,z2=1;
-+ unsigned short oz1=0,oz2=0;
-+ int mumbojumbo=0;
-+
-+ /* select rx fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,0x80 | (fifo << 1) | 1);
-+ qoz_waitbusy(qoztmp);
-+
-+ while ((oz1 != z1) && (oz2 != z2)) {
-+ oz1 = z1;
-+ oz2 = z2;
-+ z1 = qoz_inw(qoztmp,qoz_A_Z1) & 0x7f;
-+ z2 = qoz_inw(qoztmp,qoz_A_Z2) & 0x7f;
-+ }
-+ len = z1 - z2;
-+ if (len < 0) {
-+ len += qoz_FIFO_SIZE;
-+ }
-+ if (len > 2 * ZT_CHUNKSIZE) {
-+ mumbojumbo = len - (2 * ZT_CHUNKSIZE);
-+ len = ZT_CHUNKSIZE;
-+ for (i=0;i<mumbojumbo;i++) {
-+ data = qoz_inb(qoztmp,qoz_A_FIFO_DATA0);
-+ }
-+ qoztmp->clicks++;
-+ if ((qoztmp->clicks > 1) || (debug == 4)) {
-+ printk(KERN_CRIT "qozap: dropped audio card %d cardid %d bytes %d z1 %d z2 %d\n", qoztmp->cardno, qoztmp->cardID, mumbojumbo, z1, z2);
-+ qoztmp->clicks = 0;
-+ }
-+ }
-+ if (len < ZT_CHUNKSIZE) {
-+// printk(KERN_INFO "qozap: not enough to receive (%d bytes)\n",len);
-+ return 0;
-+ } else {
-+ if (bloop) {
-+ *((unsigned int *) &qoztmp->txbuf[stport][chan][0]) = qoz_indw(qoztmp,qoz_A_FIFO_DATA0);
-+ *((unsigned int *) &qoztmp->txbuf[stport][chan][4]) = qoz_indw(qoztmp,qoz_A_FIFO_DATA0);
-+ } else {
-+ *((unsigned int *) &qoztmp->rxbuf[stport][chan][0]) = qoz_indw(qoztmp,qoz_A_FIFO_DATA0);
-+ *((unsigned int *) &qoztmp->rxbuf[stport][chan][4]) = qoz_indw(qoztmp,qoz_A_FIFO_DATA0);
-+ }
-+ }
-+ if (bloop == 0)
-+ zt_ec_chunk(&qoztmp->ztdev->spans[stport].chans[chan], qoztmp->ztdev->spans[stport].chans[chan].readchunk, qoztmp->ztdev->spans[stport].chans[chan].writechunk);
-+
-+// printk(KERN_INFO "s/t port %d, channel %d, dbufi=%d, f1=%d, f2=%d, z1=%d, z2=%d => len = %d stat=%#x, hdlc=%d\n",stport,chan,qoztmp->st[stport].dbufi,f1,f2,z1,z2,len,stat,hdlc);
-+ return 0;
-+}
-+
-+
-+static inline void qoz_run(struct qoz_card *qoztmp) {
-+ int s=0;
-+ if (qoztmp->ztdev != NULL) {
-+ for (s=0;s<qoztmp->stports;s++) {
-+ if (!bloop) {
-+ if (qoztmp->ztdev->spans[s].flags & ZT_FLAG_RUNNING) {
-+ /* oh zaptel! tell us what to transmit... */
-+ zt_transmit(&qoztmp->ztdev->spans[s]);
-+ /* B1 xmit */
-+ qoz_fifo_tx(qoztmp, s * 2);
-+ /* B2 xmit */
-+ qoz_fifo_tx(qoztmp, (s * 2) + 1);
-+
-+ if ((qoztmp->st[s].layer1state != 7) && (qoztmp->ztdev->chans[s][2].bytes2transmit > 0) && (qoztmp->st[s].nt_mode != 1)) {
-+ if (qoztmp->st[s].t3 == -1) {
-+ printk(KERN_INFO "qozap: activating layer 1, span %d\n",s);
-+ qoztmp->st[s].t3 = 0;
-+ qoz_outb(qoztmp,qoz_R_ST_SEL, s);
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x60);
-+ } else {
-+ }
-+ }
-+
-+ /* D xmit */
-+ if (qoztmp->ztdev->spans[s].alarms != ZT_ALARM_RED) {
-+ qoz_dfifo_tx(qoztmp, s);
-+ } else {
-+ if ((qoztmp->st[s].t3 == -1) && (qoztmp->st[s].t4 == -1) && (qoztmp->st[s].layer1state == 3) && (qoztmp->st[s].nt_mode != 1)) {
-+ /* clear alarms */
-+ printk(KERN_INFO "qozap: clearing alarms on span %d\n",s);
-+ qoztmp->ztdev->spans[s].alarms = ZT_ALARM_NONE;
-+ zt_alarm_notify(&qoztmp->ztdev->spans[s]);
-+ }
-+ }
-+
-+ qoztmp->ztdev->chans[s][2].bytes2receive = 0;
-+ qoztmp->ztdev->chans[s][2].bytes2transmit = 0;
-+ qoztmp->ztdev->chans[s][2].eofrx = 0;
-+ qoztmp->ztdev->chans[s][2].eoftx = 0;
-+
-+ }
-+
-+ /* B1 receive */
-+ qoz_fifo_rx(qoztmp,(s*2));
-+ /* B2 receive */
-+ qoz_fifo_rx(qoztmp,(s*2)+1);
-+ /* d-chan data */
-+ if (qoztmp->st[s].drx > 0) {
-+ if (debug > 2)
-+ printk(KERN_CRIT "qozap: card %d st[%d].drx = %d\n", qoztmp->cardno, s, qoztmp->st[s].drx);
-+ qoz_dfifo_rx(qoztmp, s);
-+ }
-+ if (qoztmp->ztdev->spans[s].flags & ZT_FLAG_RUNNING) {
-+ /* oh zaptel! thou shall receive! */
-+ zt_receive(&(qoztmp->ztdev->spans[s]));
-+ }
-+ } else {
-+ // loop
-+ /* B1 receive */
-+ qoz_fifo_rx(qoztmp,(s*2));
-+ /* B2 receive */
-+ qoz_fifo_rx(qoztmp,(s*2)+1);
-+ /* d-chan data */
-+/* if (qoztmp->st[s].drx > 0) {
-+ if (debug > 2)
-+ printk(KERN_CRIT "qozap: card %d st[%d].drx = %d\n", qoztmp->cardno, s, qoztmp->st[s].drx);
-+ qoz_dfifo_rx(qoztmp, s);
-+ }
-+ if (qoztmp->ztdev->spans[s].flags & ZT_FLAG_RUNNING) {
-+ zt_receive(&(qoztmp->ztdev->spans[s]));
-+ }
-+*/
-+ if (qoztmp->ztdev->spans[s].flags & ZT_FLAG_RUNNING) {
-+ /* oh zaptel! tell us what to transmit... */
-+ // zt_transmit(&qoztmp->ztdev->spans[s]);
-+ /* B1 xmit */
-+ qoz_fifo_tx(qoztmp, s * 2);
-+ /* B2 xmit */
-+ qoz_fifo_tx(qoztmp, (s * 2) + 1);
-+ /* D xmit */
-+// qoz_dfifo_tx(qoztmp, s);
-+
-+ qoztmp->ztdev->chans[s][2].bytes2receive = 0;
-+ qoztmp->ztdev->chans[s][2].bytes2transmit = 0;
-+ qoztmp->ztdev->chans[s][2].eofrx = 0;
-+ qoztmp->ztdev->chans[s][2].eoftx = 0;
-+
-+ }
-+ }
-+ }
-+ }
-+}
-+
-+#ifdef LINUX26
-+static irqreturn_t qoz_interrupt(int irq, void *dev_id, struct pt_regs *regs) {
-+#else
-+static void qoz_interrupt(int irq, void *dev_id, struct pt_regs *regs) {
-+#endif
-+ struct qoz_card *qoztmp = dev_id;
-+ struct zt_qoz *ztqoz = qoztmp->ztdev;
-+ unsigned long flags;
-+ unsigned char irq_misc,irq_sci,status,l1state,irq_foview,fi;
-+ int st=0,i=0,offset=0;
-+ int j=0;
-+
-+ if (!qoztmp) {
-+#ifdef LINUX26
-+ return IRQ_NONE;
-+#else
-+ return;
-+#endif
-+ }
-+
-+ if ((!qoztmp->pci_io) || (!qoztmp->ioport)) {
-+ printk(KERN_CRIT "qozap: no pci mem/io\n");
-+#ifdef LINUX26
-+ return IRQ_NONE;
-+#else
-+ return;
-+#endif
-+ }
-+
-+ spin_lock_irqsave(&(qoztmp->lock),flags);
-+ status = qoz_inb(qoztmp,qoz_R_STATUS);
-+ irq_sci = qoz_inb(qoztmp,qoz_R_SCI);
-+
-+ if (!(status & 0x80) && !(status & 0x40) && (irq_sci == 0)) {
-+// printk(KERN_CRIT "qozap: status %#x\n", status);
-+ // it's not us!
-+ spin_unlock_irqrestore(&(qoztmp->lock),flags);
-+#ifdef LINUX26
-+ return IRQ_NONE;
-+#else
-+ return;
-+#endif
-+ }
-+ /* state machine irq */
-+ if (irq_sci != 0) {
-+ if (debug > 1) {
-+ printk(KERN_INFO "R_BERT_STA = %#x\n", qoz_inb(qoztmp, qoz_R_BERT_STA) & 7);
-+ }
-+ for (st=0;st<qoztmp->stports;st++) {
-+ if (irq_sci & (1 << st)) {
-+ qoz_outb(qoztmp,qoz_R_ST_SEL,st);
-+ l1state = qoz_inb(qoztmp,qoz_A_ST_RD_STA) & 0xf;
-+ if (debug > 1) {
-+ printk(KERN_INFO "A_ST_RD_STA = %#x\n", qoz_inb(qoztmp, qoz_A_ST_RD_STA));
-+ }
-+ qoztmp->st[st].layer1state = l1state;
-+ if (qoztmp->st[st].nt_mode == 1) {
-+ if (debug)
-+ printk(KERN_INFO "card %d span %d state G%d (A_ST_RD_STA = %#x)\n",qoztmp->cardno,st+1,l1state,qoz_inb(qoztmp,qoz_A_ST_RD_STA));
-+ // NT state machine
-+ if (l1state == 3) {
-+ // keep layer1 up!
-+ if (qoztmp->stports == 8) {
-+ sprintf(ztqoz->spans[st].desc,"octoBRI PCI ISDN Card %d Span %d [NT] Layer 1 ACTIVATED (G%d)",qoztmp->cardno ,st + 1, l1state);
-+ } else {
-+ sprintf(ztqoz->spans[st].desc,"quadBRI PCI ISDN Card %d Span %d [NT] (cardID %d) Layer 1 ACTIVATED (G%d)",qoztmp->cardno ,st + 1,ztqoz->card->cardID, l1state);
-+ }
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,3 | 0x10 );
-+ qoztmp->leds[st] = 1;
-+ } else {
-+ if (qoztmp->stports == 8) {
-+ sprintf(ztqoz->spans[st].desc,"octoBRI PCI ISDN Card %d Span %d [NT] Layer 1 DEACTIVATED (G%d)",qoztmp->cardno ,st + 1, l1state);
-+ } else {
-+ sprintf(ztqoz->spans[st].desc,"quadBRI PCI ISDN Card %d Span %d [NT] (cardID %d) Layer 1 DEACTIVATED (G%d)",qoztmp->cardno ,st + 1,ztqoz->card->cardID, l1state);
-+ }
-+ qoztmp->leds[st] = 0;
-+ }
-+ } else {
-+ if (debug)
-+ printk(KERN_INFO "card %d span %d state F%d (A_ST_RD_STA = %#x)\n",qoztmp->cardno,st+1,l1state,qoz_inb(qoztmp,qoz_A_ST_RD_STA));
-+ // TE state machine
-+ if (l1state == 3) {
-+ if (qoztmp->st[st].t3 > -1) {
-+ /* keep layer1 up, if the span is started. */
-+ if (qoztmp->ztdev->spans[st].flags & ZT_FLAG_RUNNING) {
-+printk("qozap: re-activating layer1 span %d\n", st);
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x60);
-+ }
-+ } else {
-+printk("qozap: not re-activating layer1 span %d\n", st);
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x40);
-+ /* if we tried to activate layer 1 and it failed make this an alarm */
-+// qoztmp->ztdev->spans[st].alarms = ZT_ALARM_RED;
-+// zt_alarm_notify(&qoztmp->ztdev->spans[st]);
-+ /* if the network shuts us down in idle mode dont make this an alarm */
-+ }
-+ qoztmp->leds[st] = 0;
-+ if (qoztmp->stports == 8) {
-+ sprintf(ztqoz->spans[st].desc,"octoBRI PCI ISDN Card %d Span %d [TE] Layer 1 DEACTIVATED (F%d)",qoztmp->cardno ,st + 1, l1state);
-+ } else {
-+ sprintf(ztqoz->spans[st].desc,"quadBRI PCI ISDN Card %d Span %d [TE] (cardID %d) Layer 1 DEACTIVATED (F%d)",qoztmp->cardno ,st + 1,ztqoz->card->cardID, l1state);
-+ }
-+ } else if (l1state == 7) {
-+ /* activation complete, stop timer t3 */
-+ qoztmp->st[st].t3 = -1;
-+ qoztmp->ztdev->spans[st].alarms = ZT_ALARM_NONE;
-+ zt_alarm_notify(&qoztmp->ztdev->spans[st]);
-+ qoztmp->leds[st] = 1;
-+ if (qoztmp->stports == 8) {
-+ sprintf(ztqoz->spans[st].desc,"octoBRI PCI ISDN Card %d Span %d [TE] Layer 1 ACTIVATED (F%d)",qoztmp->cardno ,st + 1, l1state);
-+ } else {
-+ sprintf(ztqoz->spans[st].desc,"quadBRI PCI ISDN Card %d Span %d [TE] (cardID %d) Layer 1 ACTIVATED (F%d)",qoztmp->cardno ,st + 1,ztqoz->card->cardID, l1state);
-+ }
-+ } else if (l1state == 8) {
-+ /* lost framing */
-+ printk(KERN_INFO "qozap: starting t4 for span %d\n", st);
-+ qoztmp->st[st].t4 = 0;
-+ } else {
-+ if (qoztmp->stports == 8) {
-+ sprintf(ztqoz->spans[st].desc,"octoBRI PCI ISDN Card %d Span %d [TE] Layer 1 DEACTIVATED (F%d)",qoztmp->cardno ,st + 1, l1state);
-+ } else {
-+ sprintf(ztqoz->spans[st].desc,"quadBRI PCI ISDN Card %d Span %d [TE] (cardID %d) Layer 1 DEACTIVATED (F%d)",qoztmp->cardno ,st + 1,ztqoz->card->cardID, l1state);
-+ }
-+ }
-+ }
-+
-+ }
-+ }
-+ }
-+
-+
-+ // misc irq
-+ if (status & 0x40) {
-+ irq_misc = qoz_inb(qoztmp,qoz_R_IRQ_MISC);
-+ if (irq_misc & 0x2) {
-+ // qozap timer
-+ qoztmp->ticks++;
-+ qoz_run(qoztmp);
-+ if (qoztmp->ticks % 100) {
-+ qoz_doLEDs(qoztmp);
-+ }
-+ if (qoztmp->ticks % 40) {
-+ /* you thought that 42 was the answer.... */
-+ qoz_doWD(qoztmp);
-+ }
-+ if (qoztmp->ticks > 1000) {
-+ qoztmp->ticks = 0;
-+ for (j=0;j<qoztmp->stports;j++) {
-+ /* t3 */
-+ if (qoztmp->st[j].t3 >= 0) {
-+ qoztmp->st[j].t3++;
-+ }
-+ if (qoztmp->st[j].nt_mode != 1) {
-+ if ((qoztmp->st[j].t3 > qoz_T3) && (qoztmp->st[j].layer1state != 7)) {
-+ /* deactivate layer 1 */
-+ printk(KERN_INFO "qozap: t3 timer expired for span %d\n", j);
-+ qoz_outb(qoztmp,qoz_R_ST_SEL, j);
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA, 0x40 );
-+ qoztmp->st[j].t3 = -1;
-+ qoztmp->ztdev->spans[j].alarms = ZT_ALARM_RED;
-+ zt_alarm_notify(&qoztmp->ztdev->spans[j]);
-+ qoz_waitbusy(qoztmp);
-+ }
-+ }
-+ /* t4 */
-+ if (qoztmp->st[j].t4 >= 0) {
-+ qoztmp->st[j].t4++;
-+ }
-+ if (qoztmp->st[j].nt_mode != 1) {
-+ if ((qoztmp->st[j].t4 > qoz_T4) && (qoztmp->st[j].layer1state != 7)) {
-+ /* deactivate layer 1 */
-+ printk(KERN_INFO "qozap: t4 timer expired for span %d\n", j);
-+ qoz_outb(qoztmp,qoz_R_ST_SEL, j);
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA, 0x40 );
-+ qoztmp->st[j].t4 = -1;
-+ qoztmp->ztdev->spans[j].alarms = ZT_ALARM_RED;
-+ zt_alarm_notify(&qoztmp->ztdev->spans[j]);
-+ qoz_waitbusy(qoztmp);
-+ }
-+ }
-+ }
-+ }
-+ }
-+ if (irq_misc & 0x4) {
-+ // printk(KERN_INFO "qozap proc/nonproc irq\n");
-+ }
-+ }
-+ if (status & 0x80) {
-+ /* fifo irq */
-+ irq_foview = qoz_inb(qoztmp,qoz_R_IRQ_OVIEW);
-+ if (qoztmp->type == 0xb552) {
-+ if (irq_foview & 0x60) {
-+ offset = 0;
-+ fi = qoz_inb(qoztmp,qoz_R_IRQ_FIFO_BL6);
-+ for (i=0; i < 8; i++) {
-+ if (fi & (1 << i)) {
-+ st = offset + (i / 2);
-+ if (i % 2) {
-+ if (debug > 2)
-+ printk(KERN_CRIT "qozap: HDLC RX irq fifo %d span %d\n", i, st+1);
-+ qoztmp->st[st].drx += 1;
-+ } else {
-+ if (debug > 2)
-+ printk(KERN_CRIT "qozap: HDLC TX irq fifo %d span %d\n", i, st+1);
-+ }
-+ }
-+ }
-+ }
-+ if (irq_foview & 0x80) {
-+ offset = 4;
-+ fi = qoz_inb(qoztmp,qoz_R_IRQ_FIFO_BL7);
-+ for (i=0; i < 8; i++) {
-+ if (fi & (1 << i)) {
-+ st = offset + (i / 2);
-+ if (i % 2) {
-+ if (debug > 2)
-+ printk(KERN_CRIT "qozap: HDLC RX irq fifo %d span %d\n", i, st+1);
-+ qoztmp->st[st].drx += 1;
-+ } else {
-+ if (debug > 2)
-+ printk(KERN_CRIT "qozap: HDLC TX irq fifo %d span %d\n", i, st+1);
-+ }
-+ }
-+ }
-+ }
-+ } else {
-+ if (irq_foview & 0x80) {
-+ fi = qoz_inb(qoztmp,qoz_R_IRQ_FIFO_BL7);
-+ for (i=0; i < 8; i++) {
-+ if (fi & (1 << i)) {
-+ st = i / 2;
-+ if (i % 2) {
-+ if (debug > 2)
-+ printk(KERN_CRIT "qozap: HDLC RX irq fifo %d span %d\n", i, st+1);
-+ qoztmp->st[st].drx += 1;
-+ } else {
-+ if (debug > 2)
-+ printk(KERN_CRIT "qozap: HDLC TX irq fifo %d span %d\n", i, st+1);
-+ }
-+ }
-+ }
-+ }
-+ }
-+ }
-+
-+ spin_unlock_irqrestore(&(qoztmp->lock),flags);
-+#ifdef LINUX26
-+ return IRQ_RETVAL(1);
-+#endif
-+}
-+
-+static int ztqoz_open(struct zt_chan *chan) {
-+// printk(KERN_INFO "qozap: channel %d opened.\n",chan->channo);
-+#ifndef LINUX26
-+ MOD_INC_USE_COUNT;
-+#else
-+ try_module_get(THIS_MODULE);
-+#endif
-+ return 0;
-+}
-+
-+static int ztqoz_close(struct zt_chan *chan) {
-+// printk(KERN_INFO "qozap: channel %d closed.\n",chan->channo);
-+#ifndef LINUX26
-+ MOD_DEC_USE_COUNT;
-+#else
-+ module_put(THIS_MODULE);
-+#endif
-+ return 0;
-+}
-+
-+static int ztqoz_rbsbits(struct zt_chan *chan, int bits) {
-+ return 0;
-+}
-+
-+static int ztqoz_ioctl(struct zt_chan *chan, unsigned int cmd, unsigned long data) {
-+ switch(cmd) {
-+ default:
-+ return -ENOTTY;
-+ }
-+ return 0;
-+}
-+
-+static int ztqoz_startup(struct zt_span *span) {
-+ struct zt_qoz *qozt = span->pvt;
-+ struct qoz_card *qoztmp = qozt->card;
-+ unsigned long flags;
-+ int alreadyrunning;
-+ int i=0;
-+ int offset = 0;
-+
-+ if (qoztmp == NULL) {
-+ printk(KERN_INFO "qozap: no card for span at startup!\n");
-+ }
-+
-+ alreadyrunning = span->flags & ZT_FLAG_RUNNING;
-+// printk(KERN_CRIT "already running %d flags %d\n", alreadyrunning, span->flags);
-+
-+ if (!alreadyrunning) {
-+ span->chans[2].flags &= ~ZT_FLAG_HDLC;
-+ span->chans[2].flags |= ZT_FLAG_BRIDCHAN;
-+
-+ /* setup B channel buffers (8 bytes each) */
-+ for (i=0; i<2 ; i++) {
-+ memset(qoztmp->rxbuf[span->offset][i],0x0,sizeof(qoztmp->rxbuf[span->offset][i]));
-+ span->chans[i].readchunk = qoztmp->rxbuf[span->offset][i];
-+ memset(qoztmp->txbuf[span->offset][i],0x0,sizeof(qoztmp->txbuf[span->offset][i]));
-+ span->chans[i].writechunk = qoztmp->txbuf[span->offset][i];
-+ }
-+ /* setup D channel buffer */
-+ memset(qoztmp->dtxbuf[span->offset],0x0,sizeof(qoztmp->dtxbuf[span->offset]));
-+ span->chans[2].writechunk = qoztmp->dtxbuf[span->offset];
-+ qoztmp->ztdev->chans[span->offset][2].maxbytes2transmit = sizeof(qoztmp->dtxbuf[span->offset]);
-+
-+ memset(qoztmp->drxbuf[span->offset],0x0,sizeof(qoztmp->drxbuf[span->offset]));
-+ span->chans[2].readchunk = qoztmp->drxbuf[span->offset];
-+
-+ span->flags |= ZT_FLAG_RUNNING;
-+ } else {
-+// printk(KERN_CRIT "already running\n");
-+ return 0;
-+ }
-+
-+ spin_lock_irqsave(&qoztmp->lock,flags);
-+ // irqs off
-+ qoz_outb(qoztmp,qoz_R_IRQ_CTRL, 0);
-+
-+ if (qoztmp->type == 0xb552) {
-+ offset = 24;
-+ } else {
-+ offset = 28;
-+ }
-+
-+ /* setup D-FIFO TX */
-+ qoz_outb(qoztmp,qoz_R_FIFO,(span->offset + offset) << 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x2);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0xD);
-+ qoz_outb(qoztmp,qoz_A_SUBCH_CFG,0x2);
-+ qoz_outb(qoztmp,qoz_A_CHANNEL,((span->offset * 4) + 2) << 1);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x1);
-+
-+ /* setup D-FIFO RX */
-+ qoz_outb(qoztmp,qoz_R_FIFO,((span->offset + offset) << 1) | 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x2);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0xD);
-+ qoz_outb(qoztmp,qoz_A_SUBCH_CFG,0x2);
-+ qoz_outb(qoztmp,qoz_A_CHANNEL,(((span->offset * 4) + 2) << 1) | 1);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x1);
-+
-+ /* setup B1-FIFO TX */
-+ qoz_outb(qoztmp,qoz_R_FIFO,(span->offset * 2) << 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x2);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x2);
-+ qoz_outb(qoztmp,qoz_A_CHANNEL,(span->offset * 4) << 1);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x1);
-+
-+ /* setup B1-FIFO RX */
-+ qoz_outb(qoztmp,qoz_R_FIFO,((span->offset * 2) << 1) | 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x2);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x2);
-+ qoz_outb(qoztmp,qoz_A_CHANNEL,((span->offset * 4) << 1) | 1);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x1);
-+
-+ /* setup B2-FIFO TX */
-+ qoz_outb(qoztmp,qoz_R_FIFO,((span->offset * 2) + 1) << 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x2);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x2);
-+ qoz_outb(qoztmp,qoz_A_CHANNEL,((span->offset * 4) + 1) << 1);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x1);
-+
-+ /* setup B2-FIFO RX */
-+ qoz_outb(qoztmp,qoz_R_FIFO,(((span->offset * 2) + 1) << 1) | 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x2);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x2);
-+ qoz_outb(qoztmp,qoz_A_CHANNEL,((((span->offset) * 4) + 1) << 1) | 1);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x1);
-+
-+ if (debug)
-+ printk(KERN_INFO "qozap: starting card %d span %d/%d.\n",qoztmp->cardno,span->spanno,span->offset);
-+
-+ /* activate layer 1 */
-+ qoz_outb(qoztmp,qoz_R_ST_SEL,span->offset);
-+ if (qoztmp->st[span->offset].nt_mode == 1) {
-+ // NT mode
-+ qoz_outb(qoztmp,qoz_A_ST_CTRL0,0x7);
-+ qoz_outb(qoztmp,qoz_A_ST_CTRL1,0x0);
-+ qoz_outb(qoztmp,qoz_A_ST_CTRL2,0x3);
-+ qoz_outb(qoztmp,qoz_A_ST_CLK_DLY,0x60 | CLKDEL_NT);
-+ } else {
-+ // TE mode
-+ qoz_outb(qoztmp,qoz_A_ST_CTRL0,0x3);
-+ qoz_outb(qoztmp,qoz_A_ST_CTRL1,0x0);
-+ qoz_outb(qoztmp,qoz_A_ST_CTRL2,0x3);
-+ if (qoztmp->type == 0xb550) {
-+ qoz_outb(qoztmp,qoz_A_ST_CLK_DLY,CLKDEL_TE);
-+ } else {
-+ qoz_outb(qoztmp,qoz_A_ST_CLK_DLY,CLKDEL_TE + 1);
-+ }
-+ }
-+ qoztmp->st[span->offset].t3 = 0;
-+ qoztmp->st[span->offset].t4 = -1;
-+
-+ qoz_outb(qoztmp,qoz_R_ST_SEL,span->offset);
-+ if (qoztmp->st[span->offset].nt_mode == 1) {
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x80);
-+ } else {
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x0);
-+ }
-+ /* enable irqs */
-+ qoz_outb(qoztmp,qoz_R_IRQ_CTRL, 8 | 1);
-+ spin_unlock_irqrestore(&qoztmp->lock,flags);
-+
-+ qoz_outb(qoztmp,qoz_R_ST_SEL,span->offset);
-+ if (qoztmp->st[span->offset].nt_mode == 1) {
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x60 | 0x80); // ACT, G2->G3 EN
-+ } else {
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x60); // start Activation
-+ }
-+
-+ return 0;
-+}
-+
-+static int ztqoz_shutdown(struct zt_span *span) {
-+ struct zt_qoz *ztqoz = span->pvt;
-+ struct qoz_card *qoztmp = ztqoz->card;
-+ int alreadyrunning;
-+ int offset = 0;
-+
-+ if (qoztmp == NULL) {
-+ printk(KERN_CRIT "qozap: qoztmp == NULL!\n");
-+ return 0;
-+
-+ }
-+
-+ alreadyrunning = span->flags & ZT_FLAG_RUNNING;
-+
-+ if (!alreadyrunning) {
-+ return 0;
-+ }
-+
-+// printk(KERN_CRIT "qozap: stopping card %d port %d.\n",qoztmp->cardno, span->offset + 1);
-+
-+ // turn off irqs for all fifos
-+ if (qoztmp->type == 0xb552) {
-+ offset = 24;
-+ } else {
-+ offset = 28;
-+ }
-+
-+ /* disable D TX fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,(span->offset + offset) << 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x1);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x0);
-+
-+ /* disable D RX fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,((span->offset + offset) << 1) | 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x1);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x0);
-+
-+ /* disable B1 TX fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,(span->offset * 2) << 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x2);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x0);
-+
-+ /* disable B1 RX fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,((span->offset * 2) << 1) | 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x2);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x0);
-+
-+ /* disable B2 TX fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,(((span->offset) * 2) + 1) << 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x2);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x0);
-+
-+ /* disable B2 RX fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,((((span->offset) * 2) + 1) << 1) | 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x2);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x0);
-+
-+ span->flags &= ~ZT_FLAG_RUNNING;
-+
-+ /* Deactivate Layer 1 */
-+ qoz_outb(qoztmp,qoz_R_ST_SEL,span->offset);
-+ if (qoztmp->st[span->offset].nt_mode == 1) {
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x40);
-+ } else {
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x40);
-+ }
-+
-+
-+// printk(KERN_CRIT "qozap: card %d span %d/%d down.\n",qoztmp->cardno,span->spanno,span->offset);
-+ return 0;
-+}
-+
-+static int ztqoz_maint(struct zt_span *span, int cmd) {
-+ return 0;
-+}
-+
-+static int ztqoz_chanconfig(struct zt_chan *chan,int sigtype) {
-+// printk(KERN_INFO "chan_config sigtype=%d\n",sigtype);
-+ return 0;
-+}
-+
-+static int ztqoz_spanconfig(struct zt_span *span,struct zt_lineconfig *lc) {
-+// span->lineconfig = lc->lineconfig;
-+ return 0;
-+}
-+
-+static int ztqoz_initialize(struct zt_qoz *ztqoz) {
-+ struct qoz_card *qoztmp = ztqoz->card;
-+ int i=0,s=0;
-+
-+ for (s=0; s < ztqoz->card->stports; s++) {
-+ memset(&ztqoz->spans[s],0,sizeof(struct zt_span)); // you never can tell...
-+ sprintf(ztqoz->spans[s].name,"ztqoz/%d/%d",qoz_dev_count + 1,s + 1);
-+ if (ztqoz->card->stports == 8) {
-+ if (qoztmp->st[s].nt_mode == 1){
-+ sprintf(ztqoz->spans[s].desc,"octoBRI PCI ISDN Card %d Span %d [NT]",qoztmp->cardno,s + 1);
-+ } else {
-+ sprintf(ztqoz->spans[s].desc,"octoBRI PCI ISDN Card %d Span %d [TE]",qoztmp->cardno,s + 1);
-+ }
-+ } else {
-+ if (ztqoz->card->cardID < 0xff) {
-+ if (qoztmp->st[s].nt_mode == 1){
-+ sprintf(ztqoz->spans[s].desc,"quadBRI PCI ISDN Card %d Span %d [NT] (cardID %d)",qoztmp->cardno,s + 1,ztqoz->card->cardID);
-+ } else {
-+ sprintf(ztqoz->spans[s].desc,"quadBRI PCI ISDN Card %d Span %d [TE] (cardID %d)",qoztmp->cardno,s + 1,ztqoz->card->cardID);
-+ }
-+ } else {
-+ if (qoztmp->st[s].nt_mode == 1){
-+ sprintf(ztqoz->spans[s].desc,"quadBRI PCI ISDN Card %d Span %d [NT]",qoztmp->cardno,s + 1);
-+ } else {
-+ sprintf(ztqoz->spans[s].desc,"quadBRI PCI ISDN Card %d Span %d [TE]",qoztmp->cardno,s + 1);
-+ }
-+ }
-+ }
-+
-+ ztqoz->spans[s].spanconfig = ztqoz_spanconfig;
-+ ztqoz->spans[s].chanconfig = ztqoz_chanconfig;
-+ ztqoz->spans[s].startup = ztqoz_startup;
-+ ztqoz->spans[s].shutdown = ztqoz_shutdown;
-+ ztqoz->spans[s].maint = ztqoz_maint;
-+ ztqoz->spans[s].rbsbits = ztqoz_rbsbits;
-+ ztqoz->spans[s].open = ztqoz_open;
-+ ztqoz->spans[s].close = ztqoz_close;
-+ ztqoz->spans[s].ioctl = ztqoz_ioctl;
-+
-+ ztqoz->spans[s].chans = ztqoz->chans[s];
-+ ztqoz->spans[s].channels = 3;
-+ ztqoz->spans[s].deflaw = ZT_LAW_ALAW;
-+ ztqoz->spans[s].linecompat = ZT_CONFIG_AMI | ZT_CONFIG_CCS; // <--- this is really BS
-+ init_waitqueue_head(&ztqoz->spans[s].maintq);
-+ ztqoz->spans[s].pvt = ztqoz;
-+ ztqoz->spans[s].offset = s;
-+
-+ for (i=0; i < ztqoz->spans[s].channels; i++) {
-+ memset(&(ztqoz->chans[s][i]),0x0,sizeof(struct zt_chan));
-+ sprintf(ztqoz->chans[s][i].name,"ztqoz%d/%d/%d",qoz_dev_count + 1,s + 1,i + 1);
-+ ztqoz->chans[s][i].pvt = ztqoz;
-+ ztqoz->chans[s][i].sigcap = ZT_SIG_EM | ZT_SIG_CLEAR | ZT_SIG_FXSLS | ZT_SIG_FXSGS | ZT_SIG_FXSKS | ZT_SIG_FXOLS | ZT_SIG_FXOGS | ZT_SIG_FXOKS | ZT_SIG_CAS | ZT_SIG_SF;
-+ ztqoz->chans[s][i].chanpos = i + 1;
-+ }
-+
-+ if (zt_register(&ztqoz->spans[s],0)) {
-+ printk(KERN_INFO "qozap: unable to register zaptel span %d!\n",s+1);
-+ return -1;
-+ }
-+// printk(KERN_INFO "qozap: registered zaptel span %d.\n",s+1);
-+ }
-+
-+ return 0;
-+}
-+
-+int qoz_findCards(unsigned int pcidid) {
-+ struct pci_dev *tmp;
-+ struct qoz_card *qoztmp = NULL;
-+ struct zt_qoz *ztqoz = NULL;
-+ int i=0;
-+ unsigned char dips=0;
-+ int cid=0;
-+ int modes=0;
-+ tmp = pci_find_device(PCI_VENDOR_ID_CCD,pcidid,multi_qoz);
-+ while (tmp != NULL) {
-+ multi_qoz = tmp; // skip this next time.
-+
-+ if (pci_enable_device(tmp)) {
-+ multi_qoz = NULL;
-+ return -1;
-+ }
-+
-+ qoztmp = kmalloc(sizeof(struct qoz_card),GFP_KERNEL);
-+ if (!qoztmp) {
-+ printk(KERN_WARNING "qozap: unable to kmalloc!\n");
-+ pci_disable_device(tmp);
-+ multi_qoz = NULL;
-+ return -ENOMEM;
-+ }
-+ memset(qoztmp, 0x0, sizeof(struct qoz_card));
-+
-+ spin_lock_init(&qoztmp->lock);
-+ qoztmp->pcidev = tmp;
-+ qoztmp->pcibus = tmp->bus->number;
-+ qoztmp->pcidevfn = tmp->devfn;
-+
-+ if (!tmp->irq) {
-+ printk(KERN_WARNING "qozap: no irq!\n");
-+ } else {
-+ qoztmp->irq = tmp->irq;
-+ }
-+
-+ qoztmp->pci_io = (char *) tmp->resource[1].start;
-+ if (!qoztmp->pci_io) {
-+ printk(KERN_WARNING "qozap: no iomem!\n");
-+ pci_disable_device(tmp);
-+ multi_qoz = NULL;
-+ return -EIO;
-+ }
-+
-+ qoztmp->ioport = tmp->resource[0].start;
-+ if (!qoztmp->ioport) {
-+ printk(KERN_WARNING "qozap: no ioport!\n");
-+ pci_disable_device(tmp);
-+ multi_qoz = NULL;
-+ return -EIO;
-+ }
-+ if (!request_region(qoztmp->ioport, 7, "qozap")) {
-+ printk(KERN_WARNING "qozap: couldnt request io range!\n");
-+ pci_disable_device(tmp);
-+ multi_qoz = NULL;
-+ return -EIO;
-+ }
-+
-+ if (request_irq(qoztmp->irq, qoz_interrupt, SA_INTERRUPT | SA_SHIRQ, "qozap", qoztmp)) {
-+ printk(KERN_WARNING "qozap: unable to register irq\n");
-+ kfree(qoztmp);
-+ pci_disable_device(tmp);
-+ multi_qoz = NULL;
-+ return -EIO;
-+ }
-+
-+ qoztmp->pci_io = ioremap((ulong) qoztmp->pci_io, 256);
-+
-+ pci_write_config_word(qoztmp->pcidev, PCI_COMMAND, PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
-+
-+ // disable ints
-+ qoz_outb(qoztmp,qoz_R_IRQ_CTRL, 0);
-+
-+ ztqoz = kmalloc(sizeof(struct zt_qoz),GFP_KERNEL);
-+ if (!ztqoz) {
-+ printk(KERN_INFO "qozap: unable to kmalloc!\n");
-+ qoz_shutdownCard(qoztmp);
-+ kfree(qoztmp);
-+ multi_qoz = NULL;
-+ return -ENOMEM;
-+ }
-+ memset(ztqoz, 0x0, sizeof(struct zt_qoz));
-+
-+ if (pcidid == PCI_DEVICE_ID_CCD_M) {
-+ qoztmp->stports = 8;
-+ } else {
-+ qoztmp->stports = 4;
-+ }
-+
-+
-+ if ((tmp->subsystem_device==0xb520) && (pcidid == PCI_DEVICE_ID_CCD_M4)) {
-+ // printk(KERN_INFO "MODES = %#x.\n",modes);
-+ qoz_outb(qoztmp,qoz_R_GPIO_SEL,0x80 | 0x40);
-+ dips = (qoz_inb(qoztmp,qoz_R_GPIO_IN1) >> 5);
-+ cid = 7;
-+ for (i=0;i<3;i++) {
-+ if ((dips & (1 << i)) != 0) {
-+ cid -= (1 << (2-i));
-+ }
-+ }
-+ // printk(KERN_INFO "DIPS = %#x CID= %#x\n",dips,cid);
-+ } else if ((tmp->subsystem_device==0xb550) && (pcidid == PCI_DEVICE_ID_CCD_M4)) {
-+ // printk(KERN_INFO "MODES = %#x.\n",modes);
-+ dips = ~(qoz_inb(qoztmp,qoz_R_GPI_IN3) & 7);
-+ cid = 0;
-+ for (i=0;i<3;i++) {
-+ if ((dips & (1 << i)) != 0) {
-+ cid += (1 << i);
-+ }
-+ }
-+ printk(KERN_INFO "DIPS = %#x CID= %#x\n",dips,cid);
-+ } else {
-+ cid = 0xff;
-+ }
-+
-+ if (ports == -1) {
-+ if ((tmp->subsystem_device==0xb520) && (pcidid == PCI_DEVICE_ID_CCD_M4)) {
-+ modes = qoz_inb(qoztmp,qoz_R_GPI_IN3) >> 4;
-+ } else if ((tmp->subsystem_device==0xb550) && (pcidid == PCI_DEVICE_ID_CCD_M4)) {
-+ qoz_outb(qoztmp,qoz_R_GPIO_SEL,0xff);
-+ qoz_outb(qoztmp,qoz_R_GPIO_EN0,0x00);
-+ printk(KERN_CRIT "gpio_in0 %#x \n", qoz_inb(qoztmp,qoz_R_GPIO_IN0));
-+ printk(KERN_CRIT "gpio_in1 %#x \n", qoz_inb(qoztmp,qoz_R_GPIO_IN1));
-+ printk(KERN_CRIT "gpi_in1 %#x \n", qoz_inb(qoztmp,qoz_R_GPI_IN1));
-+ printk(KERN_CRIT "gpi_in2 %#x \n", qoz_inb(qoztmp,qoz_R_GPI_IN2));
-+ printk(KERN_CRIT "gpi_in3 %#x \n", qoz_inb(qoztmp,qoz_R_GPI_IN3));
-+ modes = qoz_inb(qoztmp,qoz_R_GPI_IN3) >> 4;
-+ } else {
-+ modes = 0; // assume TE mode
-+ }
-+ } else {
-+ modes = ports >> totalBRIs;
-+ }
-+
-+ if (pcidid == PCI_DEVICE_ID_CCD_M4) {
-+ switch (tmp->subsystem_device) {
-+ case 0x08b4:
-+ if (ports == -1) ports = 0; /* assume TE mode if no ports param */
-+ printk(KERN_INFO
-+ "qozap: CologneChip HFC-4S evaluation board configured at io port %#x IRQ %d HZ %d\n",
-+ (u_int) qoztmp->ioport,
-+ qoztmp->irq, HZ);
-+ break;
-+ case 0xb520:
-+ printk(KERN_INFO
-+ "qozap: Junghanns.NET quadBRI card configured at io port %#x IRQ %d HZ %d CardID %d\n",
-+ (u_int) qoztmp->ioport,
-+ qoztmp->irq, HZ, cid);
-+ break;
-+ case 0xb550:
-+ printk(KERN_INFO
-+ "qozap: Junghanns.NET quadBRI (Version 2.0) card configured at io port %#x IRQ %d HZ %d CardID %d\n",
-+ (u_int) qoztmp->ioport,
-+ qoztmp->irq, HZ, cid);
-+ break;
-+ }
-+ totalBRIs += 4;
-+ } else {
-+ switch (tmp->subsystem_device) {
-+ case 0xb552:
-+ printk(KERN_INFO
-+ "qozap: Junghanns.NET octoBRI card configured at io port %#x IRQ %d HZ %d\n",
-+ (u_int) qoztmp->ioport,
-+ qoztmp->irq, HZ);
-+ break;
-+ default:
-+ if (qoztmp->pcidev != NULL) {
-+ pci_disable_device(qoztmp->pcidev);
-+ }
-+ pci_write_config_word(qoztmp->pcidev, PCI_COMMAND, 0);
-+ free_irq(qoztmp->irq,qoztmp);
-+ kfree(qoztmp);
-+ qoztmp = NULL;
-+ tmp = pci_find_device(PCI_VENDOR_ID_CCD,pcidid,multi_qoz);
-+ continue;
-+ break;
-+ }
-+ totalBRIs += 8;
-+ }
-+
-+ qoztmp->cardID = cid;
-+ qoztmp->type = tmp->subsystem_device;
-+
-+ printk(KERN_INFO "qozap: S/T ports: %d [",qoztmp->stports);
-+ for (i=0;i<qoztmp->stports;i++) {
-+ if ((modes & (1 << i)) != 0) {
-+ qoztmp->st[i].nt_mode = 1;
-+ printk(" NT");
-+ } else {
-+ qoztmp->st[i].nt_mode = 0;
-+ printk(" TE");
-+ }
-+ }
-+ printk(" ]\n");
-+
-+ ztqoz->card = qoztmp;
-+ qoztmp->ztdev = ztqoz;
-+
-+ qoz_registerCard(qoztmp);
-+ tmp = pci_find_device(PCI_VENDOR_ID_CCD,pcidid,multi_qoz);
-+ }
-+ return 0;
-+}
-+
-+
-+int qoz_sortCards(void) {
-+ int changed=0,tmpcardno;
-+ struct qoz_card *tmpcard,*tmpcard2;
-+ spin_lock(®isterlock);
-+ do {
-+ changed = 0;
-+ tmpcard = qoz_dev_list;
-+ while (tmpcard != NULL) {
-+ if (tmpcard->prev) {
-+ if (tmpcard->prev->cardID > tmpcard->cardID) {
-+ tmpcardno = tmpcard->prev->cardno;
-+ tmpcard->prev->cardno = tmpcard->cardno;
-+ tmpcard->cardno = tmpcardno;
-+
-+ tmpcard2 = tmpcard->prev;
-+ if (tmpcard2->prev) {
-+ tmpcard2->prev->next = tmpcard;
-+ } else {
-+ qoz_dev_list = tmpcard;
-+ }
-+ if (tmpcard->next) {
-+ tmpcard->next->prev = tmpcard2;
-+ }
-+ tmpcard2->next = tmpcard->next;
-+ tmpcard->prev = tmpcard2->prev;
-+ tmpcard->next = tmpcard2;
-+ tmpcard2->prev = tmpcard;
-+ changed = 1;
-+ tmpcard = tmpcard2;
-+ }
-+ }
-+ tmpcard = tmpcard->next;
-+ }
-+ } while (changed == 1);
-+ spin_unlock(®isterlock);
-+ return 0;
-+}
-+
-+int qoz_zapCards(void) {
-+ struct qoz_card *tmpcard;
-+ tmpcard = qoz_dev_list;
-+ while (tmpcard != NULL) {
-+ ztqoz_initialize(tmpcard->ztdev);
-+ qoz_resetCard(tmpcard);
-+ tmpcard = tmpcard->next;
-+ }
-+ return 0;
-+}
-+
-+
-+int init_module(void) {
-+ multi_qoz = NULL;
-+ qoz_findCards(PCI_DEVICE_ID_CCD_M4);
-+ qoz_findCards(PCI_DEVICE_ID_CCD_M);
-+ qoz_sortCards();
-+ qoz_zapCards();
-+ if (qoz_dev_count == 0) {
-+ printk(KERN_INFO "qozap: no multiBRI cards found.\n");
-+ } else {
-+ printk(KERN_INFO "qozap: %d multiBRI card(s) in this box, %d BRI ports total, bloop %d.\n",qoz_dev_count, totalBRIs, bloop);
-+ }
-+ return 0;
-+}
-+
-+void cleanup_module(void) {
-+ struct qoz_card *tmpcard,*tmplist;
-+ int i=0;
-+ tmplist = qoz_dev_list;
-+ while (tmplist != NULL) {
-+ qoz_undoWD(tmplist);
-+ qoz_shutdownCard(tmplist);
-+ tmplist = tmplist->next;
-+ }
-+ tmplist = qoz_dev_list;
-+ spin_lock(®isterlock);
-+ while (tmplist != NULL) {
-+ tmpcard = tmplist->next;
-+ kfree(tmplist);
-+ i++;
-+ tmplist = tmpcard;
-+ }
-+ spin_unlock(®isterlock);
-+ printk(KERN_INFO "qozap: shutdown %d multiBRI cards.\n", i);
-+}
-+#endif
-+
-+MODULE_PARM(doubleclock,"i");
-+MODULE_PARM(ports,"i");
-+MODULE_PARM(bloop,"i");
-+MODULE_PARM(debug,"i");
-+MODULE_DESCRIPTION("quad/octo BRI zaptel driver");
-+MODULE_AUTHOR("Klaus-Peter Junghanns <kpj at junghanns.net>");
-+#ifdef MODULE_LICENSE
-+MODULE_LICENSE("GPL");
-+#endif
-diff -urNad zaptel-1.2.1/qozap/qozap.h /tmp/dpep.RTh8jH/zaptel-1.2.1/qozap/qozap.h
---- zaptel-1.2.1/qozap/qozap.h 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.RTh8jH/zaptel-1.2.1/qozap/qozap.h 2005-06-13 11:56:43.000000000 +0300
-@@ -0,0 +1,237 @@
-+#define qoz_SPANS 8
-+#define qoz_FIFO_SIZE 128
-+#define qoz_DFIFO_SIZE4 2048
-+#define qoz_DFIFO_SIZE8 1024
-+
-+typedef struct qoz_span {
-+ unsigned char nt_mode;
-+ unsigned char btx;
-+ unsigned char bswapped;
-+ unsigned char drx;
-+ int t3;
-+ int t4;
-+ unsigned char layer1state;
-+} qoz_span;
-+
-+typedef struct qoz_regs {
-+ unsigned char fifo_en;
-+ unsigned char ctmt;
-+ unsigned char int_m1;
-+ unsigned char int_m2;
-+ unsigned char sctrl;
-+ unsigned char sctrl_e;
-+ unsigned char sctrl_r;
-+ unsigned char connect;
-+ unsigned char trm;
-+ unsigned char mst_mode;
-+} qoz_regs;
-+
-+typedef struct qoz_card {
-+ spinlock_t lock;
-+ int cardID;
-+ unsigned char leds[8];
-+ unsigned char cardno;
-+ unsigned int irq;
-+ unsigned int iomem;
-+ unsigned char *pci_io;
-+ unsigned long ioport;
-+ struct qoz_span st[qoz_SPANS];
-+ unsigned int pcibus;
-+ unsigned int pcidevfn;
-+ struct pci_dev *pcidev;
-+ struct zt_qoz *ztdev;
-+ unsigned char rxbuf[qoz_SPANS][2][ZT_CHUNKSIZE];
-+ unsigned char txbuf[qoz_SPANS][2][ZT_CHUNKSIZE];
-+ unsigned char drxbuf[qoz_SPANS][qoz_DFIFO_SIZE4];
-+ unsigned char dtxbuf[qoz_SPANS][qoz_DFIFO_SIZE4];
-+ unsigned char stports;
-+ unsigned int ticks;
-+ unsigned int clicks;
-+ unsigned int type;
-+ unsigned int wdp;
-+ struct qoz_card *next;
-+ struct qoz_card *prev;
-+} qoz_card;
-+
-+
-+typedef struct zt_qoz {
-+ unsigned int usecount;
-+ struct zt_span spans[qoz_SPANS];
-+ struct zt_chan chans[qoz_SPANS][3];
-+ struct qoz_card *card;
-+} zt_qoz;
-+
-+#define qoz_outb_io(a,b,c) \
-+ outw((b), ((a)->ioport+4)); \
-+ outb((c), ((a)->ioport));
-+
-+#define qoz_inb_io(a,b) ({ outw((b), (a)->ioport+4); inb((a)->ioport); })
-+
-+#define qoz_outw_io(a,b,c) \
-+ outw((b), ((a)->ioport+4)); \
-+ outw((c), ((a)->ioport));
-+
-+#define qoz_inw_io(a,b) ({ outw((b), (a)->ioport+4); inw((a)->ioport); })
-+
-+#define qoz_outdw_io(a,b,c) \
-+ outw((b), ((a)->ioport+4)); \
-+ outl((c), ((a)->ioport));
-+
-+#define qoz_indw_io(a,b) ({ outw((b), (a)->ioport+4); inl((a)->ioport); })
-+
-+#define qoz_outb(a,b,c) (writeb((c),(a)->pci_io+(b)))
-+#define qoz_inb(a,b) (readb((a)->pci_io+(b)))
-+
-+#define qoz_outw(a,b,c) (writew((c),(a)->pci_io+(b)))
-+#define qoz_inw(a,b) (readw((a)->pci_io+(b)))
-+
-+#define qoz_outdw(a,b,c) (writel((c),(a)->pci_io+(b)))
-+#define qoz_indw(a,b) (readl((a)->pci_io+(b)))
-+
-+
-+/* Write only registers */
-+#define qoz_A_CH_MSK 0xF4
-+#define qoz_A_CHANNEL 0xFC
-+#define qoz_A_CON_HDLC 0xFA
-+#define qoz_A_CONF 0xD1
-+#define qoz_A_FIFO_SEQ 0xFD
-+#define qoz_R_INC_RES_FIFO 0x0E
-+#define qoz_A_IRQ_MSK 0xFF
-+#define qoz_A_SL_CFG 0xD0
-+#define qoz_A_ST_B1_TX 0x3C
-+#define qoz_A_ST_B2_TX 0x3D
-+#define qoz_A_ST_CLK_DLY 0x37
-+#define qoz_A_ST_CTRL0 0x31
-+#define qoz_A_ST_CTRL1 0x32
-+#define qoz_A_ST_CTRL2 0x33
-+#define qoz_A_ST_D_TX 0x3E
-+#define qoz_A_ST_SQ_WR 0x34
-+#define qoz_A_ST_WR_STA 0x30
-+#define qoz_A_SUBCH_CFG 0xFB
-+#define qoz_R_BERT_WD_MD 0x1B
-+#define qoz_R_BRG_CTRL 0x45
-+#define qoz_R_BRG_MD 0x47
-+#define qoz_R_BRG_PCM_CFG 0x02
-+#define qoz_R_BRG_TIM_SEL01 0x4C
-+#define qoz_R_BRG_TIM_SEL23 0x4D
-+#define qoz_R_BRG_TIM_SEL45 0x4E
-+#define qoz_R_BRG_TIM_SEL67 0x4F
-+#define qoz_R_BRG_TIM0 0x48
-+#define qoz_R_BRG_TIM1 0x49
-+#define qoz_R_BRG_TIM2 0x4A
-+#define qoz_R_BRG_TIM3 0x4B
-+#define qoz_R_CIRM 0x00
-+#define qoz_R_CONF_EN 0x18
-+#define qoz_R_CTRL 0x01
-+#define qoz_R_DTMF0 0x1C
-+#define qoz_R_DTMF1 0x1D
-+#define qoz_R_FIFO_MD 0x0D
-+#define qoz_R_FIFO 0x0F
-+#define qoz_R_FIRST_FIFO 0x0B
-+#define qoz_R_FSM_IDX 0x0F
-+#define qoz_R_GPIO_EN0 0x42
-+#define qoz_R_GPIO_EN1 0x43
-+#define qoz_R_GPIO_OUT0 0x40
-+#define qoz_R_GPIO_OUT1 0x41
-+#define qoz_R_GPIO_SEL 0x44
-+#define qoz_R_IRQ_CTRL 0x13
-+#define qoz_R_IRQMSK_MISC 0x11
-+#define qoz_R_PCM_MD0 0x14
-+#define qoz_R_PCM_MD1 0x15
-+#define qoz_R_PCM_MD2 0x15
-+#define qoz_R_PWM_MD 0x46
-+#define qoz_R_PWM0 0x38
-+#define qoz_R_PWM1 0x39
-+#define qoz_R_RAM_ADDR0 0x08
-+#define qoz_R_RAM_ADDR1 0x09
-+#define qoz_R_RAM_ADDR2 0x0A
-+#define qoz_R_RAM_MISC 0x0C
-+#define qoz_R_SCI_MSK 0x12
-+#define qoz_R_SH0H 0x15
-+#define qoz_R_SH0L 0x15
-+#define qoz_R_SH1H 0x15
-+#define qoz_R_SH1L 0x15
-+#define qoz_R_SL_SEL0 0x15
-+#define qoz_R_SL_SEL1 0x15
-+#define qoz_R_SL_SEL2 0x15
-+#define qoz_R_SL_SEL3 0x15
-+#define qoz_R_SL_SEL4 0x15
-+#define qoz_R_SL_SEL5 0x15
-+#define qoz_R_SL_SEL6 0x15
-+#define qoz_R_SL_SEL7 0x15
-+#define qoz_R_SLOT 0x10
-+#define qoz_R_ST_SEL 0x16
-+#define qoz_R_ST_SYNC 0x17
-+#define qoz_R_TI_WD 0x1A
-+
-+/* Read only registers */
-+#define qoz_A_F1 0x0C
-+#define qoz_A_F12 0x0C
-+#define qoz_A_F2 0x0D
-+#define qoz_A_ST_B1_RX 0x3C
-+#define qoz_A_ST_B2_TX 0x3D
-+#define qoz_A_ST_D_RX 0x3E
-+#define qoz_A_ST_E_RX 0x3F
-+#define qoz_A_ST_RD_STA 0x30
-+#define qoz_A_ST_SQ_RD 0x34
-+#define qoz_A_Z1 0x04
-+#define qoz_A_Z12 0x04
-+#define qoz_A_Z1H 0x05
-+#define qoz_A_Z1L 0x04
-+#define qoz_A_Z2 0x06
-+#define qoz_A_Z2H 0x07
-+#define qoz_A_Z2L 0x06
-+#define qoz_R_BERT_ECH 0x1B
-+#define qoz_R_BERT_ECL 0x1A
-+#define qoz_R_BERT_STA 0x17
-+#define qoz_R_CHIP_ID 0x16
-+#define qoz_R_CHIP_RV 0x1F
-+#define qoz_R_CONF_OFLOW 0x14
-+#define qoz_R_F0_CNTH 0x19
-+#define qoz_R_F0_CNTL 0x18
-+#define qoz_R_GPI_IN0 0x44
-+#define qoz_R_GPI_IN1 0x45
-+#define qoz_R_GPI_IN2 0x46
-+#define qoz_R_GPI_IN3 0x47
-+#define qoz_R_GPIO_IN0 0x40
-+#define qoz_R_GPIO_IN1 0x41
-+#define qoz_R_INT_DATA 0x88
-+#define qoz_R_IRQ_FIFO_BL0 0xC8
-+#define qoz_R_IRQ_FIFO_BL1 0xC9
-+#define qoz_R_IRQ_FIFO_BL2 0xCA
-+#define qoz_R_IRQ_FIFO_BL3 0xCB
-+#define qoz_R_IRQ_FIFO_BL4 0xCC
-+#define qoz_R_IRQ_FIFO_BL5 0xCD
-+#define qoz_R_IRQ_FIFO_BL6 0xCE
-+#define qoz_R_IRQ_FIFO_BL7 0xCF
-+#define qoz_R_IRQ_MISC 0x11
-+#define qoz_R_IRQ_OVIEW 0x10
-+#define qoz_R_RAM_USE 0x15
-+#define qoz_R_SCI 0x12
-+#define qoz_R_STATUS 0x1C
-+
-+/* Read/Write registers */
-+#define qoz_A_FIFO_DATA0_NOINC 0x84
-+#define qoz_A_FIFO_DATA0 0x80
-+#define qoz_A_FIFO_DATA1_NOINC 0x84
-+#define qoz_A_FIFO_DATA1 0x80
-+#define qoz_A_FIFO_DATA2_NOINC 0x84
-+#define qoz_A_FIFO_DATA2 0x80
-+#define qoz_R_RAM_DATA 0xC0
-+
-+#define PCI_DEVICE_ID_CCD_M 0x16b8
-+#define PCI_DEVICE_ID_CCD_M4 0x08b4
-+#define CLKDEL_TE 0xe /* CLKDEL in TE mode */
-+#define CLKDEL_NT 0xc /* CLKDEL in NT mode */
-+
-+#define HFC8S_CHIP_ID 0x80
-+#define HFC4S_CHIP_ID 0xC0
-+
-+#define qoz_WD_P0 0x000000
-+#define qoz_WD_P1 0x808080
-+#define qoz_WD_P2 0x404040
-+
-+#define qoz_T3 3
-+#define qoz_T4 1
-+
-+
-diff -urNad zaptel-1.2.1/qozap/TODO /tmp/dpep.RTh8jH/zaptel-1.2.1/qozap/TODO
---- zaptel-1.2.1/qozap/TODO 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.RTh8jH/zaptel-1.2.1/qozap/TODO 2005-06-13 10:03:36.000000000 +0300
-@@ -0,0 +1,9 @@
-+- native-native bridging
-+- onchip dtmf
-+- E channel support for full debug
-+
-+
-+t3 (5ms max)
-+
-+t4 (500ms) layer 1 down/up
-+
-diff -urNad zaptel-1.2.1/qozap/zapata.conf /tmp/dpep.RTh8jH/zaptel-1.2.1/qozap/zapata.conf
---- zaptel-1.2.1/qozap/zapata.conf 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.RTh8jH/zaptel-1.2.1/qozap/zapata.conf 2005-06-13 10:03:36.000000000 +0300
-@@ -0,0 +1,49 @@
-+;
-+; Zapata telephony interface
-+;
-+; Configuration file
-+
-+[channels]
-+;
-+; Default language
-+;
-+;language=en
-+;
-+; Default context
-+;
-+;
-+switchtype = euroisdn
-+
-+; p2mp TE mode (for connecting ISDN lines in point-to-multipoint mode)
-+signalling = bri_cpe_ptmp
-+; p2p TE mode (for connecting ISDN lines in point-to-point mode)
-+;signalling = bri_cpe
-+; p2mp NT mode (for connecting ISDN phones in point-to-multipoint mode)
-+;signalling = bri_net_ptmp
-+; p2p NT mode (for connecting an ISDN pbx in point-to-point mode)
-+;signalling = bri_net
-+
-+pridialplan = local
-+prilocaldialplan = local
-+nationalprefix = 0
-+internationalprefix = 00
-+
-+echocancel = yes
-+
-+context=demo
-+group = 1
-+; S/T port 1
-+channel => 1-2
-+
-+group = 2
-+; S/T port 2
-+channel => 4-5
-+
-+group = 3
-+; S/T port 3
-+channel => 7-8
-+
-+group = 4
-+; S/T port 4
-+channel => 10-11
-+
-diff -urNad zaptel-1.2.1/qozap/zapata.conf.octoBRI /tmp/dpep.RTh8jH/zaptel-1.2.1/qozap/zapata.conf.octoBRI
---- zaptel-1.2.1/qozap/zapata.conf.octoBRI 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.RTh8jH/zaptel-1.2.1/qozap/zapata.conf.octoBRI 2005-06-13 10:03:36.000000000 +0300
-@@ -0,0 +1,65 @@
-+;
-+; Zapata telephony interface
-+;
-+; Configuration file
-+
-+[channels]
-+;
-+; Default language
-+;
-+;language=en
-+;
-+; Default context
-+;
-+;
-+switchtype = euroisdn
-+
-+; p2mp TE mode (for connecting ISDN lines in point-to-multipoint mode)
-+signalling = bri_cpe_ptmp
-+; p2p TE mode (for connecting ISDN lines in point-to-point mode)
-+;signalling = bri_cpe
-+; p2mp NT mode (for connecting ISDN phones in point-to-multipoint mode)
-+;signalling = bri_net_ptmp
-+; p2p NT mode (for connecting an ISDN pbx in point-to-point mode)
-+;signalling = bri_net
-+
-+pridialplan = local
-+prilocaldialplan = local
-+nationalprefix = 0
-+internationalprefix = 00
-+
-+echocancel = yes
-+
-+context=demo
-+group = 1
-+; S/T port 1
-+channel => 1-2
-+
-+group = 2
-+; S/T port 2
-+channel => 4-5
-+
-+group = 3
-+; S/T port 3
-+channel => 7-8
-+
-+group = 4
-+; S/T port 4
-+channel => 10-11
-+
-+group = 5
-+; S/T port 5
-+channel => 13-14
-+
-+group = 6
-+; S/T port 6
-+channel => 16-17
-+
-+group = 7
-+; S/T port 7
-+channel => 19-20
-+
-+group = 8
-+; S/T port 8
-+channel => 22-23
-+
-diff -urNad zaptel-1.2.1/qozap/zaptel.conf /tmp/dpep.RTh8jH/zaptel-1.2.1/qozap/zaptel.conf
---- zaptel-1.2.1/qozap/zaptel.conf 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.RTh8jH/zaptel-1.2.1/qozap/zaptel.conf 2005-11-20 16:35:32.000000000 +0200
-@@ -0,0 +1,18 @@
-+loadzone=nl
-+defaultzone=nl
-+# qozap span definitions
-+# most of the values should be bogus because we are not really zaptel
-+span=1,1,3,ccs,ami
-+span=2,2,3,ccs,ami
-+span=3,0,3,ccs,ami
-+span=4,0,3,ccs,ami
-+
-+bchan=1,2
-+dchan=3
-+bchan=4,5
-+dchan=6
-+bchan=7,8
-+dchan=9
-+bchan=10,11
-+dchan=12
-+
-diff -urNad zaptel-1.2.1/qozap/zaptel.conf.octoBRI /tmp/dpep.RTh8jH/zaptel-1.2.1/qozap/zaptel.conf.octoBRI
---- zaptel-1.2.1/qozap/zaptel.conf.octoBRI 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.RTh8jH/zaptel-1.2.1/qozap/zaptel.conf.octoBRI 2005-06-13 10:03:36.000000000 +0300
-@@ -0,0 +1,30 @@
-+loadzone=nl
-+defaultzone=nl
-+# qozap span definitions
-+# most of the values should be bogus because we are not really zaptel
-+span=1,1,3,ccs,ami
-+span=2,0,3,ccs,ami
-+span=3,0,3,ccs,ami
-+span=4,0,3,ccs,ami
-+span=5,1,3,ccs,ami
-+span=6,0,3,ccs,ami
-+span=7,0,3,ccs,ami
-+span=8,0,3,ccs,ami
-+
-+bchan=1,2
-+dchan=3
-+bchan=4,5
-+dchan=6
-+bchan=7,8
-+dchan=9
-+bchan=10,11
-+dchan=12
-+bchan=13,14
-+dchan=15
-+bchan=16,17
-+dchan=18
-+bchan=19,20
-+dchan=21
-+bchan=22,23
-+dchan=24
-+
-diff -urNad zaptel-1.2.1/zaphfc/LICENSE /tmp/dpep.RTh8jH/zaptel-1.2.1/zaphfc/LICENSE
---- zaptel-1.2.1/zaphfc/LICENSE 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.RTh8jH/zaptel-1.2.1/zaphfc/LICENSE 2003-08-19 04:24:43.000000000 +0300
-@@ -0,0 +1,341 @@
-+
-+ GNU GENERAL PUBLIC LICENSE
-+ Version 2, June 1991
-+
-+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-+ Everyone is permitted to copy and distribute verbatim copies
-+ of this license document, but changing it is not allowed.
-+
-+ Preamble
-+
-+ The licenses for most software are designed to take away your
-+freedom to share and change it. By contrast, the GNU General Public
-+License is intended to guarantee your freedom to share and change free
-+software--to make sure the software is free for all its users. This
-+General Public License applies to most of the Free Software
-+Foundation's software and to any other program whose authors commit to
-+using it. (Some other Free Software Foundation software is covered by
-+the GNU Library General Public License instead.) You can apply it to
-+your programs, too.
-+
-+ When we speak of free software, we are referring to freedom, not
-+price. Our General Public Licenses are designed to make sure that you
-+have the freedom to distribute copies of free software (and charge for
-+this service if you wish), that you receive source code or can get it
-+if you want it, that you can change the software or use pieces of it
-+in new free programs; and that you know you can do these things.
-+
-+ To protect your rights, we need to make restrictions that forbid
-+anyone to deny you these rights or to ask you to surrender the rights.
-+These restrictions translate to certain responsibilities for you if you
-+distribute copies of the software, or if you modify it.
-+
-+ For example, if you distribute copies of such a program, whether
-+gratis or for a fee, you must give the recipients all the rights that
-+you have. You must make sure that they, too, receive or can get the
-+source code. And you must show them these terms so they know their
-+rights.
-+
-+ We protect your rights with two steps: (1) copyright the software, and
-+(2) offer you this license which gives you legal permission to copy,
-+distribute and/or modify the software.
-+
-+ Also, for each author's protection and ours, we want to make certain
-+that everyone understands that there is no warranty for this free
-+software. If the software is modified by someone else and passed on, we
-+want its recipients to know that what they have is not the original, so
-+that any problems introduced by others will not reflect on the original
-+authors' reputations.
-+
-+ Finally, any free program is threatened constantly by software
-+patents. We wish to avoid the danger that redistributors of a free
-+program will individually obtain patent licenses, in effect making the
-+program proprietary. To prevent this, we have made it clear that any
-+patent must be licensed for everyone's free use or not licensed at all.
-+
-+ The precise terms and conditions for copying, distribution and
-+modification follow.
-+
-+ GNU GENERAL PUBLIC LICENSE
-+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-+
-+ 0. This License applies to any program or other work which contains
-+a notice placed by the copyright holder saying it may be distributed
-+under the terms of this General Public License. The "Program", below,
-+refers to any such program or work, and a "work based on the Program"
-+means either the Program or any derivative work under copyright law:
-+that is to say, a work containing the Program or a portion of it,
-+either verbatim or with modifications and/or translated into another
-+language. (Hereinafter, translation is included without limitation in
-+the term "modification".) Each licensee is addressed as "you".
-+
-+Activities other than copying, distribution and modification are not
-+covered by this License; they are outside its scope. The act of
-+running the Program is not restricted, and the output from the Program
-+is covered only if its contents constitute a work based on the
-+Program (independent of having been made by running the Program).
-+Whether that is true depends on what the Program does.
-+
-+ 1. You may copy and distribute verbatim copies of the Program's
-+source code as you receive it, in any medium, provided that you
-+conspicuously and appropriately publish on each copy an appropriate
-+copyright notice and disclaimer of warranty; keep intact all the
-+notices that refer to this License and to the absence of any warranty;
-+and give any other recipients of the Program a copy of this License
-+along with the Program.
-+
-+You may charge a fee for the physical act of transferring a copy, and
-+you may at your option offer warranty protection in exchange for a fee.
-+
-+ 2. You may modify your copy or copies of the Program or any portion
-+of it, thus forming a work based on the Program, and copy and
-+distribute such modifications or work under the terms of Section 1
-+above, provided that you also meet all of these conditions:
-+
-+ a) You must cause the modified files to carry prominent notices
-+ stating that you changed the files and the date of any change.
-+
-+ b) You must cause any work that you distribute or publish, that in
-+ whole or in part contains or is derived from the Program or any
-+ part thereof, to be licensed as a whole at no charge to all third
-+ parties under the terms of this License.
-+
-+ c) If the modified program normally reads commands interactively
-+ when run, you must cause it, when started running for such
-+ interactive use in the most ordinary way, to print or display an
-+ announcement including an appropriate copyright notice and a
-+ notice that there is no warranty (or else, saying that you provide
-+ a warranty) and that users may redistribute the program under
-+ these conditions, and telling the user how to view a copy of this
-+ License. (Exception: if the Program itself is interactive but
-+ does not normally print such an announcement, your work based on
-+ the Program is not required to print an announcement.)
-+
-+These requirements apply to the modified work as a whole. If
-+identifiable sections of that work are not derived from the Program,
-+and can be reasonably considered independent and separate works in
-+themselves, then this License, and its terms, do not apply to those
-+sections when you distribute them as separate works. But when you
-+distribute the same sections as part of a whole which is a work based
-+on the Program, the distribution of the whole must be on the terms of
-+this License, whose permissions for other licensees extend to the
-+entire whole, and thus to each and every part regardless of who wrote it.
-+
-+Thus, it is not the intent of this section to claim rights or contest
-+your rights to work written entirely by you; rather, the intent is to
-+exercise the right to control the distribution of derivative or
-+collective works based on the Program.
-+
-+In addition, mere aggregation of another work not based on the Program
-+with the Program (or with a work based on the Program) on a volume of
-+a storage or distribution medium does not bring the other work under
-+the scope of this License.
-+
-+ 3. You may copy and distribute the Program (or a work based on it,
-+under Section 2) in object code or executable form under the terms of
-+Sections 1 and 2 above provided that you also do one of the following:
-+
-+ a) Accompany it with the complete corresponding machine-readable
-+ source code, which must be distributed under the terms of Sections
-+ 1 and 2 above on a medium customarily used for software interchange; or,
-+
-+ b) Accompany it with a written offer, valid for at least three
-+ years, to give any third party, for a charge no more than your
-+ cost of physically performing source distribution, a complete
-+ machine-readable copy of the corresponding source code, to be
-+ distributed under the terms of Sections 1 and 2 above on a medium
-+ customarily used for software interchange; or,
-+
-+ c) Accompany it with the information you received as to the offer
-+ to distribute corresponding source code. (This alternative is
-+ allowed only for noncommercial distribution and only if you
-+ received the program in object code or executable form with such
-+ an offer, in accord with Subsection b above.)
-+
-+The source code for a work means the preferred form of the work for
-+making modifications to it. For an executable work, complete source
-+code means all the source code for all modules it contains, plus any
-+associated interface definition files, plus the scripts used to
-+control compilation and installation of the executable. However, as a
-+special exception, the source code distributed need not include
-+anything that is normally distributed (in either source or binary
-+form) with the major components (compiler, kernel, and so on) of the
-+operating system on which the executable runs, unless that component
-+itself accompanies the executable.
-+
-+If distribution of executable or object code is made by offering
-+access to copy from a designated place, then offering equivalent
-+access to copy the source code from the same place counts as
-+distribution of the source code, even though third parties are not
-+compelled to copy the source along with the object code.
-+
-+ 4. You may not copy, modify, sublicense, or distribute the Program
-+except as expressly provided under this License. Any attempt
-+otherwise to copy, modify, sublicense or distribute the Program is
-+void, and will automatically terminate your rights under this License.
-+However, parties who have received copies, or rights, from you under
-+this License will not have their licenses terminated so long as such
-+parties remain in full compliance.
-+
-+ 5. You are not required to accept this License, since you have not
-+signed it. However, nothing else grants you permission to modify or
-+distribute the Program or its derivative works. These actions are
-+prohibited by law if you do not accept this License. Therefore, by
-+modifying or distributing the Program (or any work based on the
-+Program), you indicate your acceptance of this License to do so, and
-+all its terms and conditions for copying, distributing or modifying
-+the Program or works based on it.
-+
-+ 6. Each time you redistribute the Program (or any work based on the
-+Program), the recipient automatically receives a license from the
-+original licensor to copy, distribute or modify the Program subject to
-+these terms and conditions. You may not impose any further
-+restrictions on the recipients' exercise of the rights granted herein.
-+You are not responsible for enforcing compliance by third parties to
-+this License.
-+
-+ 7. If, as a consequence of a court judgment or allegation of patent
-+infringement or for any other reason (not limited to patent issues),
-+conditions are imposed on you (whether by court order, agreement or
-+otherwise) that contradict the conditions of this License, they do not
-+excuse you from the conditions of this License. If you cannot
-+distribute so as to satisfy simultaneously your obligations under this
-+License and any other pertinent obligations, then as a consequence you
-+may not distribute the Program at all. For example, if a patent
-+license would not permit royalty-free redistribution of the Program by
-+all those who receive copies directly or indirectly through you, then
-+the only way you could satisfy both it and this License would be to
-+refrain entirely from distribution of the Program.
-+
-+If any portion of this section is held invalid or unenforceable under
-+any particular circumstance, the balance of the section is intended to
-+apply and the section as a whole is intended to apply in other
-+circumstances.
-+
-+It is not the purpose of this section to induce you to infringe any
-+patents or other property right claims or to contest validity of any
-+such claims; this section has the sole purpose of protecting the
-+integrity of the free software distribution system, which is
-+implemented by public license practices. Many people have made
-+generous contributions to the wide range of software distributed
-+through that system in reliance on consistent application of that
-+system; it is up to the author/donor to decide if he or she is willing
-+to distribute software through any other system and a licensee cannot
-+impose that choice.
-+
-+This section is intended to make thoroughly clear what is believed to
-+be a consequence of the rest of this License.
-+
-+ 8. If the distribution and/or use of the Program is restricted in
-+certain countries either by patents or by copyrighted interfaces, the
-+original copyright holder who places the Program under this License
-+may add an explicit geographical distribution limitation excluding
-+those countries, so that distribution is permitted only in or among
-+countries not thus excluded. In such case, this License incorporates
-+the limitation as if written in the body of this License.
-+
-+ 9. The Free Software Foundation may publish revised and/or new versions
-+of the General Public License from time to time. Such new versions will
-+be similar in spirit to the present version, but may differ in detail to
-+address new problems or concerns.
-+
-+Each version is given a distinguishing version number. If the Program
-+specifies a version number of this License which applies to it and "any
-+later version", you have the option of following the terms and conditions
-+either of that version or of any later version published by the Free
-+Software Foundation. If the Program does not specify a version number of
-+this License, you may choose any version ever published by the Free Software
-+Foundation.
-+
-+ 10. If you wish to incorporate parts of the Program into other free
-+programs whose distribution conditions are different, write to the author
-+to ask for permission. For software which is copyrighted by the Free
-+Software Foundation, write to the Free Software Foundation; we sometimes
-+make exceptions for this. Our decision will be guided by the two goals
-+of preserving the free status of all derivatives of our free software and
-+of promoting the sharing and reuse of software generally.
-+
-+ NO WARRANTY
-+
-+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-+REPAIR OR CORRECTION.
-+
-+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-+POSSIBILITY OF SUCH DAMAGES.
-+
-+ END OF TERMS AND CONDITIONS
-+
-+ How to Apply These Terms to Your New Programs
-+
-+ If you develop a new program, and you want it to be of the greatest
-+possible use to the public, the best way to achieve this is to make it
-+free software which everyone can redistribute and change under these terms.
-+
-+ To do so, attach the following notices to the program. It is safest
-+to attach them to the start of each source file to most effectively
-+convey the exclusion of warranty; and each file should have at least
-+the "copyright" line and a pointer to where the full notice is found.
-+
-+ <one line to give the program's name and a brief idea of what it does.>
-+ Copyright (C) 19yy <name of author>
-+
-+ This program is free software; you can redistribute it and/or modify
-+ it under the terms of the GNU General Public License as published by
-+ the Free Software Foundation; either version 2 of the License, or
-+ (at your option) any later version.
-+
-+ This program is distributed in the hope that it will be useful,
-+ but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ GNU General Public License for more details.
-+
-+ You should have received a copy of the GNU General Public License
-+ along with this program; if not, write to the Free Software
-+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-+
-+
-+Also add information on how to contact you by electronic and paper mail.
-+
-+If the program is interactive, make it output a short notice like this
-+when it starts in an interactive mode:
-+
-+ Gnomovision version 69, Copyright (C) 19yy name of author
-+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-+ This is free software, and you are welcome to redistribute it
-+ under certain conditions; type `show c' for details.
-+
-+The hypothetical commands `show w' and `show c' should show the appropriate
-+parts of the General Public License. Of course, the commands you use may
-+be called something other than `show w' and `show c'; they could even be
-+mouse-clicks or menu items--whatever suits your program.
-+
-+You should also get your employer (if you work as a programmer) or your
-+school, if any, to sign a "copyright disclaimer" for the program, if
-+necessary. Here is a sample; alter the names:
-+
-+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
-+
-+ <signature of Ty Coon>, 1 April 1989
-+ Ty Coon, President of Vice
-+
-+This General Public License does not permit incorporating your program into
-+proprietary programs. If your program is a subroutine library, you may
-+consider it more useful to permit linking proprietary applications with the
-+library. If this is what you want to do, use the GNU Library General
-+Public License instead of this License.
-diff -urNad zaptel-1.2.1/zaphfc/Makefile /tmp/dpep.RTh8jH/zaptel-1.2.1/zaphfc/Makefile
---- zaptel-1.2.1/zaphfc/Makefile 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.RTh8jH/zaptel-1.2.1/zaphfc/Makefile 2005-12-21 15:44:35.000000000 +0200
-@@ -0,0 +1,118 @@
-+KINCLUDES = /usr/src/linux/include
-+BRISTUFFBASE = $(shell dirname `pwd`)
-+
-+ZAP = $(shell [ -f $(BRISTUFFBASE)/zaptel-1.2.1/zaptel.h ] && echo "-I$(BRISTUFFBASE)/zaptel-1.2.1")
-+RTAI = $(shell [ -f /usr/realtime/include/rtai.h ] && echo "-DRTAITIMING -I/usr/realtime/include")
-+
-+HOSTCC=gcc
-+
-+CFLAGS+=-I. $(ZAP) $(RTAI) -O2 -g -Wall -DBUILDING_TONEZONE
-+CFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-fsigned-char"; fi)
-+
-+KFLAGS=-D__KERNEL__ -DMODULE -DEXPORT_SYMTAB -fomit-frame-pointer -O2 -Wall -I$(KINCLUDES) $(ZAP) $(RTAI) -Wall
-+KFLAGS+=$(shell [ -f $(KINCLUDES)/linux/modversions.h ] && echo "-DMODVERSIONS -include $(KINCLUDES)/linux/modversions.h")
-+KFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-msoft-float -fsigned-char"; fi)
-+
-+
-+BUILDVER=$(shell if uname -r | grep -q ^2.6; then echo "linux26"; else echo "linux24"; fi)
-+
-+MODCONF=$(shell if [ -d $(INSTALL_PREFIX)/etc/modprobe.d ]; then echo "$(INSTALL_PREFIX)/etc/modprobe.d/zaptel"; elif [ -d $(INSTALL_PREFIX)/etc/modutils ]; then echo "$(INSTALL_PREFIX)/etc/modutils/zaptel"; elif [ -f $(INSTALL_PREFIX)/etc/modprobe.conf ]; then echo "$(INSTALL_PREFIX)/modprobe.conf"; elif [ -f $(INSTALL_PREFIX)/etc/modules.conf ]; then echo "$(INSTALL_PREFIX)/etc/modules.conf"; else echo $(INSTALL_PREFIX)/etc/conf.modules ; fi)
-+
-+OBJS=zaphfc.o
-+
-+MODULES=zaphfc
-+
-+MODULESO=$(shell for x in $(MODULES); do echo "$$x.o "; done )
-+MODULESKO=$(shell for x in $(MODULES); do echo "$$x.ko "; done )
-+
-+PWD=$(shell pwd)
-+
-+obj-m := $(MODULESO)
-+
-+all: $(BUILDVER)
-+
-+linux24: $(OBJS)
-+ sync
-+
-+
-+zaphfc.o: zaphfc.c zaphfc.h
-+ $(CC) -c zaphfc.c $(KFLAGS)
-+
-+clean:
-+ rm -f $(OBJS) *.ko *.mod.c *.mod.o .*o.cmd *~
-+ rm -rf .tmp_versions
-+
-+test: all
-+ modprobe zaptel
-+ insmod ./zaphfc.o
-+ cat /proc/interrupts
-+ sleep 1
-+ cat /proc/interrupts
-+ rmmod zaphfc
-+ rmmod zaptel
-+
-+load: load$(BUILDVER)
-+
-+loadNT: load$(BUILDVER)NT
-+
-+load-debug: load$(BUILDVER)-debug
-+
-+loadNT-debug: load$(BUILDVER)NT-debug
-+
-+loadlinux24: all
-+ modprobe zaptel
-+ insmod ./zaphfc.o
-+ ztcfg -v
-+
-+loadlinux24-debug: all
-+ modprobe zaptel
-+ insmod ./zaphfc.o debug=1
-+ ztcfg -v
-+
-+loadlinux26: linux26
-+ modprobe zaptel
-+ insmod ./zaphfc.ko
-+ ztcfg -v
-+
-+loadlinux26-debug: linux26
-+ modprobe zaptel
-+ insmod ./zaphfc.ko debug=1
-+ ztcfg -v
-+
-+loadlinux24NT: all
-+ modprobe zaptel
-+ insmod ./zaphfc.o modes=1
-+ ztcfg -v
-+
-+loadlinux24NT-debug: all
-+ modprobe zaptel
-+ insmod ./zaphfc.o modes=1 debug=1
-+ ztcfg -v
-+
-+loadlinux26NT: linux26
-+ modprobe zaptel
-+ insmod ./zaphfc.ko modes=1
-+ ztcfg -v
-+
-+loadlinux26NT-debug: linux26
-+ modprobe zaptel
-+ insmod ./zaphfc.ko modes=1 debug=1
-+ ztcfg -v
-+
-+unload:
-+ -rmmod zaphfc zaptel
-+
-+zaphfc.ko: zaphfc.c zaphfc.h
-+
-+linux26:
-+ @if ! [ -d /usr/src/linux-2.6 ]; then echo "Link /usr/src/linux-2.6 to your kernel sources first!"; exit 1 ; fi
-+ make -C /usr/src/linux-2.6 SUBDIRS=$(PWD) ZAP=$(ZAP) modules
-+
-+install: install$(BUILDVER)
-+
-+installlinux26:
-+ install -D -m 644 zaphfc.ko $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/zaphfc.ko
-+
-+installlinux24:
-+ install -D -m 644 zaphfc.o $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/zaphfc.o
-+
-diff -urNad zaptel-1.2.1/zaphfc/zapata.conf /tmp/dpep.RTh8jH/zaptel-1.2.1/zaphfc/zapata.conf
---- zaptel-1.2.1/zaphfc/zapata.conf 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.RTh8jH/zaptel-1.2.1/zaphfc/zapata.conf 2005-02-26 19:24:32.000000000 +0200
-@@ -0,0 +1,38 @@
-+;
-+; Zapata telephony interface
-+;
-+; Configuration file
-+
-+[channels]
-+;
-+; Default language
-+;
-+;language=en
-+;
-+; Default context
-+;
-+;
-+switchtype = euroisdn
-+; p2mp TE mode
-+signalling = bri_cpe_ptmp
-+
-+; p2p TE mode
-+;signalling = bri_cpe
-+; p2mp NT mode
-+;signalling = bri_net_ptmp
-+; p2p NT mode
-+;signalling = bri_net
-+
-+pridialplan = dynamic
-+prilocaldialplan = local
-+nationalprefix = 0
-+internationalprefix = 00
-+
-+echocancel=yes
-+echotraining = 100
-+echocancelwhenbridged=yes
-+
-+immediate=yes
-+group = 1
-+context=demo
-+channel => 1-2
-diff -urNad zaptel-1.2.1/zaphfc/zaphfc.c /tmp/dpep.RTh8jH/zaptel-1.2.1/zaphfc/zaphfc.c
---- zaptel-1.2.1/zaphfc/zaphfc.c 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.RTh8jH/zaptel-1.2.1/zaphfc/zaphfc.c 2005-11-20 19:58:16.000000000 +0200
-@@ -0,0 +1,1149 @@
-+/*
-+ * zaphfc.c - Zaptel driver for HFC-S PCI A based ISDN BRI cards
-+ *
-+ * kernel module inspired by HFC PCI ISDN4Linux and Zaptel drivers
-+ *
-+ * Copyright (C) 2002, 2003, 2004, 2005 Junghanns.NET GmbH
-+ *
-+ * Klaus-Peter Junghanns <kpj at junghanns.net>
-+ *
-+ * This program is free software and may be modified and
-+ * distributed under the terms of the GNU Public License.
-+ *
-+ */
-+
-+#include <linux/kernel.h>
-+#include <linux/module.h>
-+#ifdef RTAITIMING
-+#include <asm/io.h>
-+#include <rtai.h>
-+#include <rtai_sched.h>
-+#include <rtai_fifos.h>
-+#endif
-+#include <linux/pci.h>
-+#include <linux/init.h>
-+#include <linux/interrupt.h>
-+#include <linux/delay.h>
-+#include <zaptel.h>
-+#include "zaphfc.h"
-+
-+#if CONFIG_PCI
-+
-+#define CLKDEL_TE 0x0f /* CLKDEL in TE mode */
-+#define CLKDEL_NT 0x6c /* CLKDEL in NT mode */
-+
-+typedef struct {
-+ int vendor_id;
-+ int device_id;
-+ char *vendor_name;
-+ char *card_name;
-+} PCI_ENTRY;
-+
-+static const PCI_ENTRY id_list[] =
-+{
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_2BD0, "CCD/Billion/Asuscom", "2BD0"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B000, "Billion", "B000"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B006, "Billion", "B006"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B007, "Billion", "B007"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B008, "Billion", "B008"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B009, "Billion", "B009"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B00A, "Billion", "B00A"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B00B, "Billion", "B00B"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B00C, "Billion", "B00C"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B100, "Seyeon", "B100"},
-+ {PCI_VENDOR_ID_ABOCOM, PCI_DEVICE_ID_ABOCOM_2BD1, "Abocom/Magitek", "2BD1"},
-+ {PCI_VENDOR_ID_ASUSTEK, PCI_DEVICE_ID_ASUSTEK_0675, "Asuscom/Askey", "675"},
-+ {PCI_VENDOR_ID_BERKOM, PCI_DEVICE_ID_BERKOM_T_CONCEPT, "German telekom", "T-Concept"},
-+ {PCI_VENDOR_ID_BERKOM, PCI_DEVICE_ID_BERKOM_A1T, "German telekom", "A1T"},
-+ {PCI_VENDOR_ID_ANIGMA, PCI_DEVICE_ID_ANIGMA_MC145575, "Motorola MC145575", "MC145575"},
-+ {PCI_VENDOR_ID_ZOLTRIX, PCI_DEVICE_ID_ZOLTRIX_2BD0, "Zoltrix", "2BD0"},
-+ {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_IOM2_E,"Digi International", "Digi DataFire Micro V IOM2 (Europe)"},
-+ {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_E,"Digi International", "Digi DataFire Micro V (Europe)"},
-+ {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_IOM2_A,"Digi International", "Digi DataFire Micro V IOM2 (North America)"},
-+ {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_A,"Digi International", "Digi DataFire Micro V (North America)"},
-+ {0x182d, 0x3069,"Sitecom","Isdn 128 PCI"},
-+ {0, 0, NULL, NULL},
-+};
-+
-+static struct hfc_card *hfc_dev_list = NULL;
-+static int hfc_dev_count = 0;
-+static int modes = 0; // all TE
-+static int debug = 0;
-+static struct pci_dev *multi_hfc = NULL;
-+static spinlock_t registerlock = SPIN_LOCK_UNLOCKED;
-+
-+void hfc_shutdownCard(struct hfc_card *hfctmp) {
-+ unsigned long flags;
-+
-+ if (hfctmp == NULL) {
-+ return;
-+ }
-+
-+ if (hfctmp->pci_io == NULL) {
-+ return;
-+ }
-+
-+ spin_lock_irqsave(&hfctmp->lock,flags);
-+
-+ printk(KERN_INFO "zaphfc: shutting down card at %p.\n",hfctmp->pci_io);
-+
-+ /* Clear interrupt mask */
-+ hfctmp->regs.int_m2 = 0;
-+ hfc_outb(hfctmp, hfc_INT_M2, hfctmp->regs.int_m2);
-+
-+ /* Reset pending interrupts */
-+ hfc_inb(hfctmp, hfc_INT_S1);
-+
-+ /* Wait for interrupts that might still be pending */
-+ spin_unlock_irqrestore(&hfctmp->lock, flags);
-+ set_current_state(TASK_UNINTERRUPTIBLE);
-+ schedule_timeout((30 * HZ) / 1000); // wait 30 ms
-+ spin_lock_irqsave(&hfctmp->lock,flags);
-+
-+ /* Remove interrupt handler */
-+ if (hfctmp->irq) {
-+ free_irq(hfctmp->irq, hfctmp);
-+ }
-+
-+ /* Soft-reset the card */
-+ hfc_outb(hfctmp, hfc_CIRM, hfc_CIRM_RESET); // softreset on
-+
-+ spin_unlock_irqrestore(&hfctmp->lock, flags);
-+ set_current_state(TASK_UNINTERRUPTIBLE);
-+ schedule_timeout((30 * HZ) / 1000); // wait 30 ms
-+ spin_lock_irqsave(&hfctmp->lock,flags);
-+
-+ hfc_outb(hfctmp,hfc_CIRM,0); // softreset off
-+
-+ pci_write_config_word(hfctmp->pcidev, PCI_COMMAND, 0); // disable memio and bustmaster
-+
-+ if (hfctmp->fifomem != NULL) {
-+ kfree(hfctmp->fifomem);
-+ }
-+ iounmap((void *) hfctmp->pci_io);
-+ hfctmp->pci_io = NULL;
-+ if (hfctmp->pcidev != NULL) {
-+ pci_disable_device(hfctmp->pcidev);
-+ }
-+ spin_unlock_irqrestore(&hfctmp->lock,flags);
-+ if (hfctmp->ztdev != NULL) {
-+ zt_unregister(&hfctmp->ztdev->span);
-+ kfree(hfctmp->ztdev);
-+ printk(KERN_INFO "unregistered from zaptel.\n");
-+ }
-+}
-+
-+void hfc_resetCard(struct hfc_card *hfctmp) {
-+ unsigned long flags;
-+
-+ spin_lock_irqsave(&hfctmp->lock,flags);
-+ pci_write_config_word(hfctmp->pcidev, PCI_COMMAND, PCI_COMMAND_MEMORY); // enable memio
-+ hfctmp->regs.int_m2 = 0;
-+ hfc_outb(hfctmp, hfc_INT_M2, hfctmp->regs.int_m2);
-+
-+// printk(KERN_INFO "zaphfc: resetting card.\n");
-+ pci_set_master(hfctmp->pcidev);
-+ hfc_outb(hfctmp, hfc_CIRM, hfc_CIRM_RESET); // softreset on
-+ spin_unlock_irqrestore(&hfctmp->lock, flags);
-+
-+ set_current_state(TASK_UNINTERRUPTIBLE);
-+ schedule_timeout((30 * HZ) / 1000); // wait 30 ms
-+ hfc_outb(hfctmp, hfc_CIRM, 0); // softreset off
-+
-+ set_current_state(TASK_UNINTERRUPTIBLE);
-+ schedule_timeout((20 * HZ) / 1000); // wait 20 ms
-+ if (hfc_inb(hfctmp,hfc_STATUS) & hfc_STATUS_PCI_PROC) {
-+ printk(KERN_WARNING "zaphfc: hfc busy.\n");
-+ }
-+
-+// hfctmp->regs.fifo_en = hfc_FIFOEN_D | hfc_FIFOEN_B1 | hfc_FIFOEN_B2;
-+// hfctmp->regs.fifo_en = hfc_FIFOEN_D; /* only D fifos enabled */
-+ hfctmp->regs.fifo_en = 0; /* no fifos enabled */
-+ hfc_outb(hfctmp, hfc_FIFO_EN, hfctmp->regs.fifo_en);
-+
-+ hfctmp->regs.trm = 2;
-+ hfc_outb(hfctmp, hfc_TRM, hfctmp->regs.trm);
-+
-+ if (hfctmp->regs.nt_mode == 1) {
-+ hfc_outb(hfctmp, hfc_CLKDEL, CLKDEL_NT); /* ST-Bit delay for NT-Mode */
-+ } else {
-+ hfc_outb(hfctmp, hfc_CLKDEL, CLKDEL_TE); /* ST-Bit delay for TE-Mode */
-+ }
-+ hfctmp->regs.sctrl_e = hfc_SCTRL_E_AUTO_AWAKE;
-+ hfc_outb(hfctmp, hfc_SCTRL_E, hfctmp->regs.sctrl_e); /* S/T Auto awake */
-+ hfctmp->regs.bswapped = 0; /* no exchange */
-+
-+ hfctmp->regs.ctmt = hfc_CTMT_TRANSB1 | hfc_CTMT_TRANSB2; // all bchans are transparent , no freaking hdlc
-+ hfc_outb(hfctmp, hfc_CTMT, hfctmp->regs.ctmt);
-+
-+ hfctmp->regs.int_m1 = 0;
-+ hfc_outb(hfctmp, hfc_INT_M1, hfctmp->regs.int_m1);
-+
-+#ifdef RTAITIMING
-+ hfctmp->regs.int_m2 = 0;
-+#else
-+ hfctmp->regs.int_m2 = hfc_M2_PROC_TRANS;
-+#endif
-+ hfc_outb(hfctmp, hfc_INT_M2, hfctmp->regs.int_m2);
-+
-+ /* Clear already pending ints */
-+ hfc_inb(hfctmp, hfc_INT_S1);
-+
-+ if (hfctmp->regs.nt_mode == 1) {
-+ hfctmp->regs.sctrl = 3 | hfc_SCTRL_NONE_CAP | hfc_SCTRL_MODE_NT; /* set tx_lo mode, error in datasheet ! */
-+ } else {
-+ hfctmp->regs.sctrl = 3 | hfc_SCTRL_NONE_CAP | hfc_SCTRL_MODE_TE; /* set tx_lo mode, error in datasheet ! */
-+ }
-+
-+ hfctmp->regs.mst_mode = hfc_MST_MODE_MASTER; /* HFC Master Mode */
-+ hfc_outb(hfctmp, hfc_MST_MODE, hfctmp->regs.mst_mode);
-+
-+ hfc_outb(hfctmp, hfc_SCTRL, hfctmp->regs.sctrl);
-+ hfctmp->regs.sctrl_r = 3;
-+ hfc_outb(hfctmp, hfc_SCTRL_R, hfctmp->regs.sctrl_r);
-+
-+ hfctmp->regs.connect = 0;
-+ hfc_outb(hfctmp, hfc_CONNECT, hfctmp->regs.connect);
-+
-+ hfc_outb(hfctmp, hfc_CIRM, 0x80 | 0x40); // bit order
-+
-+ /* Finally enable IRQ output */
-+#ifndef RTAITIMING
-+ hfctmp->regs.int_m2 |= hfc_M2_IRQ_ENABLE;
-+ hfc_outb(hfctmp, hfc_INT_M2, hfctmp->regs.int_m2);
-+#endif
-+
-+ /* clear pending ints */
-+ hfc_inb(hfctmp, hfc_INT_S1);
-+ hfc_inb(hfctmp, hfc_INT_S2);
-+}
-+
-+void hfc_registerCard(struct hfc_card *hfccard) {
-+ spin_lock(®isterlock);
-+ if (hfccard != NULL) {
-+ hfccard->cardno = hfc_dev_count++;
-+ hfccard->next = hfc_dev_list;
-+ hfc_dev_list = hfccard;
-+ }
-+ spin_unlock(®isterlock);
-+}
-+
-+static void hfc_btrans(struct hfc_card *hfctmp, char whichB) {
-+ // we are called with irqs disabled from the irq handler
-+ int count, maxlen, total;
-+ unsigned char *f1, *f2;
-+ unsigned short *z1, *z2, newz1;
-+ int freebytes;
-+
-+ if (whichB == 1) {
-+ f1 = (char *)(hfctmp->fifos + hfc_FIFO_B1TX_F1);
-+ f2 = (char *)(hfctmp->fifos + hfc_FIFO_B1TX_F2);
-+ z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B1TX_Z1 + (*f1 * 4));
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B1TX_Z2 + (*f1 * 4));
-+ } else {
-+ f1 = (char *)(hfctmp->fifos + hfc_FIFO_B2TX_F1);
-+ f2 = (char *)(hfctmp->fifos + hfc_FIFO_B2TX_F2);
-+ z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B2TX_Z1 + (*f1 * 4));
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B2TX_Z2 + (*f1 * 4));
-+ }
-+
-+ freebytes = *z2 - *z1;
-+ if (freebytes <= 0) {
-+ freebytes += hfc_B_FIFO_SIZE;
-+ }
-+ count = ZT_CHUNKSIZE;
-+
-+ total = count;
-+ if (freebytes < count) {
-+ hfctmp->clicks++;
-+ /* only spit out this warning once per second to not make things worse! */
-+ if (hfctmp->clicks > 100) {
-+ printk(KERN_CRIT "zaphfc: bchan tx fifo full, dropping audio! (z1=%d, z2=%d)\n",*z1,*z2);
-+ hfctmp->clicks = 0;
-+ }
-+ return;
-+ }
-+
-+ maxlen = (hfc_B_FIFO_SIZE + hfc_B_SUB_VAL) - *z1;
-+ if (maxlen > count) {
-+ maxlen = count;
-+ }
-+ newz1 = *z1 + total;
-+ if (newz1 >= (hfc_B_FIFO_SIZE + hfc_B_SUB_VAL)) { newz1 -= hfc_B_FIFO_SIZE; }
-+
-+ if (whichB == 1) {
-+ memcpy((char *)(hfctmp->fifos + hfc_FIFO_B1TX_ZOFF + *z1),hfctmp->ztdev->chans[0].writechunk, maxlen);
-+ } else {
-+ memcpy((char *)(hfctmp->fifos + hfc_FIFO_B2TX_ZOFF + *z1),hfctmp->ztdev->chans[1].writechunk, maxlen);
-+ }
-+
-+ count -= maxlen;
-+ if (count > 0) {
-+ // Buffer wrap
-+ if (whichB == 1) {
-+ memcpy((char *)(hfctmp->fifos + hfc_FIFO_B1TX_ZOFF + hfc_B_SUB_VAL),hfctmp->ztdev->chans[0].writechunk+maxlen, count);
-+ } else {
-+ memcpy((char *)(hfctmp->fifos + hfc_FIFO_B2TX_ZOFF + hfc_B_SUB_VAL),hfctmp->ztdev->chans[1].writechunk+maxlen, count);
-+ }
-+ }
-+
-+ *z1 = newz1; /* send it now */
-+
-+// if (count > 0) printk(KERN_CRIT "zaphfc: bchan tx fifo (f1=%d, f2=%d, z1=%d, z2=%d)\n",(*f1) & hfc_FMASK,(*f2) & hfc_FMASK, *z1, *z2);
-+ return;
-+}
-+
-+static void hfc_brec(struct hfc_card *hfctmp, char whichB) {
-+ // we are called with irqs disabled from the irq handler
-+ int count, maxlen, drop;
-+ volatile unsigned char *f1, *f2;
-+ volatile unsigned short *z1, *z2, newz2;
-+ int bytes = 0;
-+
-+ if (whichB == 1) {
-+ f1 = (char *)(hfctmp->fifos + hfc_FIFO_B1RX_F1);
-+ f2 = (char *)(hfctmp->fifos + hfc_FIFO_B1RX_F2);
-+ z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B1RX_Z1 + (*f1 * 4));
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B1RX_Z2 + (*f1 * 4));
-+ } else {
-+ f1 = (char *)(hfctmp->fifos + hfc_FIFO_B2RX_F1);
-+ f2 = (char *)(hfctmp->fifos + hfc_FIFO_B2RX_F2);
-+ z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B2RX_Z1 + (*f1 * 4));
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B2RX_Z2 + (*f1 * 4));
-+ }
-+
-+ bytes = *z1 - *z2;
-+ if (bytes < 0) {
-+ bytes += hfc_B_FIFO_SIZE;
-+ }
-+ count = ZT_CHUNKSIZE;
-+
-+ if (bytes < ZT_CHUNKSIZE) {
-+#ifndef RTAITIMING
-+ printk(KERN_CRIT "zaphfc: bchan rx fifo not enough bytes to receive! (z1=%d, z2=%d, wanted %d got %d), probably a buffer overrun.\n",*z1,*z2,ZT_CHUNKSIZE,bytes);
-+#endif
-+ return;
-+ }
-+
-+ /* allowing the buffering of hfc_BCHAN_BUFFER bytes of audio data works around irq jitter */
-+ if (bytes > hfc_BCHAN_BUFFER + ZT_CHUNKSIZE) {
-+ /* if the system is too slow to handle it, we will have to drop it all (except 1 zaptel chunk) */
-+ drop = bytes - ZT_CHUNKSIZE;
-+ hfctmp->clicks++;
-+ /* only spit out this warning once per second to not make things worse! */
-+ if (hfctmp->clicks > 100) {
-+ printk(KERN_CRIT "zaphfc: dropped audio (z1=%d, z2=%d, wanted %d got %d, dropped %d).\n",*z1,*z2,count,bytes,drop);
-+ hfctmp->clicks = 0;
-+ }
-+ /* hm, we are processing the b chan data tooooo slowly... let's drop the lost audio */
-+ newz2 = *z2 + drop;
-+ if (newz2 >= (hfc_B_FIFO_SIZE + hfc_B_SUB_VAL)) {
-+ newz2 -= hfc_B_FIFO_SIZE;
-+ }
-+ *z2 = newz2;
-+ }
-+
-+
-+ maxlen = (hfc_B_FIFO_SIZE + hfc_B_SUB_VAL) - *z2;
-+ if (maxlen > count) {
-+ maxlen = count;
-+ }
-+ if (whichB == 1) {
-+ memcpy(hfctmp->ztdev->chans[0].readchunk,(char *)(hfctmp->fifos + hfc_FIFO_B1RX_ZOFF + *z2), maxlen);
-+ } else {
-+ memcpy(hfctmp->ztdev->chans[1].readchunk,(char *)(hfctmp->fifos + hfc_FIFO_B2RX_ZOFF + *z2), maxlen);
-+ }
-+ newz2 = *z2 + count;
-+ if (newz2 >= (hfc_B_FIFO_SIZE + hfc_B_SUB_VAL)) {
-+ newz2 -= hfc_B_FIFO_SIZE;
-+ }
-+ *z2 = newz2;
-+
-+ count -= maxlen;
-+ if (count > 0) {
-+ // Buffer wrap
-+ if (whichB == 1) {
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B1RX_Z2 + (*f1 * 4));
-+ memcpy(hfctmp->ztdev->chans[0].readchunk + maxlen,(char *)(hfctmp->fifos + hfc_FIFO_B1RX_ZOFF + hfc_B_SUB_VAL), count);
-+ } else {
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B2RX_Z2 + (*f1 * 4));
-+ memcpy(hfctmp->ztdev->chans[1].readchunk + maxlen,(char *)(hfctmp->fifos + hfc_FIFO_B2RX_ZOFF + hfc_B_SUB_VAL), count);
-+ }
-+ newz2 = *z2 + count;
-+ if (newz2 >= (hfc_B_FIFO_SIZE + hfc_B_SUB_VAL)) {
-+ newz2 -= hfc_B_FIFO_SIZE;
-+ }
-+ }
-+
-+
-+ if (whichB == 1) {
-+ zt_ec_chunk(&hfctmp->ztdev->chans[0], hfctmp->ztdev->chans[0].readchunk, hfctmp->ztdev->chans[0].writechunk);
-+ } else {
-+ zt_ec_chunk(&hfctmp->ztdev->chans[1], hfctmp->ztdev->chans[1].readchunk, hfctmp->ztdev->chans[1].writechunk);
-+ }
-+ return;
-+}
-+
-+
-+static void hfc_dtrans(struct hfc_card *hfctmp) {
-+ // we are called with irqs disabled from the irq handler
-+ int x;
-+ int count, maxlen, total;
-+ unsigned char *f1, *f2, newf1;
-+ unsigned short *z1, *z2, newz1;
-+ int frames, freebytes;
-+
-+ if (hfctmp->ztdev->chans[2].bytes2transmit == 0) {
-+ return;
-+ }
-+
-+ f1 = (char *)(hfctmp->fifos + hfc_FIFO_DTX_F1);
-+ f2 = (char *)(hfctmp->fifos + hfc_FIFO_DTX_F2);
-+ z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DTX_Z1 + (*f1 * 4));
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DTX_Z2 + (*f1 * 4));
-+
-+ frames = (*f1 - *f2) & hfc_FMASK;
-+ if (frames < 0) {
-+ frames += hfc_MAX_DFRAMES + 1;
-+ }
-+
-+ if (frames >= hfc_MAX_DFRAMES) {
-+ printk(KERN_CRIT "zaphfc: dchan tx fifo total number of frames exceeded!\n");
-+ return;
-+ }
-+
-+ freebytes = *z2 - *z1;
-+ if (freebytes <= 0) {
-+ freebytes += hfc_D_FIFO_SIZE;
-+ }
-+ count = hfctmp->ztdev->chans[2].bytes2transmit;
-+
-+ total = count;
-+ if (freebytes < count) {
-+ printk(KERN_CRIT "zaphfc: dchan tx fifo not enough free bytes! (z1=%d, z2=%d)\n",*z1,*z2);
-+ return;
-+ }
-+
-+ newz1 = (*z1 + count) & hfc_ZMASK;
-+ newf1 = ((*f1 + 1) & hfc_MAX_DFRAMES) | (hfc_MAX_DFRAMES + 1); // next frame
-+
-+ if (count > 0) {
-+ if (debug) {
-+ printk(KERN_CRIT "zaphfc: card %d TX [ ", hfctmp->cardno);
-+ for (x=0; x<count; x++) {
-+ printk("%#2x ",hfctmp->dtransbuf[x]);
-+ }
-+ if (hfctmp->ztdev->chans[2].eoftx == 1) {
-+ printk("] %d bytes\n", count);
-+ } else {
-+ printk("..] %d bytes\n", count);
-+ }
-+ }
-+ maxlen = hfc_D_FIFO_SIZE - *z1;
-+ if (maxlen > count) {
-+ maxlen = count;
-+ }
-+ memcpy((char *)(hfctmp->fifos + hfc_FIFO_DTX_ZOFF + *z1),hfctmp->ztdev->chans[2].writechunk, maxlen);
-+ count -= maxlen;
-+ if (count > 0) {
-+ memcpy((char *)(hfctmp->fifos + hfc_FIFO_DTX_ZOFF),(char *)(hfctmp->ztdev->chans[2].writechunk + maxlen), count);
-+ }
-+ }
-+
-+ *z1 = newz1;
-+
-+ if (hfctmp->ztdev->chans[2].eoftx == 1) {
-+ *f1 = newf1;
-+ z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DTX_Z1 + (*f1 * 4));
-+ *z1 = newz1;
-+ hfctmp->ztdev->chans[2].eoftx = 0;
-+ }
-+// printk(KERN_CRIT "zaphfc: dchan tx fifo (f1=%d, f2=%d, z1=%d, z2=%d)\n",(*f1) & hfc_FMASK,(*f2) & hfc_FMASK, *z1, *z2);
-+ return;
-+}
-+
-+/* receive a complete hdlc frame, skip broken or short frames */
-+static void hfc_drec(struct hfc_card *hfctmp) {
-+ int count=0, maxlen=0, framelen=0;
-+ unsigned char *f1, *f2, *crcstat;
-+ unsigned short *z1, *z2, oldz2, newz2;
-+
-+ hfctmp->ztdev->chans[2].bytes2receive=0;
-+ hfctmp->ztdev->chans[2].eofrx = 0;
-+
-+ /* put the received data into the zaptel buffer
-+ we'll call zt_receive() later when the timer fires. */
-+ f1 = (char *)(hfctmp->fifos + hfc_FIFO_DRX_F1);
-+ f2 = (char *)(hfctmp->fifos + hfc_FIFO_DRX_F2);
-+
-+ if (*f1 == *f2) return; /* nothing received, strange eh? */
-+
-+ z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DRX_Z1 + (*f2 * 4));
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DRX_Z2 + (*f2 * 4));
-+
-+ /* calculate length of frame, including 2 bytes CRC and 1 byte STAT */
-+ count = *z1 - *z2;
-+
-+ if (count < 0) {
-+ count += hfc_D_FIFO_SIZE; /* ring buffer wrapped */
-+ }
-+ count++;
-+ framelen = count;
-+
-+ crcstat = (char *)(hfctmp->fifos + hfc_FIFO_DRX_ZOFF + *z1);
-+
-+ if ((framelen < 4) || (*crcstat != 0x0)) {
-+ /* the frame is too short for a valid HDLC frame or the CRC is borked */
-+ printk(KERN_CRIT "zaphfc: empty HDLC frame or bad CRC received (framelen = %d, stat = %#x, card = %d).\n", framelen, *crcstat, hfctmp->cardno);
-+ oldz2 = *z2;
-+ *f2 = ((*f2 + 1) & hfc_MAX_DFRAMES) | (hfc_MAX_DFRAMES + 1); /* NEXT!!! */
-+ // recalculate z2, because Z2 is a function of F2 Z2(F2) and we INCed F2!!!
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DRX_Z2 + (*f2 * 4));
-+ *z2 = (oldz2 + framelen) & hfc_ZMASK;
-+ hfctmp->drecinframe = 0;
-+ hfctmp->regs.int_drec--;
-+ /* skip short or broken frames */
-+ hfctmp->ztdev->chans[2].bytes2receive = 0;
-+ return;
-+ }
-+
-+ count -= 1; /* strip STAT */
-+ hfctmp->ztdev->chans[2].eofrx = 1;
-+
-+ if (count + *z2 <= hfc_D_FIFO_SIZE) {
-+ maxlen = count;
-+ } else {
-+ maxlen = hfc_D_FIFO_SIZE - *z2;
-+ }
-+
-+ /* copy first part */
-+ memcpy(hfctmp->drecbuf, (char *)(hfctmp->fifos + hfc_FIFO_DRX_ZOFF + *z2), maxlen);
-+ hfctmp->ztdev->chans[2].bytes2receive += maxlen;
-+
-+ count -= maxlen;
-+ if (count > 0) {
-+ /* ring buffer wrapped, copy rest from start of d fifo */
-+ memcpy(hfctmp->drecbuf + maxlen, (char *)(hfctmp->fifos + hfc_FIFO_DRX_ZOFF), count);
-+ hfctmp->ztdev->chans[2].bytes2receive += count;
-+ }
-+
-+ /* frame read */
-+ oldz2 = *z2;
-+ newz2 = (oldz2 + framelen) & hfc_ZMASK;
-+ *f2 = ((*f2 + 1) & hfc_MAX_DFRAMES) | (hfc_MAX_DFRAMES + 1); /* NEXT!!! */
-+ /* recalculate z2, because Z2 is a function of F2 Z2(F2) and we INCed F2!!! */
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DRX_Z2 + (*f2 * 4));
-+ *z2 = newz2;
-+ hfctmp->drecinframe = 0;
-+ hfctmp->regs.int_drec--;
-+}
-+
-+#ifndef RTAITIMING
-+#ifdef LINUX26
-+static irqreturn_t hfc_interrupt(int irq, void *dev_id, struct pt_regs *regs) {
-+#else
-+static void hfc_interrupt(int irq, void *dev_id, struct pt_regs *regs) {
-+#endif
-+ struct hfc_card *hfctmp = dev_id;
-+ unsigned long flags = 0;
-+ unsigned char stat;
-+#else
-+static void hfc_service(struct hfc_card *hfctmp) {
-+#endif
-+ struct zt_hfc *zthfc;
-+ unsigned char s1, s2, l1state;
-+ int x;
-+
-+ if (!hfctmp) {
-+#ifndef RTAITIMING
-+#ifdef LINUX26
-+ return IRQ_NONE;
-+#else
-+ return;
-+#endif
-+#else
-+ /* rtai */
-+ return;
-+#endif
-+ }
-+
-+ if (!hfctmp->pci_io) {
-+ printk(KERN_WARNING "%s: IO-mem disabled, cannot handle interrupt\n",
-+ __FUNCTION__);
-+#ifndef RTAITIMING
-+#ifdef LINUX26
-+ return IRQ_NONE;
-+#else
-+ return;
-+#endif
-+#else
-+ /* rtai */
-+ return;
-+#endif
-+ }
-+
-+ /* we assume a few things in this irq handler:
-+ - the hfc-pci will only generate "timer" irqs (proc/non-proc)
-+ - we need to use every 8th IRQ (to generate 1khz timing)
-+ OR
-+ - if we use rtai for timing the hfc-pci will not generate ANY irq,
-+ instead rtai will call this "fake" irq with a 1khz realtime timer. :)
-+ - rtai will directly service the card, not like it used to by triggering
-+ the linux irq
-+ */
-+
-+#ifndef RTAITIMING
-+ spin_lock_irqsave(&hfctmp->lock, flags);
-+ stat = hfc_inb(hfctmp, hfc_STATUS);
-+
-+ if ((stat & hfc_STATUS_ANYINT) == 0) {
-+ // maybe we are sharing the irq
-+ spin_unlock_irqrestore(&hfctmp->lock,flags);
-+#ifdef LINUX26
-+ return IRQ_NONE;
-+#else
-+ return;
-+#endif
-+ }
-+#endif
-+
-+ s1 = hfc_inb(hfctmp, hfc_INT_S1);
-+ s2 = hfc_inb(hfctmp, hfc_INT_S2);
-+ if (s1 != 0) {
-+ if (s1 & hfc_INTS_TIMER) {
-+ // timer (bit 7)
-+ // printk(KERN_CRIT "timer %d %d %d.\n", stat, s1, s2);
-+ }
-+ if (s1 & hfc_INTS_L1STATE) {
-+ // state machine (bit 6)
-+ // printk(KERN_CRIT "zaphfc: layer 1 state machine interrupt\n");
-+ zthfc = hfctmp->ztdev;
-+ l1state = hfc_inb(hfctmp,hfc_STATES) & hfc_STATES_STATE_MASK;
-+ if (hfctmp->regs.nt_mode == 1) {
-+ if (debug) {
-+ printk(KERN_CRIT "zaphfc: card %d layer 1 state = G%d\n", hfctmp->cardno, l1state);
-+ }
-+ switch (l1state) {
-+ case 3:
-+#ifdef RTAITIMING
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [NT] layer 1 ACTIVATED (G%d) [realtime]", hfctmp->cardno, l1state);
-+#else
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [NT] layer 1 ACTIVATED (G%d)", hfctmp->cardno, l1state);
-+#endif
-+ break;
-+ default:
-+#ifdef RTAITIMING
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [NT] layer 1 DEACTIVATED (G%d) [realtime]", hfctmp->cardno, l1state);
-+#else
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [NT] layer 1 DEACTIVATED (G%d)", hfctmp->cardno, l1state);
-+#endif
-+ }
-+ if (l1state == 2) {
-+ hfc_outb(hfctmp, hfc_STATES, hfc_STATES_ACTIVATE | hfc_STATES_DO_ACTION | hfc_STATES_NT_G2_G3);
-+ } else if (l1state == 3) {
-+ // fix to G3 state (see specs)
-+ hfc_outb(hfctmp, hfc_STATES, hfc_STATES_LOAD_STATE | 3);
-+ }
-+ } else {
-+ if (debug) {
-+ printk(KERN_CRIT "zaphfc: card %d layer 1 state = F%d\n", hfctmp->cardno, l1state);
-+ }
-+ switch (l1state) {
-+ case 7:
-+#ifdef RTAITIMING
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [TE] layer 1 ACTIVATED (F%d) [realtime]", hfctmp->cardno, l1state);
-+#else
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [TE] layer 1 ACTIVATED (F%d)", hfctmp->cardno, l1state);
-+#endif
-+ break;
-+ default:
-+#ifdef RTAITIMING
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [TE] layer 1 DEACTIVATED (F%d) [realtime]", hfctmp->cardno, l1state);
-+#else
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [TE] layer 1 DEACTIVATED (F%d)", hfctmp->cardno, l1state);
-+#endif
-+ }
-+ if (l1state == 3) {
-+ hfc_outb(hfctmp, hfc_STATES, hfc_STATES_DO_ACTION | hfc_STATES_ACTIVATE);
-+ }
-+ }
-+
-+ }
-+ if (s1 & hfc_INTS_DREC) {
-+ // D chan RX (bit 5)
-+ hfctmp->regs.int_drec++;
-+ // mr. zapata there is something for you!
-+ // printk(KERN_CRIT "d chan rx\n");
-+ }
-+ if (s1 & hfc_INTS_B2REC) {
-+ // B2 chan RX (bit 4)
-+ }
-+ if (s1 & hfc_INTS_B1REC) {
-+ // B1 chan RX (bit 3)
-+ }
-+ if (s1 & hfc_INTS_DTRANS) {
-+ // D chan TX (bit 2)
-+// printk(KERN_CRIT "zaphfc: dchan frame transmitted.\n");
-+ }
-+ if (s1 & hfc_INTS_B2TRANS) {
-+ // B2 chan TX (bit 1)
-+ }
-+ if (s1 & hfc_INTS_B1TRANS) {
-+ // B1 chan TX (bit 0)
-+ }
-+ }
-+#ifdef RTAITIMING
-+ /* fake an irq */
-+ s2 |= hfc_M2_PROC_TRANS;
-+#endif
-+ if (s2 != 0) {
-+ if (s2 & hfc_M2_PMESEL) {
-+ // kaboom irq (bit 7)
-+ printk(KERN_CRIT "zaphfc: sync lost, pci performance too low. you might have some cpu throtteling enabled.\n");
-+ }
-+ if (s2 & hfc_M2_GCI_MON_REC) {
-+ // RxR monitor channel (bit 2)
-+ }
-+ if (s2 & hfc_M2_GCI_I_CHG) {
-+ // GCI I-change (bit 1)
-+ }
-+ if (s2 & hfc_M2_PROC_TRANS) {
-+ // processing/non-processing transition (bit 0)
-+ hfctmp->ticks++;
-+#ifndef RTAITIMING
-+ if (hfctmp->ticks > 7) {
-+ // welcome to zaptel timing :)
-+#endif
-+ hfctmp->ticks = 0;
-+
-+ if (hfctmp->ztdev->span.flags & ZT_FLAG_RUNNING) {
-+ // clear dchan buffer
-+ hfctmp->ztdev->chans[2].bytes2transmit = 0;
-+ hfctmp->ztdev->chans[2].maxbytes2transmit = hfc_D_FIFO_SIZE;
-+
-+ zt_transmit(&(hfctmp->ztdev->span));
-+
-+ hfc_btrans(hfctmp,1);
-+ hfc_btrans(hfctmp,2);
-+ hfc_dtrans(hfctmp);
-+ }
-+
-+ hfc_brec(hfctmp,1);
-+ hfc_brec(hfctmp,2);
-+ if (hfctmp->regs.int_drec > 0) {
-+ // dchan data to read
-+ hfc_drec(hfctmp);
-+ if (hfctmp->ztdev->chans[2].bytes2receive > 0) {
-+ if (debug) {
-+ printk(KERN_CRIT "zaphfc: card %d RX [ ", hfctmp->cardno);
-+ if (hfctmp->ztdev->chans[2].eofrx) {
-+ /* dont output CRC == less user confusion */
-+ for (x=0; x < hfctmp->ztdev->chans[2].bytes2receive - 2; x++) {
-+ printk("%#2x ", hfctmp->drecbuf[x]);
-+ }
-+ printk("] %d bytes\n", hfctmp->ztdev->chans[2].bytes2receive - 2);
-+ } else {
-+ for (x=0; x < hfctmp->ztdev->chans[2].bytes2receive; x++) {
-+ printk("%#2x ", hfctmp->drecbuf[x]);
-+ }
-+ printk("..] %d bytes\n", hfctmp->ztdev->chans[2].bytes2receive);
-+ }
-+ }
-+ }
-+ } else {
-+ // hmm....ok, let zaptel receive nothing
-+ hfctmp->ztdev->chans[2].bytes2receive = 0;
-+ }
-+ if (hfctmp->ztdev->span.flags & ZT_FLAG_RUNNING) {
-+ zt_receive(&(hfctmp->ztdev->span));
-+ }
-+
-+#ifndef RTAITIMING
-+ }
-+#endif
-+ }
-+
-+ }
-+#ifndef RTAITIMING
-+ spin_unlock_irqrestore(&hfctmp->lock,flags);
-+#ifdef LINUX26
-+ return IRQ_RETVAL(1);
-+#endif
-+#endif
-+}
-+
-+
-+static int zthfc_open(struct zt_chan *chan) {
-+ struct zt_hfc *zthfc = chan->pvt;
-+ struct hfc_card *hfctmp = zthfc->card;
-+
-+ if (!hfctmp) {
-+ return 0;
-+ }
-+#ifndef LINUX26
-+ MOD_INC_USE_COUNT;
-+#else
-+ try_module_get(THIS_MODULE);
-+#endif
-+ return 0;
-+}
-+
-+static int zthfc_close(struct zt_chan *chan) {
-+ struct zt_hfc *zthfc = chan->pvt;
-+ struct hfc_card *hfctmp = zthfc->card;
-+
-+ if (!hfctmp) {
-+ return 0;
-+ }
-+
-+#ifndef LINUX26
-+ MOD_DEC_USE_COUNT;
-+#else
-+ module_put(THIS_MODULE);
-+#endif
-+ return 0;
-+}
-+
-+static int zthfc_rbsbits(struct zt_chan *chan, int bits) {
-+ return 0;
-+}
-+
-+static int zthfc_ioctl(struct zt_chan *chan, unsigned int cmd, unsigned long data) {
-+ switch(cmd) {
-+ default:
-+ return -ENOTTY;
-+ }
-+ return 0;
-+}
-+
-+static int zthfc_startup(struct zt_span *span) {
-+ struct zt_hfc *zthfc = span->pvt;
-+ struct hfc_card *hfctmp = zthfc->card;
-+ int alreadyrunning;
-+
-+ if (hfctmp == NULL) {
-+ printk(KERN_INFO "zaphfc: no card for span at startup!\n");
-+ }
-+ alreadyrunning = span->flags & ZT_FLAG_RUNNING;
-+
-+ if (!alreadyrunning) {
-+ span->chans[2].flags &= ~ZT_FLAG_HDLC;
-+ span->chans[2].flags |= ZT_FLAG_BRIDCHAN;
-+
-+ span->flags |= ZT_FLAG_RUNNING;
-+
-+ hfctmp->ticks = -2;
-+ hfctmp->clicks = 0;
-+ hfctmp->regs.fifo_en = hfc_FIFOEN_D | hfc_FIFOEN_B1 | hfc_FIFOEN_B2;
-+ hfc_outb(hfctmp, hfc_FIFO_EN, hfctmp->regs.fifo_en);
-+ } else {
-+ return 0;
-+ }
-+
-+ // drivers, start engines!
-+ hfc_outb(hfctmp, hfc_STATES, hfc_STATES_DO_ACTION | hfc_STATES_ACTIVATE);
-+ return 0;
-+}
-+
-+static int zthfc_shutdown(struct zt_span *span) {
-+ return 0;
-+}
-+
-+static int zthfc_maint(struct zt_span *span, int cmd) {
-+ return 0;
-+}
-+
-+static int zthfc_chanconfig(struct zt_chan *chan, int sigtype) {
-+// printk(KERN_CRIT "chan_config sigtype=%d\n", sigtype);
-+ return 0;
-+}
-+
-+static int zthfc_spanconfig(struct zt_span *span, struct zt_lineconfig *lc) {
-+ span->lineconfig = lc->lineconfig;
-+ return 0;
-+}
-+
-+static int zthfc_initialize(struct zt_hfc *zthfc) {
-+ struct hfc_card *hfctmp = zthfc->card;
-+ int i;
-+
-+ memset(&zthfc->span, 0x0, sizeof(struct zt_span)); // you never can tell...
-+
-+ sprintf(zthfc->span.name, "ZTHFC%d", hfc_dev_count + 1);
-+ if (hfctmp->regs.nt_mode == 1) {
-+#ifdef RTAITIMING
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [NT] [realtime]", hfc_dev_count + 1);
-+#else
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [NT]", hfc_dev_count + 1);
-+#endif
-+ } else {
-+#ifdef RTAITIMING
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [TE] [realtime]", hfc_dev_count + 1);
-+#else
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [TE]", hfc_dev_count + 1);
-+#endif
-+ }
-+
-+ zthfc->span.spanconfig = zthfc_spanconfig;
-+ zthfc->span.chanconfig = zthfc_chanconfig;
-+ zthfc->span.startup = zthfc_startup;
-+ zthfc->span.shutdown = zthfc_shutdown;
-+ zthfc->span.maint = zthfc_maint;
-+ zthfc->span.rbsbits = zthfc_rbsbits;
-+ zthfc->span.open = zthfc_open;
-+ zthfc->span.close = zthfc_close;
-+ zthfc->span.ioctl = zthfc_ioctl;
-+
-+ zthfc->span.chans = zthfc->chans;
-+ zthfc->span.channels = 3;
-+ zthfc->span.deflaw = ZT_LAW_ALAW;
-+ zthfc->span.linecompat = ZT_CONFIG_AMI | ZT_CONFIG_CCS; // <--- this is really BS
-+ zthfc->span.offset = 0;
-+ init_waitqueue_head(&zthfc->span.maintq);
-+ zthfc->span.pvt = zthfc;
-+
-+ for (i = 0; i < zthfc->span.channels; i++) {
-+ memset(&(zthfc->chans[i]), 0x0, sizeof(struct zt_chan));
-+ sprintf(zthfc->chans[i].name, "ZTHFC%d/%d/%d", hfc_dev_count + 1,0,i + 1);
-+ zthfc->chans[i].pvt = zthfc;
-+ zthfc->chans[i].sigcap = ZT_SIG_EM | ZT_SIG_CLEAR | ZT_SIG_FXSLS | ZT_SIG_FXSGS | ZT_SIG_FXSKS | ZT_SIG_FXOLS | ZT_SIG_FXOGS | ZT_SIG_FXOKS | ZT_SIG_CAS | ZT_SIG_SF;
-+ zthfc->chans[i].chanpos = i + 1;
-+ }
-+
-+ if (zt_register(&zthfc->span,0)) {
-+ printk(KERN_CRIT "unable to register zaptel device!\n");
-+ return -1;
-+ }
-+// printk(KERN_CRIT "zaphfc: registered zaptel device!\n");
-+ return 0;
-+}
-+
-+#ifdef RTAITIMING
-+#define TICK_PERIOD 1000000
-+#define TICK_PERIOD2 1000000000
-+#define TASK_PRIORITY 1
-+#define STACK_SIZE 10000
-+
-+static RT_TASK rt_task;
-+static struct hfc_card *rtai_hfc_list[hfc_MAX_CARDS];
-+static unsigned char rtai_hfc_counter = 0;
-+
-+static void rtai_register_hfc(struct hfc_card *hfctmp) {
-+ rtai_hfc_list[rtai_hfc_counter++] = hfctmp;
-+}
-+
-+static void rtai_loop(int t) {
-+ int i=0;
-+ for (;;) {
-+ for (i=0; i < rtai_hfc_counter; i++) {
-+ if (rtai_hfc_list[i] != NULL)
-+ hfc_service(rtai_hfc_list[i]);
-+ }
-+ rt_task_wait_period();
-+ }
-+}
-+#endif
-+
-+int hfc_findCards(int pcivendor, int pcidevice, char *vendor_name, char *card_name) {
-+ struct pci_dev *tmp;
-+ struct hfc_card *hfctmp = NULL;
-+ struct zt_hfc *zthfc = NULL;
-+
-+ tmp = pci_find_device(pcivendor, pcidevice, multi_hfc);
-+ while (tmp != NULL) {
-+ multi_hfc = tmp; // skip this next time.
-+
-+ if (pci_enable_device(tmp)) {
-+ multi_hfc = NULL;
-+ return -1;
-+ }
-+ pci_set_master(tmp);
-+
-+ hfctmp = kmalloc(sizeof(struct hfc_card), GFP_KERNEL);
-+ if (!hfctmp) {
-+ printk(KERN_WARNING "zaphfc: unable to kmalloc!\n");
-+ pci_disable_device(tmp);
-+ multi_hfc = NULL;
-+ return -ENOMEM;
-+ }
-+ memset(hfctmp, 0x0, sizeof(struct hfc_card));
-+ spin_lock_init(&hfctmp->lock);
-+
-+ hfctmp->pcidev = tmp;
-+ hfctmp->pcibus = tmp->bus->number;
-+ hfctmp->pcidevfn = tmp->devfn;
-+
-+ if (!tmp->irq) {
-+ printk(KERN_WARNING "zaphfc: no irq!\n");
-+ } else {
-+ hfctmp->irq = tmp->irq;
-+ }
-+
-+ hfctmp->pci_io = (char *) tmp->resource[1].start;
-+ if (!hfctmp->pci_io) {
-+ printk(KERN_WARNING "zaphfc: no iomem!\n");
-+ kfree(hfctmp);
-+ pci_disable_device(tmp);
-+ multi_hfc = NULL;
-+ return -1;
-+ }
-+
-+ hfctmp->fifomem = kmalloc(65536, GFP_KERNEL);
-+ if (!hfctmp->fifomem) {
-+ printk(KERN_WARNING "zaphfc: unable to kmalloc fifomem!\n");
-+ kfree(hfctmp);
-+ pci_disable_device(tmp);
-+ multi_hfc = NULL;
-+ return -ENOMEM;
-+ } else {
-+ memset(hfctmp->fifomem, 0x0, 65536);
-+ hfctmp->fifos = (((ulong) hfctmp->fifomem) & ~0x7FFF) + 0x8000;
-+ pci_write_config_dword(hfctmp->pcidev, 0x80, (u_int) virt_to_bus(hfctmp->fifos));
-+ hfctmp->pci_io = ioremap((ulong) hfctmp->pci_io, 256);
-+ }
-+
-+#ifdef RTAITIMING
-+ /* we need no stinking irq */
-+ hfctmp->irq = 0;
-+#else
-+ if (request_irq(hfctmp->irq, &hfc_interrupt, SA_INTERRUPT | SA_SHIRQ, "zaphfc", hfctmp)) {
-+ printk(KERN_WARNING "zaphfc: unable to register irq\n");
-+ kfree(hfctmp->fifomem);
-+ kfree(hfctmp);
-+ iounmap((void *) hfctmp->pci_io);
-+ pci_disable_device(tmp);
-+ multi_hfc = NULL;
-+ return -EIO;
-+ }
-+#endif
-+
-+#ifdef RTAITIMING
-+ rtai_register_hfc(hfctmp);
-+#endif
-+ printk(KERN_INFO
-+ "zaphfc: %s %s configured at mem %#x fifo %#x(%#x) IRQ %d HZ %d\n",
-+ vendor_name, card_name,
-+ (u_int) hfctmp->pci_io,
-+ (u_int) hfctmp->fifos,
-+ (u_int) virt_to_bus(hfctmp->fifos),
-+ hfctmp->irq, HZ);
-+ pci_write_config_word(hfctmp->pcidev, PCI_COMMAND, PCI_COMMAND_MEMORY); // enable memio
-+ hfctmp->regs.int_m1 = 0; // no ints
-+ hfctmp->regs.int_m2 = 0; // not at all
-+ hfc_outb(hfctmp,hfc_INT_M1,hfctmp->regs.int_m1);
-+ hfc_outb(hfctmp,hfc_INT_M2,hfctmp->regs.int_m2);
-+
-+ if ((modes & (1 << hfc_dev_count)) != 0) {
-+ printk(KERN_INFO "zaphfc: Card %d configured for NT mode\n",hfc_dev_count);
-+ hfctmp->regs.nt_mode = 1;
-+ } else {
-+ printk(KERN_INFO "zaphfc: Card %d configured for TE mode\n",hfc_dev_count);
-+ hfctmp->regs.nt_mode = 0;
-+ }
-+
-+ zthfc = kmalloc(sizeof(struct zt_hfc),GFP_KERNEL);
-+ if (!zthfc) {
-+ printk(KERN_CRIT "zaphfc: unable to kmalloc!\n");
-+ hfc_shutdownCard(hfctmp);
-+ kfree(hfctmp);
-+ multi_hfc = NULL;
-+ return -ENOMEM;
-+ }
-+ memset(zthfc, 0x0, sizeof(struct zt_hfc));
-+
-+ zthfc->card = hfctmp;
-+ zthfc_initialize(zthfc);
-+ hfctmp->ztdev = zthfc;
-+
-+ memset(hfctmp->drecbuf, 0x0, sizeof(hfctmp->drecbuf));
-+ hfctmp->ztdev->chans[2].readchunk = hfctmp->drecbuf;
-+
-+ memset(hfctmp->dtransbuf, 0x0, sizeof(hfctmp->dtransbuf));
-+ hfctmp->ztdev->chans[2].writechunk = hfctmp->dtransbuf;
-+
-+ memset(hfctmp->brecbuf[0], 0x0, sizeof(hfctmp->brecbuf[0]));
-+ hfctmp->ztdev->chans[0].readchunk = hfctmp->brecbuf[0];
-+ memset(hfctmp->btransbuf[0], 0x0, sizeof(hfctmp->btransbuf[0]));
-+ hfctmp->ztdev->chans[0].writechunk = hfctmp->btransbuf[0];
-+
-+ memset(hfctmp->brecbuf[1], 0x0, sizeof(hfctmp->brecbuf[1]));
-+ hfctmp->ztdev->chans[1].readchunk = hfctmp->brecbuf[1];
-+ memset(hfctmp->btransbuf[1], 0x0, sizeof(hfctmp->btransbuf[1]));
-+ hfctmp->ztdev->chans[1].writechunk = hfctmp->btransbuf[1];
-+
-+
-+ hfc_registerCard(hfctmp);
-+ hfc_resetCard(hfctmp);
-+ tmp = pci_find_device(pcivendor, pcidevice, multi_hfc);
-+ }
-+ return 0;
-+}
-+
-+
-+
-+int init_module(void) {
-+ int i = 0;
-+#ifdef RTAITIMING
-+ RTIME tick_period;
-+ for (i=0; i < hfc_MAX_CARDS; i++) {
-+ rtai_hfc_list[i] = NULL;
-+ }
-+ rt_set_periodic_mode();
-+#endif
-+ i = 0;
-+ while (id_list[i].vendor_id) {
-+ multi_hfc = NULL;
-+ hfc_findCards(id_list[i].vendor_id, id_list[i].device_id, id_list[i].vendor_name, id_list[i].card_name);
-+ i++;
-+ }
-+#ifdef RTAITIMING
-+ for (i=0; i < hfc_MAX_CARDS; i++) {
-+ if (rtai_hfc_list[i]) {
-+ printk(KERN_INFO
-+ "zaphfc: configured %d at mem %#x fifo %#x(%#x) for realtime servicing\n",
-+ rtai_hfc_list[i]->cardno,
-+ (u_int) rtai_hfc_list[i]->pci_io,
-+ (u_int) rtai_hfc_list[i]->fifos,
-+ (u_int) virt_to_bus(rtai_hfc_list[i]->fifos));
-+
-+ }
-+ }
-+ rt_task_init(&rt_task, rtai_loop, 1, STACK_SIZE, TASK_PRIORITY, 0, 0);
-+ tick_period = start_rt_timer(nano2count(TICK_PERIOD));
-+ rt_task_make_periodic(&rt_task, rt_get_time() + tick_period, tick_period);
-+#endif
-+ printk(KERN_INFO "zaphfc: %d hfc-pci card(s) in this box.\n", hfc_dev_count);
-+ return 0;
-+}
-+
-+void cleanup_module(void) {
-+ struct hfc_card *tmpcard;
-+#ifdef RTAITIMING
-+ stop_rt_timer();
-+ rt_task_delete(&rt_task);
-+#endif
-+ printk(KERN_INFO "zaphfc: stop\n");
-+// spin_lock(®isterlock);
-+ while (hfc_dev_list != NULL) {
-+ if (hfc_dev_list == NULL) break;
-+ hfc_shutdownCard(hfc_dev_list);
-+ tmpcard = hfc_dev_list;
-+ hfc_dev_list = hfc_dev_list->next;
-+ if (tmpcard != NULL) {
-+ kfree(tmpcard);
-+ tmpcard = NULL;
-+ printk(KERN_INFO "zaphfc: freed one card.\n");
-+ }
-+ }
-+// spin_unlock(®isterlock);
-+}
-+#endif
-+
-+
-+MODULE_DESCRIPTION("HFC-S PCI A Zaptel Driver");
-+MODULE_AUTHOR("Klaus-Peter Junghanns <kpj at junghanns.net>");
-+#ifdef MODULE_LICENSE
-+MODULE_LICENSE("GPL");
-+#endif
-+MODULE_PARM(modes,"i");
-+MODULE_PARM(debug,"i");
-diff -urNad zaptel-1.2.1/zaphfc/zaphfc.h /tmp/dpep.RTh8jH/zaptel-1.2.1/zaphfc/zaphfc.h
---- zaptel-1.2.1/zaphfc/zaphfc.h 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.RTh8jH/zaptel-1.2.1/zaphfc/zaphfc.h 2005-02-27 00:30:32.000000000 +0200
-@@ -0,0 +1,289 @@
-+/*
-+ * zaphfc.h - Zaptel driver for HFC-S PCI A based ISDN BRI cards
-+ *
-+ * kernel module based on HFC PCI ISDN4Linux and Zaptel drivers
-+ *
-+ * Copyright (C) 2002, 2003, 2004, 2005 Junghanns.NET GmbH
-+ *
-+ * Klaus-Peter Junghanns <kpj at junghanns.net>
-+ *
-+ * This program is free software and may be modified and
-+ * distributed under the terms of the GNU Public License.
-+ *
-+ */
-+
-+/* HFC register addresses - accessed using memory mapped I/O */
-+/* For a list, see datasheet section 3.2.1 at page 21 */
-+
-+#define hfc_outb(a,b,c) (writeb((c),(a)->pci_io+(b)))
-+#define hfc_inb(a,b) (readb((a)->pci_io+(b)))
-+
-+/* GCI/IOM bus monitor registers */
-+
-+#define hfc_C_I 0x08
-+#define hfc_TRxR 0x0C
-+#define hfc_MON1_D 0x28
-+#define hfc_MON2_D 0x2C
-+
-+
-+/* GCI/IOM bus timeslot registers */
-+
-+#define hfc_B1_SSL 0x80
-+#define hfc_B2_SSL 0x84
-+#define hfc_AUX1_SSL 0x88
-+#define hfc_AUX2_SSL 0x8C
-+#define hfc_B1_RSL 0x90
-+#define hfc_B2_RSL 0x94
-+#define hfc_AUX1_RSL 0x98
-+#define hfc_AUX2_RSL 0x9C
-+
-+/* GCI/IOM bus data registers */
-+
-+#define hfc_B1_D 0xA0
-+#define hfc_B2_D 0xA4
-+#define hfc_AUX1_D 0xA8
-+#define hfc_AUX2_D 0xAC
-+
-+/* GCI/IOM bus configuration registers */
-+
-+#define hfc_MST_EMOD 0xB4
-+#define hfc_MST_MODE 0xB8
-+#define hfc_CONNECT 0xBC
-+
-+
-+/* Interrupt and status registers */
-+
-+#define hfc_FIFO_EN 0x44
-+#define hfc_TRM 0x48
-+#define hfc_B_MODE 0x4C
-+#define hfc_CHIP_ID 0x58
-+#define hfc_CIRM 0x60
-+#define hfc_CTMT 0x64
-+#define hfc_INT_M1 0x68
-+#define hfc_INT_M2 0x6C
-+#define hfc_INT_S1 0x78
-+#define hfc_INT_S2 0x7C
-+#define hfc_STATUS 0x70
-+
-+/* S/T section registers */
-+
-+#define hfc_STATES 0xC0
-+#define hfc_SCTRL 0xC4
-+#define hfc_SCTRL_E 0xC8
-+#define hfc_SCTRL_R 0xCC
-+#define hfc_SQ 0xD0
-+#define hfc_CLKDEL 0xDC
-+#define hfc_B1_REC 0xF0
-+#define hfc_B1_SEND 0xF0
-+#define hfc_B2_REC 0xF4
-+#define hfc_B2_SEND 0xF4
-+#define hfc_D_REC 0xF8
-+#define hfc_D_SEND 0xF8
-+#define hfc_E_REC 0xFC
-+
-+/* Bits and values in various HFC PCI registers */
-+
-+/* bits in status register (READ) */
-+#define hfc_STATUS_PCI_PROC 0x02
-+#define hfc_STATUS_NBUSY 0x04
-+#define hfc_STATUS_TIMER_ELAP 0x10
-+#define hfc_STATUS_STATINT 0x20
-+#define hfc_STATUS_FRAMEINT 0x40
-+#define hfc_STATUS_ANYINT 0x80
-+
-+/* bits in CTMT (Write) */
-+#define hfc_CTMT_CLTIMER 0x80
-+#define hfc_CTMT_TIM3_125 0x04
-+#define hfc_CTMT_TIM25 0x10
-+#define hfc_CTMT_TIM50 0x14
-+#define hfc_CTMT_TIM400 0x18
-+#define hfc_CTMT_TIM800 0x1C
-+#define hfc_CTMT_AUTO_TIMER 0x20
-+#define hfc_CTMT_TRANSB2 0x02
-+#define hfc_CTMT_TRANSB1 0x01
-+
-+/* bits in CIRM (Write) */
-+#define hfc_CIRM_AUX_MSK 0x07
-+#define hfc_CIRM_RESET 0x08
-+#define hfc_CIRM_B1_REV 0x40
-+#define hfc_CIRM_B2_REV 0x80
-+
-+/* bits in INT_M1 and INT_S1 */
-+#define hfc_INTS_B1TRANS 0x01
-+#define hfc_INTS_B2TRANS 0x02
-+#define hfc_INTS_DTRANS 0x04
-+#define hfc_INTS_B1REC 0x08
-+#define hfc_INTS_B2REC 0x10
-+#define hfc_INTS_DREC 0x20
-+#define hfc_INTS_L1STATE 0x40
-+#define hfc_INTS_TIMER 0x80
-+
-+/* bits in INT_M2 */
-+#define hfc_M2_PROC_TRANS 0x01
-+#define hfc_M2_GCI_I_CHG 0x02
-+#define hfc_M2_GCI_MON_REC 0x04
-+#define hfc_M2_IRQ_ENABLE 0x08
-+#define hfc_M2_PMESEL 0x80
-+
-+/* bits in STATES */
-+#define hfc_STATES_STATE_MASK 0x0F
-+#define hfc_STATES_LOAD_STATE 0x10
-+#define hfc_STATES_ACTIVATE 0x20
-+#define hfc_STATES_DO_ACTION 0x40
-+#define hfc_STATES_NT_G2_G3 0x80
-+
-+/* bits in HFCD_MST_MODE */
-+#define hfc_MST_MODE_MASTER 0x01
-+#define hfc_MST_MODE_SLAVE 0x00
-+/* remaining bits are for codecs control */
-+
-+/* bits in HFCD_SCTRL */
-+#define hfc_SCTRL_B1_ENA 0x01
-+#define hfc_SCTRL_B2_ENA 0x02
-+#define hfc_SCTRL_MODE_TE 0x00
-+#define hfc_SCTRL_MODE_NT 0x04
-+#define hfc_SCTRL_LOW_PRIO 0x08
-+#define hfc_SCTRL_SQ_ENA 0x10
-+#define hfc_SCTRL_TEST 0x20
-+#define hfc_SCTRL_NONE_CAP 0x40
-+#define hfc_SCTRL_PWR_DOWN 0x80
-+
-+/* bits in SCTRL_E */
-+#define hfc_SCTRL_E_AUTO_AWAKE 0x01
-+#define hfc_SCTRL_E_DBIT_1 0x04
-+#define hfc_SCTRL_E_IGNORE_COL 0x08
-+#define hfc_SCTRL_E_CHG_B1_B2 0x80
-+
-+/* bits in FIFO_EN register */
-+#define hfc_FIFOEN_B1TX 0x01
-+#define hfc_FIFOEN_B1RX 0x02
-+#define hfc_FIFOEN_B2TX 0x04
-+#define hfc_FIFOEN_B2RX 0x08
-+#define hfc_FIFOEN_DTX 0x10
-+#define hfc_FIFOEN_DRX 0x20
-+
-+#define hfc_FIFOEN_B1 (hfc_FIFOEN_B1TX|hfc_FIFOEN_B1RX)
-+#define hfc_FIFOEN_B2 (hfc_FIFOEN_B2TX|hfc_FIFOEN_B2RX)
-+#define hfc_FIFOEN_D (hfc_FIFOEN_DTX|hfc_FIFOEN_DRX)
-+
-+/* bits in the CONNECT register */
-+#define hfc_CONNECT_B1_shift 0
-+#define hfc_CONNECT_B2_shift 3
-+
-+#define hfc_CONNECT_HFC_from_ST 0x0
-+#define hfc_CONNECT_HFC_from_GCI 0x1
-+#define hfc_CONNECT_ST_from_HFC 0x0
-+#define hfc_CONNECT_ST_from_GCI 0x2
-+#define hfc_CONNECT_GCI_from_HFC 0x0
-+#define hfc_CONNECT_GCI_from_ST 0x4
-+
-+/* bits in the __SSL and __RSL registers */
-+#define hfc_SRSL_STIO 0x40
-+#define hfc_SRSL_ENABLE 0x80
-+#define hfc_SRCL_SLOT_MASK 0x1f
-+
-+/* FIFO memory definitions */
-+
-+#define hfc_FMASK 0x000f
-+#define hfc_ZMASK 0x01ff
-+#define hfc_ZMASKB 0x1fff
-+
-+#define hfc_D_FIFO_SIZE 0x0200
-+#define hfc_B_SUB_VAL 0x0200
-+#define hfc_B_FIFO_SIZE 0x1E00
-+#define hfc_MAX_DFRAMES 0x000f
-+
-+#define hfc_FIFO_DTX_Z1 0x2080
-+#define hfc_FIFO_DTX_Z2 0x2082
-+#define hfc_FIFO_DTX_F1 0x20a0
-+#define hfc_FIFO_DTX_F2 0x20a1
-+#define hfc_FIFO_DTX 0x0000
-+#define hfc_FIFO_DTX_ZOFF 0x000
-+
-+#define hfc_FIFO_DRX_Z1 0x6080
-+#define hfc_FIFO_DRX_Z2 0x6082
-+#define hfc_FIFO_DRX_F1 0x60a0
-+#define hfc_FIFO_DRX_F2 0x60a1
-+#define hfc_FIFO_DRX 0x4000
-+#define hfc_FIFO_DRX_ZOFF 0x4000
-+
-+#define hfc_FIFO_B1TX_Z1 0x2000
-+#define hfc_FIFO_B1TX_Z2 0x2002
-+#define hfc_FIFO_B1RX_Z1 0x6000
-+#define hfc_FIFO_B1RX_Z2 0x6002
-+
-+#define hfc_FIFO_B1TX_F1 0x2080
-+#define hfc_FIFO_B1TX_F2 0x2081
-+#define hfc_FIFO_B1RX_F1 0x6080
-+#define hfc_FIFO_B1RX_F2 0x6081
-+
-+#define hfc_FIFO_B1RX_ZOFF 0x4000
-+#define hfc_FIFO_B1TX_ZOFF 0x0000
-+
-+#define hfc_FIFO_B2TX_Z1 0x2100
-+#define hfc_FIFO_B2TX_Z2 0x2102
-+#define hfc_FIFO_B2RX_Z1 0x6100
-+#define hfc_FIFO_B2RX_Z2 0x6102
-+
-+#define hfc_FIFO_B2TX_F1 0x2180
-+#define hfc_FIFO_B2TX_F2 0x2181
-+#define hfc_FIFO_B2RX_F1 0x6180
-+#define hfc_FIFO_B2RX_F2 0x6181
-+
-+#define hfc_FIFO_B2RX_ZOFF 0x6000
-+#define hfc_FIFO_B2TX_ZOFF 0x2000
-+
-+#define hfc_BTRANS_THRESHOLD 128
-+#define hfc_BTRANS_THRESMASK 0x00
-+
-+/* Structures */
-+
-+typedef struct hfc_regs {
-+ unsigned char fifo_en;
-+ unsigned char ctmt;
-+ unsigned char int_m1;
-+ unsigned char int_m2;
-+ unsigned char sctrl;
-+ unsigned char sctrl_e;
-+ unsigned char sctrl_r;
-+ unsigned char connect;
-+ unsigned char trm;
-+ unsigned char mst_mode;
-+ unsigned char bswapped;
-+ unsigned char nt_mode;
-+ unsigned char int_drec;
-+} hfc_regs;
-+
-+typedef struct hfc_card {
-+ spinlock_t lock;
-+ unsigned int irq;
-+ unsigned int iomem;
-+ int ticks;
-+ int clicks;
-+ unsigned char *pci_io;
-+ void *fifomem; // start of the shared mem
-+ volatile void *fifos; // 32k aligned mem for the fifos
-+ struct hfc_regs regs;
-+ unsigned int pcibus;
-+ unsigned int pcidevfn;
-+ struct pci_dev *pcidev;
-+ struct zt_hfc *ztdev;
-+ int drecinframe;
-+ unsigned char drecbuf[hfc_D_FIFO_SIZE];
-+ unsigned char dtransbuf[hfc_D_FIFO_SIZE];
-+ unsigned char brecbuf[2][ZT_CHUNKSIZE];
-+ unsigned char btransbuf[2][ZT_CHUNKSIZE];
-+ unsigned char cardno;
-+ struct hfc_card *next;
-+} hfc_card;
-+
-+typedef struct zt_hfc {
-+ unsigned int usecount;
-+ struct zt_span span;
-+ struct zt_chan chans[3];
-+ struct hfc_card *card;
-+} zt_hfc;
-+
-+/* tune this */
-+#define hfc_BCHAN_BUFFER 8
-+#define hfc_MAX_CARDS 8
-diff -urNad zaptel-1.2.1/zaphfc/zaptel.conf /tmp/dpep.RTh8jH/zaptel-1.2.1/zaphfc/zaptel.conf
---- zaptel-1.2.1/zaphfc/zaptel.conf 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.RTh8jH/zaptel-1.2.1/zaphfc/zaptel.conf 2004-03-24 16:35:12.000000000 +0200
-@@ -0,0 +1,8 @@
-+# hfc-s pci a span definition
-+# most of the values should be bogus because we are not really zaptel
-+loadzone=nl
-+defaultzone=nl
-+
-+span=1,1,3,ccs,ami
-+bchan=1-2
-+dchan=3
-diff -urNad zaptel-1.2.1/zaptel.c /tmp/dpep.RTh8jH/zaptel-1.2.1/zaptel.c
---- zaptel-1.2.1/zaptel.c 2005-12-02 02:03:01.000000000 +0200
-+++ /tmp/dpep.RTh8jH/zaptel-1.2.1/zaptel.c 2006-01-07 20:25:00.000000000 +0200
-@@ -4912,11 +4912,40 @@
- *(txb++) = fasthdlc_tx_run_nocheck(&ms->txhdlc);
- }
- bytes -= left;
-+#ifdef CONFIG_ZAPATA_BRI_DCHANS
-+ } else if (ms->flags & ZT_FLAG_BRIDCHAN) {
-+ /*
-+ * Let's get this right, we want to transmit complete frames only.
-+ * The card driver will do the dirty HDLC work for us.
-+ * txb (transmit buffer) is supposed to be big enough to store one frame
-+ * we will make this as big as the D fifo (1KB or 2KB)
-+ */
-+
-+ /* there are 'left' bytes in the user buffer left to transmit */
-+ left = ms->writen[ms->outwritebuf] - ms->writeidx[ms->outwritebuf] - 2;
-+ if (left > ms->maxbytes2transmit) {
-+ memcpy(txb, buf + ms->writeidx[ms->outwritebuf], ms->maxbytes2transmit);
-+ ms->writeidx[ms->outwritebuf] += ms->maxbytes2transmit;
-+ txb += ms->maxbytes2transmit;
-+ ms->bytes2transmit = ms->maxbytes2transmit;
-+ ms->eoftx = 0;
-+ } else {
-+ memcpy(txb, buf + ms->writeidx[ms->outwritebuf], left);
-+ ms->writeidx[ms->outwritebuf] += left + 2;
-+ txb += left;
-+ ms->bytes2transmit = left;
-+ ms->eoftx = 1;
-+ }
-+ bytes = 0;
-+#endif
- } else {
- memcpy(txb, buf + ms->writeidx[ms->outwritebuf], left);
- ms->writeidx[ms->outwritebuf]+=left;
- txb += left;
- bytes -= left;
-+#if defined(CONFIG_ZAPATA_BRI_DCHANS)
-+ ms->bytes2transmit=ZT_CHUNKSIZE;
-+#endif
- }
- /* Check buffer status */
- if (ms->writeidx[ms->outwritebuf] >= ms->writen[ms->outwritebuf]) {
-@@ -4961,6 +4990,17 @@
- /* Transmit a flag if this is an HDLC channel */
- if (ms->flags & ZT_FLAG_HDLC)
- fasthdlc_tx_frame_nocheck(&ms->txhdlc);
-+#if defined(CONFIG_ZAPATA_BRI_DCHANS)
-+ if(ms->flags & ZT_FLAG_BRIDCHAN) {
-+ // if (ms->bytes2transmit > 0) {
-+ // txb += 2;
-+ // ms->bytes2transmit -= 2;
-+ bytes=0;
-+ ms->eoftx = 1;
-+// printk(KERN_CRIT "zaptel EOF(%d) bytes2transmit %d\n",ms->eoftx,ms->bytes2transmit);
-+ // }
-+ }
-+#endif
- #ifdef CONFIG_ZAPATA_NET
- if (ms->flags & ZT_FLAG_NETDEV)
- netif_wake_queue(ztchan_to_dev(ms));
-@@ -5017,6 +5057,10 @@
- memset(txb, 0xFF, bytes);
- }
- bytes = 0;
-+#if defined(CONFIG_ZAPATA_BRI_DCHANS)
-+ } else if(ms->flags & ZT_FLAG_BRIDCHAN) {
-+ bytes = 0;
-+#endif
- } else {
- memset(txb, ZT_LIN2X(0, ms), bytes); /* Lastly we use silence on telephony channels */
- bytes = 0;
-@@ -5742,6 +5786,13 @@
- int left, x;
-
- int bytes = ZT_CHUNKSIZE;
-+#if defined(CONFIG_ZAPATA_BRI_DCHANS)
-+ if (ms->flags & ZT_FLAG_BRIDCHAN) {
-+ bytes = ms->bytes2receive;
-+ if (bytes < 1) return;
-+// printk(KERN_CRIT "bytes2receive %d\n",ms->bytes2receive);
-+ }
-+#endif
-
- while(bytes) {
- #if defined(CONFIG_ZAPATA_NET) || defined(CONFIG_ZAPATA_PPP)
-@@ -5800,6 +5851,19 @@
- }
- }
- }
-+#ifdef CONFIG_ZAPATA_BRI_DCHANS
-+ } else if (ms->flags & ZT_FLAG_BRIDCHAN) {
-+ memcpy(buf + ms->readidx[ms->inreadbuf], rxb, left);
-+ rxb += left;
-+ ms->readidx[ms->inreadbuf] += left;
-+ bytes -= left;
-+ if (ms->eofrx == 1) {
-+ eof=1;
-+ }
-+// printk(KERN_CRIT "receiving %d bytes\n",ms->bytes2receive);
-+ ms->bytes2receive = 0;
-+ ms->eofrx = 0;
-+#endif
- } else {
- /* Not HDLC */
- memcpy(buf + ms->readidx[ms->inreadbuf], rxb, left);
-diff -urNad zaptel-1.2.1/zaptel.h /tmp/dpep.RTh8jH/zaptel-1.2.1/zaptel.h
---- zaptel-1.2.1/zaptel.h 2005-11-29 20:42:08.000000000 +0200
-+++ /tmp/dpep.RTh8jH/zaptel-1.2.1/zaptel.h 2006-01-07 20:25:00.000000000 +0200
-@@ -981,6 +981,13 @@
- int do_ppp_error;
- struct sk_buff_head ppp_rq;
- #endif
-+#ifdef CONFIG_ZAPATA_BRI_DCHANS
-+ int bytes2receive;
-+ int maxbytes2transmit; /* size of the tx buffer in the card driver */
-+ int bytes2transmit;
-+ int eofrx;
-+ int eoftx;
-+#endif
- spinlock_t lock;
- char name[40]; /* Name */
- /* Specified by zaptel */
-@@ -1218,6 +1225,10 @@
- #define ZT_FLAG_T1PPP (1 << 15)
- #define ZT_FLAG_SIGFREEZE (1 << 16) /* Freeze signalling */
-
-+#if defined(CONFIG_ZAPATA_BRI_DCHANS)
-+#define ZT_FLAG_BRIDCHAN (1 << 17)
-+#endif
-+
- struct zt_span {
- spinlock_t lock;
- void *pvt; /* Private stuff */
-diff -urNad zaptel-1.2.1/zconfig.h /tmp/dpep.RTh8jH/zaptel-1.2.1/zconfig.h
---- zaptel-1.2.1/zconfig.h 2005-11-29 20:42:08.000000000 +0200
-+++ /tmp/dpep.RTh8jH/zaptel-1.2.1/zconfig.h 2006-01-07 20:25:00.000000000 +0200
-@@ -152,4 +152,10 @@
- */
- /* #define FXSFLASH */
-
-+/*
-+ * Uncomment the following for BRI D channels
-+ *
-+ */
-+#define CONFIG_ZAPATA_BRI_DCHANS
-+
- #endif
Deleted: zaptel/trunk/debian/patches/bristuff-0.3.0-PRE1h.dpatch
===================================================================
--- zaptel/trunk/debian/patches/bristuff-0.3.0-PRE1h.dpatch 2006-04-30 15:19:14 UTC (rev 1655)
+++ zaptel/trunk/debian/patches/bristuff-0.3.0-PRE1h.dpatch 2006-04-30 16:30:35 UTC (rev 1656)
@@ -1,6686 +0,0 @@
-#! /bin/sh /usr/share/dpatch/dpatch-run
-## bristuff-0.3.0-PRE1h.dpatch by <tzafrir@>
-##
-## All lines beginning with `## DP:' are a description of the patch.
-## DP: No description.
-
- at DPATCH@
-diff -urNad zaptel-1.2.2/cwain/cwain.c /tmp/dpep.xmeNb1/zaptel-1.2.2/cwain/cwain.c
---- zaptel-1.2.2/cwain/cwain.c 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.xmeNb1/zaptel-1.2.2/cwain/cwain.c 2005-10-11 17:36:14.000000000 +0200
-@@ -0,0 +1,1489 @@
-+/*
-+ * cwain.c - Zaptel driver for the Junghanns.NET E1 card
-+ *
-+ * c.w.a.i.n. == card without an interesting name
-+ *
-+ * single/double E1 board
-+ *
-+ * Copyright (C) 2004, 2005 Junghanns.NET GmbH
-+ *
-+ * Klaus-Peter Junghanns <kpj at junghanns.net>
-+ *
-+ * This program is free software and may be modified and
-+ * distributed under the terms of the GNU Public License.
-+ *
-+ */
-+#include <linux/kernel.h>
-+#include <linux/module.h>
-+#include <linux/pci.h>
-+#include <linux/init.h>
-+#include <linux/interrupt.h>
-+#include <zaptel.h>
-+#include "cwain.h"
-+
-+#if CONFIG_PCI
-+
-+static int ports=-1; /* autodetect */
-+static int debug=0;
-+static struct zt_cwain *cwain_span_list = NULL;
-+static int cwain_span_count = 0;
-+static struct zt_cwain_card *cwain_card_list = NULL;
-+static int cwain_card_count = 0;
-+static struct pci_dev *multi_cwain = NULL;
-+static spinlock_t cwain_span_registerlock = SPIN_LOCK_UNLOCKED;
-+static spinlock_t cwain_card_registerlock = SPIN_LOCK_UNLOCKED;
-+
-+static int ztcwain_shutdown(struct zt_span *span);
-+
-+int cwain_waitbusy(struct zt_cwain *cwaintmp) {
-+ int x=1000;
-+ while (x-- && (cwain_inb(cwaintmp,cwain_R_STATUS) & 1));
-+ if (x < 0) {
-+ printk(KERN_CRIT "cwain: really busy waiting!\n");
-+ return -1;
-+ } else {
-+ if ((x < 990) && (cwaintmp->ticks > 500)) {
-+ printk(KERN_CRIT "cwain: waited %d\n", 1000 - x);
-+ }
-+ return 0;
-+ }
-+}
-+
-+void cwain_unregister_zap_span(struct zt_cwain *cwainspan) {
-+ if (!cwainspan) {
-+ printk(KERN_INFO "cwain: shutting down NULL span!\n");
-+ return;
-+ }
-+ if(cwainspan->span.flags & ZT_FLAG_RUNNING) {
-+ ztcwain_shutdown(&cwainspan->span);
-+ if (debug)
-+ printk(KERN_INFO "cwain: shutdown span %d.\n",cwainspan->cardno);
-+ }
-+ if(cwainspan->span.flags & ZT_FLAG_REGISTERED) {
-+ zt_unregister(&cwainspan->span);
-+ if (debug)
-+ printk(KERN_INFO "cwain: unregistered span %d.\n",cwainspan->cardno);
-+ }
-+}
-+
-+void cwain_shutdown_span(struct zt_cwain *cwainspan) {
-+
-+ if (!cwainspan) {
-+ printk(KERN_INFO "cwain: shutting down NULL span!\n");
-+ return;
-+ }
-+
-+ if (cwainspan->pci_io == NULL) {
-+ return;
-+ }
-+
-+ if (debug)
-+ printk(KERN_INFO "cwain: shutting down span %d (cardID %d) at %p.\n",cwainspan->cardno,cwainspan->cardID,cwainspan->pci_io);
-+
-+ // turn off irqs
-+
-+ // softreset
-+ cwain_outb(cwainspan,cwain_R_CIRM,0x8);
-+ cwain_outb(cwainspan,cwain_R_CIRM,0x0);
-+ cwain_waitbusy(cwainspan);
-+
-+ cwain_outb(cwainspan,cwain_R_IRQMSK_MISC, 0);
-+ cwain_outb(cwainspan,cwain_R_IRQ_CTRL, 0);
-+
-+ pci_write_config_word(cwainspan->pcidev, PCI_COMMAND, 0); // disable memio
-+
-+ if (cwainspan->pcidev != NULL) {
-+ pci_disable_device(cwainspan->pcidev);
-+ cwainspan->pcidev = NULL;
-+ }
-+
-+// iounmap((void *) cwainspan->pci_io);
-+// cwainspan->pci_io = NULL;
-+}
-+
-+void cwain_shutdown_card(struct zt_cwain_card *cwaintmp) {
-+ unsigned long flags = 0;
-+ int i = 0;
-+
-+ if (!cwaintmp) {
-+ printk(KERN_INFO "cwain: shutting down NULL card!\n");
-+ return;
-+ }
-+
-+ for (i=0;i<cwaintmp->spans;i++) {
-+ cwain_unregister_zap_span(cwaintmp->span[i]);
-+ }
-+
-+ spin_lock_irqsave(&cwaintmp->lock,flags);
-+
-+ // turn off irqs
-+ cwain_outb(cwaintmp->span[0],cwain_R_IRQ_CTRL, 0);
-+ cwain_outb(cwaintmp->span[0],cwain_R_IRQMSK_MISC, 0);
-+
-+ for (i=0;i<cwaintmp->spans;i++) {
-+ cwain_shutdown_span(cwaintmp->span[i]);
-+ }
-+ spin_unlock_irqrestore(&cwaintmp->lock,flags);
-+
-+ for (i=0;i<cwaintmp->spans;i++) {
-+ iounmap((void *) cwaintmp->span[i]->pci_io);
-+ cwaintmp->span[i]->pci_io = NULL;
-+ }
-+
-+ free_irq(cwaintmp->irq,cwaintmp);
-+}
-+
-+void cwain_doLEDs(struct zt_cwain *cwaintmp) {
-+ /*
-+ O1 O3 (red)
-+ O2 O4 (green)
-+ */
-+ if (!(cwaintmp->span.flags & ZT_FLAG_RUNNING)) {
-+ return;
-+ }
-+ if ((cwaintmp->type == 0xb553) || (cwaintmp->type == 0xb554)) {
-+ /* sync status */
-+ if (((cwaintmp->sync_sta & 0x07) == 0x07) && cwaintmp->sync) {
-+ cwaintmp->leds[0] = 1;
-+ cwaintmp->leds[1] = 0;
-+ } else {
-+ cwaintmp->leds[0] = 0;
-+ cwaintmp->leds[1] = 1;
-+ }
-+ /* multiframe alignment */
-+ if ((cwaintmp->sync_sta & 0x20) == 0x20) {
-+ cwaintmp->leds[2] = 1;
-+ cwaintmp->leds[3] = 0;
-+ } else {
-+ if ((cwaintmp->span.lineconfig & ZT_CONFIG_CRC4) && cwaintmp->sync) {
-+ /* CRC4 requested */
-+ cwaintmp->leds[2] = 0;
-+ cwaintmp->leds[3] = 1;
-+ } else {
-+ /* no CRC4, disable 3 and 4 */
-+ cwaintmp->leds[2] = 1;
-+ cwaintmp->leds[3] = 1;
-+ }
-+ }
-+ cwain_outb(cwaintmp,cwain_R_GPIO_OUT1,(cwaintmp->leds[0] | (cwaintmp->leds[1] << 1) | (cwaintmp->leds[2] << 2) | (cwaintmp->leds[3] << 3)));
-+ }
-+}
-+
-+void cwain_reset_span(struct zt_cwain *cwaintmp) {
-+ int i = 0;
-+ pci_write_config_word(cwaintmp->pcidev, PCI_COMMAND, PCI_COMMAND_MEMORY); // enable memio
-+
-+ /* FIFO, HDLC reset */
-+ cwain_outb(cwaintmp,cwain_R_CIRM,0x10);
-+ cwain_outb(cwaintmp,cwain_R_CIRM,0x0);
-+ cwain_waitbusy(cwaintmp);
-+
-+ /* PCM reset */
-+ cwain_outb(cwaintmp,cwain_R_CIRM,0x20);
-+ cwain_outb(cwaintmp,cwain_R_CIRM,0x0);
-+ cwain_waitbusy(cwaintmp);
-+
-+ for (i=0; i<128; i++) {
-+ cwain_outb(cwaintmp,cwain_R_SLOT, i);
-+ cwain_outb(cwaintmp,cwain_A_SL_CFG, 0x0);
-+ }
-+
-+ /* E1 reset */
-+ cwain_outb(cwaintmp,cwain_R_CIRM,0x40);
-+ cwain_outb(cwaintmp,cwain_R_CIRM,0x0);
-+ cwain_waitbusy(cwaintmp);
-+
-+ /* 128 byte B chans, 4096 byte D chans */
-+ cwain_outb(cwaintmp,cwain_R_FIFO_MD,0x36);
-+ cwain_outb(cwaintmp,cwain_R_BRG_PCM_CFG,0x0);
-+ cwain_outb(cwaintmp,cwain_R_CTRL,0x0);
-+
-+ /* no blinky blink */
-+ cwain_outb(cwaintmp,cwain_R_GPIO_SEL,0x20 | 0x10);
-+ cwain_outb(cwaintmp,cwain_R_GPIO_EN1,0x0f);
-+ cwain_outb(cwaintmp,cwain_R_GPIO_OUT1,0x0f);
-+
-+ cwaintmp->leds[0] = 1;
-+ cwaintmp->leds[1] = 1;
-+ cwaintmp->leds[2] = 1;
-+ cwaintmp->leds[3] = 1;
-+
-+ cwaintmp->ticks = 0;
-+ cwaintmp->clicks = 0;
-+}
-+
-+struct zt_cwain_card *cwain_get_card(unsigned int pcibus) {
-+ struct zt_cwain_card *cwaintmp = cwain_card_list;
-+ spin_lock(&cwain_card_registerlock);
-+ while (cwaintmp) {
-+ if (cwaintmp->pcibus == pcibus) {
-+ break;
-+ }
-+ cwaintmp = cwaintmp->next;
-+ }
-+ spin_unlock(&cwain_card_registerlock);
-+ return cwaintmp;
-+}
-+
-+
-+void cwain_register_card(struct zt_cwain_card *cwaincard) {
-+ spin_lock(&cwain_card_registerlock);
-+ if (cwaincard != NULL) {
-+ cwaincard->prev = NULL;
-+ cwaincard->next = cwain_card_list;
-+ if (cwain_card_list) {
-+ cwain_card_list->prev = cwaincard;
-+ }
-+ cwain_card_list = cwaincard;
-+ cwain_card_count++;
-+ } else {
-+ printk(KERN_INFO "cwain: trying to register NULL card.\n");
-+ }
-+ spin_unlock(&cwain_card_registerlock);
-+}
-+
-+int cwain_register_span(struct zt_cwain *cwainspan) {
-+ struct zt_cwain_card *cwaintmp;
-+ spin_lock(&cwain_span_registerlock);
-+ if (cwainspan != NULL) {
-+ cwainspan->prev = NULL;
-+ cwainspan->next = cwain_span_list;
-+ if (cwain_span_list) {
-+ cwain_span_list->prev = cwainspan;
-+ }
-+ cwain_span_list = cwainspan;
-+ cwainspan->cardno = ++cwain_span_count;
-+ } else {
-+ printk(KERN_INFO "cwain: trying to register NULL span.\n");
-+ }
-+ spin_unlock(&cwain_span_registerlock);
-+
-+ if (cwainspan->type == 0xb553) {
-+ cwaintmp = kmalloc(sizeof(struct zt_cwain_card),GFP_KERNEL);
-+ if (!cwaintmp) {
-+ printk(KERN_WARNING "cwain: unable to kmalloc!\n");
-+ return -1;
-+ }
-+ memset(cwaintmp, 0x0, sizeof(struct zt_cwain_card));
-+
-+ spin_lock_init(&cwaintmp->lock);
-+ cwaintmp->pcibus = cwainspan->pcibus;
-+ cwaintmp->span[0] = cwainspan;
-+ cwaintmp->syncs[0] = -1;
-+ cwaintmp->spans = 1;
-+ cwaintmp->cardID = cwainspan->cardID;
-+ cwain_register_card(cwaintmp);
-+ printk(KERN_INFO
-+ "cwain: Junghanns.NET singleE1 PCI ISDN card configured at mem %#x IRQ %d HZ %d CardID %d\n",
-+ (u_int) cwainspan->pci_io,
-+ cwaintmp->span[0]->irq, HZ, cwainspan->cardID);
-+ } else {
-+ cwaintmp = cwain_get_card(cwainspan->pcibus);
-+ if (!cwaintmp) {
-+ cwaintmp = kmalloc(sizeof(struct zt_cwain_card),GFP_KERNEL);
-+ if (!cwaintmp) {
-+ printk(KERN_WARNING "cwain: unable to kmalloc!\n");
-+ return -1;
-+ }
-+ memset(cwaintmp, 0x0, sizeof(struct zt_cwain_card));
-+
-+ spin_lock_init(&cwaintmp->lock);
-+ cwaintmp->pcibus = cwainspan->pcibus;
-+ cwaintmp->spans = cwainspan->type - 46419;
-+ cwaintmp->span[0] = cwainspan;
-+ cwaintmp->cardID = cwainspan->cardID;
-+ cwaintmp->syncs[0] = -1;
-+ cwain_register_card(cwaintmp);
-+ } else {
-+ cwaintmp->spans = cwainspan->type - 46418;
-+ if (cwainspan->cardID < cwaintmp->cardID) {
-+ cwaintmp->cardID = cwainspan->cardID;
-+ cwaintmp->span[1] = cwaintmp->span[0];
-+ cwaintmp->syncs[1] = cwaintmp->syncs[0];
-+ cwaintmp->span[0] = cwainspan;
-+ } else {
-+ cwaintmp->span[1] = cwainspan;
-+ cwaintmp->syncs[1] = -1;
-+ }
-+ printk(KERN_INFO
-+ "cwain: Junghanns.NET doubleE1 PCI ISDN card configured at mem (%#x / %#x) IRQ %d HZ %d CardID (%d / %d) bus %#x\n",
-+ (u_int) cwaintmp->span[0]->pci_io, (u_int) cwaintmp->span[1]->pci_io,
-+ cwaintmp->span[0]->irq, HZ, cwaintmp->span[0]->cardID, cwaintmp->span[1]->cardID, cwaintmp->pcibus);
-+ }
-+ }
-+ return 0;
-+}
-+
-+static int cwain_dfifo_tx(struct zt_cwain *cwaintmp) {
-+ int chan = 15;
-+ int x=0;
-+ char fifo = 0;
-+
-+ fifo = 0x1F;
-+
-+ if (cwaintmp->chans[chan].bytes2transmit < 1) {
-+ return 0;
-+ } else {
-+ /* select fifo */
-+ cwain_outb(cwaintmp,cwain_R_FIFO,fifo << 1);
-+ cwain_waitbusy(cwaintmp);
-+
-+ if (debug)
-+ printk(KERN_INFO "cwain: card %d TX [ ", cwaintmp->cardno);
-+ /* copy frame to fifo */
-+ for (x=0;x<cwaintmp->chans[chan].bytes2transmit;x++) {
-+ if (debug)
-+ printk("%#x ",cwaintmp->dtxbuf[x]);
-+ cwain_outb(cwaintmp,cwain_A_FIFO_DATA0,cwaintmp->dtxbuf[x]);
-+ }
-+ if (debug)
-+ printk("]\n");
-+ if (debug)
-+ printk(KERN_INFO "ztx %d bytes\n",cwaintmp->chans[chan].bytes2transmit);
-+
-+ if (cwaintmp->chans[chan].eoftx == 1) {
-+ /* transmit HDLC frame */
-+ cwain_outb(cwaintmp,cwain_R_INC_RES_FIFO,0x1);
-+ cwain_waitbusy(cwaintmp);
-+ }
-+ }
-+ return 0;
-+}
-+
-+static int cwain_fifo_tx(struct zt_cwain *cwaintmp, char fifo) {
-+ int chan;
-+ if (fifo >= 15) {
-+ chan = fifo;
-+ } else {
-+ chan = fifo;
-+ }
-+ /* select fifo */
-+ cwain_outb(cwaintmp,cwain_R_FIFO,0x80 | (fifo << 1));
-+ cwain_waitbusy(cwaintmp);
-+ /* transmit 8 bytes of transparent data */
-+ cwain_outdw(cwaintmp,cwain_A_FIFO_DATA0,*((unsigned int *) &cwaintmp->txbuf[chan][0]));
-+ cwain_outdw(cwaintmp,cwain_A_FIFO_DATA0,*((unsigned int *) &cwaintmp->txbuf[chan][4]));
-+
-+ return 0;
-+}
-+
-+static int cwain_dfifo_rx(struct zt_cwain *cwaintmp) {
-+ int chan = 15;
-+ unsigned char f1=1,f2=1,data,stat;
-+ unsigned char of1=0,of2=0;
-+ int len,i;
-+ unsigned short z1=1,z2=1;
-+ unsigned short oz1=0,oz2=0;
-+ char fifo = 0;
-+
-+ fifo = 0x1F;
-+
-+ /* select fifo */
-+ cwain_outb(cwaintmp,cwain_R_FIFO,(fifo << 1) | 1);
-+ cwain_waitbusy(cwaintmp);
-+
-+ while ((oz1 != z1) && (oz2 != z2)) {
-+ oz1 = z1;
-+ oz2 = z2;
-+ z1 = cwain_inw(cwaintmp,cwain_A_Z1) & 0xfff;
-+ z2 = cwain_inw(cwaintmp,cwain_A_Z2) & 0xfff;
-+ }
-+
-+ len = z1-(z2 & 0xfff);
-+ if (len < 0) {
-+ len += cwain_DFIFO_SIZE;
-+ }
-+
-+ while ((of1 != f1) && (of2 != f2)) {
-+ of1 = f1;
-+ of2 = f2;
-+ f1 = cwain_inb(cwaintmp,cwain_A_F1) & 0xf;
-+ f2 = cwain_inb(cwaintmp,cwain_A_F2) & 0xf;
-+ }
-+
-+ if (len > cwain_DFIFO_SIZE) {
-+ printk(KERN_INFO "\ncwain: buffer overflow in D channel RX!\n");
-+ cwaintmp->chans[chan].bytes2receive = 0;
-+ cwaintmp->chans[chan].eofrx = 0;
-+ } else {
-+ if (debug) printk(KERN_INFO "cwain: card %d RX [ ", cwaintmp->cardno);
-+ for (i=0; i<len; i++) {
-+ data = cwain_inb(cwaintmp,cwain_A_FIFO_DATA0);
-+ cwaintmp->drxbuf[i] = data;
-+ if (debug) printk("%#x ",data);
-+ }
-+ if (debug) printk("] %d bytes\n", i);
-+ cwaintmp->chans[chan].bytes2receive = i;
-+ cwaintmp->chans[chan].eofrx = 1;
-+ }
-+
-+ stat = cwain_inb(cwaintmp,cwain_A_FIFO_DATA0);
-+ if (stat != 0x0) {
-+ // bad CRC, skip it
-+ if (cwaintmp->sync) {
-+ printk(KERN_INFO "cwain: BAD CRC for hdlc frame on card %d (cardID %d) stat %#x\n",cwaintmp->cardno, cwaintmp->cardID, stat);
-+ }
-+ cwaintmp->chans[chan].bytes2receive = 0;
-+ cwaintmp->chans[chan].eofrx = 0;
-+// zt_qevent_nolock(&cwaintmp->spans[stport].chans[chan], ZT_EVENT_BADFCS);
-+ }
-+ cwain_outb(cwaintmp,cwain_R_INC_RES_FIFO,0x1);
-+ cwain_waitbusy(cwaintmp);
-+
-+ /* frame received */
-+ cwaintmp->drx--;
-+ return 0;
-+}
-+
-+
-+static int cwain_fifo_rx(struct zt_cwain *cwaintmp, char fifo) {
-+ int chan;
-+ unsigned char data;
-+ int len,i;
-+ unsigned short z1=1,z2=1;
-+ unsigned short oz1=0,oz2=0;
-+ int mumbojumbo=0;
-+ int x = 1000;
-+
-+ if (fifo >= 15) {
-+ chan = fifo; /* +1 */
-+ } else {
-+ chan = fifo;
-+ }
-+
-+ // select rx fifo
-+
-+ // no hdlc, transparent data
-+ cwain_outb(cwaintmp,cwain_R_FIFO,0x80 | (fifo << 1) | 1);
-+ cwain_waitbusy(cwaintmp);
-+
-+ while (x-- && ((oz1 != z1) && (oz2 != z2))) {
-+ oz1 = z1;
-+ oz2 = z2;
-+ z1 = cwain_inw(cwaintmp,cwain_A_Z1) & 0x1ff;
-+ z2 = cwain_inw(cwaintmp,cwain_A_Z2) & 0x1ff;
-+ }
-+ if (x < 500) {
-+ printk(KERN_CRIT "cwain: prevented endless loop\n");
-+ }
-+
-+ len = z1-(z2 & 0x1ff);
-+ if (len < 0) {
-+ len += cwain_FIFO_SIZE;
-+ }
-+// if (len > 2 * ZT_CHUNKSIZE) {
-+ if (len > cwain_FIFO_HW) {
-+// mumbojumbo = len - (2 * ZT_CHUNKSIZE);
-+ mumbojumbo = len - (cwain_FIFO_HW);
-+ len = ZT_CHUNKSIZE;
-+ for (i=0;i<mumbojumbo;i++) {
-+ data = cwain_inb(cwaintmp,cwain_A_FIFO_DATA0);
-+ }
-+ cwaintmp->clicks++;
-+ }
-+ if (len < ZT_CHUNKSIZE) {
-+ if (cwaintmp->clicks > 501) {
-+ printk(KERN_INFO "cwain: not enough to receive (%d bytes)\n",len);
-+ }
-+ return 0;
-+ } else {
-+ *((unsigned int *) &cwaintmp->rxbuf[chan][0]) = cwain_indw(cwaintmp,cwain_A_FIFO_DATA0);
-+ *((unsigned int *) &cwaintmp->rxbuf[chan][4]) = cwain_indw(cwaintmp,cwain_A_FIFO_DATA0);
-+ }
-+
-+ zt_ec_chunk(&cwaintmp->span.chans[chan], cwaintmp->span.chans[chan].readchunk, cwaintmp->span.chans[chan].writechunk);
-+
-+ if (cwaintmp->clicks > 500) {
-+ printk(KERN_INFO "cwain: span %d dropped audio fifo %d mj %d\n", cwaintmp->cardID, fifo, mumbojumbo);
-+ cwaintmp->clicks = 0;
-+ }
-+// printk(KERN_INFO "s/t port %d, channel %d, dbufi=%d, f1=%d, f2=%d, z1=%d, z2=%d => len = %d stat=%#x, hdlc=%d\n",stport,chan,cwaintmp->st[stport].dbufi,f1,f2,z1,z2,len,stat,hdlc);
-+ return 0;
-+}
-+
-+void cwain_set_master(struct zt_cwain_card *cwaintmp, int span) {
-+ int i=0;
-+
-+ if (cwaintmp->syncsrc == span) return;
-+
-+ for (i=0; i < cwaintmp->spans; i++) {
-+ if (i != span) {
-+ if (cwaintmp->syncs[i] > 0) {
-+ /* enable PCM slave mode, PCM32, synced to E1 receive */
-+ cwain_outb(cwaintmp->span[i],cwain_R_PCM_MD0, 0x90);
-+ cwain_outb(cwaintmp->span[i],cwain_R_PCM_MD1, 0x0);
-+ cwain_outb(cwaintmp->span[span],cwain_R_PCM_MD0, 0xA0);
-+ cwain_outb(cwaintmp->span[i],cwain_R_PCM_MD2, 0x00);
-+ } else {
-+ /* enable PCM slave mode, PCM32 */
-+ cwain_outb(cwaintmp->span[i],cwain_R_PCM_MD0, 0x90);
-+ cwain_outb(cwaintmp->span[i],cwain_R_PCM_MD1, 0x0);
-+ cwain_outb(cwaintmp->span[span],cwain_R_PCM_MD0, 0xA0);
-+ cwain_outb(cwaintmp->span[i],cwain_R_PCM_MD2, 0x00);
-+ }
-+ cwaintmp->master[i] = 0;
-+ cwaintmp->span[i]->span.syncsrc = 0;
-+ }
-+ }
-+
-+ if (cwaintmp->syncs[span] > 0) {
-+ /* enable PCM master mode, PCM32, synced to E1 receive */
-+ if (debug)
-+ printk(KERN_INFO "cwain: cardID %d span %d, PCM master E1 sync\n", cwaintmp->cardID, span);
-+ cwain_outb(cwaintmp->span[span],cwain_R_PCM_MD0, 0x91);
-+ cwain_outb(cwaintmp->span[span],cwain_R_PCM_MD1, 0x0);
-+ cwain_outb(cwaintmp->span[span],cwain_R_PCM_MD0, 0xA1);
-+ cwain_outb(cwaintmp->span[span],cwain_R_PCM_MD2, 0x00);
-+ cwaintmp->span[span]->span.syncsrc = 1;
-+ } else {
-+ /* enable PCM master mode, PCM32, free running */
-+ if (debug)
-+ printk(KERN_INFO "cwain: cardID %d span %d, PCM master\n", cwaintmp->cardID, span);
-+ cwain_outb(cwaintmp->span[span],cwain_R_PCM_MD0, 0x91);
-+ cwain_outb(cwaintmp->span[span],cwain_R_PCM_MD1, 0x0);
-+ cwain_outb(cwaintmp->span[span],cwain_R_PCM_MD0, 0xA1);
-+ cwain_outb(cwaintmp->span[span],cwain_R_PCM_MD2, 0x04);
-+ cwaintmp->span[span]->span.syncsrc = 0;
-+ }
-+
-+ cwaintmp->master[span] = 1;
-+ cwaintmp->syncsrc = span;
-+}
-+
-+void cwain_check_timing(struct zt_cwain_card *cwaintmp) {
-+ int i=0;
-+ int bestsync = 42;
-+
-+ for (i=0; i < cwaintmp->spans; i++) {
-+ if ((cwaintmp->syncs[i] > 0) && ((cwaintmp->span[i]->sync_sta & 0x7) == 0x7)) {
-+ if (bestsync < cwaintmp->spans) {
-+ if (cwaintmp->syncs[i] < cwaintmp->syncs[bestsync]) {
-+ bestsync = i;
-+ }
-+ } else {
-+ bestsync = i;
-+ }
-+ }
-+ }
-+
-+ if (cwaintmp->syncsrc >= 0) {
-+ if (debug > 3)
-+ printk(KERN_INFO "cwain: bestsync %d cwaintmp->syncsrc %d\n", bestsync, cwaintmp->syncsrc);
-+
-+ if (bestsync == cwaintmp->syncsrc) {
-+ if (debug > 3)
-+ printk(KERN_INFO "cwain: already on best syncsrc %d\n", bestsync);
-+ return;
-+ }
-+
-+ /* if we have a better syncsrc */
-+ if (bestsync < cwaintmp->spans) {
-+ if (debug)
-+ printk(KERN_INFO "cwain: found better syncsrc %d\n", bestsync);
-+ cwain_set_master(cwaintmp, bestsync);
-+ return;
-+ }
-+ }
-+
-+ /* if reelection failed, find internal sync source */
-+ if (cwaintmp->syncsrc == -1) {
-+ /* no master yet */
-+ if (debug > 3)
-+ printk(KERN_INFO "cwain: no clocksource found cardID %d\n", cwaintmp->cardID);
-+ for (i=0; i < cwaintmp->spans; i++) {
-+ /* find the first internal source */
-+ if (debug > 3)
-+ printk(KERN_INFO "cwain: cwaintmp->syncs[%d] = %d\n", i, cwaintmp->syncs[i]);
-+ if (cwaintmp->syncs[i] == 0) {
-+ if (debug)
-+ printk(KERN_INFO "cwain: using internal clock of span %d\n", i);
-+ cwain_set_master(cwaintmp, i);
-+ return;
-+ }
-+ }
-+ }
-+
-+ /* if we have no internal sync source the only thing we can do is to enable any of the possible sync sources*/
-+ if (cwaintmp->syncsrc == -1) {
-+ /* find the first possible sync source with framing */
-+ for (i=0; i < cwaintmp->spans; i++) {
-+ if (cwaintmp->syncs[i] > 0) {
-+ if (debug)
-+ printk(KERN_INFO "cwain: desperately using clock of span %d\n", i);
-+ cwain_set_master(cwaintmp, i);
-+ break;
-+ }
-+ }
-+ }
-+}
-+
-+static inline void cwain_isr_run(struct zt_cwain *cwaintmp) {
-+ int fifo=0;
-+ if (cwaintmp->span.flags & ZT_FLAG_RUNNING) {
-+ /* oh zaptel! tell us what to transmit... */
-+ zt_transmit(&cwaintmp->span);
-+ /* B chans 1-15 mapped to fifos 0-14 */
-+ /* B chans 17-31 mapped to fifos 15-29 */
-+ for (fifo=0; fifo < 30; fifo++) {
-+ /* B xmit */
-+ cwain_fifo_tx(cwaintmp, fifo);
-+ }
-+ if (cwaintmp->sync) {
-+ cwain_dfifo_tx(cwaintmp);
-+ }
-+
-+ cwaintmp->chans[15].bytes2receive = 0;
-+ cwaintmp->chans[15].bytes2transmit = 0;
-+ cwaintmp->chans[15].eofrx = 0;
-+ cwaintmp->chans[15].eoftx = 0;
-+
-+ for (fifo=0; fifo < 30; fifo++) {
-+ /* B rx */
-+ cwain_fifo_rx(cwaintmp, fifo);
-+ }
-+
-+ /* d-chan data */
-+ if ((cwaintmp->drx > 0) && cwaintmp->sync){
-+ if (debug > 2)
-+ printk(KERN_CRIT "drx = %d\n", cwaintmp->drx);
-+ cwain_dfifo_rx(cwaintmp);
-+ }
-+ /* oh zaptel! thou shall receive! */
-+ zt_receive(&(cwaintmp->span));
-+ }
-+}
-+
-+void cwain_isr_sync(struct zt_cwain *cwainspan) {
-+ unsigned char sync_sta;
-+ unsigned char sync_ok = 0;
-+ unsigned char jatt_sta = 0;
-+
-+ if (!cwainspan->span.flags & ZT_FLAG_RUNNING) {
-+ return;
-+ }
-+
-+ sync_sta = cwain_inb(cwainspan, cwain_R_SYNC_STA);
-+
-+if ((!cwainspan->sync) || (sync_sta != cwainspan->sync_sta)) {
-+
-+ if (debug > 2)
-+ printk(KERN_CRIT "cwain: cardID %d R_SYNC_STA =%#x\n", cwainspan->cardID, sync_sta);
-+
-+ if (cwainspan->span.lineconfig & ZT_CONFIG_CRC4) {
-+ if ((sync_sta & 0x80) == 0x80) {
-+ /* reset MFA detection */
-+ cwain_outb(cwainspan ,cwain_R_RX_SL0_CFG1,0x41);
-+ } else if ((sync_sta & 0x27) == 0x27) {
-+ if ((cwainspan->sync_sta & 0x27) != 0x27) {
-+ /* sync achieved, restart JATT */
-+ if (debug)
-+ printk(KERN_INFO "cwain: %d starting jitter attenuator\n", cwainspan->cardID);
-+ cwain_outb(cwainspan, cwain_R_JATT_CFG,0x9c);
-+ }
-+ sync_ok = 0x27;
-+ } else {
-+ sync_ok = 0x00;
-+ }
-+ } else {
-+ if ((sync_sta & 0x07) == 0x07) {
-+ if ((cwainspan->sync_sta & 0x7) != 0x7) {
-+ /* sync achieved, restart JATT */
-+ if (debug)
-+ printk(KERN_INFO "cwain: %d starting jitter attenuator\n", cwainspan->cardID);
-+ cwain_outb(cwainspan, cwain_R_JATT_CFG,0x9c);
-+ }
-+ sync_ok = 0x07;
-+ } else {
-+ sync_ok = 0x00;
-+ }
-+ }
-+
-+ cwainspan->sync_sta = sync_sta;
-+
-+ jatt_sta = cwain_inb(cwainspan, cwain_R_JATT_STA);
-+ if ((jatt_sta & 0x60) != 0x60) {
-+ if (debug > 2)
-+ printk(KERN_INFO "cwain: %d jitter attenuator %#x\n", cwainspan->cardID, (jatt_sta & 0x60) >> 5);
-+ sync_ok = 0x00;
-+ } else if (!cwainspan->sync && sync_ok) {
-+ if (debug)
-+ printk(KERN_CRIT "cwain: %d jitter attenuator %#x ok!\n", cwainspan->cardID, (jatt_sta & 0x60) >> 5);
-+ }
-+
-+ if (sync_ok && (!cwainspan->sync)) {
-+ /* elastic buffer offsets */
-+ cwain_outb(cwainspan,cwain_R_RX_OFFS,0x06);
-+ cwain_outb(cwainspan,cwain_R_TX_OFFS,0x06);
-+
-+ if (debug > 2)
-+ printk(KERN_INFO "cwain: enabling D channel fifos\n");
-+ cwain_outb(cwainspan,cwain_R_FIFO,0x1F << 1);
-+ cwain_waitbusy(cwainspan);
-+ cwain_outb(cwainspan,cwain_A_CON_HDLC,0xd);
-+ cwain_outb(cwainspan,cwain_A_IRQ_MSK,0x1);
-+
-+ cwain_outb(cwainspan,cwain_R_FIFO,(0x1F << 1) | 1);
-+ cwain_waitbusy(cwainspan);
-+ cwain_outb(cwainspan,cwain_A_CON_HDLC,0xd);
-+ cwain_outb(cwainspan,cwain_A_IRQ_MSK,0x1);
-+ cwainspan->span.alarms = ZT_ALARM_NONE;
-+ zt_alarm_notify(&cwainspan->span);
-+ }
-+ if (!sync_ok && cwainspan->sync) {
-+ if (debug > 2)
-+ printk(KERN_INFO "cwain: disabling D channel fifos\n");
-+ cwain_outb(cwainspan,cwain_R_FIFO,0x1F << 1);
-+ cwain_waitbusy(cwainspan);
-+ cwain_outb(cwainspan,cwain_A_CON_HDLC,0x1);
-+ cwain_outb(cwainspan,cwain_A_IRQ_MSK,0x0);
-+ cwain_outb(cwainspan,cwain_R_FIFO,(0x1F << 1) | 1);
-+ cwain_waitbusy(cwainspan);
-+ cwain_outb(cwainspan,cwain_A_CON_HDLC,0x1);
-+ cwain_outb(cwainspan,cwain_A_IRQ_MSK,0x0);
-+ cwainspan->span.alarms = ZT_ALARM_RED;
-+ zt_alarm_notify(&cwainspan->span);
-+ }
-+
-+ cwainspan->sync = sync_ok;
-+ if (sync_ok) {
-+ switch (cwainspan->type) {
-+ case 0xb553:
-+ sprintf(cwainspan->span.desc,"Junghanns.NET singleE1 PCI ISDN Card %d (cardID %d) SYNCED",cwainspan->cardno,cwainspan->cardID);
-+ break;
-+ case 0xb554:
-+ sprintf(cwainspan->span.desc,"Junghanns.NET doubleE1 PCI ISDN Card %d (cardID %d) (1 E1 port) SYNCED",cwainspan->cardno,cwainspan->cardID);
-+ break;
-+ }
-+ } else {
-+ switch (cwainspan->type) {
-+ case 0xb553:
-+ sprintf(cwainspan->span.desc,"Junghanns.NET singleE1 PCI ISDN Card %d (cardID %d) NO SYNC (sync_sta = %#x)",cwainspan->cardno,cwainspan->cardID, sync_sta);
-+ break;
-+ case 0xb554:
-+ sprintf(cwainspan->span.desc,"Junghanns.NET doubleE1 PCI ISDN Card %d (cardID %d) (1 E1 port) NO SYNC (sync_sta = %#x)",cwainspan->cardno,cwainspan->cardID, sync_sta);
-+ break;
-+ }
-+ }
-+ cwain_doLEDs(cwainspan);
-+}
-+}
-+
-+int cwain_isr_fifo(struct zt_cwain *cwainspan, unsigned char status) {
-+ unsigned char irq_foview,fi;
-+
-+ if (status & 0x80) {
-+ /* fifo irq */
-+ irq_foview = cwain_inb(cwainspan,cwain_R_IRQ_OVIEW);
-+ if (irq_foview & 0x80) {
-+ fi = cwain_inb(cwainspan,cwain_R_IRQ_FIFO_BL7);
-+ if (fi & 0x80) {
-+ if (debug > 2)
-+ printk(KERN_CRIT "cwain: fifo 31 RX irq for D channel\n");
-+ cwainspan->drx += 1;
-+ }
-+ }
-+ return 1;
-+ }
-+ return 0;
-+}
-+
-+#ifdef LINUX26
-+static irqreturn_t cwain_interrupt(int irq, void *dev_id, struct pt_regs *regs) {
-+#else
-+static void cwain_interrupt(int irq, void *dev_id, struct pt_regs *regs) {
-+#endif
-+ struct zt_cwain_card *cwaintmp = dev_id;
-+ unsigned char status, status2, status_tmp, irq_misc, irq_misc2;
-+ unsigned long flags;
-+ int i = 0;
-+ int l1event = 0;
-+
-+ if (!cwaintmp || cwaintmp->dead) {
-+#ifdef LINUX26
-+ return IRQ_NONE;
-+#else
-+ return;
-+#endif
-+ }
-+
-+
-+ spin_lock_irqsave(&(cwaintmp->lock),flags);
-+ status = cwain_inb(cwaintmp->span[0],cwain_R_STATUS);
-+
-+ status2 = 0;
-+
-+ for (i=0;i<cwaintmp->spans;i++) {
-+ if (i == 0) {
-+ status_tmp = status;
-+ } else {
-+ status_tmp = cwain_inb(cwaintmp->span[i],cwain_R_STATUS);
-+ status2 = status_tmp;
-+ }
-+ cwain_isr_fifo(cwaintmp->span[i], status_tmp);
-+ }
-+
-+ if (!(status & 0x80) && !(status & 0x40)) {
-+ // it's not us!
-+ spin_unlock_irqrestore(&(cwaintmp->lock),flags);
-+#ifdef LINUX26
-+ return IRQ_NONE;
-+#else
-+ return;
-+#endif
-+ }
-+
-+ // misc irq
-+ if (status & 0x40) {
-+ irq_misc = cwain_inb(cwaintmp->span[0],cwain_R_IRQ_MISC);
-+ if (irq_misc & 0x2) {
-+ /* cwain timer */
-+ cwaintmp->ticks++;
-+ for (i=0;i<cwaintmp->spans;i++) {
-+ cwain_isr_run(cwaintmp->span[i]);
-+ }
-+ if (cwaintmp->ticks == 500) {
-+ cwaintmp->ticks = 0;
-+ }
-+ }
-+ if (irq_misc & 0x1) {
-+ /* state machine */
-+ if (debug > 4)
-+ printk(KERN_INFO "cwain: state machine irq\n");
-+ l1event++;
-+ }
-+ if (irq_misc & 0x10) {
-+ for (i=0;i<cwaintmp->spans;i++) {
-+ cwain_isr_sync(cwaintmp->span[i]);
-+ }
-+ }
-+ }
-+
-+ // misc irq
-+ if (status2 & 0x40) {
-+ if (cwaintmp->spans == 2) {
-+ irq_misc2 = cwain_inb(cwaintmp->span[1],cwain_R_IRQ_MISC);
-+ }
-+ if (irq_misc2 & 0x1) {
-+ /* state machine 2 */
-+ if (debug > 4)
-+ printk(KERN_INFO "cwain: state machine 2 irq\n");
-+ l1event++;
-+ }
-+ }
-+
-+ if (l1event > 0) {
-+// printk(KERN_INFO "cwain: l1event %d\n", l1event);
-+ if (cwaintmp->spans == 2) {
-+ cwain_check_timing(cwaintmp);
-+ }
-+ for (i=0;i<cwaintmp->spans;i++) {
-+ cwain_isr_sync(cwaintmp->span[i]);
-+ }
-+ }
-+
-+ spin_unlock_irqrestore(&(cwaintmp->lock),flags);
-+#ifdef LINUX26
-+ return IRQ_RETVAL(1);
-+#endif
-+}
-+
-+static int ztcwain_open(struct zt_chan *chan) {
-+// printk(KERN_INFO "cwain: channel %d opened.\n",chan->channo);
-+#ifndef LINUX26
-+ MOD_INC_USE_COUNT;
-+#else
-+ try_module_get(THIS_MODULE);
-+#endif
-+ return 0;
-+}
-+
-+static int ztcwain_close(struct zt_chan *chan) {
-+// printk(KERN_INFO "cwain: channel %d closed.\n",chan->channo);
-+#ifndef LINUX26
-+ MOD_DEC_USE_COUNT;
-+#else
-+ module_put(THIS_MODULE);
-+#endif
-+ return 0;
-+}
-+
-+static int ztcwain_rbsbits(struct zt_chan *chan, int bits) {
-+ return 0;
-+}
-+
-+static int ztcwain_ioctl(struct zt_chan *chan, unsigned int cmd, unsigned long data) {
-+ switch(cmd) {
-+ default:
-+ return -ENOTTY;
-+ }
-+ return 0;
-+}
-+
-+static int ztcwain_startup(struct zt_span *span) {
-+ struct zt_cwain_card *cwaincard = span->pvt;
-+ struct zt_cwain *cwaintmp;
-+ unsigned long flags;
-+ int alreadyrunning;
-+ int i=0;
-+
-+// printk(KERN_INFO "cwain: startup spanno %d offset %d\n", span->spanno, span->offset);
-+
-+ if (cwaincard == NULL) {
-+ printk(KERN_CRIT "cwain: cwaincard == NULL!\n");
-+ return 0;
-+ }
-+
-+ cwaintmp = cwaincard->span[span->offset];
-+ if (cwaintmp == NULL) {
-+ printk(KERN_CRIT "cwain: cwaintmp == NULL!\n");
-+ return 0;
-+ }
-+
-+
-+ alreadyrunning = span->flags & ZT_FLAG_RUNNING;
-+// printk(KERN_CRIT "already running %d flags %d\n", alreadyrunning, span->flags);
-+
-+ if (!alreadyrunning) {
-+ span->chans[15].flags &= ~ZT_FLAG_HDLC;
-+ span->chans[15].flags |= ZT_FLAG_BRIDCHAN; /* yes! */
-+
-+ /* setup B channel buffers (8 bytes each) */
-+ for (i=0; i<15 ; i++) {
-+ memset(cwaintmp->rxbuf[i],0x0,sizeof(cwaintmp->rxbuf[i]));
-+ memset(cwaintmp->txbuf[i],0x0,sizeof(cwaintmp->txbuf[i]));
-+
-+ span->chans[i].readchunk = cwaintmp->rxbuf[i];
-+ span->chans[i].writechunk = cwaintmp->txbuf[i];
-+ }
-+ for (i=16; i<31 ; i++) {
-+ memset(cwaintmp->rxbuf[i-1],0x0,sizeof(cwaintmp->rxbuf[i-1]));
-+ memset(cwaintmp->txbuf[i-1],0x0,sizeof(cwaintmp->txbuf[i-1]));
-+ span->chans[i].readchunk = cwaintmp->rxbuf[i-1];
-+ span->chans[i].writechunk = cwaintmp->txbuf[i-1];
-+ }
-+ /* setup D channel buffer */
-+ memset(cwaintmp->dtxbuf,0x0,sizeof(cwaintmp->dtxbuf));
-+ span->chans[15].writechunk = cwaintmp->dtxbuf;
-+ cwaintmp->chans[15].maxbytes2transmit = sizeof(cwaintmp->dtxbuf);
-+
-+ memset(cwaintmp->drxbuf,0x0,sizeof(cwaintmp->drxbuf));
-+ span->chans[15].readchunk = cwaintmp->drxbuf;
-+
-+ span->flags |= ZT_FLAG_RUNNING;
-+ } else {
-+ printk(KERN_CRIT "already running\n");
-+ return 0;
-+ }
-+
-+ spin_lock_irqsave(&cwaintmp->lock,flags);
-+ // irqs off
-+ cwain_outb(cwaintmp,cwain_R_IRQ_CTRL, 0);
-+
-+ /* setup D-FIFO TX */
-+ cwain_outb(cwaintmp,cwain_R_FIFO,0x1F << 1);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_R_INC_RES_FIFO,0x2);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_A_CON_HDLC,0x1);
-+ cwain_outb(cwaintmp,cwain_A_SUBCH_CFG,0x0);
-+ cwain_outb(cwaintmp,cwain_A_CHANNEL,0x10 << 1);
-+ cwain_outb(cwaintmp,cwain_A_IRQ_MSK,0x0);
-+
-+ /* setup D-FIFO RX */
-+ cwain_outb(cwaintmp,cwain_R_FIFO,(0x1F << 1) | 1);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_R_INC_RES_FIFO,0x2);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_A_CON_HDLC,0x1);
-+ cwain_outb(cwaintmp,cwain_A_SUBCH_CFG,0x0);
-+ cwain_outb(cwaintmp,cwain_A_CHANNEL,(0x10 << 1) | 1);
-+ cwain_outb(cwaintmp,cwain_A_IRQ_MSK,0x0);
-+
-+ /* setup B-FIFOs TX */
-+ /* map ts 1 to 15 to fifos 0 to 14 */
-+ for (i=1; i<16 ; i++) {
-+ cwain_outb(cwaintmp,cwain_R_FIFO,(i - 1) << 1);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_R_INC_RES_FIFO,0x2);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_A_CON_HDLC,0x2);
-+ cwain_outb(cwaintmp,cwain_A_CHANNEL,i << 1);
-+ cwain_outb(cwaintmp,cwain_A_IRQ_MSK,0x1);
-+ }
-+ /* map ts 17 to 31 to fifos 15 to 29 */
-+ for (i=17; i<32 ; i++) {
-+ cwain_outb(cwaintmp,cwain_R_FIFO,(i - 2) << 1);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_R_INC_RES_FIFO,0x2);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_A_CON_HDLC,0x2);
-+ cwain_outb(cwaintmp,cwain_A_CHANNEL,i << 1);
-+ cwain_outb(cwaintmp,cwain_A_IRQ_MSK,0x1);
-+ }
-+
-+ /* setup B-FIFOs RX */
-+ /* map ts 1 to 15 to fifos 0 to 14 */
-+ for (i=1; i<16 ; i++) {
-+ cwain_outb(cwaintmp,cwain_R_FIFO,((i-1) << 1) | 1);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_R_INC_RES_FIFO,0x2);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_A_CON_HDLC,0x2);
-+ cwain_outb(cwaintmp,cwain_A_CHANNEL,(i << 1) | 1);
-+ cwain_outb(cwaintmp,cwain_A_IRQ_MSK,0x1);
-+ }
-+ /* map ts 17 to 31 to fifos 15 to 29 */
-+ for (i=17; i<32 ; i++) {
-+ cwain_outb(cwaintmp,cwain_R_FIFO,((i-2) << 1) | 1);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_R_INC_RES_FIFO,0x2);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_A_CON_HDLC,0x2);
-+ cwain_outb(cwaintmp,cwain_A_CHANNEL,(i << 1) | 1);
-+ cwain_outb(cwaintmp,cwain_A_IRQ_MSK,0x1);
-+ }
-+
-+ if (debug)
-+ printk(KERN_INFO "cwain: starting card %d span %d/%d.\n",cwaintmp->cardno,span->spanno,span->offset);
-+
-+ if (cwaincard->spans == 1) {
-+ cwain_set_master(cwaincard, 0);
-+ }
-+
-+ /* setup E1 amplitude */
-+ cwain_outb(cwaintmp,cwain_R_PWM_MD,0x20);
-+ cwain_outb(cwaintmp,cwain_R_PWM0,0x50);
-+ cwain_outb(cwaintmp,cwain_R_PWM1,0xff);
-+
-+ /* setup E1 transceiver */
-+ cwain_outb(cwaintmp,cwain_R_TX_SL0,0xf8); // R_TX_FR1
-+ cwain_outb(cwaintmp,cwain_R_TX_SL0_CFG0,0x00); /* semiautomatic mode */
-+
-+ cwain_outb(cwaintmp,cwain_R_RX_SL0_CFG0,0x6); /* 0x26 */
-+
-+ if (cwaintmp->span.lineconfig & ZT_CONFIG_AMI) {
-+ cwain_outb(cwaintmp,cwain_R_TX0,0x82);
-+ cwain_outb(cwaintmp,cwain_R_RX0,0x02);
-+ } else if (cwaintmp->span.lineconfig & ZT_CONFIG_HDB3) {
-+ cwain_outb(cwaintmp,cwain_R_TX0,0x81);
-+ cwain_outb(cwaintmp,cwain_R_RX0,0x01);
-+ }
-+
-+ /* transmitter mode */
-+ cwain_outb(cwaintmp,cwain_R_TX1,0x60);
-+
-+ cwain_outb(cwaintmp,cwain_R_LOS0,0x10);
-+ cwain_outb(cwaintmp,cwain_R_LOS1,0x10);
-+
-+ if (cwaintmp->span.lineconfig & ZT_CONFIG_CRC4) {
-+ /* crc4 multiframe */
-+ cwain_outb(cwaintmp,cwain_R_TX_SL0_CFG1,0x31);
-+// cwain_outb(cwaintmp,cwain_R_RX_SL0_CFG1,0x41);
-+ cwain_outb(cwaintmp,cwain_R_RX_SL0_CFG1,0x03);
-+ } else {
-+ /* doubleframe */
-+ cwain_outb(cwaintmp,cwain_R_TX_SL0_CFG1,0x0);
-+// cwain_outb(cwaintmp,cwain_R_RX_SL0_CFG1,0x40);
-+ cwain_outb(cwaintmp,cwain_R_RX_SL0_CFG1,0x02);
-+ }
-+
-+
-+ /* setup sync mode */
-+ if (cwaincard->syncs[span->offset] > 0) {
-+ cwain_outb(cwaintmp,cwain_R_SYNC_CTRL,0x2);
-+ cwain_outb(cwaintmp,cwain_R_SYNC_OUT,0x1);
-+ /* layer 1, here we go! */
-+ cwain_outb(cwaintmp,cwain_R_E1_WR_STA,0x00);
-+ } else {
-+// cwain_outb(cwaintmp,cwain_R_SYNC_CTRL,0x5);
-+ cwain_outb(cwaintmp,cwain_R_SYNC_CTRL,0x7);
-+ cwain_outb(cwaintmp,cwain_R_SYNC_OUT,0x0);
-+ /* layer 1, up! */
-+ cwain_outb(cwaintmp,cwain_R_E1_WR_STA,0x11);
-+ }
-+
-+ cwaintmp->sync = 0;
-+ cwaintmp->sync_sta = 0;
-+
-+ /* enable irqs */
-+ cwain_outb(cwaintmp,cwain_R_IRQ_CTRL, 8 | 1);
-+ spin_unlock_irqrestore(&cwaintmp->lock,flags);
-+
-+ return 0;
-+}
-+
-+static int ztcwain_shutdown(struct zt_span *span) {
-+ struct zt_cwain_card *cwaincard = span->pvt;
-+ struct zt_cwain *cwaintmp;
-+ unsigned long flags;
-+ int alreadyrunning;
-+ int i=0;
-+
-+ if (cwaincard == NULL) {
-+ printk(KERN_CRIT "cwain: cwaincard == NULL!\n");
-+ return 0;
-+ }
-+
-+ cwaintmp = cwaincard->span[span->offset];
-+ if (cwaintmp == NULL) {
-+ printk(KERN_CRIT "cwain: cwaintmp == NULL!\n");
-+ return 0;
-+ }
-+
-+ alreadyrunning = span->flags & ZT_FLAG_RUNNING;
-+
-+ if (!alreadyrunning) {
-+ return 0;
-+ }
-+ spin_lock_irqsave(&cwaintmp->lock,flags);
-+
-+// printk(KERN_CRIT "cwain: stopping card %d span %d/%d.\n",cwaintmp->cardno,span->spanno,span->offset);
-+
-+ // turn off irqs for all fifos
-+
-+ /* disable FIFO TX */
-+ for (i=0; i<0x20 ; i++) {
-+ cwain_outb(cwaintmp,cwain_R_FIFO,i << 1);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_A_IRQ_MSK,0x0);
-+ }
-+
-+ /* disable FIFO RX */
-+ for (i=0; i<0x20 ; i++) {
-+ cwain_outb(cwaintmp,cwain_R_FIFO,(i << 1) | 1);
-+ cwain_waitbusy(cwaintmp);
-+ cwain_outb(cwaintmp,cwain_A_IRQ_MSK,0x0);
-+ }
-+
-+
-+ /* Deactivate Layer 1 */
-+ cwain_outb(cwaintmp,cwain_R_E1_WR_STA,0x10);
-+
-+ cwain_outb(cwaintmp,cwain_R_IRQ_CTRL, 0);
-+// cwain_outb(cwaintmp,cwain_R_IRQMSK_MISC, 0);
-+ cwain_inb(cwaintmp,cwain_R_STATUS);
-+
-+
-+ span->flags &= ~ZT_FLAG_RUNNING;
-+
-+
-+ spin_unlock_irqrestore(&cwaintmp->lock,flags);
-+
-+// printk(KERN_CRIT "cwain: card %d span %d/%d down.\n",cwaintmp->cardno,span->spanno,span->offset);
-+ return 0;
-+}
-+
-+static int ztcwain_maint(struct zt_span *span, int cmd) {
-+ return 0;
-+}
-+
-+static int ztcwain_chanconfig(struct zt_chan *chan,int sigtype) {
-+// printk(KERN_INFO "chan_config sigtype=%d\n", sigtype);
-+ return 0;
-+}
-+
-+static int ztcwain_spanconfig(struct zt_span *span,struct zt_lineconfig *lc) {
-+ struct zt_cwain_card *cwaincard = span->pvt;
-+ span->lineconfig = lc->lineconfig;
-+ span->syncsrc = lc->sync;
-+
-+ cwaincard->syncs[span->offset] = lc->sync;
-+ cwaincard->syncsrc = -1;
-+// printk(KERN_INFO "span_config %d lineconfig=%d syncsrc=%d\n", span->spanno, lc->lineconfig, lc->sync);
-+// cwain_check_timing(cwaincard);
-+ return 0;
-+}
-+
-+static int ztcwain_initialize(struct zt_cwain *cwaintmp, struct zt_cwain_card *cwaincard, int offset) {
-+ int i=0;
-+
-+ memset(&cwaintmp->span,0,sizeof(struct zt_span)); // you never can tell...
-+ sprintf(cwaintmp->span.name,"cwain/%d",cwaintmp->cardno);
-+ switch (cwaintmp->type) {
-+ case 0xb553:
-+ sprintf(cwaintmp->span.desc,"Junghanns.NET singleE1 PCI ISDN Card %d (cardID %d)",cwaintmp->cardno,cwaintmp->cardID);
-+ break;
-+ case 0xb554:
-+ sprintf(cwaintmp->span.desc,"Junghanns.NET doubleE1 PCI ISDN Card %d (cardID %d) (1 E1 port)",cwaintmp->cardno,cwaintmp->cardID);
-+ break;
-+ default:
-+ return -1;
-+ }
-+ cwaintmp->span.spanconfig = ztcwain_spanconfig;
-+ cwaintmp->span.chanconfig = ztcwain_chanconfig;
-+ cwaintmp->span.startup = ztcwain_startup;
-+ cwaintmp->span.shutdown = ztcwain_shutdown;
-+ cwaintmp->span.maint = ztcwain_maint;
-+ cwaintmp->span.rbsbits = ztcwain_rbsbits;
-+ cwaintmp->span.open = ztcwain_open;
-+ cwaintmp->span.close = ztcwain_close;
-+ cwaintmp->span.ioctl = ztcwain_ioctl;
-+
-+ cwaintmp->span.chans = cwaintmp->chans;
-+ cwaintmp->span.channels = 31;
-+ cwaintmp->span.deflaw = ZT_LAW_ALAW;
-+ cwaintmp->span.linecompat = ZT_CONFIG_AMI | ZT_CONFIG_HDB3 | ZT_CONFIG_CCS;
-+ init_waitqueue_head(&cwaintmp->span.maintq);
-+ cwaintmp->span.pvt = cwaincard;
-+ cwaintmp->span.offset = offset;
-+
-+ for (i=0; i < cwaintmp->span.channels; i++) {
-+ memset(&(cwaintmp->chans[i]),0x0,sizeof(struct zt_chan));
-+ sprintf(cwaintmp->chans[i].name,"cwain%d/%d",cwain_span_count + 1,i + 1);
-+ cwaintmp->chans[i].pvt = cwaintmp;
-+ cwaintmp->chans[i].sigcap = ZT_SIG_CLEAR;
-+ cwaintmp->chans[i].chanpos = i + 1;
-+ }
-+
-+ if (zt_register(&cwaintmp->span,0)) {
-+ printk(KERN_INFO "cwain: unable to register zaptel span!\n");
-+ return -1;
-+ }
-+// printk(KERN_INFO "cwain: registered zaptel span %d.\n",s+1);
-+
-+ return 0;
-+}
-+
-+int cwain_reset_card(struct zt_cwain_card *cwaintmp) {
-+ unsigned long flags;
-+ int i = 0;
-+
-+ cwaintmp->irq = cwaintmp->span[0]->irq;
-+
-+ if (cwaintmp->spans == 2) {
-+ if (request_irq(cwaintmp->irq, cwain_interrupt, SA_INTERRUPT | SA_SHIRQ, "cwain2", cwaintmp)) {
-+ printk(KERN_WARNING "cwain: unable to register irq\n");
-+ return -1;
-+ }
-+ } else {
-+ if (request_irq(cwaintmp->irq, cwain_interrupt, SA_INTERRUPT | SA_SHIRQ, "cwain", cwaintmp)) {
-+ printk(KERN_WARNING "cwain: unable to register irq\n");
-+ return -1;
-+ }
-+ }
-+
-+ spin_lock_irqsave(&(cwaintmp->lock),flags);
-+
-+ for (i=0;i<cwaintmp->spans;i++) {
-+ cwain_reset_span(cwaintmp->span[i]);
-+ }
-+
-+ /* no master yet, force reelection */
-+ cwaintmp->syncsrc = -1;
-+
-+ /* set up the timer 1 khz, zaptel timing */
-+ cwain_outb(cwaintmp->span[0],cwain_R_TI_WD, 0x2);
-+
-+ if (cwaintmp->spans == 2) {
-+ cwain_outb(cwaintmp->span[1],cwain_R_IRQMSK_MISC, 0x1);
-+ }
-+ /* enable timer interrupts */
-+ cwain_outb(cwaintmp->span[0],cwain_R_IRQMSK_MISC, 0x13);
-+
-+ /* Finally enable IRQ output */
-+ cwain_outb(cwaintmp->span[0],cwain_R_IRQ_CTRL, 0x8 | 0x1);
-+
-+ spin_unlock_irqrestore(&(cwaintmp->lock),flags);
-+ return 0;
-+}
-+
-+int cwain_find_spans(unsigned int pcidid) {
-+ struct pci_dev *tmp;
-+ struct zt_cwain *cwaintmp = NULL;
-+ int i=0;
-+ unsigned char dips=0;
-+ int cid=0;
-+ int modes=0;
-+ tmp = pci_find_device(PCI_VENDOR_ID_CCD,pcidid,multi_cwain);
-+ while (tmp != NULL) {
-+ multi_cwain = tmp; // skip this next time.
-+
-+ if (pci_enable_device(tmp)) {
-+ multi_cwain = NULL;
-+ return -1;
-+ }
-+
-+ cwaintmp = kmalloc(sizeof(struct zt_cwain),GFP_KERNEL);
-+ if (!cwaintmp) {
-+ printk(KERN_WARNING "cwain: unable to kmalloc!\n");
-+ pci_disable_device(tmp);
-+ multi_cwain = NULL;
-+ return -ENOMEM;
-+ }
-+ memset(cwaintmp, 0x0, sizeof(struct zt_cwain));
-+
-+ spin_lock_init(&cwaintmp->lock);
-+ cwaintmp->pcidev = tmp;
-+ cwaintmp->pcibus = tmp->bus->number;
-+ cwaintmp->pcidevfn = tmp->devfn;
-+
-+
-+ cwaintmp->pci_io = (char *) tmp->resource[1].start;
-+ if (!cwaintmp->pci_io) {
-+ printk(KERN_WARNING "cwain: no iomem!\n");
-+ pci_disable_device(tmp);
-+ multi_cwain = NULL;
-+ return -EIO;
-+ }
-+
-+ if (!tmp->irq) {
-+ printk(KERN_WARNING "cwain: PCI device has no irq!\n");
-+ pci_disable_device(tmp);
-+ multi_cwain = NULL;
-+ return -EIO;
-+ }
-+
-+ cwaintmp->irq = tmp->irq;
-+
-+ cwaintmp->pci_io = ioremap((ulong) cwaintmp->pci_io, 256);
-+
-+ /* enable memio */
-+ pci_write_config_word(cwaintmp->pcidev, PCI_COMMAND, PCI_COMMAND_MEMORY);
-+
-+ /* disable interrupts */
-+ cwain_outb(cwaintmp,cwain_R_IRQ_CTRL, 0);
-+
-+ if (((tmp->subsystem_device==0xb553) || (tmp->subsystem_device==0xb554))&& (pcidid == PCI_DEVICE_ID_CCD_E)) {
-+ dips = (cwain_inb(cwaintmp,cwain_R_GPI_IN0) >> 5);
-+ cid = 7;
-+ for (i=0;i<3;i++) {
-+ if ((dips & (1 << i)) != 0) {
-+ cid -= (1 << (2-i));
-+ }
-+ }
-+// printk(KERN_INFO "DIPS = %#x CID= %#x\n",dips,cid);
-+ } else {
-+ cid = 0xff;
-+ }
-+
-+ if (ports == -1) {
-+ if ((tmp->subsystem_device==0xb520) && (pcidid == PCI_DEVICE_ID_CCD_E)) {
-+ modes = (cwain_inb(cwaintmp,cwain_R_GPI_IN0) >> 4) & 0x01;
-+ } else {
-+ modes = 0; // assume TE mode
-+ }
-+ } else {
-+ modes = ports >> cwain_span_count;
-+ }
-+
-+
-+ cwaintmp->cardID = cid;
-+ cwaintmp->type = tmp->subsystem_device;
-+
-+ if ((modes & 1) != 0) {
-+ cwaintmp->nt_mode = 1;
-+ } else {
-+ cwaintmp->nt_mode = 0;
-+ }
-+
-+ cwain_register_span(cwaintmp);
-+
-+ tmp = pci_find_device(PCI_VENDOR_ID_CCD,pcidid,multi_cwain);
-+ }
-+ return 0;
-+}
-+
-+
-+int cwain_sort_cards(void) {
-+ int changed=0,tmpcardno;
-+ struct zt_cwain_card *tmpcard,*tmpcard2;
-+ spin_lock(&cwain_card_registerlock);
-+ do {
-+ changed = 0;
-+ tmpcard = cwain_card_list;
-+ while (tmpcard != NULL) {
-+ if (tmpcard->prev) {
-+ if (tmpcard->prev->cardID > tmpcard->cardID) {
-+ tmpcardno = tmpcard->prev->cardno;
-+ tmpcard->prev->cardno = tmpcard->cardno;
-+ tmpcard->cardno = tmpcardno;
-+
-+ tmpcard2 = tmpcard->prev;
-+ if (tmpcard2->prev) {
-+ tmpcard2->prev->next = tmpcard;
-+ } else {
-+ cwain_card_list = tmpcard;
-+ }
-+ if (tmpcard->next) {
-+ tmpcard->next->prev = tmpcard2;
-+ }
-+ tmpcard2->next = tmpcard->next;
-+ tmpcard->prev = tmpcard2->prev;
-+ tmpcard->next = tmpcard2;
-+ tmpcard2->prev = tmpcard;
-+ changed = 1;
-+ tmpcard = tmpcard2;
-+ }
-+ }
-+ tmpcard = tmpcard->next;
-+ }
-+ } while (changed == 1);
-+ spin_unlock(&cwain_card_registerlock);
-+ return 0;
-+}
-+
-+int cwain_zap_cards(void) {
-+ struct zt_cwain_card *tmpcard = cwain_card_list;
-+ int i=0;
-+ int res=0;
-+ while (tmpcard != NULL) {
-+ for (i=0; i<tmpcard->spans; i++) {
-+ ztcwain_initialize(tmpcard->span[i], tmpcard, i);
-+ }
-+ res = cwain_reset_card(tmpcard);
-+ tmpcard = tmpcard->next;
-+ }
-+ return res;
-+}
-+
-+
-+int init_module(void) {
-+ multi_cwain = NULL;
-+ cwain_find_spans(PCI_DEVICE_ID_CCD_E);
-+ cwain_sort_cards();
-+ cwain_zap_cards();
-+ if (cwain_card_count == 0) {
-+ printk(KERN_INFO "cwain: no cwain cards found.\n");
-+ } else {
-+ printk(KERN_INFO "cwain: %d cwain card(s) in this box, %d E1 ports total.\n", cwain_card_count, cwain_span_count);
-+ }
-+ return 0;
-+}
-+
-+void cleanup_module(void) {
-+ struct zt_cwain_card *tmpcard,*tmplist;
-+ struct zt_cwain *tmpspan,*spanlist;
-+ int i=0;
-+ int j=0;
-+
-+ tmplist = cwain_card_list;
-+ tmpcard = NULL;
-+ while (tmplist) {
-+ tmpcard = tmplist;
-+ tmplist = tmplist->next;
-+
-+ tmpcard->dead = 1;
-+ cwain_shutdown_card(tmpcard);
-+ kfree(tmpcard);
-+ i++;
-+ }
-+
-+ spanlist = cwain_span_list;
-+ tmpspan = NULL;
-+ while (spanlist) {
-+ tmpspan = spanlist;
-+ spanlist = spanlist->next;
-+ kfree(tmpspan);
-+ j++;
-+ }
-+ printk(KERN_INFO "cwain: shutdown %d spans, %d cwain cards.\n", j, i);
-+}
-+#endif
-+
-+MODULE_PARM(ports,"i");
-+MODULE_PARM(debug,"i");
-+MODULE_DESCRIPTION("cwain zaptel driver");
-+MODULE_AUTHOR("Klaus-Peter Junghanns <kpj at junghanns.net>");
-+#ifdef MODULE_LICENSE
-+MODULE_LICENSE("GPL");
-+#endif
-diff -urNad zaptel-1.2.2/cwain/cwain.h /tmp/dpep.xmeNb1/zaptel-1.2.2/cwain/cwain.h
---- zaptel-1.2.2/cwain/cwain.h 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.xmeNb1/zaptel-1.2.2/cwain/cwain.h 2005-09-26 09:59:05.000000000 +0300
-@@ -0,0 +1,238 @@
-+#define cwain_FIFO_SIZE 128
-+#define cwain_DFIFO_SIZE 4096
-+#define cwain_FIFO_HW 13
-+
-+typedef struct zt_cwain {
-+ /* pci resources */
-+ unsigned int irq;
-+ unsigned int iomem;
-+ unsigned char *pci_io;
-+ unsigned int pcibus;
-+ unsigned int pcidevfn;
-+ struct pci_dev *pcidev;
-+ unsigned int type;
-+
-+ /* lock to protect the structure */
-+ spinlock_t lock;
-+ int cardID;
-+ unsigned char cardno;
-+
-+ /* ticks and clicks, fish and chips */
-+ unsigned int ticks;
-+ unsigned int clicks;
-+ unsigned char nt_mode;
-+ unsigned char sync_sta;
-+ unsigned char sync;
-+ int syncmode;
-+
-+ /* blinky blink */
-+ unsigned char leds[4];
-+
-+ /* B chan buffers */
-+ unsigned char rxbuf[30][ZT_CHUNKSIZE];
-+ unsigned char txbuf[30][ZT_CHUNKSIZE];
-+
-+ /* number of RXed dchan frames */
-+ unsigned char drx;
-+ /* D chan buffer */
-+ unsigned char drxbuf[cwain_DFIFO_SIZE];
-+ unsigned char dtxbuf[cwain_DFIFO_SIZE];
-+
-+
-+ /* zaptel resources */
-+ struct zt_span span;
-+ struct zt_chan chans[31];
-+
-+ /* more zaptel stuff */
-+ unsigned int usecount;
-+ int spantype;
-+ int spanflags;
-+
-+ /* linked list */
-+ struct zt_cwain *next;
-+ struct zt_cwain *prev;
-+
-+} zt_cwain;
-+
-+typedef struct zt_cwain_card {
-+ /* lock to protect the structure */
-+ spinlock_t lock;
-+
-+ unsigned int spans;
-+ unsigned int dead;
-+ int cardID;
-+ unsigned char cardno;
-+ unsigned int ticks;
-+
-+ struct zt_cwain *span[2];
-+ int syncsrc;
-+ int syncs[2];
-+ int master[2];
-+
-+ unsigned int irq;
-+ unsigned int pcibus;
-+
-+ /* linked list */
-+ struct zt_cwain_card *next;
-+ struct zt_cwain_card *prev;
-+} zt_cwain_card;
-+
-+#define cwain_outb(a,b,c) (writeb((c),(a)->pci_io+(b)))
-+#define cwain_inb(a,b) (readb((a)->pci_io+(b)))
-+
-+#define cwain_outw(a,b,c) (writew((c),(a)->pci_io+(b)))
-+#define cwain_inw(a,b) (readw((a)->pci_io+(b)))
-+
-+#define cwain_outdw(a,b,c) (writel((c),(a)->pci_io+(b)))
-+#define cwain_indw(a,b) (readl((a)->pci_io+(b)))
-+
-+
-+/* Write only registers */
-+#define cwain_A_CH_MSK 0xF4
-+#define cwain_A_CHANNEL 0xFC
-+#define cwain_A_CON_HDLC 0xFA
-+#define cwain_A_CONF 0xD1
-+#define cwain_A_FIFO_SEQ 0xFD
-+#define cwain_R_INC_RES_FIFO 0x0E
-+#define cwain_A_IRQ_MSK 0xFF
-+#define cwain_A_SL_CFG 0xD0
-+#define cwain_A_SUBCH_CFG 0xFB
-+#define cwain_R_BERT_WD_MD 0x1B
-+#define cwain_R_BRG_PCM_CFG 0x02
-+#define cwain_R_CIRM 0x00
-+#define cwain_R_CONF_EN 0x18
-+#define cwain_R_CTRL 0x01
-+#define cwain_R_DTMF 0x1C
-+#define cwain_R_DTMF_N 0x1D
-+#define cwain_R_E1_WR_STA 0x20
-+#define cwain_R_FIFO_MD 0x0D
-+#define cwain_R_FIFO 0x0F
-+#define cwain_R_FIRST_FIFO 0x0B
-+#define cwain_R_FSM_IDX 0x0F
-+#define cwain_R_GPIO_EN0 0x42
-+#define cwain_R_GPIO_EN1 0x43
-+#define cwain_R_GPIO_OUT0 0x40
-+#define cwain_R_GPIO_OUT1 0x41
-+#define cwain_R_GPIO_SEL 0x44
-+#define cwain_R_IRQ_CTRL 0x13
-+#define cwain_R_IRQMSK_MISC 0x11
-+#define cwain_R_JATT_CFG 0x2F
-+#define cwain_R_LOS0 0x22
-+#define cwain_R_LOS1 0x23
-+#define cwain_R_PCM_MD0 0x14
-+#define cwain_R_PCM_MD1 0x15
-+#define cwain_R_PCM_MD2 0x15
-+#define cwain_R_PWM_MD 0x46
-+#define cwain_R_PWM0 0x38
-+#define cwain_R_PWM1 0x39
-+#define cwain_R_RAM_ADDR0 0x08
-+#define cwain_R_RAM_ADDR1 0x09
-+#define cwain_R_RAM_ADDR2 0x0A
-+#define cwain_R_RAM_MISC 0x0C
-+#define cwain_R_RX_OFFS 0x30
-+#define cwain_R_RX_SL0_CFG0 0x25
-+#define cwain_R_RX_SL0_CFG1 0x26
-+#define cwain_R_RX0 0x24
-+#define cwain_R_SH0H 0x15
-+#define cwain_R_SH0L 0x15
-+#define cwain_R_SH1H 0x15
-+#define cwain_R_SH1L 0x15
-+#define cwain_R_SL_SEL0 0x15
-+#define cwain_R_SL_SEL1 0x15
-+#define cwain_R_SL_SEL2 0x15
-+#define cwain_R_SL_SEL3 0x15
-+#define cwain_R_SL_SEL4 0x15
-+#define cwain_R_SL_SEL5 0x15
-+#define cwain_R_SL_SEL6 0x15
-+#define cwain_R_SL_SEL7 0x15
-+#define cwain_R_SLOT 0x10
-+#define cwain_R_SYNC_CTRL 0x35
-+#define cwain_R_SYNC_OUT 0x31
-+#define cwain_R_TI_WD 0x1A
-+#define cwain_R_TX_OFFS 0x34
-+#define cwain_R_TX_SL0_CFG0 0x2C
-+#define cwain_R_TX_SL0_CFG1 0x2E
-+#define cwain_R_TX_SL0 0x2D
-+#define cwain_R_TX0 0x28
-+#define cwain_R_TX1 0x29
-+
-+#define cwain_R_TX_FR0 0x2C
-+#define cwain_R_TX_FR1 0x2D
-+#define cwain_R_TX_FR2 0x2E
-+
-+#define cwain_R_RX_FR0 0x25
-+#define cwain_R_RX_FR1 0x26
-+
-+/* Read only registers */
-+#define cwain_A_F1 0x0C
-+#define cwain_A_F12 0x0C
-+#define cwain_A_F2 0x0D
-+#define cwain_A_Z1 0x04
-+#define cwain_A_Z12 0x04
-+#define cwain_A_Z1H 0x05
-+#define cwain_A_Z1L 0x04
-+#define cwain_A_Z2 0x06
-+#define cwain_A_Z2H 0x07
-+#define cwain_A_Z2L 0x06
-+#define cwain_R_BERT_ECH 0x1B
-+#define cwain_R_BERT_ECL 0x1A
-+#define cwain_R_BERT_STA 0x17
-+#define cwain_R_CHIP_ID 0x16
-+#define cwain_R_CHIP_RV 0x1F
-+#define cwain_R_CONF_OFLOW 0x14
-+#define cwain_R_CRC_ECH 0x35
-+#define cwain_R_CRC_ECL 0x34
-+#define cwain_R_E_ECH 0x37
-+#define cwain_R_E_ECL 0x36
-+#define cwain_R_E1_RD_STA 0x20
-+#define cwain_R_F0_CNTH 0x19
-+#define cwain_R_F0_CNTL 0x18
-+#define cwain_R_FAS_ECH 0x31
-+#define cwain_R_FAS_ECL 0x30
-+#define cwain_R_GPI_IN0 0x44
-+#define cwain_R_GPI_IN1 0x45
-+#define cwain_R_GPI_IN2 0x46
-+#define cwain_R_GPI_IN3 0x47
-+#define cwain_R_GPIO_IN0 0x40
-+#define cwain_R_GPIO_IN1 0x41
-+#define cwain_R_INT_DATA 0x88
-+#define cwain_R_IRQ_FIFO_BL0 0xC8
-+#define cwain_R_IRQ_FIFO_BL1 0xC9
-+#define cwain_R_IRQ_FIFO_BL2 0xCA
-+#define cwain_R_IRQ_FIFO_BL3 0xCB
-+#define cwain_R_IRQ_FIFO_BL4 0xCC
-+#define cwain_R_IRQ_FIFO_BL5 0xCD
-+#define cwain_R_IRQ_FIFO_BL6 0xCE
-+#define cwain_R_IRQ_FIFO_BL7 0xCF
-+#define cwain_R_IRQ_MISC 0x11
-+#define cwain_R_IRQ_OVIEW 0x10
-+#define cwain_R_JATT_STA 0x2B
-+#define cwain_R_RAM_USE 0x15
-+#define cwain_R_RX_SL0_0 0x25
-+#define cwain_R_RX_SL0_1 0x26
-+#define cwain_R_RX_SL0_2 0x27
-+#define cwain_R_SA6_VAL13_ECH 0x39
-+#define cwain_R_SA6_VAL13_ECL 0x38
-+#define cwain_R_SA6_VAL23_ECH 0x3B
-+#define cwain_R_SA6_VAL23_ECL 0x3A
-+#define cwain_R_SLIP 0x2C
-+#define cwain_R_STATUS 0x1C
-+#define cwain_R_SYNC_STA 0x24
-+#define cwain_R_VIO_ECH 0x33
-+#define cwain_R_VIO_ECL 0x32
-+
-+
-+/* Read/Write registers */
-+#define cwain_A_FIFO_DATA0_NOINC 0x84
-+#define cwain_A_FIFO_DATA0 0x80
-+#define cwain_A_FIFO_DATA1_NOINC 0x84
-+#define cwain_A_FIFO_DATA1 0x80
-+#define cwain_A_FIFO_DATA2_NOINC 0x84
-+#define cwain_A_FIFO_DATA2 0x80
-+#define cwain_R_RAM_DATA 0xC0
-+
-+#define PCI_DEVICE_ID_CCD_E 0x30b1
-+
-+#define CLKDEL_TE 0xe /* CLKDEL in TE mode */
-+#define CLKDEL_NT 0xc /* CLKDEL in NT mode */
-+
-diff -urNad zaptel-1.2.2/cwain/LICENSE /tmp/dpep.xmeNb1/zaptel-1.2.2/cwain/LICENSE
---- zaptel-1.2.2/cwain/LICENSE 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.xmeNb1/zaptel-1.2.2/cwain/LICENSE 2005-09-26 09:59:05.000000000 +0300
-@@ -0,0 +1,341 @@
-+
-+ GNU GENERAL PUBLIC LICENSE
-+ Version 2, June 1991
-+
-+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-+ Everyone is permitted to copy and distribute verbatim copies
-+ of this license document, but changing it is not allowed.
-+
-+ Preamble
-+
-+ The licenses for most software are designed to take away your
-+freedom to share and change it. By contrast, the GNU General Public
-+License is intended to guarantee your freedom to share and change free
-+software--to make sure the software is free for all its users. This
-+General Public License applies to most of the Free Software
-+Foundation's software and to any other program whose authors commit to
-+using it. (Some other Free Software Foundation software is covered by
-+the GNU Library General Public License instead.) You can apply it to
-+your programs, too.
-+
-+ When we speak of free software, we are referring to freedom, not
-+price. Our General Public Licenses are designed to make sure that you
-+have the freedom to distribute copies of free software (and charge for
-+this service if you wish), that you receive source code or can get it
-+if you want it, that you can change the software or use pieces of it
-+in new free programs; and that you know you can do these things.
-+
-+ To protect your rights, we need to make restrictions that forbid
-+anyone to deny you these rights or to ask you to surrender the rights.
-+These restrictions translate to certain responsibilities for you if you
-+distribute copies of the software, or if you modify it.
-+
-+ For example, if you distribute copies of such a program, whether
-+gratis or for a fee, you must give the recipients all the rights that
-+you have. You must make sure that they, too, receive or can get the
-+source code. And you must show them these terms so they know their
-+rights.
-+
-+ We protect your rights with two steps: (1) copyright the software, and
-+(2) offer you this license which gives you legal permission to copy,
-+distribute and/or modify the software.
-+
-+ Also, for each author's protection and ours, we want to make certain
-+that everyone understands that there is no warranty for this free
-+software. If the software is modified by someone else and passed on, we
-+want its recipients to know that what they have is not the original, so
-+that any problems introduced by others will not reflect on the original
-+authors' reputations.
-+
-+ Finally, any free program is threatened constantly by software
-+patents. We wish to avoid the danger that redistributors of a free
-+program will individually obtain patent licenses, in effect making the
-+program proprietary. To prevent this, we have made it clear that any
-+patent must be licensed for everyone's free use or not licensed at all.
-+
-+ The precise terms and conditions for copying, distribution and
-+modification follow.
-+
-+ GNU GENERAL PUBLIC LICENSE
-+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-+
-+ 0. This License applies to any program or other work which contains
-+a notice placed by the copyright holder saying it may be distributed
-+under the terms of this General Public License. The "Program", below,
-+refers to any such program or work, and a "work based on the Program"
-+means either the Program or any derivative work under copyright law:
-+that is to say, a work containing the Program or a portion of it,
-+either verbatim or with modifications and/or translated into another
-+language. (Hereinafter, translation is included without limitation in
-+the term "modification".) Each licensee is addressed as "you".
-+
-+Activities other than copying, distribution and modification are not
-+covered by this License; they are outside its scope. The act of
-+running the Program is not restricted, and the output from the Program
-+is covered only if its contents constitute a work based on the
-+Program (independent of having been made by running the Program).
-+Whether that is true depends on what the Program does.
-+
-+ 1. You may copy and distribute verbatim copies of the Program's
-+source code as you receive it, in any medium, provided that you
-+conspicuously and appropriately publish on each copy an appropriate
-+copyright notice and disclaimer of warranty; keep intact all the
-+notices that refer to this License and to the absence of any warranty;
-+and give any other recipients of the Program a copy of this License
-+along with the Program.
-+
-+You may charge a fee for the physical act of transferring a copy, and
-+you may at your option offer warranty protection in exchange for a fee.
-+
-+ 2. You may modify your copy or copies of the Program or any portion
-+of it, thus forming a work based on the Program, and copy and
-+distribute such modifications or work under the terms of Section 1
-+above, provided that you also meet all of these conditions:
-+
-+ a) You must cause the modified files to carry prominent notices
-+ stating that you changed the files and the date of any change.
-+
-+ b) You must cause any work that you distribute or publish, that in
-+ whole or in part contains or is derived from the Program or any
-+ part thereof, to be licensed as a whole at no charge to all third
-+ parties under the terms of this License.
-+
-+ c) If the modified program normally reads commands interactively
-+ when run, you must cause it, when started running for such
-+ interactive use in the most ordinary way, to print or display an
-+ announcement including an appropriate copyright notice and a
-+ notice that there is no warranty (or else, saying that you provide
-+ a warranty) and that users may redistribute the program under
-+ these conditions, and telling the user how to view a copy of this
-+ License. (Exception: if the Program itself is interactive but
-+ does not normally print such an announcement, your work based on
-+ the Program is not required to print an announcement.)
-+
-+These requirements apply to the modified work as a whole. If
-+identifiable sections of that work are not derived from the Program,
-+and can be reasonably considered independent and separate works in
-+themselves, then this License, and its terms, do not apply to those
-+sections when you distribute them as separate works. But when you
-+distribute the same sections as part of a whole which is a work based
-+on the Program, the distribution of the whole must be on the terms of
-+this License, whose permissions for other licensees extend to the
-+entire whole, and thus to each and every part regardless of who wrote it.
-+
-+Thus, it is not the intent of this section to claim rights or contest
-+your rights to work written entirely by you; rather, the intent is to
-+exercise the right to control the distribution of derivative or
-+collective works based on the Program.
-+
-+In addition, mere aggregation of another work not based on the Program
-+with the Program (or with a work based on the Program) on a volume of
-+a storage or distribution medium does not bring the other work under
-+the scope of this License.
-+
-+ 3. You may copy and distribute the Program (or a work based on it,
-+under Section 2) in object code or executable form under the terms of
-+Sections 1 and 2 above provided that you also do one of the following:
-+
-+ a) Accompany it with the complete corresponding machine-readable
-+ source code, which must be distributed under the terms of Sections
-+ 1 and 2 above on a medium customarily used for software interchange; or,
-+
-+ b) Accompany it with a written offer, valid for at least three
-+ years, to give any third party, for a charge no more than your
-+ cost of physically performing source distribution, a complete
-+ machine-readable copy of the corresponding source code, to be
-+ distributed under the terms of Sections 1 and 2 above on a medium
-+ customarily used for software interchange; or,
-+
-+ c) Accompany it with the information you received as to the offer
-+ to distribute corresponding source code. (This alternative is
-+ allowed only for noncommercial distribution and only if you
-+ received the program in object code or executable form with such
-+ an offer, in accord with Subsection b above.)
-+
-+The source code for a work means the preferred form of the work for
-+making modifications to it. For an executable work, complete source
-+code means all the source code for all modules it contains, plus any
-+associated interface definition files, plus the scripts used to
-+control compilation and installation of the executable. However, as a
-+special exception, the source code distributed need not include
-+anything that is normally distributed (in either source or binary
-+form) with the major components (compiler, kernel, and so on) of the
-+operating system on which the executable runs, unless that component
-+itself accompanies the executable.
-+
-+If distribution of executable or object code is made by offering
-+access to copy from a designated place, then offering equivalent
-+access to copy the source code from the same place counts as
-+distribution of the source code, even though third parties are not
-+compelled to copy the source along with the object code.
-+
-+ 4. You may not copy, modify, sublicense, or distribute the Program
-+except as expressly provided under this License. Any attempt
-+otherwise to copy, modify, sublicense or distribute the Program is
-+void, and will automatically terminate your rights under this License.
-+However, parties who have received copies, or rights, from you under
-+this License will not have their licenses terminated so long as such
-+parties remain in full compliance.
-+
-+ 5. You are not required to accept this License, since you have not
-+signed it. However, nothing else grants you permission to modify or
-+distribute the Program or its derivative works. These actions are
-+prohibited by law if you do not accept this License. Therefore, by
-+modifying or distributing the Program (or any work based on the
-+Program), you indicate your acceptance of this License to do so, and
-+all its terms and conditions for copying, distributing or modifying
-+the Program or works based on it.
-+
-+ 6. Each time you redistribute the Program (or any work based on the
-+Program), the recipient automatically receives a license from the
-+original licensor to copy, distribute or modify the Program subject to
-+these terms and conditions. You may not impose any further
-+restrictions on the recipients' exercise of the rights granted herein.
-+You are not responsible for enforcing compliance by third parties to
-+this License.
-+
-+ 7. If, as a consequence of a court judgment or allegation of patent
-+infringement or for any other reason (not limited to patent issues),
-+conditions are imposed on you (whether by court order, agreement or
-+otherwise) that contradict the conditions of this License, they do not
-+excuse you from the conditions of this License. If you cannot
-+distribute so as to satisfy simultaneously your obligations under this
-+License and any other pertinent obligations, then as a consequence you
-+may not distribute the Program at all. For example, if a patent
-+license would not permit royalty-free redistribution of the Program by
-+all those who receive copies directly or indirectly through you, then
-+the only way you could satisfy both it and this License would be to
-+refrain entirely from distribution of the Program.
-+
-+If any portion of this section is held invalid or unenforceable under
-+any particular circumstance, the balance of the section is intended to
-+apply and the section as a whole is intended to apply in other
-+circumstances.
-+
-+It is not the purpose of this section to induce you to infringe any
-+patents or other property right claims or to contest validity of any
-+such claims; this section has the sole purpose of protecting the
-+integrity of the free software distribution system, which is
-+implemented by public license practices. Many people have made
-+generous contributions to the wide range of software distributed
-+through that system in reliance on consistent application of that
-+system; it is up to the author/donor to decide if he or she is willing
-+to distribute software through any other system and a licensee cannot
-+impose that choice.
-+
-+This section is intended to make thoroughly clear what is believed to
-+be a consequence of the rest of this License.
-+
-+ 8. If the distribution and/or use of the Program is restricted in
-+certain countries either by patents or by copyrighted interfaces, the
-+original copyright holder who places the Program under this License
-+may add an explicit geographical distribution limitation excluding
-+those countries, so that distribution is permitted only in or among
-+countries not thus excluded. In such case, this License incorporates
-+the limitation as if written in the body of this License.
-+
-+ 9. The Free Software Foundation may publish revised and/or new versions
-+of the General Public License from time to time. Such new versions will
-+be similar in spirit to the present version, but may differ in detail to
-+address new problems or concerns.
-+
-+Each version is given a distinguishing version number. If the Program
-+specifies a version number of this License which applies to it and "any
-+later version", you have the option of following the terms and conditions
-+either of that version or of any later version published by the Free
-+Software Foundation. If the Program does not specify a version number of
-+this License, you may choose any version ever published by the Free Software
-+Foundation.
-+
-+ 10. If you wish to incorporate parts of the Program into other free
-+programs whose distribution conditions are different, write to the author
-+to ask for permission. For software which is copyrighted by the Free
-+Software Foundation, write to the Free Software Foundation; we sometimes
-+make exceptions for this. Our decision will be guided by the two goals
-+of preserving the free status of all derivatives of our free software and
-+of promoting the sharing and reuse of software generally.
-+
-+ NO WARRANTY
-+
-+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-+REPAIR OR CORRECTION.
-+
-+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-+POSSIBILITY OF SUCH DAMAGES.
-+
-+ END OF TERMS AND CONDITIONS
-+
-+ How to Apply These Terms to Your New Programs
-+
-+ If you develop a new program, and you want it to be of the greatest
-+possible use to the public, the best way to achieve this is to make it
-+free software which everyone can redistribute and change under these terms.
-+
-+ To do so, attach the following notices to the program. It is safest
-+to attach them to the start of each source file to most effectively
-+convey the exclusion of warranty; and each file should have at least
-+the "copyright" line and a pointer to where the full notice is found.
-+
-+ <one line to give the program's name and a brief idea of what it does.>
-+ Copyright (C) 19yy <name of author>
-+
-+ This program is free software; you can redistribute it and/or modify
-+ it under the terms of the GNU General Public License as published by
-+ the Free Software Foundation; either version 2 of the License, or
-+ (at your option) any later version.
-+
-+ This program is distributed in the hope that it will be useful,
-+ but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ GNU General Public License for more details.
-+
-+ You should have received a copy of the GNU General Public License
-+ along with this program; if not, write to the Free Software
-+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-+
-+
-+Also add information on how to contact you by electronic and paper mail.
-+
-+If the program is interactive, make it output a short notice like this
-+when it starts in an interactive mode:
-+
-+ Gnomovision version 69, Copyright (C) 19yy name of author
-+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-+ This is free software, and you are welcome to redistribute it
-+ under certain conditions; type `show c' for details.
-+
-+The hypothetical commands `show w' and `show c' should show the appropriate
-+parts of the General Public License. Of course, the commands you use may
-+be called something other than `show w' and `show c'; they could even be
-+mouse-clicks or menu items--whatever suits your program.
-+
-+You should also get your employer (if you work as a programmer) or your
-+school, if any, to sign a "copyright disclaimer" for the program, if
-+necessary. Here is a sample; alter the names:
-+
-+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
-+
-+ <signature of Ty Coon>, 1 April 1989
-+ Ty Coon, President of Vice
-+
-+This General Public License does not permit incorporating your program into
-+proprietary programs. If your program is a subroutine library, you may
-+consider it more useful to permit linking proprietary applications with the
-+library. If this is what you want to do, use the GNU Library General
-+Public License instead of this License.
-diff -urNad zaptel-1.2.2/cwain/Makefile /tmp/dpep.xmeNb1/zaptel-1.2.2/cwain/Makefile
---- zaptel-1.2.2/cwain/Makefile 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.xmeNb1/zaptel-1.2.2/cwain/Makefile 2006-01-18 14:02:29.000000000 +0200
-@@ -0,0 +1,90 @@
-+KINCLUDES = /usr/src/linux/include
-+BRISTUFFBASE = $(shell dirname `pwd`)
-+
-+ZAP = $(shell [ -f $(BRISTUFFBASE)/zaptel-1.2.2/zaptel.h ] && echo "-I$(BRISTUFFBASE)/zaptel-1.2.2")
-+
-+HOSTCC=gcc
-+
-+CFLAGS+=-I. $(ZAP) -O4 -g -Wall #-DBLINKYBLINK
-+CFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-fsigned-char"; fi)
-+
-+KFLAGS=-D__KERNEL__ -DMODULE -DEXPORT_SYMTAB -fomit-frame-pointer -O2 -Wall -I$(KINCLUDES) $(ZAP)
-+KFLAGS+=$(shell [ -f $(KINCLUDES)/linux/modversions.h ] && echo "-DMODVERSIONS -include $(KINCLUDES)/linux/modversions.h")
-+KFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-msoft-float -fsigned-char"; fi)
-+
-+OBJS=cwain.o
-+
-+BUILDVER=$(shell if uname -r | grep -q ^2.6; then echo "linux26"; else echo "linux24"; fi)
-+
-+MODCONF=$(shell if [ -d $(INSTALL_PREFIX)/etc/modprobe.d ]; then echo "$(INSTALL_PREFIX)/etc/modprobe.d/zaptel"; elif [ -d $(INSTALL_PREFIX)/etc/modutils ]; then echo "$(INSTALL_PREFIX)/etc/modutils/zaptel"; elif [ -f $(INSTALL_PREFIX)/etc/modprobe.conf ]; then echo "$(INSTALL_PREFIX)/modprobe.conf"; elif [ -f $(INSTALL_PREFIX)/etc/modules.conf ]; then echo "$(INSTALL_PREFIX)/etc/modules.conf"; else echo $(INSTALL_PREFIX)/etc/conf.modules ; fi)
-+
-+MODULES=cwain
-+
-+MODULESO=$(shell for x in $(MODULES); do echo "$$x.o "; done )
-+MODULESKO=$(shell for x in $(MODULES); do echo "$$x.ko "; done )
-+
-+PWD=$(shell pwd)
-+
-+obj-m := $(MODULESO)
-+
-+all: $(BUILDVER)
-+
-+linux24: $(OBJS)
-+ sync
-+
-+linux26:
-+ @if ! [ -d /usr/src/linux-2.6 ]; then echo "Link /usr/src/linux-2.6 to your kernel sources first!"; exit 1 ; fi
-+ make -C /usr/src/linux-2.6 SUBDIRS=$(PWD) ZAP=$(ZAP) modules
-+obj-m := $(OBJS)
-+
-+cwain.o: cwain.c cwain.h
-+ $(CC) -c cwain.c $(KFLAGS)
-+
-+clean:
-+ rm -f $(OBJS) *.ko *.mod.c *.mod.o .*o.cmd *~
-+
-+testlinux24: all
-+ modprobe zaptel
-+ insmod ./cwain.o
-+ ztcfg -v
-+ cat /proc/interrupts
-+ sleep 1
-+ cat /proc/interrupts
-+ rmmod cwain zaptel
-+
-+testlinux26: all
-+ modprobe zaptel
-+ insmod ./cwain.ko
-+ ztcfg -v
-+ cat /proc/interrupts
-+ sleep 5
-+ cat /proc/interrupts
-+ rmmod cwain zaptel
-+
-+reload: unload load
-+load: load$(BUILDVER)
-+
-+test: test$(BUILDVER)
-+
-+
-+loadlinux24: linux24
-+ modprobe zaptel
-+ insmod ./cwain.o
-+ ztcfg -v
-+
-+loadlinux26: linux26
-+ sync
-+ modprobe zaptel
-+ insmod ./cwain.ko debug=1
-+ ztcfg -v
-+
-+install: install$(BUILDVER)
-+
-+installlinux26:
-+ install -D -m 644 cwain.ko $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/cwain.ko
-+
-+installlinux24:
-+ install -D -m 644 cwain.o $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/cwain.o
-+
-+unload:
-+ rmmod cwain zaptel
-diff -urNad zaptel-1.2.2/cwain/TODO /tmp/dpep.xmeNb1/zaptel-1.2.2/cwain/TODO
---- zaptel-1.2.2/cwain/TODO 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.xmeNb1/zaptel-1.2.2/cwain/TODO 2005-09-26 09:59:05.000000000 +0300
-@@ -0,0 +1 @@
-+
-diff -urNad zaptel-1.2.2/cwain/zaptel.conf /tmp/dpep.xmeNb1/zaptel-1.2.2/cwain/zaptel.conf
---- zaptel-1.2.2/cwain/zaptel.conf 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.xmeNb1/zaptel-1.2.2/cwain/zaptel.conf 2005-10-27 11:26:41.000000000 +0200
-@@ -0,0 +1,11 @@
-+loadzone=nl
-+defaultzone=nl
-+span=1,2,3,ccs,hdb3,crc4
-+
-+alaw=1-31
-+
-+bchan=1-15
-+dchan=16
-+bchan=17-31
-+
-+
-diff -urNad zaptel-1.2.2/qozap/LICENSE /tmp/dpep.xmeNb1/zaptel-1.2.2/qozap/LICENSE
---- zaptel-1.2.2/qozap/LICENSE 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.xmeNb1/zaptel-1.2.2/qozap/LICENSE 2005-06-13 10:03:36.000000000 +0300
-@@ -0,0 +1,341 @@
-+
-+ GNU GENERAL PUBLIC LICENSE
-+ Version 2, June 1991
-+
-+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-+ Everyone is permitted to copy and distribute verbatim copies
-+ of this license document, but changing it is not allowed.
-+
-+ Preamble
-+
-+ The licenses for most software are designed to take away your
-+freedom to share and change it. By contrast, the GNU General Public
-+License is intended to guarantee your freedom to share and change free
-+software--to make sure the software is free for all its users. This
-+General Public License applies to most of the Free Software
-+Foundation's software and to any other program whose authors commit to
-+using it. (Some other Free Software Foundation software is covered by
-+the GNU Library General Public License instead.) You can apply it to
-+your programs, too.
-+
-+ When we speak of free software, we are referring to freedom, not
-+price. Our General Public Licenses are designed to make sure that you
-+have the freedom to distribute copies of free software (and charge for
-+this service if you wish), that you receive source code or can get it
-+if you want it, that you can change the software or use pieces of it
-+in new free programs; and that you know you can do these things.
-+
-+ To protect your rights, we need to make restrictions that forbid
-+anyone to deny you these rights or to ask you to surrender the rights.
-+These restrictions translate to certain responsibilities for you if you
-+distribute copies of the software, or if you modify it.
-+
-+ For example, if you distribute copies of such a program, whether
-+gratis or for a fee, you must give the recipients all the rights that
-+you have. You must make sure that they, too, receive or can get the
-+source code. And you must show them these terms so they know their
-+rights.
-+
-+ We protect your rights with two steps: (1) copyright the software, and
-+(2) offer you this license which gives you legal permission to copy,
-+distribute and/or modify the software.
-+
-+ Also, for each author's protection and ours, we want to make certain
-+that everyone understands that there is no warranty for this free
-+software. If the software is modified by someone else and passed on, we
-+want its recipients to know that what they have is not the original, so
-+that any problems introduced by others will not reflect on the original
-+authors' reputations.
-+
-+ Finally, any free program is threatened constantly by software
-+patents. We wish to avoid the danger that redistributors of a free
-+program will individually obtain patent licenses, in effect making the
-+program proprietary. To prevent this, we have made it clear that any
-+patent must be licensed for everyone's free use or not licensed at all.
-+
-+ The precise terms and conditions for copying, distribution and
-+modification follow.
-+
-+ GNU GENERAL PUBLIC LICENSE
-+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-+
-+ 0. This License applies to any program or other work which contains
-+a notice placed by the copyright holder saying it may be distributed
-+under the terms of this General Public License. The "Program", below,
-+refers to any such program or work, and a "work based on the Program"
-+means either the Program or any derivative work under copyright law:
-+that is to say, a work containing the Program or a portion of it,
-+either verbatim or with modifications and/or translated into another
-+language. (Hereinafter, translation is included without limitation in
-+the term "modification".) Each licensee is addressed as "you".
-+
-+Activities other than copying, distribution and modification are not
-+covered by this License; they are outside its scope. The act of
-+running the Program is not restricted, and the output from the Program
-+is covered only if its contents constitute a work based on the
-+Program (independent of having been made by running the Program).
-+Whether that is true depends on what the Program does.
-+
-+ 1. You may copy and distribute verbatim copies of the Program's
-+source code as you receive it, in any medium, provided that you
-+conspicuously and appropriately publish on each copy an appropriate
-+copyright notice and disclaimer of warranty; keep intact all the
-+notices that refer to this License and to the absence of any warranty;
-+and give any other recipients of the Program a copy of this License
-+along with the Program.
-+
-+You may charge a fee for the physical act of transferring a copy, and
-+you may at your option offer warranty protection in exchange for a fee.
-+
-+ 2. You may modify your copy or copies of the Program or any portion
-+of it, thus forming a work based on the Program, and copy and
-+distribute such modifications or work under the terms of Section 1
-+above, provided that you also meet all of these conditions:
-+
-+ a) You must cause the modified files to carry prominent notices
-+ stating that you changed the files and the date of any change.
-+
-+ b) You must cause any work that you distribute or publish, that in
-+ whole or in part contains or is derived from the Program or any
-+ part thereof, to be licensed as a whole at no charge to all third
-+ parties under the terms of this License.
-+
-+ c) If the modified program normally reads commands interactively
-+ when run, you must cause it, when started running for such
-+ interactive use in the most ordinary way, to print or display an
-+ announcement including an appropriate copyright notice and a
-+ notice that there is no warranty (or else, saying that you provide
-+ a warranty) and that users may redistribute the program under
-+ these conditions, and telling the user how to view a copy of this
-+ License. (Exception: if the Program itself is interactive but
-+ does not normally print such an announcement, your work based on
-+ the Program is not required to print an announcement.)
-+
-+These requirements apply to the modified work as a whole. If
-+identifiable sections of that work are not derived from the Program,
-+and can be reasonably considered independent and separate works in
-+themselves, then this License, and its terms, do not apply to those
-+sections when you distribute them as separate works. But when you
-+distribute the same sections as part of a whole which is a work based
-+on the Program, the distribution of the whole must be on the terms of
-+this License, whose permissions for other licensees extend to the
-+entire whole, and thus to each and every part regardless of who wrote it.
-+
-+Thus, it is not the intent of this section to claim rights or contest
-+your rights to work written entirely by you; rather, the intent is to
-+exercise the right to control the distribution of derivative or
-+collective works based on the Program.
-+
-+In addition, mere aggregation of another work not based on the Program
-+with the Program (or with a work based on the Program) on a volume of
-+a storage or distribution medium does not bring the other work under
-+the scope of this License.
-+
-+ 3. You may copy and distribute the Program (or a work based on it,
-+under Section 2) in object code or executable form under the terms of
-+Sections 1 and 2 above provided that you also do one of the following:
-+
-+ a) Accompany it with the complete corresponding machine-readable
-+ source code, which must be distributed under the terms of Sections
-+ 1 and 2 above on a medium customarily used for software interchange; or,
-+
-+ b) Accompany it with a written offer, valid for at least three
-+ years, to give any third party, for a charge no more than your
-+ cost of physically performing source distribution, a complete
-+ machine-readable copy of the corresponding source code, to be
-+ distributed under the terms of Sections 1 and 2 above on a medium
-+ customarily used for software interchange; or,
-+
-+ c) Accompany it with the information you received as to the offer
-+ to distribute corresponding source code. (This alternative is
-+ allowed only for noncommercial distribution and only if you
-+ received the program in object code or executable form with such
-+ an offer, in accord with Subsection b above.)
-+
-+The source code for a work means the preferred form of the work for
-+making modifications to it. For an executable work, complete source
-+code means all the source code for all modules it contains, plus any
-+associated interface definition files, plus the scripts used to
-+control compilation and installation of the executable. However, as a
-+special exception, the source code distributed need not include
-+anything that is normally distributed (in either source or binary
-+form) with the major components (compiler, kernel, and so on) of the
-+operating system on which the executable runs, unless that component
-+itself accompanies the executable.
-+
-+If distribution of executable or object code is made by offering
-+access to copy from a designated place, then offering equivalent
-+access to copy the source code from the same place counts as
-+distribution of the source code, even though third parties are not
-+compelled to copy the source along with the object code.
-+
-+ 4. You may not copy, modify, sublicense, or distribute the Program
-+except as expressly provided under this License. Any attempt
-+otherwise to copy, modify, sublicense or distribute the Program is
-+void, and will automatically terminate your rights under this License.
-+However, parties who have received copies, or rights, from you under
-+this License will not have their licenses terminated so long as such
-+parties remain in full compliance.
-+
-+ 5. You are not required to accept this License, since you have not
-+signed it. However, nothing else grants you permission to modify or
-+distribute the Program or its derivative works. These actions are
-+prohibited by law if you do not accept this License. Therefore, by
-+modifying or distributing the Program (or any work based on the
-+Program), you indicate your acceptance of this License to do so, and
-+all its terms and conditions for copying, distributing or modifying
-+the Program or works based on it.
-+
-+ 6. Each time you redistribute the Program (or any work based on the
-+Program), the recipient automatically receives a license from the
-+original licensor to copy, distribute or modify the Program subject to
-+these terms and conditions. You may not impose any further
-+restrictions on the recipients' exercise of the rights granted herein.
-+You are not responsible for enforcing compliance by third parties to
-+this License.
-+
-+ 7. If, as a consequence of a court judgment or allegation of patent
-+infringement or for any other reason (not limited to patent issues),
-+conditions are imposed on you (whether by court order, agreement or
-+otherwise) that contradict the conditions of this License, they do not
-+excuse you from the conditions of this License. If you cannot
-+distribute so as to satisfy simultaneously your obligations under this
-+License and any other pertinent obligations, then as a consequence you
-+may not distribute the Program at all. For example, if a patent
-+license would not permit royalty-free redistribution of the Program by
-+all those who receive copies directly or indirectly through you, then
-+the only way you could satisfy both it and this License would be to
-+refrain entirely from distribution of the Program.
-+
-+If any portion of this section is held invalid or unenforceable under
-+any particular circumstance, the balance of the section is intended to
-+apply and the section as a whole is intended to apply in other
-+circumstances.
-+
-+It is not the purpose of this section to induce you to infringe any
-+patents or other property right claims or to contest validity of any
-+such claims; this section has the sole purpose of protecting the
-+integrity of the free software distribution system, which is
-+implemented by public license practices. Many people have made
-+generous contributions to the wide range of software distributed
-+through that system in reliance on consistent application of that
-+system; it is up to the author/donor to decide if he or she is willing
-+to distribute software through any other system and a licensee cannot
-+impose that choice.
-+
-+This section is intended to make thoroughly clear what is believed to
-+be a consequence of the rest of this License.
-+
-+ 8. If the distribution and/or use of the Program is restricted in
-+certain countries either by patents or by copyrighted interfaces, the
-+original copyright holder who places the Program under this License
-+may add an explicit geographical distribution limitation excluding
-+those countries, so that distribution is permitted only in or among
-+countries not thus excluded. In such case, this License incorporates
-+the limitation as if written in the body of this License.
-+
-+ 9. The Free Software Foundation may publish revised and/or new versions
-+of the General Public License from time to time. Such new versions will
-+be similar in spirit to the present version, but may differ in detail to
-+address new problems or concerns.
-+
-+Each version is given a distinguishing version number. If the Program
-+specifies a version number of this License which applies to it and "any
-+later version", you have the option of following the terms and conditions
-+either of that version or of any later version published by the Free
-+Software Foundation. If the Program does not specify a version number of
-+this License, you may choose any version ever published by the Free Software
-+Foundation.
-+
-+ 10. If you wish to incorporate parts of the Program into other free
-+programs whose distribution conditions are different, write to the author
-+to ask for permission. For software which is copyrighted by the Free
-+Software Foundation, write to the Free Software Foundation; we sometimes
-+make exceptions for this. Our decision will be guided by the two goals
-+of preserving the free status of all derivatives of our free software and
-+of promoting the sharing and reuse of software generally.
-+
-+ NO WARRANTY
-+
-+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-+REPAIR OR CORRECTION.
-+
-+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-+POSSIBILITY OF SUCH DAMAGES.
-+
-+ END OF TERMS AND CONDITIONS
-+
-+ How to Apply These Terms to Your New Programs
-+
-+ If you develop a new program, and you want it to be of the greatest
-+possible use to the public, the best way to achieve this is to make it
-+free software which everyone can redistribute and change under these terms.
-+
-+ To do so, attach the following notices to the program. It is safest
-+to attach them to the start of each source file to most effectively
-+convey the exclusion of warranty; and each file should have at least
-+the "copyright" line and a pointer to where the full notice is found.
-+
-+ <one line to give the program's name and a brief idea of what it does.>
-+ Copyright (C) 19yy <name of author>
-+
-+ This program is free software; you can redistribute it and/or modify
-+ it under the terms of the GNU General Public License as published by
-+ the Free Software Foundation; either version 2 of the License, or
-+ (at your option) any later version.
-+
-+ This program is distributed in the hope that it will be useful,
-+ but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ GNU General Public License for more details.
-+
-+ You should have received a copy of the GNU General Public License
-+ along with this program; if not, write to the Free Software
-+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-+
-+
-+Also add information on how to contact you by electronic and paper mail.
-+
-+If the program is interactive, make it output a short notice like this
-+when it starts in an interactive mode:
-+
-+ Gnomovision version 69, Copyright (C) 19yy name of author
-+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-+ This is free software, and you are welcome to redistribute it
-+ under certain conditions; type `show c' for details.
-+
-+The hypothetical commands `show w' and `show c' should show the appropriate
-+parts of the General Public License. Of course, the commands you use may
-+be called something other than `show w' and `show c'; they could even be
-+mouse-clicks or menu items--whatever suits your program.
-+
-+You should also get your employer (if you work as a programmer) or your
-+school, if any, to sign a "copyright disclaimer" for the program, if
-+necessary. Here is a sample; alter the names:
-+
-+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
-+
-+ <signature of Ty Coon>, 1 April 1989
-+ Ty Coon, President of Vice
-+
-+This General Public License does not permit incorporating your program into
-+proprietary programs. If your program is a subroutine library, you may
-+consider it more useful to permit linking proprietary applications with the
-+library. If this is what you want to do, use the GNU Library General
-+Public License instead of this License.
-diff -urNad zaptel-1.2.2/qozap/Makefile /tmp/dpep.xmeNb1/zaptel-1.2.2/qozap/Makefile
---- zaptel-1.2.2/qozap/Makefile 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.xmeNb1/zaptel-1.2.2/qozap/Makefile 2006-01-18 13:48:42.000000000 +0200
-@@ -0,0 +1,91 @@
-+KINCLUDES = /usr/src/linux/include
-+BRISTUFFBASE = $(shell dirname `pwd`)
-+
-+ZAP = $(shell [ -f $(BRISTUFFBASE)/zaptel-1.2.2/zaptel.h ] && echo "-I$(BRISTUFFBASE)/zaptel-1.2.2")
-+
-+HOSTCC=gcc
-+
-+CFLAGS+=-I. $(ZAP) -O4 -g -Wall -DBUILDING_TONEZONE #-DTONEZONE_DRIVER
-+CFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-fsigned-char"; fi)
-+
-+KFLAGS=-D__KERNEL__ -DMODULE -DEXPORT_SYMTAB -fomit-frame-pointer -O2 -Wall -I$(KINCLUDES) $(ZAP)
-+KFLAGS+=$(shell [ -f $(KINCLUDES)/linux/modversions.h ] && echo "-DMODVERSIONS -include $(KINCLUDES)/linux/modversions.h")
-+KFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-msoft-float -fsigned-char"; fi)
-+
-+OBJS=qozap.o
-+
-+BUILDVER=$(shell if uname -r | grep -q ^2.6; then echo "linux26"; else echo "linux24"; fi)
-+
-+MODCONF=$(shell if [ -d $(INSTALL_PREFIX)/etc/modprobe.d ]; then echo "$(INSTALL_PREFIX)/etc/modprobe.d/zaptel"; elif [ -d $(INSTALL_PREFIX)/etc/modutils ]; then echo "$(INSTALL_PREFIX)/etc/modutils/zaptel"; elif [ -f $(INSTALL_PREFIX)/etc/modprobe.conf ]; then echo "$(INSTALL_PREFIX)/modprobe.conf"; elif [ -f $(INSTALL_PREFIX)/etc/modules.conf ]; then echo "$(INSTALL_PREFIX)/etc/modules.conf"; else echo $(INSTALL_PREFIX)/etc/conf.modules ; fi)
-+
-+MODULES=qozap
-+
-+MODULESO=$(shell for x in $(MODULES); do echo "$$x.o "; done )
-+MODULESKO=$(shell for x in $(MODULES); do echo "$$x.ko "; done )
-+
-+PWD=$(shell pwd)
-+
-+obj-m := $(MODULESO)
-+
-+all: $(BUILDVER)
-+
-+linux24: $(OBJS)
-+ sync
-+
-+linux26:
-+ @if ! [ -d /usr/src/linux-2.6 ]; then echo "Link /usr/src/linux-2.6 to your kernel sources first!"; exit 1 ; fi
-+ make -C /usr/src/linux-2.6 SUBDIRS=$(PWD) ZAP=$(ZAP) modules
-+obj-m := $(OBJS)
-+
-+qozap.o: qozap.c qozap.h
-+ $(CC) -c qozap.c $(KFLAGS)
-+
-+clean:
-+ rm -f $(OBJS) *.ko *.mod.c *.mod.o .*o.cmd *~
-+ rm -rf .tmp_versions
-+
-+testlinux24: all
-+ modprobe zaptel
-+ insmod ./qozap.o
-+ ztcfg -v
-+ cat /proc/interrupts
-+ sleep 1
-+ cat /proc/interrupts
-+ rmmod qozap zaptel
-+
-+testlinux26: all
-+ modprobe zaptel
-+ insmod ./qozap.ko
-+ ztcfg -v
-+ cat /proc/interrupts
-+ sleep 1
-+ cat /proc/interrupts
-+ rmmod qozap zaptel
-+
-+reload: unload load
-+load: load$(BUILDVER)
-+
-+test: test$(BUILDVER)
-+
-+
-+loadlinux24: linux24
-+ modprobe zaptel
-+ insmod ./qozap.o
-+ ztcfg -v
-+
-+loadlinux26: linux26
-+ sync
-+ modprobe zaptel
-+ insmod ./qozap.ko
-+ ztcfg -v
-+
-+unload:
-+ rmmod qozap zaptel
-+
-+install: install$(BUILDVER)
-+
-+installlinux26:
-+ install -D -m 644 qozap.ko $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/qozap.ko
-+
-+installlinux24:
-+ install -D -m 644 qozap.o $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/qozap.o
-diff -urNad zaptel-1.2.2/qozap/qozap.c /tmp/dpep.xmeNb1/zaptel-1.2.2/qozap/qozap.c
---- zaptel-1.2.2/qozap/qozap.c 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.xmeNb1/zaptel-1.2.2/qozap/qozap.c 2005-08-01 09:58:20.000000000 +0300
-@@ -0,0 +1,1493 @@
-+/*
-+ * qozap.c - Zaptel driver for the quadBRI PCI ISDN card
-+ * and the octoBRI PCI ISDN card!
-+ *
-+ * Copyright (C) 2003, 2004, 2005 Junghanns.NET GmbH
-+ *
-+ * Klaus-Peter Junghanns <kpj at junghanns.net>
-+ *
-+ * This program is free software and may be modified and
-+ * distributed under the terms of the GNU Public License.
-+ *
-+ */
-+#include <linux/kernel.h>
-+#include <linux/module.h>
-+#include <linux/pci.h>
-+#include <linux/init.h>
-+#include <linux/interrupt.h>
-+#include <zaptel.h>
-+#include "qozap.h"
-+
-+#if CONFIG_PCI
-+
-+static int doubleclock=0;
-+static int ports=-1; /* autodetect */
-+static int bloop=0;
-+static int debug=0;
-+static struct qoz_card *qoz_dev_list = NULL;
-+static int qoz_dev_count = 0;
-+static int totalBRIs = 0;
-+static struct pci_dev *multi_qoz = NULL;
-+static spinlock_t registerlock = SPIN_LOCK_UNLOCKED;
-+
-+static int ztqoz_shutdown(struct zt_span *span);
-+
-+int qoz_waitbusy(struct qoz_card *qoztmp) {
-+ int x=1000;
-+ while (x-- && (qoz_inb(qoztmp,qoz_R_STATUS) & 1));
-+ if (x < 0) {
-+ return -1;
-+ } else {
-+ return 0;
-+ }
-+}
-+
-+void qoz_shutdownCard(struct qoz_card *qoztmp) {
-+ int s=0;
-+ unsigned long flags;
-+ int stports=0;
-+ if (qoztmp == NULL) {
-+ printk(KERN_INFO "qozap: shutting down NULL card!\n");
-+ return;
-+ }
-+
-+ if ((qoztmp->pci_io == NULL) || (qoztmp->ioport == 0)) {
-+ return;
-+ }
-+
-+ if (debug)
-+ printk(KERN_INFO "qozap: shutting down card %d (cardID %d) at io port %#x.\n",qoztmp->cardno,qoztmp->cardID,(u_int) qoztmp->ioport);
-+
-+ if (qoztmp->ztdev != NULL) {
-+ stports = qoztmp->stports;
-+ for (s=0; s < stports; s++) {
-+ if(qoztmp->ztdev->spans[s].flags & ZT_FLAG_RUNNING) {
-+ ztqoz_shutdown(&qoztmp->ztdev->spans[s]);
-+ if (debug)
-+ printk(KERN_INFO "qozap: shutdown card %d span %d.\n",qoztmp->cardno,s+1);
-+ }
-+ }
-+ }
-+
-+ spin_lock_irqsave(&qoztmp->lock,flags);
-+
-+ // turn off irqs
-+ qoz_outb(qoztmp,qoz_R_IRQ_CTRL, 0);
-+ qoz_outb(qoztmp,qoz_R_IRQMSK_MISC, 0);
-+ qoz_outb(qoztmp,qoz_R_SCI_MSK, 0);
-+
-+ free_irq(qoztmp->irq,qoztmp);
-+
-+ // softreset
-+ qoz_outb(qoztmp,qoz_R_CIRM,0x8);
-+ qoz_outb(qoztmp,qoz_R_CIRM,0x0);
-+ qoz_waitbusy(qoztmp);
-+
-+ qoz_outb(qoztmp,qoz_R_IRQMSK_MISC, 0);
-+ qoz_outb(qoztmp,qoz_R_SCI_MSK, 0);
-+ qoz_outb(qoztmp,qoz_R_IRQ_CTRL, 0);
-+
-+ release_region(qoztmp->ioport, 7);
-+ iounmap((void *) qoztmp->pci_io);
-+
-+ qoztmp->pci_io = NULL;
-+ qoztmp->ioport = 0;
-+
-+ if (qoztmp->pcidev != NULL) {
-+ pci_disable_device(qoztmp->pcidev);
-+ }
-+ pci_write_config_word(qoztmp->pcidev, PCI_COMMAND, 0);
-+
-+ spin_unlock_irqrestore(&qoztmp->lock,flags);
-+
-+ if (qoztmp->ztdev != NULL) {
-+ stports = qoztmp->stports;
-+ for (s=0; s < stports; s++) {
-+ if(qoztmp->ztdev->spans[s].flags & ZT_FLAG_REGISTERED) {
-+ zt_unregister(&qoztmp->ztdev->spans[s]);
-+ if (debug)
-+ printk(KERN_INFO "qozap: unregistered card %d span %d.\n",qoztmp->cardno,s+1);
-+ }
-+ }
-+ kfree(qoztmp->ztdev);
-+ qoztmp->ztdev = NULL;
-+ }
-+}
-+
-+void qoz_doLEDs(struct qoz_card *qoztmp) {
-+ unsigned char leds = 0x0;
-+ if ((qoztmp->type == 0xb520) && (qoztmp->stports == 4)){
-+// if ((qoztmp->ticks > 0) && (qoztmp->ticks <= 300)) {
-+ qoz_outb(qoztmp,qoz_R_GPIO_SEL,0x20 | 0x10);
-+ qoz_outb(qoztmp,qoz_R_GPIO_EN1,0xf);
-+ qoz_outb(qoztmp,qoz_R_GPIO_OUT1,(qoztmp->leds[0] | (qoztmp->leds[1] << 1) | (qoztmp->leds[2] << 2) | (qoztmp->leds[3] << 3)));
-+/* }
-+ if ((qoztmp->ticks > 300) && (qoztmp->ticks <= 600)) {
-+ qoz_outb(qoztmp,qoz_R_GPIO_EN1,0x0);
-+ } */
-+ } else if ((qoztmp->type == 0xb550) && (qoztmp->stports == 4)){
-+ qoz_outb(qoztmp,qoz_R_GPIO_SEL,0x80 | 0x40 | 0x20 | 0x10);
-+ qoz_outb(qoztmp,qoz_R_GPIO_EN1,0xff);
-+ if (qoztmp->leds[0] == 0) {
-+ leds |= 0x80;
-+ } else {
-+ leds |= 0x40;
-+ }
-+ if (qoztmp->leds[1] == 0) {
-+ leds |= 0x10;
-+ } else {
-+ leds |= 0x20;
-+ }
-+ if (qoztmp->leds[2] == 0) {
-+ leds |= 0x04;
-+ } else {
-+ leds |= 0x08;
-+ }
-+ if (qoztmp->leds[3] == 0) {
-+ leds |= 0x02;
-+ } else {
-+ leds |= 0x01;
-+ }
-+ /* 0x80 st1g
-+ 0x40 st1r
-+ 0x20 st2r
-+ 0x10 st2g
-+ 0x08 st3r
-+ 0x04 st3g
-+ 0x02 st4g
-+ 0x01 st4r
-+ */
-+ qoz_outb(qoztmp,qoz_R_GPIO_OUT1, leds);
-+ }
-+}
-+
-+void qoz_doWD(struct qoz_card *qoztmp) {
-+ if (!qoztmp->wdp) {
-+ return;
-+ }
-+ if (qoztmp->wdp == 1) {
-+ qoz_outdw_io(qoztmp,0x4000, qoz_WD_P2);
-+ qoztmp->wdp = 2;
-+ } else {
-+ qoz_outdw_io(qoztmp,0x4000, qoz_WD_P1);
-+ qoztmp->wdp = 1;
-+ }
-+ qoz_inb_io(qoztmp,qoz_R_CHIP_ID);
-+}
-+
-+void qoz_undoWD(struct qoz_card *qoztmp) {
-+ printk(KERN_INFO "qozap: Stopping hardware watchdog.\n");
-+ qoz_outdw_io(qoztmp,0x4000, qoz_WD_P0);
-+ qoztmp->wdp = 0;
-+ qoz_inb_io(qoztmp,qoz_R_CHIP_ID);
-+}
-+
-+void qoz_resetCard(struct qoz_card *qoztmp) {
-+ unsigned long flags;
-+ unsigned char i=0;
-+ spin_lock_irqsave(&(qoztmp->lock),flags);
-+ pci_write_config_word(qoztmp->pcidev, PCI_COMMAND, PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
-+
-+ // soft reset
-+ qoz_outb(qoztmp,qoz_R_CIRM,0x8);
-+ qoz_outb(qoztmp,qoz_R_CIRM,0x0);
-+ qoz_waitbusy(qoztmp);
-+
-+ // fifo reset
-+ qoz_outb(qoztmp,qoz_R_CIRM,0x10);
-+ qoz_outb(qoztmp,qoz_R_CIRM,0x0);
-+ qoz_waitbusy(qoztmp);
-+
-+ // s/t reset
-+ qoz_outb(qoztmp,qoz_R_CIRM,0x40);
-+ qoz_outb(qoztmp,qoz_R_CIRM,0x0);
-+ qoz_waitbusy(qoztmp);
-+
-+ /* set S0 amplitude */
-+ qoz_outb(qoztmp,qoz_R_PWM_MD,0xa0);
-+ if (qoztmp->type == 0xb552) {
-+ qoz_outb(qoztmp,qoz_R_PWM0,0x19);
-+ } else {
-+ qoz_outb(qoztmp,qoz_R_PWM0,0x1E);
-+ }
-+
-+ /* set up the timer */
-+ qoz_outb(qoztmp,qoz_R_TI_WD, 0x2);
-+ qoz_outb(qoztmp,qoz_R_IRQMSK_MISC, 0x2);
-+ qoz_outb(qoztmp,qoz_R_PCM_MD0, 0x1);
-+
-+ /* all state changes */
-+ qoz_outb(qoztmp,qoz_R_SCI_MSK, 0xff);
-+
-+ if (qoztmp->type == 0xb552) {
-+ qoz_outb(qoztmp,qoz_R_FIFO_MD,0x16);
-+ } else {
-+ qoz_outb(qoztmp,qoz_R_FIFO_MD,0x26);
-+ }
-+
-+ // double clock
-+ if (doubleclock == 1) {
-+ // hopefully you have set CLK_MODE correctly!
-+ qoz_outb(qoztmp,qoz_R_BRG_PCM_CFG,0x20);
-+ } else {
-+ if (qoztmp->type == 0x08b4) {
-+ qoz_outb(qoztmp,qoz_R_BRG_PCM_CFG,0x0);
-+ } else if (qoztmp->type == 0xb550) {
-+ qoz_outb(qoztmp,qoz_R_BRG_PCM_CFG,0x23);
-+ } else if (qoztmp->type == 0xb520) {
-+ qoz_outb(qoztmp,qoz_R_BRG_PCM_CFG,0x20);
-+ } else {
-+ /* you are on your own here! */
-+ qoz_outb(qoztmp,qoz_R_BRG_PCM_CFG,0x20);
-+ }
-+ }
-+ qoz_outb(qoztmp,qoz_R_CTRL,0x0);
-+
-+ /* R0 G1 */
-+ qoztmp->leds[0] = 0x0;
-+ qoztmp->leds[1] = 0x0;
-+ qoztmp->leds[2] = 0x0;
-+ qoztmp->leds[3] = 0x0;
-+ qoztmp->leds[4] = 0x0;
-+ qoztmp->leds[5] = 0x0;
-+ qoztmp->leds[6] = 0x0;
-+ qoztmp->leds[7] = 0x0;
-+
-+ /* Finally enable IRQ output */
-+ qoz_outb(qoztmp,qoz_R_IRQ_CTRL, 0x8 | 0x1);
-+ if (qoztmp->type == 0xb552) {
-+ qoztmp->stports = 8;
-+ } else {
-+ qoztmp->stports = 4;
-+ }
-+ qoztmp->ticks = 0;
-+ qoztmp->clicks = 0;
-+ if (qoztmp->type == 0xb550) {
-+ printk(KERN_INFO "qozap: Starting hardware watchdog.\n");
-+ qoztmp->wdp = 2;
-+ } else {
-+ qoztmp->wdp = 0;
-+ }
-+
-+ for (i=0;i<qoztmp->stports;i++) {
-+ if (qoztmp->st[i].nt_mode) {
-+ qoz_outb(qoztmp,qoz_R_ST_SYNC,0x8 | i);
-+ if (debug)
-+ printk(KERN_INFO "qoztmp: using NT port %d for sync\n", i);
-+ break;
-+ }
-+ }
-+ if (i == qoztmp->stports) {
-+ qoz_outb(qoztmp,qoz_R_ST_SYNC,0x0);
-+ }
-+ spin_unlock_irqrestore(&(qoztmp->lock),flags);
-+}
-+
-+void qoz_registerCard(struct qoz_card *qozcard) {
-+ spin_lock(®isterlock);
-+ if (qozcard != NULL) {
-+ qozcard->prev = NULL;
-+ qozcard->next = qoz_dev_list;
-+ if (qoz_dev_list) {
-+ qoz_dev_list->prev = qozcard;
-+ }
-+ qoz_dev_list = qozcard;
-+ qozcard->cardno = ++qoz_dev_count;
-+ } else {
-+ printk(KERN_INFO "qozap: trying to register NULL card.\n");
-+ }
-+ spin_unlock(®isterlock);
-+}
-+
-+static int qoz_dfifo_tx(struct qoz_card *qoztmp, int stport) {
-+ int chan = 2;
-+ int x=0;
-+ char fifo = 0;
-+ char offset = 0;
-+
-+ if (qoztmp->type == 0xb552) {
-+ offset = 24;
-+ } else {
-+ offset = 28;
-+ }
-+
-+ fifo = stport + offset;
-+
-+ if (qoztmp->ztdev->chans[stport][chan].bytes2transmit < 1) {
-+ return 0;
-+ } else {
-+ /* select fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,fifo << 1);
-+ qoz_waitbusy(qoztmp);
-+
-+ if (debug > 1)
-+ printk(KERN_INFO "qozap: card %d stport %d TX [ ", qoztmp->cardno, stport + 1);
-+ /* copy frame to fifo */
-+ for (x=0;x<qoztmp->ztdev->chans[stport][chan].bytes2transmit;x++) {
-+ if (debug > 1)
-+ printk("%#x ",qoztmp->dtxbuf[stport][x]);
-+ qoz_outb(qoztmp,qoz_A_FIFO_DATA0,qoztmp->dtxbuf[stport][x]);
-+ }
-+ if (debug > 1)
-+ printk("] %d bytes\n",qoztmp->ztdev->chans[stport][chan].bytes2transmit);
-+
-+ if (qoztmp->ztdev->chans[stport][chan].eoftx == 1) {
-+ /* transmit HDLC frame */
-+ qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x1);
-+ qoz_waitbusy(qoztmp);
-+ }
-+ }
-+ return 0;
-+}
-+
-+static int qoz_fifo_tx(struct qoz_card *qoztmp, char fifo) {
-+ int stport = fifo / 2;
-+ int chan = fifo % 2;
-+
-+ /* select fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,0x80 | (fifo << 1));
-+ qoz_waitbusy(qoztmp);
-+ /* transmit 8 bytes of transparent data */
-+ qoz_outdw(qoztmp,qoz_A_FIFO_DATA0,*((unsigned int *) &qoztmp->txbuf[stport][chan][0]));
-+ qoz_outdw(qoztmp,qoz_A_FIFO_DATA0,*((unsigned int *) &qoztmp->txbuf[stport][chan][4]));
-+
-+ return 0;
-+}
-+
-+static int qoz_dfifo_rx(struct qoz_card *qoztmp, int stport) {
-+ unsigned char f1=1,f2=1,data,stat;
-+ unsigned char of1=0,of2=0;
-+ int len,i;
-+ unsigned short z1=1,z2=1;
-+ unsigned short oz1=0,oz2=0;
-+ char fifo = 0;
-+ char offset = 0;
-+
-+ if (qoztmp->type == 0xb552) {
-+ offset = 24;
-+ } else {
-+ offset = 28;
-+ }
-+
-+ fifo = stport + offset;
-+ // select rx fifo
-+
-+ qoz_outb(qoztmp,qoz_R_FIFO,(fifo << 1) | 1);
-+ qoz_waitbusy(qoztmp);
-+
-+ while ((of1 != f1) && (of2 != f2)) {
-+ of1 = f1;
-+ of2 = f2;
-+ f1 = qoz_inb(qoztmp,qoz_A_F1) & 0xf;
-+ f2 = qoz_inb(qoztmp,qoz_A_F2) & 0xf;
-+ }
-+
-+ if (f1 == f2) {
-+ /* no frame */
-+ qoztmp->st[stport].drx--;
-+ qoztmp->ztdev->chans[stport][2].bytes2receive = 0;
-+ return 0;
-+ }
-+
-+ while ((oz1 != z1) && (oz2 != z2)) {
-+ oz1 = z1;
-+ oz2 = z2;
-+ if (qoztmp->type != 0xb552) {
-+ z1 = qoz_inw(qoztmp,qoz_A_Z1) & 0x7ff;
-+ z2 = qoz_inw(qoztmp,qoz_A_Z2) & 0x7ff;
-+ } else {
-+ z1 = qoz_inw(qoztmp,qoz_A_Z1) & 0x3ff;
-+ z2 = qoz_inw(qoztmp,qoz_A_Z2) & 0x3ff;
-+ }
-+ }
-+
-+ if (qoztmp->type == 0xb552) {
-+ len = z1 - z2;
-+ if (len < 0) {
-+ len += qoz_DFIFO_SIZE8;
-+ }
-+ } else {
-+ len = z1 - z2;
-+ if (len < 0) {
-+ len += qoz_DFIFO_SIZE4;
-+ }
-+ }
-+
-+ if (len > qoz_DFIFO_SIZE4) {
-+ printk(KERN_INFO "\nqozap: buffer overflow in D channel RX!\n");
-+ qoztmp->ztdev->chans[stport][2].bytes2receive = 0;
-+ qoztmp->ztdev->chans[stport][2].eofrx = 0;
-+ } else {
-+ if (debug > 1) printk(KERN_INFO "qozap: card %d span %d RX [ ", qoztmp->cardno, stport + 1);
-+ for (i=0; i<len; i++) {
-+ data = qoz_inb(qoztmp,qoz_A_FIFO_DATA0);
-+ qoztmp->drxbuf[stport][i] = data;
-+ if (debug > 1) printk("%#x ",data);
-+ }
-+ if (debug > 1) printk("] %d bytes\n", len);
-+ qoztmp->ztdev->chans[stport][2].bytes2receive = i;
-+ qoztmp->ztdev->chans[stport][2].eofrx = 1;
-+ }
-+
-+ stat = qoz_inb(qoztmp,qoz_A_FIFO_DATA0);
-+ if (stat != 0x0) {
-+ // bad CRC, skip it
-+ printk(KERN_INFO "qozap: CRC error for HDLC frame on card %d (cardID %d) S/T port %d\n",qoztmp->cardno, qoztmp->cardID, stport+1);
-+ qoztmp->ztdev->chans[stport][2].bytes2receive = 0;
-+ qoztmp->ztdev->chans[stport][2].eofrx = 0;
-+// zt_qevent_nolock(&qoztmp->ztdev->chans[stport][2], ZT_EVENT_BADFCS);
-+ }
-+ qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x1);
-+ qoz_waitbusy(qoztmp);
-+
-+ /* frame recevived */
-+ if (qoztmp->st[stport].drx > 0) {
-+ qoztmp->st[stport].drx--;
-+ } else {
-+ printk(KERN_INFO "qozap: trying to receive too much (card %d span %d drx %d)\n", qoztmp->cardno, stport+1, qoztmp->st[stport].drx);
-+ qoztmp->st[stport].drx = 0;
-+ }
-+ return 0;
-+}
-+
-+
-+static int qoz_fifo_rx(struct qoz_card *qoztmp, char fifo) {
-+ int stport = fifo / 2;
-+ int chan = fifo % 2;
-+ unsigned char data;
-+ int len,i;
-+ unsigned short z1=1,z2=1;
-+ unsigned short oz1=0,oz2=0;
-+ int mumbojumbo=0;
-+
-+ /* select rx fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,0x80 | (fifo << 1) | 1);
-+ qoz_waitbusy(qoztmp);
-+
-+ while ((oz1 != z1) && (oz2 != z2)) {
-+ oz1 = z1;
-+ oz2 = z2;
-+ z1 = qoz_inw(qoztmp,qoz_A_Z1) & 0x7f;
-+ z2 = qoz_inw(qoztmp,qoz_A_Z2) & 0x7f;
-+ }
-+ len = z1 - z2;
-+ if (len < 0) {
-+ len += qoz_FIFO_SIZE;
-+ }
-+ if (len > 2 * ZT_CHUNKSIZE) {
-+ mumbojumbo = len - (2 * ZT_CHUNKSIZE);
-+ len = ZT_CHUNKSIZE;
-+ for (i=0;i<mumbojumbo;i++) {
-+ data = qoz_inb(qoztmp,qoz_A_FIFO_DATA0);
-+ }
-+ qoztmp->clicks++;
-+ if ((qoztmp->clicks > 1) || (debug == 4)) {
-+ printk(KERN_CRIT "qozap: dropped audio card %d cardid %d bytes %d z1 %d z2 %d\n", qoztmp->cardno, qoztmp->cardID, mumbojumbo, z1, z2);
-+ qoztmp->clicks = 0;
-+ }
-+ }
-+ if (len < ZT_CHUNKSIZE) {
-+// printk(KERN_INFO "qozap: not enough to receive (%d bytes)\n",len);
-+ return 0;
-+ } else {
-+ if (bloop) {
-+ *((unsigned int *) &qoztmp->txbuf[stport][chan][0]) = qoz_indw(qoztmp,qoz_A_FIFO_DATA0);
-+ *((unsigned int *) &qoztmp->txbuf[stport][chan][4]) = qoz_indw(qoztmp,qoz_A_FIFO_DATA0);
-+ } else {
-+ *((unsigned int *) &qoztmp->rxbuf[stport][chan][0]) = qoz_indw(qoztmp,qoz_A_FIFO_DATA0);
-+ *((unsigned int *) &qoztmp->rxbuf[stport][chan][4]) = qoz_indw(qoztmp,qoz_A_FIFO_DATA0);
-+ }
-+ }
-+ if (bloop == 0)
-+ zt_ec_chunk(&qoztmp->ztdev->spans[stport].chans[chan], qoztmp->ztdev->spans[stport].chans[chan].readchunk, qoztmp->ztdev->spans[stport].chans[chan].writechunk);
-+
-+// printk(KERN_INFO "s/t port %d, channel %d, dbufi=%d, f1=%d, f2=%d, z1=%d, z2=%d => len = %d stat=%#x, hdlc=%d\n",stport,chan,qoztmp->st[stport].dbufi,f1,f2,z1,z2,len,stat,hdlc);
-+ return 0;
-+}
-+
-+
-+static inline void qoz_run(struct qoz_card *qoztmp) {
-+ int s=0;
-+ if (qoztmp->ztdev != NULL) {
-+ for (s=0;s<qoztmp->stports;s++) {
-+ if (!bloop) {
-+ if (qoztmp->ztdev->spans[s].flags & ZT_FLAG_RUNNING) {
-+ /* oh zaptel! tell us what to transmit... */
-+ zt_transmit(&qoztmp->ztdev->spans[s]);
-+ /* B1 xmit */
-+ qoz_fifo_tx(qoztmp, s * 2);
-+ /* B2 xmit */
-+ qoz_fifo_tx(qoztmp, (s * 2) + 1);
-+
-+ if ((qoztmp->st[s].layer1state != 7) && (qoztmp->ztdev->chans[s][2].bytes2transmit > 0) && (qoztmp->st[s].nt_mode != 1)) {
-+ if (qoztmp->st[s].t3 == -1) {
-+ printk(KERN_INFO "qozap: activating layer 1, span %d\n",s);
-+ qoztmp->st[s].t3 = 0;
-+ qoz_outb(qoztmp,qoz_R_ST_SEL, s);
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x60);
-+ } else {
-+ }
-+ }
-+
-+ /* D xmit */
-+ if (qoztmp->ztdev->spans[s].alarms != ZT_ALARM_RED) {
-+ qoz_dfifo_tx(qoztmp, s);
-+ } else {
-+ if ((qoztmp->st[s].t3 == -1) && (qoztmp->st[s].t4 == -1) && (qoztmp->st[s].layer1state == 3) && (qoztmp->st[s].nt_mode != 1)) {
-+ /* clear alarms */
-+ printk(KERN_INFO "qozap: clearing alarms on span %d\n",s);
-+ qoztmp->ztdev->spans[s].alarms = ZT_ALARM_NONE;
-+ zt_alarm_notify(&qoztmp->ztdev->spans[s]);
-+ }
-+ }
-+
-+ qoztmp->ztdev->chans[s][2].bytes2receive = 0;
-+ qoztmp->ztdev->chans[s][2].bytes2transmit = 0;
-+ qoztmp->ztdev->chans[s][2].eofrx = 0;
-+ qoztmp->ztdev->chans[s][2].eoftx = 0;
-+
-+ }
-+
-+ /* B1 receive */
-+ qoz_fifo_rx(qoztmp,(s*2));
-+ /* B2 receive */
-+ qoz_fifo_rx(qoztmp,(s*2)+1);
-+ /* d-chan data */
-+ if (qoztmp->st[s].drx > 0) {
-+ if (debug > 2)
-+ printk(KERN_CRIT "qozap: card %d st[%d].drx = %d\n", qoztmp->cardno, s, qoztmp->st[s].drx);
-+ qoz_dfifo_rx(qoztmp, s);
-+ }
-+ if (qoztmp->ztdev->spans[s].flags & ZT_FLAG_RUNNING) {
-+ /* oh zaptel! thou shall receive! */
-+ zt_receive(&(qoztmp->ztdev->spans[s]));
-+ }
-+ } else {
-+ // loop
-+ /* B1 receive */
-+ qoz_fifo_rx(qoztmp,(s*2));
-+ /* B2 receive */
-+ qoz_fifo_rx(qoztmp,(s*2)+1);
-+ /* d-chan data */
-+/* if (qoztmp->st[s].drx > 0) {
-+ if (debug > 2)
-+ printk(KERN_CRIT "qozap: card %d st[%d].drx = %d\n", qoztmp->cardno, s, qoztmp->st[s].drx);
-+ qoz_dfifo_rx(qoztmp, s);
-+ }
-+ if (qoztmp->ztdev->spans[s].flags & ZT_FLAG_RUNNING) {
-+ zt_receive(&(qoztmp->ztdev->spans[s]));
-+ }
-+*/
-+ if (qoztmp->ztdev->spans[s].flags & ZT_FLAG_RUNNING) {
-+ /* oh zaptel! tell us what to transmit... */
-+ // zt_transmit(&qoztmp->ztdev->spans[s]);
-+ /* B1 xmit */
-+ qoz_fifo_tx(qoztmp, s * 2);
-+ /* B2 xmit */
-+ qoz_fifo_tx(qoztmp, (s * 2) + 1);
-+ /* D xmit */
-+// qoz_dfifo_tx(qoztmp, s);
-+
-+ qoztmp->ztdev->chans[s][2].bytes2receive = 0;
-+ qoztmp->ztdev->chans[s][2].bytes2transmit = 0;
-+ qoztmp->ztdev->chans[s][2].eofrx = 0;
-+ qoztmp->ztdev->chans[s][2].eoftx = 0;
-+
-+ }
-+ }
-+ }
-+ }
-+}
-+
-+#ifdef LINUX26
-+static irqreturn_t qoz_interrupt(int irq, void *dev_id, struct pt_regs *regs) {
-+#else
-+static void qoz_interrupt(int irq, void *dev_id, struct pt_regs *regs) {
-+#endif
-+ struct qoz_card *qoztmp = dev_id;
-+ struct zt_qoz *ztqoz = qoztmp->ztdev;
-+ unsigned long flags;
-+ unsigned char irq_misc,irq_sci,status,l1state,irq_foview,fi;
-+ int st=0,i=0,offset=0;
-+ int j=0;
-+
-+ if (!qoztmp) {
-+#ifdef LINUX26
-+ return IRQ_NONE;
-+#else
-+ return;
-+#endif
-+ }
-+
-+ if ((!qoztmp->pci_io) || (!qoztmp->ioport)) {
-+ printk(KERN_CRIT "qozap: no pci mem/io\n");
-+#ifdef LINUX26
-+ return IRQ_NONE;
-+#else
-+ return;
-+#endif
-+ }
-+
-+ spin_lock_irqsave(&(qoztmp->lock),flags);
-+ status = qoz_inb(qoztmp,qoz_R_STATUS);
-+ irq_sci = qoz_inb(qoztmp,qoz_R_SCI);
-+
-+ if (!(status & 0x80) && !(status & 0x40) && (irq_sci == 0)) {
-+// printk(KERN_CRIT "qozap: status %#x\n", status);
-+ // it's not us!
-+ spin_unlock_irqrestore(&(qoztmp->lock),flags);
-+#ifdef LINUX26
-+ return IRQ_NONE;
-+#else
-+ return;
-+#endif
-+ }
-+ /* state machine irq */
-+ if (irq_sci != 0) {
-+ if (debug > 1) {
-+ printk(KERN_INFO "R_BERT_STA = %#x\n", qoz_inb(qoztmp, qoz_R_BERT_STA) & 7);
-+ }
-+ for (st=0;st<qoztmp->stports;st++) {
-+ if (irq_sci & (1 << st)) {
-+ qoz_outb(qoztmp,qoz_R_ST_SEL,st);
-+ l1state = qoz_inb(qoztmp,qoz_A_ST_RD_STA) & 0xf;
-+ if (debug > 1) {
-+ printk(KERN_INFO "A_ST_RD_STA = %#x\n", qoz_inb(qoztmp, qoz_A_ST_RD_STA));
-+ }
-+ qoztmp->st[st].layer1state = l1state;
-+ if (qoztmp->st[st].nt_mode == 1) {
-+ if (debug)
-+ printk(KERN_INFO "card %d span %d state G%d (A_ST_RD_STA = %#x)\n",qoztmp->cardno,st+1,l1state,qoz_inb(qoztmp,qoz_A_ST_RD_STA));
-+ // NT state machine
-+ if (l1state == 3) {
-+ // keep layer1 up!
-+ if (qoztmp->stports == 8) {
-+ sprintf(ztqoz->spans[st].desc,"octoBRI PCI ISDN Card %d Span %d [NT] Layer 1 ACTIVATED (G%d)",qoztmp->cardno ,st + 1, l1state);
-+ } else {
-+ sprintf(ztqoz->spans[st].desc,"quadBRI PCI ISDN Card %d Span %d [NT] (cardID %d) Layer 1 ACTIVATED (G%d)",qoztmp->cardno ,st + 1,ztqoz->card->cardID, l1state);
-+ }
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,3 | 0x10 );
-+ qoztmp->leds[st] = 1;
-+ } else {
-+ if (qoztmp->stports == 8) {
-+ sprintf(ztqoz->spans[st].desc,"octoBRI PCI ISDN Card %d Span %d [NT] Layer 1 DEACTIVATED (G%d)",qoztmp->cardno ,st + 1, l1state);
-+ } else {
-+ sprintf(ztqoz->spans[st].desc,"quadBRI PCI ISDN Card %d Span %d [NT] (cardID %d) Layer 1 DEACTIVATED (G%d)",qoztmp->cardno ,st + 1,ztqoz->card->cardID, l1state);
-+ }
-+ qoztmp->leds[st] = 0;
-+ }
-+ } else {
-+ if (debug)
-+ printk(KERN_INFO "card %d span %d state F%d (A_ST_RD_STA = %#x)\n",qoztmp->cardno,st+1,l1state,qoz_inb(qoztmp,qoz_A_ST_RD_STA));
-+ // TE state machine
-+ if (l1state == 3) {
-+ if (qoztmp->st[st].t3 > -1) {
-+ /* keep layer1 up, if the span is started. */
-+ if (qoztmp->ztdev->spans[st].flags & ZT_FLAG_RUNNING) {
-+printk("qozap: re-activating layer1 span %d\n", st);
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x60);
-+ }
-+ } else {
-+printk("qozap: not re-activating layer1 span %d\n", st);
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x40);
-+ /* if we tried to activate layer 1 and it failed make this an alarm */
-+// qoztmp->ztdev->spans[st].alarms = ZT_ALARM_RED;
-+// zt_alarm_notify(&qoztmp->ztdev->spans[st]);
-+ /* if the network shuts us down in idle mode dont make this an alarm */
-+ }
-+ qoztmp->leds[st] = 0;
-+ if (qoztmp->stports == 8) {
-+ sprintf(ztqoz->spans[st].desc,"octoBRI PCI ISDN Card %d Span %d [TE] Layer 1 DEACTIVATED (F%d)",qoztmp->cardno ,st + 1, l1state);
-+ } else {
-+ sprintf(ztqoz->spans[st].desc,"quadBRI PCI ISDN Card %d Span %d [TE] (cardID %d) Layer 1 DEACTIVATED (F%d)",qoztmp->cardno ,st + 1,ztqoz->card->cardID, l1state);
-+ }
-+ } else if (l1state == 7) {
-+ /* activation complete, stop timer t3 */
-+ qoztmp->st[st].t3 = -1;
-+ qoztmp->ztdev->spans[st].alarms = ZT_ALARM_NONE;
-+ zt_alarm_notify(&qoztmp->ztdev->spans[st]);
-+ qoztmp->leds[st] = 1;
-+ if (qoztmp->stports == 8) {
-+ sprintf(ztqoz->spans[st].desc,"octoBRI PCI ISDN Card %d Span %d [TE] Layer 1 ACTIVATED (F%d)",qoztmp->cardno ,st + 1, l1state);
-+ } else {
-+ sprintf(ztqoz->spans[st].desc,"quadBRI PCI ISDN Card %d Span %d [TE] (cardID %d) Layer 1 ACTIVATED (F%d)",qoztmp->cardno ,st + 1,ztqoz->card->cardID, l1state);
-+ }
-+ } else if (l1state == 8) {
-+ /* lost framing */
-+ printk(KERN_INFO "qozap: starting t4 for span %d\n", st);
-+ qoztmp->st[st].t4 = 0;
-+ } else {
-+ if (qoztmp->stports == 8) {
-+ sprintf(ztqoz->spans[st].desc,"octoBRI PCI ISDN Card %d Span %d [TE] Layer 1 DEACTIVATED (F%d)",qoztmp->cardno ,st + 1, l1state);
-+ } else {
-+ sprintf(ztqoz->spans[st].desc,"quadBRI PCI ISDN Card %d Span %d [TE] (cardID %d) Layer 1 DEACTIVATED (F%d)",qoztmp->cardno ,st + 1,ztqoz->card->cardID, l1state);
-+ }
-+ }
-+ }
-+
-+ }
-+ }
-+ }
-+
-+
-+ // misc irq
-+ if (status & 0x40) {
-+ irq_misc = qoz_inb(qoztmp,qoz_R_IRQ_MISC);
-+ if (irq_misc & 0x2) {
-+ // qozap timer
-+ qoztmp->ticks++;
-+ qoz_run(qoztmp);
-+ if (qoztmp->ticks % 100) {
-+ qoz_doLEDs(qoztmp);
-+ }
-+ if (qoztmp->ticks % 40) {
-+ /* you thought that 42 was the answer.... */
-+ qoz_doWD(qoztmp);
-+ }
-+ if (qoztmp->ticks > 1000) {
-+ qoztmp->ticks = 0;
-+ for (j=0;j<qoztmp->stports;j++) {
-+ /* t3 */
-+ if (qoztmp->st[j].t3 >= 0) {
-+ qoztmp->st[j].t3++;
-+ }
-+ if (qoztmp->st[j].nt_mode != 1) {
-+ if ((qoztmp->st[j].t3 > qoz_T3) && (qoztmp->st[j].layer1state != 7)) {
-+ /* deactivate layer 1 */
-+ printk(KERN_INFO "qozap: t3 timer expired for span %d\n", j);
-+ qoz_outb(qoztmp,qoz_R_ST_SEL, j);
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA, 0x40 );
-+ qoztmp->st[j].t3 = -1;
-+ qoztmp->ztdev->spans[j].alarms = ZT_ALARM_RED;
-+ zt_alarm_notify(&qoztmp->ztdev->spans[j]);
-+ qoz_waitbusy(qoztmp);
-+ }
-+ }
-+ /* t4 */
-+ if (qoztmp->st[j].t4 >= 0) {
-+ qoztmp->st[j].t4++;
-+ }
-+ if (qoztmp->st[j].nt_mode != 1) {
-+ if ((qoztmp->st[j].t4 > qoz_T4) && (qoztmp->st[j].layer1state != 7)) {
-+ /* deactivate layer 1 */
-+ printk(KERN_INFO "qozap: t4 timer expired for span %d\n", j);
-+ qoz_outb(qoztmp,qoz_R_ST_SEL, j);
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA, 0x40 );
-+ qoztmp->st[j].t4 = -1;
-+ qoztmp->ztdev->spans[j].alarms = ZT_ALARM_RED;
-+ zt_alarm_notify(&qoztmp->ztdev->spans[j]);
-+ qoz_waitbusy(qoztmp);
-+ }
-+ }
-+ }
-+ }
-+ }
-+ if (irq_misc & 0x4) {
-+ // printk(KERN_INFO "qozap proc/nonproc irq\n");
-+ }
-+ }
-+ if (status & 0x80) {
-+ /* fifo irq */
-+ irq_foview = qoz_inb(qoztmp,qoz_R_IRQ_OVIEW);
-+ if (qoztmp->type == 0xb552) {
-+ if (irq_foview & 0x60) {
-+ offset = 0;
-+ fi = qoz_inb(qoztmp,qoz_R_IRQ_FIFO_BL6);
-+ for (i=0; i < 8; i++) {
-+ if (fi & (1 << i)) {
-+ st = offset + (i / 2);
-+ if (i % 2) {
-+ if (debug > 2)
-+ printk(KERN_CRIT "qozap: HDLC RX irq fifo %d span %d\n", i, st+1);
-+ qoztmp->st[st].drx += 1;
-+ } else {
-+ if (debug > 2)
-+ printk(KERN_CRIT "qozap: HDLC TX irq fifo %d span %d\n", i, st+1);
-+ }
-+ }
-+ }
-+ }
-+ if (irq_foview & 0x80) {
-+ offset = 4;
-+ fi = qoz_inb(qoztmp,qoz_R_IRQ_FIFO_BL7);
-+ for (i=0; i < 8; i++) {
-+ if (fi & (1 << i)) {
-+ st = offset + (i / 2);
-+ if (i % 2) {
-+ if (debug > 2)
-+ printk(KERN_CRIT "qozap: HDLC RX irq fifo %d span %d\n", i, st+1);
-+ qoztmp->st[st].drx += 1;
-+ } else {
-+ if (debug > 2)
-+ printk(KERN_CRIT "qozap: HDLC TX irq fifo %d span %d\n", i, st+1);
-+ }
-+ }
-+ }
-+ }
-+ } else {
-+ if (irq_foview & 0x80) {
-+ fi = qoz_inb(qoztmp,qoz_R_IRQ_FIFO_BL7);
-+ for (i=0; i < 8; i++) {
-+ if (fi & (1 << i)) {
-+ st = i / 2;
-+ if (i % 2) {
-+ if (debug > 2)
-+ printk(KERN_CRIT "qozap: HDLC RX irq fifo %d span %d\n", i, st+1);
-+ qoztmp->st[st].drx += 1;
-+ } else {
-+ if (debug > 2)
-+ printk(KERN_CRIT "qozap: HDLC TX irq fifo %d span %d\n", i, st+1);
-+ }
-+ }
-+ }
-+ }
-+ }
-+ }
-+
-+ spin_unlock_irqrestore(&(qoztmp->lock),flags);
-+#ifdef LINUX26
-+ return IRQ_RETVAL(1);
-+#endif
-+}
-+
-+static int ztqoz_open(struct zt_chan *chan) {
-+// printk(KERN_INFO "qozap: channel %d opened.\n",chan->channo);
-+#ifndef LINUX26
-+ MOD_INC_USE_COUNT;
-+#else
-+ try_module_get(THIS_MODULE);
-+#endif
-+ return 0;
-+}
-+
-+static int ztqoz_close(struct zt_chan *chan) {
-+// printk(KERN_INFO "qozap: channel %d closed.\n",chan->channo);
-+#ifndef LINUX26
-+ MOD_DEC_USE_COUNT;
-+#else
-+ module_put(THIS_MODULE);
-+#endif
-+ return 0;
-+}
-+
-+static int ztqoz_rbsbits(struct zt_chan *chan, int bits) {
-+ return 0;
-+}
-+
-+static int ztqoz_ioctl(struct zt_chan *chan, unsigned int cmd, unsigned long data) {
-+ switch(cmd) {
-+ default:
-+ return -ENOTTY;
-+ }
-+ return 0;
-+}
-+
-+static int ztqoz_startup(struct zt_span *span) {
-+ struct zt_qoz *qozt = span->pvt;
-+ struct qoz_card *qoztmp = qozt->card;
-+ unsigned long flags;
-+ int alreadyrunning;
-+ int i=0;
-+ int offset = 0;
-+
-+ if (qoztmp == NULL) {
-+ printk(KERN_INFO "qozap: no card for span at startup!\n");
-+ }
-+
-+ alreadyrunning = span->flags & ZT_FLAG_RUNNING;
-+// printk(KERN_CRIT "already running %d flags %d\n", alreadyrunning, span->flags);
-+
-+ if (!alreadyrunning) {
-+ span->chans[2].flags &= ~ZT_FLAG_HDLC;
-+ span->chans[2].flags |= ZT_FLAG_BRIDCHAN;
-+
-+ /* setup B channel buffers (8 bytes each) */
-+ for (i=0; i<2 ; i++) {
-+ memset(qoztmp->rxbuf[span->offset][i],0x0,sizeof(qoztmp->rxbuf[span->offset][i]));
-+ span->chans[i].readchunk = qoztmp->rxbuf[span->offset][i];
-+ memset(qoztmp->txbuf[span->offset][i],0x0,sizeof(qoztmp->txbuf[span->offset][i]));
-+ span->chans[i].writechunk = qoztmp->txbuf[span->offset][i];
-+ }
-+ /* setup D channel buffer */
-+ memset(qoztmp->dtxbuf[span->offset],0x0,sizeof(qoztmp->dtxbuf[span->offset]));
-+ span->chans[2].writechunk = qoztmp->dtxbuf[span->offset];
-+ qoztmp->ztdev->chans[span->offset][2].maxbytes2transmit = sizeof(qoztmp->dtxbuf[span->offset]);
-+
-+ memset(qoztmp->drxbuf[span->offset],0x0,sizeof(qoztmp->drxbuf[span->offset]));
-+ span->chans[2].readchunk = qoztmp->drxbuf[span->offset];
-+
-+ span->flags |= ZT_FLAG_RUNNING;
-+ } else {
-+// printk(KERN_CRIT "already running\n");
-+ return 0;
-+ }
-+
-+ spin_lock_irqsave(&qoztmp->lock,flags);
-+ // irqs off
-+ qoz_outb(qoztmp,qoz_R_IRQ_CTRL, 0);
-+
-+ if (qoztmp->type == 0xb552) {
-+ offset = 24;
-+ } else {
-+ offset = 28;
-+ }
-+
-+ /* setup D-FIFO TX */
-+ qoz_outb(qoztmp,qoz_R_FIFO,(span->offset + offset) << 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x2);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0xD);
-+ qoz_outb(qoztmp,qoz_A_SUBCH_CFG,0x2);
-+ qoz_outb(qoztmp,qoz_A_CHANNEL,((span->offset * 4) + 2) << 1);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x1);
-+
-+ /* setup D-FIFO RX */
-+ qoz_outb(qoztmp,qoz_R_FIFO,((span->offset + offset) << 1) | 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x2);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0xD);
-+ qoz_outb(qoztmp,qoz_A_SUBCH_CFG,0x2);
-+ qoz_outb(qoztmp,qoz_A_CHANNEL,(((span->offset * 4) + 2) << 1) | 1);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x1);
-+
-+ /* setup B1-FIFO TX */
-+ qoz_outb(qoztmp,qoz_R_FIFO,(span->offset * 2) << 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x2);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x2);
-+ qoz_outb(qoztmp,qoz_A_CHANNEL,(span->offset * 4) << 1);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x1);
-+
-+ /* setup B1-FIFO RX */
-+ qoz_outb(qoztmp,qoz_R_FIFO,((span->offset * 2) << 1) | 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x2);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x2);
-+ qoz_outb(qoztmp,qoz_A_CHANNEL,((span->offset * 4) << 1) | 1);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x1);
-+
-+ /* setup B2-FIFO TX */
-+ qoz_outb(qoztmp,qoz_R_FIFO,((span->offset * 2) + 1) << 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x2);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x2);
-+ qoz_outb(qoztmp,qoz_A_CHANNEL,((span->offset * 4) + 1) << 1);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x1);
-+
-+ /* setup B2-FIFO RX */
-+ qoz_outb(qoztmp,qoz_R_FIFO,(((span->offset * 2) + 1) << 1) | 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x2);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x2);
-+ qoz_outb(qoztmp,qoz_A_CHANNEL,((((span->offset) * 4) + 1) << 1) | 1);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x1);
-+
-+ if (debug)
-+ printk(KERN_INFO "qozap: starting card %d span %d/%d.\n",qoztmp->cardno,span->spanno,span->offset);
-+
-+ /* activate layer 1 */
-+ qoz_outb(qoztmp,qoz_R_ST_SEL,span->offset);
-+ if (qoztmp->st[span->offset].nt_mode == 1) {
-+ // NT mode
-+ qoz_outb(qoztmp,qoz_A_ST_CTRL0,0x7);
-+ qoz_outb(qoztmp,qoz_A_ST_CTRL1,0x0);
-+ qoz_outb(qoztmp,qoz_A_ST_CTRL2,0x3);
-+ qoz_outb(qoztmp,qoz_A_ST_CLK_DLY,0x60 | CLKDEL_NT);
-+ } else {
-+ // TE mode
-+ qoz_outb(qoztmp,qoz_A_ST_CTRL0,0x3);
-+ qoz_outb(qoztmp,qoz_A_ST_CTRL1,0x0);
-+ qoz_outb(qoztmp,qoz_A_ST_CTRL2,0x3);
-+ if (qoztmp->type == 0xb550) {
-+ qoz_outb(qoztmp,qoz_A_ST_CLK_DLY,CLKDEL_TE);
-+ } else {
-+ qoz_outb(qoztmp,qoz_A_ST_CLK_DLY,CLKDEL_TE + 1);
-+ }
-+ }
-+ qoztmp->st[span->offset].t3 = 0;
-+ qoztmp->st[span->offset].t4 = -1;
-+
-+ qoz_outb(qoztmp,qoz_R_ST_SEL,span->offset);
-+ if (qoztmp->st[span->offset].nt_mode == 1) {
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x80);
-+ } else {
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x0);
-+ }
-+ /* enable irqs */
-+ qoz_outb(qoztmp,qoz_R_IRQ_CTRL, 8 | 1);
-+ spin_unlock_irqrestore(&qoztmp->lock,flags);
-+
-+ qoz_outb(qoztmp,qoz_R_ST_SEL,span->offset);
-+ if (qoztmp->st[span->offset].nt_mode == 1) {
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x60 | 0x80); // ACT, G2->G3 EN
-+ } else {
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x60); // start Activation
-+ }
-+
-+ return 0;
-+}
-+
-+static int ztqoz_shutdown(struct zt_span *span) {
-+ struct zt_qoz *ztqoz = span->pvt;
-+ struct qoz_card *qoztmp = ztqoz->card;
-+ int alreadyrunning;
-+ int offset = 0;
-+
-+ if (qoztmp == NULL) {
-+ printk(KERN_CRIT "qozap: qoztmp == NULL!\n");
-+ return 0;
-+
-+ }
-+
-+ alreadyrunning = span->flags & ZT_FLAG_RUNNING;
-+
-+ if (!alreadyrunning) {
-+ return 0;
-+ }
-+
-+// printk(KERN_CRIT "qozap: stopping card %d port %d.\n",qoztmp->cardno, span->offset + 1);
-+
-+ // turn off irqs for all fifos
-+ if (qoztmp->type == 0xb552) {
-+ offset = 24;
-+ } else {
-+ offset = 28;
-+ }
-+
-+ /* disable D TX fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,(span->offset + offset) << 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x1);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x0);
-+
-+ /* disable D RX fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,((span->offset + offset) << 1) | 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x1);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x0);
-+
-+ /* disable B1 TX fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,(span->offset * 2) << 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x2);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x0);
-+
-+ /* disable B1 RX fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,((span->offset * 2) << 1) | 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x2);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x0);
-+
-+ /* disable B2 TX fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,(((span->offset) * 2) + 1) << 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x2);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x0);
-+
-+ /* disable B2 RX fifo */
-+ qoz_outb(qoztmp,qoz_R_FIFO,((((span->offset) * 2) + 1) << 1) | 1);
-+ qoz_waitbusy(qoztmp);
-+ qoz_outb(qoztmp,qoz_A_CON_HDLC,0x2);
-+ qoz_outb(qoztmp,qoz_A_IRQ_MSK,0x0);
-+
-+ span->flags &= ~ZT_FLAG_RUNNING;
-+
-+ /* Deactivate Layer 1 */
-+ qoz_outb(qoztmp,qoz_R_ST_SEL,span->offset);
-+ if (qoztmp->st[span->offset].nt_mode == 1) {
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x40);
-+ } else {
-+ qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x40);
-+ }
-+
-+
-+// printk(KERN_CRIT "qozap: card %d span %d/%d down.\n",qoztmp->cardno,span->spanno,span->offset);
-+ return 0;
-+}
-+
-+static int ztqoz_maint(struct zt_span *span, int cmd) {
-+ return 0;
-+}
-+
-+static int ztqoz_chanconfig(struct zt_chan *chan,int sigtype) {
-+// printk(KERN_INFO "chan_config sigtype=%d\n",sigtype);
-+ return 0;
-+}
-+
-+static int ztqoz_spanconfig(struct zt_span *span,struct zt_lineconfig *lc) {
-+// span->lineconfig = lc->lineconfig;
-+ return 0;
-+}
-+
-+static int ztqoz_initialize(struct zt_qoz *ztqoz) {
-+ struct qoz_card *qoztmp = ztqoz->card;
-+ int i=0,s=0;
-+
-+ for (s=0; s < ztqoz->card->stports; s++) {
-+ memset(&ztqoz->spans[s],0,sizeof(struct zt_span)); // you never can tell...
-+ sprintf(ztqoz->spans[s].name,"ztqoz/%d/%d",qoz_dev_count + 1,s + 1);
-+ if (ztqoz->card->stports == 8) {
-+ if (qoztmp->st[s].nt_mode == 1){
-+ sprintf(ztqoz->spans[s].desc,"octoBRI PCI ISDN Card %d Span %d [NT]",qoztmp->cardno,s + 1);
-+ } else {
-+ sprintf(ztqoz->spans[s].desc,"octoBRI PCI ISDN Card %d Span %d [TE]",qoztmp->cardno,s + 1);
-+ }
-+ } else {
-+ if (ztqoz->card->cardID < 0xff) {
-+ if (qoztmp->st[s].nt_mode == 1){
-+ sprintf(ztqoz->spans[s].desc,"quadBRI PCI ISDN Card %d Span %d [NT] (cardID %d)",qoztmp->cardno,s + 1,ztqoz->card->cardID);
-+ } else {
-+ sprintf(ztqoz->spans[s].desc,"quadBRI PCI ISDN Card %d Span %d [TE] (cardID %d)",qoztmp->cardno,s + 1,ztqoz->card->cardID);
-+ }
-+ } else {
-+ if (qoztmp->st[s].nt_mode == 1){
-+ sprintf(ztqoz->spans[s].desc,"quadBRI PCI ISDN Card %d Span %d [NT]",qoztmp->cardno,s + 1);
-+ } else {
-+ sprintf(ztqoz->spans[s].desc,"quadBRI PCI ISDN Card %d Span %d [TE]",qoztmp->cardno,s + 1);
-+ }
-+ }
-+ }
-+
-+ ztqoz->spans[s].spanconfig = ztqoz_spanconfig;
-+ ztqoz->spans[s].chanconfig = ztqoz_chanconfig;
-+ ztqoz->spans[s].startup = ztqoz_startup;
-+ ztqoz->spans[s].shutdown = ztqoz_shutdown;
-+ ztqoz->spans[s].maint = ztqoz_maint;
-+ ztqoz->spans[s].rbsbits = ztqoz_rbsbits;
-+ ztqoz->spans[s].open = ztqoz_open;
-+ ztqoz->spans[s].close = ztqoz_close;
-+ ztqoz->spans[s].ioctl = ztqoz_ioctl;
-+
-+ ztqoz->spans[s].chans = ztqoz->chans[s];
-+ ztqoz->spans[s].channels = 3;
-+ ztqoz->spans[s].deflaw = ZT_LAW_ALAW;
-+ ztqoz->spans[s].linecompat = ZT_CONFIG_AMI | ZT_CONFIG_CCS; // <--- this is really BS
-+ init_waitqueue_head(&ztqoz->spans[s].maintq);
-+ ztqoz->spans[s].pvt = ztqoz;
-+ ztqoz->spans[s].offset = s;
-+
-+ for (i=0; i < ztqoz->spans[s].channels; i++) {
-+ memset(&(ztqoz->chans[s][i]),0x0,sizeof(struct zt_chan));
-+ sprintf(ztqoz->chans[s][i].name,"ztqoz%d/%d/%d",qoz_dev_count + 1,s + 1,i + 1);
-+ ztqoz->chans[s][i].pvt = ztqoz;
-+ ztqoz->chans[s][i].sigcap = ZT_SIG_EM | ZT_SIG_CLEAR | ZT_SIG_FXSLS | ZT_SIG_FXSGS | ZT_SIG_FXSKS | ZT_SIG_FXOLS | ZT_SIG_FXOGS | ZT_SIG_FXOKS | ZT_SIG_CAS | ZT_SIG_SF;
-+ ztqoz->chans[s][i].chanpos = i + 1;
-+ }
-+
-+ if (zt_register(&ztqoz->spans[s],0)) {
-+ printk(KERN_INFO "qozap: unable to register zaptel span %d!\n",s+1);
-+ return -1;
-+ }
-+// printk(KERN_INFO "qozap: registered zaptel span %d.\n",s+1);
-+ }
-+
-+ return 0;
-+}
-+
-+int qoz_findCards(unsigned int pcidid) {
-+ struct pci_dev *tmp;
-+ struct qoz_card *qoztmp = NULL;
-+ struct zt_qoz *ztqoz = NULL;
-+ int i=0;
-+ unsigned char dips=0;
-+ int cid=0;
-+ int modes=0;
-+ tmp = pci_find_device(PCI_VENDOR_ID_CCD,pcidid,multi_qoz);
-+ while (tmp != NULL) {
-+ multi_qoz = tmp; // skip this next time.
-+
-+ if (pci_enable_device(tmp)) {
-+ multi_qoz = NULL;
-+ return -1;
-+ }
-+
-+ qoztmp = kmalloc(sizeof(struct qoz_card),GFP_KERNEL);
-+ if (!qoztmp) {
-+ printk(KERN_WARNING "qozap: unable to kmalloc!\n");
-+ pci_disable_device(tmp);
-+ multi_qoz = NULL;
-+ return -ENOMEM;
-+ }
-+ memset(qoztmp, 0x0, sizeof(struct qoz_card));
-+
-+ spin_lock_init(&qoztmp->lock);
-+ qoztmp->pcidev = tmp;
-+ qoztmp->pcibus = tmp->bus->number;
-+ qoztmp->pcidevfn = tmp->devfn;
-+
-+ if (!tmp->irq) {
-+ printk(KERN_WARNING "qozap: no irq!\n");
-+ } else {
-+ qoztmp->irq = tmp->irq;
-+ }
-+
-+ qoztmp->pci_io = (char *) tmp->resource[1].start;
-+ if (!qoztmp->pci_io) {
-+ printk(KERN_WARNING "qozap: no iomem!\n");
-+ pci_disable_device(tmp);
-+ multi_qoz = NULL;
-+ return -EIO;
-+ }
-+
-+ qoztmp->ioport = tmp->resource[0].start;
-+ if (!qoztmp->ioport) {
-+ printk(KERN_WARNING "qozap: no ioport!\n");
-+ pci_disable_device(tmp);
-+ multi_qoz = NULL;
-+ return -EIO;
-+ }
-+ if (!request_region(qoztmp->ioport, 7, "qozap")) {
-+ printk(KERN_WARNING "qozap: couldnt request io range!\n");
-+ pci_disable_device(tmp);
-+ multi_qoz = NULL;
-+ return -EIO;
-+ }
-+
-+ if (request_irq(qoztmp->irq, qoz_interrupt, SA_INTERRUPT | SA_SHIRQ, "qozap", qoztmp)) {
-+ printk(KERN_WARNING "qozap: unable to register irq\n");
-+ kfree(qoztmp);
-+ pci_disable_device(tmp);
-+ multi_qoz = NULL;
-+ return -EIO;
-+ }
-+
-+ qoztmp->pci_io = ioremap((ulong) qoztmp->pci_io, 256);
-+
-+ pci_write_config_word(qoztmp->pcidev, PCI_COMMAND, PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
-+
-+ // disable ints
-+ qoz_outb(qoztmp,qoz_R_IRQ_CTRL, 0);
-+
-+ ztqoz = kmalloc(sizeof(struct zt_qoz),GFP_KERNEL);
-+ if (!ztqoz) {
-+ printk(KERN_INFO "qozap: unable to kmalloc!\n");
-+ qoz_shutdownCard(qoztmp);
-+ kfree(qoztmp);
-+ multi_qoz = NULL;
-+ return -ENOMEM;
-+ }
-+ memset(ztqoz, 0x0, sizeof(struct zt_qoz));
-+
-+ if (pcidid == PCI_DEVICE_ID_CCD_M) {
-+ qoztmp->stports = 8;
-+ } else {
-+ qoztmp->stports = 4;
-+ }
-+
-+
-+ if ((tmp->subsystem_device==0xb520) && (pcidid == PCI_DEVICE_ID_CCD_M4)) {
-+ // printk(KERN_INFO "MODES = %#x.\n",modes);
-+ qoz_outb(qoztmp,qoz_R_GPIO_SEL,0x80 | 0x40);
-+ dips = (qoz_inb(qoztmp,qoz_R_GPIO_IN1) >> 5);
-+ cid = 7;
-+ for (i=0;i<3;i++) {
-+ if ((dips & (1 << i)) != 0) {
-+ cid -= (1 << (2-i));
-+ }
-+ }
-+ // printk(KERN_INFO "DIPS = %#x CID= %#x\n",dips,cid);
-+ } else if ((tmp->subsystem_device==0xb550) && (pcidid == PCI_DEVICE_ID_CCD_M4)) {
-+ // printk(KERN_INFO "MODES = %#x.\n",modes);
-+ dips = ~(qoz_inb(qoztmp,qoz_R_GPI_IN3) & 7);
-+ cid = 0;
-+ for (i=0;i<3;i++) {
-+ if ((dips & (1 << i)) != 0) {
-+ cid += (1 << i);
-+ }
-+ }
-+ printk(KERN_INFO "DIPS = %#x CID= %#x\n",dips,cid);
-+ } else {
-+ cid = 0xff;
-+ }
-+
-+ if (ports == -1) {
-+ if ((tmp->subsystem_device==0xb520) && (pcidid == PCI_DEVICE_ID_CCD_M4)) {
-+ modes = qoz_inb(qoztmp,qoz_R_GPI_IN3) >> 4;
-+ } else if ((tmp->subsystem_device==0xb550) && (pcidid == PCI_DEVICE_ID_CCD_M4)) {
-+ qoz_outb(qoztmp,qoz_R_GPIO_SEL,0xff);
-+ qoz_outb(qoztmp,qoz_R_GPIO_EN0,0x00);
-+ printk(KERN_CRIT "gpio_in0 %#x \n", qoz_inb(qoztmp,qoz_R_GPIO_IN0));
-+ printk(KERN_CRIT "gpio_in1 %#x \n", qoz_inb(qoztmp,qoz_R_GPIO_IN1));
-+ printk(KERN_CRIT "gpi_in1 %#x \n", qoz_inb(qoztmp,qoz_R_GPI_IN1));
-+ printk(KERN_CRIT "gpi_in2 %#x \n", qoz_inb(qoztmp,qoz_R_GPI_IN2));
-+ printk(KERN_CRIT "gpi_in3 %#x \n", qoz_inb(qoztmp,qoz_R_GPI_IN3));
-+ modes = qoz_inb(qoztmp,qoz_R_GPI_IN3) >> 4;
-+ } else {
-+ modes = 0; // assume TE mode
-+ }
-+ } else {
-+ modes = ports >> totalBRIs;
-+ }
-+
-+ if (pcidid == PCI_DEVICE_ID_CCD_M4) {
-+ switch (tmp->subsystem_device) {
-+ case 0x08b4:
-+ if (ports == -1) ports = 0; /* assume TE mode if no ports param */
-+ printk(KERN_INFO
-+ "qozap: CologneChip HFC-4S evaluation board configured at io port %#x IRQ %d HZ %d\n",
-+ (u_int) qoztmp->ioport,
-+ qoztmp->irq, HZ);
-+ break;
-+ case 0xb520:
-+ printk(KERN_INFO
-+ "qozap: Junghanns.NET quadBRI card configured at io port %#x IRQ %d HZ %d CardID %d\n",
-+ (u_int) qoztmp->ioport,
-+ qoztmp->irq, HZ, cid);
-+ break;
-+ case 0xb550:
-+ printk(KERN_INFO
-+ "qozap: Junghanns.NET quadBRI (Version 2.0) card configured at io port %#x IRQ %d HZ %d CardID %d\n",
-+ (u_int) qoztmp->ioport,
-+ qoztmp->irq, HZ, cid);
-+ break;
-+ }
-+ totalBRIs += 4;
-+ } else {
-+ switch (tmp->subsystem_device) {
-+ case 0xb552:
-+ printk(KERN_INFO
-+ "qozap: Junghanns.NET octoBRI card configured at io port %#x IRQ %d HZ %d\n",
-+ (u_int) qoztmp->ioport,
-+ qoztmp->irq, HZ);
-+ break;
-+ default:
-+ if (qoztmp->pcidev != NULL) {
-+ pci_disable_device(qoztmp->pcidev);
-+ }
-+ pci_write_config_word(qoztmp->pcidev, PCI_COMMAND, 0);
-+ free_irq(qoztmp->irq,qoztmp);
-+ kfree(qoztmp);
-+ qoztmp = NULL;
-+ tmp = pci_find_device(PCI_VENDOR_ID_CCD,pcidid,multi_qoz);
-+ continue;
-+ break;
-+ }
-+ totalBRIs += 8;
-+ }
-+
-+ qoztmp->cardID = cid;
-+ qoztmp->type = tmp->subsystem_device;
-+
-+ printk(KERN_INFO "qozap: S/T ports: %d [",qoztmp->stports);
-+ for (i=0;i<qoztmp->stports;i++) {
-+ if ((modes & (1 << i)) != 0) {
-+ qoztmp->st[i].nt_mode = 1;
-+ printk(" NT");
-+ } else {
-+ qoztmp->st[i].nt_mode = 0;
-+ printk(" TE");
-+ }
-+ }
-+ printk(" ]\n");
-+
-+ ztqoz->card = qoztmp;
-+ qoztmp->ztdev = ztqoz;
-+
-+ qoz_registerCard(qoztmp);
-+ tmp = pci_find_device(PCI_VENDOR_ID_CCD,pcidid,multi_qoz);
-+ }
-+ return 0;
-+}
-+
-+
-+int qoz_sortCards(void) {
-+ int changed=0,tmpcardno;
-+ struct qoz_card *tmpcard,*tmpcard2;
-+ spin_lock(®isterlock);
-+ do {
-+ changed = 0;
-+ tmpcard = qoz_dev_list;
-+ while (tmpcard != NULL) {
-+ if (tmpcard->prev) {
-+ if (tmpcard->prev->cardID > tmpcard->cardID) {
-+ tmpcardno = tmpcard->prev->cardno;
-+ tmpcard->prev->cardno = tmpcard->cardno;
-+ tmpcard->cardno = tmpcardno;
-+
-+ tmpcard2 = tmpcard->prev;
-+ if (tmpcard2->prev) {
-+ tmpcard2->prev->next = tmpcard;
-+ } else {
-+ qoz_dev_list = tmpcard;
-+ }
-+ if (tmpcard->next) {
-+ tmpcard->next->prev = tmpcard2;
-+ }
-+ tmpcard2->next = tmpcard->next;
-+ tmpcard->prev = tmpcard2->prev;
-+ tmpcard->next = tmpcard2;
-+ tmpcard2->prev = tmpcard;
-+ changed = 1;
-+ tmpcard = tmpcard2;
-+ }
-+ }
-+ tmpcard = tmpcard->next;
-+ }
-+ } while (changed == 1);
-+ spin_unlock(®isterlock);
-+ return 0;
-+}
-+
-+int qoz_zapCards(void) {
-+ struct qoz_card *tmpcard;
-+ tmpcard = qoz_dev_list;
-+ while (tmpcard != NULL) {
-+ ztqoz_initialize(tmpcard->ztdev);
-+ qoz_resetCard(tmpcard);
-+ tmpcard = tmpcard->next;
-+ }
-+ return 0;
-+}
-+
-+
-+int init_module(void) {
-+ multi_qoz = NULL;
-+ qoz_findCards(PCI_DEVICE_ID_CCD_M4);
-+ qoz_findCards(PCI_DEVICE_ID_CCD_M);
-+ qoz_sortCards();
-+ qoz_zapCards();
-+ if (qoz_dev_count == 0) {
-+ printk(KERN_INFO "qozap: no multiBRI cards found.\n");
-+ } else {
-+ printk(KERN_INFO "qozap: %d multiBRI card(s) in this box, %d BRI ports total, bloop %d.\n",qoz_dev_count, totalBRIs, bloop);
-+ }
-+ return 0;
-+}
-+
-+void cleanup_module(void) {
-+ struct qoz_card *tmpcard,*tmplist;
-+ int i=0;
-+ tmplist = qoz_dev_list;
-+ while (tmplist != NULL) {
-+ qoz_undoWD(tmplist);
-+ qoz_shutdownCard(tmplist);
-+ tmplist = tmplist->next;
-+ }
-+ tmplist = qoz_dev_list;
-+ spin_lock(®isterlock);
-+ while (tmplist != NULL) {
-+ tmpcard = tmplist->next;
-+ kfree(tmplist);
-+ i++;
-+ tmplist = tmpcard;
-+ }
-+ spin_unlock(®isterlock);
-+ printk(KERN_INFO "qozap: shutdown %d multiBRI cards.\n", i);
-+}
-+#endif
-+
-+MODULE_PARM(doubleclock,"i");
-+MODULE_PARM(ports,"i");
-+MODULE_PARM(bloop,"i");
-+MODULE_PARM(debug,"i");
-+MODULE_DESCRIPTION("quad/octo BRI zaptel driver");
-+MODULE_AUTHOR("Klaus-Peter Junghanns <kpj at junghanns.net>");
-+#ifdef MODULE_LICENSE
-+MODULE_LICENSE("GPL");
-+#endif
-diff -urNad zaptel-1.2.2/qozap/qozap.h /tmp/dpep.xmeNb1/zaptel-1.2.2/qozap/qozap.h
---- zaptel-1.2.2/qozap/qozap.h 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.xmeNb1/zaptel-1.2.2/qozap/qozap.h 2005-06-13 11:56:43.000000000 +0300
-@@ -0,0 +1,237 @@
-+#define qoz_SPANS 8
-+#define qoz_FIFO_SIZE 128
-+#define qoz_DFIFO_SIZE4 2048
-+#define qoz_DFIFO_SIZE8 1024
-+
-+typedef struct qoz_span {
-+ unsigned char nt_mode;
-+ unsigned char btx;
-+ unsigned char bswapped;
-+ unsigned char drx;
-+ int t3;
-+ int t4;
-+ unsigned char layer1state;
-+} qoz_span;
-+
-+typedef struct qoz_regs {
-+ unsigned char fifo_en;
-+ unsigned char ctmt;
-+ unsigned char int_m1;
-+ unsigned char int_m2;
-+ unsigned char sctrl;
-+ unsigned char sctrl_e;
-+ unsigned char sctrl_r;
-+ unsigned char connect;
-+ unsigned char trm;
-+ unsigned char mst_mode;
-+} qoz_regs;
-+
-+typedef struct qoz_card {
-+ spinlock_t lock;
-+ int cardID;
-+ unsigned char leds[8];
-+ unsigned char cardno;
-+ unsigned int irq;
-+ unsigned int iomem;
-+ unsigned char *pci_io;
-+ unsigned long ioport;
-+ struct qoz_span st[qoz_SPANS];
-+ unsigned int pcibus;
-+ unsigned int pcidevfn;
-+ struct pci_dev *pcidev;
-+ struct zt_qoz *ztdev;
-+ unsigned char rxbuf[qoz_SPANS][2][ZT_CHUNKSIZE];
-+ unsigned char txbuf[qoz_SPANS][2][ZT_CHUNKSIZE];
-+ unsigned char drxbuf[qoz_SPANS][qoz_DFIFO_SIZE4];
-+ unsigned char dtxbuf[qoz_SPANS][qoz_DFIFO_SIZE4];
-+ unsigned char stports;
-+ unsigned int ticks;
-+ unsigned int clicks;
-+ unsigned int type;
-+ unsigned int wdp;
-+ struct qoz_card *next;
-+ struct qoz_card *prev;
-+} qoz_card;
-+
-+
-+typedef struct zt_qoz {
-+ unsigned int usecount;
-+ struct zt_span spans[qoz_SPANS];
-+ struct zt_chan chans[qoz_SPANS][3];
-+ struct qoz_card *card;
-+} zt_qoz;
-+
-+#define qoz_outb_io(a,b,c) \
-+ outw((b), ((a)->ioport+4)); \
-+ outb((c), ((a)->ioport));
-+
-+#define qoz_inb_io(a,b) ({ outw((b), (a)->ioport+4); inb((a)->ioport); })
-+
-+#define qoz_outw_io(a,b,c) \
-+ outw((b), ((a)->ioport+4)); \
-+ outw((c), ((a)->ioport));
-+
-+#define qoz_inw_io(a,b) ({ outw((b), (a)->ioport+4); inw((a)->ioport); })
-+
-+#define qoz_outdw_io(a,b,c) \
-+ outw((b), ((a)->ioport+4)); \
-+ outl((c), ((a)->ioport));
-+
-+#define qoz_indw_io(a,b) ({ outw((b), (a)->ioport+4); inl((a)->ioport); })
-+
-+#define qoz_outb(a,b,c) (writeb((c),(a)->pci_io+(b)))
-+#define qoz_inb(a,b) (readb((a)->pci_io+(b)))
-+
-+#define qoz_outw(a,b,c) (writew((c),(a)->pci_io+(b)))
-+#define qoz_inw(a,b) (readw((a)->pci_io+(b)))
-+
-+#define qoz_outdw(a,b,c) (writel((c),(a)->pci_io+(b)))
-+#define qoz_indw(a,b) (readl((a)->pci_io+(b)))
-+
-+
-+/* Write only registers */
-+#define qoz_A_CH_MSK 0xF4
-+#define qoz_A_CHANNEL 0xFC
-+#define qoz_A_CON_HDLC 0xFA
-+#define qoz_A_CONF 0xD1
-+#define qoz_A_FIFO_SEQ 0xFD
-+#define qoz_R_INC_RES_FIFO 0x0E
-+#define qoz_A_IRQ_MSK 0xFF
-+#define qoz_A_SL_CFG 0xD0
-+#define qoz_A_ST_B1_TX 0x3C
-+#define qoz_A_ST_B2_TX 0x3D
-+#define qoz_A_ST_CLK_DLY 0x37
-+#define qoz_A_ST_CTRL0 0x31
-+#define qoz_A_ST_CTRL1 0x32
-+#define qoz_A_ST_CTRL2 0x33
-+#define qoz_A_ST_D_TX 0x3E
-+#define qoz_A_ST_SQ_WR 0x34
-+#define qoz_A_ST_WR_STA 0x30
-+#define qoz_A_SUBCH_CFG 0xFB
-+#define qoz_R_BERT_WD_MD 0x1B
-+#define qoz_R_BRG_CTRL 0x45
-+#define qoz_R_BRG_MD 0x47
-+#define qoz_R_BRG_PCM_CFG 0x02
-+#define qoz_R_BRG_TIM_SEL01 0x4C
-+#define qoz_R_BRG_TIM_SEL23 0x4D
-+#define qoz_R_BRG_TIM_SEL45 0x4E
-+#define qoz_R_BRG_TIM_SEL67 0x4F
-+#define qoz_R_BRG_TIM0 0x48
-+#define qoz_R_BRG_TIM1 0x49
-+#define qoz_R_BRG_TIM2 0x4A
-+#define qoz_R_BRG_TIM3 0x4B
-+#define qoz_R_CIRM 0x00
-+#define qoz_R_CONF_EN 0x18
-+#define qoz_R_CTRL 0x01
-+#define qoz_R_DTMF0 0x1C
-+#define qoz_R_DTMF1 0x1D
-+#define qoz_R_FIFO_MD 0x0D
-+#define qoz_R_FIFO 0x0F
-+#define qoz_R_FIRST_FIFO 0x0B
-+#define qoz_R_FSM_IDX 0x0F
-+#define qoz_R_GPIO_EN0 0x42
-+#define qoz_R_GPIO_EN1 0x43
-+#define qoz_R_GPIO_OUT0 0x40
-+#define qoz_R_GPIO_OUT1 0x41
-+#define qoz_R_GPIO_SEL 0x44
-+#define qoz_R_IRQ_CTRL 0x13
-+#define qoz_R_IRQMSK_MISC 0x11
-+#define qoz_R_PCM_MD0 0x14
-+#define qoz_R_PCM_MD1 0x15
-+#define qoz_R_PCM_MD2 0x15
-+#define qoz_R_PWM_MD 0x46
-+#define qoz_R_PWM0 0x38
-+#define qoz_R_PWM1 0x39
-+#define qoz_R_RAM_ADDR0 0x08
-+#define qoz_R_RAM_ADDR1 0x09
-+#define qoz_R_RAM_ADDR2 0x0A
-+#define qoz_R_RAM_MISC 0x0C
-+#define qoz_R_SCI_MSK 0x12
-+#define qoz_R_SH0H 0x15
-+#define qoz_R_SH0L 0x15
-+#define qoz_R_SH1H 0x15
-+#define qoz_R_SH1L 0x15
-+#define qoz_R_SL_SEL0 0x15
-+#define qoz_R_SL_SEL1 0x15
-+#define qoz_R_SL_SEL2 0x15
-+#define qoz_R_SL_SEL3 0x15
-+#define qoz_R_SL_SEL4 0x15
-+#define qoz_R_SL_SEL5 0x15
-+#define qoz_R_SL_SEL6 0x15
-+#define qoz_R_SL_SEL7 0x15
-+#define qoz_R_SLOT 0x10
-+#define qoz_R_ST_SEL 0x16
-+#define qoz_R_ST_SYNC 0x17
-+#define qoz_R_TI_WD 0x1A
-+
-+/* Read only registers */
-+#define qoz_A_F1 0x0C
-+#define qoz_A_F12 0x0C
-+#define qoz_A_F2 0x0D
-+#define qoz_A_ST_B1_RX 0x3C
-+#define qoz_A_ST_B2_TX 0x3D
-+#define qoz_A_ST_D_RX 0x3E
-+#define qoz_A_ST_E_RX 0x3F
-+#define qoz_A_ST_RD_STA 0x30
-+#define qoz_A_ST_SQ_RD 0x34
-+#define qoz_A_Z1 0x04
-+#define qoz_A_Z12 0x04
-+#define qoz_A_Z1H 0x05
-+#define qoz_A_Z1L 0x04
-+#define qoz_A_Z2 0x06
-+#define qoz_A_Z2H 0x07
-+#define qoz_A_Z2L 0x06
-+#define qoz_R_BERT_ECH 0x1B
-+#define qoz_R_BERT_ECL 0x1A
-+#define qoz_R_BERT_STA 0x17
-+#define qoz_R_CHIP_ID 0x16
-+#define qoz_R_CHIP_RV 0x1F
-+#define qoz_R_CONF_OFLOW 0x14
-+#define qoz_R_F0_CNTH 0x19
-+#define qoz_R_F0_CNTL 0x18
-+#define qoz_R_GPI_IN0 0x44
-+#define qoz_R_GPI_IN1 0x45
-+#define qoz_R_GPI_IN2 0x46
-+#define qoz_R_GPI_IN3 0x47
-+#define qoz_R_GPIO_IN0 0x40
-+#define qoz_R_GPIO_IN1 0x41
-+#define qoz_R_INT_DATA 0x88
-+#define qoz_R_IRQ_FIFO_BL0 0xC8
-+#define qoz_R_IRQ_FIFO_BL1 0xC9
-+#define qoz_R_IRQ_FIFO_BL2 0xCA
-+#define qoz_R_IRQ_FIFO_BL3 0xCB
-+#define qoz_R_IRQ_FIFO_BL4 0xCC
-+#define qoz_R_IRQ_FIFO_BL5 0xCD
-+#define qoz_R_IRQ_FIFO_BL6 0xCE
-+#define qoz_R_IRQ_FIFO_BL7 0xCF
-+#define qoz_R_IRQ_MISC 0x11
-+#define qoz_R_IRQ_OVIEW 0x10
-+#define qoz_R_RAM_USE 0x15
-+#define qoz_R_SCI 0x12
-+#define qoz_R_STATUS 0x1C
-+
-+/* Read/Write registers */
-+#define qoz_A_FIFO_DATA0_NOINC 0x84
-+#define qoz_A_FIFO_DATA0 0x80
-+#define qoz_A_FIFO_DATA1_NOINC 0x84
-+#define qoz_A_FIFO_DATA1 0x80
-+#define qoz_A_FIFO_DATA2_NOINC 0x84
-+#define qoz_A_FIFO_DATA2 0x80
-+#define qoz_R_RAM_DATA 0xC0
-+
-+#define PCI_DEVICE_ID_CCD_M 0x16b8
-+#define PCI_DEVICE_ID_CCD_M4 0x08b4
-+#define CLKDEL_TE 0xe /* CLKDEL in TE mode */
-+#define CLKDEL_NT 0xc /* CLKDEL in NT mode */
-+
-+#define HFC8S_CHIP_ID 0x80
-+#define HFC4S_CHIP_ID 0xC0
-+
-+#define qoz_WD_P0 0x000000
-+#define qoz_WD_P1 0x808080
-+#define qoz_WD_P2 0x404040
-+
-+#define qoz_T3 3
-+#define qoz_T4 1
-+
-+
-diff -urNad zaptel-1.2.2/qozap/TODO /tmp/dpep.xmeNb1/zaptel-1.2.2/qozap/TODO
---- zaptel-1.2.2/qozap/TODO 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.xmeNb1/zaptel-1.2.2/qozap/TODO 2005-06-13 10:03:36.000000000 +0300
-@@ -0,0 +1,9 @@
-+- native-native bridging
-+- onchip dtmf
-+- E channel support for full debug
-+
-+
-+t3 (5ms max)
-+
-+t4 (500ms) layer 1 down/up
-+
-diff -urNad zaptel-1.2.2/qozap/zapata.conf /tmp/dpep.xmeNb1/zaptel-1.2.2/qozap/zapata.conf
---- zaptel-1.2.2/qozap/zapata.conf 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.xmeNb1/zaptel-1.2.2/qozap/zapata.conf 2005-06-13 10:03:36.000000000 +0300
-@@ -0,0 +1,49 @@
-+;
-+; Zapata telephony interface
-+;
-+; Configuration file
-+
-+[channels]
-+;
-+; Default language
-+;
-+;language=en
-+;
-+; Default context
-+;
-+;
-+switchtype = euroisdn
-+
-+; p2mp TE mode (for connecting ISDN lines in point-to-multipoint mode)
-+signalling = bri_cpe_ptmp
-+; p2p TE mode (for connecting ISDN lines in point-to-point mode)
-+;signalling = bri_cpe
-+; p2mp NT mode (for connecting ISDN phones in point-to-multipoint mode)
-+;signalling = bri_net_ptmp
-+; p2p NT mode (for connecting an ISDN pbx in point-to-point mode)
-+;signalling = bri_net
-+
-+pridialplan = local
-+prilocaldialplan = local
-+nationalprefix = 0
-+internationalprefix = 00
-+
-+echocancel = yes
-+
-+context=demo
-+group = 1
-+; S/T port 1
-+channel => 1-2
-+
-+group = 2
-+; S/T port 2
-+channel => 4-5
-+
-+group = 3
-+; S/T port 3
-+channel => 7-8
-+
-+group = 4
-+; S/T port 4
-+channel => 10-11
-+
-diff -urNad zaptel-1.2.2/qozap/zapata.conf.octoBRI /tmp/dpep.xmeNb1/zaptel-1.2.2/qozap/zapata.conf.octoBRI
---- zaptel-1.2.2/qozap/zapata.conf.octoBRI 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.xmeNb1/zaptel-1.2.2/qozap/zapata.conf.octoBRI 2005-06-13 10:03:36.000000000 +0300
-@@ -0,0 +1,65 @@
-+;
-+; Zapata telephony interface
-+;
-+; Configuration file
-+
-+[channels]
-+;
-+; Default language
-+;
-+;language=en
-+;
-+; Default context
-+;
-+;
-+switchtype = euroisdn
-+
-+; p2mp TE mode (for connecting ISDN lines in point-to-multipoint mode)
-+signalling = bri_cpe_ptmp
-+; p2p TE mode (for connecting ISDN lines in point-to-point mode)
-+;signalling = bri_cpe
-+; p2mp NT mode (for connecting ISDN phones in point-to-multipoint mode)
-+;signalling = bri_net_ptmp
-+; p2p NT mode (for connecting an ISDN pbx in point-to-point mode)
-+;signalling = bri_net
-+
-+pridialplan = local
-+prilocaldialplan = local
-+nationalprefix = 0
-+internationalprefix = 00
-+
-+echocancel = yes
-+
-+context=demo
-+group = 1
-+; S/T port 1
-+channel => 1-2
-+
-+group = 2
-+; S/T port 2
-+channel => 4-5
-+
-+group = 3
-+; S/T port 3
-+channel => 7-8
-+
-+group = 4
-+; S/T port 4
-+channel => 10-11
-+
-+group = 5
-+; S/T port 5
-+channel => 13-14
-+
-+group = 6
-+; S/T port 6
-+channel => 16-17
-+
-+group = 7
-+; S/T port 7
-+channel => 19-20
-+
-+group = 8
-+; S/T port 8
-+channel => 22-23
-+
-diff -urNad zaptel-1.2.2/qozap/zaptel.conf /tmp/dpep.xmeNb1/zaptel-1.2.2/qozap/zaptel.conf
---- zaptel-1.2.2/qozap/zaptel.conf 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.xmeNb1/zaptel-1.2.2/qozap/zaptel.conf 2005-11-20 16:35:32.000000000 +0200
-@@ -0,0 +1,18 @@
-+loadzone=nl
-+defaultzone=nl
-+# qozap span definitions
-+# most of the values should be bogus because we are not really zaptel
-+span=1,1,3,ccs,ami
-+span=2,2,3,ccs,ami
-+span=3,0,3,ccs,ami
-+span=4,0,3,ccs,ami
-+
-+bchan=1,2
-+dchan=3
-+bchan=4,5
-+dchan=6
-+bchan=7,8
-+dchan=9
-+bchan=10,11
-+dchan=12
-+
-diff -urNad zaptel-1.2.2/qozap/zaptel.conf.octoBRI /tmp/dpep.xmeNb1/zaptel-1.2.2/qozap/zaptel.conf.octoBRI
---- zaptel-1.2.2/qozap/zaptel.conf.octoBRI 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.xmeNb1/zaptel-1.2.2/qozap/zaptel.conf.octoBRI 2005-06-13 10:03:36.000000000 +0300
-@@ -0,0 +1,30 @@
-+loadzone=nl
-+defaultzone=nl
-+# qozap span definitions
-+# most of the values should be bogus because we are not really zaptel
-+span=1,1,3,ccs,ami
-+span=2,0,3,ccs,ami
-+span=3,0,3,ccs,ami
-+span=4,0,3,ccs,ami
-+span=5,1,3,ccs,ami
-+span=6,0,3,ccs,ami
-+span=7,0,3,ccs,ami
-+span=8,0,3,ccs,ami
-+
-+bchan=1,2
-+dchan=3
-+bchan=4,5
-+dchan=6
-+bchan=7,8
-+dchan=9
-+bchan=10,11
-+dchan=12
-+bchan=13,14
-+dchan=15
-+bchan=16,17
-+dchan=18
-+bchan=19,20
-+dchan=21
-+bchan=22,23
-+dchan=24
-+
-diff -urNad zaptel-1.2.2/zaphfc/LICENSE /tmp/dpep.xmeNb1/zaptel-1.2.2/zaphfc/LICENSE
---- zaptel-1.2.2/zaphfc/LICENSE 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.xmeNb1/zaptel-1.2.2/zaphfc/LICENSE 2003-08-19 04:24:43.000000000 +0300
-@@ -0,0 +1,341 @@
-+
-+ GNU GENERAL PUBLIC LICENSE
-+ Version 2, June 1991
-+
-+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-+ Everyone is permitted to copy and distribute verbatim copies
-+ of this license document, but changing it is not allowed.
-+
-+ Preamble
-+
-+ The licenses for most software are designed to take away your
-+freedom to share and change it. By contrast, the GNU General Public
-+License is intended to guarantee your freedom to share and change free
-+software--to make sure the software is free for all its users. This
-+General Public License applies to most of the Free Software
-+Foundation's software and to any other program whose authors commit to
-+using it. (Some other Free Software Foundation software is covered by
-+the GNU Library General Public License instead.) You can apply it to
-+your programs, too.
-+
-+ When we speak of free software, we are referring to freedom, not
-+price. Our General Public Licenses are designed to make sure that you
-+have the freedom to distribute copies of free software (and charge for
-+this service if you wish), that you receive source code or can get it
-+if you want it, that you can change the software or use pieces of it
-+in new free programs; and that you know you can do these things.
-+
-+ To protect your rights, we need to make restrictions that forbid
-+anyone to deny you these rights or to ask you to surrender the rights.
-+These restrictions translate to certain responsibilities for you if you
-+distribute copies of the software, or if you modify it.
-+
-+ For example, if you distribute copies of such a program, whether
-+gratis or for a fee, you must give the recipients all the rights that
-+you have. You must make sure that they, too, receive or can get the
-+source code. And you must show them these terms so they know their
-+rights.
-+
-+ We protect your rights with two steps: (1) copyright the software, and
-+(2) offer you this license which gives you legal permission to copy,
-+distribute and/or modify the software.
-+
-+ Also, for each author's protection and ours, we want to make certain
-+that everyone understands that there is no warranty for this free
-+software. If the software is modified by someone else and passed on, we
-+want its recipients to know that what they have is not the original, so
-+that any problems introduced by others will not reflect on the original
-+authors' reputations.
-+
-+ Finally, any free program is threatened constantly by software
-+patents. We wish to avoid the danger that redistributors of a free
-+program will individually obtain patent licenses, in effect making the
-+program proprietary. To prevent this, we have made it clear that any
-+patent must be licensed for everyone's free use or not licensed at all.
-+
-+ The precise terms and conditions for copying, distribution and
-+modification follow.
-+
-+ GNU GENERAL PUBLIC LICENSE
-+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-+
-+ 0. This License applies to any program or other work which contains
-+a notice placed by the copyright holder saying it may be distributed
-+under the terms of this General Public License. The "Program", below,
-+refers to any such program or work, and a "work based on the Program"
-+means either the Program or any derivative work under copyright law:
-+that is to say, a work containing the Program or a portion of it,
-+either verbatim or with modifications and/or translated into another
-+language. (Hereinafter, translation is included without limitation in
-+the term "modification".) Each licensee is addressed as "you".
-+
-+Activities other than copying, distribution and modification are not
-+covered by this License; they are outside its scope. The act of
-+running the Program is not restricted, and the output from the Program
-+is covered only if its contents constitute a work based on the
-+Program (independent of having been made by running the Program).
-+Whether that is true depends on what the Program does.
-+
-+ 1. You may copy and distribute verbatim copies of the Program's
-+source code as you receive it, in any medium, provided that you
-+conspicuously and appropriately publish on each copy an appropriate
-+copyright notice and disclaimer of warranty; keep intact all the
-+notices that refer to this License and to the absence of any warranty;
-+and give any other recipients of the Program a copy of this License
-+along with the Program.
-+
-+You may charge a fee for the physical act of transferring a copy, and
-+you may at your option offer warranty protection in exchange for a fee.
-+
-+ 2. You may modify your copy or copies of the Program or any portion
-+of it, thus forming a work based on the Program, and copy and
-+distribute such modifications or work under the terms of Section 1
-+above, provided that you also meet all of these conditions:
-+
-+ a) You must cause the modified files to carry prominent notices
-+ stating that you changed the files and the date of any change.
-+
-+ b) You must cause any work that you distribute or publish, that in
-+ whole or in part contains or is derived from the Program or any
-+ part thereof, to be licensed as a whole at no charge to all third
-+ parties under the terms of this License.
-+
-+ c) If the modified program normally reads commands interactively
-+ when run, you must cause it, when started running for such
-+ interactive use in the most ordinary way, to print or display an
-+ announcement including an appropriate copyright notice and a
-+ notice that there is no warranty (or else, saying that you provide
-+ a warranty) and that users may redistribute the program under
-+ these conditions, and telling the user how to view a copy of this
-+ License. (Exception: if the Program itself is interactive but
-+ does not normally print such an announcement, your work based on
-+ the Program is not required to print an announcement.)
-+
-+These requirements apply to the modified work as a whole. If
-+identifiable sections of that work are not derived from the Program,
-+and can be reasonably considered independent and separate works in
-+themselves, then this License, and its terms, do not apply to those
-+sections when you distribute them as separate works. But when you
-+distribute the same sections as part of a whole which is a work based
-+on the Program, the distribution of the whole must be on the terms of
-+this License, whose permissions for other licensees extend to the
-+entire whole, and thus to each and every part regardless of who wrote it.
-+
-+Thus, it is not the intent of this section to claim rights or contest
-+your rights to work written entirely by you; rather, the intent is to
-+exercise the right to control the distribution of derivative or
-+collective works based on the Program.
-+
-+In addition, mere aggregation of another work not based on the Program
-+with the Program (or with a work based on the Program) on a volume of
-+a storage or distribution medium does not bring the other work under
-+the scope of this License.
-+
-+ 3. You may copy and distribute the Program (or a work based on it,
-+under Section 2) in object code or executable form under the terms of
-+Sections 1 and 2 above provided that you also do one of the following:
-+
-+ a) Accompany it with the complete corresponding machine-readable
-+ source code, which must be distributed under the terms of Sections
-+ 1 and 2 above on a medium customarily used for software interchange; or,
-+
-+ b) Accompany it with a written offer, valid for at least three
-+ years, to give any third party, for a charge no more than your
-+ cost of physically performing source distribution, a complete
-+ machine-readable copy of the corresponding source code, to be
-+ distributed under the terms of Sections 1 and 2 above on a medium
-+ customarily used for software interchange; or,
-+
-+ c) Accompany it with the information you received as to the offer
-+ to distribute corresponding source code. (This alternative is
-+ allowed only for noncommercial distribution and only if you
-+ received the program in object code or executable form with such
-+ an offer, in accord with Subsection b above.)
-+
-+The source code for a work means the preferred form of the work for
-+making modifications to it. For an executable work, complete source
-+code means all the source code for all modules it contains, plus any
-+associated interface definition files, plus the scripts used to
-+control compilation and installation of the executable. However, as a
-+special exception, the source code distributed need not include
-+anything that is normally distributed (in either source or binary
-+form) with the major components (compiler, kernel, and so on) of the
-+operating system on which the executable runs, unless that component
-+itself accompanies the executable.
-+
-+If distribution of executable or object code is made by offering
-+access to copy from a designated place, then offering equivalent
-+access to copy the source code from the same place counts as
-+distribution of the source code, even though third parties are not
-+compelled to copy the source along with the object code.
-+
-+ 4. You may not copy, modify, sublicense, or distribute the Program
-+except as expressly provided under this License. Any attempt
-+otherwise to copy, modify, sublicense or distribute the Program is
-+void, and will automatically terminate your rights under this License.
-+However, parties who have received copies, or rights, from you under
-+this License will not have their licenses terminated so long as such
-+parties remain in full compliance.
-+
-+ 5. You are not required to accept this License, since you have not
-+signed it. However, nothing else grants you permission to modify or
-+distribute the Program or its derivative works. These actions are
-+prohibited by law if you do not accept this License. Therefore, by
-+modifying or distributing the Program (or any work based on the
-+Program), you indicate your acceptance of this License to do so, and
-+all its terms and conditions for copying, distributing or modifying
-+the Program or works based on it.
-+
-+ 6. Each time you redistribute the Program (or any work based on the
-+Program), the recipient automatically receives a license from the
-+original licensor to copy, distribute or modify the Program subject to
-+these terms and conditions. You may not impose any further
-+restrictions on the recipients' exercise of the rights granted herein.
-+You are not responsible for enforcing compliance by third parties to
-+this License.
-+
-+ 7. If, as a consequence of a court judgment or allegation of patent
-+infringement or for any other reason (not limited to patent issues),
-+conditions are imposed on you (whether by court order, agreement or
-+otherwise) that contradict the conditions of this License, they do not
-+excuse you from the conditions of this License. If you cannot
-+distribute so as to satisfy simultaneously your obligations under this
-+License and any other pertinent obligations, then as a consequence you
-+may not distribute the Program at all. For example, if a patent
-+license would not permit royalty-free redistribution of the Program by
-+all those who receive copies directly or indirectly through you, then
-+the only way you could satisfy both it and this License would be to
-+refrain entirely from distribution of the Program.
-+
-+If any portion of this section is held invalid or unenforceable under
-+any particular circumstance, the balance of the section is intended to
-+apply and the section as a whole is intended to apply in other
-+circumstances.
-+
-+It is not the purpose of this section to induce you to infringe any
-+patents or other property right claims or to contest validity of any
-+such claims; this section has the sole purpose of protecting the
-+integrity of the free software distribution system, which is
-+implemented by public license practices. Many people have made
-+generous contributions to the wide range of software distributed
-+through that system in reliance on consistent application of that
-+system; it is up to the author/donor to decide if he or she is willing
-+to distribute software through any other system and a licensee cannot
-+impose that choice.
-+
-+This section is intended to make thoroughly clear what is believed to
-+be a consequence of the rest of this License.
-+
-+ 8. If the distribution and/or use of the Program is restricted in
-+certain countries either by patents or by copyrighted interfaces, the
-+original copyright holder who places the Program under this License
-+may add an explicit geographical distribution limitation excluding
-+those countries, so that distribution is permitted only in or among
-+countries not thus excluded. In such case, this License incorporates
-+the limitation as if written in the body of this License.
-+
-+ 9. The Free Software Foundation may publish revised and/or new versions
-+of the General Public License from time to time. Such new versions will
-+be similar in spirit to the present version, but may differ in detail to
-+address new problems or concerns.
-+
-+Each version is given a distinguishing version number. If the Program
-+specifies a version number of this License which applies to it and "any
-+later version", you have the option of following the terms and conditions
-+either of that version or of any later version published by the Free
-+Software Foundation. If the Program does not specify a version number of
-+this License, you may choose any version ever published by the Free Software
-+Foundation.
-+
-+ 10. If you wish to incorporate parts of the Program into other free
-+programs whose distribution conditions are different, write to the author
-+to ask for permission. For software which is copyrighted by the Free
-+Software Foundation, write to the Free Software Foundation; we sometimes
-+make exceptions for this. Our decision will be guided by the two goals
-+of preserving the free status of all derivatives of our free software and
-+of promoting the sharing and reuse of software generally.
-+
-+ NO WARRANTY
-+
-+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-+REPAIR OR CORRECTION.
-+
-+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-+POSSIBILITY OF SUCH DAMAGES.
-+
-+ END OF TERMS AND CONDITIONS
-+
-+ How to Apply These Terms to Your New Programs
-+
-+ If you develop a new program, and you want it to be of the greatest
-+possible use to the public, the best way to achieve this is to make it
-+free software which everyone can redistribute and change under these terms.
-+
-+ To do so, attach the following notices to the program. It is safest
-+to attach them to the start of each source file to most effectively
-+convey the exclusion of warranty; and each file should have at least
-+the "copyright" line and a pointer to where the full notice is found.
-+
-+ <one line to give the program's name and a brief idea of what it does.>
-+ Copyright (C) 19yy <name of author>
-+
-+ This program is free software; you can redistribute it and/or modify
-+ it under the terms of the GNU General Public License as published by
-+ the Free Software Foundation; either version 2 of the License, or
-+ (at your option) any later version.
-+
-+ This program is distributed in the hope that it will be useful,
-+ but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ GNU General Public License for more details.
-+
-+ You should have received a copy of the GNU General Public License
-+ along with this program; if not, write to the Free Software
-+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-+
-+
-+Also add information on how to contact you by electronic and paper mail.
-+
-+If the program is interactive, make it output a short notice like this
-+when it starts in an interactive mode:
-+
-+ Gnomovision version 69, Copyright (C) 19yy name of author
-+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-+ This is free software, and you are welcome to redistribute it
-+ under certain conditions; type `show c' for details.
-+
-+The hypothetical commands `show w' and `show c' should show the appropriate
-+parts of the General Public License. Of course, the commands you use may
-+be called something other than `show w' and `show c'; they could even be
-+mouse-clicks or menu items--whatever suits your program.
-+
-+You should also get your employer (if you work as a programmer) or your
-+school, if any, to sign a "copyright disclaimer" for the program, if
-+necessary. Here is a sample; alter the names:
-+
-+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
-+
-+ <signature of Ty Coon>, 1 April 1989
-+ Ty Coon, President of Vice
-+
-+This General Public License does not permit incorporating your program into
-+proprietary programs. If your program is a subroutine library, you may
-+consider it more useful to permit linking proprietary applications with the
-+library. If this is what you want to do, use the GNU Library General
-+Public License instead of this License.
-diff -urNad zaptel-1.2.2/zaphfc/Makefile /tmp/dpep.xmeNb1/zaptel-1.2.2/zaphfc/Makefile
---- zaptel-1.2.2/zaphfc/Makefile 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.xmeNb1/zaptel-1.2.2/zaphfc/Makefile 2006-01-18 14:02:20.000000000 +0200
-@@ -0,0 +1,118 @@
-+KINCLUDES = /usr/src/linux/include
-+BRISTUFFBASE = $(shell dirname `pwd`)
-+
-+ZAP = $(shell [ -f $(BRISTUFFBASE)/zaptel-1.2.2/zaptel.h ] && echo "-I$(BRISTUFFBASE)/zaptel-1.2.2")
-+RTAI = $(shell [ -f /usr/realtime/include/rtai.h ] && echo "-DRTAITIMING -I/usr/realtime/include")
-+
-+HOSTCC=gcc
-+
-+CFLAGS+=-I. $(ZAP) $(RTAI) -O2 -g -Wall -DBUILDING_TONEZONE
-+CFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-fsigned-char"; fi)
-+
-+KFLAGS=-D__KERNEL__ -DMODULE -DEXPORT_SYMTAB -fomit-frame-pointer -O2 -Wall -I$(KINCLUDES) $(ZAP) $(RTAI) -Wall
-+KFLAGS+=$(shell [ -f $(KINCLUDES)/linux/modversions.h ] && echo "-DMODVERSIONS -include $(KINCLUDES)/linux/modversions.h")
-+KFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-msoft-float -fsigned-char"; fi)
-+
-+
-+BUILDVER=$(shell if uname -r | grep -q ^2.6; then echo "linux26"; else echo "linux24"; fi)
-+
-+MODCONF=$(shell if [ -d $(INSTALL_PREFIX)/etc/modprobe.d ]; then echo "$(INSTALL_PREFIX)/etc/modprobe.d/zaptel"; elif [ -d $(INSTALL_PREFIX)/etc/modutils ]; then echo "$(INSTALL_PREFIX)/etc/modutils/zaptel"; elif [ -f $(INSTALL_PREFIX)/etc/modprobe.conf ]; then echo "$(INSTALL_PREFIX)/modprobe.conf"; elif [ -f $(INSTALL_PREFIX)/etc/modules.conf ]; then echo "$(INSTALL_PREFIX)/etc/modules.conf"; else echo $(INSTALL_PREFIX)/etc/conf.modules ; fi)
-+
-+OBJS=zaphfc.o
-+
-+MODULES=zaphfc
-+
-+MODULESO=$(shell for x in $(MODULES); do echo "$$x.o "; done )
-+MODULESKO=$(shell for x in $(MODULES); do echo "$$x.ko "; done )
-+
-+PWD=$(shell pwd)
-+
-+obj-m := $(MODULESO)
-+
-+all: $(BUILDVER)
-+
-+linux24: $(OBJS)
-+ sync
-+
-+
-+zaphfc.o: zaphfc.c zaphfc.h
-+ $(CC) -c zaphfc.c $(KFLAGS)
-+
-+clean:
-+ rm -f $(OBJS) *.ko *.mod.c *.mod.o .*o.cmd *~
-+ rm -rf .tmp_versions
-+
-+test: all
-+ modprobe zaptel
-+ insmod ./zaphfc.o
-+ cat /proc/interrupts
-+ sleep 1
-+ cat /proc/interrupts
-+ rmmod zaphfc
-+ rmmod zaptel
-+
-+load: load$(BUILDVER)
-+
-+loadNT: load$(BUILDVER)NT
-+
-+load-debug: load$(BUILDVER)-debug
-+
-+loadNT-debug: load$(BUILDVER)NT-debug
-+
-+loadlinux24: all
-+ modprobe zaptel
-+ insmod ./zaphfc.o
-+ ztcfg -v
-+
-+loadlinux24-debug: all
-+ modprobe zaptel
-+ insmod ./zaphfc.o debug=1
-+ ztcfg -v
-+
-+loadlinux26: linux26
-+ modprobe zaptel
-+ insmod ./zaphfc.ko
-+ ztcfg -v
-+
-+loadlinux26-debug: linux26
-+ modprobe zaptel
-+ insmod ./zaphfc.ko debug=1
-+ ztcfg -v
-+
-+loadlinux24NT: all
-+ modprobe zaptel
-+ insmod ./zaphfc.o modes=1
-+ ztcfg -v
-+
-+loadlinux24NT-debug: all
-+ modprobe zaptel
-+ insmod ./zaphfc.o modes=1 debug=1
-+ ztcfg -v
-+
-+loadlinux26NT: linux26
-+ modprobe zaptel
-+ insmod ./zaphfc.ko modes=1
-+ ztcfg -v
-+
-+loadlinux26NT-debug: linux26
-+ modprobe zaptel
-+ insmod ./zaphfc.ko modes=1 debug=1
-+ ztcfg -v
-+
-+unload:
-+ -rmmod zaphfc zaptel
-+
-+zaphfc.ko: zaphfc.c zaphfc.h
-+
-+linux26:
-+ @if ! [ -d /usr/src/linux-2.6 ]; then echo "Link /usr/src/linux-2.6 to your kernel sources first!"; exit 1 ; fi
-+ make -C /usr/src/linux-2.6 SUBDIRS=$(PWD) ZAP=$(ZAP) modules
-+
-+install: install$(BUILDVER)
-+
-+installlinux26:
-+ install -D -m 644 zaphfc.ko $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/zaphfc.ko
-+
-+installlinux24:
-+ install -D -m 644 zaphfc.o $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/zaphfc.o
-+
-diff -urNad zaptel-1.2.2/zaphfc/zapata.conf /tmp/dpep.xmeNb1/zaptel-1.2.2/zaphfc/zapata.conf
---- zaptel-1.2.2/zaphfc/zapata.conf 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.xmeNb1/zaptel-1.2.2/zaphfc/zapata.conf 2005-02-26 19:24:32.000000000 +0200
-@@ -0,0 +1,38 @@
-+;
-+; Zapata telephony interface
-+;
-+; Configuration file
-+
-+[channels]
-+;
-+; Default language
-+;
-+;language=en
-+;
-+; Default context
-+;
-+;
-+switchtype = euroisdn
-+; p2mp TE mode
-+signalling = bri_cpe_ptmp
-+
-+; p2p TE mode
-+;signalling = bri_cpe
-+; p2mp NT mode
-+;signalling = bri_net_ptmp
-+; p2p NT mode
-+;signalling = bri_net
-+
-+pridialplan = dynamic
-+prilocaldialplan = local
-+nationalprefix = 0
-+internationalprefix = 00
-+
-+echocancel=yes
-+echotraining = 100
-+echocancelwhenbridged=yes
-+
-+immediate=yes
-+group = 1
-+context=demo
-+channel => 1-2
-diff -urNad zaptel-1.2.2/zaphfc/zaphfc.c /tmp/dpep.xmeNb1/zaptel-1.2.2/zaphfc/zaphfc.c
---- zaptel-1.2.2/zaphfc/zaphfc.c 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.xmeNb1/zaptel-1.2.2/zaphfc/zaphfc.c 2005-11-20 19:58:16.000000000 +0200
-@@ -0,0 +1,1149 @@
-+/*
-+ * zaphfc.c - Zaptel driver for HFC-S PCI A based ISDN BRI cards
-+ *
-+ * kernel module inspired by HFC PCI ISDN4Linux and Zaptel drivers
-+ *
-+ * Copyright (C) 2002, 2003, 2004, 2005 Junghanns.NET GmbH
-+ *
-+ * Klaus-Peter Junghanns <kpj at junghanns.net>
-+ *
-+ * This program is free software and may be modified and
-+ * distributed under the terms of the GNU Public License.
-+ *
-+ */
-+
-+#include <linux/kernel.h>
-+#include <linux/module.h>
-+#ifdef RTAITIMING
-+#include <asm/io.h>
-+#include <rtai.h>
-+#include <rtai_sched.h>
-+#include <rtai_fifos.h>
-+#endif
-+#include <linux/pci.h>
-+#include <linux/init.h>
-+#include <linux/interrupt.h>
-+#include <linux/delay.h>
-+#include <zaptel.h>
-+#include "zaphfc.h"
-+
-+#if CONFIG_PCI
-+
-+#define CLKDEL_TE 0x0f /* CLKDEL in TE mode */
-+#define CLKDEL_NT 0x6c /* CLKDEL in NT mode */
-+
-+typedef struct {
-+ int vendor_id;
-+ int device_id;
-+ char *vendor_name;
-+ char *card_name;
-+} PCI_ENTRY;
-+
-+static const PCI_ENTRY id_list[] =
-+{
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_2BD0, "CCD/Billion/Asuscom", "2BD0"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B000, "Billion", "B000"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B006, "Billion", "B006"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B007, "Billion", "B007"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B008, "Billion", "B008"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B009, "Billion", "B009"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B00A, "Billion", "B00A"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B00B, "Billion", "B00B"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B00C, "Billion", "B00C"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B100, "Seyeon", "B100"},
-+ {PCI_VENDOR_ID_ABOCOM, PCI_DEVICE_ID_ABOCOM_2BD1, "Abocom/Magitek", "2BD1"},
-+ {PCI_VENDOR_ID_ASUSTEK, PCI_DEVICE_ID_ASUSTEK_0675, "Asuscom/Askey", "675"},
-+ {PCI_VENDOR_ID_BERKOM, PCI_DEVICE_ID_BERKOM_T_CONCEPT, "German telekom", "T-Concept"},
-+ {PCI_VENDOR_ID_BERKOM, PCI_DEVICE_ID_BERKOM_A1T, "German telekom", "A1T"},
-+ {PCI_VENDOR_ID_ANIGMA, PCI_DEVICE_ID_ANIGMA_MC145575, "Motorola MC145575", "MC145575"},
-+ {PCI_VENDOR_ID_ZOLTRIX, PCI_DEVICE_ID_ZOLTRIX_2BD0, "Zoltrix", "2BD0"},
-+ {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_IOM2_E,"Digi International", "Digi DataFire Micro V IOM2 (Europe)"},
-+ {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_E,"Digi International", "Digi DataFire Micro V (Europe)"},
-+ {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_IOM2_A,"Digi International", "Digi DataFire Micro V IOM2 (North America)"},
-+ {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_A,"Digi International", "Digi DataFire Micro V (North America)"},
-+ {0x182d, 0x3069,"Sitecom","Isdn 128 PCI"},
-+ {0, 0, NULL, NULL},
-+};
-+
-+static struct hfc_card *hfc_dev_list = NULL;
-+static int hfc_dev_count = 0;
-+static int modes = 0; // all TE
-+static int debug = 0;
-+static struct pci_dev *multi_hfc = NULL;
-+static spinlock_t registerlock = SPIN_LOCK_UNLOCKED;
-+
-+void hfc_shutdownCard(struct hfc_card *hfctmp) {
-+ unsigned long flags;
-+
-+ if (hfctmp == NULL) {
-+ return;
-+ }
-+
-+ if (hfctmp->pci_io == NULL) {
-+ return;
-+ }
-+
-+ spin_lock_irqsave(&hfctmp->lock,flags);
-+
-+ printk(KERN_INFO "zaphfc: shutting down card at %p.\n",hfctmp->pci_io);
-+
-+ /* Clear interrupt mask */
-+ hfctmp->regs.int_m2 = 0;
-+ hfc_outb(hfctmp, hfc_INT_M2, hfctmp->regs.int_m2);
-+
-+ /* Reset pending interrupts */
-+ hfc_inb(hfctmp, hfc_INT_S1);
-+
-+ /* Wait for interrupts that might still be pending */
-+ spin_unlock_irqrestore(&hfctmp->lock, flags);
-+ set_current_state(TASK_UNINTERRUPTIBLE);
-+ schedule_timeout((30 * HZ) / 1000); // wait 30 ms
-+ spin_lock_irqsave(&hfctmp->lock,flags);
-+
-+ /* Remove interrupt handler */
-+ if (hfctmp->irq) {
-+ free_irq(hfctmp->irq, hfctmp);
-+ }
-+
-+ /* Soft-reset the card */
-+ hfc_outb(hfctmp, hfc_CIRM, hfc_CIRM_RESET); // softreset on
-+
-+ spin_unlock_irqrestore(&hfctmp->lock, flags);
-+ set_current_state(TASK_UNINTERRUPTIBLE);
-+ schedule_timeout((30 * HZ) / 1000); // wait 30 ms
-+ spin_lock_irqsave(&hfctmp->lock,flags);
-+
-+ hfc_outb(hfctmp,hfc_CIRM,0); // softreset off
-+
-+ pci_write_config_word(hfctmp->pcidev, PCI_COMMAND, 0); // disable memio and bustmaster
-+
-+ if (hfctmp->fifomem != NULL) {
-+ kfree(hfctmp->fifomem);
-+ }
-+ iounmap((void *) hfctmp->pci_io);
-+ hfctmp->pci_io = NULL;
-+ if (hfctmp->pcidev != NULL) {
-+ pci_disable_device(hfctmp->pcidev);
-+ }
-+ spin_unlock_irqrestore(&hfctmp->lock,flags);
-+ if (hfctmp->ztdev != NULL) {
-+ zt_unregister(&hfctmp->ztdev->span);
-+ kfree(hfctmp->ztdev);
-+ printk(KERN_INFO "unregistered from zaptel.\n");
-+ }
-+}
-+
-+void hfc_resetCard(struct hfc_card *hfctmp) {
-+ unsigned long flags;
-+
-+ spin_lock_irqsave(&hfctmp->lock,flags);
-+ pci_write_config_word(hfctmp->pcidev, PCI_COMMAND, PCI_COMMAND_MEMORY); // enable memio
-+ hfctmp->regs.int_m2 = 0;
-+ hfc_outb(hfctmp, hfc_INT_M2, hfctmp->regs.int_m2);
-+
-+// printk(KERN_INFO "zaphfc: resetting card.\n");
-+ pci_set_master(hfctmp->pcidev);
-+ hfc_outb(hfctmp, hfc_CIRM, hfc_CIRM_RESET); // softreset on
-+ spin_unlock_irqrestore(&hfctmp->lock, flags);
-+
-+ set_current_state(TASK_UNINTERRUPTIBLE);
-+ schedule_timeout((30 * HZ) / 1000); // wait 30 ms
-+ hfc_outb(hfctmp, hfc_CIRM, 0); // softreset off
-+
-+ set_current_state(TASK_UNINTERRUPTIBLE);
-+ schedule_timeout((20 * HZ) / 1000); // wait 20 ms
-+ if (hfc_inb(hfctmp,hfc_STATUS) & hfc_STATUS_PCI_PROC) {
-+ printk(KERN_WARNING "zaphfc: hfc busy.\n");
-+ }
-+
-+// hfctmp->regs.fifo_en = hfc_FIFOEN_D | hfc_FIFOEN_B1 | hfc_FIFOEN_B2;
-+// hfctmp->regs.fifo_en = hfc_FIFOEN_D; /* only D fifos enabled */
-+ hfctmp->regs.fifo_en = 0; /* no fifos enabled */
-+ hfc_outb(hfctmp, hfc_FIFO_EN, hfctmp->regs.fifo_en);
-+
-+ hfctmp->regs.trm = 2;
-+ hfc_outb(hfctmp, hfc_TRM, hfctmp->regs.trm);
-+
-+ if (hfctmp->regs.nt_mode == 1) {
-+ hfc_outb(hfctmp, hfc_CLKDEL, CLKDEL_NT); /* ST-Bit delay for NT-Mode */
-+ } else {
-+ hfc_outb(hfctmp, hfc_CLKDEL, CLKDEL_TE); /* ST-Bit delay for TE-Mode */
-+ }
-+ hfctmp->regs.sctrl_e = hfc_SCTRL_E_AUTO_AWAKE;
-+ hfc_outb(hfctmp, hfc_SCTRL_E, hfctmp->regs.sctrl_e); /* S/T Auto awake */
-+ hfctmp->regs.bswapped = 0; /* no exchange */
-+
-+ hfctmp->regs.ctmt = hfc_CTMT_TRANSB1 | hfc_CTMT_TRANSB2; // all bchans are transparent , no freaking hdlc
-+ hfc_outb(hfctmp, hfc_CTMT, hfctmp->regs.ctmt);
-+
-+ hfctmp->regs.int_m1 = 0;
-+ hfc_outb(hfctmp, hfc_INT_M1, hfctmp->regs.int_m1);
-+
-+#ifdef RTAITIMING
-+ hfctmp->regs.int_m2 = 0;
-+#else
-+ hfctmp->regs.int_m2 = hfc_M2_PROC_TRANS;
-+#endif
-+ hfc_outb(hfctmp, hfc_INT_M2, hfctmp->regs.int_m2);
-+
-+ /* Clear already pending ints */
-+ hfc_inb(hfctmp, hfc_INT_S1);
-+
-+ if (hfctmp->regs.nt_mode == 1) {
-+ hfctmp->regs.sctrl = 3 | hfc_SCTRL_NONE_CAP | hfc_SCTRL_MODE_NT; /* set tx_lo mode, error in datasheet ! */
-+ } else {
-+ hfctmp->regs.sctrl = 3 | hfc_SCTRL_NONE_CAP | hfc_SCTRL_MODE_TE; /* set tx_lo mode, error in datasheet ! */
-+ }
-+
-+ hfctmp->regs.mst_mode = hfc_MST_MODE_MASTER; /* HFC Master Mode */
-+ hfc_outb(hfctmp, hfc_MST_MODE, hfctmp->regs.mst_mode);
-+
-+ hfc_outb(hfctmp, hfc_SCTRL, hfctmp->regs.sctrl);
-+ hfctmp->regs.sctrl_r = 3;
-+ hfc_outb(hfctmp, hfc_SCTRL_R, hfctmp->regs.sctrl_r);
-+
-+ hfctmp->regs.connect = 0;
-+ hfc_outb(hfctmp, hfc_CONNECT, hfctmp->regs.connect);
-+
-+ hfc_outb(hfctmp, hfc_CIRM, 0x80 | 0x40); // bit order
-+
-+ /* Finally enable IRQ output */
-+#ifndef RTAITIMING
-+ hfctmp->regs.int_m2 |= hfc_M2_IRQ_ENABLE;
-+ hfc_outb(hfctmp, hfc_INT_M2, hfctmp->regs.int_m2);
-+#endif
-+
-+ /* clear pending ints */
-+ hfc_inb(hfctmp, hfc_INT_S1);
-+ hfc_inb(hfctmp, hfc_INT_S2);
-+}
-+
-+void hfc_registerCard(struct hfc_card *hfccard) {
-+ spin_lock(®isterlock);
-+ if (hfccard != NULL) {
-+ hfccard->cardno = hfc_dev_count++;
-+ hfccard->next = hfc_dev_list;
-+ hfc_dev_list = hfccard;
-+ }
-+ spin_unlock(®isterlock);
-+}
-+
-+static void hfc_btrans(struct hfc_card *hfctmp, char whichB) {
-+ // we are called with irqs disabled from the irq handler
-+ int count, maxlen, total;
-+ unsigned char *f1, *f2;
-+ unsigned short *z1, *z2, newz1;
-+ int freebytes;
-+
-+ if (whichB == 1) {
-+ f1 = (char *)(hfctmp->fifos + hfc_FIFO_B1TX_F1);
-+ f2 = (char *)(hfctmp->fifos + hfc_FIFO_B1TX_F2);
-+ z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B1TX_Z1 + (*f1 * 4));
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B1TX_Z2 + (*f1 * 4));
-+ } else {
-+ f1 = (char *)(hfctmp->fifos + hfc_FIFO_B2TX_F1);
-+ f2 = (char *)(hfctmp->fifos + hfc_FIFO_B2TX_F2);
-+ z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B2TX_Z1 + (*f1 * 4));
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B2TX_Z2 + (*f1 * 4));
-+ }
-+
-+ freebytes = *z2 - *z1;
-+ if (freebytes <= 0) {
-+ freebytes += hfc_B_FIFO_SIZE;
-+ }
-+ count = ZT_CHUNKSIZE;
-+
-+ total = count;
-+ if (freebytes < count) {
-+ hfctmp->clicks++;
-+ /* only spit out this warning once per second to not make things worse! */
-+ if (hfctmp->clicks > 100) {
-+ printk(KERN_CRIT "zaphfc: bchan tx fifo full, dropping audio! (z1=%d, z2=%d)\n",*z1,*z2);
-+ hfctmp->clicks = 0;
-+ }
-+ return;
-+ }
-+
-+ maxlen = (hfc_B_FIFO_SIZE + hfc_B_SUB_VAL) - *z1;
-+ if (maxlen > count) {
-+ maxlen = count;
-+ }
-+ newz1 = *z1 + total;
-+ if (newz1 >= (hfc_B_FIFO_SIZE + hfc_B_SUB_VAL)) { newz1 -= hfc_B_FIFO_SIZE; }
-+
-+ if (whichB == 1) {
-+ memcpy((char *)(hfctmp->fifos + hfc_FIFO_B1TX_ZOFF + *z1),hfctmp->ztdev->chans[0].writechunk, maxlen);
-+ } else {
-+ memcpy((char *)(hfctmp->fifos + hfc_FIFO_B2TX_ZOFF + *z1),hfctmp->ztdev->chans[1].writechunk, maxlen);
-+ }
-+
-+ count -= maxlen;
-+ if (count > 0) {
-+ // Buffer wrap
-+ if (whichB == 1) {
-+ memcpy((char *)(hfctmp->fifos + hfc_FIFO_B1TX_ZOFF + hfc_B_SUB_VAL),hfctmp->ztdev->chans[0].writechunk+maxlen, count);
-+ } else {
-+ memcpy((char *)(hfctmp->fifos + hfc_FIFO_B2TX_ZOFF + hfc_B_SUB_VAL),hfctmp->ztdev->chans[1].writechunk+maxlen, count);
-+ }
-+ }
-+
-+ *z1 = newz1; /* send it now */
-+
-+// if (count > 0) printk(KERN_CRIT "zaphfc: bchan tx fifo (f1=%d, f2=%d, z1=%d, z2=%d)\n",(*f1) & hfc_FMASK,(*f2) & hfc_FMASK, *z1, *z2);
-+ return;
-+}
-+
-+static void hfc_brec(struct hfc_card *hfctmp, char whichB) {
-+ // we are called with irqs disabled from the irq handler
-+ int count, maxlen, drop;
-+ volatile unsigned char *f1, *f2;
-+ volatile unsigned short *z1, *z2, newz2;
-+ int bytes = 0;
-+
-+ if (whichB == 1) {
-+ f1 = (char *)(hfctmp->fifos + hfc_FIFO_B1RX_F1);
-+ f2 = (char *)(hfctmp->fifos + hfc_FIFO_B1RX_F2);
-+ z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B1RX_Z1 + (*f1 * 4));
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B1RX_Z2 + (*f1 * 4));
-+ } else {
-+ f1 = (char *)(hfctmp->fifos + hfc_FIFO_B2RX_F1);
-+ f2 = (char *)(hfctmp->fifos + hfc_FIFO_B2RX_F2);
-+ z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B2RX_Z1 + (*f1 * 4));
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B2RX_Z2 + (*f1 * 4));
-+ }
-+
-+ bytes = *z1 - *z2;
-+ if (bytes < 0) {
-+ bytes += hfc_B_FIFO_SIZE;
-+ }
-+ count = ZT_CHUNKSIZE;
-+
-+ if (bytes < ZT_CHUNKSIZE) {
-+#ifndef RTAITIMING
-+ printk(KERN_CRIT "zaphfc: bchan rx fifo not enough bytes to receive! (z1=%d, z2=%d, wanted %d got %d), probably a buffer overrun.\n",*z1,*z2,ZT_CHUNKSIZE,bytes);
-+#endif
-+ return;
-+ }
-+
-+ /* allowing the buffering of hfc_BCHAN_BUFFER bytes of audio data works around irq jitter */
-+ if (bytes > hfc_BCHAN_BUFFER + ZT_CHUNKSIZE) {
-+ /* if the system is too slow to handle it, we will have to drop it all (except 1 zaptel chunk) */
-+ drop = bytes - ZT_CHUNKSIZE;
-+ hfctmp->clicks++;
-+ /* only spit out this warning once per second to not make things worse! */
-+ if (hfctmp->clicks > 100) {
-+ printk(KERN_CRIT "zaphfc: dropped audio (z1=%d, z2=%d, wanted %d got %d, dropped %d).\n",*z1,*z2,count,bytes,drop);
-+ hfctmp->clicks = 0;
-+ }
-+ /* hm, we are processing the b chan data tooooo slowly... let's drop the lost audio */
-+ newz2 = *z2 + drop;
-+ if (newz2 >= (hfc_B_FIFO_SIZE + hfc_B_SUB_VAL)) {
-+ newz2 -= hfc_B_FIFO_SIZE;
-+ }
-+ *z2 = newz2;
-+ }
-+
-+
-+ maxlen = (hfc_B_FIFO_SIZE + hfc_B_SUB_VAL) - *z2;
-+ if (maxlen > count) {
-+ maxlen = count;
-+ }
-+ if (whichB == 1) {
-+ memcpy(hfctmp->ztdev->chans[0].readchunk,(char *)(hfctmp->fifos + hfc_FIFO_B1RX_ZOFF + *z2), maxlen);
-+ } else {
-+ memcpy(hfctmp->ztdev->chans[1].readchunk,(char *)(hfctmp->fifos + hfc_FIFO_B2RX_ZOFF + *z2), maxlen);
-+ }
-+ newz2 = *z2 + count;
-+ if (newz2 >= (hfc_B_FIFO_SIZE + hfc_B_SUB_VAL)) {
-+ newz2 -= hfc_B_FIFO_SIZE;
-+ }
-+ *z2 = newz2;
-+
-+ count -= maxlen;
-+ if (count > 0) {
-+ // Buffer wrap
-+ if (whichB == 1) {
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B1RX_Z2 + (*f1 * 4));
-+ memcpy(hfctmp->ztdev->chans[0].readchunk + maxlen,(char *)(hfctmp->fifos + hfc_FIFO_B1RX_ZOFF + hfc_B_SUB_VAL), count);
-+ } else {
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B2RX_Z2 + (*f1 * 4));
-+ memcpy(hfctmp->ztdev->chans[1].readchunk + maxlen,(char *)(hfctmp->fifos + hfc_FIFO_B2RX_ZOFF + hfc_B_SUB_VAL), count);
-+ }
-+ newz2 = *z2 + count;
-+ if (newz2 >= (hfc_B_FIFO_SIZE + hfc_B_SUB_VAL)) {
-+ newz2 -= hfc_B_FIFO_SIZE;
-+ }
-+ }
-+
-+
-+ if (whichB == 1) {
-+ zt_ec_chunk(&hfctmp->ztdev->chans[0], hfctmp->ztdev->chans[0].readchunk, hfctmp->ztdev->chans[0].writechunk);
-+ } else {
-+ zt_ec_chunk(&hfctmp->ztdev->chans[1], hfctmp->ztdev->chans[1].readchunk, hfctmp->ztdev->chans[1].writechunk);
-+ }
-+ return;
-+}
-+
-+
-+static void hfc_dtrans(struct hfc_card *hfctmp) {
-+ // we are called with irqs disabled from the irq handler
-+ int x;
-+ int count, maxlen, total;
-+ unsigned char *f1, *f2, newf1;
-+ unsigned short *z1, *z2, newz1;
-+ int frames, freebytes;
-+
-+ if (hfctmp->ztdev->chans[2].bytes2transmit == 0) {
-+ return;
-+ }
-+
-+ f1 = (char *)(hfctmp->fifos + hfc_FIFO_DTX_F1);
-+ f2 = (char *)(hfctmp->fifos + hfc_FIFO_DTX_F2);
-+ z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DTX_Z1 + (*f1 * 4));
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DTX_Z2 + (*f1 * 4));
-+
-+ frames = (*f1 - *f2) & hfc_FMASK;
-+ if (frames < 0) {
-+ frames += hfc_MAX_DFRAMES + 1;
-+ }
-+
-+ if (frames >= hfc_MAX_DFRAMES) {
-+ printk(KERN_CRIT "zaphfc: dchan tx fifo total number of frames exceeded!\n");
-+ return;
-+ }
-+
-+ freebytes = *z2 - *z1;
-+ if (freebytes <= 0) {
-+ freebytes += hfc_D_FIFO_SIZE;
-+ }
-+ count = hfctmp->ztdev->chans[2].bytes2transmit;
-+
-+ total = count;
-+ if (freebytes < count) {
-+ printk(KERN_CRIT "zaphfc: dchan tx fifo not enough free bytes! (z1=%d, z2=%d)\n",*z1,*z2);
-+ return;
-+ }
-+
-+ newz1 = (*z1 + count) & hfc_ZMASK;
-+ newf1 = ((*f1 + 1) & hfc_MAX_DFRAMES) | (hfc_MAX_DFRAMES + 1); // next frame
-+
-+ if (count > 0) {
-+ if (debug) {
-+ printk(KERN_CRIT "zaphfc: card %d TX [ ", hfctmp->cardno);
-+ for (x=0; x<count; x++) {
-+ printk("%#2x ",hfctmp->dtransbuf[x]);
-+ }
-+ if (hfctmp->ztdev->chans[2].eoftx == 1) {
-+ printk("] %d bytes\n", count);
-+ } else {
-+ printk("..] %d bytes\n", count);
-+ }
-+ }
-+ maxlen = hfc_D_FIFO_SIZE - *z1;
-+ if (maxlen > count) {
-+ maxlen = count;
-+ }
-+ memcpy((char *)(hfctmp->fifos + hfc_FIFO_DTX_ZOFF + *z1),hfctmp->ztdev->chans[2].writechunk, maxlen);
-+ count -= maxlen;
-+ if (count > 0) {
-+ memcpy((char *)(hfctmp->fifos + hfc_FIFO_DTX_ZOFF),(char *)(hfctmp->ztdev->chans[2].writechunk + maxlen), count);
-+ }
-+ }
-+
-+ *z1 = newz1;
-+
-+ if (hfctmp->ztdev->chans[2].eoftx == 1) {
-+ *f1 = newf1;
-+ z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DTX_Z1 + (*f1 * 4));
-+ *z1 = newz1;
-+ hfctmp->ztdev->chans[2].eoftx = 0;
-+ }
-+// printk(KERN_CRIT "zaphfc: dchan tx fifo (f1=%d, f2=%d, z1=%d, z2=%d)\n",(*f1) & hfc_FMASK,(*f2) & hfc_FMASK, *z1, *z2);
-+ return;
-+}
-+
-+/* receive a complete hdlc frame, skip broken or short frames */
-+static void hfc_drec(struct hfc_card *hfctmp) {
-+ int count=0, maxlen=0, framelen=0;
-+ unsigned char *f1, *f2, *crcstat;
-+ unsigned short *z1, *z2, oldz2, newz2;
-+
-+ hfctmp->ztdev->chans[2].bytes2receive=0;
-+ hfctmp->ztdev->chans[2].eofrx = 0;
-+
-+ /* put the received data into the zaptel buffer
-+ we'll call zt_receive() later when the timer fires. */
-+ f1 = (char *)(hfctmp->fifos + hfc_FIFO_DRX_F1);
-+ f2 = (char *)(hfctmp->fifos + hfc_FIFO_DRX_F2);
-+
-+ if (*f1 == *f2) return; /* nothing received, strange eh? */
-+
-+ z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DRX_Z1 + (*f2 * 4));
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DRX_Z2 + (*f2 * 4));
-+
-+ /* calculate length of frame, including 2 bytes CRC and 1 byte STAT */
-+ count = *z1 - *z2;
-+
-+ if (count < 0) {
-+ count += hfc_D_FIFO_SIZE; /* ring buffer wrapped */
-+ }
-+ count++;
-+ framelen = count;
-+
-+ crcstat = (char *)(hfctmp->fifos + hfc_FIFO_DRX_ZOFF + *z1);
-+
-+ if ((framelen < 4) || (*crcstat != 0x0)) {
-+ /* the frame is too short for a valid HDLC frame or the CRC is borked */
-+ printk(KERN_CRIT "zaphfc: empty HDLC frame or bad CRC received (framelen = %d, stat = %#x, card = %d).\n", framelen, *crcstat, hfctmp->cardno);
-+ oldz2 = *z2;
-+ *f2 = ((*f2 + 1) & hfc_MAX_DFRAMES) | (hfc_MAX_DFRAMES + 1); /* NEXT!!! */
-+ // recalculate z2, because Z2 is a function of F2 Z2(F2) and we INCed F2!!!
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DRX_Z2 + (*f2 * 4));
-+ *z2 = (oldz2 + framelen) & hfc_ZMASK;
-+ hfctmp->drecinframe = 0;
-+ hfctmp->regs.int_drec--;
-+ /* skip short or broken frames */
-+ hfctmp->ztdev->chans[2].bytes2receive = 0;
-+ return;
-+ }
-+
-+ count -= 1; /* strip STAT */
-+ hfctmp->ztdev->chans[2].eofrx = 1;
-+
-+ if (count + *z2 <= hfc_D_FIFO_SIZE) {
-+ maxlen = count;
-+ } else {
-+ maxlen = hfc_D_FIFO_SIZE - *z2;
-+ }
-+
-+ /* copy first part */
-+ memcpy(hfctmp->drecbuf, (char *)(hfctmp->fifos + hfc_FIFO_DRX_ZOFF + *z2), maxlen);
-+ hfctmp->ztdev->chans[2].bytes2receive += maxlen;
-+
-+ count -= maxlen;
-+ if (count > 0) {
-+ /* ring buffer wrapped, copy rest from start of d fifo */
-+ memcpy(hfctmp->drecbuf + maxlen, (char *)(hfctmp->fifos + hfc_FIFO_DRX_ZOFF), count);
-+ hfctmp->ztdev->chans[2].bytes2receive += count;
-+ }
-+
-+ /* frame read */
-+ oldz2 = *z2;
-+ newz2 = (oldz2 + framelen) & hfc_ZMASK;
-+ *f2 = ((*f2 + 1) & hfc_MAX_DFRAMES) | (hfc_MAX_DFRAMES + 1); /* NEXT!!! */
-+ /* recalculate z2, because Z2 is a function of F2 Z2(F2) and we INCed F2!!! */
-+ z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DRX_Z2 + (*f2 * 4));
-+ *z2 = newz2;
-+ hfctmp->drecinframe = 0;
-+ hfctmp->regs.int_drec--;
-+}
-+
-+#ifndef RTAITIMING
-+#ifdef LINUX26
-+static irqreturn_t hfc_interrupt(int irq, void *dev_id, struct pt_regs *regs) {
-+#else
-+static void hfc_interrupt(int irq, void *dev_id, struct pt_regs *regs) {
-+#endif
-+ struct hfc_card *hfctmp = dev_id;
-+ unsigned long flags = 0;
-+ unsigned char stat;
-+#else
-+static void hfc_service(struct hfc_card *hfctmp) {
-+#endif
-+ struct zt_hfc *zthfc;
-+ unsigned char s1, s2, l1state;
-+ int x;
-+
-+ if (!hfctmp) {
-+#ifndef RTAITIMING
-+#ifdef LINUX26
-+ return IRQ_NONE;
-+#else
-+ return;
-+#endif
-+#else
-+ /* rtai */
-+ return;
-+#endif
-+ }
-+
-+ if (!hfctmp->pci_io) {
-+ printk(KERN_WARNING "%s: IO-mem disabled, cannot handle interrupt\n",
-+ __FUNCTION__);
-+#ifndef RTAITIMING
-+#ifdef LINUX26
-+ return IRQ_NONE;
-+#else
-+ return;
-+#endif
-+#else
-+ /* rtai */
-+ return;
-+#endif
-+ }
-+
-+ /* we assume a few things in this irq handler:
-+ - the hfc-pci will only generate "timer" irqs (proc/non-proc)
-+ - we need to use every 8th IRQ (to generate 1khz timing)
-+ OR
-+ - if we use rtai for timing the hfc-pci will not generate ANY irq,
-+ instead rtai will call this "fake" irq with a 1khz realtime timer. :)
-+ - rtai will directly service the card, not like it used to by triggering
-+ the linux irq
-+ */
-+
-+#ifndef RTAITIMING
-+ spin_lock_irqsave(&hfctmp->lock, flags);
-+ stat = hfc_inb(hfctmp, hfc_STATUS);
-+
-+ if ((stat & hfc_STATUS_ANYINT) == 0) {
-+ // maybe we are sharing the irq
-+ spin_unlock_irqrestore(&hfctmp->lock,flags);
-+#ifdef LINUX26
-+ return IRQ_NONE;
-+#else
-+ return;
-+#endif
-+ }
-+#endif
-+
-+ s1 = hfc_inb(hfctmp, hfc_INT_S1);
-+ s2 = hfc_inb(hfctmp, hfc_INT_S2);
-+ if (s1 != 0) {
-+ if (s1 & hfc_INTS_TIMER) {
-+ // timer (bit 7)
-+ // printk(KERN_CRIT "timer %d %d %d.\n", stat, s1, s2);
-+ }
-+ if (s1 & hfc_INTS_L1STATE) {
-+ // state machine (bit 6)
-+ // printk(KERN_CRIT "zaphfc: layer 1 state machine interrupt\n");
-+ zthfc = hfctmp->ztdev;
-+ l1state = hfc_inb(hfctmp,hfc_STATES) & hfc_STATES_STATE_MASK;
-+ if (hfctmp->regs.nt_mode == 1) {
-+ if (debug) {
-+ printk(KERN_CRIT "zaphfc: card %d layer 1 state = G%d\n", hfctmp->cardno, l1state);
-+ }
-+ switch (l1state) {
-+ case 3:
-+#ifdef RTAITIMING
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [NT] layer 1 ACTIVATED (G%d) [realtime]", hfctmp->cardno, l1state);
-+#else
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [NT] layer 1 ACTIVATED (G%d)", hfctmp->cardno, l1state);
-+#endif
-+ break;
-+ default:
-+#ifdef RTAITIMING
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [NT] layer 1 DEACTIVATED (G%d) [realtime]", hfctmp->cardno, l1state);
-+#else
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [NT] layer 1 DEACTIVATED (G%d)", hfctmp->cardno, l1state);
-+#endif
-+ }
-+ if (l1state == 2) {
-+ hfc_outb(hfctmp, hfc_STATES, hfc_STATES_ACTIVATE | hfc_STATES_DO_ACTION | hfc_STATES_NT_G2_G3);
-+ } else if (l1state == 3) {
-+ // fix to G3 state (see specs)
-+ hfc_outb(hfctmp, hfc_STATES, hfc_STATES_LOAD_STATE | 3);
-+ }
-+ } else {
-+ if (debug) {
-+ printk(KERN_CRIT "zaphfc: card %d layer 1 state = F%d\n", hfctmp->cardno, l1state);
-+ }
-+ switch (l1state) {
-+ case 7:
-+#ifdef RTAITIMING
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [TE] layer 1 ACTIVATED (F%d) [realtime]", hfctmp->cardno, l1state);
-+#else
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [TE] layer 1 ACTIVATED (F%d)", hfctmp->cardno, l1state);
-+#endif
-+ break;
-+ default:
-+#ifdef RTAITIMING
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [TE] layer 1 DEACTIVATED (F%d) [realtime]", hfctmp->cardno, l1state);
-+#else
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [TE] layer 1 DEACTIVATED (F%d)", hfctmp->cardno, l1state);
-+#endif
-+ }
-+ if (l1state == 3) {
-+ hfc_outb(hfctmp, hfc_STATES, hfc_STATES_DO_ACTION | hfc_STATES_ACTIVATE);
-+ }
-+ }
-+
-+ }
-+ if (s1 & hfc_INTS_DREC) {
-+ // D chan RX (bit 5)
-+ hfctmp->regs.int_drec++;
-+ // mr. zapata there is something for you!
-+ // printk(KERN_CRIT "d chan rx\n");
-+ }
-+ if (s1 & hfc_INTS_B2REC) {
-+ // B2 chan RX (bit 4)
-+ }
-+ if (s1 & hfc_INTS_B1REC) {
-+ // B1 chan RX (bit 3)
-+ }
-+ if (s1 & hfc_INTS_DTRANS) {
-+ // D chan TX (bit 2)
-+// printk(KERN_CRIT "zaphfc: dchan frame transmitted.\n");
-+ }
-+ if (s1 & hfc_INTS_B2TRANS) {
-+ // B2 chan TX (bit 1)
-+ }
-+ if (s1 & hfc_INTS_B1TRANS) {
-+ // B1 chan TX (bit 0)
-+ }
-+ }
-+#ifdef RTAITIMING
-+ /* fake an irq */
-+ s2 |= hfc_M2_PROC_TRANS;
-+#endif
-+ if (s2 != 0) {
-+ if (s2 & hfc_M2_PMESEL) {
-+ // kaboom irq (bit 7)
-+ printk(KERN_CRIT "zaphfc: sync lost, pci performance too low. you might have some cpu throtteling enabled.\n");
-+ }
-+ if (s2 & hfc_M2_GCI_MON_REC) {
-+ // RxR monitor channel (bit 2)
-+ }
-+ if (s2 & hfc_M2_GCI_I_CHG) {
-+ // GCI I-change (bit 1)
-+ }
-+ if (s2 & hfc_M2_PROC_TRANS) {
-+ // processing/non-processing transition (bit 0)
-+ hfctmp->ticks++;
-+#ifndef RTAITIMING
-+ if (hfctmp->ticks > 7) {
-+ // welcome to zaptel timing :)
-+#endif
-+ hfctmp->ticks = 0;
-+
-+ if (hfctmp->ztdev->span.flags & ZT_FLAG_RUNNING) {
-+ // clear dchan buffer
-+ hfctmp->ztdev->chans[2].bytes2transmit = 0;
-+ hfctmp->ztdev->chans[2].maxbytes2transmit = hfc_D_FIFO_SIZE;
-+
-+ zt_transmit(&(hfctmp->ztdev->span));
-+
-+ hfc_btrans(hfctmp,1);
-+ hfc_btrans(hfctmp,2);
-+ hfc_dtrans(hfctmp);
-+ }
-+
-+ hfc_brec(hfctmp,1);
-+ hfc_brec(hfctmp,2);
-+ if (hfctmp->regs.int_drec > 0) {
-+ // dchan data to read
-+ hfc_drec(hfctmp);
-+ if (hfctmp->ztdev->chans[2].bytes2receive > 0) {
-+ if (debug) {
-+ printk(KERN_CRIT "zaphfc: card %d RX [ ", hfctmp->cardno);
-+ if (hfctmp->ztdev->chans[2].eofrx) {
-+ /* dont output CRC == less user confusion */
-+ for (x=0; x < hfctmp->ztdev->chans[2].bytes2receive - 2; x++) {
-+ printk("%#2x ", hfctmp->drecbuf[x]);
-+ }
-+ printk("] %d bytes\n", hfctmp->ztdev->chans[2].bytes2receive - 2);
-+ } else {
-+ for (x=0; x < hfctmp->ztdev->chans[2].bytes2receive; x++) {
-+ printk("%#2x ", hfctmp->drecbuf[x]);
-+ }
-+ printk("..] %d bytes\n", hfctmp->ztdev->chans[2].bytes2receive);
-+ }
-+ }
-+ }
-+ } else {
-+ // hmm....ok, let zaptel receive nothing
-+ hfctmp->ztdev->chans[2].bytes2receive = 0;
-+ }
-+ if (hfctmp->ztdev->span.flags & ZT_FLAG_RUNNING) {
-+ zt_receive(&(hfctmp->ztdev->span));
-+ }
-+
-+#ifndef RTAITIMING
-+ }
-+#endif
-+ }
-+
-+ }
-+#ifndef RTAITIMING
-+ spin_unlock_irqrestore(&hfctmp->lock,flags);
-+#ifdef LINUX26
-+ return IRQ_RETVAL(1);
-+#endif
-+#endif
-+}
-+
-+
-+static int zthfc_open(struct zt_chan *chan) {
-+ struct zt_hfc *zthfc = chan->pvt;
-+ struct hfc_card *hfctmp = zthfc->card;
-+
-+ if (!hfctmp) {
-+ return 0;
-+ }
-+#ifndef LINUX26
-+ MOD_INC_USE_COUNT;
-+#else
-+ try_module_get(THIS_MODULE);
-+#endif
-+ return 0;
-+}
-+
-+static int zthfc_close(struct zt_chan *chan) {
-+ struct zt_hfc *zthfc = chan->pvt;
-+ struct hfc_card *hfctmp = zthfc->card;
-+
-+ if (!hfctmp) {
-+ return 0;
-+ }
-+
-+#ifndef LINUX26
-+ MOD_DEC_USE_COUNT;
-+#else
-+ module_put(THIS_MODULE);
-+#endif
-+ return 0;
-+}
-+
-+static int zthfc_rbsbits(struct zt_chan *chan, int bits) {
-+ return 0;
-+}
-+
-+static int zthfc_ioctl(struct zt_chan *chan, unsigned int cmd, unsigned long data) {
-+ switch(cmd) {
-+ default:
-+ return -ENOTTY;
-+ }
-+ return 0;
-+}
-+
-+static int zthfc_startup(struct zt_span *span) {
-+ struct zt_hfc *zthfc = span->pvt;
-+ struct hfc_card *hfctmp = zthfc->card;
-+ int alreadyrunning;
-+
-+ if (hfctmp == NULL) {
-+ printk(KERN_INFO "zaphfc: no card for span at startup!\n");
-+ }
-+ alreadyrunning = span->flags & ZT_FLAG_RUNNING;
-+
-+ if (!alreadyrunning) {
-+ span->chans[2].flags &= ~ZT_FLAG_HDLC;
-+ span->chans[2].flags |= ZT_FLAG_BRIDCHAN;
-+
-+ span->flags |= ZT_FLAG_RUNNING;
-+
-+ hfctmp->ticks = -2;
-+ hfctmp->clicks = 0;
-+ hfctmp->regs.fifo_en = hfc_FIFOEN_D | hfc_FIFOEN_B1 | hfc_FIFOEN_B2;
-+ hfc_outb(hfctmp, hfc_FIFO_EN, hfctmp->regs.fifo_en);
-+ } else {
-+ return 0;
-+ }
-+
-+ // drivers, start engines!
-+ hfc_outb(hfctmp, hfc_STATES, hfc_STATES_DO_ACTION | hfc_STATES_ACTIVATE);
-+ return 0;
-+}
-+
-+static int zthfc_shutdown(struct zt_span *span) {
-+ return 0;
-+}
-+
-+static int zthfc_maint(struct zt_span *span, int cmd) {
-+ return 0;
-+}
-+
-+static int zthfc_chanconfig(struct zt_chan *chan, int sigtype) {
-+// printk(KERN_CRIT "chan_config sigtype=%d\n", sigtype);
-+ return 0;
-+}
-+
-+static int zthfc_spanconfig(struct zt_span *span, struct zt_lineconfig *lc) {
-+ span->lineconfig = lc->lineconfig;
-+ return 0;
-+}
-+
-+static int zthfc_initialize(struct zt_hfc *zthfc) {
-+ struct hfc_card *hfctmp = zthfc->card;
-+ int i;
-+
-+ memset(&zthfc->span, 0x0, sizeof(struct zt_span)); // you never can tell...
-+
-+ sprintf(zthfc->span.name, "ZTHFC%d", hfc_dev_count + 1);
-+ if (hfctmp->regs.nt_mode == 1) {
-+#ifdef RTAITIMING
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [NT] [realtime]", hfc_dev_count + 1);
-+#else
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [NT]", hfc_dev_count + 1);
-+#endif
-+ } else {
-+#ifdef RTAITIMING
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [TE] [realtime]", hfc_dev_count + 1);
-+#else
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [TE]", hfc_dev_count + 1);
-+#endif
-+ }
-+
-+ zthfc->span.spanconfig = zthfc_spanconfig;
-+ zthfc->span.chanconfig = zthfc_chanconfig;
-+ zthfc->span.startup = zthfc_startup;
-+ zthfc->span.shutdown = zthfc_shutdown;
-+ zthfc->span.maint = zthfc_maint;
-+ zthfc->span.rbsbits = zthfc_rbsbits;
-+ zthfc->span.open = zthfc_open;
-+ zthfc->span.close = zthfc_close;
-+ zthfc->span.ioctl = zthfc_ioctl;
-+
-+ zthfc->span.chans = zthfc->chans;
-+ zthfc->span.channels = 3;
-+ zthfc->span.deflaw = ZT_LAW_ALAW;
-+ zthfc->span.linecompat = ZT_CONFIG_AMI | ZT_CONFIG_CCS; // <--- this is really BS
-+ zthfc->span.offset = 0;
-+ init_waitqueue_head(&zthfc->span.maintq);
-+ zthfc->span.pvt = zthfc;
-+
-+ for (i = 0; i < zthfc->span.channels; i++) {
-+ memset(&(zthfc->chans[i]), 0x0, sizeof(struct zt_chan));
-+ sprintf(zthfc->chans[i].name, "ZTHFC%d/%d/%d", hfc_dev_count + 1,0,i + 1);
-+ zthfc->chans[i].pvt = zthfc;
-+ zthfc->chans[i].sigcap = ZT_SIG_EM | ZT_SIG_CLEAR | ZT_SIG_FXSLS | ZT_SIG_FXSGS | ZT_SIG_FXSKS | ZT_SIG_FXOLS | ZT_SIG_FXOGS | ZT_SIG_FXOKS | ZT_SIG_CAS | ZT_SIG_SF;
-+ zthfc->chans[i].chanpos = i + 1;
-+ }
-+
-+ if (zt_register(&zthfc->span,0)) {
-+ printk(KERN_CRIT "unable to register zaptel device!\n");
-+ return -1;
-+ }
-+// printk(KERN_CRIT "zaphfc: registered zaptel device!\n");
-+ return 0;
-+}
-+
-+#ifdef RTAITIMING
-+#define TICK_PERIOD 1000000
-+#define TICK_PERIOD2 1000000000
-+#define TASK_PRIORITY 1
-+#define STACK_SIZE 10000
-+
-+static RT_TASK rt_task;
-+static struct hfc_card *rtai_hfc_list[hfc_MAX_CARDS];
-+static unsigned char rtai_hfc_counter = 0;
-+
-+static void rtai_register_hfc(struct hfc_card *hfctmp) {
-+ rtai_hfc_list[rtai_hfc_counter++] = hfctmp;
-+}
-+
-+static void rtai_loop(int t) {
-+ int i=0;
-+ for (;;) {
-+ for (i=0; i < rtai_hfc_counter; i++) {
-+ if (rtai_hfc_list[i] != NULL)
-+ hfc_service(rtai_hfc_list[i]);
-+ }
-+ rt_task_wait_period();
-+ }
-+}
-+#endif
-+
-+int hfc_findCards(int pcivendor, int pcidevice, char *vendor_name, char *card_name) {
-+ struct pci_dev *tmp;
-+ struct hfc_card *hfctmp = NULL;
-+ struct zt_hfc *zthfc = NULL;
-+
-+ tmp = pci_find_device(pcivendor, pcidevice, multi_hfc);
-+ while (tmp != NULL) {
-+ multi_hfc = tmp; // skip this next time.
-+
-+ if (pci_enable_device(tmp)) {
-+ multi_hfc = NULL;
-+ return -1;
-+ }
-+ pci_set_master(tmp);
-+
-+ hfctmp = kmalloc(sizeof(struct hfc_card), GFP_KERNEL);
-+ if (!hfctmp) {
-+ printk(KERN_WARNING "zaphfc: unable to kmalloc!\n");
-+ pci_disable_device(tmp);
-+ multi_hfc = NULL;
-+ return -ENOMEM;
-+ }
-+ memset(hfctmp, 0x0, sizeof(struct hfc_card));
-+ spin_lock_init(&hfctmp->lock);
-+
-+ hfctmp->pcidev = tmp;
-+ hfctmp->pcibus = tmp->bus->number;
-+ hfctmp->pcidevfn = tmp->devfn;
-+
-+ if (!tmp->irq) {
-+ printk(KERN_WARNING "zaphfc: no irq!\n");
-+ } else {
-+ hfctmp->irq = tmp->irq;
-+ }
-+
-+ hfctmp->pci_io = (char *) tmp->resource[1].start;
-+ if (!hfctmp->pci_io) {
-+ printk(KERN_WARNING "zaphfc: no iomem!\n");
-+ kfree(hfctmp);
-+ pci_disable_device(tmp);
-+ multi_hfc = NULL;
-+ return -1;
-+ }
-+
-+ hfctmp->fifomem = kmalloc(65536, GFP_KERNEL);
-+ if (!hfctmp->fifomem) {
-+ printk(KERN_WARNING "zaphfc: unable to kmalloc fifomem!\n");
-+ kfree(hfctmp);
-+ pci_disable_device(tmp);
-+ multi_hfc = NULL;
-+ return -ENOMEM;
-+ } else {
-+ memset(hfctmp->fifomem, 0x0, 65536);
-+ hfctmp->fifos = (((ulong) hfctmp->fifomem) & ~0x7FFF) + 0x8000;
-+ pci_write_config_dword(hfctmp->pcidev, 0x80, (u_int) virt_to_bus(hfctmp->fifos));
-+ hfctmp->pci_io = ioremap((ulong) hfctmp->pci_io, 256);
-+ }
-+
-+#ifdef RTAITIMING
-+ /* we need no stinking irq */
-+ hfctmp->irq = 0;
-+#else
-+ if (request_irq(hfctmp->irq, &hfc_interrupt, SA_INTERRUPT | SA_SHIRQ, "zaphfc", hfctmp)) {
-+ printk(KERN_WARNING "zaphfc: unable to register irq\n");
-+ kfree(hfctmp->fifomem);
-+ kfree(hfctmp);
-+ iounmap((void *) hfctmp->pci_io);
-+ pci_disable_device(tmp);
-+ multi_hfc = NULL;
-+ return -EIO;
-+ }
-+#endif
-+
-+#ifdef RTAITIMING
-+ rtai_register_hfc(hfctmp);
-+#endif
-+ printk(KERN_INFO
-+ "zaphfc: %s %s configured at mem %#x fifo %#x(%#x) IRQ %d HZ %d\n",
-+ vendor_name, card_name,
-+ (u_int) hfctmp->pci_io,
-+ (u_int) hfctmp->fifos,
-+ (u_int) virt_to_bus(hfctmp->fifos),
-+ hfctmp->irq, HZ);
-+ pci_write_config_word(hfctmp->pcidev, PCI_COMMAND, PCI_COMMAND_MEMORY); // enable memio
-+ hfctmp->regs.int_m1 = 0; // no ints
-+ hfctmp->regs.int_m2 = 0; // not at all
-+ hfc_outb(hfctmp,hfc_INT_M1,hfctmp->regs.int_m1);
-+ hfc_outb(hfctmp,hfc_INT_M2,hfctmp->regs.int_m2);
-+
-+ if ((modes & (1 << hfc_dev_count)) != 0) {
-+ printk(KERN_INFO "zaphfc: Card %d configured for NT mode\n",hfc_dev_count);
-+ hfctmp->regs.nt_mode = 1;
-+ } else {
-+ printk(KERN_INFO "zaphfc: Card %d configured for TE mode\n",hfc_dev_count);
-+ hfctmp->regs.nt_mode = 0;
-+ }
-+
-+ zthfc = kmalloc(sizeof(struct zt_hfc),GFP_KERNEL);
-+ if (!zthfc) {
-+ printk(KERN_CRIT "zaphfc: unable to kmalloc!\n");
-+ hfc_shutdownCard(hfctmp);
-+ kfree(hfctmp);
-+ multi_hfc = NULL;
-+ return -ENOMEM;
-+ }
-+ memset(zthfc, 0x0, sizeof(struct zt_hfc));
-+
-+ zthfc->card = hfctmp;
-+ zthfc_initialize(zthfc);
-+ hfctmp->ztdev = zthfc;
-+
-+ memset(hfctmp->drecbuf, 0x0, sizeof(hfctmp->drecbuf));
-+ hfctmp->ztdev->chans[2].readchunk = hfctmp->drecbuf;
-+
-+ memset(hfctmp->dtransbuf, 0x0, sizeof(hfctmp->dtransbuf));
-+ hfctmp->ztdev->chans[2].writechunk = hfctmp->dtransbuf;
-+
-+ memset(hfctmp->brecbuf[0], 0x0, sizeof(hfctmp->brecbuf[0]));
-+ hfctmp->ztdev->chans[0].readchunk = hfctmp->brecbuf[0];
-+ memset(hfctmp->btransbuf[0], 0x0, sizeof(hfctmp->btransbuf[0]));
-+ hfctmp->ztdev->chans[0].writechunk = hfctmp->btransbuf[0];
-+
-+ memset(hfctmp->brecbuf[1], 0x0, sizeof(hfctmp->brecbuf[1]));
-+ hfctmp->ztdev->chans[1].readchunk = hfctmp->brecbuf[1];
-+ memset(hfctmp->btransbuf[1], 0x0, sizeof(hfctmp->btransbuf[1]));
-+ hfctmp->ztdev->chans[1].writechunk = hfctmp->btransbuf[1];
-+
-+
-+ hfc_registerCard(hfctmp);
-+ hfc_resetCard(hfctmp);
-+ tmp = pci_find_device(pcivendor, pcidevice, multi_hfc);
-+ }
-+ return 0;
-+}
-+
-+
-+
-+int init_module(void) {
-+ int i = 0;
-+#ifdef RTAITIMING
-+ RTIME tick_period;
-+ for (i=0; i < hfc_MAX_CARDS; i++) {
-+ rtai_hfc_list[i] = NULL;
-+ }
-+ rt_set_periodic_mode();
-+#endif
-+ i = 0;
-+ while (id_list[i].vendor_id) {
-+ multi_hfc = NULL;
-+ hfc_findCards(id_list[i].vendor_id, id_list[i].device_id, id_list[i].vendor_name, id_list[i].card_name);
-+ i++;
-+ }
-+#ifdef RTAITIMING
-+ for (i=0; i < hfc_MAX_CARDS; i++) {
-+ if (rtai_hfc_list[i]) {
-+ printk(KERN_INFO
-+ "zaphfc: configured %d at mem %#x fifo %#x(%#x) for realtime servicing\n",
-+ rtai_hfc_list[i]->cardno,
-+ (u_int) rtai_hfc_list[i]->pci_io,
-+ (u_int) rtai_hfc_list[i]->fifos,
-+ (u_int) virt_to_bus(rtai_hfc_list[i]->fifos));
-+
-+ }
-+ }
-+ rt_task_init(&rt_task, rtai_loop, 1, STACK_SIZE, TASK_PRIORITY, 0, 0);
-+ tick_period = start_rt_timer(nano2count(TICK_PERIOD));
-+ rt_task_make_periodic(&rt_task, rt_get_time() + tick_period, tick_period);
-+#endif
-+ printk(KERN_INFO "zaphfc: %d hfc-pci card(s) in this box.\n", hfc_dev_count);
-+ return 0;
-+}
-+
-+void cleanup_module(void) {
-+ struct hfc_card *tmpcard;
-+#ifdef RTAITIMING
-+ stop_rt_timer();
-+ rt_task_delete(&rt_task);
-+#endif
-+ printk(KERN_INFO "zaphfc: stop\n");
-+// spin_lock(®isterlock);
-+ while (hfc_dev_list != NULL) {
-+ if (hfc_dev_list == NULL) break;
-+ hfc_shutdownCard(hfc_dev_list);
-+ tmpcard = hfc_dev_list;
-+ hfc_dev_list = hfc_dev_list->next;
-+ if (tmpcard != NULL) {
-+ kfree(tmpcard);
-+ tmpcard = NULL;
-+ printk(KERN_INFO "zaphfc: freed one card.\n");
-+ }
-+ }
-+// spin_unlock(®isterlock);
-+}
-+#endif
-+
-+
-+MODULE_DESCRIPTION("HFC-S PCI A Zaptel Driver");
-+MODULE_AUTHOR("Klaus-Peter Junghanns <kpj at junghanns.net>");
-+#ifdef MODULE_LICENSE
-+MODULE_LICENSE("GPL");
-+#endif
-+MODULE_PARM(modes,"i");
-+MODULE_PARM(debug,"i");
-diff -urNad zaptel-1.2.2/zaphfc/zaphfc.h /tmp/dpep.xmeNb1/zaptel-1.2.2/zaphfc/zaphfc.h
---- zaptel-1.2.2/zaphfc/zaphfc.h 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.xmeNb1/zaptel-1.2.2/zaphfc/zaphfc.h 2005-02-27 00:30:32.000000000 +0200
-@@ -0,0 +1,289 @@
-+/*
-+ * zaphfc.h - Zaptel driver for HFC-S PCI A based ISDN BRI cards
-+ *
-+ * kernel module based on HFC PCI ISDN4Linux and Zaptel drivers
-+ *
-+ * Copyright (C) 2002, 2003, 2004, 2005 Junghanns.NET GmbH
-+ *
-+ * Klaus-Peter Junghanns <kpj at junghanns.net>
-+ *
-+ * This program is free software and may be modified and
-+ * distributed under the terms of the GNU Public License.
-+ *
-+ */
-+
-+/* HFC register addresses - accessed using memory mapped I/O */
-+/* For a list, see datasheet section 3.2.1 at page 21 */
-+
-+#define hfc_outb(a,b,c) (writeb((c),(a)->pci_io+(b)))
-+#define hfc_inb(a,b) (readb((a)->pci_io+(b)))
-+
-+/* GCI/IOM bus monitor registers */
-+
-+#define hfc_C_I 0x08
-+#define hfc_TRxR 0x0C
-+#define hfc_MON1_D 0x28
-+#define hfc_MON2_D 0x2C
-+
-+
-+/* GCI/IOM bus timeslot registers */
-+
-+#define hfc_B1_SSL 0x80
-+#define hfc_B2_SSL 0x84
-+#define hfc_AUX1_SSL 0x88
-+#define hfc_AUX2_SSL 0x8C
-+#define hfc_B1_RSL 0x90
-+#define hfc_B2_RSL 0x94
-+#define hfc_AUX1_RSL 0x98
-+#define hfc_AUX2_RSL 0x9C
-+
-+/* GCI/IOM bus data registers */
-+
-+#define hfc_B1_D 0xA0
-+#define hfc_B2_D 0xA4
-+#define hfc_AUX1_D 0xA8
-+#define hfc_AUX2_D 0xAC
-+
-+/* GCI/IOM bus configuration registers */
-+
-+#define hfc_MST_EMOD 0xB4
-+#define hfc_MST_MODE 0xB8
-+#define hfc_CONNECT 0xBC
-+
-+
-+/* Interrupt and status registers */
-+
-+#define hfc_FIFO_EN 0x44
-+#define hfc_TRM 0x48
-+#define hfc_B_MODE 0x4C
-+#define hfc_CHIP_ID 0x58
-+#define hfc_CIRM 0x60
-+#define hfc_CTMT 0x64
-+#define hfc_INT_M1 0x68
-+#define hfc_INT_M2 0x6C
-+#define hfc_INT_S1 0x78
-+#define hfc_INT_S2 0x7C
-+#define hfc_STATUS 0x70
-+
-+/* S/T section registers */
-+
-+#define hfc_STATES 0xC0
-+#define hfc_SCTRL 0xC4
-+#define hfc_SCTRL_E 0xC8
-+#define hfc_SCTRL_R 0xCC
-+#define hfc_SQ 0xD0
-+#define hfc_CLKDEL 0xDC
-+#define hfc_B1_REC 0xF0
-+#define hfc_B1_SEND 0xF0
-+#define hfc_B2_REC 0xF4
-+#define hfc_B2_SEND 0xF4
-+#define hfc_D_REC 0xF8
-+#define hfc_D_SEND 0xF8
-+#define hfc_E_REC 0xFC
-+
-+/* Bits and values in various HFC PCI registers */
-+
-+/* bits in status register (READ) */
-+#define hfc_STATUS_PCI_PROC 0x02
-+#define hfc_STATUS_NBUSY 0x04
-+#define hfc_STATUS_TIMER_ELAP 0x10
-+#define hfc_STATUS_STATINT 0x20
-+#define hfc_STATUS_FRAMEINT 0x40
-+#define hfc_STATUS_ANYINT 0x80
-+
-+/* bits in CTMT (Write) */
-+#define hfc_CTMT_CLTIMER 0x80
-+#define hfc_CTMT_TIM3_125 0x04
-+#define hfc_CTMT_TIM25 0x10
-+#define hfc_CTMT_TIM50 0x14
-+#define hfc_CTMT_TIM400 0x18
-+#define hfc_CTMT_TIM800 0x1C
-+#define hfc_CTMT_AUTO_TIMER 0x20
-+#define hfc_CTMT_TRANSB2 0x02
-+#define hfc_CTMT_TRANSB1 0x01
-+
-+/* bits in CIRM (Write) */
-+#define hfc_CIRM_AUX_MSK 0x07
-+#define hfc_CIRM_RESET 0x08
-+#define hfc_CIRM_B1_REV 0x40
-+#define hfc_CIRM_B2_REV 0x80
-+
-+/* bits in INT_M1 and INT_S1 */
-+#define hfc_INTS_B1TRANS 0x01
-+#define hfc_INTS_B2TRANS 0x02
-+#define hfc_INTS_DTRANS 0x04
-+#define hfc_INTS_B1REC 0x08
-+#define hfc_INTS_B2REC 0x10
-+#define hfc_INTS_DREC 0x20
-+#define hfc_INTS_L1STATE 0x40
-+#define hfc_INTS_TIMER 0x80
-+
-+/* bits in INT_M2 */
-+#define hfc_M2_PROC_TRANS 0x01
-+#define hfc_M2_GCI_I_CHG 0x02
-+#define hfc_M2_GCI_MON_REC 0x04
-+#define hfc_M2_IRQ_ENABLE 0x08
-+#define hfc_M2_PMESEL 0x80
-+
-+/* bits in STATES */
-+#define hfc_STATES_STATE_MASK 0x0F
-+#define hfc_STATES_LOAD_STATE 0x10
-+#define hfc_STATES_ACTIVATE 0x20
-+#define hfc_STATES_DO_ACTION 0x40
-+#define hfc_STATES_NT_G2_G3 0x80
-+
-+/* bits in HFCD_MST_MODE */
-+#define hfc_MST_MODE_MASTER 0x01
-+#define hfc_MST_MODE_SLAVE 0x00
-+/* remaining bits are for codecs control */
-+
-+/* bits in HFCD_SCTRL */
-+#define hfc_SCTRL_B1_ENA 0x01
-+#define hfc_SCTRL_B2_ENA 0x02
-+#define hfc_SCTRL_MODE_TE 0x00
-+#define hfc_SCTRL_MODE_NT 0x04
-+#define hfc_SCTRL_LOW_PRIO 0x08
-+#define hfc_SCTRL_SQ_ENA 0x10
-+#define hfc_SCTRL_TEST 0x20
-+#define hfc_SCTRL_NONE_CAP 0x40
-+#define hfc_SCTRL_PWR_DOWN 0x80
-+
-+/* bits in SCTRL_E */
-+#define hfc_SCTRL_E_AUTO_AWAKE 0x01
-+#define hfc_SCTRL_E_DBIT_1 0x04
-+#define hfc_SCTRL_E_IGNORE_COL 0x08
-+#define hfc_SCTRL_E_CHG_B1_B2 0x80
-+
-+/* bits in FIFO_EN register */
-+#define hfc_FIFOEN_B1TX 0x01
-+#define hfc_FIFOEN_B1RX 0x02
-+#define hfc_FIFOEN_B2TX 0x04
-+#define hfc_FIFOEN_B2RX 0x08
-+#define hfc_FIFOEN_DTX 0x10
-+#define hfc_FIFOEN_DRX 0x20
-+
-+#define hfc_FIFOEN_B1 (hfc_FIFOEN_B1TX|hfc_FIFOEN_B1RX)
-+#define hfc_FIFOEN_B2 (hfc_FIFOEN_B2TX|hfc_FIFOEN_B2RX)
-+#define hfc_FIFOEN_D (hfc_FIFOEN_DTX|hfc_FIFOEN_DRX)
-+
-+/* bits in the CONNECT register */
-+#define hfc_CONNECT_B1_shift 0
-+#define hfc_CONNECT_B2_shift 3
-+
-+#define hfc_CONNECT_HFC_from_ST 0x0
-+#define hfc_CONNECT_HFC_from_GCI 0x1
-+#define hfc_CONNECT_ST_from_HFC 0x0
-+#define hfc_CONNECT_ST_from_GCI 0x2
-+#define hfc_CONNECT_GCI_from_HFC 0x0
-+#define hfc_CONNECT_GCI_from_ST 0x4
-+
-+/* bits in the __SSL and __RSL registers */
-+#define hfc_SRSL_STIO 0x40
-+#define hfc_SRSL_ENABLE 0x80
-+#define hfc_SRCL_SLOT_MASK 0x1f
-+
-+/* FIFO memory definitions */
-+
-+#define hfc_FMASK 0x000f
-+#define hfc_ZMASK 0x01ff
-+#define hfc_ZMASKB 0x1fff
-+
-+#define hfc_D_FIFO_SIZE 0x0200
-+#define hfc_B_SUB_VAL 0x0200
-+#define hfc_B_FIFO_SIZE 0x1E00
-+#define hfc_MAX_DFRAMES 0x000f
-+
-+#define hfc_FIFO_DTX_Z1 0x2080
-+#define hfc_FIFO_DTX_Z2 0x2082
-+#define hfc_FIFO_DTX_F1 0x20a0
-+#define hfc_FIFO_DTX_F2 0x20a1
-+#define hfc_FIFO_DTX 0x0000
-+#define hfc_FIFO_DTX_ZOFF 0x000
-+
-+#define hfc_FIFO_DRX_Z1 0x6080
-+#define hfc_FIFO_DRX_Z2 0x6082
-+#define hfc_FIFO_DRX_F1 0x60a0
-+#define hfc_FIFO_DRX_F2 0x60a1
-+#define hfc_FIFO_DRX 0x4000
-+#define hfc_FIFO_DRX_ZOFF 0x4000
-+
-+#define hfc_FIFO_B1TX_Z1 0x2000
-+#define hfc_FIFO_B1TX_Z2 0x2002
-+#define hfc_FIFO_B1RX_Z1 0x6000
-+#define hfc_FIFO_B1RX_Z2 0x6002
-+
-+#define hfc_FIFO_B1TX_F1 0x2080
-+#define hfc_FIFO_B1TX_F2 0x2081
-+#define hfc_FIFO_B1RX_F1 0x6080
-+#define hfc_FIFO_B1RX_F2 0x6081
-+
-+#define hfc_FIFO_B1RX_ZOFF 0x4000
-+#define hfc_FIFO_B1TX_ZOFF 0x0000
-+
-+#define hfc_FIFO_B2TX_Z1 0x2100
-+#define hfc_FIFO_B2TX_Z2 0x2102
-+#define hfc_FIFO_B2RX_Z1 0x6100
-+#define hfc_FIFO_B2RX_Z2 0x6102
-+
-+#define hfc_FIFO_B2TX_F1 0x2180
-+#define hfc_FIFO_B2TX_F2 0x2181
-+#define hfc_FIFO_B2RX_F1 0x6180
-+#define hfc_FIFO_B2RX_F2 0x6181
-+
-+#define hfc_FIFO_B2RX_ZOFF 0x6000
-+#define hfc_FIFO_B2TX_ZOFF 0x2000
-+
-+#define hfc_BTRANS_THRESHOLD 128
-+#define hfc_BTRANS_THRESMASK 0x00
-+
-+/* Structures */
-+
-+typedef struct hfc_regs {
-+ unsigned char fifo_en;
-+ unsigned char ctmt;
-+ unsigned char int_m1;
-+ unsigned char int_m2;
-+ unsigned char sctrl;
-+ unsigned char sctrl_e;
-+ unsigned char sctrl_r;
-+ unsigned char connect;
-+ unsigned char trm;
-+ unsigned char mst_mode;
-+ unsigned char bswapped;
-+ unsigned char nt_mode;
-+ unsigned char int_drec;
-+} hfc_regs;
-+
-+typedef struct hfc_card {
-+ spinlock_t lock;
-+ unsigned int irq;
-+ unsigned int iomem;
-+ int ticks;
-+ int clicks;
-+ unsigned char *pci_io;
-+ void *fifomem; // start of the shared mem
-+ volatile void *fifos; // 32k aligned mem for the fifos
-+ struct hfc_regs regs;
-+ unsigned int pcibus;
-+ unsigned int pcidevfn;
-+ struct pci_dev *pcidev;
-+ struct zt_hfc *ztdev;
-+ int drecinframe;
-+ unsigned char drecbuf[hfc_D_FIFO_SIZE];
-+ unsigned char dtransbuf[hfc_D_FIFO_SIZE];
-+ unsigned char brecbuf[2][ZT_CHUNKSIZE];
-+ unsigned char btransbuf[2][ZT_CHUNKSIZE];
-+ unsigned char cardno;
-+ struct hfc_card *next;
-+} hfc_card;
-+
-+typedef struct zt_hfc {
-+ unsigned int usecount;
-+ struct zt_span span;
-+ struct zt_chan chans[3];
-+ struct hfc_card *card;
-+} zt_hfc;
-+
-+/* tune this */
-+#define hfc_BCHAN_BUFFER 8
-+#define hfc_MAX_CARDS 8
-diff -urNad zaptel-1.2.2/zaphfc/zaptel.conf /tmp/dpep.xmeNb1/zaptel-1.2.2/zaphfc/zaptel.conf
---- zaptel-1.2.2/zaphfc/zaptel.conf 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.xmeNb1/zaptel-1.2.2/zaphfc/zaptel.conf 2004-03-24 16:35:12.000000000 +0200
-@@ -0,0 +1,8 @@
-+# hfc-s pci a span definition
-+# most of the values should be bogus because we are not really zaptel
-+loadzone=nl
-+defaultzone=nl
-+
-+span=1,1,3,ccs,ami
-+bchan=1-2
-+dchan=3
-diff -urNad zaptel-1.2.2/zaptel.c /tmp/dpep.xmeNb1/zaptel-1.2.2/zaptel.c
---- zaptel-1.2.2/zaptel.c 2005-12-17 04:04:05.000000000 +0200
-+++ /tmp/dpep.xmeNb1/zaptel-1.2.2/zaptel.c 2006-01-19 00:57:34.000000000 +0200
-@@ -4913,11 +4913,40 @@
- *(txb++) = fasthdlc_tx_run_nocheck(&ms->txhdlc);
- }
- bytes -= left;
-+#ifdef CONFIG_ZAPATA_BRI_DCHANS
-+ } else if (ms->flags & ZT_FLAG_BRIDCHAN) {
-+ /*
-+ * Let's get this right, we want to transmit complete frames only.
-+ * The card driver will do the dirty HDLC work for us.
-+ * txb (transmit buffer) is supposed to be big enough to store one frame
-+ * we will make this as big as the D fifo (1KB or 2KB)
-+ */
-+
-+ /* there are 'left' bytes in the user buffer left to transmit */
-+ left = ms->writen[ms->outwritebuf] - ms->writeidx[ms->outwritebuf] - 2;
-+ if (left > ms->maxbytes2transmit) {
-+ memcpy(txb, buf + ms->writeidx[ms->outwritebuf], ms->maxbytes2transmit);
-+ ms->writeidx[ms->outwritebuf] += ms->maxbytes2transmit;
-+ txb += ms->maxbytes2transmit;
-+ ms->bytes2transmit = ms->maxbytes2transmit;
-+ ms->eoftx = 0;
-+ } else {
-+ memcpy(txb, buf + ms->writeidx[ms->outwritebuf], left);
-+ ms->writeidx[ms->outwritebuf] += left + 2;
-+ txb += left;
-+ ms->bytes2transmit = left;
-+ ms->eoftx = 1;
-+ }
-+ bytes = 0;
-+#endif
- } else {
- memcpy(txb, buf + ms->writeidx[ms->outwritebuf], left);
- ms->writeidx[ms->outwritebuf]+=left;
- txb += left;
- bytes -= left;
-+#if defined(CONFIG_ZAPATA_BRI_DCHANS)
-+ ms->bytes2transmit=ZT_CHUNKSIZE;
-+#endif
- }
- /* Check buffer status */
- if (ms->writeidx[ms->outwritebuf] >= ms->writen[ms->outwritebuf]) {
-@@ -4962,6 +4991,17 @@
- /* Transmit a flag if this is an HDLC channel */
- if (ms->flags & ZT_FLAG_HDLC)
- fasthdlc_tx_frame_nocheck(&ms->txhdlc);
-+#if defined(CONFIG_ZAPATA_BRI_DCHANS)
-+ if(ms->flags & ZT_FLAG_BRIDCHAN) {
-+ // if (ms->bytes2transmit > 0) {
-+ // txb += 2;
-+ // ms->bytes2transmit -= 2;
-+ bytes=0;
-+ ms->eoftx = 1;
-+// printk(KERN_CRIT "zaptel EOF(%d) bytes2transmit %d\n",ms->eoftx,ms->bytes2transmit);
-+ // }
-+ }
-+#endif
- #ifdef CONFIG_ZAPATA_NET
- if (ms->flags & ZT_FLAG_NETDEV)
- netif_wake_queue(ztchan_to_dev(ms));
-@@ -5018,6 +5058,10 @@
- memset(txb, 0xFF, bytes);
- }
- bytes = 0;
-+#if defined(CONFIG_ZAPATA_BRI_DCHANS)
-+ } else if(ms->flags & ZT_FLAG_BRIDCHAN) {
-+ bytes = 0;
-+#endif
- } else {
- memset(txb, ZT_LIN2X(0, ms), bytes); /* Lastly we use silence on telephony channels */
- bytes = 0;
-@@ -5743,6 +5787,13 @@
- int left, x;
-
- int bytes = ZT_CHUNKSIZE;
-+#if defined(CONFIG_ZAPATA_BRI_DCHANS)
-+ if (ms->flags & ZT_FLAG_BRIDCHAN) {
-+ bytes = ms->bytes2receive;
-+ if (bytes < 1) return;
-+// printk(KERN_CRIT "bytes2receive %d\n",ms->bytes2receive);
-+ }
-+#endif
-
- while(bytes) {
- #if defined(CONFIG_ZAPATA_NET) || defined(CONFIG_ZAPATA_PPP)
-@@ -5801,6 +5852,19 @@
- }
- }
- }
-+#ifdef CONFIG_ZAPATA_BRI_DCHANS
-+ } else if (ms->flags & ZT_FLAG_BRIDCHAN) {
-+ memcpy(buf + ms->readidx[ms->inreadbuf], rxb, left);
-+ rxb += left;
-+ ms->readidx[ms->inreadbuf] += left;
-+ bytes -= left;
-+ if (ms->eofrx == 1) {
-+ eof=1;
-+ }
-+// printk(KERN_CRIT "receiving %d bytes\n",ms->bytes2receive);
-+ ms->bytes2receive = 0;
-+ ms->eofrx = 0;
-+#endif
- } else {
- /* Not HDLC */
- memcpy(buf + ms->readidx[ms->inreadbuf], rxb, left);
-diff -urNad zaptel-1.2.2/zaptel.h /tmp/dpep.xmeNb1/zaptel-1.2.2/zaptel.h
---- zaptel-1.2.2/zaptel.h 2005-12-17 04:04:05.000000000 +0200
-+++ /tmp/dpep.xmeNb1/zaptel-1.2.2/zaptel.h 2006-01-19 00:57:34.000000000 +0200
-@@ -994,6 +994,13 @@
- int do_ppp_error;
- struct sk_buff_head ppp_rq;
- #endif
-+#ifdef CONFIG_ZAPATA_BRI_DCHANS
-+ int bytes2receive;
-+ int maxbytes2transmit; /* size of the tx buffer in the card driver */
-+ int bytes2transmit;
-+ int eofrx;
-+ int eoftx;
-+#endif
- spinlock_t lock;
- char name[40]; /* Name */
- /* Specified by zaptel */
-@@ -1231,6 +1238,10 @@
- #define ZT_FLAG_T1PPP (1 << 15)
- #define ZT_FLAG_SIGFREEZE (1 << 16) /* Freeze signalling */
-
-+#if defined(CONFIG_ZAPATA_BRI_DCHANS)
-+#define ZT_FLAG_BRIDCHAN (1 << 17)
-+#endif
-+
- struct zt_span {
- spinlock_t lock;
- void *pvt; /* Private stuff */
-diff -urNad zaptel-1.2.2/zconfig.h /tmp/dpep.xmeNb1/zaptel-1.2.2/zconfig.h
---- zaptel-1.2.2/zconfig.h 2005-11-29 20:42:08.000000000 +0200
-+++ /tmp/dpep.xmeNb1/zaptel-1.2.2/zconfig.h 2006-01-19 00:57:34.000000000 +0200
-@@ -152,4 +152,10 @@
- */
- /* #define FXSFLASH */
-
-+/*
-+ * Uncomment the following for BRI D channels
-+ *
-+ */
-+#define CONFIG_ZAPATA_BRI_DCHANS
-+
- #endif
Deleted: zaptel/trunk/debian/patches/dot_version.dpatch
===================================================================
--- zaptel/trunk/debian/patches/dot_version.dpatch 2006-04-30 15:19:14 UTC (rev 1655)
+++ zaptel/trunk/debian/patches/dot_version.dpatch 2006-04-30 16:30:35 UTC (rev 1656)
@@ -1,12 +0,0 @@
-#! /bin/sh /usr/share/dpatch/dpatch-run
-## dot_version.dpatch by Tzafrir Cohen <tzafrir.cohen at xorcom.com>
-##
-## All lines beginning with `## DP:' are a description of the patch.
-## DP: .version seems to be missing from this tarball
-
- at DPATCH@
-diff -urNad zaptel-1.2.2/.version /tmp/dpep.ey7lsz/zaptel-1.2.2/.version
---- zaptel-1.2.2/.version 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.ey7lsz/zaptel-1.2.2/.version 2006-01-19 01:52:57.000000000 +0200
-@@ -0,0 +1 @@
-+1.2.3
Modified: zaptel/trunk/debian/patches/gendigits.dpatch
===================================================================
--- zaptel/trunk/debian/patches/gendigits.dpatch 2006-04-30 15:19:14 UTC (rev 1655)
+++ zaptel/trunk/debian/patches/gendigits.dpatch 2006-04-30 16:30:35 UTC (rev 1656)
@@ -3,6 +3,7 @@
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Fix writing to be on stdout rather than some file which fails eventually.
+## -- applied upstream in 1.2 branch
@DPATCH@
--- ../build-area/zaptel-1.2.5/gendigits.c 2005-11-29 19:42:08.000000000 +0100
Deleted: zaptel/trunk/debian/patches/rtai.dpatch
===================================================================
--- zaptel/trunk/debian/patches/rtai.dpatch 2006-04-30 15:19:14 UTC (rev 1655)
+++ zaptel/trunk/debian/patches/rtai.dpatch 2006-04-30 16:30:35 UTC (rev 1656)
@@ -1,64 +0,0 @@
-#! /bin/sh /usr/share/dpatch/dpatch-run
-## rtai.dpatch by Kilian Krause <kk at verfaction.de>
-##
-## All lines beginning with `## DP:' are a description of the patch.
-## DP: add RTAI if the rtai-source is extracted Debian-style
-
- at DPATCH@
-diff -urNad --exclude=CVS --exclude=.svn ./qozap/Makefile /tmp/dpep-work.C4VZyU/zaptel-1.0.9/qozap/Makefile
---- ./qozap/Makefile 2005-07-14 11:22:30.261257408 +0100
-+++ /tmp/dpep-work.C4VZyU/zaptel-1.0.9/qozap/Makefile 2005-07-14 11:23:32.854741752 +0100
-@@ -1,7 +1,8 @@
--KINCLUDES = /usr/src/linux/include
-+KINCLUDES = $(KSRC)/include
- BRISTUFFBASE = $(shell dirname `pwd`)
-
--ZAP = $(shell [ -f $(BRISTUFFBASE)/zaptel-1.0.9/zaptel.h ] && echo "-I$(BRISTUFFBASE)/zaptel-1.0.9")
-+ZAP = $(shell [ -f /usr/src/modules/zaptel/zaptel.h ] && echo "-I/usr/src/modules/zaptel")
-+RTAI = $(shell [ -f /usr/src/modules/rtai/base/include/rtai.h ] && echo "-DRTAITIMING -I/usr/src/modules/rtai/base/include -I/usr/src/modules/rtai")
-
- HOSTCC=gcc
-
-@@ -33,8 +34,7 @@
- sync
-
- linux26:
-- @if ! [ -d /usr/src/linux-2.6 ]; then echo "Link /usr/src/linux-2.6 to your kernel sources first!"; exit 1 ; fi
-- make -C /usr/src/linux-2.6 SUBDIRS=$(PWD) ZAP=$(ZAP) modules
-+ make -C $(KSRC) SUBDIRS=$(PWD) ZAP=$(ZAP) modules
- obj-m := $(OBJS)
-
- qozap.o: qozap.c qozap.h
-diff -urNad --exclude=CVS --exclude=.svn ./zaphfc/Makefile /tmp/dpep-work.C4VZyU/zaptel-1.0.9/zaphfc/Makefile
---- ./zaphfc/Makefile 2005-07-14 11:22:30.296252088 +0100
-+++ /tmp/dpep-work.C4VZyU/zaptel-1.0.9/zaphfc/Makefile 2005-07-14 11:24:45.739661560 +0100
-@@ -1,8 +1,8 @@
--KINCLUDES = /usr/src/linux/include
-+KINCLUDES = $(KSRC)/include
- BRISTUFFBASE = $(shell dirname `pwd`)
-
--ZAP = $(shell [ -f $(BRISTUFFBASE)/zaptel-1.0.9/zaptel.h ] && echo "-I$(BRISTUFFBASE)/zaptel-1.0.9")
--RTAI = $(shell [ -f /usr/realtime/include/rtai.h ] && echo "-DRTAITIMING -I/usr/realtime/include")
-+ZAP = $(shell [ -f /usr/src/modules/zaptel/zaptel.h ] && echo "-I/usr/src/modules/zaptel")
-+RTAI = $(shell [ -f /usr/src/modules/rtai/base/include/rtai.h ] && echo "-DRTAITIMING -I/usr/src/modules/rtai/base/include -I/usr/src/modules/rtai")
-
- HOSTCC=gcc
-
-@@ -45,6 +45,7 @@
- test: all
- modprobe zaptel
- insmod ./zaphfc.o
-+ ztcfg -v
- cat /proc/interrupts
- sleep 1
- cat /proc/interrupts
-@@ -105,8 +106,7 @@
- zaphfc.ko: zaphfc.c zaphfc.h
-
- linux26:
-- @if ! [ -d /usr/src/linux-2.6 ]; then echo "Link /usr/src/linux-2.6 to your kernel sources first!"; exit 1 ; fi
-- make -C /usr/src/linux-2.6 SUBDIRS=$(PWD) ZAP=$(ZAP) modules
-+ make -C $(KSRC) SUBDIRS=$(PWD) ZAP=$(ZAP) modules
-
- install: install$(BUILDVER)
-
Deleted: zaptel/trunk/debian/patches/xpp.dpatch
===================================================================
--- zaptel/trunk/debian/patches/xpp.dpatch 2006-04-30 15:19:14 UTC (rev 1655)
+++ zaptel/trunk/debian/patches/xpp.dpatch 2006-04-30 16:30:35 UTC (rev 1656)
@@ -1,7775 +0,0 @@
-#! /bin/sh /usr/share/dpatch/dpatch-run
-## xpp.dpatch by Tzafrir Cohen <tzafrir.cohen at xorcom.com>
-##
-## All lines beginning with `## DP:' are a description of the patch.
-## DP: The zaptel drivers for the Xorcom Astribank and friends.
-## DP: Revision 187 (trunk)
-
- at DPATCH@
-diff -urNad zaptel-1.0.10/xpp/card_fxs.c /tmp/dpep.absTwN/zaptel-1.0.10/xpp/card_fxs.c
---- zaptel-1.0.10/xpp/card_fxs.c 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.absTwN/zaptel-1.0.10/xpp/card_fxs.c 2006-01-11 10:12:52.000000000 +0200
-@@ -0,0 +1,703 @@
-+/*
-+ * Written by Oron Peled <oron at actcom.co.il>
-+ * Copyright (C) 2004-2005, Xorcom
-+ *
-+ * All rights reserved.
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License as published by
-+ * the Free Software Foundation; either version 2 of the License, or
-+ * (at your option) any later version.
-+ *
-+ * This program is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ * GNU General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-+ *
-+ */
-+
-+#include <linux/init.h>
-+#include <linux/module.h>
-+#include <linux/fs.h>
-+#include "xpd.h"
-+#include "xproto.h"
-+#include "xpp_zap.h"
-+#include <linux/delay.h>
-+
-+static const char rcsid[] = "$Id: card_fxs.c 185 2006-01-10 14:39:07Z oron $";
-+static const char revision[] = "$Revision: 185 $";
-+
-+DEF_PARM(int, print_dbg, 1, "Print DBG statements"); /* must be before zap_debug.h */
-+
-+#define LINES_REGULAR 8
-+#define LINES_DIGI_OUT 2
-+#define LINES_DIGI_INP 4
-+
-+#define MASK_BITS(b) ((1U << (b)) - 1)
-+
-+#define MASK_DIGI_OUT (MASK_BITS(LINES_DIGI_OUT) << LINES_REGULAR)
-+#define MASK_DIGI_INP (MASK_BITS(LINES_DIGI_INP) << (LINES_REGULAR + LINES_DIGI_OUT))
-+
-+/*---------------- FXS Protocol Commands ----------------------------------*/
-+
-+/* 0x0F */ DECLARE_CMD(FXS, CHAN_ENABLE, xpp_line_t lines, bool on);
-+/* 0x0F */ DECLARE_CMD(FXS, CHAN_POWER, xpp_line_t lines, bool on);
-+/* 0x0F */ DECLARE_CMD(FXS, CHAN_CID, xpp_line_t lines);
-+/* 0x0F */ DECLARE_CMD(FXS, RING, int pos, bool on);
-+/* 0x0F */ DECLARE_CMD(FXS, SETHOOK, xpp_line_t hook_status);
-+/* 0x0F */ DECLARE_CMD(FXS, LED, xpp_line_t lines, byte which, bool on);
-+/* 0x0F */ DECLARE_CMD(FXS, RELAY_OUT, byte which, bool on);
-+/* 0x0F */ DECLARE_CMD(FXS, SLIC_INIT);
-+/* 0x0F */ DECLARE_CMD(FXS, SLIC_QUERY, int pos, byte reg_num);
-+
-+static bool fxs_packet_is_valid(xpacket_t *pack);
-+static void fxs_packet_dump(xpacket_t *pack);
-+static int proc_xpd_slic_read(char *page, char **start, off_t off, int count, int *eof, void *data);
-+static int proc_xpd_slic_write(struct file *file, const char __user *buffer, unsigned long count, void *data);
-+
-+#define S_(s,l,...) \
-+ { \
-+ .lines = s, \
-+ { \
-+ .len = l, \
-+ .data = { __VA_ARGS__ }, \
-+ } \
-+ }
-+struct slic_init_data {
-+ xpp_line_t lines;
-+ slic_data_t slic_data;
-+} slic_init_data[] = {
-+#include "slic_init.inc"
-+};
-+#undef S_
-+
-+#define PROC_SLIC_FNAME "slics"
-+
-+struct FXS_priv_data {
-+ struct proc_dir_entry *xpd_slic;
-+ slic_reply_t last_reply;
-+};
-+
-+/*---------------- FXS: Methods -------------------------------------------*/
-+
-+static xpd_t *FXS_card_new(xbus_t *xbus, int xpd_num, const xproto_table_t *proto_table, byte revision)
-+{
-+ xpd_t *xpd = NULL;
-+ int channels = min(8, CHANNELS_PERXPD);
-+
-+ if(xpd_num == 0)
-+ channels += 6; /* 2 DIGITAL OUTPUTS, 4 DIGITAL INPUTS */
-+ xpd = xpd_alloc(sizeof(struct FXS_priv_data), xbus, xpd_num, proto_table, channels, revision);
-+ if(!xpd)
-+ return NULL;
-+ if(xpd_num == 0) {
-+ DBG("First XPD on %s detected. Initialize digital outputs/inputs\n", xbus->busname);
-+ xpd->digital_outputs = MASK_DIGI_OUT;
-+ xpd->digital_inputs = MASK_DIGI_INP;
-+ }
-+ xpd->direction = TO_PHONE;
-+ return xpd;
-+}
-+
-+static int FXS_card_init(xbus_t *xbus, xpd_t *xpd)
-+{
-+ struct FXS_priv_data *priv;
-+
-+ BUG_ON(!xpd);
-+ priv = xpd->priv;
-+ CALL_PROTO(FXS, SLIC_INIT, xbus, xpd);
-+#ifdef CONFIG_PROC_FS
-+ DBG("Creating SLICs file for %s/%s\n", xbus->busname, xpd->xpdname);
-+ priv->xpd_slic = create_proc_entry(PROC_SLIC_FNAME, 0644, xpd->proc_xpd_dir);
-+ if(!priv->xpd_slic) {
-+ ERR("Failed to create proc file for SLICs of %s/%s\n", xbus->busname, xpd->xpdname);
-+ goto out;
-+ }
-+ priv->xpd_slic->write_proc = proc_xpd_slic_write;
-+ priv->xpd_slic->read_proc = proc_xpd_slic_read;
-+ priv->xpd_slic->data = xpd;
-+out:
-+#endif
-+ return 0;
-+}
-+
-+static int FXS_card_remove(xbus_t *xbus, xpd_t *xpd)
-+{
-+ struct FXS_priv_data *priv;
-+
-+ BUG_ON(!xpd);
-+ priv = xpd->priv;
-+ DBG("%s/%s\n", xbus->busname, xpd->xpdname);
-+#ifdef CONFIG_PROC_FS
-+ if(priv->xpd_slic) {
-+ DBG("Removing xpd SLIC file %s/%s\n", xbus->busname, xpd->xpdname);
-+ remove_proc_entry(PROC_SLIC_FNAME, xpd->proc_xpd_dir);
-+ }
-+#endif
-+ return 0;
-+}
-+
-+/*
-+ * INPUT polling is done via SLIC register 0x06 (same as LEDS):
-+ * 7 6 5 4 3 2 1 0
-+ * +-----+-----+-----+-----+-----+-----+-----+-----+
-+ * | I1 | I3 | | | I2 | I4 | | |
-+ * +-----+-----+-----+-----+-----+-----+-----+-----+
-+ *
-+ */
-+static int input_channels[] = { 6, 7, 2, 3 }; // Slic numbers of input relays
-+
-+static void poll_inputs(xbus_t *xbus, xpd_t *xpd)
-+{
-+ int i;
-+
-+ for(i = 0; i < ARRAY_SIZE(input_channels); i++) {
-+ int pos = input_channels[i];
-+
-+ CALL_PROTO(FXS, SLIC_QUERY, xbus, xpd, pos, 0x06);
-+ }
-+}
-+
-+static int FXS_card_tick(xbus_t *xbus, xpd_t *xpd)
-+{
-+ static int rate_limit = 0;
-+
-+ if((rate_limit++ % 1000) == 0) {
-+ poll_inputs(xbus, xpd);
-+ }
-+ return 0;
-+}
-+
-+/*---------------- FXS: HOST COMMANDS -------------------------------------*/
-+
-+/* 0x0F */ HOSTCMD(FXS, CHAN_ENABLE, xpp_line_t lines, bool on)
-+{
-+ int ret = 0;
-+ xpacket_t *pack;
-+ slic_cmd_t *sc;
-+ int len;
-+
-+ BUG_ON(!xbus);
-+ BUG_ON(!xpd);
-+ lines &= xpd->enabled_chans; // Ignore disabled channels
-+ if(!lines) {
-+ return 0;
-+ }
-+ DBG("Channel Activation: 0x%4X %s\n", lines, (on) ? "on" : "off");
-+ XPACKET_NEW(pack, xbus, FXS, SLIC_WRITE, xpd->id);
-+ sc = &RPACKET_FIELD(pack, FXS, SLIC_WRITE, slic_cmd);
-+ len = slic_cmd_direct_write(sc, lines, 0x40, (on)?0x01:0x00);
-+ pack->datalen = len;
-+
-+ packet_send(xbus, pack);
-+ return ret;
-+}
-+
-+/* 0x0F */ HOSTCMD(FXS, CHAN_POWER, xpp_line_t lines, bool on)
-+{
-+ int ret = 0;
-+ xpacket_t *pack;
-+ slic_cmd_t *sc;
-+ int len;
-+
-+ BUG_ON(!xbus);
-+ BUG_ON(!xpd);
-+ lines &= xpd->enabled_chans; // Ignore disabled channels
-+ if(!lines) {
-+ return 0;
-+ }
-+ DBG("Channel Power: 0x%04X %s\n", lines, (on) ? "up" : "down");
-+ XPACKET_NEW(pack, xbus, FXS, SLIC_WRITE, xpd->id);
-+ sc = &RPACKET_FIELD(pack, FXS, SLIC_WRITE, slic_cmd);
-+ if(on) {
-+ // Power up
-+ len = slic_cmd_direct_write(sc, lines, 0x42, 0x06);
-+ } else {
-+ // Power down
-+ len = slic_cmd_direct_write(sc, lines, 0x42, 0x00);
-+ }
-+ pack->datalen = len;
-+
-+ packet_send(xbus, pack);
-+ return ret;
-+}
-+
-+/* 0x0F */ HOSTCMD(FXS, CHAN_CID, xpp_line_t lines)
-+{
-+ int ret = 0;
-+ xpacket_t *pack;
-+ slic_cmd_t *sc;
-+
-+ BUG_ON(!xbus);
-+ BUG_ON(!xpd);
-+ lines &= xpd->enabled_chans; // Ignore disabled channels
-+ if(!lines) {
-+ return 0;
-+ }
-+ DBG("Channel CID: 0x%04X\n", lines);
-+ XPACKET_NEW(pack, xbus, FXS, SLIC_WRITE, xpd->id);
-+ sc = &RPACKET_FIELD(pack, FXS, SLIC_WRITE, slic_cmd);
-+ pack->datalen = slic_cmd_direct_write(sc, lines, 0x40, 0x02);
-+ packet_send(xbus, pack);
-+ return ret;
-+}
-+
-+
-+/* 0x0F */ HOSTCMD(FXS, RING, int pos, bool on)
-+{
-+ int ret = 0;
-+ xpacket_t *pack;
-+ slic_cmd_t *sc;
-+ xpp_line_t mask = (1 << pos);
-+ int len;
-+
-+ BUG_ON(!xbus);
-+ BUG_ON(!xpd);
-+ mask &= xpd->enabled_chans; // Ignore disabled channels
-+ if(!mask) {
-+ return 0;
-+ }
-+ DBG("%s pos=%d %s\n", xpd->xpdname, pos, (on) ? "on" : "off");
-+ XPACKET_NEW(pack, xbus, FXS, SLIC_WRITE, xpd->id);
-+ sc = &RPACKET_FIELD(pack, FXS, SLIC_WRITE, slic_cmd);
-+ len = slic_cmd_direct_write(sc, mask, 0x40, (on)?0x04:0x01);
-+ pack->datalen = len;
-+
-+ packet_send(xbus, pack);
-+ return ret;
-+}
-+
-+/* 0x0F */ HOSTCMD(FXS, SETHOOK, xpp_line_t hook_status)
-+{
-+ DBG("\n");
-+ return 0;
-+}
-+
-+/*
-+ * LED control is done via SLIC register 0x06:
-+ * 7 6 5 4 3 2 1 0
-+ * +-----+-----+-----+-----+-----+-----+-----+-----+
-+ * | MR | MG | MB | R | OG | OB | G | B |
-+ * +-----+-----+-----+-----+-----+-----+-----+-----+
-+ *
-+ * B - BLUE LED (0 - OFF, 1 - ON)
-+ * G - GREEN LED (0 - OFF, 1 - ON)
-+ * OB - Output BLUE (this line is output)
-+ * OG - Output GREEN (this line is output)
-+ * R - RED LED (0 - OFF, 1 - ON)
-+ * MB - Mask BLUE. (1 - B effect the BLUE LED)
-+ * MR - Mask RED. (1 - R effect the RED LED)
-+ * MG - Mask GREEN. (1 - G effect the GREEN LED)
-+ *
-+ * The BLUE LED (actually a relay out) is connected to line 0 and 4 only.
-+ */
-+
-+// GREEN RED BLUE
-+static const int led_mask[NUM_LEDS] = { BIT(7), BIT(6), BIT(5) };
-+static const int led_vals[NUM_LEDS] = { BIT(4), BIT(1), BIT(0) };
-+
-+/* 0x0F */ HOSTCMD(FXS, LED, xpp_line_t lines, byte which, bool on)
-+{
-+ int ret = 0;
-+ xpacket_t *pack;
-+ slic_cmd_t *sc;
-+ int len;
-+ int value;
-+ int i;
-+
-+ BUG_ON(!xbus);
-+ BUG_ON(!xpd);
-+ lines &= xpd->enabled_chans; // Ignore disabled channels
-+ if(!lines) {
-+ return 0;
-+ }
-+ DBG("LED: lines=0x%04X which=%d -- %s\n", lines, which, (on) ? "on" : "off");
-+ which = which % NUM_LEDS;
-+ value = BIT(2) | BIT(3);
-+ value |= ((BIT(5) | BIT(6) | BIT(7)) & ~led_mask[which]);
-+ if(on)
-+ value |= led_vals[which];
-+ for(i = 0; i < CHANNELS_PERXPD; i++) {
-+ if(!IS_SET(lines, i))
-+ continue;
-+ XPACKET_NEW(pack, xbus, FXS, SLIC_WRITE, xpd->id);
-+ sc = &RPACKET_FIELD(pack, FXS, SLIC_WRITE, slic_cmd);
-+ len = slic_cmd_direct_write(sc, lines, 0x06, value);
-+ DBG("LED pack: line=%d value=0x%04X\n", i, value);
-+ pack->datalen = len;
-+ packet_send(xbus, pack);
-+ }
-+ return ret;
-+}
-+
-+/* 0x0F */ HOSTCMD(FXS, RELAY_OUT, byte which, bool on)
-+{
-+ int ret = 0;
-+ xpacket_t *pack;
-+ slic_cmd_t *sc;
-+ int len;
-+ int value;
-+ xpp_line_t lines;
-+ int relay_channels[] = { 0, 4 };
-+
-+ BUG_ON(!xbus);
-+ BUG_ON(!xpd);
-+
-+ DBG("RELAY_OUT: which=%d -- %s\n", which, (on) ? "on" : "off");
-+ which = which % ARRAY_SIZE(relay_channels);
-+ lines = BIT(relay_channels[which]);
-+ value = BIT(2) | BIT(3);
-+ value |= ((BIT(5) | BIT(6) | BIT(7)) & ~led_mask[LED_BLUE]);
-+ if(on)
-+ value |= led_vals[LED_BLUE];
-+ XPACKET_NEW(pack, xbus, FXS, SLIC_WRITE, xpd->id);
-+ sc = &RPACKET_FIELD(pack, FXS, SLIC_WRITE, slic_cmd);
-+ len = slic_cmd_direct_write(sc, lines, 0x06, value);
-+
-+ DBG("RELAY_OUT pack: line=%d value=0x%04X\n", lines, value);
-+ pack->datalen = len;
-+ packet_send(xbus, pack);
-+ return ret;
-+}
-+
-+/* 0x0F */ HOSTCMD(FXS, SLIC_INIT)
-+{
-+ int ret = 0;
-+ xpacket_t *pack;
-+ slic_data_t *slic;
-+ struct slic_init_data *source;
-+ int i;
-+
-+ BUG_ON(!xbus);
-+ BUG_ON(!xpd);
-+ DBG("INITIALIZING SLIC\n");
-+ for(i = 0; i < ARRAY_SIZE(slic_init_data); i++) {
-+ source = &slic_init_data[i];
-+ XPACKET_NEW(pack, xbus, FXS, SLIC_INIT, xpd->id);
-+ RPACKET_FIELD(pack, FXS, SLIC_INIT, lines) = source->lines;
-+
-+ slic = &RPACKET_FIELD(pack, FXS, SLIC_INIT, slic_data);
-+ slic->len = source->slic_data.len;
-+ memcpy(slic->data, source->slic_data.data, source->slic_data.len);
-+ pack->datalen = sizeof(xpp_line_t) + slic->len + 1;
-+// dump_packet("SLIC", pack, print_dbg);
-+ packet_send(xbus, pack);
-+ mdelay(10); // FIXME: check with Dima
-+ }
-+ return ret;
-+}
-+
-+/* 0x0F */ HOSTCMD(FXS, SLIC_QUERY, int pos, byte reg_num)
-+{
-+ int ret = 0;
-+ xpacket_t *pack;
-+ slic_cmd_t *sc;
-+ int len;
-+
-+ BUG_ON(!xbus);
-+ BUG_ON(!xpd);
-+ DBG("\n");
-+ XPACKET_NEW(pack, xbus, FXS, SLIC_WRITE, xpd->id);
-+ sc = &RPACKET_FIELD(pack, FXS, SLIC_WRITE, slic_cmd);
-+ len = slic_cmd_direct_read(sc, BIT(pos), reg_num);
-+
-+ pack->datalen = len;
-+
-+ packet_send(xbus, pack);
-+ return ret;
-+}
-+
-+/*---------------- FXS: Astribank Reply Handlers --------------------------*/
-+
-+HANDLER_DEF(FXS, SIG_CHANGED)
-+{
-+ xpp_line_t sig_status = RPACKET_FIELD(pack, FXS, SIG_CHANGED, sig_status);
-+
-+ if(!xpd) {
-+ NOTICE("%s: received %s for non-existing xpd: %d\n",
-+ __FUNCTION__, cmd->name, XPD_NUM(pack->content.addr));
-+ return -EPROTO;
-+ }
-+ if(xpd->direction == TO_PHONE) { /* Hook state changes */
-+ DBG("%s (PHONE) sig_status=0x%04X\n", xpd->xpdname, sig_status);
-+ xpp_check_hookstate(xpd, sig_status);
-+ } else { /* TO_PSTN - line ring changes */
-+ unsigned long flags;
-+ int i;
-+
-+ DBG("%s (PSTN) sig_status=0x%04X\n", xpd->xpdname, sig_status);
-+ spin_lock_irqsave(&xpd->lock, flags);
-+ for(i = 0; i < xpd->channels; i++) {
-+ if(IS_SET(sig_status, i)) {
-+ xpd->ringing[i] = RINGS_NUM*2;
-+ zt_hooksig(&xpd->chans[i], ZT_RXSIG_OFFHOOK);
-+ } else {
-+ zt_hooksig(&xpd->chans[i], ZT_RXSIG_ONHOOK);
-+ xpd->ringing[i] = 0;
-+ }
-+ }
-+ spin_unlock_irqrestore(&xpd->lock, flags);
-+ }
-+ return 0;
-+}
-+
-+HANDLER_DEF(FXS, SLIC_REPLY)
-+{
-+ slic_reply_t *info = &RPACKET_FIELD(pack, FXS, SLIC_REPLY, info);
-+ xpp_line_t lines = RPACKET_FIELD(pack, FXS, SLIC_REPLY, lines);
-+ unsigned long flags;
-+ struct FXS_priv_data *priv;
-+
-+ if(!xpd) {
-+ NOTICE("%s: received %s for non-existing xpd: %d\n",
-+ __FUNCTION__, cmd->name, XPD_NUM(pack->content.addr));
-+ return -EPROTO;
-+ }
-+ spin_lock_irqsave(&xpd->lock, flags);
-+ priv = xpd->priv;
-+ BUG_ON(!priv);
-+ DBG("SLIC_REPLY: xpd #%d %s reg_num=0x%X, dataL=0x%X dataH=0x%X\n",
-+ xpd->id, (info->indirect)?"I":"D",
-+ info->reg_num, info->data_low, info->data_high);
-+ priv->last_reply = *info;
-+ if(xpd->id == 0 && info->indirect == 0 && info->reg_num == 0x06) { /* Digital Inputs Poll Result */
-+ int i;
-+ bool offhook = (info->data_low & 0x1) == 0;
-+
-+ /* Map SLIC number into line number */
-+ for(i = 0; i < ARRAY_SIZE(input_channels); i++) {
-+ int channo = input_channels[i];
-+ int newchanno;
-+
-+ if(IS_SET(lines, channo)) {
-+ newchanno = LINES_REGULAR + LINES_DIGI_OUT + i;
-+ BIT_CLR(lines, channo);
-+ BIT_SET(lines, newchanno);
-+ phone_hook(xpd, newchanno, offhook);
-+ }
-+ }
-+ }
-+ spin_unlock_irqrestore(&xpd->lock, flags);
-+ return 0;
-+}
-+
-+
-+xproto_table_t PROTO_TABLE(FXS) = {
-+ .entries = {
-+ /* Card Opcode */
-+ XENTRY( FXS, SIG_CHANGED ),
-+ XENTRY( FXS, SLIC_REPLY ),
-+ },
-+ .name = "FXS",
-+ .type = XPD_TYPE(FXS),
-+ .xops = {
-+ .card_new = FXS_card_new,
-+ .card_init = FXS_card_init,
-+ .card_remove = FXS_card_remove,
-+ .card_tick = FXS_card_tick,
-+
-+ .RING = XPROTO_CALLER(FXS, RING),
-+ .SETHOOK = XPROTO_CALLER(FXS, SETHOOK),
-+ .LED = XPROTO_CALLER(FXS, LED),
-+ .RELAY_OUT = XPROTO_CALLER(FXS, RELAY_OUT),
-+ .CHAN_ENABLE = XPROTO_CALLER(FXS, CHAN_ENABLE),
-+ .CHAN_POWER = XPROTO_CALLER(FXS, CHAN_POWER),
-+ .CHAN_CID = XPROTO_CALLER(FXS, CHAN_CID),
-+
-+ .SYNC_SOURCE = XPROTO_CALLER(GLOBAL, SYNC_SOURCE),
-+ .PCM_WRITE = XPROTO_CALLER(GLOBAL, PCM_WRITE),
-+ },
-+ .packet_is_valid = fxs_packet_is_valid,
-+ .packet_dump = fxs_packet_dump,
-+};
-+
-+static bool fxs_packet_is_valid(xpacket_t *pack)
-+{
-+ const xproto_entry_t *xe;
-+
-+ DBG("\n");
-+ xe = xproto_card_entry(&PROTO_TABLE(FXS), pack->content.opcode);
-+ return xe != NULL;
-+}
-+
-+static void fxs_packet_dump(xpacket_t *pack)
-+{
-+ DBG("\n");
-+}
-+
-+/*------------------------- SLIC Handling --------------------------*/
-+
-+static int proc_xpd_slic_read(char *page, char **start, off_t off, int count, int *eof, void *data)
-+{
-+ int len = 0;
-+ unsigned long flags;
-+ xpd_t *xpd = data;
-+ slic_reply_t *info;
-+ struct FXS_priv_data *priv;
-+
-+ BUG_ON(!xpd);
-+ spin_lock_irqsave(&xpd->lock, flags);
-+ priv = xpd->priv;
-+ BUG_ON(!priv);
-+ info = &priv->last_reply;
-+ len += sprintf(page + len, "# Writing bad data into this file may damage your hardware!\n");
-+ len += sprintf(page + len, "# Consult firmware docs first\n");
-+ len += sprintf(page + len, "SLIC_REPLY: %s reg_num=0x%X, dataH=0x%X dataL=0x%X\n",
-+ (info->indirect)?"I":"D",
-+ info->reg_num, info->data_high, info->data_low);
-+ spin_unlock_irqrestore(&xpd->lock, flags);
-+ if (len <= off+count)
-+ *eof = 1;
-+ *start = page + off;
-+ len -= off;
-+ if (len > count)
-+ len = count;
-+ if (len < 0)
-+ len = 0;
-+ return len;
-+}
-+
-+/*
-+ * Direct/Indirect
-+ * v
-+ * FF FF FF FF WD 06 1
-+ * ^---------^ ^ Reg
-+ * | Write/Read
-+ * |
-+ * SLIC #
-+ */
-+static int parse_slic_cmd(const char *buf, slic_cmd_t *sc)
-+{
-+ char op; /* [W]rite, [R]ead */
-+ char reg_type; /* [D]irect, [I]ndirect */
-+ int s1, s2, s3, s4;
-+ int reg_num;
-+ int data_low, data_high;
-+ xpp_line_t lines;
-+ int ret;
-+
-+ ret = sscanf(buf, "%x %x %x %x %c%c %x %x %x",
-+ &s1, &s2, &s3, &s4, &op, ®_type, ®_num, &data_high, &data_low);
-+ lines = (s4 << 24) | (s3 << 16) | (s2 << 8) | (s1);
-+ switch(op) {
-+ case 'R':
-+ if(reg_type == 'D' && ret == 7) {
-+ // DBG("0x%X 0x%X 0x%X 0x%X %c %x\n", s1, s2, s3, s4, reg_type, reg_num);
-+ ret = slic_cmd_direct_read(sc, lines, reg_num);
-+ } else if(reg_type == 'I' && ret == 7) {
-+ // DBG("0x%X 0x%X 0x%X 0x%X %c %x\n", s1, s2, s3, s4, reg_type, reg_num);
-+ ret = slic_cmd_indirect_read(sc, lines, reg_num);
-+ } else {
-+ NOTICE("%s: Bad read input: ret=%d buf='%s' reg_type=%c\n", __FUNCTION__, ret, buf, reg_type);
-+ goto err;
-+ }
-+ break;
-+ case 'W':
-+ if(reg_type == 'D' && ret == 8) {
-+ // DBG("0x%X 0x%X 0x%X 0x%X %c %x %X\n", s1, s2, s3, s4, reg_type, reg_num, data_high);
-+ ret = slic_cmd_direct_write(sc, lines, reg_num, data_high);
-+ } else if(reg_type == 'I' && ret == 9) {
-+ // DBG("0x%X 0x%X 0x%X 0x%X %c %x %X %X\n", s1, s2, s3, s4, reg_type, reg_num, data_high, data_low);
-+ ret = slic_cmd_indirect_write(sc, lines, reg_num, data_low, data_high);
-+ } else {
-+ NOTICE("%s: Bad write input: ret=%d buf='%s' reg_type=%c\n", __FUNCTION__, ret, buf, reg_type);
-+ goto err;
-+ }
-+ break;
-+ default:
-+ NOTICE("%s: Bad input: ret=%d buf='%s' op=%c\n", __FUNCTION__, ret, buf, op);
-+ goto err;
-+ }
-+ return ret;
-+err:
-+ return -EINVAL;
-+}
-+
-+static int process_slic_cmdline(xpd_t *xpd, char *cmdline)
-+{
-+ xbus_t *xbus;
-+ slic_cmd_t sc;
-+ xpacket_t *pack;
-+ char *p;
-+ int len = strlen(cmdline);
-+
-+ BUG_ON(!xpd);
-+ xbus = xpd->xbus;
-+ if((p = strchr(cmdline, '#')) != NULL) /* Truncate comments */
-+ *p = '\0';
-+ if((p = strchr(cmdline, ';')) != NULL) /* Truncate comments */
-+ *p = '\0';
-+ for(p = cmdline; *p && (*p == ' ' || *p == '\t'); p++) /* Trim leading whitespace */
-+ ;
-+ if(*p == '\0')
-+ return 0;
-+ len = parse_slic_cmd(p, &sc);
-+ if(len < 0)
-+ return len;
-+ sc.lines &= xpd->enabled_chans; // Ignore disabled channels
-+ if(!sc.lines) {
-+ NOTICE("%s: no enabled channels are marked. Skip.\n", __FUNCTION__);
-+ return 0;
-+ }
-+ dump_slic_cmd("WRITE_SLIC", &sc);
-+ XPACKET_NEW(pack, xbus, FXS, SLIC_WRITE, xpd->id);
-+ RPACKET_FIELD(pack, FXS, SLIC_WRITE, slic_cmd) = sc;
-+ pack->datalen = len;
-+ packet_send(xbus, pack);
-+ return 0;
-+}
-+
-+static int proc_xpd_slic_write(struct file *file, const char __user *buffer, unsigned long count, void *data)
-+{
-+ xpd_t *xpd = data;
-+ const int LINE_LEN = 500;
-+ char buf[LINE_LEN];
-+ char *p;
-+ int i;
-+ int ret;
-+
-+ BUG_ON(!xpd);
-+ for(i = 0; i < count; /* noop */) {
-+ for(p = buf; p < buf + LINE_LEN; p++) { /* read a line */
-+ if(i >= count)
-+ break;
-+ if(get_user(*p, buffer + i))
-+ return -EFAULT;
-+ i++;
-+ if(*p == '\n' || *p == '\r') /* whatever */
-+ break;
-+ }
-+ if(p >= buf + LINE_LEN)
-+ return -E2BIG;
-+ *p = '\0';
-+ ret = process_slic_cmdline(xpd, buf);
-+ if(ret < 0)
-+ return ret;
-+ }
-+ return count;
-+}
-+
-+
-+int __init card_fxs_startup(void)
-+{
-+ INFO("%s revision %s\n", THIS_MODULE->name, revision);
-+ xproto_register(&PROTO_TABLE(FXS));
-+ return 0;
-+}
-+
-+void __exit card_fxs_cleanup(void)
-+{
-+ xproto_unregister(&PROTO_TABLE(FXS));
-+}
-+
-+MODULE_DESCRIPTION("XPP FXS Card Driver");
-+MODULE_AUTHOR("Oron Peled <oron at actcom.co.il>");
-+MODULE_LICENSE("GPL");
-+MODULE_VERSION("$Id: card_fxs.c 185 2006-01-10 14:39:07Z oron $");
-+
-+module_init(card_fxs_startup);
-+module_exit(card_fxs_cleanup);
-diff -urNad zaptel-1.0.10/xpp/card_fxs.h /tmp/dpep.absTwN/zaptel-1.0.10/xpp/card_fxs.h
---- zaptel-1.0.10/xpp/card_fxs.h 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.absTwN/zaptel-1.0.10/xpp/card_fxs.h 2006-01-09 18:14:37.000000000 +0200
-@@ -0,0 +1,45 @@
-+#ifndef CARD_FXS_H
-+#define CARD_FXS_H
-+/*
-+ * Written by Oron Peled <oron at actcom.co.il>
-+ * Copyright (C) 2004-2005, Xorcom
-+ *
-+ * All rights reserved.
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License as published by
-+ * the Free Software Foundation; either version 2 of the License, or
-+ * (at your option) any later version.
-+ *
-+ * This program is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ * GNU General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-+ *
-+ */
-+
-+#include "xpd.h"
-+#include "slic.h"
-+
-+DEF_RPACKET_DATA(FXS, SIG_CHANGED,
-+ byte type; /* unused -- we have it from DEV_DESC */
-+ xpp_line_t sig_status; /* channels: lsb=1, msb=8 */
-+ xpp_line_t sig_toggles; /* channels: lsb=1, msb=8 */
-+ );
-+DEF_RPACKET_DATA(FXS, SLIC_REPLY, /* Get status of a single SLIC (for debugging) */
-+ xpp_line_t lines;
-+ slic_reply_t info;
-+ );
-+DEF_RPACKET_DATA(FXS, SLIC_INIT,
-+ xpp_line_t lines;
-+ slic_data_t slic_data;
-+ );
-+DEF_RPACKET_DATA(FXS, SLIC_WRITE,
-+ slic_cmd_t slic_cmd;
-+ );
-+
-+#endif /* CARD_FXS_H */
-diff -urNad zaptel-1.0.10/xpp/card_global.c /tmp/dpep.absTwN/zaptel-1.0.10/xpp/card_global.c
---- zaptel-1.0.10/xpp/card_global.c 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.absTwN/zaptel-1.0.10/xpp/card_global.c 2006-01-11 10:12:52.000000000 +0200
-@@ -0,0 +1,256 @@
-+/*
-+ * Written by Oron Peled <oron at actcom.co.il>
-+ * Copyright (C) 2004-2005, Xorcom
-+ *
-+ * All rights reserved.
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License as published by
-+ * the Free Software Foundation; either version 2 of the License, or
-+ * (at your option) any later version.
-+ *
-+ * This program is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ * GNU General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-+ *
-+ */
-+
-+#include "xdefs.h"
-+#include "xpd.h"
-+#include "xpp_zap.h"
-+#include "xproto.h"
-+#include <linux/module.h>
-+
-+static const char rcsid[] = "$Id: card_global.c 185 2006-01-10 14:39:07Z oron $";
-+
-+extern int print_dbg;
-+static bool pcm_valid(xpd_t *xpd, xpacket_t *pack);
-+
-+/*---------------- GLOBAL Protocol Commands -------------------------------*/
-+
-+static bool global_packet_is_valid(xpacket_t *pack);
-+static void global_packet_dump(xpacket_t *pack);
-+
-+/*---------------- GLOBAL: HOST COMMANDS ----------------------------------*/
-+
-+/* 0x04 */ HOSTCMD(GLOBAL, DESC_REQ, int xpd_num)
-+{
-+ int ret = 0;
-+ xpacket_t *pack;
-+
-+ if(!xbus) {
-+ DBG("NO XBUS\n");
-+ return -EINVAL;
-+ }
-+ XPACKET_NEW(pack, xbus, GLOBAL, DESC_REQ, xpd_num);
-+ DBG("on %s #%d\n", xbus->busname, xpd_num);
-+ ret = packet_send(xbus, pack);
-+ XBUS_COUNTER(xbus, DESC_REQ)++;
-+ return ret;
-+}
-+
-+/* 0x11 */ HOSTCMD(GLOBAL, PCM_WRITE, xpp_line_t lines, volatile byte *buf)
-+{
-+ int ret = 0;
-+ xpacket_t *pack;
-+ byte *pcm;
-+ byte *start_pcm;
-+ int i;
-+ extern ulong pcm_gen;
-+
-+ BUG_ON(!xbus);
-+ BUG_ON(!xpd);
-+ lines &= xpd->enabled_chans;
-+ if(pcm_gen != 0)
-+ return 0;
-+// if(lines == 0)
-+// return 0;
-+
-+ /*
-+ * FIXME: Workaround a bug in sync code of the Astribank.
-+ * Send dummy PCM for sync.
-+ */
-+ if(lines == 0)
-+ lines = BIT(0);
-+
-+ XPACKET_NEW(pack, xbus, GLOBAL, PCM_WRITE, xpd->id);
-+ RPACKET_FIELD(pack, GLOBAL, PCM_WRITE, lines) = lines;
-+ start_pcm = pcm = RPACKET_FIELD(pack, GLOBAL, PCM_WRITE, pcm);
-+ for(i = 0; i < CHANNELS_PERXPD; i++) {
-+ if(IS_SET(lines, i)) {
-+ memcpy(pcm, (byte *)buf, ZT_CHUNKSIZE);
-+ pcm += ZT_CHUNKSIZE;
-+ }
-+ buf += ZT_CHUNKSIZE;
-+ }
-+ pack->datalen = sizeof(xpp_line_t) + (pcm - start_pcm);
-+ packet_send(xbus, pack);
-+ XPD_COUNTER(xpd, PCM_WRITE)++;
-+ XBUS_COUNTER(xbus, PCM_WRITE)++;
-+ return ret;
-+}
-+
-+/* 0x19 */ HOSTCMD(GLOBAL, SYNC_SOURCE, bool setit, bool is_master)
-+{
-+ xpacket_t *pack;
-+ byte mask = 0;
-+
-+ BUG_ON(!xbus);
-+ BUG_ON(!xpd);
-+ if(is_master)
-+ mask |= BIT(0);
-+ if(!setit)
-+ mask |= BIT(1);
-+ DBG("SYNC_SOURCE %s setit=%s is_master=%s (mask=0x%X)\n",
-+ xpd->xpdname, (setit)?"yes":"no", (is_master)?"yes":"no", mask);
-+ XPACKET_NEW(pack, xbus, GLOBAL, SYNC_SOURCE, xpd->id);
-+ RPACKET_FIELD(pack, GLOBAL, SYNC_SOURCE, mask) = mask;
-+ packet_send(xbus, pack);
-+ return 0;
-+}
-+
-+/*---------------- GLOBAL: Astribank Reply Handlers -----------------------*/
-+
-+HANDLER_DEF(GLOBAL, DEV_DESC)
-+{
-+ byte rev = RPACKET_FIELD(pack, GLOBAL, DEV_DESC, rev);
-+ byte type = RPACKET_FIELD(pack, GLOBAL, DEV_DESC, type);
-+ xpp_line_t line_status = RPACKET_FIELD(pack, GLOBAL, DEV_DESC, line_status);
-+ int xpd_num = XPD_NUM(pack->content.addr);
-+ struct card_desc_struct *card_desc;
-+
-+ DBG("xpd=%d type=%d rev=%d line_status=0x%04X\n",
-+ xpd_num, type, rev, line_status);
-+ if((card_desc = kmalloc(sizeof(struct card_desc_struct), GFP_ATOMIC)) == NULL) {
-+ ERR("%s: Card description allocation failed.\n", __FUNCTION__);
-+ return -ENOMEM;
-+ }
-+ memset(card_desc, 0, sizeof(struct card_desc_struct));
-+ card_desc->magic = CARD_DESC_MAGIC;
-+ card_desc->xbus = xbus;
-+ card_desc->type = type;
-+ card_desc->rev = rev;
-+ card_desc->xpd_num = xpd_num;
-+ INIT_WORK(&card_desc->work, card_detected, card_desc);
-+ DBG("Queueing xpp_worker for xpd %d\n", xpd_num);
-+ if(!queue_work(xpp_worker, &card_desc->work)) {
-+ ERR("Failed to queue card description work\n");
-+ return -EINVAL;
-+ }
-+ return 0;
-+}
-+
-+HANDLER_DEF(GLOBAL, PCM_READ)
-+{
-+ /* FIXME: work around temporary hardware bug */
-+ xpp_line_t lines = RPACKET_FIELD(pack, GLOBAL, PCM_READ, lines);
-+ const byte *pcm = RPACKET_FIELD(pack, GLOBAL, PCM_READ, pcm);
-+ volatile u_char *readchunk;
-+ volatile u_char *r;
-+ unsigned long flags;
-+ int i;
-+
-+ if(!xpd) {
-+#if 0
-+ int xpd_num = XPD_NUM(pack->content.addr);
-+ NOTICE("%s: received %s for non-existing xpd: %d\n",
-+ __FUNCTION__, cmd->name, xpd_num);
-+#endif
-+ return -EPROTO;
-+ }
-+ // DBG("lines=0x%04X\n", lines);
-+
-+ if(!pcm_valid(xpd, pack)) {
-+ return -EPROTO;
-+ }
-+ spin_lock_irqsave(&xpd->lock, flags);
-+ if (xpd->timer_count & 1) {
-+ /* First part */
-+ r = readchunk = xpd->readchunk;
-+ } else {
-+ r = readchunk = xpd->readchunk + ZT_CHUNKSIZE * CHANNELS_PERXPD;
-+ }
-+
-+ /* Copy PCM and put each channel in its index */
-+ for (i = 0; i < CHANNELS_PERXPD; i++) {
-+ if(IS_SET(lines, i)) {
-+ memcpy((u_char *)r, pcm, ZT_CHUNKSIZE);
-+ //memset((u_char *)r, 0x5A, ZT_CHUNKSIZE); // DEBUG
-+ pcm += ZT_CHUNKSIZE;
-+ }
-+ r += ZT_CHUNKSIZE;
-+ }
-+
-+ XPD_COUNTER(xpd, PCM_READ)++;
-+ XBUS_COUNTER(xpd->xbus, PCM_READ)++;
-+ spin_unlock_irqrestore(&xpd->lock, flags);
-+ xpp_tick((unsigned long)xpd);
-+ return 0;
-+}
-+
-+HANDLER_DEF(GLOBAL, SYNC_REPLY)
-+{
-+ if(!xpd) {
-+ int xpd_num = XPD_NUM(pack->content.addr);
-+ NOTICE("%s: received %s for non-existing xpd: %d\n", __FUNCTION__, cmd->name, xpd_num);
-+ return -EPROTO;
-+ }
-+ DBG("SYNC_REPLY: 0x%X\n", RPACKET_FIELD(pack, GLOBAL, SYNC_REPLY, mask));
-+ return 0;
-+}
-+
-+
-+xproto_table_t PROTO_TABLE(GLOBAL) = {
-+ .entries = {
-+ /* Card Opcode */
-+ XENTRY( GLOBAL, DEV_DESC ),
-+ XENTRY( GLOBAL, PCM_READ ),
-+ XENTRY( GLOBAL, SYNC_REPLY ),
-+ },
-+ .name = "GLOBAL",
-+ .packet_is_valid = global_packet_is_valid,
-+ .packet_dump = global_packet_dump,
-+};
-+
-+static bool global_packet_is_valid(xpacket_t *pack)
-+{
-+ const xproto_entry_t *xe;
-+
-+ //DBG("\n");
-+ xe = xproto_global_entry(pack->content.opcode);
-+ return xe != NULL;
-+}
-+
-+static void global_packet_dump(xpacket_t *pack)
-+{
-+ DBG("\n");
-+}
-+
-+static bool pcm_valid(xpd_t *xpd, xpacket_t *pack)
-+{
-+ xpp_line_t lines = RPACKET_FIELD(pack, GLOBAL, PCM_READ, lines);
-+ int i;
-+ int count = 0;
-+
-+ BUG_ON(!pack);
-+ BUG_ON(pack->content.opcode != XPROTO_NAME(GLOBAL, PCM_READ));
-+ for (i = 0; i < CHANNELS_PERXPD; i++)
-+ if(IS_SET(lines, i))
-+ count++;
-+ if(pack->datalen != (sizeof(xpp_line_t) + count * 8)) {
-+ static int rate_limit = 0;
-+
-+ XPD_COUNTER(xpd, RECV_ERRORS)++;
-+ if((rate_limit++ % 1000) <= 10) {
-+ ERR("BAD PCM REPLY: pack->datalen=%d, count=%d\n", pack->datalen, count);
-+ }
-+ return 0;
-+ }
-+ return 1;
-+}
-+
-diff -urNad zaptel-1.0.10/xpp/card_global.h /tmp/dpep.absTwN/zaptel-1.0.10/xpp/card_global.h
---- zaptel-1.0.10/xpp/card_global.h 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.absTwN/zaptel-1.0.10/xpp/card_global.h 2006-01-09 18:14:37.000000000 +0200
-@@ -0,0 +1,55 @@
-+#ifndef CARD_GLOBAL_H
-+#define CARD_GLOBAL_H
-+/*
-+ * Written by Oron Peled <oron at actcom.co.il>
-+ * Copyright (C) 2004-2005, Xorcom
-+ *
-+ * All rights reserved.
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License as published by
-+ * the Free Software Foundation; either version 2 of the License, or
-+ * (at your option) any later version.
-+ *
-+ * This program is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ * GNU General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-+ *
-+ */
-+
-+#include "xdefs.h"
-+
-+DEF_RPACKET_DATA(GLOBAL, DESC_REQ);
-+DEF_RPACKET_DATA(GLOBAL, DEV_DESC,
-+ byte rev; /* Revision number */
-+ byte type; /* LSB: 1 - to_phone, 0 - to_line */
-+ xpp_line_t line_status; /* hook/ring status, depending on unit */
-+ );
-+DEF_RPACKET_DATA(GLOBAL, PCM_WRITE,
-+ xpp_line_t lines; // Must be 0xFF
-+ byte pcm[PCM_CHUNKSIZE];
-+ );
-+DEF_RPACKET_DATA(GLOBAL, PCM_READ,
-+ xpp_line_t lines; // Must be 0xFF
-+ byte pcm[PCM_CHUNKSIZE];
-+ );
-+DEF_RPACKET_DATA(GLOBAL, SYNC_SOURCE,
-+ byte mask;
-+ );
-+DEF_RPACKET_DATA(GLOBAL, SYNC_REPLY,
-+ byte mask;
-+ );
-+
-+
-+/* 0x04 */ DECLARE_CMD(GLOBAL, DESC_REQ, int xpd_num);
-+/* 0x19 */ DECLARE_CMD(GLOBAL, SYNC_SOURCE, bool setit, bool is_master);
-+/* 0x11 */ DECLARE_CMD(GLOBAL, PCM_WRITE, xpp_line_t lines, volatile byte *buf);
-+
-+extern xproto_table_t PROTO_TABLE(GLOBAL);
-+
-+#endif /* CARD_GLOBAL_H */
-diff -urNad zaptel-1.0.10/xpp/cards.c /tmp/dpep.absTwN/zaptel-1.0.10/xpp/cards.c
---- zaptel-1.0.10/xpp/cards.c 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.absTwN/zaptel-1.0.10/xpp/cards.c 2006-01-12 12:30:09.638318611 +0200
-@@ -0,0 +1,394 @@
-+#include <linux/module.h>
-+#include "xpd.h"
-+#include "xpp_zap.h"
-+#include "xpp_proto.h"
-+#include "cards.h"
-+
-+static char rcsid[] = "$Id: cards.c 150 2005-12-12 09:27:57Z oron $";
-+
-+extern int print_dbg;
-+#include "zap_debug.h"
-+
-+#define MAX_SLIC_REGISTERS 100
-+
-+struct FXS_private_data {
-+ slic_reply_t last_slic_reply;
-+};
-+
-+/*------------------------- FXS Functions --------------------------*/
-+int FXS_card_new(xpd_t *xpd)
-+{
-+ xpd->direction = TO_PHONE;
-+ xpd->channels = min(8, CHANNELS_PERXPD);
-+ if(xpd->id == 0) {
-+ DBG("First XPD detected. Initialize digital outputs\n");
-+ xpd->channels += 2;
-+ xpd->digital_outputs = BIT(8) | BIT(9); // Two extra channels
-+ }
-+ return 0;
-+}
-+
-+int FXS_card_remove(xpd_t *xpd)
-+{
-+ return 0;
-+}
-+
-+static int FXS_card_startup(struct zt_span *span)
-+{
-+ DBG("\n");
-+ return 0;
-+}
-+
-+/*
-+ * Called only for 'span' keyword in /etc/zaptel.conf
-+ */
-+static int FXS_card_spanconfig(struct zt_span *span, struct zt_lineconfig *lc)
-+{
-+ xpd_t *xpd = span->pvt;
-+
-+ DBG("%s\n", xpd->xpdname);
-+ return 0;
-+}
-+
-+/* Set signalling type (if appropriate) */
-+static int FXS_card_chanconfig(struct zt_chan *chan, int sigtype)
-+{
-+ DBG("channel %d (%s), sigtype %d.\n", chan->channo, chan->name, sigtype);
-+ dump_sigtype(print_dbg, " ", sigtype);
-+ // FIXME: sanity checks:
-+ // - should be supported (within the sigcap)
-+ // - should not replace fxs <->fxo ??? (covered by previous?)
-+ return 0;
-+}
-+
-+/*
-+ * Called only for 'span' keyword in /etc/zaptel.conf
-+ */
-+static int FXS_card_shutdown(struct zt_span *span)
-+{
-+ xpd_t *xpd = span->pvt;
-+
-+ DBG("%s\n", xpd->xpdname);
-+ return 0;
-+}
-+
-+static int FXS_card_sethook(struct zt_chan *chan, int hookstate)
-+{
-+ int pos = chan->chanpos - 1;
-+ xpd_t *xpd = chan->pvt;
-+ xbus_t *xbus;
-+ int ret = 0;
-+
-+ if(!xpd) {
-+ ERR("%s: channel=%d without an XPD!\n", __FUNCTION__, pos);
-+ return -EINVAL;
-+ }
-+ xbus = xpd->xbus;
-+ // DBG("%s (%d) (old=0x%04X, hook-command=%d)\n", chan->name, pos, xpd->hookstate, hookstate);
-+ switch(hookstate) {
-+ /* On-hook, off-hook: The PBX is playing a phone on an FXO line.
-+ * Can be ignored for an FXS line
-+ */
-+ case ZT_ONHOOK:
-+ if(IS_SET(xpd->digital_outputs, pos)) {
-+ DBG("ZT_ONHOOK %s digital output OFF\n", chan->name);
-+ ret = CALL_PROTO(RELAY_OUT, xpd->xbus, xpd, pos-8, 0);
-+ return ret;
-+ }
-+ DBG("ZT_ONHOOK: %s hookstate=0x%04X (stop ringing pos=%d)\n", chan->name, xpd->hookstate, pos);
-+ xpd->ringing[pos] = 0;
-+#if 1 // FIXME: Not needed -- verify
-+ ret = CALL_PROTO(RING, xbus, xpd, pos, 0); // RING off
-+#endif
-+ ret = CALL_PROTO(LED, xpd->xbus, xpd, BIT(pos), LED_GREEN, 0);
-+ ret = CALL_PROTO(CHAN_POWER, xbus, xpd, BIT(pos), 0); // Power down (prevent overheating!!!)
-+ if(ret) {
-+ DBG("ZT_ONHOOK(stop ring) Failed: ret=0x%02X\n", ret);
-+ break;
-+ }
-+ break;
-+ case ZT_START:
-+ DBG("ZT_START: %s hookstate=0x%04X (fall through ZT_OFFHOOK)\n", chan->name, xpd->hookstate);
-+ // Fall through
-+ case ZT_OFFHOOK:
-+ DBG("ZT_OFFHOOK: %s hookstate=0x%04X -- ignoring (FXS)\n", chan->name, xpd->hookstate);
-+ break;
-+ case ZT_WINK:
-+ DBG("ZT_WINK %s\n", chan->name);
-+ break;
-+ case ZT_FLASH:
-+ DBG("ZT_FLASH %s\n", chan->name);
-+ break;
-+ case ZT_RING:
-+ DBG("ZT_RING %s pos=%d (ringing[pos]=%d)\n", chan->name, pos, xpd->ringing[pos]);
-+ if(IS_SET(xpd->digital_outputs, pos)) {
-+ DBG("ZT_ONHOOK %s digital output ON\n", chan->name);
-+ ret = CALL_PROTO(RELAY_OUT, xpd->xbus, xpd, pos-8, 1);
-+ return ret;
-+ }
-+ xpd->ringing[pos] = RINGS_NUM*2;
-+ ret = CALL_PROTO(CHAN_POWER, xbus, xpd, (1 << pos), 1); // Power up (for ring)
-+ ret = CALL_PROTO(RING, xbus, xpd, pos, 1); // RING on
-+ if(ret) {
-+ DBG("ZT_RING Failed: ret=0x%02X\n", ret);
-+ }
-+ break;
-+ case ZT_RINGOFF:
-+ DBG("ZT_RINGOFF %s\n", chan->name);
-+ break;
-+ default:
-+ DBG("UNKNOWN hookstate=0x%X\n", hookstate);
-+ }
-+ return ret;
-+}
-+
-+static int FXS_card_ioctl(struct zt_chan *chan, unsigned int cmd, unsigned long arg)
-+{
-+ switch (cmd) {
-+ default:
-+ return xpp_ioctl(chan, cmd, arg);
-+ }
-+ return 0;
-+}
-+
-+#if 0
-+int FXS_zaptel_setup(xpd_t *xpd)
-+{
-+ struct zt_chan *cur_chan;
-+ struct zt_span *span;
-+ xbus_t *xbus;
-+ int i;
-+ int cn;
-+
-+ BUG_ON(!xpd);
-+
-+ sigfxs = ! (xpd->direction == TO_PHONE); /* signaling is opposite */
-+ cn = xpd->channels;
-+ DBG("Initializing span: xpd %d have %d channels.\n", xpd->id, cn);
-+
-+ xpd->chans = kmalloc(sizeof(struct zt_chan)*cn, GFP_ATOMIC);
-+ if (xpd->chans == NULL) {
-+ ERR("xpd: Unable to allocate channels\n");
-+ return -ENOMEM;
-+ }
-+ memset(xpd->chans, 0, sizeof(struct zt_chan)*cn);
-+ memset(&xpd->span, 0, sizeof(struct zt_span));
-+
-+ span = &xpd->span;
-+ xbus = xpd->xbus;
-+ snprintf(span->name, MAX_SPANNAME, "%s/%s",
-+ xbus->busname, xpd->xpdname);
-+ {
-+ char tmp[MAX_SPANNAME];
-+ struct xpd_sim *sim = &xbus->sim[xpd->id];
-+
-+ if(sim->simulated)
-+ snprintf(tmp, MAX_SPANNAME, " (sim to=%d)", sim->loopto);
-+ else
-+ tmp[0] = '\0';
-+
-+ snprintf(span->desc, MAX_SPANDESC, "Xorcom XPD #%d/%d: %s%s",
-+ xbus->num, xpd->id,
-+ (xpd->direction == TO_PHONE) ? "FXS" : "FXO",
-+ tmp
-+ );
-+ }
-+ for(i = 0; i < cn; i++) {
-+
-+ cur_chan = &xpd->chans[i];
-+ DBG("setting channel %d\n", i);
-+ snprintf(cur_chan->name, MAX_CHANNAME, "XPP_FXS/%d-%d", xpd->id, i);
-+ cur_chan->chanpos = i + 1;
-+ cur_chan->pvt = xpd;
-+ cur_chan->sigcap =
-+#if 1
-+ ZT_SIG_FXOKS |
-+ ZT_SIG_FXOLS |
-+ ZT_SIG_FXOGS |
-+#else
-+ ZT_SIG_SF |
-+ ZT_SIG_EM |
-+#endif
-+ 0;
-+ }
-+ span->deflaw = ZT_LAW_MULAW;
-+ init_waitqueue_head(&span->maintq);
-+ span->pvt = xpd;
-+ span->channels = cn;
-+ span->chans = xpd->chans;
-+
-+ span->startup = FXS_xpp_startup;
-+ span->shutdown = FXS_xpp_shutdown;
-+ span->spanconfig = FXS_xpp_spanconfig;
-+ span->chanconfig = FXS_xpp_chanconfig;
-+ span->open = xpp_open;
-+ span->close = xpp_close;
-+#ifdef WITH_RBS
-+ span->flags = ZT_FLAG_RBS;
-+ span->hooksig = xpp_hooksig; /* Only with RBS bits */
-+#else
-+ span->sethook = FXS_xpp_sethook;
-+#endif
-+ span->ioctl = FXS_xpp_ioctl;
-+ span->maint = xpp_maint;
-+#ifdef CONFIG_ZAPTEL_WATCHDOG
-+ span->watchdog = xpp_watchdog;
-+#endif
-+
-+ return 0;
-+}
-+#endif
-+
-+int FXS_zaptel_cleanup(xpd_t *xpd)
-+{
-+ return 0;
-+}
-+
-+/*------------------------- FXO Functions --------------------------*/
-+static int FXO_card_new(xpd_t *xpd)
-+{
-+ xpd->direction = TO_TRUNK;
-+ xpd->channels = min(8, CHANNELS_PERXPD);
-+ return 0;
-+}
-+
-+static int FXO_card_remove(xpd_t *xpd)
-+{
-+ return 0;
-+}
-+
-+static int FXO_card_startup(struct zt_span *span)
-+{
-+ DBG("\n");
-+ return 0;
-+}
-+
-+/*
-+ * Called only for 'span' keyword in /etc/zaptel.conf
-+ */
-+static int FXO_card_spanconfig(struct zt_span *span, struct zt_lineconfig *lc)
-+{
-+ xpd_t *xpd = span->pvt;
-+
-+ DBG("%s\n", xpd->xpdname);
-+ return 0;
-+}
-+
-+/* Set signalling type (if appropriate) */
-+static int FXO_card_chanconfig(struct zt_chan *chan, int sigtype)
-+{
-+ DBG("channel %d (%s), sigtype %d.\n", chan->channo, chan->name, sigtype);
-+ dump_sigtype(print_dbg, " ", sigtype);
-+ // FIXME: sanity checks:
-+ // - should be supported (within the sigcap)
-+ // - should not replace fxs <->fxo ??? (covered by previous?)
-+ return 0;
-+}
-+
-+/*
-+ * Called only for 'span' keyword in /etc/zaptel.conf
-+ */
-+static int FXO_card_shutdown(struct zt_span *span)
-+{
-+ xpd_t *xpd = span->pvt;
-+
-+ DBG("%s\n", xpd->xpdname);
-+ return 0;
-+}
-+
-+
-+static int FXO_card_sethook(struct zt_chan *chan, int hookstate)
-+{
-+ int pos = chan->chanpos - 1;
-+ xpd_t *xpd = chan->pvt;
-+ xbus_t *xbus;
-+ int ret = 0;
-+
-+ BUG_ON(!xpd);
-+ xbus = xpd->xbus;
-+ // DBG("%s (%d) (old=0x%04X, hook-command=%d)\n", chan->name, pos, xpd->hookstate, hookstate);
-+ switch(hookstate) {
-+ /* On-hook, off-hook: The PBX is playing a phone on an FXO line.
-+ * Can be ignored for an FXS line
-+ */
-+ case ZT_ONHOOK:
-+ if(IS_SET(xpd->digital_outputs, pos)) {
-+ DBG("ZT_ONHOOK %s digital output OFF\n", chan->name);
-+ ret = CALL_PROTO(RELAY_OUT, xpd->xbus, xpd, pos-8, 0);
-+ return ret;
-+ }
-+ DBG("ZT_ONHOOK: %s hookstate=0x%04X (pos=%d)\n", chan->name, xpd->hookstate, pos);
-+ xpd->ringing[pos] = 0;
-+ BIT_CLR(xpd->hookstate, pos);
-+ ret = CALL_PROTO(SETHOOK, xbus, xpd, xpd->hookstate);
-+ if(ret) {
-+ DBG("ZT_ONHOOK Failed: ret=0x%02X\n", ret);
-+ break;
-+ }
-+ break;
-+ case ZT_START:
-+ DBG("ZT_START: %s hookstate=0x%04X (fall through ZT_OFFHOOK)\n", chan->name, xpd->hookstate);
-+ // Fall through
-+ case ZT_OFFHOOK:
-+ DBG("ZT_OFFHOOK: %s hookstate=0x%04X (pos=%d)\n", chan->name, xpd->hookstate, pos);
-+ BIT_SET(xpd->hookstate, pos);
-+ xpd->ringing[pos] = 0;
-+ ret = CALL_PROTO(SETHOOK, xbus, xpd, xpd->hookstate);
-+ if(ret) {
-+ DBG("ZT_OFFHOOK Failed: ret=0x%02X\n", ret);
-+ break;
-+ }
-+ break;
-+ case ZT_WINK:
-+ DBG("ZT_WINK %s\n", chan->name);
-+ break;
-+ case ZT_FLASH:
-+ DBG("ZT_FLASH %s\n", chan->name);
-+ break;
-+ case ZT_RING:
-+ DBG("ZT_RING %s pos=%d (ringing[pos]=%d)\n", chan->name, pos, xpd->ringing[pos]);
-+ break;
-+ case ZT_RINGOFF:
-+ DBG("ZT_RINGOFF %s\n", chan->name);
-+ break;
-+ default:
-+ DBG("UNKNOWN hookstate=0x%X\n", hookstate);
-+ }
-+ return ret;
-+}
-+
-+static int FXO_card_ioctl(struct zt_chan *chan, unsigned int cmd, unsigned long arg)
-+{
-+ switch (cmd) {
-+ default:
-+ return xpp_ioctl(chan, cmd, arg);
-+ }
-+ return 0;
-+}
-+
-+
-+/*------------------------- Function table -------------------------*/
-+
-+#define DEF_(t) \
-+ [XPD_TYPE_ ## t] { \
-+ .card_new = t ## _card_new, \
-+ .card_remove = t ## _card_remove, \
-+ .card_startup = t ## _card_startup, \
-+ .card_shutdown = t ## _card_shutdown, \
-+ .card_spanconfig = t ## _card_spanconfig, \
-+ .card_chanconfig = t ## _card_chanconfig, \
-+ .card_sethook = t ## _card_sethook, \
-+ .card_ioctl = t ## _card_ioctl, \
-+ }
-+
-+xops_t xpd_card_ops[XPD_TYPE_NOMODULE] = {
-+ DEF_(FXS),
-+ DEF_(FXO)
-+};
-+
-+xops_t *get_xops(xpd_type_t xpd_type)
-+{
-+ if(xpd_type >= XPD_TYPE_NOMODULE)
-+ return NULL;
-+ return &xpd_card_ops[xpd_type];
-+}
-diff -urNad zaptel-1.0.10/xpp/cards.h /tmp/dpep.absTwN/zaptel-1.0.10/xpp/cards.h
---- zaptel-1.0.10/xpp/cards.h 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.absTwN/zaptel-1.0.10/xpp/cards.h 2006-01-12 12:30:09.638318611 +0200
-@@ -0,0 +1,23 @@
-+#ifndef CARDS_H
-+#define CARDS_H
-+
-+#include "xpd.h"
-+
-+struct xpd_card_ops {
-+ int (*card_new)(xpd_t *xpd);
-+ int (*card_remove)(xpd_t *xpd);
-+#if 0
-+ int (*zaptel_setup)(xpd_t *xpd);
-+ int (*zaptel_cleanup)(xpd_t *xpd);
-+#endif
-+ int (*card_startup)(struct zt_span *span);
-+ int (*card_shutdown)(struct zt_span *span);
-+ int (*card_spanconfig)(struct zt_span *span, struct zt_lineconfig *lc);
-+ int (*card_chanconfig)(struct zt_chan *chan, int sigtype);
-+ int (*card_sethook)(struct zt_chan *chan, int hookstate);
-+ int (*card_ioctl)(struct zt_chan *chan, unsigned int cmd, unsigned long arg);
-+};
-+
-+xops_t *get_xops(xpd_type_t xpd_type);
-+
-+#endif /* CARDS_H */
-diff -urNad zaptel-1.0.10/xpp/FPGA_XPD.hex /tmp/dpep.absTwN/zaptel-1.0.10/xpp/FPGA_XPD.hex
---- zaptel-1.0.10/xpp/FPGA_XPD.hex 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.absTwN/zaptel-1.0.10/xpp/FPGA_XPD.hex 2006-01-09 18:14:37.000000000 +0200
-@@ -0,0 +1,243 @@
-+:0A0B3C000001020203030404050592
-+:100546005010C0C0F9A4B0999282F880988883C6EA
-+:03055600A1868EED
-+:1002B700E4F513F512F511F510C203C200C202C22C
-+:1002C700011206377E077F008E238F24752B077553
-+:1002D7002C1275210775221C752907752A4A752D59
-+:1002E70007752E78EE54C070030203B875140075B5
-+:1002F70015808E168F17C374C09FFF74079ECF2477
-+:1003070002CF3400FEE48F0F8E0EF50DF50CF50BC2
-+:10031700F50AF509F508AF0FAE0EAD0DAC0CAB0B3A
-+:10032700AA0AA909A808C3120B205033E517250B01
-+:10033700F582E516350AF583E0FFE515250BF5820D
-+:10034700E514350AF583EFF0E50B2401F50BE435E9
-+:100357000AF50AE43509F509E43508F50880B78593
-+:10036700142385152474002480FF740734FFFEC30B
-+:10037700E52C9FF52CE52B9EF52BC3E5269FF5264F
-+:10038700E5259EF525C3E5289FF528E5279EF52752
-+:10039700C3E5229FF522E5219EF521C3E52A9FF5B6
-+:1003A7002AE5299EF529C3E52E9FF52EE52D9EF515
-+:1003B7002DD2E843D82090E668E0440BF090E65C45
-+:1003C700E0443DF0000000000000E4F5A20000005A
-+:1003D700D2AF90E680E020E105D2041206D090E685
-+:1003E70080E054F7F0538EF8C20390E6C2E054FB66
-+:1003F700F000000000000090E6187410F000000004
-+:1004070090E61A7408F000000090E6017403F0000B
-+:100417000000300105120080C2013003F5120B5AAB
-+:1004270050F0C203120A7B20001690E682E030E704
-+:1004370004E020E1EF90E682E030E604E020E0E42B
-+:080447001209FC120B5C80CAD3
-+:0B0B310090E50DE030E402C322D32267
-+:1000800090E6B9E0700302013F1470030201BC2442
-+:10009000FE700302023F24FB700302013914700357
-+:1000A00002013314700302012714700302012D248E
-+:1000B0000560030202A3120B5E40030202AF90E64A
-+:1000C000BBE024FE602714603824FD601114602713
-+:1000D00024067050E52390E6B3F0E524803C120B33
-+:1000E00031503EE52B90E6B3F0E52C802DE52590D0
-+:1000F000E6B3F0E5268023E52790E6B3F0E5288017
-+:100100001990E6BAE0FF120A28AA06A9077B01EABD
-+:10011000494B600DEE90E6B3F0EF90E6B4F00202CA
-+:10012000AF02029E02029E120B0E0202AF120B4E93
-+:100130000202AF120B460202AF120AFC0202AF1219
-+:100140000B6040030202AF90E6B8E0247F60151414
-+:10015000601924027063A200E43325E0FFA202E4E8
-+:10016000334F8041E490E740F0803F90E6BCE0549C
-+:100170007EFF7E00E0D394807C0040047D018002FD
-+:100180007D00EC4EFEED4F243CF582740B3EF58372
-+:10019000E493FF3395E0FEEF24A1FFEE34E68F8277
-+:1001A000F583E0540190E740F0E4A3F090E68AF094
-+:1001B00090E68B7402F00202AF02029E120B6240C4
-+:1001C000030202AF90E6B8E024FE6016240260034A
-+:1001D0000202AF90E6BAE0B40105C2000202AF022B
-+:1001E000029E90E6BAE0705590E6BCE0547EFF7E39
-+:1001F00000E0D394807C0040047D0180027D00EC0F
-+:100200004EFEED4F243CF582740B3EF583E493FFE4
-+:100210003395E0FEEF24A1FFEE34E68F82F583E014
-+:1002200054FEF090E6BCE05480131313541FFFE01B
-+:10023000540F2F90E683F0E04420F08072805F122C
-+:100240000B64506B90E6B8E024FE60192402704EF7
-+:1002500090E6BAE0B40104D200805490E6BAE064BB
-+:1002600002604C803990E6BCE0547EFF7E00E0D313
-+:1002700094807C0040047D0180027D00EC4EFEED08
-+:100280004F243CF582740B3EF583E493FF3395E0F5
-+:10029000FEEF24A1FFEE34E68F82F583800D90E619
-+:1002A000A08008120A53500790E6A0E04401F090A5
-+:0602B000E6A0E04480F02E
-+:0102B6002225
-+:03003300020B5667
-+:040B560053D8EF324F
-+:100700001201000200000040E4E411220000010296
-+:1007100000010A06000200000040010009022E004C
-+:1007200001010080320904000004FF0000000705F9
-+:10073000020200020007050402000200070586020B
-+:100740000002000705880200020009022E000101D4
-+:100750000080320904000004FF00000007050202C7
-+:100760004000000705040240000007058602400023
-+:100770000007058802400000040309041C0341002F
-+:100780007300740072006900620061006E006B000B
-+:10079000320030003000360028035800500044007A
-+:1007A00028004200610073006500640020006F00B3
-+:1007B0006E002000410058005500500050002900F4
-+:0207C000000037
-+:100559005010B0C0F9A4B0999282F880988883C6E7
-+:10056900A1868E4110ABFF4110AD004110AEFF4195
-+:0705790010AC004110AF00BF
-+:1006370090E600E054E74410F000000090E60474F0
-+:1006470080F00000007406F0000000E4F0000000F5
-+:1006570090E610F090E611F000000090E613F0002D
-+:10066700000090E615F090E61074A0F090E611F007
-+:1006770000000000000090E61274AAF0000000904D
-+:10068700E61474EAF000000090E6047480F00000BD
-+:10069700007404F0000000E4F000000090E64974E4
-+:1006A70082F0000000F000000090E6187410F000DF
-+:1006B700000090E61A7408F090E6917480F000004C
-+:0906C70000F000000043AF012225
-+:020B5A00D322A4
-+:020B5C00D322A2
-+:020B5E00D322A0
-+:080B460090E6BAE0F51BD32292
-+:100AFC0090E740E51BF0E490E68AF090E68B04F07A
-+:020B0C00D322F2
-+:080B4E0090E6BAE0F51AD3228B
-+:100B0E0090E740E51AF0E490E68AF090E68B04F068
-+:020B1E00D322E0
-+:020B6000D3229E
-+:020B6200D3229C
-+:020B6400D3229A
-+:100A530090E6B9E0242F600D04701990E604E0FFDE
-+:100A6300430780800890E604E0FF53077F000000FF
-+:070A7300EFF08002D322C363
-+:010A7A002259
-+:100AA000C0E0C083C082D2015391EF90E65D740133
-+:080AB000F0D082D083D0E032C7
-+:100AD000C0E0C083C0825391EF90E65D7404F0D013
-+:060AE00082D083D0E03259
-+:100AE600C0E0C083C0825391EF90E65D7402F0D0FF
-+:060AF60082D083D0E03243
-+:1009C600C0E0C083C082852925852A2685268285A2
-+:1009D6002583A37402F08521278522288528828510
-+:1009E6002783A37407F05391EF90E65D7410F0D05F
-+:0609F60082D083D0E03244
-+:100AB800C0E0C083C082D2035391EF90E65D740812
-+:080AC800F0D082D083D0E032AF
-+:1007C200C0E0C083C08290E680E030E7208521252A
-+:1007D200852226852682852583A37402F085292712
-+:1007E200852A28852882852783A37407F05391EFF1
-+:0D07F20090E65D7420F0D082D083D0E0321C
-+:0106FF0032C8
-+:0107FF0032C7
-+:010B6600325C
-+:010B6700325B
-+:010B6800325A
-+:010B69003259
-+:010B6A003258
-+:010B6B003257
-+:010B6C003256
-+:010B6D003255
-+:010B6E003254
-+:010B6F003253
-+:010B70003252
-+:010B71003251
-+:010B72003250
-+:010B7300324F
-+:010B7400324E
-+:010B7500324D
-+:010B7600324C
-+:010B7700324B
-+:010B7800324A
-+:010B79003249
-+:010B7A003248
-+:010B7B003247
-+:010B7C003246
-+:010B7D003245
-+:010B7E003244
-+:010B7F003243
-+:010B80003242
-+:010B81003241
-+:010B82003240
-+:010B8300323F
-+:010B8400323E
-+:010B8500323D
-+:10098A00C0E0C083C08290E6D1E09010ACF090E65F
-+:10099A00D0E4F000000090E6D17402F000000053A9
-+:1009AA0091BF00000090E66104F000000090E69913
-+:0C09BA0004F075BB06D082D083D0E03280
-+:010B8600323C
-+:03004300020800B0
-+:03005300020800A0
-+:10080000020AA000020AE600020AD000020AB800AA
-+:100810000209C6000207C2000206FF000207FF002D
-+:10082000020B6600020B6700020B6800020B6900F6
-+:10083000020B6A00020B6B00020B6C00020B6D00D6
-+:10084000020B6E000207FF00020B6F00020B70002C
-+:10085000020B7100020B7200020B7300020B74009A
-+:10086000020B75000207FF000207FF000207FF00EE
-+:10087000020B7600020B7700020B7800020B790066
-+:10088000020B7A00020B7B00020B7C00020B7D0046
-+:10089000020B7E00020B7F00020B8000020B810026
-+:1008A000020B8200020B8300020B8400020B850006
-+:0808B00002098A00020B860018
-+:1009FC0090E682E030E004E020E60B90E682E03006
-+:100A0C00E119E030E71590E680E04401F07F147EB8
-+:0C0A1C000012094490E680E054FEF02235
-+:1006D00030040990E680E0440AF0800790E680E06C
-+:1006E0004408F07FDC7E0512094490E65D74FFF05B
-+:0F06F00090E65FF05391EF90E680E054F7F02230
-+:020A2800A9071C
-+:100A2A00AE2DAF2E8F828E83A3E064037017AD01C3
-+:100A3A0019ED7001228F828E83E07C002FFDEC3E3F
-+:080A4A00FEAF0580DFE4FEFFB2
-+:010A52002281
-+:100A7B0090E682E044C0F090E681F04387010000ED
-+:040A8B000000002245
-+:100944008E188F1990E600E054187012E5192401EE
-+:10095400FFE43518C313F518EF13F519801590E665
-+:1009640000E05418FFBF100BE51925E0F519E51850
-+:1009740033F518E5191519AE18700215184E6005EF
-+:06098400120A8F80EE2232
-+:100A8F007400F58690FDA57C05A3E582458370F97A
-+:010A9F002234
-+:1005800060801000011113213C01010703030305E2
-+:10059000010000000C0D0C0C0E0E0E0E410000367A
-+:1005A0000900003F010A013B0101010701010201AD
-+:1005B0000000000002020000020202024049004066
-+:1005C0000000003F010101010101010700000000DE
-+:1005D000000000000E0E0E0E0E0E0E0E00000000AB
-+:1005E0000000003F0139010101010107000302027F
-+:1005F000020202020E0E0E0E0E0E0E0E002D000056
-+:100600000000003F60241087000000000000000090
-+:1006100000000000000000000000833611170004F5
-+:10062000030201813616170004030201471080E01F
-+:0606300000000ECE4E009A
-+:10044F0090E60174CEF090E6F574FFF0901080E026
-+:10045F0090E6F3F0901081E090E6C3F0901082E008
-+:10046F0090E6C1F0901083E090E6C2F0901085E026
-+:10047F0090E6C0F0901086E090E6F4F075AF077448
-+:10048F0010F59A7400F59B759DE4E4F59EFF90E6D8
-+:10049F007BE090E67CF00FBF80F490E67174FFF084
-+:1004AF00F5B490E672E04480F043B680000000E4BB
-+:1004BF0090E6C4F000000090E6C5F0901087E09041
-+:1004CF00E6C6F0901088E090E6C7F0901089E090B3
-+:1004DF00E6C8F090108AE090E6C9F090108BE0909B
-+:1004EF00E6CAF090108CE090E6CBF090108DE09083
-+:1004FF00E6CCF090108EE090E6CDF000000090E694
-+:10050F00D27401F000000090E6E204F00000000059
-+:10051F00000090E6EB14F000000000000000000067
-+:10052F0090E6C0F090E6C1F090E6247408F0000069
-+:06053F0000E490E625F047
-+:010545002293
-+:030000000208B83B
-+:0C08B800787FE4F6D8FD75812E0208FF61
-+:100B2000EB9FF5F0EA9E42F0E99D42F0E89C45F02B
-+:010B300022A2
-+:1008C4000202B7E493A3F8E493A34003F68001F291
-+:1008D40008DFF48029E493A3F85407240CC8C33335
-+:1008E400C4540F4420C8834004F456800146F6DF04
-+:1008F400E4800B0102040810204080900546E47E49
-+:10090400019360BCA3FF543F30E509541FFEE493F8
-+:10091400A360010ECF54C025E060A840B8E493A3BF
-+:10092400FAE493A3F8E493A3C8C582C8CAC583CAEA
-+:10093400F0A3C8C582C8CAC583CADFE9DEE780BEA2
-+:0106360000C3
-+:00000001FF
-diff -urNad zaptel-1.0.10/xpp/gen_slic_init /tmp/dpep.absTwN/zaptel-1.0.10/xpp/gen_slic_init
---- zaptel-1.0.10/xpp/gen_slic_init 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.absTwN/zaptel-1.0.10/xpp/gen_slic_init 2006-01-09 18:14:37.000000000 +0200
-@@ -0,0 +1,37 @@
-+#! /usr/bin/perl -w
-+
-+use strict;
-+
-+my $input;
-+my $header;
-+my $comment;
-+
-+ at ARGV == 2 or die "Usage: $0 <infile> <outfile>\n";
-+$input = $ARGV[0];
-+$header = $ARGV[1];
-+open(IF, "$input") or die "Failed to write '$input': $!\n";
-+open(HF, ">$header") or die "Failed to write '$header': $!\n";
-+
-+while(<IF>) {
-+ chomp;
-+ undef $comment;
-+ s/\r//; # CRLF -> LF
-+ if(s/\s*[;#]\s*(.*?)$//) { # Comments
-+ $comment = $1;
-+ }
-+ if(/^\s*$/) { # Empty lines
-+ next;
-+ }
-+ my ($slic0, $slic1, $slic2, $slic3, $len, @data) = split;
-+ die "Bad input (len=$len)" if hex($len) != @data;
-+ my $slic = "$slic3$slic2$slic1$slic0";
-+ die "Bad slic address '$slic'" if length($slic) != 8;
-+ grep(s/\w+/0x$&/g, ($slic, $len, @data));
-+ my $str = join(", ", @data);
-+ print HF "S_($slic,\t$len,\t$str),\t";
-+} continue {
-+ if(defined($comment)) {
-+ print HF "// $comment";
-+ }
-+ print HF "\n";
-+}
-diff -urNad zaptel-1.0.10/xpp/Makefile /tmp/dpep.absTwN/zaptel-1.0.10/xpp/Makefile
---- zaptel-1.0.10/xpp/Makefile 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.absTwN/zaptel-1.0.10/xpp/Makefile 2006-01-09 18:14:36.000000000 +0200
-@@ -0,0 +1,5 @@
-+EXTRA_CFLAGS = -I$(src)/..
-+
-+obj-m = xpd_fxs.o xpp.o xpp_usb.o
-+xpp-y += xproto.o card_global.o xpp_zap.o zap_debug.o
-+xpd_fxs-y += card_fxs.o slic.o
-diff -urNad zaptel-1.0.10/xpp/slic.c /tmp/dpep.absTwN/zaptel-1.0.10/xpp/slic.c
---- zaptel-1.0.10/xpp/slic.c 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.absTwN/zaptel-1.0.10/xpp/slic.c 2006-01-09 18:14:37.000000000 +0200
-@@ -0,0 +1,129 @@
-+/*
-+ * Written by Oron Peled <oron at actcom.co.il>
-+ * Copyright (C) 2004-2005, Xorcom
-+ *
-+ * All rights reserved.
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License as published by
-+ * the Free Software Foundation; either version 2 of the License, or
-+ * (at your option) any later version.
-+ *
-+ * This program is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ * GNU General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-+ *
-+ */
-+
-+#include "xproto.h"
-+#include "slic.h"
-+
-+static const char rcsid[] = "$Id: slic.c 161 2006-01-03 09:13:40Z oron $";
-+
-+#ifdef __KERNEL__
-+#include <linux/module.h>
-+
-+extern int print_dbg;
-+#include "zap_debug.h"
-+#else
-+#include <stdio.h>
-+#endif
-+
-+int slic_cmd_direct_write(slic_cmd_t *sc, xpp_line_t lines, byte reg, byte data)
-+{
-+ struct slic_reg_d *p = (struct slic_reg_d *)&sc->content;
-+
-+ sc->lines = lines;
-+ sc->bytes = sizeof(struct slic_reg_d);
-+ SLIC_REG_INIT(p, 0, reg, data);
-+ return sizeof(xpp_line_t) + 1 + sc->bytes;
-+}
-+
-+int slic_cmd_direct_read(slic_cmd_t *sc, xpp_line_t lines, byte reg)
-+{
-+ struct slic_reg_d *p = (struct slic_reg_d *)&sc->content;
-+
-+ sc->lines = lines;
-+ sc->bytes = sizeof(struct slic_reg_d);
-+ SLIC_REG_INIT(p, 1, reg, 0);
-+ return sizeof(xpp_line_t) + 1 + sc->bytes;
-+}
-+
-+int slic_cmd_indirect_write(slic_cmd_t *sc, xpp_line_t lines, byte reg, byte data_low, byte data_high)
-+{
-+ struct slic_reg_iw *p = (struct slic_reg_iw *)&sc->content;
-+
-+ sc->lines = lines;
-+ sc->bytes = sizeof(struct slic_reg_iw);
-+ SLIC_REG_INIT(&p->iw_data_low, 0, 0x1C, data_low);
-+ SLIC_REG_INIT(&p->iw_data_high, 0, 0x1D, data_high);
-+ SLIC_REG_INIT(&p->iw_reg, 0, 0x1E, reg);
-+ return sizeof(xpp_line_t) + 1 + sc->bytes;
-+}
-+
-+int slic_cmd_indirect_read(slic_cmd_t *sc, xpp_line_t lines, byte reg)
-+{
-+ struct slic_reg_ir *p = (struct slic_reg_ir *)&sc->content;
-+
-+ sc->lines = lines;
-+ sc->bytes = sizeof(struct slic_reg_ir);
-+ SLIC_REG_INIT(&p->ir_reg, 0, 0x1E, reg);
-+ return sizeof(xpp_line_t) + 1 + sc->bytes;
-+}
-+
-+void dump_slic_cmd(const char msg[], slic_cmd_t *sc)
-+{
-+ int i;
-+ struct slic_reg_d *sr;
-+ int last_data_low = -1;
-+ int last_data_high = -1;
-+
-+ sr = (struct slic_reg_d *)&sc->content;
-+ if(sc->bytes > sizeof(sc->content)) {
-+ NOTICE("%s: Bug: sc->bytes = %d\n", __FUNCTION__, sc->bytes);
-+ return;
-+ }
-+ if(sc->bytes % 2) {
-+ NOTICE("%s: Bug: ODD sc->bytes = %d\n", __FUNCTION__, sc->bytes);
-+ return;
-+ }
-+ for(i = 0; i < sc->bytes/2; i++, sr++) {
-+ if(sr->reg_num == 0x1C) {
-+ last_data_low = sr->reg_data;
-+ continue;
-+ }
-+ if(sr->reg_num == 0x1D) {
-+ last_data_high = sr->reg_data;
-+ continue;
-+ }
-+ if(sr->reg_num == 0x1E) {
-+ if(last_data_low == -1 && last_data_high == -1) // Indirect Read
-+ DBG("%s: LINES=0x%08X bytes=%d INDIRECT READ: register=0x%02X\n", msg, sc->lines, sc->bytes, sr->reg_data);
-+ else if(last_data_low == -1 || last_data_high == -1) {
-+ NOTICE("%s: BUG: PARTIAL INDIRECT: register=%d last_data_low=0x%X last_data_high=0x%X\n",
-+ msg, sr->reg_data, last_data_low, last_data_high);
-+ } else
-+ DBG("%s: LINES=0x%08X bytes=%d INDIRECT WRITE: register=%d data_low=0x%02x data_high=0x%02X\n",
-+ msg, sc->lines, sc->bytes, sr->reg_data, (byte)last_data_low, (byte)last_data_high);
-+ last_data_low = last_data_high = -1;
-+ } else {
-+ DBG("%s: LINES=0x%08X bytes=%d DIRECT %s: register=%d data=0x%02X\n",
-+ msg, sc->lines, sc->bytes, (sr->read) ? "READ" : "WRITE", sr->reg_num, sr->reg_data);
-+ }
-+ }
-+}
-+
-+#ifdef __KERNEL__
-+
-+EXPORT_SYMBOL(slic_cmd_direct_write);
-+EXPORT_SYMBOL(slic_cmd_direct_read);
-+EXPORT_SYMBOL(slic_cmd_indirect_write);
-+EXPORT_SYMBOL(slic_cmd_indirect_read);
-+EXPORT_SYMBOL(dump_slic_cmd);
-+
-+#endif
-diff -urNad zaptel-1.0.10/xpp/slic.h /tmp/dpep.absTwN/zaptel-1.0.10/xpp/slic.h
---- zaptel-1.0.10/xpp/slic.h 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.absTwN/zaptel-1.0.10/xpp/slic.h 2006-01-09 18:14:37.000000000 +0200
-@@ -0,0 +1,65 @@
-+#ifndef SLIC_H
-+#define SLIC_H
-+
-+#include "xdefs.h"
-+
-+/*------------------------------ SLIC Data Structures ----------------------*/
-+
-+struct slic_reg_d { /* SLIC Register Direct Read/Write */
-+ byte reg_num:7;
-+ byte read:1;
-+ byte reg_data;
-+} __attribute__((packed));
-+
-+struct slic_reg_iw { /* SLIC Register Indirect-Write */
-+ struct slic_reg_d iw_data_low;
-+ struct slic_reg_d iw_data_high;
-+ struct slic_reg_d iw_reg;
-+} __attribute__((packed));
-+
-+struct slic_reg_ir { /* SLIC Register Indirect-Read */
-+ struct slic_reg_d ir_reg;
-+} __attribute__((packed));
-+
-+typedef struct slic_cmd {
-+ xpp_line_t lines;
-+ byte bytes;
-+ union {
-+ struct slic_reg_d direct;
-+ struct slic_reg_iw indirect_write;
-+ struct slic_reg_ir indirect_read;
-+ } content;
-+} __attribute__((packed)) slic_cmd_t;
-+
-+typedef struct slic_reply {
-+ byte size;
-+ byte reg_num:7;
-+ byte indirect:1;
-+ byte data_low;
-+ byte data_high;
-+} __attribute__((packed)) slic_reply_t;
-+
-+#define SLIC_REG_INIT(slic_reg, reading, num, data) \
-+ do { \
-+ (slic_reg)->read = reading; \
-+ (slic_reg)->reg_num = num; \
-+ (slic_reg)->reg_data = data; \
-+ } while(0);
-+
-+/* OLD SLIC_INIT data */
-+typedef struct slic_data {
-+ byte len;
-+ byte data[40];
-+} __attribute__((packed)) slic_data_t;
-+
-+
-+/*------------------------------ SLIC Initializers -------------------------*/
-+
-+int slic_cmd_direct_write(slic_cmd_t *sc, xpp_line_t lines, byte reg, byte data);
-+int slic_cmd_direct_read(slic_cmd_t *sc, xpp_line_t lines, byte reg);
-+int slic_cmd_indirect_write(slic_cmd_t *sc, xpp_line_t lines, byte reg, byte data_low, byte data_high);
-+int slic_cmd_indirect_read(slic_cmd_t *sc, xpp_line_t lines, byte reg);
-+void dump_slic_cmd(const char msg[], slic_cmd_t *sc);
-+
-+
-+#endif /* SLIC_H */
-diff -urNad zaptel-1.0.10/xpp/slic_init.inc /tmp/dpep.absTwN/zaptel-1.0.10/xpp/slic_init.inc
---- zaptel-1.0.10/xpp/slic_init.inc 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.absTwN/zaptel-1.0.10/xpp/slic_init.inc 2006-01-11 10:12:53.000000000 +0200
-@@ -0,0 +1,65 @@
-+// ----------------------------------==== 8-channel FXS unit initialization ===-----------------------------------------
-+
-+// INTERNAL PS
-+// Change SLICs states to "Open state"s (Off,all transfers tristated to avoid data collision), Voltage sense
-+S_(0x000000FF, 0x04, 0x40, 0x00, 0x6C, 0x01),
-+
-+
-+// ------------------------------------- Initialization of indirect registers ------------------------------------------
-+S_(0x000000FF, 0x02, 0x40, 0x00),
-+S_(0x000000FF, 0x18, 0x1C, 0xC2, 0x1D, 0x55, 0x1E, 0x00, 0x1C, 0xE6, 0x1D, 0x51, 0x1E, 0x01, 0x1C, 0x85, 0x1D, 0x4B, 0x1E, 0x02, 0x1C, 0x37, 0x1D, 0x49, 0x1E, 0x03),
-+S_(0x000000FF, 0x18, 0x1C, 0x33, 0x1D, 0x33, 0x1E, 0x04, 0x1C, 0x02, 0x1D, 0x02, 0x1E, 0x05, 0x1C, 0x02, 0x1D, 0x02, 0x1E, 0x06, 0x1C, 0x98, 0x1D, 0x01, 0x1E, 0x07),
-+S_(0x000000FF, 0x18, 0x1C, 0x98, 0x1D, 0x01, 0x1E, 0x08, 0x1C, 0x11, 0x1D, 0x06, 0x1E, 0x09, 0x1C, 0x02, 0x1D, 0x02, 0x1E, 0x0A, 0x1C, 0xE5, 0x1D, 0x00, 0x1E, 0x0B),
-+S_(0x000000FF, 0x18, 0x1C, 0x1C, 0x1D, 0x0A, 0x1E, 0x0C, 0x1C, 0x30, 0x1D, 0x7B, 0x1E, 0x0D, 0x1C, 0x63, 0x1D, 0x00, 0x1E, 0x0E, 0x1C, 0x00, 0x1D, 0x00, 0x1E, 0x0F),
-+
-+S_(0x000000FF, 0x18, 0x1C, 0x70, 0x1D, 0x78, 0x1E, 0x10, 0x1C, 0x7D, 0x1D, 0x00, 0x1E, 0x11, 0x1C, 0x00, 0x1D, 0x00, 0x1E, 0x12, 0x1C, 0x00, 0x1D, 0x00, 0x1E, 0x13),
-+S_(0x000000FF, 0x18, 0x1C, 0xF0, 0x1D, 0x7E, 0x1E, 0x14, 0x1C, 0x60, 0x1D, 0x01, 0x1E, 0x15, 0x1C, 0x00, 0x1D, 0x00, 0x1E, 0x16, 0x1C, 0x00, 0x1D, 0x20, 0x1E, 0x17),
-+S_(0x000000FF, 0x18, 0x1C, 0x00, 0x1D, 0x20, 0x1E, 0x18, 0x1C, 0x00, 0x1D, 0x00, 0x1E, 0x19, 0x1C, 0x00, 0x1D, 0x40, 0x1E, 0x1A, 0x1C, 0x00, 0x1D, 0x40, 0x1E, 0x1B),
-+S_(0x000000FF, 0x18, 0x1C, 0x00, 0x1D, 0x18, 0x1E, 0x1C, 0x1C, 0x00, 0x1D, 0x40, 0x1E, 0x1D, 0x1C, 0x00, 0x1D, 0x10, 0x1E, 0x1E, 0x1C, 0x80, 0x1D, 0x00, 0x1E, 0x1F),
-+
-+S_(0x000000FF, 0x18, 0x1C, 0xF4, 0x1D, 0x0F, 0x1E, 0x20, 0x1C, 0x7E, 0x1D, 0x6E, 0x1E, 0x21, 0x1C, 0xF4, 0x1D, 0x0F, 0x1E, 0x22, 0x1C, 0x00, 0x1D, 0x88, 0x1E, 0x23),
-+S_(0x000000FF, 0x18, 0x1C, 0x20, 0x1D, 0x03, 0x1E, 0x24, 0x1C, 0x12, 0x1D, 0x00, 0x1E, 0x25, 0x1C, 0x12, 0x1D, 0x00, 0x1E, 0x26, 0x1C, 0x12, 0x1D, 0x00, 0x1E, 0x27),
-+S_(0x000000FF, 0x12, 0x1C, 0x00, 0x1D, 0x0C, 0x1E, 0x28, 0x1C, 0x00, 0x1D, 0x0C, 0x1E, 0x29, 0x1C, 0x00, 0x1D, 0x08, 0x1E, 0x2B),
-+
-+S_(0x000000FF, 0x18, 0x1C, 0xDA, 0x1D, 0x00, 0x1E, 0x63, 0x1C, 0x60, 0x1D, 0x6B, 0x1E, 0x64, 0x1C, 0x74, 0x1D, 0x00, 0x1E, 0x65, 0x1C, 0xC0, 0x1D, 0x79, 0x1E, 0x66),
-+S_(0x000000FF, 0x0C, 0x1C, 0x20, 0x1D, 0x11, 0x1E, 0x67, 0x1C, 0xE0, 0x1D, 0x3B, 0x1E, 0x68),
-+
-+// ------------------------------------- Initialization of direct registers --------------------------------------------
-+
-+// Mode(8-bit,u-Law,1 PCLK ) setting, Loopbacks and Interrupts clear
-+// --Temporary digital loopback
-+S_(0x000000FF, 0x08, 0x01, 0x29, 0x08, 0x00, 0x09, 0x00, 0x0E, 0x00),
-+S_(0x000000FF, 0x0C, 0x15, 0x00, 0x16, 0x03, 0x17, 0x00, 0x12, 0xFF, 0x13, 0xFF, 0x14, 0xFF),
-+
-+// Ring timers settings
-+S_(0x000000FF, 0x06, 0x30, 0x80, 0x31, 0x3E, 0x32, 0x80),
-+S_(0x000000FF, 0x02, 0x33, 0x3E),
-+S_(0x000000FF, 0x02, 0x22, 0x18),
-+
-+// Battery feed control(DCSW), Automatic control of Ring Trip and Loop Closure, VBATH, VBATL
-+S_(0x000000FF, 0x02, 0x42, 0x00),
-+S_(0x000000FF, 0x02, 0x43, 0x1E),
-+S_(0x000000FF, 0x04, 0x4A, 0x31, 0x4B, 0x10),
-+
-+S_(0x000000FF, 0x02, 0x45, 0x0A),
-+S_(0x000000FF, 0x02, 0x46, 0x0B),
-+S_(0x000000FF, 0x02, 0x47, 0x07),
-+
-+
-+// Setting of SLICs offsets
-+S_(0x00000001, 0x08, 0x02, 0x01, 0x03, 0x00, 0x04, 0x01, 0x05, 0x00),
-+S_(0x00000002, 0x08, 0x02, 0x09, 0x03, 0x00, 0x04, 0x09, 0x05, 0x00),
-+S_(0x00000004, 0x08, 0x02, 0x11, 0x03, 0x00, 0x04, 0x11, 0x05, 0x00),
-+S_(0x00000008, 0x08, 0x02, 0x19, 0x03, 0x00, 0x04, 0x19, 0x05, 0x00),
-+S_(0x00000010, 0x08, 0x02, 0x21, 0x03, 0x00, 0x04, 0x21, 0x05, 0x00),
-+S_(0x00000020, 0x08, 0x02, 0x29, 0x03, 0x00, 0x04, 0x29, 0x05, 0x00),
-+S_(0x00000040, 0x08, 0x02, 0x31, 0x03, 0x00, 0x04, 0x31, 0x05, 0x00),
-+S_(0x00000080, 0x08, 0x02, 0x39, 0x03, 0x00, 0x04, 0x39, 0x05, 0x00),
-+
-+// Change SLICs states to "Normal state"s (On, after offsets are set already)
-+
-+
-+S_(0x000000FF, 0x02, 0x40, 0x1),
-+S_(0x000000FF, 0x02, 0x42, 0x06),
-+// -------------------------------------------------------------
-+
-diff -urNad zaptel-1.0.10/xpp/sync.sh /tmp/dpep.absTwN/zaptel-1.0.10/xpp/sync.sh
---- zaptel-1.0.10/xpp/sync.sh 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.absTwN/zaptel-1.0.10/xpp/sync.sh 2006-01-12 12:30:09.638318611 +0200
-@@ -0,0 +1,31 @@
-+#!/bin/sh
-+
-+set -e
-+
-+SVN_ROOT=/home/tzafrir/Proj/Svn
-+XORTEL_DIR=$SVN_ROOT/xpp-zaptel/trunk/xortel
-+XPP_DIR=$SVN_ROOT/xpp-zaptel/trunk/zaptel/xpp
-+TARGET_DIR=xpp
-+FIRMWARE=$SVN_ROOT/fpgafirmware/init.dat
-+
-+curdir=$PWD
-+cd $XORTEL_DIR
-+ cd ..; svn update;
-+ cd xortel
-+ make FIRMWARE="$FIRMWARE" ../zaptel/xpp/slic_init.inc
-+cd $curdir
-+
-+cp -a $XORTEL_DIR/FPGA_XPD.hex ${TARGET_DIR}/
-+cp -a $XORTEL_DIR/xpd.h ${TARGET_DIR}/
-+cp -a $XORTEL_DIR/xpp_zap.[ch] ${TARGET_DIR}/
-+cp -a $XORTEL_DIR/xproto.[ch] ${TARGET_DIR}/
-+cp -a $XORTEL_DIR/xdefs.h ${TARGET_DIR}/
-+cp -a $XORTEL_DIR/xpp_usb.c ${TARGET_DIR}/
-+cp -a $XORTEL_DIR/zap_debug.[ch] ${TARGET_DIR}/
-+cp -a $XORTEL_DIR/slic.[ch] ${TARGET_DIR}/
-+cp -a $XORTEL_DIR/card_*.[ch] ${TARGET_DIR}/
-+cp -a $XORTEL_DIR/xpp_fxloader{,.usermap} ${TARGET_DIR}/
-+cp -a $XORTEL_DIR/xpp_modprobe ${TARGET_DIR}/
-+cp -a $XORTEL_DIR/gen_slic_init ${TARGET_DIR}/
-+cp -a $XPP_DIR/Makefile ${TARGET_DIR}/
-+cp -a $XPP_DIR/slic_init.inc ${TARGET_DIR}/
-diff -urNad zaptel-1.0.10/xpp/xdefs.h /tmp/dpep.absTwN/zaptel-1.0.10/xpp/xdefs.h
---- zaptel-1.0.10/xpp/xdefs.h 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.absTwN/zaptel-1.0.10/xpp/xdefs.h 2006-01-09 18:14:37.000000000 +0200
-@@ -0,0 +1,82 @@
-+#ifndef XDEFS_H
-+#define XDEFS_H
-+/*
-+ * Written by Oron Peled <oron at actcom.co.il>
-+ * Copyright (C) 2004-2005, Xorcom
-+ *
-+ * All rights reserved.
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License as published by
-+ * the Free Software Foundation; either version 2 of the License, or
-+ * (at your option) any later version.
-+ *
-+ * This program is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ * GNU General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-+ *
-+ */
-+
-+#ifdef __KERNEL__
-+
-+#include <linux/kernel.h>
-+
-+#define DBG(fmt, ...) \
-+ ((print_dbg) && printk(KERN_DEBUG "DBG-%s: %s: " fmt, \
-+ THIS_MODULE->name, __FUNCTION__, ## __VA_ARGS__))
-+#define INFO(fmt, ...) printk(KERN_INFO "INFO-%s: " fmt, THIS_MODULE->name, ## __VA_ARGS__)
-+#define NOTICE(fmt, ...) printk(KERN_NOTICE "NOTICE-%s: " fmt, THIS_MODULE->name, ## __VA_ARGS__)
-+#define ERR(fmt, ...) printk(KERN_ERR "ERR-%s: " fmt, THIS_MODULE->name, ## __VA_ARGS__)
-+
-+#else
-+
-+#include <stdint.h>
-+typedef uint32_t __u32;
-+
-+#include <stdio.h>
-+
-+#define DBG(fmt, ...) printf("DBG: %s: " fmt, __FUNCTION__, ## __VA_ARGS__)
-+#define INFO(fmt, ...) printf("INFO: " fmt, ## __VA_ARGS__)
-+#define NOTICE(fmt, ...) printf("NOTICE: " fmt, ## __VA_ARGS__)
-+#define ERR(fmt, ...) printf("ERR: " fmt, ## __VA_ARGS__)
-+#define __user
-+
-+struct list_head { struct list_head *next; struct list_head *prev; };
-+
-+#endif
-+
-+typedef char *charp;
-+typedef unsigned char byte;
-+typedef int bool;
-+typedef struct xbus xbus_t;
-+typedef struct xpd xpd_t;
-+typedef struct xpacket_raw xpacket_raw_t;
-+typedef struct xpacket xpacket_t;
-+typedef struct xops xops_t;
-+typedef __u32 xpp_line_t; /* at most 31 lines for E1 */
-+
-+
-+#define BIT_SET(x,i) ((x) |= (1 << (i)))
-+#define BIT_CLR(x,i) ((x) &= ~(1 << (i)))
-+#define IS_SET(x,i) (((x) & (1 << (i))) != 0)
-+#define BIT(i) (1 << (i))
-+
-+#undef SUPPORT_USB1
-+
-+#ifdef SUPPORT_USB1
-+/*
-+ * packet size <= 64 bytes:
-+ * ZT_CHUNKSIZE * 7 channels + header size <= 64
-+ */
-+#define CHANNELS_PERXPD 7 /* 7 * ZT_CHUNKSIZE + header <= 64 bytes */
-+#else
-+#define CHANNELS_PERXPD 30 /* Depends on xpp_line_t and protocol fields */
-+#endif
-+
-+
-+#endif /* XDEFS_H */
-diff -urNad zaptel-1.0.10/xpp/xpd.h /tmp/dpep.absTwN/zaptel-1.0.10/xpp/xpd.h
---- zaptel-1.0.10/xpp/xpd.h 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.absTwN/zaptel-1.0.10/xpp/xpd.h 2006-01-11 10:12:52.000000000 +0200
-@@ -0,0 +1,290 @@
-+#ifndef XPD_H
-+#define XPD_H
-+
-+/*
-+ * Written by Oron Peled <oron at actcom.co.il>
-+ * Copyright (C) 2004-2005, Xorcom
-+ *
-+ * All rights reserved.
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License as published by
-+ * the Free Software Foundation; either version 2 of the License, or
-+ * (at your option) any later version.
-+ *
-+ * This program is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ * GNU General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-+ *
-+ */
-+
-+#include "xdefs.h"
-+#include "xproto.h"
-+
-+#ifdef __KERNEL__
-+#include <linux/kernel.h>
-+#include <asm/atomic.h>
-+#include <asm/semaphore.h>
-+#include <linux/moduleparam.h>
-+#endif
-+
-+#include <zaptel.h>
-+
-+#ifdef __KERNEL__
-+#define DEF_PARM(type,name,init,desc) \
-+ type name = init; \
-+ module_param(name, type, 0600); \
-+ MODULE_PARM_DESC(name, desc)
-+
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12)
-+/*
-+ * Old 2.6 kernels had module_param_array() macro that receive the counter
-+ * by value.
-+ */
-+#define DEF_ARRAY(type,name,count,init,desc) \
-+ unsigned int name ## _num_values; \
-+ type name[count] = {[0 ... count-1] = init}; \
-+ module_param_array(name, type, name ## _num_values, 0600); \
-+ MODULE_PARM_DESC(name, desc " ( 1-" __MODULE_STRING(count) ")")
-+#else
-+#define DEF_ARRAY(type,name,count,init,desc) \
-+ unsigned int name ## _num_values; \
-+ type name[count] = {[0 ... count-1] = init}; \
-+ module_param_array(name, type, &name ## _num_values, 0600); \
-+ MODULE_PARM_DESC(name, desc " ( 1-" __MODULE_STRING(count) ")")
-+#endif
-+#endif // __KERNEL__
-+
-+
-+#define MAX_SPANNAME 20
-+#define MAX_SPANDESC 40
-+#define MAX_CHANNAME 20
-+
-+#define XPD_NAMELEN 10 /* must be <= from maximal workqueue name */
-+#define XPD_DESCLEN 20
-+#define XBUS_NAMELEN 20 /* must be <= from maximal workqueue name */
-+#define XBUS_DESCLEN 40
-+
-+/* Hardware does not check bank_num yet. So only 4 cards can be used */
-+#define MAX_XPDS 4 // 1 FXS + 2 E1/T1 + 1 (Quad * E1/T1)
-+
-+#define VALID_XPD_NUM(x) ((x) < MAX_XPDS && (x) >= 0)
-+
-+typedef struct xbus_ops xbus_ops_t;
-+
-+typedef enum xbus_type {
-+ FIRMWARE_LOOPBACK = 1,
-+ FIRMWARE_XPP = 2,
-+} xbus_type_t;
-+
-+#ifdef __KERNEL__
-+
-+
-+typedef struct packet_queue {
-+ char qname[XPD_NAMELEN];
-+ struct list_head head;
-+ unsigned int count;
-+ unsigned int worst_count;
-+ unsigned int overflows;
-+ spinlock_t lock;
-+} packet_queue_t;
-+
-+struct xbus_ops {
-+ int (*packet_send)(xbus_t *xbus, xpacket_t *packet);
-+ xpacket_t *(*packet_new)(xbus_t *xbus, int flags);
-+ void (*packet_free)(xbus_t *xbus, xpacket_t *p);
-+};
-+
-+enum {
-+ XBUS_N_DESC_REQ,
-+ XBUS_N_DEV_DESC,
-+ XBUS_N_PCM_WRITE,
-+ XBUS_N_PCM_READ,
-+ XBUS_N_TX_BYTES,
-+ XBUS_N_RX_BYTES,
-+ XBUS_N_SOFTSIM_PACKETS,
-+ XBUS_N_SIM_PACKETS,
-+};
-+
-+#define XBUS_COUNTER(xbus, counter) ((xbus)->counters[XBUS_N_ ## counter])
-+
-+#define C_(x) [ XBUS_N_ ## x ] = { #x }
-+
-+/* yucky, make an instance so we can size it... */
-+static struct xbus_counters {
-+ char *name;
-+} xbus_counters[] = {
-+ C_(DESC_REQ),
-+ C_(DEV_DESC),
-+ C_(PCM_WRITE),
-+ C_(PCM_READ),
-+ C_(TX_BYTES),
-+ C_(RX_BYTES),
-+ C_(SOFTSIM_PACKETS),
-+ C_(SIM_PACKETS),
-+};
-+
-+#undef C_
-+
-+#define XBUS_COUNTER_MAX ARRAY_SIZE(xbus_counters)
-+
-+struct xpd_sim {
-+ bool simulated;
-+ bool softloop_xpd;
-+ int loopto;
-+ xpd_type_t xpd_type;
-+ xpp_line_t hookstate;
-+};
-+
-+
-+struct xbus {
-+ char busname[XBUS_NAMELEN]; /* only xbus_new set this */
-+ char busdesc[XBUS_DESCLEN]; /* lowlevel drivers set this */
-+ int num;
-+ xbus_ops_t *ops;
-+ struct xpd *xpds[MAX_XPDS];
-+
-+ /* Simulator data */
-+ xbus_type_t bus_type;
-+#if SOFT_SIMULATOR
-+ struct xpd_sim sim[MAX_XPDS];
-+ struct workqueue_struct *sim_workqueue;
-+ struct work_struct sim_work; // workqueue job for running simulator
-+ packet_queue_t sim_packet_queue;
-+#endif
-+
-+ spinlock_t lock;
-+
-+ bool hardware_exists; /* Hardware is functional */
-+ int open_counter; /* Number of open channels */
-+ atomic_t packet_counter; /* Allocated packets */
-+ wait_queue_head_t packet_cache_empty;
-+
-+ struct timer_list poll_timer;
-+ struct rw_semaphore in_use;
-+ int num_xpds;
-+ void *priv; /* Pointer to transport level data structures */
-+
-+#ifdef XPP_PACKET_LOG
-+ struct cyclic_buff *packet_log;
-+#endif
-+
-+#ifdef CONFIG_PROC_FS
-+ struct proc_dir_entry *proc_xbus_dir;
-+ struct proc_dir_entry *proc_xbus_summary;
-+#endif
-+
-+ /* statistics */
-+ int counters[XBUS_COUNTER_MAX];
-+
-+};
-+#endif
-+
-+typedef enum xpd_direction {
-+ TO_PHONE = 0,
-+ TO_PSTN = 1,
-+} xpd_direction_t;
-+
-+#define LINE_BITS (sizeof(xpp_line_t)*8)
-+
-+
-+#ifdef __KERNEL__
-+#define BIT_SET(x,i) ((x) |= (1 << (i)))
-+#define BIT_CLR(x,i) ((x) &= ~(1 << (i)))
-+#define IS_SET(x,i) (((x) & (1 << (i))) != 0)
-+#define BIT(i) (1 << (i))
-+
-+enum {
-+ XPD_N_PCM_READ,
-+ XPD_N_PCM_WRITE,
-+ XPD_N_RECV_ERRORS,
-+};
-+
-+#define XPD_COUNTER(xpd, counter) ((xpd)->counters[XPD_N_ ## counter])
-+
-+#define C_(x) [ XPD_N_ ## x ] = { #x }
-+
-+/* yucky, make an instance so we can size it... */
-+static struct xpd_counters {
-+ char *name;
-+} xpd_counters[] = {
-+ C_(PCM_READ),
-+ C_(PCM_WRITE),
-+ C_(RECV_ERRORS),
-+};
-+
-+#undef C_
-+
-+#define XPD_COUNTER_MAX (sizeof(xpd_counters)/sizeof(xpd_counters[0]))
-+
-+enum leds {
-+ LED_GREEN,
-+ LED_RED,
-+ LED_BLUE,
-+};
-+
-+#define NUM_LEDS 3
-+
-+struct xpd {
-+ char xpdname[XPD_NAMELEN];
-+ struct zt_span span;
-+ struct zt_chan *chans;
-+ int channels;
-+ xpd_type_t type;
-+ xpd_direction_t direction; /* TO_PHONE, TO_PSTN */
-+ xpp_line_t enabled_chans; /* hardware activation: 0 - off, 1 - on */
-+ xpp_line_t hookstate; /* 0 - ONHOOK, 1 - OFHOOK */
-+ xpp_line_t ledstate[NUM_LEDS]; /* 0 - OFF, 1 - ON */
-+ xpp_line_t digital_outputs; /* 0 - no, 1 - yes */
-+ xpp_line_t digital_inputs; /* 0 - no, 1 - yes */
-+
-+ int ringing[CHANNELS_PERXPD];
-+ bool ringer_on[CHANNELS_PERXPD]; /* For ring toggling */
-+ bool led_on[CHANNELS_PERXPD]; /* For led toggling */
-+ int lasttxhook[CHANNELS_PERXPD];
-+
-+ struct work_struct xpd_post_init;
-+ xbus_t *xbus;
-+
-+ spinlock_t lock;
-+ atomic_t open_counter; /* Number of open channels */
-+
-+ int flags;
-+
-+ unsigned int board_flags;
-+#define XPD_BOARD_LOOPBACK 1
-+
-+#ifdef CONFIG_PROC_FS
-+ struct proc_dir_entry *proc_xpd_dir;
-+ struct proc_dir_entry *proc_xpd_summary;
-+ struct proc_dir_entry *proc_xpd_ztregister;
-+#endif
-+ // Bit numbers of board_flags
-+
-+ int counters[XPD_COUNTER_MAX];
-+
-+ const xops_t *xops; /* Card level operations */
-+ void *priv; /* Card level private data */
-+ atomic_t card_present;
-+
-+ unsigned int recv_errors;
-+ unsigned int seq_errors;
-+ unsigned long last_response; /* in jiffies */
-+ unsigned id;
-+ struct list_head xpd_list;
-+ unsigned int timer_count;
-+ volatile u_char *writechunk; /* Double-word aligned write memory */
-+ volatile u_char *readchunk; /* Double-word aligned read memory */
-+ /* Echo cancelation */
-+ u_char ec_chunk1[CHANNELS_PERXPD][ZT_CHUNKSIZE];
-+ u_char ec_chunk2[CHANNELS_PERXPD][ZT_CHUNKSIZE];
-+};
-+
-+#endif
-+
-+#endif /* XPD_H */
-diff -urNad zaptel-1.0.10/xpp/xpp_fxloader /tmp/dpep.absTwN/zaptel-1.0.10/xpp/xpp_fxloader
---- zaptel-1.0.10/xpp/xpp_fxloader 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.absTwN/zaptel-1.0.10/xpp/xpp_fxloader 2006-01-12 12:17:04.150673000 +0200
-@@ -0,0 +1,24 @@
-+#!/bin/sh
-+
-+FIRMWARE="/etc/xortel/FPGA_XPD.hex"
-+me=`basename $0`
-+
-+# to run manually, pass the parameter 'xppdetect'
-+V_ID=04b4
-+P_ID=8613
-+if [ "$1" = 'xppdetect' ]; then
-+ DEVICES=`lsusb | tr -d : | awk "/ ID $V_ID$P_ID /{printf \"/proc/bus/usb/%s/%s \",\\$2,\\$4}"`
-+ echo "Loading firmware for $DEVICES"
-+ for dev in $DEVICES
-+ do
-+ fxload -t fx2 -D $dev -I $FIRMWARE
-+ done
-+ exit 0
-+fi
-+
-+if [ "$ACTION" = "add" ] && [ -f "$DEVICE" ]
-+then
-+ logger -i -t "$me" "Loading firmware '$FIRMWARE' into '$DEVICE'"
-+ fxload -t fx2 -D "$DEVICE" -I "$FIRMWARE" || exit 1
-+fi
-+
-diff -urNad zaptel-1.0.10/xpp/xpp_fxloader.usermap /tmp/dpep.absTwN/zaptel-1.0.10/xpp/xpp_fxloader.usermap
---- zaptel-1.0.10/xpp/xpp_fxloader.usermap 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.absTwN/zaptel-1.0.10/xpp/xpp_fxloader.usermap 2006-01-09 18:14:37.000000000 +0200
-@@ -0,0 +1,2 @@
-+# module match_flags idVendor idProduct bcdDevice_lo bcdDevice_hi bDeviceClass bDeviceSubClass bDeviceProtocol bInterfaceClass bInterfaceSubClass bInterfaceProtocol driver_info
-+xpp_fxloader 0x0003 0x04b4 0x8613 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x0
-diff -urNad zaptel-1.0.10/xpp/xpp_modprobe /tmp/dpep.absTwN/zaptel-1.0.10/xpp/xpp_modprobe
---- zaptel-1.0.10/xpp/xpp_modprobe 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.absTwN/zaptel-1.0.10/xpp/xpp_modprobe 2006-01-11 10:12:52.000000000 +0200
-@@ -0,0 +1,10 @@
-+# Some debugging options for the brave of heart:
-+#options zaptel debug=1
-+#options wcfxo debug=1
-+#options xpp print_dbg=1
-+
-+# For pre-loading of card modules (e.g: xpp_fxs)
-+#install xpp_usb /sbin/modprobe xpd_fxs && /sbin/modprobe --ignore-install xpp_usb
-+
-+# For auto loading of card modules
-+alias xpd-type-3 xpd_fxs
-diff -urNad zaptel-1.0.10/xpp/xpp_proto.c /tmp/dpep.absTwN/zaptel-1.0.10/xpp/xpp_proto.c
---- zaptel-1.0.10/xpp/xpp_proto.c 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.absTwN/zaptel-1.0.10/xpp/xpp_proto.c 2006-01-12 12:30:09.638318611 +0200
-@@ -0,0 +1,1044 @@
-+#include <linux/module.h>
-+#include <linux/delay.h> /* for udelay */
-+#include "xpd.h"
-+#include "xpp_proto.h"
-+#include "xpp_zap.h"
-+
-+static char rcsid[] = "$Id: xpp_proto.c 136 2005-12-12 07:10:40Z oron $";
-+
-+extern int print_dbg;
-+#include "zap_debug.h"
-+
-+typedef struct xpp_command xpp_command_t;
-+typedef int (*xpp_handler_t)(xbus_t *xbus, int id, xpp_command_t *cmd, xpacket_t *packet);
-+
-+struct xpp_command {
-+ xpp_opcode_t opcode;
-+ unsigned int header_size;
-+ bool varsize;
-+ const char *name;
-+ const char *desc;
-+ xpp_handler_t handler;
-+};
-+
-+#define S_(s,l,...) \
-+ { \
-+ .lines = s, \
-+ { \
-+ .len = l, \
-+ .data = { __VA_ARGS__ }, \
-+ } \
-+ }
-+
-+struct slic_init_data {
-+ xpp_line_t lines;
-+ slic_data_t slic_data;
-+} slic_init_data[] = {
-+#include "slic_init.inc"
-+};
-+
-+static int packet_process(xbus_t *xbus, int xpd_num, xpacket_t *pack);
-+static int simulate_xpd(xbus_t *xbus, int xpd_num, xpacket_t *sent_packet);
-+static bool pcm_valid(xpd_t *xpd, xpacket_t *reply);
-+
-+#define NEW_PACKET(p, xbus, name, to) \
-+ do { \
-+ p = xbus->ops->packet_new(xbus, GFP_ATOMIC); \
-+ if(!p) \
-+ return -ENOMEM; \
-+ PACKET_INIT(p, name); \
-+ XPD_ADDR_SET(p->content.addr, to); \
-+ } while(0);
-+
-+/*------------------------- SLIC Handling --------------------------*/
-+
-+int proc_xpd_slic_read(char *page, char **start, off_t off, int count, int *eof, void *data)
-+{
-+ int len = 0;
-+ unsigned long flags;
-+ xpd_t *xpd = data;
-+ //slic_reply_t *info;
-+
-+ BUG_ON(!xpd);
-+ spin_lock_irqsave(&xpd->lock, flags);
-+#if 0
-+ info = (slic_reply_t *)&xpd->slic_info;
-+ len += sprintf(page + len, "SLIC_REPLY: %s reg_num=0x%X, dataH=0x%X dataL=0x%X\n",
-+ (info->indirect)?"I":"D",
-+ info->reg_num, info->data_high, info->data_low);
-+#endif
-+ spin_unlock_irqrestore(&xpd->lock, flags);
-+ if (len <= off+count)
-+ *eof = 1;
-+ *start = page + off;
-+ len -= off;
-+ if (len > count)
-+ len = count;
-+ if (len < 0)
-+ len = 0;
-+ return len;
-+}
-+
-+static int parse_slic_cmd(const char *buf, slic_cmd_t *sc)
-+{
-+ char op; /* [W]rite, [R]ead */
-+ char reg_type; /* [D]irect, [I]ndirect */
-+ int s1, s2, s3, s4;
-+ int reg_num;
-+ int data_low, data_high;
-+ xpp_line_t lines;
-+ int ret;
-+
-+ ret = sscanf(buf, "%x %x %x %x %c%c %x %x %x",
-+ &s1, &s2, &s3, &s4, &op, ®_type, ®_num, &data_high, &data_low);
-+ lines = (s4 << 24) | (s3 << 16) | (s2 << 8) | (s1);
-+ switch(op) {
-+ case 'R':
-+ if(reg_type == 'D' && ret == 7) {
-+ // DBG("0x%X 0x%X 0x%X 0x%X %c %x\n", s1, s2, s3, s4, reg_type, reg_num);
-+ ret = slic_cmd_direct_read(sc, lines, reg_num);
-+ } else if(reg_type == 'I' && ret == 7) {
-+ // DBG("0x%X 0x%X 0x%X 0x%X %c %x\n", s1, s2, s3, s4, reg_type, reg_num);
-+ ret = slic_cmd_indirect_read(sc, lines, reg_num);
-+ } else {
-+ NOTICE("%s: Bad read input: ret=%d buf='%s' reg_type=%c\n", __FUNCTION__, ret, buf, reg_type);
-+ goto err;
-+ }
-+ break;
-+ case 'W':
-+ if(reg_type == 'D' && ret == 8) {
-+ // DBG("0x%X 0x%X 0x%X 0x%X %c %x %X\n", s1, s2, s3, s4, reg_type, reg_num, data_high);
-+ ret = slic_cmd_direct_write(sc, lines, reg_num, data_high);
-+ } else if(reg_type == 'I' && ret == 9) {
-+ // DBG("0x%X 0x%X 0x%X 0x%X %c %x %X %X\n", s1, s2, s3, s4, reg_type, reg_num, data_high, data_low);
-+ ret = slic_cmd_indirect_write(sc, lines, reg_num, data_low, data_high);
-+ } else {
-+ NOTICE("%s: Bad write input: ret=%d buf='%s' reg_type=%c\n", __FUNCTION__, ret, buf, reg_type);
-+ goto err;
-+ }
-+ break;
-+ default:
-+ NOTICE("%s: Bad input: ret=%d buf='%s' op=%c\n", __FUNCTION__, ret, buf, op);
-+ goto err;
-+ }
-+ return ret;
-+err:
-+ return -EINVAL;
-+}
-+
-+static int process_slic_cmdline(xpd_t *xpd, char *cmdline)
-+{
-+ xbus_t *xbus;
-+ slic_cmd_t sc;
-+ xpacket_t *pack_tx;
-+ char *p;
-+ int len = strlen(cmdline);
-+
-+ BUG_ON(!xpd);
-+ xbus = xpd->xbus;
-+ if((p = strchr(cmdline, '#')) != NULL) /* Truncate comments */
-+ *p = '\0';
-+ if((p = strchr(cmdline, ';')) != NULL) /* Truncate comments */
-+ *p = '\0';
-+ for(p = cmdline; *p && (*p == ' ' || *p == '\t'); p++) /* Trim leading whitespace */
-+ ;
-+ if(*p == '\0')
-+ return 0;
-+ len = parse_slic_cmd(p, &sc);
-+ if(len < 0)
-+ return len;
-+ sc.lines &= xpd->enabled_chans; // Ignore disabled channels
-+ if(!sc.lines) {
-+ NOTICE("%s: no enabled channels are marked. Skip.\n", __FUNCTION__);
-+ return 0;
-+ }
-+ dump_slic_cmd("WRITE_SLIC", &sc);
-+ NEW_PACKET(pack_tx, xbus, SLIC_WRITE, xpd->id);
-+ PACKET_FIELD(pack_tx, SLIC_WRITE, slic_cmd) = sc;
-+ pack_tx->datalen = len;
-+ packet_send(xbus, pack_tx);
-+ return 0;
-+}
-+
-+int proc_xpd_slic_write(struct file *file, const char __user *buffer, unsigned long count, void *data)
-+{
-+ xpd_t *xpd = data;
-+ const int LINE_LEN = 500;
-+ char buf[LINE_LEN];
-+ char *p;
-+ int i;
-+ int ret;
-+
-+ BUG_ON(!xpd);
-+ for(i = 0; i < count; /* noop */) {
-+ for(p = buf; p < buf + LINE_LEN; p++) { /* read a line */
-+ if(i >= count)
-+ break;
-+ if(get_user(*p, buffer + i))
-+ return -EFAULT;
-+ i++;
-+ if(*p == '\n' || *p == '\r') /* whatever */
-+ break;
-+ }
-+ if(p >= buf + LINE_LEN)
-+ return -E2BIG;
-+ *p = '\0';
-+ ret = process_slic_cmdline(xpd, buf);
-+ if(ret < 0)
-+ return ret;
-+ }
-+ return count;
-+}
-+
-+
-+
-+/*------------------------- Protocol Functions ---------------------*/
-+
-+#define HOSTCMD(name, ...) \
-+ DECLARE_CMD(name, ## __VA_ARGS__ ); \
-+ EXPORT_SYMBOL(xpp_proto_ ## name); \
-+ DECLARE_CMD(name, ## __VA_ARGS__ )
-+
-+
-+/* 0x04 */ HOSTCMD(DESC_REQ, int xpd_num)
-+{
-+ int ret = 0;
-+ xpacket_t *pack_tx;
-+
-+ DBG("\n");
-+ if(!xbus) {
-+ DBG("NO XBUS\n");
-+ return -EINVAL;
-+ }
-+ NEW_PACKET(pack_tx, xbus, DESC_REQ, xpd_num);
-+ DBG("calling packet_send for a DESC_REQ packet.\n");
-+ ret = packet_send(xbus, pack_tx);
-+ DBG("after packet_send, updating counter (ret=%d)\n", ret);
-+ XBUS_COUNTER(xbus, DESC_REQ)++;
-+ return ret;
-+}
-+
-+/* 0x0F */ HOSTCMD(CHAN_POWER, xpp_line_t lines, bool on)
-+{
-+ int ret = 0;
-+ xpacket_t *pack_tx;
-+ slic_cmd_t *sc;
-+ int len;
-+
-+ BUG_ON(!xbus);
-+ BUG_ON(!xpd);
-+ lines &= xpd->enabled_chans; // Ignore disabled channels
-+ if(!lines) {
-+ return 0;
-+ }
-+ DBG("Channel Power: 0x%04X %s\n", lines, (on) ? "up" : "down");
-+ NEW_PACKET(pack_tx, xbus, SLIC_WRITE, xpd->id);
-+ sc = &PACKET_FIELD(pack_tx, SLIC_WRITE, slic_cmd);
-+ if(on) {
-+ // Power up
-+ len = slic_cmd_direct_write(sc, lines, 0x42, 0x06);
-+ } else {
-+ // Power down
-+ len = slic_cmd_direct_write(sc, lines, 0x42, 0x00);
-+ }
-+ pack_tx->datalen = len;
-+
-+ packet_send(xbus, pack_tx);
-+ return ret;
-+}
-+
-+/* 0x0F */ HOSTCMD(CHAN_ENABLE, xpp_line_t lines, bool on)
-+{
-+ int ret = 0;
-+ xpacket_t *pack_tx;
-+ slic_cmd_t *sc;
-+ int len;
-+
-+ BUG_ON(!xbus);
-+ BUG_ON(!xpd);
-+ lines &= xpd->enabled_chans; // Ignore disabled channels
-+ if(!lines) {
-+ return 0;
-+ }
-+ DBG("Channel Activation: 0x%4X %s\n", lines, (on) ? "on" : "off");
-+ NEW_PACKET(pack_tx, xbus, SLIC_WRITE, xpd->id);
-+ sc = &PACKET_FIELD(pack_tx, SLIC_WRITE, slic_cmd);
-+ len = slic_cmd_direct_write(sc, lines, 0x40, (on)?0x01:0x00);
-+ pack_tx->datalen = len;
-+
-+ packet_send(xbus, pack_tx);
-+ return ret;
-+}
-+
-+/* 0x0F */ HOSTCMD(RING, int pos, bool on)
-+{
-+ int ret = 0;
-+ xpacket_t *pack_tx;
-+ slic_cmd_t *sc;
-+ xpp_line_t mask = (1 << pos);
-+ int len;
-+
-+ BUG_ON(!xbus);
-+ BUG_ON(!xpd);
-+ mask &= xpd->enabled_chans; // Ignore disabled channels
-+ if(!mask) {
-+ return 0;
-+ }
-+ DBG("%s pos=%d %s\n", xpd->xpdname, pos, (on) ? "on" : "off");
-+ NEW_PACKET(pack_tx, xbus, SLIC_WRITE, xpd->id);
-+ sc = &PACKET_FIELD(pack_tx, SLIC_WRITE, slic_cmd);
-+ len = slic_cmd_direct_write(sc, mask, 0x40, (on)?0x04:0x01);
-+ pack_tx->datalen = len;
-+
-+ packet_send(xbus, pack_tx);
-+ return ret;
-+}
-+
-+/* 0x0F */ HOSTCMD(SETHOOK, xpp_line_t hook_status)
-+{
-+ int ret = 0;
-+ xpacket_t *pack_tx;
-+ slic_cmd_t *sc;
-+ int len;
-+
-+ BUG_ON(!xbus);
-+ BUG_ON(!xpd);
-+ hook_status &= xpd->enabled_chans; // Ignore disabled channels
-+ if(!hook_status) {
-+ return 0;
-+ }
-+ DBG("New hook_status: %d\n", hook_status);
-+ NEW_PACKET(pack_tx, xbus, SLIC_WRITE, xpd->id);
-+ sc = &PACKET_FIELD(pack_tx, SLIC_WRITE, slic_cmd);
-+ /* FIXME: This is fake, until Dima implements FXO */
-+ len = slic_cmd_direct_write(sc, hook_status, 0x02, 0x00);
-+ pack_tx->datalen = len;
-+
-+ packet_send(xbus, pack_tx);
-+ return ret;
-+}
-+
-+/*
-+ * LED control is done via SLIC register 0x06:
-+ * 7 6 5 4 3 2 1 0
-+ * +-----+-----+-----+-----+-----+-----+-----+-----+
-+ * | MR | MG | MB | R | OG | OB | G | B |
-+ * +-----+-----+-----+-----+-----+-----+-----+-----+
-+ *
-+ * B - BLUE LED (0 - OFF, 1 - ON)
-+ * G - GREEN LED (0 - OFF, 1 - ON)
-+ * OB - Output BLUE (this line is output)
-+ * OG - Output GREEN (this line is output)
-+ * R - RED LED (0 - OFF, 1 - ON)
-+ * MB - Mask BLUE. (1 - B effect the BLUE LED)
-+ * MR - Mask RED. (1 - R effect the RED LED)
-+ * MG - Mask GREEN. (1 - G effect the GREEN LED)
-+ *
-+ * The BLUE LED (actually a relay out) is connected to line 0 and 4 only.
-+ */
-+
-+// GREEN RED BLUE
-+static int led_mask[NUM_LEDS] = { BIT(6), BIT(7), BIT(5) };
-+static int led_vals[NUM_LEDS] = { BIT(1), BIT(4), BIT(0) };
-+
-+/* 0x0F */ HOSTCMD(LED, xpp_line_t lines, byte which, bool on)
-+{
-+ int ret = 0;
-+ xpacket_t *pack_tx;
-+ slic_cmd_t *sc;
-+ int len;
-+ int value;
-+ int i;
-+
-+ BUG_ON(!xbus);
-+ BUG_ON(!xpd);
-+ lines &= xpd->enabled_chans; // Ignore disabled channels
-+ if(!lines) {
-+ return 0;
-+ }
-+ DBG("LED: lines=0x%04X which=%d -- %s\n", lines, which, (on) ? "on" : "off");
-+ which = which % NUM_LEDS;
-+ value = BIT(2) | BIT(3);
-+ value |= ((BIT(5) | BIT(6) | BIT(7)) & ~led_mask[which]);
-+ if(on)
-+ value |= led_vals[which];
-+ for(i = 0; i < CHANNELS_PERXPD; i++) {
-+ if(!IS_SET(lines, i))
-+ continue;
-+ NEW_PACKET(pack_tx, xbus, SLIC_WRITE, xpd->id);
-+ sc = &PACKET_FIELD(pack_tx, SLIC_WRITE, slic_cmd);
-+ len = slic_cmd_direct_write(sc, lines, 0x06, value);
-+ DBG("LED pack: line=%d value=0x%04X\n", i, value);
-+ pack_tx->datalen = len;
-+ packet_send(xbus, pack_tx);
-+ }
-+ return ret;
-+}
-+
-+/* 0x0F */ HOSTCMD(RELAY_OUT, byte which, bool on)
-+{
-+ int ret = 0;
-+ xpacket_t *pack_tx;
-+ slic_cmd_t *sc;
-+ int len;
-+ int value;
-+ xpp_line_t lines;
-+ int relay_channels[] = { 0, 4 };
-+
-+ BUG_ON(!xbus);
-+ BUG_ON(!xpd);
-+
-+ DBG("RELAY_OUT: which=%d -- %s\n", which, (on) ? "on" : "off");
-+ which = which % ARRAY_SIZE(relay_channels);
-+ lines = BIT(relay_channels[which]);
-+ value = BIT(2) | BIT(3);
-+ value |= ((BIT(5) | BIT(6) | BIT(7)) & ~led_mask[LED_BLUE]);
-+ if(on)
-+ value |= led_vals[LED_BLUE];
-+ NEW_PACKET(pack_tx, xbus, SLIC_WRITE, xpd->id);
-+ sc = &PACKET_FIELD(pack_tx, SLIC_WRITE, slic_cmd);
-+ len = slic_cmd_direct_write(sc, lines, 0x06, value);
-+
-+ DBG("RELAY_OUT pack: line=%d value=0x%04X\n", lines, value);
-+ pack_tx->datalen = len;
-+ packet_send(xbus, pack_tx);
-+ return ret;
-+}
-+
-+/* 0x0F */ HOSTCMD(SLIC_INIT)
-+{
-+ int ret = 0;
-+ xpacket_t *pack_tx;
-+ slic_data_t *slic;
-+ struct slic_init_data *source;
-+ int i;
-+
-+ BUG_ON(!xbus);
-+ BUG_ON(!xpd);
-+ DBG("INITIALIZING SLIC\n");
-+ for(i = 0; i < ARRAY_SIZE(slic_init_data); i++) {
-+ source = &slic_init_data[i];
-+ NEW_PACKET(pack_tx, xbus, SLIC_INIT, xpd->id);
-+ PACKET_FIELD(pack_tx, SLIC_INIT, lines) = source->lines;
-+
-+ slic = &PACKET_FIELD(pack_tx, SLIC_INIT, slic_data);
-+ slic->len = source->slic_data.len;
-+ memcpy(slic->data, source->slic_data.data, source->slic_data.len);
-+ pack_tx->datalen = sizeof(xpp_line_t) + slic->len + 1;
-+// dump_packet("SLIC", pack_tx, print_dbg);
-+ packet_send(xbus, pack_tx);
-+ mdelay(10); // FIXME: Temporary -- Dima need to fix it
-+ }
-+ return ret;
-+}
-+
-+/* 0x0F */ HOSTCMD(SLIC_QUERY, int pos, byte reg_num)
-+{
-+ int ret = 0;
-+ xpacket_t *pack_tx;
-+ slic_cmd_t *sc;
-+ int len;
-+
-+ BUG_ON(!xbus);
-+ BUG_ON(!xpd);
-+ NEW_PACKET(pack_tx, xbus, SLIC_WRITE, xpd->id);
-+ sc = &PACKET_FIELD(pack_tx, SLIC_WRITE, slic_cmd);
-+ len = slic_cmd_direct_read(sc, (1<<pos), reg_num);
-+
-+ pack_tx->datalen = len;
-+
-+ packet_send(xbus, pack_tx);
-+ return ret;
-+}
-+
-+/* 0x11 */ HOSTCMD(PCM_WRITE, xpp_line_t lines, volatile byte *buf)
-+{
-+ int ret = 0;
-+ xpacket_t *pack_tx;
-+ byte *pcm;
-+ byte *start_pcm;
-+ int i;
-+ extern ulong pcm_gen;
-+
-+ BUG_ON(!xbus);
-+ BUG_ON(!xpd);
-+ lines &= xpd->enabled_chans;
-+ // DBG("PCM_WRITE\n");
-+ if(pcm_gen != 0)
-+ return 0;
-+// if(lines == 0)
-+// return 0;
-+
-+ /*
-+ * FIXME: Workaround a bug in sync code of the Astribank.
-+ * Send dummy PCM for sync.
-+ */
-+ if(lines == 0)
-+ lines = BIT(0);
-+
-+ NEW_PACKET(pack_tx, xbus, PCM_WRITE, xpd->id);
-+ PACKET_FIELD(pack_tx, PCM_WRITE, lines) = lines;
-+ start_pcm = pcm = PACKET_FIELD(pack_tx, PCM_WRITE, pcm);
-+ for(i = 0; i < CHANNELS_PERXPD; i++) {
-+ if(IS_SET(lines, i)) {
-+ memcpy(pcm, (byte *)buf, ZT_CHUNKSIZE);
-+ pcm += ZT_CHUNKSIZE;
-+ }
-+ buf += ZT_CHUNKSIZE;
-+ }
-+ pack_tx->datalen = sizeof(xpp_line_t) + (pcm - start_pcm);
-+ packet_send(xbus, pack_tx);
-+ XPD_COUNTER(xpd, PCM_WRITE)++;
-+ XBUS_COUNTER(xbus, PCM_WRITE)++;
-+ return ret;
-+}
-+
-+/* 0x13 */ HOSTCMD(PCM_GEN, xpp_line_t lines, volatile byte *buf)
-+{
-+ xpacket_t *pack_tx;
-+ bool gen_seq = ((lines != 0) && (buf != NULL));
-+
-+ BUG_ON(!xbus);
-+ BUG_ON(!xpd);
-+ lines &= xpd->enabled_chans; // Ignore disabled channels
-+ if(!lines) {
-+ return 0;
-+ }
-+ DBG("PCM_GEN lines=0x%04X %s\n", lines, (gen_seq) ? "seq" : "off");
-+ NEW_PACKET(pack_tx, xbus, PCM_GEN, xpd->id);
-+ PACKET_FIELD(pack_tx, PCM_GEN, lines) = lines;
-+ if(gen_seq) {
-+ PACKET_FIELD(pack_tx, PCM_GEN, gen) = 0;
-+ memcpy(&PACKET_FIELD(pack_tx, PCM_GEN, pcm_seq), (byte *)buf, ZT_CHUNKSIZE);
-+ } else {
-+ PACKET_FIELD(pack_tx, PCM_GEN, gen) = 2;
-+ }
-+ packet_send(xbus, pack_tx);
-+ return 0;
-+}
-+
-+/*
-+ * Sync source is controled by a mask byte to 0x19 command:
-+ * 7 6 5 4 3 2 1 0
-+ * +-----+-----+-----+-----+-----+-----+-----+-----+
-+ * | | | | | | | RW | AB |
-+ * +-----+-----+-----+-----+-----+-----+-----+-----+
-+ *
-+ * RW - Read or set (0 - Write, 1 - Read)
-+ * AB - This Astribank provide sync (0 - no, 1 - yes)
-+ *
-+ */
-+
-+/* 0x19 */ HOSTCMD(SYNC_SOURCE, bool setit, bool is_master)
-+{
-+ xpacket_t *pack_tx;
-+ byte mask = 0;
-+
-+ BUG_ON(!xbus);
-+ BUG_ON(!xpd);
-+ if(is_master)
-+ mask |= BIT(0);
-+ if(!setit)
-+ mask |= BIT(1);
-+ DBG("SYNC_SOURCE %s setit=%s is_master=%s (mask=0x%X)\n",
-+ xpd->xpdname, (setit)?"yes":"no", (is_master)?"yes":"no", mask);
-+ NEW_PACKET(pack_tx, xbus, SYNC_SOURCE, xpd->id);
-+ PACKET_FIELD(pack_tx, SYNC_SOURCE, mask) = mask;
-+ packet_send(xbus, pack_tx);
-+ return 0;
-+}
-+
-+/* 0x31 */ HOSTCMD(LOOPBACK_AX, byte *data, unsigned int size)
-+{
-+ xpacket_t *pack_tx;
-+
-+ BUG_ON(!xbus);
-+ BUG_ON(!xpd);
-+ DBG("LOOPBACK_AX %d bytes\n", size);
-+ NEW_PACKET(pack_tx, xbus, LOOPBACK_AX, xpd->id);
-+ memcpy(&PACKET_FIELD(pack_tx, LOOPBACK_AX, data), data, size);
-+ packet_send(xbus, pack_tx);
-+ return 0;
-+}
-+
-+/*------------------------- Protocol Simulator ---------------------*/
-+
-+
-+static int simulate_xpd(xbus_t *xbus, int xpd_num, xpacket_t *sent_packet)
-+{
-+ xpacket_t *pack = sent_packet;
-+ struct xpd_sim *xpd_sim;
-+ struct xpd_sim *loopto_sim;
-+ xpp_opcode_t opcode;
-+ int dest_xpd_num;
-+ int ret = 0;
-+
-+ // Sanity checks
-+ BUG_ON(!xbus);
-+ BUG_ON(xpd_num > MAX_XPDS || xpd_num < 0);
-+ BUG_ON(!sent_packet);
-+ BUG_ON(!xbus->sim[xpd_num].simulated);
-+
-+ XBUS_COUNTER(xbus, SIM_PACKETS)++;
-+ xpd_sim = &xbus->sim[xpd_num];
-+ opcode = pack->content.opcode;
-+ dest_xpd_num = xpd_sim->loopto;
-+ loopto_sim = &xbus->sim[dest_xpd_num];
-+// DBG("before: addr=%d, opcode=0x%X\n", xpd_num, opcode);
-+ switch(opcode) {
-+ case XPP_DESC_REQ:
-+ DBG("SIM DESC_REQ (xpd_num=%d)\n", xpd_num);
-+ PACKET_INIT(pack, DEV_DESC);
-+ PACKET_FIELD(pack, DEV_DESC, type) = xpd_sim->xpd_type;
-+ dest_xpd_num = xpd_num; // Reply as the original XPD
-+ break;
-+ case XPP_PCM_WRITE:
-+ PACKET_INIT(pack, PCM_READ);
-+ XPD_ADDR_SET(pack->content.addr, dest_xpd_num);
-+ break;
-+ case XPP_SLIC_WRITE:
-+#if FINISHED_DECODING_SLICS
-+ slic_cmd_t *sc;
-+ int len;
-+
-+ sc = &PACKET_FIELD(pack_tx, SLIC_WRITE, slic_cmd);
-+ lines = sc->lines;
-+ bool slic_write = ! (slic->data[0] & 0x80);
-+ int slic_reg = slic->data[0] & ~0x80;
-+
-+ if(slic->len == 2 && slic_write && slic_reg == 0x40) { // RING
-+ bool on = (slic->data[1] == 0x04);
-+ if(on) {
-+ loopto_sim->hookstate |= lines;
-+ } else {
-+ loopto_sim->hookstate &= ~lines;
-+ }
-+
-+ DBG("SIM RING to: xpd=%d (type=%d): (%s) ringing=0x%04X lines=0x%04X\n", dest_xpd_num, loopto_sim->xpd_type,
-+ (on)?"on":"off", loopto_sim->hookstate, lines);
-+ PACKET_INIT(pack, SIG_CHANGED);
-+ PACKET_FIELD(pack, SIG_CHANGED, type) = loopto_sim->xpd_type;
-+ PACKET_FIELD(pack, SIG_CHANGED, sig_status) = loopto_sim->hookstate;
-+ PACKET_FIELD(pack, SIG_CHANGED, sig_toggles) = lines;
-+ dump_packet("SIM RING TO", pack, print_dbg);
-+ break;
-+ } else if(slic->len == 1 && slic_write && slic_reg == 0x02) { // SETHOOK
-+ DBG("SIM SETHOOK: xpd=%d: hookstate=0x%04X lines=0x%04X\n", dest_xpd_num, loopto_sim->hookstate, lines);
-+ PACKET_INIT(pack, SIG_CHANGED);
-+ PACKET_FIELD(pack, SIG_CHANGED, type) = loopto_sim->xpd_type;
-+ PACKET_FIELD(pack, SIG_CHANGED, sig_status) = lines;
-+ PACKET_FIELD(pack, SIG_CHANGED, sig_toggles) = loopto_sim->hookstate ^ lines;
-+ loopto_sim->hookstate = lines;
-+ break;
-+ } else if(slic->len == 2 && slic_write && slic_reg == 0x06) { // LED
-+ DBG("SIM LED: xpd=%d: 0x%04X=%s\n", xpd_num, lines, (0x10)? "on" : "off");
-+ ret = 0;
-+ goto junk;
-+ } else if(slic->len == 2 && ! slic_write) { // SLIC_QUERY
-+ DBG("SIM SLIC_QUERY: xpd=%d: register=0x%02X\n", xpd_num, slic_reg);
-+ ret = 0;
-+ goto junk;
-+ } else if(slic->len >= 4) { // INITIALIZATION?
-+ DBG("SIM INITIALIZATION? xpd=%d len=%d\n", xpd_num, slic->len);
-+ ret = 0;
-+ goto junk;
-+ }
-+ NOTICE("%s: xpd=%d: SLIC_WRITE: len=%d\n", __FUNCTION__, xpd_num, slic->len);
-+#endif
-+ dump_packet("BAD SLIC_WRITE", pack, print_dbg);
-+ // FALL THROUGH
-+ default:
-+ NOTICE("%s: xpd=%d: CANNOT SIMULATE OPCODE=0x%02X\n",
-+ __FUNCTION__, xpd_num, opcode);
-+// dump_packet("BAD OPCODE", pack, print_dbg);
-+ ret = -EINVAL;
-+ goto junk;
-+ }
-+// DBG("after reversing: addr=%d, opcode=0x%X\n", xpd_num, pack->header.opcode);
-+ return packet_process(xbus, dest_xpd_num, pack);
-+junk:
-+ xbus->ops->packet_free(xbus, pack);
-+ return ret;
-+}
-+
-+#define VERBOSE_DEBUG 1
-+#define ERR_REPORT_LIMIT 20
-+
-+void dump_packet(const char *msg, xpacket_t *packet, bool print_dbg)
-+{
-+ xpp_opcode_t op = (byte)packet->content.opcode;
-+
-+ if(!print_dbg)
-+ return;
-+ DBG("%s: @0x%02X OP=0x%02X flags=0x%02X LEN=%d\n",
-+ msg,
-+ XPD_NUM(packet->content.addr),
-+ op,
-+ (byte)packet->flags,
-+ (byte)packet->datalen);
-+#if VERBOSE_DEBUG
-+ {
-+ int i;
-+ byte *p = packet->content.raw;
-+
-+ for(i = 0; i < packet->datalen; i++) {
-+ static int limiter = 0;
-+
-+ if(i >= sizeof(xpp_packet_r_t)) {
-+ if(limiter < ERR_REPORT_LIMIT) {
-+ ERR("dump_packet: length overflow i=%d > sizeof(xpp_packet_r_t)=%d\n",
-+ i+1, sizeof(xpp_packet_r_t));
-+ } else if(limiter == ERR_REPORT_LIMIT) {
-+ ERR("dump_packet: error packet #%d... squelsh reports.\n", limiter);
-+ }
-+ limiter++;
-+ break;
-+ }
-+ DBG(" %2d> %02X\n", i+1, p[i]);
-+ }
-+ }
-+#endif
-+}
-+
-+/*------------------------- Reply Handlers -------------------------*/
-+
-+#define HANDLER_DEF(name) \
-+ int CALL_PROTO(name, xbus_t *xbus, int xpd_num, xpp_command_t *cmd, xpacket_t *reply)
-+
-+/*
-+static HANDLER_DEF(notimp)
-+{
-+ NOTICE("xpp protocol error: command %s is not implemented yet\n", cmd->name);
-+ return -EPROTO;
-+}
-+*/
-+static HANDLER_DEF(DEV_DESC)
-+{
-+ byte type = PACKET_FIELD(reply, DEV_DESC, type) & 0x7; // 3 LSB's
-+ byte rev = PACKET_FIELD(reply, DEV_DESC, rev);
-+ xpp_line_t line_status = PACKET_FIELD(reply, DEV_DESC, line_status);
-+ xpd_t *xpd = xpd_of(xbus, xpd_num);
-+
-+ if(xpd) {
-+ NOTICE("Received DEV_DESC packet for an existing xpd %s of type %d\n",
-+ xpd->xpdname, type);
-+ return 0;
-+ }
-+ XBUS_COUNTER(xbus, DEV_DESC)++;
-+ DBG("xpd=%d type=%d rev=%d line_status=0x%04X\n", xpd_num, type, rev, line_status);
-+ switch(type) {
-+ case XPD_TYPE_FXS:
-+ break;
-+ case XPD_TYPE_FXO:
-+ break;
-+ case XPD_TYPE_NOMODULE:
-+ DBG("No module at address=%d\n", xpd_num);
-+ return 0;
-+ default:
-+ NOTICE("DEV_DESC: unkown type=%d\n", type);
-+ return -EPROTO;
-+ }
-+ if((xpd = xpd_new(xbus, xpd_num, type, rev)) == NULL) {
-+ NOTICE("xpd_new failed\n");
-+ }
-+ xpp_check_hookstate(xpd, line_status);
-+ return 0;
-+}
-+
-+/**
-+ * Handle signalling
-+ */
-+static HANDLER_DEF(SIG_CHANGED)
-+{
-+ xpd_t *xpd = xpd_of(xbus, xpd_num);
-+ xpp_line_t sig_status = PACKET_FIELD(reply, SIG_CHANGED, sig_status);
-+
-+ if(!xpd) {
-+ NOTICE("%s: received %s for non-existing xpd: %d\n", __FUNCTION__, cmd->name, xpd_num);
-+ return -EPROTO;
-+ }
-+ if(xpd->direction == TO_PHONE) { /* Hook state changes */
-+ DBG("%s (PHONE) sig_status=0x%04X\n", xpd->xpdname, sig_status);
-+ xpp_check_hookstate(xpd, sig_status);
-+ } else { /* TO_TRUNK - line ring changes */
-+ unsigned long flags;
-+ int i;
-+
-+ DBG("%s (TRUNK) sig_status=0x%04X\n", xpd->xpdname, sig_status);
-+ spin_lock_irqsave(&xpd->lock, flags);
-+ for(i = 0; i < xpd->channels; i++) {
-+ if(IS_SET(sig_status, i)) {
-+ xpd->ringing[i] = RINGS_NUM*2;
-+ zt_hooksig(&xpd->chans[i], ZT_RXSIG_OFFHOOK);
-+ } else {
-+ zt_hooksig(&xpd->chans[i], ZT_RXSIG_ONHOOK);
-+ xpd->ringing[i] = 0;
-+ }
-+ }
-+ spin_unlock_irqrestore(&xpd->lock, flags);
-+ }
-+ return 0;
-+}
-+
-+static HANDLER_DEF(SLIC_REPLY)
-+{
-+ slic_reply_t *info = &PACKET_FIELD(reply, SLIC_REPLY, info);
-+ xpd_t *xpd = xpd_of(xbus, xpd_num);
-+ unsigned long flags;
-+
-+ if(!xpd) {
-+ NOTICE("%s: received %s for non-existing xpd: %d\n", __FUNCTION__, cmd->name, xpd_num);
-+ return -EPROTO;
-+ }
-+ spin_lock_irqsave(&xpd->lock, flags);
-+ DBG("SLIC_REPLY: xpd #%d %s reg_num=0x%X, dataL=0x%X dataH=0x%X\n",
-+ xpd_num, (info->indirect)?"I":"D",
-+ info->reg_num, info->data_low, info->data_high);
-+ spin_unlock_irqrestore(&xpd->lock, flags);
-+ return 0;
-+}
-+
-+static HANDLER_DEF(PCM_READ)
-+{
-+ /* FIXME: work around temporary hardware bug */
-+ xpd_num = 0;
-+
-+ xpp_line_t lines = PACKET_FIELD(reply, PCM_READ, lines);
-+ const byte *pcm = PACKET_FIELD(reply, PCM_READ, pcm);
-+ xpd_t *xpd = xpd_of(xbus, xpd_num);
-+ volatile u_char *readchunk;
-+ volatile u_char *r;
-+ unsigned long flags;
-+ int i;
-+
-+ if(!xpd) {
-+ NOTICE("%s: received %s for non-existing xpd: %d\n", __FUNCTION__, cmd->name, xpd_num);
-+ return -EPROTO;
-+ }
-+ // DBG("lines=0x%04X\n", lines);
-+
-+ if(!pcm_valid(xpd, reply)) {
-+ return -EPROTO;
-+ }
-+ spin_lock_irqsave(&xpd->lock, flags);
-+ if (xpd->timer_count & 1) {
-+ /* First part */
-+ r = readchunk = xpd->readchunk;
-+ } else {
-+ r = readchunk = xpd->readchunk + ZT_CHUNKSIZE * CHANNELS_PERXPD;
-+ }
-+
-+ /* Copy PCM and put each channel in its index */
-+ for (i = 0; i < CHANNELS_PERXPD; i++) {
-+ if(IS_SET(lines, i)) {
-+ memcpy((u_char *)r, pcm, ZT_CHUNKSIZE);
-+ //memset((u_char *)r, 0x5A, ZT_CHUNKSIZE); // DEBUG
-+ pcm += ZT_CHUNKSIZE;
-+ }
-+ r += ZT_CHUNKSIZE;
-+ }
-+
-+ XPD_COUNTER(xpd, PCM_READ)++;
-+ XBUS_COUNTER(xpd->xbus, PCM_READ)++;
-+ spin_unlock_irqrestore(&xpd->lock, flags);
-+ if(xpd->id == 0)
-+ xpp_tick(0);
-+ return 0;
-+}
-+
-+static HANDLER_DEF(SYNC_REPLY)
-+{
-+ xpd_t *xpd = xpd_of(xbus, xpd_num);
-+
-+ if(!xpd) {
-+ NOTICE("%s: received %s for non-existing xpd: %d\n", __FUNCTION__, cmd->name, xpd_num);
-+ return -EPROTO;
-+ }
-+ DBG("SYNC_REPLY: 0x%X\n", PACKET_FIELD(reply, SYNC_REPLY, mask));
-+ return 0;
-+}
-+
-+static HANDLER_DEF(LOOPBACK_XA)
-+{
-+ xpd_t *xpd = xpd_of(xbus, xpd_num);
-+
-+ if(!xpd) {
-+ NOTICE("%s: received %s for non-existing xpd: %d\n", __FUNCTION__, cmd->name, xpd_num);
-+ return -EPROTO;
-+ }
-+ dump_packet("LOOPBACK_XA", reply, print_dbg);
-+ CALL_PROTO(LED, xpd->xbus, xpd, xpd->enabled_chans, LED_RED, 0); // FIXME: Find usage for extra LED
-+ return 0;
-+}
-+
-+static HANDLER_DEF(DIAG_FE)
-+{
-+ dump_packet("DIAG_FE", reply, print_dbg);
-+ return 0;
-+}
-+
-+static const xpp_packet_r_t FOR_SIZE_CALC; // Ugly hack, so we have something to sizeof()
-+
-+#define C_(op,var,txt) \
-+ [ XPP_##op ] { \
-+ .opcode = XPP_##op, \
-+ .varsize = var, \
-+ .header_size = sizeof(FOR_SIZE_CALC.cmd_##op), \
-+ .name = #op, \
-+ .desc = txt, \
-+ .handler = PROTO_FUNC(op) \
-+ }
-+
-+static xpp_command_t xpp_commands[] = {
-+ /* OP V DESCRIPTION */
-+ C_( DEV_DESC, 0, "Device description reply"),
-+ C_( SIG_CHANGED, 0, "Signaling change (hookstate/ringing)"),
-+ C_( SLIC_REPLY, 0, "Reply to slic state"),
-+ C_( PCM_READ, 1, "Read PCM data"),
-+ C_( SYNC_REPLY, 0, "SYNC_REPLY"),
-+ C_( LOOPBACK_XA, 1, "LOOPBACK Reply"),
-+ C_( DIAG_FE, 1, "DIAG FE Opcode"),
-+};
-+
-+#undef C_
-+
-+static unsigned int xpp_max_opcode(void)
-+{
-+ return ARRAY_SIZE(xpp_commands);
-+}
-+
-+static bool xpp_valid_opcode(xpp_opcode_t op)
-+{
-+ if(op <= 0 || op >= xpp_max_opcode())
-+ return 0;
-+ return xpp_commands[op].opcode != XPP_NOTIMP;
-+}
-+
-+static xpp_command_t *xpp_command(xpp_opcode_t op)
-+{
-+ if(!xpp_valid_opcode(op))
-+ return 0;
-+ return &xpp_commands[op];
-+}
-+
-+static bool xpp_valid_size(xpp_opcode_t op, xpacket_t *pack)
-+{
-+ xpp_command_t *cmd = xpp_command(op);
-+ unsigned int hsize = cmd->header_size;
-+ unsigned int size = pack->datalen;
-+ int varsize = cmd->varsize;
-+
-+ // ERR("op=%d hsize=%d size=%d\n", op, hsize, size);
-+ return (hsize == size) ||
-+ (varsize && size <= sizeof(struct xpp_packet_r));
-+}
-+
-+static bool pcm_valid(xpd_t *xpd, xpacket_t *reply)
-+{
-+ xpp_opcode_t op;
-+ xpp_command_t *cmd;
-+ xpp_line_t lines = PACKET_FIELD(reply, PCM_READ, lines);
-+ int i;
-+ int count = 0;
-+
-+ BUG_ON(!reply);
-+ op = reply->content.opcode;
-+ cmd = xpp_command(op);
-+ if(!cmd) {
-+ ERR("xpp: %s -- bad command op=0x%02X\n", __FUNCTION__, op);
-+ return 0;
-+ }
-+ for (i = 0; i < CHANNELS_PERXPD; i++)
-+ if(IS_SET(lines, i))
-+ count++;
-+ if(reply->datalen != (sizeof(xpp_line_t) + count * 8)) {
-+ static int rate_limit = 0;
-+
-+ XPD_COUNTER(xpd, RECV_ERRORS)++;
-+ if((rate_limit++ % 1000) <= 10) {
-+ ERR("BAD PCM REPLY: reply->datalen=%d, count=%d\n", reply->datalen, count);
-+ }
-+ return 0;
-+ }
-+ return 1;
-+}
-+
-+int packet_receive(xbus_t *xbus, xpacket_t *pack)
-+{
-+ int xpd_num = XPD_NUM(pack->content.addr);
-+
-+ if(!VALID_XPD_NUM(xpd_num)) {
-+ dump_packet("martian packet", pack, print_dbg);
-+ xbus->ops->packet_free(xbus, pack);
-+ return -EPROTO;
-+ }
-+ if(xbus->sim[xpd_num].simulated) {
-+ //dump_packet("packet_receive -> simulate", pack, print_dbg);
-+ return simulate_xpd(xbus, xpd_num, pack);
-+ } else {
-+ //dump_packet("packet_receive -> process", pack, print_dbg);
-+ return packet_process(xbus, xpd_num, pack);
-+ }
-+}
-+
-+static int packet_process(xbus_t *xbus, int xpd_num, xpacket_t *pack)
-+{
-+ xpp_opcode_t op;
-+ xpp_command_t *cmd;
-+ xpp_handler_t handler;
-+ int ret = 0;
-+
-+ BUG_ON(!pack);
-+ op = pack->content.opcode;
-+ cmd = xpp_command(op);
-+ /*-------- Validations -----------*/
-+ if(!cmd) {
-+ ERR("xpp: %s -- bad command op=0x%02X\n", __FUNCTION__, op);
-+ dump_packet("packet_process -- bad command", pack, print_dbg);
-+ ret = -EPROTO;
-+ goto out;
-+ }
-+ if(!xpp_valid_size(op, pack)) {
-+ ERR("xpp: %s: wrong size %d for op=0x%02X\n",
-+ __FUNCTION__, pack->datalen, op);
-+ dump_packet("packet_process -- wrong size", pack, print_dbg);
-+ ret = -EPROTO;
-+ goto out;
-+ }
-+ handler = cmd->handler;
-+ BUG_ON(!handler);
-+ XBUS_COUNTER(xbus, RX_BYTES) += pack->datalen;
-+ handler(xbus, xpd_num, cmd, pack);
-+out:
-+ xbus->ops->packet_free(xbus, pack);
-+ return ret;
-+}
-+
-+
-+void process_sim_queue(void *data)
-+{
-+ xbus_t *xbus = data;
-+ xpacket_t *pack;
-+
-+// DBG("\n");
-+ BUG_ON(!xbus);
-+ while((pack = xbus_dequeue_packet(&xbus->sim_packet_queue)) != NULL) {
-+// DBG("pack->addr=0x%X pack->opcode=0x%X\n", XPD_NUM(pack->addr), pack->header.opcode);
-+ packet_receive(xbus, pack);
-+ }
-+}
-+
-+/**
-+ * processes a packet recieved from the lower-level.
-+ * @xbus the data bus
-+ * @pack the handled packet
-+ * @returns return status (0 for success).
-+ *
-+ * Should not be blocking.
-+ * Has separate handling for PCM packets (direct write) and command packets (queued)
-+ */
-+
-+EXPORT_SYMBOL(dump_packet);
-+EXPORT_SYMBOL(packet_receive);
-+EXPORT_SYMBOL(proc_xpd_slic_read);
-+EXPORT_SYMBOL(proc_xpd_slic_write);
-diff -urNad zaptel-1.0.10/xpp/xpp_proto.h /tmp/dpep.absTwN/zaptel-1.0.10/xpp/xpp_proto.h
---- zaptel-1.0.10/xpp/xpp_proto.h 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.absTwN/zaptel-1.0.10/xpp/xpp_proto.h 2006-01-12 12:30:09.638318611 +0200
-@@ -0,0 +1,188 @@
-+#ifndef XPP_PROTO_H
-+#define XPP_PROTO_H
-+
-+#include "xpd.h"
-+#include "slic.h"
-+#ifdef __KERNEL__
-+#include <linux/list.h>
-+#endif
-+
-+#define PCM_CHUNKSIZE (CHANNELS_PERXPD * ZT_MAX_CHUNKSIZE)
-+
-+typedef enum xpp_opcode {
-+ XPP_NOTIMP = 0x00,
-+//
-+ XPP_DESC_REQ = 0x04,
-+ XPP_DEV_DESC = 0x05,
-+//
-+ XPP_SIG_CHANGED = 0x06,
-+//
-+ XPP_SLIC_WRITE = 0x0F, // Write to SLIC
-+ XPP_CHAN_ENABLE = 0x0F, // Write to SLIC
-+ XPP_CHAN_POWER = 0x0F, // Write to SLIC
-+ XPP_RING = 0x0F, // Write to SLIC
-+ XPP_SETHOOK = 0x0F, // Write to SLIC
-+ XPP_LED = 0x0F, // Write to SLIC
-+ XPP_RELAY_OUT = 0x0F, // Write to SLIC
-+ XPP_SLIC_INIT = 0x0F, // Write to SLIC
-+ XPP_SLIC_QUERY = 0x0F, // Write to SLIC
-+//
-+ XPP_SLIC_REPLY = 0x10,
-+//
-+ XPP_PCM_WRITE = 0x11,
-+ XPP_PCM_READ = 0x12,
-+//
-+ XPP_PCM_GEN = 0x13,
-+//
-+ XPP_SYNC_SOURCE = 0x19,
-+ XPP_SYNC_REPLY = 0x1A,
-+//
-+ XPP_LOOPBACK_AX = 0x31,
-+ XPP_LOOPBACK_XA = 0x32,
-+ XPP_DIAG_FE = 0xFE,
-+} xpp_opcode_t;
-+
-+/*------------------------- PROTOCOL COMMANDS ----------------------*/
-+
-+#define XPP_MAX_DATA 50
-+
-+typedef struct slic_data {
-+ byte len;
-+ byte data[40];
-+} __attribute__((packed)) slic_data_t;
-+
-+#define PROTO_FUNC(name) xpp_proto_ ## name
-+#define CALL_PROTO(name, ...) PROTO_FUNC(name)( __VA_ARGS__ )
-+#define DECLARE_CMD(name, ...) \
-+ int CALL_PROTO(name, xbus_t *xbus, xpd_t *xpd, ## __VA_ARGS__ )
-+
-+/* 0x04 */ DECLARE_CMD(DESC_REQ, int xpd_num);
-+/* 0x0F */ DECLARE_CMD(CHAN_ENABLE, xpp_line_t lines, bool on);
-+/* 0x0F */ DECLARE_CMD(CHAN_POWER, xpp_line_t lines, bool on);
-+/* 0x0F */ DECLARE_CMD(RING, int pos, bool on);
-+/* 0x0F */ DECLARE_CMD(SETHOOK, xpp_line_t hook_status);
-+/* 0x0F */ DECLARE_CMD(LED, xpp_line_t lines, byte which, bool on);
-+/* 0x0F */ DECLARE_CMD(RELAY_OUT, byte which, bool on);
-+/* 0x0F */ DECLARE_CMD(SLIC_INIT);
-+/* 0x0F */ DECLARE_CMD(SLIC_QUERY, int pos, byte reg_num);
-+/* 0x11 */ DECLARE_CMD(PCM_WRITE, xpp_line_t hookstate, volatile byte *buf);
-+/* 0x13 */ DECLARE_CMD(PCM_GEN, xpp_line_t lines, volatile byte *buf);
-+/* 0x19 */ DECLARE_CMD(SYNC_SOURCE, bool setit, bool is_master);
-+/* 0x31 */ DECLARE_CMD(LOOPBACK_AX, byte *data, unsigned int size);
-+
-+#define H_(op, ...) struct { \
-+ __VA_ARGS__ \
-+ } __attribute__((packed)) cmd_##op
-+
-+/*
-+ * This struct must be packed exactly as the wire
-+ * representation of the packet header after the
-+ * XPD address byte
-+ */
-+typedef struct xpp_packet_r {
-+ byte opcode;
-+ xpp_addr_t addr;
-+ union {
-+
-+ H_(NOTIMP);
-+ H_(DESC_REQ);
-+ H_(DEV_DESC,
-+ byte rev; /* Revision number */
-+ byte type;
-+ xpp_line_t line_status; /* hook/ring status, depending on unit */
-+ );
-+
-+ H_(SIG_CHANGED,
-+ byte type; /* unused -- we have it from DEV_DESC */
-+ xpp_line_t sig_status; /* channels: lsb=1, msb=8 */
-+ xpp_line_t sig_toggles; /* channels: lsb=1, msb=8 */
-+ );
-+
-+ H_(SLIC_INIT,
-+ xpp_line_t lines;
-+ slic_data_t slic_data;
-+ );
-+ H_(SLIC_WRITE,
-+ slic_cmd_t slic_cmd;
-+ );
-+ H_(SLIC_REPLY, /* Get status of a single SLIC (for debugging) */
-+ xpp_line_t lines;
-+ slic_reply_t info;
-+ );
-+
-+ H_(PCM_WRITE,
-+ xpp_line_t lines; // Must be 0xFF
-+ byte pcm[PCM_CHUNKSIZE];
-+ );
-+ H_(PCM_READ,
-+ xpp_line_t lines; // Must be 0xFF
-+ byte pcm[PCM_CHUNKSIZE];
-+ );
-+
-+ H_(PCM_GEN,
-+ xpp_line_t lines;
-+ byte gen;
-+ byte pcm_seq[ZT_CHUNKSIZE];
-+ );
-+
-+ H_(SYNC_SOURCE,
-+ byte mask;
-+ );
-+ H_(SYNC_REPLY,
-+ byte mask;
-+ );
-+
-+ H_(LOOPBACK_AX,
-+ byte data[XPP_MAX_DATA]; // FIXME: what data size?
-+ );
-+ H_(LOOPBACK_XA,
-+ byte data[XPP_MAX_DATA]; // FIXME: what data size?
-+ );
-+ H_(DIAG_FE);
-+ unsigned char raw[0];
-+ };
-+} __attribute__((packed)) xpp_packet_r_t;
-+#undef H_
-+
-+#ifdef __KERNEL__
-+
-+enum {
-+ XPP_PACKET_FIREANDFORGET = 0x1,
-+};
-+
-+/**
-+ * The packet that will actually be sent on the wire.
-+ *
-+ * TODO: not a good medium-level abstrction
-+ */
-+struct xpp_packet {
-+ struct xpp_packet_r content;
-+ unsigned int flags;
-+ size_t datalen;
-+ struct list_head list;
-+};
-+
-+#define DATA_LEN(p, name) \
-+ sizeof(p->content.cmd_ ## name)
-+
-+#define PACKET_LEN(p) \
-+ ((p)->datalen + sizeof(xpp_addr_t) + 1)
-+
-+#define PACKET_INIT(p, name) \
-+ p->content.opcode = XPP_ ## name; \
-+ p->datalen = DATA_LEN(p, name)
-+
-+#define PACKET_FIELD(p, name, field) \
-+ p->content.cmd_ ## name.field
-+
-+void dump_packet(const char *msg, xpacket_t *packet, bool print_dbg);
-+void enqueue_xmit(xbus_t *xbus, xpacket_t *pack);
-+void process_sim_queue(void *xbus);
-+int validate_reply(xpacket_t *reply);
-+int packet_receive(xbus_t *xbus, xpacket_t *pack);
-+int proc_xpd_slic_write(struct file *file, const char __user *buffer, unsigned long count, void *data);
-+int proc_xpd_slic_read(char *page, char **start, off_t off, int count, int *eof, void *data);
-+
-+#endif
-+
-+#endif /* XPP_PROTO_H */
-diff -urNad zaptel-1.0.10/xpp/xpp_usb.c /tmp/dpep.absTwN/zaptel-1.0.10/xpp/xpp_usb.c
---- zaptel-1.0.10/xpp/xpp_usb.c 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.absTwN/zaptel-1.0.10/xpp/xpp_usb.c 2006-01-09 18:14:37.000000000 +0200
-@@ -0,0 +1,873 @@
-+/*
-+ * Written by Oron Peled <oron at actcom.co.il>
-+ * Copyright (C) 2004-2005, Xorcom
-+ *
-+ * All rights reserved.
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License as published by
-+ * the Free Software Foundation; either version 2 of the License, or
-+ * (at your option) any later version.
-+ *
-+ * This program is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ * GNU General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-+ *
-+ */
-+#include <linux/version.h>
-+
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+# warning "This module is tested only with 2.6 kernels"
-+#endif
-+
-+#include <linux/kernel.h>
-+#include <linux/errno.h>
-+#include <linux/module.h>
-+#include <linux/init.h>
-+#include <linux/errno.h>
-+#include <linux/delay.h> /* for udelay */
-+#include <linux/seq_file.h>
-+#include <asm/uaccess.h>
-+#include <asm/atomic.h>
-+#include <asm/timex.h>
-+#include <linux/proc_fs.h>
-+#include <linux/usb.h>
-+#include "xpd.h"
-+#include "xproto.h"
-+#include "xpp_zap.h"
-+
-+static const char revision[] = "$Revision: 181 $";
-+
-+DEF_PARM(int, print_dbg, 1, "Print DBG statements"); /* must be before zap_debug.h */
-+
-+#include "zap_debug.h"
-+
-+#define USBDEV_MAX 10
-+/* Get a minor range for your devices from the usb maintainer */
-+#define USB_SKEL_MINOR_BASE 192
-+
-+#ifdef CONFIG_PROC_FS
-+#define PROC_XBUSES "xpp_usb"
-+#define PROC_USBXPP_SUMMARY "xpp_usb"
-+#endif
-+
-+#ifdef DEBUG_PCM_TIMING
-+static cycles_t stamp_last_pcm_read;
-+static cycles_t accumulate_diff;
-+#endif
-+
-+struct xusb_model_info;
-+
-+struct xusb_endpoint {
-+ int epnum;
-+ int max_size;
-+};
-+
-+static int xusb_packet_send(xbus_t *xbus, xpacket_t *pack);
-+
-+xbus_ops_t xusb_ops = {
-+ .packet_send = xusb_packet_send,
-+ .packet_new = NULL, // Default allocator
-+ .packet_free = NULL, // Default deallocator
-+};
-+
-+enum {
-+ XUSB_N_RX_PACKETS,
-+ XUSB_N_TX_PACKETS,
-+ XUSB_N_RX_ERRORS,
-+ XUSB_N_TX_ERRORS,
-+ XUSB_N_PCM_READS,
-+ XUSB_N_PCM_WRITES,
-+};
-+
-+#define XUSB_COUNTER(xusb, counter) ((xusb)->counters[XUSB_N_ ## counter])
-+
-+#define C_(x) [ XUSB_N_ ## x ] = { #x }
-+
-+static struct xusb_counters {
-+ char *name;
-+} xusb_counters[] = {
-+ C_(RX_PACKETS),
-+ C_(TX_PACKETS),
-+ C_(RX_ERRORS),
-+ C_(TX_ERRORS),
-+ C_(PCM_READS),
-+ C_(PCM_WRITES),
-+};
-+
-+#undef C_
-+
-+#define XUSB_COUNTER_MAX ARRAY_SIZE(xusb_counters)
-+
-+/*
-+ * USB XPP Bus (a USB Device)
-+ */
-+struct xpp_usb_bus {
-+ xbus_t *xbus;
-+ struct usb_device *udev; /* save off the usb device pointer */
-+ struct usb_interface *interface; /* the interface for this device */
-+ unsigned char minor; /* the starting minor number for this device */
-+
-+ struct xusb_model_info *model_info;
-+ struct xusb_endpoint ep_in;
-+ struct xusb_endpoint ep_out;
-+
-+ struct urb *read_urb;
-+
-+ struct completion write_finished; /* wait for the write to finish */
-+
-+ int present; /* if the device is not disconnected */
-+ int reading; /* is the read_urb reading (listening) */
-+ struct semaphore sem; /* locks this structure */
-+ int counters[XUSB_COUNTER_MAX];
-+};
-+
-+static spinlock_t xusb_lock = SPIN_LOCK_UNLOCKED;
-+static struct xpp_usb_bus *xusb_array[USBDEV_MAX] = {};
-+static unsigned bus_count = 0;
-+
-+
-+/* prevent races between open() and disconnect() */
-+static DECLARE_MUTEX (disconnect_sem);
-+
-+/*
-+ * Function Prototypes
-+ */
-+#if 0
-+static ssize_t xusb_read (struct file *file, char *buffer, size_t count, loff_t *ppos);
-+static ssize_t xusb_write (struct file *file, const char *buffer, size_t count, loff_t *ppos);
-+static int xusb_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg);
-+static int xusb_open (struct inode *inode, struct file *file);
-+static int xusb_release (struct inode *inode, struct file *file);
-+static void xusb_write_bulk_callback (struct urb *urb, struct pt_regs *regs);
-+#endif
-+static void xpp_urb_delete(struct urb *urb);
-+static struct urb *xpp_urb_new(struct xpp_usb_bus *dev, unsigned int ep_addr, size_t size, usb_complete_t urb_cb);
-+static void xpp_send_callback(struct urb *urb, struct pt_regs *regs);
-+static void xpp_receive_callback(struct urb *urb, struct pt_regs *regs);
-+
-+static int xusb_probe (struct usb_interface *interface, const struct usb_device_id *id);
-+static void xusb_disconnect (struct usb_interface *interface);
-+static int xusb_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data);
-+
-+/*------------------------------------------------------------------*/
-+
-+#if 0
-+/**
-+ * Allocates a new XPP packet.
-+ * @xbus The XPP bus in which the packet will flow (for counters
-+ * maintenance)
-+ * @flags Flags for kernel memory allocation.
-+ * @returns A pointer to the new packet, or NULL in case of failure.
-+ *
-+ *
-+ * Packet allocation/deallocation:
-+ * Sent packets:
-+ * - Allocated by protocol commands
-+ * - Deallocated by xmus_xmitter
-+ * Receive packets:
-+ * - Allocated/deallocated by xbus_xmiter
-+ */
-+xpacket_t *xusb_packet_new(xbus_t *xbus, int flags)
-+{
-+ xpacket_t *pack;
-+
-+ /* To avoid races we increament counter in advance and decrement it later
-+ * in case of failure */
-+ atomic_inc(&xbus->packet_counter);
-+ //DBG("Incremented packet_counter of bus %s (new packet) to %d\n",
-+ // xbus->busname, atomic_read(&xbus->packet_counter));
-+ pack = kmem_cache_alloc(packet_cache, flags);
-+ if (pack) {
-+ memset(pack, 0, sizeof(xpacket_t));
-+ atomic_inc(&xpacket_count);
-+ } else {
-+ atomic_dec(&xbus->packet_counter);
-+ //DBG("Decremented packet_counter of bus %s (failed new packet) to %d\n",
-+ // xbus->busname, atomic_read(&xbus->packet_counter));
-+ }
-+ return pack;
-+}
-+
-+void xusb_packet_free(xbus_t *xbus, xpacket_t *p)
-+{
-+ kmem_cache_free(packet_cache, p);
-+ atomic_dec(&xpacket_count);
-+ atomic_dec(&xbus->packet_counter);
-+ //DBG("Decremented packet_counter of bus %s (freed packet) to %d\n",
-+ // xbus->busname, atomic_read(&xbus->packet_counter));
-+}
-+#endif
-+
-+static int xusb_packet_send(xbus_t *xbus, xpacket_t *pack)
-+{
-+ struct xpp_usb_bus *xusb = xbus->priv;
-+ struct urb *urb;
-+ int ret = 0;
-+ size_t size;
-+
-+ BUG_ON(!pack);
-+ if(!xusb->present) {
-+ NOTICE("tried to send packets to non-exitant USB device. Ignored\n");
-+ goto error;
-+ }
-+#if SOFT_SIMULATOR
-+ {
-+ int toxpd = XPD_NUM(pack->content.addr);
-+
-+ if (xbus->sim[toxpd].softloop_xpd) {
-+ // "send" through loopback queue
-+ //DBG("%s: ENQUEUE toxpd=%d, opcode=%X\n", xbus->busname, toxpd, pack->content.opcode);
-+ XBUS_COUNTER(xbus, SOFTSIM_PACKETS)++;
-+ xbus_enqueue_packet(xbus, &xbus->sim_packet_queue, pack);
-+ ret = queue_work(xbus->sim_workqueue, &xbus->sim_work);
-+ if(ret < 0) {
-+ ERR("%s: queue_work failed with %d (ignoring)\n", __FUNCTION__, ret);
-+ goto error;
-+ }
-+ }
-+ return 0;
-+ }
-+#endif
-+ size = min(PACKET_LEN(pack), (size_t)xusb->ep_out.max_size);
-+ if(pack->content.opcode == XPROTO_NAME(GLOBAL,PCM_WRITE)) {
-+ XUSB_COUNTER(xusb, PCM_WRITES)++;
-+
-+#ifdef DEBUG_PCM_TIMING
-+ /*
-+ * DEBUG: high-res timing of PCM_READ to PCM_WRITE
-+ */
-+ cycles_t diff = get_cycles() - stamp_last_pcm_read;
-+ accumulate_diff += diff;
-+#endif
-+#if 0
-+ static int rate_limit;
-+ if((rate_limit++ % 1009) < 3) {
-+ dump_packet("USB SEND PCM", pack, print_dbg);
-+ }
-+#endif
-+ } else {
-+ dump_packet("USB_PACKET_SEND", pack, print_dbg);
-+ }
-+ urb = xpp_urb_new(xusb, xusb->ep_out.epnum, size, xpp_send_callback);
-+ if (!urb) {
-+ ERR("No free urbs available\n");
-+ ret = -ENOMEM;
-+ goto error;
-+ }
-+
-+ /* FIXME: FIXME: FIXME: we use copy+free until low-level drivers allocate memory themselves */
-+ memcpy(urb->transfer_buffer, &pack->content, size);
-+ xbus->ops->packet_free(xbus, pack);
-+
-+ ret = usb_submit_urb(urb, GFP_KERNEL);
-+ if(ret < 0) {
-+ ERR("%s: failed submit_urb\n", __FUNCTION__);
-+ XUSB_COUNTER(xusb, TX_ERRORS)++;
-+ xpp_urb_delete(urb);
-+ return -EBADF;
-+ }
-+ return 0;
-+error:
-+ xbus->ops->packet_free(xbus, pack); // FIXME: eventually will be done in the urb callback
-+ return ret;
-+}
-+
-+static void xpp_urb_delete(struct urb *urb)
-+{
-+ // DBG("%s: (%d) %p %X", __FUNCTION__, urb->transfer_buffer_length, urb->transfer_buffer, urb->transfer_dma);
-+ usb_buffer_free (urb->dev, urb->transfer_buffer_length,
-+ urb->transfer_buffer,
-+ urb->transfer_dma);
-+ usb_free_urb (urb);
-+}
-+
-+static struct urb *xpp_urb_new(struct xpp_usb_bus *dev, unsigned int ep_addr, size_t size, usb_complete_t urb_cb)
-+
-+{
-+ struct usb_device *udev = dev->udev;
-+ struct urb *urb;
-+ unsigned char *buffer; /* the buffer to send data */
-+ unsigned int epnum = ep_addr & USB_ENDPOINT_NUMBER_MASK;
-+ int pipe = usb_pipein(ep_addr)
-+ ? usb_rcvbulkpipe(udev, epnum)
-+ : usb_sndbulkpipe(udev, epnum);
-+
-+ urb = usb_alloc_urb(0, GFP_ATOMIC);
-+ if (!urb) {
-+ err("No free urbs available");
-+ return NULL;
-+ }
-+
-+ /* on some platforms using this kind of buffer alloc
-+ * call eliminates a dma "bounce buffer".
-+ *
-+ * NOTE: you'd normally want i/o buffers that hold
-+ * more than one packet, so that i/o delays between
-+ * packets don't hurt throughput. (Probably applies only to isochronous
-+ * transfers)
-+ */
-+ urb->transfer_flags = (URB_NO_TRANSFER_DMA_MAP | URB_ASYNC_UNLINK);
-+ buffer = usb_buffer_alloc(udev, size, GFP_ATOMIC, &urb->transfer_dma);
-+ // DBG("(%d) %p / %x", size, buffer, urb->transfer_dma);
-+ if (!buffer) {
-+ err("Couldn't allocate buffer");
-+ usb_free_urb(urb);
-+ return NULL;
-+ }
-+ usb_fill_bulk_urb(urb, udev, pipe, buffer, size, urb_cb, dev);
-+ return urb;
-+}
-+
-+/*------------------------- XPP USB Bus Handling -------------------*/
-+
-+static struct xusb_model_info {
-+ const char *desc;
-+ struct xusb_endpoint in;
-+ struct xusb_endpoint out;
-+ xbus_type_t bus_type;
-+} model_table[] = {
-+ { .in = { .epnum = 0x86 }, .out = { .epnum = 0x2 }, .bus_type = FIRMWARE_LOOPBACK, .desc = "bulkloop.hex" },
-+ { .in = { .epnum = 0x86 }, .out = { .epnum = 0x2 }, .bus_type = FIRMWARE_LOOPBACK, .desc = "FPGA_bulkloop.hex" },
-+ { .in = { .epnum = 0x86 }, .out = { .epnum = 0x2 }, .bus_type = FIRMWARE_XPP, .desc = "FPGA_XPD.hex" },
-+};
-+
-+/* table of devices that work with this driver */
-+static struct usb_device_id xusb_table [] = {
-+// { USB_DEVICE(0x04B4, 0x8613) }, // default of cypress
-+ { USB_DEVICE(0x0547, 0x1002), .driver_info=(int)&model_table[0] }, // bulkloop.hex
-+// { USB_DEVICE(0x04B4, 0x1004), .driver_info=(int)&model_table[1] }, // FPGA_bulkloop.hex
-+// { USB_DEVICE(0x04B4, 0x1004), .driver_info=(int)&model_table[2] }, // FIXME: temporary test for Dima
-+ { USB_DEVICE(0xE4E4, 0x2211), .driver_info=(int)&model_table[2] }, // FPGA_XPD.hex
-+ //{ USB_DEVICE(0x0548, 0x1) },
-+ //{ USB_DEVICE(0x062a, 0x0) },
-+ /* "Gadget Zero" firmware runs under Linux */
-+ //{ USB_DEVICE(0x0525, 0xa4a0) },
-+ { } /* Terminating entry */
-+};
-+
-+MODULE_DEVICE_TABLE (usb, xusb_table);
-+
-+
-+/* usb specific object needed to register this driver with the usb subsystem */
-+static struct usb_driver xusb_driver = {
-+ .owner = THIS_MODULE,
-+ .name = "xpp_usb",
-+ .probe = xusb_probe,
-+ .disconnect = xusb_disconnect,
-+ .id_table = xusb_table,
-+};
-+
-+/*
-+ * File operations needed when we register this driver.
-+ * This assumes that this driver NEEDS file operations,
-+ * of course, which means that the driver is expected
-+ * to have a node in the /dev directory. If the USB
-+ * device were for a network interface then the driver
-+ * would use "struct net_driver" instead, and a serial
-+ * device would use "struct tty_driver".
-+ */
-+static struct file_operations xusb_fops = {
-+ /*
-+ * The owner field is part of the module-locking
-+ * mechanism. The idea is that the kernel knows
-+ * which module to increment the use-counter of
-+ * BEFORE it calls the device's open() function.
-+ * This also means that the kernel can decrement
-+ * the use-counter again before calling release()
-+ * or should the open() function fail.
-+ */
-+ .owner = THIS_MODULE,
-+};
-+
-+/*
-+ * usb class driver info in order to get a minor number from the usb core,
-+ * and to have the device registered with devfs and the driver core
-+ */
-+static struct usb_class_driver xusb_class = {
-+ .name = "usb/xpp_usb%d",
-+ .fops = &xusb_fops,
-+ .mode = S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH,
-+ .minor_base = USB_SKEL_MINOR_BASE,
-+};
-+
-+/*
-+ * set up the endpoint information
-+ * check out the endpoints
-+ * FIXME: Should be simplified (above 2.6.10) to use usb_dev->ep_in[0..16] and usb_dev->ep_out[0..16]
-+ */
-+static int set_endpoints(struct xpp_usb_bus *xusb, struct usb_interface *interface, struct xusb_model_info *model_info)
-+{
-+ struct usb_host_interface *iface_desc;
-+ struct usb_endpoint_descriptor *endpoint;
-+ int i;
-+
-+ iface_desc = &interface->altsetting[0];
-+ DBG("Found interface. Endpoints: %d\n", iface_desc->desc.bNumEndpoints);
-+
-+#define BULK_ENDPOINT(ep) (((ep)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK)
-+
-+ for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
-+ endpoint = &iface_desc->endpoint[i].desc;
-+ int epnum = endpoint->bEndpointAddress;
-+
-+ if(!BULK_ENDPOINT(endpoint)) {
-+ DBG("endpoint 0x%x is not bulk: mbAttributes=0x%X\n",
-+ epnum, endpoint->bmAttributes);
-+ continue;
-+ }
-+ if(epnum & USB_DIR_IN) { // Input
-+ if(epnum == model_info->in.epnum) {
-+ if(endpoint->wMaxPacketSize < sizeof(xpacket_raw_t)) {
-+ ERR("USB input endpoint 0x%X support only wMaxPacketSize=%d (need USB-2)\n", epnum, endpoint->wMaxPacketSize);
-+ break;
-+ }
-+ xusb->ep_in.epnum = epnum;
-+ xusb->ep_in.max_size = endpoint->wMaxPacketSize;
-+ }
-+ } else { // Output
-+ if(epnum == model_info->out.epnum) {
-+ if(endpoint->wMaxPacketSize < sizeof(xpacket_raw_t)) {
-+ ERR("USB output endpoint 0x%X support only wMaxPacketSize=%d (need USB-2)\n", epnum, endpoint->wMaxPacketSize);
-+ break;
-+ }
-+ xusb->ep_out.epnum = epnum;
-+ xusb->ep_out.max_size = endpoint->wMaxPacketSize;
-+ }
-+ }
-+ }
-+ if (!xusb->ep_in.epnum || !xusb->ep_out.epnum) {
-+ ERR("Couldn't find bulk-in or bulk-out endpoints\n");
-+ return 0;
-+ }
-+ return 1;
-+}
-+
-+/**
-+ * xusb_probe
-+ *
-+ * Called by the usb core when a new device is connected that it thinks
-+ * this driver might be interested in.
-+ */
-+static int xusb_probe(struct usb_interface *interface, const struct usb_device_id *id)
-+{
-+ struct usb_device *udev = interface_to_usbdev(interface);
-+ struct xpp_usb_bus *xusb = NULL;
-+ struct xusb_model_info *model_info = (struct xusb_model_info*)id->driver_info;
-+ struct proc_dir_entry *procsummary;
-+ xbus_t *xbus;
-+ unsigned long flags;
-+ int retval = -ENOMEM;
-+ int i;
-+
-+ INFO("New XUSB device MODEL=%s bus_type=%d\n", model_info->desc, model_info->bus_type);
-+
-+ if((retval = usb_reset_device(udev)) < 0) {
-+ ERR("usb_reset_device failed: %d\n", retval);
-+ goto probe_failed;
-+ }
-+ if (!model_info) {
-+ ERR("Missing endpoint setup for this device %d:%d\n",
-+ udev->descriptor.idVendor,udev->descriptor.idProduct);
-+ retval = -ENODEV;
-+ goto probe_failed;
-+ }
-+
-+ /* allocate memory for our device state and initialize it */
-+ xusb = kmalloc(sizeof(struct xpp_usb_bus), GFP_KERNEL);
-+ if (xusb == NULL) {
-+ ERR("xpp_usb: Unable to allocate new xpp usb bus\n");
-+ retval = -ENOMEM;
-+ goto probe_failed;
-+ }
-+ memset(xusb, 0, sizeof(struct xpp_usb_bus));
-+
-+ init_MUTEX (&xusb->sem);
-+ xusb->udev = udev;
-+ xusb->interface = interface;
-+ xusb->model_info = model_info;
-+
-+ if(!set_endpoints(xusb, interface, model_info)) {
-+ retval = -ENODEV;
-+ goto probe_failed;
-+ }
-+ xusb->read_urb = xpp_urb_new(xusb, xusb->ep_in.epnum, xusb->ep_in.max_size, xpp_receive_callback);
-+ if (!xusb->read_urb) {
-+ ERR("No free urbs available\n");
-+ retval = -ENOMEM;
-+ goto probe_failed;
-+ }
-+ /* allow device read, write and ioctl */
-+ xusb->present = 1;
-+
-+ /* we can register the device now, as it is ready */
-+ usb_set_intfdata (interface, xusb);
-+ retval = usb_register_dev (interface, &xusb_class);
-+ if (retval) {
-+ /* something prevented us from registering this driver */
-+ ERR ("Not able to get a minor for this device.");
-+ goto probe_failed;
-+ }
-+
-+ xusb->minor = interface->minor;
-+
-+ /* let the user know what node this device is now attached to */
-+ INFO ("USB XPP device now attached to minor %d\n", xusb->minor);
-+
-+ /* Allocate high level structures */
-+ xbus = xbus_new((model_info->bus_type == FIRMWARE_LOOPBACK) ? ~0 : 0);
-+ if(!xbus) {
-+ retval = -ENOMEM;
-+ goto probe_failed;
-+ }
-+ xusb->xbus = xbus;
-+ xbus->priv = xusb;
-+ xbus->bus_type = model_info->bus_type;
-+
-+ spin_lock_irqsave(&xusb_lock, flags);
-+ for(i = 0; i < USBDEV_MAX; i++) {
-+ if(xusb_array[i] == NULL)
-+ break;
-+ }
-+ if(i >= USBDEV_MAX) {
-+ ERR("xpp_usb: Too many XPP USB buses\n");
-+ retval = -ENOMEM;
-+ goto probe_failed;
-+ }
-+ spin_unlock_irqrestore(&xusb_lock, flags);
-+ {
-+ char path[XBUS_DESCLEN];
-+
-+ usb_make_path(udev, path, XBUS_DESCLEN); // May trunacte... ignore
-+ snprintf(xbus->busdesc, XBUS_DESCLEN, "%s", path);
-+ }
-+ xbus->ops = &xusb_ops;
-+
-+ DBG("GOT XPP USB BUS #%d: %s (type=%d)\n", i, xbus->busdesc, xbus->bus_type);
-+
-+ xusb_array[i] = xusb;
-+
-+
-+#ifdef CONFIG_PROC_FS
-+ DBG("Creating proc entry " PROC_USBXPP_SUMMARY " in bus proc dir.\n");
-+ procsummary = create_proc_read_entry(PROC_USBXPP_SUMMARY, 0444, xbus->proc_xbus_dir,
-+ xusb_read_proc, xusb);
-+ //xbus->procsummary = 1; // temporary: not 0, for the condition below
-+ if (!procsummary) {
-+ ERR("Failed to create proc read entry for xbus %s\n", xbus->busname);
-+ // FIXME: better error handling
-+ retval = -EIO;
-+ goto probe_failed;
-+ }
-+#endif
-+ retval = usb_submit_urb(xusb->read_urb, GFP_ATOMIC);
-+ if(retval < 0) {
-+ ERR("%s: Failed to submit the receive URB errno=%d\n", __FUNCTION__, retval);
-+ }
-+ bus_count++;
-+ xbus_activate(xusb->xbus);
-+ return retval;
-+probe_failed:
-+ ERR("Failed to initialize xpp usb bus: %d\n", retval);
-+ usb_set_intfdata (interface, NULL);
-+ if(xusb) {
-+ if(xusb->read_urb)
-+ xpp_urb_delete(xusb->read_urb);
-+ if(xusb->minor) // passed registration phase
-+ usb_deregister_dev(interface, &xusb_class);
-+ kfree(xusb);
-+ }
-+ return retval;
-+}
-+
-+/**
-+ * xusb_disconnect
-+ *
-+ * Called by the usb core when the device is removed from the system.
-+ *
-+ * This routine guarantees that the driver will not submit any more urbs
-+ * by clearing dev->udev. It is also supposed to terminate any currently
-+ * active urbs. Unfortunately, usb_bulk_msg(), used in xusb_read(), does
-+ * not provide any way to do this. But at least we can cancel an active
-+ * write.
-+ */
-+static void xusb_disconnect(struct usb_interface *interface)
-+{
-+ struct xpp_usb_bus *xusb;
-+ xbus_t *xbus;
-+ int minor;
-+ int i;
-+
-+ DBG("CALLED\n");
-+ /* prevent races with open() */
-+ down (&disconnect_sem);
-+
-+ xusb = usb_get_intfdata (interface);
-+ usb_set_intfdata (interface, NULL);
-+ xbus = xusb->xbus;
-+
-+ /* find our xusb */
-+ for(i = 0; i < USBDEV_MAX; i++) {
-+ if(xusb_array[i] == xusb)
-+ break;
-+ }
-+ BUG_ON(i >= USBDEV_MAX);
-+ xusb_array[i] = NULL;
-+
-+#ifdef CONFIG_PROC_FS
-+ if(xbus->proc_xbus_dir) {
-+ remove_proc_entry(PROC_USBXPP_SUMMARY, xbus->proc_xbus_dir);
-+ }
-+#endif
-+ xusb->present = 0;
-+ xbus_deactivate(xbus); // Blocking until fully deactivated!
-+
-+ down (&xusb->sem);
-+
-+ minor = xusb->minor;
-+
-+ /* give back our minor */
-+ usb_deregister_dev (interface, &xusb_class);
-+
-+ /* terminate an ongoing write */
-+ // FIXME: Does it really kill pending URB's?
-+
-+ if(xusb->read_urb)
-+ xpp_urb_delete(xusb->read_urb);
-+
-+ up (&xusb->sem);
-+ DBG("Semaphore released\n");
-+
-+ kfree(xusb);
-+
-+ up (&disconnect_sem);
-+ INFO("XUSB #%d now disconnected", minor);
-+}
-+
-+static void xpp_send_callback(struct urb *urb, struct pt_regs *regs)
-+{
-+ struct xpp_usb_bus *xusb = (struct xpp_usb_bus *)urb->context;
-+ xbus_t *xbus = xusb->xbus;
-+
-+ BUG_ON(!xbus);
-+ /* sync/async unlink faults aren't errors */
-+ if (urb->status && !(urb->status == -ENOENT || urb->status == -ECONNRESET)) {
-+ static int rate_limit;
-+ if((rate_limit++ % 1000) < 10)
-+ DBG("nonzero read bulk status received: %d", urb->status);
-+ XUSB_COUNTER(xusb, TX_ERRORS)++;
-+ }
-+ if(!xusb->present) {
-+ ERR("A packet from non-connected device?\n");
-+ return;
-+ }
-+ xpp_urb_delete(urb);
-+ /* allow device read, write and ioctl */
-+ XUSB_COUNTER(xusb, TX_PACKETS)++;
-+}
-+
-+static void xpp_receive_callback(struct urb *urb, struct pt_regs *regs)
-+{
-+ struct xpp_usb_bus *xusb = (struct xpp_usb_bus *)urb->context;
-+ xbus_t *xbus = xusb->xbus;
-+
-+ xpacket_t *pack;
-+ size_t size;
-+ int retval;
-+
-+ BUG_ON(!xbus);
-+ if (urb->status) {
-+ /* sync/async unlink faults aren't errors */
-+ if (!(urb->status == -EOVERFLOW || urb->status == -EMSGSIZE)) {
-+ ERR("Dropped connection due to bad URB status: %d\n", urb->status);
-+ return;
-+ } else {
-+ DBG("nonzero read bulk status received: %d\n", urb->status);
-+ goto end;
-+ }
-+ }
-+ if(!down_read_trylock(&xbus->in_use)) {
-+ ERR("%s: xbus is going down\n", __FUNCTION__);
-+ return;
-+ }
-+ if(!xusb->present) {
-+ ERR("A packet from non-connected device?\n");
-+ up_read(&xbus->in_use);
-+ return;
-+ }
-+ pack = xbus->ops->packet_new(xbus, GFP_ATOMIC);
-+ if(!pack) {
-+ ERR("%s: Not enough memory for packets. Dropping\n", __FUNCTION__);
-+ goto end;
-+ }
-+
-+ size = urb->actual_length;
-+ memcpy(&pack->content, urb->transfer_buffer, size);
-+
-+ pack->datalen = size - sizeof(xpd_addr_t) - 1; // opcode size
-+ // DBG("datalen of new packet: %d\n", pack->datalen);
-+
-+ // Send UP
-+ if(pack->content.opcode == XPROTO_NAME(GLOBAL,PCM_READ)) {
-+ XUSB_COUNTER(xusb, PCM_READS)++;
-+
-+#ifdef DEBUG_PCM_TIMING
-+ /*
-+ * DEBUG: high-res timing of PCM_READ to PCM_WRITE
-+ */
-+ stamp_last_pcm_read = get_cycles();
-+#endif
-+ // fill_beep((u_char *)&PACKET_FIELD(pack, PCM_READS, pcm), 2); // Debugging BEEP
-+#if 0
-+ static int rate_limit;
-+ if((rate_limit++ % 1000) == 0)
-+ dump_packet("USB RECEIVE PCM", pack, print_dbg);
-+#endif
-+ } else if(pack->content.opcode == XPROTO_NAME(GLOBAL,PCM_WRITE)) { // FIRMWARE_LOOPBACK
-+#if 0
-+ static int rate_limit;
-+ if((rate_limit++ % 1000) == 0)
-+ dump_packet("USB RECEIVE (LOOPBACK) PCM", pack, print_dbg);
-+#endif
-+ } else {
-+ char title[XBUS_DESCLEN];
-+
-+ snprintf(title, XBUS_DESCLEN, "USB_PACKET_RECEIVE callback (%s)", xbus->busname);
-+ dump_packet(title, pack, print_dbg);
-+ }
-+ packet_receive(xbus, pack);
-+ XUSB_COUNTER(xusb, RX_PACKETS)++;
-+end:
-+ up_read(&xbus->in_use);
-+ retval = usb_submit_urb(urb, GFP_KERNEL);
-+ if (retval < 0) {
-+ ERR("failed re-submitting read urb, error %d\n", retval);
-+ return;
-+ }
-+}
-+
-+
-+/*------------------------- Initialization -------------------------*/
-+
-+int __init xpp_usb_init(void)
-+{
-+ int result;
-+ //struct xpp_usb_bus *xusb;
-+
-+ INFO("%s revision %s\n", THIS_MODULE->name, revision);
-+
-+ /* register this driver with the USB subsystem */
-+ result = usb_register(&xusb_driver);
-+ if (result) {
-+ ERR("usb_register failed. Error number %d", result);
-+ return result;
-+ }
-+ return 0;
-+}
-+
-+
-+void __exit xpp_usb_cleanup(void)
-+{
-+ int i, j;
-+
-+ DBG("\n");
-+ for(i = 0; i < USBDEV_MAX; i++) {
-+ xbus_t *xbus;
-+
-+ if(xusb_array[i] == NULL)
-+ continue;
-+ xbus = xusb_array[i]->xbus;
-+ if(!xbus) {
-+ ERR("%s: missing xbus. Skipping\n", __FUNCTION__);
-+ continue;
-+ }
-+ for(j = 0; j < MAX_XPDS; j++) {
-+ xpd_t *xpd = xpd_of(xbus, j);
-+
-+ if(xpd) {
-+ if(xpd->id != j) {
-+ ERR("%s: BUG: xpd->id=%d != j=%d\n", __FUNCTION__, xpd->id, j);
-+ continue;
-+ }
-+#if 0 // FIXME: retest after new driver start working
-+ CALL_XMETHOD(CHAN_ENABLE, xbus, xpd, 0xFF, 0); // Disable all hardware channels
-+ CALL_XMETHOD(LED, xbus, xpd, 0xFF, 1, 0); // FIXME: Show activated channels
-+#endif
-+ }
-+ }
-+ }
-+ /* deregister this driver with the USB subsystem */
-+ usb_deregister(&xusb_driver);
-+}
-+
-+
-+
-+#ifdef CONFIG_PROC_FS
-+
-+static int xusb_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data)
-+{
-+ int len = 0;
-+ unsigned long flags;
-+ //unsigned long stamp = jiffies;
-+ struct xpp_usb_bus *xusb = data;
-+
-+ if(!xusb)
-+ goto out;
-+ // TODO: probably needs a per-xusb lock:
-+ spin_lock_irqsave(&xusb_lock, flags);
-+ int i;
-+
-+ len += sprintf(page + len, "device: %d, #altsettings: %d, minor: %d\n"
-+ "\tBus Type:%d (Model Info: %s)\n"
-+ "\tIn: 0x%02X - Size: %d\n"
-+ "\tOut: 0x%02X - Size: %d\n",
-+ xusb->udev->devnum,
-+ xusb->interface->num_altsetting,
-+ xusb->minor,
-+ xusb->model_info->bus_type,
-+ xusb->model_info->desc,
-+ xusb->ep_in.epnum,
-+ xusb->ep_in.max_size,
-+ xusb->ep_out.epnum,
-+ xusb->ep_out.max_size
-+ );
-+#ifdef DEBUG_PCM_TIMING
-+ len += sprintf(page + len, "\nstamp_last_pcm_read=%lld accumulate_diff=%lld\n", stamp_last_pcm_read, accumulate_diff);
-+#endif
-+ len += sprintf(page + len, "\nCOUNTERS:\n");
-+ for(i = 0; i < XUSB_COUNTER_MAX; i++) {
-+ len += sprintf(page + len, "\t%-15s = %d\n", xusb_counters[i].name, xusb->counters[i]);
-+ }
-+#if 0
-+ len += sprintf(page + len, "<-- len=%d\n", len);
-+#endif
-+ spin_unlock_irqrestore(&xusb_lock, flags);
-+out:
-+ if (len <= off+count)
-+ *eof = 1;
-+ *start = page + off;
-+ len -= off;
-+ if (len > count)
-+ len = count;
-+ if (len < 0)
-+ len = 0;
-+ return len;
-+
-+}
-+
-+#endif
-+
-+
-+
-+MODULE_DESCRIPTION("XPP USB Driver");
-+MODULE_AUTHOR("Oron Peled <oron at actcom.co.il>");
-+MODULE_LICENSE("GPL");
-+MODULE_VERSION("$Id: xpp_usb.c 181 2006-01-05 17:13:28Z oron $");
-+
-+module_init(xpp_usb_init);
-+module_exit(xpp_usb_cleanup);
-diff -urNad zaptel-1.0.10/xpp/xpp_zap.c /tmp/dpep.absTwN/zaptel-1.0.10/xpp/xpp_zap.c
---- zaptel-1.0.10/xpp/xpp_zap.c 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.absTwN/zaptel-1.0.10/xpp/xpp_zap.c 2006-01-11 10:12:52.000000000 +0200
-@@ -0,0 +1,2312 @@
-+/*
-+ * Written by Oron Peled <oron at actcom.co.il>
-+ * Copyright (C) 2004, Xorcom
-+ *
-+ * Derived from ztdummy
-+ *
-+ * Copyright (C) 2002, Hermes Softlab
-+ * Copyright (C) 2004, Digium, Inc.
-+ *
-+ * All rights reserved.
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License as published by
-+ * the Free Software Foundation; either version 2 of the License, or
-+ * (at your option) any later version.
-+ *
-+ * This program is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ * GNU General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-+ *
-+ */
-+#include <linux/version.h>
-+
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+# warning "This module is tested only with 2.6 kernels"
-+#endif
-+
-+#include <linux/kernel.h>
-+#include <linux/errno.h>
-+#include <linux/module.h>
-+#include <linux/init.h>
-+#include <linux/delay.h> /* for udelay */
-+#include <linux/workqueue.h>
-+#include <linux/proc_fs.h>
-+#include <zaptel.h>
-+#include "xproto.h"
-+#include "xpp_zap.h"
-+
-+static char revision[] = "$Revision: 185 $";
-+
-+#ifdef CONFIG_PROC_FS
-+struct proc_dir_entry *xpp_procdir = NULL;
-+#define PROC_DIR "xpp"
-+#define PROC_XBUSES "xbuses"
-+#define PROC_SYNC "sync"
-+#define PROC_XBUS_SUMMARY "summary"
-+#define PROC_XPD_ZTREGISTER "zt_registration"
-+#define PROC_XPD_SUMMARY "summary"
-+#endif
-+
-+#undef WITH_RBS
-+//#define WITH_RBS
-+
-+#define XPP_CTL_MAJOR 42
-+#define MAX_BUSES 16
-+#define MAX_QUEUE_LEN 10000
-+#define LED_BLINK_PERIOD (HZ/8)
-+#define SAMPLE_TICKS 10000
-+
-+static spinlock_t xbuses_lock = SPIN_LOCK_UNLOCKED;
-+static xbus_t *xbuses_array[MAX_BUSES] = {};
-+static int bus_count = 0;
-+static struct timer_list xpp_timer;
-+static xpd_t *sync_master = NULL; // Start with host based sync
-+static unsigned int xpp_timer_count = 0;
-+static unsigned int xpp_last_jiffies = 0;
-+struct workqueue_struct *xpp_worker = NULL;
-+
-+static LIST_HEAD(xpd_list);
-+
-+DEF_PARM(int, print_dbg, 1, "Print DBG statements");
-+DEF_PARM(int, max_queue_len, MAX_QUEUE_LEN, "Maximum Queue Length.");
-+DEF_PARM(int, xbus_err_disable_bus, 1000, "Number of errors needed to disable bus");
-+DEF_PARM(int, ignore_xpds, 0, "a bitmask of xpd numbers to ignore");
-+#ifdef SOFT_SIMULATOR
-+DEF_PARM(ulong, softloop_xpds, 0, "a bitmask of software xpd numbers");
-+#endif
-+DEF_PARM(ulong, pcm_gen, 0, "a bitmask of line numbers for hardware tone generator");
-+
-+DEF_ARRAY(ulong, enabled_channels, MAX_XPDS, ~0, "Enabled channels for each xpd");
-+
-+#include "zap_debug.h"
-+
-+
-+static int xpd_zaptel_register(xpd_t *xpd);
-+static int xpd_zaptel_unregister(xpd_t *xpd);
-+static void xbus_remove(xbus_t *xbus);
-+static void xpd_blink_leds(xpd_t *xpd);
-+static void xpp_ring_generate(xpd_t *xpd);
-+static void xpp_transmitprep(xpd_t *xpd);
-+static void xpp_receiveprep(xpd_t *xpd);
-+static int xpd_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data);
-+static int proc_xpd_ztregister_read(char *page, char **start, off_t off, int count, int *eof, void *data);
-+static int proc_xpd_ztregister_write(struct file *file, const char __user *buffer, unsigned long count, void *data);
-+xbus_t *xbus_of(int xbus_num);
-+static void xpd_cleanup(xpd_t *xpd);
-+static void xpd_card_disable(xpd_t *xpd);
-+static void update_xpd_status(xpd_t *xpd, int alarm_flag);
-+
-+#define SPAN_REGISTERED(xpd) ((xpd)->span.flags & ZT_FLAG_REGISTERED)
-+
-+/*------------------------- Packet Handling ------------------------*/
-+static kmem_cache_t *packet_cache = NULL;
-+static atomic_t xpacket_count = ATOMIC_INIT(0);
-+
-+void card_detected(void *data)
-+{
-+ struct card_desc_struct *card_desc = (struct card_desc_struct *)data;
-+ xbus_t *xbus;
-+ xpd_t *xpd;
-+ int xpd_num;
-+ byte type;
-+ byte rev;
-+ const xops_t *xops;
-+ const xproto_table_t *proto_table;
-+
-+ BUG_ON(!card_desc);
-+ BUG_ON(card_desc->magic != CARD_DESC_MAGIC);
-+ xbus = card_desc->xbus;
-+ xpd_num = card_desc->xpd_num;
-+ type = card_desc->type;
-+ rev = card_desc->rev;
-+ BUG_ON(!xbus);
-+ DBG("%s: xpd_num=%d type=%d rev=%d\n", xbus->busname, xpd_num, type, rev);
-+ xpd = xpd_of(xbus, xpd_num);
-+ if(xpd) {
-+ if(type == XPD_TYPE(NOMODULE)) {
-+ NOTICE("%s: xpd #%d: removed\n", __FUNCTION__, xpd_num);
-+ xpd_card_disable(xpd);
-+ goto out;
-+ }
-+ NOTICE("%s: xpd #%d: already exists\n", __FUNCTION__, xpd_num);
-+ goto out;
-+ }
-+ if(type == XPD_TYPE(NOMODULE)) {
-+ DBG("No module at address=%d\n", xpd_num);
-+ goto out;
-+ }
-+ proto_table = get_xproto_table(type);
-+ if(!proto_table) {
-+ NOTICE("%s: xpd #%d: missing protocol table for type=%d. Ignored.\n", __FUNCTION__, xpd_num, type);
-+ goto out;
-+ }
-+ xops = &proto_table->xops;
-+ BUG_ON(!xops);
-+ xpd = xops->card_new(xbus, xpd_num, proto_table, rev);
-+ if(!xpd) {
-+ NOTICE("card_new(%s,%d,%d,%d) failed. Ignored.\n", xbus->busname, xpd_num, proto_table->type, rev);
-+ goto out;
-+ }
-+#if 0
-+ /*
-+ * Is it nessessary?
-+ */
-+ if(xpd->type == XPD_TYPE_FXO) {
-+ int i;
-+
-+ for(i = 0; i < xpd->channels; i++) {
-+ zt_hooksig(&xpd->chans[i], ZT_RXSIG_ONHOOK);
-+ }
-+ }
-+#endif
-+#ifdef CONFIG_PROC_FS
-+ DBG("Creating xpd proc directory for %s/%s\n", xbus->busname, xpd->xpdname);
-+ xpd->proc_xpd_dir = proc_mkdir(xpd->xpdname, xbus->proc_xbus_dir);
-+ if(!xpd->proc_xpd_dir) {
-+ ERR("Failed to create proc directory for %s/%s\n", xbus->busname, xpd->xpdname);
-+ goto err;
-+ }
-+ xpd->proc_xpd_summary = create_proc_read_entry(PROC_XPD_SUMMARY, 0444, xpd->proc_xpd_dir,
-+ xpd_read_proc, xpd);
-+ if(!xpd->proc_xpd_summary) {
-+ ERR("Failed to create proc '%s' for %s/%s\n", PROC_XPD_SUMMARY, xbus->busname, xpd->xpdname);
-+ goto err;
-+ }
-+ xpd->proc_xpd_ztregister = create_proc_entry(PROC_XPD_ZTREGISTER, 0644, xpd->proc_xpd_dir);
-+ if (!xpd->proc_xpd_ztregister) {
-+ ERR("Failed to create proc '%s' for %s/%s\n", PROC_XPD_ZTREGISTER, xbus->busname, xpd->xpdname);
-+ goto err;
-+ }
-+ xpd->proc_xpd_ztregister->data = xpd;
-+ xpd->proc_xpd_ztregister->read_proc = proc_xpd_ztregister_read;
-+ xpd->proc_xpd_ztregister->write_proc = proc_xpd_ztregister_write;
-+#endif
-+ list_add(&xpd->xpd_list, &xpd_list);
-+ xbus->xpds[xpd->id] = xpd;
-+ xbus->num_xpds++;
-+ CALL_XMETHOD(card_init, xbus, xpd);
-+ // Turn off all channels
-+ CALL_XMETHOD(CHAN_ENABLE, xbus, xpd, 0xFF, 0);
-+// CALL_XMETHOD(LED, xbus, xpd, 0xFF, LED_RED, 0); // FIXME: Show activated channels
-+ // Turn on enabled channels
-+ CALL_XMETHOD(CHAN_ENABLE, xbus, xpd, xpd->enabled_chans, 1);
-+ atomic_set(&xpd->card_present, 1);
-+ xpd_zaptel_register(xpd);
-+#if 0
-+ // FIXME: not yet initialized...
-+ xpp_check_hookstate(xpd, line_status);
-+#endif
-+
-+out:
-+ memset(card_desc, 0, sizeof(struct card_desc_struct));
-+ kfree(card_desc);
-+ return;
-+err:
-+ xpd_cleanup(xpd);
-+ goto out;
-+}
-+
-+/**
-+ * Allocates a new XPP packet.
-+ * @xbus The XPP bus in which the packet will flow (for counters
-+ * maintenance)
-+ * @flags Flags for kernel memory allocation.
-+ * @returns A pointer to the new packet, or NULL in case of failure.
-+ *
-+ *
-+ * Packet allocation/deallocation:
-+ * Sent packets:
-+ * - Allocated by protocol commands
-+ * - Deallocated by xmus_xmitter
-+ * Receive packets:
-+ * - Allocated/deallocated by xbus_xmiter
-+ */
-+xpacket_t *softloop_packet_new(xbus_t *xbus, int flags)
-+{
-+ xpacket_t *pack;
-+
-+ /* To avoid races we increament counter in advance and decrement it later
-+ * in case of failure */
-+ atomic_inc(&xbus->packet_counter);
-+ //DBG("Incremented packet_counter of bus %s (new packet) to %d\n",
-+ // xbus->busname, atomic_read(&xbus->packet_counter));
-+ pack = kmem_cache_alloc(packet_cache, flags);
-+ if (pack) {
-+ memset(pack, 0, sizeof(xpacket_t));
-+ atomic_inc(&xpacket_count);
-+ } else {
-+ atomic_dec(&xbus->packet_counter);
-+ //DBG("Decremented packet_counter of bus %s (failed new packet) to %d\n",
-+ // xbus->busname, atomic_read(&xbus->packet_counter));
-+ }
-+ return pack;
-+}
-+
-+void softloop_packet_free(xbus_t *xbus, xpacket_t *p)
-+{
-+ kmem_cache_free(packet_cache, p);
-+ atomic_dec(&xpacket_count);
-+ atomic_dec(&xbus->packet_counter);
-+ //DBG("Decremented packet_counter of bus %s (freed packet) to %d\n",
-+ // xbus->busname, atomic_read(&xbus->packet_counter));
-+}
-+
-+int call_proto(xbus_t *xbus, xpacket_t *pack)
-+{
-+ const xproto_entry_t *xe;
-+ int toxpd = XPD_NUM(pack->content.addr);
-+ xpd_t *xpd = xpd_of(xbus, toxpd);
-+
-+ xe = find_xproto_entry(xpd, pack->content.opcode);
-+ return 0;
-+}
-+
-+static void external_sync(xpd_t *the_xpd)
-+{
-+ int i, j;
-+
-+ DBG("SYNC %s\n", (the_xpd) ? "EXTERNAL" : "HOST");
-+ for(i = 0; i < MAX_BUSES; i++) {
-+ xbus_t *xbus = xbus_of(i);
-+ if(!xbus)
-+ continue;
-+ if (!xbus->hardware_exists)
-+ continue;
-+ for(j = 0; j < MAX_XPDS; j++) {
-+ xpd_t *xpd = xbus->xpds[j];
-+ if(xpd)
-+ CALL_XMETHOD(SYNC_SOURCE, xbus, xpd, 1, (the_xpd != NULL));
-+ }
-+ }
-+}
-+
-+void set_sync_master(xpd_t *xpd)
-+{
-+ DBG("SYNC: %s => %s\n",
-+ (sync_master) ? sync_master->xpdname : "HOST",
-+ (xpd) ? xpd->xpdname : "HOST"
-+ );
-+ sync_master = xpd;
-+ if(!sync_master) {
-+ external_sync(NULL);
-+ if(!timer_pending(&xpp_timer)) {
-+ xpp_timer.function = xpp_tick;
-+ xpp_timer.data = 0;
-+ xpp_timer.expires = jiffies + 1; /* Must be 1KHz rate */
-+ add_timer(&xpp_timer);
-+ }
-+ } else {
-+ del_timer_sync(&xpp_timer);
-+ external_sync(xpd);
-+ xpp_tick((unsigned long)xpd);
-+ }
-+}
-+
-+void xpp_tick(unsigned long param)
-+{
-+ xbus_t *xbus;
-+ xpd_t *the_xpd = (xpd_t *)param;
-+ int i;
-+ int j;
-+
-+ if(!the_xpd) { /* Called from timer */
-+#if 0
-+ static int rate_limit = 0;
-+ if(rate_limit++ % 1000 == 0)
-+ DBG("FROM_TIMER\n");
-+#endif
-+ mod_timer(&xpp_timer, jiffies + 1); /* Must be 1KHz rate */
-+ }
-+ else if(the_xpd != sync_master)
-+ return;
-+ /* Statistics */
-+ if((xpp_timer_count % SAMPLE_TICKS) == 0) {
-+ xpp_last_jiffies = jiffies;
-+ }
-+ xpp_timer_count++;
-+
-+ for(i = 0; i < MAX_BUSES; i++) {
-+ xbus = xbus_of(i);
-+ if(!xbus)
-+ continue;
-+ if (!xbus->hardware_exists)
-+ continue;
-+#if 0
-+ if(xbus->open_counter == 0)
-+ continue; // optimize, but zttool loopback won't function
-+#endif
-+ for(j = 0; j < MAX_XPDS; j++) {
-+ xpd_t *xpd = xbus->xpds[j];
-+
-+ if(!xpd)
-+ continue;
-+ if(!atomic_read(&xpd->card_present))
-+ continue;
-+ xpd->timer_count++;
-+ CALL_XMETHOD(card_tick, xbus, xpd);
-+ if(!SPAN_REGISTERED(xpd))
-+ continue;
-+ xpd_blink_leds(xpd);
-+ if(xpd->direction == TO_PSTN)
-+ xpp_ring_generate(xpd);
-+ xpp_transmitprep(xpd);
-+ xpp_receiveprep(xpd);
-+ }
-+ }
-+}
-+
-+#if HZ != 1000
-+#error "xpp_timer must be sampled EXACTLY 1000/per second"
-+#endif
-+
-+static void xpd_cleanup(xpd_t *xpd)
-+{
-+ xbus_t *xbus = NULL;
-+
-+ if(!xpd)
-+ return;
-+ xbus = xpd->xbus;
-+ xpd_card_disable(xpd);
-+ DBG("%s/%s\n", xbus->busname, xpd->xpdname);
-+#ifdef CONFIG_PROC_FS
-+ if(xpd->proc_xpd_dir) {
-+ if(xpd->proc_xpd_summary) {
-+ DBG("Removing proc '%s' for %s/%s\n", PROC_XPD_SUMMARY, xbus->busname, xpd->xpdname);
-+ remove_proc_entry(PROC_XPD_SUMMARY, xpd->proc_xpd_dir);
-+ xpd->proc_xpd_summary = NULL;
-+ }
-+ if(xpd->proc_xpd_ztregister) {
-+ DBG("Removing proc '%s' for %s/%s\n", PROC_XPD_ZTREGISTER, xbus->busname, xpd->xpdname);
-+ remove_proc_entry(PROC_XPD_ZTREGISTER, xpd->proc_xpd_dir);
-+ xpd->proc_xpd_ztregister = NULL;
-+ }
-+ DBG("Removing proc directory for %s/%s\n", xbus->busname, xpd->xpdname);
-+ remove_proc_entry(xpd->xpdname, xbus->proc_xbus_dir);
-+ xpd->proc_xpd_dir = NULL;
-+ }
-+#endif
-+}
-+
-+void init_xbus_packet_queue(packet_queue_t *q, const char name[])
-+{
-+ INIT_LIST_HEAD(&q->head);
-+ spin_lock_init(&q->lock);
-+ q->count = 0;
-+ q->worst_count = 0;
-+ q->overflows = 0;
-+ snprintf(q->qname, XPD_NAMELEN, "%s", name);
-+}
-+
-+#if 0
-+/*
-+ * Assume the queue is locked
-+ */
-+void __dump_packet_queue(const char *msg, packet_queue_t *q)
-+{
-+ xpacket_t *tmp;
-+
-+ list_for_each_entry(tmp, &q->head, list) {
-+ dump_packet(msg, tmp);
-+ }
-+}
-+#endif
-+
-+void drain_xbus_packet_queue(xbus_t *xbus, packet_queue_t *q)
-+{
-+ unsigned long flags;
-+ xpacket_t *pack;
-+ xpacket_t *next;
-+
-+ spin_lock_irqsave(&q->lock, flags);
-+ DBG("queue=%s count=%d\n", q->qname, q->count);
-+ DBG(" total packets count=%d\n", atomic_read(&xpacket_count));
-+ list_for_each_entry_safe(pack, next, &q->head, list) {
-+ list_del(&pack->list);
-+ q->count--;
-+ xbus->ops->packet_free(xbus, pack);
-+ }
-+ if(q->count != 0)
-+ ERR("drain_xbus_packet_queue: queue %s still has %d packets\n",
-+ q->qname, q->count);
-+ spin_unlock_irqrestore(&q->lock, flags);
-+}
-+
-+void xbus_enqueue_packet(xbus_t *xbus, packet_queue_t *q, xpacket_t *pack)
-+{
-+ unsigned long flags;
-+
-+ spin_lock_irqsave(&q->lock, flags);
-+
-+ if(q->count >= max_queue_len) {
-+ static unsigned long last_notice = 0; // rate limit
-+
-+ if((jiffies - last_notice) < HZ) {
-+ NOTICE("xbus_enqueue_packet: dropping packet (queue len = %d, max=%d)\n",
-+ q->count, max_queue_len);
-+ last_notice = jiffies;
-+ }
-+ q->overflows++;
-+ xbus->ops->packet_free(xbus, pack);
-+ goto out;
-+ }
-+ list_add_tail(&pack->list, &q->head);
-+ q->count++;
-+
-+ if(q->count > q->worst_count)
-+ q->worst_count = q->count;
-+
-+ if(q->count < max_queue_len/100 && q->worst_count > q->count) // Decay worst_count
-+ q->worst_count--;
-+
-+ // dump_packet("ENQUEUED", pack, print_dbg);
-+out:
-+ spin_unlock_irqrestore(&q->lock, flags);
-+}
-+
-+xpacket_t *xbus_dequeue_packet(packet_queue_t *q)
-+{
-+ unsigned long flags;
-+ struct list_head *p;
-+ xpacket_t *pack = NULL;
-+
-+ spin_lock_irqsave(&q->lock, flags);
-+
-+ if(list_empty(&q->head)) {
-+ // DBG("LIST EMPTY (count=%d)\n", q->count);
-+ goto out;
-+ }
-+ p = q->head.next;
-+ list_del(p);
-+ q->count--;
-+ pack = list_entry(p, xpacket_t, list);
-+ // dump_packet("DEQUEUED", pack, print_dbg);
-+out:
-+ spin_unlock_irqrestore(&q->lock, flags);
-+ return pack;
-+}
-+
-+
-+/*------------------------- XPD Management -------------------------*/
-+
-+#ifdef CONFIG_PROC_FS
-+
-+/**
-+ * Prints a general procfs entry for the bus, under xpp/BUSNAME/summary
-+ * @page TODO: figure out procfs
-+ * @start TODO: figure out procfs
-+ * @off TODO: figure out procfs
-+ * @count TODO: figure out procfs
-+ * @eof TODO: figure out procfs
-+ * @data an xbus_t pointer with the bus data.
-+ */
-+static int xpd_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data)
-+{
-+ int len = 0;
-+ xpd_t *xpd = data;
-+ xbus_t *xbus;
-+#if SOFT_SIMULATOR
-+ struct xpd_sim *sim;
-+#endif
-+ int channels;
-+ int i;
-+
-+ if(!xpd)
-+ goto out;
-+
-+ xbus = xpd->xbus;
-+#if SOFT_SIMULATOR
-+ sim = &xbus->sim[xpd->id];
-+#endif
-+ channels = xpd->channels;
-+ len += sprintf(page + len, "%s (%s ,card %s, span_registered=%s)%s\n"
-+ "timer_count: %d span->mainttimer=%d\n"
-+ ,
-+ xpd->xpdname, xproto_name(xpd->type),
-+ (atomic_read(&xpd->card_present))?"present":"missing",
-+ (SPAN_REGISTERED(xpd))?"yes":"no",
-+ (xpd == sync_master) ? " SYNCER" : "",
-+ xpd->timer_count, xpd->span.mainttimer
-+ );
-+ len += sprintf(page + len, "STATES:");
-+ len += sprintf(page + len, "\n\t%-17s: ", "enabled");
-+ for(i = 0; i < channels; i++) {
-+ len += sprintf(page + len, "%d ", IS_SET(xpd->enabled_chans, i));
-+ }
-+ len += sprintf(page + len, "\n\t%-17s: ", "output_relays");
-+ for(i = 0; i < channels; i++) {
-+ len += sprintf(page + len, "%d ", IS_SET(xpd->digital_outputs, i));
-+ }
-+ len += sprintf(page + len, "\n\t%-17s: ", "input_relays");
-+ for(i = 0; i < channels; i++) {
-+ len += sprintf(page + len, "%d ", IS_SET(xpd->digital_inputs, i));
-+ }
-+ len += sprintf(page + len, "\n\t%-17s: ", "hookstate");
-+ for(i = 0; i < channels; i++) {
-+ len += sprintf(page + len, "%d ", IS_SET(xpd->hookstate, i));
-+ }
-+ len += sprintf(page + len, "\n\t%-17s: ", "ring-state");
-+ for(i = 0; i < channels; i++) {
-+ len += sprintf(page + len, "%d ", xpd->lasttxhook[i]);
-+ }
-+ len += sprintf(page + len, "\n\t%-17s: ", "ringing");
-+ for(i = 0; i < channels; i++) {
-+ len += sprintf(page + len, "%d ", xpd->ringing[i]);
-+ }
-+#if 1
-+ if(SPAN_REGISTERED(xpd)) {
-+ len += sprintf(page + len, "\nreadchunk: ");
-+ for(i = 0; i < channels; i++) {
-+ struct zt_chan *chans = xpd->span.chans;
-+ byte chunk[ZT_CHUNKSIZE];
-+ int j;
-+
-+ memcpy(chunk, chans[i].readchunk, ZT_CHUNKSIZE);
-+ len += sprintf(page + len, "\n\tport %2d> ", i);
-+ for(j = 0; j < ZT_CHUNKSIZE; j++) {
-+ len += sprintf(page + len, "%02X ", chunk[j]);
-+ }
-+ }
-+ }
-+#endif
-+#if SOFT_SIMULATOR
-+ if(sim->simulated) {
-+ len += sprintf(page + len, "\nSIMULATED (xpd_type=%d, loopto=%d):", sim->xpd_type, sim->loopto);
-+ len += sprintf(page + len, "\n\t%-17s: ", "hookstate");
-+ for(i = 0; i < channels; i++) {
-+ len += sprintf(page + len, "%d ", IS_SET(sim->hookstate, i));
-+ }
-+ }
-+#endif
-+#if 0
-+ if(SPAN_REGISTERED(xpd)) {
-+ len += sprintf(page + len, "\nSignalling:\n");
-+ for(i = 0; i < channels; i++) {
-+ struct zt_chan *chan = &xpd->span.chans[i];
-+ len += sprintf(page + len, "\t%2d> sigcap=0x%04X sig=0x%04X\n", i, chan->sigcap, chan->sig);
-+ }
-+ }
-+#endif
-+ len += sprintf(page + len, "\nCOUNTERS:\n");
-+ for(i = 0; i < XPD_COUNTER_MAX; i++) {
-+ len += sprintf(page + len, "\t\t%-20s = %d\n",
-+ xpd_counters[i].name, xpd->counters[i]);
-+ }
-+ len += sprintf(page + len, "<-- len=%d\n", len);
-+out:
-+ if (len <= off+count)
-+ *eof = 1;
-+ *start = page + off;
-+ len -= off;
-+ if (len > count)
-+ len = count;
-+ if (len < 0)
-+ len = 0;
-+ return len;
-+
-+}
-+
-+#endif
-+
-+/*
-+ * xpd_alloc - Allocator for new XPD's
-+ *
-+ */
-+xpd_t *xpd_alloc(size_t privsize, xbus_t *xbus, int xpd_num, const xproto_table_t *proto_table, int channels, byte revision)
-+{
-+ xpd_t *xpd = NULL;
-+ size_t alloc_size = sizeof(xpd_t) + privsize;
-+
-+ INFO("New XPD #%d (Revision %d.%d) detected on xbus %s\n",
-+ xpd_num, revision / 10, revision % 10, xbus->busname);
-+ if(!VALID_XPD_NUM(xpd_num)) {
-+ ERR("%s: illegal xpd id = %d\n", __FUNCTION__, xpd_num);
-+ goto err;
-+ }
-+ if(channels > CHANNELS_PERXPD) {
-+ ERR("%s: too many channels %d for xpd #%d\n", __FUNCTION__, channels, xpd_num);
-+ goto err;
-+ }
-+
-+ if((xpd = kmalloc(alloc_size, GFP_KERNEL)) == NULL) {
-+ ERR("%s: Unable to allocate memory for xpd #%d\n", __FUNCTION__, xpd_num);
-+ goto err;
-+ }
-+ memset(xpd, 0, alloc_size);
-+ xpd->priv = (byte *)xpd + sizeof(xpd_t);
-+
-+ spin_lock_init(&xpd->lock);
-+ xpd->xbus = xbus;
-+ xpd->id = xpd_num;
-+ xpd->channels = channels;
-+ xpd->chans = NULL;
-+ atomic_set(&xpd->card_present, 0);
-+ snprintf(xpd->xpdname, XPD_NAMELEN, "XPD-%d", xpd_num);
-+ xpd->hookstate = 0x0; /* ONHOOK */
-+ xpd->type = proto_table->type;
-+ xpd->xops = &proto_table->xops;
-+ xpd->enabled_chans = enabled_channels[xpd_num];
-+ xpd->digital_outputs = 0;
-+ xpd->digital_inputs = 0;
-+ atomic_set(&xpd->open_counter, 0);
-+
-+ xpd->chans = kmalloc(sizeof(struct zt_chan)*xpd->channels, GFP_KERNEL);
-+ if (xpd->chans == NULL) {
-+ ERR("%s: Unable to allocate channels\n", __FUNCTION__);
-+ goto err;
-+ }
-+ /* 8 channels, double buffer, Read/Write */
-+ int need = ZT_MAX_CHUNKSIZE * CHANNELS_PERXPD * 2 * 2;
-+ if((xpd->writechunk = kmalloc(need, GFP_KERNEL)) == NULL) {
-+ ERR("%s: Unable to allocate memory for writechunks\n", __FUNCTION__);
-+ goto err;
-+ }
-+ /* Initialize Write/Buffers to all blank data */
-+ memset((void *)xpd->writechunk, 0x00, need);
-+ xpd->readchunk = xpd->writechunk + ZT_CHUNKSIZE * CHANNELS_PERXPD * 2;
-+
-+ return xpd;
-+err:
-+ if(xpd->chans)
-+ kfree((void *)xpd->chans);
-+ if(xpd->writechunk)
-+ kfree((void *)xpd->writechunk);
-+ if(xpd)
-+ kfree(xpd);
-+ return NULL;
-+}
-+
-+static void xpd_card_disable(xpd_t *xpd)
-+{
-+ BUG_ON(!xpd);
-+ atomic_set(&xpd->card_present, 0);
-+ if(SPAN_REGISTERED(xpd))
-+ update_xpd_status(xpd, ZT_ALARM_NOTOPEN);
-+}
-+
-+void xpd_remove(xpd_t *xpd)
-+{
-+ xbus_t *xbus;
-+
-+ BUG_ON(!xpd);
-+ xbus = xpd->xbus;
-+ INFO("Remove XPD #%d from xbus=%s\n", xpd->id, xbus->busname);
-+#if 0
-+ // TODO: elect a new sync master
-+ if(sync_master == xpd)
-+ set_sync_master(NULL);
-+#endif
-+ xpd_zaptel_unregister(xpd);
-+ xbus->xpds[xpd->id] = NULL;
-+ list_del(&xpd->xpd_list);
-+ xbus->num_xpds--;
-+ CALL_XMETHOD(card_remove, xbus, xpd);
-+ xpd_cleanup(xpd);
-+ kfree((void *)xpd->writechunk);
-+ kfree(xpd);
-+}
-+
-+static void update_xpd_status(xpd_t *xpd, int alarm_flag)
-+{
-+ struct zt_span *span = &xpd->span;
-+
-+ if(!SPAN_REGISTERED(xpd)) {
-+ NOTICE("%s: %s is not registered. Skipping.\n", __FUNCTION__, xpd->xpdname);
-+ return;
-+ }
-+ switch (alarm_flag) {
-+ case ZT_ALARM_NONE:
-+ xpd->last_response = jiffies;
-+ break;
-+ default:
-+ // Nothing
-+ break;
-+ }
-+ if(span->alarms == alarm_flag)
-+ return;
-+ span->alarms = alarm_flag;
-+ zt_alarm_notify(span);
-+ DBG("Update XPD alarms: %s -> %02X\n", xpd->span.name, alarm_flag);
-+}
-+
-+void phone_hook(xpd_t *xpd, int channo, bool offhook)
-+{
-+ struct zt_chan *chan = &xpd->span.chans[channo];
-+
-+ if(offhook && !IS_SET(xpd->hookstate, channo)) { // OFFHOOK
-+ DBG("OFFHOOK: channo=%d\n", chan->channo);
-+ xpd->ringing[channo] = 0;
-+ BIT_SET(xpd->hookstate, channo);
-+ zt_hooksig(chan, ZT_RXSIG_OFFHOOK);
-+ if(!IS_SET(xpd->digital_outputs, channo) && !IS_SET(xpd->digital_inputs, channo)) {
-+ CALL_XMETHOD(CHAN_POWER, xpd->xbus, xpd, BIT(channo), 0); // Power down (prevent overheating!!!)
-+ CALL_XMETHOD(LED, xpd->xbus, xpd, BIT(channo), LED_GREEN, 1);
-+ }
-+ } else if(!offhook && IS_SET(xpd->hookstate, channo)) { // ONHOOK
-+ DBG("ONHOOK channo=%d\n", chan->channo);
-+ xpd->ringing[channo] = 0;
-+ BIT_CLR(xpd->hookstate, channo);
-+ zt_hooksig(chan, ZT_RXSIG_ONHOOK);
-+ if(!IS_SET(xpd->digital_outputs, channo) && !IS_SET(xpd->digital_inputs, channo)) {
-+ CALL_XMETHOD(CHAN_POWER, xpd->xbus, xpd, BIT(channo), 0); // Power down (prevent overheating!!!)
-+ CALL_XMETHOD(LED, xpd->xbus, xpd, BIT(channo), LED_GREEN, 0);
-+ }
-+ }
-+}
-+
-+void xpp_check_hookstate(xpd_t *xpd, xpp_line_t fxs_off_hook)
-+{
-+ int i;
-+ unsigned long flags;
-+
-+ spin_lock_irqsave(&xpd->lock, flags);
-+ if(xpd->direction != TO_PHONE) {
-+ ERR("%s: %s: Only PHONE can report hookstate changes\n", __FUNCTION__, xpd->xpdname);
-+ goto out;
-+ }
-+ if(!SPAN_REGISTERED(xpd)) {
-+ NOTICE("%s: %s is not registered. Skipping.\n", __FUNCTION__, xpd->xpdname);
-+ goto out;
-+ }
-+ DBG("%s: hookstate=0x%04X fxs_off_hook=0x%04X\n", xpd->xpdname, xpd->hookstate, fxs_off_hook);
-+ for(i = 0; i < xpd->channels; i++) {
-+ phone_hook(xpd, i, IS_SET(fxs_off_hook, i));
-+ }
-+out:
-+ spin_unlock_irqrestore(&xpd->lock, flags);
-+}
-+
-+static void xpd_blink_leds(xpd_t *xpd)
-+{
-+ int i;
-+ unsigned long flags;
-+
-+ BUG_ON(!xpd);
-+
-+ spin_lock_irqsave(&xpd->lock, flags);
-+ for(i = 0; i < xpd->channels; i++) {
-+ if(IS_SET(xpd->digital_outputs, i) || IS_SET(xpd->digital_inputs, i))
-+ continue;
-+ if(xpd->ringing[i]) {
-+ // led state is toggled
-+ if((xpd->timer_count % LED_BLINK_PERIOD) == 0) {
-+ DBG("%s pos=%d ringing=%d led_on=%d\n", xpd->xpdname, i, xpd->ringing[i], xpd->led_on[i]);
-+ if(xpd->ringing[i] && xpd->led_on[i]) {
-+ CALL_XMETHOD(LED, xpd->xbus, xpd, BIT(i), LED_GREEN, 1);
-+ } else {
-+ CALL_XMETHOD(LED, xpd->xbus, xpd, BIT(i), LED_GREEN, 0);
-+ }
-+ xpd->led_on[i] = !xpd->led_on[i];
-+ }
-+ }
-+ }
-+ spin_unlock_irqrestore(&xpd->lock, flags);
-+}
-+
-+static void xpp_ring_generate(xpd_t *xpd)
-+{
-+ int i;
-+ static int bug_counter = 0;
-+ unsigned long flags;
-+
-+ BUG_ON(!xpd);
-+
-+ spin_lock_irqsave(&xpd->lock, flags);
-+ if(xpd->direction != TO_PSTN && ((bug_counter++ % 1000) == 0)) {
-+ ERR("%s: %s: Only FXO can report ring changes\n", __FUNCTION__, xpd->xpdname);
-+ goto out;
-+ }
-+ if(!SPAN_REGISTERED(xpd)) {
-+ NOTICE("%s: %s is not registered. Skipping.\n", __FUNCTION__, xpd->xpdname);
-+ goto out;
-+ }
-+ /*
-+ * Ring detect logic:
-+ * fxo_power is toggled
-+ */
-+ for(i = 0; i < xpd->channels; i++) {
-+ if(xpd->ringing[i] || xpd->ringer_on[i]) {
-+ // ring state is only changed once per second:
-+ if((xpd->timer_count % 1000) == 0) {
-+ DBG("pos=%d ringing=%d ringer_on=%d\n", i, xpd->ringing[i], xpd->ringer_on[i]);
-+ if(xpd->ringer_on[i]) {
-+ zt_hooksig(&xpd->chans[i], ZT_RXSIG_OFFHOOK);
-+ } else {
-+ zt_hooksig(&xpd->chans[i], ZT_RXSIG_RING);
-+ }
-+ xpd->ringing[i]--;
-+ xpd->ringer_on[i] = !xpd->ringer_on[i];
-+ if (xpd->ringing[i] < 0)
-+ xpd->ringing[i]=0;
-+ }
-+ }
-+ }
-+out:
-+ spin_unlock_irqrestore(&xpd->lock, flags);
-+}
-+
-+/*------------------------- Bus Management -------------------------*/
-+
-+xbus_t *xbus_of(int xbus_num)
-+{
-+ if(xbus_num < 0 || xbus_num >= MAX_BUSES)
-+ return NULL;
-+ return xbuses_array[xbus_num];
-+}
-+
-+xpd_t *xpd_of(xbus_t *xbus, int xpd_num)
-+{
-+ if(!VALID_XPD_NUM(xpd_num))
-+ return NULL;
-+ return xbus->xpds[xpd_num];
-+}
-+
-+void xbus_reset_counters(xbus_t *xbus)
-+{
-+ int i;
-+
-+ DBG("Reseting counters of %s\n", xbus->busname);
-+ for(i = 0; i < XBUS_COUNTER_MAX; i++) {
-+ xbus->counters[i] = 0;
-+ }
-+// xbus->xmit_queue.worst_count = 0;
-+// xbus->xmit_queue.overflows = 0;
-+}
-+
-+#ifdef CONFIG_PROC_FS
-+
-+/**
-+ * Prints a general procfs entry for the bus, under xpp/BUSNAME/summary
-+ * @page TODO: figure out procfs
-+ * @start TODO: figure out procfs
-+ * @off TODO: figure out procfs
-+ * @count TODO: figure out procfs
-+ * @eof TODO: figure out procfs
-+ * @data an xbus_t pointer with the bus data.
-+ */
-+static int xbus_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data)
-+{
-+ int len = 0;
-+ unsigned long flags;
-+ xbus_t *xbus = data;
-+ int i;
-+
-+ if(!xbus)
-+ goto out;
-+ spin_lock_irqsave(&xbus->lock, flags);
-+
-+ len += sprintf(page + len, "%s: CONNECTOR=%s STATUS=%s bus_type=%d\n",
-+ xbus->busname,
-+ xbus->busdesc,
-+ (xbus->hardware_exists) ? "connected" : "missing",
-+ xbus->bus_type
-+ );
-+ len += sprintf(page + len, "open_counter=%d packet_count=%d\n",
-+ xbus->open_counter,
-+ atomic_read(&xbus->packet_counter)
-+ );
-+#if SOFT_SIMULATOR
-+ len += sprintf(page + len, "XPDS SIM\n");
-+ for(i = 0; i < MAX_XPDS; i++) {
-+ struct xpd_sim *sim = &xbus->sim[i];
-+ xpd_t *xpd = xpd_of(xbus, i);
-+ len += sprintf(page + len, "\t%d> ignored=%d simulated=%d softloop_xpd=%d loopto=%d instanciated=%s\n",
-+ i, IS_SET(ignore_xpds, i), sim->simulated, sim->softloop_xpd, sim->loopto, (xpd) ? "yes" : "no");
-+ }
-+#endif
-+ len += sprintf(page + len, "COUNTERS:\n");
-+ for(i = 0; i < XBUS_COUNTER_MAX; i++) {
-+ len += sprintf(page + len, "\t%-15s = %d\n",
-+ xbus_counters[i].name, xbus->counters[i]);
-+ }
-+ len += sprintf(page + len, "<-- len=%d\n", len);
-+ spin_unlock_irqrestore(&xbus->lock, flags);
-+out:
-+ if (len <= off+count)
-+ *eof = 1;
-+ *start = page + off;
-+ len -= off;
-+ if (len > count)
-+ len = count;
-+ if (len < 0)
-+ len = 0;
-+ return len;
-+
-+}
-+
-+int proc_sync_read(char *page, char **start, off_t off, int count, int *eof, void *data)
-+{
-+ int len = 0;
-+
-+ len += sprintf(page + len, "# To modify sync source write into this file:\n");
-+ len += sprintf(page + len, "# HOST - For host based sync\n");
-+ len += sprintf(page + len, "# 0 0 - XBUS-0/XPD-0 provide sync\n");
-+ len += sprintf(page + len, "# m n - XBUS-m/XPD-n provide sync\n");
-+ if(!sync_master)
-+ len += sprintf(page + len, "HOST\n");
-+ else
-+ len += sprintf(page + len, "%s/%s\n", sync_master->xbus->busname, sync_master->xpdname);
-+ len += sprintf(page + len, "tick: #%d\n", xpp_timer_count);
-+ unsigned int xpp_timer_rate = 0;
-+ unsigned int now = jiffies;
-+ if(now - xpp_last_jiffies > 0) {
-+ xpp_timer_rate = ((xpp_timer_count % SAMPLE_TICKS) * 1000) / (now - xpp_last_jiffies);
-+ len += sprintf(page + len, "tick rate: %4d/second (average over %d seconds)\n", xpp_timer_rate, SAMPLE_TICKS/HZ);
-+ }
-+ if (len <= off+count)
-+ *eof = 1;
-+ *start = page + off;
-+ len -= off;
-+ if (len > count)
-+ len = count;
-+ if (len < 0)
-+ len = 0;
-+ return len;
-+}
-+
-+static int proc_sync_write(struct file *file, const char __user *buffer, unsigned long count, void *data)
-+{
-+ DBG("%s: count=%ld\n", __FUNCTION__, count);
-+ const int NUM_SIZE = 100;
-+ char buf[NUM_SIZE];
-+ int xbus_num;
-+ int xpd_num;
-+ xbus_t *xbus;
-+ xpd_t *xpd;
-+ int ret;
-+
-+ if(count >= NUM_SIZE)
-+ return -EINVAL;
-+ if(copy_from_user(buf, buffer, count))
-+ return -EFAULT;
-+ buf[count] = '\0';
-+ if(strncmp("HOST", buf, 4) == 0) {
-+ set_sync_master(NULL);
-+ goto out;
-+ }
-+ ret = sscanf(buf, "%d %d", &xbus_num, &xpd_num);
-+ if(ret != 2)
-+ return -EINVAL;
-+ DBG("%s: %d/%d\n", __FUNCTION__, xbus_num, xpd_num);
-+ if(xbus_num >= MAX_BUSES)
-+ return -EINVAL;
-+ xbus = xbus_of(xbus_num);
-+ if(!xbus)
-+ return -EINVAL;
-+ xpd = xpd_of(xbus, xpd_num);
-+ if(!xpd) {
-+ ERR("%s: XPD number %d does not exist\n", __FUNCTION__, xpd_num);
-+ return -ENXIO;
-+ }
-+ set_sync_master(xpd);
-+out:
-+ return count;
-+}
-+
-+int proc_xpd_ztregister_read(char *page, char **start, off_t off, int count, int *eof, void *data)
-+{
-+ int len = 0;
-+ unsigned long flags;
-+ xpd_t *xpd = data;
-+
-+ BUG_ON(!xpd);
-+ spin_lock_irqsave(&xpd->lock, flags);
-+
-+ len += sprintf(page + len, "%d\n", SPAN_REGISTERED(xpd));
-+ spin_unlock_irqrestore(&xpd->lock, flags);
-+ if (len <= off+count)
-+ *eof = 1;
-+ *start = page + off;
-+ len -= off;
-+ if (len > count)
-+ len = count;
-+ if (len < 0)
-+ len = 0;
-+ return len;
-+}
-+
-+static int proc_xpd_ztregister_write(struct file *file, const char __user *buffer, unsigned long count, void *data)
-+{
-+ xpd_t *xpd = data;
-+ const int NUM_SIZE = 100;
-+ char buf[NUM_SIZE];
-+ bool zt_reg;
-+ int ret;
-+
-+ BUG_ON(!xpd);
-+ if(count >= NUM_SIZE)
-+ return -EINVAL;
-+ if(copy_from_user(buf, buffer, count))
-+ return -EFAULT;
-+ buf[count] = '\0';
-+ ret = sscanf(buf, "%d", &zt_reg);
-+ if(ret != 1)
-+ return -EINVAL;
-+ DBG("%s: %s/%s %s\n", __FUNCTION__,
-+ xpd->xbus->busname, xpd->xpdname, (zt_reg) ? "register" : "unregister");
-+ if(zt_reg)
-+ ret = xpd_zaptel_register(xpd);
-+ else
-+ ret = xpd_zaptel_unregister(xpd);
-+ return (ret < 0) ? ret : count;
-+}
-+
-+#endif
-+
-+/**
-+ *
-+ * Packet is freed:
-+ * - In case of error, by this function.
-+ * - Otherwise, by the underlying sending mechanism
-+ */
-+int packet_send(xbus_t *xbus, xpacket_t *pack_tx)
-+{
-+ int ret = -ENODEV;
-+ int toxpd;
-+
-+ if(!pack_tx) {
-+ DBG("null pack\n");
-+ return -EINVAL;
-+ }
-+ toxpd = XPD_NUM(pack_tx->content.addr);
-+ if(!xbus) {
-+ DBG("null xbus\n");
-+ ret = -EINVAL;
-+ goto error;
-+ }
-+ if (!xbus->hardware_exists) {
-+ DBG("xbus %s Dropped a packet -- NO HARDWARE.", xbus->busname);
-+ ret = -ENODEV;
-+ goto error;
-+ }
-+ if(!VALID_XPD_NUM(toxpd)) {
-+ ERR("%s: toxpd=%d > MAX_XPDS\n", __FUNCTION__, toxpd);
-+ ret = -EINVAL;
-+ goto error;
-+ }
-+#if 0
-+ // DEBUG: For Dima
-+ if(pack_tx->content.opcode == XPP_PCM_WRITE) {
-+ static int rate_limit;
-+ static int count;
-+
-+ if(sync_master == NULL)
-+ count = 0;
-+ if(count++ > 5) {
-+ ret = 0;
-+ goto error;
-+ }
-+ if(rate_limit++ % 1000 == 0)
-+ INFO("DEBUG: TRANSMIT (PCM_WRITE)\n");
-+ }
-+#endif
-+ if(down_read_trylock(&xbus->in_use)) {
-+ ret = xbus->ops->packet_send(xbus, pack_tx);
-+ XBUS_COUNTER(xbus, TX_BYTES) += pack_tx->datalen;
-+ up_read(&xbus->in_use);
-+ } else {
-+ DBG("Dropped packet. %s is in_use\n", xbus->busname);
-+ }
-+ return ret;
-+
-+error:
-+ xbus->ops->packet_free(xbus, pack_tx);
-+ return ret;
-+}
-+
-+static void xbus_poll(xbus_t *xbus, int probe_all)
-+{
-+ int id;
-+ int ret;
-+ xpd_t **xpds;
-+ xpd_t *xpd;
-+
-+ DBG("%s (probe_all=%d)\n", xbus->busname, probe_all);
-+ xpds = xbus->xpds;
-+ for(id = 0; id < MAX_XPDS; id++) {
-+ if(!xbus->hardware_exists)
-+ break;
-+ xpd = xpd_of(xbus, id);
-+ if(!probe_all) {
-+ if(!xpd) {
-+ DBG(" Skipping XPD #%d is MISSING\n", id);
-+ continue;
-+ }
-+ if(!atomic_read(&xpd->card_present)) {
-+ DBG(" Skipping XPD #%d not present\n", id);
-+ continue;
-+ }
-+ if(time_after(xpd->last_response+20, jiffies)) {
-+ DBG(" SKIP DESC_REQ\n");
-+ continue;
-+ }
-+ }
-+ if(IS_SET(ignore_xpds, id)) { /* skip xpds */
-+ DBG(" Ignoring XPD #%d\n", id);
-+ continue;
-+ }
-+ DBG(" Polling slot %d %s\n", id, xbus->busname);
-+ ret = CALL_PROTO(GLOBAL, DESC_REQ, xbus, NULL, id);
-+ if(ret < 0) {
-+ NOTICE("xpp: %s: Failed sending DESC_REQ to XPD #%d\n", __FUNCTION__, id);
-+ }
-+ }
-+}
-+
-+void process_xbus_poll(void *data) {
-+ xbus_t *xbus = (xbus_t*) data;
-+
-+ ERR("%s: issuing xbus_poll\n", __FUNCTION__);
-+ xbus_poll(xbus, 1);
-+}
-+
-+
-+#if SOFT_SIMULATOR
-+/*
-+ * Assume xbus->lock is held
-+ */
-+static void simulator_setup(xbus_t *xbus, ulong sim_xpds)
-+{
-+ int i;
-+ int last_fxo = 0;
-+ bool first = 1;
-+
-+ DBG("%s: sim_xpds=0x%lX\n", xbus->busname, sim_xpds);
-+ for(i = 0; i < MAX_XPDS; i++) {
-+ if (!IS_SET(sim_xpds, i) || xbus->sim[i].simulated)
-+ continue;
-+ if (first) {
-+ last_fxo=i;
-+ } else {
-+ // setting simulated twice here: in case of odd number of simulated XPDs
-+ xbus->sim[i].xpd_type = XPD_TYPE_FXO;
-+ xbus->sim[i].loopto = last_fxo;
-+ xbus->sim[i].simulated = 1;
-+ xbus->sim[last_fxo].xpd_type = XPD_TYPE_FXS;
-+ xbus->sim[last_fxo].loopto = i;
-+ xbus->sim[last_fxo].simulated = 1;
-+
-+ }
-+ if(IS_SET(softloop_xpds, i))
-+ xbus->sim[i].softloop_xpd = 1;
-+ xbus->sim[i].hookstate = 0;
-+
-+ first = !first;
-+ }
-+}
-+#endif
-+
-+void xbus_activate(xbus_t *xbus)
-+{
-+ xbus_ops_t *ops;
-+
-+ BUG_ON(!xbus);
-+ ops = xbus->ops;
-+ BUG_ON(!ops);
-+ BUG_ON(!xbus->priv);
-+ /* Sanity checks */
-+ if(!ops->packet_send) {
-+ ERR("%s: missing mandatory handler: packet_send=\n", __FUNCTION__);
-+ return;
-+ }
-+ if(!ops->packet_new || !ops->packet_free) {
-+ ops->packet_new = softloop_packet_new;
-+ ops->packet_free = softloop_packet_free;
-+ }
-+
-+ xbus->hardware_exists = 1;
-+ DBG("Activating: %s\n", xbus->busname);
-+ /* Poll it */
-+ xbus_poll(xbus, 1);
-+}
-+
-+void xbus_deactivate(xbus_t *xbus)
-+{
-+ int i;
-+
-+ BUG_ON(!xbus);
-+ DBG("%s\n", xbus->busname);
-+ xbus->hardware_exists = 0;
-+ for(i = 0; i < MAX_XPDS; i++) {
-+ xpd_t *xpd = xpd_of(xbus, i);
-+ if(!xpd)
-+ continue;
-+ if(xpd->id != i) {
-+ ERR("%s: BUG: xpd->id=%d != i=%d\n", __FUNCTION__, xpd->id, i);
-+ continue;
-+ }
-+ xpd_card_disable(xpd);
-+ }
-+ down_write(&xbus->in_use);
-+ DBG("%s (deactivated)\n", xbus->busname);
-+ if(xbus->open_counter == 0) {
-+ xbus_remove(xbus);
-+ }
-+}
-+
-+
-+static void xbus_cleanup(xbus_t *xbus)
-+{
-+ BUG_ON(!xbus);
-+#ifdef CONFIG_PROC_FS
-+ if(xbus->proc_xbus_dir) {
-+ if(xbus->proc_xbus_summary) {
-+ DBG("Removing proc '%s' for %s\n", PROC_XBUS_SUMMARY, xbus->busname);
-+ remove_proc_entry(PROC_XBUS_SUMMARY, xbus->proc_xbus_dir);
-+ xbus->proc_xbus_summary = NULL;
-+ }
-+ DBG("Removing proc directory %s\n", xbus->busname);
-+ remove_proc_entry(xbus->busname, xpp_procdir);
-+ xbus->proc_xbus_dir = NULL;
-+ }
-+#endif
-+ kfree(xbus);
-+}
-+
-+xbus_t *xbus_new(ulong loopback_xpds)
-+{
-+ unsigned long flags;
-+ int xbus_num;
-+ int err;
-+ xbus_t *xbus;
-+
-+ xbus = kmalloc(sizeof(xbus_t), GFP_KERNEL);
-+ if(!xbus)
-+ return NULL;
-+ memset(xbus, 0, sizeof(xbus_t));
-+
-+ spin_lock_irqsave(&xbuses_lock, flags);
-+ for(xbus_num = 0; xbus_num < MAX_BUSES; xbus_num++)
-+ if(xbuses_array[xbus_num] == NULL)
-+ break;
-+ if(xbus_num >= MAX_BUSES) {
-+ spin_unlock_irqrestore(&xbuses_lock, flags);
-+ err = -ENOMEM;
-+ goto nobus;
-+ }
-+ /* Found empty slot */
-+ xbuses_array[xbus_num] = xbus;
-+ bus_count++;
-+ spin_unlock_irqrestore(&xbuses_lock, flags);
-+
-+ /* Init data structures */
-+ spin_lock_init(&xbus->lock);
-+ snprintf(xbus->busname, XBUS_NAMELEN, "XBUS-%d", xbus_num);
-+ INFO("New xbus: %s\n", xbus->busname);
-+ init_waitqueue_head(&xbus->packet_cache_empty);
-+ atomic_set(&xbus->packet_counter, 0);
-+ init_rwsem(&xbus->in_use);
-+ xbus->num = xbus_num;
-+ xbus->num_xpds = 0;
-+#if SOFT_SIMULATOR
-+ xbus->sim_workqueue = create_singlethread_workqueue(xbus->busname);
-+ if(!xbus->sim_workqueue) {
-+ ERR("Failed to create workqueue for xbus %s\n", xbus->busname);
-+ err = -ENOMEM;
-+ goto nobus;
-+ }
-+ init_xbus_packet_queue(&xbus->sim_packet_queue, "SIM_PACKET_QUEUE");
-+ INIT_WORK(&xbus->sim_work, process_sim_queue, xbus);
-+ simulator_setup(xbus, loopback_xpds); // Hardware loopback must use simulator
-+ simulator_setup(xbus, softloop_xpds); // Add the soft loopback to the simulated set
-+#endif
-+ xbus_reset_counters(xbus);
-+#ifdef CONFIG_PROC_FS
-+ DBG("Creating xbus proc directory %s.\n",xbus->busname);
-+ xbus->proc_xbus_dir = proc_mkdir(xbus->busname, xpp_procdir);
-+ if(!xbus->proc_xbus_dir) {
-+ ERR("Failed to create proc directory for xbus %s\n", xbus->busname);
-+ err = -EIO;
-+ goto nobus;
-+ }
-+ xbus->proc_xbus_summary = create_proc_read_entry(PROC_XBUS_SUMMARY, 0444, xbus->proc_xbus_dir,
-+ xbus_read_proc, xbus);
-+ if (!xbus->proc_xbus_summary) {
-+ ERR("Failed to create '%s' proc file for xbus %s\n", PROC_XBUS_SUMMARY, xbus->busname);
-+ err = -EIO;
-+ goto nobus;
-+ }
-+#endif
-+ return xbus;
-+nobus:
-+ spin_lock_irqsave(&xbuses_lock, flags);
-+ xbuses_array[xbus_num] = NULL;
-+ bus_count--;
-+ spin_unlock_irqrestore(&xbuses_lock, flags);
-+ xbus_cleanup(xbus);
-+ return NULL;
-+}
-+
-+static void xbus_remove(xbus_t *xbus)
-+{
-+ int i;
-+ unsigned long flags;
-+
-+ BUG_ON(!xbus);
-+ DBG("%s\n", xbus->busname);
-+ spin_lock_irqsave(&xbuses_lock, flags);
-+ BUG_ON(xbus != xbus_of(xbus->num));
-+ xbuses_array[xbus->num] = NULL;
-+ bus_count--;
-+ spin_unlock_irqrestore(&xbuses_lock, flags);
-+#if SOFT_SIMULATOR
-+ if(xbus->sim_workqueue) {
-+ cancel_delayed_work(&xbus->sim_work);
-+ }
-+#endif
-+ INFO("Removing xbus(%d) %s\n", xbus->num, xbus->busname);
-+ for(i = 0; i < MAX_XPDS; i++) {
-+ xpd_t *xpd = xpd_of(xbus, i);
-+
-+ if(xpd) {
-+ const xops_t *xops = xpd->xops;
-+
-+ if(xpd->id != i) {
-+ ERR("%s: BUG: xpd->id=%d != i=%d\n", __FUNCTION__, xpd->id, i);
-+ continue;
-+ }
-+ BUG_ON(!xops);
-+ DBG(" Removing xpd id=%d\n", xpd->id);
-+ xpd_remove(xpd);
-+ }
-+ xbus->xpds[i] = NULL;
-+ }
-+#if SOFT_SIMULATOR
-+ if(xbus->sim_workqueue) {
-+ flush_workqueue(xbus->sim_workqueue);
-+ destroy_workqueue(xbus->sim_workqueue);
-+ xbus->sim_workqueue = NULL;
-+ }
-+ drain_xbus_packet_queue(xbus, &xbus->sim_packet_queue);
-+#endif
-+ int ret = wait_event_interruptible(xbus->packet_cache_empty,
-+ atomic_read(&xbus->packet_counter) == 0);
-+ if(ret) {
-+ ERR("waiting for packet_cache_empty interrupted!!!\n");
-+ }
-+ xbus_cleanup(xbus);
-+}
-+
-+
-+#define XPP_MAX_LEN 512
-+
-+/*------------------------- Zaptel Interfaces ----------------------*/
-+
-+#define PREP_REPORT_RATE 1000
-+
-+static void xpp_transmitprep(xpd_t *xpd)
-+{
-+ volatile u_char *writechunk;
-+ volatile u_char *w;
-+ int ret;
-+ int i;
-+ int channels = xpd->channels;
-+ struct zt_chan *chans = xpd->span.chans;
-+
-+// if((xpd->timer_count % PREP_REPORT_RATE) < 10)
-+// DBG("%d\n", xpd->timer_count);
-+
-+// if(xpd->hookstate == 0)
-+// return;
-+ if (xpd->timer_count & 1) {
-+ /* First part */
-+ w = writechunk = xpd->writechunk /* + 1 */;
-+ } else {
-+ w = writechunk = xpd->writechunk + ZT_CHUNKSIZE * CHANNELS_PERXPD /* + 1 */;
-+ }
-+ zt_transmit(&xpd->span);
-+
-+ for (i = 0; i < channels; i++) {
-+ if(IS_SET(xpd->hookstate, i)) {
-+ memcpy((u_char *)w, chans[i].writechunk, ZT_CHUNKSIZE);
-+ // fill_beep((u_char *)w, 5);
-+ }
-+ w += ZT_CHUNKSIZE;
-+ }
-+ if(xpd->hookstate != 0 || sync_master == xpd || !sync_master) {
-+ ret = CALL_XMETHOD(PCM_WRITE, xpd->xbus, xpd, xpd->hookstate, writechunk);
-+ if(ret < 0) {
-+ DBG("failed to write PCM %d\n", ret);
-+ }
-+ }
-+}
-+
-+void fill_beep(u_char *buf, int duration)
-+{
-+ int which = (jiffies/(duration*HZ)) & 0x3;
-+
-+ /*
-+ * debug tones
-+ */
-+ static u_char beep[] = {
-+// 0x7F, 0xBE, 0xD8, 0xBE, 0x80, 0x41, 0x24, 0x41, /* Dima */
-+// 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, /* silence */
-+ 0x67, 0x90, 0x89, 0x90, 0xFF, 0x10, 0x09, 0x10, /* Izzy */
-+// 0x67, 0xCD, 0xC5, 0xCD, 0xFF, 0x49, 0x41, 0x49, /* Dima 2 */
-+// 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, /* silence */
-+ };
-+ memcpy(buf, &beep[(which*8) % ARRAY_SIZE(beep)], ZT_CHUNKSIZE);
-+}
-+
-+static void xpp_receiveprep(xpd_t *xpd)
-+{
-+ volatile u_char *readchunk;
-+ int i;
-+ int channels = xpd->channels;
-+ struct zt_chan *chans = xpd->span.chans;
-+
-+// if((xpd->timer_count % PREP_REPORT_RATE) == 0)
-+// DBG("%d\n", xpd->timer_count);
-+
-+ if (xpd->timer_count & 1) {
-+ /* First part */
-+ readchunk = xpd->readchunk;
-+ } else {
-+ readchunk = xpd->readchunk + ZT_CHUNKSIZE * CHANNELS_PERXPD;
-+ }
-+
-+ for (i = 0; i < channels; i++) {
-+ if(IS_SET(xpd->hookstate, i)) {
-+ memcpy(chans[i].readchunk, (u_char *)readchunk, ZT_CHUNKSIZE);
-+ }
-+ readchunk += ZT_CHUNKSIZE;
-+ }
-+
-+#if 0
-+ /* FIXME: need to Echo cancel double buffered data */
-+ for (i = 0;i < xpd->span.channels; i++) {
-+ zt_ec_chunk(&chans[i], chans[i].readchunk, xpd->ec_chunk2[i]);
-+ memcpy(xpd->ec_chunk2[i], xpd->ec_chunk1[i], ZT_CHUNKSIZE);
-+ memcpy(xpd->ec_chunk1[i], chans[i].writechunk, ZT_CHUNKSIZE);
-+ }
-+#endif
-+ zt_receive(&xpd->span);
-+}
-+
-+static int xpp_startup(struct zt_span *span)
-+{
-+ DBG("\n");
-+ return 0;
-+}
-+
-+/*
-+ * Called only for 'span' keyword in /etc/zaptel.conf
-+ */
-+static int xpp_spanconfig(struct zt_span *span, struct zt_lineconfig *lc)
-+{
-+ xpd_t *xpd = span->pvt;
-+
-+ DBG("%s\n", xpd->xpdname);
-+ return 0;
-+}
-+
-+/*
-+ * Called only for 'span' keyword in /etc/zaptel.conf
-+ */
-+static int xpp_shutdown(struct zt_span *span)
-+{
-+ xpd_t *xpd = span->pvt;
-+
-+ DBG("%s\n", xpd->xpdname);
-+ return 0;
-+}
-+
-+int xpp_open(struct zt_chan *chan)
-+{
-+ xpd_t *xpd = chan->pvt;
-+ xbus_t *xbus = xpd->xbus;
-+ unsigned long flags;
-+
-+ spin_lock_irqsave(&xbus->lock, flags);
-+ xbus->open_counter++;
-+ atomic_inc(&xpd->open_counter);
-+ DBG("chan=%d (open_counter=%d)\n", chan->chanpos, xbus->open_counter);
-+ spin_unlock_irqrestore(&xbus->lock, flags);
-+ return 0;
-+}
-+
-+int xpp_close(struct zt_chan *chan)
-+{
-+ xpd_t *xpd = chan->pvt;
-+ xbus_t *xbus = xpd->xbus;
-+ unsigned long flags;
-+ bool should_remove = 0;
-+
-+ spin_lock_irqsave(&xbus->lock, flags);
-+ xbus->open_counter--;
-+ atomic_dec(&xpd->open_counter);
-+ if (!xbus->hardware_exists && xbus->open_counter == 0)
-+ should_remove = 1;
-+ spin_unlock_irqrestore(&xbus->lock, flags);
-+
-+ DBG("chan=%d (open_counter=%d, should_remove=%d)\n", chan->chanpos, xbus->open_counter, should_remove);
-+ if(should_remove)
-+ xbus_remove(xbus);
-+ return 0;
-+}
-+
-+int xpp_ioctl(struct zt_chan *chan, unsigned int cmd, unsigned long arg)
-+{
-+ xpd_t *xpd = chan->pvt;
-+ int pos = chan->chanpos - 1;
-+ int x;
-+
-+ switch (cmd) {
-+ case ZT_ONHOOKTRANSFER:
-+ if (get_user(x, (int *)arg))
-+ return -EFAULT;
-+ if (xpd->lasttxhook[pos] == 0x1) {
-+ /* Apply the change if appropriate */
-+ xpd->lasttxhook[pos] = 0x2;
-+ // CALL_XMETHOD(CHAN_CID, xpd->xbus, xpd, BIT(pos)); // CALLER ID
-+ }
-+ DBG("xpd=%d: ZT_ONHOOKTRANSFER (%d millis) chan=%d\n", xpd->id, x, pos);
-+ return -ENOTTY;
-+ case ZT_TONEDETECT:
-+ if (get_user(x, (int *)arg))
-+ return -EFAULT;
-+ DBG("xpd=%d: ZT_TONEDETECT chan=%d: TONEDETECT_ON=%d TONEDETECT_MUTE=%d\n",
-+ xpd->id, pos, (x & ZT_TONEDETECT_ON), (x & ZT_TONEDETECT_MUTE));
-+ return -ENOTTY;
-+ default:
-+ DBG("ENOTTY: chan=%d cmd=0x%x\n", pos, cmd);
-+ DBG(" IOC_TYPE=0x%02X\n", _IOC_TYPE(cmd));
-+ DBG(" IOC_DIR=0x%02X\n", _IOC_DIR(cmd));
-+ DBG(" IOC_NR=0x%02X\n", _IOC_NR(cmd));
-+ DBG(" IOC_SIZE=0x%02X\n", _IOC_SIZE(cmd));
-+ return -ENOTTY;
-+ }
-+ return 0;
-+}
-+
-+#ifdef WITH_RBS
-+static int xpp_hooksig(struct zt_chan *chan, zt_txsig_t txsig)
-+{
-+ xpd_t *xpd = chan->pvt;
-+ xbus_t *xbus;
-+ int pos = chan->chanpos - 1;
-+ int ret = 0;
-+
-+ if(!xpd) {
-+ ERR("%s: channel=%d without an XPD!\n", __FUNCTION__, pos);
-+ return -EINVAL;
-+ }
-+ xbus = xpd->xbus;
-+
-+ if (txsig == ZT_TXSIG_START) {
-+ if(xpd->direction == TO_PHONE) {
-+ // A PHONE line: ZT_START will be treated as ZT_RING
-+ DBG("Got ZT_START for PHONE channel %d, treated as ZT_RING\n", pos);
-+ //hookstate = ZT_TXSIG_RING;
-+
-+ if(IS_SET(xpd->digital_inputs, pos)) {
-+ NOTICE("%s: Trying to RING a digital input channel %d. Ignoring\n", __FUNCTION__, pos);
-+ return -EINVAL;
-+ }
-+ if(IS_SET(xpd->digital_outputs, pos)) {
-+ DBG("ZT_RING %s digital output ON\n", chan->name);
-+ ret = CALL_XMETHOD(RELAY_OUT, xpd->xbus, xpd, pos-8, 1);
-+ return ret;
-+ }
-+ xpd->ringing[pos] = RINGS_NUM*2;
-+ DBG("ZT_RING %s ringing=%d\n", chan->name, xpd->ringing[pos]);
-+ ret = CALL_XMETHOD(RING, xbus, xpd, pos, 1); // RING on
-+ if(ret) {
-+ DBG("ZT_RING Failed: ret=0x%02X\n", ret);
-+ return ret;
-+ }
-+ return ret;
-+ } else { /* TO_PSTN */
-+ // An FXO line: ZT_START will be treated as ZT_OFFHOOK
-+ DBG("Got ZT_START for FXO channel %d, treated as ZT_OFFHOOK\n", pos);
-+ txsig = ZT_TXSIG_OFFHOOK;
-+ }
-+ }
-+ switch(txsig) {
-+ case ZT_TXSIG_START:
-+ DBG("ZT_TXSIG_START: (doing OFFHOOK) %s (chan->dialing=%d)\n", chan->name, chan->dialing);
-+ break;
-+ /* Fall through */
-+ case ZT_TXSIG_OFFHOOK:
-+ DBG("ZT_TXSIG_OFFHOOK: %s hookstate=0x%04X\n", chan->name, xpd->hookstate);
-+ BIT_SET(xpd->hookstate, pos);
-+ xpd->ringing[pos] = 0;
-+ if(IS_SET(xpd->digital_inputs, pos)) {
-+ NOTICE("%s: Trying to OFFHOOK a digital input channel %d. Ignoring\n", __FUNCTION__, pos);
-+ return -EINVAL;
-+ }
-+ if(IS_SET(xpd->digital_outputs, pos)) {
-+ DBG("ZT_TXSIG_OFFHOOK %s digital output OFF\n", chan->name);
-+ ret = CALL_XMETHOD(RELAY_OUT, xpd->xbus, xpd, pos-8, 0);
-+ return ret;
-+ }
-+ ret = CALL_XMETHOD(SETHOOK, xbus, xpd->id, xpd->hookstate);
-+ if(ret) {
-+ DBG("ZT_TXSIG_OFFHOOK Failed: ret=0x%02X\n", ret);
-+ break;
-+ }
-+ CALL_XMETHOD(LED, xpd->xbus, xpd, BIT(i), LED_GREEN, 0);
-+ break;
-+ //DBG("ZT_TXSIG_OFFHOOK %d\n", pos);
-+ //BIT_SET(xpd->hookstate, pos);
-+ //break;
-+ case ZT_TXSIG_KEWL:
-+ DBG("ZT_TXSIG_KEWL (doing ONHOOK): %d.\n", pos);
-+ break;
-+ /* Fall through */
-+ case ZT_TXSIG_ONHOOK:
-+ DBG("ZT_TXSIG_ONHOOK: %s hookstate=0x%04X\n", chan->name, xpd->hookstate);
-+ xpd->ringing[pos] = 0;
-+ if(IS_SET(xpd->digital_inputs, pos)) {
-+ NOTICE("%s: Trying to ONHOOK a digital input channel %d. Ignoring\n", __FUNCTION__, pos);
-+ return -EINVAL;
-+ }
-+ if(IS_SET(xpd->digital_outputs, pos)) {
-+ DBG("ZT_TXSIG_ONHOOK %s digital output OFF\n", chan->name);
-+ ret = CALL_XMETHOD(RELAY_OUT, xpd->xbus, xpd, pos-8, 0);
-+ return ret;
-+ }
-+ BIT_CLR(xpd->hookstate, pos);
-+ ret = CALL_XMETHOD(SETHOOK, xbus, xpd->id, xpd->hookstate);
-+ if(ret) {
-+ DBG("ZT_ONHOOK Failed: ret=0x%02X\n", ret);
-+ break;
-+ }
-+ CALL_XMETHOD(LED, xpd->xbus, xpd, BIT(i), LED_GREEN, 0);
-+ break;
-+ //DBG("ZT_TXSIG_ONHOOK: %d\n", pos);
-+ //BIT_CLR(xpd->hookstate, pos);
-+ //break;
-+ default:
-+ DBG("hooksig: unkown txsig=%d on channel %d\n", txsig, pos);
-+ return -EINVAL;
-+ }
-+ //ret = CALL_XMETHOD(SETHOOK, xbus, xpd->id, xpd->hookstate);
-+ //if(ret) {
-+ // DBG("ZT_TXSIG_START Failed: ret=0x%02X\n", ret);
-+ //}
-+ return ret;
-+}
-+#endif
-+
-+static int xpp_sethook(struct zt_chan *chan, int hookstate)
-+{
-+ int pos = chan->chanpos - 1;
-+ xpd_t *xpd = chan->pvt;
-+ xbus_t *xbus;
-+ int ret = 0;
-+
-+ if(!xpd) {
-+ ERR("%s: channel=%d without an XPD!\n", __FUNCTION__, pos);
-+ return -EINVAL;
-+ }
-+ xbus = xpd->xbus;
-+ DBG("%s (%d) (old=0x%04X, hook-command=%d)\n", chan->name, pos, xpd->hookstate, hookstate);
-+ switch(hookstate) {
-+ /* On-hook, off-hook: The PBX is playing a phone on an FXO line.
-+ * Can be ignored for an FXS line
-+ */
-+ case ZT_ONHOOK:
-+ if(IS_SET(xpd->digital_inputs, pos)) {
-+ NOTICE("%s: Trying to ONHOOK a digital input channel %d. Ignoring\n", __FUNCTION__, pos);
-+ return -EINVAL;
-+ }
-+ if(IS_SET(xpd->digital_outputs, pos)) {
-+ DBG("ZT_ONHOOK %s digital output OFF\n", chan->name);
-+ ret = CALL_XMETHOD(RELAY_OUT, xpd->xbus, xpd, pos-8, 0);
-+ return ret;
-+ }
-+ if(xpd->direction == TO_PHONE) { /* Stop ring */
-+ DBG("ZT_ONHOOK: %s hookstate=0x%04X (stop ringing pos=%d)\n", chan->name, xpd->hookstate, pos);
-+ xpd->ringing[pos] = 0;
-+#if 1 // FIXME: Not needed -- verify
-+ ret = CALL_XMETHOD(RING, xbus, xpd, pos, 0); // RING off
-+#endif
-+ xpd->lasttxhook[pos] = 1;
-+ ret = CALL_XMETHOD(LED, xpd->xbus, xpd, BIT(pos), LED_GREEN, 0);
-+ ret = CALL_XMETHOD(CHAN_POWER, xbus, xpd, BIT(pos), 0); // Power down (prevent overheating!!!)
-+ if(ret) {
-+ DBG("ZT_ONHOOK(stop ring) Failed: ret=0x%02X\n", ret);
-+ break;
-+ }
-+ } else {
-+ DBG("ZT_ONHOOK: %s hookstate=0x%04X (pos=%d)\n", chan->name, xpd->hookstate, pos);
-+ xpd->ringing[pos] = 0;
-+ BIT_CLR(xpd->hookstate, pos);
-+ ret = CALL_XMETHOD(SETHOOK, xbus, xpd, xpd->hookstate);
-+ if(ret) {
-+ DBG("ZT_ONHOOK Failed: ret=0x%02X\n", ret);
-+ break;
-+ }
-+ }
-+ break;
-+ case ZT_START:
-+ DBG("ZT_START: %s hookstate=0x%04X (fall through ZT_OFFHOOK)\n", chan->name, xpd->hookstate);
-+ // Fall through
-+ case ZT_OFFHOOK:
-+ if(xpd->direction == TO_PHONE) {
-+ DBG("ZT_OFFHOOK: %s hookstate=0x%04X -- ignoring (PHONE)\n", chan->name, xpd->hookstate);
-+ break;
-+ }
-+ DBG("ZT_OFFHOOK: %s hookstate=0x%04X (pos=%d)\n", chan->name, xpd->hookstate, pos);
-+ BIT_SET(xpd->hookstate, pos);
-+ xpd->ringing[pos] = 0;
-+ ret = CALL_XMETHOD(SETHOOK, xbus, xpd, xpd->hookstate);
-+ if(ret) {
-+ DBG("ZT_OFFHOOK Failed: ret=0x%02X\n", ret);
-+ break;
-+ }
-+ break;
-+ case ZT_WINK:
-+ DBG("ZT_WINK %s\n", chan->name);
-+ break;
-+ case ZT_FLASH:
-+ DBG("ZT_FLASH %s\n", chan->name);
-+ break;
-+ case ZT_RING:
-+ DBG("ZT_RING %s pos=%d (ringing[pos]=%d)\n", chan->name, pos, xpd->ringing[pos]);
-+ if(xpd->direction == TO_PHONE) {
-+ if(IS_SET(xpd->digital_inputs, pos)) {
-+ NOTICE("%s: Trying to RING a digital input channel %d. Ignoring\n", __FUNCTION__, pos);
-+ return -EINVAL;
-+ }
-+ if(IS_SET(xpd->digital_outputs, pos)) {
-+ DBG("ZT_ONHOOK %s digital output ON\n", chan->name);
-+ ret = CALL_XMETHOD(RELAY_OUT, xpd->xbus, xpd, pos-8, 1);
-+ return ret;
-+ }
-+ xpd->ringing[pos] = RINGS_NUM*2;
-+ ret = CALL_XMETHOD(CHAN_POWER, xbus, xpd, BIT(pos), 1); // Power up (for ring)
-+ ret = CALL_XMETHOD(RING, xbus, xpd, pos, 1); // RING on
-+ if(ret) {
-+ DBG("ZT_RING Failed: ret=0x%02X\n", ret);
-+ }
-+ }
-+ break;
-+ case ZT_RINGOFF:
-+ DBG("ZT_RINGOFF %s\n", chan->name);
-+ break;
-+ default:
-+ DBG("UNKNOWN hookstate=0x%X\n", hookstate);
-+ }
-+ return ret;
-+}
-+
-+/* Req: Set the requested chunk size. This is the unit in which you must
-+ report results for conferencing, etc */
-+int xpp_setchunksize(struct zt_span *span, int chunksize);
-+
-+/* Enable maintenance modes */
-+int xpp_maint(struct zt_span *span, int cmd)
-+{
-+ xpd_t *xpd = span->pvt;
-+ int ret = 0;
-+#if 0
-+ char loopback_data[] = "THE-QUICK-BROWN-FOX-JUMPED-OVER-THE-LAZY-DOG";
-+#endif
-+
-+ BUG_ON(!xpd);
-+ DBG("%s: span->mainttimer=%d\n", __FUNCTION__, span->mainttimer);
-+ switch(cmd) {
-+ case ZT_MAINT_NONE:
-+ printk("XXX Turn off local and remote loops XXX\n");
-+ CALL_XMETHOD(LED, xpd->xbus, xpd, xpd->enabled_chans, LED_RED, 0); // FIXME: Find usage for extra LED
-+ break;
-+ case ZT_MAINT_LOCALLOOP:
-+ printk("XXX Turn on local loopback XXX\n");
-+ break;
-+ case ZT_MAINT_REMOTELOOP:
-+ printk("XXX Turn on remote loopback XXX\n");
-+ break;
-+ case ZT_MAINT_LOOPUP:
-+ printk("XXX Send loopup code XXX\n");
-+ CALL_XMETHOD(LED, xpd->xbus, xpd, xpd->enabled_chans, LED_RED, 1); // FIXME: Find usage for extra LED
-+ // CALL_XMETHOD(LOOPBACK_AX, xpd->xbus, xpd, loopback_data, ARRAY_SIZE(loopback_data));
-+ break;
-+ case ZT_MAINT_LOOPDOWN:
-+ printk("XXX Send loopdown code XXX\n");
-+ CALL_XMETHOD(LED, xpd->xbus, xpd, xpd->enabled_chans, LED_RED, 0); // FIXME: Find usage for extra LED
-+ break;
-+ case ZT_MAINT_LOOPSTOP:
-+ printk("XXX Stop sending loop codes XXX\n");
-+ break;
-+ default:
-+ ERR("XPP: Unknown maint command: %d\n", cmd);
-+ ret = -EINVAL;
-+ break;
-+ }
-+ if (span->mainttimer || span->maintstat)
-+ update_xpd_status(xpd, ZT_ALARM_LOOPBACK);
-+ return ret;
-+}
-+
-+/* Set signalling type (if appropriate) */
-+static int xpp_chanconfig(struct zt_chan *chan, int sigtype)
-+{
-+ DBG("channel %d (%s), sigtype %d.\n", chan->channo, chan->name, sigtype);
-+ dump_sigtype(print_dbg, " ", sigtype);
-+ // FIXME: sanity checks:
-+ // - should be supported (within the sigcap)
-+ // - should not replace fxs <->fxo ??? (covered by previous?)
-+ return 0;
-+}
-+
-+#if 0
-+/* Okay, now we get to the signalling. You have several options: */
-+
-+/* Option 1: If you're a T1 like interface, you can just provide a
-+ rbsbits function and we'll assert robbed bits for you. Be sure to
-+ set the ZT_FLAG_RBS in this case. */
-+
-+/* Opt: If the span uses A/B bits, set them here */
-+int (*rbsbits)(struct zt_chan *chan, int bits);
-+
-+/* Option 2: If you don't know about sig bits, but do have their
-+ equivalents (i.e. you can disconnect battery, detect off hook,
-+ generate ring, etc directly) then you can just specify a
-+ sethook function, and we'll call you with appropriate hook states
-+ to set. Still set the ZT_FLAG_RBS in this case as well */
-+int (*hooksig)(struct zt_chan *chan, zt_txsig_t hookstate);
-+
-+/* Option 3: If you can't use sig bits, you can write a function
-+ which handles the individual hook states */
-+int (*sethook)(struct zt_chan *chan, int hookstate);
-+#endif
-+
-+#ifdef CONFIG_ZAPTEL_WATCHDOG
-+/*
-+ * If the watchdog detects no received data, it will call the
-+ * watchdog routine
-+ */
-+static int xpp_watchdog(struct zt_span *span, int cause)
-+{
-+ static int rate_limit = 0;
-+
-+ if((rate_limit++ % 1000) == 0)
-+ DBG("\n");
-+ return 0;
-+}
-+#endif
-+
-+/**
-+ * Unregister an xpd from zaptel and release related resources
-+ * @xpd The xpd to be unregistered
-+ * @returns 0 on success, errno otherwise
-+ *
-+ * Checks that nobody holds an open channel.
-+ *
-+ * Called by:
-+ * - User action through /proc
-+ * - During xpd_remove()
-+ */
-+static int xpd_zaptel_unregister(xpd_t *xpd)
-+{
-+ BUG_ON(!xpd);
-+
-+ if(!SPAN_REGISTERED(xpd)) {
-+ NOTICE("%s: %s is already unregistered\n", __FUNCTION__, xpd->xpdname);
-+ return -EIDRM;
-+ }
-+ if(sync_master == xpd)
-+ set_sync_master(NULL); // FIXME: it's better to elect a new prince
-+ update_xpd_status(xpd, ZT_ALARM_NOTOPEN);
-+ if(atomic_read(&xpd->open_counter)) {
-+ NOTICE("%s: %s is busy (open_counter=%d). Skipping.\n", __FUNCTION__, xpd->xpdname, atomic_read(&xpd->open_counter));
-+ return -EBUSY;
-+ }
-+ mdelay(2); // FIXME: This is to give chance for transmit/receiveprep to finish.
-+ zt_unregister(&xpd->span);
-+ return 0;
-+}
-+
-+static int xpd_zaptel_register(xpd_t *xpd)
-+{
-+ struct zt_chan *cur_chan;
-+ struct zt_span *span;
-+ xbus_t *xbus;
-+ int sigfxs;
-+ int i;
-+ int cn;
-+ const xops_t *xops;
-+
-+ BUG_ON(!xpd);
-+ xops = xpd->xops;
-+
-+ if (SPAN_REGISTERED(xpd)) {
-+ ERR("xpd %s already registered\n", xpd->xpdname);
-+ return -EEXIST;
-+ }
-+ sigfxs = ! (xpd->direction == TO_PHONE); /* signaling is opposite */
-+ cn = xpd->channels;
-+ DBG("Initializing span: xpd %d have %d channels.\n", xpd->id, cn);
-+
-+ memset(xpd->chans, 0, sizeof(struct zt_chan)*cn);
-+ memset(&xpd->span, 0, sizeof(struct zt_span));
-+
-+ span = &xpd->span;
-+ xbus = xpd->xbus;
-+ snprintf(span->name, MAX_SPANNAME, "%s/%s",
-+ xbus->busname, xpd->xpdname);
-+ {
-+ char tmp[MAX_SPANNAME];
-+#if SOFT_SIMULATOR
-+ struct xpd_sim *sim = &xbus->sim[xpd->id];
-+
-+ if(sim->simulated)
-+ snprintf(tmp, MAX_SPANNAME, " (sim to=%d)", sim->loopto);
-+ else
-+#endif
-+ tmp[0] = '\0';
-+
-+ snprintf(span->desc, MAX_SPANDESC, "Xorcom XPD #%d/%d: %s%s",
-+ xbus->num, xpd->id,
-+ (xpd->direction == TO_PHONE) ? "FXS" : "FXO",
-+ tmp
-+ );
-+ }
-+ for(i = 0; i < cn; i++) {
-+
-+ cur_chan = &xpd->chans[i];
-+ DBG("setting channel %d (sigfxs=%d)\n", i, sigfxs);
-+ if(IS_SET(xpd->digital_outputs, i)) {
-+ snprintf(cur_chan->name, MAX_CHANNAME, "XPP_OUT/%d-%d", xpd->id, i);
-+ } else if(IS_SET(xpd->digital_inputs, i)) {
-+ snprintf(cur_chan->name, MAX_CHANNAME, "XPP_IN/%d-%d", xpd->id, i);
-+ } else {
-+ snprintf(cur_chan->name, MAX_CHANNAME, "XPP_%s/%d-%d", (sigfxs) ? "FXO" : "FXS", xpd->id, i);
-+ }
-+ cur_chan->chanpos = i + 1;
-+ cur_chan->pvt = xpd;
-+ if (sigfxs)
-+ cur_chan->sigcap =
-+#if 1
-+ ZT_SIG_FXSKS |
-+ ZT_SIG_FXSLS |
-+#else
-+ ZT_SIG_SF |
-+#endif
-+ 0;
-+ else
-+ cur_chan->sigcap =
-+#if 1
-+ ZT_SIG_FXOKS |
-+ ZT_SIG_FXOLS |
-+ ZT_SIG_FXOGS |
-+#else
-+ ZT_SIG_SF |
-+ ZT_SIG_EM |
-+#endif
-+ 0;
-+ }
-+ span->deflaw = ZT_LAW_MULAW;
-+ init_waitqueue_head(&span->maintq);
-+ span->pvt = xpd;
-+ span->channels = cn;
-+ span->chans = xpd->chans;
-+
-+ span->startup = xpp_startup;
-+ span->shutdown = xpp_shutdown;
-+ span->spanconfig = xpp_spanconfig;
-+ span->chanconfig = xpp_chanconfig;
-+ span->open = xpp_open;
-+ span->close = xpp_close;
-+#ifdef WITH_RBS
-+ span->flags = ZT_FLAG_RBS;
-+ span->hooksig = xpp_hooksig; /* Only with RBS bits */
-+#else
-+ span->sethook = xpp_sethook;
-+#endif
-+ span->ioctl = xpp_ioctl;
-+ span->maint = xpp_maint;
-+#ifdef CONFIG_ZAPTEL_WATCHDOG
-+ span->watchdog = xpp_watchdog;
-+#endif
-+
-+ DBG("Finished span_load: ZT_FLAG_RUNNING=%d\n", span->flags & ZT_FLAG_RUNNING);
-+
-+ DBG("Registering span of %s.\n", xpd->xpdname);
-+ if(zt_register(&xpd->span, 1)) {
-+ xbus_t *xbus = xpd->xbus;
-+ ERR("Failed to zt_register of span of xpd %s.\n", xpd->xpdname);
-+ xbus->xpds[xpd->id] = NULL;
-+ list_del(&xpd->xpd_list);
-+ xbus->num_xpds--;
-+ return -ENODEV;
-+ }
-+// if(xpd->id == 0)
-+// set_sync_master(xpd);
-+
-+ return 0;
-+}
-+
-+
-+/*------------------------- Proc debugging interface ---------------*/
-+
-+#ifdef CONFIG_PROC_FS
-+
-+static int xpp_zap_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data)
-+{
-+ int len = 0;
-+ unsigned long flags;
-+ int i;
-+
-+ spin_lock_irqsave(&xbuses_lock, flags);
-+ for(i = 0; i < MAX_BUSES; i++) {
-+ xbus_t *xbus = xbus_of(i);
-+
-+ if(xbus) {
-+ len += sprintf(page + len, "%s: CONNECTOR=%s STATUS=%s bus_type=%d\n",
-+ xbus->busname,
-+ xbus->busdesc,
-+ (xbus->hardware_exists) ? "connected" : "missing",
-+ xbus->bus_type
-+ );
-+ }
-+ }
-+#if 0
-+ len += sprintf(page + len, "<-- len=%d\n", len);
-+#endif
-+ spin_unlock_irqrestore(&xbuses_lock, flags);
-+ if (len <= off+count)
-+ *eof = 1;
-+ *start = page + off;
-+ len -= off;
-+ if (len > count)
-+ len = count;
-+ if (len < 0)
-+ len = 0;
-+ return len;
-+
-+}
-+
-+#if 0
-+static int xpp_zap_write_proc(struct file *file, const char __user *buffer, unsigned long count, void *data)
-+{
-+}
-+#endif
-+
-+#endif
-+
-+/*------------------------- File Operations ------------------------*/
-+
-+#define MINOR_XBUS_NUM(m) ((m) >> 4)
-+#define MINOR_XPD_NUM(m) ((m) & 0xF);
-+
-+static int xpp_sys_open (struct inode * inode, struct file * file)
-+{
-+ xbus_t *xbus;
-+ unsigned int minor = iminor(inode);
-+ unsigned int busnum = MINOR_XBUS_NUM(minor);
-+ unsigned long flags;
-+
-+ spin_lock_irqsave(&xbuses_lock, flags);
-+ xbus = xbus_of(busnum);
-+ spin_unlock_irqrestore(&xbuses_lock, flags);
-+ if(xbus == NULL)
-+ return -ENODEV;
-+ file->private_data = xbus;
-+ DBG("unit %d xbus %s\n", busnum, xbus->busname);
-+ return 0;
-+}
-+
-+static int xpp_sys_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
-+{
-+ switch(cmd) {
-+ default:
-+ return -ENOTTY;
-+ }
-+ return 0;
-+}
-+
-+static int xpp_sys_release (struct inode * inode, struct file * file)
-+{
-+ unsigned int minor = iminor(inode);
-+ unsigned int busnum = MINOR_XBUS_NUM(minor);
-+ xbus_t *xbus = file->private_data;
-+ DBG("unit %d xbus %s\n", busnum, xbus->busname);
-+ if(xbus == NULL) {
-+ ERR("xpp_sys_release: xbus has dissappeared\n");
-+ return -EINVAL;
-+ }
-+ return 0;
-+}
-+
-+#if 0
-+static ssize_t xpp_sys_write (struct file * file, const char __user * buf,
-+ size_t count, loff_t * ppos)
-+{
-+ unsigned int minor = iminor(file->f_dentry->d_inode);
-+ unsigned int busnum = MINOR_XBUS_NUM(minor);
-+ int xpdnum = MINOR_XPD_NUM(minor)
-+ xbus_t *xbus = file->private_data;
-+ xpacket_t *pack_tx;
-+
-+ DBG("count=%d from %d/%d xbus %s\n", count, busnum, xpdnum, xbus->busname);
-+ if(xbus == NULL) {
-+ ERR("xpp_sys_write: xbus has dissappeared\n");
-+ return -EINVAL;
-+ }
-+ if(count == 0)
-+ return 0;
-+ if(count >= sizeof(xpacket_raw_t)) {
-+ DBG("count=%d, partial write...\n", count);
-+ count = sizeof(xpacket_raw_t);
-+ }
-+ pack_tx = xbus->ops->packet_new(xbus, GFP_KERNEL);
-+ if (!pack_tx) {
-+ return -ENOMEM;
-+ }
-+ if (copy_from_user (pack_tx->content.raw, buf, count)) {
-+ return -EFAULT;
-+ }
-+ XPD_ADDR_SET(pack_tx->content.addr, xpdnum);
-+ pack_tx->datalen = count;
-+ // pack_tx->flags |= XPP_PACKET_FIREANDFORGET;
-+ DBG("sending op=%d to %d\n", pack_tx->content.opcode, xpdnum);
-+ xbus_reset_counters(xbus);
-+ pcm_write_enable = 1;
-+ packet_send(xbus, pack_tx);
-+ return count;
-+}
-+#endif
-+
-+static struct file_operations xpp_fops = {
-+ .owner = THIS_MODULE,
-+ .llseek = no_llseek,
-+#if 0
-+ .write = xpp_sys_write,
-+#endif
-+ .ioctl = xpp_sys_ioctl,
-+ .open = xpp_sys_open,
-+ .release = xpp_sys_release,
-+};
-+
-+
-+/*------------------------- Initialization -------------------------*/
-+
-+static void do_cleanup(void)
-+{
-+ if(timer_pending(&xpp_timer))
-+ del_timer_sync(&xpp_timer);
-+ unregister_chrdev(XPP_CTL_MAJOR, THIS_MODULE->name);
-+#ifdef CONFIG_PROC_FS
-+ remove_proc_entry(PROC_SYNC, xpp_procdir);
-+ remove_proc_entry(PROC_XBUSES, xpp_procdir);
-+ if(xpp_procdir) {
-+ remove_proc_entry(PROC_DIR, NULL);
-+ }
-+#endif
-+ if (xpp_worker) {
-+ flush_workqueue(xpp_worker);
-+ destroy_workqueue(xpp_worker);
-+ xpp_worker = NULL;
-+ }
-+ kmem_cache_destroy(packet_cache);
-+}
-+
-+int __init xpp_zap_init(void)
-+{
-+ INFO("%s revision %s\n", THIS_MODULE->name, revision);
-+
-+ packet_cache = kmem_cache_create("xpp_packets",
-+ sizeof(xpacket_t),
-+ 0, 0,
-+ NULL, NULL);
-+ if(!packet_cache) {
-+ return -ENOMEM;
-+ }
-+#ifdef CONFIG_PROC_FS
-+ xpp_procdir = proc_mkdir(PROC_DIR, NULL);
-+ if(!xpp_procdir) {
-+ do_cleanup();
-+ return -EIO;
-+ }
-+ struct proc_dir_entry *ent;
-+
-+ ent = create_proc_entry(PROC_SYNC, 0644, xpp_procdir);
-+ if(!ent) {
-+ do_cleanup();
-+ return -EFAULT;
-+ }
-+ ent->read_proc = proc_sync_read;
-+ ent->write_proc = proc_sync_write;
-+ ent->data = NULL;
-+ ent = create_proc_read_entry(PROC_XBUSES, 0444, xpp_procdir, xpp_zap_read_proc, 0);
-+ if (!ent) {
-+ do_cleanup();
-+ return -EFAULT;
-+ }
-+#endif
-+ xpp_worker = create_singlethread_workqueue("xppworker");
-+ if(!xpp_worker) {
-+ ERR("Failed to create card detector workqueue.\n");
-+ do_cleanup();
-+ return -ENOMEM;
-+ }
-+
-+ if (register_chrdev(XPP_CTL_MAJOR, THIS_MODULE->name, &xpp_fops)) {
-+ printk (KERN_WARNING "%s: unable to get major %d\n", THIS_MODULE->name, XPP_CTL_MAJOR);
-+ do_cleanup();
-+ return -EIO;
-+ }
-+
-+ /* Only timer init. We add it only *after* zt_register */
-+ init_timer(&xpp_timer);
-+ set_sync_master(NULL); /* Internal ticking */
-+ return 0;
-+}
-+
-+void __exit xpp_zap_cleanup(void)
-+{
-+// unsigned long flags;
-+ int i;
-+
-+ for(i = 0; i < MAX_BUSES; i++) {
-+ xbus_t *xbus = xbus_of(i);
-+ if(!xbus)
-+ continue;
-+ xbus_remove(xbus);
-+ }
-+// spin_lock_irqsave(&xbuses_lock, flags);
-+ if(bus_count) {
-+ ERR("%s: bus_count=%d!\n", __FUNCTION__, bus_count);
-+ }
-+// spin_unlock_irqrestore(&xbuses_lock, flags);
-+ do_cleanup();
-+}
-+
-+EXPORT_SYMBOL(print_dbg);
-+EXPORT_SYMBOL(card_detected);
-+EXPORT_SYMBOL(xpd_alloc);
-+EXPORT_SYMBOL(xbus_activate);
-+EXPORT_SYMBOL(xbus_deactivate);
-+EXPORT_SYMBOL(xpd_of);
-+EXPORT_SYMBOL(xbus_new);
-+EXPORT_SYMBOL(xbus_remove);
-+EXPORT_SYMBOL(xbus_reset_counters);
-+EXPORT_SYMBOL(packet_send);
-+EXPORT_SYMBOL(fill_beep);
-+EXPORT_SYMBOL(xbus_enqueue_packet);
-+EXPORT_SYMBOL(xbus_dequeue_packet);
-+EXPORT_SYMBOL(init_xbus_packet_queue);
-+EXPORT_SYMBOL(drain_xbus_packet_queue);
-+EXPORT_SYMBOL(phone_hook);
-+EXPORT_SYMBOL(xpp_check_hookstate);
-+EXPORT_SYMBOL(xpp_tick);
-+EXPORT_SYMBOL(xpp_open);
-+EXPORT_SYMBOL(xpp_close);
-+EXPORT_SYMBOL(xpp_ioctl);
-+EXPORT_SYMBOL(xpp_maint);
-+
-+MODULE_DESCRIPTION("XPP Zaptel Driver");
-+MODULE_AUTHOR("Oron Peled <oron at actcom.co.il>");
-+MODULE_LICENSE("GPL");
-+MODULE_VERSION("$Id: xpp_zap.c 185 2006-01-10 14:39:07Z oron $");
-+
-+module_init(xpp_zap_init);
-+module_exit(xpp_zap_cleanup);
-diff -urNad zaptel-1.0.10/xpp/xpp_zap.h /tmp/dpep.absTwN/zaptel-1.0.10/xpp/xpp_zap.h
---- zaptel-1.0.10/xpp/xpp_zap.h 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.absTwN/zaptel-1.0.10/xpp/xpp_zap.h 2006-01-11 10:12:52.000000000 +0200
-@@ -0,0 +1,58 @@
-+#ifndef XPP_ZAP_H
-+#define XPP_ZAP_H
-+
-+#include <linux/workqueue.h>
-+#include "xpd.h"
-+#include "xproto.h"
-+
-+xpacket_t *xpacket_new(xbus_t *xbus, int flags);
-+void xpacket_free(xbus_t *xbus, xpacket_t *p);
-+
-+/* packet queues */
-+void init_xbus_packet_queue(packet_queue_t *q, const char name[]);
-+void drain_xbus_packet_queue(xbus_t *xbus, packet_queue_t *q);
-+void xbus_enqueue_packet(xbus_t *xbus, packet_queue_t *q, xpacket_t *pack);
-+xpacket_t *xbus_dequeue_packet(packet_queue_t *q);
-+
-+xbus_t *xbus_new(ulong loopback_xpds);
-+void xbus_activate(xbus_t *xbus);
-+void xbus_deactivate(xbus_t *xbus);
-+
-+void xbus_reset_counters(xbus_t *xbus);
-+int packet_send(xbus_t *xbus, xpacket_t *pack_tx);
-+void phone_hook(xpd_t *xpd, int channo, bool offhook);
-+void xpp_check_hookstate(xpd_t *xpd, xpp_line_t fxs_off_hook);
-+xpd_t *xpd_of(xbus_t *xbus, int xpd_num);
-+void card_detected(void *data);
-+xpd_t *xpd_alloc(size_t privsize, xbus_t *xbus, int xpd_num, const xproto_table_t *proto_table, int channels, byte revision);
-+void xpd_remove(xpd_t *xpd);
-+void fill_beep(u_char *buf, int duration);
-+void xpp_tick(unsigned long param);
-+int xpp_open(struct zt_chan *chan);
-+int xpp_close(struct zt_chan *chan);
-+int xpp_ioctl(struct zt_chan *chan, unsigned int cmd, unsigned long arg);
-+int xpp_maint(struct zt_span *span, int cmd);
-+
-+#define CARD_DESC_MAGIC 0xca9dde5c
-+
-+struct card_desc_struct {
-+ struct work_struct work;
-+ u32 magic;
-+ xbus_t *xbus;
-+ byte rev; /* Revision number */
-+ byte type; /* LSB: 1 - to_phone, 0 - to_line */
-+ byte xpd_num;
-+};
-+extern struct workqueue_struct *xpp_worker;
-+
-+#ifdef CONFIG_PROC_FS
-+#include <linux/proc_fs.h>
-+
-+extern struct proc_dir_entry *xpp_procdir;
-+#endif
-+extern xpd_t *sync_master;
-+
-+// Number of rings our simulated phone will ring:
-+#define RINGS_NUM 3
-+
-+#endif /* XPP_ZAP_H */
-diff -urNad zaptel-1.0.10/xpp/xproto.c /tmp/dpep.absTwN/zaptel-1.0.10/xpp/xproto.c
---- zaptel-1.0.10/xpp/xproto.c 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.absTwN/zaptel-1.0.10/xpp/xproto.c 2006-01-11 10:12:52.000000000 +0200
-@@ -0,0 +1,334 @@
-+/*
-+ * Written by Oron Peled <oron at actcom.co.il>
-+ * Copyright (C) 2004-2005, Xorcom
-+ *
-+ * All rights reserved.
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License as published by
-+ * the Free Software Foundation; either version 2 of the License, or
-+ * (at your option) any later version.
-+ *
-+ * This program is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ * GNU General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-+ *
-+ */
-+
-+#include "xpd.h"
-+#include "xproto.h"
-+#include "xpp_zap.h"
-+#include <linux/module.h>
-+
-+static const char rcsid[] = "$Id: xproto.c 184 2006-01-10 11:22:14Z oron $";
-+
-+extern int print_dbg;
-+static int packet_process(xbus_t *xbus, int xpd_num, xpacket_t *pack);
-+
-+static const xproto_table_t *xprotocol_tables[XPD_TYPE_NOMODULE];
-+
-+bool valid_xpd_addr(const xpd_addr_t *addr)
-+{
-+ return ((addr->bank_num & ~0x1) == 0) && ((addr->card_id & ~0x3) == 0);
-+}
-+
-+int xpd_addr2num(const xpd_addr_t *addr)
-+{
-+ BUG_ON(!valid_xpd_addr(addr));
-+ return addr->bank_num * 4 + addr->card_id;
-+}
-+
-+void xpd_set_addr(xpd_addr_t *addr, int xpd_num)
-+{
-+ if(xpd_num < 4) {
-+ addr->card_id = xpd_num;
-+ addr->bank_num = 0;
-+ } else {
-+ addr->card_id = xpd_num % 4;
-+ addr->bank_num = xpd_num / 4;
-+ }
-+}
-+
-+
-+/*---------------- General Protocol Management ----------------------------*/
-+
-+const xproto_entry_t *xproto_card_entry(const xproto_table_t *table, byte opcode)
-+{
-+ const xproto_entry_t *xe;
-+
-+ //DBG("\n");
-+ xe = &table->entries[opcode];
-+ return (xe->handler != NULL) ? xe : NULL;
-+}
-+
-+const xproto_entry_t *xproto_global_entry(byte opcode)
-+{
-+ const xproto_entry_t *xe;
-+
-+ xe = xproto_card_entry(&PROTO_TABLE(GLOBAL), opcode);
-+ //DBG("opcode=0x%X xe=%p\n", opcode, xe);
-+ return xe;
-+}
-+
-+const xproto_handler_t xproto_global_handler(byte opcode)
-+{
-+ return xproto_card_handler(&PROTO_TABLE(GLOBAL), opcode);
-+}
-+
-+const xproto_table_t *xproto_table(xpd_type_t cardtype)
-+{
-+ if(cardtype >= XPD_TYPE_NOMODULE)
-+ return NULL;
-+ return xprotocol_tables[cardtype];
-+}
-+
-+const xproto_table_t *get_xproto_table(xpd_type_t cardtype)
-+{
-+ const xproto_table_t *xtable;
-+
-+ if(cardtype >= XPD_TYPE_NOMODULE)
-+ return NULL;
-+ xtable = xprotocol_tables[cardtype];
-+ if(!xtable) { /* Try to load the relevant module */
-+ int ret = request_module("xpd-type-%d", cardtype);
-+ if(ret != 0) {
-+ NOTICE("%s: Failed to load module for type=%d. exit status=%d.\n",
-+ __FUNCTION__, cardtype, ret);
-+ /* Drop through: we may be luck... */
-+ }
-+ xtable = xprotocol_tables[cardtype];
-+ }
-+ return xtable;
-+}
-+
-+const xproto_handler_t xproto_card_handler(const xproto_table_t *table, byte opcode)
-+{
-+ const xproto_entry_t *xe;
-+
-+ //DBG("\n");
-+ xe = xproto_card_entry(table, opcode);
-+ return xe->handler;
-+}
-+
-+const xproto_entry_t *find_xproto_entry(xpd_t *xpd, byte opcode)
-+{
-+ const xproto_entry_t *xe;
-+
-+ xe = xproto_global_entry(opcode);
-+ // DBG("opcode=0x%X xe=%p\n", opcode, xe);
-+ if(!xe) {
-+ const xproto_table_t *xtable;
-+
-+ if(!xpd)
-+ return NULL;
-+ xtable = xproto_table(xpd->type);
-+ if(!xtable)
-+ return NULL;
-+ xe = xproto_card_entry(xtable, opcode);
-+ if(!xe)
-+ return NULL;
-+ }
-+ return xe;
-+}
-+
-+const xops_t *get_xops(xpd_type_t xpd_type)
-+{
-+ const xproto_table_t *proto_table;
-+
-+ if(xpd_type >= XPD_TYPE_NOMODULE)
-+ return NULL;
-+ proto_table = xprotocol_tables[xpd_type];
-+ if(!proto_table)
-+ return NULL;
-+ return &proto_table->xops;
-+}
-+
-+int packet_receive(xbus_t *xbus, xpacket_t *pack)
-+{
-+ int xpd_num;
-+
-+ if(!valid_xpd_addr(&pack->content.addr)) {
-+ static int rate_limit = 0;
-+
-+ if((rate_limit++ % 5003) < 3)
-+ dump_packet("bad address", pack, print_dbg);
-+ xbus->ops->packet_free(xbus, pack);
-+ return -EPROTO;
-+ }
-+ xpd_num = XPD_NUM(pack->content.addr);
-+#if SOFT_SIMULATOR
-+ if(xbus->sim[xpd_num].simulated) {
-+ //dump_packet("packet_receive -> simulate", pack, print_dbg);
-+ return simulate_xpd(xbus, xpd_num, pack);
-+ } else
-+#endif
-+ {
-+ //dump_packet("packet_receive -> process", pack, print_dbg);
-+ return packet_process(xbus, xpd_num, pack);
-+ }
-+}
-+
-+static int packet_process(xbus_t *xbus, int xpd_num, xpacket_t *pack)
-+{
-+ byte op;
-+ const xproto_entry_t *xe;
-+ xproto_handler_t handler;
-+ xproto_table_t *table;
-+ xpd_t *xpd;
-+ int ret = 0;
-+
-+ BUG_ON(!pack);
-+ op = pack->content.opcode;
-+ xpd_num = XPD_NUM(pack->content.addr);
-+ xpd = xpd_of(xbus, xpd_num);
-+ xe = find_xproto_entry(xpd, op);
-+ /*-------- Validations -----------*/
-+ if(!xe) {
-+ ERR("xpp: %s -- bad command op=0x%02X\n", __FUNCTION__, op);
-+ dump_packet("packet_process -- bad command", pack, print_dbg);
-+ ret = -EPROTO;
-+ goto out;
-+ }
-+ table = xe->table;
-+ BUG_ON(!table);
-+ if(!table->packet_is_valid(pack)) {
-+ ERR("xpp: %s: wrong size %d for op=0x%02X\n",
-+ __FUNCTION__, pack->datalen, op);
-+ dump_packet("packet_process -- wrong size", pack, print_dbg);
-+ ret = -EPROTO;
-+ goto out;
-+ }
-+ handler = xe->handler;
-+ BUG_ON(!handler);
-+ XBUS_COUNTER(xbus, RX_BYTES) += pack->datalen;
-+ handler(xbus, xpd, xe, pack);
-+out:
-+ xbus->ops->packet_free(xbus, pack);
-+ return ret;
-+}
-+
-+#define VERBOSE_DEBUG 1
-+#define ERR_REPORT_LIMIT 20
-+
-+void dump_packet(const char *msg, xpacket_t *packet, bool print_dbg)
-+{
-+ byte op = packet->content.opcode;
-+
-+ if(!print_dbg)
-+ return;
-+ DBG("%s: @0x%1X%1X OP=0x%02X LEN=%d\n",
-+ msg,
-+ packet->content.addr.bank_num,
-+ packet->content.addr.card_id,
-+ op,
-+ (byte)packet->datalen);
-+#if VERBOSE_DEBUG
-+ {
-+ int i;
-+ byte *p = packet->content.data;
-+
-+ for(i = 0; i < packet->datalen; i++) {
-+ static int limiter = 0;
-+
-+ if(i >= sizeof(xpacket_raw_t)) {
-+ if(limiter < ERR_REPORT_LIMIT) {
-+ ERR("%s: length overflow i=%d > sizeof(xpacket_raw_t)=%d\n",
-+ __FUNCTION__, i+1, sizeof(xpacket_raw_t));
-+ } else if(limiter == ERR_REPORT_LIMIT) {
-+ ERR("%s: error packet #%d... squelsh reports.\n",
-+ __FUNCTION__, limiter);
-+ }
-+ limiter++;
-+ break;
-+ }
-+ DBG(" %2d> %02X\n", i+1, p[i]);
-+ }
-+ }
-+#endif
-+}
-+
-+const char *xproto_name(xpd_type_t xpd_type)
-+{
-+ const xproto_table_t *proto_table;
-+
-+ BUG_ON(xpd_type >= XPD_TYPE(NOMODULE));
-+ proto_table = xprotocol_tables[xpd_type];
-+ if(!proto_table)
-+ return NULL;
-+ return proto_table->name;
-+}
-+
-+#define CHECK_XOP(f) \
-+ if(!(xops)->f) { \
-+ ERR("%s: missing xmethod %s [%s (%d)]\n", __FUNCTION__, #f, name, type); \
-+ return -EINVAL; \
-+ }
-+
-+int xproto_register(const xproto_table_t *proto_table)
-+{
-+ int type;
-+ const char *name;
-+ const xops_t *xops;
-+
-+ BUG_ON(!proto_table);
-+ type = proto_table->type;
-+ name = proto_table->name;
-+ if(type >= XPD_TYPE(NOMODULE)) {
-+ NOTICE("%s: Bad xproto type %d\n", __FUNCTION__, type);
-+ return -EINVAL;
-+ }
-+ DBG("%s (%d)\n", name, type);
-+ if(xprotocol_tables[type])
-+ NOTICE("%s: overriding registration of %s (%d)\n", __FUNCTION__, name, type);
-+ xops = &proto_table->xops;
-+ CHECK_XOP(card_new);
-+ CHECK_XOP(card_init);
-+ CHECK_XOP(card_remove);
-+ CHECK_XOP(card_tick);
-+ CHECK_XOP(SYNC_SOURCE);
-+ CHECK_XOP(PCM_WRITE);
-+ CHECK_XOP(CHAN_ENABLE);
-+ CHECK_XOP(CHAN_POWER);
-+ CHECK_XOP(CHAN_CID);
-+ CHECK_XOP(RING);
-+ CHECK_XOP(SETHOOK);
-+ CHECK_XOP(LED);
-+ CHECK_XOP(RELAY_OUT);
-+
-+ xprotocol_tables[type] = proto_table;
-+ return 0;
-+}
-+
-+void xproto_unregister(const xproto_table_t *proto_table)
-+{
-+ int type;
-+ const char *name;
-+
-+ BUG_ON(!proto_table);
-+ type = proto_table->type;
-+ name = proto_table->name;
-+ DBG("%s (%d)\n", name, type);
-+ if(type >= XPD_TYPE(NOMODULE)) {
-+ NOTICE("%s: Bad xproto type %s (%d)\n", __FUNCTION__, name, type);
-+ return;
-+ }
-+ if(!xprotocol_tables[type])
-+ NOTICE("%s: xproto type %s (%d) is already unregistered\n", __FUNCTION__, name, type);
-+ xprotocol_tables[type] = NULL;
-+}
-+
-+EXPORT_SYMBOL(dump_packet);
-+EXPORT_SYMBOL(packet_receive);
-+EXPORT_SYMBOL(valid_xpd_addr);
-+EXPORT_SYMBOL(xpd_addr2num);
-+EXPORT_SYMBOL(xpd_set_addr);
-+EXPORT_SYMBOL(xproto_global_entry);
-+EXPORT_SYMBOL(xproto_card_entry);
-+EXPORT_SYMBOL(xproto_name);
-+EXPORT_SYMBOL(xproto_register);
-+EXPORT_SYMBOL(xproto_unregister);
-diff -urNad zaptel-1.0.10/xpp/xproto.h /tmp/dpep.absTwN/zaptel-1.0.10/xpp/xproto.h
---- zaptel-1.0.10/xpp/xproto.h 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.absTwN/zaptel-1.0.10/xpp/xproto.h 2006-01-09 18:14:37.000000000 +0200
-@@ -0,0 +1,239 @@
-+#ifndef XPROTO_H
-+#define XPROTO_H
-+/*
-+ * Written by Oron Peled <oron at actcom.co.il>
-+ * Copyright (C) 2004-2005, Xorcom
-+ *
-+ * All rights reserved.
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License as published by
-+ * the Free Software Foundation; either version 2 of the License, or
-+ * (at your option) any later version.
-+ *
-+ * This program is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ * GNU General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-+ *
-+ */
-+
-+#include "xdefs.h"
-+
-+#ifdef __KERNEL__
-+#include <linux/list.h>
-+#endif
-+
-+#define XPD_TYPE(n) XPD_TYPE_ ## n
-+#define PROTO_TABLE(n) n ## _protocol_table
-+
-+typedef enum xpd_type {
-+ XPD_TYPE(FXO) = 0x02,
-+ XPD_TYPE(FXS) = 0x03,
-+ XPD_TYPE(NOMODULE) = 0x0F,
-+} xpd_type_t;
-+
-+#define LINE_BITS (sizeof(xpp_line_t)*8)
-+#define PCM_CHUNKSIZE (CHANNELS_PERXPD * 8) /* samples of 8 bytes */
-+
-+typedef struct xpd_addr {
-+ byte card_id:4;
-+ byte bank_num:4;
-+} __attribute__((packed)) xpd_addr_t;
-+
-+bool valid_xpd_addr(const xpd_addr_t *addr);
-+int xpd_addr2num(const xpd_addr_t *addr);
-+void xpd_set_addr(xpd_addr_t *addr, int xpd_num);
-+
-+#define XPD_NUM(x) xpd_addr2num(&x)
-+#define XPD_ADDR_SET(x,val) xpd_set_addr(&x, val)
-+#define MAX_XPACKET_DATALEN 100
-+
-+#define XPROTO_NAME(card,op) card ## _ ## op
-+#define XPROTO_HANDLER(card,op) XPROTO_NAME(card,op ## _handler)
-+#define XPROTO_CALLER(card,op) XPROTO_NAME(card,op ## _send)
-+
-+#define HANDLER_DEF(card,op) \
-+ int XPROTO_HANDLER(card,op) ( \
-+ xbus_t *xbus, \
-+ xpd_t *xpd, \
-+ const xproto_entry_t *cmd, \
-+ xpacket_t *pack)
-+
-+#define CALL_PROTO(card,op, ...) XPROTO_CALLER(card,op)( __VA_ARGS__ )
-+
-+#define DECLARE_CMD(card,op, ...) \
-+ int CALL_PROTO(card, op, xbus_t *xbus, xpd_t *xpd, ## __VA_ARGS__ )
-+
-+#define HOSTCMD(card, op, ...) \
-+ DECLARE_CMD(card, op, ## __VA_ARGS__ ); \
-+ EXPORT_SYMBOL(XPROTO_CALLER(card, op)); \
-+ DECLARE_CMD(card, op, ## __VA_ARGS__ )
-+
-+#define RPACKET_NAME(card,op) XPROTO_NAME(RPACKET_ ## card, op)
-+#define RPACKET_TYPE(card,op) struct RPACKET_NAME(card, op)
-+
-+#define DEF_RPACKET_DATA(card,op, ...) \
-+ struct RPACKET_NAME(card,op) { \
-+ byte opcode; \
-+ xpd_addr_t addr; \
-+ __VA_ARGS__ \
-+ } __attribute__((packed))
-+
-+#define RPACKET_CAST(p,card,op) ((RPACKET_TYPE(card,op) *)p)
-+#define RPACKET_FIELD(p,card,op,field) (RPACKET_CAST(p,card,op)->field)
-+#define RPACKET_SIZE(card,op) sizeof(RPACKET_TYPE(card,op))
-+
-+#define PACKET_LEN(p) \
-+ ((p)->datalen + sizeof(xpd_addr_t) + 1)
-+
-+#define XENTRY(card,op) \
-+ [ XPROTO_NAME(card,op) ] { \
-+ .handler = XPROTO_HANDLER(card,op), \
-+ .datalen = RPACKET_SIZE(card,op), \
-+ .name = #op, \
-+ .table = &PROTO_TABLE(card) \
-+ }
-+
-+
-+#define XPACKET_INIT(p, card, op) \
-+ do { \
-+ p->content.opcode = XPROTO_NAME(card,op); \
-+ p->datalen = RPACKET_SIZE(card,op); \
-+ } while(0)
-+
-+#define XPACKET_NEW(p, xbus, card, op, to) \
-+ do { \
-+ p = xbus->ops->packet_new(xbus, GFP_ATOMIC); \
-+ if(!p) \
-+ return -ENOMEM; \
-+ XPACKET_INIT(p, card, op); \
-+ XPD_ADDR_SET(p->content.addr, to); \
-+ } while(0);
-+
-+typedef struct xproto_entry xproto_entry_t;
-+typedef struct xproto_table xproto_table_t;
-+
-+typedef int (*xproto_handler_t)(
-+ xbus_t *xbus,
-+ xpd_t *xpd,
-+ const xproto_entry_t *cmd,
-+ xpacket_t *pack);
-+
-+const xproto_entry_t *find_xproto_entry(xpd_t *xpd, byte opcode);
-+
-+const xproto_table_t *get_xproto_table(xpd_type_t cardtype);
-+const xproto_entry_t *xproto_card_entry(const xproto_table_t *table, byte opcode);
-+const xproto_handler_t xproto_card_handler(const xproto_table_t *table, byte opcode);
-+
-+const xproto_entry_t *xproto_global_entry(byte opcode);
-+const xproto_handler_t xproto_global_handler(byte opcode);
-+
-+#define CALL_XMETHOD(name, xbus, xpd, ...) \
-+ (xpd)->xops->name(xbus, xpd, ## __VA_ARGS__ )
-+
-+struct xops {
-+ xpd_t *(*card_new)(xbus_t *xbus, int xpd_num, const xproto_table_t *proto_table, byte revision);
-+ int (*card_init)(xbus_t *xbus, xpd_t *xpd);
-+ int (*card_remove)(xbus_t *xbus, xpd_t *xpd);
-+ int (*card_tick)(xbus_t *xbus, xpd_t *xpd);
-+
-+ int (*SYNC_SOURCE)(xbus_t *xbus, xpd_t *xpd, bool setit, bool is_master);
-+ int (*PCM_WRITE)(xbus_t *xbus, xpd_t *xpd, xpp_line_t hookstate, volatile byte *buf);
-+
-+ int (*CHAN_ENABLE)(xbus_t *xbus, xpd_t *xpd, xpp_line_t lines, bool on);
-+ int (*CHAN_POWER)(xbus_t *xbus, xpd_t *xpd, xpp_line_t lines, bool on);
-+ int (*CHAN_CID)(xbus_t *xbus, xpd_t *xpd, xpp_line_t lines);
-+ int (*RING)(xbus_t *xbus, xpd_t *xpd, int pos, bool on);
-+ int (*SETHOOK)(xbus_t *xbus, xpd_t *xpd, xpp_line_t hook_status);
-+ int (*LED)(xbus_t *xbus, xpd_t *xpd, xpp_line_t lines, byte which, bool on);
-+ int (*RELAY_OUT)(xbus_t *xbus, xpd_t *xpd, byte which, bool on);
-+};
-+
-+const xops_t *get_xops(xpd_type_t xpd_type);
-+
-+#undef XMETHOD
-+
-+struct xproto_entry {
-+ xproto_handler_t handler;
-+ int datalen;
-+ const char *name;
-+ xproto_table_t *table;
-+};
-+
-+struct xproto_table {
-+ xproto_entry_t entries[255]; /* Indexed by opcode */
-+ xops_t xops;
-+ xpd_type_t type;
-+ const char *name;
-+ bool (*packet_is_valid)(xpacket_t *pack);
-+ void (*packet_dump)(xpacket_t *pack);
-+};
-+
-+#include "card_global.h"
-+#include "card_fxs.h"
-+
-+enum opcodes {
-+ XPROTO_NAME(GLOBAL, DESC_REQ) = 0x04,
-+ XPROTO_NAME(GLOBAL, DEV_DESC) = 0x05,
-+/**/
-+ XPROTO_NAME(GLOBAL, PCM_WRITE) = 0x11,
-+ XPROTO_NAME(GLOBAL, PCM_READ) = 0x12,
-+/**/
-+ XPROTO_NAME(GLOBAL, SYNC_SOURCE) = 0x19,
-+ XPROTO_NAME(GLOBAL, SYNC_REPLY) = 0x1A,
-+
-+ XPROTO_NAME(FXS, SIG_CHANGED) = 0x06,
-+/**/
-+ XPROTO_NAME(FXS, SLIC_WRITE) = 0x0F, /* Write to SLIC */
-+ XPROTO_NAME(FXS, CHAN_ENABLE) = 0x0F, /* Write to SLIC */
-+ XPROTO_NAME(FXS, CHAN_POWER) = 0x0F, /* Write to SLIC */
-+ XPROTO_NAME(FXS, CHAN_CID) = 0x0F, /* Write to SLIC */
-+ XPROTO_NAME(FXS, RING) = 0x0F, /* Write to SLIC */
-+ XPROTO_NAME(FXS, SETHOOK) = 0x0F, /* Write to SLIC */
-+ XPROTO_NAME(FXS, LED) = 0x0F, /* Write to SLIC */
-+ XPROTO_NAME(FXS, RELAY_OUT) = 0x0F, /* Write to SLIC */
-+ XPROTO_NAME(FXS, SLIC_INIT) = 0x0F, /* Write to SLIC */
-+ XPROTO_NAME(FXS, SLIC_QUERY) = 0x0F, /* Write to SLIC */
-+/**/
-+ XPROTO_NAME(FXS, SLIC_REPLY) = 0x10,
-+};
-+
-+
-+#define MEMBER(card,op) RPACKET_TYPE(card,op) RPACKET_NAME(card,op)
-+
-+struct xpacket_raw {
-+ byte opcode;
-+ xpd_addr_t addr;
-+ union {
-+ MEMBER(GLOBAL, DESC_REQ);
-+ MEMBER(GLOBAL, DEV_DESC);
-+ MEMBER(GLOBAL, PCM_WRITE);
-+ MEMBER(GLOBAL, PCM_READ);
-+ MEMBER(GLOBAL, SYNC_REPLY);
-+
-+ MEMBER(FXS, SIG_CHANGED);
-+ MEMBER(FXS, SLIC_REPLY);
-+
-+ byte data[0];
-+ };
-+} __attribute__((packed));
-+
-+struct xpacket {
-+ xpacket_raw_t content;
-+ size_t datalen;
-+ struct list_head list;
-+};
-+
-+void dump_packet(const char *msg, xpacket_t *packet, bool print_dbg);
-+int packet_receive(xbus_t *xbus, xpacket_t *pack);
-+int xproto_register(const xproto_table_t *proto_table);
-+void xproto_unregister(const xproto_table_t *proto_table);
-+const xproto_entry_t *xproto_global_entry(byte opcode);
-+const char *xproto_name(xpd_type_t xpd_type);
-+
-+#endif /* XPROTO_H */
-diff -urNad zaptel-1.0.10/xpp/zap_debug.c /tmp/dpep.absTwN/zaptel-1.0.10/xpp/zap_debug.c
---- zaptel-1.0.10/xpp/zap_debug.c 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.absTwN/zaptel-1.0.10/xpp/zap_debug.c 2006-01-09 18:14:37.000000000 +0200
-@@ -0,0 +1,136 @@
-+/*
-+ * Written by Oron Peled <oron at actcom.co.il>
-+ * Copyright (C) 2004-2005, Xorcom
-+ *
-+ * All rights reserved.
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License as published by
-+ * the Free Software Foundation; either version 2 of the License, or
-+ * (at your option) any later version.
-+ *
-+ * This program is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ * GNU General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-+ *
-+ */
-+#include <linux/version.h>
-+
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+# warning "This module is tested only with 2.6 kernels"
-+#endif
-+
-+#include <linux/kernel.h>
-+#include <linux/errno.h>
-+#include <linux/module.h>
-+#include <zaptel.h>
-+#include "zap_debug.h"
-+
-+static const char rcsid[] = "$Id: zap_debug.c 161 2006-01-03 09:13:40Z oron $";
-+
-+#define P_(x) [ x ] = { .value = x, .name = #x, }
-+static struct {
-+ int value;
-+ char *name;
-+} poll_names[] = {
-+ P_(POLLIN),
-+ P_(POLLPRI),
-+ P_(POLLOUT),
-+ P_(POLLERR),
-+ P_(POLLHUP),
-+ P_(POLLNVAL),
-+ P_(POLLRDNORM),
-+ P_(POLLRDBAND),
-+ P_(POLLWRNORM),
-+ P_(POLLWRBAND),
-+ P_(POLLMSG),
-+ P_(POLLREMOVE)
-+};
-+#undef P_
-+
-+void dump_poll(int print_dbg, const char *msg, int poll)
-+{
-+ int i;
-+
-+ for(i = 0; i < ARRAY_SIZE(poll_names); i++) {
-+ if(poll & poll_names[i].value)
-+ DBG("%s: %s\n", msg, poll_names[i].name);
-+ }
-+}
-+
-+#define E_(x) [ x ] = { .value = x, .name = #x, }
-+static struct {
-+ int value;
-+ char *name;
-+} zt_event_names[] = {
-+ E_(ZT_EVENT_NONE),
-+ E_(ZT_EVENT_ONHOOK),
-+ E_(ZT_EVENT_RINGOFFHOOK),
-+ E_(ZT_EVENT_WINKFLASH),
-+ E_(ZT_EVENT_ALARM),
-+ E_(ZT_EVENT_NOALARM),
-+ E_(ZT_EVENT_ABORT),
-+ E_(ZT_EVENT_OVERRUN),
-+ E_(ZT_EVENT_BADFCS),
-+ E_(ZT_EVENT_DIALCOMPLETE),
-+ E_(ZT_EVENT_RINGERON),
-+ E_(ZT_EVENT_RINGEROFF),
-+ E_(ZT_EVENT_HOOKCOMPLETE),
-+ E_(ZT_EVENT_BITSCHANGED),
-+ E_(ZT_EVENT_PULSE_START),
-+ E_(ZT_EVENT_TIMER_EXPIRED),
-+ E_(ZT_EVENT_TIMER_PING),
-+ E_(ZT_EVENT_POLARITY)
-+};
-+#undef E_
-+
-+char *event2str(int event)
-+{
-+ BUG_ON(event > ARRAY_SIZE(zt_event_names));
-+ return zt_event_names[event].name;
-+}
-+
-+#define S_(x) [ x ] = { .value = x, .name = #x, }
-+static struct {
-+ int value;
-+ char *name;
-+} zt_sig_types[] = {
-+ S_(ZT_SIG_NONE),
-+ S_(ZT_SIG_FXSLS),
-+ S_(ZT_SIG_FXSGS),
-+ S_(ZT_SIG_FXSKS),
-+ S_(ZT_SIG_FXOLS),
-+ S_(ZT_SIG_FXOGS),
-+ S_(ZT_SIG_FXOKS),
-+ S_(ZT_SIG_EM),
-+ S_(ZT_SIG_CLEAR),
-+ S_(ZT_SIG_HDLCRAW),
-+ S_(ZT_SIG_HDLCFCS),
-+ S_(ZT_SIG_HDLCNET),
-+ S_(ZT_SIG_SLAVE),
-+ S_(ZT_SIG_SF),
-+ S_(ZT_SIG_CAS),
-+ S_(ZT_SIG_DACS),
-+ S_(ZT_SIG_EM_E1),
-+ S_(ZT_SIG_DACS_RBS)
-+};
-+#undef S_
-+
-+void dump_sigtype(int print_dbg, const char *msg, int sigtype)
-+{
-+ int i;
-+
-+ for(i = 0; i < ARRAY_SIZE(zt_sig_types); i++) {
-+ if(sigtype == zt_sig_types[i].value)
-+ DBG("%s: %s\n", msg, zt_sig_types[i].name);
-+ }
-+}
-+
-+EXPORT_SYMBOL(dump_poll);
-+EXPORT_SYMBOL(event2str);
-+EXPORT_SYMBOL(dump_sigtype);
-diff -urNad zaptel-1.0.10/xpp/zap_debug.h /tmp/dpep.absTwN/zaptel-1.0.10/xpp/zap_debug.h
---- zaptel-1.0.10/xpp/zap_debug.h 1970-01-01 02:00:00.000000000 +0200
-+++ /tmp/dpep.absTwN/zaptel-1.0.10/xpp/zap_debug.h 2006-01-09 18:14:37.000000000 +0200
-@@ -0,0 +1,16 @@
-+#ifndef ZAP_DEBUG_H
-+#define ZAP_DEBUG_H
-+
-+#define DBG(fmt, ...) \
-+ ((print_dbg) && printk(KERN_DEBUG "DBG-%s: %s: " fmt, \
-+ THIS_MODULE->name, __FUNCTION__, ## __VA_ARGS__))
-+#define INFO(fmt, ...) printk(KERN_INFO "INFO-%s: " fmt, THIS_MODULE->name, ## __VA_ARGS__)
-+#define NOTICE(fmt, ...) printk(KERN_NOTICE "NOTICE-%s: " fmt, THIS_MODULE->name, ## __VA_ARGS__)
-+#define ERR(fmt, ...) printk(KERN_ERR "ERR-%s: " fmt, THIS_MODULE->name, ## __VA_ARGS__)
-+
-+
-+void dump_poll(int print_dbg, const char *msg, int poll);
-+char *event2str(int event);
-+void dump_sigtype(int print_dbg, const char *msg, int sigtype);
-+
-+#endif /* ZAP_DEBUG_H */
Modified: zaptel/trunk/debian/patches/xpp_fixes.dpatch
===================================================================
--- zaptel/trunk/debian/patches/xpp_fixes.dpatch 2006-04-30 15:19:14 UTC (rev 1655)
+++ zaptel/trunk/debian/patches/xpp_fixes.dpatch 2006-04-30 16:30:35 UTC (rev 1656)
@@ -3,6 +3,7 @@
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: No description.
+## -- already in 1.2 branch
@DPATCH@
diff -urNad zaptel-1.2.5/xpp/xpp_usb.c /tmp/dpep.f30gdf/zaptel-1.2.5/xpp/xpp_usb.c
Deleted: zaptel/trunk/debian/patches/zaphfc_0.2.0-RC8n_florz-8.dpatch
===================================================================
--- zaptel/trunk/debian/patches/zaphfc_0.2.0-RC8n_florz-8.dpatch 2006-04-30 15:19:14 UTC (rev 1655)
+++ zaptel/trunk/debian/patches/zaphfc_0.2.0-RC8n_florz-8.dpatch 2006-04-30 16:30:35 UTC (rev 1656)
@@ -1,1809 +0,0 @@
-#! /bin/sh /usr/share/dpatch/dpatch-run
-## zaphfc-florz.dpatch by Kilian Krause <kilian at debian.org>
-##
-## All lines beginning with `## DP:' are a description of the patch.
-## DP: Add florz' zaphfc code as alternative. Should need less IO.
-
- at DPATCH@
-diff -urNad --exclude=CVS --exclude=.svn ./zaphfc-florz/LICENSE /tmp/dpep-work.8uAAbh/zaptel-1.0.9.1/zaphfc-florz/LICENSE
---- ./zaphfc-florz/LICENSE 1970-01-01 01:00:00.000000000 +0100
-+++ /tmp/dpep-work.8uAAbh/zaptel-1.0.9.1/zaphfc-florz/LICENSE 2005-08-27 23:17:30.000000000 +0200
-@@ -0,0 +1,341 @@
-+
-+ GNU GENERAL PUBLIC LICENSE
-+ Version 2, June 1991
-+
-+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-+ Everyone is permitted to copy and distribute verbatim copies
-+ of this license document, but changing it is not allowed.
-+
-+ Preamble
-+
-+ The licenses for most software are designed to take away your
-+freedom to share and change it. By contrast, the GNU General Public
-+License is intended to guarantee your freedom to share and change free
-+software--to make sure the software is free for all its users. This
-+General Public License applies to most of the Free Software
-+Foundation's software and to any other program whose authors commit to
-+using it. (Some other Free Software Foundation software is covered by
-+the GNU Library General Public License instead.) You can apply it to
-+your programs, too.
-+
-+ When we speak of free software, we are referring to freedom, not
-+price. Our General Public Licenses are designed to make sure that you
-+have the freedom to distribute copies of free software (and charge for
-+this service if you wish), that you receive source code or can get it
-+if you want it, that you can change the software or use pieces of it
-+in new free programs; and that you know you can do these things.
-+
-+ To protect your rights, we need to make restrictions that forbid
-+anyone to deny you these rights or to ask you to surrender the rights.
-+These restrictions translate to certain responsibilities for you if you
-+distribute copies of the software, or if you modify it.
-+
-+ For example, if you distribute copies of such a program, whether
-+gratis or for a fee, you must give the recipients all the rights that
-+you have. You must make sure that they, too, receive or can get the
-+source code. And you must show them these terms so they know their
-+rights.
-+
-+ We protect your rights with two steps: (1) copyright the software, and
-+(2) offer you this license which gives you legal permission to copy,
-+distribute and/or modify the software.
-+
-+ Also, for each author's protection and ours, we want to make certain
-+that everyone understands that there is no warranty for this free
-+software. If the software is modified by someone else and passed on, we
-+want its recipients to know that what they have is not the original, so
-+that any problems introduced by others will not reflect on the original
-+authors' reputations.
-+
-+ Finally, any free program is threatened constantly by software
-+patents. We wish to avoid the danger that redistributors of a free
-+program will individually obtain patent licenses, in effect making the
-+program proprietary. To prevent this, we have made it clear that any
-+patent must be licensed for everyone's free use or not licensed at all.
-+
-+ The precise terms and conditions for copying, distribution and
-+modification follow.
-+
-+ GNU GENERAL PUBLIC LICENSE
-+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-+
-+ 0. This License applies to any program or other work which contains
-+a notice placed by the copyright holder saying it may be distributed
-+under the terms of this General Public License. The "Program", below,
-+refers to any such program or work, and a "work based on the Program"
-+means either the Program or any derivative work under copyright law:
-+that is to say, a work containing the Program or a portion of it,
-+either verbatim or with modifications and/or translated into another
-+language. (Hereinafter, translation is included without limitation in
-+the term "modification".) Each licensee is addressed as "you".
-+
-+Activities other than copying, distribution and modification are not
-+covered by this License; they are outside its scope. The act of
-+running the Program is not restricted, and the output from the Program
-+is covered only if its contents constitute a work based on the
-+Program (independent of having been made by running the Program).
-+Whether that is true depends on what the Program does.
-+
-+ 1. You may copy and distribute verbatim copies of the Program's
-+source code as you receive it, in any medium, provided that you
-+conspicuously and appropriately publish on each copy an appropriate
-+copyright notice and disclaimer of warranty; keep intact all the
-+notices that refer to this License and to the absence of any warranty;
-+and give any other recipients of the Program a copy of this License
-+along with the Program.
-+
-+You may charge a fee for the physical act of transferring a copy, and
-+you may at your option offer warranty protection in exchange for a fee.
-+
-+ 2. You may modify your copy or copies of the Program or any portion
-+of it, thus forming a work based on the Program, and copy and
-+distribute such modifications or work under the terms of Section 1
-+above, provided that you also meet all of these conditions:
-+
-+ a) You must cause the modified files to carry prominent notices
-+ stating that you changed the files and the date of any change.
-+
-+ b) You must cause any work that you distribute or publish, that in
-+ whole or in part contains or is derived from the Program or any
-+ part thereof, to be licensed as a whole at no charge to all third
-+ parties under the terms of this License.
-+
-+ c) If the modified program normally reads commands interactively
-+ when run, you must cause it, when started running for such
-+ interactive use in the most ordinary way, to print or display an
-+ announcement including an appropriate copyright notice and a
-+ notice that there is no warranty (or else, saying that you provide
-+ a warranty) and that users may redistribute the program under
-+ these conditions, and telling the user how to view a copy of this
-+ License. (Exception: if the Program itself is interactive but
-+ does not normally print such an announcement, your work based on
-+ the Program is not required to print an announcement.)
-+
-+These requirements apply to the modified work as a whole. If
-+identifiable sections of that work are not derived from the Program,
-+and can be reasonably considered independent and separate works in
-+themselves, then this License, and its terms, do not apply to those
-+sections when you distribute them as separate works. But when you
-+distribute the same sections as part of a whole which is a work based
-+on the Program, the distribution of the whole must be on the terms of
-+this License, whose permissions for other licensees extend to the
-+entire whole, and thus to each and every part regardless of who wrote it.
-+
-+Thus, it is not the intent of this section to claim rights or contest
-+your rights to work written entirely by you; rather, the intent is to
-+exercise the right to control the distribution of derivative or
-+collective works based on the Program.
-+
-+In addition, mere aggregation of another work not based on the Program
-+with the Program (or with a work based on the Program) on a volume of
-+a storage or distribution medium does not bring the other work under
-+the scope of this License.
-+
-+ 3. You may copy and distribute the Program (or a work based on it,
-+under Section 2) in object code or executable form under the terms of
-+Sections 1 and 2 above provided that you also do one of the following:
-+
-+ a) Accompany it with the complete corresponding machine-readable
-+ source code, which must be distributed under the terms of Sections
-+ 1 and 2 above on a medium customarily used for software interchange; or,
-+
-+ b) Accompany it with a written offer, valid for at least three
-+ years, to give any third party, for a charge no more than your
-+ cost of physically performing source distribution, a complete
-+ machine-readable copy of the corresponding source code, to be
-+ distributed under the terms of Sections 1 and 2 above on a medium
-+ customarily used for software interchange; or,
-+
-+ c) Accompany it with the information you received as to the offer
-+ to distribute corresponding source code. (This alternative is
-+ allowed only for noncommercial distribution and only if you
-+ received the program in object code or executable form with such
-+ an offer, in accord with Subsection b above.)
-+
-+The source code for a work means the preferred form of the work for
-+making modifications to it. For an executable work, complete source
-+code means all the source code for all modules it contains, plus any
-+associated interface definition files, plus the scripts used to
-+control compilation and installation of the executable. However, as a
-+special exception, the source code distributed need not include
-+anything that is normally distributed (in either source or binary
-+form) with the major components (compiler, kernel, and so on) of the
-+operating system on which the executable runs, unless that component
-+itself accompanies the executable.
-+
-+If distribution of executable or object code is made by offering
-+access to copy from a designated place, then offering equivalent
-+access to copy the source code from the same place counts as
-+distribution of the source code, even though third parties are not
-+compelled to copy the source along with the object code.
-+
-+ 4. You may not copy, modify, sublicense, or distribute the Program
-+except as expressly provided under this License. Any attempt
-+otherwise to copy, modify, sublicense or distribute the Program is
-+void, and will automatically terminate your rights under this License.
-+However, parties who have received copies, or rights, from you under
-+this License will not have their licenses terminated so long as such
-+parties remain in full compliance.
-+
-+ 5. You are not required to accept this License, since you have not
-+signed it. However, nothing else grants you permission to modify or
-+distribute the Program or its derivative works. These actions are
-+prohibited by law if you do not accept this License. Therefore, by
-+modifying or distributing the Program (or any work based on the
-+Program), you indicate your acceptance of this License to do so, and
-+all its terms and conditions for copying, distributing or modifying
-+the Program or works based on it.
-+
-+ 6. Each time you redistribute the Program (or any work based on the
-+Program), the recipient automatically receives a license from the
-+original licensor to copy, distribute or modify the Program subject to
-+these terms and conditions. You may not impose any further
-+restrictions on the recipients' exercise of the rights granted herein.
-+You are not responsible for enforcing compliance by third parties to
-+this License.
-+
-+ 7. If, as a consequence of a court judgment or allegation of patent
-+infringement or for any other reason (not limited to patent issues),
-+conditions are imposed on you (whether by court order, agreement or
-+otherwise) that contradict the conditions of this License, they do not
-+excuse you from the conditions of this License. If you cannot
-+distribute so as to satisfy simultaneously your obligations under this
-+License and any other pertinent obligations, then as a consequence you
-+may not distribute the Program at all. For example, if a patent
-+license would not permit royalty-free redistribution of the Program by
-+all those who receive copies directly or indirectly through you, then
-+the only way you could satisfy both it and this License would be to
-+refrain entirely from distribution of the Program.
-+
-+If any portion of this section is held invalid or unenforceable under
-+any particular circumstance, the balance of the section is intended to
-+apply and the section as a whole is intended to apply in other
-+circumstances.
-+
-+It is not the purpose of this section to induce you to infringe any
-+patents or other property right claims or to contest validity of any
-+such claims; this section has the sole purpose of protecting the
-+integrity of the free software distribution system, which is
-+implemented by public license practices. Many people have made
-+generous contributions to the wide range of software distributed
-+through that system in reliance on consistent application of that
-+system; it is up to the author/donor to decide if he or she is willing
-+to distribute software through any other system and a licensee cannot
-+impose that choice.
-+
-+This section is intended to make thoroughly clear what is believed to
-+be a consequence of the rest of this License.
-+
-+ 8. If the distribution and/or use of the Program is restricted in
-+certain countries either by patents or by copyrighted interfaces, the
-+original copyright holder who places the Program under this License
-+may add an explicit geographical distribution limitation excluding
-+those countries, so that distribution is permitted only in or among
-+countries not thus excluded. In such case, this License incorporates
-+the limitation as if written in the body of this License.
-+
-+ 9. The Free Software Foundation may publish revised and/or new versions
-+of the General Public License from time to time. Such new versions will
-+be similar in spirit to the present version, but may differ in detail to
-+address new problems or concerns.
-+
-+Each version is given a distinguishing version number. If the Program
-+specifies a version number of this License which applies to it and "any
-+later version", you have the option of following the terms and conditions
-+either of that version or of any later version published by the Free
-+Software Foundation. If the Program does not specify a version number of
-+this License, you may choose any version ever published by the Free Software
-+Foundation.
-+
-+ 10. If you wish to incorporate parts of the Program into other free
-+programs whose distribution conditions are different, write to the author
-+to ask for permission. For software which is copyrighted by the Free
-+Software Foundation, write to the Free Software Foundation; we sometimes
-+make exceptions for this. Our decision will be guided by the two goals
-+of preserving the free status of all derivatives of our free software and
-+of promoting the sharing and reuse of software generally.
-+
-+ NO WARRANTY
-+
-+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-+REPAIR OR CORRECTION.
-+
-+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-+POSSIBILITY OF SUCH DAMAGES.
-+
-+ END OF TERMS AND CONDITIONS
-+
-+ How to Apply These Terms to Your New Programs
-+
-+ If you develop a new program, and you want it to be of the greatest
-+possible use to the public, the best way to achieve this is to make it
-+free software which everyone can redistribute and change under these terms.
-+
-+ To do so, attach the following notices to the program. It is safest
-+to attach them to the start of each source file to most effectively
-+convey the exclusion of warranty; and each file should have at least
-+the "copyright" line and a pointer to where the full notice is found.
-+
-+ <one line to give the program's name and a brief idea of what it does.>
-+ Copyright (C) 19yy <name of author>
-+
-+ This program is free software; you can redistribute it and/or modify
-+ it under the terms of the GNU General Public License as published by
-+ the Free Software Foundation; either version 2 of the License, or
-+ (at your option) any later version.
-+
-+ This program is distributed in the hope that it will be useful,
-+ but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ GNU General Public License for more details.
-+
-+ You should have received a copy of the GNU General Public License
-+ along with this program; if not, write to the Free Software
-+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-+
-+
-+Also add information on how to contact you by electronic and paper mail.
-+
-+If the program is interactive, make it output a short notice like this
-+when it starts in an interactive mode:
-+
-+ Gnomovision version 69, Copyright (C) 19yy name of author
-+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-+ This is free software, and you are welcome to redistribute it
-+ under certain conditions; type `show c' for details.
-+
-+The hypothetical commands `show w' and `show c' should show the appropriate
-+parts of the General Public License. Of course, the commands you use may
-+be called something other than `show w' and `show c'; they could even be
-+mouse-clicks or menu items--whatever suits your program.
-+
-+You should also get your employer (if you work as a programmer) or your
-+school, if any, to sign a "copyright disclaimer" for the program, if
-+necessary. Here is a sample; alter the names:
-+
-+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
-+
-+ <signature of Ty Coon>, 1 April 1989
-+ Ty Coon, President of Vice
-+
-+This General Public License does not permit incorporating your program into
-+proprietary programs. If your program is a subroutine library, you may
-+consider it more useful to permit linking proprietary applications with the
-+library. If this is what you want to do, use the GNU Library General
-+Public License instead of this License.
-diff -urNad --exclude=CVS --exclude=.svn ./zaphfc-florz/Makefile /tmp/dpep-work.8uAAbh/zaptel-1.0.9.1/zaphfc-florz/Makefile
---- ./zaphfc-florz/Makefile 1970-01-01 01:00:00.000000000 +0100
-+++ /tmp/dpep-work.8uAAbh/zaptel-1.0.9.1/zaphfc-florz/Makefile 2005-08-27 23:20:49.000000000 +0200
-@@ -0,0 +1,118 @@
-+KINCLUDES = /usr/src/linux/include
-+BRISTUFFBASE = $(shell dirname `pwd`)
-+
-+ZAP = $(shell [ -f $(BRISTUFFBASE)/zaptel-1.0.9/zaptel.h ] && echo "-I$(BRISTUFFBASE)/zaptel-1.0.9")
-+RTAI = $(shell [ -f /usr/realtime/include/rtai.h ] && echo "-DRTAITIMING -I/usr/realtime/include")
-+
-+HOSTCC=gcc
-+
-+CFLAGS+=-I. $(ZAP) $(RTAI) -O2 -g -Wall -DBUILDING_TONEZONE
-+CFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-fsigned-char"; fi)
-+
-+KFLAGS=-D__KERNEL__ -DMODULE -DEXPORT_SYMTAB -fomit-frame-pointer -O2 -Wall -I$(KINCLUDES) $(ZAP) $(RTAI) -Wall
-+KFLAGS+=$(shell [ -f $(KINCLUDES)/linux/modversions.h ] && echo "-DMODVERSIONS -include $(KINCLUDES)/linux/modversions.h")
-+KFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-msoft-float -fsigned-char"; fi)
-+
-+
-+BUILDVER=$(shell if uname -r | grep -q ^2.6; then echo "linux26"; else echo "linux24"; fi)
-+
-+MODCONF=$(shell if [ -d $(INSTALL_PREFIX)/etc/modprobe.d ]; then echo "$(INSTALL_PREFIX)/etc/modprobe.d/zaptel"; elif [ -d $(INSTALL_PREFIX)/etc/modutils ]; then echo "$(INSTALL_PREFIX)/etc/modutils/zaptel"; elif [ -f $(INSTALL_PREFIX)/etc/modprobe.conf ]; then echo "$(INSTALL_PREFIX)/modprobe.conf"; elif [ -f $(INSTALL_PREFIX)/etc/modules.conf ]; then echo "$(INSTALL_PREFIX)/etc/modules.conf"; else echo $(INSTALL_PREFIX)/etc/conf.modules ; fi)
-+
-+OBJS=zaphfc-florz.o
-+
-+MODULES=zaphfc-florz
-+
-+MODULESO=$(shell for x in $(MODULES); do echo "$$x.o "; done )
-+MODULESKO=$(shell for x in $(MODULES); do echo "$$x.ko "; done )
-+
-+PWD=$(shell pwd)
-+
-+obj-m := $(MODULESO)
-+
-+all: $(BUILDVER)
-+
-+linux24: $(OBJS)
-+ sync
-+
-+
-+zaphfc-florz.o: zaphfc-florz.c zaphfc-florz.h
-+ $(CC) -c zaphfc-florz.c $(KFLAGS)
-+
-+clean:
-+ rm -f $(OBJS) *.ko *.mod.c *.mod.o .*o.cmd *~
-+ rm -rf .tmp_versions
-+
-+test: all
-+ modprobe zaptel
-+ insmod ./zaphfc-florz.o
-+ cat /proc/interrupts
-+ sleep 1
-+ cat /proc/interrupts
-+ rmmod zaphfc-florz
-+ rmmod zaptel
-+
-+load: load$(BUILDVER)
-+
-+loadNT: load$(BUILDVER)NT
-+
-+load-debug: load$(BUILDVER)-debug
-+
-+loadNT-debug: load$(BUILDVER)NT-debug
-+
-+loadlinux24: all
-+ modprobe zaptel
-+ insmod ./zaphfc-florz.o
-+ ztcfg -v
-+
-+loadlinux24-debug: all
-+ modprobe zaptel
-+ insmod ./zaphfc-florz.o debug=1
-+ ztcfg -v
-+
-+loadlinux26: linux26
-+ modprobe zaptel
-+ insmod ./zaphfc-florz.ko
-+ ztcfg -v
-+
-+loadlinux26-debug: linux26
-+ modprobe zaptel
-+ insmod ./zaphfc-florz.ko debug=1
-+ ztcfg -v
-+
-+loadlinux24NT: all
-+ modprobe zaptel
-+ insmod ./zaphfc-florz.o modes=1
-+ ztcfg -v
-+
-+loadlinux24NT-debug: all
-+ modprobe zaptel
-+ insmod ./zaphfc-florz.o modes=1 debug=1
-+ ztcfg -v
-+
-+loadlinux26NT: linux26
-+ modprobe zaptel
-+ insmod ./zaphfc-florz.ko modes=1
-+ ztcfg -v
-+
-+loadlinux26NT-debug: linux26
-+ modprobe zaptel
-+ insmod ./zaphfc-florz.ko modes=1 debug=1
-+ ztcfg -v
-+
-+unload:
-+ -rmmod zaphfc-florz zaptel
-+
-+zaphfc-florz.ko: zaphfc-florz.c zaphfc-florz.h
-+
-+linux26:
-+ @if ! [ -d /usr/src/linux-2.6 ]; then echo "Link /usr/src/linux-2.6 to your kernel sources first!"; exit 1 ; fi
-+ make -C /usr/src/linux-2.6 SUBDIRS=$(PWD) ZAP=$(ZAP) modules
-+
-+install: install$(BUILDVER)
-+
-+installlinux26:
-+ install -D -m 644 zaphfc-florz.ko $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/zaphfc-florz.ko
-+
-+installlinux24:
-+ install -D -m 644 zaphfc-florz.o $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/zaphfc-florz.o
-+
-diff -urNad --exclude=CVS --exclude=.svn ./zaphfc-florz/zapata.conf /tmp/dpep-work.8uAAbh/zaptel-1.0.9.1/zaphfc-florz/zapata.conf
---- ./zaphfc-florz/zapata.conf 1970-01-01 01:00:00.000000000 +0100
-+++ /tmp/dpep-work.8uAAbh/zaptel-1.0.9.1/zaphfc-florz/zapata.conf 2005-08-27 23:17:30.000000000 +0200
-@@ -0,0 +1,38 @@
-+;
-+; Zapata telephony interface
-+;
-+; Configuration file
-+
-+[channels]
-+;
-+; Default language
-+;
-+;language=en
-+;
-+; Default context
-+;
-+;
-+switchtype = euroisdn
-+; p2mp TE mode
-+signalling = bri_cpe_ptmp
-+
-+; p2p TE mode
-+;signalling = bri_cpe
-+; p2mp NT mode
-+;signalling = bri_net_ptmp
-+; p2p NT mode
-+;signalling = bri_net
-+
-+pridialplan = dynamic
-+prilocaldialplan = local
-+nationalprefix = 0
-+internationalprefix = 00
-+
-+echocancel=yes
-+echotraining = 100
-+echocancelwhenbridged=yes
-+
-+immediate=yes
-+group = 1
-+context=demo
-+channel => 1-2
-diff -urNad --exclude=CVS --exclude=.svn ./zaphfc-florz/zaphfc-florz.c /tmp/dpep-work.8uAAbh/zaptel-1.0.9.1/zaphfc-florz/zaphfc-florz.c
---- ./zaphfc-florz/zaphfc-florz.c 1970-01-01 01:00:00.000000000 +0100
-+++ /tmp/dpep-work.8uAAbh/zaptel-1.0.9.1/zaphfc-florz/zaphfc-florz.c 2005-08-27 23:21:24.000000000 +0200
-@@ -0,0 +1,928 @@
-+/*
-+ * zaphfc-florz.c - Zaptel driver for HFC-S PCI A based ISDN BRI cards
-+ *
-+ * kernel module inspired by HFC PCI ISDN4Linux and Zaptel drivers
-+ *
-+ * Copyright (C) 2002, 2003, 2004, 2005 Junghanns.NET GmbH
-+ *
-+ * Klaus-Peter Junghanns <kpj at junghanns.net>
-+ *
-+ * Copyright (C) 2004, 2005 Florian Zumbiehl <florz at gmx.de>
-+ * - support for slave mode of the HFC-S chip which allows it to
-+ * sync its sample clock to an external source/another HFC chip
-+ * - support for "interrupt bundling" (let only one card generate
-+ * 8 kHz timing interrupt no matter how many cards there are
-+ * in the system)
-+ * - interrupt loss tolerant b channel handling
-+ *
-+ * This program is free software and may be modified and
-+ * distributed under the terms of the GNU General Public License.
-+ *
-+ */
-+
-+#include <linux/kernel.h>
-+#include <linux/module.h>
-+#include <linux/pci.h>
-+#include <linux/init.h>
-+#include <linux/interrupt.h>
-+#include <linux/delay.h>
-+#include <zaptel.h>
-+#include "zaphfc-florz.h"
-+
-+#define log2(n) ffz(~(n))
-+
-+#if CONFIG_PCI
-+
-+#define CLKDEL_TE 0x0f /* CLKDEL in TE mode */
-+#define CLKDEL_NT 0x6c /* CLKDEL in NT mode */
-+
-+typedef struct {
-+ int vendor_id;
-+ int device_id;
-+ char *vendor_name;
-+ char *card_name;
-+} PCI_ENTRY;
-+
-+static const PCI_ENTRY id_list[] =
-+{
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_2BD0, "CCD/Billion/Asuscom", "2BD0"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B000, "Billion", "B000"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B006, "Billion", "B006"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B007, "Billion", "B007"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B008, "Billion", "B008"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B009, "Billion", "B009"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B00A, "Billion", "B00A"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B00B, "Billion", "B00B"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B00C, "Billion", "B00C"},
-+ {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B100, "Seyeon", "B100"},
-+ {PCI_VENDOR_ID_ABOCOM, PCI_DEVICE_ID_ABOCOM_2BD1, "Abocom/Magitek", "2BD1"},
-+ {PCI_VENDOR_ID_ASUSTEK, PCI_DEVICE_ID_ASUSTEK_0675, "Asuscom/Askey", "675"},
-+ {PCI_VENDOR_ID_BERKOM, PCI_DEVICE_ID_BERKOM_T_CONCEPT, "German telekom", "T-Concept"},
-+ {PCI_VENDOR_ID_BERKOM, PCI_DEVICE_ID_BERKOM_A1T, "German telekom", "A1T"},
-+ {PCI_VENDOR_ID_ANIGMA, PCI_DEVICE_ID_ANIGMA_MC145575, "Motorola MC145575", "MC145575"},
-+ {PCI_VENDOR_ID_ZOLTRIX, PCI_DEVICE_ID_ZOLTRIX_2BD0, "Zoltrix", "2BD0"},
-+ {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_IOM2_E,"Digi International", "Digi DataFire Micro V IOM2 (Europe)"},
-+ {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_E,"Digi International", "Digi DataFire Micro V (Europe)"},
-+ {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_IOM2_A,"Digi International", "Digi DataFire Micro V IOM2 (North America)"},
-+ {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_A,"Digi International", "Digi DataFire Micro V (North America)"},
-+ {0x182d, 0x3069,"Sitecom","Isdn 128 PCI"},
-+ {0, 0, NULL, NULL},
-+};
-+
-+static struct hfc_card *hfc_dev_list = NULL;
-+static int hfc_dev_count = 0;
-+static int modes = 0; // all TE
-+static int debug = 0;
-+static int sync_slave = 0; // all master
-+static int timer_card = 0;
-+static int jitterbuffer = 1;
-+static struct pci_dev *multi_hfc = NULL;
-+static spinlock_t registerlock = SPIN_LOCK_UNLOCKED;
-+
-+void hfc_shutdownCard1(struct hfc_card *hfctmp) {
-+ printk(KERN_INFO "zaphfc-florz: shutting down card at %p.\n",hfctmp->pci_io);
-+
-+ /* Clear interrupt mask */
-+ hfctmp->regs.int_m2 = 0;
-+ hfc_outb(hfctmp, hfc_INT_M2, hfctmp->regs.int_m2);
-+
-+ /* Remove interrupt handler */
-+ free_irq(hfctmp->irq,hfctmp);
-+}
-+
-+void hfc_shutdownCard2(struct hfc_card *hfctmp) {
-+ unsigned long flags;
-+
-+ spin_lock_irqsave(&hfctmp->lock,flags);
-+
-+ /* Reset pending interrupts */
-+ hfc_inb(hfctmp, hfc_INT_S1);
-+
-+ /* Soft-reset the card */
-+ hfc_outb(hfctmp, hfc_CIRM, hfc_CIRM_RESET); // softreset on
-+
-+ spin_unlock_irqrestore(&hfctmp->lock, flags);
-+ set_current_state(TASK_UNINTERRUPTIBLE);
-+ schedule_timeout((30 * HZ) / 1000); // wait 30 ms
-+ spin_lock_irqsave(&hfctmp->lock,flags);
-+
-+ hfc_outb(hfctmp,hfc_CIRM,0); // softreset off
-+
-+ pci_write_config_word(hfctmp->pcidev, PCI_COMMAND, 0); // disable memio and bustmaster
-+
-+ if (hfctmp->fifos != NULL) {
-+ free_pages((unsigned long)hfctmp->fifos,log2(hfc_FIFO_MEM_SIZE_PAGES));
-+ }
-+ iounmap((void *) hfctmp->pci_io);
-+ hfctmp->pci_io = NULL;
-+ if (hfctmp->pcidev != NULL) {
-+ pci_disable_device(hfctmp->pcidev);
-+ }
-+ spin_unlock_irqrestore(&hfctmp->lock,flags);
-+ if (hfctmp->ztdev != NULL) {
-+ zt_unregister(&hfctmp->ztdev->span);
-+ vfree(hfctmp->ztdev);
-+ printk(KERN_INFO "unregistered from zaptel.\n");
-+ }
-+}
-+
-+void hfc_shutdownCard(struct hfc_card *hfctmp) {
-+ if (hfctmp == NULL) {
-+ return;
-+ }
-+
-+ if (hfctmp->pci_io == NULL) {
-+ return;
-+ }
-+
-+ hfc_shutdownCard1(hfctmp);
-+ hfc_shutdownCard2(hfctmp);
-+}
-+
-+void hfc_resetCard(struct hfc_card *hfctmp) {
-+ unsigned long flags;
-+
-+ spin_lock_irqsave(&hfctmp->lock,flags);
-+ pci_write_config_word(hfctmp->pcidev, PCI_COMMAND, PCI_COMMAND_MEMORY); // enable memio
-+ hfctmp->regs.int_m2 = 0;
-+ hfc_outb(hfctmp, hfc_INT_M2, hfctmp->regs.int_m2);
-+
-+// printk(KERN_INFO "zaphfc-florz: resetting card.\n");
-+ pci_set_master(hfctmp->pcidev);
-+ hfc_outb(hfctmp, hfc_CIRM, hfc_CIRM_RESET); // softreset on
-+ spin_unlock_irqrestore(&hfctmp->lock, flags);
-+
-+ set_current_state(TASK_UNINTERRUPTIBLE);
-+ schedule_timeout((30 * HZ) / 1000); // wait 30 ms
-+ hfc_outb(hfctmp, hfc_CIRM, 0); // softreset off
-+
-+ set_current_state(TASK_UNINTERRUPTIBLE);
-+ schedule_timeout((20 * HZ) / 1000); // wait 20 ms
-+ if (hfc_inb(hfctmp,hfc_STATUS) & hfc_STATUS_PCI_PROC) {
-+ printk(KERN_WARNING "zaphfc-florz: hfc busy.\n");
-+ }
-+
-+// hfctmp->regs.fifo_en = hfc_FIFOEN_D | hfc_FIFOEN_B1 | hfc_FIFOEN_B2;
-+// hfctmp->regs.fifo_en = hfc_FIFOEN_D; /* only D fifos enabled */
-+ hfctmp->regs.fifo_en = 0; /* no fifos enabled */
-+ hfc_outb(hfctmp, hfc_FIFO_EN, hfctmp->regs.fifo_en);
-+
-+ hfctmp->regs.trm = 2;
-+ hfc_outb(hfctmp, hfc_TRM, hfctmp->regs.trm);
-+
-+ if (hfctmp->regs.nt_mode == 1) {
-+ hfc_outb(hfctmp, hfc_CLKDEL, CLKDEL_NT); /* ST-Bit delay for NT-Mode */
-+ } else {
-+ hfc_outb(hfctmp, hfc_CLKDEL, CLKDEL_TE); /* ST-Bit delay for TE-Mode */
-+ }
-+ hfctmp->regs.sctrl_e = hfc_SCTRL_E_AUTO_AWAKE;
-+ hfc_outb(hfctmp, hfc_SCTRL_E, hfctmp->regs.sctrl_e); /* S/T Auto awake */
-+ hfctmp->regs.bswapped = 0; /* no exchange */
-+
-+ hfctmp->regs.ctmt = hfc_CTMT_TRANSB1 | hfc_CTMT_TRANSB2; // all bchans are transparent , no freaking hdlc
-+ hfc_outb(hfctmp, hfc_CTMT, hfctmp->regs.ctmt);
-+
-+ hfctmp->regs.int_m1=hfc_INTS_L1STATE;
-+ if(hfctmp->cardno==timer_card){
-+ hfctmp->regs.int_m2=hfc_M2_PROC_TRANS;
-+ }else{
-+ hfctmp->regs.int_m1|=hfc_INTS_DREC;
-+ hfctmp->regs.int_m2=0;
-+ }
-+ hfc_outb(hfctmp, hfc_INT_M1, hfctmp->regs.int_m1);
-+ hfc_outb(hfctmp, hfc_INT_M2, hfctmp->regs.int_m2);
-+
-+ /* Clear already pending ints */
-+ hfc_inb(hfctmp, hfc_INT_S1);
-+
-+ if (hfctmp->regs.nt_mode == 1) {
-+ hfctmp->regs.sctrl = 3 | hfc_SCTRL_NONE_CAP | hfc_SCTRL_MODE_NT; /* set tx_lo mode, error in datasheet ! */
-+ } else {
-+ hfctmp->regs.sctrl = 3 | hfc_SCTRL_NONE_CAP | hfc_SCTRL_MODE_TE; /* set tx_lo mode, error in datasheet ! */
-+ }
-+
-+ hfc_outb(hfctmp, hfc_MST_MODE, hfctmp->regs.mst_mode);
-+ hfc_outb(hfctmp, hfc_MST_EMOD, hfctmp->regs.mst_emod);
-+
-+ hfc_outb(hfctmp, hfc_SCTRL, hfctmp->regs.sctrl);
-+ hfctmp->regs.sctrl_r = 3;
-+ hfc_outb(hfctmp, hfc_SCTRL_R, hfctmp->regs.sctrl_r);
-+
-+ hfctmp->regs.connect = 0;
-+ hfc_outb(hfctmp, hfc_CONNECT, hfctmp->regs.connect);
-+
-+ hfc_outb(hfctmp, hfc_CIRM, 0x80 | 0x40); // bit order
-+
-+ /* Finally enable IRQ output */
-+ hfctmp->regs.int_m2 |= hfc_M2_IRQ_ENABLE;
-+ hfc_outb(hfctmp, hfc_INT_M2, hfctmp->regs.int_m2);
-+
-+ /* clear pending ints */
-+ hfc_inb(hfctmp, hfc_INT_S1);
-+ hfc_inb(hfctmp, hfc_INT_S2);
-+}
-+
-+void hfc_registerCard(struct hfc_card *hfccard) {
-+ spin_lock(®isterlock);
-+ if (hfccard != NULL) {
-+ hfccard->cardno = hfc_dev_count++;
-+ hfccard->next = hfc_dev_list;
-+ hfc_dev_list = hfccard;
-+ }
-+ spin_unlock(®isterlock);
-+}
-+
-+/*===========================================================================*/
-+
-+#if hfc_B_FIFO_SIZE%ZT_CHUNKSIZE
-+#error hfc_B_FIFO_SIZE is not a multiple of ZT_CHUNKSIZE even though the code assumes this
-+#endif
-+
-+static void hfc_dch_init(struct hfc_card *hfctmp){
-+ struct dch *chtmp=&hfctmp->dch;
-+
-+ chtmp->rx.f1.p=(u8 *)(hfctmp->fifos+hfc_FIFO_DRX_F1);
-+ chtmp->rx.f2.v=0x1f;
-+ chtmp->rx.f2.z2.v=0x1ff;
-+
-+ chtmp->tx.f1.p=(u8 *)(hfctmp->fifos+hfc_FIFO_DTX_F1);
-+ chtmp->tx.f1.v=0x1f;
-+ chtmp->tx.f1.z1.v=0x1ff;
-+ chtmp->tx.f2.p=(u8 *)(hfctmp->fifos+hfc_FIFO_DTX_F2);
-+}
-+
-+static void hfc_bch_init(struct hfc_card *hfctmp){
-+ struct bch *chtmp=&hfctmp->bch;
-+
-+ chtmp->checkcnt=0;
-+ chtmp->fill_fifo=0;
-+
-+ chtmp->rx.c[0].z1p=(unsigned short *)(hfctmp->fifos+hfc_FIFO_B1RX_Z1+0x1f*4);
-+ chtmp->rx.c[0].fifo_base=(char *)(hfctmp->fifos+hfc_FIFO_B1RX_ZOFF);
-+ chtmp->rx.c[1].z1p=(unsigned short *)(hfctmp->fifos+hfc_FIFO_B2RX_Z1+0x1f*4);
-+ chtmp->rx.c[1].fifo_base=(char *)(hfctmp->fifos+hfc_FIFO_B2RX_ZOFF);
-+ chtmp->rx.z2=hfc_B_SUB_VAL;
-+ chtmp->rx.diff=0;
-+
-+ chtmp->tx.c[0].z1p=(unsigned short *)(hfctmp->fifos+hfc_FIFO_B1TX_Z1+0x1f*4);
-+ chtmp->tx.c[0].z2p=(unsigned short *)(hfctmp->fifos+hfc_FIFO_B1TX_Z2+0x1f*4);
-+ chtmp->tx.c[0].fifo_base=(char *)(hfctmp->fifos+hfc_FIFO_B1TX_ZOFF);
-+ chtmp->tx.c[0].filled=0;
-+ chtmp->tx.c[1].z1p=(unsigned short *)(hfctmp->fifos+hfc_FIFO_B2TX_Z1+0x1f*4);
-+ chtmp->tx.c[1].z2p=(unsigned short *)(hfctmp->fifos+hfc_FIFO_B2TX_Z2+0x1f*4);
-+ chtmp->tx.c[1].fifo_base=(char *)(hfctmp->fifos+hfc_FIFO_B2TX_ZOFF);
-+ chtmp->tx.c[1].filled=0;
-+ chtmp->tx.z1=hfc_B_SUB_VAL;
-+ chtmp->tx.diff=0;
-+
-+ hfc_dch_init(hfctmp);
-+
-+ chtmp->initialized=0;
-+}
-+
-+static int hfc_bch_check(struct hfc_card *hfctmp){
-+ struct bch *chtmp=&hfctmp->bch;
-+ int x,r;
-+
-+ for(x=0;x<2;x++){
-+ chtmp->tx.c[x].filled=(chtmp->tx.z1-*chtmp->tx.c[x].z2p+hfc_B_FIFO_SIZE)%hfc_B_FIFO_SIZE;
-+ chtmp->rx.c[x].filled=(*chtmp->rx.c[x].z1p-chtmp->rx.z2+hfc_B_FIFO_SIZE)%hfc_B_FIFO_SIZE;
-+ }
-+ if(chtmp->fill_fifo){
-+ chtmp->checkcnt++;
-+ chtmp->checkcnt%=ZT_CHUNKSIZE;
-+ r=!chtmp->checkcnt;
-+ }else{
-+ x=chtmp->tx.c[0].filled-chtmp->tx.c[1].filled;
-+ if(abs(x-chtmp->tx.diff)>1){
-+ printk(KERN_CRIT "zaphfc-florz[%d]: tx sync changed: %d, %d\n",hfctmp->cardno,chtmp->tx.c[0].filled,chtmp->tx.c[1].filled);
-+ chtmp->tx.diff=x;
-+ }
-+ r=chtmp->tx.c[0].filled<=ZT_CHUNKSIZE*jitterbuffer&&chtmp->tx.c[1].filled<=ZT_CHUNKSIZE*jitterbuffer;
-+ }
-+ return(r);
-+}
-+
-+#define hfc_bch_inc_z(a,b) (a)=((a)-hfc_B_SUB_VAL+(b))%hfc_B_FIFO_SIZE+hfc_B_SUB_VAL
-+
-+static void hfc_bch_tx(struct hfc_card *hfctmp){
-+ struct bch *chtmp=&hfctmp->bch;
-+ int x;
-+
-+ for(x=0;x<2;x++)
-+ memcpy((void *)(chtmp->tx.c[x].fifo_base+chtmp->tx.z1),hfctmp->ztdev->chans[x].writechunk,ZT_CHUNKSIZE);
-+ hfc_bch_inc_z(chtmp->tx.z1,ZT_CHUNKSIZE);
-+ if(chtmp->fill_fifo){
-+ chtmp->fill_fifo--;
-+ }else if(chtmp->tx.c[0].filled<=1||chtmp->tx.c[1].filled<=1){
-+ chtmp->fill_fifo=jitterbuffer;
-+ if(chtmp->initialized)
-+ printk(KERN_CRIT "zaphfc-florz[%d]: b channel buffer underrun: %d, %d\n",hfctmp->cardno,chtmp->tx.c[0].filled,chtmp->tx.c[1].filled);
-+ }
-+ if(!chtmp->fill_fifo)
-+ for(x=0;x<2;x++)*chtmp->tx.c[x].z1p=chtmp->tx.z1;
-+}
-+
-+static void hfc_bch_rx(struct hfc_card *hfctmp){
-+ struct bch *chtmp=&hfctmp->bch;
-+ int x;
-+
-+ x=chtmp->rx.c[0].filled-chtmp->rx.c[1].filled;
-+ if(abs(x-chtmp->rx.diff)>1){
-+ printk(KERN_CRIT "zaphfc-florz[%d]: rx sync changed: %d, %d\n",hfctmp->cardno,chtmp->rx.c[0].filled,chtmp->rx.c[1].filled);
-+ chtmp->rx.diff=x;
-+ }
-+ if(chtmp->rx.c[0].filled>=ZT_CHUNKSIZE&&chtmp->rx.c[1].filled>=ZT_CHUNKSIZE){
-+ if((chtmp->rx.c[0].filled>=ZT_CHUNKSIZE*(jitterbuffer+2)&&chtmp->rx.c[1].filled>=ZT_CHUNKSIZE*(jitterbuffer+2))||!chtmp->initialized){
-+ if(chtmp->initialized)
-+ printk(KERN_CRIT "zaphfc-florz[%d]: b channel buffer overflow: %d, %d\n",hfctmp->cardno,chtmp->rx.c[0].filled,chtmp->rx.c[1].filled);
-+ hfc_bch_inc_z(chtmp->rx.z2,chtmp->rx.c[0].filled-chtmp->rx.c[0].filled%ZT_CHUNKSIZE-ZT_CHUNKSIZE);
-+ chtmp->initialized=1;
-+ }
-+ for(x=0;x<2;x++){
-+ memcpy(hfctmp->ztdev->chans[x].readchunk,(void *)(chtmp->rx.c[x].fifo_base+chtmp->rx.z2),ZT_CHUNKSIZE);
-+ zt_ec_chunk(&hfctmp->ztdev->chans[x],hfctmp->ztdev->chans[x].readchunk,hfctmp->ztdev->chans[x].writechunk);
-+ }
-+ hfc_bch_inc_z(chtmp->rx.z2,ZT_CHUNKSIZE);
-+ }
-+}
-+
-+/*===========================================================================*/
-+
-+static void hfc_dch_tx(struct hfc_card *hfctmp){
-+ struct dch *chtmp=&hfctmp->dch;
-+ u8 tx_f2_v;
-+ u16 x;
-+
-+ if(hfctmp->ztdev->chans[2].bytes2transmit){
-+ if(debug){
-+ printk(KERN_CRIT "zaphfc-florz[%d]: card TX [ ",hfctmp->cardno);
-+ for(x=0;x<hfctmp->ztdev->chans[2].bytes2transmit;x++){
-+ printk("%#2x ",hfctmp->dtransbuf[x]);
-+ }
-+ printk("] %d bytes\n",hfctmp->ztdev->chans[2].bytes2transmit);
-+ }
-+ tx_f2_v=*chtmp->tx.f2.p;
-+ if(!(tx_f2_v-chtmp->tx.f1.v+hfc_MAX_DFRAMES+1-1)&(hfc_MAX_DFRAMES+1-1)){
-+ printk(KERN_CRIT "zaphfc-florz[%d]: dchan tx fifo total number of frames exceeded!\n",hfctmp->cardno);
-+ }else{
-+ if(((*(volatile u16 *)(hfctmp->fifos+hfc_FIFO_DTX_Z2+tx_f2_v*4)-chtmp->tx.f1.z1.v+hfc_D_FIFO_SIZE-1)&(hfc_D_FIFO_SIZE-1))<hfctmp->ztdev->chans[2].bytes2transmit){
-+ printk(KERN_CRIT "zaphfc-florz[%d]: dchan tx fifo not enough space for frame!\n",hfctmp->cardno);
-+ }else{
-+ chtmp->tx.f1.v=((chtmp->tx.f1.v+1)&hfc_MAX_DFRAMES)|(hfc_MAX_DFRAMES+1);
-+ x=min(hfctmp->ztdev->chans[2].bytes2transmit,hfc_D_FIFO_SIZE-chtmp->tx.f1.z1.v);
-+ memcpy(hfctmp->fifos+hfc_FIFO_DTX_ZOFF+chtmp->tx.f1.z1.v,hfctmp->ztdev->chans[2].writechunk,x);
-+ memcpy(hfctmp->fifos+hfc_FIFO_DTX_ZOFF,hfctmp->ztdev->chans[2].writechunk+x,hfctmp->ztdev->chans[2].bytes2transmit-x);
-+ *(volatile u16 *)(hfctmp->fifos+hfc_FIFO_DTX_Z2+chtmp->tx.f1.v*4)=chtmp->tx.f1.z1.v;
-+ chtmp->tx.f1.z1.v=(chtmp->tx.f1.z1.v+hfctmp->ztdev->chans[2].bytes2transmit+hfc_D_FIFO_SIZE)&(hfc_D_FIFO_SIZE-1);
-+ *(volatile u16 *)(hfctmp->fifos+hfc_FIFO_DTX_Z1+chtmp->tx.f1.v*4)=chtmp->tx.f1.z1.v;
-+ *chtmp->tx.f1.p=chtmp->tx.f1.v;
-+ }
-+ }
-+ }
-+}
-+
-+static void hfc_dch_rx(struct hfc_card *hfctmp){
-+ struct dch *chtmp=&hfctmp->dch;
-+ u16 size;
-+
-+ hfctmp->ztdev->chans[2].bytes2receive=0;
-+ hfctmp->ztdev->chans[2].eofrx=0;
-+ if(*chtmp->rx.f1.p==chtmp->rx.f2.v){
-+ hfctmp->regs.int_drec=0;
-+ }else{
-+ size=((*(volatile u16 *)(hfctmp->fifos+hfc_FIFO_DRX_Z1+chtmp->rx.f2.v*4)-chtmp->rx.f2.z2.v+hfc_D_FIFO_SIZE)&(hfc_D_FIFO_SIZE-1))+1;
-+ if(size<4){
-+ printk(KERN_CRIT "zaphfc-florz[%d]: empty HDLC frame received.\n",hfctmp->cardno);
-+ }else{
-+ u16 x=min(size,(u16)(hfc_D_FIFO_SIZE-chtmp->rx.f2.z2.v));
-+ memcpy(hfctmp->drecbuf,hfctmp->fifos+hfc_FIFO_DRX_ZOFF+chtmp->rx.f2.z2.v,x);
-+ memcpy(hfctmp->drecbuf+x,hfctmp->fifos+hfc_FIFO_DRX_ZOFF,size-x);
-+ if(hfctmp->drecbuf[size-1]){
-+ printk(KERN_CRIT "zaphfc-florz[%d]: received d channel frame with bad CRC.\n",hfctmp->cardno);
-+ }else{
-+ hfctmp->ztdev->chans[2].bytes2receive=size-1;
-+ hfctmp->ztdev->chans[2].eofrx=1;
-+ }
-+ }
-+ chtmp->rx.f2.z2.v=(chtmp->rx.f2.z2.v+size)&(hfc_D_FIFO_SIZE-1);
-+ chtmp->rx.f2.v=((chtmp->rx.f2.v+1)&hfc_MAX_DFRAMES)|(hfc_MAX_DFRAMES+1);
-+ }
-+}
-+
-+/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
-+
-+#ifdef LINUX26
-+static irqreturn_t hfc_interrupt(int irq, void *dev_id, struct pt_regs *regs) {
-+#else
-+static void hfc_interrupt(int irq, void *dev_id, struct pt_regs *regs) {
-+#endif
-+ struct hfc_card *hfctmp = dev_id;
-+ struct hfc_card *hfctmp2;
-+ struct zt_hfc *zthfc;
-+ unsigned char stat, s1, s2, l1state;
-+ unsigned long flags;
-+ unsigned long flags2=0;
-+ int x;
-+
-+ if (!hfctmp) {
-+#ifdef LINUX26
-+ return IRQ_NONE;
-+#else
-+ return;
-+#endif
-+ }
-+
-+ if (!hfctmp->pci_io) {
-+ printk(KERN_WARNING "%s: IO-mem disabled, cannot handle interrupt\n",
-+ __FUNCTION__);
-+#ifdef LINUX26
-+ return IRQ_NONE;
-+#else
-+ return;
-+#endif
-+ }
-+
-+ spin_lock_irqsave(&hfctmp->lock, flags);
-+ stat = hfc_inb(hfctmp, hfc_STATUS);
-+ if ((stat & hfc_STATUS_ANYINT) == 0) {
-+ // maybe we are sharing the irq
-+ spin_unlock_irqrestore(&hfctmp->lock,flags);
-+#ifdef LINUX26
-+ return IRQ_NONE;
-+#else
-+ return;
-+#endif
-+ }
-+ s1 = hfc_inb(hfctmp, hfc_INT_S1);
-+ s2 = hfc_inb(hfctmp, hfc_INT_S2);
-+ if (s1 != 0) {
-+ if (s1 & hfc_INTS_TIMER) {
-+ // timer (bit 7)
-+ // printk(KERN_CRIT "timer %d %d %d.\n", stat, s1, s2);
-+ }
-+ if (s1 & hfc_INTS_L1STATE) {
-+ // state machine (bit 6)
-+ // printk(KERN_CRIT "zaphfc-florz: layer 1 state machine interrupt\n");
-+ zthfc = hfctmp->ztdev;
-+ l1state = hfc_inb(hfctmp,hfc_STATES) & hfc_STATES_STATE_MASK;
-+ if (hfctmp->regs.nt_mode == 1) {
-+ if (debug) {
-+ printk(KERN_CRIT "zaphfc-florz: card %d layer 1 state = G%d\n", hfctmp->cardno, l1state);
-+ }
-+ switch (l1state) {
-+ case 3:
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [NT] layer 1 ACTIVATED (G%d)", hfctmp->cardno, l1state);
-+ break;
-+ default:
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [NT] layer 1 DEACTIVATED (G%d)", hfctmp->cardno, l1state);
-+ }
-+ if (l1state == 2) {
-+ hfc_outb(hfctmp, hfc_STATES, hfc_STATES_ACTIVATE | hfc_STATES_DO_ACTION | hfc_STATES_NT_G2_G3);
-+ } else if (l1state == 3) {
-+ // fix to G3 state (see specs)
-+ hfc_outb(hfctmp, hfc_STATES, hfc_STATES_LOAD_STATE | 3);
-+ }
-+ } else {
-+ if (debug) {
-+ printk(KERN_CRIT "zaphfc-florz: card %d layer 1 state = F%d\n", hfctmp->cardno, l1state);
-+ }
-+ switch (l1state) {
-+ case 7:
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [TE] layer 1 ACTIVATED (F%d)", hfctmp->cardno, l1state);
-+ break;
-+ default:
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [TE] layer 1 DEACTIVATED (F%d)", hfctmp->cardno, l1state);
-+ }
-+ if (l1state == 3) {
-+ hfc_outb(hfctmp, hfc_STATES, hfc_STATES_DO_ACTION | hfc_STATES_ACTIVATE);
-+ }
-+ }
-+
-+ }
-+ if (s1 & hfc_INTS_DREC) {
-+ // D chan RX (bit 5)
-+ hfctmp->regs.int_drec = 1;
-+ // mr. zapata there is something for you!
-+ // printk(KERN_CRIT "d chan rx\n");
-+ }
-+ if (s1 & hfc_INTS_B2REC) {
-+ // B2 chan RX (bit 4)
-+ }
-+ if (s1 & hfc_INTS_B1REC) {
-+ // B1 chan RX (bit 3)
-+ }
-+ if (s1 & hfc_INTS_DTRANS) {
-+ // D chan TX (bit 2)
-+// printk(KERN_CRIT "zaphfc-florz: dchan frame transmitted.\n");
-+ }
-+ if (s1 & hfc_INTS_B2TRANS) {
-+ // B2 chan TX (bit 1)
-+ }
-+ if (s1 & hfc_INTS_B1TRANS) {
-+ // B1 chan TX (bit 0)
-+ }
-+ }
-+ if (s2 != 0) {
-+ if (s2 & hfc_M2_PMESEL) {
-+ // kaboom irq (bit 7)
-+ // printk(KERN_CRIT "zaphfc-florz: sync lost, pci performance too low. you might have some cpu throtteling enabled.\n");
-+ }
-+ if (s2 & hfc_M2_GCI_MON_REC) {
-+ // RxR monitor channel (bit 2)
-+ }
-+ if (s2 & hfc_M2_GCI_I_CHG) {
-+ // GCI I-change (bit 1)
-+ }
-+ if((s2&hfc_M2_PROC_TRANS)&&(hfctmp->cardno==timer_card)){
-+ // processing/non-processing transition (bit 0)
-+ hfctmp2=hfctmp;
-+ hfctmp=hfc_dev_list;
-+ while(hfctmp){
-+ if(hfctmp->active){
-+ if(hfctmp!=hfctmp2)spin_lock_irqsave(&hfctmp->lock, flags2);
-+ if(hfc_bch_check(hfctmp)){
-+ if (hfctmp->ztdev->span.flags & ZT_FLAG_RUNNING) {
-+ // clear dchan buffer
-+ // memset(hfctmp->drecbuf, 0x0, sizeof(hfctmp->drecbuf));
-+
-+ hfctmp->ztdev->chans[2].bytes2transmit = 0;
-+ hfctmp->ztdev->chans[2].maxbytes2transmit = hfc_D_FIFO_SIZE;
-+
-+ zt_transmit(&(hfctmp->ztdev->span));
-+
-+ hfc_bch_tx(hfctmp);
-+ hfc_dch_tx(hfctmp);
-+ }
-+ hfc_bch_rx(hfctmp);
-+ if (hfctmp->regs.int_drec) {
-+ // dchan data to read
-+ hfc_dch_rx(hfctmp);
-+ if (hfctmp->ztdev->chans[2].bytes2receive > 0) {
-+ if (debug) {
-+ printk(KERN_CRIT "zaphfc-florz: card %d RX [ ", hfctmp->cardno);
-+ if (hfctmp->ztdev->chans[2].eofrx) {
-+ /* dont output CRC == less user confusion */
-+ for (x=0; x < hfctmp->ztdev->chans[2].bytes2receive - 2; x++) {
-+ printk("%#2x ", hfctmp->drecbuf[x]);
-+ }
-+ printk("] %d bytes\n", hfctmp->ztdev->chans[2].bytes2receive - 2);
-+ } else {
-+ for (x=0; x < hfctmp->ztdev->chans[2].bytes2receive; x++) {
-+ printk("%#2x ", hfctmp->drecbuf[x]);
-+ }
-+ printk("..] %d bytes\n", hfctmp->ztdev->chans[2].bytes2receive);
-+ }
-+ }
-+ }
-+ } else {
-+ // hmm....ok, let zaptel receive nothing
-+ hfctmp->ztdev->chans[2].bytes2receive = 0;
-+ }
-+ if (hfctmp->ztdev->span.flags & ZT_FLAG_RUNNING) {
-+ zt_receive(&(hfctmp->ztdev->span));
-+ }
-+ }
-+ if(hfctmp!=hfctmp2)spin_unlock_irqrestore(&hfctmp->lock,flags2);
-+ }
-+ hfctmp=hfctmp->next;
-+ }
-+ hfctmp=hfctmp2;
-+ }
-+ }
-+ spin_unlock_irqrestore(&hfctmp->lock,flags);
-+#ifdef LINUX26
-+ return IRQ_RETVAL(1);
-+#endif
-+}
-+
-+
-+static int zthfc_open(struct zt_chan *chan) {
-+ struct zt_hfc *zthfc = chan->pvt;
-+ struct hfc_card *hfctmp = zthfc->card;
-+
-+ if (!hfctmp) {
-+ return 0;
-+ }
-+#ifndef LINUX26
-+ MOD_INC_USE_COUNT;
-+#else
-+ try_module_get(THIS_MODULE);
-+#endif
-+ return 0;
-+}
-+
-+static int zthfc_close(struct zt_chan *chan) {
-+ struct zt_hfc *zthfc = chan->pvt;
-+ struct hfc_card *hfctmp = zthfc->card;
-+
-+ if (!hfctmp) {
-+ return 0;
-+ }
-+
-+#ifndef LINUX26
-+ MOD_DEC_USE_COUNT;
-+#else
-+ module_put(THIS_MODULE);
-+#endif
-+ return 0;
-+}
-+
-+static int zthfc_rbsbits(struct zt_chan *chan, int bits) {
-+ return 0;
-+}
-+
-+static int zthfc_ioctl(struct zt_chan *chan, unsigned int cmd, unsigned long data) {
-+ switch(cmd) {
-+ default:
-+ return -ENOTTY;
-+ }
-+ return 0;
-+}
-+
-+static int zthfc_startup(struct zt_span *span) {
-+ struct zt_hfc *zthfc = span->pvt;
-+ struct hfc_card *hfctmp = zthfc->card;
-+ int alreadyrunning;
-+
-+ if (hfctmp == NULL) {
-+ printk(KERN_INFO "zaphfc-florz: no card for span at startup!\n");
-+ }
-+ alreadyrunning = span->flags & ZT_FLAG_RUNNING;
-+
-+ if (alreadyrunning) return 0;
-+
-+ span->chans[2].flags &= ~ZT_FLAG_HDLC;
-+ span->chans[2].flags |= ZT_FLAG_BRIDCHAN;
-+
-+ span->flags |= ZT_FLAG_RUNNING;
-+
-+ hfctmp->ticks = -2;
-+ hfctmp->regs.fifo_en = hfc_FIFOEN_D | hfc_FIFOEN_B1 | hfc_FIFOEN_B2;
-+ hfc_outb(hfctmp, hfc_FIFO_EN, hfctmp->regs.fifo_en);
-+
-+ hfc_bch_init(hfctmp);
-+ // drivers, start engines!
-+ hfc_outb(hfctmp, hfc_STATES, hfc_STATES_DO_ACTION | hfc_STATES_ACTIVATE);
-+ hfctmp->active=1;
-+ return 0;
-+}
-+
-+static int zthfc_shutdown(struct zt_span *span) {
-+ return 0;
-+}
-+
-+static int zthfc_maint(struct zt_span *span, int cmd) {
-+ return 0;
-+}
-+
-+static int zthfc_chanconfig(struct zt_chan *chan, int sigtype) {
-+// printk(KERN_CRIT "chan_config sigtype=%d\n", sigtype);
-+ return 0;
-+}
-+
-+static int zthfc_spanconfig(struct zt_span *span, struct zt_lineconfig *lc) {
-+ span->lineconfig = lc->lineconfig;
-+ return 0;
-+}
-+
-+static int zthfc_initialize(struct zt_hfc *zthfc) {
-+ struct hfc_card *hfctmp = zthfc->card;
-+ int i;
-+
-+ memset(&zthfc->span, 0x0, sizeof(struct zt_span)); // you never can tell...
-+
-+ sprintf(zthfc->span.name, "ZTHFC%d", hfc_dev_count + 1);
-+ if (hfctmp->regs.nt_mode == 1) {
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [NT]", hfc_dev_count + 1);
-+ } else {
-+ sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [TE]", hfc_dev_count + 1);
-+ }
-+
-+ zthfc->span.spanconfig = zthfc_spanconfig;
-+ zthfc->span.chanconfig = zthfc_chanconfig;
-+ zthfc->span.startup = zthfc_startup;
-+ zthfc->span.shutdown = zthfc_shutdown;
-+ zthfc->span.maint = zthfc_maint;
-+ zthfc->span.rbsbits = zthfc_rbsbits;
-+ zthfc->span.open = zthfc_open;
-+ zthfc->span.close = zthfc_close;
-+ zthfc->span.ioctl = zthfc_ioctl;
-+
-+ zthfc->span.chans = zthfc->chans;
-+ zthfc->span.channels = 3;
-+ zthfc->span.deflaw = ZT_LAW_ALAW;
-+ zthfc->span.linecompat = ZT_CONFIG_AMI | ZT_CONFIG_CCS; // <--- this is really BS
-+ zthfc->span.offset = 0;
-+ init_waitqueue_head(&zthfc->span.maintq);
-+ zthfc->span.pvt = zthfc;
-+
-+ for (i = 0; i < zthfc->span.channels; i++) {
-+ memset(&(zthfc->chans[i]), 0x0, sizeof(struct zt_chan));
-+ sprintf(zthfc->chans[i].name, "ZTHFC%d/%d/%d", hfc_dev_count + 1,0,i + 1);
-+ zthfc->chans[i].pvt = zthfc;
-+ zthfc->chans[i].sigcap = ZT_SIG_EM | ZT_SIG_CLEAR | ZT_SIG_FXSLS | ZT_SIG_FXSGS | ZT_SIG_FXSKS | ZT_SIG_FXOLS | ZT_SIG_FXOGS | ZT_SIG_FXOKS | ZT_SIG_CAS | ZT_SIG_SF;
-+ zthfc->chans[i].chanpos = i + 1;
-+ }
-+
-+ if (zt_register(&zthfc->span,0)) {
-+ printk(KERN_CRIT "unable to register zaptel device!\n");
-+ return -1;
-+ }
-+// printk(KERN_CRIT "zaphfc-florz: registered zaptel device!\n");
-+ return 0;
-+}
-+
-+int hfc_findCards(int pcivendor, int pcidevice, char *vendor_name, char *card_name) {
-+ struct pci_dev *tmp;
-+ struct hfc_card *hfctmp = NULL;
-+ struct zt_hfc *zthfc = NULL;
-+
-+ tmp = pci_find_device(pcivendor, pcidevice, multi_hfc);
-+ while (tmp != NULL) {
-+ multi_hfc = tmp; // skip this next time.
-+
-+ if (pci_enable_device(tmp)) {
-+ multi_hfc = NULL;
-+ return -1;
-+ }
-+ pci_set_master(tmp);
-+
-+ hfctmp = vmalloc(sizeof(struct hfc_card));
-+ if (!hfctmp) {
-+ printk(KERN_WARNING "zaphfc-florz: unable to vmalloc!\n");
-+ pci_disable_device(tmp);
-+ multi_hfc = NULL;
-+ return -ENOMEM;
-+ }
-+ memset(hfctmp, 0x0, sizeof(struct hfc_card));
-+ spin_lock_init(&hfctmp->lock);
-+
-+ hfctmp->active=0;
-+ hfctmp->pcidev = tmp;
-+ hfctmp->pcibus = tmp->bus->number;
-+ hfctmp->pcidevfn = tmp->devfn;
-+
-+ if (!tmp->irq) {
-+ printk(KERN_WARNING "zaphfc-florz: no irq!\n");
-+ } else {
-+ hfctmp->irq = tmp->irq;
-+ }
-+
-+ hfctmp->pci_io = (char *) tmp->resource[1].start;
-+ if (!hfctmp->pci_io) {
-+ printk(KERN_WARNING "zaphfc-florz: no iomem!\n");
-+ vfree(hfctmp);
-+ pci_disable_device(tmp);
-+ multi_hfc = NULL;
-+ return -1;
-+ }
-+
-+ hfctmp->fifos=(void *)__get_free_pages(GFP_KERNEL,log2(hfc_FIFO_MEM_SIZE_PAGES));
-+ if (!hfctmp->fifos) {
-+ printk(KERN_WARNING "zaphfc-florz: unable to __get_free_pages fifomem!\n");
-+ vfree(hfctmp);
-+ pci_disable_device(tmp);
-+ multi_hfc = NULL;
-+ return -ENOMEM;
-+ } else {
-+ pci_write_config_dword(hfctmp->pcidev, 0x80, (u_int) virt_to_bus(hfctmp->fifos));
-+ hfctmp->pci_io = ioremap((ulong) hfctmp->pci_io, 256);
-+ }
-+
-+ if (request_irq(hfctmp->irq, &hfc_interrupt, SA_INTERRUPT | SA_SHIRQ, "zaphfc-florz", hfctmp)) {
-+ printk(KERN_WARNING "zaphfc-florz: unable to register irq\n");
-+ free_pages((unsigned long)hfctmp->fifos,log2(hfc_FIFO_MEM_SIZE_PAGES));
-+ vfree(hfctmp);
-+ iounmap((void *) hfctmp->pci_io);
-+ pci_disable_device(tmp);
-+ multi_hfc = NULL;
-+ return -EIO;
-+ }
-+
-+ printk(KERN_INFO
-+ "zaphfc-florz: %s %s configured at mem %p fifo %p(%#lx) IRQ %d HZ %d\n",
-+ vendor_name, card_name,
-+ hfctmp->pci_io,
-+ hfctmp->fifos,
-+ virt_to_bus(hfctmp->fifos),
-+ hfctmp->irq, HZ);
-+ pci_write_config_word(hfctmp->pcidev, PCI_COMMAND, PCI_COMMAND_MEMORY); // enable memio
-+ hfctmp->regs.int_m1 = 0; // no ints
-+ hfctmp->regs.int_m2 = 0; // not at all
-+ hfc_outb(hfctmp,hfc_INT_M1,hfctmp->regs.int_m1);
-+ hfc_outb(hfctmp,hfc_INT_M2,hfctmp->regs.int_m2);
-+
-+ if ((modes & (1 << hfc_dev_count)) != 0) {
-+ printk(KERN_INFO "zaphfc-florz: Card %d configured for NT mode\n",hfc_dev_count);
-+ hfctmp->regs.nt_mode = 1;
-+ } else {
-+ printk(KERN_INFO "zaphfc-florz: Card %d configured for TE mode\n",hfc_dev_count);
-+ hfctmp->regs.nt_mode = 0;
-+ }
-+
-+ if(sync_slave&(1<<hfc_dev_count)){
-+ printk(KERN_INFO "zaphfc-florz: Card %d configured for slave mode\n",hfc_dev_count);
-+ hfctmp->regs.mst_mode=hfc_MST_MODE_SLAVE|hfc_MST_MODE_F0_LONG_DURATION;
-+ hfctmp->regs.mst_emod=hfc_MST_EMOD_SLOW_CLOCK_ADJ;
-+ }else{
-+ printk(KERN_INFO "zaphfc-florz: Card %d configured for master mode\n",hfc_dev_count);
-+ hfctmp->regs.mst_mode=hfc_MST_MODE_MASTER|hfc_MST_MODE_F0_LONG_DURATION;
-+ hfctmp->regs.mst_emod=0;
-+ }
-+
-+ zthfc = vmalloc(sizeof(struct zt_hfc));
-+ if (!zthfc) {
-+ printk(KERN_CRIT "zaphfc-florz: unable to vmalloc!\n");
-+ hfc_shutdownCard(hfctmp);
-+ vfree(hfctmp);
-+ multi_hfc = NULL;
-+ return -ENOMEM;
-+ }
-+ memset(zthfc, 0x0, sizeof(struct zt_hfc));
-+
-+ zthfc->card = hfctmp;
-+ zthfc_initialize(zthfc);
-+ hfctmp->ztdev = zthfc;
-+
-+ memset(hfctmp->drecbuf, 0x0, sizeof(hfctmp->drecbuf));
-+ hfctmp->ztdev->chans[2].readchunk = hfctmp->drecbuf;
-+
-+ memset(hfctmp->dtransbuf, 0x0, sizeof(hfctmp->dtransbuf));
-+ hfctmp->ztdev->chans[2].writechunk = hfctmp->dtransbuf;
-+
-+ memset(hfctmp->brecbuf[0], 0x0, sizeof(hfctmp->brecbuf[0]));
-+ hfctmp->ztdev->chans[0].readchunk = hfctmp->brecbuf[0];
-+ memset(hfctmp->btransbuf[0], 0x0, sizeof(hfctmp->btransbuf[0]));
-+ hfctmp->ztdev->chans[0].writechunk = hfctmp->btransbuf[0];
-+
-+ memset(hfctmp->brecbuf[1], 0x0, sizeof(hfctmp->brecbuf[1]));
-+ hfctmp->ztdev->chans[1].readchunk = hfctmp->brecbuf[1];
-+ memset(hfctmp->btransbuf[1], 0x0, sizeof(hfctmp->btransbuf[1]));
-+ hfctmp->ztdev->chans[1].writechunk = hfctmp->btransbuf[1];
-+
-+ hfc_registerCard(hfctmp);
-+ hfc_resetCard(hfctmp);
-+ tmp = pci_find_device(pcivendor, pcidevice, multi_hfc);
-+ }
-+ return 0;
-+}
-+
-+int init_module(void) {
-+ int i = 0;
-+ if(jitterbuffer<1){
-+ printk(KERN_INFO "zaphfc-florz: invalid jitterbuffer size specified: %d - changing to minimum of 1\n",jitterbuffer);
-+ jitterbuffer=1;
-+ }else if(jitterbuffer>500){
-+ printk(KERN_INFO "zaphfc-florz: invalid jitterbuffer size specified: %d - changing to maximum of 500\n",jitterbuffer);
-+ jitterbuffer=500;
-+ }
-+ printk(KERN_INFO "zaphfc-florz: jitterbuffer size: %d\n",jitterbuffer);
-+ while (id_list[i].vendor_id) {
-+ multi_hfc = NULL;
-+ hfc_findCards(id_list[i].vendor_id, id_list[i].device_id, id_list[i].vendor_name, id_list[i].card_name);
-+ i++;
-+ }
-+ printk(KERN_INFO "zaphfc-florz: %d hfc-pci card(s) in this box.\n", hfc_dev_count);
-+ return 0;
-+}
-+
-+void cleanup_module(void) {
-+ struct hfc_card *tmpcard;
-+
-+ printk(KERN_INFO "zaphfc-florz: stop\n");
-+// spin_lock(®isterlock);
-+ tmpcard=hfc_dev_list;
-+ while(tmpcard){
-+ hfc_shutdownCard1(tmpcard);
-+ tmpcard=tmpcard->next;
-+ }
-+ while (hfc_dev_list != NULL) {
-+ if (hfc_dev_list == NULL) break;
-+ hfc_shutdownCard2(hfc_dev_list);
-+ tmpcard = hfc_dev_list;
-+ hfc_dev_list = hfc_dev_list->next;
-+ if (tmpcard != NULL) {
-+ vfree(tmpcard);
-+ tmpcard = NULL;
-+ printk(KERN_INFO "zaphfc-florz: freed one card.\n");
-+ }
-+ }
-+// spin_unlock(®isterlock);
-+}
-+#endif
-+
-+
-+MODULE_DESCRIPTION("HFC-S PCI A Zaptel Driver");
-+MODULE_AUTHOR("Klaus-Peter Junghanns <kpj at junghanns.net>");
-+#ifdef MODULE_LICENSE
-+MODULE_LICENSE("GPL");
-+#endif
-+MODULE_PARM(modes,"i");
-+MODULE_PARM(debug,"i");
-+MODULE_PARM(sync_slave,"i");
-+MODULE_PARM(timer_card,"i");
-+MODULE_PARM(jitterbuffer,"i");
-+
-+/* vim:set sw=4: */
-+
-diff -urNad --exclude=CVS --exclude=.svn ./zaphfc-florz/zaphfc-florz.h /tmp/dpep-work.8uAAbh/zaptel-1.0.9.1/zaphfc-florz/zaphfc-florz.h
---- ./zaphfc-florz/zaphfc-florz.h 1970-01-01 01:00:00.000000000 +0100
-+++ /tmp/dpep-work.8uAAbh/zaptel-1.0.9.1/zaphfc-florz/zaphfc-florz.h 2005-08-27 23:17:39.000000000 +0200
-@@ -0,0 +1,345 @@
-+/*
-+ * zaphfc-florz.h - Zaptel driver for HFC-S PCI A based ISDN BRI cards
-+ *
-+ * kernel module based on HFC PCI ISDN4Linux and Zaptel drivers
-+ *
-+ * Copyright (C) 2002, 2003, 2004, 2005 Junghanns.NET GmbH
-+ *
-+ * Klaus-Peter Junghanns <kpj at junghanns.net>
-+ *
-+ * This program is free software and may be modified and
-+ * distributed under the terms of the GNU Public License.
-+ *
-+ */
-+
-+/* HFC register addresses - accessed using memory mapped I/O */
-+/* For a list, see datasheet section 3.2.1 at page 21 */
-+
-+#define hfc_outb(a,b,c) (writeb((c),(a)->pci_io+(b)))
-+#define hfc_inb(a,b) (readb((a)->pci_io+(b)))
-+
-+/* GCI/IOM bus monitor registers */
-+
-+#define hfc_C_I 0x08
-+#define hfc_TRxR 0x0C
-+#define hfc_MON1_D 0x28
-+#define hfc_MON2_D 0x2C
-+
-+
-+/* GCI/IOM bus timeslot registers */
-+
-+#define hfc_B1_SSL 0x80
-+#define hfc_B2_SSL 0x84
-+#define hfc_AUX1_SSL 0x88
-+#define hfc_AUX2_SSL 0x8C
-+#define hfc_B1_RSL 0x90
-+#define hfc_B2_RSL 0x94
-+#define hfc_AUX1_RSL 0x98
-+#define hfc_AUX2_RSL 0x9C
-+
-+/* GCI/IOM bus data registers */
-+
-+#define hfc_B1_D 0xA0
-+#define hfc_B2_D 0xA4
-+#define hfc_AUX1_D 0xA8
-+#define hfc_AUX2_D 0xAC
-+
-+/* GCI/IOM bus configuration registers */
-+
-+#define hfc_MST_EMOD 0xB4
-+#define hfc_MST_MODE 0xB8
-+#define hfc_CONNECT 0xBC
-+
-+
-+/* Interrupt and status registers */
-+
-+#define hfc_FIFO_EN 0x44
-+#define hfc_TRM 0x48
-+#define hfc_B_MODE 0x4C
-+#define hfc_CHIP_ID 0x58
-+#define hfc_CIRM 0x60
-+#define hfc_CTMT 0x64
-+#define hfc_INT_M1 0x68
-+#define hfc_INT_M2 0x6C
-+#define hfc_INT_S1 0x78
-+#define hfc_INT_S2 0x7C
-+#define hfc_STATUS 0x70
-+
-+/* S/T section registers */
-+
-+#define hfc_STATES 0xC0
-+#define hfc_SCTRL 0xC4
-+#define hfc_SCTRL_E 0xC8
-+#define hfc_SCTRL_R 0xCC
-+#define hfc_SQ 0xD0
-+#define hfc_CLKDEL 0xDC
-+#define hfc_B1_REC 0xF0
-+#define hfc_B1_SEND 0xF0
-+#define hfc_B2_REC 0xF4
-+#define hfc_B2_SEND 0xF4
-+#define hfc_D_REC 0xF8
-+#define hfc_D_SEND 0xF8
-+#define hfc_E_REC 0xFC
-+
-+/* Bits and values in various HFC PCI registers */
-+
-+/* bits in status register (READ) */
-+#define hfc_STATUS_PCI_PROC 0x02
-+#define hfc_STATUS_NBUSY 0x04
-+#define hfc_STATUS_TIMER_ELAP 0x10
-+#define hfc_STATUS_STATINT 0x20
-+#define hfc_STATUS_FRAMEINT 0x40
-+#define hfc_STATUS_ANYINT 0x80
-+
-+/* bits in CTMT (Write) */
-+#define hfc_CTMT_CLTIMER 0x80
-+#define hfc_CTMT_TIM3_125 0x04
-+#define hfc_CTMT_TIM25 0x10
-+#define hfc_CTMT_TIM50 0x14
-+#define hfc_CTMT_TIM400 0x18
-+#define hfc_CTMT_TIM800 0x1C
-+#define hfc_CTMT_AUTO_TIMER 0x20
-+#define hfc_CTMT_TRANSB2 0x02
-+#define hfc_CTMT_TRANSB1 0x01
-+
-+/* bits in CIRM (Write) */
-+#define hfc_CIRM_AUX_MSK 0x07
-+#define hfc_CIRM_RESET 0x08
-+#define hfc_CIRM_B1_REV 0x40
-+#define hfc_CIRM_B2_REV 0x80
-+
-+/* bits in INT_M1 and INT_S1 */
-+#define hfc_INTS_B1TRANS 0x01
-+#define hfc_INTS_B2TRANS 0x02
-+#define hfc_INTS_DTRANS 0x04
-+#define hfc_INTS_B1REC 0x08
-+#define hfc_INTS_B2REC 0x10
-+#define hfc_INTS_DREC 0x20
-+#define hfc_INTS_L1STATE 0x40
-+#define hfc_INTS_TIMER 0x80
-+
-+/* bits in INT_M2 */
-+#define hfc_M2_PROC_TRANS 0x01
-+#define hfc_M2_GCI_I_CHG 0x02
-+#define hfc_M2_GCI_MON_REC 0x04
-+#define hfc_M2_IRQ_ENABLE 0x08
-+#define hfc_M2_PMESEL 0x80
-+
-+/* bits in STATES */
-+#define hfc_STATES_STATE_MASK 0x0F
-+#define hfc_STATES_LOAD_STATE 0x10
-+#define hfc_STATES_ACTIVATE 0x20
-+#define hfc_STATES_DO_ACTION 0x40
-+#define hfc_STATES_NT_G2_G3 0x80
-+
-+/* bits in HFCD_MST_MODE */
-+#define hfc_MST_MODE_MASTER 0x01
-+#define hfc_MST_MODE_SLAVE 0x00
-+#define hfc_MST_MODE_F0_LONG_DURATION 0x08
-+/* remaining bits are for codecs control */
-+
-+/* bits in HFCD_MST_EMOD */
-+#define hfc_MST_EMOD_SLOW_CLOCK_ADJ 0x01
-+
-+/* bits in HFCD_SCTRL */
-+#define hfc_SCTRL_B1_ENA 0x01
-+#define hfc_SCTRL_B2_ENA 0x02
-+#define hfc_SCTRL_MODE_TE 0x00
-+#define hfc_SCTRL_MODE_NT 0x04
-+#define hfc_SCTRL_LOW_PRIO 0x08
-+#define hfc_SCTRL_SQ_ENA 0x10
-+#define hfc_SCTRL_TEST 0x20
-+#define hfc_SCTRL_NONE_CAP 0x40
-+#define hfc_SCTRL_PWR_DOWN 0x80
-+
-+/* bits in SCTRL_E */
-+#define hfc_SCTRL_E_AUTO_AWAKE 0x01
-+#define hfc_SCTRL_E_DBIT_1 0x04
-+#define hfc_SCTRL_E_IGNORE_COL 0x08
-+#define hfc_SCTRL_E_CHG_B1_B2 0x80
-+
-+/* bits in FIFO_EN register */
-+#define hfc_FIFOEN_B1TX 0x01
-+#define hfc_FIFOEN_B1RX 0x02
-+#define hfc_FIFOEN_B2TX 0x04
-+#define hfc_FIFOEN_B2RX 0x08
-+#define hfc_FIFOEN_DTX 0x10
-+#define hfc_FIFOEN_DRX 0x20
-+
-+#define hfc_FIFOEN_B1 (hfc_FIFOEN_B1TX|hfc_FIFOEN_B1RX)
-+#define hfc_FIFOEN_B2 (hfc_FIFOEN_B2TX|hfc_FIFOEN_B2RX)
-+#define hfc_FIFOEN_D (hfc_FIFOEN_DTX|hfc_FIFOEN_DRX)
-+
-+/* bits in the CONNECT register */
-+#define hfc_CONNECT_B1_shift 0
-+#define hfc_CONNECT_B2_shift 3
-+
-+#define hfc_CONNECT_HFC_from_ST 0x0
-+#define hfc_CONNECT_HFC_from_GCI 0x1
-+#define hfc_CONNECT_ST_from_HFC 0x0
-+#define hfc_CONNECT_ST_from_GCI 0x2
-+#define hfc_CONNECT_GCI_from_HFC 0x0
-+#define hfc_CONNECT_GCI_from_ST 0x4
-+
-+/* bits in the __SSL and __RSL registers */
-+#define hfc_SRSL_STIO 0x40
-+#define hfc_SRSL_ENABLE 0x80
-+#define hfc_SRCL_SLOT_MASK 0x1f
-+
-+/* FIFO memory definitions */
-+
-+#define hfc_FMASK 0x000f
-+#define hfc_ZMASK 0x01ff
-+#define hfc_ZMASKB 0x1fff
-+
-+#define hfc_D_FIFO_SIZE 0x0200
-+#define hfc_B_SUB_VAL 0x0200
-+#define hfc_B_FIFO_SIZE 0x1E00
-+#define hfc_MAX_DFRAMES 0x000f
-+
-+#define hfc_FIFO_DTX_Z1 0x2080
-+#define hfc_FIFO_DTX_Z2 0x2082
-+#define hfc_FIFO_DTX_F1 0x20a0
-+#define hfc_FIFO_DTX_F2 0x20a1
-+#define hfc_FIFO_DTX 0x0000
-+#define hfc_FIFO_DTX_ZOFF 0x000
-+
-+#define hfc_FIFO_DRX_Z1 0x6080
-+#define hfc_FIFO_DRX_Z2 0x6082
-+#define hfc_FIFO_DRX_F1 0x60a0
-+#define hfc_FIFO_DRX_F2 0x60a1
-+#define hfc_FIFO_DRX 0x4000
-+#define hfc_FIFO_DRX_ZOFF 0x4000
-+
-+#define hfc_FIFO_B1TX_Z1 0x2000
-+#define hfc_FIFO_B1TX_Z2 0x2002
-+#define hfc_FIFO_B1RX_Z1 0x6000
-+#define hfc_FIFO_B1RX_Z2 0x6002
-+
-+#define hfc_FIFO_B1TX_F1 0x2080
-+#define hfc_FIFO_B1TX_F2 0x2081
-+#define hfc_FIFO_B1RX_F1 0x6080
-+#define hfc_FIFO_B1RX_F2 0x6081
-+
-+#define hfc_FIFO_B1RX_ZOFF 0x4000
-+#define hfc_FIFO_B1TX_ZOFF 0x0000
-+
-+#define hfc_FIFO_B2TX_Z1 0x2100
-+#define hfc_FIFO_B2TX_Z2 0x2102
-+#define hfc_FIFO_B2RX_Z1 0x6100
-+#define hfc_FIFO_B2RX_Z2 0x6102
-+
-+#define hfc_FIFO_B2TX_F1 0x2180
-+#define hfc_FIFO_B2TX_F2 0x2181
-+#define hfc_FIFO_B2RX_F1 0x6180
-+#define hfc_FIFO_B2RX_F2 0x6181
-+
-+#define hfc_FIFO_B2RX_ZOFF 0x6000
-+#define hfc_FIFO_B2TX_ZOFF 0x2000
-+
-+#define hfc_BTRANS_THRESHOLD 128
-+#define hfc_BTRANS_THRESMASK 0x00
-+
-+#define hfc_FIFO_MEM_SIZE_BYTES (32*1024)
-+#define hfc_FIFO_MEM_SIZE_PAGES ((hfc_FIFO_MEM_SIZE_BYTES+PAGE_SIZE-1)/PAGE_SIZE)
-+
-+/* Structures */
-+
-+typedef struct hfc_regs {
-+ unsigned char fifo_en;
-+ unsigned char ctmt;
-+ unsigned char int_m1;
-+ unsigned char int_m2;
-+ unsigned char sctrl;
-+ unsigned char sctrl_e;
-+ unsigned char sctrl_r;
-+ unsigned char connect;
-+ unsigned char trm;
-+ unsigned char mst_mode;
-+ unsigned char mst_emod;
-+ unsigned char bswapped;
-+ unsigned char nt_mode;
-+ unsigned char int_drec;
-+} hfc_regs;
-+
-+struct bch {
-+ int fill_fifo,checkcnt,initialized;
-+ struct {
-+ u16 z2;
-+ struct {
-+ volatile u16 *z1p;
-+ volatile u8 *fifo_base;
-+ int filled;
-+ } c[2];
-+ int diff;
-+ } rx;
-+ struct {
-+ u16 z1;
-+ struct {
-+ volatile u16 *z1p,*z2p;
-+ volatile u8 *fifo_base;
-+ int filled;
-+ } c[2];
-+ int diff;
-+ } tx;
-+};
-+
-+struct dch {
-+ struct {
-+ struct {
-+ volatile u8 *p;
-+ } f1;
-+ struct {
-+ u8 v;
-+ struct {
-+ u16 v;
-+ } z2;
-+ } f2;
-+ } rx;
-+ struct {
-+ struct {
-+ u8 v;
-+ volatile u8 *p;
-+ struct {
-+ u16 v;
-+ } z1;
-+ } f1;
-+ struct {
-+ volatile u8 *p;
-+ } f2;
-+ } tx;
-+};
-+
-+typedef struct hfc_card {
-+ spinlock_t lock;
-+ unsigned int irq;
-+ unsigned int iomem;
-+ int ticks;
-+ unsigned char *pci_io;
-+ void *fifos; // 32k aligned mem for the fifos
-+ struct hfc_regs regs;
-+ unsigned int pcibus;
-+ unsigned int pcidevfn;
-+ struct pci_dev *pcidev;
-+ struct zt_hfc *ztdev;
-+ int drecinframe;
-+ unsigned char drecbuf[hfc_D_FIFO_SIZE];
-+ unsigned char dtransbuf[hfc_D_FIFO_SIZE];
-+ unsigned char brecbuf[2][ZT_CHUNKSIZE];
-+ unsigned char btransbuf[2][ZT_CHUNKSIZE];
-+ unsigned char cardno;
-+ int active;
-+ struct bch bch;
-+ struct dch dch;
-+ struct hfc_card *next;
-+} hfc_card;
-+
-+typedef struct zt_hfc {
-+ unsigned int usecount;
-+ struct zt_span span;
-+ struct zt_chan chans[3];
-+ struct hfc_card *card;
-+} zt_hfc;
-+
-+/* vim:set sw=4: */
-+
-diff -urNad --exclude=CVS --exclude=.svn ./zaphfc-florz/zaptel.conf /tmp/dpep-work.8uAAbh/zaptel-1.0.9.1/zaphfc-florz/zaptel.conf
---- ./zaphfc-florz/zaptel.conf 1970-01-01 01:00:00.000000000 +0100
-+++ /tmp/dpep-work.8uAAbh/zaptel-1.0.9.1/zaphfc-florz/zaptel.conf 2005-08-27 23:17:30.000000000 +0200
-@@ -0,0 +1,8 @@
-+# hfc-s pci a span definition
-+# most of the values should be bogus because we are not really zaptel
-+loadzone=nl
-+defaultzone=nl
-+
-+span=1,1,3,ccs,ami
-+bchan=1-2
-+dchan=3
Deleted: zaptel/trunk/debian/patches/zaphfc_gcc4.dpatch
===================================================================
--- zaptel/trunk/debian/patches/zaphfc_gcc4.dpatch 2006-04-30 15:19:14 UTC (rev 1655)
+++ zaptel/trunk/debian/patches/zaphfc_gcc4.dpatch 2006-04-30 16:30:35 UTC (rev 1656)
@@ -1,19 +0,0 @@
-#! /bin/sh /usr/share/dpatch/dpatch-run
-## zaphfc_gcc41.dpatch by Santiago Ruano Rincon <santiago at unicauca.edu.co>
-##
-## All lines beginning with `## DP:' are a description of the patch.
-## DP: Patch to allow zaphfc compiles with gcc-4.0.1
-
- at DPATCH@
-diff -urNad zaptel-1.0.9.1/zaphfc/zaphfc.c /tmp/dpep.rQizd7/zaptel-1.0.9.1/zaphfc/zaphfc.c
---- zaptel-1.0.9.1/zaphfc/zaphfc.c 2005-08-19 00:25:28.000000000 -0500
-+++ /tmp/dpep.rQizd7/zaptel-1.0.9.1/zaphfc/zaphfc.c 2005-08-19 00:26:17.000000000 -0500
-@@ -997,7 +997,7 @@
- return -ENOMEM;
- } else {
- memset(hfctmp->fifomem, 0x0, 65536);
-- (ulong) hfctmp->fifos = (((ulong) hfctmp->fifomem) & ~0x7FFF) + 0x8000;
-+ hfctmp->fifos = (((ulong) hfctmp->fifomem) & ~0x7FFF) + 0x8000;
- pci_write_config_dword(hfctmp->pcidev, 0x80, (u_int) virt_to_bus(hfctmp->fifos));
- hfctmp->pci_io = ioremap((ulong) hfctmp->pci_io, 256);
- }
Deleted: zaptel/trunk/debian/patches/ztcfg_init.dpatch
===================================================================
--- zaptel/trunk/debian/patches/ztcfg_init.dpatch 2006-04-30 15:19:14 UTC (rev 1655)
+++ zaptel/trunk/debian/patches/ztcfg_init.dpatch 2006-04-30 16:30:35 UTC (rev 1656)
@@ -1,32 +0,0 @@
-#! /bin/sh /usr/share/dpatch/dpatch-run
-## ztcfg_init.dpatch by Kilian Krause <kilian at debian.org>
-##
-## All lines beginning with `## DP:' are a description of the patch.
-## DP: make ztcfg not kill channels when executed twice
-
- at DPATCH@
---- zaptel-1.0.9.1/ztcfg.c 2005-05-12 04:36:11.000000000 +0200
-+++ zaptel.new/ztcfg.c 2005-08-27 22:41:39.000000000 +0200
-@@ -756,15 +756,14 @@
- /* destroy them all */
- ioctl(fd, ZT_DYNAMIC_DESTROY, &zds[x]);
- }
-- if (stopmode) {
-- for (x=0;x<spans;x++) {
-- if (ioctl(fd, ZT_SHUTDOWN, &lc[x].span)) {
-- fprintf(stderr, "Zaptel shutdown failed: %s\n", strerror(errno));
-- close(fd);
-- exit(1);
-- }
-+ for (x=0;x<spans;x++) {
-+ if (ioctl(fd, ZT_SHUTDOWN, &lc[x].span)) {
-+ fprintf(stderr, "Zaptel shutdown failed: %s\n", strerror(errno));
-+ close(fd);
-+ exit(1);
- }
-- } else {
-+ }
-+ if (!stopmode) {
- for (x=0;x<spans;x++) {
- if (ioctl(fd, ZT_SPANCONFIG, lc + x)) {
- fprintf(stderr, "ZT_SPANCONFIG failed on span %d: %s (%d)\n", lc[x].span, strerror(errno), errno);
More information about the Pkg-voip-commits
mailing list